import std.stdio, std.string, std.conv; import std.array, std.algorithm; void main(){ auto l = readln.strip.to!int; auto arr = readln.strip.split.map!(to!int).array; uint ans; if(l == 1){ans = arr[0];} while(arr.length > 1){ int max, pos; foreach(i, x; arr){ if(max < x){ max = x; pos = i.to!int; } } ans += max; if(pos+1 < arr.length){ arr = arr.remove(pos+1); } arr = arr.remove(pos); if(pos-1 >= 0){ arr = arr.remove(pos-1); } } ans.writeln; }