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

S, Q = input(), int(input())
rev = False
for _ in range(Q):
  a = input().split(' ')
  if a[0] == '1':
    rev = not rev
  else:
    if (rev and a[1] == '1') or (not rev and a[1] != '1'):
      S = S + a[2]
    else:
      S = a[2] + S
if rev:
  print(S[::-1])
else:
  print(S)

### FIXED CODE ###

S, Q = input(), int(input())
rev = False
st = []
ed = []
for _ in range(Q):
  a = input().split(' ')
  if a[0] == '1':
    rev = not rev
    continue
  if not rev:
    if a[1] == '1':
      st.append(a[2])
    else:
      ed.append(a[2])
  else:
    if a[1] == '1':
      ed.append(a[2])
    else:
      st.append(a[2])
if rev:
  print(''.join(reversed(ed)) + S[::-1] + ''.join(st))
else:
  print(''.join(reversed(st)) + S + ''.join(ed))
### BUGGY CODE ###

import itertools,heapq
INFTY = 10**8
N,M,R = map(int,input().split())
R = list(map(int,input().split()))
G = {}
for _ in range(M):
    A,B,C = map(int,input().split())
    if A not in G:
        G[A] = []
    G[A].append((B,C))
    if B not in G:
        G[B] = []
    G[B].append((A,C))
D = [[INFTY for j in range(N+1)] for i in range(N+1)]
for i in range(1,N+1):
    hist = [0 for _ in range(N+1)]
    heap = [(0,i)]
    while heap:
        cur = heapq.heappop(heap)
        if hist[cur[1]]==0:
            hist[cur[1]] = 1
            for x in G[cur[1]]:
                if hist[x[0]]==0:
                    if D[i][x[0]]>cur[0]+x[1]:
                        D[i][x[0]] = cur[0]+x[1]
                        heapq.heappush(heap,(D[i][x[0]],x[0]))
dmin = INFTY
for r in itertools.permutations(R,len(R)):
    d = 0
    for i in range(1,len(r)):
        d += D[r[i]][r[i-1]]
    dmin = min(dmin,d)
print(dmin)

### FIXED CODE ###

from itertools import permutations
INFTY = 10**8
N,M,R = map(int,input().split())
A = list(map(int,input().split()))
G = {i:[] for i in range(1,N+1)}
for _ in range(M):
    a,b,c = map(int,input().split())
    G[a].append((b,c))
    G[b].append((a,c))
d = {i:[INFTY for _ in range(N+1)] for i in range(N+1)}
for i in G:
    d[i][i] = 0
    for x in G[i]:
        d[i][x[0]] = x[1] 
for k in range(1,N+1):
    for i in range(1,N+1):
        for j in range(1,N+1):
            d[i][j] = min(d[i][j],d[i][k]+d[k][j])
dmin = INFTY
for x in permutations(range(R),R):
    cnt = 0
    for i in range(R-1):
        cnt += d[A[x[i]]][A[x[i+1]]]
    dmin = min(dmin,cnt)
print(dmin)
### BUGGY CODE ###

while True:
    n = int(input())
    if n == 0:
        break
    inp = []
    for i in range(n):
        inp.append(list(input()))
    ans = 0
    for i in range(n):
        p = [(x, y) for x in range(n - i) for y in range(n - i)]
        for x, y in p:
            if inp[y][x] == ".":
                pp = [(xx, yy) for xx in range(x, x + i + 1) for yy in range(y, y + i + 1)]
                for xx, yy in pp:
                    if inp[yy][xx] == "*":
                        break
                else:
                    ans = i + 1
                    break
        else:
            continue
    print(ans)



### FIXED CODE ###

while True:
    n = int(input())
    if n == 0:
        break
    inp = []
    for i in range(n):
        inp.append(list(input()))
    
    sq_max = [[0 for i in range(n + 1)] for j in range(n + 1)]
    
    for y in range(n):
        for x in range(n):
            if inp[y][x] == ".":
                sq_max[y + 1][x + 1] = min(sq_max[y][x + 1], sq_max[y + 1][x], sq_max[y][x]) + 1
            else:
                sq_max[y + 1][x + 1] = 0
    ans = max(map(max, sq_max))
    print(ans)
