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

#!/usr/bin/python

import sets
import sys

def main(argv):
    tokens = sys.stdin.readline().rstrip("\n").split(" ")

    while len(tokens) == 3:
        n, k, l = map(lambda x: int(x), tokens)

        roads = [set([i]) for i in xrange(n)]
        railways = [set([i]) for i in xrange(n)]

        for i in xrange(0, k):
            x, y = map(
              lambda c: int(c), sys.stdin.readline().rstrip("\n").split(" "))
            if roads[x - 1] != roads[y - 1]:
                roads[x - 1].update(roads[y - 1])
                for j in roads[y - 1]:
                    roads[j] = roads[x - 1]

        for i in xrange(0, l):
            x, y = map(
              lambda c: int(c), sys.stdin.readline().rstrip("\n").split(" "))
            if railways[x - 1] != railways[y - 1]:
                railways[x - 1].update(railways[y - 1])
                for j in railways[y - 1]:
                    railways[j] = railways[x - 1]

        results = []
        for i in xrange(0, n):
            results.append(str(len(roads[i].intersection(railways[i]))))
        print " ".join(results)

        tokens = sys.stdin.readline().rstrip("\n").split(" ")
if __name__ == "__main__":
    main(sys.argv)

### FIXED CODE ###

#!/usr/bin/python

import sets
import sys

def find(parent, x):
    if parent[x] == x:
        return x
    else:
        parent[x] = find(parent, parent[x])
        return parent[x]

def union(parent, x, y):
    parent_x = find(parent, x)
    parent_y = find(parent, y)

    if parent_x != parent_y:
        parent[parent_y] = parent[parent_x]

def main(argv):
    tokens = sys.stdin.readline().rstrip("\n").split()

    while len(tokens) == 3:
        n, k, l = [int(i) for i in tokens]

        parent_roads = [int(i) for i in xrange(n)]
        parent_railways = [int(i) for i in xrange(n)]

        for i in xrange(k):
            x, y = [int(i) for i in raw_input().split(" ")]
            union(parent_roads, x - 1, y - 1)

        for i in xrange(l):
            x, y = [int(i) for i in raw_input().split(" ")]
            union(parent_railways, x - 1, y - 1)

        count = dict()
        for i in xrange(n):
            key = (find(parent_roads, i), find(parent_railways, i))
            if not count.has_key(key):
                count[key] = 0
            count[key] += 1

        results = []
        for i in xrange(n):
            key = (find(parent_roads, i), find(parent_railways, i))
            results.append(str(count[key]))
        print " ".join(results)

        tokens = sys.stdin.readline().rstrip("\n").split()

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

import math


# 公約数列挙
# 重複する約数は1つにまとまるので注意
def make_common_divisors(x1, x2):
    cd = [1]
    for i in range(2, min(x1, x2) + 1):
        if x1 % i == 0 and x2 % i == 0:
            cd.append(i)
    return cd


A, B = map(int, input().split())
CD = make_common_divisors(A, B)


# 引数nが素数かどうかを判定
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


count = 1
for i in range(len(CD)):
    if is_prime(CD[i]):
        count += 1

print(count)


### FIXED CODE ###


