Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N, X, Y = map(int, input().split())

X = X-1
Y = Y-1

for kIndx in range(1, N):
    kNum = 0

    for jIndx in range(N):
        for iIndx in range(jIndx):
            if (jIndx <= X) or (iIndx >= Y):
                if jIndx - iIndx == kIndx:
                    kNum += 1
            elif (iIndx <= X) and (jIndx >= Y):
                if (jIndx - iIndx) - (Y - X -1) == kIndx:
                    kNum += 1
            elif (iIndx <= X) and ((jIndx > X) and (jIndx < Y)):
                if 2 * jIndx - (X + Y) - 1 > 0:
                    if (jIndx - iIndx) - (2 * jIndx - (X + Y) - 1) == kIndx:
                        kNum += 1
                else:
                    if jIndx - iIndx == kIndx:
                        kNum += 1
            elif ((iIndx > X) and (iIndx < Y)) and (jIndx >= Y):
                if (X + Y) - 2 * iIndx - 1 > 0:
                    if (jIndx - iIndx) - ((X + Y) - 2 * iIndx - 1) == kIndx:
                        kNum += 1
                else:
                    if jIndx - iIndx == kIndx:
                        kNum += 1
            else:
                if (2 * (jIndx - iIndx) - (Y - X) - 1) > 0:
                    if (jIndx - iIndx) - (2 * (jIndx - iIndx) - (Y - X) - 1) == kIndx:
                        kNum += 1
                else:
                    if jIndx - iIndx == kIndx:
                        kNum += 1
    print(kNum)


### FIXED CODE ###

N, X, Y = map(int, input().split())

X = X-1
Y = Y-1

kDict = {}

for kIndx in range(1, N+1):
    kDict[kIndx] = 0

for jIndx in range(N):
    for iIndx in range(jIndx):
        if (jIndx <= X) or (iIndx >= Y):
            kDict[jIndx - iIndx] += 1
        elif (iIndx <= X) and (jIndx >= Y):
            kDict[(jIndx - iIndx) - (Y - X - 1)] += 1
        elif (iIndx <= X) and ((jIndx > X) and (jIndx < Y)):
            if 2 * jIndx - (X + Y) - 1 > 0:
                kDict[(jIndx - iIndx) - (2 * jIndx - (X + Y) - 1)] += 1
            else:
                kDict[jIndx - iIndx] += 1
        elif ((iIndx > X) and (iIndx < Y)) and (jIndx >= Y):
            if (X + Y) - 2 * iIndx - 1 > 0:
                kDict[(jIndx - iIndx) - ((X + Y) - 2 * iIndx - 1)] += 1
            else:
                kDict[jIndx - iIndx] += 1
        else:
            if (2 * (jIndx - iIndx) - (Y - X) - 1) > 0:
                kDict[(jIndx - iIndx) - (2 * (jIndx - iIndx) - (Y - X) - 1)] += 1
            else:
                kDict[jIndx - iIndx] += 1

for kIndx in range(1, N):
    print(kDict[kIndx])
### BUGGY CODE ###

from heapq import heappop, heappush
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())

    l = []
    for _ in range(H):
        s = input()
        l.append([1 if i=="#" else 0 for i in s])

    Ch -= 1
    Cw -= 1
    Dh -= 1
    Dw -= 1

    q = [(0, Ch, Cw)]
    INF = 10**12
    costs = [[INF]*W for _ in range(H)]
    costs[Ch][Cw] = 0

    while q:
        cost, h, w = heappop(q)
    
        for hh, ww in [(h+1, w), (h-1, w), (h, w+1), (h, w-1)]:
            if not (0<=hh<H and 0<=ww<W):
                continue
            if l[hh][ww]:
                continue
            if costs[hh][ww] > costs[h][w]:
                costs[hh][ww] = costs[h][w]
                heappush(q, (cost, hh, ww))

        for dh in range(-2, 3):
            for dw in range(-2, 3):
                hh = h+dh
                ww = w+dw
                if not (0<=hh<H and 0<=ww<W):
                    continue
                if l[hh][ww]:
                    continue
                if costs[hh][ww] > costs[h][w]+1:
                    costs[hh][ww] = costs[h][w]+1
                    heappush(q, (cost+1, hh, ww))

    print(costs[Dh][Dw] if costs[Dh][Dw]!=INF else -1)