### BUGGY CODE ###

import collections

n = int(input())
a = list(map(int, input().split()))
c_lst = []
c = collections.Counter(a)
for i in c.most_common()[::-1]:
    if i[1] >= 2:
        c_lst.append(list(i))
if c_lst:
    values, counts = zip(*c_lst)
else:
    values = []

cnt = 0
for i in range(len(c_lst)):
    cnt += (c_lst[i][1] * (c_lst[i][1] - 1)) // 2
    
for i in a:
    ans = 0
    if i in values:
        c_lst[values.index(i)][1] -= 1
        for k in range(len(c_lst)):
            if c_lst[k][1] >= 2:
                ans += (c_lst[k][1] * (c_lst[k][1] - 1)) // 2
        c_lst[values.index(i)][1] += 1
    else:
        ans = cnt
    print(ans)

### FIXED CODE ###

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

def set(a, b, d):
  if D[a][b] == -1 or D[a][b] > d:
    D[a][b] = d
    R[a].append(b)
  if D[b][a] == -1 or D[b][a] > d:
    D[b][a] = d
    R[b].append(a)

N = int(input())
xy = [[i] + list(map(int, input().split())) for i in range(N)]
M = 10 ** 20
R = [[] for _ in range(N)]
D = [[-1] * N for _ in range(N)]
xy.sort(key = lambda x: x[1])
for i in range(1, N):
  a = xy[i]
  b = xy[i - 1]
  d = abs(a[1] - b[1])
  set(a[0], b[0], d)
xy.sort(key = lambda x: x[2])
for i in range(1, N):
  a = xy[i]
  b = xy[i - 1]
  d = abs(a[2] - b[2])
  set(a[0], b[0], d)

import heapq
q = [[0, 0]]
L = [True] * N
pop = heapq.heappop
push = heapq.heappush
ans = 0

for _ in range(N):
  k, t = pop(q)
  while not L[t]:
    k, t = pop(q)
  L[t] = False
  ans += k
  for i in R[t]:
    if L[i]:
      push(q, [D[t][i], i])
print(ans)


### FIXED CODE ###

def set(a, b):
  R[a].append(b)
  R[b].append(a)

N = int(input())
xy = [[i] + list(map(int, input().split())) for i in range(N)]
R = [[] for _ in range(N)]
xy.sort(key = lambda x: x[1])
for i in range(1, N):
  a = xy[i]
  b = xy[i - 1]
  set(a[0], b[0])
xy.sort(key = lambda x: x[2])
for i in range(1, N):
  a = xy[i]
  b = xy[i - 1]
  set(a[0], b[0])

xy.sort()
import heapq
q = [[0, 0]]
L = [True] * N
pop = heapq.heappop
push = heapq.heappush
ans = 0

for _ in range(N):
  k, t = pop(q)
  while not L[t]:
    k, t = pop(q)
  L[t] = False
  ans += k
  for i in R[t]:
    if L[i]:
      x = abs(xy[t][1] - xy[i][1])
      x = min(x, abs(xy[t][2] - xy[i][2]))
      push(q, [x, i])
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))  # 1-indexed


journey = [1]  # 道順

for i in range(2**n):
    nxt = a[journey[-1]]
    journey.append(nxt)

if k <= n:
    print(journey[k])
    exit()

# k > n
loop_end = n

loop_start = n - 1  # ループの始まりのindex

while(journey[loop_start] != journey[loop_end]):
    loop_start -= 1

period = loop_end - loop_start

k %= period

while k < n:
    k += period
    
print(journey[k])
    

### FIXED CODE ###

from collections import defaultdict

n, k = map(int, input().split())
*a, = map(int, input().split())
a = [a[i] - 1 for i in range(n)]
ans = 0

