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

N = int(input())
start = [0] * N
end = [0] * N
imosu = [0] * (2 * N)
imosu2 = [-10 ** 10] * (2 * N)
imosu3 = [0] * (2 * N)
for i in range(N):
  x, l = map(int, input().split())
  start[i] = x - l
  end[i] = x + l
  imosu[2 * i] = x - l
  imosu[2 * i + 1] = x + l
imosu = sorted(imosu)
#print(start, end, imosu)
j = 0
for i in range(2 * N):
  if i == 0:
    imosu2[j] = imosu[i]
  else:
    if imosu[i] != imosu[i - 1]:
      j += 1
      imosu2[j] = imosu[i]
#print(imosu2)
for i in start:
  x = imosu2.index(i)
  imosu3[x] += 1
#print(imosu3)
for i in end:
  x = imosu2.index(i)
  imosu3[x] -= 1
#print(imosu3)

for i in range(1, 2 * N):
  imosu3[i] += imosu3[i - 1]
#print(imosu3)

ans = 0 
now = 0
for i in range(2 * N):
  #print(i)
  if imosu3[i] > 0:
    now = max(now, imosu3[i])
  else:
    if now >= 2:
      ans += now - 1
      now = 0
    else:
      now = 0

print(N - ans)


### FIXED CODE ###

N = int(input())
xl = [0] * N
for i in range(N):
  x, l = map(int ,input().split())
  a = x - l
  b = x + l
  xl[i] = [a, b]
  
xl = sorted(xl, key = lambda x:x[1])

ans = 0
now = 0
for i in range(N):
  if i == 0:
    ans += 1
    now = xl[0][1]
  else:
    if xl[i][0] >= now:
      ans += 1
      now = xl[i][1]
      
print(ans)
### BUGGY CODE ###

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

grid = [list(input()) for _ in range(h)]
left = [[0 for _ in range(w)] for _ in range(h)]
right = [[0 for _ in range(w)] for _ in range(h)]
up = [[0 for _ in range(w)] for _ in range(h)]
down = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    current = 0
    for j in range(w):
        if grid[i][j] == '#':
            current = 0
        else:
            current += 1
        left[i][j] = current
    
for i in range(h):
    current = 0
    for j in range(w - 1, -1, -1):
        if grid[i][j] == '#':
            current = 0
        else:
            current += 1
        right[i][j] = current

for i in range(w):
    current = 0
    for j in range(h):
        if grid[j][i] == '#':
            current = 0
        else:
            current += 1
        up[j][i] = current

for i in range(w):
    current = 0
    for j in range(h - 1, -1, -1):
        if grid[j][i] == '#':
            current = 0
        else:
            current += 1
        down[j][i] = current

ans = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] == '#':
            continue
        ans = max(ans, left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3)

print(ans)

### FIXED CODE ###

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

grid = [list(input()) for _ in range(h)]
left = [[0] * w for _ in range(h)]
right = [[0] * w for _ in range(h)]
up = [[0] * w for _ in range(h)]
down = [[0] * w for _ in range(h)]

for i in range(h):
    current = 0
    for j in range(w):
        if grid[i][j] == '#':
            current = 0
        else:
            current += 1
        left[i][j] = current
    
for i in range(h):
    current = 0
    for j in range(w - 1, -1, -1):
        if grid[i][j] == '#':
            current = 0
        else:
            current += 1
        right[i][j] = current

for i in range(w):
    current = 0
    for j in range(h):
        if grid[j][i] == '#':
            current = 0
        else:
            current += 1
        up[j][i] = current

for i in range(w):
    current = 0
    for j in range(h - 1, -1, -1):
        if grid[j][i] == '#':
            current = 0
        else:
            current += 1
        down[j][i] = current

ans = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] == '#':
            continue
        ans = max(ans, left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3)

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

# D Anything Goes to Zero

n = int(input())
x = input()

