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

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

# 最短距離が１の頂点の組は(N - 1)個
# 最短距離が２の頂点の組は(N - 1) * (N - 2) // 2個以下
# （star型のときが等号成立）

# よってK > (N - 1) * (N - 2) // 2なら解なし

if K > (N - 1) * (N - 2) // 2:
    print(-1)

# Kがこれ以下の場合はグラフが実際に構築可能である。
# ウニみたいな形を作ってとげ部分をいくつかつなげばよい。
# （単純グラフは二重辺や自己ループがなければ、通常のループはOK!!!）

else:
    dif = (N - 1) * (N - 2) // 2 - K
    print(N - 1 + dif)
    
    for i in range(N - 1):
        print(' '.join(map(str, [1, i + 2])))
    
    first = 2
    while dif >= N - first:
        for j in range(first + 1, N + 1):
            print(' '.join(map(str, [first, j])))
        dif -= N - first
        first += 1

    for k in range(dif):
        print(' '.join(map(str, [first, first + 1 + k])))


### FIXED CODE ###

import itertools

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

# 最短距離が１の頂点の組は(N - 1)個以下
# 最短距離が２の頂点の組は(N - 1) * (N - 2) // 2個以下
# （star型のときが等号成立）

# よってK > (N - 1) * (N - 2) // 2なら解なし

if K > (N - 1) * (N - 2) // 2:
    print(-1)

# Kがこれ以下の場合はグラフが実際に構築可能である。
# ウニみたいな形を作ってとげ部分をいくつかつなげばよい。
# （単純グラフは二重辺や自己ループがなければ、通常のループはOK!!!）