# nを素因数分解したリストを返す
def decomposition_prime(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(int(n))
    return table

A, B = map(int, input().split())
Ap = set(decomposition_prime(A))
Bp = set(decomposition_prime(B))
print(len(Ap & Bp)+1)
### BUGGY CODE ###

def main():
    s = input()
    n = len(s)
    mod = 10 ** 9 + 7

    table1 = [0] * 13
    table2 = [0] * 13
    table1[0] = 1
    for l in s:
        for i in range(13):
            q = table1[i]
            r = [int(l)] if l != '?' else range(10)
            for d in r:
                k = (10 * i + d) % 13
                table2[k] += q

        table1 = table2
        table2 = [0] * 13

    print(table1[5] % mod)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    s = input()
    mod = 10 ** 9 + 7
    table1 = [0] * 13
    table2 = [0] * 13
    table1[0] = 1
    pre = [[((10 * i + j) % 13) for j in range(10)] for i in range(13)]

    for l in s:
        for i in range(13):
            q = table1[i] % mod
            if q == 0:
                continue
            if l == '?':
                for k in pre[i]:
                    table2[k] += q
            else:
                k = (10 * i + int(l)) % 13
                table2[k] += q

        table1 = table2
        table2 = [0] * 13

    print(table1[5] % mod)


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

s = input()
k = int(input())

_all = []

for i in range(1, len(s)+1):
	for j in range(len(s)-i+1):
		sub = s[j:j+i]
		if sub not in _all:
			_all.append(sub)

print(sorted(_all)[k-1])

### FIXED CODE ###

s = input()
k = int(input())

_all = []

for i in range(1, min(k+1, len(s)+1)):
	for j in range(len(s)-i+1):
		sub = s[j:j+i]
		if sub not in _all:
			_all.append(sub)

print(sorted(_all)[k-1])
### BUGGY CODE ###

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

for i in range(m):
    a_max = max(a)
    a_max_i = a.index(a_max)
    new = int(a_max / 2) if not a_max == 0 else 0
    a[a_max_i] = new

print(int(sum(a)))

### FIXED CODE ###

import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x) * -1, input().split()))
heapq.heapify(a)

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

print(-1 * sum(a))
### BUGGY CODE ###

n=int(input())
cnt=[0]*n

for a in range(1, n+1):
    for b in range(a, n+1):
        if a*b <= n-1:
                if a==b:
                    cnt[a*b]+=1
                else:
                    cnt[a*b]+=2
        if a*b > n:
            break


print(sum(cnt))


### FIXED CODE ###

n=int(input())
cnt=[0]*n

for a in range(1, n+1):
    for b in range(a, n+1):
        if a*b <= n-1:
                if a==b:
                    cnt[a*b]+=1
                else:
                    cnt[a*b]+=2
        if a*b > n:
            break


print(sum(cnt))
### BUGGY CODE ###

n, t = map(int, input().split())
a = []
for i in range(n):
  x, y = map(int, input().split())
  a.append([x, y])
a = sorted(a, key=lambda x: x[0], reverse=True)
dp = [[0 for i in range(t+1)] for j in range(n+1)]
for i in range(1, n+1):
  for j in range(1, t+1):
    dp[i][j] = max(dp[i-1][j], dp[i][j-1])
    if j == 1:
      dp[i][j] = max(dp[i][j], a[i-1][1])
    if j >= a[i-1][0]:
      dp[i][j] = max(dp[i][j], dp[i-1][j-a[i-1][0]] + a[i-1][1])
print(dp[n][t])  

### FIXED CODE ###

n, t = map(int, input().split())
a = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
  x, y = map(int, input().split())
  a[i][0], a[i][1] = x, y
a = sorted(a, key=lambda x: x[0], reverse=True)
dp = [[0 for i in range(t+1)] for j in range(n+1)]

for i in range(1, n+1):
  for j in range(1, t+1):
    dp[i][j] = max(dp[i-1][j], dp[i][j-1])
    if j == 1:
      dp[i][j] = max(dp[i][j], a[i-1][1])
    if j >= a[i-1][0]:
      dp[i][j] = max(dp[i][j], dp[i-1][j-a[i-1][0]] + a[i-1][1])
print(dp[n][t])
### BUGGY CODE ###

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

for i in range(n):
	r = 0
	for j in range(n):
		k = (i+j)%n
		if j%2 == 0:
			#print('plus')
			r += aList[k]
			#print(aList[k])
		else:
			#print('minus')
			r -= aList[k]
			#print(aList[k])
	print(str(r) ,end=' ')
			
	


### FIXED CODE ###

n=int(input())
aList=list(map(int,input().split()))
rList = []
r1 = 0
for i in range(n):
	if i%2 == 0:
		r1 += aList[i]
	else:
		r1 -= aList[i]
