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

import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
#sys.stdin = open("input.txt", "r")
#sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


N=l()[0]
A=l()
ans=1
if(0 in A):
    ans=0
    print(ans)
    exit()
for i in range(N):
    ans*=A[i]
if(ans>10**18):
    ans=-1
print(ans)


### FIXED CODE ###

import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
#sys.stdin = open("input.txt", "r")
#sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


N=l()[0]
A=l()
ans=1
if(0 in A):
    ans=0
    print(ans)
    exit()
A.sort(reverse=True)
for i in range(N):
    ans*=A[i]
    if(ans>10**18):
        ans=-1
        break
print(ans)
### BUGGY CODE ###

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

import functools
import operator

result = functools.reduce(operator.mul, a)
if result>10**18:
    print(-1)
else:
    print(result)

### FIXED CODE ###

import sys
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
s=a[n-1]
if s==0:
    print(0)
else:
    for i in range(0,n-1):
        s*=a[i]
        if s>10**18:
            print(-1)
            sys.exit()
    print(s)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
for _ in range(M):
    A, B = map(int, input().split())
    G[A].append(B)

def dfs(v, o):
    for c in G[v]:
        if c == o:
            return [v]
    for c in G[v]:
        ret = dfs(c, o)
        if ret:
            return [v] + ret

for v in range(1, N+1):
    cur = dfs(v, v)
    if cur:
        break
else:
    print(-1)
    exit()

while True:
    cur_set = set(cur)
    unused = None
    for i in range(len(cur)):
        u, v = cur[i], cur[(i+1) % len(cur)]
        for c in G[u]:
            if c == v:
                continue
            elif c in cur_set:
                unused = (i, cur.index(c))
                break

    if not unused:
        break
    else:
        t, s = unused
        nxt = []
        i = s
        while i != t:
            nxt.append(cur[i])
            i = (i + 1) % len(cur)
        nxt.append(cur[t])
        cur = nxt

print(len(cur))
print(*cur, sep='\n')

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
for _ in range(M):
    A, B = map(int, input().split())
    G[A].append(B)

def dfs(v, o):
    for c in G[v]:
        if c == o:
            return [v]
    for c in G[v]:
        if visited[c]:
            continue
        visited[c] = True
        ret = dfs(c, o)
        if ret:
            return [v] + ret

for v in range(1, N+1):
    visited = [False] * (N+1)
    cur = dfs(v, v)
    if cur:
        break
else:
    print(-1)
    exit()

while True:
    cur_set = set(cur)
    unused = None
    for i in range(len(cur)):
        u, v = cur[i], cur[(i+1) % len(cur)]
        for c in G[u]:
            if c == v:
                continue
            elif c in cur_set:
                unused = (i, cur.index(c))
                break

    if not unused:
        break
    else:
        t, s = unused
        nxt = []
        i = s
        while i != t:
            nxt.append(cur[i])
            i = (i + 1) % len(cur)
        nxt.append(cur[t])
        cur = nxt

print(len(cur))
print(*cur, sep='\n')
### BUGGY CODE ###

n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
di={}
ti={}
for i in range(m):
  if t[i] not in ti:
    ti[t[i]]=1
  else:
    ti[t[i]]+=1
  if t[i] not in di:
    di[t[i]]=d.count(t[i])
for i in ti:
  if ti[i]>di[i]:
    print('NO')
    exit()
print('YES')

### FIXED CODE ###

n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
if n<m:
  print('NO')
  exit()
d.sort()
t.sort()
i=0
j=0
while i<n and j<m:
  if d[i]==t[j]:
    i+=1
    j+=1
  else:
    i+=1
if j==m:
  print('YES')
else:
  print('NO')
### BUGGY CODE ###

