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

s=input()
count_1=0
l=[]
num =int(input())


for x in range(num):
    i=input().rstrip().split()
    if i[0]=="1":
        count_1+=1
        
    elif i[1]=="1" and count_1%2==0:
        s=i[2]+s
   
    elif i[1]=="1" and count_1%2==1:
        s=s+i[2]

    elif i[1]=="2" and count_1%2==0:
        s=s+i[2]

    elif i[1]=="2" and count_1%2==1:
        s=i[2]+s

if count_1%2==1:
    s=s[::-1]
print(s)

### FIXED CODE ###

s=input()
s1=""
s2=""
count_1=0
l=[]
num =int(input())
 
 
for x in range(num):
    i=input().rstrip().split()
    if i[0]=="1":
        count_1+=1
        
    elif i[1]=="1" and count_1%2==0:
        s1=i[2]+s1
   
    elif i[1]=="1" and count_1%2==1:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==0:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==1:
        s1=i[2]+s1
s=s1+s+s2
 
if count_1%2==1:
    s=s[::-1]
print(s)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
import itertools

def main():
    K,S = map(int, input().split())
    n = 0
    for i in range(K+1):
        if i + 2*K < S:
            continue
        for j in range(K+1):
            if i+j +K < S:
                continue
            for k in range(K+1):
                if i+j+k == S:
                    n += 1
    print(n)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input=sys.stdin.readline

def main():
    K,S = map(int, input().split())
    n = 0
    for i in range(K+1):
        for j in range(K+1):
            if S-i-j >= 0 and S-i-j <= K:
                n += 1
    print(n)

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

def main():
    s = input()
    q = int(input())
    qus = [tuple(map(str, input().split())) for _ in range(q)]
    for qu in qus:
        if len(qu) == 1:
            s = s[::-1]
        else:
            if qu[1] == '1':
                s = qu[2] + s
            else:
                s = s + qu[2]

    print(s)
main()

### FIXED CODE ###

def main():
    s = input()
    q = int(input())
    jun = True
    mae = ""
    ushiro = ""
    for _ in range(q):
        qu = input()
        if qu == '1':
            jun = not jun
        else:
            if qu[2] == '1':
                if jun:
                    mae = qu[4] + mae
                else:
                    ushiro = ushiro + qu[4]
            else:
                if jun:
                    ushiro = ushiro + qu[4]
                else:
                    mae = qu[4] + mae
    s = mae + s + ushiro
    if not jun:
        s = s[::-1]
    print(s)
main()
### BUGGY CODE ###

import itertools
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
s = SR(n)

name_h = tuple([name[0] for name in s if name[0] in {'M', 'A', 'R', 'C', 'H'}])

ans = list(itertools.combinations(name_h, 3))
ans = len([a for a in ans if len(set(a)) == 3])

print(ans)


### FIXED CODE ###

from collections import defaultdict
from itertools import combinations
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
s = SR(n)
d = defaultdict(int)
for c in ['M', 'A', 'R', 'C', 'H']:
    d[c] = 0
for name in s:
    if name[0] in {'M', 'A', 'R', 'C', 'H'}:
        d[name[0]] += 1
combs = list(combinations(['M', 'A', 'R', 'C', 'H'], 3))

ans = 0
for c in combs:
    ans += d[c[0]] * d[c[1]] * d[c[2]]
print(ans)
### BUGGY CODE ###

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


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


a = make_divisors(A)
b = make_divisors(B)
L = []
for x in a:
    if x in b:
        L.append(x)

ans = 0
for l in L:
    flag = False
    for i in range(2, l):
        if l % i == 0:
            flag = True
            break
    if flag:
        continue
    ans += 1

print(ans)

### FIXED CODE ###

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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 is_prime(p):
    if p == 1:
        return False
    for i in range(2, int(p ** 0.5) + 1):
        if p % i == 0:
            return False
    return True


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

g = gcd(A, B)
d = make_divisors(g)

ans = 1
for i in d:
    if is_prime(i):
        ans += 1

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

def main():
    H = int(input())
    n = 1
    ans = 0
    a = 1
    while a == 1:
        H = H // 2
        n += 1
        if H == 1:
            break
    print(2 ** n - 1)
main()


### FIXED CODE ###

def main():
    H = int(input())
    n = 1
    ans = 0
    a = 1
    while H != 1:
        H = H // 2
        n += 1
    print(2 ** n - 1)
main()
### BUGGY CODE ###

import heapq

