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

s = input()
q = int(input())
f = 1
for i in range(q):
  query = list(map(str, input().split()))
  if query[0] == '1':
    f *= -1
  else:
    if (f == 1 and query[1] == '1') or (f == -1 and query[1] == '2'):
      s = query[2] + s
    else:
      s += query[2]
if f == -1:
  s = s[::-1]
print(s)

### FIXED CODE ###

s = input()
q = int(input())
flag = 1
f = ''
b = ''
for i in range(q):
  query = list(map(str, input().split()))
  if query[0] == '1':
    flag *= -1
  else:
    if flag == 1:
      if query[1] == '1':
        f += query[2]
      else:
        b += query[2]
    else:
      if query[1] == '1':
        b += query[2]
      else:
        f += query[2]
ans = f[::-1] + s + b
if flag == -1:
  ans = ans[::-1]
print(ans)
### BUGGY CODE ###

import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    # divisors.sort()
    return divisors


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    aset = list(set(A))
    aset.sort()

    past = set()
    ans = 0
    ansset = set()
    for a in aset:
        divs = make_divisors(a)
        for div in divs:
            if div in past:
                break
        else:
            ansset.add(a)
            ans += 1

        past.add(a)

    c = collections.Counter(A)
    for cc in c.most_common():
        if cc[1] == 1:
            break

        if cc[1] > 1 and cc[0] in ansset:
            ans -= 1

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    aset = list(set(A))
    aset.sort()

    ans = [0] * (10 ** 6 + 1)

    for a in aset:
        for i in range(2, 10 ** 6 + 1):
            if a * i > 10 ** 6:
                break
            ans[a * i] += 1

    res = 0
    c = collections.Counter(A)
    for a in A:
        if ans[a] == 0 and c[a] == 1:
            res += 1

    print(res)



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

from collections import Counter
 
n = int(input())
cnt = Counter(input().split())
c1, c2, c3 = cnt['1'], cnt['2'], cnt['3']
total = c1 + 2 * c2 + 3 * c3
c23 = c2 + c3
dp = [[[0.0] * (c3 + 1) for _ in range(c2 + c3 + 1)] for _ in range(n + 2)]  # ←ここを0で初期化するとTLE
 
for k in range(1, n + 1):
    still = n / k
    for a1 in range(k, max(-1, 2 * k - total - 1, k - c23 - 1), -1):
        dpap, dpac, dpan = dp[a1 - 1], dp[a1], dp[a1 + 1]
        for a2 in range(min(k - a1, c2 + c3), max(-1, 3 * k - 2 * a1 - total - 1, k - a1 - c3 - 1), -1):
            a3 = k - a1 - a2
            tmp = 0
            if a1:
                tmp += dpap[a2][a3] * a1
            if a2:
                tmp += dpan[a2 - 1][a3] * a2
            if a3:
                tmp += dpac[a2 + 1][a3 - 1] * a3
            dpac[a2][a3] = tmp / k + still
print(dp[c1][c2][c3])

### FIXED CODE ###

from collections import Counter
 
n = int(input())
cnt = Counter(input().split())
c1, c2, c3 = cnt['1'], cnt['2'], cnt['3']
total = c1 + 2 * c2 + 3 * c3
c23 = c2 + c3
dp = [[[0.0] * (c3 + 1) for _ in range(c2 + c3 + 1)] for _ in range(n + 2)]  # ←ここを0で初期化するとTLE
 
for k in range(1, n + 1):
    still = n / k
    for a1 in range(k, max(-1, 2 * k - total - 1, k - c23 - 1), -1):
        dpap, dpac, dpan = dp[a1 - 1], dp[a1], dp[a1 + 1]
        for a2 in range(min(k - a1, c2 + c3), max(-1, 3 * k - 2 * a1 - total - 1, k - a1 - c3 - 1), -1):
            a3 = k - a1 - a2
            tmp = 0
            if a1:
                tmp += dpap[a2][a3] * a1
            if a2:
                tmp += dpan[a2 - 1][a3] * a2
            if a3:
                tmp += dpac[a2 + 1][a3 - 1] * a3
            dpac[a2][a3] = tmp / k + still
