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

from collections import deque

h,w = map(int,input().split())
s = [None]*h

for i in range(h):
    s[i] = input()

d = [[10000000 for i in range(w)] for j in range(h)]
sharp = 0

sx = []
sy = []
            
dx = [1,0,-1,0]
dy = [0,1,0,-1]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            sx.append(j)
            sy.append(i)
            d[i][j] = 0
            
            
def bfs():
    que = deque()
    ans = 0
    for i in range(len(sx)):
        que.append([sy[i],sx[i]])
    
    while que:
        y,x = que.popleft()
        
        for k in range(4):
            nx = x + dx[k]
            ny = y + dy[k]
            
            if 0<=nx and nx<w and 0<=ny and ny<h and d[ny][nx] == 10000000:
                if d[ny][nx] > d[y][x]+1:
                    d[ny][nx] = d[y][x]+1
                    que.append([ny,nx])
                    
                    if d[ny][nx] > ans:
                        ans = d[ny][nx]
    
    print(ans)
        
bfs()

### FIXED CODE ###

from collections import deque
 
h,w = map(int,input().split())
s = [None]*h
 
for i in range(h):
    s[i] = input()
 
d = [[10000000 for i in range(w)] for j in range(h)]
sharp = 0
 
sx = []
sy = []
            
dx = [1,0,-1,0]
dy = [0,1,0,-1]
 
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            sx.append(j)
            sy.append(i)
            d[i][j] = 0
            
            
def bfs():
    que = deque()
    ans = 0
    for i in range(len(sx)):
        que.append([sy[i],sx[i]])
    
    while que:
        y,x = que.popleft()
        
        for k in range(4):
            nx = x + dx[k]
            ny = y + dy[k]
            
            if 0<=nx and nx<w and 0<=ny and ny<h and d[ny][nx] == 10000000:
                if d[ny][nx] > d[y][x]+1:
                    d[ny][nx] = d[y][x]+1
                    que.append([ny,nx])
                    
                    if d[ny][nx] > ans:
                        ans = d[ny][nx]
    
    print(ans)
        
bfs()
### BUGGY CODE ###

import fractions
from functools import reduce

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

l = []
for i in range(n):
    a_except_for_i = a[:i] + a[i + 1:]
    l.append(reduce(fractions.gcd, a_except_for_i))
print(max(l))

### FIXED CODE ###

import fractions
from functools import reduce

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

l = [0]
r = [0]
for i in range(n):
    l.append(fractions.gcd(l[i], a[i]))
    r.append(fractions.gcd(r[i], a[-(i + 1)]))

m = [fractions.gcd(l[i], r[-(i + 2)]) for i in range(n)]
print(max(m))
### BUGGY CODE ###

from math import log,floor
N = int(input())
A = list(map(int, input().split()))

# log(10**9 + 10**9)/log(2) = 30.89 < 31
#print(log(2 * 10**9) / log(2))

A.sort(reverse=True)
usedI = [0] * N
cnt = 0

for i in range(N):
  if usedI[i] == 1:
    continue
  #print(i, log(A[i]) / log(2) )
  x = floor(log(A[i]) / log(2)) + 1 #実現可能なべき上
  search_x = 2 ** x - A[i]
  for j in range(i+1,N):
    if search_x == A[j]:
      if usedI[j] == 1:
        continue
      else:
        cnt += 1
        usedI[i] = 1
        usedI[j] = 1
        break
    elif search_x > A[j]:
      break

print(cnt)
    

### FIXED CODE ###

from math import log,floor
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
C = Counter(A)

cnt = 0
last_a = -1
for i in range(N):
  a = A[i]
  if last_a == a:
    continue
  last_a = a
  count_a = C[a]
  if count_a <= 0:
    continue
  b = pow(2,floor(log(a)/log(2))+1) - a
  count_b = C[b]
  if count_b <= 0:
    continue
  i += count_a - 1
  x = min(count_a, count_b) if a != b else count_a // 2
  cnt += x
  C[a] -= x
  C[b] -= x
  
print(cnt)
### BUGGY CODE ###

from collections import deque

n,m = map(int,input().split())

g = {i:set() for i in range(n+1)}

