Harryxun/stf_run huggingface dataset:
#!/usr/bin/env python3
import sys
import numpy as np

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    A = [[int()] * (M+1) for _ in range(N)] # type: "List[int]"

    for i in range(N):
        A[i] = [int(next(tokens)) for _ in range(M+1)]
    
    # print(A)

    A = np.array(A)
    min_c = [10000000]

    def dfs(k, dep):
        if dep == N-1:
            if (k[1:]>=X).all():
                min_c[0] = min(min_c[0], k[0])
            elif (k[1:]+A[dep][1:]>=X).all():
                min_c[0] = min(min_c[0], k[0]+A[dep][0])
        else:
            dfs(k+A[dep],dep+1)
            dfs(k,dep+1)

    dfs(A[0], 1)          
    dfs(np.zeros(M+1), 1)
    
    if min_c[0] != 10000000:
        print(int(min_c[0]))
    else:
        print(-1)




if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import numpy as np

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    A = np.zeros((N,M+1))
    for i in range(N):
        A[i] = [int(next(tokens)) for _ in range(M+1)]
    
    min_c = [10000000]

    def dfs(k, dep):
        if dep == N-1:
            if (k[1:]>=X).all():
                min_c[0] = min(min_c[0], k[0])
            elif ((k+A[dep])[1:]>=X).all():
                min_c[0] = min(min_c[0], k[0]+A[dep][0])
        else:
            dfs(k+A[dep],dep+1)
            dfs(k,dep+1)
    
    dfs(np.zeros(M+1), 0)
    
    if min_c[0] != 10000000:
        print(int(min_c[0]))
    else:
        print(-1)




if __name__ == '__main__':
    main()
n,m=map(int,input().split())
lip,lis=[],[]
old=0
ansa=0
wa=0
for i in range(1,m):
    p,s=input().split()
    lip.append(p)
    lis.append(s)
    if len(lip)==1:
        if s=="AC": #1問目がACの時
            ansa+=1
            old=lip[0]
        else:
            wa+=1
    elif old!=p:
        if s=="AC":#その問題で初めてのAC
            ansa+=1
            old=p #最後のACの問題番号 = old
            ansb=wa #その問題のペナが反映
        else:
            wa+=1
    else:
        wa=0
print(ansa,ansb)

### FIXED CODE ###

n,m=map(int,input().split())
acs=[0]*n
was=[0]*n
WA=0
for i in range(m):
    p,s=input().split()
    p=int(p)
    if acs[p-1]==0:
        if s=="AC":
            acs[p-1]=1
            WA+=was[p-1]
        else:
            was[p-1]+=1
print(sum(acs),WA)
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n,k,q = i2()
ls = [k-q]*n 
for _ in range(q):
	a = i()
	ls[a-1] += 1 

for _ in range(n):
	if ls[j] > 0:
		print("Yes")
	else:
		print("No")

### FIXED CODE ###

def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n,k,q = i2()
ls = [k-q]*n 
for _ in range(q):
	a = i()
	ls[a-1] += 1 

for j in range(n):
	if ls[j] > 0:
		print("Yes")
	else:
		print("No")
N = int(input())
str_input = input()
 
if N % 2 != 0:
  print('No')
else:
  print('Yes') if str_input[:N/2] == str_input[(N/2):] else print('No')

### FIXED CODE ###

N = input()
S = input()
index = len(S) // 2

if len(S) % 2 != 0:
  print('No')
elif S[:index] != S[index:]:
  print('No')
else:
  print('Yes')
#! -*- coding:utf-8 -*-

def search(values,hp,vp,fruit):
    if not (0<=hp<len(values)): return
    if not (0<=vp<len(values[hp])): return
    if fruit!=values[hp][vp]: return
    values[hp][vp]=0
    search(values,hp-1,vp,fruit)
    search(values,hp+1,vp,fruit)
    search(values,hp,vp-1,fruit)
    search(values,hp,vp+1,fruit)

def solve(values):
    count=0
    for i in range(len(values)):
        for j in range(len(values[i])):
            if values[i][j] in ['@','#','*']:
                search(values,i,j,values[i][j])
                count+=1
    return count

def main():
    line,values=input(),list()
    while line!='0 0':
        H,W = list(map(int,line.split(' ')))
        value = list()
        for _ in range(H):
            value.append([x for x in input().strip()])
            values.append(value)
    for value in values:
        print(solve(value))

if __name__=='__main__':
    main():

### FIXED CODE ###

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