print(dp[c1][c2][c3])
### BUGGY CODE ###

a = int(input())
b = 0
count = 0
for i in range(a):
    for j in range(a):
        if (i+1)*(j+1) == a:
            if count == 0:
                count += 1
                c = i+1
                d = j+1
            if count>0:
                if (c+d)>(i+1)+(j+1):
                    c = i+1
                    d = j+1
ans = c+d-2
print(ans)

### FIXED CODE ###

a = int(input())
b = 0
l = int(a**0.5)+1
count = 0
for i in range(l):
    i = i+1
    if a%i == 0:
        j = a//i
    if i*j == a:
        if count == 0:
            count += 1
            c = i
            d = j
        if count>0:
            if (c+d)>(i+j):
                c = i
                d = j
ans = c+d-2
print(ans)
### BUGGY CODE ###

import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
V,C = zip(*CA.most_common())
S = 0
for i in range(len(C)):
    S += int(C[i]*(C[i]-1)/2)
for k in range(N):
    print(S - A.count(A[k]) + 1)

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
S = 0
for i in CA.values():
    S += i*(i-1)//2
for x in A:
    print(S - CA[x] + 1)
### BUGGY CODE ###

mod=1000000007
n=int(input())
#n,k=map(int,input().split())
a=[int(i) for i in input().split()]
ans=chk=0
for i in range(n-1):
    for j in range(i+1,n):
        ans+=(a[i]*a[j])%mod
        ans%=mod
print(ans)

### FIXED CODE ###

mod=1000000007
n=int(input())
#n,k=map(int,input().split())
a=[int(i) for i in input().split()]
t=[0]*(n+1)
for i in range(n):
    t[i]=t[i-1]+a[i]
ans=chk=0
#print(t)
for i in range(n-1):
#    print(-(i+1))
    x=-1*(i+1)
#    print(x)
#    print(a[x],t[x-2])
    ans+=a[x]*t[x-2]
    ans%=mod
print(ans)
### BUGGY CODE ###

l = []
for _ in range(int(input())):
  s=input()
  s=list(s)
  s.sort()
  t=''.join(s)
  l.append(t)
c=0
for i in range(len(l)-1):
  for j in range(i+1,len(l)):
    if l[i]==l[j]:
      c+=1
print(c)

### FIXED CODE ###

d={}
for _ in range(int(input())):
  s=input()
  s=list(s)
  s.sort()
  t=''.join(s)
  if t in d:
    d[t]+=1
  else:
    d[t]=1
c=0
# print(d)
for i in d:
  c+=(d[i]*(d[i]-1))//2
print(c)
### BUGGY CODE ###

import math
import sys


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

nn = max(N, M)
mm = min(N, M)

if mm != nn and mm + 1 < nn:
    print(0)
    sys.exit()

if N == M:
    print(math.factorial(N)*math.factorial(M) * 2)
else:
    print(math.factorial(N)*math.factorial(M))


### FIXED CODE ###

import math
import sys


N, M = map(int, input().split())
C = 10**9 + 7

nn = max(N, M)
mm = min(N, M)

if mm != nn and mm + 1 < nn:
    print(0)
    sys.exit()

if N == M:
    pN = math.factorial(N) % C
    pM = math.factorial(M) % C
    p = pN * pM * (2 % C)
    print(p % C)

else:
    pN = math.factorial(N) % C
    pM = math.factorial(M) % C
    print((pN * pM) % C)
### BUGGY CODE ###

from collections import deque
import numpy as np

H, W = list(map(int, input().split()))
field = [input() for _ in range(H)]
dist = [[5000] * W for _ in range(H)]

