import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; void main(){ auto N = readln.chomp.to!long; auto S = readln.chomp; if(N == 1){ writeln(1); return; } if(N == 2){ writeln(S[0] == S[1] ? 1 : 2); return; } auto count = new ulong[10]; ulong mod = 0; foreach(c; S){ count[c - '0']++; mod += c - '0'; } mod %= 3; bool[long] result; for(auto i = 0; i < 1000; i++){ auto s = "%03d".format(i); auto cnt = new ulong[10]; auto m = 0; foreach(c; s){ cnt[c - '0']++; m += c - '0'; } m %= 3; if(iota(10).any!(a => cnt[a] > count[a])) continue; result[((mod + 3 - m) * 1000 + i) % 120] = true; } result.length.writeln; }