Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, but it is not stupid!). The encryption has several levels of security, and here is how the first one looks.

Heidi is presented with a screen that shows her a sequence of integers A and a positive integer p. She knows that the encryption code is a single number S, which is defined as follows:

Define the score of X to be the sum of the elements of X modulo p.

Heidi is given a sequence A that consists of N integers, and also given an integer p. She needs to split A into 2 parts such that:   Each part contains at least 1 element of A, and each part consists of contiguous elements of A.  The two parts do not overlap.  The total sum S of the scores of those two parts is maximized. This is the encryption code. 

Output the sum S, which is the encryption code.


-----Input-----

The first line of the input contains two space-separated integer N and p (2 ≤ N ≤ 100 000, 2 ≤ p ≤ 10 000) – the number of elements in A, and the modulo for computing scores, respectively.

The second line contains N space-separated integers which are the elements of A. Each integer is from the interval [1, 1 000 000].


-----Output-----

Output the number S as described in the problem statement.


-----Examples-----
Input
4 10
3 4 7 2

Output
16

Input
10 12
16 3 24 13 9 8 7 5 12 12

Output
13



-----Note-----

In the first example, the score is maximized if the input sequence is split into two parts as (3, 4), (7, 2). It gives the total score of $(3 + 4 \operatorname{mod} 10) +(7 + 2 \operatorname{mod} 10) = 16$.

In the second example, the score is maximized if the first part consists of the first three elements, and the second part consists of the rest. Then, the score is $(16 + 3 + 24 \operatorname{mod} 12) +(13 + 9 + 8 + 7 + 5 + 12 + 12 \operatorname{mod} 12) = 7 + 6 = 13$.

Difficulty: interview

Starter code:

Solutions:
#http://codeforces.com/contest/958/problem/C1

N,p=list(map(int,input().split()))
A=list(map(int,input().split()))
sum1=A[0]
sum2=sum(A[1:])
ans=(sum1%p)+(sum2%p)
for i in range(1,N-1):
    sum1+=A[i]
    sum2-=A[i]
    ans1=sum1%p
    ans2=sum2%p
    ans=max(ans1+ans2,ans)
print(ans)

N, p = list(map(int, input().split()))
A = list(map(int, input().split()))
sa = sum(A)
cursum = 0
ans = 0
for i, a in enumerate(A[:-1]):
    cursum += a
    score = (cursum % p) + ((sa - cursum) % p)
    ans = max(ans, score)

print(ans)




n,p=list(map(int,input().split()))
a=list(map(int,input().split()))

sum1=0
pre=[]
for i in range(n):
    sum1+=a[i]
    sum1=sum1%p
    pre.append(sum1)
post=[0 for i in range(n)] #ii is not included
sum1=0
for i in range(n-1,-1,-1):
        post[i]=sum1
        sum1+=a[i]
        sum1=sum1%p
s=0
for i in range(n):
    s=max(pre[i]+post[i],s)
print(s)


N,P = list(map(int,input().split()))
src = list(map(int,input().split()))
K = sum(src)%P
ans = tmp = 0
for a in src:
    tmp += a
    tmp %= P
    ans = max(ans, tmp + (K-tmp)%P)
print(ans)


n, m = [int(x) for x in input().split(' ')]
numbers = [int(x) for x in input().split(' ')]

max_res = 0
total_sum = sum(numbers)
sum_thus_far = 0
for i in range(n-1):
	tmp_a = sum_thus_far + numbers[i]
	tmp_b = total_sum - tmp_a
	tmp_sum = (tmp_a % m) + (tmp_b % m)
	if tmp_sum > max_res:
		max_res = tmp_sum

print(max_res)

n, p = list(map(int, input().split()))
arr = list(map(int, input().split()))
sum_ = sum(arr)
res = 0
temp = 0
for i in arr:
    temp += i
    sum_ -= i
    res = max(res, temp % p + sum_ % p)

print(res)


n, p = list(map(int, input().split()))
pre = [0] * 100100
A = list(map(int, input().split()))
for i in range(n):
  pre[i + 1] = (pre[i] + A[i]) % p
print(max((pre[i] - pre[0]) % p + (pre[n] - pre[i]) % p for i in range(1, n)))
  


n,m=map(int,input().split())
arr=list(map(int,input().split()))
s1=arr[0]
s2=sum(arr)-arr[0]
ans=[s1%m+s2%m]
for i in range(1,n-1):
    s1+=arr[i]
    s2-=arr[i]
    ans.append(s1%m+s2%m)
print(max(ans))

s = input().split()
n, p = int(s[0]), int(s[1])
cl = list(map(int, input().split()))
mx = 0
sm = sum(cl)
qs = cl[0]
for i in range(1, n):
  y = qs%p + (sm-qs)%p
  if y>mx:
    mx = y
  qs+=cl[i]

print(mx)

n,p = map(int,input().split())
a = list(map(int,input().split()))
pref = [a[0]]
for i in range(1,n):
    pref.append(pref[-1]+a[i])