S = input().strip()
N = len(S)
K = int(input())
A = [ord(S[i]) for i in range(N)]
cnt = 0
a0 = 96
while True:
    amin = 1000
    for i in range(N):
        if a0<A[i]<=amin:
            amin = A[i]
    Ind = []
    for i in range(N):
        if A[i]==amin:
            Ind.append(i)
    a0 = amin
    B = []
    for i in Ind:
        for j in range(i,N):
            x = S[i:j+1]
            if x not in B:
                B.append(x)
    B = sorted(B)
    k = K-cnt
    if len(B)>=k:
        ans = B[k-1]
        break
    else:
        cnt += len(B)
print(ans)

### FIXED CODE ###

S = input().strip()
N = len(S)
K = int(input())
A = []
for k in range(1,min(6,N+1)):
    for i in range(N-k+1):
        x = S[i:i+k]
        if x not in A:
            A.append(x)
A = sorted(A)
print(A[K-1])
### BUGGY CODE ###

N = int(input())
A = [int(x) for x in input().split()]
ans = 0
index = 1
if min(A) != 1:
    print(-1)
else:
    for i in range(N):
        left = A.pop(0)
        if left == index:
            index += 1
        else:
            ans += 1
    print(ans)


### FIXED CODE ###

from collections import deque
N = int(input())
A = [int(x) for x in input().split()]
d = deque()
for i in range(N):
    d.append(A[i])
ans = 0
index = 1
if min(A) != 1:
    print(-1)
else:
    for i in range(N):
        left = d.popleft()
        if left == index:
            index += 1
        else:
            ans += 1
    print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
def inpl(): return map(int, input().split())

N, M = inpl()
G = [[] for _ in range(N+1)]
for _ in range(M):
    a, b = inpl()
    G[a].append(b)
    G[b].append(a)

searched = [False] * (N+1)

m = 1
searched[m] = True
ans = []

def dfs(c):
    searched[c] = True
    for d in G[c]:
        if not searched[d]:
            res = dfs(d)
            break
    else:
        res = []
    
    return res + [c]

L = dfs(1)
R = dfs(1)[-2::-1]

ans = L + R
print(len(ans))
print(*ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
def inpl(): return map(int, input().split())

N, M = inpl()
G = [[] for _ in range(N+1)]
for _ in range(M):
    a, b = inpl()
    G[a].append(b)
    G[b].append(a)

searched = [False] * (N+1)

m = 1
searched[m] = True

ans = []
def dfs(c):
    global ans
    searched[c] = True
    for d in G[c]:
        if not searched[d]:
            ans.append(c)
            dfs(d)
            break 
    else:
        ans.append(c)
    
dfs(1)
ans = ans[:0:-1]
dfs(1)

print(len(ans))
print(*ans)
### BUGGY CODE ###

#!/usr/bin/env pypy


def main():
    n, m = map(int, input().split())
    a = [int(input()) for _ in range(m)]
    diff_a = [a[i+1] - a[i] for i in range(m - 1)]
    if 1 in diff_a:
        print(0)
        return
    method = [0] * (n + 1)
    method[0] = 1
    if 1 not in a:
        method[1] = 1
    for i in range(2, n + 1):
        if i in a:
            continue
        else:
            method[i] = method[i-1] + method[i-2]
            # method[i] %= 1000000007
    print(method[n] % 1000000007)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
A = list(map(int, readlines()))
assert len(A) == M

MOD = 10 ** 9 + 7


def solve():
    broken = [False] * (N + 1)
    for a in A:
        broken[a] = True
    p1, p2 = 1, 0
    for i in range(1, N + 1):
        if broken[i]:
            p1, p2 = 0, p1
        elif i == 1:
            p1, p2 = p1, p1
        else:
            p1, p2 = (p1 + p2) % MOD, p1
    return p1


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

#!/usr/bin/env python3
import sys

def solve(N: int, L: "List[int]", R: "List[int]"):
    LR= list(zip(L,R))
    LR.sort(key=lambda x:x[0])

    answer = 0
    for i in range(1,N):
        a = 0
        mi = 0
        ma = 10**9
        for lr in LR[:i]:
            mi = max(lr[0],mi)
            ma = min(lr[1],ma)
        a += ma-mi+1
        
        mi = 0
        ma = 10**9
        for lr in LR[i:]:
            mi = max(lr[0],mi)
            ma = min(lr[1],ma)
        a += ma-mi+1

        answer = max(a,answer)
    print(answer)
        
  
        



    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int()] * (N)  # type: "List[int]"
    R = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, L, R)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

