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

job = list()
salary = list()
k = 0
n,m = map(int,input().split())

for i in range(n):
    job.append(tuple(map(int,input().split())))

job.sort(reverse = True)

for x in job:
    a,b = x
    salary.append(b)

    if a + k > m:
        salary.remove(min(salary))
    else:
        k += 1

print(sum(salary))


### FIXED CODE ###

import heapq
job = list()
salary = list()
n,m = map(int,input().split())

for i in range(n):
    a,b = map(int,input().split())
    job.append((a,b))

job.sort(reverse = True)

for x in job:
    s,t = x
    heapq.heappush(salary,t)
    if s - m > 0:
        heapq.heappop(salary)
    else:
        m -= 1

print(sum(salary))
### BUGGY CODE ###

import sys
input=sys.stdin.readline

def main():
    N,K = map(int,input().split())
    ans = 0
    if K%2==0:
        a0 = K//2
    else:
        a0 = K
    for a in range(a0, N+1, a0):
        for _ in range(K - a%K, N+1, K):
            for _ in range(K - a%K, N+1, K):
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input=sys.stdin.readline

def main():
    N,K = map(int,input().split())
    r1 = 0
    for i in range(1,N+1):
        if i%K == 0:
            r1 += 1
    if K%2 == 1:
        print(r1**3)
    else:
        r2 = 0
        for i in range(1,N+1):
            if i%K == K//2:
                r2 += 1
        print(r1**3+r2**3)
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

def main():
    import sys
    readline = sys.stdin.readline
    # readlines = sys.stdin.readlines
    H, N = map(int, input().split())
    M = [tuple(map(int, readline().split())) for _ in range(N)]
    INF = float('inf')
    dp = [INF] * (H + 1)
    dp[0] = 0
    
    for i in range(N):
        a, b = M[i]
        for j in range(H):
            nj = min(H, j + a)
            dp[nj] = min(dp[nj], dp[j] + b)

    print(dp[H])


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

H, N = map(int, input().split())
M = [tuple(map(int, x.split())) for x in sys.stdin.readlines()]
# A = [0] * N
# B = [0] * N
# for i, (a, b) in enumerate(M):
#     A[i] = a
#     B[i] = b


INF = 10 ** 9
dp = [INF] * (H + 1)
dp[0] = 0

for i in range(H):
    for j in range(N):
        ni = min(H, i + M[j][0])
        b = M[j][1]
        dp[ni] = min(dp[ni], dp[i] + b)

print(dp[H])
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10000)
def resolve():
    s = input()
    K = int(input())
    mem = []
    kinds = sorted(list(set(s)))
    skips = []
    if len(kinds) > K:
        skips = kinds[K+1:]
    for j in range(len(s)): # window starts at
        if s[j] in skips:
            continue
        for i in range(1, len(s)+1): # window size
            subs = s[j:j+i]
            mem.append(subs)
    mem = sorted(list(set(mem)))
    # print(mem)
    print(mem[K-1])


if '__main__' == __name__:
    resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10000)
def resolve():
    s = input()
    K = int(input())
    mem = []
    for i in range(1, K+1): # window size
        for j in range(len(s)): # window starts at
            subs = s[j:j+i]
            if subs not in mem:
                mem.append(subs)
    mem.sort()
    # print(mem)
    print(mem[K-1])
    
    
if '__main__' == __name__:
    resolve()
### BUGGY CODE ###

import numpy as np
h,w,m = map(int,input().split())
bomb = list(tuple(map(lambda x: int(x)-1,input().split())) for i in range(m))
MapX = [[0]*w for i in range(h)]
MapY = [[0]*h for i in range(w)]
for i in bomb:
    MapX[i[0]][i[1]] = 1
    MapY[i[1]][i[0]] = 1
bombx = list(i.count(1) for i in MapX)
bomby = list(i.count(1) for i in MapY)
maxx = max(bombx)
maxy = max(bomby)
maxx_index = list(i for i in range(h) if bombx[i] == maxx)
maxy_index = list(i for i in range(w) if bomby[i] == maxy)
flag = 0
for i in maxx_index:
    for j in maxy_index:
        if (i,j) not in bomb:
            print(maxx+maxy)
            exit()
print(maxx+maxy-1)

