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

import sys

S = sys.stdin.readline().strip()
X,Y=map(int,input().split())
A=len(S)

def check_ans(s,x):
  if len(s)==0:
    return x==0
  
  dp=[[False for i in range(A)] for j in range(len(s)+1)]
  dp[1][s[0]]=True
  for i in range(1,len(s)):
    for j in range(0,A):
      if dp[i][j]:
        res=abs(j+s[i])
        res2=abs(j-s[i])
        dp[i+1][res]=True
        dp[i+1][res2]=True
  return dp[len(s)][x]

d=1
while S and S[0]=='F':
  S=S[1:]
  X-=1
if len(S)==0:
  if X==0 and Y==0:
    print("Yes")
  else:
    print("No")
  sys.exit()

nx=[]
ny=[]
X=abs(X)
Y=abs(Y)

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if step==0:
    break
  if d==1:
    nx.append(step)
  else:
    ny.append(step)

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

import sys

def check_ans(s,x):
  res=[0]
  for i in s:
    res = set([x + i for x in res]) | set([x - i for x in res])
  return x in res

S = sys.stdin.readline().strip()
X,Y=map(int,input().split())
d=1
while S and S[0]=='F':
  S=S[1:]
  X-=1
if len(S)==0:
  if X==0 and Y==0:
    print("Yes")
  else:
    print("No")
  sys.exit()

nx=[]
ny=[]
X=abs(X)
Y=abs(Y)

while S:
  step=0
  while S and S[0]=='T':
    d*=-1
    S=S[1:]
  while S and S[0]=='F':
    step+=1
    S=S[1:]
  if step==0:
    break
  if d==1:
    nx.append(step)
  else:
    ny.append(step)

if check_ans(nx,X) and check_ans(ny,Y):
  print("Yes")
else:
  print("No")
### BUGGY CODE ###

def check(s, m, parity):
    lo = parity
    hi = m - (m - parity) % 2

    for c in s:
        if c == '0':
            lo += 1
            hi += 1
        elif c == '1':
            lo -= 1
            hi -= 1
        else:
            lo -= 1
            hi += 1

        if lo < 0:
            lo += 2
        if hi > m:
            hi -= 2

        if lo > hi:
            return False

    return True


s = input()
l, r = 0, len(s)
while l + 1 < r:
    m = (l + r) // 2
    if check(s, m, 0) or check(s, m, 1):
        r = m
    else:
        l = m
print(r)


### FIXED CODE ###

def check(s, m, parity):
    lo = parity
    hi = m - (m - parity) % 2

    for c in s:
        if c == '0':
            lo += 1
            hi += 1
        elif c == '1':
            lo -= 1
            hi -= 1
        else:
            lo -= 1
            hi += 1

        if lo < 0:
            lo += 2
        if hi > m:
            hi -= 2

        if lo > hi:
            return False

    return True


s = input()
l, r = 0, len(s)
while l + 1 < r:
    m = (l + r) // 2
    if check(s, m, 0) or check(s, m, 1):
        r = m
    else:
        l = m
print(r)
### BUGGY CODE ###

n = int(input())
def digit_sum(n):
    # 各桁の和を求める
    # 計算量: O(logN)
    ans = 0
    while n > 0:
        ans += n % 10
        n //= 10
    return ans
s = digit_sum(n)
if s % 9 == 0:
    print('Yes')
else:
    print('No')



### FIXED CODE ###

n = int(input())
if n % 9 == 0:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

# 小さいのでメモ化再帰でいけるか？
# （[ここまでの回答数, ここまでの点数]みたいなやつ）
# んーーーーーー？？？？ RE*1、あとTLEになる。。。
# REはどうせ再帰の制限
import sys

sys.setrecursionlimit(10 ** 8)

d, g = map(int, input().split())
memo = {}
points, bonus = [], []
for _ in range(d):
    p, c = map(int, input().split())
    points.append(p)
    bonus.append(c)


def f(c, p):
    if (c, p) in memo:
        return memo[(c, p)]
    if p >= g:
        return c
    ret = 10 ** 10
    for i in range(d):
        if points[i] == 1:
            points[i] = 0
            ret = min(ret, f(c + 1, p + (i + 1) * 100 + bonus[i]))
            points[i] = 1
        elif points[i] > 1:
            points[i] -= 1
            ret = min(ret, f(c + 1, p + (i + 1) * 100))
            points[i] += 1
        elif points[i] == 0:
            continue
        else:
          print(3/0)
    memo[(c, p)] = ret
    return ret


