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

S = input()
Q = int(input())
reverseFlag = False
for i in range(Q):
    tmp = input()
    if tmp[0] == '1':
        reverseFlag = not reverseFlag
    else:
        tmpt, tmpf, tmpc = tmp.split(' ')
        if tmpf == '1' and reverseFlag == False or tmpf == '2' and reverseFlag == True:
            S = ''.join([tmpc, S]) 
        else:
            S = ''.join([S, tmpc])

if reverseFlag == True:
    S = S[::-1]
print(S)

### FIXED CODE ###

S = input()
Q = int(input())
reverseFlag = False
forwardList = []
backwardList = []
for i in range(Q):
    tmp = input()
    if tmp[0] == '1':
        reverseFlag = not reverseFlag
    else:
        tmpt, tmpf, tmpc = tmp.split(' ')
        if tmpf == '1' and reverseFlag == False or tmpf == '2' and reverseFlag == True:
            forwardList.append(tmpc) 
        else:
            backwardList.append(tmpc)

if reverseFlag == True:
    S = ''.join(reversed(backwardList)) + S[::-1] + ''.join(forwardList)
else:
    S = ''.join(reversed(forwardList)) + S + ''.join(backwardList)
print(S)
### BUGGY CODE ###

import sys
readline = sys.stdin.readline

def main():
    N, M = map(int, readline().rstrip().split())
    inp = [list(map(int, readline().rstrip().split())) for _ in range(M)]
    pref = {}
    for p, y in inp:
        pref.setdefault(p, [])
        pref[p].append(y)

    res = []
    for p, city in inp:
        cities = sorted(pref[p])
        id = str(p).zfill(6) + str(cities.index(city)+1).zfill(6)
        res.append(id)
    
    print(*res, sep='\n')

if __name__ == '__main__':
    main()

### FIXED CODE ###

from operator import itemgetter

def main():
    num_prefecture, num_city = list(map(int, input().rstrip().split()))
    prefecture_list = []
    for i in range(num_prefecture):
        prefecture_list.append([])
    #print(prefecture_list)
    id_list = []
    for idx_city in range(num_city):
        p_belong, y_born = list(map(int, input().rstrip().split()))
        p_belong -= 1 # 0から始まるようにする
        prefecture_list[p_belong].append([idx_city, y_born])
    
    #print(prefecture_list)
    # 各県のリスト内で, 市の誕生順にソートする
    for l in prefecture_list:
        l.sort(key = itemgetter(1))
    
    #print(prefecture_list)
    
    for idx_p, l in enumerate(prefecture_list):
        for x, [idx_city, y_born] in enumerate(l):
            id_first = '{0:06d}'.format(idx_p + 1)
            id_end = '{0:06d}'.format(x + 1)
            id_num = str(id_first) + str(id_end)
            id_list.append([idx_city, id_num])
    
    id_list.sort(key = itemgetter(0))
    
    for id_num in id_list:
        print(id_num[1])
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n,k=map(int,input().split())
p=list(map(int,input().split()))
maxim=0
ans=[]
for i in range(n-k+1):
    if maxim<=sum(p[i:i+k]):
        maxim=sum(p[i:i+k])
        ans=p[i:i+k]

ans1=0
for i in ans:
    ans1+=(i+1)/2

print(ans1)


### FIXED CODE ###

n,k=map(int,input().split())
p=list(map(int,input().split()))
maxim=[0]*(n-k+1)
cnt=0
s=0
for i in range(n):
    cnt+=1
    s+=p[i]
    if cnt==k:
        maxim[i-(k-1)]=s
        cnt=k-1
        s+=-p[i-(k-1)]

ans=(max(maxim)+k)/2
print(ans)
### BUGGY CODE ###

# -*- coding:utf-8 -*-

comb_dic = {}

def combination_formula_MOD(n, r, MOD):
    """nCrを O(min(n-r, r)) で高速に計算する"""
    def _inv(x, MOD):
        """xの逆元を返す"""
        return pow(x, MOD-2, MOD)
    if r > n: return 0

    if n in comb_dic:
        return comb_dic[n]

    r = min(n-r, r)
    bunsi, bunbo = 1, 1
    for i in range(r):
        bunsi = bunsi*(n-i)%MOD
        bunbo = bunbo*(i+1)%MOD

    ans = (bunsi*_inv(bunbo, MOD))%MOD
    comb_dic[n] = ans
    return ans


