Harryxun/stf_run huggingface dataset:
import math
a,b,c,d = map(int, input().split())
e = (c*d)//math.gcd(c,d)
A = (a-1)//c + (a-1)//d - (a-1)//e
B = b//c + b//d - b//e
print((b-a+1)-(B-A))

### FIXED CODE ###

from fractions import gcd
a,b,c,d = map(int, input().split())
x = (c*d) // gcd(c,d)
c1, d1, cd1 = b // c, b // d, b // x
c2, d2, cd2 = (a-1) // c, (a-1) // d, (a-1) // x
ans = (c1+d1-cd1) - (c2+d2-cd2)
print(b-a+1-ans)
n=int(input())
A=list(map(int,input().split()))
B=[0]*(n+max(A)+1)
res=0

for i in range(n):
	if 0<=(i+1)+A[i]:
		B[i+A[i]+1]+=1
		if 0<=i-A[i]+1:
			res+=B[i-A[i]+1]

print(res)

### FIXED CODE ###

from collections import defaultdict

n=int(input())
A=list(map(int,input().split()))
B=defaultdict(int)
res=0

for i in range(n):
	B[A[i]+i]+=1
	if i-A[i] in B:
		res+=B[i-A[i]]

print(res)
import numpy as np
s = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
        if len(str(divisors[-1]))<=9:
            break
    return divisors

tmp = int(np.ceil(np.sqrt(s)))
tmp2 = tmp*(tmp) - s
if tmp2<=1:
    tmp2 = tmp*(tmp+1) - s
    y3 = tmp +1
else:
    y3 = tmp
div = make_divisors(tmp2)[-2:]

x1 = 0
y1 = 0
x2 = tmp
y2 = div[0]
x3 = div[1]

print(x1, y1, x2, y2, x3, y3)

### FIXED CODE ###

import numpy as np
s = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
        if len(str(divisors[-1]))<=9:
            break
    return divisors

if s != 1000000000000000000:
    tmp = int(np.ceil(np.sqrt(s)))
    tmp2 = tmp*(tmp) - s
    if tmp2<=1:
        tmp2 = tmp*(tmp+1) - s
        y3 = tmp +1
    else:
        y3 = tmp
    div = make_divisors(tmp2)[-2:]

    x1 = 0
    y1 = 0
    x2 = tmp
    y2 = div[0]
    try:
        x3 = div[1]
    except:
        x3 = div[0]
    if x2==x3 and y2==y3:
        dummy = y2
        y2 = x3
        x3 = dummy
else:
    x1, y1, x2, y2, x3, y3 = 0, 0, 0, 1000000000, 1000000000, 0
    
print(x1, y1, x2, y2, x3, y3)
k=int(input())
s=input()
if len(s)<=k:
  print(k)
else:
  print(k[:k]&"...")

### FIXED CODE ###

k=int(input())
s=input()
if len(s)<=k:
  print(s)
else:
  print(s[:k]+"...")
import permutations
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

a = [i+1 for i in range(n)]
for i,per in enumerate(list(permutations(a))):
    if per == p:
        x = i
    if per == q:
        y = i
print(abs(x-y))


### FIXED CODE ###

from itertools import permutations
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

a = [i+1 for i in range(n)]
for i,per in enumerate(list(permutations(a))):
    if per == p:
        x = i
    if per == q:
        y = i
print(abs(x-y))
print((int(sys.stdin.readline())) ** 2)

### FIXED CODE ###

import sys

print((int(sys.stdin.readline())) ** 2)
import sys

w, h, x, y = input().split()
w = float(w)
h = float(h)
x = float(x)
y = float(y)
s=0

for i in range(100000000):
  a=i/1000
  if a<=h/w:
    cand=w*(a*w-2*a*x+2*y)/2
    s_cand=min(cand,w*h-cand)
    if s_cand>s:
      s=s_cand
  else:
    cand=h*(h+2*a*x-2*y)/(2*a)
    s_cand=min(cand,w*h-cand)
    if s_cand>s:
      s=s_cand
      