if k <= n:
    i = 0
    while(k > 0):
        ans = a[i]
        i = a[i]
        k -= 1
        # print(ans + 1)
    ans += 1

else:
    # 周期の場所をチェック
    start_period = 1
    period_i = -1
    d = defaultdict(int)
    d[0] = 1
    i = 0
    count = 1
    while(1):
        # print(f'i = {i}, count = {count}')
        if a[i] in d.keys():
            period_i = count
            start_period = d[a[i]]
            break

        d[a[i]] = count + 1
        i = a[i]
        count += 1
        
    # 逆引き
    d_r = {i:k for k, i in d.items()}
    # print('d: ', d)
    # print('d_r: ', d_r)
    # print('period_i:', period_i)
    # print('start_period:', start_period)
    # print(f'{k - (start_period - 1)}')
    # print(f'{(k - (start_period - 1)) % (period_i - start_period + 1)}')
    # print('d_r[start_period]: ', d_r[start_period])
    # print(d_r[start_period + ((k - (start_period - 1)) % (period_i - start_period + 1))])
    ans = d_r[start_period + ((k - (start_period - 1)) % (period_i - start_period + 1))] + 1
    
    
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
m = max(a)
c = [0] * (m + 1)

for ai in a:
    for i in range(ai, m + 1, ai):
        if i in a:
            c[i] += 1

print(c.count(1))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
m = a[-1]
c = [0] * (m + 1)

for ai in a:
    for i in range(ai, m + 1, ai):
        c[i] += 1

ans = 0
for ai in a:
    if c[ai] == 1:
        ans += c[ai]

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

from functools import lru_cache


a = int(input())
b = input()

@lru_cache(maxsize=None)
def func(c):
    c = [int(z) for z in c]
    x = int(sum(c))
    if x == 0:
        return 0
    n = 1
    nsum = 0
    for i in reversed(c):
        nsum += n * i
        n = n % x if n > x else n
        if n == 0:
            break
        n *= 2
    nsum %= x
    cans = bin(nsum).count("1")
    if cans == 0:
        return 1
    else:
        return 1 + func(bin(nsum)[2:])




for i in range(a):
    ran = list(b)
    ran[i] = "0" if ran[i] == "1" else "1"
    c = "".join(ran)
    print(func(c))

### FIXED CODE ###

from functools import lru_cache


a = int(input())
b = input()
X = b.count("1")
ans1 = []
ans2 = []

@lru_cache(maxsize=None)
def func1(c):
    x = X + 1
    n = 1
    nsum = 0
    for i in reversed(range(len(c))):
        ans1.append(n)
        nsum += n * int(c[i])
        n = n % x if n > x else n
        n *= 2
    return nsum
    
@lru_cache(maxsize=None)
def func2(c):
    x = X - 1
    if x == 0:
        return 0
    n = 1
    nsum = 0
    for i in reversed(range(len(c))):
        ans2.append(n)
        nsum += n * int(c[i])
        n = n % x if n > x else n
        n *= 2
    return nsum    

def func(c):
    x = c.count("1")
    if x == 0:
        return 0
    n = 1
    nsum = 0
    for i in reversed(range(len(c))):
        nsum += n * int(c[i])
        n = n % x if n > x else n
        if n == 0:
            break
        n *= 2
    nsum %= x
    cans = bin(nsum).count("1")
    if cans == 0:
        return 1
    else:
        return 1 + func(bin(nsum)[2:])
    
allans1 = func1(b)
allans2 = func2(b)
ans1 = ans1[::-1]
if allans2 == 0:
    ans2 = [0] * a
else:
    ans2 = ans2[::-1]

c = list(b)
for i in range(a):
    if c[i] == "0":
        ans = (allans1 + ans1[i]) % (X + 1)
        ans = func(bin(ans)[2:]) + 1
        print(str(ans))
    else:
        if allans2 - ans2[i] == 0 and X - 1 == 0:
            print("0")
        else:
            ans = (allans2 - ans2[i]) % (X - 1)
            ans = func(bin(ans)[2:]) + 1
            print(str(ans))
