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

import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    s = input().strip()
    k = int(input().strip())
    ans = ""
    for i, c in enumerate(s):
        if i == len(s)-1:
            ans += chr(ord('a') + (ord(c) + k % 26 - ord('a')) % 26)
            break
        d = ord('z') - ord(c) + 1
        if d < k:
            k -= d
            ans += 'a'
        else:
            ans += c
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    s = input().strip()
    ans = list(s[:])
    k = int(input().strip())
    for i in range(len(s)):
        d = (ord('z') - ord(s[i]) + 1) % 26
        if k - d >= 0:
            ans[i] = 'a'
            k -= d
        if i == len(s) - 1:
            # print((ord(ans[i]) + k%26) % 26)
            ans[i] = chr(ord('a') + (ord(ans[i]) - ord('a') + k%26) % 26)
    print(''.join(ans))

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

import sys
result=input()
def query(n):
	print "? %d"%n
	sys.stdout.flush()
	return raw_input()
i=1
while i<=1000000000 and query(i)=="Y":
	i*=10
if i==1000000000*10:
	while i!=0 and query(i+1)=="Y":
		i/=10
	print i*10 if i!=0 else 1
else:
	l=i/10
	r=i-1
	print l, r
	while l+1!=r:
		if query(((l+r)/2)*10)=="Y":
			r=(l+r)/2
		else:
			l=(l+r)/2
	print r


### FIXED CODE ###

import sys
def query(n):
	print "? %d"%n
	sys.stdout.flush()
	return raw_input()
i=1
while i<=1000000000 and query(i)=="Y":
	i*=10
if i==1000000000*10:
	while i!=0 and query(i+1)=="Y":
		i/=10
	print "! %d"%(i*10 if i!=0 else 1)
else:
	l=i/10
	r=i-1
	while l+1!=r:
		if query(((l+r)/2)*10)=="Y":
			r=(l+r)/2
		else:
			l=(l+r)/2
	print "! %d"%r
### BUGGY CODE ###

def jyou(n, maxNum):
    i = 1
    result = 0

    if n == 1:
        return 1

    while True:
        val = n ** i
        if val > maxNum:
            break

        i += 1
        result = val

    return result


N = int(input())
dp = [[0 for _ in range(3)] for _ in range(10000000)]

nums = [9,6,1]

index = 0
isMatch = False
while True:
    for i,e in enumerate(nums):
        for k in range(3):
            maxNum = N - dp[index][k] 
            result = jyou(e, maxNum)
            nextVal = dp[index][k] + result

            dp[index + 1][i] = max(dp[index + 1][i], nextVal) 

            if nextVal == N:
                isMatch = True
                break
        if isMatch:
            break

    if isMatch:
        break
    index += 1
        
print(index + 1)


### FIXED CODE ###

N = int(input())
dp = list(range(N + 1))

for i in range(N + 1):
    pom6 = 1
    while pom6 <= i:
        dp[i] = min(dp[i], dp[i - pom6] + 1)
        pom6 *= 6

    pom9 = 1
    while pom9 <= i:
        dp[i] = min(dp[i], dp[i - pom9] + 1)
        pom9 *= 9

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

from collections import Counter
S = str(input())
N = len(S)

smod = [int(S[i:])%2019 for i in range(N)]
cmod = Counter(smod)

ans = 0
for x,y in cmod.items():
    if x == 0:
        y += 1
        ans += y*(y-1)/2
    else:
        ans += y*(y-1)/2
print(int(ans))

### FIXED CODE ###

from collections import Counter
S = str(input())
N = len(S)

#smod = [int(S[i:])%2019 for i in range(N)]
smod = [0]
tmod = 0
keta = 1
for i in range(N):
    temp = tmod + int(S[(N-1)-i])*keta
    #print(temp)
    tmod = temp%2019
    smod.append(tmod)
    keta = keta*10%2019


cmod = Counter(smod)
#print(cmod)

ans = 0
for i in cmod.values():
    ans += i*(i-1)/2
print(int(ans))
### BUGGY CODE ###

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

# M回の握手の幸福度最大化
# X以上になる握手を全て採用したときに、M通りを越える
# Xの最大値を求める

