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

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

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

for i in range(m):
  prices.sort()
  prices[n-1] = prices[n-1] // 2
  
print(sum(prices))
	

    

### FIXED CODE ###

import heapq

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

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

q = []

for a in A:
    heapq.heappush(q, -a)

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

print(-sum(q))
### BUGGY CODE ###

from collections import Counter
n=int(input())
s=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
ss=Counter(s)
tt=Counter(t)
s1=list(ss.keys())
s2=list(ss.values())
for i,j in tt.items():
    if i not in s:
        print("NO")
        exit()
    if s2[s1.index(i)]<j:
        print("NO")
        exit()
print("YES")

### FIXED CODE ###

from collections import Counter
input()
s=list(input().split())
s=Counter(s)
input()
for i in input().split():
    if s.get(i,0)==0:
        print("NO")
        break
    else:
        s[i]-=1
else:
    print("YES")
### BUGGY CODE ###

import math
A, B = map(int, input().split())
ans = 1


def cf(x1,x2):
    cf=[]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf


def is_prime(n):
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return 0
    return 1


for i in cf(A, B):
    ans += is_prime(i)

print(ans)

### FIXED CODE ###

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


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


a = set(prime_decomposition(A))
b = set(prime_decomposition(B))

print(len(a & b) + 1)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
print(sum(A[i] > A[j] for i in range(N - 1) for j in range(i + 1, N)))


### FIXED CODE ###

INF = float("inf")
cnt = 0
def merge(A, left, mid, right):
    global cnt
    L = A[left: mid] + [INF]
    R = A[mid: right] + [INF]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            cnt += j
            i += 1
        else:
            A[k] = R[j]
            j += 1
def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)
n = int(input())
S = list(map(int, input().split()))
mergeSort(S, 0, n)
print(cnt)
### BUGGY CODE ###

n,r = map(int,input().split())
i = 0
while n > 0:
    n / r
    i += 1
print(i)

### FIXED CODE ###

n,k=map(int,input().split())
count=0
while n !=0:
    n //= k
    count += 1
print(count)
### BUGGY CODE ###

import collections

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

s_count_list = [collections.Counter(S) for S in s]

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if s_count_list[i] == s_count_list[j]:
            ans += 1
            
print(ans)

### FIXED CODE ###

import collections
import sys

N = int(input())
s = [sorted(collections.Counter(sys.stdin.readline().rstrip()).items()) for _ in range(N)]

counted = {}
for s_count in s:
    if str(s_count) not in counted:
        counted[str(s_count)] = 1
    else:
        counted[str(s_count)] += 1


count = 0        
for n in counted.values():
    count += n * (n - 1) // 2
            
print(count)
### BUGGY CODE ###

def main():
    l = []
    N, K = map(int, input().split())
    for i in range(N):
        a, b = map(int, input().split())
        l.extend([a for j in range(b)])

    l = sorted(l)
    print(l[K-1])

main()

### FIXED CODE ###

def main():
    l = []
    N, K = map(int, input().split())
    d_num = {i: 0 for i in range(100002)}
    for i in range(N):
        a, b = map(int, input().split())
        d_num[a] = d_num[a] + b

    for i in range(100002):
        K = K - d_num[i+1]

        if K <= 0:
            break

    print(i+1)

main()
### BUGGY CODE ###

import sys
from itertools import accumulate

input = lambda: sys.stdin.readline().rstrip()
n, m, k = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [0] + a
b = [0] + b
# 累積和を利用
a_accum = list(accumulate(a))
b_accum = list(accumulate(b))

ans = 0
for i in range(len(a_accum)):
    for j in range(len(b_accum)):
        if (a_accum[i] + b_accum[j] <= k):
            ans = max(ans, i + j)
        else:
            break
print(ans)


### FIXED CODE ###

import sys
from itertools import accumulate
import bisect

input = lambda: sys.stdin.readline().rstrip()
n, m, k = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [0] + a
b = [0] + b
# 累積和を利用
a_accum = list(accumulate(a))
b_accum = list(accumulate(b))

# print(a_accum, b_accum)