### BUGGY CODE ###

from bisect import bisect_left
import numpy as np
def main():
    N, M, K = map(int, input().split())
    A = np.array([0] + list(map(int, input().split())), dtype=np.int64)
    B = np.array([0] + list(map(int, input().split())), dtype=np.int64)

    As = np.cumsum(A)
    Bs = np.cumsum(B)

    count = 0
    Amax = bisect_left(As, K+1)
    Bmax = bisect_left(Bs, K+1)

    for i in range(Amax):
        j = M
        while As[i] + Bs[j] > K:
            j -= 1
        count = max(count, (i+j))

    print(count)

if __name__ == '__main__':
    main()

### FIXED CODE ###

from bisect import bisect_right
import numpy as np
def main():
    N, M, K = map(int, input().split())
    A = np.array([0] + list(map(int, input().split())), dtype=np.int64)
    B = np.array([0] + list(map(int, input().split())), dtype=np.int64)

    As = np.cumsum(A)
    Bs = np.cumsum(B)

    count = 0

    for i, a in enumerate(As):
        if a > K:
            break
        j = bisect_right(Bs, K-a)
        #print(f"i={i} j={j} Bs={Bs} cost={K-a}")
        count = max(count, (i+j-1))

    print(count)

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

import sys
INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))
sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    H = LIST()

    D = ""
    for i in range(N-1):
        if H[i] >= H[i+1]: D += "o"
        else: D += "x"

    ans = 0
    for i in range(1, N):
        if "o"*i in D: ans += 1
        else: break

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))
sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    H = LIST()

    D = [0]
    idx = 0
    for i in range(N-1):
        if H[i] >= H[i+1]: D[idx] += 1
        else:
            idx += 1
            D.append(0)

    print(max(D))


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

a,b = map(int,input().split())
if a==b:
  print(a)
else:
  ans = a
  for i in range(a+1,b+1):
    ans = ans^i
  print(ans)

### FIXED CODE ###

a,b = map(int,input().split())
if a==b:
  print(a)
else:
  ans = a
  if b-a<10**7:
    for i in range(a+1,b+1):
      ans = ans^i
    print(ans)
  else:
    if a%2==0:
      if (b-a)%4==1:
        print(1)
      elif (b-a)%4==2:
        print(b+1)
      elif (b-a)%4==3:
        print(0)
      else:
        print(b)
    else:
      if (b-a)%4==1:
        print(a^b)
      elif (b-a)%4==2:
        print(a-1)
      elif (b-a)%4==3:
        print((a-1)^b)
      else:
        print(a)
### BUGGY CODE ###

from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
next_step = [0] * N
memo = [-1] * (2*10**5)
cnt = 0
for i, a in enumerate(A+A):
    if memo[a-1] >= 0:
        if next_step[memo[a-1]%N]:
            continue
        next_step[memo[a-1]] = i - memo[a-1] + 1
        cnt += 1
    if cnt == N:
        break
    memo[a-1] = i