for i in range(m):
    a,b = map(int,input().split())
    g[a].add(b)
    g[b].add(a)
    
seen = {i:0 for i in range(n+1)}
seen[0]=1
seen[1]=1
q = deque()
q.append(1)
grpsize=1

while 0 in seen.values():
    if len(q)>0:
        now = q.popleft()
        nextp = g[now]
        for i in nextp:
            if seen[i]==0:
                q.append(i)
                grpsize+=1
                seen[i]=grpsize
        
    else:
        for i in range(1,n+1):
            if seen[i]==0:
                grpsize=1
                seen[i]=grpsize
                q.append(i)
                break
                
print(max(seen.values()))

### FIXED CODE ###

from sys import setrecursionlimit

def find(par,i):
    if par[i]<0:
        return i
    par[i] = find(par,par[i])
    return par[i]

def unite(par,i,j):
    ri = find(par,i)
    rj = find(par, j)
    if ri==rj:
        return
    par[rj] += par[ri]
    par[ri] = rj
    
setrecursionlimit(10**6)
n,m = map(int,input().split())

parent = [-1]*n
for _ in range(m):
    a,b = map(lambda x:int(x)-1,input().split())
    unite(parent,a,b)
    
print(-min(parent))
### BUGGY CODE ###

from collections import defaultdict
def main():
    s = list(input())
    n = len(s)
    for i in range(n):
        s[i] = int(s[i])
    dp = [0 for _ in range(2019)]
    dp[0] += 1
    x = 0
    for i in range(n):
        x = (x+s[n-1-i]*(10**i))%2019
        dp[x%2019] += 1
    ans = 0
    for i in range(2019):
        ans += (dp[i]*(dp[i]-1))//2
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    s = input()
    n = len(s)
    dp = [0 for _ in range(2019)]
    dp[0] += 1
    x = 0
    for i in range(n):
        x = (x+int(s[n-1-i])*pow(10,i,2019))%2019
        dp[x] += 1
    ans = 0
    for i in range(2019):
        ans += (dp[i]*(dp[i]-1))//2
    print(ans)

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

N = int(input())

def count_n(n):
    ans = 0
    for x in range(1,int(N**0.5)+1):
        if 6*x**2 == n:
            ans = 1
            return ans
        for y in range(1,int(N**0.5)+1):
                if (3*x**2 + y**2 + 2*x*y)  == n:
                    ans += 3
                    return ans
    return ans

for i in range(1,N+1):
    print(count_n(i))

### FIXED CODE ###

n = int(input())
a = [0]*(n+1)
for i in range(1, 102):
    for j in range(1, 102):
        for k in range(1, 102):
            if (i*i + j*j + k*k + i*j + j*k + i*k) <= n:
                a[i*i + j*j + k*k + i*j + j*k + i*k] +=1
                
for x in a[1:]:
    print(x)
### BUGGY CODE ###

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

judge = [1]*N
for i in range(N):
  for j in range(i):
    if P[i] > P[j]:
      judge[i] = 0
      break
print(judge.count(1))

### FIXED CODE ###

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

ans = 1
tmp = P[0]
for i in range(1,N):
  if P[i] <= tmp:
    ans+=1
    tmp = P[i]
print(ans)
### BUGGY CODE ###

import itertools
N=int(input())
st=list(input())
count=0
cnt=0
num=["0","1","2","3","4","5","6","7","8","9"]

num_list=p = ["".join(i) for i in itertools.product(num,repeat=3)]
for number in num_list:
    mark = 0
    for i in range(N):
        if cnt==0 and number[0]==st[i]:
            mark=i
            cnt+=1
        if cnt==1 and number[1]==st[i] and i>mark:
            cnt+=1
            mark=i
        if cnt==2 and number[2]==st[i] and i>mark:
            cnt+=1
            break
    if cnt==3:
        count+=1
    cnt=0
print(count)

### FIXED CODE ###

def main():
  N = int(input())
  S = list(map(int,input()))
  ans = 0
  for i in range(10):
    for j in range(10):
      for k in range(10):
        flg = False
        flg2 = False
        for x in range(N):
          if flg2:
            break
          if not flg:
            if S[x] == i:
              flg = True
          else:
            if S[x] == j:
              flg2 = True
              if k in S[x+1:]:
                ans +=1
  print(ans)