print(f(0, 0))


### FIXED CODE ###

# 未知のアルゴリズムか天才系DPかと思ってすぐ諦めて解説読んでしまった

d, g = map(int, input().split())
points = []
for _ in range(d):
    p, c = map(int, input().split())
    points.append((p, c))
ans = 10**12
for bit in range(2**d):
    arr = [False] * d
    for i in range(d):
        if bit >> i & 1 == 1:
            arr[i] = True
    tmp_sum = 0
    count = 0
    for i in range(d):
        if arr[i]:
            # kompuli-to
            tmp_sum += points[i][1]
            tmp_sum += (i + 1) * 100 * points[i][0]
            count += points[i][0]
    if tmp_sum < g:
        # 達成できるまで得点の高いやつからやっていく
        for i in range(d - 1, -1, -1):
            if arr[i]:
                # すでにkompuli-toしてるので
                continue
            used = 0
            for j in range(points[i][0]):
                if tmp_sum < g:
                    tmp_sum += (i + 1) * 100
                    count += 1
                    used += 1
            if used == points[i][0]:
                tmp_sum += points[i][1]
            if tmp_sum >= g:
                break
    ans = min(ans, count)
print(ans)
### BUGGY CODE ###

s = input()
for n in range(len(s)):
    if s[n:n+2] == 'BC':
        s = s[:n]+'D'+s[n+2:]
#print(s)
ans = 0
cnta = 0
for n in range(len(s)):
    if s[n] == 'A':
        cnta += 1
    elif s[n] == 'D':
        ans += cnta
    elif s[n] == 'B' or s[n] == 'C':
        cnta = 0

print(ans)

### FIXED CODE ###

s = input()
s = s.replace('BC','D')

ans = 0
cnta = 0
for n in range(len(s)):
    if s[n] == 'A':
        cnta += 1
    elif s[n] == 'D':
        ans += cnta
    elif s[n] == 'B' or s[n] == 'C':
        cnta = 0

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

k=int(input())
lst = [k+1]*k
queue = [1]
lst[1] = 1
while queue:
    a = queue.pop(0)
    if lst[a*10%k] > lst[a]:
        lst[a*10%k] = lst[a]
        queue.insert(0,a*10%k)
    if lst[(a+1)%k]>= lst[a]+1:
        lst[(a+1)%k] = lst[a]+1
        queue.append((a+1)%k)
print(lst[0])

### FIXED CODE ###

import collections
k=int(input())
lst = [k+1]*k
q = collections.deque([1])
lst[1] = 1
while q:
    a = q.pop()
    if lst[a*10%k] > lst[a]:
        lst[a*10%k] = lst[a]
        q.append(a*10%k)
    if lst[(a+1)%k]>= lst[a]+1:
        lst[(a+1)%k] = lst[a]+1
        q.appendleft((a+1)%k)
print(lst[0])
### BUGGY CODE ###

n = int(input())
a = [''.join(sorted(input())) for i in range(n)]
b = []
ans = 0
for i in range(n) :
    x = a[i]
    if x in b :
        ans += b.count(x)
        b.append(x)
    else :
        b.append(x)
print(ans)


### FIXED CODE ###

n = int(input())
a = [''.join(sorted(input())) for i in range(n)]
ans = 0
count = 0
a.sort()
for i in range(1,n) :
    if a[i] == a[i-1] :
        count += 1
        ans += count
    else :
        count = 0
print(ans)
### BUGGY CODE ###

n = int(input())
li =[list(map(int,input().split())) for i in range(1,n+1)]

cnt = 0
check = []
play = 0

while play < n*(n-1) // 2:
    s = play
    for i in range(1,n):
        if i in check or len(li[i-1]) == 0:
            continue
        temp = li[i-1][0]
        if temp <= i:
            continue
        if li[temp-1][0] == i and temp not in check:
            del li[i-1][0]
            del li[temp-1][0]
            play += 1
            check.append(temp)
    cnt += 1
    check = []
    
    if s == play:
        print(-1)
        exit()

print(cnt)


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
 
N = int(input())
A = [[-1] + [int(x)-1 for x in row.split()][::-1] for row in sys.stdin.readlines()]
 
A.append([-1])

def f(cand):
    cand1 = set()
    can_use = []
    for n in cand:
        if A[A[n][-1]][-1] == n:
            can_use.append(n)
    for n in can_use:
        A[n].pop()
        cand1.add(n)
        if A[n][-1] != -1:
            cand1.add(A[n][-1])
    return len(can_use), cand1
    