import bisect

ok=-1
ma=A[-1]
ng=(ma**2)*m+1

# x以上の握手をm通り以上作れるか
def isOk(x,m):
  cnt=0
  # 左手をループする
  for i in range(len(A)):
    left=A[i]
    minright=x-left
    # minright以上の数を数える
    cnt+=n-bisect.bisect_left(A,minright)
    if cnt>=m:
      return True
  return cnt>=m

while abs(ok-ng)>1:
  mid=abs(ok+ng)//2
  if isOk(mid,m):
    ok=mid
  else:
    ng=mid

x=ok
# x以上となる幸福度を足し合わせる
# 足し合わせた握手がMを越える場合、xぴったりを足し過ぎている

# 効率化のため累積和を作成
Asum=[0]+A
for i in range(1,len(Asum)):
  Asum[i]=Asum[i-1]+Asum[i]
  
# Aの添字i以降を全て足すときは、
# Asum[-1]-Asum[i]

ans=0
cnt=0
for i in range(len(A)):
  left=A[i]
  minright=x-left
  start=bisect.bisect_left(A,minright)
  cnt+=n-start
  ans+=left*(n-start)+(Asum[-1]-Asum[start])
  
if cnt>m:
  ans-=(cnt-m)*x
  
print(ans)


### FIXED CODE ###

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

# M回の握手の幸福度最大化
# X以上になる握手を全て採用したときに、M通りを越える
# Xの最大値を求める

import bisect

ok=-1
ng=(10**10)+2

# x以上の握手をm通り以上作れるか
def isOk(x,m):
  cnt=0
  # 左手をループする
  for i in range(len(A)):
    left=A[i]
    minright=x-left
    # minright以上の数を数える
    cnt+=n-bisect.bisect_left(A,minright)
    if cnt>=m:
      return True
  return cnt>=m

while abs(ok-ng)>1:
  mid=abs(ok+ng)//2
  if isOk(mid,m):
    ok=mid
  else:
    ng=mid

x=ok
# x以上となる幸福度を足し合わせる
# 足し合わせた握手がMを越える場合、xぴったりを足し過ぎている

# 効率化のため累積和を作成
Asum=[0]+A
for i in range(1,len(Asum)):
  Asum[i]=Asum[i-1]+Asum[i]
  
# Aの添字i以降を全て足すときは、
# Asum[-1]-Asum[i]

ans=0
cnt=0
for i in range(len(A)):
  left=A[i]
  minright=x-left
  start=bisect.bisect_left(A,minright)
  cnt+=n-start
  ans+=left*(n-start)+(Asum[-1]-Asum[start])
  
if cnt>m:
  ans-=(cnt-m)*x
  
print(ans)
### BUGGY CODE ###

A, B, C, K = map(int, input().split())
res = 0
total = 0
S = K - A
Z = S - B
for c in range(C+1):
    if Z == c:
        total = A*1 + B*0 + c*-1
        if res < total:
            res = total
print(res)

### FIXED CODE ###

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

xa = min(A, K)
K = K - xa
xb = min(B, K)
K = K - xb
xc = min(C, K)
total = xa*1 + xb*0 + xc*-1
print(total)
### BUGGY CODE ###

ans = 0
N, A = map(int, input().split())
X1 = list(map(int, input().split()))
a = 0

def dfs(total, loop, card_num, target_mean):
    global ans
    global N
    
    if loop == N:
        if total/card_num == target_mean:
            ans += 1
        return 0
    else:
        dfs(total        , loop+1, card_num  , target_mean)
        dfs(total+X[loop], loop+1, card_num+1, target_mean)
 
X = X1.copy()
for i in range(N):
    dfs(X[0], 1, 1, A)
    X.pop(0)
    N = len(X)
print(ans)

### FIXED CODE ###

import collections

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

for i in range(N):
    X[i] -= A

sums = collections.Counter([0,X[0]])

for i in X[1:]:
    c = collections.Counter()
    for p,q in sums.items():
        c[i+p] = q
    sums += c

print(sums[0]-1)
### BUGGY CODE ###