solve()

### FIXED CODE ###

from heapq import heappop, heappush
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())

    l = []
    for _ in range(H):
        s = input()
        l.append([1 if i=="#" else 0 for i in s])

    Ch -= 1
    Cw -= 1
    Dh -= 1
    Dw -= 1

    q = [(0, (Ch, Cw))]
    INF = 10**12
    costs = [[INF]*W for _ in range(H)]
    costs[Ch][Cw] = 0

    while q:
        cost, pos = heappop(q)
        h, w = pos
        for dh in range(-2, 3):
            for dw in range(-2, 3):
                hh = h+dh
                ww = w+dw
                if not (0<=hh<H and 0<=ww<W):
                    continue
                if l[hh][ww]:
                    continue
                
                if (abs(dh)==1 and abs(dw)==0) or (abs(dh)==0 and abs(dw)==1):
                    if costs[hh][ww] > costs[h][w]:
                        costs[hh][ww] = costs[h][w]
                        heappush(q, (cost, (hh, ww)))
                elif costs[hh][ww] > costs[h][w]+1:
                    costs[hh][ww] = costs[h][w]+1
                    heappush(q, (cost+1, (hh, ww)))

    print(costs[Dh][Dw] if costs[Dh][Dw]!=INF else -1)


solve()
### BUGGY CODE ###

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

for i in A:
    if i%2 == 0:
        A.remove(i)

ans = len(A)

if ans%2 == 0:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

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

ans = len([a for a in A if a % 2 == 1])

if ans%2 == 0:
    print("YES")
else:
    print("NO")
### BUGGY CODE ###

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

cnt = [i for i in range(a, b + 1) if i % x == 0]
print(len(cnt))

### FIXED CODE ###

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

print(b // x - (a - 1) // x)
### BUGGY CODE ###

def evaluate(directions):
    ans = 0
    for i, d in enumerate(directions):
        if 0 <= i+d and i+d <= N-1:
            if directions[i] == directions[i+d]:
                ans += 1
    return ans

def find_lr(directions):
    N = len(directions)
    for i in range(1, N):
        if directions[i-1] != directions[i]:
            l = i
            break
    else:
        l = None
        return None, None
    
    for i in range(l+1, N):
        if directions[i-1] != directions[i]:
            r = i
            break
    else:
        r = N
    return l, r

def solve(directions):
    l, r = find_lr(directions)
    if l is None:
        return False
    else:
        if l is not None:
            for i in range(l, r):
                directions[i] *= -1
        return True 
    
N, K = map(int, input().split())
S = input()
directions = [1 if s=="R" else -1 for s in S]
for k in range(K):
    result = solve(directions)
    if result == False:
        break
    
print(evaluate(directions))

### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    S = input()
    score = 0
    for i in range(1, N):
        if S[i-1] == S[i]:
            score += 1
    print(min(N-1, score + 2*K))
main()
### BUGGY CODE ###

#!/usr/bin/env python3
#ABC75 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,k = LI()
xy = [LI() for _ in range(n)]
ans = inf
for u in range(n):
    for d in range(n):
        for r in range(n):
            for l in range(n):
                cnt = 0
                for i in range(n):
                    x,y = xy[i]
                    if xy[l][0] <= x <= xy[r][0]  and xy[d][1] <= y <= xy[u][1]:
                        cnt += 1
                if cnt >= k:
                    S = (xy[u][1] - xy[d][1])*(xy[r][0] - xy[l][0])
                    ans = min(ans,S)
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#ABC75 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,K = LI()
xy = []
X = []
Y = []
for _ in range(n):
    x,y = LI()
    xy.append([x,y])
    X.append(x)
    Y.append(y)
X.sort(reverse = True)
Y.sort(reverse = True)
ans = inf
for i in range(n):
    uy = Y[i]
    for j in range(i+1,n):
        dy = Y[j]
        for k in range(n):
            rx = X[k]
            for l in range(k+1,n):
                lx = X[l]
                cnt = 0
                for x,y in xy:
                    if lx <= x <= rx and dy <= y <= uy:
                        cnt += 1
                if cnt >= K:
                    S = (uy - dy)*(rx - lx)
                    ans = min(ans,S)
print(ans)
### BUGGY CODE ###

s = str(input())
Q = int(input())
front = 1
for i in range(Q):
    q = list(input().split())
    if q[0] == "1":
        front *= -1
    else:
        if q[1] == "1":
            if front == 1:
                s = q[2] + s
            else:
                s = s + q[2]             
        else:
            if front == 1:
                s = s + q[2]
            else:
                s = q[2] + s

if front == -1:
    s = s[::-1]
print(s)

### FIXED CODE ###

s = str(input())
Q = int(input())
forward = 1
front = ""
back = ""

for i in range(Q):
    q = list(input().split())
    if q[0] == "1":
        forward *= -1
    else:
        if q[1] == "1":
            if forward == 1:
                front = q[2] + front
            else:
                back = back + q[2]        
        else:
            if forward == 1:
                back = back + q[2]
            else:
                front = q[2] + front

s = front + s + back
if forward == -1:
    s = s[::-1]
print(s)
### BUGGY CODE ###

mtch = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} 

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