main()
### BUGGY CODE ###

import math
n = int(input())
s = input()

cnt = 0

for i in range(1, n+1):
    for j in range(i+1, n+1):
        for k in range(j+1, n+1):
            if (s[i-1] != s[j-1]) and (s[i-1] != s[k-1])\
                    and (s[j-1] != s[k-1]) and j-i != k-j:
                cnt += 1
print(cnt)


### FIXED CODE ###

n = int(input())
s = list(input())

cnt = s.count("R")*s.count("G")*s.count("B")
for i in range(0, n):
    for j in range(i+1, n):
        k = 2*j - i
        if s[i] == s[j] or k >= n or s[k] == s[i] or s[k] == s[j]:
            continue
        else:
            cnt -= 1

print(cnt)
### BUGGY CODE ###

# def main():
#     N, Q = list(map(int, input().split()))
#     parents = [[] for i in range(N+1)]
#     ans = [0] * (N+1)

#     for i in range(N-1):
#         a, b = list(map(int, input().split()))
#         parents[b].append(a)

#     for i in range(Q):
#         p, x = list(map(int, input().split()))
#         ans[p] += x

#     print(parents[1:])

#     for i in range(1, N+1):
#         for p in parents[i]:
#             ans[i] += ans[p]

#     print(*ans[1:])

import queue


def main():
    N, Q = map(int, input().split())
    tree = [[] for i in range(N+1)]
    ans = [0] * (N+1)
    visit = [False]*(N+1)

    for i in range(N-1):
        a, b = map(int, input().split())
        tree[a].append(b)
        tree[b].append(a)

    for i in range(Q):
        p, x = map(int, input().split())
        ans[p] += x

    q = queue.Queue()
    q.put(1)
    visit[1] = True

    while (not q.empty()):
        n = q.get()
        # print(tree[n])
        for i in tree[n]:
            if visit[i] is False:
                ans[i] += ans[n]
                # print(i, '+=', n)
                visit[i] = True
                q.put(i)

    print(*ans[1:])


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import queue
input = sys.stdin.readline
N, Q = map(int, input().split())
 
tree = [[] for i in range(N+1)]
values = [0] * (N+1)
visit = [False]*(N+1)
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
 
for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x
 
 
q = queue.Queue()
q.put(1)
visit[1] = True
while (not q.empty()):
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            values[next] += values[now]
            visit[next] = True
            q.put(next)
 
values = values[1:]
print(" ".join(map(str, values)))
### BUGGY CODE ###

# Between a and b ...
a, b, x = map(int, input().split())
count = 0

for i in range(a, b+1):
    if i % x == 0:
        count = count +1
    else:
        pass
print(count)

### FIXED CODE ###

# Between a and b ...

a, b, x = map(int, input().split())
c = a // x
if a == 0:
    ans = (b // x) + 1
else:
    ans = (b // x) - ((a - 1) // x )
print(ans)
### 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()))
def do(): 
    n,m,k=INTM()
    A=LIST()
    B=LIST()
    As=[0]*(n+1)
    Bs=[0]*(m+1)
    ans=0
    for i in range(n):
        As[i+1]=As[i]+A[i]
    A=As
    for i in range(m):
        Bs[i+1]=Bs[i]+B[i]
    B=Bs
    #print(A,B)

    if A[-1]+B[-1]<=k:
        ans=n+m

    for i in range(n+1):

        if A[i]>k:
            #print(i)
            temp=i-1
            ans=max(ans,temp)
            break
        for i2 in range(m+1):
            #print(i,i2)
            #print(A[i]+B[i2])
            if A[i]+B[i2]>k:
                temp=i+i2-1
                #print(ans,temp)
                ans=max(ans,temp)
                break
        

    
    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()))