def combination_formula(n, r):
    """nCrは、O(min(n-r, r))で実装する
    Notes:
        分子と分母がかなり大きな値になった場合、計算は遅くなるので注意
        求める値がmodをとった値でいい場合、フェルマーの小定理を使った方法が速い。
    """
    if r > n: return 0

    if n in comb_dic:
        return comb_dic[n]

    r = min(n-r, r)
    bunsi, bunbo = 1, 1
    for i in range(r):
        bunsi = bunsi*(n-i)
        bunbo = bunbo*(i+1)

    comb_dic[n] = bunsi//bunbo
    return comb_dic[n]


def solve():
    N = int(input())
    As = list(map(int, input().split()))
    MOD = 10**9+7

    dic = {}
    for a in As:
        if not a in dic:
            dic[a] = 0
        dic[a] += 1

    ans_dic = {}  # すでに答えを計算したもの
    for a in As:
        if not a in ans_dic:
            ans = 0
            for key, value in dic.items():
                if key == a:
                    value -= 1
                ans += combination_formula(value, 2)
                # ans += combination_formula_MOD(value, 2, MOD)
            ans_dic[a] = ans
            print(ans_dic[a])
        else:
            print(ans_dic[a])


if __name__ == "__main__":
    solve()


### FIXED CODE ###

# -*- coding:utf-8 -*-

comb_dic = {}


def combination_formula(n, r):
    """nCrは、O(min(n-r, r))で実装する
    Notes:
        分子と分母がかなり大きな値になった場合、計算は遅くなるので注意
        求める値がmodをとった値でいい場合、フェルマーの小定理を使った方法が速い。
    """
    if r > n: return 0

    if n in comb_dic:
        return comb_dic[n]

    r = min(n-r, r)
    bunsi, bunbo = 1, 1
    for i in range(r):
        bunsi = bunsi*(n-i)
        bunbo = bunbo*(i+1)

    comb_dic[n] = bunsi//bunbo
    return comb_dic[n]


def solve():
    N = int(input())
    As = list(map(int, input().split()))

    dic = {}
    for a in As:
        if not a in dic:
            dic[a] = 0
        dic[a] += 1

    # combination_formula(v, 2)はくっそ早いので、
    # しゃくとりっぽく解く
    total = 0
    for key, value in dic.items():
        total += combination_formula(value, 2)

    for a in As:
        ans = total
        ans -= combination_formula(dic[a], 2)
        ans += combination_formula(dic[a]-1, 2)
        print(ans)


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

M=998244353
n,m,k=map(int,input().split())
a=m*pow(m-1,n-1,M)
c=1
for i in range(1,k+1):
  t=m*pow(m-1,n-i-1,M)
  c=c*(n-i)*pow(i,M-2,M)
  a+=t*c%M
print(a%M)

### FIXED CODE ###

M=998244353
n,m,k=map(int,input().split())
p,c=[m]*n,[1]*n
for i in range(1,n):
  p[i]=p[i-1]*(m-1)%M
  c[i]=c[i-1]*(n-i)*pow(i,M-2,M)%M
print(sum(p[n-i-1]*c[i]%M for i in range(k+1))%M)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
flug = False
kaizen=0

for i in range(1,N):
    if A[i-1]>A[i]:
        kaizen=i
        flug=True
        break
    
if flug==False:
    print(0)
    exit()

keisu=0
keisuichi=0
for i in range(N):
    if abs(A[i])>keisu:
        keisu=A[i]
        keisuichi=i
if keisu>0:
    Ansx=[]
    Ansy=[]    
    while flug==True:
        Ansx.append(keisuichi)
        Ansy.append(kaizen)
        Ansx.append(keisuichi)
        Ansy.append(kaizen)
        A[kaizen]=A[kaizen]+A[keisuichi]*2
        keisuichi=kaizen
        flug=False
        for i in range(1,N):
            if A[i-1]>A[i]:
                kaizen=i
                flug=True
                break
        
    print(len(Ansx))
    for i in range(len(Ansx)):
        print(Ansx[i]+1,Ansy[i]+1)
    