### FIXED CODE ###

h,w,m = map(int,input().split())
bombX = [0]*h
bombY = [0]*w
bomb = set()
maxX = maxY = 0
for i in range(m):
    i,j = map(lambda x:int(x)-1, input().split())
    bomb.add((i,j))
    bombX[i] += 1
    bombY[j] += 1
    maxX = max(maxX,bombX[i])
    maxY = max(maxY,bombY[j])
maxX_index = list(i for i in range(h) if bombX[i] == maxX)
maxY_index = list(i for i in range(w) if bombY[i] == maxY)
for i in maxX_index:
    for j in maxY_index:
        if (i,j) in bomb: continue
        print(maxX+maxY)
        exit()
print(maxX+maxY-1)
### BUGGY CODE ###

n=int(input())
a=[int(input())for _ in range(n)]

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

### FIXED CODE ###

n=int(input())
a=[int(input())for _ in range(n)]
b=sorted(a)

for i in a:
  if i==b[-1]:
    print(b[-2])
  else:
    print(b[-1])
### BUGGY CODE ###

import sys
import math
from collections import deque
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

N = I()
S = input()
cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if S[i]==S[j] or S[j]==S[k] or S[k]==S[i] or j-i==k-j:
                continue
            cnt += 1

print(cnt)


### FIXED CODE ###

import sys
import math
from collections import deque
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

input = sys.stdin.readline


N = I()
S = input().rstrip()
R = S.count('R')
G = S.count('G')
B = N-R-G

ans = R*G*B
for i in range(N):
    for j in range(i+1,N):
        if 2*j-i < N and S[i]!=S[j] and S[j]!=S[2*j-i] and S[2*j-i]!=S[i]:
            ans -= 1
print(ans)
### BUGGY CODE ###

from scipy.sparse import*
i=lambda:tuple(map(int,input().split()))
f=csgraph.johnson
n,m,l=i()
d=eval('[0]*-~n,'*-~n)
exec('a,b,c=i();d[a][b]=c;'*m)
d=f(f(d,0)<=l)
d[d>n]=0
for _ in'_'*i()[0]:print(int(d[i()])-1)

### FIXED CODE ###

from scipy.sparse import*
s=csgraph.floyd_warshall
n,m,l,*t=map(int,open(0).read().split())
d=eval('[9e9]*-~n,'*-~n)
for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=d[b][a]=c
d=s(d)
d[d>l]=9e9
d[d<=l]=1
d=s(d)
d[d>9e9]=9e9
for s,t in zip(*[iter(t[m*3+1:])]*2):print(int(d[s,t]%9e9-1))
### BUGGY CODE ###

# coding: utf-8
# Here your code !
N=int(input())
b=input()
c=b.split(" ")
d=map(int,c)
a=list(d)
X=sum(a)
ans=[]
for i in range(N-1):
    A=abs(X-2*sum(a[0:i+1]))
    ans.append(A)
ans1=min(ans)
print(ans1)

### FIXED CODE ###

# coding: utf-8
# Here your code !
N=int(input())
b=input()
c=b.split(" ")
d=map(int,c)
a=list(d)
X=sum(a)
ans=[]
Y=0
for i in range(N-1):
#    A=abs(X-2*sum(a[0:i]))
    Y=Y+a[i]
    B=abs(X-2*Y)
    ans.append(B)
ans1=min(ans)
print(ans1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    s = [list(input().strip()) for i in range(H)]

    left = [[0] * W for i in range(H)]
    right = [[0] * W for i in range(H)]
    up = [[0] * W for i in range(H)]
    down = [[0] * W for i in range(H)]

    for i in range(H):
        count = 0
        for j in range(W):
            if s[i][j] == ".":
                count += 1
                left[i][j] = count
            else:
                count = 0
                left[i][j] = count
        count = 0
        for j in range(W-1, -1, -1):
            if s[i][j] == ".":
                count += 1
                right[i][j] = count
            else:
                count = 0
                right[i][j] = count

    for j in range(W):
        count = 0
        for i in range(H):
            if s[i][j] == ".":
                count += 1
                down[i][j] = count
            else:
                count = 0
                down[i][j] = count
        count = 0
        for i in range(H-1, -1, -1):
            if s[i][j] == ".":
                count += 1
                up[i][j] = count
            else:
                count = 0
                up[i][j] = count
    
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3)
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy as np

