import std.stdio; import std.conv; import std.string; import std.math; import std.algorithm; void main(){ auto nk = readln.split.map!(to!int); int[] numMemo; numMemo.length = 1_000_005; int wi; int wiCount(int j){ return numMemo[j..$].reduce!("a + b"); } foreach(i; 1..nk[0]+1){ wi = readln.chomp.to!int; if(wi > 0){ if(wiCount(wi) < nk[1] ){ numMemo[wi] += 1; } } else{ numMemo[abs(wi)] = max(0, numMemo[abs(wi)] - 1); } } auto res = numMemo.reduce!("a + b"); res.writeln; }