def bfs():
  q = deque()
  for y in range(H):
    for x in range(W):
      if field[y][x] == '#':
        q.append((y, x))
        dist[y][x] = 0
  while len(q) > 0:
    y, x = q.popleft()
    for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
      ny, nx = y + dy, x + dx
      if ny < 0 or ny >= H or nx < 0 or nx >= W:
        continue
      if field[ny][nx] == '#':
        continue
      if dist[ny][nx] < dist[y][x] + 1:
        continue
      dist[ny][nx] = dist[y][x] + 1
      q.append((ny, nx))
      
bfs()
print(np.max(np.asarray(dist).flatten()))

### FIXED CODE ###

from collections import deque
import copy

def main():
  H, W = map(int, input().split())
  maps = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if maps[i][j]])
  count = 0
  while True:
    nq = deque()
    while q:
      x, y = q.popleft()
      if x > 0 and not maps[x-1][y]:
        maps[x-1][y] = True
        nq.append((x-1,y))
      if y > 0 and not maps[x][y-1]:
        maps[x][y-1] = True
        nq.append((x,y-1))
      if x < H-1 and not maps[x+1][y]:
        maps[x+1][y] = True
        nq.append((x+1,y))
      if y < W-1 and not maps[x][y+1]:
        maps[x][y+1] = True
        nq.append((x,y+1))
    if nq:
      q = copy.copy(nq)
    else:
        break
    count += 1
  print(count)

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

import sys
input = sys.stdin.readline

c = input()
c = c[:len(c)-1]
q = int(input())

num = len(c)

hantei = 0

for i in range(q):
    q_i= list(input())
    #print(q_i)
    if q_i[0] == '1' and hantei ==0:
        hantei = 1
    elif q_i[0] == '1' and hantei == 1:
        hantei = 0
    elif (q_i[2] =='1' and hantei == 0) or (q_i[2] == '2' and hantei == 1):
            c = q_i[4] +c
    elif (q_i[2] =='2' and hantei == 0) or (q_i[2] == '1' and hantei ==1):
            c += q_i[4]



if hantei == 1:
    c = c[::-1]


print(c)


### FIXED CODE ###

import sys
input = sys.stdin.readline

c = input()
c = c[:len(c)-1]
q = int(input())

num = len(c)
c_mae = ''
c_ato = ''

hantei = 1

for i in range(q):
    q_i= list(input())
    #print(q_i)
    if q_i[0] == '1':
        hantei *= -1
    elif (q_i[2] =='1' and hantei == 1) or (q_i[2] == '2' and hantei == -1):
        c_mae = q_i[4] + c_mae
    else:
        c_ato += q_i[4]

print(c_mae+c+c_ato if hantei == 1 else (c_mae+c+c_ato)[::-1])
### BUGGY CODE ###

all_num, select_num = map(int, input().split())
dice = [int(a) for a in input().split()]
max_sum = 0

for i in range(all_num - (select_num - 1)):
    this_sum = 0
    for s in range(select_num):
        this_sum += dice[i+s]
 
    if this_sum > max_sum:
        max_sum = this_sum

print((max_sum + select_num) * 0.5)

### FIXED CODE ###

all_num, select_num = map(int, input().split())
dice = [int(a) for a in input().split()]

for i in range(all_num - (select_num - 1)):
    if i == 0:
        max_sum = this_sum = sum(dice[i:(i + select_num)])
    else:
        this_sum = this_sum - dice[i - 1] + dice[i + select_num - 1]

        if this_sum > max_sum:
            max_sum = this_sum

print((max_sum + select_num) * 0.5)
### BUGGY CODE ###

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

