I solved this problem: https://codeforces.net/contest/1328/problem/E with the following program: https://codeforces.net/contest/1328/submission/78374395. The time it takes is ok, but it takes up quite a lot of memory (180 mb), but that doesn't make sense in my opinion since the program stores at most about 15 million integers.