rList.append(r1)

for i in range(n-1):
	r = (2 * aList[i]) - rList[i]
	rList.append(r)

print(' '.join(map(str, rList)))
### BUGGY CODE ###

# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
import sys

def main():
  H, W = list(map(int, input().split()))
  all_in = sys.stdin.readlines()
  all_count = H * W
  blacks = [i*W+j for i in range(H) for j in range(W) if all_in[i][j] == "#"]
  L = [False] * all_count
  for black in blacks:
    L[black] = True
  black_count = len(blacks)
 
  cands_H = [-W, W]
  cands_W = [-1, 1]
  result = 0
  while black_count < all_count:
    next_steps = set([black+cand for black in blacks for cand in cands_H]) | set([black+cand for black in blacks for cand in cands_W if black%W not in [0, W-1]])
    blacks = [i for i in next_steps if i >= 0 and i < all_count and not L[i]]
    for i in blacks:
      L[i] = True
    black_count += len(blacks)
    result += 1

  print(result)

if __name__ == "__main__":
  main()


### FIXED CODE ###

# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy

def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)

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

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

ans = 0 
mod = 7+10**9

def expo(x,n):
  var = 1
  while n>0:
    if n%2 == 1:
      var = (var*x) % mod
    x = (x*x)%mod
    n = n>>1
  return var

def combi(n,k):
  N = 1
  mK = 1
  mN_K = 1
  for i in range(1,n+1):
    N = (N*i)%mod
  for i in range(1,k+1):
    mK = (mK * expo(i,mod-2))%(mod)
  for i in range(1,n-k+1):
    mN_K = (mN_K*expo(i,mod-2))%mod
  return (((N*mK)%mod)*mN_K)%mod

print(expo(2,N)-1-combi(N,A)-combi(N,B))

### FIXED CODE ###

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

ans = 0 
mod = 7+10**9

def expo(x,n):
  var = 1
  while n>0:
    if n%2 == 1:
      var = (var*x) % mod
    x = (x*x)%mod
    n = n>>1
  return var

def combi(n,k):
  N = 1
  K = 1
  for i in range(n-k+1,n+1):
    N = (N*i)%mod
  for i in range(1,k+1):
    K = (K * i)%mod
  return (N*expo(K,mod-2))%mod

print((expo(2,N)-1-combi(N,A)-combi(N,B))%mod)
### BUGGY CODE ###

from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
h = []

maxv = A[0] + B[0] + C[0]


def inv(v):
    return maxv - v


pushed = []
heappush(h, (0, 0, 0, 0))
for _ in range(K):
    invv, i, j, k = heappop(h)
    print(inv(invv))
    if i + 1 < X and (i + 1, j, k) not in pushed:
        heappush(h, (inv(A[i + 1] + B[j] + C[k]), i + 1, j, k))
        pushed.append((i + 1, j, k))
    if j + 1 < Y and (i, j + 1, k) not in pushed:
        heappush(h, (inv(A[i] + B[j + 1] + C[k]), i, j + 1, k))
        pushed.append((i, j + 1, k))
    if k + 1 < Z and (i, j, k + 1) not in pushed:
        heappush(h, (inv(A[i] + B[j] + C[k + 1]), i, j, k + 1))
        pushed.append((i, j, k + 1))


### FIXED CODE ###

from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
h = []

maxv = A[0] + B[0] + C[0]


def inv(v):
    return maxv - v


pushed = [[[] for _ in range(Y)] for _ in range(X)]
heappush(h, (0, 0, 0, 0))
for _ in range(K):
    invv, i, j, k = heappop(h)
    print(inv(invv))
    if i + 1 < X and k not in pushed[i + 1][j]:
        heappush(h, (inv(A[i + 1] + B[j] + C[k]), i + 1, j, k))
        pushed[i + 1][j].append(k)
    if j + 1 < Y and k not in pushed[i][j + 1]:
        heappush(h, (inv(A[i] + B[j + 1] + C[k]), i, j + 1, k))
        pushed[i][j + 1].append(k)
    if k + 1 < Z and k + 1 not in pushed[i][j]:
        heappush(h, (inv(A[i] + B[j] + C[k + 1]), i, j, k + 1))
        pushed[i][j].append(k + 1)