else:
    Ansx=[]
    Ansy=[]    
    while flug==True:
        Ansx.append(keisuichi)
        Ansy.append(kaizen)
        Ansx.append(keisuichi)
        Ansy.append(kaizen)
        A[kaizen]=A[kaizen]+A[keisuichi]*2
        keisuichi=kaizen
        flug=False
        for i in range(1,N):
            if A[i-1]>A[i]:
                kaizen=i
                flug=True
                break
        
    print(len(Ansx))
    for i in range(len(Ansx)):
        print(Ansx[i]+1,Ansy[i]+1)
    

### FIXED CODE ###

# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
flug = False
kaizen=0

for i in range(1,N):
    if A[i-1]>A[i]:
        kaizen=i
        flug=True
        break
    
if flug==False:
    print(0)
    exit()

keisu=0
keisuichi=0
for i in range(N):
    if abs(A[i])>abs(keisu):
        keisu=A[i]
        keisuichi=i
if keisu>0:
    Ansx=[]
    Ansy=[]
    for i in range(N):
        Ansx.append(keisuichi)
        Ansy.append(i)
        Ansx.append(keisuichi)
        Ansy.append(i)
        A[i]=A[i]+A[keisuichi]*2
        keisuichi=i
        
        
    print(len(Ansx))
    for i in range(len(Ansx)):
        print(Ansx[i]+1,Ansy[i]+1)
    
else:
    Ansx=[]
    Ansy=[]
    for i in range(N):
        Ansx.append(keisuichi)
        Ansy.append(N-i)
        Ansx.append(keisuichi)
        Ansy.append(N-i)
        A[N-i-1]=A[N-i-1]+A[keisuichi]*2
        keisuichi=N-i-1
        
        
    print(len(Ansx))
    for i in range(len(Ansx)):
        print(Ansx[i]+1,Ansy[i])
### BUGGY CODE ###

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

han=-32
for a in range(N-K+1):
    gou=0
    for b in range(K):
        i=a+b
        kei=sum(range(1,P[i]+1))/P[i]

        gou+=kei
    if gou>han:
        han=gou
print(han)

### FIXED CODE ###

N,K=map(int,input().split())
P=list(map(int,input().split()))
X=[]
for a in P:
    X.append(a/2+0.5)
gou=sum(X[0:K])

han=-32
saigou=sum(X[N-K:N])
han=saigou
for a in range(N-K-1):

    if gou>han:
        han=gou
    gou=gou-X[a]+X[a+K]

print(han)
### BUGGY CODE ###

inr = lambda: list(map(int, input().split()))
inn = lambda: input()

N,Q = inr()
S = inn()
for q in range(Q):
    l,r = inr()
    bubun = S[l-1:r]

    cou = 0
    ccc = 0
    for b in bubun:
        if b == "C":
            if ccc ==1:
                cou += 1
            ccc = 0
        elif b == "A":
            ccc = 1
        else:
            ccc = 0

    print(cou)

### FIXED CODE ###

n,q = map(int,input().split())
s = input()
pref = [0]
for i in range(1,n):
  if s[i-1:i+1] == "AC": 
      pref.append(pref[-1]+1)
  else: 
      pref.append(pref[-1])
for i in range(q):
    l,r = map(int,input().split())
    print(pref[r-1]-pref[l-1])
### BUGGY CODE ###

import bisect
import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

a.sort()
f.sort(reverse=True)

for ans in range(a[-1] * f[-1] + 1):
    tmp = 0
    for x, y in zip(a,f):
        tmp += x - math.floor(ans / y)
    if tmp <= k:
        break
print(ans)

### FIXED CODE ###

import math
(n,k),a,f = [list(map(int, s.split())) for s in open(0)]

a.sort()
f.sort(reverse=True)

low = 0
high = 0
for x, y in zip(a,f):
    high = max(high, x*y)