h, w = map(int, input().split())

up = np.zeros((h, w), dtype=int)
down = np.zeros((h, w), dtype=int)
right = np.zeros((h, w), dtype=int)
left = np.zeros((h, w), dtype=int)

map = np.array([list(input()) for i in range(h)]) == "."

for i in range(1, h):
    up[i] = (up[i-1] + 1) * map[i-1]
    down[h-1-i] = (down[h-i] + 1) * map[h-i]
for j in range(1, w):
    left[:,j] = (left[:,j-1] + 1) * map[:,j-1]
    right[:,w-1-j] = (right[:,w-j] + 1) * map[:,w-j]

print(((up+down+right+left+1) * map).max())
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
#n,k=100000,100
#a=[i for i in range(100000)]

kl=[i for i in range(1,k+1)]

dp=[float("inf")]*(n)
dp[0]=0
for i in range(n):
  for j in kl:
    ij=i+j
    if ij < n:
      m=dp[i]+abs(a[i]-a[ij])
      if m < dp[ij]:
        dp[ij]=m

print(dp[n-1])


### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
#n,k=100000,100
#a=[i for i in range(100000)]

kl=[i for i in range(1,k+1)]

dp=[float("inf")]*(n)
dp[0]=0
for i in range(1,n):
  dp[i] = min(dp[j] + abs(a[i] - a[j]) for j in range(max(0, i - k), i))

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

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

road = {k:[] for k in range(1,n+1)}
for _ in range(m):
  a,b = map(int,input().split())
  road[a].append(b)
  road[b].append(a)


next_visited = [1]
visited = [1]
temp_next = []

visit_num = {}

while True:
  temp_next = []
  for room in next_visited:
    ava_room = road[room]
    for r in ava_room:
      if r not in visited:
        visit_num[r] = room
        temp_next.append(r)
        visited.append(r)
        
  if temp_next == []:
    break
  next_visited = temp_next

if len(visit_num) != n-1:
  print('No')

else:
  print('Yes')
  for v in sorted(visit_num.items()):
    print(v[1])

  
 

### FIXED CODE ###

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

road = {k:[] for k in range(1,n+1)}
for _ in range(m):
  a,b = map(int,input().split())
  road[a].append(b)
  road[b].append(a)


next_visited = [1]
visited = {1:None}
temp_next = []

visit_num = {}
count = 0

while True:
  temp_next = []
  for room in next_visited:
    ava_room = road[room]
    for r in ava_room:
      try:
        visited[r]
      except:
        visit_num[r] = room
        temp_next.append(r)
        visited[r] = None
        
  if temp_next == []:
    break
  next_visited = temp_next

if len(visit_num) != n-1:
  print('No')

else:
  print('Yes')
  for v in sorted(visit_num.items()):
    print(v[1])
### BUGGY CODE ###

n,k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

if n<k: print(0)
else:
    for i in range(k):
        h.pop(h.index(max(h)))

    print(sum(h))


### FIXED CODE ###

n,k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

h.sort()

if n<=k: print(0)
else:
    for i in range(k):
        h.pop(-1)

    print(sum(h))
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, p = map(int, input().strip().split())
  s = input().strip()
  ans = 0
  if 10 % p == 0:
    for r in range(n):
      if int(s[r]) % p == 0:
        ans += r+1
    print(ans)
    return
  
  remains = [0] * (n+1)
  x = 1
  for r in range(n-1, -1, -1):
    remain = (int(s[r]) * x) % p
    remains[r] = (remains[r+1] + remain) % p
    x *= 10
  
  counts = [0] * p
  for remain in remains:
    counts[remain] += 1
  for count in counts:
    ans += (count * (count - 1)) // 2
  print(ans)

if __name__=='__main__':
  main()



### FIXED CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, p = map(int, input().strip().split())
  s = input().strip()
  ans = 0
  if 10 % p == 0:
    for r in range(n):
      if int(s[r]) % p == 0:
        ans += r+1
    print(ans)
    return
  
  remains = [0] * (n+1)
  counts = [0] * p
  counts[0] += 1
  x = 1
  for r in range(n):
    remain = (int(s[-(r+1)]) * x) % p
    remains[-(r+1)] = (remains[-r] + remain) % p
    counts[remains[-(r+1)]] += 1
    x = (x * 10) % p
  for count in counts:
    ans += (count * (count - 1)) // 2
  print(ans)

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

