Harryxun/stf_run huggingface dataset:
N, M = map(int, input().split())
k = []
for i in range(N):
  t = list(map(int, input().split()))
  for j in range(W):
    if t[j] == "snuke":p = [i,j]
abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
print(abc[p[1]]+str(p[0]))
  

### FIXED CODE ###

N, M = map(int, input().split())
k = []
for i in range(N):
  t = list(map(str, input().split()))
  for j in range(M):
    if t[j] == "snuke":p = [i,j]
abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
print(abc[p[1]]+str(p[0]+1))
n = int(input())
a = list(map(int, input().split()))
info = [0 for i in range(10**6)]
mid = 5*10**5

for i in range(n):
    num = a[i] - i
    info[mid + num] += 1
#print(info[mid-8:mid+8])
ans = 0
for i in range(n):
    num = a[i] - i
    ans += info[mid + num - a[i]*2]

print(ans)



### FIXED CODE ###


n = int(input())
a = list(map(int, input().split()))
info = [0 for i in range(10**6)]
mid = 5*10**5

for i in range(n):
    if(a[i]<=2*10**5):
        num = a[i] - i
        info[mid + num] += 1
#print(info[mid-8:mid+8])
ans = 0
for i in range(n):
    if(a[i]<=2*10**5):
        num = a[i] - i
        ans += info[mid + num - a[i]*2]

print(ans)
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i],y[i] = map(int,input().split())

if N == 1:
    print(1)
memo = {}

for i in range(N-1):
    for j in range(i+1,N):
        dx = x[j] - x[i]
        dy = y[j] - y[i]
        if (dx,dy) in memo:
            memo[(dx,dy)] += 1
        elif (-dx,-dy) in memo:
            memo[(-dx,-dy)] += 1
        else:
            memo[(dx,dy)] = 1
        #print(memo)

M = max(memo.values())

print(N-M)


### FIXED CODE ###

N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i],y[i] = map(int,input().split())

if N == 1:
    print(1)
else:
    memo = {}

    for i in range(N-1):
        for j in range(i+1,N):
            dx = x[j] - x[i]
            dy = y[j] - y[i]
            if (dx,dy) in memo:
                memo[(dx,dy)] += 1
            elif (-dx,-dy) in memo:
                memo[(-dx,-dy)] += 1
            else:
               memo[(dx,dy)] = 1
            #print(memo)

    M = max(memo.values())

    print(N-M)
x, k, d = map(int, input().split(" "))
x = abs(x)
min_val = x
while i <= k:
    val = abs(x + (i * d) - ((k-i) * d))
    if val < min_val:
        min_val = val
    i = i + 1
print(min_val)

### FIXED CODE ###

x, k, d = map(int, input().split(" "))

x = abs(x)
mov = x // d
ans = 0
if mov >= k:
    ans = x - k * d
else:
    if (k - mov) % 2 == 0:
        ans = x % d
    else:
        ans = abs(x%d - d)
print(ans)
n,k=map(int,input().split())
ans=0
for b in range(1,N+1):
  p = N//b
  r = N%b
  ans+=p*max(0,b-K)
  ans+=max(0,r-K+1)
print(ans)


### FIXED CODE ###

N,K=map(int,input().split())
ans=0
for b in range(1,N+1):
  p = N//b
  r = N%b
  ans+=p*max(0,b-K)
  ans+=max(0,r-K+1)
if(K==0):
  ans-=N
print(ans)
s=input()
a=int(input())

for i in range(a):
    c=input()
    if c[0]=='1':
        s=''.join(list(reversed(s)))
    else:
        if c[2]=='1':
            s=c[4]+s
        else:
            s=s+c[4]
    
    print(s)
            
print(s)

