Input:
s = [int(x) for x in eval(input())]

##print(s)

count = len(s)-1##+の入りうるポジション数

sum = 0

for bit in range(2**count):

    hugou = [""] * count

    ##print(bin(bit))

    for i in range(count):

        if (bit >> i) & 1:

            hugou[count-1-i] = "+"

            ##print(hugou)

    calc = ""

    for j in range(count):

        calc += str(s[j])

        ##print(s)

        calc += str(hugou[j])

        ##print(hugou)

        ##print(calc)

    calc += str(s[-1])

    ##print(calc)

    sum += eval(calc)

print(sum)

s = eval(input())

len = len(s)

ns = list(map(int,s))

total_sum = 0

for bit in range(1 << (len-1)):

  ##print(bit)

  sum_ = 0

  num = ns[0]

  for i in range(1, len):

    if (bit & 1) > 0:

      sum_ += num

      num = ns[i]

    else:

      num = (num * 10 + ns[i])

    bit = bit >> 1

  total_sum += sum_ + num

print(total_sum)

s = [int(x) for x in eval(input())]
##print(s)
count = len(s) - 1  ##+の入りうるポジション数
sum = 0
for bit in range(2**count):
    hugou = [""] * count
    ##print(bin(bit))
    for i in range(count):
        if (bit >> i) & 1:
            hugou[count - 1 - i] = "+"
            ##print(hugou)
    calc = ""
    for j in range(count):
        calc += str(s[j])
        ##print(s)
        calc += str(hugou[j])
        ##print(hugou)
        ##print(calc)
    calc += str(s[-1])
    ##print(calc)
    sum += eval(calc)
print(sum)

s = eval(input())
len = len(s)
ns = list(map(int, s))
total_sum = 0
for bit in range(1 << (len - 1)):
    ##print(bit)
    sum_ = 0
    num = ns[0]
    for i in range(1, len):
        if (bit & 1) > 0:
            sum_ += num
            num = ns[i]
        else:
            num = num * 10 + ns[i]
        bit = bit >> 1
    total_sum += sum_ + num
print(total_sum)

-s = [int(x) for x in eval(input())]
-##print(s)
-count = len(s) - 1  ##+の入りうるポジション数
-sum = 0
-for bit in range(2**count):
-    hugou = [""] * count
-    ##print(bin(bit))
-    for i in range(count):
-        if (bit >> i) & 1:
-            hugou[count - 1 - i] = "+"
-            ##print(hugou)
-    calc = ""
-    for j in range(count):
-        calc += str(s[j])
-        ##print(s)
-        calc += str(hugou[j])
-        ##print(hugou)
-        ##print(calc)
-    calc += str(s[-1])
-    ##print(calc)
-    sum += eval(calc)
-print(sum)
+s = eval(input())
+len = len(s)
+ns = list(map(int, s))
+total_sum = 0
+for bit in range(1 << (len - 1)):
+    ##print(bit)
+    sum_ = 0
+    num = ns[0]
+    for i in range(1, len):
+        if (bit & 1) > 0:
+            sum_ += num
+            num = ns[i]
+        else:
+            num = num * 10 + ns[i]
+        bit = bit >> 1
+    total_sum += sum_ + num
+print(total_sum)


Input:
n = int(eval(input()))

count = 0

for i in range(n):

    l,r = list(map(int,input().split()))

    count += r-l+1

print(count)

n = int(eval(input()))

count = 0

for i in range(n):

    li,ri = list(map(int,input().split()))

    count += ri-li+1

print(count)

n = int(eval(input()))
count = 0
for i in range(n):
    l, r = list(map(int, input().split()))
    count += r - l + 1
print(count)

n = int(eval(input()))
count = 0
for i in range(n):
    li, ri = list(map(int, input().split()))
    count += ri - li + 1
print(count)

-    l, r = list(map(int, input().split()))

+    li, ri = list(map(int, input().split()))


Input:
from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,fractions,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = eval(input())

n = len(s)

r = [ord('z') - ord(t) + 1 if t != 'a' else 0 for t in s]

res = [None] * n

k = inp()

for i,x in enumerate(r):

    if x <= k:

        res[i] = 'a'

        k -= x

if k > 0:

    tmp = 'a' if res[-1] != None else s[-1]

    res[-1] = chr((ord(tmp) - ord('a') + k)%26 + ord('a'))

for i,t in enumerate(res):

    if t == None:

        res[i] = s[i]

print((''.join(res)))

from collections import Counter,defaultdict,deque

from heapq import heappop,heappush

from bisect import bisect_left,bisect_right

import sys,math,itertools,fractions,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

s = list(eval(input()))

k = inp()

n = len(s)

nxa = ord('z') + 1

for i,x in enumerate(s):

    if x == 'a':

        continue

    rem = nxa - ord(x)

    if rem <= k:

        s[i] = 'a'

        k -= rem

if k > 0:

    s[-1] = chr(ord('a') + (ord(s[-1])-ord('a')+k)%26)

print((''.join(s)))

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")

def inp():
    return int(sys.stdin.readline())

def inpl():
    return list(map(int, sys.stdin.readline().split()))

def inpln(n):
    return list(int(sys.stdin.readline()) for i in range(n))

s = eval(input())
n = len(s)
r = [ord("z") - ord(t) + 1 if t != "a" else 0 for t in s]
res = [None] * n
k = inp()
for i, x in enumerate(r):
    if x <= k:
        res[i] = "a"
        k -= x
if k > 0:
    tmp = "a" if res[-1] != None else s[-1]
    res[-1] = chr((ord(tmp) - ord("a") + k) % 26 + ord("a"))
for i, t in enumerate(res):
    if t == None:
        res[i] = s[i]
print(("".join(res)))

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")

def inp():
    return int(sys.stdin.readline())

def inpl():
    return list(map(int, sys.stdin.readline().split()))

s = list(eval(input()))
k = inp()
n = len(s)
nxa = ord("z") + 1
for i, x in enumerate(s):
    if x == "a":
        continue
    rem = nxa - ord(x)
    if rem <= k:
        s[i] = "a"
        k -= rem
if k > 0:
    s[-1] = chr(ord("a") + (ord(s[-1]) - ord("a") + k) % 26)
print(("".join(s)))

-from heapq import heappop, heappush, heapify

-import sys, bisect, math, itertools, fractions, pprint

+from bisect import bisect_left, bisect_right

+import sys, math, itertools, fractions, pprint

-    return list(int(sys.stdin.readline()) for i in range(n))

-r = [ord("z") - ord(t) + 1 if t != "a" else 0 for t in s]

-    tmp = "a" if res[-1] != None else s[-1]


Input:
N,A,B = list(map(int,input().split()))

S = eval(input())

pa = pb = 0

for c in S:

    if c == 'a' and pa+pb < A+B:

        print('Yes')

        pa += 1

    elif c == 'b' and pa+pb < A+B and pb < B:

        print('Yes')

        pb += 1

    else:

        print('No')

N,A,B = map(int,input().split())

S = input()

ans = ['No'] * N

p = b = 0

for i,c in enumerate(S):

    if c == 'a':

        if p < A+B:

            ans[i] = 'Yes'

            p += 1

    elif c == 'b':

        if p < A+B and b < B:

            ans[i] = 'Yes'

            p += 1

            b += 1

print(*ans,sep='\n')

N, A, B = list(map(int, input().split()))
S = eval(input())
pa = pb = 0
for c in S:
    if c == "a" and pa + pb < A + B:
        print("Yes")
        pa += 1
    elif c == "b" and pa + pb < A + B and pb < B:
        print("Yes")
        pb += 1
    else:
        print("No")

N, A, B = map(int, input().split())
S = input()
ans = ["No"] * N
p = b = 0
for i, c in enumerate(S):
    if c == "a":
        if p < A + B:
            ans[i] = "Yes"
            p += 1
    elif c == "b":
        if p < A + B and b < B:
            ans[i] = "Yes"
            p += 1
            b += 1
print(*ans, sep="\n")

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

-    elif c == "b" and pa + pb < A + B and pb < B:


Input:
O = eval(input())

E = eval(input())

P = ""

for i in range(min(len(O),len(E))):

  if O[i] == "":

    break

  else:

    P = P+O[i]

  if E[i] == "":

    break

  else:

    P = P+E[i]

if len(O)-len(E) == 1:

  P = P+O[-1]

elif len(E)-len(O) == 1:

  P = P+E[-1]

else:

  P = P

print(P)

S = eval(input())

T = eval(input())

ans = ""

if len(S)>len(T):

  for i in range(len(T)):

    ans += S[i]

    ans += T[i]

  ans += S[-1]

elif len(S)<len(T):

  for i in range(len(S)):

    ans += S[i]

    ans += T[i]

  ans += T[-1]

else:

  for i in range(len(T)):

    ans += S[i]

    ans += T[i]

print(ans)

O = eval(input())
E = eval(input())
P = ""
for i in range(min(len(O), len(E))):
    if O[i] == "":
        break
    else:
        P = P + O[i]
    if E[i] == "":
        break
    else:
        P = P + E[i]
if len(O) - len(E) == 1:
    P = P + O[-1]
elif len(E) - len(O) == 1:
    P = P + E[-1]
else:
    P = P
print(P)

S = eval(input())
T = eval(input())
ans = ""
if len(S) > len(T):
    for i in range(len(T)):
        ans += S[i]
        ans += T[i]
    ans += S[-1]
elif len(S) < len(T):
    for i in range(len(S)):
        ans += S[i]
        ans += T[i]
    ans += T[-1]
else:
    for i in range(len(T)):
        ans += S[i]
        ans += T[i]
print(ans)

-O = eval(input())
-E = eval(input())
-P = ""
-for i in range(min(len(O), len(E))):
-    if O[i] == "":
-        break
-    else:
-        P = P + O[i]
-    if E[i] == "":
-        break
-    else:
-        P = P + E[i]
-if len(O) - len(E) == 1:
-    P = P + O[-1]
-elif len(E) - len(O) == 1:
-    P = P + E[-1]
+S = eval(input())
+T = eval(input())
+ans = ""
+if len(S) > len(T):
+    for i in range(len(T)):
+        ans += S[i]
+        ans += T[i]
+    ans += S[-1]
+elif len(S) < len(T):
+    for i in range(len(S)):
+        ans += S[i]
+        ans += T[i]
+    ans += T[-1]
-    P = P
-print(P)
+    for i in range(len(T)):
+        ans += S[i]
+        ans += T[i]
+print(ans)


Input:
a,b,c = list(map(int,input().split()))

if (b-a) == (c-b):

  print('YES')

else:

  print('NO')

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

print(('YES' if b-a == c-b else 'NO'))

a, b, c = list(map(int, input().split()))
if (b - a) == (c - b):
    print("YES")
else:
    print("NO")

a, b, c = list(map(int, input().split()))
print(("YES" if b - a == c - b else "NO"))

+print(("YES" if b - a == c - b else "NO"))


Input:
N,M,K = list(map(int,input().split()))

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

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

sumA = [0] * (N+1)

sumB = [0] * (M+1)

for i in range(N):

    sumA[i+1] = sumA[i] + A[i]

for i in range(M):

    sumB[i+1] = sumB[i] + B[i]

ans = 0

import bisect

for i in range(N+1):

    if K - sumA[i] >= 0:

        idx = bisect.bisect_right(sumB,K-sumA[i])

        ans = max(ans,i + idx - 1)

#         print(idx-1)

print(ans)

n,m,k = list(map(int,input().split()))

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

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

from itertools import accumulate

import bisect

sum_a_list = list(accumulate([0] + a_list))

sum_b_list = list(accumulate([0] + b_list))

ans = 0

b_idx = 0

for a_idx in range(n+1):

    if sum_a_list[a_idx] > k:

        continue

    time_rest = k - sum_a_list[a_idx]

    b_idx = bisect.bisect_right(sum_b_list,time_rest)

    ans = max(ans, a_idx + b_idx - 1)

print(ans)

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sumA = [0] * (N + 1)
sumB = [0] * (M + 1)
for i in range(N):
    sumA[i + 1] = sumA[i] + A[i]
for i in range(M):
    sumB[i + 1] = sumB[i] + B[i]
ans = 0
import bisect

for i in range(N + 1):
    if K - sumA[i] >= 0:
        idx = bisect.bisect_right(sumB, K - sumA[i])
        ans = max(ans, i + idx - 1)
#         print(idx-1)
print(ans)

