
uses
  SysUtils;

var
     k,i,n:Integer;
     a:array [1..100] of Integer;
begin
  k:=0;
 Readln(n);
  for i:=1 to n do
  begin
    Read(a[i]);
  end;
  for i:=1 to n do
  begin
  if a[i]=a[i-1] then
   k:=k+a[i-1]+a[i];
   a[3]:=a[3]-1;
   a[2]:=a[2]-1;
   a[1]:=a[1]-1;
  end;
  Writeln(k);
  Readln(n);
end.