here is my solution: https://codeforces.me/contest/1624/submission/144304382 for this problem: https://codeforces.me/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.