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

S=input()
Q=int(input())
query=[]

for i in range(Q):
  query.append(list(input().split()))

for q in range(Q):
  if query[q][0]=="1":
    S = S[::-1]
  
  if query[q][0]=="2":
    if query[q][1]=="1":
      S=query[q][2]+S
    else:
      S=S+query[q][2]

print(S)


### FIXED CODE ###

from collections import deque
S=list(input())
Q=int(input())
query=[]
reverseflg=False
S=deque(S)

for i in range(Q):
  query.append(list(input().split()))

for q in range(Q):
  if query[q][0]=="1":
    reverseflg= not reverseflg
  
  if query[q][0]=="2":
    if query[q][1]=="1":
      if reverseflg== False:
        S.appendleft(query[q][2])
      else:
        S.append(query[q][2])
    
    else:
      if reverseflg== False:
        S.append(query[q][2])
      else:
        S.appendleft(query[q][2])

if reverseflg==True:
  S.reverse()
  
print(''.join(S))
### BUGGY CODE ###

s = list(input())
count = 0
i = 0
while i < len(s)-1:
    if s[i] != s[i+1]:
        del s[i]
        del s[i]
        count += 2
        i = 0
    else:
        i += 1      


print(count)

### FIXED CODE ###

s = list(input())
count0 =s.count('0')      
count1 =s.count('1')

print(min(count0,count1)*2)
### BUGGY CODE ###

