Harryxun/stf_run huggingface dataset:
N, Q = map(int, input().split())
connections = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    pa, ki = map(int, input().split())
    connections[pa].append(ki)
    connections[ki].append(pa)
scores = [0 for _ in range(N + 1)]
for _ in range(Q):
    tag, p = map(int, input().split())
    scores[tag] += p

i = 1
fins = []

def dfs(k=1):
    global scores
    global fins
    if k in fins:
        return
    fins.append(k)
    kids = connections[k]
    if not kids:
        return
    for kid in kids:
        if kid in fins:
            continue
        scores[kid]+=scores[k]
        dfs(kid)


dfs()



print(*scores[1:])

### FIXED CODE ###

import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline

N, Q = map(int, input().split())
connections = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    pa, ki = map(int, input().split())
    connections[pa].append(ki)
    connections[ki].append(pa)

scores = [0 for _ in range(N + 1)]
for _ in range(Q):
    tag, p = map(int, input().split())
    scores[tag] += p

i = 1

def dfs(k=1,bef=-1):
    global scores
    global fins
    kids = connections[k]
    if len(kids)==1 and bef==kids[0]:
        return
    for kid in kids:
        # print(f'k:{k} kids:{kids}')
        if bef==kid:
            continue
        scores[kid]+=scores[k]
        dfs(kid,k)


dfs()



print(*scores[1:])
week = ['SUN','MON','TUE','WED','THU','FRI','SAT']
x = input()
week.index(x)
print(7-x)

### FIXED CODE ###

week = ['SUN','MON','TUE','WED','THU','FRI','SAT']
x = input()
print(7-week.index(x))
a, b = map(int, input().split())
d = 0
while a > b:
    a -= b
    d += 1
r = a
f = round(a/b, 5)
print('{} {} {}'.format(d, r, f))


### FIXED CODE ###

a, b = map(int, input().split())
d = int(a/b)
r = a%b
f = a/b
print('{} {} {:0.9f}'.format(d, r, f))
N,M=[int(i) for i in input().split()]
arrR=[0]*N
for m in range(M):
    a,b=[int(i) for i in input().split()]
    arrR[a-1]+=1
    arrR[b-1]+=1
[print(arrR[i]) for i in range(M)]


### FIXED CODE ###

N,M=[int(i) for i in input().split()]
arrR=[0]*N
for m in range(M):
    a,b=[int(i) for i in input().split()]
    arrR[a-1]+=1
    arrR[b-1]+=1
[print(arrR[i]) for i in range(N)]
A,B = map(int,input().split())
K = (A+B)/2
if != isinstance(K):
  print("IMPOSSIBLE")

### FIXED CODE ###

A,B = map(int,input().split())
if (A+B)%2 != 0:
  print("IMPOSSIBLE")