N = int(input())
place = []
d = {}
j = 0
for i in range(N):
    x, y = map(int, input().split())
    place.append((x,y))
    if not (x,y) in d:
        d[(x,y)] = j
        j += 1
N = j

sort_x = sorted(place)
sort_y = sorted(place, key = lambda k:k[1])

edge=[[] for i in range(N)]
flag = False
for x,y in sort_x:
    now = d[(x,y)]
    if flag:
        edge[before].append([x-before_x,now])
        edge[now].append([x-before_x,d[(before_x,before_y)]])
    else:
        flag = True
    before_x = x
    before_y = y
    before = now

flag = False
for x,y in sort_y:
    now = d[(x,y)]
    if flag:
        edge[before].append([y-before_y,now])
        edge[now].append([y-before_y,before])
    else:
        flag = True
    before_x = x
    before_y = y
    before = now

used = [True]*N
edgelist = []
for e in edge[0]:
    heapq.heappush(edgelist,e)
used[0] = False
res = 0

while len(edgelist) != 0:
    minedge = heapq.heappop(edgelist)
    if not used[minedge[1]]:
            continue
    v = minedge[1]
    used[v] = False
    for e in edge[v]:
        if used[e[1]]:
            heapq.heappush(edgelist,e)
    res += minedge[0]

print(res)

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N = int(input())
xy = []
uf = UnionFind(N)
d = {}
j = 0
for i in range(N):
    x, y = map(int, input().split())
    if not (x,y) in d:
        d[(x,y)] = j
        xy.append((x,y))
        j += 1
N = len(xy)

xy = sorted(xy, key = lambda x:x[0])

root = []
for i in range(N-1):
    before_x, before_y = xy[i]
    x, y = xy[i+1]
    root.append((d[xy[i]],d[xy[i+1]],x - before_x))

xy = sorted(xy, key = lambda x:x[1])

for i in range(N-1):
    before_x, before_y = xy[i]
    x, y = xy[i+1]
    root.append((d[xy[i]],d[xy[i+1]],y - before_y))

root = sorted(root, key = lambda x:x[2])

ans = 0
for s,g,c in root:
    if uf.same(s,g):
        continue
    else:
        uf.union(s,g)
        ans += c

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

# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wv, wlimit):
    dp = [[0] * (wlimit + 1) for _ in range(n + 1)]
    for i, (wi, vi) in enumerate(wv):
        for w in range(wlimit + 1):
            w_ = w - wi
            v_ = dp[i][w] if w_ < 0 else dp[i][w_] + vi
            dp[i + 1][w] = max(dp[i][w], v_)
    return(dp[-1][-1])

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5
wv = [list(map(int, input().rstrip().split())) for _ in range(n)]

print(f(n, wv, w))


### FIXED CODE ###

# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, wlimit):
    dp = [-1] * (wlimit + 1)
    dp[0] = 0
    for i in range(1, n + 1):
        wi, vi = map(int, input().rstrip().split())
        dp_ = list(dp)
        for w in range(wlimit + 1):
            if dp[w] >= 0:
                w_ = w + wi
                v_ = dp[w] + vi
                if w_ <= wlimit and dp[w_] < v_:
                    dp_[w_] = v_
        dp = dp_
    return(max(dp))

n, w = map(int, input().rstrip().split()) # 1 <= n <= 100, 1 <= w <= 10^5

print(f(n, w))
### BUGGY CODE ###

def compare(a, A):
    R=0
    for i in range(0, len(A)):
        if(a==A[i]):
            R+=1

    if(R==a):
        return 0
    elif(a<R):
        return R-a
    return R

N = int(input())

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

R=0
R+=compare(a[0],a)

for i in range(1, N):
    if(a[i] != a[i-1]):
        R+=compare(a[i],a)

print(R)

### FIXED CODE ###

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

a.sort()
a.append(0)

T=[]
j=0
t=0
s=0
for i in range(N):
    j+=1
    if a[i] != a[i+1]:
        if j-s > a[i]:
            t+=(j-s)-a[i]
        elif j-s < a[i]:
            t += j-s
        s=j

print(t)
### BUGGY CODE ###

X = int(input())
Y = 0
while Y == 0:
  Y = 1
  for i in range(2,X-1):
    Y = Y * (X % i)
  X += 1
print(X-1)

### FIXED CODE ###

X = int(input())
Y = 0
while Y == 0:
  Y = 1
  for i in range(2,int(X*0.5+1)):
    Y = Y * (X % i)
  X += 1
print(X-1)
### BUGGY CODE ###