def solve(N: int, L: "List[int]", R: "List[int]"):
    LR= list(zip(L,R))
    LR.sort(key=lambda x:x[0])

    r_left_max = [] ##index 以下のrightのmin
    for lr in LR:
        if r_left_max:
            r_left_max.append(min(r_left_max[-1],lr[1]))
        else:
            r_left_max.append(lr[1])

    r_right_max = []
    for lr in LR[::-1]:
        if r_right_max:
            r_right_max.append(min(r_right_max[-1],lr[1]))
        else:
            r_right_max.append(lr[1])

    answer = 0
    for i in range(1,N):
        a = 0
        a += max(r_left_max[i-1]-LR[i-1][0]+1,0)
        a += max(r_right_max[N-i-1]-LR[-1][0]+1,0)
        answer = max(a,answer)

    ## 一つとその他の場合。indexがiのものを一つにする
    for i in range(N):
        a =0 
        a+= LR[i][1]-LR[i][0]+1
        if i == N-1:
            min_upper_limit = r_left_max[N-2]
            a+= max(min_upper_limit-LR[N-2][0]+1,0)
        elif i == 0:
            min_upper_limit = r_right_max[N-2]
            a+= max(min_upper_limit-LR[-1][0]+1,0)
        else:
            min_upper_limit = min(r_left_max[i-1],r_right_max[N-i-2])

            a+= max(min_upper_limit-LR[-1][0]+1,0)

        answer = max(a,answer)
    
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int()] * (N)  # type: "List[int]"
    R = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, L, R)

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

N, K = map(int, input().split())
A = list(map(int, input().split()))
#N,K=5 ,3
#A=[96, 98, 95, 100, 20]
ten=[0]*(N-K+1)
a=1
for i in range(K):
    a*=A[i]
#print(a)   
ten[0]=a
for i in range(1,(N-K+1)):
    ten[i]=ten[i-1]*(A[K+i-1]/A[i-1])
#print(ten)
for i in range(1,N-K+1):
    #print(ten[i])
    if ten[i]>ten[i-1]:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

from decimal import Decimal
N, K = map(int, input().split())
A = list(map(int, input().split()))
#N,K=5 ,3
#A=[96, 98, 95, 100, 20]
ten=[0]*(N-K+1)
a=100000*(10**20)+0.1
#for i in range(K):
 #   a*=A[i]
#print(a)
#a=1
ten[0]=Decimal(a)
for i in range(1,(N-K+1)):
    ten[i]=Decimal(ten[i-1]*A[K+i-1]/A[i-1])
#print(ten)
for i in range(1,N-K+1):
    #print(ten[i])
    if ten[i]>ten[i-1]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import itertools
import numpy as np

m, n = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(m)]


val = 0
tmp_val = 0
x = 0
y = 0
z = 0
for i in itertools.combinations(range(len(c)), n):
    for j in i:
        x += c[j][0]
        y += c[j][1]
        z += c[j][2]
    tmp_val = abs(x)+abs(y)+abs(z)
    val = max(val, tmp_val)
    tmp_val = 0
    x = 0
    y = 0
    z = 0

print(val)


### FIXED CODE ###

m, n = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(m)]


val = 0
temp_list = []

for i in range(2**3):
    temp_list = []
    op = [-1] * 3
    for j in range(3):
        if ((i >> j) & 1):
            op[3 - 1 - j] = 1

    for k in range(m):
        temp_list.append((op[0]*c[k][0])+(op[1]*c[k][1])+(op[2]*c[k][2]))
        temp_list.sort(reverse=True)
    val = max(val, sum(temp_list[:n]))
