codeforces 493 (div2) and BoardFolding
optimization for full rows