### 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)
import math
n=int(input())
k=int(math.sqrt(n))
l=[]
for i in range(1,k+2):
    if n%i==0:l.append(max(len(str(i),len(str(n//i))))
print(min(l))

### FIXED CODE ###

import math
n=int(input())
k=int(math.sqrt(n))
l=[]
for i in range(1,k+2):
    if n%i==0:l.append(max( len(str(i)), len(str(n//i)) ))
print(min(l))
a = list(map(int,input().split))
k = 0
for i in a:
  if(i==1):
    k += 1
    
print(k)

### FIXED CODE ###

a = list(input())

k = 0

for i in a:
  if(int(i)==1):
    k += 1
    
print(k)
s=input()
k=int(input())
if k==1:
    print(s[0])
else:
    if s[0]=="1":
        if k < =(10**18):
            print(s[1])
        else:
            print(s[2])
    else:
        if k < =(10**18):
            print(s[0])
        else:
            print(s[1])
            

### FIXED CODE ###

a,b=list(map(int,input().split()))
area=(a*b)-(a+b-1)
print(area)
N,M = map(int,input().split())

ans = input().split()

for i in range(N):
  b = input().split()
  c = set(ans) & set(b)
  ans = list(c)
  
print(len(ans))

### FIXED CODE ###

N,M = map(int,input().split())
L = [0]*N
for i in range(N):
    L[i] = list(map(int,input().split()))
for i in range(N):
    del L[i][0]
L.sort() #第一要素でソート

ans = 0
for i in range(1,M+1):
    cnt = 0
    for j in range(N):
        if i in L[j]:
            cnt += 1
    if cnt == N:
        ans += 1
    
print(ans)
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n,m;
  vector<string> s(n),t(m),o(n);
  cin>>n;
  rep(i,n){
    cin>>s.at(i);
  }
  cin>>m;
  rep(j,m){
    cin>>t.at(j)
  }
  rep(i,n){
    int sss=0, ttt=0;
      rep(j,n){
        if(s.at(i)==s.at(j)){
          sss++;
        }
      }
      rep(k,m){
        if(s.at(i)==t.at(k)){
          ttt++;
        }
      o.at(i) = sss - ttt;
    }
  int max=0;
  rep(i,n){
    if(max<o.at(i)){
      max = o.at(i);
    }
  }
  cout<<max;
}
  
  
  
      
          
        
  
  
  
  
  
}

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
l =[0]*n
for j in range(n):
  a = s.count(s[j])
  b = t.count(s[j])
  l[j] = a-b
print(max(max(l),0))
a, b, cx = map(int, input().split())

d = a - b
print(max(0, c - d))

### FIXED CODE ###


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

d = a - b
print(max(0, c - d))
from itertools import product, combinations

INF = float('inf')
def floyd_warshall(E):
    N = len(E)
    dist = [[INF for _ in range(N)] for _ in range(N)]
    for v in V:
        dist[v][v] = 0
        for u, c in E[v]: dist[v][u] = c
    for k in V:        
        for i, j in product(V, repeat=2):
            if dist[i][j] > dist[i][k] + dist[k][j]:
                dist[i][j] = dist[i][k] + dist[k][j]
    return dist

N, M, L = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    E[a-1].append((b-1, c))
    E[b-1].append((a-1, c))
dist = floyd_warshall(V, E)

E_charge = [[] for _ in V]
for u, v in combinations(V, 2):
    if dist[u][v] <= L:
        E_charge[u].append((v, 1))
        E_charge[v].append((u, 1))
charge = floyd_warshall(V, E_charge)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    n = charge[s-1][t-1]
    print(n - 1 if n != INF else -1)

### FIXED CODE ###

from itertools import product, combinations

INF = float('inf')
def floyd_warshall(E):
    N = len(E)
    dist = [[INF for _ in range(N)] for _ in range(N)]
    for v in range(N):
        dist[v][v] = 0
        for u, c in E[v]: dist[v][u] = c
    for k in range(N):        
        for i, j in product(range(N), repeat=2):
            if dist[i][j] > dist[i][k] + dist[k][j]:
                dist[i][j] = dist[i][k] + dist[k][j]
    return dist

N, M, L = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    E[a-1].append((b-1, c))
    E[b-1].append((a-1, c))
dist = floyd_warshall(E)

E_charge = [[] for _ in range(N)]
for u, v in combinations(range(N), 2):
    if dist[u][v] <= L:
        E_charge[u].append((v, 1))
        E_charge[v].append((u, 1))
charge = floyd_warshall(E_charge)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    n = charge[s-1][t-1]
    print(n - 1 if n != INF else -1)
a=int(input())
b=int(input())
c=int(input())
if a==1:
  print("Hello World")
if a==2:
  print(int(b+c))

### FIXED CODE ###

a=int(input())
if a==1:
  print("Hello World")
else:
  b=int(input())
  c=int(input())
  print(int(b+c))
# -*- coding: utf-8 -*-
INF=10**10

def main():
    
    str=input()
    n=len(str)
    if n==2:
        if str[0]==str[1]:
            print("1 2")
        else:
            print("-1 -1")
        
    
    for i in range(n-1):
        temp=str[i:i+3]
        for j in range(2):
            for k in range(j+1,3):
                if temp[j]==temp[k]:
                    print("{0} {1}".format(i+1,i+3))
                    return 0
    print("-1 -1")
    
if __name__=="__main__":
    main()
    

### FIXED CODE ###

# -*- coding: utf-8 -*-
INF=10**10

def main():
    
    str=input()
    n=len(str)
    if n==2:
        if str[0]==str[1]:
            print("1 2")
            return 0
        else:
            print("-1 -1")
            return 0
        
    
    for i in range(n-2):
        temp=str[i:i+3]
        for j in range(2):
            for k in range(j+1,3): #(0,1),(0,2),(1,2)
                if temp[j]==temp[k]:
                    print("{0} {1}".format(i+1,i+3))
                    return 0
    print("-1 -1")
    
if __name__=="__main__":
    main()
n = int(input())
s = input()

x = n - s[::-1].find(")")
l = 0
r = 0
for i in range(x):
    if s[i] == "(":
        l += 1
    else:
        r += 1

if l < r:
    ans = "(" * (r - l) + s
print(ans + ")" * max(0, (ans.count("(") - ans.count(")"))))


### FIXED CODE ###

n = int(input())
s = input()

tmp = 0
a = 0
for i in s:
    if i == "(":
        tmp -= 1
    else:
        tmp += 1
    a = max(a, tmp)
ans = a * "(" + s
print(ans + ")" * (ans.count("(") - ans.count(")")))
import sys, math, re
from itertools import accumulate
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    x, y = i2(N)
    d = {}

    for i in range(N):
        for j in range(N):
            if i == j:
                continue

            pair = (x[i]-x[j], y[i]-y[j])
            if not pair in d:
                d[pair] = 0
            
            d[pair] += 1

    print(N-max(d.values()))


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys, math, re
from itertools import accumulate
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    if N == 1:
        print(1)
        return
        
    x, y = i2(N)
    d = {}

    for i in range(N):
        for j in range(N):
            if i == j:
                continue

            pair = (x[i]-x[j], y[i]-y[j])
            if not pair in d:
                d[pair] = 0
            
            d[pair] += 1

    print(N-max(d.values()))


if __name__ == "__main__":
    main()
A, P = input().split()
B = 3 * A + P
print(B/2)


### FIXED CODE ###

A, P = input().split()
print(int((3*int(A)+int(P))/2))
#coding: utf-8
string = str(input())
X = 0; li = []
for a in range(len(string)):
  if a = " ":
    li.append(string[X:a])
    X = a
h1 = li[0];m1 = li[1];h2 = li[2];m1 = li[3];k = li[4]
Time = (h1 * 60 + m1) - (h2 * 60 + m2) - K
print(int(Time))

### FIXED CODE ###

#coding: utf-8
string = str(input())
X = 0
li = []
for a in range(len(string)):
    if string[a] == " ":
        li.append(string[X:a])
        X = a+1
li.append(string[X:])
for aa in range(len(li)):
    li[aa] = int(li[aa])
h1 = li[0]
m1 = li[1]
h2 = li[2]
m2 = li[3]
k = li[4]
Time = (h2 * 60 + m2) - (h1 * 60 + m1) - k
print(int(Time))
import functools
n,x,y = map(int, input().split())
a = list(map(int, input().split()))

@functools.lru_cache()
def solve(x_turn, idx, x, y):
    if idx == n:
        return abs(x-y)
    if x_turn:
        score = [solve(False, i+1, a[i], y) for i in range(idx, n)]
        return max(score)
    else:
        score = [solve(True, i+1, x, a[i]) for i in range(idx, n)]
        return min(score)

print(solve(True, 0, x, y))        

### FIXED CODE ###

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

if n == 1:
    print(abs(a[-1] - y))
else:
    print(max(abs(a[-1] - y), abs(a[-1] - a[-2])))
S = input()
ret = []
for s in S:
    if s == 'B' and len(s):
        ret.pop()
    else:
        ret.append(s)
print(''.join(ret))

### FIXED CODE ###

S = input()
ret = []
for s in S:
    if s == 'B':
        if len(ret):
            ret.pop()
    else:
        ret.append(s)
print(''.join(ret))
# -*- coding: utf-8 -*-
import numpy as np

n = input()
list = np.array([], dtype=long)

for i in xrange(n):
    command = raw_input().split()
    if command[0] == "insert":
        list = np.append(int(command[1]), list)
    elif command[0] == "delete":
        key = int(command[1])
        for i in xrange(len(list)):
            if list[i] == key:
                list = np.delete(list, i)
    elif command[0] == "deleteFirst":
        list = np.delete(list, 0)
    elif command[0] == "deleteLast":
        list = np.delete(list, len(list)-1)
        
print " ".join(map(str,list))

### FIXED CODE ###

# -*- coding: utf-8 -*-
n = input()
l = []
tail = 0
for i in xrange(n):
    cmd = raw_input().split()
    if cmd[0] == "insert":
        l.append(cmd[1])
    elif cmd[0] == "delete":
        try:
            l.pop(len(l) - l[::-1].index(cmd[1]) -1)
        except ValueError:
            pass
    elif cmd[0] == "deleteFirst":
        l.pop()
    elif cmd[0] == "deleteLast":
        tail += 1

print " ".join(l[tail:][::-1])
S = input()
l = len(S)
c = 0
for i in range(l // 2):
  if S[i] == S[l-i]:
    c +=1
print(c)

### FIXED CODE ###

S = input()
l = len(S)
c = 0
for i in range(l // 2):
  if S[i] == S[l-i-1]:
    pass
  else:
    c +=1
print(c)
def x_cube :
  A = x*x*x
  print A 

### FIXED CODE ###

x = int(input())
cube = x*x*x
print cube
week = {"1": "Thursday", "2": "Friday", "3": "Saturday", "4": "Sunday", "5": "Monday", "6": "Tuesday", "7": "Wednesday"}
month = {"1": 0, "2": 31, "3": 60, "4": 91, "5": 121, "6": 152, "7": 182, "8": 213, "9": 244, "10": 274, "11": 305, "12": 335}
m, d = input().split()
while m != "0":
    days = month[m] + int(d)
    print(week[str(days % 7)])
    m, d = input().split()

### FIXED CODE ###

while True:
    m, d = map(int, input().split())
    if m == d == 0:
        break
    dim = {1: 0, 2: 31, 3: 60, 4: 91, 5: 121, 6: 152, 7: 182, 8: 213, 9: 244, 10: 274, 11: 305, 12: 335}
    ds = dim[m] + d -1
    print({0:'Thursday', 1:'Friday', 2:'Saturday', 3:'Sunday', 4:'Monday', 5:'Tuesday', 6:'Wednesday'}[ds % 7])
a, b = map(int, input().split())

if a == 1:
  if b == 1:
    print('Draw')
  else:
    print(Alice)
else:
  if b == 1:
    print('Bob')
  elif a > b:
    print('Alice')
  elif a == b:
    print('Draw')
  else:
    print('Bob')

### FIXED CODE ###

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

if a == 1:
  if b == 1:
    print('Draw')
  else:
    print('Alice')
else:
  if b == 1:
    print('Bob')
  elif a > b:
    print('Alice')
  elif a == b:
    print('Draw')
  else:
    print('Bob')
n=int(input())
D=[int(i) for i in input().split()]
if n>=24:
  print(0)
else:
  ans=0
  for i in range(2**(n-1)):
    C=[0,D[0],24]
    for j in range(n-1):
      if i&(1<<j):
        C.append(24-D[j+1])
      else:
        C.append(D[j+1])
    C.sort()
    cur=24
    for j in range(n):
      cur=min(cur,C[j+1]-C[j])
    ans=max(ans,cur)
print(ans)

### FIXED CODE ###

n=int(input())
D=[int(i) for i in input().split()]
C=[1]+[0]*12

for d in D:
  C[min(d,24-d)]+=1
if max(C)>2 or C[0]>1 or C[12]>1:
  print(0)
else:
  ans=0
  
  for i in range(2**(11)):
    CC=[1]+[0]*23+[1]
    for j in range(1,12):
      if C[j]==2:
        CC[j]=1
        CC[24-j]=1
      elif C[j]==1:
        if i&(1<<(j-1)):
          CC[j]=1
        else:
          CC[24-j]=1
    if C[12]==1:
      CC[12]=1
    cur=24
    t=0
    for j in range(1,25):
      if CC[j]==1:
        cur=min(cur,t+1)
        t=0
      else:
        t+=1
    ans=max(ans,cur)
  print(ans)
import sys
input = sys.stdin.readline
N, M, V, P = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A = sorted(A)
kakutei = A[-P]
kakutei_idx = A.index(kakutei)
ans = N - kakutei_idx
V -= (ans - 1)
A = A[:kakutei_idx]
A = sorted(A, reverse=True)
N = len(A)
kakutei_muri = A[-(V - 1)]
kakutei_muri_idx = A.index(kakutei_muri)
ans += (kakutei_muri_idx)
print(ans)



### FIXED CODE ###

import sys
input = sys.stdin.readline

n, m, v, p = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
a = a[::-1]

ans = p

b = a[p:]
b_cumsum = [a[p - 1]]
for i in b:
    b_cumsum.append(b_cumsum[-1] + i)

for i in range(len(b)):
    vote_cnt = max(0, (v - p - (len(b) - (i + 1))))
    if b_cumsum[i] + m * vote_cnt <= (b[i] + m) * (i + 1) and a[p - 1] <= b[i] + m:
        ans += 1
    else:
        break

print(ans)
# リストのうちmaxのインデックス以外は全てmaxを出力、maxのインデックスは2番目に大きい値を出力する
n = int(input())
a = list(int(input()) for _ in range(n))

# リストのmaxとmaxのインデックスを取得
a_max = max(a)
max_index_all = [i for i, x in enumerate(a) if x == a_max]

# リストからmaxを全部削除し、2番目に大きい値を取得
for i in max_index_all:
    a.pop(i)
a_second_max = max(a)


for i in range(n):
    # maxのインデックスでは、2番目に大きな値を出力
    if i in max_index_all:
        print(a_second_max)
    # max以外のインデックスでは、maxを出力
    else:
        print(a_max)

### FIXED CODE ###

import copy
n = int(input())
a = [int(input()) for _ in range(n)]
 
b = copy.deepcopy(a)
b.sort()
max1 = b[-1]
max2 = b[-2]
 
for i in a:
    if i == max1:
        print(max2)
    else:
        print(max1)
N = int(input())
u = [input().split() for _ in range(N)]

Y=0
for i in range(N):
    if i[i][1]=="JPY":
        Y+=u[i][0]
    else:
        Y+=u[i][0]*380000

print(Y)

### FIXED CODE ###

N = int(input())
u = [input().split() for _ in range(N)]

Y=0
for i in range(N):
    if u[i][1]=="JPY":
        Y+=float(u[i][0])
    else:
        Y+=float(u[i][0])*380000

print(Y)
s = input()
n = len(s)
res = 0
  
if s[0] == 'A':
  if s.find('C') >= 2 and s.find('C') < n-2:
    s.lower(0)
    s.lower(s.find('C'))
    if s == s.lower():
      print('AC')
    else:
      print('WA')
  else:
    print('WA')
else:
  print('WA')

### FIXED CODE ###

s = input()
a = s.lower()
l = len(s)
c = 0
n = 0

if s[0] == 'A':
  for i in range(2 , l-1):
    if s[i] == 'C':
      c += 1
  if c == 1:
    for i in range(1,l):
      if s[i] != a[i]:
        n += 1
    if n == 1:
      print('AC')
      exit()
print('WA')
K, N = map(int, input().split())
A = list(map(int, input().split()))
B = []
while all(a< N-1 for a in A):
  B.append(A[a+1]-A[a])

B.append(A[1]+K-A[a])

print(K-max(B))

### FIXED CODE ###

K, N = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * N
k = 0
for i in A:
  k += 1
  if k != N:
    B[k-1]=A[k]-A[k-1]
  else:
    B[N-1] = A[0] + K - A[N-1]

print(K-max(B))
import numpy
while 1:
    e = int(input())
    if  e == 0 :break
    m = e
    for z in range(int(numpy.cbrt(e))+1):
        for y in range(int(numpy.sqrt(e) + 1)):
            if  e-y**2-z**3+y+z < 0 or e - y**2 -z**3 <0:break
            if m > e-y**2-z**3+y+z: m =  e-y**2-z**3+y+z
    print(m)


### FIXED CODE ###

import math
while 1:
    e = int(input().strip())
    if e ==0:break
    m=e
    z =0
    while z**3 <= e:
        y = int(math.sqrt(e-z**3))
        x = e - y**2- z**3 
        if x < 0:break
        if m > x+y+z: m = x+y+z    
        z+=1
    print(m)
def judge(a, b, y, x, m):
	for i in range(0, m):
		for j in range(0, m):
			if a[y+i][x+j] != b[y+i][x+j]: return False
	return True

N, M = map(int, raw_input().split())
A = []
B = []
for i in range(0, N):
	A.append(raw_input())
for i in range(0, M):
	B.append(raw_input())

ans = 'No'
for i in range(0, N-M+1):
	for j in range(0, N-M+1):
		if judge(A, B, i, j, M):
			ans = 'Yes'
			break

print ans


### FIXED CODE ###

def judge(a, b, y, x, m):
	for i in range(0, m):
		for j in range(0, m):
			if a[y+i][x+j] != b[i][j]: return False
	return True

N, M = map(int, raw_input().split())
A = []
B = []
for i in range(0, N):
	A.append(raw_input())
for i in range(0, M):
	B.append(raw_input())

ans = 'No'
for i in range(0, N-M+1):
	for j in range(0, N-M+1):
		if judge(A, B, i, j, M):
			ans = 'Yes'
			break

print ans
# -*- coding: utf-8 -*-
"""
D - Ki
https://atcoder.jp/contests/abc138/tasks/abc138_d

"""
import sys


from functools import lru_cache
from collections import deque

def solve(N, Q):
    @lru_cache(maxsize=None)
    def calc_score(n):
        if n == 1 or nodes[n][3]:
            return nodes[n][0]
        res = calc_score(nodes[n][2]) + nodes[n][0]
        nodes[n][3] = True
        return res

    nodes = [[0, -1, -1, False] for _ in range(N+1)]
    edges = [[] for _ in range(N+1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        edges[a].append(b)
        edges[b].append(a)
    for _ in range(Q):
        p, x = map(int, input().split())
        nodes[p][0] += x

    visited = set()
    q = deque([1])
    while q:
        n = q.popleft()
        if n not in visited:
            visited.add(n)
            for m in (e for e in edges[n] if e not in visited):
                q.appendleft(m)
                nodes[m][2] = n
    ans = [calc_score(i) for i in range(1, N+1)]
    return ans


def main(args):
    N, Q = map(int, input().split())
    ans = solve(N, Q)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

### FIXED CODE ###

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]
 
sys.setrecursionlimit(1000000)
mod = 1000000007
 
#A
def A():
    a = I()
    s = input()
    if a >= 3200:
        print(s)
    else:
        print("red")
    return
 
#B
def B():
    n = I()
    a = LI()
    ans = 0
    for i in a:
        ans += 1/i
    print(1/ans)
    return
 
#C
def C():
    n = I()
    v = LI()
    q = []
    for i in v:
        heappush(q,i)
    while q:
        x = heappop(q)
        if not q:
            print(x)
            return
        y = heappop(q)
        heappush(q,(x+y)/2)
    return
 
#D
def D():
    def dfs(x,d,s):
        for y in v[x]:
            if d[y]:
                s += f[y]
                ans[y] = s
                d[y] = 0
                dfs(y,d,s)
                s -= f[y]
    n,q = LI()
    v = [[] for i in range(n)]
    for i in range(n-1):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
    f = [0]*n
    for i in range(q):
        p,x = LI()
        p -= 1
        f[p] += x
    ans = [0]*n
    d = [1]*n
    d[0] = 0
    ans[0] = f[0]
    s = f[0]
    dfs(0,d,s)
    print(*ans)
    return
 
#E
def E():
    s = input()
    t = input()
 
    return
 
#F
def F():
 
    return
 
#Solve
if __name__ == "__main__":
    D()
import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)
n,m,q = map(int, input().split())
lis = [1 for i in range(n)]
ords = []
cost = []
dp = [200 for i in range(200)]
ans = 0
for i in range(q):
    o = list(map(int, input().split()))
    ords.append(o[:n])
    cost.append(o[-1])
def checker(p, arr, ans):
    if(dp[p]!= 200):
        return dp[p]
    for i in range(n-p-1, -1, -1):
        for c in range(m):
            arr[p] = c
            temp = 0
            ans = checker(p+1, arr, ans)
            for i in range(q):
                if(arr[ords[i][1]-1]-arr[ords[i][0]-1]==ords[i][2]):
                    temp+=cost[i]
            if(temp > ans):
                ans = temp
            dp[p] = ans
    return ans
print(checker(0, lis, 0))


### FIXED CODE ###

N,M,Q=map(int,input().split())
L = []
for i in range(Q):
  L.append(list(map(int, input().split())))
  L[i][0]-=1
  L[i][1]-=1
 
import itertools
l =list(range(1,M+1))
v=list(itertools.combinations_with_replacement(l,N))
ans=0
for arr in v:
  score=0
  for a,b,c,d in L:
    if (arr[b] - arr[a])==c:      
      score+=d
  ans=max(ans,score)
print(ans)