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

import itertools
def main():
    N = int(input().strip())
    S = []
    for _ in range(N):
        in_s = (input().strip())[0]
        if in_s in ['M','A','R','C','H']:
            S.append(in_s)

    if not S:
        return 0

    pat = itertools.combinations(S, 3);
    
    count = 0
    for x in pat:
        if len(x) == len(set(x)):
            count += 1
    return count
    
if __name__ == '__main__':
    print(main())

### FIXED CODE ###

import math
def kumi(s, n):
    count = 1
    for x in range(s, s - n, -1):
        count *= x
    ret = count // math.factorial(n)
    return ret

def main():
    N = int(input().strip())
    S = []
    D = {}
    for _ in range(N):
        in_s = (input().strip())[0]
        if in_s in ['M','A','R','C','H']:
            S.append(in_s)
            D[in_s] = D.get(in_s, 0) + 1

    if not S or len(D.keys()) < 3:
        return 0

    
    # 組み合わせ数
    count = kumi(len(S), 3)
    # 重複削除
    for v in D.values():
        if v < 2:
            continue
        elif v == 2:
            count -= len(S) - v
        else:
            count -= kumi(v, 2) * (len(S) - v)
            count -= kumi(v, 3)
    return count

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

n = int(input())
s = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(0, n):
    t = 0
    m = i
    if i != n - 1:
        t = s[i][0] + s[i][1]
        m += 1
    while True:
        if m == n - 1:
            break
        while True:
            if (t - s[m][1]) % s[m][2] == 0 and t < s[m][1]:
                t = s[m][1]
            if (t - s[m][1]) % s[m][2] == 0 and t >= s[m][1]:
                break
            t += 1
        t += s[m][0]
        m += 1
    print(t)

### FIXED CODE ###

n = int(input())
s = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(0, n):
    t = 0
    m = i
    if i != n - 1:
        t = s[i][0] + s[i][1]
        m += 1
    while True:
        if m == n - 1:
            break
        while True:
            if (t - s[m][1]) % s[m][2] == 0 and t < s[m][1]:
                t = s[m][1]
            if (t - s[m][1]) % s[m][2] == 0 and t >= s[m][1]:
                break
            t += 1
        t += s[m][0]
        m += 1
    print(t)
### BUGGY CODE ###

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

for x in range(1,n+1):
  print(an.index(x)+1, end=" ")
 
  

### FIXED CODE ###

n = int(input())
an = list(map(int,input().split()))
zyunban = [0]*n
t = 1

for x in an:
  zyunban[x-1] = t
  t += 1
  


zyunban = list(map(str,zyunban))

print(" ".join(zyunban))
### BUGGY CODE ###

K,S=map(int,input().split())
count=0
for X in range(K+1):
    for Y in range(K+1):
        for Z in range(K+1):
            com=X+Y+Z
            if(com==S):
                count+=1
            else:
                pass
print(count)

### FIXED CODE ###

K,S=map(int,input().split())
count=0
for X in range(K+1):
    for Y in range(K+1):
        com=S-(X+Y)
        if(com>=0 and com<=K):
            count+=1
        else:
            pass
print(count)
### BUGGY CODE ###

import sys


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


H, W = map(int, input().split())

A = [[1 if s == "#" else 0 for s in input()] for i in range(H)]

lu = [[1<<20] * (W+2) for j in range(H + 2)]

for ii in range(H * W):
    i = ii // W + 1
    j = ii % W + 1
    lu[i][j] = min(lu[i - 1][j], lu[i][j - 1]) + 1
    if A[i - 1][j - 1]:
        lu[i][j] = 0
    elif j < W and A[i - 1][j]:
        lu[i][j] = 1

for ii in range(H * W):
    i = H - ii // W
    j = W - ii % W
    lu[i][j] = min(lu[i + 1][j] + 1, lu[i][j + 1] + 1, lu[i][j])