def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)
n=int(input())
a=list(map(int,input().split()))
l=[0 for _ in range(n)]
id=0
frac=[1 for _ in range(10**5+10)]
p=10**9+7
for i in range(n+1):
    x=a[i]-1
    l[x]=l[x]+1
for i in range(n):
    if l[i]==2:
        id=i+1
buf=[]
for i in range(1,10**5+10):
    frac[i]=(frac[i-1]*i)%p
#print(frac[:6])
for i in range(n+1):
    if a[i]==id:
        buf.append(i)
#print(a,l,buf)
short=(n+1)-(max(buf)-min(buf))
N=n+1
#print(short,N)

for i in range(1,n+2,1):
    all=(frac[N]*modinv(frac[i],p)*modinv(frac[N-i],p))%p
    sub1=(frac[short]*modinv(frac[i],p)*modinv(frac[short-i],p))%p
    sub2=(frac[short-1]*modinv(frac[i],p)*modinv(frac[short-i-1],p))%p
    if short-i<0:
        sub1=0
    if short-i-1<0:
        sub2=0
    #print(all,sub1,sub2)
    print((all-sub1+sub2)%p)

### FIXED CODE ###

import collections
def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)
n=int(input())
a=list(map(int,input().split()))
id=0
frac=[1]*(10**5+10)
fracinv=[0]*(10**5+10)
p=10**9+7
c=collections.Counter(a)
id=c.most_common()[0][0]
buf=[]
for i in range(1,10**5+10):
    frac[i]=(frac[i-1]*i)%p
for i in range(0,10**5+10):
    fracinv[i]=modinv(frac[i],p)
#print(frac[:6])
for i in range(n+1):
    if a[i]==id:
        buf.append(i)
#print(a,l,buf)
N=n+1
short=N-(max(buf)-min(buf))

#print(short,N)

for i in range(1,n+2,1):
    if short-i<0:
        sub1=0
    else:
        sub1 = (((frac[short] * fracinv[i]) % p) * fracinv[short-i]) % p

    if short-i-1<0:
        sub2=0
    else:
        sub2 = (((frac[short - 1] * fracinv[i]) % p) * fracinv[short - i - 1]) % p
    all=(((frac[N]*fracinv[i])%p)*fracinv[N-i])%p

    #print(all,sub1,sub2)
    print((all-(sub1-sub2)%p)%p)
### BUGGY CODE ###

import sys
import re
import queue
import collections
import math
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []


def main():
	N,K = i_map()
	A = i_list()

	for i in range(0,len(A)):
		A[i] = A[i] - 1

	lengthA = math.ceil(math.log2(K))

	next = [[0 for _ in range(N)] for _ in range(lengthA)]
	
	for i in range(0,N):
		next[0][i] = A[(i)%(N)]

	for i in range(1,lengthA):
		for j in range(0,N):
			next[i][j] = next[i-1][next[i-1][j]]

	current = 0

	for i in range(0,lengthA):
		if((1 << i) & K):
			current = next[i][current]

	print(current+1)

	return

if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys
import re
import queue
import collections
import math
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []


def main():
	N,K = i_map()
	A = i_list()

	for i in range(0,len(A)):
		A[i] = A[i] - 1

	lengthA = math.ceil(math.log2(K))

	next = [[0 for _ in range(N)] for _ in range(lengthA)]
	
	for i in range(0,N):
		next[0][i] = A[(i)%(N)]

	for i in range(1,lengthA):
		for j in range(0,N):
			next[i][j] = next[i-1][next[i-1][j]]

	current = 0

	for i in range(0,lengthA):
		if((1 << i) & K):
			current = next[i][current]

	print(current+1)

	return

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

import collections
 
N = int(input())
data = list([input() for i in range(N)])
 
dicdata = collections.Counter(data)
 
newdata = [k for k, v in dicdata.items() if v == max(dicdata.values())]
 
newdata = sorted(newdata)
 
[print(i) for i in newdata]

### FIXED CODE ###

import collections

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

dicdata = collections.Counter(data)

m = max(dicdata.values())