def do(): 
    n,m,k=INTM()
    A=LIST()
    B=LIST()
    As=[0]*(n+1)
    Bs=[0]*(m+1)
    ans=0
    for i in range(n):
        As[i+1]=As[i]+A[i]
    A=As
    for i in range(m):
        Bs[i+1]=Bs[i]+B[i]
    B=Bs
    #print(A,B)

    if A[-1]+B[-1]<=k:
        ans=n+m

    b_s=m

    for i in range(n+1):

        if A[i]>k:
            #print(i)
            temp=i-1
            ans=max(ans,temp)
            break
        for i2 in range(b_s,-1,-1):
            #print(i,i2)
            #print(A[i]+B[i2])
            if A[i]+B[i2]<=k:
                temp=i+i2
                b_s=i2
                #print(ans,temp)
                ans=max(ans,temp)
                break
        

    
    print(ans)

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

s = input()
mul = set(str(2019*i) for i in range(1,100))
ans = 0

for i in range(len(s)-3):
  p = 4
  while i+p<=len(s):
    if s[i:i+p] in mul:
      ans += 1
    p += 1

print(ans)

### FIXED CODE ###

S = input()[::-1]
ans = 0
mods = [0] * 2019
mods[0] = 1
current = 0
x = 1
for s in S:
  current = (current + x * int(s)) % 2019
  ans += mods[current % 2019]
  mods[current % 2019] += 1
  x = x * 10 % 2019
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N = int(input())
T0 = list(map(int, input().split()))
V = list(map(int, input().split()))

INF = 1000
def main():
    Tmax = 0
    T = [0]
    for t in T0:
        Tmax += t
        T.append(Tmax)

    preh = 0
    ans = 0
    for t0 in range(2*Tmax+1):
        t = t0/2
        height = INF
        for n in range(-1, N+1):
            if n == -1:
                t1, t2, v = -1, 0, 0
            elif n == N:
                t1, t2, v = Tmax, Tmax+1, 0
            else:
                t1, t2, v = T[n], T[n+1], V[n]
            
            if t < t1:
                y = v + t1 - t
            elif t1 <= t <= t2:
                y = v
            else:
                y = v + t - t2
            height = min(height, y)
        
        ans += (preh + height)*0.5/2
        preh = height
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
T0 = list(map(int, input().split()))
V = list(map(int, input().split()))

INF = 1000
def main():
    Tmax = 0
    T = [0]
    for t in T0:
        Tmax += t
        T.append(Tmax)

    preh = 0
    ans = 0
    for t0 in range(2*Tmax+1):
        t = t0/2
        height = INF
        for n in range(-1, N+1):
            if n == -1:
                t1, t2, v = -1, 0, 0
            elif n == N:
                t1, t2, v = Tmax, Tmax+1, 0
            else:
                t1, t2, v = T[n], T[n+1], V[n]
            
            if t < t1:
                y = v + t1 - t
            elif t1 <= t <= t2:
                y = v
            else:
                y = v + t - t2
            height = min(height, y)
        
        ans += (preh + height)*0.5/2
        preh = height
    print(ans)

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

# -*- coding: utf-8 -*-
import copy

N = int(input())
H = list(map(int, input().split()))
H_bak = copy.copy(H)

while H != sorted(H):
    for i in range(N-1):
        while H[i] > H[i+1]:
            H[i] -= 1

if all([abs(H[i]-H_bak[i]) < 2 for i in range(N)]):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

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

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

m = 0
ans = "Yes"
for i in range(N):
    if m - H[i] > 1:
        ans = "No"
        break
    m = max(m, H[i])

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

A, B, K = map(int, input().split())
integer_list = [i for i in range(A, B+1)]
res_list = sorted(list(set(integer_list[:K]) | set(integer_list[-K:])))
for i in res_list:
    print(i)


### FIXED CODE ###

A, B, K = map(int, input().split())
if B-A+1 >= 2*K:
    res_set = set([i for i in range(A, A+K)]) | set([i for i in range(B-K+1, B+1)])
    for i in sorted(res_set):
        print(i)
else:
    res_list = [i for i in range(A, B+1)]
    for i in res_list:
        print(i)
### BUGGY CODE ###

mod = 10 ** 9 + 7

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

def combinations_count(n, r):
    return factorial(n) % mod // (factorial(n - r) % mod * factorial(r) % mod)

x, y = map(int,  input().split())

if (x + y) % 3 != 0:
    print(0)