n, m, k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
from itertools import accumulate
import bisect

sum_a_list = list(accumulate([0] + a_list))
sum_b_list = list(accumulate([0] + b_list))
ans = 0
b_idx = 0
for a_idx in range(n + 1):
    if sum_a_list[a_idx] > k:
        continue
    time_rest = k - sum_a_list[a_idx]
    b_idx = bisect.bisect_right(sum_b_list, time_rest)
    ans = max(ans, a_idx + b_idx - 1)
print(ans)

-N, M, K = list(map(int, input().split()))

+n, m, k = list(map(int, input().split()))

+a_list = list(map(int, input().split()))

+b_list = list(map(int, input().split()))

-        idx = bisect.bisect_right(sumB, K - sumA[i])

+sum_a_list = list(accumulate([0] + a_list))

+sum_b_list = list(accumulate([0] + b_list))

+    b_idx = bisect.bisect_right(sum_b_list, time_rest)


Input:
N=int(eval(input()))

S=str(eval(input()))

T=0

for i in range(N-1):

    if S[i]==S[i+1]:

        T+=1

print((N-T))

N=int(eval(input()))

S=str(eval(input()))

c=''

t=0

for s in S:

    if s==c:

        t+=1

    c=s

print((N-t))

N = int(eval(input()))
S = str(eval(input()))
T = 0
for i in range(N - 1):
    if S[i] == S[i + 1]:
        T += 1
print((N - T))

N = int(eval(input()))
S = str(eval(input()))
c = ""
t = 0
for s in S:
    if s == c:
        t += 1
    c = s
print((N - t))


Input:
import copy

n,m=list(map(int,input().split()))

l=[list(map(int,input().split())) for i in range(m)]

s,t=list(map(int,input().split()))

connection=[[] for i in range(3*n)]

for i in range(m):

  connection[l[i][0]-1].append(l[i][1]-1+n)

  connection[l[i][0]-1+n].append(l[i][1]-1+2*n)

  connection[l[i][0]-1+2*n].append(l[i][1]-1)

distance=[-1 for i in range(3*n)]

distance[s-1]=0

L=[s-1]

L2=[]

L3=[]

ct=1

while len(L2)!=3*n and len(L)!=0:

  for j in range(len(L)):

    for k in range(len(connection[L[j]])):

      if distance[connection[L[j]][k]]==-1:

        distance[connection[L[j]][k]]=ct

        L3.append(connection[L[j]][k])

    L2.append(L[j])

  L=copy.copy(L3)

  L3=[]

  ct+=1

if distance[t-1]==-1:

  print((-1))