newdata = [k for k, v in dicdata.items() if v == m]

newdata.sort()

[print(i) for i in newdata]
### BUGGY CODE ###

from scipy.special import comb
n=int(input())
a=list(map(int,input().split()))

l=[0]*(n+1)
tmp=0
for i in range(0,n):
  l[i+1]=tmp+a[i]
  tmp=l[i+1]
#print(l)

s=set(l)
ans=0
s=set([i for i in s if l.count(i) > 1])
#print(s)
for i in s:
  ans+=comb(l.count(i), 2, exact=True)
print(ans)

### FIXED CODE ###

from scipy.special import comb
from collections import Counter as C
n=int(input())
a=list(map(int,input().split()))

l=[0]*(n+1)
tmp=0
for i in range(0,n):
  l[i+1]=tmp+a[i]
  tmp=l[i+1]

c=C(l)
ans=0

for v in c.values():
  ans+=comb(v, 2, exact=True)
print(ans)
### BUGGY CODE ###

N = int(input())

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

ans = i = j = 0

import bisect

for b in B:
    if b in A:
        b -= 1
    i = len(A[:bisect.bisect_left(A,b)])
    if b in C:
        b += 1
    j = len(C[bisect.bisect_left(C,b):])

    ans += i * j

print(ans)

### FIXED CODE ###

N = int(input())

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

ans = i = j = 0

import bisect

for b in B:
    i = bisect.bisect_left(A,b)
    j = N - bisect.bisect_right(C,b)
    ans += i * j
print(ans)
### BUGGY CODE ###

def resolve():

    s=str(input())
    K=int(input())

    ls=[]
    for i in range(len(s)):
        for j in range(i+1,len(s)+1):
            ls.append(s[i:j])

    print(sorted(list(set(ls)))[K-1])


resolve()

### FIXED CODE ###

def resolve():

    s=str(input())
    K=int(input())

    ls=[]
    for i in range(len(s)):
        for j in range(i+1,i+K+1):
            ls.append(s[i:j])

    print(sorted(set(ls))[K-1])


resolve()
### BUGGY 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()))
mod=10**9+7
def do():
    n=INT()
    A=LIST()
    B=[0]*(n)
    ans=0
    for i in range(1,n):
        B[i]=sum(A[i:])%mod

    for i in range(n-1):
        ans+=(A[i]*B[i+1])%mod
        ans=ans%mod

    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()))
mod=10**9+7
def do():
    n=INT()
    A=LIST()
    B=[0]*(n)
    B[0]=sum(A[1:])
    ans=0

    for i in range(1,n):
        B[i]=(B[i-1]-A[i])%mod

    for i in range(n-1):
        ans+=(A[i]*B[i])%mod
        ans=ans%mod

    print(ans)

    

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

n = list(map(int,input().split()))
a = n[0]
b = n[1]
while 1>0:
  c=a
  if a>b:
    a=a-b
  else:
    a=b-a
  if c<=a:
    break
print(c)

### FIXED CODE ###

n = list(map(int,input().split()))
a = n[0]
b = n[1]
c = a%b
d = b - c
if d<c:
    print(d)
else:
    print(c)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
# 整数の入力
n = int(input())
# 文字列の入力
s = input()
# 数え上げ
count = 0
for i in range(n):
    for j in range(i+1, n):
        if s[i] != s[j]:
            if s[i] != 'R' and s[j] != 'R':
                C = 'R'
            elif s[i] != 'G' and s[j] != 'G':
                C = 'G'
            else:
                C = 'B'
            count += s.count(C, j+1, 2*j - i)
            count += s.count(C, 2*j - i + 1)
print(count)

### FIXED CODE ###

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

N, M = map(int, input().split())
A = list(map(int, input().split()))
array = []
for _ in range(M):
    B, C = map(int, input().split())
    for __ in range(B):
        A.append(C)
        
A.sort(reverse=True)
print(sum(A[:N]))

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
array = []
for _ in range(M):
    tmp = list(map(int, input().split()))
    array.append(tmp)
array.sort(key=lambda x: x[1], reverse=True)

_sum = 0
_num = 0