dist = max(sum([l[1:-1] for l in lu[1:-1]], []))
print(dist)


### FIXED CODE ###

import sys


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


H, W = map(int, input().split())

A = [[1 if s == "#" else 0 for s in input()] for i in range(H)]

lu = [[1<<20] * (W+2) for j in range(H + 2)]

for ii in range(H * W):
    i = ii // W + 1
    j = ii % W + 1
    lu[i][j] = min(lu[i - 1][j], lu[i][j - 1]) + 1
    if A[i - 1][j - 1]:
        lu[i][j] = 0
    elif j < W and A[i - 1][j]:
        lu[i][j] = 1

for ii in range(H * W):
    i = H - ii // W
    j = W - ii % W
    lu[i][j] = min(lu[i + 1][j] + 1, lu[i][j + 1] + 1, lu[i][j])

dist = []
[dist.extend(l[1:-1]) for l in lu[1:-1]]
print(max(dist))
### BUGGY CODE ###

from copy import deepcopy
from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())

n = I()
s = list(S())

ans = 0
for i in range(len(s)-2):
    color = set()
    color.add(s[i])
    for j in range(i+1,len(s)-1):
        if not s[j] in color:
            buff = deepcopy(color)
            buff.add(s[j])
            for k in range(j+1,len(s)):
                if not s[k] in buff:
                    if k-j != j-i:
                        ans += 1

print(ans)

### FIXED CODE ###

from sys import stdin
def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
 
n = I()
s = list(S())

r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
for i in range(n-1):
    for j in range(1,n):
        if i-j<0 or n<=i+j:
            break
        else:
            if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
                ans-=1
 
print(ans)
### BUGGY CODE ###

x = map(int,raw_input().split())
n=x[0]
m=x[1]
a = map(int,raw_input().split())
a=list(map(float, a))                                                           

for i in range(m):                                                         
    a[a.index(max(a))]=max(a)/2

a=list(map(int, a))

print(sum(a))

### FIXED CODE ###

import heapq

x = map(int,raw_input().split())
n=x[0]
m=x[1]
a = map(int, raw_input().split())

def minus(n):
    return float(n*(-1))

def plus(n):
    return int(n*(-1))

a=list(map(minus, a))
heapq.heapify(a)

for i in range(m):
    heapq.heappush(a, heapq.heappop(a)/2)

a=list(map(plus, a))

print(sum(a))
### BUGGY CODE ###

import itertools
alp = [chr(ord('a') + i) for i in range(26)]
N = int(input())
allS = list(itertools.product(alp[0:N], repeat=N))
answers = []
PatternList = []
for s in allS:
    pattern = []
    letters = []
    num = 0
    for l in s:
        if not(l in letters):
            letters.append(l)
        pattern.append(letters.index(l))
    if not(pattern in PatternList):
        PatternList.append(pattern)
        answers.append(s)
for answer in answers:
    print(''.join(answer))

### FIXED CODE ###

n = int(input())

def dfs(s, cn):
    if len(s) == n:
        print(s)
    else:
        for i in range(0, cn + 1):
            c = chr(ord('a') + i)
            if i == cn: dfs(s+c, cn+1)
            else: dfs(s+c, cn)

dfs('', 0)
### BUGGY CODE ###

import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("void(i8,i8,i8,i8[:,:],i8,i8[:,:],i8[:])", cache=True)
def dfs(H, W, D, A, Q, LR, ans):
    position = [(-1, -1)] * (H * W + 1)
    for h in range(H):
        for w in range(W):
            position[A[h][w]] = (h, w)

    mp = np.zeros(shape=(H * W + 1), dtype=np.int64)

    for i in range(1, H * W + 1 - D):
        h, w = position[i]
        y, x = position[i + D]
        mp[i] = abs(x - w) + abs(y - h)

    for i in range(Q):
        l, r = LR[i]
        ans[i] = mp[l:r:D].sum()