ans = 0
for i in range(len(a_accum)):
    nokori = k - a_accum[i]
    if nokori < 0:
        break
    # にぶたん
    b_pos = bisect.bisect(b_accum, nokori) - 1
    ans = max(ans, i + b_pos)
    # print(nokori,ans,b_pos)
print(ans)
### BUGGY CODE ###

N,M = map(int, input().split())
L = [list(map(int,input().split())) for _ in range(M)]
L.sort(key=lambda x: x[0])
funes1 = []
for a,b in L:
    if a == 1:
        funes1.append(b)
    else:
        if a in funes1:
            if b == N:
                print('POSSIBLE')
                exit()
print('IMPOSSIBLE')

### FIXED CODE ###

N,M = map(int, input().split())
L = [list(map(int,input().split())) for _ in range(M)]
L.sort(key=lambda x: x[0])
funes1 = [False]*N
for a,b in L:
    if a == 1:
        funes1[b] = True
    else:
        if funes1[a]:
            if b == N:
                print('POSSIBLE')
                exit()
print('IMPOSSIBLE')
### BUGGY CODE ###


def c():
    n = int(input())
    s = ['']*n
    for i in range(n):
        temp = input()
        if temp not in s:
            s[i]  = temp
    print(n - s.count(''))

def b():
    a,b,c,d = map(int, input().split())
    while True:
        c -= b
        if c <= 0:
            print('Yes')
            break
        a -= d
        if a <= 0:
            print('No')
            break

def a():
    s, w = map(int, input().split())
    if w >= s:
        print('unsafe')
    else:
        print('safe')



c()

### FIXED CODE ###


def c():
    n = int(input())
    s = ['']*n
    for i in range(n):
        s[i] = input()
    s.sort()
    count = 1
    for i in range(1, n):
        if s[i - 1] != s[i]:
            count += 1
    print(count)

def b():
    a,b,c,d = map(int, input().split())
    while True:
        c -= b
        if c <= 0:
            print('Yes')
            break
        a -= d
        if a <= 0:
            print('No')
            break

def a():
    s, w = map(int, input().split())
    if w >= s:
        print('unsafe')
    else:
        print('safe')



c()
### BUGGY CODE ###

n=int(input())
ta=[list(map(int,input().split())) for _ in range(n)]
ans=ta[0]
for i in range(1,n):
  if (ta[i-1][0]<ta[i][0]) and (ta[i-1][1]<ta[i][1]):
    pass
  else:
    r=ta[i][0]
    l=ta[i][1]
    while (ta[i-1][0]>ta[i][0]) or (ta[i-1][1]>ta[i][1]):
      ta[i][0]+=r
      ta[i][1]+=l
print(sum(ta[-1]))

### FIXED CODE ###

n=int(input())
ta=[list(map(int,input().split())) for _ in range(n)]
ans=ta[0]
for i in range(1,n):
  if (ta[i-1][0]<=ta[i][0]) and (ta[i-1][1]<=ta[i][1]):
    pass
  else:
    l=ta[i-1][0]//ta[i][0]
    if ta[i-1][0]%ta[i][0]!=0:
      l+=1
    r=ta[i-1][1]//ta[i][1]
    if ta[i-1][1]%ta[i][1]!=0:
      r+=1
    ta[i][0]*=max(l,r)
    ta[i][1]*=max(l,r)
print(sum(ta[-1]))
### BUGGY CODE ###

from heapq import heapify, heappop, heappush
from sys import stdin

N, M = map(int, input().split())
A = list(map(int, stdin.readline().split()))
heapify(A)

for i in range(M):
    B, C = map(int, stdin.readline().split())
    for i in range(B):
        if C <= A[0]:
            break
        heappop(A)
        heappush(A, C)

print(sum(A))


### FIXED CODE ###

from heapq import heapify, heappop, heappush
from sys import stdin

N, M = map(int, input().split())
A = list(map(int, stdin.readline().split()))
heapify(A)
BC = [None] * M
for i in range(M):
    BC[i] = tuple(map(int, stdin.readline().split()))
BC = sorted(BC, key=lambda x: x[1], reverse=True)

