here is my solution: https://mirror.codeforces.com/contest/1624/submission/144304382 for this problem: https://mirror.codeforces.com/contest/1624/problem/E I think time complexity of this solution is O(n*m) is small enough, but why this still give TLE? Thanks you for read my shi* blog.