def main():
    from fractions import gcd
    import sys
    input = sys.stdin.readline
    n=int(input())
    a = tuple(map(int, input().split()))
    ans = a[0]

    mmm=10**9+7
    for i in a[1:]:
        ans = ans *i // gcd(ans, i)

    result=0
    for item in a:
      result+=ans//item

    print(result%mmm)

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    from fractions import gcd
    import sys
    n=int(input())
    a = tuple(map(int, input().split()))
    ans = 1

    mmm=10**9+7
    for i in a:
        ans = ans *i // gcd(ans, i)

    result=0
    for item in a:
      result+=ans//item

    print(result%mmm)

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

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7

def f():
    n = int(input())
    a = list(map(int, input().split()))
    b = [0]*n
    for _ in range(n):
        b[a[_]-1] = _
    r = (b[0]+1) * (n-b[0])
    c = [b[0]]
    m = 2
    for i in b[1:]:
        ri = bisect.bisect(c, i)
        if ri == 0:
            r += (i+1) * (c[ri]-i) * m
        elif ri == m-1:
            r += (i-c[ri-1]) * (n-i) * m
        else:
            r += (i-c[ri-1]) * (c[ri]-i) * m
        m += 1
        bisect.insort(c, i)

    return r

print(f())


### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7

def f():
    n = int(input())
    a = list(map(int, input().split()))
    l = list(range(n+2))
    r = list(range(n+2))
    b = [0]*(n+2)
    for i, x in enumerate(a, 1):
        b[x] = i
    c = 0
    for i in range(n,0,-1):
        bi = b[i]
        c += i * (r[bi] - bi + 1) * (bi - l[bi] + 1)
        r[l[bi]-1] = r[bi]
        l[r[bi]+1] = l[bi]
    return c

print(f())
### BUGGY CODE ###

import sys
 
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
 
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return sys.stdin.readline()[:-1]
 
def main():
    n = II()
    s = S()
    inf = n + 2
    m = [[0 for i in range(n)] for i in range(n)]
    first = [[inf for i in range(n)] for i in range(n)]
    # set 1st index value
    lcs = 0
    for i, c in enumerate(s):
        # print(c, s[0])
        if c == s[0]:
            m[i][0] = 1
            first[i][0] = i
            if i != 0:
                lcs = 1
    for i in range(1, n):
        for j in range(1, n):
            if i <= j:
                continue
            if s[i] == s[j]:
                if first[i-1][j-1] > j:
                    m[i][j] = m[i-1][j-1] + 1
                    lcs = max(m[i][j], lcs)
                    if first[i-1][j-1] == inf:
                        first[i][j] = i
                    else:
                        first[i][j] = first[i-1][j-1]
            else:
                m[i][j] = 0
 
    # print(m)
    print(lcs)
 
 
if __name__ == '__main__':
    main()

### FIXED CODE ###


import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return sys.stdin.readline()[:-1]

def main():
    n = II()
    s = S()
    inf = n + 2
    m = [[0 for i in range(n)] for i in range(n)]
    first = [[inf for i in range(n)] for i in range(n)]
    # set 1st index value
    lcs = 0
    for i, c in enumerate(s):
        # print(c, s[0])
        if c == s[0]:
            m[i][0] = 1
            first[i][0] = i
            if i != 0:
                lcs = 1
    for i in range(1, n):
        for j in range(1, n):
            if i <= j:
                continue
            if s[i] == s[j]:
                if first[i-1][j-1] > j:
                    m[i][j] = m[i-1][j-1] + 1
                    lcs = max(m[i][j], lcs)
                    if first[i-1][j-1] == inf:
                        first[i][j] = i
                    else:
                        first[i][j] = first[i-1][j-1]
            else:
                m[i][j] = 0

    # print(m)
    print(lcs)


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

ans = input()
n = int(input())
vec = 1
for i in range(n):
    query = input()
    if query == "1":
        vec *= -1
    else:
        _,option,str = query.split()
        if ((option == "1") and (vec == 1)) or ((option == "2") and (vec == -1)):
            ans = str + ans
        else:
            ans += str
if vec == -1:
    ans = ans[::-1]
print(ans)

### FIXED CODE ###

from collections import deque

def main():
    ans = deque(input())
    n = int(input())
    vec = 1
    for i in range(n):
        q = input()
        if q == "1":
            vec *= -1
        else:
            _,o,s = q.split()
            if ((o == "1") and (vec == 1)) or ((o == "2") and (vec == -1)):
                ans.appendleft(s)
            else:
                ans.append(s)
    if vec == -1:
        ans.reverse()
    ans = ''.join(ans)
    print(ans)

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

