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

n = int(input())
import math
ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            tmp = math.gcd(i,j)
            ans += math.gcd(tmp,k)
print(ans)

### FIXED CODE ###

n = int(input())
import math
ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            tmp = math.gcd(i,j)
            ans += math.gcd(tmp,k)
print(ans)
### BUGGY CODE ###

from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,A = inpl()
x = inpl()
dp = [[[0 for _ in range(n+5)] for i in range(3005)] for j in range(n+5)]
dp[0][0][0] = 1
for i in range(n):
    for j in range(sum(x)+1):
        for k in range(n):
            if j >= x[i]:
                dp[i+1][j][k+1] = dp[i][j-x[i]][k] + dp[i][j][k+1]
            else:
                dp[i+1][j][k] = dp[i][j][k]
# for i in range(n+1):
#     print(dp[i][:50])
ans = 0
for j in range(1,sum(x)+1):
    for k in range(1,n+1):
        if j/k == A:
            ans += dp[n][j][k]
print(ans)

### FIXED CODE ###

from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,A = inpl()
x = inpl()
dp = [[[0 for _ in range(n+5)] for i in range(3005)] for j in range(n+5)]
dp[0][0][0] = 1
for i in range(n):
    for j in range(sum(x)+1):
        for k in range(n):
            if j >= x[i]:
                dp[i+1][j][k+1] = dp[i][j-x[i]][k] + dp[i][j][k+1]
            else:
                dp[i+1][j][k] = dp[i][j][k]
# for i in range(n+1):
#     print(dp[i][:50])
ans = 0
for j in range(1,sum(x)+1):
    for k in range(1,n+1):
        if j/k == A:
            ans += dp[n][j][k]
print(ans)
### BUGGY CODE ###

N,K = map(int,input().split())
H = sorted(list(map(int,input().split())), reverse = True)
if(N <= K):
    s = 0
else:
    for i in range(K):
        del H[0]
    s = sum(H)
print(s)

### FIXED CODE ###

N,K = map(int,input().split())
H = sorted(list(map(int,input().split())), reverse = True)
if(N <= K):
    s = 0
else:
    del H[0:K]
    s = sum(H)
print(s)
### BUGGY CODE ###

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    B, C = [], []
    D = [0] * N
    A.sort()
    for i in range(M):
        b, c = map(int, input().split())
        B.append(b)
        C.append(c)
        D += [c] * b
        D = sorted(D, reverse=True)[:N]

    res = 0
    for i in range(N):
        res += max(A[i], D[i])

    print(res)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    BC = []

    D = []
    for i in range(M):
        b, c = map(int, input().split())
        BC.append((b, c))
    BC.sort(key=lambda x: x[1], reverse=True)
    ld = 0
    for b, c in BC:
        D += [c] * b
        ld += b
        if ld > N:
            break
    
    res = 0
    A.sort()
    for i in range(N):
        if i < ld:
            res += max(A[i], D[i])
        else:
            res += A[i]
    

    print(res)

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

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

def getSum(list):
    sum = 0
    for i in list:
      sum = sum + i
    return sum  

prev = 0
for i in range(0,n-1):
    left = list[:i+1]
    right = list[i+1:]
    diff = abs(getSum(left) - getSum(right))
    if(i == 0):
        prev = diff
    else:
        if diff < prev:
            prev = diff
    if diff == 0:
        print(prev)
        exit()
print(prev)


### FIXED CODE ###

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

left= array[0]
right = sum(array) - left

prev = 0
for i in range(0,n-1):
    diff = abs(left - right)
    left = left + array[i+1]
    right = right - array[i+1]

    if(i == 0):
        prev = diff
    else:
        if diff < prev:
            prev = diff
print(prev)
### BUGGY CODE ###

N=int(input())
aN=list(map(int,input().split()))
aN.sort()
count =0
a_set=set(aN)
for a in a_set:
  acount=aN.count(a)
  if a <= acount:
    count+=acount-a
  else:
    count+=acount
print(count)

### FIXED CODE ###

N=int(input())
aN=list(map(int,input().split()))
dic={}
for a in aN:
  if a in dic:
    dic[a] += 1
  else:
    dic[a] = 1