answer = 0
rest = N*(N-1)
cand = set(range(N))
while True:
    answer += 1
    x,cand = f(cand)
    if x == 0:
        answer = -1
        break
    rest -= x
    if rest == 0:
        break
    
print(answer)
### BUGGY CODE ###

n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
x = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if a[i] < b[j] < c[k]:
                x += 1
print(x)

### FIXED CODE ###

import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
ans = 0
for i in b:
    aa = bisect.bisect_left(a, i)
    cc = n-bisect.bisect_right(c, i)
    ans += aa*cc
print(ans)
### BUGGY CODE ###

import sys

input = sys.stdin.readline

def main():
    n = int(input().rstrip())
    a = list(map(int, input().rstrip().split()))
    count = 0
    for i in range(n):
      count_temp = 0
      for k in range(n):
        if i != k and a[i] % a[k] == 0:
          count_temp += 1
          break
      if count_temp == 0:
        count += 1
    print(count)
  
if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import Counter
import sys
n=int(input())
a=sorted(list(map(int,input().split())))
 
c=[1 for i in range(10**6+1)]
d = Counter(a)
s = list(set(a))
count = 0
if d[1] == 1:
  print(1)
  sys.exit()
elif d[1] >=2:
  print(0)
  sys.exit()
for x in s:
  t = x * 2
  while t <= 10 ** 6:
    c[t] = 0
    t += x
 
for x in a:
  if d[x] == 1 and c[x] == 1:
    count += 1
print(count)
### BUGGY CODE ###

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

a_list = []
tmp = []
for i in range(m):
    a, b = map(int, input().split())
    
    # 島1から出ている船の行き先
    if a == 1:
        tmp.append(b)
    
    # 島1から意外の運航便のリスト
    else:
        a_list.append([a, b])

a_list.sort(key=lambda x: x[0])
tmp.sort()
#print(a_list)
#print(tmp)

possible = 0
for b in tmp:
    #print(a_list)

    for j in range(len(a_list)):
        if len(a_list) == 1:
            if a_list[0][1] == n:
                possible = 1

        elif a_list[j][0] < b:
            a_list.pop(j)

        elif a_list[j][0] == b:
            if a_list[j][1] == n:
                possible = 1
                break
        else:
            break

if possible == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

    


### FIXED CODE ###

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

a_list = []
tmp_start = []
tmp_goal = []
for i in range(m):
    a, b = map(int, input().split())
    
    # 島1から出ている船の行き先
    if a == 1:
        tmp_start.append(b)
    
    if b == n:
        tmp_goal.append(a)
    

    # 島1から意外の運航便のリスト
    #else:
    #    a_list.append([a, b])

agree = set(tmp_start) & set(tmp_goal)

if len(agree) == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

#for j in tmp_start:
#    if j in tmp_goal:
#        print('POSSIBLE')
#        break

#else:
#    print('IMPOSSIBLE')
### BUGGY CODE ###

N,M = map(int,input().split())
H = list(map(int,input().split()))
road = []
for i in range(M):
    road.append(list(map(int,input().split())))

def judge(i):
    for r in road:
        pair = 0
        if r[0]==i:
            pair = r[1]
        if r[1]==i:
            pair = r[0]
        if pair !=0 and H[i-1] <= H[pair-1]:
            return 0
    return 1

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

print(s)

### FIXED CODE ###

N,M = map(int,input().split())
H = list(map(int,input().split()))
road = []
for i in range(M):
    road.append(list(map(int,input().split())))

judge = [1]*N

for r in road:
    h1 = H[r[0]-1]
    h2 = H[r[1]-1]
    if h1 < h2:
        judge[r[0]-1] = 0
    if h1 == h2:
        judge[r[0]-1] = judge[r[1]-1] = 0
    if h1 > h2:
        judge[r[1]-1] = 0

print(sum(judge))
### BUGGY CODE ###

H,W,D = [int(x) for x in input().split()]

d = {}

masu = [[int(x) for x in input().split()] for _ in range(H)]


for y in range(H):
    for x in range(W):
        v=masu[y][x]
        d[v] = (x,y)

Q = int(input())

