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

K = int(input())
count = 0
an = 0

if K%2 == 0 or K%2 ==0:
    print("-1")
    exit(0)
while True:
  an = 10*an + 7
  count +=1
  if an % K == 0:
    print(count)
    break


### FIXED CODE ###

def calc(k):
    cur = 0
    for i in range(1, 10 ** 7):
        cur *= 10
        cur += 7
        cur %= k
        if cur == 0:
            return i

    return -1


k = int(input())
print(calc(k))
### BUGGY CODE ###

import time
import math
a,b = map(int,input().split())
cnt = 0
if a <= b:
  A = int(math.sqrt(b))
else:
  A = int(math.sqrt(a))
pn=[2]

t1 = time.time()
for L in range(3,A):
    chk=True
    for L2 in pn:
        if L%L2 == 0:chk=False
    if chk==True:pn.append(L)
pn.append(1)
t2 = time.time()
for i in pn:
  if a%i ==0 and b%i == 0:
    cnt += 1
t3 = time.time()
print(cnt)

### FIXED CODE ###

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

def make_divisors(n):
	divisors = set()
	for i in range(1, int(n**0.5)+1):
		if n % i == 0:
			divisors.add(i)
			if i != n // i:
				divisors.add(n//i)
	return divisors
	
A = make_divisors(a)
B = make_divisors(b)
S = A & B
#Sから素数だけを抽出してカウント
import math

def is_prime(n):
	if n == 1: return False
	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False
	return True
cnt = 1
for i in S:
	if is_prime(i) == True:
		cnt += 1

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

import itertools
n,m,q=map(int,input().split())
qs = [list(map(int,input().split())) for i in range(q)]

max_score = 0
for mid in itertools.product(range(m),repeat=n-1):
    if sum(mid)>m-1:
        continue
    tmp_score=0
    for i in qs:
        sum_mid = 0
        for j in range(i[0]-1,i[1]-1):
            sum_mid += mid[j]
        if sum_mid == i[2]:
            tmp_score += i[3]
    if tmp_score > max_score:
        max_score = tmp_score
        
print(max_score)


### FIXED CODE ###

import itertools
n,m,q=map(int,input().split())
qs = [list(map(int,input().split())) for i in range(q)]

max_ans = 0
for mid in itertools.combinations_with_replacement(range(1,m+1), n):
    sum_ans=0
    for q in qs:
        if mid[q[1]-1]-mid[q[0]-1] == q[2]:
            sum_ans += q[3]
    if sum_ans > max_ans:
        max_ans = sum_ans
        
print(max_ans)
### BUGGY CODE ###



def main():
    H,W=map(int, input().split())
    A=[["#"]*(W+2)for _ in range(H+2)]
    import queue
    q=queue.Queue()
    
    for i in range(H):
        S=input()
        for j in range(W):
            A[i+1][j+1]=S[j]
            if S[j]=="#":
                q.put((i+1,j+1,0))
                
    
    

    
    inf=-1

                
    
    dx=[0,0,1,-1]
    dy=[1,-1,0,0]
    ans=0
    
    while not q.empty():
        ii,jj,d=q.get()
        for k in range(4):
            nxt_i=ii+dx[k]
            nxt_j=jj+dy[k]
            if A[nxt_i][nxt_j]==".":
                q.put((nxt_i,nxt_j,d+1))
                A[nxt_i][nxt_j]="#"
    print(d)

                
    
            

main()


### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]

black_idx = []
for h in range(H):
    for w in range(W):
        if A[h][w] == "#":
            black_idx.append([h,w])

distance = [[float("inf")]*W for _ in range(H)]
for b in black_idx:
    distance[b[0]][b[1]] = 0

d = deque(black_idx)
ans = 0

while d:
    y, x = d.popleft()
    for new_y, new_x in ([y+1, x], [y, x+1], [y-1, x], [y, x-1]):
        if 0 <= new_y <= H-1 and 0 <= new_x <= W-1 and distance[y][x] + 1 < distance[new_y][new_x]:
            distance[new_y][new_x] = distance[y][x] + 1
            ans = max(ans, distance[y][x] + 1)
            d.append([new_y, new_x])

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

N = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p//2
r = p//2

while True:
    if q in A and p != q:
        print(p,q)
        exit(0)
    elif r in A:
        print(p,r)
        exit(0)
    else:
        q+=1
        r-=1

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
p = max(A)
q = p//2
r = 10**9+7
ans = 0
for k in range(N):
    if abs(A[k]-q) < r and A[k] != p:
        r = abs(A[k]-q)
        ans = A[k]

print(p,ans)
### BUGGY CODE ###

n=int(input())
Alist=[0]+[int(input()) for i in range(n)]

now=1
count=0
Hist=[1]

while now!=2:
    now=Alist[now]
    count+=1
    if now in Hist:
        count=-1
        break
    Hist.append(now)
print(count)

### FIXED CODE ###

n=int(input())
Alist=[0]+[int(input()) for i in range(n)]

now=1
count=0

for _ in range(n):
    now=Alist[now]
    count+=1
    if now==2:
        print(count)
        exit()
print(-1)
### BUGGY CODE ###

while True:
    n = int(input())
    if n == 0:
        break
    a = []
    for _ in range(n):
        a.append(int(input()))
    print(max(max(sum(a[j:j + i + 1]) for j in range(n - i)) for i in range(n)))

### FIXED CODE ###

while True:
    n = int(input())
    if not n:
        break
    a = [int(input()) for _ in range(n)]
    for i in range(1, n):
        if a[i - 1] > 0:
            a[i] += a[i - 1]
    print(max(a))
### BUGGY CODE ###

n=int(input())
a=[int(i) for i in input().split()]
l=[]

for i in range(1,n):
  j=n-i
  x=sum(a[:i])
  y=sum(a[i:n])
  l.append(abs(x-y))
l.sort()
print(l[0])

### FIXED CODE ###

n=int(input())
a=[int(i) for i in input().split()]
x=0
y=sum(a)
l=float("inf")
for i in range(n-1):
  x+=a[i]
  y=y-a[i]
  l=min(l,abs(x-y))
print(l)
### BUGGY CODE ###

n,k=map(int, input().split())
an=[int(i) for i in input().split()]

def comb(n, r,mod):
    r=min(r,n-r)
    p, q = 1, 1
    for i in range(r):
        p = p * (n-i) % mod
        q = q * (i+1) % mod
    return p * pow(q, mod-2, mod) % mod

an=sorted(an)
r_an=list(reversed(an))

mod=10**9+7
max1=0
min1=0
for i in range(1,n-k+2):
    c=comb(n-i,k-1,mod)
    max1=max1 + an[-i]*c%mod
    min1=min1 + r_an[-i]*c%mod
print((max1-min1)%mod)

### FIXED CODE ###

n,k=map(int, input().split())
an=[int(i) for i in input().split()]

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r=min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 5
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2,N+1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

an=sorted(an)
r_an=list(reversed(an))

max1=0
min1=0
for i in range(1,n-k+2):
    c=cmb(n-i,k-1,p)
    max1=max1 + an[-i]*c%p
    min1=min1 + r_an[-i]*c%p
print((max1-min1)%p)
### BUGGY CODE ###

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

list1 = []
for i in range(m):
    list1.append(int(input()))

dp = [0]*(n+1)
dp[0] = 1
if not 1 in list1: 
	dp[1] = 1 #i+2まで考えるため、初期設定はi = 1まで必要
for i in range(n-1):
	if i not in list1:
		dp[i+2] += dp[i]
	if i+1 not in list1:
		dp[i+2] += dp[i+1]

print(dp[n]%1000000007)

### FIXED CODE ###

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


dp = [0]*(n+1)
dp[0] = 1

for i in range(m):
	dp[int(input())] = -1

if dp[1] != -1:
	dp[1] = 1

for i in range(n-1):
	if dp[i+2] != -1:
		if dp[i+1] != -1:
			dp[i+2] += dp[i+1]
		if dp[i] != -1:
			dp[i+2] += dp[i]

print(dp[n]%1000000007)
### BUGGY CODE ###

n = int(input())

ll = [[0]*i for i in range(n)]
for i in range(n):
  x, l =map(int, input().split())
  ll[i] = [x-l, x+l]
ll = sorted(ll)

l = [1] * n

for i in range(n-1):
  for j in range(i+1, n):
    if l[i] == 0:
      continue
    elif ll[i][1] > ll[j][0]:
      l[j] = 0
    else:
      break

print(sum(l)) 

### FIXED CODE ###

n = int(input())
ll = []
for i in range(n):
  x, l = map(int, input().split())
  ll.append([x-l, x+l])
ll = sorted(ll)

ans = n
r = ll.pop()[0]

while ll:
  while ll and ll[-1][1] > r:
    ans -= 1
    ll.pop()
  if ll:
    r = ll.pop()[0]

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

import bisect
from collections import deque

N,M=map(int,input().split())
A=[int(_) for _ in input().split()]
A.sort()
A=deque(A)

for m in range(M):
    a=A.pop()//2
    insert_index = bisect.bisect(A,a)
    A=list(A)
    A.insert(insert_index,a)
    A=deque(A)
print(sum(A))

### FIXED CODE ###

import heapq

N,M=map(int,input().split())
A=[-int(_) for _ in input().split()]
heapq.heapify(A)

for _ in range(M):
    a=heapq.heappop(A)
    heapq.heappush(A,-((-a)//2))

print(-sum(A))
### BUGGY CODE ###

n,s=map(int,input().split())
a = list(map(int,input().split()))
mod = 998244353
dp = [[[0 for i in range(2)] for i in range(s+1)]for i in range(n+1)]
dp[0][0][0]=1

for i in range(1,n+1):
    for j in range(s+1):
        if j==0:
            b=1
        else:
            b=0
        dp[i][j][0] += (dp[i-1][j][0]+b)
        dp[i][j][0] %= mod
        dp[i][j][1] += (dp[i-1][j][1]+dp[i-1][j][0]+b)
        dp[i][j][1] %= mod
        if j-a[i-1]>=0:
            dp[i][j][0] += (dp[i-1][j-a[i-1]][0]+b)
            dp[i][j][0] %= mod
            dp[i][j][1] += (b+dp[i-1][j-a[i-1]][0])
            dp[i][j][1] %= mod


print(dp[n][s][1])


### FIXED CODE ###

import sys
import math
def input():
    return sys.stdin.readline()[:-1]
n,s=map(int,input().split())
a = list(map(int,input().split()))
mod = 998244353
dp0 = [[0 for i in range(s+1)]for i in range(n+1)]
dp1 = [[0 for i in range(s+1)]for i in range(n+1)]
for i in range(1,n+1):
    for j in range(s+1):
        if j==0:
            b=1
        else:
            b=0
        dp0[i][j] += (dp0[i-1][j]+b)
        dp0[i][j] %= mod
        dp1[i][j] += (dp1[i-1][j]+dp0[i-1][j]+b)
        dp1[i][j] %= mod
        if j+a[i-1]<=s:
            dp0[i][j+a[i-1]] += (dp0[i-1][j]+b)
            dp0[i][j+a[i-1]] %= mod
            dp1[i][j+a[i-1]] += (b+dp0[i-1][j])
            dp1[i][j+a[i-1]] %= mod

        dp0[i][j]%=mod
        dp1[i][j]%=mod

print(dp1[n][s])
### BUGGY CODE ###

# N=総数、A=青、B=赤
N, A, B = map(int, input().split())

# 残りボールのカウント
a_r_bal = A
b_r_bal = B
# セットしたボールのカウント
a_s_bal = 0
b_s_bal = 0
for i in range(N):
    # a,bのボールなし
    if(a_r_bal == 0 and b_r_bal == 0):
        a_r_bal = A
        b_r_bal = B

    # aの残りボールあり
    if(a_r_bal > 0):
        a_r_bal -= 1
        a_s_bal += 1
    else:
        b_r_bal -= 1
        b_s_bal += 1
# 出力
print(a_s_bal)

### FIXED CODE ###

# N=総数、A=青、B=赤
N, A, B = map(int, input().split())

# A+Bの商
n = N // (A+B)
# A+Bのあまり
r = N % (A+B)

# A+BのあまりがAより大きい場合は、Aとする
if(r > A):
    b_r = A
else:
    b_r = r

# 青の個数 = 商*A + あまり(0~A)
blue = n * A + b_r

print(blue)
### BUGGY CODE ###

from collections import Counter
N = int(input())
S = [input() for i in range(N)]
C = Counter(S)
M = [kv[0] for kv in C.items() if kv[1] == max(C.values())]
M.sort()
A = '\n'.join(M)
print(A)

### FIXED CODE ###

from collections import Counter
N = int(input())
S = [input() for i in range(N)]
C = Counter(S)
freq = max(C.values())
M = [kv[0] for kv in C.items() if kv[1] == freq]
M.sort()
A = '\n'.join(M)
print(A)
### BUGGY CODE ###

s = input()
s = list(s.replace("BC", "D"))
pos = 0
str_len = len(s)
count = 0
state = 0
seq_a = 0
seq_d = 0


while pos < str_len:
    if state == 0:
        if s[pos] == "A":
            state = 1
            seq_a = 1
        pos += 1
    elif state == 1:
        if s[pos] == "A":
            state = 1
            seq_a += 1
            pos += 1
        elif s[pos] == "D":
            while pos < str_len and s[pos] == "D":
                seq_d += 1
                pos += 1
            tmp_pos = pos - seq_a
            for i in range(tmp_pos-seq_d, tmp_pos):
                s[i] = "D"
            for i in range(tmp_pos, pos):
                s[i] = "A"
            pos = tmp_pos
            count += seq_a * seq_d
            state = 0
            seq_a = 0
            seq_d = 0
#            print(pos, s)
        else:
            state = 0
            pos += 1

print(count)


### FIXED CODE ###

s = input()
pos = 0
str_len = len(s)
count = 0
seq_a = 0
seq_bc = 0

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if pos + 1 < str_len and s[pos] == "B" and s[pos+1] == "C":
            while pos < str_len and s[pos] == "B" and pos + 1 < str_len and s[pos+1] == "C":
                seq_bc += 1
                pos += 2
            count += seq_a * seq_bc
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_bc = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)
### BUGGY CODE ###

N=int(input())
ABC=[[int(i) for i in input().split()] for _ in range(3)]
b=[]
c=[]
count=0
for i in range(3):
    ABC[i].sort()

for j in range(N):
    b=[int(i) for i in ABC[1] if i>ABC[0][j]]
    for k in range(len(b)):
        c=[int(i) for i in ABC[2] if i>b[k]]
        count+=len(c)
print(count)

### 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()
count=0

for j in b:
   x=bisect.bisect_left(a,j)
   y=bisect.bisect_right(c,j)
   count+=x*(N-y)
print(count)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

n,w = MI()
item = []
for i in range(n):
	item.append(LI())

def main():
	dp = [0]*(w+1)
	for i in range(n):
		for j in range(w,item[i][0]-1,-1):
			dp[j] = max(dp[j], dp[j-item[i][0]]+item[i][1])
	print(dp[w])

if __name__ == '__main__':
	main()


### FIXED CODE ###

def solver():
	N,W = map(int, input().split())
	item = []
	for i in range(N):
		item.append(list(map(int, input().split())))
	dp = [0 for _ in range(W+1)]
 
	for i in range(0,N):
		for j in range(W, item[i][0]-1, -1):
			dp[j] = max(dp[j], dp[j-item[i][0]]+item[i][1])
	print(dp[W])
 
solver()
### BUGGY CODE ###

import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
S =sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
ans = 0
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

C = sum(cut)
res = K - C
length = length[:res+1]
for k in range(res):
  cut[length[0][1]] += 1
  length[0][0] = length[0][0]*cut[length[0][1]]/(cut[length[0][1]]+1)
  for k in range(1, len(length)):
    if length[0][0] > length[k][0]:
      length = length[1:k] + [length[0]] +length[k:]
      break
  else:
    length = length[1:]
print(math.ceil(length[0][0]))


### FIXED CODE ###

import math
from collections import deque
N, K = map(int, input().split())
A = list(map(int, input().split()))
S =sum(A)
cut = []
for k in range(N):
  cut.append(K*A[k]//S)

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  return deque(lis[:now+1] + [item] + lis[now+1:])
  

C = sum(cut)
res = min(K - C, N)
length = length[:res+1]
length = deque(length)
for k in range(res):
  a = length.popleft()
  cut[a[1]] += 1
  a[0] = a[0]*cut[a[1]]/(cut[a[1]]+1)
  if a[0] <= length[-1][0]:
    length.append(a)
  elif a[0] >= length[0][0]:
    length.appendleft(a)
  else:
    length = nibun_insert(list(length), list(a))
  length.pop()

print(math.ceil(length.popleft()[0]))
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()
scores = [x * y for x, y in zip(A, F)]
scores = list(zip(scores, A, F))

while K > 0 and any(s[0] > 0 for s in scores):
    max_score = max(scores)
    index = scores.index(max_score)
    max_score = list(max_score)
    max_score[0] -= max_score[2]
    max_score[1] -= 1
    scores[index] = tuple(max_score)
    K -= 1

print(max(scores)[0])


### FIXED CODE ###

import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), np.int64)
F = np.array(input().split(), np.int64)
A.sort()
F.sort()
F = F[::-1]

l = 0
r = (A * F).max()

while l < r:
    m = (l + r) // 2
    if np.maximum(A - m // F, 0).sum() <= K:
        r = m
    else:
        l = m + 1

print(r)
### BUGGY CODE ###

#! /usr/bin/env python
# -*- coding: utf-8 -*-

sN = []
sQ = []
dQ = []
Q = 0
N = 0


def gor(pos):
    for i in range(Q):
        if sN[pos] == sQ[i]:
            if dQ[i] == 'R':
                pos = pos + 1
            else:
                pos = pos - 1

            if pos < 0:
                return False
            if pos > N - 1:
                return True

    return False


def getr():
    l = 0
    r = N - 1
    res = N
    while r >= l:
        mid = (l + r) // 2
        if gor(mid):
            res = mid
            r = mid - 1
        else:
            l = mid + 1
    return res


def gol(pos):
    for i in range(Q):
        if sN[pos] == sQ[i]:
            if dQ[i] == 'L':
                pos = pos - 1
            else:
                pos = pos + 1

            if pos > N - 1:
                return False
            if pos < 0:
                return True

    return False


def getl():
    l = 0
    r = N - 1
    res = -1
    while l <= r:
        mid = (l + r) // 2
        if gol(mid):
            res = mid
            l = mid + 1
        else:
            r = mid - 1
    return res


if __name__ == '__main__':
    N, Q = map(int, input().split())  # N, Q for number

    sN = input()  # squares

    for i in range(0, Q):
        t, d = input().split()
        sQ.append(t)
        dQ.append(d)
        #sQ.append({'t': t, 'd': d})

    removed_l = getl() + 1
    removed_r = N - getr()

    print(N - removed_l - removed_r)


### FIXED CODE ###

#! /usr/bin/env python
# -*- coding: utf-8 -*-

sN = []
sQ = []
dQ = []
Q = 0
N = 0


def gor(pos):
    for i in range(Q):
        if sN[pos] == sQ[i]:
            if dQ[i] == 'R':
                pos = pos + 1
            else:
                pos = pos - 1

            if pos < 0:
                return False
            if pos > N - 1:
                return True

    return False


def getr():
    l = 0
    r = N - 1
    res = N
    while r >= l:
        mid = (l + r) // 2
        if gor(mid):
            res = mid
            r = mid - 1
        else:
            l = mid + 1
    return res


def gol(pos):
    for i in range(Q):
        if sN[pos] == sQ[i]:
            if dQ[i] == 'L':
                pos = pos - 1
            else:
                pos = pos + 1

            if pos > N - 1:
                return False
            if pos < 0:
                return True

    return False


def getl():
    l = 0
    r = N - 1
    res = -1
    while l <= r:
        mid = (l + r) // 2
        if gol(mid):
            res = mid
            l = mid + 1
        else:
            r = mid - 1
    return res


if __name__ == '__main__':
    N, Q = map(int, input().split())  # N, Q for number

    sN = input()  # squares

    for i in range(0, Q):
        t, d = input().split()
        sQ.append(t)
        dQ.append(d)
        #sQ.append({'t': t, 'd': d})

    removed_l = getl() + 1
    removed_r = N - getr()

    print(N - removed_l - removed_r)
### BUGGY CODE ###

x=int(input())
de=100
count=0
while de<x:
    count+=1
    de//=100
print(count)

### FIXED CODE ###

x=int(input())
de=100
count=0
while de<x:
    count+=1
    de+=de//100
print(count)
### BUGGY CODE ###

s = list(input())
q = int(input())

rev_flag = False
for i in range(q):
    tmp_in = list(input().split())

    if tmp_in[0] == '1':
        if rev_flag:
            rev_flag = False
        else:
            rev_flag = True
    else:
        if rev_flag:
            if tmp_in[1] == '1':
                s.append(tmp_in[2])
            else:
                s.insert(0, (tmp_in[2]))
        else:
            if tmp_in[1] == '1':
                s.insert(0, tmp_in[2])
            else:
                s.append(tmp_in[2])

if rev_flag:
    s.reverse()

ans = "".join(s)
print(ans)



### FIXED CODE ###

from collections import deque

s = deque(input())
q = int(input())

rev_flag = False
for i in range(q):
    tmp_in = list(input().split())

    if tmp_in[0] == '1':
        if rev_flag:
            rev_flag = False
        else:
            rev_flag = True
    else:
        if rev_flag:
            if tmp_in[1] == '1':
                s.append(tmp_in[2])
            else:
                s.appendleft(tmp_in[2])
        else:
            if tmp_in[1] == '1':
                s.appendleft(tmp_in[2])
            else:
                s.append(tmp_in[2])

if rev_flag:
    s.reverse()

ans = "".join(s)
print(ans)
### BUGGY CODE ###

from itertools import combinations

N = int(input())
L = list(map(int, input().split()))
ans = 0
for l in combinations(L, 3):
    if max(l) < sum(l) - max(l):
        ans += 1
print(ans)


### FIXED CODE ###

import bisect

N = int(input())
L = sorted(map(int, input().split()))
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = bisect.bisect_left(L, L[i] + L[j])
        if k > j:
            ans += k - j - 1
print(ans)
### BUGGY CODE ###

import heapq

# d = [8, 2, 2, 7, 4, 6, 5, 3, 8]

N = int(input())
d = list(map(int, input().split()))
d_rev = d[::-1]

d1 = d[:N]
heapq.heapify(d1)
d2 = [-i for i in d_rev[:N]]
heapq.heapify(d2)
sum_d1 = sum(d1)
sum_d2 = sum(d2)

sum_d1_arr = [sum_d1]
sum_d2_arr = [sum_d2]

for k in range(N, 2 * N):
    l = d[:]
    c = sum_d1_arr[-1]
    c += d[k]
    n = heapq.heappushpop(d1, d[k])
    c -= n
    sum_d1_arr.append(c)

    m = d[:]
    e = sum_d2_arr[-1]
    e += -d_rev[k]
    n = heapq.heappushpop(d2, -1 * d_rev[k])
    e -= n
    sum_d2_arr.append(e)

print(max(v+w for v, w in zip(sum_d1_arr, sum_d2_arr[::-1])))

### FIXED CODE ###

from heapq import heappush, heappushpop
 
N = int(input())
a = list(map(int, input().split()))
 
a_list_1 = []
a_list_2 = []
for i in a[0:N]:
    heappush(a_list_1, i)
for i in list(reversed(a))[0:N]:
    heappush(a_list_2, -i)
 
sum_1 = sum(a_list_1)
sum_2 = sum(a_list_2)
sum_arr_1 = [0] * (N + 1)
sum_arr_1[0] = sum_1
sum_arr_2 = [0] * (N + 1)
sum_arr_2[-1] = sum_2
for k in range(N, 2 * N):
    l = heappushpop(a_list_1, a[k])
    sum_1 += a[k] - l
    sum_arr_1[k - N + 1] = sum_1
 
for k in reversed(range(N, 2 * N)):
    l = heappushpop(a_list_2, -a[k])
    sum_2 += -a[k] - l
    sum_arr_2[k - N] = sum_2
 
max_score = float('-inf')
for s1, s2 in zip(sum_arr_1, sum_arr_2):
    score = s1 + s2
    if score > max_score:
        max_score = score
 
print(max_score)