ans=0
for k,v in dic.items():
  if k > v:
    ans +=v
  else:
    ans+=v-k
print(ans)
### BUGGY CODE ###

n,k = map(int,input().split())
m = [0] + list(map(int,input().split()))
p = 1

q = [1]

while True:
  p = m[p]
  if (p in q):
    break
  q.append(p)
i = q.index(p)
q1 = q[:i]
q2 = q[i:]
if len(q1) > 0 and k < len(q1):
  print(q1[k])
else: 
  print(q2[(k - len(q1)) % len(q2)])

### FIXED CODE ###

n,k = map(int,input().split())
m = [0] + list(map(int,input().split()))
p = 1

c = [0] * (n + 1)

q = [1]

while True:
  p = m[p]
  if (c[p] == 1):
    break
  c[p] += 1
  q.append(p)
i = q.index(p)
q1 = q[:i]
q2 = q[i:]
if len(q1) > 0 and k < len(q1):
  print(q1[k])
else: 
  print(q2[(k - len(q)) % len(q2)])
### BUGGY CODE ###

N = int(input())
A = [int(input()) for i in range(N)]
 
 
left_max = [-1] * N
right_max = [0]
all = sum(A)
left_max[0] = A[0]
right_max[0] = A[-1]
for i in range(1, N):
        left_max[i] = max(left_max[i-1], A[i])
for i in reversed(range(0, N-1)):
        right_max.insert(0, max(right_max[0], A[i]))
 
 
print(right_max[1])
for i in range(1,N-1):
        print(max(left_max[i-1], right_max[i+1]))
print(left_max[-2])

### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]


A_hash = {}
for i in range(N):
        if A[i] in A_hash:
                A_hash[A[i]] += 1
        else:
                A_hash[A[i]] = 1


A_max = max(A)
A_keys = list(A_hash.keys())
A_keys.sort()

if len(A_keys) > 1:
        A_second_max = A_keys[-2]
else:
        A_second_max = A_keys[-1]



for i in range(N):
        if A[i] == A_max:
                if A_hash[A_max] == 1:
                        print(A_second_max)
                else:
                        print(A_max)
        else:
                print(A_max)
### BUGGY CODE ###

N = int(input())

c = [[0]*10 for _ in range(10)]

for i in range(10):
	for j in range(10):
		for k in range(1,N+1):
			if int(str(k)[0]) == i and int(str(k)[-1]) == j:
				c[i][j] += 1


ans = 0
for i in range(10):
	for j in range(10):
		ans += c[i][j]*c[j][i]
print(ans)

### FIXED CODE ###

import numpy as np
N = int(input())

c = np.zeros((10,10),dtype = int)

for k in range(1,N+1):
	c[int(str(k)[0])][int(str(k)[-1])] += 1

ans = 0
for i in range(10):
	for j in range(10):
		ans += c[i][j]*c[j][i]
print(ans)
### BUGGY CODE ###

def main():
    NumString = int(input())
    String = input()
    
    total_ans = 0
    for i in range(NumString):
        for j in range(i, NumString):
            for k in range(j, NumString):
                if String[i] != String[j] and String[j] != String[k] and \
                    String[i] != String[k] and j - i != k - j:
                    total_ans += 1
    
    print(total_ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

NumString = int(input())
String = input()

r_string_num, g_string_num, b_string_num = 0, 0, 0
for i_string in String:
    if i_string == 'R':
        r_string_num += 1
    elif i_string == 'G':
        g_string_num += 1
    else:
        b_string_num += 1
    
total_ans = r_string_num * g_string_num * b_string_num

exclude_num = 0
for i in range(NumString-2):
    for j in range(i+1, NumString-1):
        if (2*j - i) < NumString and String[i] != String[j] and \
            String[j] != String[2*j-i] and String[i] != String[2*j-i]:
            exclude_num += 1

total_ans -= exclude_num

print(total_ans)
### BUGGY CODE ###

n=int(input())
S=['*']+list(input())+['*']

ans=n
for i in range(1,n+2):
  ans=min(ans,S[:i].count('W')+S[i:].count('E'))
print(ans)

### FIXED CODE ###

n=int(input())
S=input()

E_num=S.count('E')
W_num=0
ans=n
for i in range(n):
  if S[i]=='E':
    E_num-=1
    ans=min(ans,E_num+W_num)
  else:
    ans=min(ans,E_num+W_num)
    W_num+=1
print(ans)
### BUGGY CODE ###

R,G,B,N = map(int, input().split())
c = 0
for i in range(0,int(N/R)+1):
    for j in range(0,int((N-R*i)/G)+1):
        for k in range(0,int((N-R*i-G*j)/B)+1):
            if N-R*i-G*j-B*k == 0:
                c += 1
print(c)


### FIXED CODE ###

R,G,B,N = map(int, input().split())
c = 0
for i in range(0,int(N/R)+1):
    for j in range(0,int((N-R*i)/G)+1):
        if (N-R*i-G*j)%B == 0:
            c += 1
print(c)
### BUGGY CODE ###

import math

N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('INF')] * (10**5 + 10)