def main():
    H, W, D = map(int, input().split())
    A = np.zeros(shape=(H, W), dtype=np.int64)
    for i in range(H):
        A[i] = tuple(map(int, input().split()))
    Q = int(input())
    LR = np.zeros(shape=(Q, 2), dtype=np.int64)
    for i in range(Q):
        LR[i] = tuple(map(int, input().split()))

    ans = np.zeros(shape=Q, dtype=np.int64)
    dfs(H, W, D, A, Q, LR, ans)

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("void(i8,i8,i8,i8[:,:],i8,i8[:,:],i8[:])", cache=True)
def dfs(H, W, D, A, Q, LR, ans):
    position = [(-1, -1)] * (H * W + 1)
    for h in range(H):
        for w in range(W):
            position[A[h][w]] = (h, w)

    mp = np.zeros(shape=(H * W + 1), dtype=np.int64)

    for i in range(1, H * W + 1 - D):
        h, w = position[i]
        y, x = position[i + D]
        mp[i + D] = abs(x - w) + abs(y - h)

    for d in range(1, D + 1):
        mp[d::D] = np.cumsum(mp[d::D])

    for i in range(Q):
        l, r = LR[i]
        ans[i] = mp[r] - mp[l]


def main():
    H, W, D = map(int, input().split())
    A = np.zeros(shape=(H, W), dtype=np.int64)
    for i in range(H):
        A[i] = tuple(map(int, input().split()))
    Q = int(input())
    LR = np.zeros(shape=(Q, 2), dtype=np.int64)
    for i in range(Q):
        LR[i] = tuple(map(int, input().split()))

    ans = np.zeros(shape=Q, dtype=np.int64)
    dfs(H, W, D, A, Q, LR, ans)

    print("\n".join(map(str, ans)))


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

import sys
input = sys.stdin.readline
n = int(input())
s = input()
q = int(input())
for i in range(q):
  que = input().split()
  if que[0] == '1':
    na,mu = que[1],que[2]
    na = int(na)
    s = s[:na-1] + mu + s[na:]
  else:
    na,mu = que[1],que[2]
    na,mu = int(na),int(mu)
    c = set(s[na-1:mu])
    print(len(c))

### FIXED CODE ###

import sys
readline = sys.stdin.readline

from bisect import bisect_left, insort_left

def main():
    n = int(readline())
    s = list(readline().rstrip())
    q = int(readline())
    
    chk_abc = [[] for i in range(26)]
    for i, si in enumerate(s):
        ci = ord(si) - 97
        chk_abc[ci].append(i)
        
    ans = []
    for _ in range(q):
        cmd, i, j = readline().rstrip().split()
        i = int(i) - 1
        
        if cmd == "1":
            if s[i] == j:
                continue
            c1 = ord(s[i]) - 97
            prev = chk_abc[c1]
            c2 = ord(j) - 97
            prev.pop(bisect_left(prev, i))
            s[i] = j
            insort_left(chk_abc[c2], i)
            
        else:
            j = int(j) - 1
            num = 0
            for chk in chk_abc:
                le = len(chk)
                k = bisect_left(chk, i, 0, le)
                if k == le:
                    continue
                if i <= chk[k] <= j:
                    num += 1
            ans.append(num)

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

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

import numpy as np

n, k = map(int, input().split())
p = np.array(list(map(int, input().split())))

q = np.zeros_like(p, dtype='float')
for i in range(n):
    q[i] += (1+p[i]) / 2.0

ans = 0
for i in range(n):
    ans = max(ans, sum(q[i:i+k]))
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
p = [(1+int(x)) / 2.0 for x in input().split()]

ans = sum(p[0:k])
tmp = sum(p[0:k])

for i in range(0, n-k):
    tmp = tmp - p[i] + p[i+k]
    ans = max(ans, tmp)

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