tot = pref[-1]
ans = 0
for i in range(n-1):
    ans = max(ans,(pref[i]%p)+((pref[-1]-pref[i])%p))
print(ans)

n, p = [int(i) for i in input().split()]
soma = [0 for i in range(n + 1)]
for idx, i in enumerate(input().split()):
  soma[idx + 1] = soma[idx] + int(i)%p
  
r = -float("inf")
for i in range(1, n):
  r = max(r, soma[i]%p + (soma[n] - soma[i])%p)

print(r)

n, p = list(map(int, input().split()))
a = list(map(int, input().split()))
a = [c % p for c in a]
s = sum(a)
sp = s % p
if sp == s or sp + 1 == p:
    print(sp)
else:
    print(sp + p)


n, p = (int(x) for x in input().split())
a = [int(x) for x in input().split()]

sum1 = int(0)
sum2 = int(0)

for i in range(0, n):
    sum2 = sum2 + a[i]
k = n-1
b = [0]
for i in range(0, k):
    sum1 = sum1 + a[i]
    sum2 = sum2 - a[i]
    b.append((sum1 % p) + (sum2 % p))
print(max(b))
    


n, p = map(int, input().split())


a = list(map(int, input().split()))

m = -1

s = sum(a)

sums = 0
for i in a:

	sums+=i

	m = max(m, sums%p+(s-sums)%p)

print(m)

n, p = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
s1, s2 = a[0], sum(a) - a[0]
ans = s1 % p + s2 % p
for i in range(n - 1):
    s1 = (s1 + a[i]) % p
    s2 = (s2 - a[i]) % p
    ans = max(ans, s1 + s2)
print(ans)


# from dust i have come dust i will be

n,p=list(map(int,input().split()))
a=list(map(int,input().split()))

s=sum(a)
mx=0
t=0
for i in range(n-1):
    t+=a[i]
    x=(t%p)+(s-t)%p
    mx=max(mx,x)

print(mx)




n, p = map(int, input().split())


a = list(map(int, input().split()))

m = -1

s = sum(a)

sums = 0
for i in a:

	sums+=i

	m = max(m, sums%p+(s-sums)%p)

print(m)

n, p = map(int, input().split())
a = [int(x) for x in input().split()]
s = sum(a)
ans = -1; psum = 0
for i in a:
    psum += i
    ans = max(ans, psum % p + (s - psum) % p)
print(ans)

n,p = list(map(int, input().split()))
a = list(map(int, input().split()))

x = a[0] % p
y = sum(a[1:]) % p
s = x+y
for i in range(1, n-1):
	x = (x+a[i]) % p
	y = (y-a[i]) % p
	s = max(s, x+y)
print(s)


from itertools import accumulate

N, p = list(map(int, input().split()))
A = list(map(int, input().split()))

left = [0] + list(accumulate(A))
right = list(accumulate(A[::-1]))[::-1] + [0]

ans = [(left[i] % p) + (right[i] % p) for i in range(N + 1)]

print(max(ans))


n, p = map(int, input().split())
a = list(map(int, input().split()))
a = [c % p for c in a]
s = sum(a)
sp = s % p
if sp == s or sp + 1 == p:
    print(sp)
else:
    print(sp + p)

line1=list(map(int,input().split()))
nums=list(map(int,input().split()))
n,p=line1[0],line1[1]
sum_all=sum(nums)
sum_left=nums[0]
sum_right=sum_all-sum_left
res=sum_left%p + sum_right%p
for i in range(1,n-1):
    sum_left+=nums[i]
    sum_right-=nums[i]
    temp=sum_left%p + sum_right%p
    res=max(res,temp)
    
print(res)


np = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

max = 0

mod = []
sum = 0
for i in range(0, np[0]) :
    sum += a[i]
    mod.append(sum % np[1])
index = 0
mm = 0
for i in range(0, np[0]) :
    if mod[i] > mm :
        mm = mod[i]
        index = i


sum2 = 0;
for i in range(index+1, np[0]) :
    sum2 += a[i]
sum2 = sum2 % np[1]

print(mod[index] + sum2)



np = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

l1 = [a[0]]
l2 = [a[np[0] - 1]]

for i in range(1, np[0] - 1) :
    l1.append(l1[i - 1] + a[i])
    l2.append(l2[i - 1] + a[-(i + 1)])

max = 0
for i in range(0, np[0] - 1) :
    if l1[i] % np[1] + l2[-(i + 1)] % np[1] > max:
        max = l1[i] % np[1] + l2[-(i + 1)] % np[1]

print(max)


n, p = [int(a) for a in input().strip().split(' ')]
e = [int(a) for a in input().strip().split(' ')]
max_sum = 0
s = sum(e)
current_s = 0
for i in e:
    current_s += (i % p)
    current_s %= p
    max_sum = max(max_sum,current_s + (s - current_s) % p)
print(max_sum)