I have solved this problem but I am not able to pass the timelimit Can someone tell the improvement in the code .. asked 21 Jul '17, 16:34

Just try to run with the following input:
You will get an overflow. In your code, you are calculating c to power O(n^2). Which is super exponential w.r.t. n. Just n=100 and c=2 leads to an overflow. Just think what will happen with the largest possible inputs. For example,
which will lead to c^10^36. That's a HUGEEEE number. Obviously your code will break. Try to come up with another algorithm and think about when you should be using the MOD limit of 10^9+7. There is a catch while writing Python codes. As the popular saying goes: With great power comes great responsibilities. Similarly, with great Python one liners, comes a great responsibility of understanding what's going on behind the scene and what complexity a library call involves. answered 21 Jul '17, 17:04