### BUGGY CODE ###

s = input()
q = int(input())

reverse_status = False

for i in range(q):
  query = list(map(format, input().split()))
  if int(query[0]) == 1:
    if reverse_status:
      reverse_status = False
    else:
      reverse_status = True
  else:
    if int(query[1]) == 1:
      if reverse_status:
        s = s + query[2]
      else:
        s = query[2] + s
    else:
      if reverse_status:
        s = query[2] + s
      else:
        s = s + query[2]

if reverse_status:
  print(''.join(list(reversed(s))))
else:
  print(s)

### FIXED CODE ###

from collections import deque

s = deque()
s.extend(list(input()))
q = int(input())

reverse_status = False

for i in range(q):
  query = list(map(format, input().split()))
  if int(query[0]) == 1:
    if reverse_status:
      reverse_status = False
    else:
      reverse_status = True
  else:
    if int(query[1]) == 1:
      if reverse_status:
        s.append(query[2])
      else:
        s.appendleft(query[2])
    else:
      if reverse_status:
        s.appendleft(query[2])
      else:
        s.append(query[2])

if reverse_status:
  s.reverse()
print(''.join(s))
### BUGGY CODE ###

n, m = map(int, input().split())
a, b = [0]*n, [0]*n
for i in range(n):
    a[i], b[i] = map(int, input().split())

flag = 1
while flag:
    flag = 0
    for j in range(n-1):
        if a[j] > a[j+1]:
            tmp = a[j]
            a[j] = a[j+1]
            a[j+1] = tmp
            res = b[j]
            b[j] = b[j+1]
            b[j+1] = res
            flag = 1

ans = 0
for i in range(n):
    if m > b[i]:
        ans += a[i]*b[i]
        m -= b[i]
    else:
        ans += m*a[i]
        break

print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
a = [0]*n
for i in range(n):
    a[i] = list(map(int, input().split()))

a.sort(key=lambda x: x[0])

ans = 0
for i in range(n):
    if m > a[i][1]:
        ans += a[i][0]*a[i][1]
        m -= a[i][1]
    else:
        ans += m*a[i][0]
        break

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

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

p = 10 ** 9 + 7
p2 = 10 ** 9 + 9
q = 10 ** 2
q2 = 83

def rollingHash(N, M, A, ans):
	mul1 = 1
	mul2 = 1
	for i in range(M):
		mul1 = (mul1 * q) % p
		mul2 = (mul2 * q2) % p2

	Droll1 = defaultdict(lambda:-1)
	Droll2 = defaultdict(lambda:-1)
	val1 = 0
	val2 = 0
	for i in range(M):
		val1 = val1 * q + A[i]
		val1 %= p
		val2 = val2 * q2 + A[i]
		val2 %= p2

	Droll1[val1] = 0
	Droll2[val2] = 0
	for i in range(N - M):
		val1 = (val1 * q - A[i] * mul1 + A[i + M]) % p
		val2 = (val2 * q2 - A[i] * mul2 + A[i + M]) % p2

		if Droll1[val1] != -1 and Droll1[val1] == Droll2[val2] and i + 1 - Droll1[val1] >= M:
			return M

		Droll1[val1] = i + 1
		Droll2[val2] = i + 1

	return ans