import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    n0=0
    print(n0)
    s=input()
    if s=="Vacant":sys.exit()
    left,right=0,n
    mid=(right+left)//2
    sl=s
    print(mid)
    sm=input()
    while sm!="Vacant" and right>left:
        if ((mid-left)%2==0 and sm==sl) or ((mid-left)%2==1 and sm!=sl):
            left=mid
            sl=sm
        else:
            right=mid
        mid=(right+left)//2
        print(mid)
        sm=input()        
    if left>=right:
        print(left)

if __name__=='__main__':
    main()

### FIXED CODE ###

N=int(input())
l,r=0,N
print(0)
s=input()
ls=s
if s!='Vacant':
    for i in range(19):
        x=l+(r-l)//2
        print(x)
        s=input()
        if s=='Vacant':
            break
        elif (x-l)%2==0 and s==ls or (x-l)%2==1 and s!=ls:
            l=x
            ls=s
        else:
            r=x
### BUGGY CODE ###

n = int(input())
s={}
for i in range(0,n):
  cs=input()
  if cs in s.keys():
    s[cs]+=1
  else:
    s[cs]=1

maxks=[kv[0] for kv in s.items() if kv[1]==max(s.values())]
maxks.sort()
print('\n'.join(maxks))



### FIXED CODE ###

# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

from collections import Counter

n = int(input())
s=[input() for i in range(n)]
l=Counter(s)
m=0
for i in l.values():
  m=max(m,i)
ans=[]
for k,v in l.items():
  if v==m:
    ans.append(k)
ans.sort()
print(*ans,sep='\n')
### BUGGY CODE ###

import numpy as np

h, w = map(int, input().split())
s = [['#'] * (w + 2)] + [list('#' + input() + '#') for _ in range(h)] + [['#'] * (w + 2)]
s = np.array(s)
s = (s == ".") * 1
def neext(a):
    l, m = a[0], a[1]
    return [(l, m+1), (l, m-1), (l+1, m), (l-1, m)]
def solve(i, j):
    if s[i][j] == 0:
        return 0
    else:
        pre = 0
        p = np.full_like(s, -1)
        check = [((-1, -1), (i, j), 0)]#(from,now, dist)
        while check:
            From, now, d = check.pop(0)
            p[now[0]][now[1]] = d
            pre = max(pre, d)
            for b, c in neext((now[0], now[1])):

                if (b == From[0] and c == From[1]) or p[b][c] != -1 or s[b][c] == 0:
                    continue
                else:
                    check.append(((i, j), (b, c), d + 1))
        return pre
ans = 0
for H in range(len(s)):
    for W in range(len(s[0])):
        ans = max(ans, solve(H, W))
print(ans)

### FIXED CODE ###

import numpy as np
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = 0
for i in range(len(s)):
    for j in range(len(s[0])):
        if s[i][j] == '#':
            continue
        pre = 0
        p = np.full((h, w), -1)
        p[i][j] = 0
        check = deque([((i, j), 0)])#(from,now, dist)
        while check:
            now, d = check.popleft()
            pre = max(pre, d)
            for k, l in [(1,0), (-1,0),(0,1), (0,-1)]:
                b = now[0] + k
                c = now[1] + l
                if b < 0 or c < 0 or b >= h or c >= w:
                    continue 
                elif p[b][c] == -1 and s[b][c] != '#':
                    check.append(((b, c), d + 1))
                    p[b][c] = d + 1
        ans = max(ans, pre)

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

from itertools import combinations
# n = int(input())
n, k = map(int, input().split())

doc = map(int, input().split())
ans = sorted([i for i in combinations(doc, 2)], key = lambda x: x[0] * x[1])[k-1]

print(ans[0] * ans[1])

### FIXED CODE ###

import numpy as np
import sys

input = sys.stdin.readline

n, k = [int(x) for x in input().split()]
A = np.array([int(a) for a in input().split()], dtype="int64")

A = np.sort(A)

A_pos = A[A > 0]
A_neg = A[A < 0]
A_zero = A[A == 0]

