import std.algorithm, std.conv, std.range, std.stdio, std.string; import core.bitop; void main() { size_t n = readln.chomp.to!size_t; uint c = toBuf(10.iota); foreach (_; n.iota) { string[] rd = readln.split; int[] ai = rd[0..4].to!(int[]); string yn = rd[4]; int b = toBuf(ai); c = yn.predSwitch("YES", c & b, "NO", c & ~b); } writeln(bsr(c)); } uint toBuf(Range)(Range ai) if (isInputRange!Range) { return reduce!((a, b) => a | (1 << b))(0, ai); }