print((function (f, fh, m) local x,r = fh:read("*n"),0ULL for _=1,fh:read("*n") do r=r+f(x,fh:read("*n"),m) end return tostring(r%m):sub(1,-4) end)(function (x, n, m) local ba,rs,r = bit.band,bit.rshift,1ULL while n~=0 do r,x,n=ba(n,1)~=0 and r*x%m or r,x*x%m,rs(n,1) end return r%m end, io.stdin, 1000003ULL))