import math
import numpy as np
import itertools

k = int(input())
tot = 0

g = np.array([[-1] * (k + 1)] * (k + 1), dtype=np.int64)

for l, m, n in itertools.product(range(1, k + 1), 
                                 range(1, k + 1), range(1, k + 1)):
    if g[l][m] == -1:
        g[l][m] = math.gcd(l, m)
    lm_gcd = g[l][m]

    if g[lm_gcd][n] == -1:
        g[lm_gcd][n] = math.gcd(lm_gcd, n)
    tot += g[lm_gcd][n]
    
print(tot) 

### FIXED CODE ###

from math import gcd

k = int(input())
tot = 0

for l in range(1, k + 1):
    for m in range(1, k + 1):
        for n in range(1, k + 1):
            tot += gcd(gcd(l, m), n)
print(tot)
### BUGGY CODE ###

#H=4
#W=6
#
#S[0]=["#",".",".","#",".","."]
#S[1]=[".",".",".",".",".","#"]
#S[2]=[".",".",".",".","#","."]
#S[3]=["#",".","#",".",".","."]

H,W=map(int,input().split())
S=[0]*H
for i in range(H):
    S[i]=list(input())


MAP=[[[0,0,0,0] for i in range(W)]for i in range(H)]
MAX=0
#ue

for i in range(W):
    c=0
    d=0
    for j in range(H):
        if(S[j][i]=="."):
            c+=1
            MAP[j][i][0]+=c
        else:
            c=0
        if(S[H-j-1][W-i-1]=="."):
            d+=1
            MAP[H-j-1][W-i-1][0]+=d
        else:
            d=0

#hidari
for j in range(H):
    c=0
    d=0
    for i in range(W):
        if(S[j][i]=="."):
            c+=1
            MAP[j][i][0]+=c
            MAX=max(MAX,MAP[j][i][0]-3)
        else:
            c=0
        if(S[H-j-1][W-i-1]=="."):
            d+=1
            MAP[H-j-1][W-i-1][0]+=d
            MAX=max(MAX,MAP[H-j-1][W-i-1][0]-3)
        else:
            d=0

print(MAX)

### FIXED CODE ###

#H=4
#W=6
#
#S[0]=["#",".",".","#",".","."]
#S[1]=[".",".",".",".",".","#"]
#S[2]=[".",".",".",".","#","."]
#S[3]=["#",".","#",".",".","."]

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

S = [[0]*W for i in range(H)]

for i in range(H):
    T=list(input())
    for j in range(W):
        if T[j] == "#":
            S[i][j] = 0
        else:
            S[i][j] = 1
MAP=[[0]*(W+2) for i in range(H+2)]
MAPH=[[0]*(W+2) for i in range(H+2)]
MAPU=[[0]*(W+2) for i in range(H+2)]
MAPL=[[0]*(W+2) for i in range(H+2)]
MAPR=[[0]*(W+2) for i in range(H+2)]

MAX=0

for i in range(1,W+1):
    for j in range(1,H+1):
            MAPH[j][i]=(MAPH[j-1][i]+1)*S[j-1][i-1]
            MAP[j][i]+=MAPH[j][i]
            MAPU[H-j+1][W-i+1]=(MAPU[H-j+2][W-i+1]+1)*S[H-j][W-i]
            MAP[H-j+1][W-i+1]+=MAPU[H-j+1][W-i+1]
for j in range(1,H+1):
    for i in range(1,W+1):
            MAPL[j][i]=(MAPL[j][i-1]+1)*S[j-1][i-1]
            MAP[j][i]+=MAPL[j][i]
            MAPR[H-j+1][W-i+1]=(MAPR[H-j+1][W-i+2]+1)*S[H-j][W-i]
            MAP[H-j+1][W-i+1]+=MAPR[H-j+1][W-i+1]
            MAX=max(MAX,MAP[j][i]-3,MAP[H-j+1][W-i+1]-3)
