Harryxun/stf_run huggingface dataset:
import sys
sys.setrecursionlimit(2000)
n,q=map(int,input().split())
e=[[] for _ in range(n)]
cnt=[0]*n
for _ in range(n-1):
  a,b=map(int,input().split())
  e[a-1].append(b-1)
  e[b-1].append(a-1)
for _ in range(q):
  x,y=map(int,input().split())
  cnt[x-1]+=y

def dfs(now,vis):
  vis.append(now)
  for i in e[now]:
    if i not in vis:
      cnt[i]+=cnt[now]
      dfs(i,vis)
dfs(0,[])
print(' '.join(map(str,cnt)))

### FIXED CODE ###

import sys
sys.setrecursionlimit(2000)
n,q=map(int,input().split())
e=[[] for _ in range(n)]
cnt=[0]*n
for _ in range(n-1):
  a,b=map(int,input().split())
  e[a-1].append(b-1)
  e[b-1].append(a-1)
for _ in range(q):
  x,y=map(int,input().split())
  cnt[x-1]+=y
vis=[1]*n
queue=[0]
vis[0]=0
while queue:
  now=queue.pop()
  for i in e[now]:
    if vis[i]:
      queue.append(i)
      cnt[i]+=cnt[now]
      vis[i]=0
print(' '.join(map(str,cnt)))
a=[int(input()) for _ in range()]
if sorted(a)==[5,5,7]:
  print("YES")
else:
  print("NO")


### FIXED CODE ###

a=list(map(int,input().split()))
print(['NO','YES'][a.count(5)==2 and a.count(7)==1])
def main():
    n, m = [int(x) for x in input().split()]
    global dp
    dp = [-1]*n
    grafo = [[] for _ in range(n)]

    for _ in range(m):
        x, y = [int(x) for x in input().split()]
        x -= 1
        y -= 1

        grafo[x].append(y)

    resp = 0
    for u in range(n):
        resp = max(dfs(u, grafo), resp)

    print(resp)
        

def dfs(u, grafo):
    global dp

    if len(grafo[u]) == 0:
        dp[u] = 0
        return dp[u]

    if dp[u] != -1:
        return dp[u]


    for v in grafo[u]:
        dp[u] = max(dfs(v, grafo) + 1, dp[u])

    return dp[u]
        
main()

### FIXED CODE ###

from collections import deque

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


grafo = [[] for i in range(n+1)]

num_adj = [0] * (n+1)

for i in range(m):
    u, v = map(int,input().split())
    grafo[u].append(v)
    num_adj[v] += 1

q = deque()

for i in range(1, n+1):
    if num_adj[i] == 0:
        q.append(i)

dp = [0] * (n + 1)

while q:
    n = q.popleft()
    for s in grafo[n]:
        num_adj[s] -= 1

        if num_adj[s] == 0:
            q.append(s)
            dp[s] = dp[n] + 1

print(max(dp))
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

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


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    n += 1
    a = list(map(int, input().split()))
    c = [0] * (n + 1)
    for i in range(n):
        c[i + 1] = c[i] + a[i]
    ans = [0] * n
    for i in range(n):
        ans[i] = c[n] - c[i]
    if n == 1 and a[0] == 0:
        print(-1)
        return
    if n > 1 and a[o] > 0:
        print(-1)
        return
    ans[0] = min(1, ans[0])
    for i in range(1, n):
        ans[i] = min(ans[i], (ans[i-1]-a[i-1]) * 2)
        if ans[i] < a[i]:
            print(-1)
            return

    print(sum(ans))
main()


### FIXED CODE ###

from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

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


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    n += 1
    a = list(map(int, input().split()))
    c = [0] * (n + 1)
    for i in range(n):
        c[i + 1] = c[i] + a[i]
    ans = [0] * n
    for i in range(n):
        ans[i] = c[n] - c[i]
    if n == 1 and a[0] == 0:
        print(-1)
        return
    if n > 1 and a[0] > 0:
        print(-1)
        return
    ans[0] = min(1, ans[0])
    if ans[0] < a[0]:
        print(-1)
        return
    for i in range(1, n):
        ans[i] = min(ans[i], (ans[i-1]-a[i-1]) * 2)
        if ans[i] < a[i]:
            print(-1)
            return

    print(sum(ans))