for _ in range(Q):
    f,t = [int(x) for x in input().split()]
    n = int((t-f)/D)
    mp = 0
    currentV = f
    for _ in range(n):
        prev = d[currentV]
        nxt = d[currentV+D]
        mp += abs(prev[0]-nxt[0])+abs(prev[1]-nxt[1])
        currentV += D
    print(mp)


### FIXED CODE ###

H,W,D = [int(x) for x in input().split()]

d = {}

masu = [[int(x) for x in input().split()] for _ in range(H)]


for y in range(H):
    for x in range(W):
        v=masu[y][x]
        d[v-1] = (x,y)

mpDict = {}

for i in range(D):
    
    modD = i
    mpDict[modD] = {}
    index = modD
    acc = 0
    mpDict[modD][i] = 0
    index+=D
    while index<H*W:
        #print()
        #print("i",i)
        #print(index)
        prev = d[index-D]
        #print(prev)
        nxt = d[index]
        #print(nxt)
        acc += abs(prev[0]-nxt[0])+abs(prev[1]-nxt[1])
        mpDict[modD][index] = acc
        index+=D



Q = int(input())

for _ in range(Q):
    f,t = [int(x) for x in input().split()]
    modD = (f-1)%D
    mp = mpDict[modD][t-1] - mpDict[modD][f-1]
    print(mp)
### BUGGY CODE ###

k = int(input())
mod = 7 % k
if k % 2 == 0:
    print(-1)
else:
    ans = 1
    while mod != 0:
        mod = (10*mod + 7) % k
        ans += 1
        if ans >= 10**10:
            print(-1)
            break
    if ans < 10**10:
        print(ans)

### FIXED CODE ###

k = int(input())
mod = 7 % k
if k % 2 == 0:
    print(-1)
else:
    ans = 1
    while mod != 0:
        mod = (10*mod + 7) % k
        ans += 1
        if ans >= 10**7:
            print(-1)
            break
    if ans < 10**7:
        print(ans)
### BUGGY CODE ###

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

S=[a,b]
M=max(S)

for i in range(M):
  if abs(a-i)==abs(b-i):
    print(i)
    exit()
print("IMPOSSIBLE")

### FIXED CODE ###

A,B=map(int, input().split())
 
if (A+B)%2==0:
	print(int((A+B)/2))
else:
	print("IMPOSSIBLE")
### BUGGY CODE ###

n,a,b = map(int,input().split())
h = []
for i in range(n):
	x = int(input())
	h.append(x)
counter = 0
while max(h) > 0:
	counter += 1
	indexnumber = h.index(max(h))
	h[indexnumber] = h[indexnumber] - a
	for i in range(indexnumber):
		h[i] = h[i] - b
	for i in range(indexnumber+1,n):
		h[i] = h[i] -b
print(counter)

### FIXED CODE ###

def judge(h,t,a,b,n):
    counter = 0
    for i in range(n):
        if h[i] > b*t:
            if ((h[i]-b*t)/(a-b))%1 == 0:
                counter += (h[i]-b*t)//(a-b)
            else:
                counter += (h[i]-b*t)//(a-b) + 1
    if counter <= t:
        return True
    else:
        return False

n,a,b = map(int,input().split())
h = []
for i in range(n):
    temp = int(input())
    h.append(temp)

left = 1
right = max(h)//b + 1

while abs(right-left) > 1:
    check = judge(h,(left+right)//2,a,b,n)
    if check:
        right = (left+right)//2
    else:
        left = (left+right)//2

if judge(h,left,a,b,n):
    print(left)
else:
    print(right)
### BUGGY CODE ###

import sys
# A,B,C = [int(n) for n in input().split()]
N,K = [int(n) for n in input().split()]
# S = str(input())
# T = str(input())
bucket = [0]*(N+1)
A = [int(n) for n in input().split()]
s = set(A)
for a in A:
    bucket[a]+=1
bucket = [n for n in bucket if n != 0]
rc = len(s) - K
ans = 0
for r in range(rc):
    tmin = min(bucket)
    ans += tmin
    bucket[bucket.index(tmin)]=200006
print(ans if ans >=0 else 0)


### FIXED CODE ###

import sys
# A,B,C = [int(n) for n in input().split()]
N,K = [int(n) for n in input().split()]
# S = str(input())
# T = str(input())
bucket = [0]*(N+1)
A = [int(n) for n in input().split()]
dic = {}
for a in A:
    if not(a in dic):
        dic[a]=1
    else:
        dic[a]+=1
val = sorted(dic.values())
# print(val)
rc = len(val) - K
ans = 0
for r in range(rc):
    ans += val[r]
print(ans if ans >=0 else 0)
### BUGGY CODE ###

a,b,c,k=map(int,input().split())
if a==b and b==c:
    print(0)
else:
    for i in range(k):
        a,b,c=b+c,a+c,a+b
    if abs(a-b)>10**18:
        print("Unfair")
    else:
        print(a-b)
    

### FIXED CODE ###

a,b,c,k=map(int,input().split())
if abs(a-b)<10**18:
    if k%2==0:
        print(a-b)
    else:
        print(b-a)
else:
    print("Unfair")
### BUGGY CODE ###

N = int(input())
ans = 0
for i in range(N):
    ans += i
print(ans)

### FIXED CODE ###

N = int(input())
print(N*(N-1)//2)
### BUGGY CODE ###

n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))