print(MAX)
### BUGGY CODE ###

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

# 隣接リスト
A = [[] for _ in range(N)]
# 根
root = -1
R = [True]*N

for i in range(N-1+M):
    a,b = map(int,input().split())
    # a -> b
    A[a-1].append(b-1)
    # a -> b のため、bには親がいる
    R[b-1] = False

# 親判定
for i in range(N):
    if R[i]:
        root = i
        break

# 出力すべき木の親を確定させる
P = [-1]*N
P[root] = -1

from collections import deque
Q = deque([root])
while Q!=[]:
    tmpQ = deque([])
    for q in Q:
        for i in A[q]:
            # 親の更新
            P[i] = q
            # 自身をtmpQに
            tmpQ.append(i)
    Q = tmpQ

for i in range(N):
    print(P[i]+1)





### FIXED CODE ###

N,M = map(int,input().split())
AB = [tuple(map(int,input().split())) for _ in range(N-1+M)]

A = [[] for _ in range(N)]
P = [0]*N
C = [0]*N
root = -1

for (a,b) in AB:
    # a -> b
    A[a-1].append(b-1)
    C[b-1] += 1

for i in range(N):
    if C[i]==0:
        root = i
P[root] = -1

from collections import deque
que = deque((a,root) for a in A[root])
while que:
    n,par = que.popleft()
    C[n] -= 1
    if C[n]==0:
        P[n] = par
        for i in A[n]:
            que.append((i,n))

for p in P:
    print(p+1)
### BUGGY CODE ###

n = int(input())
an = []
for i in range(n):
    an.append(int(input()))
import copy
for i in range(n):
    an_tmp = copy.copy(an)
    del an_tmp[i]
    res = max(an_tmp)
    print(res)

### FIXED CODE ###

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

import numpy as np
an = np.array(an)
_an = an.argsort()[::-1]
_max = np.max(an[_an[0]])
_max_next = np.max(an[_an[1]])
an[an < _max] = _max
an[_an[0]] = _max_next
an = an.astype("str")
print("\n".join(list(an)))
### BUGGY CODE ###

k, s = list(map(int, input().split()))
ct = 0
for x in range(k+1):
    for y in range(x, k+1):
        if x + y > s:
            break;
        for z in range(y, k+1):
            if x + y + z == s:
                if x == y and y == z:
                    ct += 1
                elif x != y and y != z and z != x:
                    ct += 6
                else:
                    ct += 3
                break;
print(ct)

### FIXED CODE ###

k, s = list(map(int, input().split()))
ct = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z <= k:
            ct += 1
print(ct)
### BUGGY CODE ###

def resolve():
    import re
    x = input()
    while "ST" in x:
        x = re.sub("ST", "", x)
    print(len(x))
resolve()

### FIXED CODE ###

def resolve():
    from collections import deque
    x = input()
    final = deque([])
    final.append(x[0])
    for i in range(1, len(x)):
        if x[i] == "S":
            final.append("S")
        else:
            if not final:
                final.append("T")
            else:
                last = final.pop()
                if last == "S":
                    continue
                else:
                    final.append("T")
                    final.append("T")
    print(len(final))
resolve()
### BUGGY CODE ###

n, m = map(int, input().split())
G = [[] for _ in range(n)]
ST = tuple(tuple(map(lambda x:int(x)-1, input().split())) for _ in range(m))
for s, t in ST:
  G[s].append(t)
#枝(s, t)を塞いだ時にそれぞれそこからあと何手かかるかを求める
def f(s, t):
  dp = [0]*n #そこからあと何手かかるかの期待値
  for i in range(n-2, -1, -1):
    temp = 0
    for v in G[i]:
      temp += dp[v]
    if i==s:
      temp -= dp[t]
      dp[i] = temp/(len(G[i])-1) + 1
    else:
      dp[i] = temp/len(G[i]) + 1
  return dp
T = f(-1, -1)
ans = T[0]
for i in range(n-1):
  if len(G[i]) == 1:
    continue
  m = 0
  t = -1
  for v in G[i]:
    if T[v] > m:
      m = T[v]
      t = v
  temp = f(i, t)[0]
  ans = min(ans, temp)
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
G = [[] for _ in range(n)]
ST = tuple(tuple(map(lambda x:int(x)-1, input().split())) for _ in range(m))
for s, t in ST:
  G[s].append(t)
