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

import math

S = input().split(" ")
N = int(S[0])
K = int(S[1])

arr = [int(s) for s in input().split(" ")]


def calculate(n, k, arr):
    minsArr = []
    plusArr = []
    for ar in arr:
        if ar < 0:
            minsArr.append(ar)
        else:
            plusArr.append(ar)

    # find start index
    startIndex = -10000

    if len(minsArr) > k:
        startIndex = len(minsArr) - k
    else:
        startIndex = 0

    minValues = []
    while startIndex <= len(minsArr):
        tmpArr = arr[startIndex:startIndex + k]
        if len(tmpArr) < k:
            break
        minValue = 0

        if tmpArr[0] * tmpArr[-1] < 0:
            minValue = math.fabs(tmpArr[-1] - tmpArr[0]) + min(math.fabs(tmpArr[-1]), math.fabs(tmpArr[0]))
            a = 1
        else:
            #全部为正数
            if tmpArr[0] >= 0:
                minValue = math.fabs(tmpArr[-1])
            #全部为负数
            else:
                minValue = math.fabs(tmpArr[0])


        minValues.append(minValue)
        startIndex = startIndex + 1

    return int(min(minValues))


result = calculate(N, K, arr)
print(result)

### FIXED CODE ###

import math
S = input().split(" ")
N = int(S[0])
K = int(S[1])
arr = [int(s) for s in input().split(" ")]


def calculate(n, k, arr):
    minsArr = []
    plusArr = []
    for ar in arr:
        if ar < 0:
            minsArr.append(ar)
        else:
            plusArr.append(ar)

    # find start index
    startIndex = -10000

    if len(minsArr) > k:
        startIndex = len(minsArr) - k
    else:
        startIndex = 0

    minValues = []
    while startIndex <= len(minsArr):

        if k == N:
            s1 = arr[0]
            s2 = arr[-1]
            minValue = math.fabs(s2 - s1) + min(math.fabs(s2), math.fabs(s1))
            minValues.append(minValue)
            break

        if startIndex + k > len(arr):
            break

        s1 = arr[startIndex]
        s2 = arr[startIndex + k - 1]

        minValue = 0

        if s1 * s2 < 0:
            minValue = math.fabs(s2 - s1) + min(math.fabs(s2), math.fabs(s1))
        else:
            # 全部为正数
            if s1 >= 0:
                minValue = math.fabs(s2)
            # 全部为负数
            else:
                minValue = math.fabs(s1)

        minValues.append(minValue)
        startIndex = startIndex + 1

    return int(min(minValues))


result = calculate(N, K, arr)
print(result)
### BUGGY CODE ###

import itertools
N,M = map(int,input().split())
A = []
X = [[0]]*M

for m in range(M):
  a,b = map(int,input().split())
  A.append([a,b])
  #X[m] = X[m] + [a] + [b]

ans = []
XX = []
X = A.copy()
for _ in range(N):
  for m,v in itertools.product(range(len(X)),A):
    if X[m][-1] == v[0]:
      if v[1] in X[m]:
        ans.append(X[m]+[v[1]])
        break
      else:
        XX.append(X[m] + [v[1]])
  if len(XX) == 0:break
  X = XX

if ans == []:
  print(-1)
else:
  ans[0] = [len(ans[0])-1] + ans[0]
  print(*ans[0][:-1])


### FIXED CODE ###

def main():
  from collections import deque
  n,m,*t=map(int,open(0).read().split())
  i=[0]*n
  o=[[]for _ in range(n)]
  for a,b in zip(*[iter(t)]*2):
    o[a-1]+=b-1,
    i[b-1]+=1
  q=deque(v for v,f in enumerate(i)if f<1)
  r=[]
  while q:
    v=q.popleft()
    r+=v,
    for w in o[v]:
      i[w]-=1
      if i[w]==0:q+=w,
  print(-(len(r)==n))
main()
### BUGGY CODE ###

import fractions
import itertools
from functools import reduce

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