for i in range(n):
    max_temp=a[i]
    a[i]=0
    
    maxmax=max(a)
    print(maxmax)
    a[i]=max_temp

### FIXED CODE ###

n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))

maxmax=max(a)
maxmax_ind=a.index(maxmax)
a[maxmax_ind]=0
maxmax2=max(a)
a[maxmax_ind]=maxmax

if maxmax==maxmax2:
    for i in range(n):
        print(maxmax)

else:
    for i in range(n):
        if i==maxmax_ind:
            print(maxmax2)
        else:
            print(maxmax)
### BUGGY CODE ###

from collections import deque

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

chart = [list(input()) for _ in range(H)]

start = (-1, -1)
for h in range(H):
    for w in range(W):
        if chart[h][w] == 'S':
            start = (h, w)
            chart[h][w] = '.'

minDist  = [[float('inf')] * W for _ in range(H)]
que = deque([(start[0], start[1], 0)])
while que:
    nh, nw, dist = que.popleft()

    minDist[nh][nw] = dist
    if dist == K:
        continue

    for toH in [nh - 1, nh + 1]:
        if toH < 0 or toH >= H:
            continue
        if chart[toH][nw] == '.':
            que.append((toH, nw, dist + 1))
    for toW in [nw - 1, nw + 1]:
        if toW < 0 or toW >= W:
            continue
        if chart[nh][toW] == '.':
            que.append((nh, toW, dist + 1))

