POLYEVAL question

I am trying POLYEVAL. Here’s my solution: 14635086

I am getting TLE for the second task. I tried using Xellos0’s method in a comment to this Editorial: Here

However, it does not seem much faster than the brute force method: 14621704

Is the TLE because I am using Python? or is there anything that can be more optimized?