j = 0
while True:
    if j + next_step[j%N] < N*K:
        j += next_step[j%N]
        if j%N == 0:
            j = max(j, N*K//j*j)
    else:
        break

q = deque()
for k in range(j, N*K):
    a = A[k%N]
    if a not in q:
        q.append(a)
    else:
        while a in q:
            q.pop()

print(*q)


### FIXED CODE ###

from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
next_step = [0] * N
memo = [-1] * (2*10**5)
cnt = 0
for i, a in enumerate(A+A):
    if memo[a-1] >= 0:
        if next_step[memo[a-1]%N]:
            continue
        next_step[memo[a-1]%N] = i - memo[a-1] + 1
        if next_step[memo[a-1]%N] == 0:
            pass
        cnt += 1
    if cnt == N:
        break
    memo[a-1] = i

j = 0
while True:
    if j + next_step[j%N] < N*K:
        j += next_step[j%N]
        if j%N == 0:
            j = max(j, N*K//j*j)
    else:
        break

q = deque()
memo = [-1] * (2*10**5)
cnt = 0
for k in range(j, N*K):
    a = A[k%N]
    if memo[a-1] < 0:
        q.append(a)
        memo[a-1] = cnt
        cnt += 1
    else:
        while True:
            b = q.pop()
            memo[b-1] = -1
            if b == a:
                break

print(*q)
### BUGGY CODE ###

import math
import bisect

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

XH=[[0,0] for _ in range(N)]
for i in range(N):
    x,h=map(int,input().split())
    XH[i][0]=x
    XH[i][1]=h
    
XH.sort()

X=[0]*N
H=[0]*N
for i in range(N):
    X[i]=XH[i][0]
    H[i]=XH[i][1]


#bの倍数の中でaを超える最小
def calc(a,b):
    return math.ceil(a/b)*b

ans=0
for i in range(N):
    if H[i]>0:
        bom=X[i]+D
        Lb=i
        Rb=bisect.bisect_right(X,bom+D)
        ans+=H[i]//A
        if H[i]%A!=0:
            ans+=1
        dam=calc(H[i],A)
        for j in range(Lb,Rb):
            H[j]-=dam
        
print(ans)
    
    
    
    




### FIXED CODE ###

import math
import bisect
import sys
input = sys.stdin.readline

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

XH=[[0,0] for _ in range(N)]
for i in range(N):
    x,h=map(int,input().split())
    XH[i][0]=x
    XH[i][1]=h
    
XH.sort()

X=[0]*N
for i in range(N):
    X[i]=XH[i][0]



ans=0
S=[0]*(N+1)#累積和


for i in range(N):
    if S[i]<XH[i][1]:
        bom=X[i]+D
        Lb=i
        Rb=bisect.bisect_right(X,bom+D)
        num=(XH[i][1]-S[i])//A
        if (XH[i][1]-S[i])%A!=0:
            num+=1
        ans+=num
        dam=num*A
        #imosで遅延
        S[Lb]+=dam
        S[Rb]-=dam
    S[i+1]+=S[i]
        
print(ans)
### BUGGY CODE ###

import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    r, c, k = ns()

    mat = [[0] * (c + 1) for __ in range(r + 1)]
    for _ in range(k):
        x, y, v = ns()
        x, y = x - 1, y - 1
        mat[x][y] = v

    dp = [[[0] * 4 for _ in range(c + 1)] for __ in range(r + 1)]

    for i in range(r):
        for j in range(c):
            for n in range(2, -1, -1):
                dp[i][j][n + 1] = max(dp[i][j][n + 1], dp[i][j][n] + mat[i][j])

            dp[i + 1][j][0] = max(dp[i][j])
            for n in range(4):
                dp[i][j + 1][n] = max(dp[i][j + 1][n], dp[i][j][n])

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


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    r, c, k = ns()

    mat = [[0 for _ in range(c + 1)] for __ in range(r + 1)]
    for _ in range(k):
        x, y, v = ns()
        x, y = x - 1, y - 1
        mat[x][y] = v

    dp = [[0] * 4 for _ in range(c + 1)]

    for i in range(r):
        ndp = [[0] * 4 for _ in range(c + 1)]
        for j in range(c):
            for n in range(2, -1, -1):
                dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j])

            ndp[j][0] = max(dp[j])
            for n in range(4):
                dp[j + 1][n] = max(dp[j + 1][n], dp[j][n])
        dp = ndp

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


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

target_str = "AC"

N, Q = map(int, input().split()) 
S = input().strip()

target_list = [0 for i in range(N)]

for i in range(N - 1):
  if S[i: i + 2] == target_str:
    target_list[i] = 1

for i in range(Q):
  l, r = map(int, input().split()) 
  print(sum(target_list[l - 1: r - 1]))

### FIXED CODE ###

target_str = "AC"

N, Q = map(int, input().split()) 
S = input().strip()

cumsum_list = [0 for i in range(N)]