print(val)
### BUGGY CODE ###

import heapq

# https://nashidos.hatenablog.com/entry/2020/04/07/100508
def dijkstra(s):
    hq = [(0, s)]
    heapq.heapify(hq) # リストを優先度付きキューに変換
    cost = [float('inf')] * ((maxsilver+1)*n) # 行ったことのないところはinf
    cost[s] = 0 # 開始地点は0
    while hq:
        c, v = heapq.heappop(hq)
        if c > cost[v]: # コストが現在のコストよりも高ければスルー
            continue
        for d, w in e[v]:
            tmp = d + cost[v]
            if tmp < cost[w]:
                cost[w] = tmp
                heapq.heappush(hq, (tmp, w))
    return cost

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

u,v,a,b = [0]*m,[0]*m,[0]*m,[0]*m 
c,d = [0]*n,[0]*n 
for i in range(m):
    u[i],v[i],a[i],b[i] = list(map(int,input().split()))
for i in range(n):
    c[i],d[i] = list(map(int,input().split()))

maA = max(a)
maxsilver = maA*(n-1)
p = (maxsilver+1) * n
# 都市i(0~)で銀貨j枚持っている時,i*(maxsilver+1)+j番目
e = [[] for i in range(p)]
# 金貨交換
for i in range(n):
    for j in range(maxsilver+1):
        e[i*(maxsilver+1) + j].append((d[i], i*(maxsilver+1) + min(j+c[i], maxsilver)))
# 移動
for i in range(m):
    for j in range(a[i],maxsilver+1):
        e[(u[i]-1)*(maxsilver+1) + j].append((b[i], (v[i]-1)*(maxsilver+1) + j-a[i]))
        e[(v[i]-1)*(maxsilver+1) + j].append((b[i], (u[i]-1)*(maxsilver+1) + j-a[i]))

# print(e)
# 初期地点は0+min(s,maxsilver)
for i in range(1,n):
    ans = float("inf")
    x = [0]*(maxsilver+1)
    for j in range(maxsilver+1):
        x[j] =  dijkstra(min(s,maxsilver))[i*(maxsilver+1)+j]
    heapq.heapify(x)
    ans = heapq.heappop(x)
    print(ans)

### FIXED CODE ###

import heapq

# https://nashidos.hatenablog.com/entry/2020/04/07/100508
def dijkstra(s):
    hq = [(0, s)]
    heapq.heapify(hq) # リストを優先度付きキューに変換
    cost = [float('inf')] * ((maxsilver+1)*n) # 行ったことのないところはinf
    cost[s] = 0 # 開始地点は0
    while hq:
        c, v = heapq.heappop(hq)
        if c > cost[v]: # コストが現在のコストよりも高ければスルー
            continue
        for d, w in e[v]:
            tmp = d + cost[v]
            if tmp < cost[w]:
                cost[w] = tmp
                heapq.heappush(hq, (tmp, w))
    return cost

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

u,v,a,b = [0]*m,[0]*m,[0]*m,[0]*m 
c,d = [0]*n,[0]*n 
for i in range(m):
    u[i],v[i],a[i],b[i] = list(map(int,input().split()))
for i in range(n):
    c[i],d[i] = list(map(int,input().split()))

maA = max(a)
maxsilver = maA*(n-1)
p = (maxsilver+1) * n
# 都市i(0~)で銀貨j枚持っている時,i*(maxsilver+1)+j番目
e = [[] for i in range(p)]
# 金貨交換
for i in range(n):
    for j in range(maxsilver+1):
        e[i*(maxsilver+1) + j].append((d[i], i*(maxsilver+1) + min(j+c[i], maxsilver)))
# 移動
for i in range(m):
    for j in range(a[i],maxsilver+1):
        e[(u[i]-1)*(maxsilver+1) + j].append((b[i], (v[i]-1)*(maxsilver+1) + j-a[i]))
        e[(v[i]-1)*(maxsilver+1) + j].append((b[i], (u[i]-1)*(maxsilver+1) + j-a[i]))