#処理内容
def main():
	N = int(input())
	S = list(input())
	for i in range(N):
		S[i] = ord(S[i]) - 97

	ans = 0
	for i in range(1, int(N // 2) + 1):
		ans = rollingHash(N, i, S, ans)

	print(ans)



if __name__ == '__main__':
	main()

### FIXED CODE ###

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

p = 10 ** 9 + 7
p2 = 10 ** 9 + 9
q = 1007
q2 = 2009

def rollingHash(N, M, A, ans):
	mul1 = 1
	mul2 = 1
	for i in range(M):
		mul1 = (mul1 * q) % p
		mul2 = (mul2 * q2) % p2

	Droll1 = defaultdict(lambda:-1)
	Droll2 = defaultdict(lambda:-1)
	val1 = 0
	val2 = 0
	for i in range(M):
		val1 = val1 * q + A[i]
		val1 %= p
		val2 = val2 * q2 + A[i]
		val2 %= p2

	Droll1[val1] = 0
	Droll2[val2] = 0
	rolling_Hash1 = [None] * (N - M + 1)
	rolling_Hash1[0] = val1
	rolling_Hash2 = [None] * (N - M + 1)
	rolling_Hash2[0] = val2

	for i in range(N - M):
		val1 = (val1 * q - A[i] * mul1 + A[i + M]) % p
		val2 = (val2 * q2 - A[i] * mul2 + A[i + M]) % p2
		rolling_Hash1[i + 1] = val1
		rolling_Hash2[i + 1] = val2

		if Droll1[val1] == -1:
			Droll1[val1] = i + 1
		else:
			if rolling_Hash1[i + 1] == rolling_Hash1[Droll1[val1]] and rolling_Hash2[i + 1] == rolling_Hash2[Droll1[val1]] and i + 1 - Droll1[val1] >= M:
				return M

	return ans

#処理内容
def main():
	N = int(input())
	S = list(input())
	for i in range(N):
		S[i] = ord(S[i]) - 97

	ans = 0
	for i in range(1, int(N // 2) + 1):
		ans = rollingHash(N, i, S, ans)

	print(ans)



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

n,k = map(int,input().split())
l = list(map(int,input().split()))
l_ans = [0,abs(l[1]-l[0])]+[0]*(n-2)
for i in range(2,n):
    tmp1=float("inf")
    for j in range(1,min(i+1,k+1)):
        tmp2=l_ans[i-j]+abs(l[i]-l[i-j])
        if tmp1>tmp2:tmp1=tmp2
    l_ans[i]=tmp1
print(l_ans[::-1][0])

### FIXED CODE ###

n,k = map(int,input().split())
l = list(map(int,input().split()))
l_ans = [0,abs(l[1]-l[0])]+[0]*(n-2)
for i in range(2,n):
    tmp1=float("inf")
    for j in range(1,min(i+1,k+1)):
        tmp2=l_ans[i-j]+abs(l[i]-l[i-j])
        if tmp1>tmp2:tmp1=tmp2
    l_ans[i]=tmp1
print(l_ans[::-1][0])
### BUGGY CODE ###

# ABC158 B - Count Balls

N,A,B = map(int,input().split())
A_A = 0
B_B = 0
for i in range(N):
    if N >= A:
        A_A +=A
        N -=A
    else:
        A_A +=N
        break
    if N >= B:
        B_B +=B
        N -=B
    else:
        B_B +=N
        break
print(A_A)
    


### FIXED CODE ###

# ABC158 B - Count Balls

M,A,B = map(int,input().split())
import math
C = math.floor(M/(A+B))
N = M%(A+B)
E = C*A
A_A = 0
B_B = 0
for i in range(N):
    if N >= A:
        A_A +=A
        N -=A
    else:
        A_A +=N
        break
    if N >= B:
        B_B +=B
        N -=B
    else:
        B_B +=N
        break
print(A_A+E)
### BUGGY CODE ###

def resolve():

    n,a,b =map(int, input().split())
    lis = []
    while True:
        for i in range(a):
            lis.append("b")
        for j in range(b):
            lis.append("r")
        if len(lis)>= n:
            break
    print(lis[0:n].count("b"))
    
    
    
if __name__ == "__main__":
    resolve()

### FIXED CODE ###

def resolve():
    n,a,b = map(int, input().split())
    if a ==0:
        print(0)
    else:
        ans=0
        tmp = n //(a+b)
        ans += a*tmp
        if n - (a+b)*tmp >a :
            ans +=a
        else:
            ans += n - (a+b)*tmp
        
        print(ans)

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

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  N=I()
  for h in range(1,3501):
    for n in range(1,3501):
      a=4*h*n-N*n-N*h
      b=N*h*n
      x=a//b

      if x>0 and a%b==0:
        return str(h)+' '+str(n)+' '+str(a//b)

# main()
print(main())


### FIXED CODE ###

import sys,collections

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a=I()

  for h in range(1,3501):
    for n in range(1,3501):
      x=(4*h*n-a*n-a*h)
      if x==0:
        continue
      w=a*h*n/x
      if w>0 and w==int(w) and w<=3500:
        print(h,n,int(w))
        exit()

main()
# print(main())
### BUGGY CODE ###

nn = int(input())
cap_list = list(range(5))
for ii in range(5):
    cap_list[ii] = int(input())
people_in_city = [nn, 0, 0, 0, 0, 0]
time = 0

while people_in_city[5] < nn:
    train = min(cap_list[0], people_in_city[0])
    bus = min(cap_list[1], people_in_city[1])
    taxi = min(cap_list[2], people_in_city[2])
    airplane = min(cap_list[3], people_in_city[3])
    ship = min(cap_list[4], people_in_city[4])
    
    people_in_city[0] += -train
    people_in_city[1] += train - bus
    people_in_city[2] += bus - taxi
    people_in_city[3] += taxi - airplane
    people_in_city[4] += airplane - ship
    people_in_city[5] += ship
    
    time += 1

print(time)

### FIXED CODE ###

N = int(input())
abcde = [int(input()) for _ in range(5)]

m = min(abcde)
group = N//m if N%m==0 else N//m+1
print(5 + group - 1)
### BUGGY CODE ###


n=int(input())
a = list(map(int, input().split()))
an=0
for i in range(n-2):
    s=a[i]
    for j in range(s+i+1,n):
        if j-i==a[j]+s:
            an+=1
print(an)

### FIXED CODE ###

import collections
n=int(input())
a = list(map(int, input().split()))
an=0
ii=[]
jj=[]
for i in range(n):
    ii.append(i+a[i])
    jj.append(i-a[i])
jjj=collections.Counter(jj)
for i in range(n):
    an+=jjj[ii[i]]
print(an)
### BUGGY CODE ###

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

#print(ai)
#ais = sorted(ai, reverse=True)
ais = sorted(ai)
#print(ais)
dica={}
for i in range(len(ais)):
    dica.setdefault(i,ais[i])
#print(dica)

bc = []
for i in range(m):
    bc.append(list(map(int, input().split())))

#print(bc)
bcs = sorted(bc, reverse=True, key=lambda x:x[1])
#print(bcs)

pt = 0
for i in range(m):
    tn, tv =bcs[i]
    for j in range(pt,n):
        if dica[j] < tv and 0<tn:
            dica[j]=tv
            tn=tn-1
            pt=j

#print(ais)
print(sum(dica.values()))


### FIXED CODE ###


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

#print(ai)
#ais = sorted(ai, reverse=True)
ais = sorted(ai)
#print(ais)
dica={}
for i in range(len(ais)):
    dica.setdefault(i,ais[i])
#print(dica)

bc = []
for i in range(m):
    bc.append(list(map(int, input().split())))

#print(bc)
bcs = sorted(bc, reverse=True, key=lambda x:x[1])
#print(bcs)

pt = 0
for i in range(m):
    tn, tv =bcs[i]
    #print(pt, n)
    #print(dica)
    for j in range(pt,n):
        if dica[j] < tv and 0 < tn:
            dica[j]=tv
            tn=tn-1
            pt=j+1
        else:
            break

#print(ais)
print(sum(dica.values()))