else:

  x=distance[t-1]-distance[s-1]

  if x%3==0:

    print((x//3))

  else:

    print((-1))

n,m=list(map(int,input().split()))

l=[list(map(int,input().split())) for i in range(m)]

s,t=list(map(int,input().split()))

connection=[[] for i in range(3*n)]

for i in range(m):

  connection[l[i][0]-1].append(l[i][1]-1+n)

  connection[l[i][0]-1+n].append(l[i][1]-1+2*n)

  connection[l[i][0]-1+2*n].append(l[i][1]-1)

def bfs(v):

  distance=[-1]*(3*n)

  distance[v]=0

  next=connection[v]

  next2=set()

  visited=[-1]*(3*n)

  visited[v]=1

  visitct=1

  ct=0

  while len(next)!=0 and visitct!=3*n:

    ct+=1

    for i in range(len(next)):

      if visited[next[i]]==-1:

        distance[next[i]]=ct

        visited[next[i]]=1

        visitct+=1

        for j in range(len(connection[next[i]])):

          if visited[connection[next[i]][j]]==-1:

            next2.add(connection[next[i]][j])

    next=list(next2)

    next2=set()

  return distance

if bfs(s-1)[t-1]==-1 or bfs(s-1)[t-1]%3!=0:

  print((-1))

else:

  print((bfs(s-1)[t-1]//3))

import copy

n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
s, t = list(map(int, input().split()))
connection = [[] for i in range(3 * n)]
for i in range(m):
    connection[l[i][0] - 1].append(l[i][1] - 1 + n)
    connection[l[i][0] - 1 + n].append(l[i][1] - 1 + 2 * n)
    connection[l[i][0] - 1 + 2 * n].append(l[i][1] - 1)
distance = [-1 for i in range(3 * n)]
distance[s - 1] = 0
L = [s - 1]
L2 = []
L3 = []
ct = 1
while len(L2) != 3 * n and len(L) != 0:
    for j in range(len(L)):
        for k in range(len(connection[L[j]])):
            if distance[connection[L[j]][k]] == -1:
                distance[connection[L[j]][k]] = ct
                L3.append(connection[L[j]][k])
        L2.append(L[j])
    L = copy.copy(L3)
    L3 = []
    ct += 1
if distance[t - 1] == -1:
    print((-1))
else:
    x = distance[t - 1] - distance[s - 1]
    if x % 3 == 0:
        print((x // 3))
    else:
        print((-1))

n, m = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(m)]
s, t = list(map(int, input().split()))
connection = [[] for i in range(3 * n)]
for i in range(m):
    connection[l[i][0] - 1].append(l[i][1] - 1 + n)
    connection[l[i][0] - 1 + n].append(l[i][1] - 1 + 2 * n)
    connection[l[i][0] - 1 + 2 * n].append(l[i][1] - 1)

def bfs(v):
    distance = [-1] * (3 * n)
    distance[v] = 0
    next = connection[v]
    next2 = set()
    visited = [-1] * (3 * n)
    visited[v] = 1
    visitct = 1
    ct = 0
    while len(next) != 0 and visitct != 3 * n:
        ct += 1
        for i in range(len(next)):
            if visited[next[i]] == -1:
                distance[next[i]] = ct
                visited[next[i]] = 1
                visitct += 1
                for j in range(len(connection[next[i]])):
                    if visited[connection[next[i]][j]] == -1:
                        next2.add(connection[next[i]][j])
        next = list(next2)
        next2 = set()
    return distance

if bfs(s - 1)[t - 1] == -1 or bfs(s - 1)[t - 1] % 3 != 0:
    print((-1))
else:
    print((bfs(s - 1)[t - 1] // 3))

-while len(L2) != 3 * n and len(L) != 0:

-        for k in range(len(connection[L[j]])):

-            if distance[connection[L[j]][k]] == -1:

-                distance[connection[L[j]][k]] = ct

-                L3.append(connection[L[j]][k])

+    while len(next) != 0 and visitct != 3 * n:

+                for j in range(len(connection[next[i]])):

+                    if visited[connection[next[i]][j]] == -1:

+                        next2.add(connection[next[i]][j])

-    x = distance[t - 1] - distance[s - 1]


Input:
import copy

def main():

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

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

    dp = [[0] * (50*N + 1) for _ in range(N+1)]

    dp[0][0] = 1

    for k in range(N):

        dpn = copy.deepcopy(dp)

        for i in range(k+1):

            for j in range(50 * N + 1 -x[k]):

                dpn[i+1][j+x[k]] += dp[i][j]

        dp = dpn

    r = 0

    for i in range(1, N+1):

        r += dp[i][i*A]

    return r

print((main()))

def main():

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

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

    dp = [[0] * (50*N + 1) for _ in range(N+1)]

    dp[0][0] = 1

    for k in range(N):

        for i in reversed(list(range(k+1))):

            for j in range(50 * N + 1 -x[k]):

                dp[i+1][j+x[k]] += dp[i][j]

    r = 0

    for i in range(1, N+1):

        r += dp[i][i*A]

    return r

print((main()))

import copy

def main():
    N, A = list(map(int, input().split()))
    x = list(map(int, input().split()))
    dp = [[0] * (50 * N + 1) for _ in range(N + 1)]
    dp[0][0] = 1
    for k in range(N):
        dpn = copy.deepcopy(dp)
        for i in range(k + 1):
            for j in range(50 * N + 1 - x[k]):
                dpn[i + 1][j + x[k]] += dp[i][j]
        dp = dpn
    r = 0
    for i in range(1, N + 1):
        r += dp[i][i * A]
    return r

print((main()))

def main():
    N, A = list(map(int, input().split()))
    x = list(map(int, input().split()))
    dp = [[0] * (50 * N + 1) for _ in range(N + 1)]
    dp[0][0] = 1
    for k in range(N):
        for i in reversed(list(range(k + 1))):
            for j in range(50 * N + 1 - x[k]):
                dp[i + 1][j + x[k]] += dp[i][j]
    r = 0
    for i in range(1, N + 1):
        r += dp[i][i * A]
    return r

print((main()))

+        for i in reversed(list(range(k + 1))):


Input:
import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

class UnionFind:

    # Reference: https://note.nkmk.me/python-union-find/

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n

    def find(self, x):

        if self.parents[x] < 0:

            return x

        else:

            self.parents[x] = self.find(self.parents[x])

            return self.parents[x]

    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if x == y:

            return

        if self.parents[x] > self.parents[y]:

            x, y = y, x

        self.parents[x] += self.parents[y]

        self.parents[y] = x

    def same(self, x, y):

        return self.find(x) == self.find(y)

N, M, *AB = map(int, read().split())

uf = UnionFind(N)

ans = [N * (N - 1) // 2]

for a, b in zip(AB[-2:0:-2], AB[-1:1:-2]):

    a -= 1

    b -= 1

    if uf.same(a, b):

        ans.append(ans[-1])

    else:

        ans.append(ans[-1] - uf.parents[uf.find(a)] * uf.parents[uf.find(b)])

        uf.union(a, b)

print(*reversed(ans), sep='\n')

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

class UnionFind:

    # Reference: https://note.nkmk.me/python-union-find/

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n

    def find(self, x):

        if self.parents[x] < 0:

            return x

        else:

            self.parents[x] = self.find(self.parents[x])

            return self.parents[x]

    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if x == y:

            return

        if self.parents[x] > self.parents[y]:

            x, y = y, x

        self.parents[x] += self.parents[y]

        self.parents[y] = x

    def size(self, x):

        return -self.parents[self.find(x)]

    def same(self, x, y):

        return self.find(x) == self.find(y)

    def members(self, x):

        root = self.find(x)

        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):

        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):

        return len(self.roots())

def main():

    N, M, *AB = map(int, read().split())

    count = N * (N - 1) // 2

    ans = [count]

    uf = UnionFind(N)

    for a, b in zip(reversed(AB[::2]), reversed(AB[1::2])):

        a -= 1

        b -= 1

        if not uf.same(a, b):

            count -= uf.size(a) * uf.size(b)

            uf.union(a, b)

        ans.append(count)

    print(*reversed(ans[:-1]), sep='\n')

    return

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60

class UnionFind:
    # Reference: https://note.nkmk.me/python-union-find/
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

N, M, *AB = map(int, read().split())
uf = UnionFind(N)
ans = [N * (N - 1) // 2]
for a, b in zip(AB[-2:0:-2], AB[-1:1:-2]):
    a -= 1
    b -= 1
    if uf.same(a, b):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - uf.parents[uf.find(a)] * uf.parents[uf.find(b)])
        uf.union(a, b)
print(*reversed(ans), sep="\n")

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60

class UnionFind:
    # Reference: https://note.nkmk.me/python-union-find/
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

def main():
    N, M, *AB = map(int, read().split())
    count = N * (N - 1) // 2
    ans = [count]
    uf = UnionFind(N)
    for a, b in zip(reversed(AB[::2]), reversed(AB[1::2])):
        a -= 1
        b -= 1
        if not uf.same(a, b):
            count -= uf.size(a) * uf.size(b)
            uf.union(a, b)
        ans.append(count)
    print(*reversed(ans[:-1]), sep="\n")
    return

if __name__ == "__main__":
    main()

+        return -self.parents[self.find(x)]

+        return [i for i in range(self.n) if self.find(i) == root]

-        ans.append(ans[-1] - uf.parents[uf.find(a)] * uf.parents[uf.find(b)])

+        return [i for i, x in enumerate(self.parents) if x < 0]

+    N, M, *AB = map(int, read().split())

+    for a, b in zip(reversed(AB[::2]), reversed(AB[1::2])):

+            count -= uf.size(a) * uf.size(b)

+    print(*reversed(ans[:-1]), sep="\n")


Input:
import sys

from itertools import product

read = sys.stdin.read

readline = sys.stdin.readline

N, *S = list(map(str, read().split()))

N = int(N)

x = 0

answer = 0

for y in range(N):

    for i, j in product(list(range(N)), repeat=2):

        if S[(i + x) % N][(j + y) % N] != S[(j + x) % N][(i + y) % N]:

            break

    else:

        answer += N

print(answer)

import sys

import numpy as np

read = sys.stdin.read

readline = sys.stdin.readline

N, *S = list(map(str, read().split()))

S = np.array(list(map(list, S)), np.str)

N = int(N)

answer = 0

for y in range(N):

    for i in range(N):

        a = S[i, y:].tolist() + S[i, :y].tolist()

        b = S[:, (i + y) % N].tolist()

        if a != b:

            break

    else:

        answer += N

print(answer)

+S = np.array(list(map(list, S)), np.str)

-    for i, j in product(list(range(N)), repeat=2):

+        a = S[i, y:].tolist() + S[i, :y].tolist()


Input:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)

inf=10**20

mod=10**9+7

def LI(): return list(map(int,input().split()))

def I(): return int(eval(input()))

def LS(): return input().split()

def S(): return eval(input())

def main():

  s=S()

  l=['dream','dreamer','erase','eraser']

  while True:

    a=s[-5:]

    b=s[-7:]

    c=s[-6:]

    if a==l[0]:

      s=s[:-5]

    elif b==l[1]:

      s=s[:-7]

    elif a==l[2]:

      s=s[:-5]

    elif c==l[3]:

      s=s[:-6]

    else:

      if s=='':

        return 'YES'

      else:

        return 'NO'

print((main()))

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)

inf=10**20

mod=10**9+7

def LI(): return list(map(int,input().split()))

def I(): return int(eval(input()))

def LS(): return input().split()

def S(): return eval(input())

def main():

  s=list(S())

  l=[['d', 'r', 'e', 'a', 'm'],

  ['d', 'r', 'e', 'a', 'm', 'e', 'r'],

  ['e', 'r', 'a', 's', 'e'],

  ['e', 'r', 'a', 's', 'e', 'r']]

  while True:

    if len(s)<=4:

      break

    else:

      if l[0]==s[-5:]:

        [s.pop() for _ in ' '*5]

      elif l[1]==s[-7:]:

        [s.pop() for _ in ' '*7]

      elif l[2]==s[-5:]:

        [s.pop() for _ in ' '*5]

      elif l[3]==s[-6:]:

        [s.pop() for _ in ' '*6]

      else:

        return 'NO'

  if len(s)==0:

    return 'YES'

  return 'NO'

print((main()))

import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI():
    return list(map(int, input().split()))

def I():
    return int(eval(input()))

def LS():
    return input().split()

def S():
    return eval(input())

def main():
    s = S()
    l = ["dream", "dreamer", "erase", "eraser"]
    while True:
        a = s[-5:]
        b = s[-7:]
        c = s[-6:]
        if a == l[0]:
            s = s[:-5]
        elif b == l[1]:
            s = s[:-7]
        elif a == l[2]:
            s = s[:-5]
        elif c == l[3]:
            s = s[:-6]
        else:
            if s == "":
                return "YES"
            else:
                return "NO"

print((main()))

import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI():
    return list(map(int, input().split()))

def I():
    return int(eval(input()))

def LS():
    return input().split()

def S():
    return eval(input())

def main():
    s = list(S())
    l = [
        ["d", "r", "e", "a", "m"],
        ["d", "r", "e", "a", "m", "e", "r"],
        ["e", "r", "a", "s", "e"],
        ["e", "r", "a", "s", "e", "r"],
    ]
    while True:
        if len(s) <= 4:
            break
        else:
            if l[0] == s[-5:]:
                [s.pop() for _ in " " * 5]
            elif l[1] == s[-7:]:
                [s.pop() for _ in " " * 7]
            elif l[2] == s[-5:]:
                [s.pop() for _ in " " * 5]
            elif l[3] == s[-6:]:
                [s.pop() for _ in " " * 6]
            else:
                return "NO"
    if len(s) == 0:
        return "YES"
    return "NO"

print((main()))

-    l = ["dream", "dreamer", "erase", "eraser"]


Input:
a, b = input().split()

c = int(a + b)

print(("Yes" if c ** 0.5 % 1 == 0 else "No"))

a, b = list(map(str, input().split()))

c = int(a + b)

if c ** 0.5 == int(c ** 0.5):

    print("Yes")

else:

    print("No")

a, b = input().split()
c = int(a + b)
print(("Yes" if c**0.5 % 1 == 0 else "No"))

a, b = list(map(str, input().split()))
c = int(a + b)
if c**0.5 == int(c**0.5):
    print("Yes")
else:
    print("No")


Input:
import sys

def solve():

    file_input = sys.stdin

    H, W = list(map(int, file_input.readline().split()))

    dp = [[0] * (W + 1)]

    for line in file_input:

        dp.append([0] + list(map(int, line.split())))

    max_width = 0

    for i in range(1, H + 1):

        for j in range(1, W + 1):

            if dp[i][j] == 1:

                dp[i][j] = 0

            else:

                dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1

                max_width = max(max_width, dp[i][j])

    print((max_width ** 2))

solve()

import sys

def solve():

    file_input = sys.stdin

    H, W = list(map(int, file_input.readline().split()))

    side_length = 0

    prev = [0] * (W + 1)

    for line in file_input:

        tile_line = list(map(int, line.split()))

        current = [0] * (W + 1)

        for i, tpl in enumerate(zip(tile_line, prev, prev[1:]), start=1):

            t, p1, p2 = tpl

            if t:

                current[i] = 0

            else:

                current[i] = min(p1, p2, current[i - 1]) + 1

        prev = current

        side_length = max(side_length, max(current))

    print((side_length ** 2))

solve()

import sys

def solve():
    file_input = sys.stdin
    H, W = list(map(int, file_input.readline().split()))
    dp = [[0] * (W + 1)]
    for line in file_input:
        dp.append([0] + list(map(int, line.split())))
    max_width = 0
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if dp[i][j] == 1:
                dp[i][j] = 0
            else:
                dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
                max_width = max(max_width, dp[i][j])
    print((max_width**2))

solve()

import sys

def solve():
    file_input = sys.stdin
    H, W = list(map(int, file_input.readline().split()))
    side_length = 0
    prev = [0] * (W + 1)
    for line in file_input:
        tile_line = list(map(int, line.split()))
        current = [0] * (W + 1)
        for i, tpl in enumerate(zip(tile_line, prev, prev[1:]), start=1):
            t, p1, p2 = tpl
            if t:
                current[i] = 0
            else:
                current[i] = min(p1, p2, current[i - 1]) + 1
        prev = current
        side_length = max(side_length, max(current))
    print((side_length**2))

solve()

-        dp.append([0] + list(map(int, line.split())))

+        tile_line = list(map(int, line.split()))

+        for i, tpl in enumerate(zip(tile_line, prev, prev[1:]), start=1):

-                max_width = max(max_width, dp[i][j])

+                current[i] = min(p1, p2, current[i - 1]) + 1

+        side_length = max(side_length, max(current))


Input:
def main():

    a = eval(input())

    if a in ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']:

        print('A')

    else:

        print('a')

if __name__ == "__main__":

    main()

def main():

    s = eval(input())

    ko = [i for i in range(ord('a'),ord('z')+1)]

    if ord(s) in ko:

        print('a')

    else:

        print('A')

if __name__ == "__main__":

    main()

def main():
    s = eval(input())
    ko = [i for i in range(ord("a"), ord("z") + 1)]
    if ord(s) in ko:
        print("a")
    else:
        print("A")

if __name__ == "__main__":
    main()

+    ko = [i for i in range(ord("a"), ord("z") + 1)]


Input: from functools import*;_,a=open(0);print(('YNeos'[reduce(lambda x,y:x^y,list(map(int,a.split())))>0::2]))

_,a=open(0);a,*b=list(map(int,a.split()))

for b in b:a^=b

print(('YNeos'[a>0::2]))

from functools import *

_, a = open(0)
print(("YNeos"[reduce(lambda x, y: x ^ y, list(map(int, a.split()))) > 0 :: 2]))

_, a = open(0)
a, *b = list(map(int, a.split()))
for b in b:
    a ^= b
print(("YNeos"[a > 0 :: 2]))

-print(("YNeos"[reduce(lambda x, y: x ^ y, list(map(int, a.split()))) > 0 :: 2]))


Input:
# UnionFind

import sys

sys.setrecursionlimit(10**9)

class UnionFind:

  def __init__(self, n):

    self.n = [-1]*n

    self.r = [0]*n

    self.siz = n

  def find_root(self, x):

    if self.n[x] < 0:

      return x

    else:

      self.n[x] = self.find_root(self.n[x])

      return self.n[x]

  def unite(self, x, y):

    x = self.find_root(x)

    y = self.find_root(y)

    if x == y:

      return

    elif self.r[x] > self.r[y]:

      self.n[x] += self.n[y]

      self.n[y] = x

    else:

      self.n[y] += self.n[x]

      self.n[x] = y

      if self.r[x] == self.r[y]:

        self.r[y] += 1

    self.siz -= 1

  def root_same(self, x, y):

    return self.find_root(x) == self.find_root(y)

  def count(self, x):

    return -self.n[self.find_root(x)]

  def size(self):

    return self.siz

n,q=list(map(int,input().split()))

uf=UnionFind(n)

for _ in range(q):

  t,u,v=list(map(int,input().split()))

  if t==0:

    uf.unite(u,v)

  else:

    print((uf.root_same(u,v)+0))

# UnionFind

import sys

def input(): return sys.stdin.readline().rstrip()

sys.setrecursionlimit(10**9)

class UnionFind:

  def __init__(self, n):

    self.n = [-1]*n

    self.r = [0]*n

    self.siz = n

  def find_root(self, x):

    if self.n[x] < 0:

      return x

    else:

      self.n[x] = self.find_root(self.n[x])

      return self.n[x]

  def unite(self, x, y):

    x = self.find_root(x)

    y = self.find_root(y)

    if x == y:

      return

    elif self.r[x] > self.r[y]:

      self.n[x] += self.n[y]

      self.n[y] = x

    else:

      self.n[y] += self.n[x]

      self.n[x] = y

      if self.r[x] == self.r[y]:

        self.r[y] += 1

    self.siz -= 1

  def root_same(self, x, y):

    return self.find_root(x) == self.find_root(y)

  def count(self, x):

    return -self.n[self.find_root(x)]

  def size(self):

    return self.siz

n,q=list(map(int,input().split()))

uf=UnionFind(n)

for _ in range(q):

  t,u,v=list(map(int,input().split()))

  if t==0:

    uf.unite(u,v)

  else:

    print((uf.root_same(u,v)+0))

# UnionFind
import sys

sys.setrecursionlimit(10**9)

class UnionFind:
    def __init__(self, n):
        self.n = [-1] * n
        self.r = [0] * n
        self.siz = n

    def find_root(self, x):
        if self.n[x] < 0:
            return x
        else:
            self.n[x] = self.find_root(self.n[x])
            return self.n[x]

    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.r[x] > self.r[y]:
            self.n[x] += self.n[y]
            self.n[y] = x
        else:
            self.n[y] += self.n[x]
            self.n[x] = y
            if self.r[x] == self.r[y]:
                self.r[y] += 1
        self.siz -= 1

    def root_same(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.n[self.find_root(x)]

    def size(self):
        return self.siz

n, q = list(map(int, input().split()))
uf = UnionFind(n)
for _ in range(q):
    t, u, v = list(map(int, input().split()))
    if t == 0:
        uf.unite(u, v)
    else:
        print((uf.root_same(u, v) + 0))

# UnionFind
import sys

def input():
    return sys.stdin.readline().rstrip()

sys.setrecursionlimit(10**9)

class UnionFind:
    def __init__(self, n):
        self.n = [-1] * n
        self.r = [0] * n
        self.siz = n

    def find_root(self, x):
        if self.n[x] < 0:
            return x
        else:
            self.n[x] = self.find_root(self.n[x])
            return self.n[x]

    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.r[x] > self.r[y]:
            self.n[x] += self.n[y]
            self.n[y] = x
        else:
            self.n[y] += self.n[x]
            self.n[x] = y
            if self.r[x] == self.r[y]:
                self.r[y] += 1
        self.siz -= 1

    def root_same(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.n[self.find_root(x)]

    def size(self):
        return self.siz

n, q = list(map(int, input().split()))
uf = UnionFind(n)
for _ in range(q):
    t, u, v = list(map(int, input().split()))
    if t == 0:
        uf.unite(u, v)
    else:
        print((uf.root_same(u, v) + 0))

+    return sys.stdin.readline().rstrip()


Input:
n, m = list(map(int, input().split()))

l = [tuple(map(int, input().split())) for i in range(m)]

c = [[] for _ in range(n+1)]

for x in l:

    c[x[0]].append(x[1])

    c[x[1]].append(x[0])

if set(c[1])&set(c[n]):

    print("POSSIBLE")

else:

    print("IMPOSSIBLE")

import sys

readline = sys.stdin.buffer.readline

ni = lambda: int(readline().rstrip())

nm = lambda: list(map(int, readline().split()))

nl = lambda: list(map(int, readline().split()))

def solve():

    n, m = nm()

    G = [list() for _ in range(n)]

    for _ in range(m):

        u, v = nm()

        u -= 1; v -= 1

        G[u].append(v)

        G[v].append(u)

    if (set(G[0]) & set(G[n-1])):

        print('POSSIBLE')

    else:

        print('IMPOSSIBLE')

    return

solve()

# T = ni()

# for _ in range(T):

#     solve()

n, m = list(map(int, input().split()))
l = [tuple(map(int, input().split())) for i in range(m)]
c = [[] for _ in range(n + 1)]
for x in l:
    c[x[0]].append(x[1])
    c[x[1]].append(x[0])
if set(c[1]) & set(c[n]):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

import sys

readline = sys.stdin.buffer.readline
ni = lambda: int(readline().rstrip())
nm = lambda: list(map(int, readline().split()))
nl = lambda: list(map(int, readline().split()))

def solve():
    n, m = nm()
    G = [list() for _ in range(n)]
    for _ in range(m):
        u, v = nm()
        u -= 1
        v -= 1
        G[u].append(v)
        G[v].append(u)
    if set(G[0]) & set(G[n - 1]):
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    return

solve()
# T = ni()
# for _ in range(T):
#     solve()

-l = [tuple(map(int, input().split())) for i in range(m)]

+nm = lambda: list(map(int, readline().split()))

+nl = lambda: list(map(int, readline().split()))


Input:
N = int(eval(input()))

S = eval(input())

mod = 7 + 10 ** 9

word = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"\

    ,"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y","z"]

count = [1] * 26

for i in range(N):

    count[word.index(S[i])] += 1

Total = 1

for c in count:

    Total *= c

    Total %= mod

print((Total - 1))

import sys

class alphabet: #Trueなら大文字

    def __init__(self, capitalize):

        self.num = dict()

        self.index = dict()

        self.abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"\

            ,"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

        if capitalize:

            for i in range(26): self.abc[i] = self.abc[i].upper()

        for i, a in enumerate(self.abc):

            self.num[a] = i

            self.index[i] = a

def solve():

    input = sys.stdin.readline

    N = int(eval(input()))

    S = input().strip("\n")

    AB = alphabet(False)

    Count = [1] * 26

    for i in range(len(S)):

        Count[AB.num[S[i]]] += 1

    mod = 7 + 10 ** 9

    Ans = 1

    for i, n in enumerate(Count):

        Ans *= n

        Ans %= mod

    print(((Ans - 1 + mod) % mod))

    return 0

if __name__ == "__main__":

    solve()

import sys

class alphabet:  # Trueなら大文字
    def __init__(self, capitalize):
        self.num = dict()
        self.index = dict()
        self.abc = [
            "a",
            "b",
            "c",
            "d",
            "e",
            "f",
            "g",
            "h",
            "i",
            "j",
            "k",
            "l",
            "m",
            "n",
            "o",
            "p",
            "q",
            "r",
            "s",
            "t",
            "u",
            "v",
            "w",
            "x",
            "y",
            "z",
        ]
        if capitalize:
            for i in range(26):
                self.abc[i] = self.abc[i].upper()
        for i, a in enumerate(self.abc):
            self.num[a] = i
            self.index[i] = a

def solve():
    input = sys.stdin.readline
    N = int(eval(input()))
    S = input().strip("\n")
    AB = alphabet(False)
    Count = [1] * 26
    for i in range(len(S)):
        Count[AB.num[S[i]]] += 1
    mod = 7 + 10**9
    Ans = 1
    for i, n in enumerate(Count):
        Ans *= n
        Ans %= mod
    print(((Ans - 1 + mod) % mod))
    return 0

if __name__ == "__main__":
    solve()

+                self.abc[i] = self.abc[i].upper()

+        for i, a in enumerate(self.abc):


Input:
from collections import deque

import itertools

from scipy.sparse.csgraph import floyd_warshall as wf

import sys

input = sys.stdin.readline

MAX = 1e9

def main():

    N, M, R = list(map(int, input().split()))

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

    link = [[MAX if j != i else 0 for j in range(N+1)] for i in range(N+1)]

    for i in range(M):

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

        link[a][b] = c

        link[b][a] = c

    link = wf(link)

    ans = MAX

    for per in list(itertools.permutations(r)):

        tmp = 0

        for i in range(R-1):

            tmp += link[per[i]][per[i+1]]

        ans = min(ans, tmp)

    print((int(ans)))

if __name__ == "__main__":

    main()

from scipy.sparse.csgraph import floyd_warshall as wf

from itertools import permutations

import sys

input = sys.stdin.readline

def main():

    N, M, R = list(map(int, input().split()))

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

    MAX = int(1e9)

    link = [[MAX if i != j else 0 for j in range(N)] for i in range(N)]

    for i in range(M):

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

        a -= 1

        b -= 1

        link[a][b] = c

        link[b][a] = c

    link = wf(link)

    ans = -1

    for t in permutations(r):

        tmp = 0

        for i in range(1, R):

            tmp += link[t[i-1]-1][t[i]-1]

        if ans == -1:

            ans = tmp

        else:

            ans = min(ans, tmp)

    print((int(ans)))

if __name__ == "__main__":

    main()

from collections import deque
import itertools
from scipy.sparse.csgraph import floyd_warshall as wf
import sys

input = sys.stdin.readline
MAX = 1e9

def main():
    N, M, R = list(map(int, input().split()))
    r = list(map(int, input().split()))
    link = [[MAX if j != i else 0 for j in range(N + 1)] for i in range(N + 1)]
    for i in range(M):
        a, b, c = list(map(int, input().split()))
        link[a][b] = c
        link[b][a] = c
    link = wf(link)
    ans = MAX
    for per in list(itertools.permutations(r)):
        tmp = 0
        for i in range(R - 1):
            tmp += link[per[i]][per[i + 1]]
        ans = min(ans, tmp)
    print((int(ans)))

if __name__ == "__main__":
    main()

from scipy.sparse.csgraph import floyd_warshall as wf
from itertools import permutations
import sys

input = sys.stdin.readline

def main():
    N, M, R = list(map(int, input().split()))
    r = list(map(int, input().split()))
    MAX = int(1e9)
    link = [[MAX if i != j else 0 for j in range(N)] for i in range(N)]
    for i in range(M):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        link[a][b] = c
        link[b][a] = c
    link = wf(link)
    ans = -1
    for t in permutations(r):
        tmp = 0
        for i in range(1, R):
            tmp += link[t[i - 1] - 1][t[i] - 1]
        if ans == -1:
            ans = tmp
        else:
            ans = min(ans, tmp)
    print((int(ans)))

if __name__ == "__main__":
    main()

-    link = [[MAX if j != i else 0 for j in range(N + 1)] for i in range(N + 1)]

+    link = [[MAX if i != j else 0 for j in range(N)] for i in range(N)]

-    for per in list(itertools.permutations(r)):

-            tmp += link[per[i]][per[i + 1]]


Input:
import sys

input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)

#from functools import lru_cache

def RD(): return input().rstrip().decode()

def II(): return int(eval(input()))

def FI(): return float(eval(input()))

def MI(): return list(map(int,input().split()))

def MF(): return list(map(float,input().split()))

def LI(): return list(map(int,input().split()))

def LF(): return list(map(float,input().split()))

def TI(): return tuple(map(int,input().split()))

# rstrip().decode()

def main():

	nn=II()

	A=LI()

	ans="pairwise coprime"

	n = 500005

	primes = set(range(2, n+1))

	for i in range(2, int(n**0.5+1)):

		primes.difference_update(list(range(i*2, n+1, i)))

	primes=set(primes)

	#print(primes)

	B=set(range(1,5*10**5+5))

	C=set()

	for i in A:

		a=set()

		while i%2==0:

			a.add(2)

			i//=2

		f=3

		while f*f<=i:

			if i in primes:

				break

			elif i%f==0:

				a.add(f)

				i//=f

			else:

				f+=2

		if i!=1:

			a.add(i)

		B&=a

		if C&a:

			ans="setwise coprime"

		C|=a

	if B:

		ans="not coprime"

	print(ans)

if __name__ == "__main__":

	main()

import sys

input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)

#from functools import lru_cache

def RD(): return input().rstrip().decode()

def II(): return int(eval(input()))

def FI(): return float(eval(input()))

def MI(): return list(map(int,input().split()))

def MF(): return list(map(float,input().split()))

def LI(): return list(map(int,input().split()))

def LF(): return list(map(float,input().split()))

def TI(): return tuple(map(int,input().split()))

# rstrip().decode()

def main():

	nn=II()

	A=LI()

	ans="pairwise coprime"

	n = 333335

	primes = set(range(2, n+1))

	for i in range(2, int(n**0.5+1)):

		primes.difference_update(list(range(i*2, n+1, i)))

	primes=set(primes)

	#print(primes)

	B=set(range(1,333335))

	C=set()

	for i in A:

		a=set()

		while i%2==0:

			a.add(2)

			i//=2

		f=3

		while f*f<=i:

			if i in primes:

				break

			elif i%f==0:

				a.add(f)

				i//=f

			else:

				f+=2

		if i!=1:

			a.add(i)

		B&=a

		if C&a:

			ans="setwise coprime"

		C|=a

	if B:

		ans="not coprime"

	print(ans)

if __name__ == "__main__":

	main()

import sys

input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**9)
# from functools import lru_cache
def RD():
    return input().rstrip().decode()

def II():
    return int(eval(input()))

def FI():
    return float(eval(input()))

def MI():
    return list(map(int, input().split()))

def MF():
    return list(map(float, input().split()))

def LI():
    return list(map(int, input().split()))

def LF():
    return list(map(float, input().split()))

def TI():
    return tuple(map(int, input().split()))

# rstrip().decode()
def main():
    nn = II()
    A = LI()
    ans = "pairwise coprime"
    n = 500005
    primes = set(range(2, n + 1))
    for i in range(2, int(n**0.5 + 1)):
        primes.difference_update(list(range(i * 2, n + 1, i)))
    primes = set(primes)
    # print(primes)
    B = set(range(1, 5 * 10**5 + 5))
    C = set()
    for i in A:
        a = set()
        while i % 2 == 0:
            a.add(2)
            i //= 2
        f = 3
        while f * f <= i:
            if i in primes:
                break
            elif i % f == 0:
                a.add(f)
                i //= f
            else:
                f += 2
        if i != 1:
            a.add(i)
        B &= a
        if C & a:
            ans = "setwise coprime"
        C |= a
    if B:
        ans = "not coprime"
    print(ans)

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**9)
# from functools import lru_cache
def RD():
    return input().rstrip().decode()

def II():
    return int(eval(input()))

def FI():
    return float(eval(input()))

def MI():
    return list(map(int, input().split()))

def MF():
    return list(map(float, input().split()))

def LI():
    return list(map(int, input().split()))

def LF():
    return list(map(float, input().split()))

def TI():
    return tuple(map(int, input().split()))

# rstrip().decode()
def main():
    nn = II()
    A = LI()
    ans = "pairwise coprime"
    n = 333335
    primes = set(range(2, n + 1))
    for i in range(2, int(n**0.5 + 1)):
        primes.difference_update(list(range(i * 2, n + 1, i)))
    primes = set(primes)
    # print(primes)
    B = set(range(1, 333335))
    C = set()
    for i in A:
        a = set()
        while i % 2 == 0:
            a.add(2)
            i //= 2
        f = 3
        while f * f <= i:
            if i in primes:
                break
            elif i % f == 0:
                a.add(f)
                i //= f
            else:
                f += 2
        if i != 1:
            a.add(i)
        B &= a
        if C & a:
            ans = "setwise coprime"
        C |= a
    if B:
        ans = "not coprime"
    print(ans)

if __name__ == "__main__":
    main()


Input: print(((51,1,4,1,4,5,2,2,15,1,2,2,5,1,5,1,14,1,2,1,5,1,2,2,5,1,2,1,2,1,1,1)[-int(eval(input()))]))

print((ord(' 3    '[int(eval(input()))%14])))

print((ord(" 3    "[int(eval(input())) % 14])))


Input:
import sys

def solve():

    person = 0

    for i in range(0,H):

        for j in range(0,W):

            if geo[i][j] is not "_":

                search(i,j)

                person += 1

    print(person)

def search(i,j):

    temp = geo[i][j]

    geo[i][j] = "_"

    for a in range(0,4):

        idx, jdy = i + dx[a], j + dy[a]

        if(isOnMap(idx, jdy)):

            if(isNeededToSolve(temp, idx, jdy)):

                search(idx,jdy)

def isOnMap(i,j): return (0<=i and 0<=j and i<H and j<W)

def isNeededToSolve(temp,i,j):

    target = geo[i][j]

    return (target is not "_" and temp is target)

limit = 10**7

sys.setrecursionlimit(limit)

H, W, tempH = -1, -1, 0

dx = [-1,0,1,0]

dy = [0,-1,0,1]

geo = [[0 for i in range(1)]for j in range(1)]

while True:

    line = eval(input())

    if H is -1 and W is -1:

        p = line.split(" ")

        H, W = int(p[0]), int(p[1])

        geo = [[0 for i in range(W)] for j in range(H)]

    else:

        geo[tempH] = list(line)

        tempH+=1

    if H is 0 and W is 0:break

    if tempH is H:

        solve()

        H, W, tempH = -1, -1, 0

# -*- coding:utf-8 -*-

import sys

def dfs(x, y, sym):

	tile[x][y] = "."

	for i in range(len(DX)):

		nx = x + DX[i]

		ny = y + DY[i]

		if (0<=nx and nx<N and 0<=ny and ny<M and tile[nx][ny] is sym):

			dfs(nx, ny, sym)

def solve():

	res = 0

	for i in range(N):

		for j in range(M):

			sym = tile[i][j]

			if tile[i][j] != ".":

				if tile[i][j] is sym:

					dfs(i, j, sym)

					res += 1

	print(res)

counter=0

DX = [-1,0,1,0]

DY = [0,-1,0,1]

sys.setrecursionlimit(10**7)

while True:

	line = eval(input())

	if " " in line:

		nums = line.split(" ")

		N = int(nums[0])

		M = int(nums[1])

		tile = [[0 for i in range(M)] for j in range(N)]

	else:

		tile[counter-1] = list(line)

	if N is 0 and M is 0:

		break

	counter += 1

	if counter-1 is N:

		solve()

		counter = 0

import sys

def solve():
    person = 0
    for i in range(0, H):
        for j in range(0, W):
            if geo[i][j] is not "_":
                search(i, j)
                person += 1
    print(person)

def search(i, j):
    temp = geo[i][j]
    geo[i][j] = "_"
    for a in range(0, 4):
        idx, jdy = i + dx[a], j + dy[a]
        if isOnMap(idx, jdy):
            if isNeededToSolve(temp, idx, jdy):
                search(idx, jdy)

def isOnMap(i, j):
    return 0 <= i and 0 <= j and i < H and j < W

def isNeededToSolve(temp, i, j):
    target = geo[i][j]
    return target is not "_" and temp is target

limit = 10**7
sys.setrecursionlimit(limit)
H, W, tempH = -1, -1, 0
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
geo = [[0 for i in range(1)] for j in range(1)]
while True:
    line = eval(input())
    if H is -1 and W is -1:
        p = line.split(" ")
        H, W = int(p[0]), int(p[1])
        geo = [[0 for i in range(W)] for j in range(H)]
    else:
        geo[tempH] = list(line)
        tempH += 1
    if H is 0 and W is 0:
        break
    if tempH is H:
        solve()
        H, W, tempH = -1, -1, 0

# -*- coding:utf-8 -*-
import sys

def dfs(x, y, sym):
    tile[x][y] = "."
    for i in range(len(DX)):
        nx = x + DX[i]
        ny = y + DY[i]
        if 0 <= nx and nx < N and 0 <= ny and ny < M and tile[nx][ny] is sym:
            dfs(nx, ny, sym)

def solve():
    res = 0
    for i in range(N):
        for j in range(M):
            sym = tile[i][j]
            if tile[i][j] != ".":
                if tile[i][j] is sym:
                    dfs(i, j, sym)
                    res += 1
    print(res)

counter = 0
DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]
sys.setrecursionlimit(10**7)
while True:
    line = eval(input())
    if " " in line:
        nums = line.split(" ")
        N = int(nums[0])
        M = int(nums[1])
        tile = [[0 for i in range(M)] for j in range(N)]
    else:
        tile[counter - 1] = list(line)
    if N is 0 and M is 0:
        break
    counter += 1
    if counter - 1 is N:
        solve()
        counter = 0