def main():
    st = input()
    q = int(input())

    for _ in range(q):
        try:
            t, f, a = input().split()
            if f == '1':
                st = a + st
            else:
                st = st + a
        except:
            st = st[::-1]

    print(st)

main()

### FIXED CODE ###

def string():
    s = input()
    q = int(input())
    l = ''
    r = ''
    re = False
    for _ in range(q):
        t = input().split()
        if t[0] == '1':
            re = not re
        else:
            if re:
                if t[1] == '1':
                    r = r + t[2]
                else:
                    l = t[2] + l
            else:
                if t[1] == '1':
                    l = t[2] + l
                else:
                    r = r + t[2]
    s = l + s + r
    if re:
        s = s[::-1]
    print(s)
string()
### BUGGY CODE ###

import sys
N = int(input())
A = list(map(int, sys.stdin.readline().split()))

ans = 1
flag = True
for a in A:
    ans *= a
    if ans > 10 ** 18:
        flag = False
    else:
        flag = True

if flag:
    print(ans)
else:
    print(-1)
        

### FIXED CODE ###

import sys
N = int(input())
A = sorted(list(map(int, sys.stdin.readline().split())))

ans = 1
flag = True
flag_zero = False
for a in A:
    ans *= a
    if ans > 10 ** 18:
        flag = False
        break
    if a == 0:
        flag_zero = True
        break

if flag:
    if not flag_zero:
        print(ans)
    else:
        print(0)
else:
    print(-1)
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
max_sum = sum(a)
for i in range(m):
    b, c = map(int, input().split())
    for j in range(b):
        if c > a[j]:
            a[j] = c
        else:
            break

    a.sort()
    if sum(a) > max_sum:
        max_sum = sum(a)

print(max_sum)


### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
BC_LIST.sort(reverse=True, key=lambda x: x[1])  # C降順にソート
for b, c in BC_LIST:
    for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break
print(sum(A_LIST))
### BUGGY CODE ###

from collections import Counter
 
def flatten(array):
    return [item for sublist in array for item in sublist]

n, x, y = map(int, input().split())
c = [[10**4]*n for i in range(n)]
for i in range(n):
    c[i-1][i] = 1
    c[i][i-1] = 1
c[-1][0] = 10**4
c[0][-1] = 10**4
c[x-1][y-1] = 1
c[y-1][x-1] = 1
 
for k in range(n):
    for i in range(n):
        for j in range(n):
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])
            c[j][j]=0

