{
    DWID (Does What It Does) 0.0.1
    Copyright (C) 2003 Andrej Krutak

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
}

program u1;

var x, s, m1, m2: integer;

begin
     {tato cast by sa dala vyriesit aj nacitanim prvych dvoch skupin osobitne}
     {ale bolo by to dlhe a netreba to :)}
     m1:=-MAXINT;
     m2:=-MAXINT-1;
     read(x);

     {zvysok je asi jasny}
     while (x<>-2) do begin
           s:=0;
           while ((x<>-1) AND (x<>-2)) do begin
                 s:=s+x;
                 read(x);
           end;

           {trik na zvladnutie -1 aj -2 na konci skupiny, whoa yeah!}
           if (x<>-2) then read(x);

           if (s>m1) then begin m2:=m1; m1:=s; end
           else if (s>m2) then m2:=s;
     end;
     
     {najobtiaznejsia cast programu :o)}
     writeln('2. najvacsi sucet: ', m2);
end.