+        if 0 <= nx and nx < N and 0 <= ny and ny < M and tile[nx][ny] is sym:

-        idx, jdy = i + dx[a], j + dy[a]

-            if isNeededToSolve(temp, idx, jdy):

-    return 0 <= i and 0 <= j and i < H and j < W

-    return target is not "_" and temp is target

-geo = [[0 for i in range(1)] for j in range(1)]

-        geo = [[0 for i in range(W)] for j in range(H)]

+        tile = [[0 for i in range(M)] for j in range(N)]


Input:
#!/usr/bin/env python

n = int(eval(input()))

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

a = sorted(a)

ma = a[-1]

dup = [0 for _ in range(ma+1)]

div = [0 for _ in range(ma+1)]

for i in range(n):

    dup[a[i]] += 1

#print('dup =', dup)

for i in range(n):

    for j in range(a[i], ma+1, a[i]):

        div[j] += 1

#print('div =', div)

ans = 0

for i in range(n):

    if div[a[i]] == 1:

        ans += 1

print(ans)

#!/usr/bin/env python

n = int(eval(input()))

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

a = sorted(a)

ma = a[-1]

div = [0 for _ in range(ma+1)]

for i in range(n):

    for j in range(a[i], ma+1, a[i]):

        div[j] += 1

ans = 0

