I solved Mister B and PR Shifts using trie ... Time complexity of my code is O(n * log(n)) where maximum n = 1000000 ... but it takes about 1620 ms at least to get the answer, so can anyone please tell me why? this is my first submission: http://codeforces.net/contest/819/submission/28102807 and this is the best code I came up with: http://codeforces.net/contest/819/submission/28110510 sorry for my bad English. thanks.