while all(i%2==0 for i in a ):
  A = [i//2 for i in a]
  cnt+=1

print(cnt)

### FIXED CODE ###

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

while all(i%2==0 for i in A):
  A=[i//2 for i in A]
  cnt+=1
print(cnt)
### BUGGY CODE ###

N=int(input())
A=list(map(int, input().split()))
for i in range(1,N+1):
  print(len([1 for x in A if x==i]))

### FIXED CODE ###

import numpy as np
N=int(input())
A_np = np.zeros(N)
A=list(map(int, input().split()))
for Ai in A:
  A_np[Ai-1] = A_np[Ai-1] + 1
for i in range(N):
  print('{:.0f}'.format(A_np[i]))
### BUGGY CODE ###

k, s = map(lambda x: int(x), input().split(' '))

r = 0
for a in range(k + 1):
    if a > s:
        break
    for b in range(k + 1):
        if a + b > s:
            break
        for c in range(k + 1):
            if a + b + c == s:
                r += 1
                break
            if a + b + c > s:
                break
print(r)


### FIXED CODE ###

k, s = map(lambda x: int(x), input().split(' '))
r = 0
for a in range(k + 1):
    if a > s:
        break
    for b in range(k + 1):
        if a + b > s:
            break
        elif s - (a + b) < k + 1:
            r += 1
print(r)
### BUGGY CODE ###

#!python
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = list(map(int, input().split()))
    T1 = [0]
    s = 0
    for i in range(N):
        s += A[i]
        T1.append(s)
    SUM = s
    T2 = [SUM]
    for i in range(N):
        s -= A[i]
        T2.append(s)

    c = 0
    for i in range(N + 1):
        for j in range(i + 1, N + 1):
            if SUM - T1[i] - T2[j] == 0:
                c += 1
    print(c)
    return 0


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!python
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = list(map(int, input().split()))
    T = [0]
    s = 0
    for i in range(N):
        s += A[i]
        T.append(s)

    T.sort()

    _a = None
    n = 0
    c = 0
    for a in T:
        if _a == a:
            n += 1
            c += n
        else:
            n = 0
        _a = a
    print(c)
    return 0


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

import numpy as np
mod = 10 ** 9 + 7

n = int(input())
a = np.asarray(list(map(int, input().split())))
ans = 0
bit = 1
for i in range(60):
  n_one = sum(a & 1)
  ans += n_one * (n - n_one) * bit
  a >>= 1
  bit *= 2
  ans %= mod
  bit %= mod
print(ans)

### FIXED CODE ###

import numpy as np
mod = 10 ** 9 + 7

n = int(input())
a = np.asarray(list(map(int, input().split())))
ans = 0
bit = 1
for i in range(60):
  n_one = np.count_nonzero(a & 1)
  ans += n_one * (n - n_one) * bit
  a >>= 1
  bit *= 2
  ans %= mod
  bit %= mod
print(ans)
### BUGGY CODE ###

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

if k == 0:
	print(max(a))
	exit()

suki = max(a)
kirai = 0
a.sort(key= lambda x: -x)
while int(suki) != int(kirai):
	targ = (suki+kirai)/2
	cnt = 0
	mode = 1
	for i in range(n):
		motome = math.ceil(a[i] / targ)-1
		if motome <= 0:
			break
		cnt += math.ceil(a[i] / targ)-1
		if cnt > k:
			mode = 0
			break
	if mode:
		suki = targ
	else:
		kirai = targ

print(math.ceil(suki))

### FIXED CODE ###

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

if k == 0:
	print(max(a))
	exit()

suki = 1000000000
kirai = 0
while int(suki) != int(kirai):
	targ = (suki+kirai)/2
	cnt = 0
	mode = 1
	for i in range(n):
		cnt += (a[i]-1)//targ
		if cnt > k:
			mode = 0
			break
	if mode:
		suki = targ
	else:
		kirai = targ

print(math.ceil(suki))
### BUGGY CODE ###

import itertools

N = int(input())
A = list(map(int,input().split()))
#Aa=[]
#for i in A:
    #Aa.append(i%(10**9+7))
#print(Aa)
ans = 0

for i,j in itertools.combinations(A,2):
    #print(i,j)
    ans += i*j
    #print(ans)

print(ans%(10**9+7))

### FIXED CODE ###

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

MOD = 10**9+7
S = sum(A)
ans = 0

for i in range(N-1):
    S -= A[i]
    ans = (ans + S*A[i])%MOD
    
print(ans)
### BUGGY CODE ###

N = int(input())

a = [int(N) for N in input().split()]

for i in range(1,N+1):
    print(a.count(i))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
 
ans = [0]*n
for i in range(n-1):
    ans[a[i]-1] += 1
for j in range(n):
    print(ans[j])
### BUGGY CODE ###

n=int(input())
f=[0]*n
d=[list(map(int,input().split()))+[i]for i in range(n)]
t=sorted(d,key=lambda x:(x[0]-x[1],-x[0]))
a=sorted(d,key=lambda x:(x[0]-x[1],-x[1]))
sumt=suma=0
while t:
    x=t.pop(0)
    while t and f[x[2]]:
        x=t.pop(0)
    if not f[x[2]]:
        sumt+=x[0]
    f[x[2]]=1
    if a:
        y=a.pop(0)
        while a and f[y[2]]:
            y=a.pop(0)
        if not f[y[2]]:
            suma+=y[1]
        f[y[2]]=1
print(sumt-suma)

### FIXED CODE ###

n=int(input())
d=sorted([list(map(int,input().split()))for _ in[0]*n],key=lambda x:sum(x))[::-1]
t=d[::2]
a=d[1::2]
print(sum(v[0]for v in t)-sum(v[1]for v in a))
### BUGGY CODE ###

N=int(input())

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

num=[0]*(N+1)

for i in range(len(ball)):
  num[ball[i]]+=1

for j in ball:
  key=j
  num[key]-=1
  
  cnb=0
  for k in num:
    if k>=2:
      cnb+=int(k*(k-1)/2)

  print(cnb)
  num[key]+=1

### FIXED CODE ###

N=int(input())

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

num=[0]*(N+1) #それぞれの数の個数

cnb=[-1]*(N+1) #それぞれの球を抜いた時のコンビネーション

for i in range(len(ball)):
  num[ball[i]]+=1


allcnb=0
for i in num:
  if i>=2:
    allcnb+=int(i*(i-1)/2)

for i in ball:
  cnb=0

  if num[i]>=2:
    cnb=num[i]-1

  print(allcnb-cnb)
### BUGGY CODE ###

def makefac(n):
    global faclist
    faclist = [1, 1]
    for i in range(2, n + 1):
        faclist.append(faclist[-1] * i % MOD)
    return None
def mcomb(n, r):#nCr % MOD
    return faclist[n] * pow(faclist[r],MOD - 2,MOD) * pow(faclist[n-r], MOD - 2) % MOD
def mperm(n, r):#nPr % MOD
    return faclist[n] * pow(faclist[n-r],MOD - 2, MOD)

N, M = map(int, input().split())
MOD = 10 ** 9 + 7
makefac(M)
ans = mperm(M, N)
for k in range(1, N + 1):
    ans += ((-1)**k * mcomb(N, k) * mperm(M - k, N - k)) % MOD
ans = ans * mperm(M, N) % MOD
print(ans)


### FIXED CODE ###

def makefac(n):
    global faclist
    faclist = [1, 1]
    for i in range(2, n + 1):
        faclist.append(faclist[-1] * i % MOD)
    return None
def mcomb(n, r):#nCr % MOD
    return faclist[n] * pow(faclist[r],MOD - 2, MOD) * pow(faclist[n-r], MOD - 2, MOD)
def mperm(n, r):#nPr % MOD
    return faclist[n] * pow(faclist[n-r],MOD - 2, MOD)

N, M = map(int, input().split())
MOD = 10 ** 9 + 7
makefac(M)
ans = mperm(M, N)
for k in range(1, N + 1):
    ans += ((-1)**k * mcomb(N, k) * mperm(M - k, N - k)) % MOD
ans = ans * mperm(M, N) % MOD
print(ans)
### BUGGY CODE ###

def main():
    n,m = map(int, input().split())
    s = [list(input().split()) for i in range(m)]

    ac_list = []
    correct = 0
    wrong = [0] * n
    penalty = 0

    for i,k in enumerate(s):
        if k[1] == 'AC' and k[0] not in ac_list:
            ac_list.append(k[0])
            correct += 1
        elif k[1] == 'WA' and k[0] not in ac_list:
            wrong[int(k[0])-1] += 1 
        else:
            continue
    
    for i,k in enumerate(ac_list):
        penalty += wrong[int(k)-1]

    print('{} {}'.format(correct,penalty))


if __name__ == '__main__':
    main()

### FIXED CODE ###

n, m = map(int, input().split())
ac = 0
wa = 0
 
ac_tf = [0] * n
wa_num = [0] * n
 
for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == "AC":
        if ac_tf[p] == 0:
            ac += 1
            wa += wa_num[p]
            ac_tf[p] = 1
    else:
        wa_num[p] += 1
            
print(ac, wa)
### BUGGY CODE ###

import numpy as np
N=int(input())
A=np.array(list(map(int, input().split())))
l=[]
for _ in range(N):
  l.append(str(A.argmin()+1))
  A[A.argmin()]=N+1
print(" ".join(l))

### FIXED CODE ###

import numpy as np
_=int(input())
A=np.array(list(map(int, input().split())))
B=np.argsort(A)
B=B+1
B=B.tolist()
B=map(str, B)
C=' '.join(B)
print(C)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
lcm=1
d=dict()
for i in range(n):
  k=a[i]
  for j in range(1,int(a[i]**0.5)+1):
    cnt=0
    while k%(j+1)==0:
      k//=j+1
      cnt+=1
    if j+1 in d:
      if d[j+1]<cnt:
        lcm*=(j+1)**(cnt-d[j+1])
        d[j+1]=cnt
    else:
      lcm*=(j+1)**cnt
      d[j+1]=cnt
  if k in d:
    if d[k]<1:
      lcm*=k
      d[k]=1
  else:
    lcm*=k
    d[k]=1
ans=0
for i in range(n):
  ans+=(lcm//a[i])%mod
print(ans%mod)


### FIXED CODE ###

from fractions import gcd
P = 10**9 + 7
N = 1000001 #使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心
inv = [0] + [1] # 1/x
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
n=int(input())
a=list(map(int,input().split()))
lcm=a[0]
mod=10**9+7
for i in range(1,n):
  lcm=(lcm//gcd(lcm,a[i]))*a[i]
ans=0
lcm%=mod
for i in range(n):
  ans=(ans+lcm*inv[a[i]])%mod
print(ans%mod)
### BUGGY CODE ###

def muridesu():
    N,K=[int(_) for _ in input().split()]
    aA=[int(_) for _ in input().split()]
    def f(i,N,aA):
        return sum(i^aA[j] for j in range(N))
    print(max(f(k,N,aA) for k in range(K+1)))
muridesu()


### FIXED CODE ###

#場合分けがつらい
def 解():
    N,K=[int(_) for _ in input().split()]
    aD =[0]*40
    aA=[int(_) for _ in input().split()]
    iL = 0
    for i in range(40):
        m = 2**i
        aD[i]=sum((_ & m) for _ in aA)
        if aD[i]:
            iL = i
    iLK = len(bin(K))-3
    iML = max(iL,iLK)
    dp = [[0]*2 for _ in range(2)]
    #[x][0] Kに沿う
    #[x][0] Kに沿わない最大
    for i in range(iML,-1,-1):
        ib = i%2 #桁%2 dp
        inb = 0 if ib else 1 #次のdp
        i0 = aD[i] #反転しない
        i1 = (2**i)*N-i0 #反転する
        iM = max(i0,i1) #選べるとき
        bL = i < iLK #Kより長い
        if (K>>i)&1:
            dp[inb][1] = dp[ib][1] + i1
            dp[inb][0] = max(dp[ib][1] + i0 ,dp[ib][0]+(iM if bL else i0))
        else:
            dp[inb][1] = dp[ib][1] + i0
            dp[inb][0] = dp[ib][0] + (iM if bL else i0)
    print(max(dp[inb]))
解()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
R,C,K = map(int,input().split())
RCV = [tuple(map(int,input().split())) for i in range(K)]

goods = [dict() for _ in range(R)]
for r,c,v in RCV:
    r,c = r-1,c-1
    goods[r][c] = v

dp = [[[0]*4 for _ in range(C)] for _ in range(R)]
if 0 in goods[0]:
    dp[0][0][1] = goods[0][0]
for i in range(R):
    for j in range(C):
        if i:
            pre = max(dp[i-1][j])
            dp[i][j][0] = pre
            if j in goods[i]:
                dp[i][j][1] = pre + goods[i][j]
        if j:
            for k in range(4):
                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
            if j in goods[i]:
                for k in reversed(range(3)):
                    dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j-1][k] + goods[i][j])

print(max(dp[-1][-1]))

### FIXED CODE ###

import sys
input = sys.stdin.readline
R,C,K = map(int,input().split())
RCV = [tuple(map(int,input().split())) for i in range(K)]

goods = [dict() for _ in range(R)]
for r,c,v in RCV:
    r,c = r-1,c-1
    goods[r][c] = v

dp0 = [[0]*4 for _ in range(C)]
dp1 = [[0]*4 for _ in range(C)]
if 0 in goods[0]:
    dp1[0][1] = goods[0][0]
for i in range(R):
    for j in range(C):
        if i:
            pre = max(dp0[j])
            dp1[j][0] = pre
            if j in goods[i]:
                dp1[j][1] = pre + goods[i][j]
        if j:
            for k in range(4):
                dp1[j][k] = max(dp1[j][k], dp1[j-1][k])
            if j in goods[i]:
                for k in reversed(range(3)):
                    dp1[j][k+1] = max(dp1[j][k+1], dp1[j-1][k] + goods[i][j])
    dp0 = dp1
    dp1 = [[0]*4 for _ in range(C)]
print(max(dp0[-1]))
### BUGGY CODE ###

N = int(input())
 
input_list = []
tmplist = []
 
for i in range(N):
  input_list.append(int(input()))
 
for i in input_list:
  tmplist = input_list[:]
  tmplist.remove(i)
  print(max(tmplist))

### FIXED CODE ###

N = int(input())
 
input_list = []
tmplist = []
 
for i in range(N):
  input_list.append(int(input()))

sorted_list = sorted(input_list)

first_val = sorted_list[-1]
second_val = sorted_list[-2]

for i in input_list:
  if i == first_val:
    print(second_val)
  else:
    print(first_val)
### BUGGY CODE ###

n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
for i in range(n):
  temp = a.pop(i)
  max_num = max(a)
  print(max_num)
  a.insert(i, temp)
    

### FIXED CODE ###

import copy
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))