def chmin(a, b):
    if a >= b:
        return b
    else:
        return a

dp[0] = 0 #初期値 = 0
for i in range(N-1):
    for j in range(K+1):
        if i+j < N:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))
print(dp[N-1])

### FIXED CODE ###

import math

N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('INF')] * (10**5 + 10)

def chmin(a, b):
    if a >= b:
        return b
    else:
        return a

dp[0] = 0 #初期値 = 0
for i in range(N-1):
    for j in range(K+1):
        if i+j < N:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))
print(dp[N-1])
### BUGGY CODE ###

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

R_index = []
G_index = []
B_index = []

for i in range(n):
    if s[i] == 'R':
        R_index.append(i)
    elif s[i] == 'G':
        G_index.append(i)
    elif s[i] == 'B':
        B_index.append(i)

ans = 0
# print(R_index)
# print(G_index)
# print(B_index)

for i in R_index:
    for j in G_index:
        for k in B_index:
            temp_i = min(i,j,k)
            temp_k = max(i,j,k)
            temp_j = i + j + k - temp_i - temp_k
            if temp_k - temp_j == temp_j - temp_i:
                continue
            ans += 1


print(ans)


### FIXED CODE ###

n = int(input())
s = input()
ans = 0
ans_list = []

R_index = []
G_index = []
B_index = []

for i in range(n):
    if s[i] == 'R':
        R_index.append(i)
    elif s[i] == 'G':
        G_index.append(i)
    elif s[i] == 'B':
        B_index.append(i)

ans = len(R_index) * len(G_index) * len(B_index)

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

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

N=int(input())
a=input().split()
cards=[int(b) for b in a]
whole=sum(cards)
answers=[]
for c in range(N-1):
    sunuke=cards[:c+1]
    goukei=sum(sunuke)
    answers.append(abs(whole-goukei*2))
print(min(answers))


### FIXED CODE ###

N=int(input())
a=input().split()
a=[int(b) for b in a]
numbers=[]
number=0
for a_ in a:
    number+=a_
    numbers.append(number)
del numbers[-1]
if N==2:
    print(abs(a[0]-a[1]))
else:
    whole=sum(a)
    answers=[]
    for number in numbers:
        answer=abs(number*2-whole)
        answers.append(answer)
    print(min(answers))
### BUGGY CODE ###

N = int(input())
a = list(map(int,input().split()))
b = list(set(a))
cnt = 0
for i in range(len(b)):
  c = a.count(b[i])
  if b[i] <= c:
    cnt += c - b[i]
  else:
    cnt += c
print(cnt)

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
b = list(set(a))
ans = 0
for i in range(len(b)):
  cnt = 1
  while len(a) > 1 and a[-1] == a[-2]:
    a.pop()
    cnt += 1
  c = a.pop()
  if c <= cnt:
    ans += cnt - c
  else:
    ans += cnt
print(ans)
### BUGGY CODE ###

H = int(input())
n = 1
h = H
while True:
    n *= 2
    h = h//2
    if h == 1:
        break
print(n*2-1)


### FIXED CODE ###