def dv(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
    
A,B = map(int,input().split())
Cd = list(set(dv(A))&set(dv(B)))
N = len(Cd)
ans = 0
for bit in range(1<<N):
    d = []
    for i in range(N):
        if (bit>>i)&1 == 1:
            d.append(Cd[i])
    if not d:
        continue
    Flag = 1
    for i in itertools.permutations(d, 2):
        if gcd_list(i) != 1:
            Flag = 0
            break
    if Flag == 1:
        ans = max(ans,len(d))
print(ans)

### FIXED CODE ###

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
import fractions
A,B = map(int,input().split())
ans = factorization(fractions.gcd(A,B))
if ans[0][0] == 1:
    print(len(ans))
else:
    print(len(ans)+1)
### BUGGY CODE ###

n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
am=[]
ap=[]
zc=0
for i in a:
  if i<0:
    am.append(i)
  elif i>0:
    ap.append(i)
  else:
    zc+=1
am.sort()
ap.sort()
#print(am,ap)
def count(n,m,p,z):
  mx=-10**20
  lm=len(m)
  lp=len(p)
  if n==0:
    if z or (lm and lp):
      return (lm*lp+(lm+lp)*z+(z*(z-1))//2,0 if z else m[-1]*p[0])
    else:
      return (0,0)
  elif n<0:
    r=0
    j=0
    for i in m:
      while j<len(p) and i*p[j]>n:
        j+=1
      if j<len(p) and mx<i*p[j]:
         mx=i*p[j]
      r+=len(p)-j
    return (r,mx)
  else:
    if z or (lm and lp):
      mx=0 if z else m[-1]*p[0]
    r=lm*lp+(lm+lp)*z+(z*(z-1))//2
    j=lp-1
    for i in range(lp):
      while j>i and p[i]*p[j]>n:
        j-=1
      if j>i and p[i]*p[j]>mx:
        mx=p[i]*p[j]
      r+=j-i
      if i==j:
        break
    j=lm-1
    for i in range(lm):
      while j>i and m[i]*m[j]<=n:
        j-=1
      if i>j:
        j=i
      if j<lm-1 and m[i]*m[j+1]>mx:
        mx=m[i]*m[j+1]
      r+=lm-j-1
    return (r,mx)

r=10**18
t=0
s=set()

while True:
  ret=count(t,am,ap,zc)
  #if r<100:
  #  print(t,ret)
  if ret[0]<k:
    s.add(t)
    t+=r
    r=(r+1)//2
  elif ret[0]==k:
    print(ret[1])
    break
  else:
    if t in s:
      print(ret[1])
      break
    s.add(t)
    t-=r
    r=(r+1)//2
  
  
  
  

### FIXED CODE ###

n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
am=[]
ap=[]
zc=0
for i in a:
  if i<0:
    am.append(i)
  elif i>0:
    ap.append(i)
  else:
    zc+=1
am.sort()
ap.sort()
#print(am,ap)
def count(n,m,p,z):
  mx=-10**20
  lm=len(m)
  lp=len(p)
  if n==0:
    if z or (lm and lp):
      return (lm*lp+(lm+lp)*z+(z*(z-1))//2,0 if z else m[-1]*p[0])
    else:
      return (0,0)
  elif n<0:
    r=0
    j=0
    for i in m:
      while j<len(p) and i*p[j]>n:
        j+=1
      if j<len(p) and mx<i*p[j]:
         mx=i*p[j]
      r+=len(p)-j
    return (r,mx)
  else:
    if z or (lm and lp):
      mx=0 if z else m[-1]*p[0]
    r=lm*lp+(lm+lp)*z+(z*(z-1))//2
    j=lp-1
    for i in range(lp):
      while j>i and p[i]*p[j]>n:
        j-=1
      if j>i and p[i]*p[j]>mx:
        mx=p[i]*p[j]
      r+=j-i
      if i==j:
        break
    j=lm-1
    for i in range(lm):
      while j>i and m[i]*m[j]<=n:
        j-=1
      if i>j:
        j=i
      if j<lm-1 and m[i]*m[j+1]>mx:
        mx=m[i]*m[j+1]
      r+=lm-j-1
    return (r,mx)

r=10**18
t=0
s=set()

while True:
  ret=count(t,am,ap,zc)
  #if r<100:
  #  print(t,ret)
  if ret[0]<k:
    s.add(t)
    t+=r
    r=(r+1)//2
  elif ret[0]==k:
    print(ret[1])
    break
  else:
    if t in s:
      print(ret[1])
      break
    s.add(t)
    t-=r
    r=(r+1)//2
### BUGGY CODE ###

k, s = map(int, input().split())
ans = 0
for i in range(k+1):
  for j in range(k+1):
    for l in range(k+1):
      if (i + j + l) == s:
        ans += 1
        
print(ans)

### FIXED CODE ###

k, s = map(int, input().split())
ans = 0
for i in range(k+1):
  for j in range(k+1):
    z = (s - i - j)
    if 0<= z <= k:
      ans += 1
        
print(ans)
### BUGGY CODE ###

def fun(a, b, c):
    global ans
    for i in range(len(a)):
        for j in range(len(b)):
            for k in range(len(c)):
                if a[i] < b[j] and b[j] < c[k] and b[j] - a[i] != c[k] - b[j]:
                    ans += 1


n = int(input())
s = input()
r = [0] * n
g = [0] * n
b = [0] * n
rr = 0
gg = 0
bb = 0
ans = 0
for i in range(n):
    if s[i] == "R":
        r[rr] = i
        rr += 1
    if s[i] == "G":
        g[gg] = i
        gg += 1
    if s[i] == "B":
        b[bb] = i
        bb += 1

r = r[:rr]
g = g[:gg]
b = b[:bb]

fun(r, g, b)
fun(r, b, g)
fun(g, r, b)
fun(g, b, r)
fun(b, r, g)
fun(b, g, r)

print(ans)


### FIXED CODE ###

n = int(input())
s = input()
rr = 0
gg = 0
bb = 0
for i in range(n):
    if s[i] == "R":
        rr += 1
    if s[i] == "G":
        gg += 1
    if s[i] == "B":
        bb += 1

ans = rr * gg * bb

for j in range(n):
    for i in range(min(j+1, n-j)):
        if s[j - i] != s[j] and s[j] != s[j + i] and s[j + i] != s[j - i]:
            ans -= 1
print(ans)
### BUGGY CODE ###

a,b,x=map(int,input().split())
c=0
def fun():
     print('1')
     print('2')
for i in range(a,b+1):
     if i%x==0:
          c+=1
print(c)

### FIXED CODE ###

a, b, x = [int(x) for x in input().split()]
print(b // x - (a - 1) // x)
### BUGGY CODE ###

n, p = map(int, input().split())
s = input()
s += '0'
p_cnt = 0

div_dic = dict(zip(range(p), [0] * p))

if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            p_cnt += i+1
else:
    for i in range(n+1):
        div_dic[int(s[i:]) % p] += 1

    for v in div_dic.values():
        p_cnt += v * (v - 1) / 2



print(int(p_cnt))

### FIXED CODE ###

n, p = map(int, input().split())
s = [int(i) for i in input()]
p_cnt = 0

if p == 2 or p == 5:
    for i in range(n):
        if s[i] % p == 0:
            p_cnt += i+1
        
else:
    s = s[::-1]
    div_dic = dict(zip(range(p), [0] * p))
    tmp = 0

    for i in range(n):
        tmp += s[i] * pow(10, i, p)
        tmp %= p
        div_dic[tmp] += 1

    for v in div_dic.values():
        p_cnt += v * (v - 1)
    p_cnt //= 2
    p_cnt += div_dic.get(0)

print(p_cnt)
### BUGGY CODE ###

from sys import stdin

X = int(stdin.readline())
Y = 100

count = 1
while True:
  Y += Y*0.01
  if Y >= X:
    print(count)
  else:
    count += 1

### FIXED CODE ###

from sys import stdin

X = int(stdin.readline())
Y = 100

count = 1
while True:
  Y += int(Y*0.01)
  if Y >= X:
    print(count)
    break
  else:
    count += 1
### BUGGY CODE ###

import numpy as np
N,K = map(int, input().split())

S = []
for i in range(K):
    L,R = map(int, input().split())
    S.append((L,R))
S = sorted(S)

step = np.zeros(2*N+1)
step[1] = 1

for j in range(1,N):
    for l,r in S:
        step[j+l:j+r+1] += step[j]
        step[j+l:j+r+1] %= 998244353
    
print(int(step[N]))

### FIXED CODE ###

mod = 998244353
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for i in range(k)]
for i in range(k):
    lr[i][1] += 1

dp = [0]*n
dp[0] = 1
for i in range(1,n):
    dp[i] = dp[i-1]
    if i == 1:
        dp[1] = 0
    for l,r in lr:
        if i - l >= 0:
            dp[i] += dp[i-l]
        if i - r >= 0:
            dp[i] -= dp[i-r]
        dp[i] %= mod
print(dp[n-1])
### BUGGY CODE ###

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    dp = [0] * (N+10)
    dp[2] = abs(A[1] - A[0])
    for i in range(2,N):
        res = []
        if K > i:
            kk = i+1
        else:
            kk = K + 1
        for j in range(1,kk):
            res.append(abs(A[i] - A[i-j])+dp[i-j+1])
        dp[i+1] = min(res)
    
    print(dp[N])
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    dp = [0] * (N+10)
    dp[2] = abs(A[1] - A[0])
    for i in range(2,N):
        res = []
        if K > i:
            kk = i+1
        else:
            kk = K + 1
        for j in range(1,kk):
            res.append(abs(A[i] - A[i-j])+dp[i-j+1])
        dp[i+1] = min(res)
    
    print(dp[N])
if __name__ == "__main__":
    main()
### BUGGY CODE ###

def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

import numpy as np
n=n0()
a=n1()
A=np.array(a)

ans=0
for i in range(n):
    h=A[i]
    B=np.array(range(-i,-i+n))
    C=abs(B)-A-h
    ans+=n-np.count_nonzero(C)
print(ans//2)

### FIXED CODE ###

def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

from collections import defaultdict
n=n0()
a=[0]
a.extend(n1())

m1=[i+a[i] for i in range(n+1)]
m2=[j-a[j] for j in range(n+1)]

d1=defaultdict(list)
d2=defaultdict(list)
for i in range(1,n+1):
    d1[m1[i]].append(i)
    d2[m2[i]].append(i)

ans=0
for i in d1:
    ans+=len(d1[i])*len(d2[i])
            
print(ans)
### BUGGY CODE ###

n=input()
list1=map(int,input().split())
ans = 1
for i in list1:
    ans*=i
    if ans>1e18:
        ans=-1
print(ans)

### FIXED CODE ###

n=input()
list1=list(map(int,input().split()))
if 0 in list1:
    print(0)
else:
    ans=1
    for i in list1:
        ans*=i
        if ans>1e18:
            ans=-1
            break
    print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
b=[0]*(n+1)
b[0]=1
MOD=(10**9)+7
if not 1 in a:
  b[1]=1  
for j in range(2,n+1):
  if not j in a:
    b[j]=(b[j-1]+b[j-2])%MOD    
print(b[n])    
    
  
  
  



### FIXED CODE ###

n,m=map(int,input().split())
mod=10**9+7
a=[0]*(n+1)
dp=[0]*(n+1)
dp[0]=1
for i in range(m):
    a[int(input())]=1
    
if a[1]==1:
    dp[1]=0
else:
    dp[1]=1
    
for j in range(2,n+1):
    if a[j]==0:
        dp[j]=dp[j-1]+dp[j-2] 
                  
print(dp[n]%mod)
### BUGGY CODE ###

a = list(map(int, input().split()))
inp = []
for i in range(a[2]):
    inp.append(int(input()))
n_dict = {}
for i in range(a[0]):
    n_dict[i+1] = a[1]
for i in range(a[2]):
    for k , v in n_dict.items():
        n_dict[k] -= 1
for i in range(a[2]):
    n_dict[inp[i]] += 1
for kk , vv in n_dict.items():
    if int(vv) <= 0:
        print('No')
    else:
        print('Yes')

### FIXED CODE ###

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

hito_dict = {(i+1) : ((n[2]-n[1])*-1) for i in range(n[0])}
for i in range(n[2]):
    d = int(input())
    hito_dict[d] = hito_dict[d] + 1
for j in range(n[0]):
    if hito_dict[j + 1] > 0:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

#!/usr/bin/env python3
# Atcoder necoak answer
# https://atcoder.jp/contests/abc165/tasks/abc165_c

import numpy as np
from itertools import combinations_with_replacement

# def create_list(tmp_anslist, zan_length, zan_num_list):
#     if zan_length == 0:
#         anslist_candidates.append(tmp_anslist)
#         return
#     
#     for i, num in enumerate(zan_num_list):
#         more_zan_num_list = zan_num_list[i:]
#         create_list(tmp_anslist + [num], zan_length-1, more_zan_num_list)

N, M, Q = map(int, input().split())

abcd_array = np.empty((Q, 4), dtype=int)

for i in range(Q):
    a, b, c, d = map(int, input().split())
    abcd_array[i] = [a, b, c, d]

# anslist_candidates = []
# create_list([], N, [ax for ax in range(1, M+1)])
# print(anslist_candidates)

anslist_candidates = combinations_with_replacement(range(1, M+1), N)


max_anslist_score = 0
for tmp_anslist in anslist_candidates:
    sum_d = 0

    is_valid_anslist = True
    prev_ansitem = tmp_anslist[0]
    for ansitem in tmp_anslist[1:]:
        if prev_ansitem > ansitem:
            is_valid_anslist = False
            break
    if not is_valid_anslist:
        continue

    for ai, bi, ci, di in abcd_array:
        #print('ai:%d, bi:%d, ci:%d, di:%d' % (ai, bi, ci, di))
        #print('tmp_anslist:%s' % (tmp_anslist))
        if ((tmp_anslist[bi-1] - tmp_anslist[ai-1]) == ci):
            sum_d += di
    #print('%s : %d' % (tmp_anslist, sum_d))
    max_anslist_score = max(max_anslist_score, sum_d)

print(max_anslist_score)


### FIXED CODE ###

#!/usr/bin/env python3
# Atcoder necoak answer
# https://atcoder.jp/contests/abc165/tasks/abc165_c

import numpy as np
from itertools import combinations_with_replacement

# def create_list(tmp_anslist, zan_length, zan_num_list):
#     if zan_length == 0:
#         anslist_candidates.append(tmp_anslist)
#         return
#     
#     for i, num in enumerate(zan_num_list):
#         more_zan_num_list = zan_num_list[i:]
#         create_list(tmp_anslist + [num], zan_length-1, more_zan_num_list)

N, M, Q = map(int, input().split())

# abcd_array = np.empty((Q, 4), dtype=int)
abcd_array = []
for i in range(Q):
    abcd = map(int, input().split())
    abcd_array.append(list(abcd))
# print(abcd_array)

# anslist_candidates = []
# create_list([], N, [ax for ax in range(1, M+1)])
# print(anslist_candidates)

anslist_candidates = combinations_with_replacement(range(1, M+1), N)


max_anslist_score = 0
for tmp_anslist in anslist_candidates:
    sum_d = 0

    is_valid_anslist = True
    prev_ansitem = tmp_anslist[0]
    for ansitem in tmp_anslist[1:]:
        if prev_ansitem > ansitem:
            is_valid_anslist = False
            break
    if not is_valid_anslist:
        continue

    for ai, bi, ci, di in abcd_array:
        #print('ai:%d, bi:%d, ci:%d, di:%d' % (ai, bi, ci, di))
        #print('tmp_anslist:%s' % (tmp_anslist))
        if ((tmp_anslist[bi-1] - tmp_anslist[ai-1]) == ci):
            sum_d += di
    #print('%s : %d' % (tmp_anslist, sum_d))
    max_anslist_score = max(max_anslist_score, sum_d)

print(max_anslist_score)
### BUGGY CODE ###

s=input()
l=len(s)
mod=10**9+7
dp=[[0 for j in range(13)] for i in range(l+1)]
dp[0][0]=1

for i in range(1,l+1):
	if s[i-1]=='?':
		for j in range(10):
			for k in range(13):
				dp[i][(k*10+j)%13]+=dp[i-1][k]%mod
	else:
		for k in range(13):
			dp[i][(k*10+int(s[i-1]))%13]+=dp[i-1][k]%mod

print(dp[l][5]%mod)

### FIXED CODE ###

INF = 10 ** 9 + 7

S = input()
# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i + 1)]
    if x == "?":
        for k in range(10):
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= INF
    else:
        k = int(x)
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= INF
    mul = mul * 10 % 13  # 計算量削減のためここで13で割っている

print(dp[len(S)][5])
### BUGGY CODE ###

from collections import Counter
N = int(input())
A = map(int, input().split())
c = Counter(A)
Q = int(input())
for _ in range(Q):
    B, Q = map(int, input().split())
    c[Q] += c[B]
    c[B] = 0
    summ = 0
    for k, v in c.items():
        summ += k * v
    print(summ)


### FIXED CODE ###

from collections import Counter
N = int(input())
A = map(int, input().split())
c = Counter(A)
summ = 0
for k, v in c.items():
    summ += k * v
Q = int(input())
for _ in range(Q):
    B, Q = map(int, input().split())
    summ += Q * c[B] - B * c[B]
    c[Q] += c[B]
    c[B] = 0
    print(summ)
### BUGGY CODE ###

N,K=map(int,input().split())
H=list(map(int,input().split()))
if(N<K):
    K=N
C=[10**9]*N
C[0]=0
C[1]=abs(H[1]-H[0])
for i in range(2,K):
    for j in range(1,i+1):
        C[i]=min(C[i-j]+abs(H[i]-H[i-j]),C[i])
for i in range(K,N):
    for j in range(1,K+1):
        C[i]=min(C[i-j]+abs(H[i]-H[i-j]),C[i])
print(C[N-1])


### FIXED CODE ###

N,K=map(int,input().split())
H=list(map(int,input().split()))
if(N<K):
    K=N
C=[10**9]*N
C[0]=0
C[1]=abs(H[1]-H[0])
for i in range(2,K):
    for j in range(1,i+1):
        C[i]=min(C[i-j]+abs(H[i]-H[i-j]),C[i])
for i in range(K,N):
    for j in range(1,K+1):
        C[i]=min(C[i-j]+abs(H[i]-H[i-j]),C[i])
print(C[N-1])
### BUGGY CODE ###

N = int(input())
P = list(map(int,input().split()))
k = []
ans = 0
k = []
for i in range(0,N):
  #P_i <= P_jの判定
  #これまでで最小値だったら、+1
  k.append(P[i])
  k.sort()
  if k[0] == P[i]:
    ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
minimum = 10**8
ans = 0
P = list(map(int,input().split()))
for i in range(N):
  if P[i] < minimum:
    minimum = P[i]
    ans += 1
print(ans)
### BUGGY CODE ###

def make_Graph(N, edges):#頂点の名前はi - 1で受け付ける
    graph = {}
    for i in range(N):
        graph[i] = {}
        for j in range(N):
            graph[i][j] = 0
    for edge in edges:
        a, b, c = edge
        graph[a][b] = c
        graph[b][a] = c
    return graph

def BFS(N, graph, start):
    Q = []
    V = []
    prev = {}
    d = {}
    for i in range(N):
        prev[i] = None
        d[i] = float("inf")
    Q.append(start)
    d[start] = 0
    while len(V) < N:
        a = Q.pop(0)
        V.append(a)
        for b in range(N):
            if graph[a][b] and not b in V:
                Q.append(b)
                prev[b] = a
                d[b] = d[a] + graph[a][b]
    return d

N = int(input())
edges = []
for i in range(N-1):
    a, b, c = (int(j) for j in input().split())
    edges.append((a-1, b-1, c))

graph = make_Graph(N, edges)

Q, K =(int(i) for i in input().split())

d = BFS(N, graph, K-1)
for i in range(Q):
    x, y = (int(a) for a in input().split())
    print(d[x-1] + d[y-1])

### FIXED CODE ###

import sys
input = sys.stdin.readline

def make_Graph(N, edges):#頂点の名前はi - 1で受け付ける
    graph = [ [] for i in range(N)]
    for edge in edges:
        a, b, c = edge
        graph[a].append((b,c))
        graph[b].append((a,c))
    return graph

def BFS(N, graph, start):
    Q = []
    V = []
    prev = [None] * N
    dd = [float("inf")] * N
    Q.append(start)
    dd[start] = 0
    while len(V) < N:
        a = Q.pop(0)
        V.append(a)
        for b, c in graph[a]:
            if b != prev[a]:
                Q.append(b)
                prev[b] = a
                dd[b] = dd[a] + c
    return dd

def DFS(N, graph, a, p, d):
    dd[a] = d
    for b, c in graph[a]:
        if b == p or dd[b] != 0:
            continue
        else:
            DFS(N, graph, b, a, d + c)

N = int(input())
graph = [ [] for i in range(N)]
for i in range(N-1):
    a, b, c = (int(j) for j in input().split())
    graph[a-1].append((b-1,c))
    graph[b-1].append((a-1,c))

Q, K =(int(i) for i in input().split())
dd = [0] * N

try:
    DFS(N, graph, K-1, -1, 0)
except:
    dd = BFS(N, graph, K-1)

for i in range(Q):
    x, y = (int(a) for a in input().split())
    print(dd[x-1] + dd[y-1])
### BUGGY CODE ###

n = int(input())
A = list(map(int,input().split()))
B = []
def Cumulative_sum(n,A):
  B=[0]
  for i in range(n):
    B.append(A[i] + B[i])
  return B
B = Cumulative_sum(n,A)
ans = 0
B_set = set(B)
for x in B_set:
  count = B.count(x)
  if count > 1:
    ans += (count*(count-1)/2)
print(int(ans))
    



### FIXED CODE ###

n = int(input())
A = list(map(int,input().split()))
B = []
def Cumulative_sum(n,A):
  B=[0]
  for i in range(n):
    B.append(A[i] + B[i])
  return B
B = Cumulative_sum(n,A)
B_sort = sorted(B)
y = 0
ans = 0
count = 1
while(y < n):
  if B_sort[y] == B_sort[y+1]:
    count += 1
    y += 1
  else:
    if count > 1:
      ans += (count*(count-1)/2)
      count = 1
    y += 1
    
if count > 1:
  ans += (count*(count-1)/2)
print(int(ans))
### BUGGY CODE ###

#coding=utf-8
from itertools import combinations
from collections import Counter

def solve(n, ss):
    filtered_ss = list(filter(lambda x: x in "MARCH", ss))

    gc = Counter(filtered_ss)
    if len(gc) < 3:
        return 0

    ans = 0
    for permutation in combinations("MARCH", 3):
        ans += (gc[permutation[0]] * gc[permutation[1]] * gc[permutation[2]])

    return ans

def main():
    n = int(input())
    ss = []
    for x in range(n):
        ss = ss + [input()[0]]
    print(solve(n, ss))

if __name__ == '__main__':
    main()


### FIXED CODE ###

#coding=utf-8
from itertools import combinations
from collections import Counter

def solve(n, gc):
    #filtered_ss = list(filter(lambda x: x in "MARCH", ss))

    #gc = Counter(filtered_ss)
    if len(gc) < 3:
        return 0

    ans = 0
    for permutation in combinations("MARCH", 3):
        ans += (gc[permutation[0]] * gc[permutation[1]] * gc[permutation[2]])

    return ans

def main():
    n = int(input())
    gc = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
    for _ in range(n):
        x = input()[0]
        if x in "MARCH":
            gc[x] += 1
    print(solve(n, gc))

if __name__ == '__main__':
    main()