else:
  print((A+B)//2)
n, m = map(int, input().split())
ac = [0] * n
pen = [0] * n
pen_count = 0
for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if ac[p] == "AC":
        continue
    elif s == "AC":
        ac[p] = "AC"
    else:
        pen[p] += 1

for i in range(m):
    if ac[i] == "AC":
        pen_count = pen[i]

print(ac.count("AC"), pen_count)

### FIXED CODE ###

c = input()
a_list= list('abcdefghijklmnopqrstuvwxyz')
for i in range(0, len(a_list)):
    if a_list[i] == c:
        i += 1
        print(a_list[i])
n, x = [int(i) for i in input().split()]

3 <= n <= 100

if n == x == 0:
    break

for a in range(1, n+1):
    for b in range(1, a):
        for c in range(1, b-1):
             if a == b == c or a == b or a == c or b == c:
               None
             if a + b + c == x:
               return
             else:
               None
print()

### FIXED CODE ###

while True:
    n, x = [int(i) for i in input().split()]

    if n == x == 0:
        break

    count = 0
    for s in range(1, n+1):
        for m in range(s+1, n):
            for e in range(m+1, n+1):
                if x == sum([s, m, e]):
                    count += 1

    print(count)
a,b=map(int,input().split())
if a*b%2==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, C, K = (int(x) for x in input().split())

a = [1] * A
b = [0] * B
c = [-1] * C
X = a + b + c
print(sum(X[:K]))


### FIXED CODE ###

A, B, C, K = map(int,input().split())
if K <= A:
    print(K)
elif K <= A + B:
    print(A)
else:
    print(2*A + B - K)
a = input().split()
p = int(a[0])
q = int(a[1])
r = int(a[2])
print(min[p+q,p+r,q+r])

### FIXED CODE ###

a = input().split()
p = int(a[0])
q = int(a[1])
r = int(a[2])
x = p + q
y = q + r
z = p + r
print(min([x,y,z]))
import math
import numpy as np
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

K = int(input())

ans = 0

for a in range(1,K+1) :
    for b in range(1,K+1) :
        for c in range(1,K+1) :
           X = math.gcd(a, b)
           Y = math.gcd(X, c)
           ans += Y

print(ans)

### FIXED CODE ###

from math import gcd

K = int(input())

ans = 0

for a in range(1,K+1) :
    for b in range(1,K+1) :
        X = gcd(a, b)
        for c in range(1,K+1) :
           Y = gcd(X, c)
           ans += Y

print(ans)
from collections import Counter
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b = Counter(a_list)
b_list = sorted(b.items(), key=lambda x:x[1])[:k]
d = sum(b_list.values())
print(n-d)

### FIXED CODE ###

import collections
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b = collections.Counter(a_list)
d = b.most_common()[k:]
sum = 0
for i in d:
    sum += i[1]
print(sum)
a = input().split()
if a[1] == "0":
  print(a[0])
else:
  number_list = input().split()
  n = 1
  number = int(a[0])
  while True:
    num = number + n
    num2 = number - n
    if str(num) not in number_list or str(num2) not in number_list:
      if str(num) in number_list:
        print(num2)
      else:
        print(num1)
      break
    n += 1
    

### FIXED CODE ###

a = input().split()
if a[1] == "0":
  print(a[0])
else:
  number_list = input().split()
  n = 0
  number = int(a[0])
  while True:
    num = number + n
    num2 = number - n
    if str(num) not in number_list or str(num2) not in number_list:
      if str(num) not in number_list and str(num2) not in number_list:
        print(num2)
        break
      if str(num) in number_list:
        print(num2)
      else:
        print(num)
      break
    n += 1
S_str=str(input())
S_list=list(S_str)
S=int(S_list[-1])
N=len(S_str)

mod=[0]*2018
mod[0]=1
now=S%2019
mod[now]+=1

for i in range(N-1)[::-1]:
    #print(i+1,S,S%2019)
    next=pow(10,N-1-i,2019)
    next=(next*int(S_list[i]))%2019
    now=(now+next)%2019
    mod[now]+=1

    

def culc(x):
    return x*(x-1)//2


ans=0
for j in range(len(mod)):
    ans+=culc(mod[j])

print(ans)




### FIXED CODE ###

S_str=str(input())
S=int(S_str[-1])
N=len(S_str)

mod=[0]*2019
mod[0]=1
now=S%2019
mod[now]+=1

for i in range(N-1)[::-1]:
    #print(i+1,S,S%2019)
    next=pow(10,N-1-i,2019)
    next=(next*int(S_str[i]))%2019
    now=(now+next)%2019
    mod[now]+=1

    

def culc(x):
    return x*(x-1)//2


ans=0
for j in range(len(mod)):
    ans+=culc(mod[j])

print(ans)
s = input()

if s = "RRR":
  print(3)
elif s = "RRS" or s = "SRR":
  print(2)
elif s = "SSS":
  print(0)
else:
  print(1)

### FIXED CODE ###

s = input()

if s == "RRR":
  print(3)
elif s == "RRS" or s == "SRR":
  print(2)
elif s == "SSS":
  print(0)
else:
  print(1)
t = input()
maxt = ""
if len(t) = 1:
  print("D")
else:
  while len(maxt) = len(t):
    if len(maxt) // 2 = 0:
      maxt += "P"
    else:
      maxt += "D"
  
  print(maxt)


### FIXED CODE ###

t = input()
tt = t.replace("?", "D")
print(tt)
i = input()
i = int(i)
lis = []
for j in range(i):
    f = input()
    f = int(f)
    lis.append(f)


lis.sort(reverse=True)
print(lis)

### FIXED CODE ###

input()
i = list(map(int, input().split()))
i.reverse()
for j in range(len(i)) :
    if j != 0 :
        print(' ', end = '')
    print(i[j], end = '')
print()
import fractions

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

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

print(lcm(A,B))

### FIXED CODE ###

A = int(input())
B = int(input())

if (A == 1 and B == 2) or (A == 2 and B == 1):
    print(3)

if (A == 1 and B == 3) or (A == 3 and B == 1):
    print(2)

if (A == 3 and B == 2) or (A == 2 and B == 3):
    print(1)
import math
N = input()
min_page = math.ceil(N/2)
print(min_page)

### FIXED CODE ###

import math
N = int(input())
min_page = math.ceil(N/2)
print(min_page)
s, t = input.split()
print(t, s, sep='')

### FIXED CODE ###

s, t = input().split()
print(t, s, sep='')
import sys

n, y = list(map(int, sys.stdin.readline(),strip().split(" ")))

t_list = []

for i in range(n + 1):
    for j in range(n-i+1):
        t_list.append(N-i-j, j, i)

for a, b, c in t_list:
    if 10000 * a + 5000 * b + 1000 * c == y:
        print(" ".join([str(a), str(b), str(c)]))
        sys.exit()

print("-1 -1 -1")


### FIXED CODE ###

import sys

n, y = list(map(int, sys.stdin.readline().strip().split(" ")))

t_list = []

for a in range(n + 1):
    for b in range(n-a+1):
        #t_list.append((n-i-j, j, i))
        c = n-a-b
        if 10000 * a + 5000 * b + 1000 * c == y:
            print(" ".join([str(a), str(b), str(c)]))
            sys.exit()

print("-1 -1 -1")
import sys

A,B = map(float,input().split())

val_1 = A / 0.08
val_2 = B / 0.10

i = 1

if int(val_1) == int(val_2):
    print(int(val_1))
    sys.exit()

else:
    while val_1 != val_2:
	val_2 = (B + 0.1*i)/0.1
	i += 1
	if val_1 < val_2:
            print(-1)
            sys.exit()

print(int(val_1))

### FIXED CODE ###

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

ans = -1

for i in range(10000,-1,-1):
    tax1 = int(i * 0.08)
    tax2 = int(i * 0.10)
    if tax1 == A and tax2 == B:
        ans = i

print(ans)
a,b,c,d = map(int,input().split())
ta = 0
aok = 0
while True:
    ta = c-b
    c = ta
    if c <=0:
        print("Yes")
        break
    aok = a - d
    a = aok
    if a <=0:
        print("No")
        break

       

    



### FIXED CODE ###

s, w = map(int, input().split())
if w >= s:
    print("unsafe")
else:
    print("safe")
import numpy as np

n, m = map(int, input().split())
hlist = np.array(list(map(int, input().split())))
ab = [list(map(int, input().split())) for _ in range(m)]

connect = np.zeros((n,n)).astype(int)
for a, b in ab:
  connect[a-1, b-1] = connect[b-1, a-1] = 1
ans = 0
for i in range(n):
  if (connect[i] * hlist >= hlist[i]).sum() == 0:
    ans += 1
print(ans)

### FIXED CODE ###

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

maxh = [0]*n
for a, b in ab:
  maxh[a-1] = max(maxh[a-1], hlist[b-1])
  maxh[b-1] = max(maxh[b-1], hlist[a-1])
ans = 0
for i in range(n):
  if maxh[i] < hlist[i]:
    ans += 1
print(ans)
N,Y=map(int,input().split())
x=-1
y=-1
z=-1
for i in range(N+1):
    for j in range(N+1):

        k=N-j-i
        sum = i*10000 + j*5000 + k*1000
        if Y==sum and i+j+k==N:
            x=i
            y=j
            z=k
            break

    else:
        continue
    break
print(str(x)+' '+str(y)+' '+str(z))

### FIXED CODE ###

N=int(input())
d=[input() for i in range(N)]
sum=1
d.sort(reverse=True)
for i in range(1,N):
    if d[i-1]>d[i]:
        sum+=1
print(sum)
N=int(input())
if N==1:
  print('''Yes
2
1
1'''
elif N==3:
  print('''Yes
3
2 1 2
2 3 1
2 2 3''')
else:
  print('No')

### FIXED CODE ###

N=int(input())
X=0
for i in range(1,1000):
  X+=i
  if X==N:
    P=[[] for j in range(i+1)]
    X=0
    for j in range(i):
      for k in range(i-j):
        P[j].append(k+X+1)
      for k in range(i-j):
        P[k+j+1].append(k+X+1)
      X+=i-j
    print('Yes')
    print(i+1)
    for j in range(i+1):
      print(len(P[j]),end=' ')
      print(*P[j])
    exit()
print('No')
def userCeil(a,b) :
    return (a + b - 1) // b

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

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

A.sort()

maxDigit = userCeil(max(K,A[-1]), 2)

ans = 0

# 前計算
maxVal = [0] * maxDigit
for i in range(maxDigit) :
    count = 0
    mask = 2**i
    for a in A :
        count += (a & mask) // mask
    count = max(N - count, count)
    if i == 0 :
        maxVal[0] = count
    else :
        maxVal[i] = count * mask + maxVal[i-1]

valK = [0] * (maxDigit + 1)
for i in range(maxDigit-1, -1, -1) :
    mask = 2**i
    maskK = K & mask
    sumK = 0
    for a in A :
        val = a & mask
        if maskK != val :
            sumK += mask
    valK[i] = sumK + valK[i+1]

print(0)


### FIXED CODE ###

N , K = map(int,input().split())
 
A = list(map(int,input().split()))
 
A.sort()
 
maxDigit = max(K,A[-1]).bit_length()
 
# 前計算
maxVal = [0] * maxDigit
for i in range(maxDigit) :
    count = 0
    mask = 2**i
    for a in A :
        count += (a & mask) // mask
    count = max(N - count, count)
    if i == 0 :
        maxVal[0] = count
    else :
        maxVal[i] = count * mask + maxVal[i-1]
 
valK = [0] * (maxDigit + 1)
for i in range(maxDigit-1, -1, -1) :
    mask = 2**i
    maskK = K & mask
    sumK = 0
    for a in A :
        val = a & mask
        if maskK != val :
            sumK += mask
    valK[i] = sumK + valK[i+1]
 
ans = valK[0]  # X = K
for i in range(maxDigit-1, -1, -1) :  # 上からi+1桁まではKと同じ
    if not K & (2**i) > 0  :  # i桁目が0の場合
        continue
 
    sumXor = valK[i+1]
 
    # i桁目 0にする
    mask = 2**i
    for n in range(N) :
        if A[n] & mask > 0 :
            sumXor += mask
 
    if i > 0 :
        sumXor += maxVal[i-1]
 
    ans = max(ans, sumXor)
 
print(ans)
n=int(input())
d=[]
e=[]
for i in range(n):
    p=[0,0]
    s=input()
    for j in s:
        if j==")":
            if p[0]!=0:
                p[0]-=1
            else:
                p[1]+=1
        else:
            p[0]+=1
    if p[0]-p[1]>=0:
        d.append(p)
    else:
        e.append(p)
d=sorted(d,key=lambda x:x[1])
e=sorted(e,key=lambda x:-x[0])
s=d+e
q=0
for i,j in s:
    if q<j:
        print("No")
        exit()
    else:
        q=q-j+i
if q==0:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

s=input()
print("Yes"if s==input()[:-1]else"No")
def main():
    n = input()
    D = []
    O = []
    for i in range(n):
        c, k = raw_input().split()
        if c == 'insert':
            D.append(k)
        else:
            O.append(search(D,k))

    for item in O:
        print item

def search(D,k):
    Dc = D[:]
    if Dc == []:
        return 'no'
    else:
        d = Dc.pop()
        if d == k:
            return 'yes'
        else:
            return search(Dc,k)


if __name__ == "__main__":
    main()

### FIXED CODE ###

m = 2000003

def MyHash(k,i):
    return (k%m+i*(1+(k%m)))%m

def main():
    n = input()
    T = ['']*2000003
    O = []
    for i in range(n):
        c, k = raw_input().split()
        i = 0
        if c == 'insert':
            k_hashed = hash(k)
            while True:
                j = MyHash(k_hashed,i)
                if T[j] == '':
                    T[j] = k
                    break
                else:
                    i += 1
        else:
            O.append(search(T,k))

    for item in O:
        print item

    return 0


def search(T,k):
    k_hashed = hash(k)
    i = 0
    while True:
        j = MyHash(k_hashed,i)
        if T[j] == k:
            o = 'yes'
            break
        elif T[j] == '':
            o = 'no'
            break
        else:
            i += 1

    return o


if __name__ == "__main__":
    main()
print(int(input)+1//2)

### FIXED CODE ###

print((int(input())+1)//2)
a,b=map(int,input())
if a+b>=24:
    print(a+b-24)
else:
    print(a+b)

### FIXED CODE ###

a,b=map(int,input().split())
if a+b>=24:
    print(a+b-24)
else:
    print(a+b)
A = int(input())
B = int(input())
print(A * B)

### FIXED CODE ###

a, b = map(int, input().split())
print(a * b)
m = map(int,raw_input().split())
if m[0] < m[1] < m[2]:
 print Yes
else:
 print No

### FIXED CODE ###


n = map(int,raw_input().split())

if n[0] < n[1] < n[2]:
 print "Yes"
else:
 print "No"
#! /usr/bin/python
from operator import mul
print("Yes" if mul(map(int,input().split()))%2==1 else "No")


### FIXED CODE ###

#! /usr/bin/python
from operator import mul
print("Yes" if mul(*map(int,input().split()))%2==1 else "No")
A,B=map(int,input().split())
min_a=12.5*A;max_a=(100a+1)/8
min_b=10*b;max_b=min_b+1
if(max_b<min_a or max_a<min_b):
  print(-1)
else:
  print(int(round(max(min_a,min_b)+0.4999999,0)))

### FIXED CODE ###

S=input()
if("AAA"==S or S=="BBB"):
  print("No")
else:
  print("Yes")
N=int(input())
Q=sorted([int(input()) for i in range(N)])
S=sum(Q)
mods=S%10
if mods!=0:
    ans=S
else:
    for i in Q:
        if i%10!=0:
            ans=S-i
            break
print(ans)

### FIXED CODE ###

N=int(input())
Q=sorted([int(input()) for i in range(N)])
S=sum(Q)
mods=S%10
if mods!=0:
    ans=S
else:
    for n,i in enumerate(Q):
        if i%10!=0:
            ans=S-i
            break
        if n==N-1:
            ans=0
            break
print(ans)
n = int(input())
a = [int(i) for i in input().split()]
a_uni = list(set(a))
if len(a_uni) == 1:
	if a[0] == 0:
		print("Yes")
	else
		print("No")
elif n%3 != 0:
	print("No")
elif len(a_uni) == 2:
	if a.count(0) == n/3:
		print("Yes")	
	else:
		print("No")	
elif len(a_uni) == 3:
	if a_uni[0]^a_uni[1]!=a_uni[2]:
		print("No")
	elif a.count(a_uni[0])==n/3 and a.count(a_uni[1])==n/3:
		print("Yes")
	else:
		print("No")
else:
	print("No")

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
a_uni = list(set(a))
if len(a_uni) == 1:
	if a[0] == 0:
		print("Yes")
	else:
		print("No")
elif n%3 != 0:
	print("No")
elif len(a_uni) == 2:
	if a.count(0) == n/3:
		print("Yes")	
	else:
		print("No")	
elif len(a_uni) == 3:
	if a_uni[0]^a_uni[1]!=a_uni[2]:
		print("No")
	elif a.count(a_uni[0])==n/3 and a.count(a_uni[1])==n/3:
		print("Yes")
	else:
		print("No")
else:
	print("No")
def prime_factor(n):
    p = {}
    for i in range(2,n):
        if n % i == 0:
            p[i] = 0
        while n % i == 0:
            n //= i
            p[i] += 1
        if i * i > n: break
    if n != 1:
        p[n] = 1
    return p

N = int(input())
pN = {}
for i in range(2,N+1):
    p = prime_factor(i)
    for x in p:
        if x not in pN:
            pN[x] = p[x]
        else:
            pN[x] += p[x]

# 75 = 3 * 5 * 5
res = 0
for x in pN:
    for y in pN:
        for z in pN:
            if (x < y and y < z):
                if(pN[x]>=2 and pN[y]>=4 and pN[z]>=4):
                    res+=1
                if(pN[x]>=4 and pN[y]>=2 and pN[z]>=4):
                    res+=1
                if(pN[x]>=4 and pN[y]>=4 and pN[z]>=2):
                    res+=1

# 75 = 3 * 25
for x in pN:
    for y in pN:
        if x < y:
            if(pN[x]>=24 and pN[y]>= 2):
                res+=1
            if(pN[x]>= 2 and pN[y]>=24):
                res+=1

# 75 = 15 * 5
for x in pN:
    for y in pN:
        if x < y:
            if(pN[x]>=14 and pN[y]>= 4):
                res+=1
            if(pN[x]>= 4 and pN[y]>=14):
                res+=1

if pN[2] >= 74:
    res += 1
    
print(res)   

### FIXED CODE ###

def prime_factor(n):
    p = {}
    for i in range(2,n):
        if n % i == 0:
            p[i] = 0
        while n % i == 0:
            n //= i
            p[i] += 1
        if i * i > n: break
    if n != 1:
        p[n] = 1
    return p

N = int(input())
if N == 1:
    print(0)
else:
    
    pN = {}
    for i in range(2,N+1):
        p = prime_factor(i)
        for x in p:
            if x not in pN:
                pN[x] = p[x]
            else:
                pN[x] += p[x]
    
    # 75 = 3 * 5 * 5
    res = 0
    for x in pN:
        for y in pN:
            for z in pN:
                if (x < y and y < z):
                    if(pN[x]>=2 and pN[y]>=4 and pN[z]>=4):
                        res+=1
                    if(pN[x]>=4 and pN[y]>=2 and pN[z]>=4):
                        res+=1
                    if(pN[x]>=4 and pN[y]>=4 and pN[z]>=2):
                        res+=1
    
    # 75 = 3 * 25
    for x in pN:
        for y in pN:
            if x < y:
                if(pN[x]>=24 and pN[y]>= 2):
                    res+=1
                if(pN[x]>= 2 and pN[y]>=24):
                    res+=1
    
    # 75 = 15 * 5
    for x in pN:
        for y in pN:
            if x < y:
                if(pN[x]>=14 and pN[y]>= 4):
                    res+=1
                if(pN[x]>= 4 and pN[y]>=14):
                    res+=1
    
    if pN[2] >= 74:
        res += 1
        
    print(res)
import math
n,s,*x=map(int,open(0).read().split())
a=[abs(i-s) for i in x]
set(a)
ans=min(a)
for i in a:
    if i%ans==0:
        continue
    else:
        ans=math.gcd(ans,ans%i)
print(ans)  

### FIXED CODE ###

import fractions
n,*x=map(int,open(0).read().split())
x.sort()
a=[i-j for i,j in zip(x[1:],x[:-1])]
set(a)
a.sort()
b=[i for i in a if i%a[0]]
b.append(a[0])
if len(b)==1:
    print(*b)
else:
    ans=b[0]
    for i in b[1:]:
        ans=fractions.gcd(ans,i)
    print(ans)
def CurrentPos(ls,h=0,w=0):    
    if ls[h][w] == '>':
        w +=1
    elif ls[h][w] =='<':
        w -=1
    elif ls[h][w] =='^':
        h -=1
    elif ls[h][w] =='v':
        h +=1
    return [h,w]

def HasPosReached(pos_list,h,w):
    for k,j in pos_list:    
        if (h,w) == (k,j):
            return True
            break

while True:
    H,W =  map(int, raw_input().split())
    if [H,W] == [0,0]:
        break
    ls = []
    for h in range(H):
        ls.append(raw_input())
    
    pos_list=[]
    h =0; w=0
    while True:
        [h,w] = CurrentPos(ls,h,w)
        pos_list.append((h,w))
        if HasPosReached(h,w):
            print "LOOP"
            break
    else:
        print " ".join(map(str,[h,w]))

### FIXED CODE ###

while True:
    H,W = map(int,raw_input().split())
    if (H,W) == (0,0): break
    array = [raw_input() for i in range(H)]
    saw = [[False for i in range(W)] for j in range(H)]
    X = 0
    Y = 0
    while True:
        if array[X][Y] == ">":
            Y += 1
            if saw[X][Y]:
                print 'LOOP'
                break
            saw[X][Y] = True
        elif array[X][Y] == "<":
            Y -= 1
            if saw[X][Y]:
                print 'LOOP'
                break
            saw[X][Y] = True
        elif array[X][Y] == "^":
            X -= 1
            if saw[X][Y]:
                print 'LOOP'
                break
            saw[X][Y] = True
        elif array[X][Y] == "v":
            X += 1
            if saw[X][Y]:
                print 'LOOP'
                break
            saw[X][Y] = True
        elif array[X][Y] ==".":
            print Y,X
            break