else:
    n = (2 * y - x) // 3
    m = (2 * x - y) // 3
    comb_num = combinations_count(n+m, n)
    print(comb_num)

### FIXED CODE ###

mod = 10 ** 9 + 7
x, y = map(int,  input().split())

def nCm_mod(A, B, mod):
    mul_one = 1
    mul_two = 1

    for i in range(B):
        mul_one *= A - i
        mul_two *= i + 1
        mul_one %= mod
        mul_two %= mod
    
    return (mul_one * pow(mul_two, mod-2, mod)) % mod

n = (2 * y - x) // 3
m = (2 * x - y) // 3

if (x + y) % 3 != 0 or n < 0 or m < 0:
    print(0)
else:
    comb_num = nCm_mod(n+m, min(n,m), mod)
    print(comb_num)
### BUGGY CODE ###

from collections import*
from itertools import*
n,c=map(int,input().split())
cost=[list(map(int,input().split()))for i in range(c)]
grid=[list(map(int,input().split()))for i in range(n)]
d=defaultdict(list)
for i in range(1,n+1):
    for j in range(1,n+1):
        d[(i+j)%3].append(grid[i-1][j-1]-1)
ans=[]
for cmb in permutations(range(c),3):
    ans.append(sum(sum(cost[i][cmb[dindex]]for i in d[dindex])for dindex in range(3)))
print(min(ans))

### FIXED CODE ###

from itertools import*
n,c=map(int,input().split())
cost=[list(map(int,input().split()))for i in range(c)]
d=[[0]*c for i in range(3)]
for i in range(n):
    for j,v in enumerate(map(int,input().split())):
        d[(i+j)%3][v-1]+=1
print(min(sum(cost[j][cmb[i]]*d[i][j]for j in range(c)for i in range(3))for cmb in permutations(range(c),3)))
### BUGGY CODE ###

from collections import defaultdict

h, w, m = map(int, input().split())

row_dict = defaultdict(int)
col_dict = defaultdict(int)
row_col_dict = defaultdict(list)
for _ in range(m):
    row, col = map(int, input().split())
    row_dict[row] += 1
    col_dict[col] += 1
    row_col_dict[row].append(col)

max_row = max(row_dict.values())
max_col = max(col_dict.values())

max_rows = [k for k, v in row_dict.items() if v == max_row]
max_cols = [k for k, v in col_dict.items() if v == max_col]
ans = max_row + max_col - 1
flg = False
for row in max_rows:
    for col in max_cols:
        if not col in row_col_dict[row]:
            ans += 1
            flg = True
            break
    if flg:
        break

print(ans)


### FIXED CODE ###

from collections import defaultdict

h, w, m = map(int, input().split())

row_dict = defaultdict(int)
col_dict = defaultdict(int)
row_col_dict = defaultdict(set)
for _ in range(m):
    row, col = map(int, input().split())
    row_dict[row] += 1
    col_dict[col] += 1
    row_col_dict[row].add(col)

max_row = max(row_dict.values())
max_col = max(col_dict.values())

max_rows = [k for k, v in row_dict.items() if v == max_row]
max_cols = [k for k, v in col_dict.items() if v == max_col]
ans = max_row + max_col - 1
flg = False
if ans < m:
    for row in max_rows:
        for col in max_cols:
            if not col in row_col_dict[row]:
                ans += 1
                flg = True
                break
        if flg:
            break

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

a,b=map(int,input().split())
def lcm(x, y):
 
   if x > y:
       greater = x
   else:
       greater = y
 
   while(True):
       if((greater % x == 0) and (greater % y == 0)):
           lcm = greater
           break
       greater += 1
 
   return lcm
 
print(lcm(a,b))

### FIXED CODE ###

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

def NonRecursiveGcd(x,y):
 
    while(y):
        x , y = y , x % y
    return x 
def computeLcmWithNonRecursiveGcd(x,y):
    
    lcm = (x*y)//NonRecursiveGcd(x,y)
    
    return lcm  
print(computeLcmWithNonRecursiveGcd(a,b))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
INF = 1000000007
ans = 0
keta = len(bin(max(A)))-2
shift = 0
while(shift < keta):
    c1 = 0
    c0 = 0
    for a in A:
        if a>>shift &1:
            c1 += 1
        else:
            c0 += 1
    ans += c1 * c0 * 2**shift
    shift += 1