H = int(input())
n = 1
h = H
while True:
    if h == 1:
        break
    n *= 2
    h = h//2

print(n*2-1)
### BUGGY CODE ###

n,W=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
dp=[-1]*(W+1)
dp[0]=0
for w,v in wv:
    for i in range(W-w,-1,-1):
        if dp[i]==-1:continue
        nv=dp[i]+v
        if nv>dp[i+w]:
            dp[i+w]=nv
print(max(dp))

### FIXED CODE ###

import sys
input=sys.stdin.readline

n, cap = map(int, input().split())
val =[0]*(cap+1)
def nap(n,cap):
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap,w-1,-1):
            nv=val[wk-w]+v
            if val[wk]<nv:
                val[wk]=nv
    return max(val)
print(nap(n,cap))
### BUGGY CODE ###

import copy

n = int(input())
value_list = []

for i in range(n):
    value_list.append(int(input()))

for i in range(n):
    keep_list = copy.copy(value_list)
    keep_list[i] = 0
    print(max(keep_list))

### FIXED CODE ###

n = int(input())
value_list = []

for i in range(n):
    value_list.append(int(input()))

most_max = max(value_list)

if len([i for i, x in enumerate(value_list) if x == most_max]) == 2:
    for i in range(n):
        print(most_max)
else:
    most_max_index = value_list.index(most_max)
    value_list[most_max_index] = 0
    second_max = max(value_list) 
    value_list[most_max_index] = most_max
    
    for i in range(n):
        if value_list[i] == most_max:
            print(second_max)
        else:
            print(most_max)
### BUGGY CODE ###


from itertools import permutations

def power(base, exp):
  """ Fast power calculation using repeated squaring """
  if exp < 0:
      return 1 / power(base, -exp)
  ans = 1
  while exp:
      if exp & 1:
          ans *= base
      exp >>= 1
      base *= base
  return ans

def parse():
  return int(input())

def main():
  X = parse()

  A = None
  B = None

  # Z = [i for i in range(0, 5)]
  # print(Z)
  # print(list(permutations(range(0, 5), 2)))
  # print(list(permutations(range(0, 5), 2)))
  # exit(0)

  max_val = 1000
  signs = [[1, 1], [-1, 1], [1, -1], [-1, -1]]

  for i in range(0, max_val + 1):
    for j in range(0, max_val + 1):
      for sign in signs:
        # A5 = 
        # print(i * sign[0], j * sign[1])
        if power(i * sign[0], 5) - power(j * sign[1], 5) == X:
          A = i * sign[0]
          B = j * sign[1]
          break

  print(A, B)

if __name__ == "__main__":
  main()

### FIXED CODE ###


from itertools import permutations

def power(base, exp):
  """ Fast power calculation using repeated squaring """
  if exp < 0:
      return 1 / power(base, -exp)
  ans = 1
  while exp:
      if exp & 1:
          ans *= base
      exp >>= 1
      base *= base
  return ans

def parse():
  return int(input())

def main():
  X = parse()

  A = None
  B = None

  # Z = [i for i in range(0, 5)]
  # print(Z)
  # print(list(permutations(range(0, 5), 2)))
  # print(list(permutations(range(0, 5), 2)))
  # exit(0)

  max_val = 1000
  signs = [[1, 1], [-1, 1], [1, -1], [-1, -1]]

  for i in range(0, max_val + 1):
    for j in range(0, max_val + 1):
      for sign in signs:
        # A5 = 
        # print(i * sign[0], j * sign[1])
        if power(i * sign[0], 5) - power(j * sign[1], 5) == X:
          A = i * sign[0]
          B = j * sign[1]
          print(A, B)
          exit(0)
  print(0, 0)

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

n=int(input())
x=list(map(int,input().split()))
ans=1
for i in x:
  ans=ans*i
  if ans>10**18:
    ans=-1
print(ans)

### FIXED CODE ###

n=int(input())
x=list(map(int,input().split()))
ans=1
for i in x:
  if i==0:
    print(0)
    exit()

for i in x:
    ans=ans*i
    if ans>10**18:
      ans=-1
      break
print(ans)
### BUGGY CODE ###

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

