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

N=int(input())
A=list(map(int,input().split()))
p=[None]*N
for i,a in enumerate(A):
    p[a-1]=i
ans=0
b={-1:1,N:1}
from bisect import bisect
for i in range(N):
    bs=sorted(b.keys())
    s=bisect(bs,p[i])
    ans+=(i+1)*(p[i]-bs[s-1])*(bs[s]-p[i])
    b[p[i]]=1
print(ans)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
p=[None]*N
for i,a in enumerate(A):
    p[a-1]=i
ans=0
l,r=[i for i in range(N)],[i for i in range(N)]
for i in range(N-1,-1,-1):
    left,right=l[p[i]],r[p[i]]
    ans+=(i+1)*(p[i]-left+1)*(right-p[i]+1)
    if left>0:
        r[left-1]=right
    if right<N-1:
        l[right+1]=left
print(ans)
### BUGGY CODE ###

l,r = map(int,input().split())
ans = 2019

for i in range(l,r):
    for j in range(i+1,r+1):
        if ans == 0:
            break
        ans = min(ans,i*j%2019)

print(ans)

### FIXED CODE ###

l,r = map(int,input().split())
ans = 2019

for i in range(l,min(r+1,l+2020)):
    for j in range(i+1,min(r+1,l+2020)):
        if ans == 0:
            break
        ans = min(ans,i*j%2019)

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

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

limit = int(m/n)
ans = 1
for i in range(limit,1,-1):
    if m%i == 0:
        ans = i
        break
print(ans)

### FIXED CODE ###

n,m = map(int,input().split())
def getDivisor(inte):
    Ans1 = [1]
    Ans2 = [inte]
    for i in range(2,int(inte**(0.5))):
        if inte % i == 0:
            Ans1.append(i)
            Ans2.append(int(inte/i))
    if inte % inte**(0.5) == 0:
        Ans1.append(int(int(inte**(0.5))))
    Ans = Ans1 + Ans2[::-1]
    return Ans

limit = int(m/n)
for i in reversed(getDivisor(m)):
    if i <= limit:
        print(i)
        break
### BUGGY CODE ###

n = int(input())
x = list(map(int, input().split()))
ans = 1 ;
for i in range(0, n) :
    ans *= x[i]
if ans > 1000000000000000000 :
    print(-1)
else :
    print(ans)

### FIXED CODE ###

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

if 0 in x :
    print(0)
else :
    ans = 1
    con = True
    for i in range(0, n):
        ans *= x[i]
        if ans > 1000000000000000000:
            print(-1)
            con = False
            break
    if con : print(ans)
### BUGGY CODE ###

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

    for i in range(N-1):
        for j in range(i + 1, N):
            if a[i] == a[j]:
                print("NO")
                return
    
    print("YES")
    return


if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import defaultdict

def main():
    N = int(input())
    a = list(map(int, input().split()))
    dct = defaultdict(int)

    for i in a:
        if dct[i] != 0:
            print("NO")
            return 
        else:
            dct[i] += 1
    
    print("YES")
    return


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

S = input()
t = S

while '01' in t or '10' in t:
    t= t.replace('01', '').replace('10', '')

print(len(S) - len(t))

### FIXED CODE ###

S = input()

print(min(S.count('0'), S.count('1')) * 2)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
def main():
    N = int(input())
    M = [0]*(N+1)
    for i in range(1,N+1):
        for j in range(i, N+1, i):
            M[j] += 1
    ans = 0
    for i in range(1, N+1):
        ans += i * M[i]
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
    N = int(input())
    M = [0]*(N+1)
    for i in range(1,N+1):
        for j in range(i, N+1, i):
            M[j] += 1
    ans = 0
    for i in range(1, N+1):
        ans += i * M[i]
    print(ans)

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

mod = 10**9+7 #出力の制限
N = 5001
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

Pow=[pow(inverse[2],i,mod) for i in range(N+1)]