print(ans % INF)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
INF = 1000000007
keta = len(bin(max(A))) - 2
ans = 0
shift = 0
for _ in range(keta):
    num_1 = 0
    for a in A:
        if a>>shift&1:
            num_1 += 1
    ans += num_1 * (N-num_1) * 2 ** shift
    shift += 1
print(ans % INF)
### BUGGY CODE ###

def main():
    h,W = map(int,input().split())
    c = [tuple(input()) for _ in range(h)]
    c = tuple(c)
    ans = 0
    w = [0 for _ in range((h+1)**2)]
    dp = [0 for _ in range((h+1)**2)]
    for j in range(W-1):
        for x in range(h+1):
            for y in range(h+1):
                if x == 0 or y == 0:
                    w[x*(h+1)+y] = 0
                    for z in range(h-max(x,y)):
                        if c[y+z][j] == c[x+z][j+1]:
                            w[x*(h+1)+y] += 1
                    if x == y:
                        dp[x*h+y] = 0
                    elif x == 0:
                        dp[x*(h+1)+y] = dp[x*(h+1)+y-1]+w[x*(h+1)+y-1]
                    else:
                        dp[x*(h+1)+y] = dp[(x-1)*(h+1)+y]+w[(x-1)*(h+1)+y]
                    continue
                w[x*(h+1)+y] = w[(x-1)*(h+1)+y-1]
                if c[h-x][j] == c[h-y][j+1]:
                    w[x*(h+1)+y] -= 1
                dp[x*(h+1)+y] = min(dp[x*(h+1)+y-1]+w[x*(h+1)+y-1],dp[(x-1)*(h+1)+y]+w[(x-1)*(h+1)+y])
        ans += dp[(h+1)**2-1]
    print(ans)
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
    h,W = map(int,input().split())
    c = [tuple(input()) for _ in range(h)]
    c = tuple(c)
    ans = 0
    w = [0 for _ in range((h+1)**2)]
    dp = [0 for _ in range((h+1)**2)]
    for j in range(W-1):
        for x in range(h,0,-1):
            for y in range(h,0,-1):
                w[(x-1)*(h+1)+y-1] = w[x*(h+1)+y]
                if c[h-x][j] == c[h-y][j+1]:
                    w[(x-1)*(h+1)+y-1] += 1
        for x in range(h+1):
            for y in range(h+1):
                if x == 0 or y == 0:
                    if x == y:
                        dp[x*h+y] = 0
                    elif x == 0:
                        dp[x*(h+1)+y] = dp[x*(h+1)+y-1]+w[x*(h+1)+y-1]
                    else:
                        dp[x*(h+1)+y] = dp[(x-1)*(h+1)+y]+w[(x-1)*(h+1)+y]
                    continue
                dp[x*(h+1)+y] = min(dp[x*(h+1)+y-1]+w[x*(h+1)+y-1],dp[(x-1)*(h+1)+y]+w[(x-1)*(h+1)+y])
        ans += dp[-1]
    print(ans)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

N = int(input())

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

A = sorted(A,reverse=True)
B = sorted(B,reverse=True)
C = sorted(C,reverse=True)

count = 0
for i in range(N):
    a = A[i]
    for j in range(N):
        b = B[j]
        if a >= b:
            #flag = True
            break
        for k in range(N):
            c = C[k]
            if b >= c:
                break
            #print(a,b,c)
            count += 1
print(count)


### FIXED CODE ###

def bs_left(A, target):
    low, high = 0, len(A)
    while low<high:
        mid = (low+high)//2
        if A[mid]<target:
            low = mid+1
        else:
            high = mid
    return low

def bs_right(C, target):
    low, high = 0, len(C)
    while low<high:
        mid = (low+high)//2
        if target<C[mid]:
            high = mid
        else:
            low = mid+1
    return low
if __name__ == '__main__':
    N = int(input())

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

    count = 0
    for i in range(N):
        b = B[i]
        count = count + bs_left(A,b) * (N - bs_right(C,b))
    print(count)