import sys
sys.setrecursionlimit(10**6)

def search(field,hp,vp,item):
	if not (0<=hp<len(field)): return
	if not (0<=vp<len(field[hp])): return
	if item!=field[hp][vp]: return
	field[hp][vp]=True
	for dh,dv in [[0,1],[0,-1],[1,0],[-1,0]]:
		search(field,hp+dh,vp+dv,item)
#	search(field,hp-1,vp,item)
#	search(field,hp+1,vp,item)
#	search(field,hp,vp-1,item)
#	search(field,hp,vp+1,item)

def solve(field):
	count,valid_items=0,set(['@','#','*'])
	for i in range(len(field)):
		for j in range(len(field[i])):
			if field[i][j] in valid_items:
				search(field,i,j,field[i][j])
				count+=1
	return count

def main():
	line = input().strip()
	while line!='0 0':
		H,W = list(map(int,line.split(' ')))
		field = list()
		for _ in range(H):
			field.append(list(input().strip()))
		print(solve(field))
		line = input().strip()

if __name__=='__main__':
	main()
def main():
    k = int(input())
    r = 0
    for ia in range(1, k + 1):
        for ib in range(1, k + 1):
            for ic in range(1, k + 1):
                t1 = gcd(ib, ic)
                r += gcd(t1,ia)
    print(r)

if __name__ == '__main__':
    main()

### FIXED CODE ###

from math import gcd
def main():
    k = int(input())
    r = 0
    for ia in range(1, k + 1):
        for ib in range(1, k + 1):
            for ic in range(1, k + 1):
                t1 = gcd(ib, ic)
                r += gcd(t1,ia)
    print(r)

if __name__ == '__main__':
    main()
import random
n=int(input())
a=input().split(' ')

count = 0
for i in range(n-1):
	if a[i]==a[i+1]:
		count+=1
		if i<n-1:
			while True:
				a[i+1]=random.randint(1,n)
				if a[i+1]!=a[i+2]:
					 break
				else:
					continue
print(count)

### FIXED CODE ###

n=int(input())
a=input().split(' ')

count = 0
i=0
while i<n-1:
	if a[i]==a[i+1]:
		count+=1
		i+=2
	else:
		i+=1
print(count)
S, T = map(input().split())
A, B = map(int, input().split())
U = input()
if S=U:
  print("{} {}".format(S-1,T))
else:
  print("{} {}".format(S,T-1)


### FIXED CODE ###


S, T = input().split()
A, B = map(int, input().split())
U = input()
if S==U:
  print("{} {}".format(A-1,B))
else:
  print("{} {}".format(A,B-1))
N, W = map(int, raw_input().split())

v = [0] * N
w = [0] * N

for i in range(N):
    v[i], w[i] = map(int, raw_input().split())


def rec(i, j):
    if i == N:
        res = 0
    elif j < w[i]:
        res = rec(i + 1, j)
    else:
        res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i])
    return res

print(rec(0, W))

### FIXED CODE ###

N, W = map(int, raw_input().split())

v = [0] * N
w = [0] * N
dp = [[0 for i in range(W + 1)] for j in range(N + 1)]

for i in range(N):
    v[i], w[i] = map(int, raw_input().split())

for i in range(N - 1, -1, -1):
    for j in range(W + 1):
        if j < w[i]:
            dp[i][j] = dp[i + 1][j]
        else:
            dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i])

print(dp[0][W])
n = int(input()) 
#n=3
lst = [int(i) for i in input().split()]
#lst = [2, 10, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [1000000000, 1000000000, 1000000000]
hps = set(lst)
while(1):
    hps = sorted(hps)
    #print(hps)
    if(hps[0]==0): break
    if(hps[0]==hps[n-1]): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

### FIXED CODE ###

def gcd(a,b):
    r = a%b
    #print(a,b,r)
    if(r==0): return b
    return gcd(b,r)
n = int(input()) 
#n=4
hps = [int(i) for i in input().split()]
#lst = [2, 2, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [0, 1, 0]
    ##2 4 5 -> 1
    ## minと全ての要素のgcd
hps = sorted(hps)
for i in range(1,n):
    hps[0] = gcd(hps[i], hps[0])
#print(hps)
for i in range(len(hps)):
    if(hps[i]==0): continue
    print(hps[i])
    break
N = int(input())
S1 = list(input())
S2 = list(input())
i = 0


if S1[i] != S2[i]:
    res = 6
    i+=2
    rear = 1
else :
    res = 3
    i+=1
    rear = 0