ori_cnt = x.count("1")
for i in range(n):
  xi = int(x, 2)
  if x[i] == "1":
    new_cnt = ori_cnt - 1
  elif x[i] == "0":
    new_cnt = ori_cnt + 1
  xi = xi ^ (1 << n-i-1)
  if xi == 0:
    print(0)
  else:
    xi = xi % new_cnt
    ans = 1
    while xi != 0:
      xi = xi % bin(xi).count("1")
      ans += 1
    print(ans)


### FIXED CODE ###

# D Anything Goes to Zero

n = int(input())
x = input()

original_pop_count = x.count("1")
one_pop_count = original_pop_count - 1
zero_pop_count = original_pop_count + 1

one_mod = 0
zero_mod = 0
for b in x:
  if one_pop_count != 0:
    one_mod = (one_mod * 2 + int(b)) % one_pop_count
  zero_mod = (zero_mod * 2 + int(b)) % zero_pop_count

#fの前計算
f = [0] * 220000
pop_count = [0] * 220000
for i in range(1, 220000):
  pop_count[i] = pop_count[i//2] + i % 2
  f[i] = f[i % pop_count[i]] + 1

#pow2の前計算
one_pow2 = [1] * 220000
zero_pow2 = [1] * 220000
for i in range(1, 220000):
  if one_pop_count != 0:
    one_pow2[i] = one_pow2[i-1] * 2 % one_pop_count
  zero_pow2[i] = zero_pow2[i-1] * 2 % zero_pop_count

for i in range(n-1, -1, -1):
  if x[n-1-i] == "1":
    if one_pop_count != 0:
      nxt = one_mod
      nxt -= one_pow2[i]
      nxt %= one_pop_count
      print(f[nxt] + 1)
    else:
      print(0)
  if x[n-1-i] == "0":
    nxt = zero_mod
    nxt += zero_pow2[i]
    nxt %= zero_pop_count
    print(f[nxt] + 1)
### BUGGY CODE ###

import copy
n = int(input())
l = [int(input()) for i in range(n)]
l1 = copy.copy(l)
for i in range(len(l1)):
  del l[i]
  print(max(l))
  l = copy.copy(l1)


### FIXED CODE ###

n = int(input())
l = [int(input()) for i in range(n)]
a = max(l)
b = sorted(l)[-2]
for i in l:
  print(b if i == a else a)
### BUGGY CODE ###

import sys
N = int(input())

result = 0
for c in range(1, N):
    n = N - c

    total = 0
    for a in range(1, n + 1):
        if n % a != 0:
            continue

        total += 1

        b = n // a
        if a == b:
            result += (total * 2) - 1
            break

        if a > b:
            result += (total - 1) * 2
            break

print(result)


### FIXED CODE ###

import sys

N = int(input())

result = 0
for a in range(1, N):
    if N % a == 0:
        b_count = N // a - 1
    else:
        b_count = N // a
    result += b_count

print(result)
### BUGGY CODE ###

import sys
#from scipy.special import comb
#from scipy.misc import comb

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

A = [0]*M

for i in range(M):
    A[i] = int(input())

A.append(N+1)

def step_comb(L):
    c = 0
    if L==1 or L == 0:
        c = 1
    else:
        for i in range(L//2 +1):
            j = L - 2*i
            #c += comb(j+i, i, exact=True)
            c += cmb(j+i, i)
    return c

total_comb = 1
NOW = 0
for a in A:
    if NOW == a:
        print(0)
        sys.exit()
    L = a-1-NOW
    total_comb *= step_comb(L)
    NOW = a + 1
    
print(total_comb % 1000000007 )


### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)

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

if M == 0:
    A = []
else:
    A = [0]*M
    for i in range(M):
        A[i] = int(input())

A.append(N+1)

# DP version
DP = [0]*(N+1)
DP[0] = 1
# １段の階段を登るやり方の数
DP[1] = 1
# 2段の階段を登るやり方の数
#DP[2] = 2

for i in range(2,N+1):
    DP[i] = DP[i-1] + DP[i-2]

def step_comb(L):
    if DP[L]>0:
        return DP[L]
    DP[L] = step_comb(L-1) + step_comb(L-2)
    return DP[L]
    
total_comb = 1
NOW = 0
for a in A:
    if NOW == a:
        print(0)
        sys.exit()
    L = a-1-NOW
    total_comb *= step_comb(L)
    NOW = a + 1
    if NOW == N:
        break
    
print(total_comb % 1000000007 )
### BUGGY CODE ###

n= int(input())
arr = [int(x) for x in input().strip().split()]

mem = {}
def helper(i, mon, stk):
    key = (i, mon, stk)
    if key in mem:
        return mem[key]
    
    if i==len(arr):
        return mon
    
    ans = helper(i+1, mon, stk)
    buy = 1
    while True:
        if arr[i]*buy<=mon:
            ans = max(ans, helper(i+1, mon - arr[i]*buy, stk+buy))
        else:
            break
        
        buy += 1
    
    for s in range(1, stk+1):
        ans = max(ans, helper(i+1, mon+arr[i]*s, stk-s))
    
    mem[key] = ans
    return ans

    
print(helper(0, 1000, 0))

### FIXED CODE ###

n= int(input())
arr = [int(x) for x in input().strip().split()]


def Greedy(arr):
    
    curr = 1000
    for i in range(len(arr)-1):
        if arr[i+1]>arr[i]:
            stocks = curr // arr[i]
            curr += (arr[i+1] - arr[i])*stocks
    return curr

print(Greedy(arr))

        
# mem = {}
# def helper(i, mon, stk):
#     key = (i, mon, stk)
#     if key in mem:
#         return mem[key]
    
#     if i==len(arr):
#         return mon
    
#     ans = helper(i+1, mon, stk)
#     buy = 1
#     while True:
#         if arr[i]*buy<=mon:
#             ans = max(ans, helper(i+1, mon - arr[i]*buy, stk+buy))
#         else:
#             break
        
#         buy += 1
    
#     for s in range(1, stk+1):
#         ans = max(ans, helper(i+1, mon+arr[i]*s, stk-s))
    
#     mem[key] = ans
#     return ans

    
# print(helper(0, 1000, 0))
### BUGGY CODE ###

#D
import numpy as np

N, K = map(int, input().split())
P = list(map(int, input().split()))
P = np.array(P)
ans = 0

for i in range(0, N-K+1):
    sum_P = np.sum(P[i:i+K])
    ans = max(ans, K+0.5*(sum_P-K))
    
print(ans)

### FIXED CODE ###

#D
N, K = map(int, input().split())
P = list(map(int, input().split()))
ans = sum(P[0:K])
sum_P = ans

for i in range(1, N-K+1):
    sum_P = sum_P - P[i-1] + P[i+K-1]
    ans = max(ans, sum_P)
#     ans = max(ans, K+0.5*(sum_P-K))
    
print(K+0.5*(ans-K))
### BUGGY CODE ###

import sys
h,w=map(int,input().split())
cmap=[input() for _ in range(h)]

whitesum=0
for each in cmap:
    whitesum += each.count(".")

def nextpoint(y,x):
    global cmap
    tmp=[]
    returnlist=[]
    cmap[y]=cmap[y][:x] + "#" + cmap[y][x+1:]

    if y == 0:
        tmp.append([y+1,x])
    elif y == h-1:
        tmp.append([y-1,x])
    else:
        tmp.extend([[y-1,x],[y+1,x]])

    if x == 0:
        tmp.append([y,x+1])
    elif x == w-1:
        tmp.append([y,x-1])
    else:
        tmp.extend([[y,x+1],[y,x-1]])

    for l in tmp:
        if cmap[l[0]][l[1]] == ".":
            returnlist.append(l)

    return returnlist

start=[0,0]
seen=[start]
todo=[]
todo.extend(nextpoint(start[0],start[1]))

i=2

while todo != []:
    nextlist=[]

    for nep in todo:
        if nep == [h-1,w-1]:
            print(whitesum-i)
            sys.exit()
        else:
            nextlist.extend(nextpoint(nep[0],nep[1]))
    todo=[]
    todo.extend(nextlist)

    i += 1

print("-1")



### FIXED CODE ###

import sys
h,w=map(int,input().split())
cmap=[input() for _ in range(h)]

whitesum=0
for each in cmap:
    whitesum += each.count(".")

def nextpoint(y,x):
    global cmap
    tmp=[]
    returnlist=[]
    cmap[y]=cmap[y][:x] + "#" + cmap[y][x+1:]

    if y == 0:
        tmp.append([y+1,x])
    elif y == h-1:
        tmp.append([y-1,x])
    else:
        tmp.extend([[y-1,x],[y+1,x]])

    if x == 0:
        tmp.append([y,x+1])
    elif x == w-1:
        tmp.append([y,x-1])
    else:
        tmp.extend([[y,x+1],[y,x-1]])

    for l in tmp:
        if cmap[l[0]][l[1]] == ".":
            cmap[l[0]]=cmap[l[0]][:l[1]] + "#" + cmap[l[0]][l[1]+1:]
            returnlist.append(l)

    return returnlist

start=[0,0]
seen=[start]
todo=[]
todo.extend(nextpoint(start[0],start[1]))

i=2
finishflag=True

while finishflag:
    nextlist=[]

    for nep in todo:
        if nep == [h-1,w-1]:
            print(whitesum-i)
            sys.exit()
        else:
            nextlist.extend(nextpoint(nep[0],nep[1]))
    todo=[]
    todo.extend(nextlist)

    if todo == []:
        finishflag = False

    i += 1

print("-1")
### BUGGY CODE ###

def main():
    n = int(input())
    As = [int(input()) for _ in range(n)]

    move = []
    i = 0
    ans = 1
    while As[i] != 2:
        if As[i] not in move:
            move.append(As[i])
            ans += 1
            i = As[i]-1
        else:
            ans = -1
            break
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n = int(input())
    As = [int(input()) for _ in range(n)]

    x = [0]*n
    i = 0
    ans = 0
    while x[i] == 0:
        ans += 1
        x[i] = 1
        i = As[i] - 1
        if i == 1:
            print(ans)
            exit()
    print(-1)


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

n,m=map(int,input().split())
# a=sorted(a)
c=abs(n-m)
while True:
    n=abs(n-m)
    if n<=c:
        c=n
    else:
        break
print(c)

### FIXED CODE ###

n,m=map(int,input().split())
# a=sorted(a)
l=[]
c=abs(n-m)
if n%m==0:
    c=0
    print(c)
else:
    c=n%m
    d=abs(m-c)
    l.append(c)
    l.append(d)
    l=sorted(l)
    print(l[0])
### BUGGY CODE ###

n,m = map(int, input().split())
dp = [float("inf")]*(2**n)
dp[0] = 0
for M in range(m):
    a,b = map(int, input().split())
    C = list(map(int, input().split()))

    state = 0
    for c in C:
        state += 2**(c-1)

    for i in range(2**n):
        if dp[i] != float("inf"):
            dp[i|state] = min(dp[i]+a,dp[i|state])

if dp[-1]==float("inf"):
    print(-1)
else:
    print(dp[-1])


### FIXED CODE ###

import sys

def main():
    input = sys.stdin.readline
    N,M = map(int,input().split())
    full = 2**N
    dp = [float("inf")]*full
    dp[0] = 0


    for m in range(M):
        a,b = map(int, input().split())
        C = list(map(int, input().split()))
        #鍵mで開く宝箱を二進法で表記
        state = 0
        for c in C:
            state += 2**(c-1)

        #状態iに対して鍵mを使い、状態i|stateにいく場合と、元から入っている場合の大小を比較
        #状態i|state即ち状態iに対して鍵mを使った後の状態
        for i in range(full):
            if dp[i] != float("inf"):
                dp[i|state] = min(dp[i]+a,dp[i|state])

    if dp[-1]==float("inf"):
    #dp[-1]はdp[full-1]でも同じ
        return -1

    return dp[-1]

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

MOD = 10**9 + 7
S = input()
res = 0
dpn = 1
dp0 = 0 # a
dp1 = 0 # ab

for c in S:
    if c == 'A':
        dp0 += dpn
    elif c == 'B':
        dp1 += dp0
    elif c == 'C':
        res += dp1
    else:
        dp0,dp1,res = dp0*3+dpn,dp1*3+dp0,res*3+dp1
        dpn *= 3

    dp1 %= MOD
    res %= MOD
print(res)


### FIXED CODE ###

MOD = 10**9 + 7
S = input()
res = 0
dpn = 1
dp0 = 0 # a
dp1 = 0 # ab

for c in S:
    if c == 'A':
        dp0 += dpn
    elif c == 'B':
        dp1 += dp0
    elif c == 'C':
        res += dp1
    else:
        dp0,dp1,res = dp0*3+dpn,dp1*3+dp0,res*3+dp1
        dpn *= 3
    dpn %= MOD
    dp0 %= MOD
    dp1 %= MOD
    res %= MOD
print(res)
### BUGGY CODE ###

h,w = map(int, input().split())
l = [None]*h
for i in range(h):
    l[i] = list(input())

from collections import deque
def solve():
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    ans=0
    while True:
        Q = deque()
        cnt=0
        for y in range(h):
            for x in range(w):
                if l[y][x] == "#":
                    Q.append([x,y])
                    cnt+=1
        if cnt >= h*w:
            return ans

        ans+=1
        while Q:
            p = Q.popleft()
            for i in range(4):
                nx = p[0] + dx[i]
                ny = p[1] + dy[i]

                if 0 <= nx < w and 0 <= ny < h:
                    if l[ny][nx]==".":
                        l[ny][nx] = "#"

print(solve())

### FIXED CODE ###

h,w = map(int, input().split())
l = [None]*h
for i in range(h):
    l[i] = list(input())

from collections import deque
def solve():
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    Q = deque()

    cnt=h*w
    for x in range(w):
        for y in range(h):
            if l[y][x]=="#":
                cnt-=1
                Q.append([x,y])
    if cnt==0:
        return 0

    ans=0
    while True:
        nxtQ = deque()

        ans+=1
        while Q:
            p = Q.popleft()
            for i in range(4):
                nx = p[0] + dx[i]
                ny = p[1] + dy[i]

                if 0 <= nx < w and 0 <= ny < h:
                    if l[ny][nx]==".":
                        l[ny][nx] = "#"
                        nxtQ.append([nx,ny])
                        cnt-=1
        Q=nxtQ
        if cnt<=0:
            return ans

print(solve())
### BUGGY CODE ###

from collections import defaultdict
n,W=list(map(int,input().split()))
li=[]
wr=[0]*n
vr=[0]*n
dd=defaultdict(lambda:0)
for i in range(n):
	w,v=map(int,input().split())
	wr[i]=w
	vr[i]=v
mw=min(wr)
def maxv(i,w):
	if dd[(i,w)]!=0:
		return dd[(i,w)]
	if i==n:
		return 0
	if W-w<mw:
		return 0
	if w+wr[i]>W:
		m=maxv(i+1,w)
		dd[(i,w)]=m
		return m
	a=vr[i]+maxv(i+1,w+wr[i])
	b=maxv(i+1,w)
	c=max(a,b)
	dd[(i,w)]=c
	return c
print(maxv(0,0))



### FIXED CODE ###

n,W=map(int,input().split())
dp=[0]*(W+1)
dd=dp.copy()
for i in range(n):
	w,v=map(int,input().split())
	for j in range(W):
		cw=j+w
		cv=dp[j]+v
		if cw <=W and dd[cw]<cv:
			dd[cw]=cv
	dp=dd.copy()
print(dp[W])
### BUGGY CODE ###

n = int(input())
s = list(input())
pin_li = []
for i in range(len(s)):
    if len(set(pin_li)) >1000:
        break
    for j in range(i+1,len(s)):
        for k in range(j+1,len(s)):
            pin_li.append(s[i]+s[j]+s[k])
            if len(set(pin_li)) > 1000:
                break
print(len(set(pin_li)))

### FIXED CODE ###

n = int(input())
s = input()
cnt = 0
for i in range(1000):
    p = '{:03}'.format(i)
    s2 = s
    for j in range(3):#indexのループ
        if s2.find(p[j]) == -1:
            break
        s2 = s2[s2.find(p[j]) +1:]
    else:
        cnt+=1
print(cnt)
### BUGGY CODE ###

# D - Binomial Coefficients

import bisect, math

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

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    
idx = bisect.bisect_left(a, a[-1]//2)

try:
    if a[-1] != a[idx]:
        tmp = comb(a[-1], a[idx])
        ans = [a[-1], a[idx]]
    else:
        tmp = 0
    if tmp < comb(a[-1], a[idx-1]) and a[-1] != a[idx-1]:
        tmp = comb(a[-1], a[idx-1])
        ans = [a[-1], a[idx-1]]
    if tmp < comb(a[-1], a[idx+1]) and a[-1] != a[idx+1]:
        ans = [a[-1], a[idx+1]]
except IndexError:
    pass

print(*ans)

### FIXED CODE ###

# D - Binomial Coefficients

import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
    
idx = bisect.bisect_left(a, a[-1]//2)
tmp = float("inf")

try:
    if idx != n-1:
        tmp = abs(a[idx]-a[-1]/2)
        ans = [a[-1], a[idx]]
    if abs(a[idx-1] - a[-1]/2) < tmp:
        tmp = abs(a[idx-1] - a[-1]/2)
        ans = [a[-1], a[idx-1]]
    if abs(a[idx+1] - a[-1]/2) < tmp and idx+1 != n-1:
        ans = [a[-1], a[idx+1]]
except IndexError:
    pass

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

a=0
for i in range(10**13):
  a+=1
print(0)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)
total=0
def bfs(ind,num):
    kouho=friends[ind]
    
    for i in kouho:
        if sans[i]!=-1:
            continue
        num+=1
        sans[i]=sans[ind]
        l[sans[ind]].add(i)
        num+=bfs(i,0)
    return num
n,m,k=list(map(int,input().split()))
f=[list(map(int,input().split())) for _ in range(m)]
friends=[set() for _ in range(n)]
friends_num=list(map(lambda x:len(x),friends))
bl=[list(map(int,input().split())) for _ in range(k)]
l=[{i} for i in range(n)]

for each in f:
    a,b=each
    friends[a-1].add(b-1)
    friends[b-1].add(a-1)

block=[set() for _ in range(n)]
for each in bl:
    a,b=each
    block[a-1].add(b-1)
    block[b-1].add(a-1)

sans=[-1 for _ in range(n)]
sans[0]=0
total=bfs(0,total)
for i in range(n):
    if sans[i]!=-1:
        continue
    sans[i]=i
    total=bfs(i,total)
ans=[0 for _ in range(n)]


for i in range(n):
    l[i]=set(l[i])


for i in range(n):
    tmp=l[sans[i]]
    ans[i]+=len(tmp)-len(friends[i])-1
    for j in block[i]:
        if sans[i]==sans[j]:
            ans[j]-=1

ans=" ".join(map(str,ans))
#print("total:",total)
print(ans)
### BUGGY CODE ###

N, W = map(int, raw_input().split())
dp = [0]*(W+1)
 
for i in xrange(N):
    w, v = map(int, raw_input().split())
    for j in xrange(W, w-1, -1):
        x = dp[j-w] + v
        if x > dp[j]:
            dp[j] = x
 
print dp[-1]

### FIXED CODE ###

def main():

    N, W = map(int, raw_input().split())
    dp = [0]*(W+1)
 
    for i in xrange(N):
        w, v = map(int, raw_input().split())
        for j in xrange(W, w-1, -1):
            x = dp[j-w] + v
            if x > dp[j]:
                dp[j] = x
 
    print dp[-1]

main()
### BUGGY CODE ###

#!/usr/bin/env python3

x = int(input())

ok = False

def dfs(n, flg):
    global ok
    if flg:
        return 
    if n == x:
        ok = True
        return
    if n > x:
        ok = False
        return
    dfs(n+100, ok) 
    dfs(n+101, ok) 
    dfs(n+102, ok) 
    dfs(n+103, ok) 
    dfs(n+104, ok) 
    dfs(n+105, ok) 

dfs(0, False)
if ok: print(1)
else: print(0)


### FIXED CODE ###

#!/usr/bin/env python

x = int(input())

n = x//100

for i in range(n+1):
    tmp = x 
    tmp -= i*100
    if 5*i >= tmp:
        print(1)
        exit()
print(0)
### BUGGY CODE ###

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

l = [0]*(N+10)
for i in range(1, N):
    l[i] = min(l[j]+abs(H[i]-H[j]) for j in range(max(0, i-K), i))

print(l[N-1])

### FIXED CODE ###

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

costs = [0]*(N+10)
for i in range(1, N):
    j = max(0, i-K)
    h_i = H[i]
    costs[i] = min(cost+abs(h_i-h) for cost, h in zip(costs[j:i], H[j:i]))

print(costs[N-1])
### BUGGY CODE ###

N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*N
dp[0]=0
for n in range(1,N):
    dp[n]=dp[n-1]+abs(h[n-1]-h[n])
    if N-K>=0 and n-K>=0:
        for i in range(n-K,n):
            if dp[n]>=dp[i]+abs(h[i]-h[n]):
                dp[n]=dp[i]+abs(h[i]-h[n])
    elif N-K>=0 and n-K<0:
        for i in range(0,n):
            if dp[n]>=dp[i]+abs(h[i]-h[n]):
                dp[n]=dp[i]+abs(h[i]-h[n])
    else:
        for i in range(0,n):
            if dp[n]>=dp[i]+abs(h[i]-h[n]):
                dp[n]=dp[i]+abs(h[i]-h[n])
print(dp[N-1])

### FIXED CODE ###

N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*N
dp[0]=0
for n in range(1,N):
    dp[n]=dp[n-1]+abs(h[n-1]+h[n])
    for i in range(max(0,n-K),n):
            dp[n]=min(dp[n],dp[i]+abs(h[n]-h[i]))
print(dp[N-1])
### BUGGY CODE ###

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

for i in range(n):
    m*=a[i]

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



### FIXED CODE ###

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

if 0 in a:
    print(0)
else:
    m=1
    for i in a:
        m*=i
        if 10**18 < m:
            print(-1)
            break
    else:
        print(m)
### BUGGY CODE ###

s = list(input())
q = int(input())
rev = 0
revcnt = 0
for _ in range(q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        revcnt += 1
        if rev == 0:
            rev = 1
        elif rev == 1:
            rev = 0

    elif query[0] == "2":
        if rev == 0:
            if query[1] == "1":
                s = s[::-1]
                s.append(query[2])
                s = s[::-1]
            elif query[1] == "2":
                s.append(query[2])
        else:
            if query[1] == "1":
                s.append(query[2])
            elif query[1] == "2":
                s = s[::-1]
                s.append(query[2])
                s = s[::-1]

if revcnt%2 == 0:
    print("".join(s))
else:
    print("".join(s[::-1]))

### FIXED CODE ###

from collections import deque
s = list(input())
q = int(input())
rev = 0
revcnt = 0
s_q = deque(s)
for _ in range(q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        revcnt += 1
        if rev == 0:
            rev = 1
        elif rev == 1:
            rev = 0

    elif query[0] == "2":
        if rev == 0:
            if query[1] == "1":
                s_q.appendleft(query[2])
            elif query[1] == "2":
                s_q.append(query[2])
        else:
            if query[1] == "1":
                s_q.append(query[2])
            elif query[1] == "2":
                s_q.appendleft(query[2])
s = list(s_q)
if revcnt%2 == 0:
    print("".join(s))
else:
    print("".join(s[::-1]))