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

A, B, N = list(map(int, input().split()))
max = 0
for x in range(N + 1):
    f = A * x // B - A * (x // B)
    if f > max:
        max = f
print(max)

### FIXED CODE ###

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

if N >= B:
    max = (A * (B - 1) ) // B
else:
    max = A * N // B
print(max)
### BUGGY CODE ###

import heapq
import sys

N, X, Y = map(int, input().split())
a = [[] for i in range(N)]
a[X - 1].append(Y - 1)
a[Y - 1].append(X - 1)
for i in range(N - 1):
	a[i].append(i + 1)
	a[i + 1].append(i)
ans = [0] * (N - 1)
for i in range(N - 1):
	b = [[0, i]]
	c = [False] * N
	d = [sys.maxsize] * N
	d[i] = 0
	while len(b):
		e = heapq.heappop(b)
		c[e[1]] = True
		for j in a[e[1]]:
			if c[j]:
				continue
			if e[0] + 1 < d[j]:
				d[j] = e[0] + 1
				heapq.heappush(b, [d[j], j])
	j = i + 1
	while j < N:
		ans[d[j] - 1] += 1
		j += 1
for i in ans:
	print(i)

### FIXED CODE ###

import heapq
import sys

N, X, Y = map(int, input().split())
a = [[] for i in range(N)]
a[X - 1].append(Y - 1)
a[Y - 1].append(X - 1)
for i in range(N - 1):
	a[i].append(i + 1)
	a[i + 1].append(i)
ans = [0] * (N - 1)
for i in range(N - 1):
	b = [[0, i]]
	c = [False] * N
	d = [sys.maxsize] * N
	d[i] = 0
	while len(b):
		e = heapq.heappop(b)
		c[e[1]] = True
		for j in a[e[1]]:
			if c[j]:
				continue
			if e[0] + 1 < d[j]:
				d[j] = e[0] + 1
				heapq.heappush(b, [d[j], j])
	j = i + 1
	while j < N:
		ans[d[j] - 1] += 1
		j += 1
for i in ans:
	print(i)
### BUGGY CODE ###

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
s = [list(map(str, input())) for i in range(n)]
count = 0
for i in range(n):
    s[i].sort()
for i in s:
    k = s.count(i)
    l = i
    if k == 1:
        s.remove(l)
    else:
        count += combinations_count(k, 2)
        for j in range(k):
            s.remove(s[s.index(l)])
print(count)

### FIXED CODE ###

from collections import Counter
n = int(input())
S = ["".join(sorted(input())) for i in range(n)]
s = Counter(S)


def calc(x):
    return x * (x-1) // 2


ans = 0
for i in s.values():
    ans += calc(i)
print(ans)
### BUGGY CODE ###

import sys
N=int(sys.stdin.readline())
L=list(map(int,sys.stdin.readline().split()))
C=list(set(L))
x=0
for i in range(len(C)):
  a = L.count(C[i])
  x += int(a*(a-1)/2)  
for K in range(N):
  print(x-L.count(L[K])+1)

### FIXED CODE ###

import sys
from collections import Counter
N=int(sys.stdin.readline())
L=list(map(int,sys.stdin.readline().split()))
C=Counter(L)
x=0
for a in C.values():
  x += int(a*(a-1)/2)  
for K in range(N):
  print(x-C[L[K]]+1)
### BUGGY CODE ###

import math
from sys import stdin,stdout
#% 998244353
from heapq import heapify,heappop,heappush
import collections

n,k=list(map(int,stdin.readline().split()))
a=list(map(int,stdin.readline().split()))


for i in range(k):
    #nw=[0]*n
    pr=[0]*n
    for x,d in enumerate(a):
        if d==0:
            pr[x]+=1
            if x!=n-1:
                pr[x+1]-=1
            continue
        l=math.floor(x-d)
        r=math.floor(x+d)
        l=max(0,l)
        r=min(n-1,r)
        pr[l]+=1
        if r!=n-1:
            pr[r+1]-=1
    
    for m in range(1,n):
        pr[m]+=pr[m-1]
    
    a[:]=pr


        

for i in a:
    print(i,end=" ")

### FIXED CODE ###

import math
from sys import stdin,stdout
#% 998244353
from heapq import heapify,heappop,heappush
import collections