while high != low:
    test = int((high + low) // 2)
    tmp = 0
    for x, y in zip(a,f):
        tmp += max(0, x - math.floor(test / y))
        if tmp > k:
            low = test + 1
            break
    else:
        high = test
print(high)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    import heapq

    heapq.heapify(A)

    for i in range(M):
        for j in range(B[i]):
            t = heapq.heappop(A)
            if(t >= C[i]):
                heapq.heappush(A, t)
                break
            else:
                t = C[i]
                heapq.heappush(A, t)


    print(sum(A))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]" 
    C = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, A, B, C)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    x = [[B[i],C[i]] for i in range(M)]
    x = sorted(x, key=lambda x: -x[1])

    A.sort()

    dn = 0
    for b, c in x:
        for j in range(b):
            if(dn >= N):
                break
            if(A[dn] < c):
                A[dn] = c
                dn += 1
            else:
                break


    print(sum(A))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]" 
    C = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, A, B, C)

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

from collections import defaultdict
H, N= map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

dp = defaultdict(lambda : 10**10)
dp[0] = 0

for i in range(0,N):
    ndp = dp.copy()
    a = A[i]
    b = B[i]
    for h,m in dp.items():
        cnt = 0
        while True:
            damage = h+a*cnt
            if damage >= H:
                ndp[H] = min(ndp[H], ndp[h] + b*cnt)
                break
            ndp[damage] = min(ndp[damage], ndp[h] + b*cnt)
            cnt += 1
    dp = ndp

print(dp[H])




### FIXED CODE ###

from collections import defaultdict
H, N= map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

dp = [10**10]*(H+1)
dp[0] = 0

for i in range(0,N):
    a = A[i]
    b = B[i]
    for h in range(H+1-a):
        dp[h+a] = min(dp[h+a], dp[h] + b)
    dp[H] = min(dp[H], min(dp[H-a:H])+b)

print(dp[H])
### BUGGY CODE ###

n=int(input())

a=[]

for i in range(n):
    b=int(input())
    a.append(b)
    
a.sort()

ans=["" for i in range(n)]

