Problem:


Score : 600 points

Problem Statement
Q tuples of integers (L_i, A_i, B_i, M_i). For each tuple, answer the following question. -->

There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}.

The initial term is A, and the common difference is B. That is, s_i = A + B \times i holds.

Consider the integer obtained by concatenating the terms written in base ten without leading zeros. For example, the sequence 3, 7, 11, 15, 19 would be concatenated into 37111519. What is the remainder when that integer is divided by M?

Constraints

All values in input are integers.

1 \leq L, A, B < 10^{18}

2 \leq M \leq 10^9

All terms in the arithmetic progression are less than 10^{18}.

Input

Input is given from Standard Input in the following format:

L A B M

Output

Print the remainder when the integer obtained by concatenating the terms is divided by M.

Sample Input 1

5 3 4 10007

Sample Output 1

5563

Our arithmetic progression is 3, 7, 11, 15, 19, so the answer is 37111519 mod 10007, that is, 5563.

Sample Input 2

4 8 1 1000000

Sample Output 2

891011

Sample Input 3

107 10000000000007 1000000000000007 998244353

Sample Output 3

39122908



Sample input:
5 3 4 10007


Sample output:
5563

Submission status: Runtime Error

Solution code:
inputs = [int(s) for s in input().split()]
l = inputs[0]
a = inputs[1]
b = inputs[2]
m = inputs[3]

s = [0]*l
result = 0

for i in range(l):
    s[i] = a + b*i

k = 0
mk = len(str(m))
for i in range(l-1, -1, -1):
    print(s[i])
    result = (result + s[i] * (10 ** k)) % m
    k = k + len(str(s[i]))

print(result)

Submission status: Runtime Error

Solution code:
inp = input().split()
L = int(inp[0])
A = int(inp[1])
B = int(inp[2])
M = int(inp[3])

summ = int(''.join([str(i) for i in range(A, L*A, B)]))
print(summ%M)

Submission status: Runtime Error

Solution code:
L,A,B,M=map(int,input().split())
gap=[-1 for k in range(37)]
for k in range(37):
    tmp=10**k-A
    if tmp%B==0:
        gap[k]=-1+tmp//B
    else:
        gap[k]=tmp//B
    gap[k]=min(L-1,gap[k])
    gap[k]=max(-1,gap[k])
num=[0 for k in range(37)]
for k in range(1,37):
    #k-1,k
    num[k]=-gap[k-1]+gap[k]

def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
def inv(x):
    return egcd(x,M)[0]
ans=0
geta=0
for k in range(36,-1,-1):
    n=num[k]
    P=A+B*gap[k-1]
    Q=B
    R=pow(10,num[k],M)
    tmp=R*(P*(R-1)*(pow(R,n,M)-1)+n*Q*pow(R,n+1,M)-(n+1)*Q*pow(R,n,M)+Q)
    tmp%=M
    tmp*=pow(10,geta,M)
    tmp*=inv((R-1)**2)
    tmp%=M
    ans+=tmp
    ans%=M
    geta+=k*gap[k]
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
l,a,b,m = map(int,input().split())
#tlist = range(a,a+b*(l-1),b)
tlist = np.arange(a,a+b*(l-1),b)

str_tlist = [str(i) for i in tlist ]
conbined = "".join(str_tlist)
conbined = int(conbined)
print(conbined%m)

Submission status: Runtime Error

Solution code:
s = ''
l, a, b, m = map(int, raw_input().split())
for i in range(l):
  s += str(a+b*i)
s = int(s)
print s%m

Submission status: Runtime Error

Solution code:
import math
L, A, B, M = map(int, input().split())

ans = 0
keta = 0
ketasu = 0
for i in range(L):
    ans += ((A+B*(L-i-1))*pow(10, keta))%M
    ketasu = math.log10(A+B*(L-i-1))
    if ketasu == int(ketasu):
        keta += ketasu + 1
    else:
	    keta += math.ceil(ketasu)
print(int(ans%M))

Submission status: Runtime Error

Solution code:
import math
L, A, B, M = map(int, input().split())



ans = 0
keta = 0
ketasu = 0
for i in range(L):
    ans += ((A+B*(L-i-1))*pow(10, keta))%M
    ketasu = math.log10(A+B*(L-i-1))
    if ketasu == int(ketasu):
        keta += ketasu + 1
    else:
	    keta += math.ceil(ketasu)
print(ans%M)

Submission status: Runtime Error

Solution code:
import numpy as np
T = input()
data = T.split()
L, A, B, M = list(map(int, data))
END = A + B * L
ans_list = np.arange(A, END, B)
ans_tmp = int(''.join(map(str, ans_list)) ) 
print(ans_tmp % M)

Submission status: Runtime Error

Solution code:
l,a,b,m = map(int,input().split())
tlist = []
for i in range(l):
    tlist.append(a+b*i)

str_tlist = [str(i) for i in tlist ]
conbined = join(str_tlist)
conbined = int(conbined)
print(conbined%m)

Submission status: Runtime Error

Solution code:
L, A, B, M = map(int, input().split())

S = [0]*L

for i in range(L):
    S[i] = A + B * i

mapS = map(str, S)
joinS = ''.join(mapS)


ans = int(joinS)

print(ans % M)

Submission status: Runtime Error

Solution code:
l,a,b,m = input().split()
l = int(l)
a = int(a)
b = int(b)
m = int(m)
list = [0]*l
for i in range(l):
    list[i]=a+b*i
list = [str(n) for n in list]
mojiretu = ' '
for x in list:
    mojiretu += x
mojiretu = int(mojiretu)
print(mojiretu%m)