else:
    diff = (N - 1) * (N - 2) // 2 - K
    print(N - 1 + diff)
    
    for i in range(N - 1):
        print(' '.join(map(str, [1, i + 2])))

    lst = list(range(2, N+1))
    combi = list(itertools.combinations(lst, 2))
    for i in range(diff):
        print(' '.join(map(str, combi[i])))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    a=list(map(int,input().split()))
    dp0=[1]*N
    dp1=[1]*N
    mask=(1<<K)-1
    for i in range(N-1):
        if a[i]<K:
            dp0[i+1]=(dp0[i]|(dp0[i]<<a[i]))&mask
        else:
            dp0[i+1]=dp0[i]
        if a[N-i-1]<K:
            dp1[N-i-2]=(dp1[N-i-1]|(dp1[N-i-1]<<a[N-i-1]))&mask
        else:
            dp1[N-i-2]=dp1[N-i-1]
    ans=0
    for i in range(N):
        if K>a[i]:
            mask2=((1<<a[i])-1)<<(K-a[i])
            for j in range(K):
                if (dp0[i]>>j)&1:
                    if (dp1[i]<<j)&mask2:
                        break
            else:
                ans+=1
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    a=list(map(int,input().split()))
    a.sort(reverse=1)
    dp0=[1]*N
    dp1=[1]*N
    mask=(1<<K)-1
    for i in range(N-1):
        if a[i]<K:
            dp0[i+1]=(dp0[i]|(dp0[i]<<a[i]))&mask
        else:
            dp0[i+1]=dp0[i]
        if a[N-i-1]<K:
            dp1[N-i-2]=(dp1[N-i-1]|(dp1[N-i-1]<<a[N-i-1]))&mask
        else:
            dp1[N-i-2]=dp1[N-i-1]
    ans=0
    def nibutan(ok,ng):
        while abs(ok-ng) > 1:
            mid = (ok + ng) // 2
            if solve(mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    def solve(i):
        if a[i]<K:
            mask2=((1<<a[i])-1)<<(K-a[i])
            for j in range(dp0[i].bit_length()):
                if j>mask2.bit_length():
                    return True
                if (dp0[i]>>j)&1:
                    if dp1[i]&(mask2>>j):
                        return True
        else:
            return True
        return False
    
    res=nibutan(-1,N)
    print(N-1-res)
    


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

s = input()
q = int(input())
que = []
for i in range(q):
    que.append(list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            s = que[i][2] + s
        else:
            s += que[i][2]
    else:
        s = s[::-1]
print(s)

### FIXED CODE ###

from collections import deque
s = input()
sque = deque(s)
q = int(input())
que = [0] * q
flg = False
for i in range(q):
    que[i] = (list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            if flg:
                sque.append(que[i][2])
            else:
                sque.appendleft(que[i][2])
        else:
            if flg:
                sque.appendleft(que[i][2])
            else:
                sque.append(que[i][2])
    else:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    sque.reverse()
    print("".join(list(sque)))
else:
    print("".join(list(sque)))
### BUGGY CODE ###


import heapq
import collections
import math
import sys
N =  int(input())
input = sys.stdin.readline
# num = a << b →  a  * (2 ** b)
# 1 << i → i桁目のマスク
# mask = 1 << i
# num = a << b
# num & mask
nums = list(map(int,input().split(" ")))
keta = [0] * 61
# ある桁の1の出現回数
# keta[k] → 2**k の桁
jijou = []
MOD = 10 ** 9 + 7
for i in range(62):
    temp = 1 << i
    temp%= MOD
    jijou.append(temp)

for num in nums:
    # s = format(num,"b")
    # l = len(s)

    for i in range(0,62):
        if num == 0:
            break
        temp = num & 1
        num  = num >> 1
        keta[i] += temp

ans = 0
for j,num in  enumerate(nums[:-1]):

    for i in range(0,61): #i →  2 ** i 乗 桁目に対応

        if num == 0:
            ans += (keta[i] * jijou[i]) % MOD
        else:
            temp = num & 1
            num = num >> 1
            if temp == 0:
                ans += (keta[i] * jijou[i]) % MOD
            else:
#              (N - j + 1) - (keta[i] + 1 ) → 0が経っているところの個数
                ans += (( (N - j + 1) - (keta[i] + 1)  ) * ( jijou[i]) ) % MOD
                keta[i] -= 1
        ans %= MOD
    ans %= MOD


print(ans)

### FIXED CODE ###


import heapq
import collections
import math
import sys
N =  int(input())
input = sys.stdin.readline
# num = a << b →  a  * (2 ** b)
# 1 << i → i桁目のマスク
# mask = 1 << i
# num = a << b
# num & mask


#
nums = list(map(int,input().split(" ")))
keta = [0] * 62
# ある桁の1の出現回数
# keta[k] → 2**k の桁
jijou = []
MOD = 10 ** 9 + 7


for num in nums:
    s = format(num,"b")
    l = len(s)

    for i in range(0,l):
        if s[l - i - 1 ] == "1":
            keta[i] += 1

ans = 0
temp = 1
for i in range(62):

    ans += ( keta[i] * (N - keta[i])) * temp
    ans %= MOD
    temp *= 2
    temp %= MOD
print(ans)
### BUGGY CODE ###


def main():
    
    
    in1 = [int(e) for e in input().split()]
    n = in1[0]
    q = in1[1]

    a = []
    b = []
    for i in range(n-1):
        in1 = [int(e) for e in input().split()]
        a.append(in1[0])
        b.append(in1[1])

    p = []
    x = []
    for i in range(q):
        in1 = [int(e) for e in input().split()]
        p.append(in1[0])
        x.append(in1[1])

    l = [0] * n

    def addval(p,x):
        l[p-1] += x

        for j in range(p-1,n-1):
            #print('j',j)
            if(a[j] == p):
                addval(b[j],x)

    for i in range(q):
        addval(p[i],x[i])

    
    for i in range(n):
        print(l[i], end="")
        print(" ", end="")
        




if __name__ == "__main__":
    main()


### FIXED CODE ###

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import sys
sys.setrecursionlimit(40000000)

n,q = mi()
b = [[] for i in range(n)]
ans = [0]*n

# O(2n)
for i in range(n-1):
    a,c = mi()
    b[a-1].append(c-1)
    b[c-1].append(a-1)

# jun = []
# O(2n)
# def chil_pop(l,p):
#     jun.append(l)
#     for i in b[l]:
#         if i == p:
#             continue
#         chil_pop(i,l)
#     b[l] = p

# chil_pop(0,-1)


# O(q)
for i in range(q):
    p,x = mi()
    ans[p-1] += x


count = 0
q = [(0,-1)]
while q:
    c,p = q.pop()
    for i in b[c]:
        if i == p:
            continue
        ans[i] += ans[c]
        q.append((i,c))
    
    

# for i in jun[1:]:
#     ans[i] += ans[b[i]]

# ans_str = ''
# for i in range(n):
#     print(ans[i],end=' ')
#     # ans_str = ans_str + str(ans[i]) + ' '
print(*ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
def main():
    N, M = [int(n) for n in input().split()]
    from_li = [[] for i in range(N)] # from[i]:=点iからつながった点
    to_li = [[] for i in range(N)] # to[i]:=点iにつながる点
    for i in range(M):
        x, y = [int(n) for n in input().split()]
        from_li[x-1].append(y-1)
        to_li[y-1].append(x-1)
    parents = []
    children = []
    dp = [-1]*N
    for index, to in enumerate(to_li):
        if len(to) == 0:
            parents.append(index)
    for index, fr in enumerate(from_li):
        if(len(fr)) == 0:
            children.append(index)
    print(max([g(to_li, from_li, parents, dp, c) for c in children]))

    
def g(to_li, from_li, parents, dp, n):
    # nにつくパスの最大長
    if dp[n] != -1:
        return dp[n]
    if n in parents:
        return 0
    val = max([g(to_li, from_li, parents, dp, t)+1 for t in to_li[n]])
    dp[n] = val
    return val
    


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
def main():
    n, m = [int(n) for n in input().split()]
    paths = [[] for i in range(n+1)]
    for i in range(m):
        x, y = [int(r) for r in input().split()]
        paths[x].append(y)
    dp = [-1]*(n+1)

    ans = 0
    for i in range(n+1):
        ans = max(ans, dfs(paths, dp, i))
    print(ans-1)
def dfs(paths, dp, n):
    # nから下の最大長
    length = 0
    for p in paths[n]:
        val=0
        if dp[p] != -1:
            val = dp[p]
        else:
            val = dfs(paths, dp, p)
        length = max(length, val)
    length += 1 # pからnまでの一本もしくはnから終点までの一本
    dp[n] = length
    return length

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

H,W = map(int,input().split())
masu = [list(input()) for _ in range(H)]
from collections import deque
def bfs():
    que = deque([])
    seen = [[float('inf')]*W for _ in range(H)]
    for w in range(W):
        for h in range(H):
            if masu[h][w] == '#':
                que.append((w,h))
                seen[h][w] =0
    while que:
        a,b = que.popleft()
        for x,y in [[0,1],[1,0],[0,-1],[-1,0]]:
            nx = a+x
            ny = b+y
            if 0<=nx<W and 0<=ny<H and seen[ny][nx] == float('inf') and masu[ny][nx] != '#':
                seen[ny][nx] = seen[b][a] +1
                que.append((nx,ny))
    ans = 0
    for i in range(H):
        for j in range(W):
            if seen[i][j] > ans:
                ans = seen[i][j]
    return ans
print(bfs())

### FIXED CODE ###

from collections import deque
 
def solve(h, w, a):
    used = [[True] * (w+2) for _ in range(h+2)]
    que = deque()
    for r in range(h):
        used[r+1][1:-1] = map(lambda _:_=="#", a[r])
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k
 
h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))
### BUGGY CODE ###

from collections import deque
n,m=[int(i) for i in input().split()]
a_to=deque([])
to_b=deque([])
for i in range(m):
    a,b=[int(i) for i in input().split()]
    if a==1:
        a_to.append(b)
    if b==n:
        to_b.append(a)
for i in a_to:
    if i in to_b:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

### FIXED CODE ###

n,m=[int(i) for i in input().split()]
a_to_b=[0]*n
for i in range(m):
    a,b=[int(j) for j in input().split()]
    if a==1:
        a_to_b[b]+=1
    if b==n:
        a_to_b[a]+=1
if 2 in a_to_b:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

N, K = map(int, input().split())
X, Y = [], []
for i in range(N):
    xi, yi = map(int, input().split())
    X.append(xi)
    Y.append(yi)

ans = float('inf')
for i in range(N):  # 左
    for j in range(N):  # 右
        if X[i] >= X[j]:
            continue
        for k in range(N):  # 下
            for l in range(N):  # 上
                if Y[k] >= Y[l]:
                    continue
                cnt = 0
                for x, y in zip(X, Y):  # 含まれてるかカウント
                    if X[i] <= x <= X[j] and Y[k] <= y <= Y[l]:
                        cnt += 1
                if cnt >= K:
                    ans = min(ans, (X[j]-X[i]) * (Y[l]-Y[k]))
print(ans)


### FIXED CODE ###

N, K = map(int, input().split())
XY = []
YX = []
for i in range(N):
    x, y = map(int, input().split())
    XY.append([x, y, i])
    YX.append([y, x, i])
XY.sort()
YX.sort()

x_order = {}
for xo, p in enumerate(XY):
    x, y, i = p
    x_order[i] = xo

cums = [[0 for j in range(N+1)] for i in range(N+1)]
for i in range(N):
    y, x, pi = YX[i]
    xo = x_order[pi]
    for j in range(N + 1):
        cums[i + 1][j] = cums[i][j] + (1 if j > xo else 0)

ans = float('inf')

for i in range(N-1):
    for j in range(i+1, N):
        for k in range(N-1):
            for l in range(k+1, N):
                if cums[l+1][j+1] - cums[l+1][i] - cums[k][j+1] + cums[k][i] >= K:
                        ans = min(ans, (XY[j][0]-XY[i][0]) * (YX[l][0]-YX[k][0]))

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

s = input()
c = 0
for i in range(len(s)):
    for j in range(i+4,len(s)+1):
        a = int(s[i:j])
        if a>=2019 and a%3==0 and a%673==0:
            c += 1
print(c)

### FIXED CODE ###

s = input()
len_s = len(s)
pre = 0
mod = [0]*2019
mod[0]=1
x = 1
for i in range(len_s):
    pre = (x*int(s[len_s-i-1])+pre)%2019
    mod[pre] += 1
    x *= 10
    x %= 2019
print(sum([m*(m-1)//2 for m in mod]))
### BUGGY CODE ###

n,k = map(lambda x:int(x),input().split())
p_n = list(map(lambda x:int(x),input().split()))


def culc_exp(n):
    return 0.5 * (n+1)

p_n = list(map(lambda x:culc_exp(x),p_n))

def sum_list_a_to_k(list,a,k):
    result = 0
    for i in range(k):
        result = result+list[a+i]
    return result





def max_tuple(list):
    max = 0
    for i in range(len(list)-(k-1)):
        tmp = sum_list_a_to_k(list,i,k)
        if tmp > max:
            max = tmp
    return max


print(max_tuple(p_n))


### FIXED CODE ###

#x,y = map(lambda x: int(x), input().split())
#list = list(map(lambda x: int(x), input().split()))


n,k = map(lambda x: int(x), input().split())
p_lst = list(map(lambda x: int(x), input().split()))


def cum_sum(list):
    result = []
    for i in range(len(list)):
        if i == 0:
            result.append(list[i])
        else:
            result.append(result[i-1] + list[i])
    return result


def cum_sum_exp(list):
    result = []
    for i in range(len(list)):
        if i == 0:
            result.append((list[i]+1)/2)
        else:
            result.append(result[i-1] + (list[i]+1)/2)
    return result



cum_sum_main = cum_sum_exp(p_lst)


cmp = cum_sum_main[k-1]


for i in range(k-1,n):
    if i == k-1:
        cmp = cum_sum_main[i]
    else:
        tmp = cum_sum_main[i] - cum_sum_main[i-k]

        if cmp < tmp:
            cmp = tmp



print(cmp)
### BUGGY CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]

b = [a[0]]
for i in range(1, n):
    x = -1
    for j in range(len(b)):
        if b[j] < a[i]:
            if x == -1 or b[j] > b[x]:
                x = j

    if x == -1:
        b.append(a[i])
    else:
        b[x] = a[i]

print(len(b))    


### FIXED CODE ###

from bisect import bisect_left, bisect_right
from collections import deque
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for _ in range(n)]

dq = deque([a[0]])
for i in range(1, n):
    idx = bisect_left(dq, a[i])
    if idx == 0:
        dq.appendleft(a[i])
    else:
        dq[idx-1] = a[i]

print(len(dq))
### BUGGY CODE ###

n_max = 100000

bs = [(6 ** i, 6) for i in range (1, 10)]
bs.extend([(9 ** i, 9) for i in range (1, 10)])
bs = list(sorted(filter(lambda x: x[0] <= n_max, bs)))
bms = []
s = 5
for b, i in bs:
    s += b * (i - 1)
    bms.append((b, i, s))

#print(bs)
#print(bms, len(bms))

#m = 44852
m = int(input())

stack = [(m, 0, len(bms) - 1)]
#print("search start!")
result = 10000
while stack:
    m, n, bms_i = stack.pop()
    b, i, s = bms[bms_i]
    #print(m, n, bms_i, b, i, s)

    if n > result:
        #print("skip!", m, n, bms_i)
        continue
    if bms_i < 0:
        if m <= 6 and m + n < result:
            result = m + n
        #    print('get result!', result)
        continue

    for j in range(i):
        next_m = m - b * j
        if next_m >= 0 and n + j < result:
            stack.append((next_m, n + j, bms_i - 1))

print(result)


### FIXED CODE ###

n_max = 100000

bs = [(6 ** i, 6) for i in range (1, 10)]
bs.extend([(9 ** i, 9) for i in range (1, 10)])
bs = list(sorted(filter(lambda x: x[0] <= n_max, bs)))
bms = []
s = 5
for b, i in bs:
    s += b * (i - 1)
    bms.append((b, i, s))

#print(bs)
#print(bms, len(bms))

#m = 44852
m = int(input())

stack = [(m, 0, len(bms) - 1)]
#print("search start!")
result = 10000
while stack:
    m, n, bms_i = stack.pop()
    b, i, s = bms[bms_i]
    #print(m, n, bms_i, b, i, s)

    if n > result:
        #print("skip!", m, n, bms_i)
        continue
    if m > s:
        continue
    if bms_i < 0:
        if m <= 6 and m + n < result:
            result = m + n
        #    print('get result!', result)
        continue

    for j in range(i):
        next_m = m - b * j
        if next_m >= 0 and n + j < result:
            stack.append((next_m, n + j, bms_i - 1))

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

import sys
input = sys.stdin.readline
 
from heapq import heappop,heappush
import math
 
xs,ys,xt,yt = map(int,input().split())
n = int(input())
 
v = [[xs,ys,0]]
for _ in range(n):
    x,y,r = map(int,input().split())
    v.append([x,y,r])
v.append([xt,yt,0])
 
def dd(a,b):
    return max(0,math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2) - a[2] - b[2])

edges=[[0]*(n+2) for _ in range(n+2)]
for i in range(n+2):
    for j in range(i+1,n+2):
        edges[i][j] = dd(v[i],v[j])
        edges[j][i] = dd(v[i],v[j])

def dijkstra(s,n,edges):
    #edges[i][j] : the cost of i→j
    #import 'heap'
    d = [float('inf') for _ in range(n)]
    d[s] = 0
    q = [[0, s]]
    while q:
        dist_u, u = heappop(q)
        if d[u] < dist_u:
            continue
        for v, c in enumerate(edges[u]):
            if d[v] > dist_u + c:
                d[v] = dist_u + c
                heappush(q, [d[v], v])
    return d

ans = dijkstra(0,n+2,edges)
print(ans[n+1])

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
from heapq import heappop,heappush
import math
 
xs,ys,xt,yt = map(int,input().split())
n = int(input())
 
v = [[xs,ys,0]]
for _ in range(n):
    x,y,r = map(int,input().split())
    v.append([x,y,r])
v.append([xt,yt,0])
 
def dd(a,b):
    return max(0,math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2) - a[2] - b[2])

edges=[[0]*(n+2) for _ in range(n+2)]
for i in range(n+2):
    for j in range(i+1,n+2):
        edges[i][j] = dd(v[i],v[j])
        edges[j][i] = dd(v[i],v[j])

def dijkstra(s,n,edges):
    #edges[i][j] : the cost of i→j
    #import 'heap'
    d = [float('inf') for _ in range(n)]
    d[s] = 0
    q = [(0, s)]
    while q:
        dist_u, u = heappop(q)
        if d[u] < dist_u:
            continue
        for v, c in enumerate(edges[u]):
            if d[v] > dist_u + c:
                d[v] = dist_u + c
                heappush(q, (d[v], v))
    return d

ans = dijkstra(0,n+2,edges)
print(ans[n+1])
### BUGGY CODE ###

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

sum_a = 0
for i in range(n-1):
	for j in range(i+1,n):
		sum_a += (A[i] * A[j])

print(int(sum_a%(1e9 + 7)))

### FIXED CODE ###

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

sum_a = sum(A)
ans = 0

for i in range(n-1):
	sum_a -= A[i]
	ans += A[i] * sum_a
	ans = ans %(int(1e9 + 7))

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

X, Y, Z, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
AB = []
ans = []
for a in A:
    for b in B:
        AB.append(a + b)
AB.sort(reverse=True)
AB = AB[:min(3001, X*Y*Z+1)]
for c in C:
    for ab in AB:
        ans.append(c + ab)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])


