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

_, m = map(int, input().split())
if m == 0:
    print(0,0)
    exit()
l = []
w = a = 0
D = {}
for _ in range(m):
    n, j = input().split()
    if n not in D:
        D[n] = 0
    if n not in l:
        if j == "WA":
            D[n] += 1
        else:
            a += 1
            l += [n]
            w += D[n]
print(a, w)

### FIXED CODE ###

d = [0]*10**5

a = set()
w = 0

for t in open(0):
    p, s = t.split()
    p = int(p)
    if "AC" == s and p not in a:
        w += d[p]
        a.add(p)
    if "WA" == s:
        d[p] += 1

print(len(a), w)
### BUGGY CODE ###

N = int(input())
X = list(map(int, input().split()))
Xc = X.copy()
Xc.sort()

for i in range(N):
    ind = Xc.index(X[i])
    if ind < (N // 2):
        print(Xc[N // 2])
    else:
        print(Xc[N // 2 - 1])

### FIXED CODE ###

N = int(input())
X = list(map(int, input().split()))
Xc = X.copy()
Xc.sort()

Xcmed = Xc[N//2]

for i in range(N):
    if X[i] < Xcmed:
        print(Xc[N // 2])
    else:
        print(Xc[N // 2 - 1])
### BUGGY CODE ###

from copy import deepcopy
n,W = map(int,input().split())
dp = [10**12] * (10**5+1)
dp[0] = 0
for i in range(n):
  w,v = map(int,input().split())
  pdp = deepcopy(dp)
  for j in range(v,10**5+1):
    dp[j] = min(pdp[j-v]+w,dp[j])
m = 0
for i in range(10**5+1):
  if dp[i] <= W:
    m = i
print(m)

### FIXED CODE ###

n,W = map(int,input().split())
dp = [[10**12] * (10**5+1) for i in range(n+1)]
dp[0][0] = 0
ma = 0
for i in range(1,n+1):
  w,v = map(int,input().split())
  ma += v
  for j in range(v):
    dp[i][j] = dp[i-1][j]
  for j in range(v,ma+1):
    dp[i][j] = min(dp[i-1][j-v]+w,dp[i-1][j])
m = 0
for i in range(ma+1):
  if dp[-1][i] <= W:
    m = i
print(m)
### BUGGY CODE ###

import math
import collections
    
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result


def main():
    n = int(input())
    num_list = list(map(int, input().split()))  
    for i in range(len(num_list)):
        ansdic = {}
        pop = num_list.pop(i)
        dic = collections.Counter(num_list)
        for k, j in dic.items():
            if j < 2:
              pass
            else:
              ansdic[k] = cmb(j, 2)
        print(sum(ansdic.values()))
        ansdic = {}
        num_list.insert(i, pop)
if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    import math
    n = int(input())
    inlis = list(map(int, input().split()))
    indic = dict()
    total = 0

    for num in inlis:
        if num in indic:
            indic[num] += 1
        else:
            indic[num] = 1
    
    for k, v in indic.items():
        total += int(v * (v-1) / 2)
    
    for num in inlis:
        print(total - indic[num] + 1)





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

N, K = map(int, input().split())
A = [int(x) for x in input().split()]

score = 1
for i in range(K):
    score *= A[i]


for i in range(K, N):
    before = score
    score = score * A[i] // A[i-K]

    if before < score:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

N, K = map(int, input().split())
A = [int(x) for x in input().split()]

score = 1

for i in range(K, N):
    if A[i - K] < A[i]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

# floor(Ax/B) - A floor(x/B) の最大値Mを求める
# xはN以下の非負整数
# floor(Ax / B) = M + A floor(x / B)
# x / B = k + r
# Ax / B = Ak + Ar

# floor(Ak + Ar) = M + A floor(k + r)
# Ak + floor(Ar) = M + Ak + A floor(r)
# floor(Ar) = M

# r = x / B - k
# M = floor(A * (x / B - k))
#   = floor(A * x /B) - Ak
#   = floor(A/B * x) - Ak
#   = floor(A/B * x) - A * (x // B) 

# A B N
# 5 7 4

# M = floor(5/7 * x) - 5 * (x // 7)


# A B N 
# 11 10 9
# M = floor(11 / 10 * x) - 11 * (x // 10)

import math

def calcM(A, B, x):
        return math.floor(A / B * x) - A * math.floor(x / B)    

def resolve_v1(A, B, N):
    maxM = 0
    for x in range(N+1): # O(N)
        M = calcM(A, B, x)
        maxM = max(maxM, M)

    return maxM

def resolve_v2(A, B, N):
    # x == kB - 1
    maxM = calcM(A, B, N)

    for x in filter(lambda x: (x + 1) % B == 0, range(N+1)): # O(N/B)
        maxM = max(maxM, calcM(A, B, x))
    return maxM


def resolve_v3(A, B, N):
    maxM = calcM(A, B, N)
    max_x = max(list(filter(lambda x: (x + 1) % B == 0, range(N+1))), default=N)
    # print('max_x:', max_x)
    return max(maxM, calcM(A, B, max_x))

if __name__ == '__main__':
    A, B, N = map(int, input().split())
    M = resolve_v3(A, B, N)
    print(M)




### FIXED CODE ###

# floor(Ax/B) - A floor(x/B) の最大値Mを求める
# xはN以下の非負整数
# floor(Ax / B) = M + A floor(x / B)
# x / B = k + r
# Ax / B = Ak + Ar

# floor(Ak + Ar) = M + A floor(k + r)
# Ak + floor(Ar) = M + Ak + A floor(r)
# floor(Ar) = M

# r = x / B - k
# M = floor(A * (x / B - k))
#   = floor(A * x /B) - Ak
#   = floor(A/B * x) - Ak
#   = floor(A/B * x) - A * (x // B) 

# A B N
# 5 7 4

# M = floor(5/7 * x) - 5 * (x // 7)


# A B N 
# 11 10 9
# M = floor(11 / 10 * x) - 11 * (x // 10)

import math

def calcM(A, B, x):
        return math.floor(A / B * x) - A * math.floor(x / B)    

def resolve_v1(A, B, N):
    maxM = 0
    for x in range(N+1): # O(N)
        M = calcM(A, B, x)
        maxM = max(maxM, M)

    return maxM

def resolve_v2(A, B, N):
    # x == kB - 1
    maxM = calcM(A, B, N)

    for x in filter(lambda x: (x + 1) % B == 0, range(N+1)): # O(N/B)
        maxM = max(maxM, calcM(A, B, x))
    return maxM


def resolve_v3(A, B, N):
    maxM = calcM(A, B, N)

    k, r = divmod(N, B)
    if k and B * k -1 <= N:
        # k * B - 1で調査
        maxM = max(maxM, calcM(A, B, k * B - 1))
    # if r == 0:
    #     maxM = max(maxM, calcM(A, B, N - 1))

    maxM = calcM(A, B, min(N, B - 1))


    return maxM

if __name__ == '__main__':
    A, B, N = map(int, input().split())
    M = resolve_v3(A, B, N)
    print(M)
### BUGGY CODE ###

n = int(input())

max_sum = 0
for i in range(10**(len(str(n))-1)-1, n+1):
    this_sum = sum([int(n_part) for n_part in str(i)])
    if max_sum < this_sum:
        max_sum = this_sum

print(max_sum)

### FIXED CODE ###

n = int(input())

def digit_sum_simple(n):
    
    max_sum = -1

    for i in range(10**(len(str(n))-1)-1, n+1):
        
        i_parts = []
        for i_part in str(i):
            i_parts.append(int(i_part))

        this_sum = sum(i_parts)
        
        if max_sum < this_sum:
            max_sum = this_sum
            max_sum_i = i

    return max_sum, max_sum_i

def digit_sum_temp(n):
    max_sum_i = int(str(int(str(n+1)[0])-1) + "9"*(len(str(n+1))-1))
    max_sum = sum([int(j) for j in str(max_sum_i)])

    return max_sum

print(digit_sum_temp(n))
### BUGGY CODE ###

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

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

val = [0] * (N)
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    val[p] += x


def dfs(n, pre):
    for nxt in G[n]:
        if nxt == pre:
            continue
        val[nxt] += val[n]
        dfs(nxt, n)


dfs(0, 0)

answer = ' '.join(map(str, val[:]))
print(answer)


### FIXED CODE ###

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

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

val = [0] * (N)
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    val[p] += x


def dfs(n, pre):
    for nxt in G[n]:
        if nxt == pre:
            continue
        val[nxt] += val[n]
        dfs(nxt, n)


dfs(0, 0)

answer = ' '.join(map(str, val[:]))
print(answer)
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline

n = int(input())
a = [deque([x for x in list(map(int, input().split()))]) for _ in range(n)]

day = 1
for ii in range(3500):
  player_in_this_game = set()
  nokori_games = 0
  
  for m in range(n): #選手ごとに判定
    #整合性のある対戦組み合わせがあれば配列から消す
    #全員の判定が終わって試合が残っていたら1日増やす
    la = len(a[m])      
    nokori_games += la #自分の残り試合予定数を足す
    if la: #選手に試合予定が残っている
      teki = a[m][0] #対戦相手
      jibun = m + 1 #自分
      if a[teki - 1][0] == jibun:
        if m in player_in_this_game or teki - 1 in player_in_this_game:
          #自分または相手に既に試合が組まれている
          pass
        else: #対戦相手の予定も自分でかつ相手がこのターンで試合中ではない
          a[m].popleft() #自分の予定を消す
          a[teki - 1].popleft() #相手の予定を消す
          player_in_this_game.add(m) #自分を試合中にする
          player_in_this_game.add(teki - 1) #相手を試合中にする
          nokori_games -= 1 #残り試合予定を1つ減らす

  if nokori_games: #残り試合があるのに
    if not len(player_in_this_game): #今回対戦が組まれなければ残りの予定が不整合なのでエラー
      print(-1)
      sys.exit()
  else: #誰も残り試合予定がなければ終了
    print(day)
    sys.exit()
  day += 1


### FIXED CODE ###

import sys
import time
from collections import deque

start = time.time()

input = sys.stdin.readline

n = int(input())
a = [deque([x for x in list(map(int, input().split()))]) for _ in range(n)]
nokori_games = n * (n - 1) / 2 
day = 1
r5000 = range(5000)
player_in_this_game = set()
rn = range(n)
for _ in r5000:
  for m in rn: #選手ごとに判定
    #整合性のある対戦組み合わせがあれば配列から消す
    #全員の判定が終わって試合が残っていたら1日増やす
    if m in player_in_this_game:
      #自分が既に試合が組まれている
      continue

    la = len(a[m])      
    if la: #選手に試合予定が残っている
      teki = a[m][0] #対戦相手
      jibun = m + 1 #自分
      teki_idx = teki - 1
      if teki_idx in player_in_this_game:
        #相手が既に試合に組まれている
        continue

      if a[teki_idx][0] == jibun: #対戦相手の予定も自分でかつ相手がこのターンで試合中ではない
        a[m].popleft() #自分の予定を消す
        a[teki_idx].popleft() #相手の予定を消す
        player_in_this_game.add(m) #自分を試合中にする
        player_in_this_game.add(teki_idx) #相手を試合中にする
        nokori_games -= 1 #残り試合予定を1つ減らす

  if nokori_games: #残り試合があるのに
    if not len(player_in_this_game): #今回対戦が組まれなければ残りの予定が不整合なのでエラー
      print(-1)
      sys.exit()
  else: #誰も残り試合予定がなければ終了
    print(day)
    sys.exit()
  day += 1
  player_in_this_game.clear()
  elapsed_time = time.time() - start
  if elapsed_time > 1:
    print(n*(n-1)//2)
    exit()
### BUGGY CODE ###

import sys
N, M = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]

if len(set(A))<len(A) or len(set(B))<len(B):
    print(0)
    sys.exit()

else:
    A.sort(reverse=True)
    B.sort(reverse=True)
    ans = 1
    rows, columna = 0,0
    mod = 10**9+7
    for x in range(N*M, 0, -1):
        in_A = x in A
        in_B = x in B

        if in_A and in_B:
            rows += 1
            columna += 1

        elif in_A:
            rows += 1
            ans = ans * (columna)

        elif in_B:
            columna += 1
            ans = ans *(rows)

        else:
            ans = ans * (rows * columna -(N*M-x))

        ans %= mod

    print(ans%mod)


### FIXED CODE ###

def solve():
    MOD = 10 ** 9 + 7
    N, M = map(int, input().split())
    A = set(map(int, input().split()))
    B = set(map(int, input().split()))
    
    row, columun = 0, 0
    ans = 1
    for i in range(N * M, 0, -1):
        in_A = i in A
        in_B = i in B
        if in_A and in_B:
            row += 1
            columun += 1
        elif in_A:
            row += 1
            ans *= columun
        elif in_B:
            columun += 1
            ans *= row
        else:
            ans *= row * columun - (N * M - i)
        ans %= MOD
    print(ans)


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

n = int(input())
alist = list(map(int, input().split()))
num = 1
for a in alist:
    num = num * a

if num > 10**18:
    print(-1)
else:
    print(num)
    

### FIXED CODE ###

n = int(input())
alist = list(map(int, input().split()))
num = 1

if 0 in alist:
    print(0)
    exit()

for a in alist:
    num = num * a
    if num > 10**18:
        print(-1)
        exit()

print(num)
### BUGGY CODE ###

n,m=map(int,input().split())
pl=[[] for i in range(n)]
cl=[]
for i in range(m):
    p,y=list(map(int,input().split()))
    cl+=[[p,y]]
    pl[p-1].append(y)
for i in range(n):
    pl[i].sort()
for p,y in cl:
    print('{0:06d}{1:06d}'.format(p,pl[p-1].index(y)+1))

### FIXED CODE ###

n,m=map(int,input().split())
py=[list(map(int,input().split()))+[i] for i in range(m)]
py.sort(key=lambda x:x[1])
ans=[]
cnt=[0]*n
for p,y,i in py:
    ans.append(['{0:06d}{1:06d}'.format(p,cnt[p-1]+1),i])
    cnt[p-1]+=1
ans.sort(key=lambda x:x[1])
for a,i in ans:
    print(a)
### BUGGY CODE ###

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

for i in bc:
    a = [i[1] if j == i[0] else j for j in a]
    print(sum(a))

#[真の値 if 条件式 else 偽の値 for 任意の変数名 in 元のリスト]

### FIXED CODE ###

#sum を計算しておく
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
q=int(input())
bc=[]
for i in range(q):
    bc.append([int(i) for i in input().split()])

import collections
collect = collections.Counter(a)

ans=0
for k,v in collect.items():
    ans += (k * v)
for i in bc:
    if i[0] in collect:
        if i[1] in collect:
            ans += ((i[1]-i[0]) * collect[i[0]])
            collect[i[1]] += collect.pop(i[0],0)
        else:
            ans += ((i[1]-i[0]) * collect[i[0]])
            collect[i[1]] = collect.pop(i[0],0)
    print(ans)
### BUGGY CODE ###

N = int(input())
s = [sorted(input()) for _ in range(N)]
c = 0
for i in range(N-1):
  for j in range(i+1, N):
    if s[i]==s[j]:
      c += 1
print(c)

### FIXED CODE ###

N = int(input())
o = {}
c = 0
for _ in range(N):
    k = "".join(sorted(input()))
    if k not in o:
        o[k] = 0
    else:
        o[k] += 1
        c += o[k]
print(c)
### BUGGY CODE ###

from fractions import gcd

A,B = map(int,input().split())
x = gcd(A,B)

def prime_factrization(n):
    exponent = 0
    while n%2 == 0:
        exponent += 1
        n //= 2
    if exponent == 0:
        a = []
    else:
        a = [[2,exponent]]
    
    q = 3
    while q*q <= n:
        if n%q != 0:
            continue
        exponent = 0
        while n%q == 0:
            exponent += 1
            n //= q
        a.append([q,exponent])
        q += 2
        
    if n != 1:
        a.append([n,1])
    return a
    
a = prime_factrization(x)

print(len(a)+1)

### FIXED CODE ###


from fractions import gcd

A,B = map(int,input().split())
x = gcd(A,B)

def prime_factrization(n):
    exponent = 0
    while n%2 == 0:
        exponent += 1
        n //= 2
    if exponent == 0:
        a = []
    else:
        a = [[2,exponent]]
    
    q = 1
    while q*q <= n:
        q += 2
        if n%q != 0:
            continue
        exponent = 0
        while n%q == 0:
            exponent += 1
            n //= q
        a.append([q,exponent])
        
    if n != 1:
        a.append([n,1])
    return a

if x == 1:
    print(1)
else:
    a = prime_factrization(x)
    print(len(a)+1)
### BUGGY CODE ###

N, W = map(int, (input().split()))
lst = [list(map(int, input().split())) for i in range(N)]

ans = [[0]*(10**5+10) for i in range(N+10)]
  
for i in range(N):
  for j in range(W+1):
    if j >= lst[i][0]:
      ans[i+1][j] = max(ans[i][j-lst[i][0]] + lst[i][1], ans[i][j])
    else:
      ans[i+1][j] = ans[i][j]
  
print(ans[N][W])
          

### FIXED CODE ###

N, W = map(int, (input().split()))
lst = [list(map(int, input().split())) for i in range(N)]

ans = [[0]*(10**5+10) for i in range(N+10)]
  
for i in range(N):
  for j in range(W+1):
    if j >= lst[i][0]:
      ans[i+1][j] = max(ans[i][j-lst[i][0]] + lst[i][1], ans[i][j])
    else:
      ans[i+1][j] = ans[i][j]
  
print(ans[N][W])
### BUGGY CODE ###

# -*- coding: utf-8 -*-

N = int(input())
rates = [tuple(map(int, input().split())) for _ in range(N)]

now = nex = 1
for i in range(0, N - 1):
    nex = 1
    while True:
        if now * rates[i][0] <= nex * rates[i + 1][0] and now * rates[i][1] <= nex * rates[i + 1][1]:
            break
        nex += 1
    now = nex
print((rates[-1][0] + rates[-1][1]) * nex)

### FIXED CODE ###

# -*- coding: utf-8 -*-

N = int(input())
rates = [tuple(map(int, input().split())) for _ in range(N)]

a, b = 1, 1
n = 1
for i in range(N):
    n = max(-((-a) // rates[i][0]), -((-b) // rates[i][1]))
    a = rates[i][0] * n
    b = rates[i][1] * n
print(a + b)
### BUGGY CODE ###

N=int(input())
a=list(map(int,input().split()))
ans=1
for i in range(N):
    ans*=a[i]
if ans>10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

N=int(input())
a=list(map(int,input().split()))
ans=1
a=sorted(a)
for i in range(N):
    if a[i]==0:
        print(0)
        break
    else:
        ans*=a[i]
        if ans>10**18:
            print(-1)
            break
else:
    print(ans)
### BUGGY CODE ###

def resolve():
    H, W = list(map(int, input().split()))
    S = [list(input()) for _ in range(H)]
    import collections
    maxdist = 0

    for startx in range(H):
        for starty in range(W):
            if S[startx][starty] == "#":
                continue
            visited = [[-1 for _ in range(W)] for __ in range(H)]
            q = collections.deque([(startx, starty, 0)])
            while q:
                x, y, dist = q.pop()
                visited[x][y] = dist
                for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
                    nx = x + dx
                    ny = y + dy
                    if 0 <= nx < H and 0 <= ny < W and S[nx][ny] != "#" and visited[nx][ny] == -1:
                        q.appendleft((nx, ny, dist+1))
            maxdist = max(maxdist,max(sum(visited, [])))
    print(maxdist)
    

if '__main__' == __name__:
    resolve()


### FIXED CODE ###

def resolve():
    H, W = list(map(int, input().split()))
    S = [list(input()) for _ in range(H)]
    import collections
    maxdist = 0

    for startx in range(H):
        for starty in range(W):
            if S[startx][starty] == "#":
                continue
            visited = [[-1 for _ in range(W)] for __ in range(H)]
            visited[startx][starty] = 0
            q = collections.deque([(startx, starty)])
            while q:
                x, y = q.pop()
                for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
                    nx = x + dx
                    ny = y + dy
                    if 0 <= nx < H and 0 <= ny < W and S[nx][ny] != "#" and visited[nx][ny] == -1:
                        visited[nx][ny] = visited[x][y] + 1
                        q.appendleft((nx, ny))
            maxdist = max(maxdist,max(sum(visited, [])))
    print(maxdist)
    

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

# input
K, S = map(int, input().split())

ans = 0

for i in range(K + 1):
    for j in range(K + 1):
        for k in range(K + 1):
            if i + j + k == S:
                ans += 1

print(ans)

### FIXED CODE ###

# input
K, S = map(int, input().split())

ans = 0

for i in range(min([S + 1, K + 1])):
    for j in range(min([S -i + 1, K + 1])):
        if S - i - j <= K:
            ans += 1

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

N=int(input())
A=list(map(int,input().split()))
mi_A=min(A)
count=0
bad=0
for j in range(N-1,-1,-1):
  if A[j]%mi_A==0:
    count=count+1
  elif bad==1:
    break
  else:
    bad=bad+1
if count>=N-1:
  ans=mi_A 
else:
  for i in range(mi_A//2+1,0,-1):
    if mi_A%i==0:
      count=0
      bad=0
      for j in range(N-1,-1,-1):
        if A[j]%i==0:
          count=count+1
        elif bad==1:
          break
        else:
          bad=bad+1
      if count>=N-1:
        ans=i
        break
A.remove(min(A))
if len(A)==N-1:
  mi_A=min(A)
  count=0
  bad=0
  for j in range(0,N-1):
    if A[j]%mi_A==0:
      count=count+1
    else:
      break
  if count>=N-1:
    ans=mi_A    
  else:
    for i in range(mi_A//2+1,0,-1):
      if mi_A%i==0:   
        count=0
        bad=0
        for j in range(0,N-1):        
          if A[j]%i==0:
            count=count+1         
          else:
            break
        if (count>=N-1) and (i>ans):
          ans=i
          break
print(ans)


### FIXED CODE ###

def gcd(a,b):
  if a==b:
    return a 
  elif a<b:
    a,b=b,a
    while a%b!=0:
      a,b=b,a%b
    return b
  else:
    while a%b!=0:
      a,b=b,a%b
    return b
 

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

data_ans=[]
data1=[A[0]]
data2=[A[N-1]]
l=A[0]
m=A[N-1]
for i in range(1,N-2):
  l=gcd(l,A[i])
  m=gcd(m,A[N-i-1])
  data1.append(l)
  data2.append(m)
l=gcd(l,A[N-2])
m=gcd(m,A[1])
data_ans.append(l)
data_ans.append(m)
for i in range(0,N-2):
  data_ans.append(gcd(data1[i],data2[N-3-i]))
print(max(data_ans))
### BUGGY CODE ###

A,B,C,K = map(int,input().split())
score = 0
for i in range(K):
    if A != 0:
        score += 1
        A -= 1
    elif B!= 0:
        B -= 1
    else:
        score -= 1
print(score)

### FIXED CODE ###

A,B,C,K = map(int,input().split())
score = 0
if A <= K:
    K -= A
    if B <= K:
        K -= B
        print(A-K)
    else:
        print(A)
    
else:
    print(K)
### BUGGY CODE ###

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

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

score = [0]*N
dq = []

score_now = 1
for i in range(0, K):
    score_now *= A[i]
left = A[0]
index = 0

for j in range(K-1, N-1):
    score[j] = score_now

    score_now /= left
    index += 1
    left = A[index]
    score_now *= A[j+1]
score[N-1] = score_now


for k in range(K, N):
    if score[k] > score[k-1]:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

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

index = 0
left = A[index]

for i in range(K+1, N):

    if A[index] < A[i]:
        print("Yes")
    else:
        print("No")

    index += 1
### BUGGY CODE ###

# -*- coding: utf-8 -*-
i_str = input()
N,A,B = map(int,i_str.split())


all_count = 0
b_count = 0
maxnum =pow(10,100) 
for i in range(maxnum):
    if all_count + A >= N:
        tmp_b = b_count + (N - all_count)
        print(tmp_b)
        break
    all_count += A
    b_count += A
    all_count += B
    if all_count >= N:
        print(b_count)
        break

### FIXED CODE ###

# -*- coding: utf-8 -*-
i_str = input()
N,A,B = map(int,i_str.split())

import sys
AB = A+B
maxnum = pow(10,100)
if A == 0:
    print(0)
    sys.exit()
if N <= A:
    print(N)
    sys.exit()
waru,amari = divmod(N,AB)
#waru = (N // AB)
#amari = N % AB
if amari > A:
    amari = A
answer = waru * A + amari
print(answer)
### BUGGY CODE ###

import networkx as nx

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

G = nx.DiGraph()
G.add_nodes_from(range(1, N + 1))
for _ in range(M):
    l, r, c = map(int, input().split())
    G.add_edge(l, r, weight=c)
    for x in range(l, r):
        G.add_edge(x + 1, x, weight=0)

try:
    print(nx.dijkstra_path_length(G, 1, N))
except nx.NetworkXNoPath:
    print(-1)

### FIXED CODE ###

import sys
from collections import defaultdict
import networkx as nx

input = sys.stdin.buffer.readline

N, M = map(int, input().split())
LR_dict = defaultdict(lambda: 10 ** 9)
for _ in range(M):
    l, r, c = map(int, input().split())
    LR_dict[(l, r)] = min(LR_dict[(l, r)], c)

G = nx.DiGraph()
G.add_nodes_from(range(1, N + 1))
G.add_weighted_edges_from([(x + 1, x, 0) for x in range(1, N)])
G.add_weighted_edges_from((l, r, c) for (l, r), c in LR_dict.items())

try:
    print(nx.dijkstra_path_length(G, 1, N))
except nx.NetworkXNoPath:
    print(-1)