# print(e)
# 初期地点は0+min(s,maxsilver)
d = dijkstra(min(s,maxsilver))
for i in range(1,n):
    ans = float("inf")
    x = [0]*(maxsilver+1)
    for j in range(maxsilver+1):
        x[j] =  d[i*(maxsilver+1)+j]
    heapq.heapify(x)
    ans = heapq.heappop(x)
    print(ans)
### BUGGY CODE ###

import sys


scan = sys.stdin.readline


def main():
  n, m = map(int, scan().rstrip().split())
  a = list(map(int, scan().rstrip().split()))
  operations = [tuple(map(int, scan().rstrip().split())) for _ in range(m)]
  
  for b, c in operations:
    a.sort()
    count = 0
    while count < b and a[count] < c:
      a[count] = c
      count += 1
  
  print(sum(a))
  

if __name__ == "__main__":
  main()


### FIXED CODE ###

import sys
from operator import itemgetter
from collections import deque


scan = sys.stdin.readline


def main():
  n, m = map(int, scan().rstrip().split())
  a = list(map(int, scan().rstrip().split()))
  operations = [tuple(map(int, scan().rstrip().split())) for _ in range(m)]
  
  a.sort()
  operations.sort(key=itemgetter(1), reverse=True)
  
  a = deque(a)
  
  for b, c in operations:
    count = 0
    while count < b:
      if a[0] < c:
        a.append(c)
        count += 1
        a.popleft()
      else:
        print(sum(a))
        exit(0)

  print(sum(a))
  

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

n, m = map(int, input().split())
g = [[] for _ in range(n)] # 隣接リスト

for _ in range(m):
    a, b = [int(x) for x in input().split()]
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)

from collections import deque

def bfs(u):
    queue = deque([u])
    d = [None] * n # uからの距離の初期化
    d[u] = 0 # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                queue.append(i)
    return d

# 0からの各頂点の距離
d = bfs(0)
print('Yes')
for i in range(n - 1):
    print(d.index((d[i + 1]) - 1) + 1)

### FIXED CODE ###

n, m = map(int, input().split())
g = [[] for _ in range(n)] # 隣接リスト

for _ in range(m):
    a, b = [int(x) for x in input().split()]
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)

from collections import deque

def bfs(u):
    queue = deque([u])
    d = [None] * n # uからの距離の初期化
    d[u] = 0 # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = v
                queue.append(i)
    return d

# 0からの各頂点の距離
d = bfs(0)
print('Yes')
for i in range(1, n):
    print(d[i] + 1)
### BUGGY CODE ###

#!/usr/bin/env python

import sys

n,m = [ int(x) for x in sys.stdin.readline().split() ]
ai= [ int(x) for x in sys.stdin.readline().split() ]
#
for i in range(m):
    bi, ci= [ int(x) for x in sys.stdin.readline().split() ]
    ai+= [ci]*bi
#
ai.sort()
s= 0
j= len(ai)
for i in range(n):
    j-=1
    s+= ai[j]
print( s )


### FIXED CODE ###

#!/usr/bin/env python

import sys

n,m = [ int(x) for x in sys.stdin.readline().split() ]
k = dict()
for x in sys.stdin.readline().split():
    x = int(x)
    k[x]= k.get(x,0) + 1
#
for i in range(m):
    bi, ci= [ int(x) for x in sys.stdin.readline().split() ]
    k[ci]= k.get(ci,0) + bi
    #ai+= [ci]*bi
#
s = 0
rest= n
for val in sorted( k.keys(),reverse=True ):
    num = k[val]
    if rest>num:
        s+= num * val
        rest-= num
    else:
        s+= val * rest
        break
print( s )
### BUGGY CODE ###

N = int(input())
S = input()
ans = [0] * N