### FIXED CODE ###

import sys
X, Y, Z, K = map(int, input().split())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
C = list(map(int, sys.stdin.readline().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
AB = []
ans = []
for a in A:
    for b in B:
        AB.append(a + b)
AB.sort(reverse=True)
AB = AB[:min(3001, X*Y*Z+1)]
for c in C:
    for ab in AB:
        ans.append(c + ab)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])
### BUGGY CODE ###

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

def toId(i, j):
    pair = A[i][j]
    if i > pair:
        i, pair = pair, i
    return ids[i][pair]

def dfs(x):
    if dp[x] != -1:
        if done[x]:
            return dp[x]
        else:
            return -1
    dp[x] = 1
    for y in G[x]:
        res = dfs(y)
        if res == -1:
            return -1
        dp[x] = max(dp[x], res+1)
    done[x] = True
    return dp[x]

N = int(input())
A = [list(map(lambda x: int(x)-1, input().split())) for i in range(N)]
ids = [[0]*N for i in range(N)]
num = 0
for i in range(N):
    for j in range(N):
        if i < j:
            ids[i][j] = num
            num += 1
allv = N*N
G = [[] for i in range(allv)]
for i in range(N):
    for j in range(N-2):
        G[toId(i,j+1)].append(toId(i,j))
dp = [-1]*allv
done = [False]*allv
ans = 0
for i in range(allv):
    res = dfs(i)
    if res == -1:
        print(-1)
        exit()
    ans = max(ans, res)
