import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } void main() { debug { foreach (m; 1 .. 4) foreach (n; 1 .. 5) { foreach (p; 0 .. 1 << (m * n)) { auto a = new int[][](m, n); foreach (x; 0 .. m) foreach (y; 0 .. n) { a[x][y] = (p >> (x * n + y)) & 1; } auto dp = new bool[][][][][](m + 1, m + 1, n + 1, n + 1, 2); foreach (x; 0 .. m) foreach (y; 0 .. n) { dp[x][x + 1][y][y + 1][a[x][y]] = true; } foreach (h; 1 .. m + 1) foreach (w; 1 .. n + 1) { foreach (x0; 0 .. m - h + 1) foreach (y0; 0 .. n - w + 1) { const x1 = x0 + h, y1 = y0 + w; foreach (x; x0 + 1 .. x1) { foreach (s; 0 .. 2) { if (dp[x0][x][y0][y1][s] && dp[x][x1][y0][y1][s ^ 1]) { dp[x0][x1][y0][y1][] = true; } } } foreach (y; y0 + 1 .. y1) { foreach (s; 0 .. 2) { if (dp[x0][x1][y0][y][s] && dp[x0][x1][y][y1][s ^ 1]) { dp[x0][x1][y0][y1][] = true; } } } } } /* foreach (x; 0 .. m) { foreach (y; 0 .. n) { write(a[x][y]); } writeln(); } writeln(dp[0][m][0][n][1]); writeln(); */ const row = iota(m).any!(x => iota(n).all!(y => (a[x][0] == a[x][y]))); const col = iota(n).any!(y => iota(m).all!(x => (a[0][y] == a[x][y]))); if (m * n > 1) { assert(dp[0][m][0][n][1] == !(row && col)); } } } } try { for (; ; ) { const M = readInt(); const N = readInt(); auto A = new string[M]; foreach (x; 0 .. M) { A[x] = readToken(); } const row = iota(M).any!(x => iota(N).all!(y => (A[x][0] == A[x][y]))); const col = iota(N).any!(y => iota(M).all!(x => (A[0][y] == A[x][y]))); const ans = ((M == 1 && N == 1) || !(row && col)); writeln(ans ? "YES" : "NO"); } } catch (EOFException e) { } }