for i in range(n):

    if div[a[i]] == 1:

        ans += 1

print(ans)

#!/usr/bin/env python
n = int(eval(input()))
a = list(map(int, input().split()))
a = sorted(a)
ma = a[-1]
dup = [0 for _ in range(ma + 1)]
div = [0 for _ in range(ma + 1)]
for i in range(n):
    dup[a[i]] += 1
# print('dup =', dup)
for i in range(n):
    for j in range(a[i], ma + 1, a[i]):
        div[j] += 1
# print('div =', div)
ans = 0
for i in range(n):
    if div[a[i]] == 1:
        ans += 1
print(ans)

#!/usr/bin/env python
n = int(eval(input()))
a = list(map(int, input().split()))
a = sorted(a)
ma = a[-1]
div = [0 for _ in range(ma + 1)]
for i in range(n):
    for j in range(a[i], ma + 1, a[i]):
        div[j] += 1
ans = 0
for i in range(n):
    if div[a[i]] == 1:
        ans += 1
print(ans)

-dup = [0 for _ in range(ma + 1)]
-for i in range(n):
-    dup[a[i]] += 1
-# print('dup =', dup)
-# print('div =', div)


Input:
ri = lambda: int(input())

rl = lambda: list(map(int,input().split()))

rr = lambda N: [ri() for _ in range(N)]

YN = lambda b: print('YES') if b else print('NO')

yn = lambda b: print('Yes') if b else print('No')

OE = lambda x: print('Odd') if x%2 else print('Even')

INF = 10**18

N=ri()

W=[0]*N

ans = 1

for i in range(N):

    W[i] = input()

    if i != 0 and W[i-1][-1] != W[i][0]:

        ans = 0

import collections

Wc = collections.Counter(W).most_common()

if Wc[0][1] != 1:

    ans = 0

yn(ans)

ri = lambda: int(input())

rl = lambda: list(map(int,input().split()))

rr = lambda N: [ri() for _ in range(N)]

YN = lambda b: print('YES') if b else print('NO')

yn = lambda b: print('Yes') if b else print('No')

OE = lambda x: print('Odd') if x%2 else print('Even')

INF = 10**18

N=ri()

W=[0]*N

ans = 1

for i in range(N):

    W[i] = input()

    if ans == 1 and i != 0 and W[i-1][-1] != W[i][0]:

        ans = 0

if ans == 1 and len(set(W)) != N:

    ans = 0

yn(ans)

ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print("YES") if b else print("NO")
yn = lambda b: print("Yes") if b else print("No")
OE = lambda x: print("Odd") if x % 2 else print("Even")
INF = 10**18
N = ri()
W = [0] * N
ans = 1
for i in range(N):
    W[i] = input()
    if i != 0 and W[i - 1][-1] != W[i][0]:
        ans = 0
import collections

Wc = collections.Counter(W).most_common()
if Wc[0][1] != 1:
    ans = 0
yn(ans)

ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print("YES") if b else print("NO")
yn = lambda b: print("Yes") if b else print("No")
OE = lambda x: print("Odd") if x % 2 else print("Even")
INF = 10**18
N = ri()
W = [0] * N
ans = 1
for i in range(N):
    W[i] = input()
    if ans == 1 and i != 0 and W[i - 1][-1] != W[i][0]:
        ans = 0
if ans == 1 and len(set(W)) != N:
    ans = 0
yn(ans)


Input:
from itertools import accumulate

from bisect import bisect

def main():

    n, m, k = list(map(int, input().split()))

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

    b = tuple(map(int, input().split()))

    aa = tuple(accumulate(a))

    ba = tuple(accumulate(b))

    r = 0

    for i1 in range(n):

        if aa[i1] > k:

            break

        else:

            t = bisect(ba, k - aa[i1])

            r = max(r, i1 + 1 + t)

    for j1 in range(m):

        if ba[j1] > k:

            break

        else:

            t = bisect(aa, k - ba[j1])

            r = max(r, j1 + 1 + t)

    print(r)

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read

readlines = sys.stdin.readlines

from itertools import accumulate

from bisect import bisect

def main():

    n, m, k = list(map(int, input().split()))

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

    b = tuple(map(int, input().split()))

    aa = [0] + list(accumulate(a))

    ba = [0] + list(accumulate(b))

    r = 0

    for i1, aae in enumerate(aa):

        if aae > k:

            break

        else:

            time_remain = k - aae

            b_num = bisect(ba, time_remain)

            r = max(r, i1 + b_num - 1)

    print(r)

if __name__ == '__main__':

    main()

from itertools import accumulate
from bisect import bisect

def main():
    n, m, k = list(map(int, input().split()))
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))
    aa = tuple(accumulate(a))
    ba = tuple(accumulate(b))
    r = 0
    for i1 in range(n):
        if aa[i1] > k:
            break
        else:
            t = bisect(ba, k - aa[i1])
            r = max(r, i1 + 1 + t)
    for j1 in range(m):
        if ba[j1] > k:
            break
        else:
            t = bisect(aa, k - ba[j1])
            r = max(r, j1 + 1 + t)
    print(r)

if __name__ == "__main__":
    main()

import sys

read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect

def main():
    n, m, k = list(map(int, input().split()))
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))
    aa = [0] + list(accumulate(a))
    ba = [0] + list(accumulate(b))
    r = 0
    for i1, aae in enumerate(aa):
        if aae > k:
            break
        else:
            time_remain = k - aae
            b_num = bisect(ba, time_remain)
            r = max(r, i1 + b_num - 1)
    print(r)

if __name__ == "__main__":
    main()

+            b_num = bisect(ba, time_remain)


Input:
import sys

from collections import deque

import numpy as np

import math

sys.setrecursionlimit(10**6)

def S(): return sys.stdin.readline().rstrip()

def SL(): return list(map(str,sys.stdin.readline().rstrip().split()))

def I(): return int(sys.stdin.readline().rstrip())

def IL(): return list(map(int,sys.stdin.readline().rstrip().split()))

if __name__=='__main__':

    n = I()

    c = list(S())

    i,j = 0,n-1

    ans = 0

    while i<j:

        while c[i]=='R':

            i += 1

            if i==n-1:

                break

        while c[j]=='W':

            j -= 1

            if j==0:

                break

        if i<j:

            c[i],c[j] = c[j],c[i]

            i += 1

            j -= 1

            ans += 1

    print(ans)

    exit()