ans = float('inf')
for h in range(H):
    for w in range(W):
        if minDist[h][w] == float('inf'):
            continue
        d = min(h, w, H - h - 1, W - w - 1)
        if d == 0:
            ans = min(ans, 1)
        else:
            ans = min(ans, -(-d // K) + 1)

print(ans)

### FIXED CODE ###

from collections import deque

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

chart = [list(input()) for _ in range(H)]

start = (-1, -1)
for h in range(H):
    for w in range(W):
        if chart[h][w] == 'S':
            start = (h, w)
            chart[h][w] = '.'

minDist  = [[float('inf')] * W for _ in range(H)]
que = deque([(start[0], start[1], 0)])
while que:
    nh, nw, dist = que.popleft()

    if minDist[nh][nw] <= dist:
        continue

    minDist[nh][nw] = dist
    if dist == K:
        continue

    for toH in [nh - 1, nh + 1]:
        if toH < 0 or toH >= H:
            continue
        if chart[toH][nw] == '.':
            que.append((toH, nw, dist + 1))
    for toW in [nw - 1, nw + 1]:
        if toW < 0 or toW >= W:
            continue
        if chart[nh][toW] == '.':
            que.append((nh, toW, dist + 1))

ans = float('inf')
for h in range(H):
    for w in range(W):
        if minDist[h][w] == float('inf'):
            continue
        d = min(h, w, H - h - 1, W - w - 1)
        if d == 0:
            ans = min(ans, 1)
        else:
            ans = min(ans, -(-d // K) + 1)

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

def resolve():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    points = [0 for _ in range(N+1)]
    acc = 1
    for i in range(1, N+1):
        if i < K:
            points[i] = 0
            acc *= A[i-1]
        else:
            acc *= A[i-1]
            points[i] = acc
            acc /= A[i-K]
    #print(points)
    for i in range(K, N):
        if points[i] < points[i+1]:
            print("Yes")
        else:
            print("No")


    
if '__main__' == __name__:
    resolve()

### FIXED CODE ###

def resolve():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    for i in range(K, N):
        if A[i-K] < A[i]:
            print("Yes")
        else:
            print("No")


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

mod = 10**9+7
n,a,b = map(int, input().split())
ans = 0
c = 1
x = n
y = 1
if a!=n and b!=n: ans+=c
for i in range(1,(n+2)//2):
    c = c*x//y
    x-=1
    y+=1
    ans += c*2
    if i==a or n-i==a:
        ans -= c
    if i==b or n-i==b:
        ans -= c
    if i==n/2:
        ans -= c

print(ans%mod)

### FIXED CODE ###

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

mod = 10**9+7
ans = pow(2,n,mod)-1

nca = 1
ncb = 1

for i in range(b):
    ncb = ncb*(n-i)%mod
    ncb *= pow(i+1,mod-2,mod)
    if i+1==a:
        nca = ncb

ans -= nca+ncb
print(ans%mod)
### BUGGY CODE ###

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

ans = 0

for i in range(N):
    count = 0
    tmp = A[i]
    for j in range(i+1):
        if tmp <= A[j]:
            count += 1
        else:
            break

    if count == i+1:
        ans += 1

print(ans)


### FIXED CODE ###

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

minv = 10 ** 9
ans = 0

for i in P:
    if i < minv:
        ans += 1
        minv = i

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

N = int(input())
A = list(map(int, input().split()))
val2ind = {}
for i, one in enumerate(A):
    if one not in val2ind:
        val2ind[one] = []
    val2ind[one].append(i)

Q = int(input())

for _ in range(Q):
    B, C = list(map(int, input().split()))
    if B in val2ind:
        cand = val2ind[B]
        del val2ind[B]
        if C not in val2ind:
            val2ind[C] = cand
        else:
            cand.extend(val2ind[C])
            val2ind[C] = list(set(cand))
    print(sum([key*len(val2ind[key]) for key in val2ind]))

### FIXED CODE ###

from collections import Counter
N = int(input())
val2ind = Counter(list(map(int, input().split())))
ans = sum([key*val2ind[key] for key in val2ind])
Q = int(input())

for _ in range(Q):
    B, C = list(map(int, input().split()))
    if B in val2ind:
        cand = val2ind[B]
        del val2ind[B]
        if C not in val2ind:
            val2ind[C] = cand
        else:
            val2ind[C] += cand
        ans = ans+(C-B)*cand
    print(ans)
### BUGGY CODE ###

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

def Ans(x):
    s=math.floor(a*x/b)
    t=a*math.floor(x/b)
    return s-t

ans=0
for i in range(b//a,n+1):
    ans=max(Ans(i),ans)

print(Ans(min(b-1,n)))

### FIXED CODE ###

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

def Ans(x):
    s=math.floor(a*x/b)
    t=a*math.floor(x/b)
    return s-t

ans=0
print(Ans(min(b-1,n)))
### BUGGY CODE ###

n=int(input())
s=input()
cnt=0
for i in range(n):
    for j in range(i+1,n):
        if s[i]!=s[j]:
            for k in range(j+1,n):
                if s[i]!=s[k] and s[j]!=s[k] and k-j!=j-i:
                    cnt+=1
print(cnt)
        

### FIXED CODE ###

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

import numpy as np

N, M = map(int, input().split())
LR = [[int(i) for i in input().split()] for i in range(M)]
ID = np.zeros(N)
for i in range(M):
    ID[LR[i][0] - 1:LR[i][1]] += 1
print(np.count_nonzero(ID == M))


### FIXED CODE ###

N, M = map(int, input().split())
L = [0] * M
R = [0] * M
for i in range(M):
    L[i], R[i] = map(int, input().split())
max_L = max(L)
min_R = min(R)
if(min_R - max_L + 1 > 0):
    print(min_R - max_L + 1)
else:
    print(0)
### BUGGY CODE ###

#coding: utf-8
K,S=map(int,input().split(" "))
answer=0
for X in range(K+1):
  for Y in range(K+1):
    if S-(X+Y)<=K and S-(X+Y)>=0:
      answer+=1
print(answer)

### FIXED CODE ###

#coding: utf-8
K,S=map(int,input().split(" "))
answer=0
for X in range(K+1):
  if S-X>2*K:
    continue
  for Y in range(K+1):
    if S-(X+Y)<=K and S-(X+Y)>=0:
      answer+=1
print(answer)
### BUGGY CODE ###

import math
from functools import reduce
import time

def gcd(*numbers):
    return reduce(math.gcd, numbers)

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


### FIXED CODE ###

import math
from functools import reduce
import time

def gcd(*numbers):
    return reduce(math.gcd, numbers)

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