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

x, y, z, k = map(int, input().split())
k = min(x * y * z, k)
a = sorted(list(map(int, input().split())), reverse=True)[:k]
b = sorted(list(map(int, input().split())), reverse=True)[:k]
c = sorted(list(map(int, input().split())), reverse=True)[:k]
def f(a, b):
    results = []
    cnt = 0
    for i in a:
        for j in b:
            cnt += 1
            results.append(i + j)
    return results
ab_results = sorted(f(a, b), reverse=True)
results = sorted(f(c, ab_results[:k]), reverse=True)

print("\n".join(map(str, results[:k])))


### FIXED CODE ###

import numpy as np
x, y, z, k = map(int, input().split())
k = min(x * y * z, k)
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
c = np.array(list(map(int, input().split())))

ab = np.ravel(a + b[:, None])
ab.sort()
abc = np.ravel(c + ab[-k:, None])
abc.sort()
print(np.sum(abc[-k:][::-1].astype(str).astype(object) + "\n"), end="")
### BUGGY CODE ###

N = int(input())
A = [int(x) for x in input().split()]

def count(num, counter_list):
    isFound = False
    for item in counter_list:
        if item[0] == num:
            item[1] += 1
            isFound = True
            break
    if not isFound:
        counter_list.append([num, 1])

def calc(list):
    result = 0
    for item in list:
        cmp_count = item[1] - item[0]
        result += cmp_count if cmp_count >= 0 else item[1]
    return result

def main():
    counter_list = []
    for i in range(N):
        count(A[i], counter_list)
    ans = calc(counter_list)
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split()]

def count(num, counter_list):
    if len(counter_list) == 0:
        counter_list.append([num, 0])
    current = counter_list[-1]     
    if current[0] == num:
        current[1] += 1
    else:
        counter_list.append([num, 1])

def calc(list):
    result = 0
    for item in list:
        cmp_count = item[1] - item[0]
        result += cmp_count if cmp_count >= 0 else item[1]
    return result

def main():
    A.sort()
    counter_list = []
    for i in range(N):
        count(A[i], counter_list)
    ans = calc(counter_list)
    print(ans)

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

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

b = []

for i in range(n):
    b.append(a[i])
    b = b[::-1]

print(' '.join(map(str, b)))

### FIXED CODE ###

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

if(len(a)%2 == 0):
    b = a[1::2][::-1]+a[0::2]
    print(' '.join(map(str, b)))
else:
    b = a[0::2][::-1]+a[1::2]
    print(' '.join(map(str, b)))
### BUGGY CODE ###

N = int(input())
A = [int(n) for n in input().split()]
ans = [0] * N
for i in set(A):
    ans[i-1] = A.count(i)
for n in range(N):
    print(ans[n])


### FIXED CODE ###

from sys import stdin
N = int(input())
A = [0]*2 + [int(n) for n in stdin.readline().split()]
ans = [0]+[0]*N
for i in range(2, N+1):
    ans[A[i]] += 1
for i in range(1, N+1):
    print(ans[i])
### BUGGY CODE ###

mod = 10**9+7
n, k = map(int,input().split())
import numpy as np

def c(n,k):
    return (pow(np.math.factorial(n),1,mod) * pow(np.math.factorial(k), mod-2, mod) * pow(np.math.factorial(n-k), mod-2, mod)) % mod


ans = 0
for m in range(1,min(n-1,k)+1):
    # print((c(n,m) * c(n-1,m)) % mod)
    ans += (c(n,m)%mod * c(n-1,m)%mod) % mod

if k == 1:
    print(ans % mod)

else:
    print((ans+1) % mod)




### FIXED CODE ###

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

mod = 10**9+7
MOD = 10 ** 9 + 7
MAX = 2*n+1


fact = [1] * (MAX + 1)  # i!
finv = [1] * (MAX + 1)  # (i!)^{-1}
iinv = [1] * (MAX + 1)  # i^{-1}

for i in range(2, MAX + 1):
    fact[i] = fact[i - 1] * i % MOD
    iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * iinv[i] % MOD