import sys

def S(): return sys.stdin.readline().rstrip()

def I(): return int(sys.stdin.readline().rstrip())

if __name__=='__main__':

    n = I()

    c = list(S())

    i,j = 0,n-1

    ans = 0

    while i<j:

        while c[i]=='R':

            i += 1

            if i==n:

                break

        while c[j]=='W':

            j -= 1

            if j==-1:

                break

        if i<j:

            c[i],c[j] = c[j],c[i]

            i += 1

            j -= 1

            ans += 1

    print(ans)

    exit()

import sys
from collections import deque
import numpy as np
import math

sys.setrecursionlimit(10**6)

def S():
    return sys.stdin.readline().rstrip()

def SL():
    return list(map(str, sys.stdin.readline().rstrip().split()))

def I():
    return int(sys.stdin.readline().rstrip())

def IL():
    return list(map(int, sys.stdin.readline().rstrip().split()))

if __name__ == "__main__":
    n = I()
    c = list(S())
    i, j = 0, n - 1
    ans = 0
    while i < j:
        while c[i] == "R":
            i += 1
            if i == n - 1:
                break
        while c[j] == "W":
            j -= 1
            if j == 0:
                break
        if i < j:
            c[i], c[j] = c[j], c[i]
            i += 1
            j -= 1
            ans += 1
    print(ans)
    exit()

import sys

def S():
    return sys.stdin.readline().rstrip()

def I():
    return int(sys.stdin.readline().rstrip())

if __name__ == "__main__":
    n = I()
    c = list(S())
    i, j = 0, n - 1
    ans = 0
    while i < j:
        while c[i] == "R":
            i += 1
            if i == n:
                break
        while c[j] == "W":
            j -= 1
            if j == -1:
                break
        if i < j:
            c[i], c[j] = c[j], c[i]
            i += 1
            j -= 1
            ans += 1
    print(ans)
    exit()

-    return list(map(str, sys.stdin.readline().rstrip().split()))

-    return list(map(int, sys.stdin.readline().rstrip().split()))


Input:
n = int(eval(input()))

a = [int(eval(input())) for i in range(n)]

Amax = max(a)

Amax2 = sorted(a)[-2]

for i in range(n):

    if Amax > a[i]:

        print(Amax)

    else:

        print(Amax2)

n =  int(eval(input()))

A = []

for i in range(n):

    A.append(int(eval(input())))

ma = max(A)

ma2 = sorted(A)[-2]

for a in A:

    if a == ma:

        print(ma2)

    else:

        print(ma)

-a = [int(eval(input())) for i in range(n)]


Input:
n,*l=list(map(int,open(0).read().split()))

t=0

for i in l:

  if i<t: print('No'); break

  if i>t: i-=1

  t=i

else: print('Yes')

n,*l=list(map(int,open(0).read().split()))

t=0

for i in l:

  if i<t: print('No'); exit()

  if i>t: t=i-1

print('Yes')

n, *l = list(map(int, open(0).read().split()))
t = 0
for i in l:
    if i < t:
        print("No")
        break
    if i > t:
        i -= 1
    t = i
else:
    print("Yes")

n, *l = list(map(int, open(0).read().split()))
t = 0
for i in l:
    if i < t:
        print("No")
        exit()
    if i > t:
        t = i - 1
print("Yes")

-        break
+        exit()
-        i -= 1
-    t = i
-else:
-    print("Yes")
+        t = i - 1
+print("Yes")


Input:
from heapq import*

(n,m,s),*t=[list(map(int,t.split()))for t in open(0)]

*e,=eval('[],'*8**6)

for u,v,a,b in t[:m]:

    for i in range(2501-a):

        e[(i+a)*51+u]+=(b,i*51+v),

        e[(i+a)*51+v]+=(b,i*51+u),

for i,(c,d)in enumerate(t[m:],1):

    for j in range(2501-c):

        e[j*51+i]+=(d,(j+c)*51+i),

d=[10**18]*8**6

f=[1]*8**6

q=[(0,min(2500,s)*51+1)]

while q:

    c,v=heappop(q)

    if f[v]<1:continue

    d[v],f[v]=c,0

    for p,w in e[v]:

        if f[w]:heappush(q,(c+p,w))

for i in range(2,n+1):print((min(d[i::51])))

def main():

    from heapq import heappush,heappop

    (n,m,s),*t=[list(map(int,r.split()))for r in open(0)]

    e=[[]for _ in range(8**6)]

    for u,v,a,b in t[:m]:

        for i in range(2501-a):

            e[(i+a)*51+u]+=(b,i*51+v),

            e[(i+a)*51+v]+=(b,i*51+u),

    for i,(c,d)in enumerate(t[m:],1):

        for j in range(2501-c):

            e[j*51+i]+=(d,(j+c)*51+i),

    x=[10**18]*8**6

    f=[1]*8**6

    q=[(0,min(2500,s)*51+1)]

    while q:

        c,v=heappop(q)

        if f[v]<1:continue

        x[v],f[v]=c,0

        for p,w in e[v]:

            if f[w]:heappush(q,(c+p,w))

    for i in range(2,n+1):print((min(x[i::51])))

main()

def main():
    from heapq import heappush, heappop

    (n, m, s), *t = [list(map(int, r.split())) for r in open(0)]
    e = [[] for _ in range(8**6)]
    for u, v, a, b in t[:m]:
        for i in range(2501 - a):
            e[(i + a) * 51 + u] += ((b, i * 51 + v),)
            e[(i + a) * 51 + v] += ((b, i * 51 + u),)
    for i, (c, d) in enumerate(t[m:], 1):
        for j in range(2501 - c):
            e[j * 51 + i] += ((d, (j + c) * 51 + i),)
    x = [10**18] * 8**6
    f = [1] * 8**6
    q = [(0, min(2500, s) * 51 + 1)]
    while q:
        c, v = heappop(q)
        if f[v] < 1:
            continue
        x[v], f[v] = c, 0
        for p, w in e[v]:
            if f[w]:
                heappush(q, (c + p, w))
    for i in range(2, n + 1):
        print((min(x[i::51])))

main()

+    from heapq import heappush, heappop

-(n, m, s), *t = [list(map(int, t.split())) for t in open(0)]

+    (n, m, s), *t = [list(map(int, r.split())) for r in open(0)]

+    for i, (c, d) in enumerate(t[m:], 1):

+                heappush(q, (c + p, w))


Input:
s=eval(input())

a=b=0

for i in range(len(s)):

  if s[i]=='B':

    b+=1

  else:

    a+=b

print(a)

a=b=0

for s in eval(input()):

 if s>'B':a+=b

 else:b+=1

print(a)

s = eval(input())
a = b = 0
for i in range(len(s)):
    if s[i] == "B":
        b += 1
    else:
        a += b
print(a)

a = b = 0
for s in eval(input()):
    if s > "B":
        a += b
    else:
        b += 1
print(a)

-s = eval(input())
-for i in range(len(s)):
-    if s[i] == "B":
+for s in eval(input()):
+    if s > "B":
+        a += b
+    else:
-    else:
-        a += b


Input:
n = int(eval(input()))