ans[n//2]=a[-1]
a.remove(a[-1])
l=(n//2)-1
r=(n//2)+1
num=0
for i in range(n-1):
    if i%4==0:
        ans[l]=a[0]
        a.remove(a[0])
        num+=abs(ans[l+1]-ans[l])
        l-=1
    elif i%4==1:
        ans[r]=a[0]
        a.remove(a[0])
        num+=abs(ans[r]-ans[r-1])
        r+=1
    elif i%4==2:
        ans[l]=a[-1]
        a.remove(a[-1])
        num+=abs(ans[l+1]-ans[l])
        l-=1
    elif i%4==3:
        ans[r]=a[-1]
        a.remove(a[-1])
        num+=abs(ans[r]-ans[r-1])
        r-=1

ans.append(ans[0]) 
num+=abs(ans[-1]-ans[-2])    

num-=min(abs(ans[0]-ans[1]),abs(ans[-1]-ans[-2]),abs(ans[-2]-ans[-3]))
        
print(num)




### FIXED CODE ###

n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
l.sort()
if n%2==0:
    ln=l[:n//2]
    lx=l[n//2:]
    print(2*(sum(lx)-sum(ln))-lx[0]+ln[-1])
else:
    ln=l[:n//2]
    lm=l[n//2]
    lx=l[n//2+1:]
    p=sum(lx)
    q=sum(ln)
    print(max(2*(p-q)+ln[-1]-lm,2*(p-q)-lx[0]+lm))
### BUGGY CODE ###

s = input()
oddone = ''
evenone = ''

for i in range(len(s)):
    if i % 2 == 1:
        oddone += '1'
        evenone += '0'
    else:
        oddone += '0'
        evenone += '1'

def diffCount(s1, s2):
    count = 0
    if len(s1) != len(s2):
        print('error')
        return

    for i in range(len(s1)):
        if s1[i] != s2[i]:
            count += 1

    return count

print(min(diffCount(s, oddone), diffCount(s, evenone)))



### FIXED CODE ###

s = input()
oddone = ''
evenone = ''

for i in range(len(s)):
    if i % 2 == 1:
        oddone += '1'
        evenone += '0'
    else:
        oddone += '0'
        evenone += '1'

def diffCount(s1, s2):
    count = 0
    if len(s1) != len(s2):
        print('error')
        return

    for i in range(len(s1)):
        if s1[i] != s2[i]:
            count += 1

    return count

print(min(diffCount(s, oddone), diffCount(s, evenone)))
### BUGGY CODE ###

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

class segtree:
    x_unit=0 # 要素として入れられる最大値
    def __init__(self,N):
        self.n=(1<<len(bin(N-1)[2:]))
        self.x=[self.x_unit]*(2*self.n)

    def build(self, seq):
        for i,j in enumerate(seq, start=self.n):  # n番目からseqをx配列に移していく
            self.x[i] = j
        for i in range(self.n-1, 0, -1):
            self.x[i] = 0
            # セグ木トーナメント表の左右を比較
            # 例えばn=8の時、seq[4]はx[12]に、seq[5]はx[13]に入っている
            # さらにx[14]とx[15]の間に来るのはx[7]、x[12]とx[13]の間に来るのはx[6]

    def fold(self,l,r): # 区間[l, r)値に+1 
        l+=self.n
        r+=self.n-1
        while l<r:
            if l%2==1: # lが奇数
                self.x[l]+=1
                l+=1 # 偶数に調節
            if r%2==0: # rが偶数
                self.x[r]+=1
                r-=1 # 開区間なので1個前は奇数番目の要素
            l //= 2
            r //= 2
        if l==r:
            self.x[l]+=1
        #print(self.x)
    def get(self,i): # seq[i]に対する値を取得 
        i+=self.n
        ret=self.x[i]
        while i>1:
            i //= 2
            ret+=self.x[i]
        return ret

for z in range(k):
    seq=[0]*n
    q=[(max(0, i-a[i]), min(n,i+a[i]+1)) for i in range(n)]
    seg=segtree(n)
    seg.build(seq)
    for i in range(n):
        l,r=q[i]
        seg.fold(l,r)
    ans=[]
    for i in range(n):
        ans.append(seg.get(i))
    a=ans+[]
    if all([i==n for i in a]):
        break
print(*a)

### FIXED CODE ###

n,k=map(int, input().split())
a=list(map(int, input().split()))
from itertools import accumulate
for _ in range(k):
    new=[0]*n
    for i in range(n):
        j=a[i]
        l=max(0,i-j)
        r=min(n-1,i+j)
        new[l]+=1
        if r+1<n:
            new[r+1]-=1
    new=list(accumulate(new))
    a=new
    if all([i==n for i in a]):
        break
print(*a)
### BUGGY CODE ###

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

As = sorted(list(map(int,input().split())))

Bs = []
Cs = []
for i in range(M):
	inputs = list(map(int,input().split()))
	Bs.append(inputs[0])
	Cs.append(inputs[1])

for j in range(1, M + 1):
	for n in range(Bs[j - 1]):
		if As[0] < Cs[j - 1]:
			As[0] = Cs[j - 1]
			As = sorted(As)

print(sum(As))


### FIXED CODE ###

import numpy as np

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

As = sorted(list(map(int,input().split())))
BCs = []

for i in range(M):
	inputs = list(map(int,input().split()))
	BCs.append(inputs)
BCs = sorted(BCs, reverse = True, key=lambda x: x[1])

index = 0
for bc in BCs:
	b = bc[0]
	c = bc[1]

	for n in range(b):
		try:
			if As[index] < c:
				As[index] = c
				index += 1
			else:
				break
		except:
			break
print(sum(As))
### BUGGY CODE ###

k = int(input())
a=7
i=1
while True:
  if a%k ==0:
    print(i)
    break
  i+=1
  a = a + 7*10**(i-1)

### FIXED CODE ###

k = int(input())
if k % 2 == 0 or k%5==0:
    print(-1)
    exit()
a = 7
ans = 1
while True:
    if a % k == 0:
        print(ans)
        exit()
    a = (a*10+7) % k
    ans += 1
### BUGGY CODE ###

from bisect import bisect_left
import sys
input = sys.stdin.buffer.readline


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


ans = 0
for keta in range(0, 29)[::-1]:
    MOD = 1 << (keta + 1)
    T = 1 << keta
    for i in range(n):
        a[i] %= MOD
        b[i] %= MOD
    b.sort()

    # T <= a[i] + b[j] < 2T もしくは 3T <= a[i] + b[j] < 4T
    # を満たすi, jの組の個数を二分探索で探す。
    cnt = 0
    for i in range(n):
        l = bisect_left(b, T - a[i]) 
        r = bisect_left(b, 2 * T - a[i]) 
        cnt += r - l
        l = bisect_left(b, 3 * T - a[i], lo=r) 
        r = bisect_left(b, 4 * T - a[i], lo=r) 
        cnt += r - l

    # i, jの組の個数が奇数だったら、xorしたときにTが残る
    if cnt % 2 == 1:
        ans += T

print(ans)

### FIXED CODE ###

from bisect import bisect_left
import sys
input = sys.stdin.buffer.readline


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


ans = 0
for keta in range(0, 29)[::-1]:
    MOD = 1 << (keta + 1)
    T = 1 << keta
    for i in range(n):
        a[i] %= MOD
        b[i] %= MOD
    a.sort(reverse=True)
    b.sort()

    # T <= a[i] + b[j] < 2T もしくは 3T <= a[i] + b[j] < 4T
    # を満たすi, jの組の個数を尺取り法で探す
    T1 = [0] * n
    l = 0
    for i in range(n):
        while l < n and a[i] + b[l] < T:
            l += 1
        T1[i] = l

    T2 = [0] * n
    l = 0
    for i in range(n):
        while l < n and a[i] + b[l] < 2 * T:
            l += 1
        T2[i] = l

    T3 = [0] * n
    l = 0
    for i in range(n):
        while l < n and a[i] + b[l] < 3 * T:
            l += 1
        T3[i] = l

    T4 = [0] * n
    l = 0
    for i in range(n):
        while l < n and a[i] + b[l] < 4 * T:
            l += 1
        T4[i] = l

    cnt = 0  
    for i in range(n):
        cnt += (T2[i] - T1[i]) + (T4[i] - T3[i])

    # i, jの組の個数が奇数だったら、xorしたときにTが残る
    if cnt % 2 == 1:
        ans += T

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

from bisect import bisect_left, insort_left
N = int(input())
A = list(map(int, raw_input().split()))


# 各数の出現場所を持ってソート: 1-indexed
A_with_position = sorted([[a, i] for i, a in enumerate(A, start=1)])


# 出現したもののindex
appeared_index = [0, N + 1]

ans = 0
for a, i in A_with_position:
    li = bisect_left(appeared_index, i) - 1
    ri = bisect_left(appeared_index, i)

    lx, rx = appeared_index[li], appeared_index[ri]
    ans += a * (i - lx) * (rx - i)

    insort_left(appeared_index, i)

print(ans)


### FIXED CODE ###

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

d = [0] * (N+1)
for i in range(N):
    d[a[i]] = i

left = list(range(N+1))
right = list(range(N+1))

ans = 0
for i in range(N, 0, -1):
    di = d[i]
    ans += i * (right[di]-di+1) * (di-left[di]+1)
    right[left[di] - 1] = right[di]
    left[right[di] + 1] = left[di]

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

inp = int(input())

def check(n):
    i = 1
    print(" ",end="")
    while(i != n):
        if  (i % 3 == 0):
            print(i,end="")
        elif(i % 10 == 3):
            print(i,end="")
            i = i / 10
        i = i + 1
        

check(inp)


### FIXED CODE ###

n = int(input())

for  i in range(1,n+1):
    if i%3 == 0 or str(i).find("3") != -1:
        print(" %d" %i ,end="")
print()
### BUGGY CODE ###

N,K=map(int,input().split())
a=[]
for i in range(N):
    b,c=list(map(int,input().split()))
    for j in range(c):
        a.append(b)
a.sort()
print(a[K-1])


### FIXED CODE ###

N,K=map(int,input().split())
a=[]*N
b=0
for i in range(N):
    a.append(list(map(int,input().split())))
a.sort()
for i in range(N):
    b+=a[i][1]
    if b>=K:
      print(a[i][0])
      exit()