for i in range(N+M):
    if A[0] > array[0][1]:
        _sum += A.pop(0)
        _num += 1
        
    else:
        a = array[0][0] if array[0][0] < N - _num else N - _num
        _sum += array.pop(0)[1] * a
        _num += a
        if not array:
            break
        
    if _num == N:
        break
    
if _num != N:
    while _num < N:
        _sum += A.pop(0)
        _num += 1
        
print(_sum)
### BUGGY CODE ###

n,k=map(int,input().split())
x,y=[[0,0] for i in range(n)],[[0,0] for i in range(n)]
xy=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    x_sub,y_sub=xy[i]
    x[i][0]=x_sub
    x[i][1]=i
    y[i][0]=y_sub
    y[i][1]=i
x.sort(key=lambda z:z[0])
y.sort(key=lambda z:z[0])
ans=(10**18)*5
for i1 in range(n-1):
    for i2 in range(i1+1,n):
        for j1 in range(n-1):
            for j2 in range(j1+1,n):
                x_sub1,y_sub1=10**9+1,10**9+1
                x_sub2,y_sub2=-10**9-1,-10**9-1
                z=[0]*n
                for i in range(i1,i2+1):
                    l=x[i][1]
                    x_sub1=min(xy[l][0],x_sub1)
                    x_sub2=max(xy[l][0],x_sub2)
                    y_sub1=min(xy[l][1],y_sub1)
                    y_sub2=max(xy[l][1],y_sub2)
                    z[l]=1
                for i in range(j1,j2+1):
                    l=y[i][1]
                    x_sub1=min(xy[l][0],x_sub1)
                    x_sub2=max(xy[l][0],x_sub2)
                    y_sub1=min(xy[l][1],y_sub1)
                    y_sub2=max(xy[l][1],y_sub2)
                    z[l]=1
                if sum(z)>=k:
                    ans=min((x_sub2-x_sub1)*(y_sub2-y_sub1),ans)

print(ans)


### FIXED CODE ###

n,k=map(int,input().split())
x,y=[[0,0] for i in range(n)],[[0,0] for i in range(n)]
xy=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    x_sub,y_sub=xy[i]
    x[i][0]=x_sub
    x[i][1]=i
    y[i][0]=y_sub
    y[i][1]=i
x.sort()
y.sort()
ans=(10**18)*5
for i1 in range(n):
    for l1 in range(n-i1,1,-1):
        for i2 in range(n):
            for l2 in range(n-i2,1,-1):
                x_sub1=x[i1][0]
                x_sub2=x[i1+l1-1][0]
                y_sub1=y[i2][0]
                y_sub2=y[i2+l2-1][0]
                z=[0]*n
                for i in range(n):
                    if x_sub1<=xy[i][0]<=x_sub2 and y_sub1<=xy[i][1]<=y_sub2:
                        z[i]=1
                if sum(z)>=k:
                    ans=min((x_sub2-x_sub1)*(y_sub2-y_sub1),ans)
                else:
                    break
print(ans)
### BUGGY CODE ###

X,Y,Z,K=map(int,input().split())

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

out=[]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)


for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if i*j*k<=k:
                out.append(A[i]+B[j]+C[k])

out.sort(reverse=True)

for i in range(K):
    print(out[i])


### FIXED CODE ###

X,Y,Z,K=map(int,input().split())
     
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
     
r=[]
out=[]
     
for i in range(X):
    for j in range(Y):
        r.append(A[i]+B[j])
     
r.sort(reverse=True)
     
if len(r)>K:
    for i in range(K):
        for j in range(Z):
            out.append(r[i]+C[j])
else:
    for i in range(len(r)):
        for j in range(Z):
           out.append(r[i]+C[j])
     
out.sort(reverse=True)
     
for i in range(K):
    print(out[i])
### BUGGY CODE ###

S = input() 
Q = int(input())

for i in range(Q):
    lists = input().split()
    if lists[0] == "1":
        S = S[::-1]
    elif lists[0] == "2":
        if lists[1] == "1":
            S = lists[2] + S
        elif lists[1] == "2":
            S = S + lists[2]

print(S)

### FIXED CODE ###