n,k=list(map(int,stdin.readline().split()))
a=list(map(int,stdin.readline().split()))


for i in range(min(k,100)):
    #nw=[0]*n
    pr=[0]*n
    for x,d in enumerate(a):
        if d==0:
            pr[x]+=1
            if x!=n-1:
                pr[x+1]-=1
            continue
        l=math.floor(x-d)
        r=math.floor(x+d)
        l=max(0,l)
        r=min(n-1,r)
        pr[l]+=1
        if r!=n-1:
            pr[r+1]-=1
    
    for m in range(1,n):
        pr[m]+=pr[m-1]
    
    a[:]=pr


        

for i in a:
    print(i,end=" ")
### BUGGY CODE ###

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

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

### FIXED CODE ###

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

D={}
for i in range(N-1):
    if (A[i] in D.keys())==True:
        D[A[i]]+=1
    elif (A[i] in D.keys())==False:
        D[A[i]]=1
for i in range(1,N+1):
    try:
        print(D[i])
    except:
        print(0)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
flag = False
for i in range(n-1):
    for j in range (i+1,n):
        if a[i] == a[j]:
            flag = True
            break
print('YES' if flag == False else 'NO')

### FIXED CODE ###

import math

def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = {}
    for val in a:
        cnt[val] = cnt.get(val, 0) + 1
    distinct = True
    for val in cnt:
        if cnt[val] > 1:
            distinct = False
    if distinct:
        print("YES")
    else:
        print("NO")

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

import numpy as np
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    count=np.zeros(2019,dtype=int)
    ans=0
    count_t=np.zeros(2019,dtype=int)
    for i in range(len(s)):
        count_t[int(s[i])]+=1
        for k in range(2019):
            a=count[k]
            if a==0:
                continue
            else: 
                t=(k*10+int(s[i]))%2019
                count_t[k]-=a
                count_t[t]+=a
                if t==0:
                    ans+=a
        #print(count[0:20])
        #print(count_t[0:20])
        count=count+count_t
        count_t-=count_t
    print(ans)
                
if __name__ == '__main__':
    do()

### FIXED CODE ###

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    cnt=[0]*2019
    cnt[0]=1
    temp=0
    keta=1
    ans=0
    for i in s[::-1]:
        temp=(temp+int(i)*keta)%2019
        keta=(keta*10)%2019
        cnt[temp]+=1
    for i in cnt:
        ans+=(i*(i-1))//2
    print(ans)
    
    
if __name__ == '__main__':
    do()
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
import collections
def count_ident(v):
    c = collections.Counter(v)
    val_list=c.values()
    v_count=0
    for k in val_list:
        if k>1:
            v_count=v_count+int(k*(k-1)/2)
        else:
            v_count=v_count
    print(v_count)

import copy
c = copy.deepcopy(a)    
for i in range(len(a)):
    tmp = copy.deepcopy(a)    
    tmp.pop(i)
    count_ident(tmp)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
import collections
c = collections.Counter(a)
val_list=list(c.values())
v_count=map(lambda x: x * (x-1), val_list)
total_count=int(sum(v_count)/2)

for i in a:
    print(total_count-(c[i]-1))
### BUGGY CODE ###

R, G, B, N = map(int, input().split())

RGB = sorted([R, G, B], reverse=True)
max1 = N // RGB[0] 

count = 0
for r in range(max1+1):
    for g in range(N-r+1):
        Bb = N - (r*RGB[0] + g*RGB[1])
        if Bb >= 0 and Bb % RGB[2] == 0:
            count += 1
print(count)

### FIXED CODE ###

R, G, B, N = map(int, input().split())

RGB = sorted([R, G, B], reverse=True)
max1 = N // RGB[0] 

