import std.stdio; import std.algorithm; import std.string; import std.conv; void main() { int[1000] lane, tasteMemo; immutable n = readln.chomp.to!int; readln.splitter.map!(to!int).copy(lane[]); foreach (i, x; lane[0..n]) { if (i < 2) { tasteMemo[i] = x; continue; } int max = 0; foreach_reverse (j, y; tasteMemo[0..(i - 1)]) { if (y > max) { max = y; } } tasteMemo[i] = x + max; } writeln(tasteMemo.reduce!max); }