if w/2==x and h/2==y:
  print(w*h/2, 1)
else:
  print(s,0)

### FIXED CODE ###

x, a = input().split()
x = int(x)
a = int(a)

if x < a:
  print(0)
else:
  print(10)
N = input()
S = list(map(int, N))
print("Yes" if N % sum(S) == 0 else "No")

### FIXED CODE ###

N = input()
S = list(map(int, N))
print("Yes" if int(N) % sum(S) == 0 else "No")
n=list(input())

if n[3]==n[4] and n[5]==n[6]:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

n=list(input())

if n[2]==n[3] and n[4]==n[5]:
    print("Yes")
else:
    print("No")
a = map(int, raw_input().split())
  
a.sort()
print '%d, %d, %d' % (a[1], a[2], a[3])

### FIXED CODE ###

a = map(int, raw_input().split())
  
a.sort()
print '%d %d %d' % (a[0], a[1], a[2])
a,b=map(int,input().split())
print(b*100*a//100)

### FIXED CODE ###

from decimal import Decimal as D
a,b=map(str,input().split())
print(int(D(a)*D(b)))
N=int(input())

for _ in range(N):
    t,x,y = map(int,input().split())
    if x + y > t or (t -x -y) % 2:
        print('No')
        exit() 
print('Yes')

### FIXED CODE ###

a,b=map(int,input().split())
if a*b%2==0:
    print('Even')
else:
    print('Odd')
N = int( input() )

R = list(range(1,N+1))
L = list(range(1,N+1))

if N==1:

    print(1%1)

elif N==2:

    R.insert(0,R.pop(1))


else:
    R.insert(len(R)-1,R.pop(1))


    print(sum(list(map(lambda x,y: x % y,L,R))))


### FIXED CODE ###

N = int(input())
print( (N *(N-1)) // 2 )
from itertools import Counter
n = int(input())
lst = [0]*n
for i in range(n):
    s = input()
    lst[i] = s

c = Counter(lst)
max_num = max(c.values())
most_lst = sorted([k for k, v in c.items() if v == max_num])
for x in most_lst:
    print(x)

### FIXED CODE ###

n = int(input())
lst = [0]*n
for i in range(n):
    s = input()
    lst[i] = s

lst_af = sorted(lst)

word = lst_af[0]
most_lst = []
most_lst.append(word)
max_num = 1
cnt = 1

for i in range(1, n):
    now_word = lst_af[i]
    if now_word == word:
        cnt += 1
    else:
        cnt = 1
    if max_num == cnt:
        most_lst.append(now_word)
    if max_num < cnt:
        most_lst = []
        most_lst.append(now_word)
        max_num = cnt
    word = now_word

for x in most_lst:
    print(x)
from collections import Counter
a = input()
b = Counter(a)
c = 0

for i in b.values:
  if i%2!=0:
    c = 1
    break
else:
  if c==0:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

from collections import Counter
a = input()
b = Counter(a)
c = 0

for i in b.values():
  if i%2!=0:
    c = 1
else:
  if c==0:
    print("Yes")
  else:
    print("No")
a,b,c = map(int,input()split())
count = 0
for i in range(a,b+1):
    d = c % i
    if d == 0:
        count += 1

print('%d' %count)

### FIXED CODE ###

a,b,c = map(int,input().split())
print(len([x for x in range(a,b+1) if (c % x ) == 0]))
n,d=map(int,input())
print(int(n//(2*d+1))

### FIXED CODE ###

n,d=map(int,input().split())
if n%(2*d+1)==0:
  print(int(n//(2*d+1)))
else:
  print(int(n//(2*d+1))+1)
As = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(As[K-1])

### FIXED CODE ###

As = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(As[K-1])
import collections


def solve(string):
    n, *v = map(int, string.split())
    if len(set(v)) == 1:
        return str(n // 2)
    else:
        odds = v[1::2]
        _o = collections.Counter(odds)
        r_o = {str(v): k for k, v in _o.items()}
        evens = v[::2]
        _e = collections.Counter(evens)
        r_e = {str(v): k for k, v in _e.items()}
        ans1 = 0
        tmp = max(_o.values())
        ans1 += len(odds) - tmp
        key = r_o[str(tmp)]
        if key in _e.keys():
            _e[key] = 0
        ans1 += len(evens) - max(_e.values())

        ans2 = 0
        _o = collections.Counter(odds)
        r_o = {str(v): k for k, v in _o.items()}
        _e = collections.Counter(evens)
        r_e = {str(v): k for k, v in _e.items()}
        tmp = max(_e.values())
        ans2 += len(evens) - tmp
        key = r_e[str(tmp)]
        if key in _o.keys():
            _o[key] = 0
        ans2 += len(evens) - max(_o.values())

        return str(min(ans1, ans2))


if __name__ == '__main__':
    print(solve(input()))


### FIXED CODE ###

import collections
n = int(input())
v = input().split(" ")
"""
n = 10000
# v = [_i % 10 for _i in range(n)]
v = [_i for _i in range(n)]
n = 10
v = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2]
"""
if len(set(v)) == 1:
    print(n // 2)
else:
    odds = v[1::2]
    _o = collections.Counter(odds)
    r_o = {str(v): k for k, v in _o.items()}
    evens = v[::2]
    _e = collections.Counter(evens)
    r_e = {str(v): k for k, v in _e.items()}
    ans1 = 0
    tmp = max(_o.values())
    ans1 += len(odds) - tmp
    key = r_o[str(tmp)]
    if key in _e.keys():
        _e[key] = 0
    ans1 += len(evens) - max(_e.values())

    ans2 = 0
    _o = collections.Counter(odds)
    r_o = {str(v): k for k, v in _o.items()}
    _e = collections.Counter(evens)
    r_e = {str(v): k for k, v in _e.items()}
    tmp = max(_e.values())
    ans2 += len(evens) - tmp
    key = r_e[str(tmp)]
    if key in _o.keys():
        _o[key] = 0
    ans2 += len(evens) - max(_o.values())

    print(min(ans1, ans2))
abc = input().split() 
abc[0],abc[1],abc[2] = abc[2],abc[0],abc[1]
print(f'{abc[0]} {abc[1]} {abc[2]}')


### FIXED CODE ###

x, y, z = map(int,input().split())
print(z,x,y)
n, a, b = map(int, input().split())
counts = [0]*(n+1)
counts[1] = n
mod = 10**9+7
for i in range(2, n+1):
    counts[i] = counts[i-1] * (n-i+1) // i % mod
counts[a] = 0
counts[b] = 0
print(sum(counts))

### FIXED CODE ###

n, a, b = map(int, input().split())
mod = 10**9+7
ans = pow(2, n, mod) - 1

up = 1
bo = 1
for i in range(b):
    up = up*(n-i)%mod
    bo = bo*(i+1)%mod
    if i == a-1:
        acombs = up*pow(bo, mod-2, mod)%mod

bcombs = up*pow(bo, mod-2, mod)%mod

print((ans - acombs - bcombs)%mod)
x,y = map(int. input ().split())
while True
    if x == y == 0
        break
    elif x < y:
        print(x,y)
    else:
        print(y,x)
        


### FIXED CODE ###

while True:
    x,y = map(int,input().split())

    if x == 0 and y == 0:
        break
    elif x < y:
        print(x,y)
    else:
        print(y,x)
from collections import Counter as ct
n, k = map(int, input().split())

td = [list(map(int, input().split())) for i in range(n)]

kind = len(ct(list(map(lambda x: x[0], td))))
std = sorted(td, key=lambda x: x[1], reverse=True)
dup = []
eat_k = set()
ans = 0
for i in range(k):
    ans += std[i][1]
    if std[i][0] in eat_k:
        dup.append(std[i])
    eat_k.add(std[i][0])
ans += len(eat_k)** 2
tmpa = ans
for i in range(k, n):
    if std[i][0] not in eat_k:
        t = dup.pop()
        tmpa -= t[1]
        tmpa += std[i][1]
        tmpa -= len(eat_k)** 2
        eat_k.add(std[i][0])
        tmpa += len(eat_k)** 2
        ans = max(tmpa, ans)
print(ans)


### FIXED CODE ###

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

td = sorted(td, key=lambda x: - x[1])

dict_td = set()
q = []
ans = 0
for i in range(k):
    if td[i][0] in dict_td:
        q.append(td[i])
    ans += td[i][1]
    dict_td.add(td[i][0])

ans += len(dict_td) ** 2

tmp_ans = ans
for i in range(k, n):
    if len(q) == 0:
        break
    if td[i][0] not in dict_td :
        minus = q.pop()
        tmp_ans += td[i][1] - minus[1]
        dict_len = len(dict_td)
        tmp_ans += (dict_len + 1) ** 2 - dict_len ** 2
        dict_td.add(td[i][0])
    ans = max(tmp_ans, ans)

print(ans)
from collections import deque
import random
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
if 0:
    N=2*10**5
    A=[random.randrange(1,N+1) for i in range(N)]
    B=[random.randrange(1,N+1) for i in range(N)]
    A.sort()
    B.sort()
a=[0 for i in range(N+1)]
b=[0 for i in range(N+1)]
for i in range(N):
    a[A[i]]+=1
    b[B[i]]+=1
if max([a[i]+b[i] for i in range(1,N+1)])>N:
    print("No")
    exit()
print("Yes")
ans0=[0 for i in range(N)]
ans1=[0 for i in range(N)]
flag0=1
flag1=1
q=deque([])
for i in range(N):
    q.append(B[i])
for i in range(N):
    if q[0]==q[-1] and q[0]==A[i]:
        flag0=0    
        break
    if q[-1]==A[i]:
        ans0[i]=q.popleft()
    else:
        ans0[i]=q.pop()
q=deque([])
for i in range(N):
    q.append(B[i])
for i in range(N):
    if q[0]==q[-1] and q[0]==A[i]:
        flag1=0    
        break
    if q[0]==A[i]:
        ans1[i]=q.pop()
    else:
        ans1[i]=q.popleft()
if flag0:
    print(*ans0)
elif flag1:
    print(*ans1)
else:
    while(1):
        ans2=[0 for i in range(N)]
        flag2=1
        q=deque([])
        for i in range(N):
            q.append(B[i])
        for i in range(N):
            if q[0]==q[-1] and q[0]==A[i]:
                flag1=0    
                break
            if q[0]==A[i]:
                ans2[i]=q.pop()
            elif q[-1]==A[i]:
                ans2[i]=q.popleft()
            else:
                if random.randrange(2):
                    ans2[i]=q.pop()
                else:
                    ans2[i]=q.popleft()
        if flag2:
            print(*ans)
            exit()

exit()
if min([abs(A[i]-ans[i]) for i in range(N)])==0:
    print("NG")


### FIXED CODE ###

import random
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
a=[0 for i in range(N+1)]
b=[0 for i in range(N+1)]
for i in range(N):
    a[A[i]]+=1
    b[B[i]]+=1
if max([a[i]+b[i] for i in range(1,N+1)])<=N:
    print("Yes")
else:
    print("No")
    exit()
B=B[::-1]
point=0
for i in range(N):
    if A[i]==B[i]:
        point+=1
while(point>0):
    x=random.randrange(N)
    y=random.randrange(N)
    if x==y:
        continue
    before=0
    after=0
    if A[x]==B[x]:
        before+=1
    if A[y]==B[y]:
        before+=1
    if A[x]==B[y]:
        after+=1
    if A[y]==B[x]:
        after+=1
    if before>after:
        B[x],B[y]=B[y],B[x]
        point=point+after-before
print(*B)
import sys


class Stack:
    def __init__(self, lst):
        self.lst = lst

    def push(x):
        lst.append(x)
    def pop():
        lst.pop(-1)

def cul(exp):

    S = Stack(exp)

    for val in exp:
        if val in ["+", "-", "*"]:
            if val == "+":
                x = reduce(lambda a,b:int(a)+int(b), S[-2:])
            elif val == "-":
                x = reduce(lambda a,b:int(a)-int(b), S[-2:])
            elif val == "*":
                x = reduce(lambda a,b:int(a)*int(b), S[-2:])
            for i in range(2):
                S.pop()
            S.push(x)
        else:
            S.push(val)

    return S[0]


if __name__ == "__main__":
    exp = sys.stdin.read().strip().split(" ")
    ans = cul(exp)
    print ans

### FIXED CODE ###

import sys


Stack = []

def push(x):
    Stack.append(x)

def pop():
    Stack.pop(-1)


def cul(exp):
    for val in exp:
        if val in ["+", "-", "*"]:
            a = int(Stack[-2])
            b = int(Stack[-1])
            if val == "+":
                x = a + b
            elif val == "-":
                x = a - b
            elif val == "*":
                x = a * b
            for i in range(2):
                pop()
            push(x)
        else:
            push(val)

    return Stack[0]


if __name__ == "__main__":
    exp = sys.stdin.read().strip().split(" ")
    ans = cul(exp)
    print ans
abc = input().split()
a =int(a)
b = int(b)
c = int(c)
if a<B and b<c:
    print("Yes")
else:
    print("No")
    


### FIXED CODE ###

a,b,c = input().split()
a =int(a)
b = int(b)
c = int(c)
if a<b and b<c:
    print("Yes")
else:
    print("No")
inf = 10**9+7
import sys
a = 0
def nCr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1: 
            result = (result * numerator[k])%inf
    return result

x, y = map(int, input().split())
key = 0
if x == 2*y:
    print(1)
    sys.exit()
if y == 2*x:
    print(1)
    sys.exit()
while x>0 and y>0:
    x, y = x-3, y-3
    key += 1
    print(x/y)
    if x == 2*y:
        a = 1
        break
    if y == 2*x:
        a = -1
        break

if x < 0 or y < 0:
    print(0)
    sys.exit()
if a == 0:
    print(0)
    sys.exit()
if a == 1:
    print(int(nCr(key*2+y ,key)))
else:
    print(int(nCr(key*2+x ,key)))

### FIXED CODE ###

inf = 10**9+7
import sys
a = 0
def nCr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1: 
            result = (result * numerator[k])%inf
    return result

x, y = map(int, input().split())
key = 0
if x == 2*y:
    print(1)
    sys.exit()
if y == 2*x:
    print(1)
    sys.exit()
while x>0 and y>0:
    x, y = x-3, y-3
    key += 1
    if x == 2*y:
        a = 1
        break
    if y == 2*x:
        a = -1
        break

if x < 0 or y < 0:
    print(0)
    sys.exit()

if a == 0:
    print(0)
elif a == 1:
    print(int(nCr(key*2+y ,key)))
else:
    print(int(nCr(key*2+x ,key)))
# coding: utf-8
import math

a, b, x = [int(y) for y in input().split(" ")]

if a * a * b <= 2 * x:
    t = (a * a * a / (a * a * b - x)) / 2
    print(90 - math.degrees(math.atan(t)))
else:
    t = 2 * (x / (a * b * b))
    print(90 - math.degrees(math.atan(t)))

### FIXED CODE ###

# coding: utf-8
import math

a, b, x = [int(y) for y in input().split(" ")]

if a * a * b == x:
    print(0)
else:
    if a * a * b <= 2 * x:
        t = (a * a * a / (a * a * b - x)) / 2
        print(90 - math.degrees(math.atan(t)))
    else:
        t = 2 * (x / (a * b * b))
        print(90 - math.degrees(math.atan(t)))
H, W = map(int, input().split())
F = [input() for _ in range(H)]
FH = [[0]*W for _ in range(H)]
FV = [[0]*W for _ in range(H)]


def search(x, y, c, d):
    if not (0 <= x < H and 0 <= y < W):
        return c
    if F[x][y] == "#":
        return c
    else:
        if d == "h":
            return search(x, y+1, c+1, "h")
        else:
            return search(x+1, y, c+1, "v")

ans = 0
for i in range(H):
    for j in range(W):
        if F[i][j] == "#":
            FH[i][j] = 0
        elif F[i][j] == ".":
            if FH[i][j-1] > 0:
                FH[i][j] = FH[i][j-1]
            else:
                FH[i][j] = search(i, j+1, 1, "h")

for i in range(H):
    for j in range(W):
        if F[i][j] == "#":
            FV[i][j] = 0
        elif F[i][j] == ".":
            if FV[i-1][j] > 0:
                FV[i][j] = FV[i-1][j]
            else:
                FV[i][j] = search(i+1, j, 1, "v")

ans = 0
for i in range(H):
    for j in range(W):
        if FH[i][j] + FV[i][j] > ans:
            ans = FH[i][j] + FV[i][j]

print(ans-1)


### FIXED CODE ###

import numpy as np

H, W = map(int, input().split())
F = np.array([[1 if i == "." else 0 for i in input()] for _ in range(H)])
FU = np.zeros((H, W), dtype=int)
FD = np.zeros((H+1, W), dtype=int)
FL = np.zeros((H, W), dtype=int)
FR = np.zeros((H, W+1), dtype=int)

for i in range(H):
    FU[i] += (FU[i-1]+1)*F[i]

for i in range(H-1, -1, -1):
    FD[i] += (FD[i+1]+1)*F[i]

for i in range(W):
    FL[:, i] += (FL[:, i-1]+1)*F[:, i]

for i in range(W-1, -1, -1):
    FR[:, i] += (FR[:, i+1]+1)*F[:, i]

FV = FU + FD[:-1] - 1
FH = FL + FR[:, :-1] - 1
ans = np.max(FV+FH)
if ans >= 2:
    print(ans-1)
else:
    print(ans)
a = int(input())
b = int(input())
 
if a > 8 or b > 8:
    print(":(")
else:
    print("Yay!")


### FIXED CODE ###

if __name__ == "__main__":
    a, b = map(int, input().split(" "))
 
    if a > 8 or b > 8:
        print(":(")
    else:
        print("Yay!")
import bisect

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

big = a[0:n//3]
tempmin = a[n//3::]
tempmin.sort()
small = tempmin[0:n//3]

spare = tempmin[n//3:]


big.sort()
small.sort()
ans = sum(big)-sum(small)

mxm = ans
for i in range(n//3,2*n//3):
    if a[i] > big[0]:
        ans += a[i]-big[0]
        index = bisect.bisect_left(big,a[i])
        big.insert(index,a[i])
        big.pop(0)
    if a[i] <= small[-1]:
        index = bisect.bisect_left(spare,a[i])
        ans -= spare[index] - a[i]
        aindex = bisect.bisect_left(small,spare[index])
        small.insert(aindex,spare[index])
        aindex = bisect.bisect_left(small,a[i])
        small.pop(aindex)
        spare.pop(index)

    if len(spare) != 0 and a[i] >= spare[0]:
        index = bisect.bisect_left(spare,a[i])
        spare.pop(index)

    if ans > mxm:
        mxm = ans
print(mxm)

### FIXED CODE ###

import heapq
import bisect

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

left = a[0:n//3]
right = list(-i for i in a[2*n//3:])

leftsum = [0 for i in range(n//3+1)]
rightsum = [0 for i in range(n//3+1)]

heapq.heapify(left)
leftsum[0] = sum(left)
for i in range(n//3):
    k = i + n//3
    heapq.heappush(left,a[k])
    temp = heapq.heappop(left)
    leftsum[i+1] = leftsum[i]+a[k]-temp

heapq.heapify(right)
rightsum[-1] = -sum(right)
for i in range(n//3)[::-1]:
    k = i + n//3
    heapq.heappush(right,-a[k])
    temp = -heapq.heappop(right)
    rightsum[i] = rightsum[i+1] - temp + a[k]




mxm = -sum(a)
for i in range(n//3+1):
    if leftsum[i]-rightsum[i] > mxm:
        mxm = leftsum[i]-rightsum[i]
print(mxm)