def main():
    x,y = map(int,input().split())
    tmp = []
    for i in range(1,max(2,min(int(x // 2), int(y // 2 )))):
        if x % i ==0 and y % i == 0:
            # if x % (i*i) != 0 and y % (i*i) != 0:
            tmp.append(i)
    for i,a in enumerate(tmp):
        if a < 4:
            tmp[i] = 1
            continue
        j = 2
        for j in range(2,int(a**0.5)+1):
            if a % j == 0:
                tmp[i] = 0
                break
        if tmp[i] != 0:
            tmp[i] = 1
    print(sum(tmp))
    # print(tmp)

    # cnt = 0
    # # print(tmp)
    # flg = 0
    # for i,a in enumerate(tmp):
    #     # print('out' + str(i) + ' ' + str(a))
    #     if a == 1:
    #         continue
    #     leng = len(tmp)
    #     for j in range(i+1,leng):
    #         # print(j)
    #         # print(tmp)
    #         # print(leng)
    #         if flg == 1:
    #             j -=1
    #         flg = 0
    #         if j >= leng:
    #             break
    #         # print(str(j) + ' ' + str(leng) + ' ' + str(tmp[j]))
    #         if tmp[j] % a == 0:
    #             tmp.pop(j)
    #             leng -=1
    #             j -= 1
    #             # print(tmp)
    #             # print(j)
    #             flg = 1
    #
    #                 # print(j)
    #                 # print(a)
    #

    # print(len(tmp))
    # print(tmp)
if __name__=='__main__':
    main()


### FIXED CODE ###

def main():
    x,y = map(int,input().split())
    tmp = [1]
    i = 2
    ans = 0
    # if x == y:
    #     ans += 1
    # a = factorization(x)
    # print(a)
    tempx = x

    for i in range(2, int(-(-x**0.5//1))+1):
        if tempx % i == 0:
            tmp.append(i)
            while tempx % i == 0:

                tempx //= i
    if tempx!=1:
        tmp.append(tempx)
    # print(tmp)

    for i,a in enumerate(tmp):
        if y % a == 0:
            tmp[i] = 1
        else:
            tmp[i] = 0
    print(sum(tmp))


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

from fractions import gcd

def factorization(n):
    pf_cnt = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            pf_cnt[i] = cnt

    if temp != 1: pf_cnt[temp] = 1
    if not pf_cnt: pf_cnt[n] = 1
    return pf_cnt


def main():
    n = int(input())
    al = list(map(int, input().split()))

    al_fac = [0]*n
    for i, a in enumerate(al):
        fac = factorization(a)
        al_fac[i] = fac
        
    gcd_l = [1]*n
    gcd_r = [1]*n

    gcd_l[0] = al[0]
    gcd_r[-1] = al[-1]

    for i in range(1,n):
        next_l = al[i]
        gcd_l[i] = gcd(next_l, gcd_l[i-1])

        next_r = al[n-i-1]
        gcd_r[n-i-1] = gcd(next_r, gcd_r[n-i])


    ans = max(gcd_r[1], gcd_l[n-2])
    for i in range(1,n-1):
        curr_gcd = gcd(gcd_l[i-1], gcd_r[i+1])
        ans = max(ans, curr_gcd)

    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

from fractions import gcd

def factorization(n):
    pf_cnt = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            pf_cnt[i] = cnt

    if temp != 1: pf_cnt[temp] = 1
    if not pf_cnt: pf_cnt[n] = 1
    return pf_cnt


def main():
    n = int(input())
    al = list(map(int, input().split()))

    gcd_l = [1]*n
    gcd_r = [1]*n

    gcd_l[0] = al[0]
    gcd_r[-1] = al[-1]

    for i in range(1,n):
        next_l = al[i]
        gcd_l[i] = gcd(next_l, gcd_l[i-1])

        next_r = al[n-i-1]
        gcd_r[n-i-1] = gcd(next_r, gcd_r[n-i])


    ans = max(gcd_r[1], gcd_l[n-2])
    for i in range(1,n-1):
        curr_gcd = gcd(gcd_l[i-1], gcd_r[i+1])
        ans = max(ans, curr_gcd)

    print(ans)


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

n = int(input())
l = list(map(int,input().split()))
a = 0
l.sort()
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[i] + l[j] > l[k]:
                a += 1
print(a)

### FIXED CODE ###

import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for b in range(n):
  for a in range(b):
    ans += bisect.bisect_left(l,l[a]+l[b])-(b+1)
print(ans)
### BUGGY CODE ###

def modpow(x, n, p):
    res = 1
    while n > 0:
        if n & 1:
            res = res * x % p
        x = x * x % p
        n >>= 1
    return res

MOD = pow(10, 9) + 7

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

n = len(s)

fact = [1 for _ in range(n + k + 1)]
p25 = [1 for _ in range(n + k + 1)]
for i in range(1, n + k + 1):
    fact[i] = fact[i - 1] * i % MOD
    p25[i] = p25[i - 1] * 25 % MOD

inv = [1 for _ in range(n + k + 1)]
inv[n + k] = modpow(fact[n + k], MOD - 2, MOD)
for i in range(n + k - 1, -1, -1):
    inv[i] = inv[i + 1] * (i + 1) % MOD

ans = modpow(26, n + k, MOD)
for i in range(n):
    ans -=  fact[n + k] * inv[i] * inv[n + k - i] * p25[n + k - i]

print(ans % MOD)

### FIXED CODE ###

def modpow(x, n, p):
    res = 1
    while n > 0:
        if n & 1:
            res = res * x % p
        x = x * x % p
        n >>= 1
    return res

MOD = pow(10, 9) + 7

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

n = len(s)

fact = [1 for _ in range(n + k + 1)]
p25 = [1 for _ in range(n + k + 1)]
for i in range(1, n + k + 1):
    fact[i] = fact[i - 1] * i % MOD
    p25[i] = p25[i - 1] * 25 % MOD

inv = [1 for _ in range(n + k + 1)]
inv[n + k] = modpow(fact[n + k], MOD - 2, MOD)
for i in range(n + k - 1, -1, -1):
    inv[i] = inv[i + 1] * (i + 1) % MOD

ans = modpow(26, n + k, MOD)
for i in range(n):
    ans -= fact[n + k] * inv[i] % MOD * inv[n + k - i] % MOD * p25[n + k - i] % MOD
    if ans < 0:
        ans += MOD

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

s = input()
dp = [[0 for _ in range(0,4)] for _ in range(0,len(s)+1)]
dp[len(s)][3] = 1
dp[len(s)][0] = 0
dp[len(s)][1] = 0
dp[len(s)][2] = 0
abc = ["A","B","C"]
for i in range(len(s)-1,-1,-1):
    m = 1
    if s[i] ==  "?":
        m=3
    dp[i][3] += m * dp[i+1][3]

for i in range(len(s)-1,-1,-1):
    for j in range(0,3):
        m1,m2 = 1,0
        if s[i] == "?":
            m1,m2 = 3,1
        if s[i] == abc[j]:
            m1,m2 = 1,1
        dp[i][j] += m1 * dp[i+1][j] + m2 * dp[i+1][j+1]
# for i in range(len(s),-1,-1):
#     print(dp[i])
print(dp[0][0] % (10**9 + 7))


### FIXED CODE ###

s = input()
dp = [0 for _ in range(0,4)]
dp[3] = 1
dp[0] = 0
dp[1] = 0
dp[2] = 0
abc = "ABC".index
mod = 10**9 + 7
for i in range(len(s)-1,-1,-1):
    if s[i] == "?":
        dp = [
        (dp[0]*3+ dp[1])%mod
        ,(dp[1]*3+ dp[2])%mod
        ,(dp[2]*3 + dp[3])%mod
        ,(dp[3]*3)%mod
        ]
    else:
        num = abc(s[i])
        dp[num] += dp[num+1] % mod
print(dp[0] %mod)
### BUGGY CODE ###

import sys
import bisect
import heapq
sys.setrecursionlimit(10 ** 7)

# TLE

N, Q = map(int, input().split())
STX = [[int(x) for x in input().split()] for _ in range(N)]
EVENT = []
for s, t, x in STX:
    EVENT.append((s-x, 1, x))
    EVENT.append((t-x, 0, x))

for i in range(Q):
    d = int(input())
    EVENT.append((d, 2, i))

ans = [-1] * Q

EVENT.sort()

# print(EVENT)

STOP = set()
h = []
for t, op, x in EVENT:
    if op == 2 and STOP:
        ans[x] = min(list(STOP))
    elif op == 1:
        STOP.add(x)
    elif op == 0:
        STOP.remove(x)


print("\n".join(map(str, ans)))


### FIXED CODE ###

#D in [S_i-X_i,T_i-X_i) → Xiで止まる
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
from collections import defaultdict

N,Q = map(int,input().split())
task = []

STX = [[int(x) for x in input().split()] for _ in range(N)]
for s,t,x in STX:
  task.append((t-x,0,x)) # xで止まらなくなる
  task.append((s-x,1,x)) # xで止まる

for i in range(Q):
  d = int(input())
  task.append((d,2,i)) # 止まる位置を答える
answer = [-1]*Q

task.sort()

# 引っかかってる場所の管理
se = set()
se_hp = [] # heapで最小値を先頭に保つ

# 小さい時刻から順に見ていく
for a,b,c in task:
  if not b: # b == 0
    se.remove(c)
  elif b&1: # b == 1
    se.add(c)
    heappush(se_hp,c)
  else: # b == 2
    while se_hp and se_hp[0] not in se:
      heappop(se_hp)
    answer[c] = se_hp[0] if se_hp else -1

print('\n'.join(map(str,answer)))
### BUGGY CODE ###

N = int(input())

ans = 0

def prime_factorize(n: int):
    a = []
    f = 2
    while n > 1:
        if n % f == 0:
            a.append(f)
            n /= f
        else:
            f += 1
    return set(a)

prime_list = prime_factorize(N)

if prime_list:
    for prime_num in prime_list:
        if N % prime_num == 0:
            i = 1
            while N % prime_num**i == 0:
                N //= prime_num**i
                ans += 1
                i += 1
print(ans)


### FIXED CODE ###

N = int(input())

ans = 0

# if N % 2 == 0:
#     i = 1
#     while N % 2**i == 0:
#         N //= 2**i
#         ans += 1
#         i += 1

# if N % 3 == 0:
#     i = 1
#     while N % 3**i == 0:
#         N //= 3**i
#         ans += 1
#         i += 1

# if N % 5 == 0:
#     i = 1
#     while N % 5**i == 0:
#         N //= 5**i
#         ans += 1
#         i += 1

# if N % 7 == 0:
#     i = 1
#     while N % 7**i == 0:
#         N //= 7**i
#         ans += 1
#         i += 1

# if N % 11 == 0:
#     i = 1
#     while N % 11**i == 0:
#         N //= 11**i
#         ans += 1
#         i += 1

# if N % 13 == 0:
#     i = 1
#     while N % 13**i == 0:
#         N //= 13**i
#         ans += 1
#         i += 1

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return set(a)

prime_list = prime_factorize(N)

if prime_list:
    for prime_num in prime_list:
        if N % prime_num == 0:
            for j in range(1, 100):
                if N < prime_num**j:
                    break
                if N % prime_num**j == 0:
                    # print(prime_num, j)
                    N //= prime_num**j
                    ans += 1
# print(N)
# print(prime_list)
print(ans)
### BUGGY CODE ###

class SegmentTree():
    _data = []
    _offset = 0
    _size = 0

    def __init__(self, size):
        _size = size
        t = 1
        while t < size:
            t *= 2
        self._offset = t - 1
        self._data = [set() for _ in range(t * 2 - 1)]

    def update_all(self, iterable):
        self._data[self._offset:self._offset+self._size] = [set(c) for c in iterable]
        for i in range(self._offset - 1, -1, -1):
            self._data[i] = self._data[i * 2 + 1] | self._data[i * 2 + 2]

    def update(self, index, value):
        i = self._offset + index
        self._data[i] = set(value)
        while i >= 1:
            i = (i - 1) // 2
            self._data[i] = self._data[i * 2 + 1] | self._data[i * 2 + 2]

    def query(self, start, stop):
        result = set()
        l = start + self._offset
        r = stop + self._offset
        while l < r:
            if l & 1 == 0:
                result = result | self._data[l]
            if r & 1 == 0:
                result = result | self._data[r - 1]
            l = l // 2
            r = (r - 1) // 2
        return result


N = int(input())
S = input()

st = SegmentTree(N)
st.update_all(S)

Q = int(input())
for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        i, c = q[1:]
        i = int(i) - 1
        st.update(i, c)
    elif q[0] == '2':
        l, r = map(int, q[1:])
        print(len(st.query(l - 1, r)))


### FIXED CODE ###

class SegmentTree():
    _data = []
    _offset = 0
    _size = 0

    def __init__(self, size):
        _size = size
        t = 1
        while t < size:
            t *= 2
        self._offset = t - 1
        self._data = [0 for _ in range(t * 2 - 1)]

    def update_all(self, iterable):
        self._data[self._offset:self._offset+self._size] = [1 << (ord(c) - ord('a')) for c in iterable]
        for i in range(self._offset - 1, -1, -1):
            self._data[i] = self._data[i * 2 + 1] | self._data[i * 2 + 2]

    def update(self, index, value):
        i = self._offset + index
        self._data[i] = 1 << (ord(value) - ord('a'))
        while i >= 1:
            i = (i - 1) // 2
            self._data[i] = self._data[i * 2 + 1] | self._data[i * 2 + 2]

    def query(self, start, stop):
        result = 0
        l = start + self._offset
        r = stop + self._offset
        while l < r:
            if l & 1 == 0:
                result = result | self._data[l]
            if r & 1 == 0:
                result = result | self._data[r - 1]
            l = l // 2
            r = (r - 1) // 2
        return result


N = int(input())
S = input()

st = SegmentTree(N)
st.update_all(S)

Q = int(input())
for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        i, c = q[1:]
        i = int(i) - 1
        st.update(i, c)
    elif q[0] == '2':
        l, r = map(int, q[1:])
        print(bin(st.query(l - 1, r)).count('1'))
### BUGGY CODE ###

T = int(input())
for i in range(T):
	A,B,C,D = map(int,input().split(" "))
	if A < B:
		print("No")
		continue

	if D < B:
		print("No")
		continue

	if A > C:
		init = C + ((A - C) % B)
		if init != C:
			init -= B
		if init < 0:
			print("No")
			continue
	else:
		init = A

	if C >= (B-1):
		print("Yes")
		continue

	dif = (D - B)
	if dif == 0:
		print("Yes")
		continue

	i = init
	while True:
		k = C - ((C - i)%dif)
		if k + dif < B:
			print("No")
			break
		l = B - ((B - i)%dif)
		i = (l + dif)%B
		if (init - i) % dif == 0:
			print("Yes")
			break

	#print(B//dif,C // dif)
	


### FIXED CODE ###

T = int(input())

def gcd (a: int,b: int) -> int:
    if a < b: a,b = b,a
    return a if b == 0 else gcd(b,a%b)
def lcm (a: int,b: int) -> int:
    return a // gcd(a,b) * b


for i in range(T):
    A,B,C,D = map(int,input().split(" "))
    g = gcd(B,D)
    if A < B or D < B:
        print("No")
        continue
    if C >= ((B - g) + (A % g)):
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

import itertools

def prime(M):
    lst = []
    i = 2
    while M != 1:
        if M % i == 0:
            lst.append(i)
            M = M // i
        else:
            i += 1
    return lst

def volume(lst):
    res = 1
    for i in lst:
        res *= int(i)
    return res


N, M = map(int, input().split())
lst = prime(M)
res_lst = []
for i in range(len(prime(M)) + 1):
    for j in itertools.combinations(lst, i):
        if not volume(j) in res_lst:
            res_lst.append(volume(j))
res_lst = sorted(res_lst)
res = 1
for num in res_lst:
    if (M // N) < num:
        break
    else:
        res = num

print(res)



### FIXED CODE ###

import math


def prime(M):
    if M == 1:
        return [1]
    lst = []
    for i in range(1, int(math.sqrt(M)+1)):
        if M % i == 0:
            lst.append(i)
            div = M // i
            if div not in lst:
                lst.append(div)
    return sorted(lst)


N, M = map(int, input().split())
lst = prime(M)
res = 1
for num in lst:
    if (M // N) < num:
        break
    else:
        res = num

print(res)
### BUGGY CODE ###

def solve():
    N, *sl = map(lambda x: int(x), open(0).read().split())
    ans = "Yes"
    for i in range(N-1):
        a = sl[i] - 1
        b = min(sl[i+1:])
        if b < a:
            ans = "No"
            break
    print(ans)  
if __name__ == '__main__':
    solve()


### FIXED CODE ###

def solve():
    N, *sl = map(lambda x: int(x), open(0).read().split())
    ans = "Yes"
    s_max = sl[0]
    for i in range(1, N):
        a = sl[i]
        if s_max > a + 1:
            ans = "No"
            break
        s_max = max(s_max, a)
    print(ans)  
if __name__ == '__main__':
    solve()
### BUGGY CODE ###

N = int(input())
P = [int(i) for i in input().split()]
count = 0

for i in range(0, N):
    for j in range(0, i+1):
        if P[i] > P[j]:
            break
        elif j == i:
            count += 1

print(count)


### FIXED CODE ###

N = int(input())
P = [int(i) for i in input().split()]
count = 0
min_int = 2 * 10**5
for i in range(0, N):
    if P[i] <= min_int:
        count += 1
        min_int = P[i]

print(count)
### BUGGY CODE ###

import numpy as np
import math
N,K = map(int, input().split()) 
Logs = np.array([float(x) for x in input().split()])
cut = [1]*N
chip = Logs.copy()
for i in range(K):
  x = np.argmax(chip)
  cut[x]+=1
  chip[x]= Logs[x]/cut[x]
print(math.ceil((max(chip))))

### FIXED CODE ###

import numpy as np
import math
N,K = map(int, input().split()) 
Logs = np.array([int(x) for x in input().split()])
ave = sum(Logs)/(N+K)
cut = np.array([max(1,int(x/ave)) for x in Logs])
chip = Logs/cut
chip=np.sort(chip)[::-1]
print(math.ceil(chip[N+K-sum(cut)]))
### BUGGY CODE ###

def resolve():
    N = int(input())
    S = input()
    d = {}
    for i in range(N):
        for j in range(i+1, N+1):
            key = S[i:j]
            d.setdefault(key, [])
            if len(d[key]) > 0:
                if d[key][-1][1] <= i:
                    d[key].append((i, j))    
            else:
                d[key].append((i, j))
    ans = 0
    for k, v in d.items():
        if len(v) > 1:
            ans = max(ans, len(k))
    print(ans)





if '__main__' == __name__:
    resolve()


### FIXED CODE ###

def resolve():
    N = int(input())
    S = input()
    dp = [[0]*(N+1) for _ in range(N+1)]
    for i in reversed(range(N)):
        for j in reversed(range(N)):
            if S[i] == S[j]:
                dp[i][j] = dp[i+1][j+1] + 1
    
    ans = 0
    for i in range(N):
        for j in range(i, N):
            ans = max(min(dp[i][j], j-i), ans)
    print(ans)


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

a = int(input())

ans = 0
for i in range(a):
  ans += i
print(ans)

### FIXED CODE ###

b = int(input())
if b % 2 == 1:
    print((b-1) * ((b-1) // 2) + ((b-1) // 2))
else:
    print((b - 1) * ((b-1) // 2 + 1))
### BUGGY CODE ###

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

### FIXED CODE ###

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_sort = list(sorted(a))
a_max = a_sort[-1]
a_second = a_sort[-2]
for i in range(n):
    if a[i] == a_max:
        print(a_second)
    else:
        print(a_max)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import numpy as np
N,K,Q = map(int,input().split())
A_list = []
point_list = []

for i in range(Q):
    A_list.append(int(input()))

for i in range(N):
    point_list.append(Q-A_list.count(i+1))

np_point_list = np.array(point_list)

last = K - np_point_list
for i in range(len(last)):
    if last[i] > 0:
        print("Yes")
    elif last[i] <= 0:
        print("No")


### FIXED CODE ###

# -*- coding: utf-8 -*-
import numpy as np
N,K,Q = map(int,input().split())
point_list = [K-Q]*N

for i in range(Q):
    point_list[int(input())-1] += 1 


for i in range (N):
    if point_list[i] > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

import bisect
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
BC = []
for b in B:
    C2 = C[:]
    ok = bisect.bisect(C2,b)
    if ok!=N:
        bisect.insort(C2,b)
        for _ in range(N-ok):
            BC.append(C2[ok:])
for a in A:
    for bc in BC:
        if bisect.bisect(bc,a)==0:
            ans += 1
print(ans)


### FIXED CODE ###

import bisect
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
for b in B:
    ok_a = bisect.bisect_left(A,b)
    ok_c = bisect.bisect_right(C,b)
    if ok_a!=0 and ok_c!=N:
        ans += ok_a*(N-ok_c)
print(ans)
### BUGGY CODE ###

import math
a,b=map(int,input().split())
c=list(map(int,input().split()))
d=list(map(int,input().split()))
c.sort()
d.sort(reverse=True)
e=[0 for i in range(a)]
for i in range(a):
  e[i]=c[i]*d[i]
def s(e,x):
  k=0
  for i in range(a):
    if e[i]<x:
      continue
    else:
      k+=math.ceil((e[i]-x)/d[i])
  if k>b:
    return False
  else:
    return True
    
left=0
right=max(e)
while left!=right:
  mid=(left+right)//2
  if s(e,mid):
    right=mid
  else:
    left=mid+1
print(left)

### FIXED CODE ###

import math
a,b=map(int,input().split())
c=list(map(int,input().split()))
d=list(map(int,input().split()))
c.sort()
d.sort(reverse=True)
e=[0 for i in range(a)]
for i in range(a):
  e[i]=c[i]*d[i]
def s(e,x):
  k=0
  for i in range(a):
    if e[i]<x:
      continue
    else:
      k+=math.ceil((e[i]-x)/d[i])
  if k>b:
    return False
  else:
    return True
    
left=0
right=max(e)
while left!=right:
  mid=(left+right)//2
  if s(e,mid):
    right=mid
  else:
    left=mid+1
print(left)
### BUGGY CODE ###

def main() -> None:
    S = list(input())
    m = len(S)
    pre = len(S)
    while len(S) > 1:
        for i in range(len(S) - 1):
            if len(S) > i + 1:
                if S[i] != S[i+1]:
                    S.remove(S[i])
                    S.remove(S[i])
            else:
                break

        # 抜けなかった
        if pre == len(S):
            break
        else:
            pre = len(S)

    # 最初の数から引けば抜いた数
    print(m - len(S))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import collections


def main() -> None:
    S = list(input())
    a = collections.Counter(S)
    zero = a['0']
    one = a['1']
    if zero >= one:
        print(one * 2)
    else:
        print(zero * 2)


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

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

L.sort(reverse=True)

L_new = []

for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            L_new.append([L[i],L[j],L[k]])
            
count = 0

for i in range(len(L_new)):
    a = L_new[i][0]
    b = L_new[i][1]
    c = L_new[i][2]
    
    if a+b > c and b+c > a and c+a > b:
        count += 1
print(count)  

### FIXED CODE ###

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

L.sort()

import bisect
ans = 0

for i in range(N-2):
    for j in range(i+1,N-1):
        a = L[i] 
        b = L[j] 
        
        insert_index = bisect.bisect_left(L,a+b)
        #print(insert_index,a,b,a+b)
        
        if i < insert_index:
            ans += insert_index - j - 1
            #print(i,j,insert_index)
        
print(ans)
### BUGGY CODE ###

import fractions

N = int(input())
A = list(map(int,input().split()))
MOD = 10** 9 + 7
lcm = 1
for a in A:
    lcm = a // fractions.gcd(a,lcm) * lcm

ans = 0
for a in A:
    ans += lcm // a

print(sum(lcm//a for a in A)%MOD)

### FIXED CODE ###

import fractions

N = int(input())
A = list(map(int,input().split()))
MOD = 10** 9 + 7
lcm = 1
for a in A:
    lcm = a // fractions.gcd(a,lcm) * lcm

print(sum(lcm//a for a in A)%MOD)