count = 0
for r in range(max1+1):
    max2 = min([N-r, (N-r*RGB[0])//RGB[1]])
    for g in range(max2+1):
        if (N - (r*RGB[0] + g*RGB[1])) % RGB[2] == 0:
            count += 1
print(count)
### BUGGY CODE ###

# Picking Up
# グラフ,有向グラフ,ベクトル, ２次元、コスト,

N = int(input())
S = []
for _ in range(N):
    x, y = map(int, input().split())
    S.append([x, y])
cost = N

for k in range(len(S)):
    for i in range(len(S)):
        if k == i:
            continue
        t_vec_x1 = S[i][0] - S[k][0]
        t_vec_y1 = S[i][1] - S[k][1]
        edge = 0
        for l in range(len(S)):
            for m in range(len(S)):
                if l == m:
                    continue
                vec_x = S[m][0] - S[l][0]
                vec_y = S[m][1] - S[l][1]
                if t_vec_x1 == vec_x and t_vec_y1 == vec_y:
                    edge += 1
        cost = min(cost, N - edge)
        # t_vec_x2 = S[k][0] - S[i][0]
        # t_vec_y2 = S[k][1] - S[i][1]
        # edge = 0
        # for l in range(len(S)):
        #     for m in range(len(S)):
        #         if l == m:
        #             continue
        #         vec_x = S[l][0] - S[m][0]
        #         vec_y = S[l][1] - S[m][1]
        #         if t_vec_x2 == vec_x and t_vec_y2 == vec_y:
        #             edge += 1
        # print(edge)
        cost = min(cost, N - edge)

print(cost)


### FIXED CODE ###

# Picking Up
# グラフ,有向グラフ,ベクトル, ２次元、コスト,

N = int(input())
S = []
for _ in range(N):
    x, y = map(int, input().split())
    S.append([x, y])
cost = N
d = {}

if N==1:
    print(1)
    exit()
for l,le in enumerate(S):
    for m, me in enumerate(S):
        if l == m:
            continue
        t = (me[0] - le[0], me[1] - le[1])
        if t in d:
            d[t] +=1
        else:
            d[t] = 1

print(N - max(d.values()))
### BUGGY CODE ###

N, K = map(int, input().split())
*A, = map(int, input().split())
dp = [False] * (K+1)
for i in range(1, K+1):
    for a in A:
        if i - a < 0: break
        dp[i] |= not dp[i-a]
print('First' if dp[K] else 'Second')

### FIXED CODE ###

N, K = map(int, input().split())
*A, = map(int, input().split())
dp = [False] * (K+1)
for i in range(1, K+1):
    for a in A:
        if i - a < 0: break
        dp[i] |= not dp[i-a]
print('First' if dp[K] else 'Second')
### BUGGY CODE ###

n, p = map(int, input().split())
s = input()
x = [1] + [0]*(p-1)
ans = 0
if p in [2,5]:
  for i in range(n):
    if int(s[i])%p==0:
      ans += i+1
else:
  for i in range(n-1,-1,-1):
    u = int(s[i:])%p
    ans += x[u]
    x[u] += 1
print(ans)

### FIXED CODE ###

n, p = map(int, input().split())
s = input()
x = [1] + [0]*(p-1)
ans = 0
u = 0
if p in [2,5]:
  for i in range(n):
    if int(s[i])%p==0:
      ans += i+1
else:
  for i in range(n-1,-1,-1):
    u = (int(s[i])*pow(10,n-1-i,p)+u)%p
    ans += x[u]
    x[u] += 1
print(ans)
### BUGGY CODE ###

x, y = map(int, input().split())
dp = [[-1]*(y+1) for _ in range(x+1)]

for i in range(y+1):
    dp[0][i] = 0

for i in range(1, x+1):
    w, v = map(int, input().split())
    for j in range(y+1):
        if j-w >= 0:
            dp[i][j] = max(dp[i-1][j-w]+v, dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]
print(max(dp[-1]))


### FIXED CODE ###

def num():
    x, y = map(int, input().split())
    dp = [0]*(y+1)

    for i in range(x):
        w, v = map(int, input().split())
        for j in range(y, w-1, -1):
            num = dp[j-w]+v
            if num > dp[j]:
                dp[j] = num
    print(dp[-1])

num()
### BUGGY CODE ###

s = input()
n = int(input())
for _ in range(n):
    q = input().split()
    if q[0] == '1':
        s = s[::-1]
    else:
        if q[1] == '1':
            s = q[2] + s
        else:
            s += q[2]
    # print(s)

print(s)


### FIXED CODE ###

def main():
    c = 0
    s = input()
    f = ''
    b = ''
    for _ in range(int(input())):
        q = input().split()
        if q[0] == '1':
            c += 1
        else:
            if (q[1] == '1' and c%2 == 0) or (q[1]=='2' and c%2==1):
                f = q[2] + f
            else:
                b += q[2]
    if c % 2 == 0:
        print(f+s+b)
    else:
        print(b[::-1]+s[::-1]+f[::-1])

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

S = list(input())
n = int(input())
Q = [list(map(str, input().split())) for _ in range(n)]

for q in Q:
    if q[0] == "1":
        S.reverse()
    elif q[0] == "2":
        if q[1] == "1":
            S.insert(0,q[2])
        else:
            S.append(q[2])
print("".join(S))

### FIXED CODE ###

S = str(input())
n = int(input())
Q = [list(map(str, input().split())) for _ in range(n)]
cnt = 0
s_pre = ""
s_pro = ""
for q in Q:
    if q[0] == "1":
        cnt += 1
    else:
        if (int(q[1])+cnt)%2 == 1:
#             S = q[2] + S
            s_pre = q[2] + s_pre
        else:
            s_pro = s_pro + q[2]
#             S = S + q[2]

S = s_pre + S + s_pro
if cnt%2==1:
    S = list(S)
    S.reverse()
print("".join(S))
### BUGGY CODE ###

n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())

MAX = max(a)

for i in range(n):
    if a[i] == MAX:
        print(max(a[:i] + a[i+1:]))
    else:
        print(MAX)


### FIXED CODE ###

n = int(input())
a = {}
for i in range(n):
    a[i] = int(input())

max_i, MAX = max(a.items(), key=lambda x: x[1])
del a[max_i]

SECOND = max(a.values())


for i in range(n):
    if i == max_i:
        print(SECOND)
    else:
        print(MAX)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
count = [0] * N
answer = [-1] * N
#p = [0] * N
for i in range(N):
  count[i]  = A.count(i + 1)
  
nanimo = 0 
for i in range(N):
  nanimo += count[i] * (count[i] - 1) // 2
for i in range(N):
  if answer[A[i] - 1] != -1:
    #p[i] = answer[A[i] - 1]
    print(answer[A[i] - 1])
  else:
    tekito = count[A[i] - 1]
    if tekito == 2:
      s = nanimo - 1
    elif tekito == 1:
      s = nanimo
    else:
      s = nanimo -  ((tekito * (tekito - 1) //2) - ((tekito - 1) * (tekito - 2) //2))
    #p[i] = s
    print(s)
    answer[A[i] - 1] = s
#for i in p:
  #print(i)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
count = [0] * N
for i in range(N):
  count[A[i] - 1]  += 1
  
nanimo = 0 
for i in range(N):
  nanimo += count[i] * (count[i] - 1) // 2
for i in range(N):
  tekito = count[A[i] - 1]
  if tekito == 2:
    s = nanimo - 1
  elif tekito == 1:
    s = nanimo
  else:
    s = nanimo -  ((tekito * (tekito - 1) //2) - ((tekito - 1) * (tekito - 2) //2))
  print(s)
### BUGGY CODE ###

n = int(input())
s = list(input())
tot = 0
R = [i for i, x in enumerate(s) if x == 'R']
G = [i for i, x in enumerate(s) if x == 'G']
B = [i for i, x in enumerate(s) if x == 'B']
tot += len(R) * len(G) * len(B)
for i in range(len(R)):
    for j in range(len(G)):
        for k in range(len(B)):
            if 2 * R[i] == G[j] + B[k] or 2 * G[j] == R[i] + B[k] or 2 * B[k] == G[j] + R[i]:
                tot -= 1
print(tot)


### FIXED CODE ###

n = int(input())
s = list(input())
tot = 0
tot += s.count('R') * s.count('G') * s.count('B')
for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i
        if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            tot -= 1
print(tot)
### BUGGY CODE ###

val = list(map(int, input().strip().split()))
n = val[0]
m = val[1]
a = []

for i in range(m):
    a.append(int(input().strip()))

pastpast_result = 0
past_result = 1
result = 0

for i in range(n):
    result = 0
    if i not in a:
        result += past_result
    if i-1 not in a:
        result += pastpast_result
    
    pastpast_result = past_result
    past_result = result

print(result % 1000000007)

### FIXED CODE ###

import bisect

def find_bisect(a, x):
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return True
    return False

val = list(map(int, input().strip().split()))
n = val[0]
m = val[1]
a = []

for i in range(m):
    a.append(int(input().strip()))

pastpast_result = 0
past_result = 1
result = 0

for i in range(n):
    result = 0
    if not find_bisect(a, i):
        result += past_result
    if not find_bisect(a, i-1):
        result += pastpast_result

    if result > 1000000007:
        result = result % 1000000007
    
    if result == 0:
        break
    
    pastpast_result = past_result
    past_result = result

print(result % 1000000007)
### BUGGY CODE ###

import re

n, q = map(int, input().split())
s = input()
li_lr = list()
pt = re.compile('AC')

for i in range(q):
    li_lr.append(list(map(int, input().split())))

for l in li_lr:
    print(len(re.findall(pt, s[l[0] - 1: l[1]])))



### FIXED CODE ###

n, q = map(int, input().split())
s = input()
li_lr = list()

li_flg = [0] * len(s)

for i in range(q):
    li_lr.append(list(map(int, input().split())))


for idx, v in enumerate(s):
    if v == 'C' and idx != 0 and s[idx - 1] == 'A':
        li_flg[idx] = li_flg[idx - 1] + 1
    else:
        li_flg[idx] = li_flg[idx - 1]

for l in li_lr:
    print(li_flg[l[1] - 1] - li_flg[l[0] - 1])
### BUGGY CODE ###

def main():

    # input
    N, T = map(int, input().split())
    a, b = [0] * N, [0] * N
    for i in range(N):
        a[i], b[i] = map(int, input().split())

    # sort
    ab_ratio = [a[i] / (b[i] + 1) for i in range(N)]
    key = sorted(range(N), key=lambda x: -ab_ratio[x])
    a = [a[i] for i in key]
    b = [b[i] for i in key]

    # dp
    dp = [[float('inf') for _ in range(N + 2)] for _ in range(N + 1)]  # dp[for i shops][passed j shops] := min time
    dp[0][0] = 0
    for i in range(N):
        for j in range(N + 1):
            if j > 0:
                dt = 1 + a[i] * (dp[i][j - 1] + 1) + b[i]
                if dp[i][j - 1] + dt <= T + 0.5:
                    dp[i + 1][j] = min(dp[i][j], dp[i][j - 1] + dt)
                else:
                    dp[i + 1][j] = dp[i][j]
            else:
                dp[i + 1][j] = dp[i][j]

    # print answer
    for i in range(N + 1):
        if dp[N][i + 1] == float('inf'):
            print(i)
            exit()


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    # input
    N, T = map(int, input().split())
    a, b = [], []
    a0_b = []
    for i in range(N):
        a_in, b_in = map(int, input().split())
        if a_in == 0:
            a0_b.append(b_in)
        else:
            a.append(a_in)
            b.append(b_in)
    L = len(a)

    # sort
    ab_ratio = [a[i] / (b[i] + 1) for i in range(L)]
    key = sorted(range(L), key=lambda x: -ab_ratio[x])
    a = [a[i] for i in key]
    b = [b[i] for i in key]
    a0_b.sort()

    # --- case a >= 1 --- #
    # dp[for i shops][passed j shops] := min time
    # j:29 for T < 10^9
    J_MAX = min(L + 1, 29)
    dp = [[float('inf') for _ in range(J_MAX)] for _ in range(L + 1)]
    dp[0][0] = 0
    for i in range(L):
        for j in range(J_MAX):
            if j > 0:
                dt = 1 + a[i] * (dp[i][j - 1] + 1) + b[i]
                if dp[i][j - 1] + dt <= T:
                    dp[i + 1][j] = min(dp[i][j], dp[i][j - 1] + dt)
                else:
                    dp[i + 1][j] = dp[i][j]
            else:
                dp[i + 1][j] = dp[i][j]

    # --- case a = 0 --- #
    ans = 0
    for i in range(J_MAX):
        if dp[L][i] == float('inf'):
            break
        else:
            time_cnt = dp[L][i]
            shop_cnt = i
            for t_b in a0_b:
                if time_cnt + 1 + t_b <= T:
                    time_cnt += 1 + t_b
                    shop_cnt += 1
            if ans < shop_cnt:
                ans = shop_cnt

    print(ans)


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

N = int(input())
s = list(map(int,input().split()))
a = s[0]

if len(s) > 1:
    for i in range(1,N):
        if s[i] == 0:
            a=0
            break
        a = a * s[i]
        
if a > 10**18:
    a = -1
print(a)

### FIXED CODE ###

N = int(input())
s = list(map(int,input().split()))
a = s[0]

if not 0 in s:
    if len(s) > 1:
        for i in range(1,N):
            a = a * s[i]
            
            if a > 10**18:
                a = -1
                break
else:
    a=0
print(a)
### BUGGY CODE ###

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

N = int(input())
A = [[-1] + [int(x)-1 for x in row.split()][::-1] for row in sys.stdin.readlines()]

A.append([-1])

def f():
    can_use = []
    for n in range(N):
        if A[A[n][-1]][-1] == n:
            can_use.append(n)
    for n in can_use:
        A[n].pop()
    return len(can_use)

answer = 0
rest = N*(N-1)
while True:
    answer += 1
    x = f()
    if x == 0:
        answer = -1
        break
    rest -= x
    if rest == 0:
        break

print(answer)

### FIXED CODE ###

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

N = int(input())
A = [[-1] + [int(x)-1 for x in row.split()][::-1] for row in sys.stdin.readlines()]

A.append([-1])

def f(cand):
    cand1 = set()
    can_use = []
    for n in cand:
        if A[A[n][-1]][-1] == n:
            can_use.append(n)
    for n in can_use:
        A[n].pop()
        cand1.add(n)
        if A[n][-1] != -1:
            cand1.add(A[n][-1])
    return len(can_use),cand1

answer = 0
rest = N*(N-1)
cand = set(range(N))
while True:
    answer += 1
    x,cand = f(cand)
    if x == 0:
        answer = -1
        break
    rest -= x
    if rest == 0:
        break

print(answer)
### BUGGY CODE ###

s=input()
q=int(input())
query=[]
for i in range(q):
    query.append(input())
seq=s
rev=0
for i in range(q):
    if query[i][0]=="1":
        rev+=1
    else:
        n,f,c=query[i].split()
        if (rev+int(f))%2==0:
            seq=seq+c
        else:
            seq=c+seq

if rev%2==0:
    print(seq)
else:
    for i in range(len(seq)):
        print(seq[len(seq)-i-1],end="")

### FIXED CODE ###

s=input()
q=int(input())
query=[]
for i in range(q):
    query.append(input())
rev=0
bef=""
aft=""
for i in range(q):
    if query[i][0]=="1":
        rev+=1
    else:
        n,f,c=query[i].split()
        if (rev+int(f))%2==0:
            aft=aft+c
        else:
            bef=c+bef
seqfin=bef+s+aft
if rev%2==0:
    print(seqfin)
else:
    print(seqfin[::-1])
### BUGGY CODE ###

import numpy as np
N = int(input())
alist = np.array(list(map(int, input().split())))
ranges = np.arange(1, 10**5)


def f(m):
    return np.sum(np.mod(alist, m))


num_f = np.frompyfunc(f, 1, 1)
print(max(num_f(ranges)) - N)


### FIXED CODE ###

import numpy as np
N = int(input())
alist = np.array(list(map(int, input().split())))
print(np.sum(alist - 1))
### BUGGY CODE ###

def work(l):
    l.sort(key=lambda x:x[1],reverse=True)
    salary = l.pop(0)
    return salary[1]

n,m = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]

queue = []
ans = 0
i = 0
while i < m:
    i += 1
    for j in range(len(a)):
        if a[j][0] == i:
            queue.append(a[j])
    if len(queue)>0:
        ans += work(queue)
print(ans)

### FIXED CODE ###

import heapq

N, M = list(map(int, input().split()))
jobs = [[] for _ in range(M)]

for i in range(N):
    d, r = list(map(int, input().split()))
    if d-1 < M:
        jobs[d-1].append(-r)

#解法
rewards = 0
heap = []
for i in range(M):
    for reward in jobs[i]:
        heapq.heappush(heap, reward)
    if len(heap) >0:
        reword = heapq.heappop(heap)
        rewards += -reword

print(rewards)