import std.stdio; import std.algorithm; import std.string : chomp; import std.range; import std.conv; void main(string[] args) { immutable n = readln.chomp.to!int; readln .splitter .map!(to!int) .map!(x => iota(x, n + 1, x)) .join .sort() .uniq .walkLength .writeln; }