dp = [["-" for j in range(N + 1)] for i in range(N//2 + 1)]
dp[0][0] = ""

for i in range(N//2 + 1):
    for j in range(N + 1):
        for a in A:
            if dp[i][j] != "-" and j + mtch[a] <= N:
                added = dp[i][j] + str(a)
                if dp[i + 1][j + mtch[a]] < added:
                    dp[i + 1][j + mtch[a]] = added

for i in range(N//2, -1, -1):
    if dp[i][N] != "-":
        print(dp[i][N])
        break

### FIXED CODE ###

match = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)

dp = [-1 for i in range(N + 1)]
dp[0] = 0
for i in range(N + 1):
    for a in A:
        if dp[i] >= 0 and i + match[a] <= N:
            dp[i + match[a]] = max(dp[i] + 1, dp[i + match[a]])

ans = ""
while N > 0:
    for a in A:
        if N - match[a] >= 0 and dp[N - match[a]] == dp[N] - 1:
            ans += str(a)
            N -= match[a]
            break

print(ans)
### BUGGY CODE ###

#input
N, P = map(int, input().split())
S = input()

# process
ans = 0
if P == 2 or P == 5:
    # 1桁目がPで割り切れる数をカウント
    S = list(map(int, S))
    for i in range(N):
        if S[i] % P == 0:
            ans += i+1

else:
    cnt = [0]*P # S[i:N]%Pの結果をカウント
    for i in range(N):
        cnt[int(S[i:N])%P] += 1

    ans += cnt[0]
    for c in cnt:
        if c > 1:
            ans += c*(c-1)//2

# output
print(ans)


### FIXED CODE ###

#input
N, P = map(int, input().split())
S = input()

# process
ans = 0
if P == 2 or P == 5:
    # 1桁目がPで割り切れる数をカウント
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i+1

else:
    cnt = [0]*P # S[i:N]%Pの結果をカウント
    num = 0
    tenPow = 1
    for i in reversed(range(N)):
        num = (num + int(S[i])*tenPow)%P
        tenPow = tenPow*10%P
        cnt[num] += 1

    ans += cnt[0]
    for c in cnt:
        ans += c*(c-1)//2 # c=0,1のときは0加算

# output
print(ans)
### BUGGY CODE ###

S = str(input())
l = len(S)
ans = 0
for i in range(l-3):
  for j in range(i+4, l+1):
    s = int(S[i:j])
    if s % 2019 == 0:
      ans += 1
print(ans)

### FIXED CODE ###

S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)
### BUGGY CODE ###

#
# ~oisín~ Python3 Template
#

import sys
import math
import statistics
import datetime
import collections

def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 1
    for x in a:
        ans *= x
    if ans > 1000000000000000000:
        print("-1")
    else:
        print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#
# ~oisín~ Python3 Template
#

import sys
import math
import statistics
import datetime
import collections

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 1
    e = False
    for x in a:
        if ans > 1000000000000000000:
            print("-1")
            e = True
            break
        ans *= x
    if ans > 1000000000000000000 and e == False:
        print("-1")
    elif e == False:
        print(ans)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
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

def solve():
    def dfs(x):
        fx = f[x]
        for y in v[x]:
            if d[y]:
                d[y] = 0
                f[y] += fx
                dfs(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
    d = [1]*n
    d[0] = 0
    dfs(0)
    print(*f,sep=" ")
    return

#Solve
if __name__ == "__main__":
    solve()


### FIXED CODE ###

#!usr/bin/env python3
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()
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def dist(p1,p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

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

cand = []
for i in (-1,0,1):
    for j in (-1,0,1):
        points.sort(key = lambda x: i*x[0] + j*x[1])
        cand.append(points[0])
outs = []
for i in cand:
    for p in points:
        outs.append(dist(i,p))
print(max(outs))


### FIXED CODE ###

import sys
input = sys.stdin.readline

def dist(p1,p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

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

cand = []
for i in (-1,0,1):
    for j in (-1,0,1):
        best = -10 ** 9
        bestP = (0,0)
        for p in points:
            val = i * p[0] + j * p[1]
            if val > best:
                best = val
                bestP = p
        cand.append(bestP)
                
best = 0
for i in cand:
    for p in points:
       best = max(best,dist(i,p))
print(best)
### BUGGY CODE ###

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

count_R = [0]
count_G = [0]
count_B = [0]
d = {'R': count_R, 'G': count_G, 'B': count_B}
for c in s:
    count_R.append(count_R[-1]+1) if c == 'R' else count_R.append(count_R[-1])
    count_G.append(count_G[-1]+1) if c == 'G' else count_G.append(count_G[-1])
    count_B.append(count_B[-1]+1) if c == 'B' else count_B.append(count_B[-1])

res = 0
for i in range(n-2):
    for k in range(i+1, n-1):
        if s[i] == s[k]:
            continue
        st = {'R', 'G', 'B'}
        st.discard(s[i])
        st.discard(s[k])
        c = st.pop()
        cnt = d[c]
        res += cnt[-1] - cnt[k]
        if k+k-i < n and s[k+k-i] == c:
            res -= 1

print(res)


### FIXED CODE ###

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

count_R = [0]
count_G = [0]
count_B = [0]
d = {'R': count_R, 'G': count_G, 'B': count_B}
for c in s:
    count_R.append(count_R[-1]+1) if c == 'R' else count_R.append(count_R[-1])
    count_G.append(count_G[-1]+1) if c == 'G' else count_G.append(count_G[-1])
    count_B.append(count_B[-1]+1) if c == 'B' else count_B.append(count_B[-1])

res = 0
for i in range(n-2):
    for k in range(i+1, n-1):
        if s[i] == s[k]:
            continue
        st = {'R', 'G', 'B'}
        st.discard(s[i])
        st.discard(s[k])
        c = st.pop()
        cnt = d[c]
        res += cnt[-1] - cnt[k]
        if k+k-i < n and s[k+k-i] == c:
            res -= 1

print(res)
### BUGGY CODE ###

N, A, B, C = list(map(int, input().split()))
L = [int(input()) for _ in range(N)]

from itertools import permutations


def min_cost(g_list):
    g1, g2, g3 = g_list
    return abs(g1 - A) + abs(g2 - B) + abs(g3 - C)


ans = []
for LL in permutations(L):
    for p1 in range(1, N - 1):
        for p2 in range(p1+1, N):
            for p3 in range(p2 + 1, N+1):
                g1, g2, g3 = sum(LL[:p1]), sum(LL[p1:p2]), sum(LL[p2:p3])
                syn = [len(
                    L[:p1])-1, len(L[p1:p2])-1, len(L[p2:p3])-1]
                # print(g1, g2, g3)
                # print(p1, p2, p3)
                # print(syn)
                ans.append(min_cost([g1, g2, g3]) + sum(syn) * 10)
    # break

print(min(ans))
# print(ans)


### FIXED CODE ###

N, A, B, C = list(map(int, input().split()))
L = [int(input()) for _ in range(N)]

from itertools import permutations, combinations


def dellist(items, contents):
    items = items.copy()
    for rm in contents:
        # print(rm)
        items.remove(rm)
    return items


ans = []
L_temp = L.copy()

for n_g1 in range(1, N):
    for n_g2 in range(1, N - n_g1+1):
        for n_g3 in range(1, N - n_g1 - n_g2 + 1):
            # print(n_g1, n_g2, n_g3)
            L_temp = L.copy()
            for G1 in combinations(L_temp, n_g1):
                L_temp = L.copy()
                L_temp = dellist(L_temp, G1)
                # print('G1', L_temp)
                for G2 in combinations(L_temp, n_g2):
                    L_temp = L.copy()
                    L_temp = dellist(L_temp, G1)
                    L_temp = dellist(L_temp, G2)
                    # print('G2', L_temp)
                    for G3 in combinations(L_temp, n_g3):
                        # print('G3', L_temp)
                        s1, s2, s3 = sum(G1), sum(G2), sum(G3)
                        syn = len(G1) + len(G2) + len(G3) - 3
                        ans.append(abs(s1 - A) + abs(s2 - B) +
                                   abs(s3 - C) + syn * 10)

# print(ans)
print(min(ans))
### BUGGY CODE ###

## dijkstraで解く

from collections import deque
import heapq

H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh_, dw_ = map(int, input().split())

fs = []
for i in range(H):
    r = list(input())
    fs.append(r)

INF = 1 << 10
N = 10**4
dps = [[INF]*W for i in range(H)]
dps[ch-1][cw-1] = 0
q = []
heapq.heapify(q)
heapq.heappush(q,(0, (ch-1)*N+(cw-1)))
while q:
    cnt, n  = heapq.heappop(q)
    h,w = divmod(n, N)
    if cnt > dps[h][w]:continue
    dps[h][w] = cnt
    # 歩いた
    for dh in range(-2,3):
        for dw in range(-2,3):            
            hn = h + dh
            wn = w + dw

            if not 0 <= wn < W: continue
            if not 0 <= hn < H: continue
            if fs[hn][wn] == "#": continue
            if dps[hn][wn] != INF:continue
            if abs(dh) + abs(dw) <= 1:
                heapq.heappush(q, (cnt, hn*N+wn))
            else:
                heapq.heappush(q, (cnt+1, hn*N+wn))

ans = dps[dh_-1][dw_-1]
print(ans if ans != INF else -1)


### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh_, dw_ = map(int, input().split())

fs = []
for i in range(H):
    r = list(input())
    fs.append(r)

walks = [(-1,0),(1,0),(0,1),(0,-1)]
magics = []
for i in range(-2,3):
    for j in range(-2,3):
        if i==j==0:continue
        if (i,j) not in walks:
            magics.append((i,j))

INF = 1 << 50
dps = [[INF]*W for i in range(H)]
dps[ch-1][cw-1] = 0
q = deque([])
q.appendleft((ch-1,cw-1,0))
while len(q)>0:
    h,w,cnt = q.popleft()
    if cnt > dps[h][w]:continue
    dps[h][w] = cnt
    for dh, dw in walks:
        hn = h + dh
        wn = w + dw
        if 0<=hn<H and 0<=wn<W:
            if dps[hn][wn] != INF:continue
            if fs[hn][wn] == ".":
                q.appendleft((hn, wn, cnt))
    for dh, dw in magics:
        hn = h + dh
        wn = w + dw
        if 0<=hn<H and 0<=wn<W:
            if dps[hn][wn] != INF:continue
            if fs[hn][wn] == ".":
                q.append((hn, wn, cnt+1))

ans = dps[dh_-1][dw_-1]
print(ans if ans != INF else -1)
### BUGGY CODE ###

import itertools
n = int(input())

l = [input()[0] for _ in range(n)]

l = [i for i in l if i in {'M','A','R','C','H'}]

l2 = [i for i in list(itertools.combinations(l,3)) if len(set(i)) == 3]

print(len(l2))



### FIXED CODE ###

from collections import Counter
import itertools
n = int(input()) 
l = [input()[0] for _ in range(n)]
l = [i for i in l if i in {'M','A','R','C','H'}]

if len(l) < 3:
    print(0)
else:
    c = Counter(l)
    cl = list(itertools.combinations(c,3))
    ans = 0
    for i in cl:
        ans += c[i[0]] * c[i[1]] * c[i[2]]
    print(ans)