Harryxun/stf_run huggingface dataset:
def f1():
	L.sort(key = (lambda x: - x[1]//(x[0] - w1 + 40)))
	ans = 0
	w2 = 0
	i = 0
	while i < N:
		w2 = w2 + L[i][0]
		if w2 > W:
			break
		ans = ans + L[i][1]
		i = i + 1
	
	return ans

def f2():
	dp = [[0] * (W + 1) for i in range(N + 1)]
	for n in range(1,N + 1):
		w,v = L[n - 1]
		if w > W:
			continue
		for m in range(w):
			dp[n][m] = dp[n - 1][m]
		for m in range(w,W + 1):
			dp[n][m] = max(dp[n - 1][m - w] + v, dp[n - 1][m])
	return max(dp[-1])
	
N,W = map(int,input().split())
L = [list(map(int,input().split())) for i in range(N)]
w1 = L[0][0]
if w1 > 10000000:
	print(f1())
else:
	print(f2())


### FIXED CODE ###

def f1():
	L.sort(key = (lambda x: - x[1]//(x[0] - w1 + 40)))
	ans = 0
	w2 = 0
	i = 0
	while i < N:
		w2 = w2 + L[i][0]
		if w2 > W:
			break
		ans = ans + L[i][1]
		i = i + 1
	
	return ans
	
def f3():
	L.sort(key = (lambda x: - x[1]//x[0]))
	ans = 0
	w2 = 0
	i = 0
	while i < N:
		w2 = w2 + L[i][0]
		if w2 > W:
			break
		ans = ans + L[i][1]
		i = i + 1
	
	return ans
def f2():
	dp = [[0] * (W + 1) for i in range(N + 1)]
	for n in range(1,N + 1):
		w,v = L[n - 1]
		if w > W:
			continue
		for m in range(w):
			dp[n][m] = dp[n - 1][m]
		for m in range(w,W + 1):
			dp[n][m] = max(dp[n - 1][m - w] + v, dp[n - 1][m])
	return max(dp[-1])
	
N,W = map(int,input().split())
L = [list(map(int,input().split())) for i in range(N)]
w1 = L[0][0]
if w1 > 10000000:
	print(f1())
elif W > 10000000:
	print(f3())
else:
	print(f2())
N=int(input())
x=0
 
for i range(1,n+1):
  if i%2==1:
    x+=1
    
print(x/n)

### FIXED CODE ###

n=int(input())
x=0
for i in range(1,n+1):
  if (i%2==1):
    x+=1
    
print(x/n)
N, M = map(int, input().split())
tenbo_height = list(map(int, input().split()))
roads = []
for i in range(M):
  #road[0] = start, road[1] = goal
  road = list(map(int, input().split()))
  roads.append(road)

good_tenbo = 0
for tenbo in range(N):
  adjacent_tenbo = []
  #good tenbo if no road or adjacent tenbo is all lower
  #count number of road connected to this tenbo
  for road in roads:
    if (road[0] == tenbo):
      adjacent_tenbo.append(road[1])
    elif (road[1] == tenbo):
      adjacent_tenbo.append(road[0])
  
  #check if no road connected
  if (len(adjacent_tenbo) == 0):
    good_tenbo += 1
    continue
  #check if adjacent tenbo is all lower
  all_lower = True
  for a_tenbo in adjacent_tenbo:
    if (tenbo_height[a_tenbo] >= tenbo_height[tenbo]):
      all_lower = False
      break
  if (all_lower):
    good_tenbo += 1
    continue
    
print(good_tenbo)

### FIXED CODE ###

N, M = map(int, input().split())
tenbo_height = list(map(int, input().split()))
adj_height = [0]*N

for i in range(M):
  #road[0] = start, road[1] = goal
  road = list(map(int, input().split()))
  adj_height[road[0]-1] = max(adj_height[road[0]-1], tenbo_height[road[1]-1])
  adj_height[road[1]-1] = max(adj_height[road[1]-1], tenbo_height[road[0]-1])
  
good_tenbo = 0
for tenbo in range(N):
  if ((tenbo_height[tenbo] > adj_height[tenbo])) or (adj_height[tenbo] == 0):
    good_tenbo += 1
print(good_tenbo)
N,K = map(int,input().split())
S = input()
L = [0]
for i in range(N):
    if S[i] == '0'and a != S[i]:
        L.append(i)
    a = S[i]
L.append(N)
for i in range(len(L)-(K+1)):
    ans = (L[i+(K+1)]-1)-(L[i])
if N == 1:
    ans = 1
elif N == 2 or S == '010':
    ans = 2
elif N == 3:
    ans = 3
    
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
S = input()
L = [0]
ans = 0
res = '1'
i = 0
for s in S:
    if s != res:
        L.append(i)
        i += 1
    else:
        i += 1
    res = s
L.append(i)
L.append(i)
if len(L)<=2*K+1:
    ans = N
for i in range(0,len(L)-K*2-1,2):
    ans = max(ans,L[i+K*2+1]-L[i])
print(ans)
nums =  list(map(int, input().split()))
 
max_num = max(nums)
min_num = max(nums)
two = [max_num, min_num]
mid_num = list(set(nums) - set(two))
 
two_num = str(max_num) + str(mid_num[0])
print(int(two_num) +int(min_num))

### FIXED CODE ###

num = list(map(int, input().split()))
num.sort(reverse=True)
print(num[0] * 10 + num[1] + num[2])
wet = ["Sunny","Cloudy","Rainy"]
s = wet.index(input())
print(wet[s+1] if s != 2 else s[1])

### FIXED CODE ###

wet = ["Sunny","Cloudy","Rainy"]
s = wet.index(input())
print(wet[s+1] if s != 2 else wet[0])
A,B,T=map(int,input())

print(B*(T//A))


### FIXED CODE ###

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

print(B*(T//A))
import sys

from collections import deque
# q = deque(); q.append(x); q.appendleft(x); q.pop() -> x; q.popleft() -> x
from collections import defaultdict
# d = defaultdict(lambda: []); d[key] -> []
import heapq
# hq = []; heapq.heappush(hq, x); heapq.heappop(hq) -> x; heapq.heappushpop(hq, x) -> x
import bisect
# i = bisect.bisect_left([1,2,3,4], 1.5); i = bisect.bisect_right([4,3,2,1], 1.5)

import numpy as np
#from scipy.misc import comb

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

"""
マスは1つの色を持つ -> c[i][j]
マスは3グループのいずれかに属する -> (i+j)%3
グループは1つの色 gc を持つ、ただし他のグループと同じ色を持てない gc1 != gc2 != gc3
マス違和感 = D[マスの色][グループの色]
グループ違和感 = グループ内のマスの、マス違和感の合計 = DG[グループ色]
全体違和感 = 3グループの、グループ違和感の合計
答え = 全体違和感
"""
def main():
    N, C = i2nn()
    D = ii2nnn(C)
    c = ii2nnn(N)
    iwakanG = [[0] * C for _ in range(3)]  # グループ違和感[グループID][グループ色] = グループID/色ごとのマス違和感の計
    for i in range(N):
        for j in range(N):
            groupID = (i + j) % 3  # グループID
            cM = c[i][j] - 1  # マス色
            for cG in range(C):
                iwakanM = D[cM][cG]   # マス違和感
                iwakanG[groupID][cG] += iwakanM  # グループ違和感にマス違和感を加算
    iwakan = 1e+9
    for gc1 in range(C):
        for gc2 in range(C):
            for gc3 in range(C):
                if gc1 == gc2 or gc2 == gc3 or gc3 == gc1:
                    continue
                n = iwakanG[0][gc1] + iwakanG[1][gc2] + iwakanG[2][gc3]
                if iwakan > n:
                    iwakan = n  # 全体違和感の最小化
    print(iwakan)

main()


### FIXED CODE ###

# ContestName
# URL
import sys
#import numpy as np

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, C = i2nn()
    D = ii2nnn(C)
    c = ii2nnn(N)
    E = [[0] * C for _ in range(3)]
    for i in range(N):
        for j in range(N):
            before = c[i][j]
            e = (i+j) % 3
            for after in range(1, C+1):
                E[e][after-1] += D[before-1][after-1]
    iwakan = N * N * 1000
    for c1 in range(C):
        for c2 in range(C):
            for c3 in range(C):
                if c1 == c2 or c2 == c3 or c3 == c1:
                    continue
                n = E[0][c1] + E[1][c2] + E[2][c3]
                if n < iwakan:
                    iwakan = n
    print(iwakan)

main()
while True:
    N,W = map(int,input().split())
    if N == 0: break
    src = [int(input()) for i in range(N)]
    highest = max(src)
    bands = highest//W + 1
    hist = [0 for i in range(bands)]
    for i in range(N):
        hist[src[i] // W] += 1
    ans = maxn = 0
    for i,n in enumerate(hist):
        ans += n * (bands-1-i)
        maxn = max(n, maxn)
    print(ans * / maxn / (bands-1) + 0.01)

### FIXED CODE ###

while True:
    N,W = map(int,input().split())
    if N == 0: break
    src = [int(input()) for i in range(N)]
    highest = max(src)
    bands = highest//W + 1
    hist = [0 for i in range(bands)]
    for i in range(N):
        hist[src[i] // W] += 1
    ans = maxn = 0
    for i,n in enumerate(hist):
        ans += n * (bands-1-i)
        maxn = max(n, maxn)
    print(ans / maxn / (bands-1) + 0.01)
from collections import deque
h,w = map(int, input().split())
maze = [list(input()) for i in range(h)]


def bfs(maze, sx, sy, gy, gx):
    d = [[float("inf")] * w for i in range(h)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sy, sx))
    d[sy][sx] = 0

    while que:
        p = que.popleft()
        if p[0] == gy and p[1] == gx:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[gy][gx]


ans = 0
for i in range(h):
    for j in range(w):
        if maze[i][j]!="#":
            for k in range(i,h):
                for l in range(j,w):
                    if maze[k][l]!="#":
                        ans = max(ans, bfs(maze, j, i, l, k))

print(ans)


### FIXED CODE ###

from collections import deque
h,w = map(int, input().split())
maze = [list(input()) for i in range(h)]
emp = []

#迷路と始点を引数に、最も遠い点までの距離を返す
def bfs(maze, sx, sy):
    d = [[-float("inf")] * w for i in range(h)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sy, sx))
    d[sy][sx] = 0

    while que:
        p = que.popleft()
        # if p[0] == gy and p[1] == gx:
        #     break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[nx][ny] == -float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1
    an = 0
    for i in d:
        an = max(an,max(i))
    return an

# 取りうる全ての始点と終点の最短経路の最大値を求める
ans = 0
for i in range(h):
    for j in range(w):
        if maze[i][j]!="#":
            ans = max(ans, bfs(maze, j, i))

print(ans)
#EDPC L
import sys
sys.setrecursionlimit(10**5)


def main():
    N=int(input())
    a=list(map(int,input().split()))
    #dp[l][r]:=区間[l,r]が残っている時の(直後の人の最終的な得点-そうじゃない方の最終的な得点）
    dp=[[-1]*N for _ in range(N)]
    print(rec(0,N-1))

def rec(l,r):
    if dp[l][r]!=-1:
        return dp[l][r]
    
    if l==r:
        dp[l][r]=a[l]
        return dp[l][r]
    
    dp[l][r]=max(a[l]-rec(l+1,r),a[r]-rec(l,r-1))

    return dp[l][r]
main()

### FIXED CODE ###

#EDPC L メモ化再帰じゃTLEで通らないのでやり直し

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

#dp[l][r]:=区間[l,r]が残っている時の(直後の人の最終的な得点-そうじゃない方の最終的な得点）

dp=[[-1]*N for _ in range(N)]

for k in range(N):
    dp[k][k]=a[k]

for r in range(1,N):
    for l in reversed(range(r)):
        dp[l][r]=max(a[l]-dp[l+1][r],a[r]-dp[l][r-1])

print(dp[0][N-1])
import sys
from heapq import heappop, heappush, heapify

def main():
    input = sys.stdin.readline
    
    N, Q = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    ls = [b-a for a, b in zip(A, B)]
    st = set(ls[1:-1])
    q_m = [-v for v in ls[1:-1] if v < 0]
    q_p = [v for v in ls[1:-1] if v >= 0]
    heapify(q_m)
    heapify(q_p)
    sum_A = sum(A)
    sum_q_p = sum(q_p)
    to_remove = set()
    odd = len(q_p) % 2
    Ans = []
    ans = sum_A + sum_q_p - (min(q_p[0], q_m[0]) if odd else 0)
    for _ in range(Q):
        p, x, y = map(int, input().split())
        p -= 1
        v = y-x
        sum_A += x - A[p]
        if p==0 or p==2*N-1:
            ans += x - A[p]
            Ans.append(ans)
            A[p] = x
            continue
        A[p] = x
        odd ^= (ls[p] >= 0) ^ (v >= 0)
        if v >= 0:
            sum_q_p += v
        if ls[p] >= 0:
            sum_q_p -= ls[p]
        to_remove.add(ls[p])
        ls[p] = v
        if v >= 0:
            heappush(q_p, v)
        else:
            heappush(q_m, -v)
        ans = sum_q_p + sum_A
        if odd:
            while q_p[0] in to_remove:
                heappop(q_p)
            while -q_m[0] in to_remove:
                heappop(q_m)
            ans -= min(q_p[0], q_m[0])
        Ans.append(ans)
    print("\n".join(map(str, Ans)))

main()


### FIXED CODE ###

import sys
from heapq import heappop, heappush, heapify

def main():
    input = sys.stdin.readline
    
    N, Q = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    ls = [b-a for a, b in zip(A, B)]
    q_m = [-v for v in ls[1:-1] if v < 0]
    q_p = [v for v in ls[1:-1] if v >= 0]
    heapify(q_m)
    heapify(q_p)
    sum_A = sum(A)
    sum_q_p = sum(q_p)
    to_remove = set()
    odd = len(q_p) % 2
    Ans = []
    ans = sum_A + sum_q_p - (min(q_p[0], q_m[0]) if odd else 0)
    for _ in range(Q):
        p, x, y = map(int, input().split())
        p -= 1
        v = y-x
        sum_A += x - A[p]
        if p==0 or p==2*N-1:
            ans += x - A[p]
            Ans.append(ans)
            A[p] = x
            continue
        A[p] = x
        odd ^= (ls[p] >= 0) ^ (v >= 0)
        if v >= 0:
            sum_q_p += v
        if ls[p] >= 0:
            sum_q_p -= ls[p]
        to_remove.add(ls[p])
        ls[p] = v
        if v >= 0:
            heappush(q_p, v)
        else:
            heappush(q_m, -v)
        ans = sum_q_p + sum_A
        if odd:
            while q_p[0] in to_remove:
                to_remove.remove(heappop(q_p))
            while -q_m[0] in to_remove:
                to_remove.remove(-heappop(q_m))
            ans -= min(q_p[0], q_m[0])
        Ans.append(ans)
    print("\n".join(map(str, Ans)))

main()
def main():
    N, M = map(int, input().split())

    i = 0
    AB = []
    while i < M:
        AB.append(tuple(map(int, input().split())))
        i += 1

    edge = [0 for i in range(M)]
    for i in AB:
        j = i[0] - 1
        end = i[1] - 1
        while j < end:
            edge[j] += 1
            j += 1

    for i in edge:
        if i % 2 > 0:
            print('NO')
            break
    else:
        print('YES')

main()


### FIXED CODE ###

def main():
    N, M = map(int, input().split())

    i = 0
    AB = [0 for i in range(N)]
    while i < M:
        a, b = map(int, input().split())
        AB[a-1] += 1
        AB[b-1] += 1
        i += 1

    for i in AB:
        if i % 2 > 0:
            print('NO')
            break
    else:
        print('YES')

main()
s,t =input().split()
a,b = map(int, input().split())
u = input()

if s == u:
    print(f'{a-1} {b}')
else:
    print(f'{a} {b-1}')


### FIXED CODE ###

s,t =input().split()
a,b = map(int, input().split())
u = input()


if u == s:
    print(a-1, b)
elif u == t:
    print(a, b-1)
# 入力
a = int(input())
op = input()
b = int(input())

# 処理
if op == '+':
    answer = a + b
elif op == '-':
    answer = a - b

# 出力
print(answer)

### FIXED CODE ###

# 入力
a, op, b = map(str, input().split())
a = int(a)
b = int(b)

# 処理
if op == '+':
    answer = a + b
elif op == '-':
    answer = a - b

# 出力
print(answer)
n=input()
satis=[]

for i in range(n):
	satis.extend(list(map(int,input().split())))

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))

### FIXED CODE ###

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

for i in range(n):
  A=list(map(int,input().split()))
  satis.extend(A)

tempA=satis[0]
tempB=satis[1]
tempC=satis[2]
if n > 1:
  for i in range(n-1):
    tempA2=satis[3*i+3]+max([tempB,tempC])
    tempB2=satis[3*i+4]+max([tempA,tempC])
    tempC2=satis[3*i+5]+max([tempA,tempB])
    tempA=tempA2
    tempB=tempB2
    tempC=tempC2
  print(max([tempA,tempB,tempC]))
else:
  print(max([tempA,tempB,tempC]))
mod = 10**9 + 7
def iip():
    ret = [int(i) for i in input().split()]
    if len(ret) == 1:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret

n = iip()
A = iip()

def main():
    ss = []
    for a_i in A:
        for s in ss:
            if a_i % s == 0:
                a_i //= s

        ss.extend(soinsuu_bunkai(a_i))

    #print(ss)
    all = 1
    for s in ss:
        all *= s
        all %= mod

    ans = 0
    for a_i in A:
        ans += (all * inv(a_i, mod)) % mod
        ans %= mod
    print(ans)


main()

### FIXED CODE ###

mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret

n = iip()
A = iip(listed=True)

def main():
    ss = []
    for a_i in A:
        for s in ss:
            if a_i % s == 0:
                a_i //= s

        ss.extend(soinsuu_bunkai(a_i))

    #print(ss)
    all = 1
    for s in ss:
        all *= s
        all %= mod

    ans = 0
    for a_i in A:
        ans += (all * inv(a_i, mod)) % mod
        ans %= mod
    print(ans)


main()
fac=[1]*505050
inv=[1]*505050
finv=[1]*505050
mod=1000000007
for i in range(1,500010):
  fac[i]=fac[i-1]*i%mod
  inv[i]=(mod-inv[mod%i]*(mod//i))%mod
  finv[i]=finv[i-1]*inv[i]%mod

def C(n,r):
  if n<0 or r<0 or n<r: return 0
  return fac[n]*inv[n-r]*inv[r]%mod

n,m=map(int,input().split())
ans=0
for i in range(N+1):
  ans+=C(n,i)*fac[M]*finv[M-i]*(C(M-i,N-i)**2)*(1 if i%2==0 else -1) % mod
print(ans%mod)


### FIXED CODE ###

fac=[1]*505050
inv=[1]*505050
finv=[1]*505050
mod=1000000007
for i in range(2,500010):
  fac[i]=fac[i-1]*i%mod
  inv[i]=-inv[mod%i]*(mod//i)%mod
  finv[i]=finv[i-1]*inv[i]%mod

def C(n,r):
  if n<0 or r<0 or n<r: return 0
  return fac[n]*finv[n-r]*finv[r]%mod

N,M=map(int,input().split())
ans=0
for i in range(N+1):
  ans+=C(N,i)*fac[M]*finv[M-i]*((fac[M-i]*finv[M-N])**2)*(1 if i%2==0 else -1) % mod
print(ans%mod)
n = int(input())
a = list(map(int, input().split()))
q = int(input())
d = dict()
s = 0
for num in a:
  if num in d:
    d[num] += 1
  else:
    d[num] = 1
  s += num
for i in range(q):
  B, C = list(map(int, input().split()))
  if B in d:
    if C in d:
      d[C] += d[B]
    else:
      d[C] = d[B]
    s += (C-B)*d[B]
    s[B] = 0
  print(s)

### FIXED CODE ###

n = int(input())
a = input().split()
q = int(input())
d = dict()
s = 0
for num in a:
  if num in d:
    d[num] += 1
  else:
    d[num] = 1
  s += int(num)
for i in range(q):
  B, C = input().split()
  if B in d:
    if C in d:
      d[C] += d[B]
    else:
      d[C] = d[B]
    s += (int(C)-int(B))*d[B]
    d[B] = 0
  print(s)
def Area(a, b):
    return a*b

def Lap(a, b):
    return 2*(a+b)

num = input()
a,b = num.split()
print('{} {}'.format(Area(a,b), Lap(a,b)))

### FIXED CODE ###

def Area(a, b):
    return a*b

def Lap(a, b):
    return 2*(a+b)

num = input()
a,b = num.split()
a = int(a)
b = int(b)
print('{} {}'.format(Area(a,b), Lap(a,b)))
A, B, C, D = map(int, input().split())

C_s = (A-A%C)//C
C_e = (B-B%C)//C

D_s = (A-A%D)//D
D_e = (B-B%D)//D

C_cnt = C_e - C_s
if A%C==0:
    C_cnt += 1
D_cnt = D_e - C_s
if A%C==0:
    D_cnt += 1

import math
lcm = (C * D) // math.gcd(C, D)

lcm_s = (A-A%lcm)//lcm
lcm_e = (B-B%lcm)//lcm

lcm_cnt = lcm_e - lcm_s
if A%lcm==0:
    lcm_cnt += 1

cnt = C_cnt + D_cnt - lcm_cnt
ans = B - A + 1 - cnt
print(ans)

### FIXED CODE ###

A, B, C, D = map(int, input().split())

C_s = (A-A%C)//C
C_e = (B-B%C)//C

D_s = (A-A%D)//D
D_e = (B-B%D)//D

C_cnt = C_e - C_s
if A%C==0:
    C_cnt += 1
D_cnt = D_e - D_s
if A%D==0:
    D_cnt += 1

import fractions
lcm = (C * D) // fractions.gcd(C, D)

lcm_s = (A-A%lcm)//lcm
lcm_e = (B-B%lcm)//lcm

lcm_cnt = lcm_e - lcm_s
if A%lcm==0:
    lcm_cnt += 1

cnt = C_cnt + D_cnt - lcm_cnt
ans = B - A + 1 - cnt
print(ans)
n = int(input())
L = [[int(i) for i in input().split()], [-int(i) for i in input().split()]]

c = 10**15
for i in range(2):
    A = L[i]
    if A[0] != 0:
        ans = 0
        S = A[0]
        f = A[0]//abs(A[0])
    else:
        ans = 1
        S = 1
        f = 1

    for a in A[1:]:
        S += a
        if S == 0:
            ans += 1
            S = -f
        else:
            if S/abs(S) != f*(-1):
                ans += abs(S)+1
                S = -f
        f *= -1
    c = min(ans, c)
print(c)


### FIXED CODE ###

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

ans=10**20
for flg in (-1,1):
    c=0
    s=0
    for a in a_list:
        s+=a
        if s==0:
            c+=1
            s=flg
        if s//abs(s)!=flg:
            c+=abs(s)+1
            s=flg
        flg*=-1
    ans=min(ans,c)
print(ans)
import sys
input = sys.stdin.readline

N = int(input())
edge = [[] for _ in range(N+1)]
 
for _ in range(N-1):
  a,b,c = map(int,input().split())
  edge[a].append((b,c))
  edge[b].append((a,c))

Q,K = map(int,input().split())

dist = [None]*(N+1)

def set_dist(x,d):
  dist[x] = d
  for y,dd in edge[x]:
    if dist[y] is not None:
      continue
    set_dist(y,d+dd)

set_dist(K,0)

for _ in range(Q):
  x,y = map(int,input().split())
  print(dist[x] + dist[y])

### FIXED CODE ###

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

N = int(input())
edge = [[] for _ in range(N+1)]
 
for _ in range(N-1):
  a,b,c = map(int,input().split())
  edge[a].append((b,c))
  edge[b].append((a,c))

Q,K = map(int,input().split())

dist = [None]*(N+1)

def set_dist(x,d):
  dist[x] = d
  for y,dd in edge[x]:
    if dist[y] is not None:
      continue
    set_dist(y,d+dd)

set_dist(K,0)

for _ in range(Q):
  x,y = map(int,input().split())
  print(dist[x] + dist[y])
import itertools
N, K = map(int, input().split())
pair = itertools.combinations(map(int, input().split()), 2)
res = [i[0] * i[1] for i in pair]
res.sort()
if len(res) != 0:
    print(res[K-1])

### FIXED CODE ###

A, B, C = map(int, input().split())
if A == B and A == C:
    print("No")
elif A == B or A == C or B == C:
    print("Yes")
else:
    print("No")
A,B = [int(x) for x in input().split()]
print((B-1)//(A-2) + 1)

### FIXED CODE ###

import math
Input = input().split(" ")
A = int(Input[0])
B = int(Input[1])
n = (B-1)/(A-1)
print(math.ceil(n))
import sys
ds = int(raw_input())
list =[long(x) for x in sys.stdin]
print list
for i in xrange(ds):
    print str(list[i*2]+list[i*2+1])

### FIXED CODE ###

ds = int(raw_input())
for i in xrange(ds):
    x=int(raw_input())
    y=int(raw_input())
    sum = str(x+y)
    if len(sum) > 80:
        print "overflow"
    else:
        print sum