local ffi = require 'ffi' local C = ffi.C ffi.cdef [[ long atol(const char *); int printf(const char *, ...); ]] C.printf("%d\n", (function (f, m, n) local r = 0LL for _=1,n do r=r+f(io.stdin:read("*l"),m) end return r%m end)(function (s, m) local c,d = C.atol(s:match("(%d+)%s")),C.atol(s:match("%s(%d+)")) return (((c/2LL+(c%2LL~=0 and 1LL or 0LL))%m) * (d%m))%m end, 1000000007LL, tonumber(io.stdin:read("*l"))))