while i != (N-1):
    if S1[i] != S2[i]:
        if rear == 1:
            res *= 3
        else:
            res *= 2
        rear = 1
        i += 2

    else:
        if rear == 0:
            res *= 2
        i += 1
        rear = 0


print(res%1000000007)

### FIXED CODE ###

N = int(input())
S1 = list(input())
S2 = list(input())
i = 0


if S1[i] != S2[i]:
    res = 6
    i+=2
    rear = 1
else :
    res = 3
    i+=1
    rear = 0

while i != N:
    if S1[i] != S2[i]:
        if rear == 1:
            res *= 3
        else:
            res *= 2
        rear = 1
        i += 2

    else:
        if rear == 0:
            res *= 2
        i += 1
        rear = 0


print(res%1000000007)
s = intput()
if(s[1]=='B'): print('ARC')
else: print('ABC')

### FIXED CODE ###

s = input()
if(s[1]=='B'): print('ARC')
else: print('ABC')
s = str(input())
S = [int(s[i]) for i in range(len(s))]
K = int(input())
ans = 1
for i in S:
    if S[i] != 1:
        ans = S[i]
        break
print(ans)

### FIXED CODE ###

s = str(input())
S = [int(s[i]) for i in range(len(s))]
K = int(input())
ans = 1
count = 0
for i in range(min(len(S),K)):
    if S[i] != 1 and count == 0:
        ans = S[i]
        count += 1
        break
print(ans)
import collections
n = int(input())
S = [list(input()) for i in range(n)]
Sc = [collections.Counter(i) for i in S]

counter = Sc[0] & Sc[1]
for i in range(2, len(Sc)):
    counter = counter & Sc[i]

Sclist = list(counter.elements())
Sclist.sort()
ans = "".join(Sclist)
print(ans)


### FIXED CODE ###

import collections
n = int(input())
S = [list(input()) for i in range(n)]
Sc = [collections.Counter(i) for i in S]


if n == 1:
    S[0].sort()
    ans = "".join(S[0])
    print(ans)
else:
    counter = Sc[0] & Sc[1]
    for i in range(2, len(Sc)):
        counter = counter & Sc[i]

    Sclist = list(counter.elements())
    Sclist.sort()
    ans = "".join(Sclist)

    print(ans)
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

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

A, B, C = S_LIST()
if A[-1] == B[0] and B[-1] = C[0]:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

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

A, B, C = S_LIST()
if A[-1] == B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")
Q = int(input())

def is_prime(n):
    if n == 1: return False
    for k in range(2, int(n**0.5)+1):
        if n % k == 0:
            return 0
    return n

prime_numbers = [is_prime(i) for i in range(2, 10**5 + 1) if is_prime(i) != 0]
same = [0]*(10**5 + 1)
for n in prime_numbers:
    if (n+1) // 2 in prime_numbers:
        same[n] += 1

for i in range(10**5):
    same[i+1] += same[i]

ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    N = same[r] - same[l-1]
    ans.append(N)

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


### FIXED CODE ###

m=int(input())
print(48-m)
n, d = map(int,input().split())
print(math.ceil(n/(2*d+1)))

### FIXED CODE ###