main()
s=input()
n=int(input())
rev=1
pre=''
suf=''

for i in range(n):
  q=input().split()
  if q[0]=='1':
    rev+=1
  elif (rev+int(q[1]))%2==0:
    pre=q[2]+pre
  else:
    suf=suf+q[2]
    
ans=pre+s+suf
  
if rev%2==0:
  ans.reverse()

print(ans)

### FIXED CODE ###

s=input()
n=int(input())
rev=1
pre=''
suf=''

for i in range(n):
  q=input().split()
  if q[0]=='1':
    rev+=1
  elif (rev+int(q[1]))%2==0:
    pre=q[2]+pre
  else:
    suf=suf+q[2]
    
ans=pre+s+suf
  
if rev%2==0:
  print(ans[::-1])
else:
  print(ans)
# AtCoder Beginner Contest 176
# C - Step

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

ans=0

for i in range (1,N):
    if Als[i]>=max(Als[0:i]):
        pass
    else :
        ans+= max(Als[0:i])-Als[i]
        print(i,Als[0:i],max(Als[0:i])-Als[i])
print(ans)

### FIXED CODE ###

# AtCoder Beginner Contest 176
# C - Step

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

ans=0

for i in range (1,N):
    if Als[i]>=Als[i-1]:
        pass
    else :
        step=abs(Als[i]-Als[i-1])
        ans+=step
        Als[i]+=step
print(ans)
S = str(input())
N = int(input())

print(S.count('ABC'))


### FIXED CODE ###

N = int(input())


S = str(input())

print(S.count('ABC'))
a = int(raw_input())
b = int(raw_input())

if a>b:
 print "a>b"
if a<b:
 print "a<b"
else:
 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"
choice = [1, 2, 3]
a = input()
b = input()
choice.remove(a)
choice.remove(b)
print(choice)

### FIXED CODE ###

c = ['1', '2', '3']
a = input()
b = input()
c.remove(a)
c.remove(b)
print(c[0])
n = int(input())
inp = list(map(int, input().split()))
length = len(inp)
ans = 0
curr_max = 0
for i in range(-1,-length,-1):
    if inp[i] <= inp[i-1]:
        ans += 1
        if ans > curr_max:
            curr_max = ans
    else:
        ans = 0
print(curr_max)

### FIXED CODE ###

s = input()
t = input()
ans = 0
for i in range(3):
    if s[i] == t[i]:
        ans += 1
print(ans)
n,m=map(int,input().split())

for i in range(1,int(m**0.5)+1):
    if m%i==0:
        if i<=m//n:
            tmp=i
        if i>=n:
            tmp=m//i
            print(tmp)
            sys.exit()
print(tmp)

### FIXED CODE ###

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

ans=0
for i in range(1,int(m**0.5)+1):
    if m%i==0:
        if i<=m//n:
            tmp=i
        if i>=n:
            tmp=m//i
        if tmp>ans:
            ans=tmp
print(ans)
import sys
args = sys.argv
radius = args[0]
print(radius * radius)

### FIXED CODE ###

radius = int(input())
print(radius * radius)
import numpy as np
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
p = np.array(p)

p_isorder = p[1:]>p[:-1]

ans = n - k + 1
no_change = False
for j in range(k-1):
    if not p_isorder[i+j]:
        break
else:
    no_change = True

for i in range(n-k):
    dec = False
    q = p[i:i+k+1]
    if (q.argmin()==0 and q.argmax()==k):
        ans -= 1
        dec = True
    
    for j in range(k-1):
        if not p_isorder[i+j+1]:
            break
    else:
        if no_change and not dec:
            ans -= 1
        no_change = True

print(ans)

### FIXED CODE ###

import numpy as np
import heapq

(n,k),p = [list(map(int, s.split())) for s in open(0)]