sum = 0

for i in range(n-1):
    sum_i = 0
    for j in range(n-i-1):
        sum_i += a[-(j+1)]
    sum += (sum_i * a[i])

print(sum%((10 ** 9)+7))

### FIXED CODE ###

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

sum_a = 0
sum_i = sum(a)

for i in range(n-1):
    sum_i -= a[i]
    sum_a += (a[i] * sum_i)

print(sum_a%((10 **9)+7))
### BUGGY CODE ###

N,M=[int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]

_A=[0]

for i in range(N):
    _A.append((_A[-1]+A[i])%M)
count=0





for i in set(_A):
    _count=_A.count(i)

    count+=(_count-1)*_count/2
print(int(count))


### FIXED CODE ###

N,M=[int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]

_A=[0]
sum=0
d={0:1}
key=[0]
for i in range(N):
    sum=(sum+A[i])%M
    try:
        d[sum]+=1
    except KeyError:
        d[sum]=1
        key.append(sum)

count=0
for i in key:
    _count=d[i]

    count+=(_count-1)*_count/2
print(int(count))
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split()]

ans = []
for i in range(len(a)):
  ans.append(a[i])
  ans = ans[::-1]

print(" ".join(list(map(str, ans))))

### FIXED CODE ###

n=int(input())
a=[i for i in input().split()]

b=[]
c=[]
if n%2==0:
    for i in range(n):
        if i%2==0:
            b.append(a[i])
        else:
            c.append(a[i])
else:
    for i in range(n):
        if i%2==0:
            c.append(a[i])
        else:
            b.append(a[i])
c=c[::-1]
print(" ".join(c)+" "+" ".join(b))
### BUGGY CODE ###

n,p=map(int,input().split())
 
if n==1:
    print(p)
else:
    x=round((p**(1/n)+1))+1
    for i in range(x,0,-1):        
        if p%i==0:
            if p%(i**2)==0:
                if p%(i**n)==0:
                    print(i)
                    break
 

### FIXED CODE ###

N, P = map(int, input().split())
ans = 1
 
if N >= 45:
  print(ans)
elif N == 1:
  print(P)
  
 
  
else:
  i = 1
  while(i**N <= P):
    if P % (i**N) == 0:
      ans = i
    i += 1
  print(ans)
### BUGGY CODE ###

s = input()
k = int(input())
substrings = []
for i in range(len(s)):##初期位置
  for j in range(1,len(s)-i+1):##長さ
    substrings.append(s[i:i+j])
print(sorted(list(set(substrings)))[k-1])

### FIXED CODE ###

s = input()
k = int(input())
substrings = []
index = []
for ss in sorted(list(set(s))):
  index_list = [n for n, v in enumerate(s) if v == ss]
  for i in index_list:##初期位置
    for j in range(1,min(k+1,len(s)-i+1)):##長さ
      substrings.append(s[i:i+j])
  if len(set(substrings)) >= k:
    break
print(sorted(list(set(substrings)))[k-1])
### BUGGY CODE ###

N, K, Q = map(int, input().split())
A=[int(input()) for _ in range(Q)]
P = [K] * N

for i in range(N):
    ans = K - Q + A.count(i+1)
    # print(ans)
    if ans > 0:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

N, K, Q = map(int, input().split())
P = [0] * N

for i in range(Q):
    P[int(input())-1] += 1
for i in range(N):
    ans = K - Q + P[i]
    # print(ans)
    if ans > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

MOD=10**9+7
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
if n==1:
  print(1)
  exit()
if 1 in a and 2 in a:
  print(0)
  exit()
elif 1 in a:
  ans=[0,1]
elif 2 in a:
  ans=[1,0]
else:
  ans=[1,2]

for i in range(2,n):
  if i+1 in a:
    ans.append(0)
  else:
    s=(ans[-1]+ans[-2])%MOD
    ans.append(s)
print(ans[-1]%MOD)

### FIXED CODE ###

N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]
a.sort(reverse=True)

if 1 in a:
  a.pop()
  fibs = [1,0]
else:
  fibs = [1,1]