p = sorted(Counter(flatten(c)).items(), key=lambda x: x[0])[1:]
t = 0
for _, cnt in p:
    print(cnt // 2)
for _ in range(n-1-len(p)):
    print(0)

### FIXED CODE ###

#!/usr/bin/env python3
n, x, y = map(int, input().split())
a = abs
d = [0] * n
for i in range(1, n+1):
    for j in range(i + 1, n+1):
        d[min(j-i, a(x-i)+a(y-j)+1, a(x-j)+a(y-i)+1)] += 1
print(*d[1:], sep="\n")
### BUGGY CODE ###

from itertools import combinations


trash = input()
nums = [int(i) for i in input().split(" ")]

s = 0
for pair in combinations(nums, 2):
    s += pair[0] ^ pair[1]
print(s % (10**9+7))

### FIXED CODE ###

import itertools


N = int(input())
nums = [int(i) for i in input().split(" ")]
longest = len(bin(max(nums))) - 2
nums_bin = [format(i, "b").zfill(longest) for i in nums]


result = 0
for index, numbers in enumerate(zip(*nums_bin)):
    i = longest - index - 1
    zero = numbers.count("0")
    one = N - zero
    result += (2 ** i) * (zero * one)
print(result % (10 ** 9 + 7))
### BUGGY CODE ###

N, W = map(int, input().split())
inputs = [[int(i) for i in input().split()] for _ in range(N)]

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for n in range(1, N+1):
    weight, value = inputs[n-1][0], inputs[n-1][1]
    tmp_dp = [0 for _ in range(W+1)]
    for w in range(W+1):
        if w - weight >= 0:
            tmp_dp[w] = max(dp[n-1][w], dp[n-1][w-weight] + value)
        else:
            tmp_dp[w] = dp[n-1][w]
    dp[n] = tmp_dp

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


### FIXED CODE ###

import numpy as np

N, W = map(int, input().split())
inputs = np.array([np.array([int(i) for i in input().split()]) for _ in range(N)])

dp = np.zeros(W+1, dtype=np.int64)
for n in range(1, N+1):
    weight, value = inputs[n-1][0], inputs[n-1][1]
    dp[weight:] = np.maximum(dp[weight:], dp[:-weight] + value)

print(dp[-1])
### BUGGY CODE ###

from itertools import product
n = int(input())
s = input()
ans = 0
for p in product([0,1], repeat=2*n):
    if p.count(1) != p.count(0):
        continue
    left = right = ""
    for j in range(2*n):
        if p[j]:
            left += s[j]
        else:
            right += s[j]
    right = right[-1::-1]
    if left == right:
        ans += 1
print(ans)


### FIXED CODE ###

from itertools import product
from collections import defaultdict
n = int(input())
s = input()
sa, sb = s[:n], s[n:][::-1]
a, b, ans = defaultdict(int), defaultdict(int), 0
for p in product(range(2), repeat=n):
    word_a_1, word_b_1, word_a_2, word_b_2 = "", "", "", ""
    for j in range(n):
        if p[j]:
            word_a_1 += sa[j]
            word_b_1 += sb[j]
        else:
            word_a_2 += sa[j]
            word_b_2 += sb[j]
    a[(word_a_1, word_a_2)] += 1
    b[(word_b_1, word_b_2)] += 1
while a:
    key, value = a.popitem()
    ans += value * b[key]
print(ans)
### BUGGY CODE ###

L,R = list(map(int, input().split()))


MOD=[0] * (2019*2019)

def myidx(i,j):
    return i * 2019 + j

for i in range(2019):
    for j in range(2019):
        idx = myidx(i,j)
        MOD[idx] = (i*j) % 2019

for i in range(2019):
    idx = myidx(i,i)
    MOD[idx] = 2019

MMM = []
Lmod = L % 2019
Rmod = R % 2019

if L+2019 <= R:
    for i in range(2019):
        for j in range(i+1,2019):
            idx = myidx(i,j)
            MMM.append(MOD[idx])
elif Lmod <= Rmod:
    for i in range(Lmod, Rmod+1):
        for j in range(i+1, Rmod+1):
            idx = myidx(i,j)
            MMM.append(MOD[idx])

elif Lmod > Rmod:
    for i in list(range(0,Rmod+1)) + list(range(Lmod, 2019)):
        for j in list(range(i+1,Rmod+1)) + list(range(i+1, 2019)):
            idx = myidx(i,j)
            MMM.append(MOD[idx])

MMM=list(set(MMM))
MMM.sort()
print(MMM.pop(0))


### FIXED CODE ###

L,R = list(map(int, input().split()))

MOD=[0] * (2019*2019)

def myidx(i,j):
    return i * 2019 + j

for i in range(2019):
    for j in range(i+1,2019):
        idx = myidx(i,j)
        MOD[idx] = (i*j) % 2019

#for i in range(2019):
#    idx = myidx(i,i)
#    MOD[idx] = 2019

MMM = []
MIN = 2019
Lmod = L % 2019
Rmod = R % 2019

if L+2019 <= R:
    for i in range(2019):
        for j in range(i+1,2019):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])
elif Lmod <= Rmod:
    for i in range(Lmod, Rmod+1):
        for j in range(i+1, Rmod+1):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])

elif Lmod > Rmod:
    for i in list(range(0,Rmod+1)) + list(range(Lmod, 2019)):
        for j in list(range(i+1,Rmod+1)) + list(range(max(Lmod,i+1), 2019)):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])

#MMM=list(set(MMM))
#MMM.sort()
#print(MMM.pop(0))
print(MIN)
### BUGGY CODE ###

n=int(input())
A=sorted([int(i) for i in input().split()])
B=sorted([int(i) for i in input().split()])
C=sorted([int(i) for i in input().split()])
a=[]
b=[]
for i in range(n):
    for j in range(n):
        if A[i]<B[j]:
            a.append(n-j)
            break
    else:
        a.append(0)
for i in range(n):
    for j in range(n):
        if B[i]<C[j]:
            b.append(n-j)
            break
    else:
        b.append(0)
#print(a)
#print(b)
ans=0
for i in range(n):
    if a[i]!=0:
        for j in range(n-a[i],n):
            ans+=b[j]
#            print(ans)
print(ans)

### FIXED CODE ###

import bisect
n=int(input())
abc=[sorted(list(int(i) for i in input().split())) for i in range(3)]
print(sum([bisect.bisect_left(abc[0],b)*(n-bisect.bisect_right(abc[2],b)) for b in abc[1]]))