# 積がc以下となる組み合わせの数を求める
def n_comb_lt(c):
    n_comb = 0
    # A[i] > 0であるA[i]について
    target = c // A_pos  # target以下の値がA[i]の相方
    n_comb += np.searchsorted(A, target, side="right").sum()

    # A[i] == 0であるA[i]について
    n_comb += n * len(A_zero) if c >= 0 else 0

    # A[i] < 0であるA[i]について
    target = -(-c // A_neg)
    n_comb += (n - np.searchsorted(A, target, side="left")).sum()

    # 組み合わせのうち、A[i]*A[i]となっているものを引いて、2で割る
    n_comb -= A[A * A <= c].size
    n_comb //= 2

    return n_comb

ok = -10 ** 18 - 1
ng = 10 ** 18 + 1

# k番目の積は、積がm未満となる組み合わせがk個未満となる最大のm
# ←→積が(m-1)以下となる組み合わせがk個未満となる最大のm
while ng - ok > 1:
    mid = (ng + ok) // 2
    if n_comb_lt(mid - 1) < k:
        ok = mid
    else:
        ng = mid

print(ok)
### BUGGY CODE ###

def f(ls,m,s):
	global n
	count = 0
	if m > 0:
		for i in range(len(ls)):
			lls = ls[:]
			a = (n-m+1)*lls.pop(i)
			if s-a < 0:
				break
			else:
				count += f(lls,m-1,s-a)
		return count
	else:
		if s == 0:
			return 1
		else:
			return 0
			
ls = [i for i in range(10)]
while True:
	try:
		n,s = map(int, raw_input().split())
		print f(ls,n,s)
	except:
		break

### FIXED CODE ###

def mxmn(ls,m):
	global n
	s1,s2 = 0, 0
	for i in range(m):
		s1 += (n-i)*ls[-i-1]
		s2 += (n-i)*ls[i]
	return s1,s2

def f(ls,m,s):
	global n
	count = 0
	if m > 0:
		mx,mn = mxmn(ls,m)
		if mx < s or mn > s: return 0
		elif mx == s or mn == s: return 1
		for i in range(len(ls)):
			lls = ls[:]
			a = (n-m+1)*lls.pop(i)
			if s-a < 0:	break
			else: count += f(lls,m-1,s-a)
		return count
	else:
		return 1 if s == 0 else 0
			
ls = [i for i in range(10)]
while True:
	try:
		n,s = map(int, raw_input().split())
		print f(ls,n,s)
	except:
		break
### BUGGY CODE ###

n=int(input())
a=[0]
cnt=[0]
ans=True
for i in range(n):
    s=input()
    for j in range(len(a)):
        if a[j]==s:
            cnt[j]+=1
            ans=False
        if ans:
            cnt.append(1)
            a.append(s)
    ans=True
m=int(input())
for i in range(m):
    s=input()
    for j in range(len(a)):
        if a[j]==s:
            cnt[j]-=1
print(max(cnt))


### FIXED CODE ###

s=[input() for _ in range(int(input()))]
t=[input() for _ in range(int(input()))]
cnt=[0]*(len(s)+1)
for i in range(len(s)):
    cnt[i]=s.count(s[i])-t.count(s[i])
print(max(cnt))
### BUGGY CODE ###

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

p = 1
for i in arr[:k]: p *= i
j = 0
for i in arr[k:]:
	s = (p // arr[j]) * i
	if s > p:print('Yes')
	else:print('No')
	p = s
	j += 1

### FIXED CODE ###

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

j = 0
for i in arr[k:]:
	if i > arr[j]:print('Yes')
	else:print('No')
	j += 1
### BUGGY CODE ###

import sys

primes = [2]
for line in sys.stdin:
  try:
    n = int(line)
    for i in range(max(primes) + 1, n + 1):
      primes.append(i)
      for p in primes:
        if i % p == 0 and i != p:
          primes.pop()
          break
    ans = [i for i in primes if i <= n]
    print(len(ans))
  except:
    break

### FIXED CODE ###

import sys
import math

# Sieve of Eratosthenes
N = 999999
searchList = list(range(3, N + 1, 2))
primes = [2]
while True:
  top = searchList.pop(0)
  primes.append(top)
  if top > math.sqrt(N):
    break
  searchList = [s for s in searchList if s % top != 0]
primes.extend(searchList)

# solve
for line in sys.stdin:
  try:
    n = int(line)
    ans = [i for i in primes if i <= n]
    print(len(ans))
  except:
    break
### BUGGY CODE ###

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

ans = 0

for i in range(n - 2):
    a = l[i]
    for j in range(n - i - 2):
        b = l[i + j + 1]
        for k in range(n - i - j - 2):
            c = l[i + j + k + 2]
            if a < b + c and b < c + a and c < a + b:
                ans += 1

print(ans)


### FIXED CODE ###

import bisect

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

l.sort()

ans = 0

for i in range(n - 2):
    a = l[i]
    for j in range(n - i - 2):
        b = l[i + j + 1]
        index = bisect.bisect_left(l, a + b)
        if index > i + j + 2:
            ans += index - (i + j + 2)

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

from decimal import Decimal

N, *A = map(Decimal, open(0).read().split())
N = int(N)

d = {}
for a in A:
    a = int(a * (10 ** 9))
    x = -9
    while a % 2 == 0:
        x += 1
        a %= 2
    y = -9
    while a % 5 == 0:
        y += 1
        a %= 5
    t = (x, y)
    d.setdefault(t, 0)
    d[t] += 1

result = 0
xs = d.values()
for i in range(len(xs)):
    x, y = xs[i]
    for j in range(i + 1, len(xs)):
        m, n = xs[j]
        if x + m >= 0 and y + n >= 0:
            result += d[xs[i]] * d[xs[j]]
print(result)


### FIXED CODE ###

def conv(s):
    if s.find('.') == -1:
        s += '.'
    s = s.rstrip('0')
    t = len(s) - s.find('.') - 1
    a = int(s.replace('.', ''))
    if a == 0:
        return (0, 0)
    x, y = -t, -t
    while a % 5 == 0:
        x += 1
        a //= 5
    while a % 2 == 0:
        y += 1
        a //= 2
    return (x, y)


N, *A = open(0).read().split()
N = int(N)

d = {}
for a in A:
    t = conv(a)
    d.setdefault(t, 0)
    d[t] += 1

result = 0
xs = list(d.keys())
for i in range(len(xs)):
    x, y = xs[i]
    t = d[xs[i]]
    if x >= 0 and y >= 0:
        result += t * (t - 1) // 2
    for j in range(i + 1, len(xs)):
        m, n = xs[j]
        if x + m >= 0 and y + n >= 0:
            result += t * d[xs[j]]
print(result)
### BUGGY CODE ###

from bisect import bisect_right

N, D, A = map(int, input().split())
M = [tuple(map(int, input().split())) for i in range(N)]

M.sort()
X = [M[i][0] for i in range(N)]
H = [M[i][1] for i in range(N)]
ans = 0
for i in range(N):
    if H[i] <= 0:
        continue
    blast_r = X[i] + 2 * D
    max_j = bisect_right(X, blast_r, i + 1)
    c = (H[i] + A - 1) // A
    ans += c
    if i + 1 < max_j:
        H[i + 1:max_j] = [H[j] - A * c for j in range(i + 1, max_j)]
print(ans)


### FIXED CODE ###

from collections import deque

N, D, A = map(int, input().split())
M = [tuple(map(int, input().split())) for i in range(N)]

M.sort()
X = [M[i][0] for i in range(N)]
H = [M[i][1] for i in range(N)]
ans = 0
diff = 0
q = deque()
for i in range(N):
    Xi, Hi = M[i]
    while len(q) > 0 and q[0][0] < Xi:
        diff += q.popleft()[1]
    Hi += diff
    if Hi <= 0:
        continue
    c = (Hi + A - 1) // A
    ans += c
    diff -= A * c
    q.append((Xi + 2 * D, A * c))
print(ans)
### BUGGY CODE ###

import sys
import math

N = int(input())

ans = 0
for i in range (1,N+1):
    for j in range (1,N+1):
        for k in range (1,N+1):
            ans += math.gcd(math.gcd(i,j),math.gcd(j,k))
            
print(ans)


### FIXED CODE ###

import sys
import math

N = int(input())

ans = 0
for i in range (1,N+1):
    for j in range (1,i+1):
        for k in range (1,j+1):
            if i == j == k:
                ans += math.gcd(math.gcd(i,j),k)
            elif i == j or j== k:
                ans += 3*math.gcd(math.gcd(i,j),k)
            else:
                ans += 6*math.gcd(math.gcd(i,j),k)
            #print(i,j,k)
         
            
print(ans)
### BUGGY CODE ###

#N　展望台の数　M　道の数
N,M = map(int, input().split())
#高さ
H =list(map(int,input().split()))

ans=0

#道
J=[]
for i in range(M):
  J.append(list(map(int, input().split())))

for i in range(1,N+1):
  dic={}
  flg = 0
  for j in J:    
    if j[0] == i:
      dic.setdefault(j[1],0)
      dic[j[1]]+=1 
    elif j[1] == i:
      dic.setdefault(j[0],0)
      dic[j[0]]+=1
  
  if len(dic) == 0:
    ans+=1
  else:
    for k,v in dic.items():
      if H[k-1] >= H[i-1]:
        flg = 1
    if flg == 0:
      ans+=1

    
print(ans)

### FIXED CODE ###

#N　展望台の数　M　道の数
N,M = map(int, input().split())
#高さ
H =list(map(int,input().split()))

ans=0
di = {}
#道
J=[""]*M
for i in range(M):
  a,b=list(map(int, input().split()))
  di.setdefault(a,[])
  di[a].append(b)
  di.setdefault(b,[])
  di[b].append(a)
  
#  J[i]=(list(map(int, input().split())))

for i in range(1,N+1):
  flg = 0

  if i in di.keys():
#    print(i)
#    print(di[i])
    for k in di[i]:
      if H[k-1] >= H[i-1]:
        flg = 1
    if flg == 0:
      ans+=1

  else:
    ans+=1

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

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

x = 0
y = 0
S = []

for a in A:
    if a in S:
        if a < x:
            continue
        elif a > y:
            x = y
            y = a
        else:
            x = a
        S.remove(a)
    else:
        S.append(a)

print(x*y)


### FIXED CODE ###

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

x = 0
y = 0
S = set()

for a in A:
    if a in S:
        if a < x:
            continue
        elif a > y:
            x = y
            y = a
        else:
            x = a
        S.remove(a)
    else:
        S.add(a)

print(x*y)
### BUGGY CODE ###

import sys
inputs = sys.stdin.readlines()

h, n = map(int, inputs[0].split())
AB = []
for s in inputs[1:]:
    a, b = map(int, s.split())
    AB.append((a, b))
AB.sort(key=lambda ab:ab[1])

dp = [10 ** 9] * (h+1)
dp[0] = 0
 
for i in range(h):
    for a, b in AB:
        k = min(i + a, h)
        dp[k] = min(dp[k], dp[i] + b)
print(dp[h])

### FIXED CODE ###

import sys
inputs = sys.stdin.readlines()

h, n = map(int, inputs[0].split())
AB = []
for s in inputs[1:]:
    a, b = map(int, s.split())
    AB.append((a, b))
AB.sort(key=lambda ab:ab[1])

dp = [10 ** 9] * (h+1)
dp[0] = 0
 
for i in range(h):
    for a, b in AB:
        k = min(i + a, h)
        dp[k] = min(dp[k], dp[i] + b)
print(dp[h])