import math
n, d = map(int,input().split())
print(math.ceil(n/(2*d+1)))
S = input()
i = 0
for i in range(len(S))
    if S[i] != S[i+1]:
      print('Yes)
    else:
      print('No')
    

### FIXED CODE ###

S = input()
count = 0
for i in range(len(S)-1):
    if S[i] != S[i+1]:
      count+=1
    else:
      continue
if count>=1:
  print('Yes')
else:
  print('No')
import numpy as np
N, W = map(int, input().split())
w, v = [], []
for i in range(N):
    a, b = map(int, input().split())
    w += [a]
    v += [b]

DP = np.zeros(W+1, dtype=int)
# i 円以下で買える商品の最大価値
for i in range(N):
    DP[w[i]:] = np.maximum(DP[:-w[i]]+ v[i], DP[w[i]:])
print(DP[-1])

### FIXED CODE ###

import numpy as np
N, W = map(int, input().split())
w, v = [], []
for i in range(N):
    a, b = map(int, input().split())
    w += [a]
    v += [b]
 
DP = np.ones(N*1000+1, dtype=int) *(W+1)
DP[0] = 0
#総価値 i 円を得るために最低限必要な重量
for i in range(N):
    DP[v[i]:] = np.minimum(DP[:-v[i]]+ w[i], DP[v[i]:])
ans = 0
for k in range(N*1000+1):
    if DP[k] <= W:
        ans = k
        
print(ans)
import sys
import math


def main():
    input = sys.stdin.readline
    a, b = (int(i) for i in input().split())
    if a <= b:
        print("unsafe")
    else:
        print("safe)


main()


### FIXED CODE ###

import sys
import math


def main():
    input = sys.stdin.readline
    a, b = (int(i) for i in input().split())
    if a <= b:
        print("unsafe")
    else:
        print("safe")


main()
N,K,C=map(int,input().split())
S=list(input())
if S=="o" and K==1:
    print(1)
    exit()
#print(S)
F=[]
cnt=C
num=1
for i in range(N):
    if cnt>=C and S[i]=="o":
        F.append([num,i])
        num+=1
        cnt=0
    else:
        F.append([F[-1][0],F[-1][1]])
        cnt+=1
#print(F)
E=[]
RS=S[::-1]
cnt=C
num=1
for i in range(N):
    if cnt>=C and S[N-i-1]=="o":
        E.append([num,N-1-i])
        num+=1
        cnt=0
    else:
        E.append([E[-1][0],E[-1][1]])
        cnt+=1
E=E[::-1]
#print(E)
ans=[]
for i in range(N):
    if i==0:
        if E[i+1][0]<K:
            ans.append(1)
    elif i==N-1:
        if F[i-1][0]<K:
            ans.append(N)
    else:
        cnt=F[i-1][0]+E[i+1][0]
        if E[i+1][1]-F[i-1][1]<C:
            cnt-=1
        if cnt<K:
            ans.append(i+1)
#print(ans)
if len(ans)==0:
    print("")
    exit()
for i in range(len(ans)):
    print(ans[i])

### FIXED CODE ###

N,K,C = map(int,input().split())
S = list(input())
F = []
maru = 0
last = -10**9
span = C
for i in range(N):
    if S[i]=="o" and span >= C:
        maru += 1
        last = i
        F.append([maru,last])
        span = 0
    else:
        span += 1
        F.append([maru,last])
#print(F)
s = S[::-1]
maru = 0
last = 10**9
span = C
E = []
for i in range(N):
    if s[i] == "o" and span >= C:
        maru += 1
        last = N-1-i
        E.append([maru,last])
        span = 0
    else:
        E.append([maru,last])
        span += 1
E = E[::-1]
#print(E)
F = [[0,-10**9]] + F + [[0,10**9]]
E = [[0,-10**9]] + E + [[0,10**9]]
#print(F)
#print(E)
ans = []
for i in range(1,N+1):
    cnt = F[i-1][0] + E[i+1][0]
    
    if S[i-1] == "o":
        if E[i+1][1] - F[i-1][1] < C:
            cnt -= 1
        if cnt == K-1:
            ans.append(i)
    #print(F[i-1],E[i+1],cnt)
for i in range(len(ans)):
    print(ans[i])
i = input().split()
i = [int(j) for j in i]

flg = 0
for a in range(i[0]):
  if 2*a+4*b==i[1]:
    print("Yes")
    flg = 1
    
if flg==0:
  print("No")

### FIXED CODE ###

i = input().split()
i = [int(j) for j in i]
 
flg = 0
for a in range(i[0]+1):
  if 2*a+4*(i[0]-a)==i[1]:
    print("Yes")
    flg = 1
    
if flg==0:
  print("No")
// C/C++ キーワード定義ファイル データ型
// cpp_kw1_datatypes.kwd
//
//  Created on: 2015/06/13
//      Author: KeitetsuWorks
// CASE=True

ATOM
BOOL
BOOLEAN
BYTE
CHAR
COLORREF
DWORD
DWORD32
DWORD64
DWORDLONG
DWORD_PTR
FILE
FLOAT
HACCEL
HALF_PTR
HANDLE
HBITMAP
HBRUSH
HCOLORSPACE
HCONV
HCONVLIST
HCURSOR
HDC
HDDEDATA
HDESK
HDROP
HDWP
HENHMETAFILE
HFILE
HFONT
HGDIOBJ
HGLOBAL
HHOOK
HICON
HINSTANCE
HKEY
HKL
HLOCAL
HMENU
HMETAFILE
HMODULE
HMONITOR
HPALETTE
HPEN
HRESULT
HRGN
HRSRC
HSZ
HWINSTA
HWND
INT
INT32
INT64
INT_PTR
LANGID
LCID
LCTYPE
LGRPID
LONG
LONG32
LONG64
LONGLONG
LONG_PTR
LPARAM
LPBOOL
LPBYTE
LPCOLORREF
LPCSTR
LPCTSTR
LPCVOID
LPCWSTR
LPDWORD
LPHANDLE
LPINT
LPLONG
LPSTR
LPTSTR
LPVOID
LPWORD
LPWSTR
LRESULT
PBOOL
PBOOLEAN
PBYTE
PCHAR
PCSTR
PCTSTR
PCWSTR
PDWORD32
PDWORD64
PDWORDLONG
PDWORD_PTR
PFLOAT
PHALF_PTR
PHANDLE
PHKEY
PINT
PINT32
PINT64
PINT_PTR
PLCID
PLONG
PLONG32
PLONG64
PLONGLONG
PLONG_PTR
POINTER_32
POINTER_64
PSHORT
PSIZE_T
PSSIZE_T
PSTR
PTBYTE
PTCHAR
PTSTR
PUCHAR
PUHALF_PTR
PUINT
PUINT32
PUINT64
PUINT_PTR
PULONG
PULONG32
PULONG64
PULONGLONG
PULONG_PTR
PUSHORT
PVOID
PWCHAR
PWORD
PWSTR
SC_HANDLE
SC_LOCK
SERVICE_STATUS_HANDLE
SHORT
SIZE_T
SSIZE_T
TBYTE
TCHAR
UCHAR
UHALF_PTR
UINT
UINT32
UINT64
UINT_PTR
ULONG
ULONG32
ULONG64
ULONGLONG
ULONG_PTR
USHORT
USN
VOID
WCHAR
WORD
WPARAM
_EXCEPTION_POINTERS
_FPIEEE_RECORD
_HEAPINFO
_HFILE
_PNH
__finddata64_t
__int16
__int32
__int64
__int8
__stat64
__time64_t
__timeb64
__wchar_t
__wfinddata64_t
_complex
_dev_t
_diskfree_t
_exception
_finddata_t
_finddatai64_t
_off_t
_onexit_t
_purecall_handler
_stat
_stati64
_timeb
_utimbuf
_wfinddata_t
_wfinddatai64_t
bool
char
clock_t
div_t
double
float
fpos_t
int
intptr_t
jmp_buf
lconv
ldiv_t
long
mbstate_t
ptrdiff_t
short
sig_atomic_t
signed
size_t
terminate_function
time_t
tm
uintptr_t
unsigned
va_list
void
wchar_t
wctrans_t
wctype_t
wint_t


### FIXED CODE ###

R = int(input())

import math

print(2*R*math.pi)
import sympy

def divisors_count(n):
    #lower_divisors , upper_divisors = [], []
    i = 1
    c = 0
    while i*i <= n:
        if n % i == 0:
            #lower_divisors.append(i)
            c += 1
            if i != n // i:
                #upper_divisors.append(n//i)
                c += 1
        i += 1
    #return lower_divisors + upper_divisors[::-1]
    return c

N = int(input())
ans = 0
for i in range(1, N+1):
    ans += i * divisors_count(i)
print(ans)

### FIXED CODE ###

N = int(input())
ans = 0

for i in range(1, N+1):
    j = N // i
    ans += int(j * (j+1) * i / 2)
print(ans)
n,m = map(int,input().split())
way = [1 for _ in range(n+1)]
b1 = 1
b2 = 1
count = 1
ai = int(input())
if ai == 1:
  b2 = 0
  ai = int(input())
  count += 1
for i in range(2,n+1):
  if i == ai:
    b1 = b2
    b2 = 0
    if count < m:
      ai = int(input())
      count+=1
  else:
    tmp = b2
    b2 = (b1 + tmp)%1000000007
    b1 = tmp
print(b2)    

### FIXED CODE ###

n,m = map(int,input().split())
way = [1 for _ in range(n+1)]
for i in range(m):
  ai = int(input())
  way[ai] = 0
for i in range(2,n+1):
  if way[i] != 0:
    way[i] = (way[i-1]+way[i-2])%1000000007
print(way[n])
n = int(input())
s = input()
print(s if not a < 3200 else "red")

### FIXED CODE ###

n = int(input())
s = input()
print(s if not n < 3200 else "red")
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
possibility = [[], [], []]

for i in range(M):
    for j in range(N):
        if sc[i][0]==j+1:
            possibility[j].append(sc[i][1])
ans = ''
for i in range(N):
    if i == 0:
        if list(set(possibility[i]))[0] == 0:
            ans = -1
            break
        elif possibility[i] == []:
            ans += str(1)
            continue
    if len(possibility[i]) == 0:
        ans += str(0)
        continue
    if len(set(possibility[i])) != 1:
        ans = -1
        break
    ans += str(list(set(possibility[i]))[0])

print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
possibility = [[], [], []]

for i in range(M):
    for j in range(N):
        if sc[i][0]==j+1:
            possibility[j].append(sc[i][1])

ans = ''
if N > 1:
    for i in range(N):
        if i == 0:
            if (0 in list(set(possibility[i]))) or len(set(possibility[i])) > 1:
                ans = -1
                break
            elif len(possibility[i]) == 0:
                ans += str(1)
                continue
            else:
                ans += str(list(set(possibility[i]))[0])
        else:
            if len(possibility[i]) == 0:
                ans += str(0)
                continue
            elif len(set(possibility[i])) > 1:
                ans = -1
                break
            else:
                ans += str(list(set(possibility[i]))[0])
else:
    if len(set(possibility[0])) > 1:
        ans = -1
    elif len(possibility[0]) == 0:
        ans += str(0)
    else:
        ans += str(list(set(possibility[0]))[0])


print(ans)
from typing import List


class Solution:
    def solve(self, N: int, A) -> str:

        for a in A:
            if a % 2 == 0:
                if a % 3 != 0 and a % 5 != 0:
                    return "DENIED"

        return "APPROVED"


if __name__ == '__main__':

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

    # solve
    solution = Solution()
    print(solution.solve(N, A))


### FIXED CODE ###

class Solution:
    def solve(self, N: int, A) -> str:

        for a in A:
            if a % 2 == 0:
                if a % 3 != 0 and a % 5 != 0:
                    return "DENIED"

        return "APPROVED"


if __name__ == '__main__':

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

    # solve
    solution = Solution()
    print(solution.solve(N, A))
I0 = lambda :map(int,input().split())
I1 = lambda :int(input())
I2 = lambda :list(map(int,input().split()))
#####################################################




def dfs(p,father=-1):
    for i in tree[p]:
        if i == father:
            continue
        counter[i]+=counter[p]
        dfs(i,p)

n ,q = I0()
counter = [0]*n
tree = [[] for i in range(n)]
for i in range(n-1):
    a,b=I0()
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

for i in range(q):
    p,x = I0()
    counter[p-1]+=x
    

dfs(0)

print(*counter)

'''stack = [1]
while stack:
    yy = stack.pop()
    for i in tree[yy]:
        counter[i-1]+=counter[yy-1]
        stack.append(i)'''

### FIXED CODE ###

I0 = lambda :map(int,input().split())
I1 = lambda :int(input())
I2 = lambda :list(map(int,input().split()))
#####################################################


from sys import stdin,setrecursionlimit
#from copy import deepcopy
 
setrecursionlimit(10**6)
input=stdin.readline

def dfs(p,father=-1):
    for i in tree[p]:
        if i == father:
            continue
        counter[i]+=counter[p]
        dfs(i,p)

n ,q = I0()
counter = [0]*n
tree = [[] for i in range(n)]
for i in range(n-1):
    a,b=I0()
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

for i in range(q):
    p,x = I0()
    counter[p-1]+=x
    

dfs(0)

print(*counter)

'''stack = [1]
while stack:
    yy = stack.pop()
    for i in tree[yy]:
        counter[i-1]+=counter[yy-1]
        stack.append(i)'''
a=input()strip().split(" ")

b=[int(i) for i in a]

c=b[0]+c[1]

if(c>=10):
    print("error")
else:
    print(c)

### FIXED CODE ###

a=input().strip().split(" ")

b=[int(i) for i in a]

c=b[0]+b[1]

if(c>=10):
    print("error")
else:
    print(c)
a, b = map(int().split())
if (a*b) % 0:
  print("Even")
else:
  print("Odd")

### FIXED CODE ###

a, b = map(int, input().split())
if (a * b) % 2 == 0:
  print('Even')
else:
  print('Odd')
a.b=map(int,input().split())
X=str((a+b)*5)
x=int(X[-1])
if x>=5:
    print((a+b)//2+1)
else:
    print((a+b)//2)


### FIXED CODE ###

a,b=map(int,input().split())
X=str((a+b)*5)
x=int(X[-1])
if x>=5:
    print((a+b)//2+1)
else:
    print((a+b)//2)