enough = False
for bc in BC:
    if enough:
        break
    for i in range(bc[0]):
        if bc[1] <= A[0]:
            enough = True
            break
        heappop(A)
        heappush(A, bc[1])

print(sum(A))
### BUGGY CODE ###

#!/usr/bin/env python3
 
import sys
# 以下を記述しないとTLEになる, 何故？
#from heapq import heappush, heappop,heappushpop
from collections import defaultdict
# ---- ここまで -----------------------
 
S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        sys.exit()
 
ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1
 
print(ans)

### FIXED CODE ###

import bisect
s = input().rstrip()
t = input().rstrip()

a_ord = ord("a")
ch_place = [[] for _ in range(26)]
for i, ch in enumerate(s):
    ch_place[ord(ch) - a_ord].append(i)

# print(ch_place)

count = 0
idx = -1 
for ch in t:
    ch_num = ord(ch) - a_ord
    if len(ch_place[ch_num]) == 0:
        print(-1)
        exit()
    place = bisect.bisect_right(ch_place[ch_num], idx)
    # print(ch_place[ch_num], idx, place)
    if place == len(ch_place[ch_num]):
        idx = ch_place[ch_num][0]
        count += 1
    else:
        idx = ch_place[ch_num][place]

# print(count, idx)
print(count * len(s) + idx + 1)
### BUGGY CODE ###

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

for i in range(len(A)):
    A[i] = (A[i]+1)/2

L = [0]*(N[0]-N[1]+1)

for i in range(N[0]-N[1]+1):
    for j in range(N[1]):
        L [i] += A[i+j]
print(max(L))

### FIXED CODE ###

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

L = 0
for i in range(K):
    L += A[i]

ans = L

for i in range(N-K):
    L  = L+A[K+i]-A[i]
    ans = max(ans, L)
ans += K
ans /= 2
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

from fractions import gcd