def c(n, k):
    if n < k or n < 0 or k < 0:
        return 0
    return (fact[n] * finv[k] % MOD) * finv[n - k] % MOD


ans = 0
for m in range(1,min(n-1,k)+1):
    # print((c(n,m) * c(n-1,m)) % mod)
    ans += (c(n,m)%mod * c(n-1,m)%mod) % mod

if k == 1:
    print(ans % mod)

else:
    print((ans+1) % mod)
### BUGGY CODE ###

q = int(input())
import math
def is_prime(n):
	if n == 1:
		return False
	
	for k in range(2, int(math.sqrt(n)) + 1):
		if n%k == 0:
			return False
	return True

a = [0 for i in range(10**5+1)]
for i in range(1,10**5+1,2):
	if is_prime(i) and is_prime((i+1)//2):
		a[i] = 1

for i in range(q):
	l, r = map(int, input().split())
	print (sum(a[l:r+1]))

### FIXED CODE ###

q = int(input())
import math
def is_prime(n):
	if n == 1:
		return False
	
	for k in range(2, int(math.sqrt(n)) + 1):
		if n%k == 0:
			return False
	return True

a = [0 for i in range(10**5+1)]
for i in range(1,10**5+1,2):
	if is_prime(i) and is_prime((i+1)//2):
		a[i] = a[i-1] + 1
		a[i+1] = a[i-1] + 1
	else:
		a[i] = a[i-1]
		a[i+1] = a[i-1]
for i in range(q):
	l, r = map(int, input().split())
	print (a[r]-a[l-1])
### BUGGY CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))
islands = []
for i in range(n):
    islands.append(i)
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    if h[a] > h[b]:
        if b in islands:
            islands.remove(b)
    elif h[a] < h[b]:
        if a in islands:
            islands.remove(a)
    else:
        if a in islands:
            islands.remove(a)
        if b in islands:
            islands.remove(b)
print(len(islands))

### FIXED CODE ###

n, m = map(int, input().split())
h = list(map(int, input().split()))
maxh = []
for height in h:
    maxh.append(0)
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    maxh[a] = max(maxh[a], h[b])
    maxh[b] = max(maxh[b], h[a])
g = 0
for height, maxheight in zip(h, maxh):
    if height > maxheight:
        g += 1
print(g)
### BUGGY CODE ###

from collections import deque

n = int(input())

q = deque()
for i in range(n):
    cmd = input().strip().split()
    try:
        if cmd[0][0] == 'i':
            q.appendleft(cmd[1])
        elif cmd[0][-1] == 'e':
            q.remove(cmd[1])
        elif cmd[0][6] == 'F':
            q.popleft()
        else:
            q.pop()
    except:
        pass

print(' '.join(q))

### FIXED CODE ###

import sys
from collections import deque

n = int(sys.stdin.readline())
q = deque()
for i in range(n):
    cmd = sys.stdin.readline()[:-1]
    if cmd[0] == 'i':
        q.appendleft(cmd[7:])
    elif cmd[6] == ' ':
        try:
            q.remove(cmd[7:])
        except:
            pass
    elif cmd[6] == 'F':
        q.popleft()
    else:
        q.pop()

print(' '.join(q))
### BUGGY CODE ###

f=input; n=int(f()); s=list(f())
d={chr(97+i):[0]*(n+1) for i in range(26)}
def bsum(k,i):
  s=0
  while i: s+=d[k][i]; i-=i&-i
  return s
def badd(k,i,x):
  while i<=n: d[k][i]+=x; i+=i&-i
for i in range(n): badd(s[i],i+1,1)
for i in range(int(f())):
  a,b,c=f().split(); b=int(b)-1
  if a>'1': print(sum(1 for k in d.keys() if bsum(k,int(c))-bsum(k,b)))
  else: badd(s[b],b+1,-1); s[b]=c; badd(c,b+1,1)

### FIXED CODE ###

n=int(input())
l=list(input())
q=int(input())
bit=[[0]*(n+1) for i in range(26)]
def bit_sum(o,i):
  s=0
  while i:
    s+=bit[o][i]
    i-=i&-i
  return s
def bit_add(o,i,x):
  while i<=n:
    bit[o][i] += x
    i+=i&-i
for i in range(n):
  bit_add(ord(l[i])-97,i+1,1)
for i in range(q):
  a,b,c=input().split()
  b=int(b)-1
  if a=='1':
    bit_add(ord(l[b])-97,b+1,-1)
    l[b]=c
    bit_add(ord(c)-97,b+1,1)
  else:
    c=int(c)
    print(sum(1 for o in range(26) if bit_sum(o,c)-bit_sum(o,b)))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
AA=[0]*N
for i in range(N):
    AA[i]=A[i]%(10**9+7)

B=[0]*N
c=0

for i in range(N-1):
    for j in range(i+1,N):
      B[j]=(A[i]*A[j])%(10**9+7)
      c=(c+B[j])%(10**9+7)
print(c)

### FIXED CODE ###

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

c=0
for i in range(N):
    c=c+A[i]**2
    
print((sum(A)**2-c)//2%(10**9+7))
### BUGGY CODE ###

from functools import reduce
import fractions
N = int(input())
t = tuple(map(int,input().split()))

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

m=reduce(lcm, t)-1
ans=0
for i in t:
  ans+=m%i
print(int(ans))

### FIXED CODE ###

N = int(input())
t = tuple(map(int,input().split()))
ans=0
for i in t:
  ans+=i-1
print(ans)
### BUGGY CODE ###

n=int(input())
s=input()
# 1<=i<j<k<=n
# j-i!=k-j
# si!=sj, sj!=sk, si!=sk
ans=0
cl=['R','G','B']
for i in range(n-2):
    c1=s[i]
    if c1=='R':
        c2='G'
        c3='B'
    if c1=='G':
        c2='R'
        c3='B'
    if c1=='B':
        c2='G'
        c3='R'
    # c2
    p=sum([x==c3 for x in s[i+1:]])
    pj=i+1
    for j in range(i+1,n-1):
        if s[j]!=c2:
            continue
        p-=sum([x==c3 for x in s[pj:j]])
        pj=j
        ans+=p
        if 2*j-i < n and s[2*j-i] != s[i] and s[2*j-i] != s[j]:
            ans-=1

    # c3
    p=sum([x==c2 for x in s[i+1:]])
    pj=i+1
    for j in range(i+1,n-1):
        if s[j]!=c3:
            continue
        p-=sum([x==c2 for x in s[pj:j]])
        pj=j
        ans+=p
        if 2*j-i < n and s[2*j-i] != s[i] and s[2*j-i] != s[j]:
            ans-=1

print(ans)


### FIXED CODE ###

n=int(input())
s=input()
nr=s.count('R')
ng=s.count('G')
nb=s.count('B')
ans=nr*ng*nb
for i in range(1,1+(n-1)//2):
      for j in range(n-2*i):
            if s[j]!=s[j+i] and s[j]!=s[2*i+j] and s[j+i]!=s[j+2*i]:
                  ans-=1
print(ans)
### BUGGY CODE ###

a,b = (int(i) for i in input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def divisor(n): #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)

    # divisors.sort()
    return divisors
  
def is_prime(n):
  for p in range(2, n):
    if n % p == 0:
      return False
  return True

cnt = 0
for i in divisor(gcd(a,b)):
  if is_prime(i):
    cnt += 1
print(cnt)

### FIXED CODE ###

a,b = (int(i) for i in input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
def is_prime(n):
  for p in range(2, n):
    if n % p == 0:
      return False
  return True

cnt = 0

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
list = prime_factorize(gcd(a,b))

print(len(set(list))+1)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from itertools import chain
import numpy as np


def sieve(n: int):
    """n以下の(1を含まない)素数を返す"""
    if n < 2:
        return []
    primes = [2]
    if n == 2:
        return primes
    flags = np.array([True for i in range(3, n + 1, 2)])
    for i in range(len(flags)):
        if flags[i]:
            n = i * 2 + 3
            primes.append(n)
            flags[i::n] = False
    return primes


def print_a(A):
    for i in range(0, len(A), 5):
        s = f"{i:3} :"
        for j in range(i, min(i + 5, len(A))):
            s += f"{A[j]:7d}"
        print(s)


def f(X, primes):
    y = 1
    for prime in primes:
        if prime > X:
            break
        count = 1
        while X % prime == 0:
            X = X // prime
            count += 1
        y *= count
    return y


def solve(N: int):
    primes = sieve(N)
    fx = np.ones(N + 1, dtype=np.uint64)
    for prime in primes:
        factor = prime
        t = 1
        while factor <= N:
            fx[factor::factor] *= (t + 1)
            fx[factor::factor] = fx[factor::factor] / t
            t += 1
            factor *= prime
    fx *= np.arange(0, len(fx), dtype=np.uint64)
    return fx.sum()


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N = map(int, line.split())
    N = int(next(tokens))  # type: int
    answer = solve(N)
    print(answer)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3

#                 N    N'
#   | 1  2  3  4  5
# 1 | 1  2  3  4  5 :  N // 1   1 * N' (N'+1) // 2
# 2 |    2     4    :  N // 2   2 * N' (N'+1) // 2
# 3 |       3       :  N // 3   3 * N' (N'+1) // 2
# 4 |          4    :  N // 4   4 * N' (N'+1) // 2
# 5 |             5 :  N // 5   5 * N' (N'+1) // 2


def solve(N):
    answer = 0
    for i in range(1, N + 1):
        mprime = N // i
        answer += i * (mprime * (mprime + 1)) // 2
    return answer


def main():
    N = int(input())  # type: int
    answer = solve(N)
    print(answer)


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

import math

S = input().strip()
Q = int(input().strip())
order = 1

for i in range(Q):
  q = input().strip().split()
  #print(q)
  if q[0] == '1':
    # 反転
    # S = S[::-1]
    order *= -1
  else:
    F = q[1]
    if F == '1':
      if order == 1:
        # 先頭にCを追加
        S = q[2] + S
      else:
        # 末尾にCを追加
        S = S + q[2]
    else:
      if order == 1:
        # 末尾にCを追加
        S = S + q[2]        
      else:
        # 先頭にCを追加
        S = q[2] + S
        
print(S[::order])

### FIXED CODE ###

import math

S = input().strip()
Q = int(input().strip())
order = 1
tmp = 'T'

for i in range(Q):
  q = input().strip().split()
  #print(q)
  if q[0] == '1':
    # 反転
    # S = S[::-1]
    order *= -1
  else:
    F = q[1]
    if F == '1':
      if order == 1:
        # 先頭にCを追加
        # S = q[2] + S
        tmp = q[2] + tmp
      else:
        # 末尾にCを追加
        # S = S + q[2]
        tmp = tmp + q[2]
    else:
      if order == 1:
        # 末尾にCを追加
        # S = S + q[2]        
        tmp = tmp + q[2]
      else:
        # 先頭にCを追加
        # S = q[2] + S
        tmp = q[2] + tmp

S = tmp.replace('T', S)        
print(S[::order])
### BUGGY CODE ###

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

m = n//2
INF = 10**18
dp = [[-INF]*(m+1) for _ in range(n+1)]
for i in range(1, n+1):
    for j in range(i//2-1, (i+1)//2+1):
        if j == 1:
            dp[i][j] = max(dp[i-1][j], A[i-1])
            continue
        if 0 <= i-2 and 0 <= j <= m:
            dp[i][j] = max(dp[i-1][j], dp[i-2][j-1]+A[i-1])
print(dp[-1][m])


### FIXED CODE ###

from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
m = n//2
INF = 10**18
dp = [defaultdict(lambda: -INF) for _ in range(n+1)]
for i in range(1, n+1):
    L = i//2-1
    R = (i+1)//2+1
    for j in range(L, R):
        if j == 1:
            dp[i][j] = max(dp[i-1][j], A[i-1])
        elif 0 <= i-2 and 0 <= j <= m:
            dp[i][j] = max(dp[i-1][j], dp[i-2][j-1]+A[i-1])
print(dp[-1][m])
### BUGGY CODE ###

R,G,B,N = map(int, input().split())

ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        check = (N - (R*r + G*g))/B
        if float.is_integer(check) and check >= 0:
            ans += 1
        # if check >= 0 and check%B == 0:
            # ans += 1
        # if check == 0:
        #     # print(r, g, check//B, check)
        #     ans += 1
        # elif check > 0 and check%B == 0:
        #         # print(r, g, check//B, check)
        #         ans += 1

print(ans)

### FIXED CODE ###

R,G,B,N = list(map(int, input().split()))
ans=0
for r in range(N//R+1):
    x = N-R*r
    for g in range(x//G+1):
        if (x-G*g)%B==0:
            ans+=1
print(ans)
### BUGGY CODE ###

n = input()

max = 10**9 + 7

a_list = [int(a) % max for a in input().split(" ")]

sum = 0
for i in range(0, len(a_list)-1):
  for j in range(i+1, len(a_list)):
    sum += a_list[i] * a_list[j]
    sum = sum % max
print(sum)


### FIXED CODE ###

n = input()
 
max = 10**9 + 7
 
a_list = [int(a) % max for a in input().split(" ")]
a_sum = sum(a_list)

total = 0
for i in range(0, len(a_list)-1):
    a_sum -= a_list[i]
    total += a_list[i] * a_sum
total = total % max
print(total)
### BUGGY CODE ###

# match matching
import bisect
import sys
input = sys.stdin.readline
compare = [10**i for i in range(5*10**3+1)]
N, M = map(int, input().split())
ok = list(map(int, input().split()))
ok.sort()
a = [i for i in range(1, 10)]
b = [2, 5, 5, 4, 5, 6, 3, 7, 6]
data = {a[i]: b[i] for i in range(9)}
dp = [[0 for i in range(N+1)] for j in range(M+1)]


def find(X):
    return bisect.bisect_right(compare, X)


for i in range(M):
    for cnt in range(N+1):
        for num in ok[:i+1]:
            cost = data[num]
            if cnt > cost:
                K = dp[i+1][cnt-cost]
                if K > 0:
                    dp[i+1][cnt] = max(K + num*10 ** find(K), dp[i+1][cnt])
                    continue
                else:
                    dp[i+1][cnt] = max(K, dp[i+1][cnt])
                    continue
            elif cnt == cost:
                dp[i+1][cnt] = max(num, dp[i+1][cnt])
                continue
            else:
                dp[i+1][cnt] = max(dp[i][cnt], dp[i+1][cnt])
                continue
ans = dp[M][N]
print(ans)

### FIXED CODE ###

matches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

n, m = map(int, input().split())
alist = list(map(int, input().split()))
alist.sort(reverse=True)

dp = [-1 for _ in range(n + 1)]
dp[0] = 0
for a in alist:
    match = matches[a]
    for i in range(n - match + 1):
        if dp[i] == -1: continue
        dp[i + match] = max(dp[i + match], dp[i] * 10 + a)

print(dp[-1])
### BUGGY CODE ###

N, M = map(int, input().split())
As = list(map(int, input().split()))
ans = 0
for l in range(N):
    tmp = 0
    for r in range(l, N):
        tmp += As[r]
        if tmp % M == 0:
            ans += 1
print(ans)

### FIXED CODE ###

import collections
N, M = map(int, input().split())
As = list(map(int, input().split()))
b = [0]*N
b[0] = As[0]
ans = 0
for i in range(1,N):
    b[i] = b[i-1] + As[i]
bmod = [i % M for i in b]
for i in collections.Counter(bmod).values():
    if i >= 2:
        ans += i*(i-1) //2
for i in bmod:
    if i == 0:
        ans += 1
print(ans)
### BUGGY CODE ###

N,M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
while M > 0:
    A[-1] /= 2
    M -= 1
    A = sorted(A)
ans = 0
for i in A:
    ans += int(i)
print(ans)

### FIXED CODE ###

N,M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] *= -1
import heapq
heapq.heapify(A)
for i in range(M):
    m = heapq.heappop(A)
    heapq.heappush(A,-1*(-m//2))
print(-1*sum(A))
### BUGGY CODE ###

import numpy as np

n, m, Q = map(int, input().split())

array = np.zeros([n,n])
for _ in range(m):
    p, q = map(int, input().split())
    array[p-1][q-1] += 1

for _ in range(Q):
    p, q = map(int, input().split())
    print(int(sum(sum(array[p-1:, :q]))))

### FIXED CODE ###

import numpy as np

n, m, Q = map(int, input().split())

array = np.zeros([n,n])
for _ in range(m):
    p, q = map(int, input().split())
    array[p-1][q-1] += 1
    
for p in range(n):
    for q in range(1, n):
        array[p][q] += array[p][q-1]

for p in range(1,n):
    for q in range(n):
        array[p][q] += array[p-1][q]

for _ in range(Q):
    p, q = map(int, input().split())
    if p == 1:
        print(int(array[q-1][q-1]))
    else:
        print(int(array[q-1][q-1] - array[p-2][q-1]))
### BUGGY CODE ###

import math
n, h = map(int, input().split())
a_list = []
b_list = []
for i in range(n):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
all_list = a_list + b_list
all_list = sorted(all_list, reverse=True)
count = 0
for i in range(len(all_list)):
    if all_list[i] in a_list:
        count += math.ceil(h/all_list[i])
        break
    else:
        h -= all_list[i]
        count += 1
print(count)


### FIXED CODE ###

import math
n, h = map(int, input().split())
a_max = 0
b_list = []
for i in range(n):
    a, b = map(int, input().split())
    a_max = max(a_max, a)
    b_list.append(b)
b_list = sorted(b_list, reverse=True)
count = 0
flag = 0
for i in range(len(b_list)):
    if a_max < b_list[i]:
        h -= b_list[i]
        count += 1
    else:
        flag = 1
        count += math.ceil(h/a_max)
        break
    if h <= 0:
        flag = 1
        break
if flag == 0:
    count += math.ceil(h/a_max)
print(count)
### BUGGY CODE ###

import sys
n,k = map(int, sys.stdin.readline().rstrip("\n").split())
a = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
p = 1
for i in range(k):
    p *= a[i]
for i in range(k,n):
    pnew = p * a[i]
    pnew = pnew // a[i-k]
    if p < pnew:
        print('Yes')
    else:
        print('No')
    p = pnew

### FIXED CODE ###

import sys
n,k = map(int, sys.stdin.readline().rstrip("\n").split())
a = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
p = 1
for i in range(k,n):
    if a[i-k] < a[i]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import sys
import fractions
from collections import Counter, defaultdict, deque
from functools import reduce

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


def I():
    return int(input())


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


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    k = I()

    def gcgcd(a, b, c):
        return fractions.gcd(fractions.gcd(a, b), c)

    sum = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                sum += gcgcd(a, b, c)

    print(sum)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
import math
from collections import Counter, defaultdict, deque
from functools import reduce

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


def I():
    return int(input())


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


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    k = I()

    def gcd(a, b, c):
        return math.gcd(math.gcd(a, b), c)

    sum = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                if a == b or a == c:
                    sum += math.gcd(b, c)
                elif b == c:
                    sum += math.gcd(a, c)
                else:
                    sum += gcd(a, b, c)

    print(sum)


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

n = int(input())
c = 0
for i in range(n):
    x = int(input())
    counter = 0
    for j in range(x):
        if x % (j+1) == 0:
            counter = counter + 1
    if counter == 2:
        c = c + 1

print(c)

### FIXED CODE ###

n = int(input())
c = 0

def devisor(n):
    if n == 2:
        return 1
    else:
        if n < 2 or n % 2 == 0:
            return 0
        elif pow(2,n-1,n) == 1:
            return 1
        else: return 0

for i in range(n):
    x = int(input())
    c += devisor(x)

print(c)