using System; using System.Linq; class No178{ static void Main(){ long max=0; long count=0; var isEvenNum=false; var num=Int32.Parse(Console.ReadLine()); for(int i=0;iInt64.Parse(x)).ToArray(); var l=line[0]+line[1]*4; if(i!=0&&((l%2==0)!=isEvenNum)){ count=-1; break; } else isEvenNum=l%2==0; if(l>max){ count+=(l-max)*i; max=l; } count+=max-l; } Console.WriteLine(count>0?count/2:count); } }