cnt = 0
for i in range(N - 1):
  if S[i: i + 2] == target_str:
    cnt += 1
  cumsum_list[i] = cnt
cumsum_list.insert(0, 0)
cumsum_list.insert(0, 0)


for i in range(Q):
  l, r = map(int, input().split()) 
  print(cumsum_list[r] - cumsum_list[l])
### BUGGY CODE ###

def factorial(n):
    a = 1
    for i in range(1, n + 1):
        a *= i
    return a

def nCr(n,r):
    if r > n:
        return 0
    return factorial(n) // factorial(r) // factorial(n - r)

def nC2(n):
    if n < 2:
        return 0
    else:
        return n * (n-1) // 2


####
N = int(input())
sorted_dic = {}
for i in range(N):
    s = "".join(sorted(input()))
    v = 0
    if s in sorted_dic:
        v = sorted_dic[s]
    sorted_dic[s] = v + 1

ans = 0
for k in sorted_dic:
    v = sorted_dic[k]
    #print(k,v,factorial(v),factorial(2), factorial(v - 2), nCr(v, 2))
    ans = ans + nCr(v, 2)

print(ans)

### FIXED CODE ###

def factorial(n):
    a = 1
    for i in range(1, n + 1):
        a *= i
    return a

def nCr(n,r):
    if r > n:
        return 0
    return factorial(n) // factorial(r) // factorial(n - r)

def nC2(n):
    if n < 2:
        return 0
    else:
        return n * (n-1) // 2


####
N = int(input())
sorted_dic = {}
for i in range(N):
    s = "".join(sorted(input()))
    v = 0
    if s in sorted_dic:
        v = sorted_dic[s]
    sorted_dic[s] = v + 1

ans = 0
for k in sorted_dic:
    v = sorted_dic[k]
    #print(k,v,factorial(v),factorial(2), factorial(v - 2), nCr(v, 2))
    ans = ans + nC2(v)

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

N = int(input())


def binary_search(L, target):
    """
    >>> binary_search([1,3,5],2)
    [3, 5]
    >>> binary_search([1,3,5],5)
    []
    >>> binary_search([1,3,5],9)
    []
    >>> binary_search([1,3,5],1)
    [3, 5]
    >>> binary_search([1,3,3,3,3,5],3)
    [5]
    """
    if L[0] > target:
        return L
    if L[-1] <= target:
        return []
    right_i = len(L) - 1
    left_i = 0
    j = 0
    while left_i + 1 != right_i and j != 10:
        j += 1
        med_i = (right_i + left_i) // 2
        if L[med_i] < target:
            left_i = med_i
        elif L[med_i] > target:
            right_i = med_i
        else:
            while L[med_i + 1] == target:
                med_i += 1
            return L[med_i + 1:]

    return L[right_i:]


D = []
for _ in range(3):
    D.append(list(map(int, input().split())))
A, B, C = D
A.sort()
B.sort()
C.sort()
ans = 0

for a in A:
    b_rest = binary_search(B, a)
    for b in b_rest:
        ans += len(binary_search(C, b))
print(ans)


### FIXED CODE ###

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


def hoge():
    count = 0
    Ai = -1
    Ci = -1
    for i in range(N):
        if Ai < N - 1:
            while A[Ai + 1] < B[i]:
                Ai += 1
                if Ai == N - 1:
                    break
        if Ci < N - 1:
            while C[Ci + 1] <= B[i]:
                Ci += 1
                if Ci == N - 1:
                    break
        count += (Ai + 1) * (N - (Ci + 1))
    return count


print(hoge())
### BUGGY CODE ###

h = int(input())

for i in range(10**12):
  h = h // 2
  if h == 1:
    break
    
#print(i+1)
ans = 0
for j in range(i+2):
  ans += 2**j
  
print(ans)

### FIXED CODE ###

h = int(input())

if h >= 2:
  for i in range(10**12):
    h = h // 2
    if h == 1:
      break
  ans = 0
  for j in range(i+2):
    ans += 2**j
  
  print(ans)
else:
  print(h)