def func(n):
    if n%2==0:
        return (-g1[n]*g2[n//2]*Pow[n//2])%mod
    else:
        return 0

import sys

sys.setrecursionlimit(10**4)
input=sys.stdin.buffer.readline

N=int(input())
edge=[[] for i in range(N)]
for i in range(N-1):
    x,y=map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)


dp=[[] for i in range(N)]
sz=[0 for i in range(N)]

def dfs(v,pv):
    sz[v]=1
    dp[v]=[0]*(sz[v]+1)
    dp[v][1]=1
    for nv in edge[v]:
        if nv!=pv:
            dfs(nv,v)
            merged=[0]*(sz[v]+sz[nv]+1)
            for i in range(sz[v]+1):
                for j in range(sz[nv]+1):
                    merged[i+j] +=dp[v][i]*dp[nv][j]
                    merged[i+j]%=mod
            sz[v]+=sz[nv]
            dp[v] =merged
    dp[v][0]=(sum(func(k)*dp[v][k] for k in range(1,sz[v]+1)))%mod

dfs(0,-1)

print((-dp[0][0])%mod)

### FIXED CODE ###

mod = 10**9+7 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

import sys

sys.setrecursionlimit(10**4)

N=int(input())
edge=[[] for i in range(N)]
parent=[0]*N
deg=[1]*N
deg[0]=0
for i in range(N-1):
    x,y=map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)


def prv(v,pv):
    for nv in edge[v]:
        if nv!=pv:
            parent[nv]=v
            prv(nv,v)

prv(0,-1)

for i in range(N):
    new=[]
    for v in edge[i]:
        if v!=parent[i]:
            new.append(v)
    edge[i]=new


from collections import deque
ans = list(v for v in range(N) if deg[v]==0)
deq = deque(ans)
used = [0]*N

while deq:
    v = deq.popleft()
    for t in edge[v]:
        deg[t] -= 1
        if deg[t]==0:
            deq.append(t)
            ans.append(t)


dp=[[] for i in range(N)]
sz=[0 for i in range(N)]