S = input() 
Q = int(input())
rlist, llist = [], []
flag, cnt = 0, 0

def trans(f):
    if f == 1:
        f = 0
    elif f == 0:
        f = 1
    return f

def pros(f, r, add):
    if f == 0:
        if r == "1":
            llist.append(lists[2])
        elif r == "2":
            rlist.append(lists[2])
    elif f == 1:
        if r == "2":
            llist.append(lists[2])
        elif r == "1":
            rlist.append(lists[2])

for i in range(Q):
    lists = input().split()
    if lists[0] == "1":
        flag = trans(flag)
        cnt += 1
    else:
        pros(flag, lists[1], lists[2])
        
llist.reverse()
        
S = "".join(llist) + S + "".join(rlist)

if cnt % 2 == 1:
    S = S[::-1]
print(S)
### BUGGY CODE ###

S = raw_input()
S = str(S)

counter = 0


while True:
    killer = 0

    killer += int(S.count('10'))
    S = S.replace('10','')

    killer += int(S.count('01'))
    S = S.replace('01','')

    counter += int(killer)

    if killer == 0:
        break
print counter * 2


### FIXED CODE ###

S = raw_input()
S = str(S)

S_1 = int(S.count('1'))
S_0 = int(S.count('0'))

if S_1 > S_0:
    print S_0 * 2
else:
    print S_1 * 2
### BUGGY CODE ###

n,m,q=map(int,input().split())
t=[[0 for i in range(n+1)] for j in range(n+1)]
s=[[0 for i in range(n+1)] for j in range(n+1)]

a=list()

for i in range(m):
  l,r=map(int,input().split())
  t[l][r] += 1

for i in range(1,n+1):
  for j in range(i,n+1):
    for x in range(i,j+1):
      for y in range(i,j+1): 
        s[i][j] += t[x][y]

for i in range(q):
  l,r=map(int,input().split())
  a.append(s[l][r])

for i in range(q):
  print(a[i])


### FIXED CODE ###

n,m,q=map(int,input().split())
s=[[0 for i in range(n+1)] for j in range(n+1)]

a=list()

for i in range(m):
  l,r=map(int,input().split())
  s[l][r] += 1

for i in range(1,n+1):
  for j in range(1,n+1):
    s[i][j] += s[i][j-1] 

for i in range(1,n+1):
  for j in range(1,n+1):
    s[j][i] += s[j-1][i]

for i in range(q):
  l,r=map(int,input().split())
  t = s[r][r] - s[l-1][r] - s[r][l-1] + s[l-1][l-1]
  a.append(t)

for i in range(q):
  print(a[i])
### BUGGY CODE ###

a,b,k=map(int,input().split())

for i in range(a,b+1):
    if i<a+k or i>b-k:
        print(i)

### FIXED CODE ###

a,b,k=map(int,input().split())
lst=[]
for i in range(a,a+k):
    if i>b:
        break
    lst.append(i)
    print(i)
for i in range(b-k+1,b+1):
    if i<a:
        continue
    if not i in lst:
        print(i)
### BUGGY CODE ###

def snuke_festival(N,arr):
    n_pair = 0
    for i in range(N):
        for j in range(N):
            if arr[0][i] < arr[1][j]:
                for k in range(N):
                    if arr[1][j] < arr[2][k]:
                        n_pair += 1
    return n_pair


if __name__ == "__main__":
    N  =int(input())
    arr = []
    for i in range(3):
        arr.append(list(map(int,input().split())))

    print(snuke_festival(N,arr))

### FIXED CODE ###

import bisect

def snuke_festival(N,arr):
    n_pair = 0
    for item in arr[1]:
        up_pair = bisect.bisect_left(arr[0],item)
        down_pair = bisect.bisect_right(arr[2],item)
        n_pair += up_pair*(N-down_pair)
    return n_pair


if __name__ == "__main__":
    N  =int(input())
    arr = []
    for i in range(3):
        arr.append(list(map(int,input().split())))
    arr_sorted = []
    for j in range(3):
        arr_sorted.append(arr[j].sort())
    print(snuke_festival(N,arr))