I am trying to implement a circular rotation algorithm for a hackerrank challenge question. My code(middle block) seems to run fine for small inputs but fails for larger inputs due to timeout. Any help optimizing the code will be much appreciated.
Here is my code:
import sys
n,k,q = raw_input().strip().split(' ')
n,k,q = [int(n),int(k),int(q)]
a = map(int,raw_input().strip().split(' '))
for j in range(0,k):
temp = a[n-1]
for i in range(n-2, -1, -1):
a[i+1] = a[i]
a[0] = temp
for a0 in xrange(q):
m = int(raw_input().strip())
print a[m]