#枝(s, t)を塞いだ時にそれぞれそこからあと何手かかるかを求める
def f(s, t):
  dp = [0]*n #そこからあと何手かかるかの期待値
  for i in range(n-2, -1, -1):
    temp = 0
    for v in G[i]:
      temp += dp[v]
    if i==s:
      temp -= dp[t]
      dp[i] = temp/(len(G[i])-1) + 1
    else:
      dp[i] = temp/len(G[i]) + 1
  return dp
T = f(-1, -1)
ans = T[0]
for i in range(n-1):
  if len(G[i]) == 1:
    continue
  m = 0
  t = -1
  for v in G[i]:
    if T[v] > m:
      m = T[v]
      t = v
  temp = f(i, t)[0]
  ans = min(ans, temp)
print(ans)
### BUGGY CODE ###

A,B,N=map(int,input().split())
count=0
x=0
for i in range(N+1):
    result=(i/B)-(int(i/B))
    if count<result:
        count=result
        x=i
result=int(A*x/B)-(A*int(x/B))
print(result)

### FIXED CODE ###

A,B,N=map(int,input().split())
x=min(B-1,N)
print(int(A*x/B)-A*int(x/B))
### BUGGY CODE ###

import sys
import numpy as np
import math
# for AtCoder
import fractions
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n = int(input())

sum = 0

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

for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            sum += gcd_list([i, j, k])
print(sum)


### FIXED CODE ###

import sys
import numpy as np
import math

from collections import deque 
from functools import reduce
from functools import lru_cache

# input = sys.stdin.readline

n = int(input())

gcd_num = 0

for i in range(1, n+1):
    for j in range(1, n+1):
        g = math.gcd(i, j)
        for k in range(1, n+1):
            gcd_num += math.gcd(g, k)
print(gcd_num)
### BUGGY CODE ###

S = input()

count = 0
while S.find("BW") != -1:
    count += S.count("BW")
    S = S.replace("BW","WB")
print(count)

### FIXED CODE ###

S = input()

ans = 0
countB = 0
for i in range(len(S)):
    if S[i] == "W":
        ans += countB
    elif S[i] == "B":
        countB += 1
print(ans)
### BUGGY CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
def move(a):
    for i in range(len(a)-1):
        if a[i] < a[i+1]:
            a[i],a[i+1] = a[i+1],a[i]
        else:
            break
    return a
for i in range(m):
    a[0] //= 2
    a = move(a)
ans = 0
for x in a:
    ans += x
print(ans)


### FIXED CODE ###

import heapq
n,m = map(int,input().split())
a = list(map(lambda x: int(x)*(-1),input().split()))
a.sort(reverse=True)
heapq.heapify(a)
for i in range(m):
    x = -heapq.heappop(a)
    x //= 2
    heapq.heappush(a,-x)
print(-sum(a))
### BUGGY CODE ###

from collections import Counter

from sys import setrecursionlimit
setrecursionlimit(300 ** 3 + 10)


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

memo = {(0, 0, 0): 0.0}
def dp(i, j, k):
    if (i, j, k) in memo:
        return memo[(i, j, k)]

    res = N
    if i > 0:
        res += i * dp(i - 1, j, k)
    if j > 0:
        res += j * dp(i + 1, j - 1, k)
    if k > 0:
        res += k * dp(i, j + 1, k - 1)

    res /= (i + j + k)

    memo[(i, j, k)] = res

    return res

C = Counter(A)
print(dp(C[1], C[2], C[3]))

### FIXED CODE ###

from collections import Counter

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

C = Counter(A)
dp = [[[.0] * (N + 2) for _ in range(N + 2)] for _ in range(N + 2)]
for i in range(C[3] + 1):
    for j in range(N - C[1] - i + 1):
        for k in range(N - i - j + 1):
            if i + j + k != 0:
                dp[i][j][k] = (
                    N +
                    i * dp[i - 1][j + 1][k] +
                    j * dp[i][j - 1][k + 1] +
                    k * dp[i][j][k - 1]
                ) / (i + j + k)

print(dp[C[3]][C[2]][C[1]])