if n%2 == 0:

  print((n//2-1))

else:

  print(((n+1)//2-1))

n = int(eval(input()))

if n%2 == 0:

    print((n//2-1))

else:

    print((n//2))

n = int(eval(input()))
if n % 2 == 0:
    print((n // 2 - 1))
else:
    print((n // 2))


Input:
d=[1]+[0]*12

for c in eval(input()):

 p=[0]*13

 for j in range(13):

  for k in range(10):t=(j*10+k)%13;p[t]+=d[j]*(c>'9'or k==int(c));p[t]%=10**9+7

 d=p

print((d[5]))


Input:
from collections import deque

def main():

    eval(input())

    A = list(enumerate(input().split()))

    size = len(A)

    b = deque()

    for i, a in A:

        if i % 2 == 0:

            if size % 2 == 0:

                b.append(a)

            else:

                b.appendleft(a)

        else:

            if size % 2 == 0:

                b.appendleft(a)

            else:

                b.append(a)

    print((" ".join(list(b))))

main()

from collections import deque

def main():

    eval(input())

    A = list(enumerate(input().split()))

    b = deque()

    (append1, append2) = (b.append, b.appendleft) if len(A) % 2 == 0 else (b.appendleft, b.append)

    for i, a in A:

        if i % 2 == 0:

            append1(a)

        else:

            append2(a)

    print((" ".join(list(b))))

main()

from collections import deque

def main():
    eval(input())
    A = list(enumerate(input().split()))
    b = deque()
    (append1, append2) = (
        (b.append, b.appendleft) if len(A) % 2 == 0 else (b.appendleft, b.append)
    )
    for i, a in A:
        if i % 2 == 0:
            append1(a)
        else:
            append2(a)
    print((" ".join(list(b))))

main()

+        (b.append, b.appendleft) if len(A) % 2 == 0 else (b.appendleft, b.append)


Input:
from numba import njit, b1, i4, i8, f8

import numpy as np

import sys

@njit((i8[:], i8), cache=True)

def sum(tree, i):

    s = 0

    while i > 0:

        s += tree[i]

        i -= i & -i

    return s

@njit((i8[:], i8, i8, i8), cache=True)

def add(tree, size,  i, x):

    while i <= size:

        tree[i] += x

        i += i & -i

@njit((i8[:], i8, i8), cache=True)

def range_sum(tree, l, r):

    return sum(tree, r) - sum(tree, l)

def main():

    n, q = list(map(int, sys.stdin.buffer.readline().split()))

    bit = np.array([0] + sys.stdin.buffer.readline().split(), np.int64)

    for i in range(1, n+1):

        if i + (i & -i) < n + 1:

            bit[i + (i & -i)] += bit[i]

    for y in sys.stdin.buffer.readlines():

        q, p, x = list(map(int, y.split()))

        if q:

            print((range_sum(bit, p, x)))

        else:

            add(bit, n, p+1, x)

if __name__ == "__main__":

    main()

import sys

def sum(tree, i):

    s = 0

    while i > 0:

        s += tree[i]

        i -= i & -i

    return s

def add(tree, size,  i, x):

    while i <= size:

        tree[i] += x

        i += i & -i

def range_sum(tree, l, r):

    return sum(tree, r) - sum(tree, l)

def main():

    n, q = list(map(int, sys.stdin.buffer.readline().split()))

    bit = [0] + list(map(int, sys.stdin.buffer.readline().split()))

    for i in range(1, n+1):

        if i + (i & -i) < n + 1:

            bit[i + (i & -i)] += bit[i]

    for y in sys.stdin.buffer.readlines():

        q, p, x = list(map(int, y.split()))

        if q:

            print((range_sum(bit, p, x)))

        else:

            add(bit,n, p+1, x)

if __name__ == "__main__":

    main()

from numba import njit, b1, i4, i8, f8
import numpy as np
import sys

@njit((i8[:], i8), cache=True)
def sum(tree, i):
    s = 0
    while i > 0:
        s += tree[i]
        i -= i & -i
    return s

@njit((i8[:], i8, i8, i8), cache=True)
def add(tree, size, i, x):
    while i <= size:
        tree[i] += x
        i += i & -i

@njit((i8[:], i8, i8), cache=True)
def range_sum(tree, l, r):
    return sum(tree, r) - sum(tree, l)

def main():
    n, q = list(map(int, sys.stdin.buffer.readline().split()))
    bit = np.array([0] + sys.stdin.buffer.readline().split(), np.int64)
    for i in range(1, n + 1):
        if i + (i & -i) < n + 1:
            bit[i + (i & -i)] += bit[i]
    for y in sys.stdin.buffer.readlines():
        q, p, x = list(map(int, y.split()))
        if q:
            print((range_sum(bit, p, x)))
        else:
            add(bit, n, p + 1, x)

if __name__ == "__main__":
    main()

import sys

def sum(tree, i):
    s = 0
    while i > 0:
        s += tree[i]
        i -= i & -i
    return s

def add(tree, size, i, x):
    while i <= size:
        tree[i] += x
        i += i & -i

def range_sum(tree, l, r):
    return sum(tree, r) - sum(tree, l)

def main():
    n, q = list(map(int, sys.stdin.buffer.readline().split()))
    bit = [0] + list(map(int, sys.stdin.buffer.readline().split()))
    for i in range(1, n + 1):
        if i + (i & -i) < n + 1:
            bit[i + (i & -i)] += bit[i]
    for y in sys.stdin.buffer.readlines():
        q, p, x = list(map(int, y.split()))
        if q:
            print((range_sum(bit, p, x)))
        else:
            add(bit, n, p + 1, x)

if __name__ == "__main__":
    main()

-    bit = np.array([0] + sys.stdin.buffer.readline().split(), np.int64)

+    bit = [0] + list(map(int, sys.stdin.buffer.readline().split()))


Input:
N, A, B = list(map(int, input().split()))

print((min(N * A, B)))

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

print((min(B, A*N)))

N, A, B = list(map(int, input().split()))
print((min(B, A * N)))

-print((min(N * A, B)))
+print((min(B, A * N)))


Input:
n = int(eval(input()))

A = [int(i) for i in input().split()]

B = []

for i in range(n):

    b = A[i] - ( i + 1)

    B.append(b)

B.sort()

ans = 0

for i in range(n):

    ans += abs(A[i] - (B[len(B) // 2] + i + 1))

print(ans)

n = int(eval(input()))

A = [int(i) for i in input().split()]

M = []

for i in range(n):

    M.append(A[i] - (i + 1))

M.sort()

b = M[len(M) // 2]

ans = 0

for i in range(n):

    ans += abs(A[i] - (b + i + 1))

print(ans)

n = int(eval(input()))
A = [int(i) for i in input().split()]
B = []
for i in range(n):
    b = A[i] - (i + 1)
    B.append(b)
B.sort()
ans = 0
for i in range(n):
    ans += abs(A[i] - (B[len(B) // 2] + i + 1))
print(ans)


Input:
from collections import defaultdict

n = int(eval(input()))

d = [int(eval(input())) for i in range(n)]

dict = defaultdict(int)

for i in d:

    dict[i] += 1

print((len(dict)))

n = int(eval(input()))

d = {int(eval(input())) for i in range(n)}

print((len(d)))

-d = [int(eval(input())) for i in range(n)]

+d = {int(eval(input())) for i in range(n)}


Input:
x, y, z, k = list(map(int, input().split()))

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

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

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

a.sort(reverse=True)

b.sort(reverse=True)

c.sort(reverse=True)

t = []

for i in range(x):

    for j in range(y):

        for l in range(z):

            if (i+1) * (j+1) * (l+1) <= k:

                t.append(a[i]+b[j]+c[l])

            else:

                break

t.sort(reverse=True)

for i in range(k):

    print((t[i]))

x, y, z, k = list(map(int, input().split()))

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

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

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

a.sort(reverse=True)

b.sort(reverse=True)

c.sort(reverse=True)

xl = set(range(x))

yl = set(range(y))

zl = set(range(z))

t = []

for i in xl:

    for j in yl:

        for l in zl:

            if (i+1) * (j+1) * (l+1) <= k:

                t.append(a[i]+b[j]+c[l])

            else:

                break

t.sort(reverse=True)

for i in range(k):

    print((t[i]))

x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
t = []
for i in range(x):
    for j in range(y):
        for l in range(z):
            if (i + 1) * (j + 1) * (l + 1) <= k:
                t.append(a[i] + b[j] + c[l])
            else:
                break
t.sort(reverse=True)
for i in range(k):
    print((t[i]))

x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
xl = set(range(x))
yl = set(range(y))
zl = set(range(z))
t = []
for i in xl:
    for j in yl:
        for l in zl:
            if (i + 1) * (j + 1) * (l + 1) <= k:
                t.append(a[i] + b[j] + c[l])
            else:
                break
t.sort(reverse=True)
for i in range(k):
    print((t[i]))

+xl = set(range(x))
+yl = set(range(y))
+zl = set(range(z))
-for i in range(x):
-    for j in range(y):
-        for l in range(z):
+for i in xl:
+    for j in yl:
+        for l in zl:


Input:
# 約数の列挙

#############################################################

def make_divisors(n):

    lower_divisors, upper_divisors = [], []

    i = 1

    while i * i <= n:

        if n % i == 0:

            lower_divisors.append(i)

            if i != n // i:

                upper_divisors.append(n // i)

        i += 1

    return lower_divisors + upper_divisors[::-1]

#############################################################

N, K = list(map(int, input().split()))

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

sum_A = sum(A)

div_list = make_divisors(sum_A)

ans = 1

# print(div_list)

for div in div_list:

    tmp = []

    for a in A:

        tmp.append(a % div)

    tmp.sort()

    cumsum1 = [0]

    cumsum2 = [0]

    for i in tmp:

        cumsum1.append(cumsum1[-1] + i)

        if i != 0:

            cumsum2.append(cumsum2[-1] + (div - i))

        else:

            cumsum2.append(cumsum2[-1])

    for i in range(1, N):

        if cumsum1[i] <= K and cumsum2[N] - cumsum2[i] <= K:

            ans = div

print(ans)

import sys

input = sys.stdin.readline

# 約数の列挙

#############################################################

def make_divisors(n):

    lower_divisors, upper_divisors = [], []

    i = 1

    while i * i <= n:

        if n % i == 0:

            lower_divisors.append(i)

            if i != n // i:

                upper_divisors.append(n // i)

        i += 1

    return lower_divisors + upper_divisors[::-1]

#############################################################

N, K = list(map(int, input().split()))

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

# 操作後も総和は変わらない

# 操作後にdivが公約数なら、divは総和の約数でもある

sum_A = sum(A)

div_list = make_divisors(sum_A)

ans = 1

for div in div_list:

    # divで割った余りのリストをソート

    # どこかを境に、左側は-1をして右側は+1をすると仮定する

    tmp = [a % div for a in A]

    tmp.sort()

    # 累積和

    cumsum1 = [0]

    cumsum2 = [0]

    for i in tmp:

        cumsum1.append(cumsum1[-1] + i)

        if i != 0:

            cumsum2.append(cumsum2[-1] + (div - i))

        else:

            cumsum2.append(cumsum2[-1])

    for i in range(1, N):

        cnt_minus = cumsum1[i]

        cnt_plus = cumsum2[N] - cumsum2[i]

        # 条件を満たす時、必ずどこかで等しくなる

        # （証明が理解できていないが、実験すると確かにそうなりそう）

        if cnt_minus == cnt_plus and cnt_minus <= K:

            ans = div

print(ans)

+# 操作後も総和は変わらない

+# 操作後にdivが公約数なら、divは総和の約数でもある

+    # divで割った余りのリストをソート

+    # どこかを境に、左側は-1をして右側は+1をすると仮定する

-        if cumsum1[i] <= K and cumsum2[N] - cumsum2[i] <= K:

+        cnt_plus = cumsum2[N] - cumsum2[i]

+        # 条件を満たす時、必ずどこかで等しくなる

+        # （証明が理解できていないが、実験すると確かにそうなりそう）

+        if cnt_minus == cnt_plus and cnt_minus <= K:


Input:
import sys

S = list(eval(input()))

v = S.pop(0)

for s in S:

    if s == v:

        print('Bad')

        sys.exit()

    v = s

print('Good')

S = eval(input())

if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:

    print('Bad')

else:

    print('Good')

import sys

S = list(eval(input()))
v = S.pop(0)
for s in S:
    if s == v:
        print("Bad")
        sys.exit()
    v = s
print("Good")

S = eval(input())
if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
    print("Bad")
else:
    print("Good")


Input:
N, K = list(map(int, input().split()))

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

h = sorted(h, reverse=True)

for i, h_i in enumerate(h):

  if h_i >= K:

    continue

  else:

    print(i)

    exit()

print(N)

import bisect

N, K = list(map(int, input().split()))

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

h = sorted(h)

print((N - bisect.bisect_left(h,K)))

import bisect

N, K = list(map(int, input().split()))
h = list(map(int, input().split()))
h = sorted(h)
print((N - bisect.bisect_left(h, K)))

+import bisect
+
-h = sorted(h, reverse=True)
-for i, h_i in enumerate(h):
-    if h_i >= K:
-        continue
-    else:
-        print(i)
-        exit()
-print(N)
+h = sorted(h)
+print((N - bisect.bisect_left(h, K)))


Input:
n = int(eval(input()))

ans = ''

for i in range(1, 99):

    if n <= 26 ** i:

        n -= 1

        for j in range(i):

            ans += chr(ord('a') + n%26)

            n //= 26

        break

    else:

        n -= 26 ** i

print((ans[::-1]))

n = int(eval(input()))

ans = ''

while n>0:

    n -= 1

    ans += chr(ord('a') + n%26)

    n //= 26

print((ans[::-1]))

n = int(eval(input()))
ans = ""
for i in range(1, 99):
    if n <= 26**i:
        n -= 1
        for j in range(i):
            ans += chr(ord("a") + n % 26)
            n //= 26
        break
    else:
        n -= 26**i
print((ans[::-1]))

n = int(eval(input()))
ans = ""
while n > 0:
    n -= 1
    ans += chr(ord("a") + n % 26)
    n //= 26
print((ans[::-1]))


Input:
import numpy as np

i = eval(input())

N = list(set(map(int, input().split(' '))))

def one_turn(l):

  l.sort()

  n = l[0]

  return np.array(list(set([n]+[ l[i]%n for i in range(1,len(l)) if ((l[i]%n != 0))])))

if len(set(N)) == 1 :

  print((N[0]))

else :

  N = np.array(N)

  while True :

    N = one_turn(N)

    if N[0] == 1 :

      print((1))

      break

    if len(N) == 1 :

      print((N[0]))

      break

import numpy as np

N= int(eval(input()))

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

A.sort()

def gcd(a,b):

  if b==0:

    return a

  else:

    return gcd(b,a%b)

r = 0

for i in A:

  r = gcd(i,r)

print(r)

import numpy as np

i = eval(input())
N = list(set(map(int, input().split(" "))))

def one_turn(l):
    l.sort()
    n = l[0]
    return np.array(
        list(set([n] + [l[i] % n for i in range(1, len(l)) if ((l[i] % n != 0))]))
    )

if len(set(N)) == 1:
    print((N[0]))
else:
    N = np.array(N)
    while True:
        N = one_turn(N)
        if N[0] == 1:
            print((1))
            break
        if len(N) == 1:
            print((N[0]))
            break

import numpy as np

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

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

r = 0
for i in A:
    r = gcd(i, r)
print(r)

-N = list(set(map(int, input().split(" "))))

-        list(set([n] + [l[i] % n for i in range(1, len(l)) if ((l[i] % n != 0))]))


Input:
#import sys

#input = sys.stdin.readline

n = int(eval(input()))

abc = []

for i in range(n):

    abc.append([int(i) for i in input().split()])

dp = [[float("inf") for i in range(3)] for i in range(n)]

dp[0] = abc[0]

for i in range(n-1):

    dp[i+1][0] = abc[i+1][0] + max(dp[i][1], dp[i][2])

    dp[i+1][1] = abc[i+1][1] + max(dp[i][0], dp[i][2])

    dp[i+1][2] = abc[i+1][2] + max(dp[i][0], dp[i][1])

print((max(dp[-1])))

#import sys

#input = sys.stdin.readline

n = int(eval(input()))

for i in range(n):

    if i == 0:

        dp = [int(i) for i in input().split()]

    else:

        abc = [int(i) for i in input().split()]

        dp[0], dp[1], dp[2] = abc[0] + max(dp[1], dp[2]), abc[1] + max(dp[0], dp[2]), abc[2] + max(dp[0], dp[1])

print((max(dp)))

# import sys
# input = sys.stdin.readline
n = int(eval(input()))
abc = []
for i in range(n):
    abc.append([int(i) for i in input().split()])
dp = [[float("inf") for i in range(3)] for i in range(n)]
dp[0] = abc[0]
for i in range(n - 1):
    dp[i + 1][0] = abc[i + 1][0] + max(dp[i][1], dp[i][2])
    dp[i + 1][1] = abc[i + 1][1] + max(dp[i][0], dp[i][2])
    dp[i + 1][2] = abc[i + 1][2] + max(dp[i][0], dp[i][1])
print((max(dp[-1])))

# import sys
# input = sys.stdin.readline
n = int(eval(input()))
for i in range(n):
    if i == 0:
        dp = [int(i) for i in input().split()]
    else:
        abc = [int(i) for i in input().split()]
        dp[0], dp[1], dp[2] = (
            abc[0] + max(dp[1], dp[2]),
            abc[1] + max(dp[0], dp[2]),
            abc[2] + max(dp[0], dp[1]),
        )
print((max(dp)))

-    abc.append([int(i) for i in input().split()])

-dp = [[float("inf") for i in range(3)] for i in range(n)]

+        dp = [int(i) for i in input().split()]

+        abc = [int(i) for i in input().split()]


Input:
import sys

input = sys.stdin.readline

n, m = list(map(int, input().split()))

ab = [tuple(map(int, input().split())) for _ in range(n)]

ab.sort()

ans = 0

for a, b in ab:

    buy = [m, b][0 <= m-b]

    m -= buy

    ans += a*buy

print(ans)

import sys

input = sys.stdin.readline

n, m = list(map(int, input().split()))

ab = [tuple(map(int, input().split())) for _ in range(n)]

ab.sort()

ans = 0

for a, b in ab:

    buy = min(m, b)

    m -= buy

    ans += a*buy

print(ans)

import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
for a, b in ab:
    buy = [m, b][0 <= m - b]
    m -= buy
    ans += a * buy
print(ans)

import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
for a, b in ab:
    buy = min(m, b)
    m -= buy
    ans += a * buy
print(ans)


Input:
import sys

sys.setrecursionlimit(10000000)

import os

import math

import bisect

import collections

import itertools

import heapq

import re

import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())

il = lambda: list(map(int, sys.stdin.buffer.readline().split()))

fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))

iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()

sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))

isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7

MAX = float('inf')

def main():

    if os.getenv("LOCAL"):

        sys.stdin = open("input.txt", "r")

    N, M = il()

    A = set(iln(M))

    dp = [0]*(N+1)

    dp[0] = 1

    for n in range(1, N+1):

        if n in A:

            dp[n] = 0

        else:

            dp[n] = dp[n-1] + dp[n-2]

    print((dp[N]%MOD))

if __name__ == '__main__':

    main()

import sys

sys.setrecursionlimit(10000000)

import os

import math

import bisect

import collections

import itertools

import heapq

import re

import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())

il = lambda: list(map(int, sys.stdin.buffer.readline().split()))

fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))

iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()

sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))

isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7

MAX = float('inf')

def main():

    if os.getenv("LOCAL"):

        sys.stdin = open("input.txt", "r")

    N, M = il()

    A = set(iln(M))

    dp = [0]*(N+1)

    dp[0] = 1

    for n in range(1, N+1):

        if n in A:

            dp[n] = 0

        else:

            dp[n] = (dp[n-1] + dp[n-2])%MOD

    print((dp[N]%MOD))

if __name__ == '__main__':

    main()

import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)
MOD = 10**9 + 7
MAX = float("inf")

def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")
    N, M = il()
    A = set(iln(M))
    dp = [0] * (N + 1)
    dp[0] = 1
    for n in range(1, N + 1):
        if n in A:
            dp[n] = 0
        else:
            dp[n] = dp[n - 1] + dp[n - 2]
    print((dp[N] % MOD))

if __name__ == "__main__":
    main()

import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)
MOD = 10**9 + 7
MAX = float("inf")

def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")
    N, M = il()
    A = set(iln(M))
    dp = [0] * (N + 1)
    dp[0] = 1
    for n in range(1, N + 1):
        if n in A:
            dp[n] = 0
        else:
            dp[n] = (dp[n - 1] + dp[n - 2]) % MOD
    print((dp[N] % MOD))

if __name__ == "__main__":
    main()


Input:
n, m = list(map(int, input().split()))

ab = [tuple(map(int, input().split())) for _ in range(m)]

u = [-1] * (n + 1)

def find(v):

    if u[v] < 0:

        return v

    else:

        return find(u[v])

total = n * (n - 1) // 2

ans = [total]

for a, b in reversed(ab[1:]):

    af = find(a)

    bf = find(b)

    af, bf =sorted([af, bf])

    if af != bf:

        total -= u[af] * u[bf]

        u[af] += u[bf]

        u[bf] = af

    ans.append(total)

for a in reversed(ans):

    print(a)

class UnionFind():

    def __init__(self, n):

        self.n = n

        self.parents = [-1] * n

    def find(self, x):

        if self.parents[x] < 0:

            return x

        else:

            self.parents[x] = self.find(self.parents[x])

            return self.parents[x]

    def union(self, x, y):

        x = self.find(x)

        y = self.find(y)

        if x == y:

            return

        if self.parents[x] > self.parents[y]:

            x, y = y, x

        self.parents[x] += self.parents[y]

        self.parents[y] = x

    def size(self, x):

        return -self.parents[self.find(x)]

    def same(self, x, y):

        return self.find(x) == self.find(y)

N, M, *X = list(map(int,open(0).read().split()))

uf = UnionFind(N + 1)

S = N * (N - 1) // 2

r = [S]

while X:

  b, a = X.pop(), X.pop()

  if not uf.same(a, b):

    S -= uf.size(a) * uf.size(b)

  r.append(S)

  uf.union(a, b)

for a in r[-2::-1]:

  print(a)

n, m = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(m)]
u = [-1] * (n + 1)

def find(v):
    if u[v] < 0:
        return v
    else:
        return find(u[v])

total = n * (n - 1) // 2
ans = [total]
for a, b in reversed(ab[1:]):
    af = find(a)
    bf = find(b)
    af, bf = sorted([af, bf])
    if af != bf:
        total -= u[af] * u[bf]
        u[af] += u[bf]
        u[bf] = af
    ans.append(total)
for a in reversed(ans):
    print(a)

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

N, M, *X = list(map(int, open(0).read().split()))
uf = UnionFind(N + 1)
S = N * (N - 1) // 2
r = [S]
while X:
    b, a = X.pop(), X.pop()
    if not uf.same(a, b):
        S -= uf.size(a) * uf.size(b)
    r.append(S)
    uf.union(a, b)
for a in r[-2::-1]:
    print(a)

-ab = [tuple(map(int, input().split())) for _ in range(m)]

+            self.parents[x] = self.find(self.parents[x])

+        if self.parents[x] > self.parents[y]:

+        self.parents[x] += self.parents[y]

+        return -self.parents[self.find(x)]

+        return self.find(x) == self.find(y)

+N, M, *X = list(map(int, open(0).read().split()))


Input:
N = int(eval(input()))

if N % 2 == 1:

    print((0))

else:

    cnt = 0

    div = 10

    for _ in range(100):

        cnt += N // div

        div *= 5

    print(cnt)

N = int(eval(input()))

if N % 2 == 1:

    print((0))

else:

    ans = 0

    div = 10

    for _ in range(100):

        ans += N // div

        div *= 5

    print(ans)

-    cnt = 0
+    ans = 0
-        cnt += N // div
+        ans += N // div
-    print(cnt)
+    print(ans)


Input:
def bubbleSort( cards ):

    n = len( cards )

    for i in range( 0, n ):

        for j in range( n-1 , i, -1 ):

            if int( cards[j][1] ) < int( cards[ j-1 ][1] ):

                cards[j], cards[ j-1 ] = cards[ j-1 ], cards[j]

    print(( " ".join( map( str, cards ) ) ))

def selectionSort( cards ):

	n = len( cards )

	for i in range( 0, n ):

		mini = i

		for j in range( i , n ):

			if int( cards[j][1] ) < int( cards[ mini ][1] ):

				mini = j

		if mini != i:

			cards[i], cards[ mini ] = cards[ mini ], cards[i]

	print(( " ".join( map( str, cards ) ) ))

n = int( eval(input( )) )

cards = input( ).split( " " )

cards2 = list( cards )

bubbleSort( cards )

print( "Stable" )

selectionSort( cards2 )

if " ".join( map( str, cards2 ) ) == " ".join( map( str, cards ) ):

	print( "Stable" )

else:

	print( "Not stable" )

def bubbleSort( cards ):

    n = len( cards )

    for i in range( 0, n ):

        for j in range( n-1 , i, -1 ):

            if int( cards[j][1] ) < int( cards[ j-1 ][1] ):

                cards[j], cards[ j-1 ] = cards[ j-1 ], cards[j]

    print(( " ".join( map( str, cards ) ) ))

def selectionSort( cards ):

	n = len( cards )

	for i in range( 0, n ):

		mini = i

		for j in range( i , n ):

			if int( cards[j][1] ) < int( cards[ mini ][1] ):

				mini = j

		if mini != i:

			cards[i], cards[ mini ] = cards[ mini ], cards[i]

	print(( " ".join( map( str, cards ) ) ))

n = int( input( ) )

cards = input( ).split( " " )

cards2 = list( cards )

bubbleSort( cards )

print( "Stable" )

selectionSort( cards2 )

if cards2 == cards:

	print( "Stable" )

else:

	print( "Not stable" )

def bubbleSort(cards):
    n = len(cards)
    for i in range(0, n):
        for j in range(n - 1, i, -1):
            if int(cards[j][1]) < int(cards[j - 1][1]):
                cards[j], cards[j - 1] = cards[j - 1], cards[j]
    print((" ".join(map(str, cards))))

def selectionSort(cards):
    n = len(cards)
    for i in range(0, n):
        mini = i
        for j in range(i, n):
            if int(cards[j][1]) < int(cards[mini][1]):
                mini = j
        if mini != i:
            cards[i], cards[mini] = cards[mini], cards[i]
    print((" ".join(map(str, cards))))

n = int(eval(input()))
cards = input().split(" ")
cards2 = list(cards)
bubbleSort(cards)
print("Stable")
selectionSort(cards2)
if " ".join(map(str, cards2)) == " ".join(map(str, cards)):
    print("Stable")
else:
    print("Not stable")

def bubbleSort(cards):
    n = len(cards)
    for i in range(0, n):
        for j in range(n - 1, i, -1):
            if int(cards[j][1]) < int(cards[j - 1][1]):
                cards[j], cards[j - 1] = cards[j - 1], cards[j]
    print((" ".join(map(str, cards))))

def selectionSort(cards):
    n = len(cards)
    for i in range(0, n):
        mini = i
        for j in range(i, n):
            if int(cards[j][1]) < int(cards[mini][1]):
                mini = j
        if mini != i:
            cards[i], cards[mini] = cards[mini], cards[i]
    print((" ".join(map(str, cards))))

n = int(input())
cards = input().split(" ")
cards2 = list(cards)
bubbleSort(cards)
print("Stable")
selectionSort(cards2)
if cards2 == cards:
    print("Stable")
else:
    print("Not stable")

-if " ".join(map(str, cards2)) == " ".join(map(str, cards)):


Input:
from sys import stdin

def main():

    N, *LR = list(map(int, stdin.buffer.read().split()))

    L, R = LR[::2], LR[1::2]

    Lp = max(L)

    Rq = min(R)

    A, B = list(zip(*sorted((max(0, r - Lp + 1), -max(0, Rq - l + 1)) for l, r in zip(L, R))))

    mi = float("inf")

    ma = max(r - l + 1 for l, r in zip(L, R)) + max(0, Rq - Lp + 1)

    for a, b in zip(A[1:], B):

        mi = min(mi, -b)

        ma = max(ma, mi + a)

    print(ma)

main()

from sys import stdin

def main():

    N, *LR = list(map(int, stdin.buffer.read().split()))

    L, R = LR[::2], LR[1::2]

    Lp = max(L)

    Rq = min(R)

    AB = sorted((max(0, r - Lp + 1), -max(0, Rq - l + 1)) for l, r in zip(L, R))

    mi = float("inf")

    ma = max(r - l + 1 for l, r in zip(L, R)) + max(0, Rq - Lp + 1)

    for i, (a, b) in enumerate(AB):

        if i:

            ma = max(ma, mi + a)

        mi = min(mi, -b)

    print(ma)

main()

from sys import stdin

def main():
    N, *LR = list(map(int, stdin.buffer.read().split()))
    L, R = LR[::2], LR[1::2]
    Lp = max(L)
    Rq = min(R)
    A, B = list(
        zip(*sorted((max(0, r - Lp + 1), -max(0, Rq - l + 1)) for l, r in zip(L, R)))
    )
    mi = float("inf")
    ma = max(r - l + 1 for l, r in zip(L, R)) + max(0, Rq - Lp + 1)
    for a, b in zip(A[1:], B):
        mi = min(mi, -b)
        ma = max(ma, mi + a)
    print(ma)

main()

-        zip(*sorted((max(0, r - Lp + 1), -max(0, Rq - l + 1)) for l, r in zip(L, R)))

+    AB = sorted((max(0, r - Lp + 1), -max(0, Rq - l + 1)) for l, r in zip(L, R))