p_np = np.array(p)
p_cumsum = (p_np[1:]>p_np[:-1]).cumsum()

c = [False] * n

_min = p[:k].copy()
_max = [-x for x in p[:k]]
heapq.heapify(_min)
heapq.heapify(_max)

ans = n - k + 1
no_change = False
if p_cumsum[k-2]==k-1:
    no_change = True

for i in range(n-k):
    decrease = False
    
    heapq.heappush(_min, p[i+k])
    heapq.heappush(_max, -p[i+k])
    
    while c[_min[0]]:
        heapq.heappop(_min)
    while c[-_max[0]]:
        heapq.heappop(_max)
    
    if (_min[0]==p[i] and -_max[0]==p[i+k]):
        ans -= 1
        decrease = True
    
    c[p[i]] = True
    
    if p_cumsum[i]+k-1 == p_cumsum[i+k-1]:
        if no_change and not decrease:
            ans -= 1
        no_change = True

print(ans)
import sys
s = sys.stdin.readlines()
s = input() .split()
for i in range(1, len(s)):
    s.add(p[i])
print(len(set(s)))

### FIXED CODE ###

n = int(input())
p = [input() for i in range(n)]
s = set()
for i in range(n):
    s.add(p[i])
print(len(s))
# shortest path on line

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

graph = {i: {} for i in range(1, n + 1)}

for i in range(1, n):
    graph[i + 1][i] = 0

for _ in range(m):
    l, r, c = map(int, input().split())
    graph[l][r] = c


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

import heapq

def dijkstra(s, graph, n):
    # ｓからのグラフの最短最短距離をまとめたデータを返す
    dist = [10**20 for i in range(n + 1)]
    dist[s] = 0
    pq = []
    heapq.heapify(pq)
    # 全ての接点を一度優先度付きキューに挿入する
    heapq.heappush(pq, (0, s))
    while pq:
        x = heapq.heappop(pq)
        node, mini_dis = x[1], x[0]
        for point in graph[node].keys():
            w = graph[node][point]
            # nodeからpointに対して伸びる辺の長さ
            newlen = dist[node] + w
            if newlen < dist[point]:
                heapq.heappush(pq, (newlen, point))
                dist[point] = newlen

    return dist
###############################################################


a = dijkstra(1, graph, n)
if a[n]>=10**20:
    print(-1)
else:
    print(a[n])
    


### FIXED CODE ###