for v in ans[::-1]:
    sz[v]=1
    dp[v]=[0]*(sz[v]+1)
    dp[v][1]=1
    for nv in edge[v]:
        merged=[0]*(sz[v]+sz[nv]+1)
        for i in range(sz[v]+1):
            for j in range(sz[nv]+1):
                merged[i+j]=(merged[i+j]+dp[v][i]*dp[nv][j])%mod
        sz[v]+=sz[nv]
        dp[v] =merged
    for k in range(1,sz[v]+1):
        dp[v][0]=(dp[v][0]-(g1[k]*g2[k//2])%mod*((k+1)%2)*dp[v][k])%mod

print((-dp[0][0]*pow(inverse[2],N//2,mod))%mod)
### BUGGY CODE ###

from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

A,B,N = FLI()
max = 0
for i in range(1,N+1):
    j = floor((A*i)/B) - A * floor(i/B)
    if j > max:
       max = j

print(max)

### FIXED CODE ###

from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

A,B,N = FLI()

def f(x):
  return (A*x)//B - A * (x//B)
max = 0
x = min(B-1,N)

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

N=int(input())
ls=[int(s) for s in input().split()]
lsA=[i+ls[i] for i in range(N)]
lsB=[i-ls[i] for i in range(N)]
ans=0
for i in range(N):
  for j in range(i,N):
    if lsA[i]==lsB[j]:
      ans+=1
print(ans)
    

### FIXED CODE ###

N=int(input())
ls=[int(s) for s in input().split()]
dicA={}
dicB={}
for i in range(N):
  a=i+ls[i]
  if a in dicA:
    dicA[a]+=1
  else:
    dicA[a]=1
  b=i-ls[i]
  if b in dicB:
    dicB[b]+=1
  else:
    dicB[b]=1
ans=0
for a,na in dicA.items():
  if a in dicB:
    ans+=na*dicB[a]
print(ans)
### BUGGY CODE ###

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

waza = 0
for i in range(0, N):
    waza = waza + int(A.split()[i])

if waza >= H:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

def actual(h, n, A):
    max_damage = sum(A)

    if max_damage >= h:
        return 'Yes'

    return 'No'

h, n = map(int, input().split())
A = map(int, input().split())

print(actual(h, n, A))
### BUGGY CODE ###

from collections import Counter
from itertools import product
N = int(input())
S = input()
Left = Counter()
Right = Counter()
S_left = S[:N]
S_right = S[2*N-1:N-1:-1]
for B in product(range(2),repeat = N):
    red_left = ''
    blue_left = ''
    red_right = ''
    blue_right = ''
    for i in range(N):
        if int(B[i]) == 1:
            red_left += S_left[i]
            red_right += S_right[i]
        else:
            blue_left += S_left[i]
            blue_right += S_right[i]
    Left[red_left + '|' + blue_left] += 1
    Right[blue_right + '|' + red_right] += 1
ans = 0
for i in Left.keys():
    ans += Left[i]*Right[i]
print(ans)

### FIXED CODE ###

from collections import Counter
from itertools import product
N = int(input())
S = input()
Left = Counter()
Right = Counter()
S_left = S[:N]
S_right = S[2*N-1:N-1:-1]
for B in product(range(2),repeat = N):
    red_left = ''
    blue_left = ''
    red_right = ''
    blue_right = ''
    for i in range(N):
        if B[i]:
            red_left += S_left[i]
            red_right += S_right[i]
        else:
            blue_left += S_left[i]
            blue_right += S_right[i]
    Left[red_left + '|' + blue_left] += 1
    Right[blue_right + '|' + red_right] += 1
ans = 0
for i in Left.keys():
    ans += Left[i]*Right[i]
print(ans)
### BUGGY CODE ###

limit = 1000000000000000000

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

result = 1
for n in A:
  result = result * n

if result < 0 or result > limit:
  result = -1

print(result)

### FIXED CODE ###

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

limit = 1000000000000000000

result = 1
if 0 not in A:
  for i in A:
    result = result * i
    if result > limit:
      result = -1
      break
else:
  result = 0

print(result)
### BUGGY CODE ###

from collections import deque
N, M = list(map(int, input().split()))
S = set()
for _ in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    S.add((a, b))
    S.add((b, a))

parents = [-1]*N
parents[0] = 0
L = deque([0])
while L:
    k = L.pop()
    for l in S:
        if l[0] == k and parents[l[1]] < 0:
            L.appendleft(l[1])
            parents[l[1]] = k
    # print(L)

if -1 in parents:
    print('No')
else:
    print('Yes')
    for i in range(1, N):
        print(parents[i]+1)


### FIXED CODE ###

from collections import deque
N, M = list(map(int, input().split()))
S = [set() for _ in range(N)]
for _ in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    S[a].add(b)
    S[b].add(a)
# print(S)

parents = [-1]*N
parents[0] = 0
L = deque([0])
while L:
    k = L.pop()
    s=S[k]
    for l in s:
        if parents[l] < 0:
            L.appendleft(l)
            parents[l] = k
    # print(L)

if -1 in parents:
    print('No')
else:
    print('Yes')
    for i in range(1, N):
        print(parents[i]+1)
### BUGGY CODE ###

import numpy as np
inputs = open(0).readlines()

def main(inputs):
    h, w, k = map(int, inputs[0].split())
    cake, count, coords = np.zeros((h, w), dtype=np.int), 0, {}
    for i, s in enumerate(inputs[1:]):
        for j, c in enumerate(s):
            if c == '#':
                count += 1
                cake[i, j] = count
                coords[count] = (j, i)

    for i in range(1, count+1):
        x, y = coords[i]
        x0, y0 = x-1, y-1
        x1, y1 = x+1, y+1
        while 0 <= x0 and cake[y, x0] == 0:
            cake[y, x0] = i
            x0 -= 1
        x0 += 1
        while x1 < w and cake[y, x1] == 0:
            cake[y, x1] = i
            x1 += 1
        while 0 <= y0 and not np.any(cake[y0, x0:x1]):
            cake[y0, x0:x1] = i
            y0 -= 1
        while y1 < h and not np.any(cake[y1, x0:x1]):
            cake[y1, x0:x1] = i
            y1 += 1

    for rows in cake:
        print(*rows)

main(inputs)

### FIXED CODE ###

import numpy as np
inputs = open(0).readlines()

def main(inputs):
    h, w, k = map(int, inputs[0].split())
    cake, count, coords = np.zeros((h, w), dtype=np.uint), 0, {}
    for i, s in enumerate(inputs[1:]):
        for j, c in enumerate(s):
            if c == '#':
                count += 1
                cake[i, j] = count
                coords[count] = (j, i)
    empty_rows = {i for i, rows in enumerate(cake) if not np.any(rows)}

    for i in range(1, count+1):
        x, y = coords[i]
        x0, y0 = x-1, y-1
        x1, y1 = x+1, y+1
        while 0 <= x0 and cake[y, x0] == 0:
            cake[y, x0] = i
            x0 -= 1
        x0 += 1
        while x1 < w and cake[y, x1] == 0:
            cake[y, x1] = i
            x1 += 1
        while 0 <= y0 and y0 in empty_rows:
            cake[y0, x0:x1] = i
            y0 -= 1
        while y1 < h and y1 in empty_rows:
            cake[y1, x0:x1] = i
            y1 += 1

    for rows in cake:
        print(*rows)

main(inputs)
### BUGGY CODE ###

from collections import deque
S = deque(input())
Q = int(input())
querry = [list(map(str, input().split())) for i in range(Q)]
for i in range(Q):
    if querry[i][0] == '1':
        S.reverse()
    elif querry[i][0] == '2':
        if querry[i][1] == '1':
            S.appendleft(querry[i][2])
        elif querry[i][1] == '2':
            S.append(querry[i][2])

ans=list(S)

print("".join(ans))

### FIXED CODE ###

from collections import deque
S = deque(input())
Q = int(input())
querry = [list(map(str, input().split())) for i in range(Q)]
reverse = False
for i in range(Q):
    if querry[i][0] == '1':
        reverse = not reverse
    elif querry[i][0] == '2':
        if querry[i][1] == '1':
            if reverse:
                S.append(querry[i][2])
            else:
                S.appendleft(querry[i][2])
        elif querry[i][1] == '2':
            if reverse:
                S.appendleft(querry[i][2])
            else:
                S.append(querry[i][2])

ans=list(S)

if reverse:
    print("".join(reversed(ans)))
else:
    print("".join(ans))
### BUGGY CODE ###

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

p = []
for i in range(m):
  l,r = map(int, input().split())
  p.append([l,r])
  
  
s = 0
for i in range(1, n+1):
  t = 0
  for l,r in p:
    if l <= i and i <= r:
      t += 1
  if t == m:
    s += 1
print(s)

### FIXED CODE ###

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

a = [0]*m
b = [0]*m
for i in range(m):
  l,r = map(int, input().split())
  a[i] = l
  b[i] = r

x = min(b)
y = max(a)
if x >= y:
  print(x-y+1)
else:
  print(0)
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
j=0
for i in range(M):
    A[A.index(max(A[:j+1]))]=A[A.index(max(A[:j+1]))]//2
    j=j+1
    if j==50:
        A.sort(reverse=True)    
        j=0
print(sum(A))

### FIXED CODE ###

import heapq
N,M=map(int,input().split())
A=list(map(lambda x: x*(-1),list(map(int,input().split()))))
A.sort()
B=[]
for i in range(N):
    heapq.heappush(B,A[i])
for i in range(M):
    heapq.heappush(B,(((heapq.heappop(B))*(-1))//2)*(-1))
print((sum(B))*(-1))
### BUGGY CODE ###

mod=1000000007
n,m=map(int,input().split())
a=[]
af=0
for i in range(m):
    a.append(int(input()))
al=len(a)
if al>0:
    a.sort()
    af=1
f=0
for i in range(len(a)):
    if a[i]+1 in a:
        f=1
        break
if f==1:
    print(0)
else:
    dp=[0]*(n+1)
    dp[0]=1
    if 1 in a:
        dp[1]=0
        a.pop(0)
        al-=1
    else:
        dp[1]=1
    
    for i in range(2,n+1):
        if al>0 and i==a[0]:
            dp[i]=0
            a.pop(0)
            al-=1
        else:
            dp[i]=(dp[i-1]+dp[i-2])%mod
    print(dp[n]%mod)
  

### FIXED CODE ###

import sys
input = sys.stdin.readline

mod=1000000007
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()))
al=len(a)


f=0
for i in range(al-1):
    if a[i+1]==a[i]+1:
        f=1
        break
if f==1:
    print(0)
else:
    dp=[0]*(n+1)
    dp[0]=1
    if 1 in a:
        dp[1]=0
        a.pop(0)
        al-=1
    else:
        dp[1]=1
    
    for i in range(2,n+1):
        if al>0 and i==a[0]:
            dp[i]=0
            a.pop(0)
            al-=1
        else:
            dp[i]=(dp[i-1]+dp[i-2])%mod
    print(dp[n]%mod)
### BUGGY CODE ###

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    N, M = map(int, input().split())
    graph = defaultdict(list)
    route = deque()
    for _ in range(M):
        A, B = map(int, input().split())
        if not route:
            route.appendleft(A)
            route.append(B)
        graph[A].append(B)
        graph[B].append(A)

    while True:
        start, end = route[0], route[-1]
        start_ok = True
        for n in graph[start]:
            if n not in route:
                start_ok = False
                route.appendleft(n)
                break

        end_ok = True
        for n in graph[end]:
            if n not in route:
                end_ok = False
                route.append(n)
                break

        if start_ok and end_ok:
            break

    print(len(route))
    print(*route, sep=" ")


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    N, M = map(int, input().split())
    graph = defaultdict(list)

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

    route = deque()
    used = set()
    route.appendleft(1)
    used.add(1)
    for n in graph[1]:
        route.append(n)
        used.add(n)
        break

    while True:
        start, end = route[0], route[-1]
        start_ok = True
        for n in graph[start]:
            if n not in used:
                start_ok = False
                route.appendleft(n)
                used.add(n)
                break

        end_ok = True
        for n in graph[end]:
            if n not in used:
                end_ok = False
                route.append(n)
                used.add(n)
                break

        if start_ok and end_ok:
            break

    print(len(route))
    print(*route, sep=" ")


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

from collections import deque

S = deque(list(input()))
Q = int(input())

for q in range(Q):
    query = list(input().split())
    if len(query) > 1:
        if query[1] == "1":
            S.appendleft(query[2])
        elif query[1] == "2":
            S.append(query[2])
    else:
        S.reverse()

print("".join(S))


### FIXED CODE ###

from collections import deque

S = deque(list(input()))
Q = int(input())
rvs = False

for q in range(Q):
    query = list(input().split())
    if len(query) > 1:
        if query[1] == "1":
            if rvs:
                S.append(query[2])
            else:
                S.appendleft(query[2])
        elif query[1] == "2":
            if rvs:
                S.appendleft(query[2])
            else:
                S.append(query[2])
    else:
        rvs = not (rvs)

if rvs:
    S.reverse()

print("".join(S))
### BUGGY CODE ###

import collections
n = int(input())
a = list(map(int, input().split()))
coun = collections.Counter(a)
k = list(coun.keys())
num = list(coun.values())
num_2 = []
for i in range(len(num)):
    B = num[:]
    B[i] = B[i] - 1
    num_2 += [int(sum(list(map(lambda x: (x - 1) * (2 + (x - 2)) / 2, B))))]
dic = dict(zip(k, num_2))
for i in range(n):
    print(dic[a[i]])


### FIXED CODE ###

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
dif = [0] * (n + 1)
sum_c = 0
c = Counter(a)
for i, v in c.items():
    if v < 2:
        continue
    val = v * (v - 1) / 2
    dif[i] = v - 1
    sum_c += val
print('\n'.join([str(int(sum_c - dif[i])) for i in a]))
### BUGGY CODE ###

input()
a = list(map(int, input().split()))
ans = 0
ai = 0
while all(ai%2==0 for ai in a):
    a = [ai/2 for i in a]
    ans += 1
print(ans)

### FIXED CODE ###

input()
a = list(map(int, input().split()))
ans = 0
while all(ai%2==0 for ai in a):
    a = [ai/2 for ai in a]
    ans += 1
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())

d = {}

for i in range(N):
    d[i+1] = []

for i in range(M):
    a, b = map(int,input().split())
    d[a].append(b)
    d[b].append(a)
que = [1]
checked = set()
ans = {1:-1}
while que and len(ans) != N:
    now = que.pop(0)
    for h in d[now]:
        if not h in ans:
            ans[h] = now
            if len(ans) == N:
                break
            que.append(h)
    
if len(ans) == N:
    print('Yes')
    for i in range(N-1):
        print(ans[i+2]) 
else:
    print('No')



### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())

d = {}

for i in range(N):
    d[i+1] = set()

for i in range(M):
    a, b = map(int,input().split())
    d[a].add(b)
    d[b].add(a)

que = deque([1])
checked = set()
ans = {1:-1}

while que:
    now = que.popleft()
    for h in d[now]:
        if not h in ans:
            ans[h] = now
            que.append(h)
    if len(ans) == N:
        break
    
if len(ans) == N:
    print('Yes')
    for i in range(N-1):
        print(ans[i+2]) 
else:
    print('No')
### BUGGY CODE ###

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

a_sum = sum(a_list)
min_num = float("inf")

for i in range(1, N):
    x = sum(a_list[:i])
    y = a_sum - x
    if min_num >= abs(x-y):
        min_num = abs(x-y)
print(min_num)

### FIXED CODE ###

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

a_sum = sum(a_list)
min_num = float("inf")
r = []

for i in range(1, N):
    if len(r) == 0:
        r.append(a_list[0])
    else:
        r.append(r[i-2] + a_list[i-1])

    x = r[i-1]
    y = a_sum - x
    if min_num >= abs(x-y):
        min_num = abs(x-y)
print(min_num)
### BUGGY CODE ###

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

ans=0
bc_count=[0]*(n+1)
def check(list_count,i):
    ok=n
    ng=-1
    B=b[i]
    while ok-ng>1:
        mid=(ok+ng)//2
        if list_count[mid]>B:
            ok=mid
        else:
            ng=mid
    bc_count[i+1]=n-ok+bc_count[i]
    #print(i,ok)

for i in range(n):
    check(c,i)

bc_max=bc_count[-1]
for i in range(n):

    ind=0
    while ind<n:
        if a[i]<b[ind]:
            ans=ans+bc_max-bc_count[ind]
            break
        ind+=1

print(ans)#,bc_count)
#print(a,b,c,sep='\n')

### FIXED CODE ###

import sys
input=sys.stdin.readline
n=int(input())
a=sorted(list(map(int,input().split())))
b=list(map(int,input().split()))
c=sorted(list(map(int,input().split())))

ans=0
def ab_check(list_count,i):
    ok=-1
    ng=n
    B=b[i]
    while ng-ok>1:
        mid=(ok+ng)//2
        if list_count[mid]<B:
            ok=mid
        else:
            ng=mid
    #print(ok+1,'A')
    return ok+1

def bc_check(list_count,i):
    ok=n
    ng=-1
    B=b[i]
    while ok-ng>1:
        mid=(ok+ng)//2
        if list_count[mid]>B:
            ok=mid
        else:
            ng=mid
    #print(n-ok,'B')
    return n-ok
    #print(i,ok)

for i in range(n):
    ans+=ab_check(a,i)*bc_check(c,i)
print(ans)
#print(a,c,sep='\n')