MOD = 10**9+7
N = int(input())
F = []
zero_v = 0
inf = 0
zero = 0
for _ in range(N):
  x,y = map(int,input().split())
  if x==0 and y==0:
    zero_v += 1
  elif x==0:
    inf += 1
  elif y==0:
    zero += 1
  else:
    G = gcd(abs(x),abs(y))
    F.append((x//G,y//G))

setF = set(F)

all_keys = set()

for x,y in setF:
  if x*y >0:
    if x>0:
      all_keys.add((x,y))
    else:
      all_keys.add((-x,-y))
  x,y = -y,x
  if x*y >0:
    if x>0:
      all_keys.add((x,y))
    else:
      all_keys.add((-x,-y))

all_dic = {k:[0,0] for k in all_keys}

for x,y in F:
  if x*y > 0:
    if x>0:
      all_dic[(x,y)][0] += 1
    else:
      all_dic[(-x,-y)][0] += 1
  else:
    if x>0:
      all_dic[(-y,x)][1] += 1
    else:
      all_dic[(y,-x)][1] += 1

ans = (pow(2,inf,MOD)) + (pow(2,zero,MOD))-1
ans %= MOD

for k in all_keys:
  P,N = all_dic[k]
  ans *= (pow(2,P,MOD)) + (pow(2,N,MOD))-1
  ans %= MOD


ans += zero_v-1

print(ans%MOD)

### FIXED CODE ###

import sys
input = sys.stdin.readline

def gcd(a, b):
  while b:
    a, b = b, a % b
  return a

MOD = 10**9+7
N = int(input())
F = []
zero_v = 0
inf = 0
zero = 0
for _ in range(N):
  x,y = map(int,input().split())
  if x==0 and y==0:
    zero_v += 1
  elif x==0:
    inf += 1
  elif y==0:
    zero += 1
  else:
    G = gcd(abs(x),abs(y))
    F.append((x//G,y//G))

all_keys = set()

for x,y in F:
  if x*y >0:
    if x>0:
      all_keys.add((x,y))
    else:
      all_keys.add((-x,-y))
  x,y = -y,x
  if x*y >0:
    if x>0:
      all_keys.add((x,y))
    else:
      all_keys.add((-x,-y))

all_dic = {k:[0,0] for k in all_keys}

for x,y in F:
  if x*y > 0:
    if x>0:
      all_dic[(x,y)][0] += 1
    else:
      all_dic[(-x,-y)][0] += 1
  else:
    if x>0:
      all_dic[(-y,x)][1] += 1
    else:
      all_dic[(y,-x)][1] += 1

ans = (pow(2,inf,MOD)) + (pow(2,zero,MOD))-1
ans %= MOD

for k in all_keys:
  P,N = all_dic[k]
  ans *= (pow(2,P,MOD)) + (pow(2,N,MOD))-1
  ans %= MOD


ans += zero_v-1

print(ans%MOD)
### BUGGY CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve(ins):
    n, k, *h = map(int, ins.split())
    costs = [0]
    for i in range(1, n):
        cost = min([costs[-j] + abs(h[i] - h[i - j]) for j in range(1, min(i, k) + 1)])
        costs.append(cost)
    return costs[-1]


if __name__ == "__main__":
    print(solve("\n".join([input(), input()])))


### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve(ins):
    n, k, *h = map(int, ins.split())
    costs = [0]
    for i in range(1, n):
        cost = min([costs[-j] + abs(h[i] - h[i - j]) for j in range(1, min(i, k) + 1)])
        costs.append(cost)
    return costs[-1]


if __name__ == "__main__":
    print(solve("\n".join([input(), input()])))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

N,M=map(int, sys.stdin.readline().split())

nl=[ [] for i in range(N+1) ] 
f=[ 0 for i in range(N+1) ]
dp=[ 0 for i in range(N+1) ]

for i in range(M):
	x,y=map(int, sys.stdin.readline().split())
	nl[x].append(y)
	f[y]=1

start=[]
for i in range(1,N+1):
	if f[i]==0:
		start.append(i)


def dfs(v):
	for u in nl[v]:
		dp[u]=max( dp[u], dp[v]+1)
		dfs(u)


for s in start:
	dfs(s)

print max(dp)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

N,M=map(int, sys.stdin.readline().split())

nl=[ [] for i in range(N+1) ] 

for i in range(M):
	x,y=map(int, raw_input().split())
	nl[x].append(y)


memo={}

def depth(n):
	if n in memo: return memo[n]
	ret=0
	if len( nl[n] )==0:
		return 0
	else:
		for x in nl[n]:
			ret=max(ret, depth(x)+1)
	memo[n]=ret
	return ret


ans=0
for i in range(1,N+1):
	ans=max( ans , depth(i) )

print ans
### BUGGY CODE ###

N,A,B=map(int,input().split())
ans,i=0,0
for i in range(N):
    if (i+1)%(A+B)<=A and (i+1)%(A+B)!=0:
        ans+=1
print(ans)

### FIXED CODE ###

N,A,B=map(int,input().split())
t=N//(A+B)
ans=(t*A)+(min((N%(A+B)),A))
print(ans)
### BUGGY CODE ###

from collections import Counter 
n = int(input())
a = sorted(list(map(int, input().split())))
s = sorted(set(a))
c = Counter(a)
bool = [True] * (10**6 + 1)
for i in a:
    if c[i] > 1 :
        bool[i] = False 
    for j in range(i*2, 10**6+1, i):
        bool[j] = False 
print(sum(1 for i in a if bool[i]))



### FIXED CODE ###

from collections import Counter 
n = int(input())
a = list(map(int, input().split()))
s = set(a)
c = Counter(a)
t = [0] * (10**6 + 1)
for i in s:
    for j in range(i, 10**6+1, i):
        t[j] += 1

ans = len([1 for i in s if t[i] == 1 and c[i] == 1])
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
P = list(map(int, input().split()))

D = dict.fromkeys(P, 0)
for key in D.keys():
    D[key] = sum([j for j in range(1, key + 1)]) / key

ans = 0.0
for i in range(0, n - k + 1):
    tmp = sum(D[t] for t in P[i: i + k])
    ans = max(tmp, ans)
    
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
P = list(map(int, input().split()))

C = [(1 + p) / 2 for p in P]

ans = tmp = sum(C[: k])
for i in range(k, n):
    tmp += (C[i] - C[i - k])
    ans = max(tmp, ans)

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

n = int(input())
a = list(map(int,input().split()))
flag = 1
count = 0
while flag:
    flag = 0
    for i in range(n-1):
        if a[i] > a[i+1]:
            a[i], a[i+1] = a[i+1], a[i]
            count += 1
            flag = 1

print(count)

### FIXED CODE ###

n = int(input())
s = list(map(int,input().split()))
count = 0

def merge(a, left, mid, right):
    global count
    l = a[left:mid] + [float("inf")]
    r = a[mid:right] + [float("inf")]
    i = j = 0
    for k in range(left, right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1
            count += len(l) - i - 1

def mergeSort(a, left, right):
    if left + 1 < right:
        mid = right + (left - right)//2
        mergeSort(a, left, mid)
        mergeSort(a, mid, right)
        merge(a, left, mid, right)

mergeSort(s, 0, n)

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

import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


r,g,b,n=l()
ans=0
r,g,b=sorted([r,g,b])
for i in range(n//r+1):
    for j in range(n//g+1):
        k=n-i*r-j*g
        if(k<0):
            break
        if(k>=0 and k%b==0):
            ans+=1
print(ans)

### FIXED CODE ###


r,g,b,n=map(int,input().split())
ans=0
r,g,b=sorted([r,g,b])[::-1]
for i in range(n//r+1):
    for j in range(n//g+1):
        k=n-i*r-j*g
        if(k<0):
            break
        if(k>=0 and k%b==0):
            ans+=1
print(ans)
### BUGGY CODE ###

N,W=map(int,input().split())
w=[]
v=[]
for i in range(N):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
    
dp=[[-1]*(W+1) for i in range(N+1)]
for i in range(W+1):
    dp[0][i]=0
for i in range(N):
    for j in range(W+1):
        if j-w[i]<0:
            dp[i+1][j]=dp[i][j]
        else:
            dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i])
print(dp[N][W])

### FIXED CODE ###

import numpy as np

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

dp = np.zeros(W+1, dtype=np.int64)

for _ in range(N):
  w,v = map(int,input().split())
  np.maximum(dp[:-w]+v,dp[w:], out=dp[w:])

print(dp[-1])
### BUGGY CODE ###

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

class SegTree:
    def __init__(self, init_val, f=lambda x,y : x*y, default=1):
        size = len(init_val)
        self.size = 2**(size-1).bit_length()
        self.default = default
        self.dat = [default]*(self.size*2)
        self.f = f

        for i in range(size):
            self.dat[self.size + i] = init_val[i]
        for i in range(self.size- 1, 0, -1):
            self.dat[i] = self.f(self.dat[2 * i], self.dat[2 * i + 1])

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres)
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res

seg = SegTree(Ai)
# print(seg.query(0, 1))

def score(i):
    return seg.query(i - K, i)

for i in range(K + 1, N + 1):
    sp = score(i - 1)
    s = score(i)

    if sp < s:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

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

# class SegTree:
#     def __init__(self, init_val, f=lambda x,y : x*y, default=1):
#         size = len(init_val)
#         self.size = 2**(size-1).bit_length()
#         self.default = default
#         self.dat = [default]*(self.size*2)
#         self.f = f
#
#         for i in range(size):
#             self.dat[self.size + i] = init_val[i]
#         for i in range(self.size- 1, 0, -1):
#             self.dat[i] = self.f(self.dat[2 * i], self.dat[2 * i + 1])
#
#     def update(self, i, x):
#         i += self.size
#         self.dat[i] = x
#         while i > 0:
#             i >>= 1
#             self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])
#
#     def query(self, l, r):
#         l += self.size
#         r += self.size
#         lres, rres = self.default, self.default
#         while l < r:
#             if l & 1:
#                 lres = self.f(lres, self.dat[l])
#                 l += 1
#
#             if r & 1:
#                 r -= 1
#                 rres = self.f(self.dat[r], rres)
#             l >>= 1
#             r >>= 1
#         res = self.f(lres, rres)
#         return res
#
# seg = SegTree(Ai)
# print(seg.query(0, 1))

# def score(i):
#     return seg.query(i - K, i)

for i in range(K + 1, N + 1):
    # sp = score(i - 1)
    # s = score(i)

    sp = Ai[i - K - 1]
    s = Ai[i - 1]

    if sp < s:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

s=list(map(str,input()))
c=0
while "1" in s and "0" in s:
    for i in range(1,len(s)):
        if s[i-1] != s[i]:
            del s[i-1]
            del s[i-1]
            c+=2
            break
        else:
            pass
print(c)


### FIXED CODE ###

import collections
s=list(map(str,input()))
c=collections.Counter(s)
print(2*min(c["1"],c["0"]))
### BUGGY CODE ###

mod = 998244353
import sys
sys.setrecursionlimit(10**9)
S = input()
N = len(S)
Sum = [0]*(N+1)
for i in range(1, N+1):
    Sum[i] = Sum[i-1]+int(S[i-1])
memo = [[-1]*(N*2+1) for _ in range(N*2+1)]
def dp(i, j):
    if memo[i][j]>=0:
        return memo[i][j]
    n = min(i+j+1, N)
    if i+j == N*2:
        return 1
    res = 0
    s = Sum[n]
    if i<s:
        res+=dp(i+1, j)
    if j<2*n-s:
        res+=dp(i, j+1)
    memo[i][j] = res
    return res%mod
print(dp(0, 0))

### FIXED CODE ###

mod = 998244353
import sys
sys.setrecursionlimit(10**9)
S = input()
N = len(S)
Sum = [0]*(N+1)
for i in range(1, N+1):
    Sum[i] = Sum[i-1]+int(S[i-1])
dp = [[0]*(N*2+1) for _ in range(N*2+1)]
for i in range(N*2+1)[::-1]:
    for j in range(N*2+1)[::-1]:
        if i+j == N*2:
            dp[i][j] = 1
            continue
        n = min(i+j+1, N)
        s = Sum[n]
        if i<s:
            dp[i][j]+=dp[i+1][j]
        if 2*n-s>j:
            dp[i][j]+=dp[i][j+1]
        dp[i][j]%=mod
print(dp[0][0])
### BUGGY CODE ###

n, k = [int(elem) for elem in input().split()]
h = [int(elem) for elem in input().split()]

dp=[0]*n
for i in range(0, n):
  for j in range(1, k+1):
    if len(h) > (i+j):
      tmp = dp[i] + abs(h[i] - h[i+j])
      if dp[i+j] == 0:
        dp[i+j] = tmp
      else:
        if dp[i+j] > tmp:
          dp[i+j] = tmp
print(dp[-1])

### FIXED CODE ###

INF = 10**10
 
def main():
    n, k = map(int, input().split())
    hs = list(map(int, input().split()))
 
    dp = [INF]*n
    dp[0] = 0
 
    for i in range(1,n):
        from_ = max(i-k, 0)
        dp[i] = min(d + abs(hs[i]-h) for d, h in zip(dp[from_:i], hs[from_:i]))
    print(dp[-1])
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

u = []
for i in range(q):
    u.append(list(map(str,input().split())))

l = ''
r = ''

x = 1
for i in range(q):
    if int(u[i][0]) == 1:
        x = x*(-1)
    else:
        if int(u[i][1])*x == 1 or int(u[i][1])*x == -2:
            l += u[i][2]
        else:
            r += u[i][2]
if x == 1:
    print(l[::-1]+s[::x]+r)
else:
    print(r[::-1]+s[::x]+l)

### FIXED CODE ###

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

u = []
for i in range(q):
    u.append(list(map(str,input().split())))

from collections import deque
l = deque([])
r = deque([])

x = 1
for i in range(q):
    if int(u[i][0]) == 1:
        x = x*(-1)
    else:
        if int(u[i][1])*x == 1 or int(u[i][1])*x == -2:
            l.append(u[i][2])
        else:
            r.append(u[i][2])
if x == 1:
    print(''.join(l)[::-1]+s[::x]+''.join(r))
else:
    print(''.join(r)[::-1]+s[::x]+''.join(l))