copy_a = copy.deepcopy(a)
max_num = max(a)
a.remove(max_num)
second_num = max(a)

for i in range(n):
  if copy_a[i] >= max_num:
    print(second_num)
  else:
    print(max_num)
### BUGGY CODE ###

N = int(input())
print(sum([i for i in range(N)]))

### FIXED CODE ###

N = int(input())
print((N-1) * N // 2)
### BUGGY CODE ###

import copy

N = int(input().strip())
P = list(map(int, input().strip().split()))
ans = 0
for i in range(N):
  Q = copy.copy(P[0:i+1])
  Q.sort()
  #print(P)
  #print(Q)
  if Q[0] >= P[i]:
    ans += 1
  """
  flag = True
  for j in range(0, i):
    if P[i] > P[j]:
      flag = False
      break
  if flag:
    ans += 1
  """
print(ans)

### FIXED CODE ###

import copy

N = int(input().strip())
P = list(map(int, input().strip().split()))
ans = 0
min = 1e10
for i in range(N):
  #Q = copy.copy(P[0:i+1])
  #Q.sort()
  #print(P)
  #print(Q)
  #if Q[0] >= P[i]:
  #  ans += 1
  if P[i] < min:
    min = P[i]
    ans += 1
  """
  flag = True
  for j in range(0, i):
    if P[i] > P[j]:
      flag = False
      break
  if flag:
    ans += 1
  """
  
print(ans)