n=int(input())
print((n-1)//2)
a,b,t=map(int, input().split())
cnt=0
t+=0.5
for i in range(1,t,a):
    cnt+=b
print(cnt)

### FIXED CODE ###

a,b,t=map(int, input().split())
print(b*(t//a))
def main():
    import sys
    input=sys.stdin.readline
    n,s=map(int,input().split())
    A=list(map(int,input().split()))
    mod=998244353
    dp=[[0]*(s+1) for _ in range(n+1)]
    dp[0][0]=1
    for i in range(1,n+1):
        for j in range(s+1):
            a=A[n-i]
            if j-a>0:
                dp[i][j]=(dp[i-1][j]+dp[i-1][j-a])%mod
            elif j==a:
                dp[i][j]=(dp[i-1][j]+i)%mod
            else:
                dp[i][j]=dp[i-1][j]
    ans=0
    for i in range(1,n+1):
        a=A[i-1]
        ans=(ans+dp[n-i][s-a]*i)%mod
    print(ans)
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input=sys.stdin.readline
    n,s=map(int,input().split())
    A=list(map(int,input().split()))
    mod=998244353
    dp=[[0]*(s+1) for _ in range(n+1)]
    dp[0][0]=1
    for i in range(1,n+1):
        for j in range(s+1):
            a=A[n-i]
            if j-a>0:
                dp[i][j]=(dp[i-1][j]+dp[i-1][j-a])%mod
            elif j==a:
                dp[i][j]=(dp[i-1][j]+i)%mod
            else:
                dp[i][j]=dp[i-1][j]
    ans=0
    for i in range(1,n+1):
        a=A[i-1]
        if s>a:
            ans=(ans+dp[n-i][s-a]*i)%mod
        elif s==a:
            ans=(ans+(n-i+1)*i)%mod
    print(ans)
if __name__ == '__main__':
    main()
# B - K-th Common Divisor

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

def gcd(x, y):
    if x==0:
        return y
    else:
        return gcd(y%x, x)

gcdAB = gcd(A, B)

cdlist = [gcdAB]
for i in range(1, (int(gcdAB**0.5))+1)[::-1]:
    if gcdAB%1==0:
        cdlist.append(i)

print(cdlist[K-1])

### FIXED CODE ###

# B - K-th Common Divisor

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

cnt = 0
for i in range(1, min(A, B)+1)[::-1]:
    if A%i==0 and B%i==0:
        cnt += 1
        if cnt==K:
            print(i)
            break
import numpy as np
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
p = np.array(p)

p_isorder = p[1:]>p[:-1]

ans = n - k + 1
no_change = False
if p_isorder[:k-1].all():
    no_change = True

for i in range(n-k):
    dec = False
    q = p[i:i+k+1]
    if (q.argmin()==0 and q.argmax()==k):
        ans -= 1
        dec = True
    
    if p_isorder[i+1:i+k].all():
        if no_change and not dec:
            ans -= 1
        no_change = True

print(ans)

### FIXED CODE ###

import numpy as np
import heapq

(n,k),p = [list(map(int, s.split())) for s in open(0)]

p_np = np.array(p)
p_cumsum = (p_np[1:]>p_np[:-1]).cumsum()

c = [False] * n

_min = p[:k].copy()
_max = [-x for x in p[:k]]
heapq.heapify(_min)
heapq.heapify(_max)

ans = n - k + 1
no_change = False
if p_cumsum[k-2]==k-1:
    no_change = True

for i in range(n-k):
    decrease = False
    
    heapq.heappush(_min, p[i+k])
    heapq.heappush(_max, -p[i+k])
    
    while c[_min[0]]:
        heapq.heappop(_min)
    while c[-_max[0]]:
        heapq.heappop(_max)
    
    if (_min[0]==p[i] and -_max[0]==p[i+k]):
        ans -= 1
        decrease = True
    
    c[p[i]] = True
    
    if p_cumsum[i]+k-1 == p_cumsum[i+k-1]:
        if no_change and not decrease:
            ans -= 1
        no_change = True

print(ans)
def input(): return sys.stdin.readline().strip()

def resolve():
    x=int(input())
    l=[]
    for i in range(1,33):
        for j in range(1,11):
            if i**j>=x:
                l.append(i**(j-1))
                break
    print(max(l))
resolve()

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    x=int(input())
    l=[]
    for i in range(1,33):
        for j in range(2,11):
            y=i**j
            if y<x:
                l.append(y)
            elif y==x:
                l.append(y)
                break
            else:
                break
    print(max(l))
resolve()
# encoding: utf-8
A, B, C, D, E, F = map(int, input().split())

max_rate = -1
ans = None
for i in range(30 // A + 1):
    for j in range(30 // B + 1):
        water = A * i + B * j
        # escape
        if water == 0: continue
        elif 100 * water > F: break
        elif (F - 100 * water) / water < max_rate: continue
        # search
        salt_upper = int(E * water)
        max_rate_tmp = 0
        ans_tmp = None
        for l in list(range(salt_upper // D + 1))[::-1]:
            salt = ((salt_upper - l * D) // C) * C + l * D
            rate_tmp = salt / water
            if rate_tmp == E:
                if 100 * water + salt > F: continue
                ans_tmp = (i, j, ((salt_upper - l * D) // C), l)
                break
            elif rate_tmp > max_rate_tmp:
                if 100 * water + salt > F: continue
                ans_tmp = (i, j, ((salt_upper - l * D) // C), l)
                max_rate_tmp = rate_tmp
                continue
            else:
                continue
        # end loop
        if ans_tmp == None: continue
        if max_rate_tmp > max_rate:
            ans = ans_tmp
            max_rate = max_rate_tmp
        if max_rate == E: break
    if max_rate == E: break

salt = C * ans[2] + D * ans[3]
water = 100 * (A * ans[0] + B * ans[1])
    
print(salt + water, salt)


### FIXED CODE ###

# encoding: utf-8
A, B, C, D, E, F = map(int, input().split())

max_rate = 0
ans = (1, 0, 0, 0)
for i in range(30 // A + 1):
    for j in range(30 // B + 1):
        water = A * i + B * j
        # escape
        if water == 0: continue # avoid 0 div.
        elif 100 * water > F: break
        elif (F - 100 * water) / water < max_rate: continue
        # search (safer version)
        salt_upper = int(E * water)
        max_rate_tmp = 0
        ans_tmp = None
        for k in list(range(salt_upper // C + 1))[::-1]:
            for l in list(range(salt_upper // D + 1))[::-1]:
                salt = k * C + D * l
                # escape
                if salt == 0: continue
                elif salt / water > E: continue
                elif salt + 100 * water > F: continue
                # judge (only for max l)
                if salt / water > max_rate_tmp:
                    ans_tmp = (i, j, k, l)
                    max_rate_tmp = salt / water
                break
        # end loop
        if max_rate_tmp == 0: continue
        elif max_rate_tmp > max_rate:
            ans = ans_tmp
            max_rate = max_rate_tmp
        if max_rate == E: break
    if max_rate == E: break

salt = C * ans[2] + D * ans[3]
water = 100 * (A * ans[0] + B * ans[1])
    
print(salt + water, salt)
n = int(input())
a=[]
for i in range(n):
  x,y = input().split()
  a.append([x,-int(y),i+1])
a.sort()
for i in range(n):
  print(a[i][2])

### FIXED CODE ###

A,N = map(int,input().split())
print((3*A+N)//2)
n i = map(int,input().split())
print((n - i) + 1)


### FIXED CODE ###

n, i = map(int,input().split())
print((n - i) + 1)
list=[int(i) for i in input().split()]
a=0
for i in list:
    if i==1:
        a=a+1
    elif:
        a=a+0
print(a)

### FIXED CODE ###

print(input().count('1'))
#coding:utf-8

I=raw_input()
n,k=map(int, I.split(" "))

def f(n):
    if n==3:return 2
    if n%2==0:return f(n-1)
    return f(n-1)+1

if f(n)>=k:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

#coding:utf-8

I=raw_input()
n,k=map(int, I.split(" "))

def f(n):
    if n<3:return 0
    if n==3:return 2
    if n%2==0:return f(n-1)
    return f(n-1)+1

if f(n)>=k or k==1:
    print("YES")
else:
    print("NO")
N = int(input())
l = [list(map(int, input().split())) for l in range(N)]
    
for i in range(len(l)):
  if l[i][0]==l[i][1]:
    if l[i+1][0]==l[i+1][1]:
      if l[i+2][0]==l[i+2][1]:
        print('Yes')
      else:
        print('No')
    else:
      print('No')
        
  else:
    print('No')

### FIXED CODE ###

def judge():
    cnt = 0  # 今何連続でゾロ目が出ているか記録しておきます
 
    for _ in range(N):
        x, y = map(int, input().split())
        if x == y:
            # ゾロ目ストリークが1増えました
            cnt += 1
        else:
            # ゾロ目ストリークが切れました
            cnt = 0
 
        if cnt == 3:
            # 3連続になった瞬間、return True していいです
            return True
    
    # ダメでした
    return False
 
N = int(input())
 
if judge():
    print("Yes")
else:
    print("No")
A,B=int(int,input().split())
m=A-2*B
if m<0:
  print(0)
else:
  print(m)

### FIXED CODE ###

A,B=map(int,input().split())
m=A-2*B
if m<0:
  print(0)
else:
  print(m)
n=input()
print(n+n*n+n*n*n)

### FIXED CODE ###

n=int(input())
print(n+n*n+n*n*n)
li = []
lis = []
time = 0
for i in range(5):
    li.append(int(input()))
    lis.append(li[i] % 10)
lista = sorted(lis)
for i in range(5):
    if lista[i] != 0:
        a = lista[i]
        break
last = lis.index(a)
for i in range(5):
    if i == last:
        continue
    elif lis[i] == 0:
        time += li[i]
    elif 1 <= li[i] <= 9:
        time += 10
    else:
        time += int(li[i] / 10) * 10 + 10
print(time + li[last])

### FIXED CODE ###

import itertools
C = []
for i in range(5):
    C.append(int(input()))

ans = float("inf")
for order in itertools.permutations(C, 5):
    total = 0
    for c in order:
        if total % 10 != 0:
            total = (total // 10 + 1) * 10
        total += c

    ans = min(total, ans)

print(ans)
a, b, c = input.split()

print(str(a[0]) + str(b[1]) + str(c[2]))

### FIXED CODE ###

a = input()
b = input()
c = input()
print(a[0] + b[1] + c[2])
N, M = [int(n) for n in input().split()]
 X = sorted([int(n) for n in input().split()])

 if N >= M:
     print(0)
 else:
     diff = []
     for i in range(len(X) - 1):
         diff.append(X[i+1] - X[i])

     diff = list(reversed(sorted(diff)))
     s = 0

     for i in range(N - 1):
         s += diff[i]
     answer = X[-1] - X[0] - s
     print(answer)

### FIXED CODE ###

N, M = [int(n) for n in input().split()]
X = sorted([int(n) for n in input().split()])

answer = 0

if N >= M:
    pass
else:
    diff = []
    for i in range(len(X) - 1):
        diff.append(X[i+1] - X[i])

    diff = list(reversed(sorted(diff)))
    s = 0
    for i in range(N - 1):
        s += diff[i]
    answer = X[-1] - X[0] - s

print(answer)
from functools import lru_cache


@lru_cache(maxsize=1000)
def attack(h, mp):
    """
    毎回Nパターン選択肢がある
    最小値を返す
    """
    min_mp = 999999
    for a, b in sorted_ab_list:
        new_h = h - a
        new_mp = mp + b

        if new_mp >= min_mp:
            # 既に最小値超えてたら中断
            continue

        if new_h > 0:
            min_mp = min(min_mp, attack(new_h, new_mp))
        else:
            min_mp = min(min_mp, new_mp)

    # 最小値をとる
    return min_mp


if __name__ == '__main__':
    H, N = list(map(int, input().split()))
    AB_list = []
    for n in range(N):
        a, b = list(map(int, input().split()))
        AB_list.append([a, b])

    sorted_ab_list = sorted(AB_list, key=lambda x: x[0]/x[1], reverse=True)

    print(attack(H, 0))

### FIXED CODE ###

import sys

H, N = list(map(int, input().split()))
AB = [list(map(int, input().split())) for n in range(N)]

dp = [sys.maxsize for i in range(H+1)]
dp[0] = 0

# 各ダメージ段階の最小値を求める
for i in range(H):
    if dp[i] == sys.maxsize:
        continue
    # 各魔法を使って最小値なら更新
    for j in range(N):
        a = min(i + AB[j][0], H)
        b = dp[i] + AB[j][1]
        if dp[a] > b:
            dp[a] = b

print(dp[H])
a,b,c,d,e,f=map(int,input().split())
x=set()
y=set()
m=f//(100*a)
for i in range(m+1):
  for j in range((m-i*a)//(100*b)+1):
    x1=i*100*a+j*100*b
    if x1<=f:
      x.add(x1)

m=int(f*(e/100))
for i in range(0,m+1,c):
  for j in range(0,m-i+1,d):
     y.add(i+j)
x.remove(0) 
z=[-1]
ans=[]
for i in x:
  for j in y:
    if i+j<=f and j*100/(i+j)<=e*100/(100+e):
      if j*100/(i+j)>max(z):
        z.append(j*100/(i+j))
        ans.append([i+j,j])
        
print(ans[-1][0],ans[-1][1])
print(x)


### FIXED CODE ###

a,b,c,d,e,f=map(int,input().split())
x=set()
y=set()
m=f//(100*a)
for i in range(m+1):
  for j in range(f//(100*b)+1):
    x1=i*100*a+j*100*b
    if x1<=f:
      x.add(x1)

m=int(f*(e/100))
for i in range(0,m+1,c):
  for j in range(0,m-i+1,d):
     y.add(i+j)
x.remove(0) 
z=[-1]
ans=[]
for i in x:
  for j in y:
    if i+j<=f and j*100/(i+j)<=e*100/(100+e):
      if j*100/(i+j)>max(z):
        z.append(j*100/(i+j))
        ans.append([i+j,j])
        
print(ans[-1][0],ans[-1][1])
H, W, A, B = map(int, input().split())

total = 0
tmp1, tmp2 = 1, 1		# 初期化
tmp3, tmp4 = 1, 1		# 初期化
for i in range(B,W,1):
  conv1, conv2 = 0, 0	# 初期化
  if i == B:
    for j in range(i):
      tmp1 *= i+(H-A-1)-j
    tmp1 %= (10**9+7)
    for j in range(i, 0, -1):
      tmp2 *= j
    tmp2 %= (10**9+7)
  else:
    tmp1 *= i+(H-A-1)
    tmp1 %= (10**9+7)
    tmp2 *= i
    tmp2 %= (10**9+7)
  conv1 = tmp1/tmp2
  
  if i == B:
    for j in range(W-1-i):
      tmp3 *= (A-1)+(W-1-i)-j
    tmp3 %= (10**9+7)
    for j in range(W-1-i, 0, -1):
      tmp4 *= j
    tmp4 %= (10**9+7)
  else:
    tmp3 *= W-1-i+1
    tmp3 %= (10**9+7)
    tmp4 *= (A-1)+(W-1-i)+1
    tmp4 %= (10**9+7)
  conv2 = tmp3/tmp4
  total += conv1*conv2
print(int(total))

### FIXED CODE ###

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

if (A == 5 and B == 5 and C == 7) or (A == 5 and B == 7 and C == 5) or (A == 7 and B == 5 and C == 5):
  print('YES')
else:
  print('NO')
def calc(c1,c2,c3,c4):
    return c1*10 + c2*50 + c3*100 + c4*500

def coindiff(p,c1,c2,c3,c4):
    n = c1+c2+c3+c4
    over = calc(c1,c2,c3,c4) - p
    n -= (over%50) // 10
    n -= (over%100) // 50
    n -= (over%500) // 100
    n -= over // 500
    return n

while True:
    N = int(input())
    if N == 0: break
    c1,c2,c3,c4 = map(int,input().split())
    s1 = (N//10) % 5
    maxdiff = -9999999
    ans = None
    for n1 in range(s1,c1+1,5):
        for n2 in range(c2+1):
            for n3 in range(c3+1):
                rem = (N - n1*10 - n2*50 - n3*100)
                n4 = max(0, (rem-1)//500 + 1)
                d = coindiff(N,n1,n2,n3,n4)
                if d > maxdiff:
                    maxdiff = d
                    ans = {10:n1,50:n2,100:n3,500:n4}
    for k,v in sorted(ans.items()):
        print('{0} {1}'.format(k, v))
    print('')

### FIXED CODE ###

first = True
while True:
    P = int(input())
    if P== 0: break
    if first:
        first = False
    else:
        print('')
    c1,c2,c3,c4 = map(int,input().split())
    v = c1*10 + c2*50 + c3*100 + c4*500
    n = c1 + c2 + c3 + c4
    ans = {}
    rem = v - P
    ans[10] = c1 - (rem//10) % 5
    ans[50] = c2 - (rem//50) % 2
    ans[100] = c3 - (rem//100) % 5
    ans[500] = c4 - rem//500
    for k,v in sorted(ans.items()):
        if v <= 0: continue
        print('{0} {1}'.format(k,v))