program Azadacha;

{$APPTYPE CONSOLE}

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 downto n do
  begin
   if (a[i]=a[i-1]) and (a[i-1]>0) then
   k:=k+a[i];
  end;

  Writeln(k);
 readln(n);
end.
 
