Harryxun/stf_run huggingface dataset:
#!/usr/bin/env python3


def dfs(v, adj_list, depth, visited):
    visited[v] = True
    x = depth
    for w in adj_list[v]:
        if not visited[w]:
            x += dfs(w, adj_list, depth + 1, visited)

    return x


def solve(n, d):

    if n < 7:
        print(-1)
        return

    d.sort()
    w = [1] * n
    edges = []
    adj_list = [[] for _ in range(n)]
    for j in range(n - 1, 0, -1):
        di, i = d[j]
        pdi = di - n + 2 * w[i]
        p = None
        lo, hi = 0, j
        while lo < hi:
            mid = (lo + hi) // 2
            xdi, xi = d[mid]
            if xdi == pdi:
                p = xi
                break
            elif xdi < pdi:
                lo = mid + 1
            else:
                hi = mid
        if p is None:
            print(-1)
            return
        u, v = i, p
        if v < u:
            u, v = v, u
        edges.append((u + 1, v + 1))
        adj_list[u].append(v)
        adj_list[v].append(u)
        w[p] += w[i]

    d0, r = d[0]
    visited = [False] * n
    x = dfs(r, adj_list, 0, visited)
    if x != d0:
        print(-1)
        return

    edges.sort()
    for uv in edges:
        u, v = uv
        print('{} {}'.format(u, v))



def main():
    n = input()
    n = int(n)
    d = []
    for i in range(n):
        di = input()
        di = int(di)
        d.append((di, i))


    solve(n, d)


if __name__ == '__main__':
    main()



### FIXED CODE ###

#!/usr/bin/env python3
import sys

sys.setrecursionlimit(101010)

def dfs(v, adj_list, depth, visited):
    visited[v] = True
    x = depth
    for w in adj_list[v]:
        if not visited[w]:
            x += dfs(w, adj_list, depth + 1, visited)

    return x


def solve(n, d):

    if n < 7:
        print(-1)
        return

    d.sort()
    w = [1] * n
    edges = []
    adj_list = [[] for _ in range(n)]
    for j in range(n - 1, 0, -1):
        di, i = d[j]
        pdi = di - n + 2 * w[i]
        p = None
        lo, hi = 0, j
        while lo < hi:
            mid = (lo + hi) // 2
            xdi, xi = d[mid]
            if xdi == pdi:
                p = xi
                break
            elif xdi < pdi:
                lo = mid + 1
            else:
                hi = mid
        if p is None:
            print(-1)
            return
        u, v = i, p
        if v < u:
            u, v = v, u
        edges.append((u + 1, v + 1))
        adj_list[u].append(v)
        adj_list[v].append(u)
        w[p] += w[i]

    d0, r = d[0]
    visited = [False] * n
    x = dfs(r, adj_list, 0, visited)
    if x != d0:
        print(-1)
        return

    edges.sort()
    for uv in edges:
        u, v = uv
        print('{} {}'.format(u, v))



def main():
    n = input()
    n = int(n)
    d = []
    for i in range(n):
        di = input()
        di = int(di)
        d.append((di, i))


    solve(n, d)


if __name__ == '__main__':
    main()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
b = nl()



ans = []

for i in range(n):
    for j in range(b):
        if b[j] == j+1:
            ans.append(b[j])
            del b[j]
            continue
        print(-1)
        exit()

print(' '.join(reversed(ans)))




### FIXED CODE ###

ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
b = nl()

ans = []

for i in range(n):
    for j in range(len(b))[::-1]:
        if b[j] == j + 1:
            ans.append(b[j])
            del b[j]
            break
        if j == 0:
            print(-1)
            exit()

print(' '.join([str(_) for _ in reversed(ans)]))
print(max(1,input()[:int(input())].replace("1","")[:1]))

### FIXED CODE ###

s=input()
k=int(input())
for i in range(k):
    if s[i] !="1":
        print(s[i])
        exit()