print(ans)

### FIXED CODE ###

N = int(input())
A = [list(map(lambda n: int(n)-1, input().split())) for i in range(N)]
cur = [0 for i in range(N)]
que = [i for i in range(N)]
ans = 0
while len(que) > 0:
    done = {}
    que2 = []
    for n in que:
        if done.get(n):
            continue
        pair = A[n][cur[n]]
        if done.get(pair):
            continue
        if n == A[pair][cur[pair]]:
            cur[n] += 1
            cur[pair] += 1
            done[n] = True
            done[pair] = True
            if cur[n] < N-1:
                que2.append(n)
            if cur[pair] < N-1:
                que2.append(pair)
    if len(done) > 0:
        ans += 1
    que = que2
ok = True
for i in range(N):
    if cur[i] < N-1:
        ok = False
if ok:
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

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


a = sorted(a)
b = sorted(b)
c = sorted(c)
a_tmp = [one+0.2 for one in a]
b_tmp = [one+ i/10**6 for i,one in enumerate(b)]
ab = sorted(a_tmp+b_tmp)
ab_len = 2*N
ab_dict = dict()
for one in enumerate(ab):
    ab_dict[one[1]] = one[0]
b_ans = [ab_dict[one] - i for i,one in enumerate(b_tmp)]

b_tmp = [one+0.2 for one in b]
c_tmp = [one+ i/10**6 for i,one in enumerate(c)]
bc = sorted(b_tmp+c_tmp)
bc_len = 2*N
bc_dict = dict()
for one in enumerate(bc):
    bc_dict[one[1]] = one[0]
c_ans = [bc_dict[one] - i for i,one in enumerate(c_tmp)]

ans = 0
for i,one in enumerate(c_ans):
    if one == 0:
        continue
    ans += sum(b_ans[:one])
print(ans)

### FIXED CODE ###

import bisect
import numpy as np
N = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
b_bisect = [bisect.bisect_left(a,one) for one in b]
b_cumsum = np.cumsum(b_bisect)
c_bisect = [bisect.bisect_left(b,one) for one in c]

ans = 0
for one in c_bisect:
    if one == 0:
        continue
    else:
        ans += b_cumsum[one-1]
print(ans)