for i in range(2,N+1):
  if len(a) > 0 and i == a[-1]:
    a.pop()
    fibs[0] = fibs[1]
    fibs[1] = 0
  else:
    next = fibs[1] + fibs[0]
    if next > 1000000007:
      next -= 1000000007
    fibs[0] = fibs[1]
    fibs[1] = next

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

from fractions import gcd

K = int(input())

res = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            res += gcd(gcd(i,j),k)
print(res)


### FIXED CODE ###

from math import gcd

K = int(input())

res = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        tmp = gcd(i,j)
        for k in range(1,K+1):
            res += gcd(tmp,k)
print(res)
### BUGGY CODE ###

N,K = map(int,input().split())
H = list(map(int,input().split()))

while(K>0):
    maxHeath = max(H)
    ind = H.index(maxHeath)
    H[ind]=0
    K-=1

allAttack = 0
for i in range(0,N):
    allAttack+=H[i]
print(allAttack)

### FIXED CODE ###

N,K = map(int,input().split())
H = list(map(int,input().split()))

H.sort()

for i in range(0,K):
    if H:
      H.pop()

print(sum(H))
### BUGGY CODE ###

import numpy as np
import itertools
N, M=map(int, input().split())
a =[]
c = []
for i in range(2*M):
  if i%2 == 0:
    temp,_=map(int, input().split()) 
    a.append(temp)
  else:
    temp=list(map(int, input().split()))
    c.append(temp)
a = np.array(a) 
mini = -1
for n in range(M):
    for l in list(itertools.combinations(range(M),n+1)):
        temp = []
        for nn in l:
            temp = temp +c[nn]
        temp = set(temp)
        temp = list(temp)
        if len(temp) == N:
            cost = sum(a[[np.array(l)]])
            if mini == -1 or mini > cost:
                mini = cost


print(mini)  

### FIXED CODE ###

N, M = map(int, input().split())
Inf = 10**8
Dp = [Inf]*(2**N)
Dp[0] = 0

for i in range(M): #カギiで
    a,_=map(int, input().split())
    c = list(map(int, input().split()))
    d = sum((1<<p-1) for p in c) #iで開けられる宝箱の2bit表記
    for j in range(2**N):
        ope = j|d
        Dp[ope] = min(Dp[ope], Dp[j] + a)

if Dp[-1] == Inf:
    print(-1)
else:
    print(Dp[-1])
### BUGGY CODE ###

import math
import numpy as np
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
num_list =  input().split(' ')
num_list2 = [int(n) for n in num_list]
num_list3 = [0]*n
num_list4 = [0]*n
num_list5 = [0]*n
for i in range(len(num_list2)):
    num_list3[num_list2[i]-1] += 1
for i in range(len(num_list2)):
    if num_list4[num_list2[i]-1] == 0:
        size = max(0 , num_list3[num_list2[i]-1])
        if size >= 2:
            ans = comb(size,2)
        elif size == 1:
            ans = 0
        else :
            ans = 0 
        num_list4[num_list2[i]-1] = ans

    if num_list5[num_list2[i]-1] == 0:
        size = max(0 , num_list3[num_list2[i]-1]-1)
        if size >= 2:
            ans = comb(size,2)
        elif size == 1:
            ans = 0
        else :
            ans = 0 
        num_list5[num_list2[i]-1] = ans
for i in range(n):
    print(num_list5[num_list2[i]-1]-num_list4[num_list2[i]-1]+np.sum(num_list4))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
cnt = [0] * n
for i in a:
    cnt[i-1] += 1
total = [0] * n
for i in range(n):
    total[i] = cnt[i] * (cnt[i] - 1) // 2
total_sum = sum(total)
for i in a:
    ans = total_sum
    ans -= total[i-1]
    ans += (cnt[i-1] - 1) * (cnt[i-1] - 2) // 2
    print(ans)
### BUGGY CODE ###

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

l = [1 for _ in range(a)] + [0 for _ in range(b)] + [-1 for _ in range(c)]
print(sum(l[:k]))

### FIXED CODE ###

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

ans = 0
ans += min(a, k)
ans -= max(0, k - a - b) 

print(ans)