print("1")
import math
a, b, k = map(int, input().split())
l = []
gcd = math.gcd(a, b)
for i in range(1, int(gcd**0.5)+1):
    if gcd%i==0:
        l.append(i)
        if i != gcd//i:
            l.append(gcd//i)
l.sort(reverse = True)
print(l[k-1])


### FIXED CODE ###

import fractions
a, b, k = map(int, input().split())
l = []
gcd = fractions.gcd(a, b)
for i in range(1, int(gcd**0.5)+1):
    if gcd%i==0:
        l.append(i)
        if i != gcd//i:
            l.append(gcd//i)
l.sort(reverse = True)
print(l[k-1])
X,Y,A,B,C= map(int, input().split())

#R = [0]*(10**6)
#G = [0]*(10**6)
#N = [0]*(10**6)

R = [0]*(6)
G = [0]*(6)
N = [0]*(6)
ans = []

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

R.sort()
G.sort()
N.sort(reverse=True)

#Rs = sorted(R)
#Gs = sorted(G)
#Ns = sorted(N)

R2 = R[-X:]
G2 = G[-Y:]

W = sorted(R2 + G2)

for i in range(C):
	if W[i] < N[i]:
		W[i] = N[i]



#print(R,G,N)
#print(Rs,Gs,Ns)
#print(R2,G2)
#print(W)

print(sum(W))

### FIXED CODE ###

X,Y,A,B,C= map(int, input().split())
R = list(map(int, input().split()))
G = list(map(int, input().split()))
N = list(map(int, input().split()))

R.sort(reverse=True)
G.sort(reverse=True)
N.sort(reverse=True)

R2 = R[:X]
G2 = G[:Y]

W = sorted(R2 + G2 + N, reverse=True)

print(sum(W[0:X+Y]))
imp = imput()
alp = ['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(alp[alp.index(imp) + 2])

### FIXED CODE ###

imp = input()
alp = ['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(alp[alp.index(imp) + 1])
a = input('')
b = input('')
if b[:-1] == a:
  return 'Yes'

### FIXED CODE ###

a = input('')
b = input('')

if b[:-1] == a:
    print('Yes')

else:
    print('No')
#!/usr/bin/env python3
N = int(input())
X = input()

x_num = int(X, 2)
cnt1 = X.count('1')

p_zero = x_num % (cnt1 + 1)
p_one = x_num % (cnt1 - 1)


def f(cnt):
    if (cnt > 0):
        pcount = p_count(cnt)
        return f(cnt % pcount) + 1
    else:
        return 0


def p_count(x):
    cnt = 0
    while (x > 0):
        if x % 2 != 0:
            cnt += 1
        x //= 2
    return cnt


def f1(x):
    cnt = 0
    while (x > 0):
        x %= bin(x).count('1')
        cnt += 1
    return cnt


for i, x in enumerate(list(X)):
    if (x == '1'):
        #x_num = int(''.join(X), 2)
        if (x_num - (2**(N-(i+1)))) != 0:
            print(f1((x_num - pow(2, (N - (i + 1)), cnt1 - 1)) % (cnt1 - 1)) + 1)
        else:
            print(0)
    else:
        #x_num = int(''.join(X), 2)
        print(f1((x_num + pow(2, (N - (i + 1)), cnt1 + 1)) % (cnt1 + 1)) + 1)

### FIXED CODE ###

#!/usr/bin/env python3
N = int(input())
X = input()

x_num = int(X, 2)
cnt1 = X.count('1')

p_zero = x_num % (cnt1 + 1)
p_one = (x_num % (cnt1 - 1) if cnt1 - 1 > 0 else 1)


def f(cnt):
    if (cnt > 0):
        pcount = p_count(cnt)
        return f(cnt % pcount) + 1
    else:
        return 0


def p_count(x):
    cnt = 0
    while (x > 0):
        if x % 2 != 0:
            cnt += 1
        x //= 2
    return cnt


def f1(x):
    cnt = 0
    while (x > 0):
        x %= bin(x).count('1')
        cnt += 1
    return cnt


for i, x in enumerate(list(X)):
    if (x == '1'):
        #x_num = int(''.join(X), 2)
        if cnt1 - 1 > 0:
            xxx = (p_one - pow(2, (N - (i + 1)), cnt1 - 1)) % (cnt1 - 1)
            xxx += cnt1 - 1 if xxx < 0 else 0
            print(f1(xxx) + 1)
        else:
            print(0)
    else:
        #x_num = int(''.join(X), 2)
        xxx = (p_zero + pow(2, (N - (i + 1)), cnt1 + 1)) % (cnt1 + 1)
        xxx += cnt1 + 1 if xxx < 0 else 0
        print(f1(xxx) + 1)
while True:
    m, f, r = [int(i) for i in input().solit()]

    if m == f == r == -1:
        break

    if m == -1 or f == -1:
        print("F")

    if m + f >= 80:
        print("A")

    if 65 <= m + f < 80:
        print("B")

    if 50 <= m + f < 65:
        print("C")

    if 30 <= m + f < 50:
        print("D")

    elif r >= 50:
        print("C")

    else:
        print("F")

### FIXED CODE ###

while True:
    m, f, r = [int(i) for i in input().split()]

    if m == f == r == -1:
        break

    elif m == -1 or f == -1:
        print("F")

    elif m + f >= 80:
        print("A")

    elif 65 <= m + f < 80:
        print("B")

    elif 50 <= m + f < 65:
        print("C")

    elif 30 <= m + f < 50:
        if r >= 50:
            print("C")
        else:
            print("D")

    elif m + f < 30:
        print("F")

    elif m + f < 30:
        print("F")
n, k = map(int,input().split())
a = list(map(int,input().split()))

zerofrag = 0
zerobig = []
zerosmall = []

for i in a:
    if i == 0:
        zerofrag =1
    elif i > 0:
        zerobig.append(i)
    else:
        zerosmall.append(abs(i))

if k == 1 and zerofrag == 1:
    print(0)
else:
    if zerofrag == 1:
        k = k -1

    zerobig.sort()
    zerosmall.sort()
    #print(zerobig,zerosmall)
    kouho = []
    if len(zerobig) >=k:
        kouho.append(zerobig[k-1])
    if len(zerosmall) >=k:
        kouho.append(zerosmall[k-1])
        
    for ii in range(len(zerosmall)):
        if k - (ii) > len(zerobig):
            continue
        else:
            try:
                kouho.append(zerosmall[ii] * 2 + zerobig[k - ii - 2])
            except:
                continue
    for jj in range(len(zerobig)):
        if k - (jj ) > len(zerosmall):
            continue
        else:
            try:
                kouho.append(zerobig[jj] * 2 + zerosmall[k - jj - 2])
            except:
                continue
    #print(kouho)
    print(min(kouho))
    

### FIXED CODE ###

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

zerofrag = 0
zerobig = []
zerosmall = []

for i in a:
    if i == 0:
        zerofrag =1
    elif i > 0:
        zerobig.append(i)
    else:
        zerosmall.append(abs(i))

if k == 1 and zerofrag == 1:
    print(0)
else:
    if zerofrag == 1:
        k = k -1

    zerobig.sort()
    zerosmall.sort()
    #print(zerobig,zerosmall)
    kouho = []
    if len(zerobig) >=k:
        kouho.append(zerobig[k-1])
    if len(zerosmall) >=k:
        kouho.append(zerosmall[k-1])
        
    for ii in range(len(zerosmall)):
        if k - (ii) > len(zerobig):
            continue
        else:
            try:
                kouho.append(zerosmall[ii] * 2 + zerobig[k - ii - 2])
            except:
                continue
    for jj in range(len(zerobig)):
        if k - (jj ) > len(zerosmall):
            continue
        else:
            try:
                kouho.append(zerobig[jj] * 2 + zerosmall[k - jj - 2])
            except:
                continue
    #print(kouho)
    if zerofrag == 1:
        k = k + 1
    if kouho == [] :
        print(min( (max(zerosmall)*2 + max(zerobig)) ,  max(zerobig) * 2 + max(zerosmall)) )
    else:
        print(min(kouho))
from sys import stdin, gettrace
import sys
 
if not gettrace():
    def input():
        return next(stdin)[:-1]
 
 
# def input():
#    return stdin.buffer.readline()
 
def main():
    def mincost(n,h):
    	dp=[-1 for i in range(n)]
    	dp[n-1]=0
    	dp[n-2]=abs(h[n-2]-h[n-1])
    	for i in range(n-3,-1,-1):
        	mn=min(i+k+1,n)
        	mnm=sys.maxsize
        	for j in range(i+1,mn):
            	mnm=min(dp[j]+abs(h[j]-h[i]),mnm)
        	dp[i]=mnm    
    	return dp[0]

	n,k=map(int,input().split())
	h=[int(x) for x in input().split()]
	print(mincost(n,h))
 
 
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
def mincost(n,h):
    dp=[-1 for i in range(n)]
    dp[n-1]=0
    dp[n-2]=abs(h[n-2]-h[n-1])
    for i in range(n-3,-1,-1):
        dp[i]=min(dp[i+1]+abs(h[i+1]-h[i]),dp[i+2]+abs(h[i+2]-h[i]))
    return dp[0]    

n=int(input())
h=[int(x) for x in input().split()]
print(mincost(n,h))
while 1:
  a, b, c, d, e, f = map(int, raw_input().split())
  g = b / e
  x = (c - g * f) / (float(a) - g)
  y = (c - a * x) / float(b)
  print str(x) + " " + str(y)

### FIXED CODE ###

while 1:
    try:
        a, b, c, d, e, f = map(float, raw_input().split())
        x = (c * e - b * f) / (a * e - b * d)
        y = (f * a - c * d) / (a * e - d * b)
        if x == -0.000:
            x = 0.000
        if y == -0.000:
            y = 0.000
        print str('%.3f' % x) + " " + str('%.3f' % y)
    except:
        break
import math

N = int(input())
h = list(map(int, input().split()))
dp = [float('INF')] * N
INF = float('INF')
def chmin(a, b):
    if a >= b:
        return b
    else:
        return a

def DFS(i):
    if dp[i] < INF:
        return dp[i]
    
    if (i == 0):
        dp[i] = 0
        return 0
    
    res = INF
    res = chmin(INF, DFS(i-1) + abs(h[i] - h[i-1]))
    
    if i > 1:
        res = chmin(res, DFS(i-2) + abs(h[i] - h[i-2]))
        
    dp[i] = res
    return res
print(DFS(N-1))

### FIXED CODE ###

import math

N = int(input())
h = list(map(int, input().split()))
dp = [float('INF')] * N

def chmin(a, b):
    if a >= b:
        return b
    else:
        return a

#初期値
dp[0] = 0

#Loop
for i in range(1, N):
    dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if i > 1:
        dp[i] = chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
print(dp[-1])
def input_undirected_graph(V: int, E: int, origin: int = 1):
    graph = [list() for _ in range(V)]
    for i in range(E):
        u, v = [int(x) for x in input().split()]
        u -= origin
        v -= origin
        graph[u].append(v)
        graph[v].append(u)
    return graph


def main():
    N, Q = [int(x) for x in input().split()]
    graph = input_undirected_graph(N, N-1)

    vals = [0] * N
    for _ in range(Q):
        p, x = [int(x) for x in input().split()]
        vals[p-1] += x
    
    ans = [0] * N
    # stack = [(0, -1, 0)]  # node, par, val
    # while stack:
    #     node, par, val = stack.pop()
    #     ans[node] += vals[node] + val

    #     for child in graph[node]:
    #         if child == par:
    #             continue
    #         stack.append((child, node, ans[node]))

    def dfs(node, par, val):
        ans[node] += vals[node] + val
        for child in graph[node]:
            if child == par:
                continue
            dfs(child, node, ans[node])
    dfs(0,-1,0)

    for i in range(N):
        print(ans[i])
 
 
if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(20005)
    main()

### FIXED CODE ###

from collections import defaultdict, deque


def main():
    N, Q = map(int, input().split())

    tree = defaultdict(list)
    counter = defaultdict(int)
    for _ in range(N-1):
        a, b = map(int, input().split())
        tree[a].append(b)
        tree[b].append(a)
    for _ in range(Q):
        p, x = map(int, input().split())
        counter[p] += x

    # bfs
    q = deque([1])
    visited = {1}

    while q:
        i = q.popleft()

        for j in tree[i]:
            if j not in visited:
                q.append(j)
                counter[j] += counter[i]
                visited.add(j)

    counts = [counter[i] for i in range(1, N+1)]
    ans = " ".join(map(str, counts))
    print(ans)



if __name__ == '__main__':
    main()
print((a - 1) * (b - 1))

### FIXED CODE ###

a, b = map(int, input().split())
print((a - 1) * (b - 1))
import sys
x = 500000
f = [0, 1] * xx
i = 3

while i * i <= 2 * xx:
    if f[i] == 1:
        j = i * i
        while j <= 2 * xx:
            f[j] = 0
            j += i + i
    i += 2

f.pop(0)
f.pop(1)

for n in sys.stdin:
    i = int(n)
    if i < 2:
        print(0)
    else:
        print(sum(f[:i - 1]))

### FIXED CODE ###

import sys

f = [1, 0, 0, 0, 1, 0] * (1000000 // 6 + 1)
f = [0, 0, 1, 1] + f[3:-2]

i = 5
while i < 1000:
    if f[i] == 1:
        j = i * i
        while j <= 1000000:
            f[j] = 0
            j += i + i
    i += 2

for n in sys.stdin:
    i = int(n)
    print(sum(f[:i + 1]))
import bisect,sys
from itertools import *
n=range(50001);a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in map(int,sys.stdin):
 if x:print(len(1 for d in p[:bisect.bisect(p,x//2)]if a[x-d]))


### FIXED CODE ###

import bisect,sys
from itertools import *
n=range(50001);a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in map(int,sys.stdin):
 if x:print(len([1 for d in p[:bisect.bisect(p,x//2)]if a[x-d]]))
n = input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])
if a+b+c+d==7:
  print(a+"+"b+"+"+c+"+"+d+"=7")
elif a+b+c-d==7:
  print(a+"+"b+"+"+c+"-"+d+"=7")
elif a+b-c+d==7:
  print(a+"+"b+"-"+c+"+"+d+"=7")
elif a+b-c-d==7:
  print(a+"+"b+"-"+c+"-"+d+"=7")
elif a-b+c+d==7:
  print(a+"-"b+"+"+c+"+"+d+"=7")
elif a-b+c-d==7:
  print(a+"-"b+"+"+c+"-"+d+"=7")
elif a-b-c+d==7:
  print(a+"-"b+"-"+c+"+"+d+"=7")
else:
  print(a+"-"b+"-"+c+"-"+d+"=7")

### FIXED CODE ###

n = input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])
if a+b+c+d==7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif a+b+c-d==7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif a+b-c+d==7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif a+b-c-d==7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif a-b+c+d==7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif a-b+c-d==7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif a-b-c+d==7:
  print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
else:
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
s=list(input())
x=len(s)

for i range(1,x//2):
    s=s[:-2]
    if s[:len(s)//2==s[len(s)//2:]:
            break
print(len(s))


### FIXED CODE ###

s=list(str(input())
        )
for i in range(1,len(s)//2):
    s=s[:-2]
    if s[:len(s)//2]==s[len(s)//2:]:
        break
print(len(s))
a = [int(i) for i in input().split()]
a.sort()
b = [a[2]-a[1], a[1]-a[0], a[2]-[0]]
print(sum(b)-max(b))

### FIXED CODE ###

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

m = min(abs(a - b) + abs(b - c), abs(a - c) + abs(c - b), abs(b - a) + abs(a - c))
print(m)
n=int(input())
a=list(map(int,input().split()))
from numpy import cumsum
left_cumsum=cumsum(a)
a.reverse()
right_cumsum=cumsum(a)
ans=10000000000
for i in range(n-1):
    ans=min(ans,abs(left_cumsum[i]-right_cumsum[-i-2]))
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
left_ruiseki=[a[0]]
for i in range(1,n):
    left_ruiseki.append(left_ruiseki[i-1]+a[i])
a.reverse()
right_ruiseki=[a[0]]
for i in range(1,n):
    right_ruiseki.append(right_ruiseki[i-1]+a[i])

ans=10000000000
for i in range(n-1):
    ans=min(ans,abs(left_ruiseki[i]-right_ruiseki[-i-2]))
print(ans)
N,A,B = map(int,input().split())

ans = 0
for i in range(1,N+1):
  d = sum(list(map(int,list[str(i)])))
  if A <= d <= B:
    ans += 1

print(ans)


### FIXED CODE ###

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

ans = 0
for i in range(1,N+1):
  d = sum(list(map(int,list(str(i)))))
  if A <= d <= B:
    ans += i

print(ans)
a,op,b = map(string, input(),split())

if op == "-":
    print(int(a) - int(b))
else:
    print(int(a) + int(b))


### FIXED CODE ###

a,op,b = map(str, input().split())
if op == "+":
    print(int(a) + int(b))
else:
    print(int(a) - int(b))
from collections import deque


def bfs(S):  # 幅優先探索  # キュー
    dist = [-1] * (w * h)  # 前処理
    que = deque()
    for i, Si in enumerate(S):
        for j, Sij in enumerate(Si):
            if Sij == '#':
                dist[i + (w * j)] = 0
                que.append((i, j))

    while len(que) > 0:
        (x, y) = que.popleft()
        near = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
        for i, j in near:  # 移動先の候補
            if 0 <= i < h and 0 <= j < w and dist[i][j] < 0:
                dist[i + (w * j)] = dist[x + (w * y)] + 1
                que.append((i, j))
    return dist[x + (w * y)]


h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(bfs(a))


### FIXED CODE ###

from collections import deque


def bfs(S):  # 幅優先探索  # キュー
    dist = [[-1] * w for _ in range(h)]  # 前処理
    que = deque()
    for i, Si in enumerate(S):
        for j, Sij in enumerate(Si):
            if Sij == '#':
                dist[i][j] = 0
                que.append((i, j))

    while len(que) > 0:
        (x, y) = que.popleft()
        near = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
        for i, j in near:  # 移動先の候補
            if 0 <= i < h and 0 <= j < w and dist[i][j] < 0:
                dist[i][j] = dist[x][y] + 1
                que.append((i, j))
    return dist[x][y]


h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(bfs(a))
import sys
N, M = map(int, input().split())

C = []
S = []

for i in range(M):
    c, s = map(int, input().split())
    C.append(c)
    S.append(s)

for x in range(1000):
    keta = 1
    nx = x//10
    d = [x%10]


    while(nx):
        keta += 1
        d.append(nx%10)
        nx = nx // 10
    d = list(reversed(d))

    isOk = True
    
    for i in range(M):
        if( d[C[i]-1] != S[i-1] ):
            isOk = False

    if isOk :
        num = "".join(map(str, d))
        break

if isOk:
    print(num)
else:
    print(-1)

### FIXED CODE ###

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

ans = [0 for i in range(N)]
isTerms = [0 for i in range(N)]
jadge = True

for i in range(M):
    s, c = map(int, input().split())
    if( ans[s-1] != c and isTerms[s-1] != 0):
        jadge = False
    elif( s == 1 and c == 0):
        jadge = False
    else:
        ans[s-1] = c
        isTerms[s-1] = 1

if( N != 1 and ans[0] == 0 and jadge):
    ans[0] = 1

if( N == 1 and ans[0] == 0):
    jadge = True

if jadge:
    if(N==1):
        print(ans[0])
    else:
        for i in range(N-1):
            print(ans[i] ,end = "")
        print(ans[i+1])
else:
    print(-1)
N =input(int())
a =input(int())
print(N-a+1)

### FIXED CODE ###

N, i = map(int, input().split())
print(int(N-i+1))
a = input()
b = input()
if a < b:
   print a '<' b
if a > b:
   print a '>' b
print a '==' b

### FIXED CODE ###

a, b = map(int, raw_input().split())

if a < b:
    print 'a < b'
elif a > b:
    print 'a > b'
else:
    print 'a == b'
N = int(input())
A = list(map(int, input().split(" ")))

dp_dict = {}


def dp(i, j):
    print(i, j)
    if i >= N:
        return (-1*10e+9)-1
    if j == 1:
        return A[i]
    if (i, j) in dp_dict:
        return dp_dict[(i, j)]
    else:
        temp = max([dp(i+2, j-1)+A[i], dp(i+1, j)])
        dp_dict[(i, j)] = temp
        return temp


print(dp(0, (N//2)))

### FIXED CODE ###

N = int(input())
A = [0]+list(map(int, input().split(" ")))

dp_list = [{0, 0}, {0: 0, 1: A[1]}, {0: 0, 1: A[1] if A[1] > A[2] else A[2]}]

for i in range(3, N+1):
    b = (i-1)//2
    f = (i+1)//2
    dp_list.append({})
    for j in range(b, f+1):
        if j in dp_list[i-1]:
            dp_list[i][j] = dp_list[i-2][j-1]+A[i] if dp_list[i -
                                                              2][j-1]+A[i] > dp_list[i-1][j] else dp_list[i-1][j]
        else:
            dp_list[i][j] = dp_list[i-2][j-1]+A[i]

print(dp_list[-1][N//2])
n = int(input())
m = 1
ans = 0
while m <= sqrt(n):
    if n % m == 0 and m < n // m:
        ans += n // i - 1
    m += 1
print(ans)


### FIXED CODE ###

n = int(input())
ans = 0
for m in range(1, int(n**0.5)+1):
    if n%m == 0 and m < n//m-1:
        ans += n//m -1
print(ans)
"""
while m <= int(n**0.5):
    if n % m == 0 and m < n // m:
        ans += n // m - 1
    m += 1
print(ans)
"""
N = int(input())
list = list(map(int, input().split()))
print("Yes" if max(list) < (sum(list))-(max(list)) else "No"))

### FIXED CODE ###

N = int(input())
list = list(map(int, input().split()))
print("Yes" if 2*max(list) < sum(list) else "No")
import sys
import numpy as np

n=int(sys.stdin.readline())
h=np.array(sys.stdin.readline().split(),dtype='int64')
h=np.flip(h)
miss=0
for i in range(n):
    if i==0:
        pre=h[i]
    elif pre+1==h[i]:
        pass
    elif pre==h[i]:
        pass
    elif pre+1<h[i]:
        miss=1
        break
    else:
        pre=h[i]

if miss==1:
    print('No')
else:
    print('Yes')
    


### FIXED CODE ###

import sys
import numpy as np

n=int(sys.stdin.readline())
h=np.array(sys.stdin.readline().split(),dtype='int64')
h=h[::-1]
miss=0
for i in range(n):
    if i==0:
        pre=h[i]
    elif pre+1==h[i]:
        pass
    elif pre==h[i]:
        pass
    elif pre+1<h[i]:
        miss=1
        break
    else:
        pre=h[i]

if miss==1:
    print('No')
else:
    print('Yes')