ans[0] = S[1:].count('E')
ans[-1] = S[:-1].count('W')
for i in range(1, N):
    ans[i] = S[:i].count('W') + S[i + 1:].count('E')

print(min(ans))

### FIXED CODE ###

N = int(input())
S = input()
E = [0] * N
W = [0] * N
ans = [0] * N

count = 0
for i in range(N):
    if S[i] == 'W':
        count += 1
        W[i] = count
    else:
        W[i] = count


count = 0
for i in reversed(range(N)):
    if S[i] == 'E':
        count += 1
        E[i] = count
    else:
        E[i] = count

ans[0] = E[1]
ans[-1] = W[-2]
for i in range(1, N - 1):
    ans[i] = W[i - 1] + E[i + 1]

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

import bisect

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()

ans = 0
mem_idx_a = {}
for idx_c in range(N):
  idx_b = bisect.bisect_left(B,C[idx_c])
  if idx_b == 0: continue
  for i in range(idx_b):
    if B[i] in mem_idx_a:
      idx_a = mem_idx_a[B[i]]
    else:
      idx_a = bisect.bisect_left(A,B[i])
      mem_idx_a[B[i]] = idx_a    
    ans += idx_a
print(ans)

### FIXED CODE ###

import bisect

N = int(input())

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

ans = 0
mem_idx_a = {}
for idx_b in range(N):
  idx_c = bisect.bisect_right(C,B[idx_b])
  idx_a = bisect.bisect_left(A,B[idx_b])
  ans += (N-idx_c)*idx_a
print(ans)
### BUGGY CODE ###

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

dp = [0]*N
for i in range(1,N):
    dp[i] = min(abs(H[i]-H[i-n]) + dp[i-n] for n in range(1,min(K+1,i+1)))

print(dp[-1])

### FIXED CODE ###

N,K = map(int,input().split())
H = tuple(map(int,input().split()))

dp = [0]

for i in range(1,N):
  h = H[i]
  dp.append(min(dp[j]+abs(H[j]-h) for j in range(max(i-K,0),i)))

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

N, K = map(int, input().split())
List = [int(input()) for _ in range(N)]

List = sorted(List)

tmp = 10**9
for i in range(N-K+1):
    lst = List[i:i+K]
    diff = max(lst)-min(lst)
    if diff<tmp:
        tmp = diff
print(tmp)

### FIXED CODE ###

N, K = map(int, input().split())
List = [int(input()) for _ in range(N)]

List = sorted(List)

tmp = 10**9
for i in range(N-K+1):
    diff = List[i+K-1]-List[i]
    if diff<tmp:
        tmp = diff
print(tmp)
### BUGGY CODE ###

import copy
import collections
import math

def combinations_count(n, r):
    if n <= 1:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = [int(i) for i in input().split()] 

maxnum = max(A)
lis = [-1] * maxnum
bigC = collections.Counter(A)
for i, a in enumerate(A):
  if lis[a-1] < 0:
    newA = copy.deepcopy(A)
    newA.pop(i)
    c = collections.Counter(newA)
    total = 0
    for idx in c:
      total += combinations_count(c[idx], 2)
      
    lis[a-1] = total
    for x in bigC:
      if bigC[x] == bigC[a]:
        lis[x-1] = total
      
    print(total)
  else:
    print(lis[a-1])
    
  

### FIXED CODE ###

import copy
import collections
import math
 
N = int(input())
A = [int(i) for i in input().split()] 
 
maxnum = max(A)
lis = [-1] * maxnum
bigC = collections.Counter(A)
for i, a in enumerate(A):
  if lis[a-1] < 0:
    newA = copy.deepcopy(A)
    newA.pop(i)
    c = collections.Counter(newA)
    total = 0
    for idx in c:
      num = c[idx]
      total += num * (num-1) // 2
      
    lis[a-1] = total
    for x in bigC:
      if bigC[x] == bigC[a]:
        lis[x-1] = total
      
    print(total)
  else:
    print(lis[a-1])