peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
s = input()

ans = 753
for i in range(len(s)-3):
  subs = int(s[i:i+3])
  ans = min(abs(ans-subs),ans)
  
print(ans)
# Judge status: Accepted
n, a, b = map(int, input().split())

q, mod = divmod(n, (a+b))
if mod > a:
    print(q*a+a)
else:
    print(q*a+mod)
# Judge status: Accepted
n = int(input())
ab=[list(map(int,input().split())) for i in range(n)]
cnt=0
for i in reversed(range(n)):
    a,b=ab[i]
    a+=cnt
    if a%b==0:
        continue
    if a<=b:
        cnt+=(b-a)
        continue
    cnt += -(-a//b) * b - a
print(cnt)
# Judge status: Accepted
N=int(input())
for num in range(1,10):
    if (N/num).is_integer() and 1<=(N/num)<=9:
        print("Yes")
        break
else:
    print("No")
# Judge status: Wrong Answer
A=int(input())
B=list(map(int, input().split()))
print(sum(B)/2-max(B)/2)
# Judge status: Accepted
import itertools


n, m, q = map(int, input().split())
queries = [list(map(int, input().split())) for _ in range(q)]
ans = 0

nums = list(range(1, m+1))
seqs = list(itertools.combinations_with_replacement(nums, n))

for seq in seqs:
    point = 0
    for query in queries:
        a, b, c, d = query
        if seq[b-1] - seq[a-1] == c:
            point += d
    if point > ans:
        ans = point

print(ans)
# Judge status: Accepted
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    A, B, C = map(int, readline().split())
    if A%2==0 or B%2==0 or C%2==0:
        ans = 0
    else:
        ans = min(A*B, B*C, C*A)
    print(ans)



if __name__ == '__main__':
    main()
# Judge status: Accepted
N = list(map(int, input()))

# print(N)
ans = 0
DP = [0] *2
DP[0] = 0
DP[1] = 1
for i in N:
    a, b = DP[0] ,DP[1]
    DP[0] = a + i if a+i < b +(10-i) else b +(10-i)
    DP[1] = a + i+1 if a + i+1 < b + (9-i) else b + (9-i)

    # print(DP)

print(DP[0] if DP[0] <= DP[1]+1 else DP[1] +1)
# Judge status: Wrong Answer
s = input()
s = s[::-1]
n = len(s)

cur = 0
while cur < n:

  if s[cur:cur+5:] == "maerd" or "esare":
    cur += 5
    continue
  if s[cur:cur+6:] == "resare":
    cur += 6
    continue
  if s[cur:cur+7:] == "remaerd":
    cur += 7
    continue
  print("NO")
  exit()

print("YES")
# Judge status: Wrong Answer
n = int(input())

a = n // 15

print(n * 800 + a * 200)
# Judge status: Wrong Answer
N, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
children = [0] * N
a.sort()
kashi = 0
while kashi < x:
    for i in range(0,N):
        kashi += a[i]
        children[i] += 1
        if kashi > x:
            kashi -= a[i]
            children[i] -= 1
            break
    if kashi == 0:
        break
print(N - children.count(0))
# Judge status: Accepted
N = int(input())
v = list(map(int, input().split()))
ans = min(v)
v.remove(min(v))
for i in range(N-1):
    ans = (ans + min(v)) /2
    v.remove(min(v))

print(ans)
# Judge status: Accepted
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    N = int(input())
    presuf = [[0] * 10 for _ in range(10)]
    for i in range(1,N + 1):
        pre = int(str(i)[0])
        suf = i%10
        presuf[pre][suf] += 1
    
    ans = 0
    for i in range(10):
        for j in range(10):
            ans += presuf[i][j]*presuf[j][i]
    print(ans)
if __name__ == '__main__':
    main()
# Judge status: Accepted
t = input()
for i in range(len(t)):
    if t[i] == "?":
        print("D",end="")
    else:
        print(t[i],end="")
print()
# Judge status: Accepted
s = input()
n = len(s)-1
if n%2!=0:
    n-=1

while n>1:
    if s[0:int(n/2)]==s[int(n/2):n]:
        print(n)
        break
    else:
        n-=2
# Judge status: Wrong Answer

N = int(input())

if N < 2:
    print(0)
    exit()
N = N - 2

result = 2 * (10 ** N)
result = result % ((10 ** 9)+ 7)

print(result)
# Judge status: Accepted
def main():
    n = int(input())
    P = list(map(int, input().split()))
    ans = 0
    next = 0
    on = False
    for i in range(n):
        if P[i] == i + 1:
            ans += 1
            if on:
                next += 1
                on = False
            else:
                on = True
        else:
            on = False
    print(ans - next)

if __name__ == '__main__':
    main()
# Judge status: Accepted
def func():
    count = 0
    for _ in range(N):
        a, b = map(int, input().split())
        if a == b:
            count += 1
        else:
            count = 0
        if count >= 3:
            return "Yes"
    return "No"


N = int(input())

print(func())
# Judge status: Wrong Answer
x=input()
if x:
  print('0')
else:
  print('1')
# Judge status: Wrong Answer
k = int(input())
i = 0
s = 0
ans = -1

for z in range(k):
    i += 1
    s = 7 + 10*s
    if s % k != 0:
        s = s % k
    else:
        ans = i
        break

print(ans)
# Judge status: Wrong Answer
w = sorted(input())
count = 0
ans = 'Yes'
for i in range(len(w)-1):
  count += 1
  if w[i]!=w[i+1]:
    if count%2!=0:
      ans = 'No'
      break
    else:
      count = 0
print(ans)
# Judge status: Accepted
w=input()
ans={}
k=0
for i in w:
    if i not in ans:
        ans[i]=1
    else :
        ans[i]+=1
for i in ans:
    if ans[i]%2==1:
        print("No")
        break
else :
    print("Yes")
# Judge status: Accepted
s = input()

days_of_the_week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']

n = days_of_the_week.index(s)

print(7 - days_of_the_week.index(s))
# Judge status: Wrong Answer
n,p=map(int,input().split())
a=list(map(int,input().split()))
temp1=0
temp0=0
for i in range(n):
  if a[i]%2==0:
    temp0=temp0+1
  else:
    temp1=temp1+1
if p%2==0:
  print(2**(n-1))
else:
  if temp1==0:
    print(0)
  else:
    print(2**(n-1))
# Judge status: Accepted
a, b, c, k = map(int,input().split())

if a >= k:
    print(k)
elif a < k and a+b >= k:
    print(a)
elif a+b < k:
    print(a-(k-a-b))
# Judge status: Accepted
A,B,C,D = map(int,input().split())

s = max(A,C)
e = min(B,D)

print(e-s if e-s>0 else 0)
# Judge status: Wrong Answer
N, A, B = map(int, input().split())

if N == 1:
    if A == B:
        ans = 1
    else:
        ans = 0
elif N == 2:
    ans = 1
else:
    ans = (N - 2) * B - (N - 2) * A + 1
    
print(ans)
# Judge status: Accepted
X=int(input())
sum=0
A=100
while A<X:
  A=(A*101)//100
  sum+=1
print(sum)
# Judge status: Wrong Answer
S = input()

if S[-1] == 's':
  S = S + 's'
else:
  S = S + 'es'

print(S)
# Judge status: Accepted
N, M, K = map(int, input().split())

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

AD = [0]
for i in range(N):
    AD.append(AD[i]+A[i])
BD = [0]
for i in range(M):
    BD.append(BD[i]+B[i])

ans = 0
for i in range(N+1):
    if K < AD[i]:
        break
    else:
        while BD[M] > K - AD[i]:
            M -= 1
        ans = max(ans, i + M)

print(ans)
# Judge status: Wrong Answer
A,B,C =map(int,input().split())
K = int(input())
l = [A,B,C]
sl = sorted(l)
#print(sl)

for i in range(K):
    if sl[-1] <= 25:
        sl[-1] *= 2
    elif sl[-2] <= 25:
        sl[-2] *= 2
    elif sl[-3] <= 25:
        sl[-3] *= 2
    else:
        pass
#print(sl)
print(sum(sl))
# Judge status: Wrong Answer
N = int(input())
Plist = list(map(int, input().split()))
now = Plist[0]
ans = 0
for p in Plist:
    if p <= now:
        ans += 1
    else:
        break
    now = p
print(ans)
# Judge status: Accepted
a = input()
b = input()[::-1]

if a == b:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
X = int(input())
pos = 0
for i in range(1, 100001):
    pos += i
    if pos >= X:
        print(i)
        break
# Judge status: Wrong Answer
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,P = MI()
A = LI()

x = sum(A[i] & 1 for i in range(N))  # Aiの中で、偶数であるものの個数
y = N-x  # Aiの中で、奇数であるものの個数

if y == 0:
    print(0 if P == 1 else 2**x)
else:
    print(2**(x+y-1))
# Judge status: Accepted
N, D = [int(i) for i in input().split()]
X = []
for i in range(N):
  X += [[int(i) for i in input().split()]]
a = 0
for i in range(N):
  for j in range(i):
    y = 0
    for k in range(D):
      y += (X[i][k] - X[j][k]) ** 2
    if y == int(y ** 0.5) ** 2:
      a += 1
print(a)
# Judge status: Accepted
def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if s != 'a' and ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        ans[-1] = chr((ord(ans[-1]) + k - 97) % 26 + 97)
    print(''.join(ans))

if __name__ == '__main__':
    main()
# Judge status: Accepted
n=input()
print("Yes" if "9" in n else "No")
# Judge status: Accepted
from math import floor


n = int(input())
m = floor(n**0.5)
ans = 0
for i in range(1, m+1):
  ans += 2*((n-1)//i)
  ans -= 2*i-1
if m*m == n:
  ans += 1
print(ans)
# Judge status: Accepted
N, K, Q = map(int, input().split())
Ans = [K - Q] * N
A = []
for i in range(Q):
    Ans[int(input()) - 1] += 1

for i in Ans:
    if i > 0:
        print('Yes')
    else:
        print('No')
# Judge status: Wrong Answer
import math
n = int(input())
power = math.factorial(n)
print(power)
print(power%(10**9))
# Judge status: Accepted
trump=[2,3,4,5,6,7,8,9,10,11,12,13,1]
a,b=map(int,input().split(" "))
if a==b:print("Draw")
else:print(["Alice","Bob"][trump.index(b)>trump.index(a)])
# Judge status: Wrong Answer
l,r=map(int,input().split())
l=l%2019
r=r%2019
if (l<=1009 and r<=1009) or (l>1009 and r>1009):
    print((l*(l+1))%2019)
else:
    print(0)
# Judge status: Wrong Answer
import math
x = int(input())
seen = [0] * 1001
ans = 1
for i in range(x):
    if(seen[i]): pass
    cur = i
    if(i > 1):
        while (cur <= x):
            cur *= i
            if(cur <= x): ans = max(ans, cur)
print(ans)
# Judge status: Accepted
import math

a, b, x = map(int, input().split())

if a * a * b / 2.0 <= x:
  ans = math.degrees(math.atan(2 * (a * a * b - x) / (a * a * a)))
else:
  ans = math.degrees(math.pi / 2.0 - math.atan(2 * x / (a * b * b)))
print('{:.010f}'.format(ans))
# Judge status: Accepted
N = int(input())
P = [list(map(int,input().split())) for i in range(N)]

a=[P[0][0]]*N
b=[P[0][1]]*N
c=[P[0][2]]*N

for i in range (1, N):
	a[i] = max(b[i-1], c[i-1])+P[i][0]
	b[i] = max(a[i-1], c[i-1])+P[i][1]
	c[i] = max(a[i-1], b[i-1])+P[i][2]

print(max(a[N-1], b[N-1], c[N-1]))
# Judge status: Accepted
N, X = map(int, input().split())
Ls = [int(i) for i in input().split()]

Ds = [0]
for i, l in enumerate(Ls):
    Ds.append(Ds[i] + l)

print(sum([d <= X for d in Ds]))
# Judge status: Accepted
n = int(input())
rng = []
for _ in range(n):
    x, l = map(int, input().split())
    rng.append((x-l, x+l))
rng.sort(key=lambda x: x[1])

ans = 1
tmp = rng[0][1]
for i in range(1, n):
    l, r = rng[i]
    if tmp <= l:
        ans += 1
        tmp = r

print(ans)
# Judge status: Wrong Answer
a, b = map(int, input().split())
count = 0
for i in range(a, b):
  A = str(i)
  if A[0] == A[-1] and A[1] == A[-2]:
    count += 1
print(count)
# Judge status: Accepted
a, b = map(int, input().split())
if (a * b) % 2 == 0:
  print("Even")
else:
  print("Odd")
# Judge status: Accepted
import math

K = int(input())
check = {}
ans = 0

for i in range(201):
    check[i] = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        check[math.gcd(a, b)] += 1

for c in range(1, K+1):
    for k in check.keys():
        num = math.gcd(c, k) * check[k]
        ans += num

print(ans)
# Judge status: Accepted
words = ("dream","dreamer","erase","eraser")
import sys
readline = sys.stdin.readline

S = readline().rstrip()

stack = [0]
while stack:
  ind = stack.pop()
  if ind == len(S):
    print("YES")
    break
  for w in words:
    if S[ind:ind + len(w)] == w:
      stack.append(ind + len(w))
else:
  print("NO")
# Judge status: Accepted
import fractions

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

ans = A[0]
for i in range(1, N):
    ans = fractions.gcd(ans, A[i])
print(ans)
# Judge status: Accepted
h=int(input())
w=int(input())
n=int(input())
m=max(h,w)
import math
print(math.ceil(n/m))
# Judge status: Accepted
import sys
n = int(sys.stdin.readline())
m = map(int, sys.stdin.read().split())
ab = list(zip(m, m))
res = 0
for i, j in ab[::-1]:
  if j != 1:
  	res += - (i + res) % j
print(res)
# Judge status: Accepted
def dfs(s,l):
  if s!="":
    if len(s)>10 or s[0]=="0":
      return
  if s!="":
    l.append(int(s))
  for c in "0123456789":
    if s!="":
      if abs(int(s[-1])-int(c))<=1:
        dfs(s+c,l)
    else:
      if c!="0":
        dfs(s+c,l)

k=int(input())
l=[]
dfs("",l)
l.sort()
print(l[k-1])
# Judge status: Accepted
# C - Forbidden List
X, N = map(int, input().split()) 
num_list = list(map(int, input().split())) 
for i in range(len(num_list)):
    num_list[i] = num_list[i]-X
for i in range(101):
    if (-i in num_list) is False:
        print(X-i)
        break
    if (i in num_list) is False:
        print(X+i)
        break
# Judge status: Accepted
N, L = map(int, input().split())
A = sorted([L + i for i in range(N)], key=lambda x: abs(x))
print(sum(A[1:]))
# Judge status: Accepted
x, y = [int(x) for x in input().split()]

if x == 0:
    ans = abs(y) + (y < 0)
else:
    ans = 1 if (x < 0 and abs(x) < abs(y)) or (x > 0 and abs(x) > abs(y)) else 0
    ans += abs(abs(y) - abs(x))
    ans += 1 if (-1 if (x < 0 and abs(x) < abs(y)) or (x > 0 and abs(x) > abs(y)) else 1) * x * y < 0 else 0

print(ans)
# Judge status: Accepted
s,t=input().split(" ")
a,b=map(int,input().split(" "))
u=input()
 
if s==u:
  print(a-1, b)
else:
  print(a, b-1)
# Judge status: Accepted
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

hi = 10**18
lo = 0

while hi - lo > 1:
    mid = (hi + lo) // 2
    cut = 0
    for i in range(N):
        cut += (A[i] + mid - 1) // mid - 1
    if cut <= K:
        hi = mid
    else:
        lo = mid

print(hi)
# Judge status: Accepted
import math
import collections
import sys

#input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]

a,b,c=MI()
print(min(int(b/a),c))
# Judge status: Accepted
n=int(input())
p,q=divmod(n,11)
if q==0:
    print(2*p)
elif q<=6:
    print(2*p+1)
else:
    print(2*p+2)
# Judge status: Wrong Answer
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

flg = False
for y in range(N-M+1):
  for x in range(N-M+1):
    res = True
    for i in range(M):
      if A[y+i][y+i:y+i+M] != B[i][i:i+M]: res = False
    if res: flg = True
    if flg: break
  if flg: break

print("Yes" if flg else "No")
# Judge status: Accepted
import collections
w = input()
cw = collections.Counter(w)
for val in cw.values():
    if val%2 == 1:
        print('No')
        exit()
print('Yes')
# Judge status: Accepted
import itertools

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

a.sort()
a = list(itertools.accumulate(a))

cnt = 0

for i in range(len(a)):
    if x > a[i]:
        if i == len(a)-1:
            break
        cnt += 1
    elif x == a[i]:
        cnt += 1
        break
    else:
        break

print(cnt)
# Judge status: Accepted
a = list(input())
# print(a[1])
b = 0
c = 0
for i in range(len(a)):
    if i % 2 == 1:
        b = b + int(a[i] != "R")
    if i % 2 == 0:
        c = c + int(a[i] != "L")
if b +c == len(a):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())
x = list(map(int, input().split()))

max_x = max(x)
min_x = min(x)

ans = []
for i in range(1, 101):
  a = 0
  for xi in x:
    a += (xi - i)*(xi - i)
  ans.append(a)
  
print(min(ans))
# Judge status: Accepted
from fractions import gcd

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

left = [0 for _ in range(N+1)]
right = [0 for _ in range(N+1)]

for i in range(N):
  left[i+1] = gcd(left[i],arr[i])
  right[-i-2] = gcd(right[-i-1], arr[-i-1])

ans = 1
for i in range(N):
  result = gcd(left[i], right[i+1])
  ans = max(ans, result)

print(ans)
# Judge status: Wrong Answer
count = int(input())
n_sequence = sorted([int(x) for x in input().split()])

for n in range(count):
    if (n_sequence[n-2] == n_sequence[n-1]) or (n_sequence[n-1] == n_sequence[n]) \
       or (n_sequence[n-2] == n_sequence[n]):
        print("NO")
        break
else:
    print("YES")
# Judge status: Wrong Answer
import itertools

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

if (x+y) % 3 != 0:
  print(0)
else:
  roots = 0
  
  for seq in itertools.permutations(['u', 'l'], int((x+y)/3)):
    _x = 0
    _y = 0
    
    for v in seq:
      if v == 'u':
        _x += 1
        _y += 2
      else:
        _x += 2
        _y += 1

    if (_x == x) & (_y == y):
      roots += 1

  print(roots % (pow(10, 9)+7))
# Judge status: Wrong Answer
N = int(input())
A = [int(input()) for i in range(N)]
cnt = 1

if 2 not in A:
  print(-1)

a = A[0]
while a != 2: 
  a = A[a-1]
  cnt += 1
  if a == 1:
    print(-1)
    exit()
print(cnt)
# Judge status: Accepted
y,m,d = map(int,input().split(sep="/"))
if 4 > m:
    print("Heisei")
elif m == 4 and d <= 30:
    print("Heisei")
else:
    print("TBD")
# Judge status: Accepted
A, B, M = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
x = []
y = []
c = []
setmin = 1001001001001
for _ in range(M):
    xi, yi, ci = map(int, input().split())
    x.append(xi)
    y.append(yi)
    c.append(ci)
    discountprice = a[xi-1] + b[yi-1] - ci
    if discountprice < setmin:
        setmin = discountprice
print(min(min(a)+min(b), setmin))
# Judge status: Accepted
def main():
  N=int(input())
  A=list(map(int,input().split()))

  mod=10**9+7
  ans=0

  for i in range(60):
      a=0
      for x in A:
          if x>>i&1:
              a+=1
      ans+=a*(N-a)*pow(2,i,mod)
      ans%=mod
  print(ans)
if __name__ == '__main__':
    main()
# Judge status: Accepted
N, K = map(int, input().split())
H = sorted([int(input()) for _ in range(N)])
print(min([H[i + K - 1] - H[i] for i in range(N - K + 1)]))
# Judge status: Accepted
n = int(input())
print("0.5" if n %2 == 0 else ((n//2+1)/n))
# Judge status: Accepted
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N = int(input())
if N % 1000 != 0:
    print(1000 - N % 1000)
else:
    print(0)
# Judge status: Accepted
k, n = map(int, input().split())
A = input().split()
a = [int(i) for i in A]

kyori = k + a[0] - a[n-1]

for i in range(n):
    if kyori < a[i] - a[i-1]:
        kyori = a[i] - a[i-1]
print(k-kyori)
# Judge status: Accepted
s = input()
t = input()

n = len(s)
nt = len(t)

ans = 1000
for i in range(n - nt + 1):
    string = s[i:i + nt]

    count = 0
    for c1, c2 in zip(string, t):
        if c1!=c2: count += 1
    
    ans = min(ans, count)

print(ans)
# Judge status: Accepted
A,B,C=map(int,input().split())
print("Yes" if A<=C<=B or B<=C<=A else "No")
# Judge status: Wrong Answer
# C - Build Stairs

n = int(input())
h = list(int(x) for x in input().split())

ans = 'Yes'
for i in range(1, n):
    if h[i-1]-h[i]>1:
        ans = 'No'
        break
    if i>1 and h[i-2]>h[i-1] and h[i-1]>h[i]:
        ans = 'No'
        break

print(ans)
# Judge status: Wrong Answer
n, w = map(int, input().split())
wts = []

for i in range(n):
    wts.append(list(map(int, input().split())))
    
dp = [[0]*(w+1) for i in range(n)]
dp[0][wts[0][0]] = wts[0][1]

for i in range(1, n):
    for j in range(1+w):
        if j >= wts[i][0]:
            dp[i][j] = max(dp[i-1][j], wts[i][1]+dp[i-1][j-wts[i][0]])
        else:
            dp[i][j] += dp[i-1][j]

print(dp[-1][-1])
# Judge status: Accepted
a,b=map(int,input().split())
if abs(a-b) > 1:
  print(':(')
else:print('Yay!')
# Judge status: Accepted
if sorted(input()) == list('abc'):
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
a=["a","e","i","o","u"]
print("vowel" if input() in a else "constant")
# Judge status: Wrong Answer
x = int(input())

if x <= 6:
    print(1)
else:
    q, m = divmod(x, 11)
    ans = q*2

    while m >= 0:
        m -= ([5, 6])[ans%2]
        ans += 1

    print(ans)
# Judge status: Wrong Answer
input = input()
if input[2] == input[3] and input[4] == input[5]:
    print('Yes')
else:
    print('NO')
# Judge status: Accepted
n,m=list(map(int,input().split()))
r=[[]for i in range(n)]
for i in range(m):
  inp=list(map(lambda x:int(x)-1,input().split()))
  r[inp[0]].append(inp[1])
  r[inp[1]].append(inp[0])

w=[0 for i in range(n)]
w[0]=1
a=[0]
b=[]
while True:
  for i in a:
    for j in r[i]:
      if w[j]==0:
        w[j]=i+1
        b.append(j)
  if len(b)==0:
    break
  a=b
  b=[]
print("Yes")
for i in range(1,n):
  print(w[i])
# Judge status: Accepted
N = int(input())
m = 1000
k = 0
A = list(map(int,input().split()))
M = A[0]
for a in A:
  if M > a:
    if k > 0:
      m += k * M
      k = 0
  elif M < a:
    if k == 0:
      k,m = divmod(m,M)
  M = a
m += k * M
print(m)
# Judge status: Accepted
n=int(input())
a=[int(i) for i in input().split()]
nC2=[0 for i in range(n+1)]
for i in range(2,n+1):
    nC2[i]=i*(i-1)//2
cnt=[0 for i in range(n)]
for i in a:
    cnt[i-1]+=1
res=0
for i in cnt:
    res+=nC2[i]
for i in a:
    print(res-nC2[cnt[i-1]]+nC2[cnt[i-1]-1])
# Judge status: Accepted
import math

def main():
    a, b = map(int, input().split())
    n = str(a) + str(b)
    N = int(n)
    if math.sqrt(N) % 1 == 0:
        print('Yes')
    else:
        print('No')
main()
# Judge status: Wrong Answer
S=input()
if S[0]=="A" and S[2:-1].count("C")==1:
    for s in S[1:]:
        if s!="C":
            if s.islower():
                print("AC")
                exit()
print("WA")
# Judge status: Wrong Answer
N=int(input())
S=input()
ans=0
black=0
white=0
for n in range(N):
    if S[n]=='.':
        white+=1
    else:
        black+=1
stones={'b':0,'w':white}
for n in range(N-1):
    if S[n]=='#':
        stones['b']+=1
    else:
        stones['w']-=1
    if S[n]!=S[n+1]:
        ans+=min(stones['b'],stones['w'])
print(min(ans,black,white))
# Judge status: Wrong Answer
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
l = set(list(map(int,input().split())))
for i in range(1,max(x,100-x)+1):
    if x-i not in l:
        print(x-i)
        exit()
    if x+i not in l:
        print(x+i)
        exit()
# Judge status: Wrong Answer
n = int(input())
l = [0]
ans = []
a = 0
cur = 1
while a < 1000000000000001:
  a += 26**cur
  cur += 1
  l.append(a)
l = list(reversed(l))
for i in range(len(l)-1):
  if l[i] >= n:
    ans.append(0)
  else:
    div = (n-1)//(l[i]-l[i+1])
    n = n-div*(l[i]-l[i+1])
    ans.append(div)
ans.append(n)
ans =list(map(lambda x:x+96, ans))
for i in range(len(ans)):
  if ans[i] > 96:
    ans2 = ans[i:]
    break
ans2 = "".join([chr(i) for i in ans2])
print(ans2)
# Judge status: Wrong Answer
import numpy as np

N = raw_input()
ans = 0

shiharai = np.zeros(len(N)+1)
uketori = np.zeros(len(N)+1)

for i in range(len(N)):
    item = int(N[-1-i])
    if item < 6:
        shiharai[i] = shiharai[i] + item
        ans = ans + item
    else:
        ans = ans + (11-item)
        shiharai[i+1] = shiharai[i+1] + 1
        uketori[i] = uketori[i] + (10-item)

sol = shiharai - uketori
ans = 0.0
for item in sol:
    ans = ans + np.abs(item)

print int(ans)
# Judge status: Wrong Answer
s = list(input())
if len(set(s))==2 and (s[0]==s[1] and s[2]==s[3]) or (s[0]==s[2] and s[1]==s[3]) or (s[0]==s[3] and s[1]==s[2]):
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline

S = input()
Q = int(input())
A = [(input().split()) for _ in range(Q)]

for i in range(Q):
  if A[i] == ["1"]:
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] == "1":
      S = S + A[i][2]
    else:
      S = A[i][2] + S
      
print(S)
# Judge status: Wrong Answer
h, n = map(int, input().split())
A = list(map(int, input().split()))
flag = False

for a in A:
  h -= a
  if h<0:
    flag = True
    break

print("Yes" if flag else "No")