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

import math

# 最大公約数を求める問題
N, X = map(int, input().split())
x = [int(_) for _ in input().split()]
if N == 1:
    print(abs(x[0]-X))
    exit()

x.sort()
# N > 1と仮定
for i in range(N-1):
    if x[i] < X and x[i+1] > X:
        x = x[:i+1] + [X] + x[i+1:]
        break
    elif x[i] >= X:
        x = [X] + x
    elif x[i+1] <= X:
        x = x + [X]

if len(x) >= 3:
    base = math.gcd(x[1]-x[0], x[2]-x[1])
    for i in range(2, N):
        diff = x[i+1] - x[i]
        base = math.gcd(base, diff)
    print(base)
else:
    print(x[1] - x[0])


### FIXED CODE ###

import math

# 最大公約数を求める問題
N, X = map(int, input().split())
x = [int(_) for _ in input().split()]
if N == 1:
    print(abs(x[0]-X))
    exit()

x.sort()
# N > 1と仮定
for i in range(N-1):
    if x[i] < X and x[i+1] > X:
        x = x[:i+1] + [X] + x[i+1:]
        break
    elif x[i] >= X:
        x = [X] + x
        break
    elif x[i+1] <= X:
        x = x + [X]
        break

if len(x) >= 3:
    base = math.gcd(x[1]-x[0], x[2]-x[1])
    for i in range(2, N):
        diff = x[i+1] - x[i]
        base = math.gcd(base, diff)
    print(base)
else:
    print(x[1] - x[0])
### BUGGY CODE ###

K,S = map(int,input().split())
cnt = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            sum = i + j + k
            if sum == S:
                cnt+=1
print(cnt)

### FIXED CODE ###

K, S = map(int, input().split())
cnt = 0
for i in range(K + 1):
    for j in range(K + 1):
        if S - (i + j) < 0 or S-(i+j)>K:
            cnt = cnt
        else:
            cnt += 1

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

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

if k == 0:
	print(max(a))
	exit()

suki = max(a)
kirai = 0
a.sort(key= lambda x: -x)
while int(suki) != int(kirai):
	targ = (suki+kirai)/2
	cnt = 0
	mode = 1
	for i in range(n):
		cnt += math.ceil(a[i] / targ)-1
		if cnt > k:
			mode = 0
			break
	if mode:
		suki = targ
	else:
		kirai = targ
print(math.ceil(suki))

### FIXED CODE ###

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

if k == 0:
	print(max(a))
	exit()

suki = 1000000000
kirai = 0
while int(suki) != int(kirai):
	targ = (suki+kirai)/2
	cnt = 0
	mode = 1
	for i in range(n):
		cnt += (a[i]-1)//targ
		if cnt > k:
			mode = 0
			break
	if mode:
		suki = targ
	else:
		kirai = targ

print(math.ceil(suki))
### BUGGY CODE ###

n = int(input())

l=list(range(1,n+1))

for i in range(1,n+1) :

    if i%3==0:
        l.remove(i)

    elif i%5==0:
        l.remove(i)
    else:
        pass
print(sum(l))

### FIXED CODE ###

n = int(input())

l=list(range(1,n+1))

count=0

for i in range(1,n+1) :
    if i%3!=0 and i%5!=0:
        count += i
print(count)
### BUGGY CODE ###

import bisect as bi
import sys
from operator import itemgetter
input = sys.stdin.readline

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0] * m
for i in range(m):
    b[i] = list(map(int,input().split()))
a.sort()
#print(a)
b.sort(key=itemgetter(1),reverse=True)
for i in b:
    tmp = bi.bisect_left(a,i[1])
    for j in range(min(tmp,i[0])):
        a[j] = i[1]
    a.sort()
#print(a)
print(sum(a))

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter

N,M = map(int,readline().split())
A = list(map(int,readline().split()))
m = map(int,read().split())
BC = list(zip(m,m))

BC.sort(key = itemgetter(1),reverse=True)

BC.append((N,-1))

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break

A += change
A.sort()
answer = sum(A[-N:])
print(answer)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from itertools import combinations

def inpl(): return tuple(map(int, input().split()))

N = int(input())
A = inpl()
s = sum(A)

X = [sum(A[:i]) for i in range(1, N)]
print(min([abs(2*x - s) for x in X]))

### FIXED CODE ###

# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

N = int(input())
A = inpl()
s = sum(A)

x, y = A[0], sum(A[1:])
res = abs(x-y)

for a in A[1:-1]:
    x += a
    y -= a
    if abs(x-y) < res:
        res = abs(x-y)
print(res)
### BUGGY CODE ###

s = input()

n = int(input())

#y = []
#for i in range(n):
#    x = input()
#    y.append(x)
#
#print(y)
#print(y[0].split())
for i in range(n):
    x = input()
    if int(x[0]) == 1:
        s = s[::-1]
    else:
        x = x.split()
        if int(x[1]) == 1:
            s = x[2] + s

        else:
            s = s + x[2]


print(s)

### FIXED CODE ###

import numpy as np
import sys

input = sys.stdin.readline

S = input()
Q = int(input())

left = []
right = []
rev = False

for i in range(Q):
    l = input().split()
    if l[0] == '1':
        rev = not rev
    else:
        if (l[1] == '1' and not rev) or (l[1] == '2' and rev):
            left.append(l[2])
        else:
            right.append(l[2])

S = ''.join(left[::-1]) + S + ''.join(right)

if rev:
    print(S[::-1].replace('\n',''))
else:
    print(S.replace('\n',''))
### BUGGY CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n, t = MAP()
a = LIST()
get = 0
ans = 0
b = [a[0]]
for i in range(1, n - 1):
    if a[i - 1] < a[i] < a[i + 1]:
        continue
    b.append(a[i])
b.append(a[-1])
d = [b[i] - min(b[:i]) for i in range(1, len(b))]
mx = max(d)
print(d.count(mx))


### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n, t = MAP()
a = LIST()
get = 0
ans = 0
b = [a[0]]
for i in range(1, n - 1):
    if a[i - 1] < a[i] < a[i + 1]:
        continue
    b.append(a[i])
b.append(a[-1])
d = [0 for i in range(len(b) - 1)]
mn = inf
for i in range(len(b) - 1):
    if mn > b[i]:
        mn = b[i]
    d[i] = b[i + 1] - mn
mx = max(d)
print(d.count(mx))
### BUGGY CODE ###

N,Q = map(int,input().split())
S = input()
for i in range(Q):
    a,b = map(int,input().split())
    print(S[a-1:b].count("AC"))

### FIXED CODE ###

N,Q = map(int,input().split())
S = input()
ac = [0]*(N+1)
for i in range(N):
    ac[i+1] = ac[i] + (1 if S[i:i+2] == "AC" else 0)
for i in range(Q):
    l,r = map(int,input().split())
    print(ac[r-1]-ac[l-1])
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
knd = len(set(a))##種類数
d = dict(list((_, a.count(_))) for _ in set(a))
print(sum(sorted(d.values())[:knd - k]))    

### FIXED CODE ###

n, k = map(int, input().split())
a = input().split()

d = dict()
for i in a:
    d[i] = d.get(i, 0) + 1
d_sorted = sorted(d.values())
knd = len(set(a))##種類数
print(sum(d_sorted[:knd - k]))
### BUGGY CODE ###

n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j+ 1, n):
            if l[i] + l[j] > l[k]:
                ans += 1
            else:
                break
print(ans)

### FIXED CODE ###

from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        ans += bisect_left(l, l[i] + l[j]) - j - 1

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

import collections

N = int(raw_input())
S = raw_input()

ans_list = [" "]

for num in range(1000):
    cha3 = str(num%10)
    cha2 = str((num%100 - num%10)/10)
    cha1 = str(num/100)


    for i in range(N):
        if S[i] == cha1:
            for j in range(i+1, N):
                if S[j] == cha2:
                    for k in range(j+1,N):
                        if S[k] == cha3:
                            string = cha1+cha2+cha3
                            ans_list.append(string)
                            break

print len(collections.Counter(ans_list))-1

### FIXED CODE ###

def str_find(S, target, start):
    for i in range(start, len(S)):
        if S[i] == target:
            return i

    return 10**9+7

N = int(raw_input())
S = str(raw_input())

candidates = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            candi = str(i)+str(j)+str(k)
            candidates.append(candi)


ans = 0
for candi in candidates:
    x = candi[0]
    i = str_find(S, x, 0)

    y = candi[1]
    j = str_find(S, y, i+1)

    z = candi[2]
    k = str_find(S, z, j+1)

    if i+j+k< 10**8:
        ans = ans + 1

print ans
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)

N,M=map( int, raw_input().split() )
S="z"+raw_input()
num=[ [ 0 for i in range(2) ] for j in range(N+1) ] 

nl= [ [] for j in range(N+1) ] 


deleted=[ 0 for j in range(N+1) ] 

for i in range(M):
	a,b=map( int, sys.stdin.readline().split() )
	if not b in nl[a]:
		nl[a].append(b)
		nl[b].append(a)
		if S[b]=="A":  num[a][0]+=1
		elif S[b]=="B":  num[a][1]+=1
		if S[a]=="A":  num[b][0]+=1
		elif S[a]=="B":  num[b][1]+=1


def delete(x):
	if deleted[x]==1: return
	if num[x][0]==0 or num[x][1]==0:

		deleted[x]=1
		for u in nl[x]:
			if deleted[u]==0:
				if S[x]=="A": num[u][0]-=1						
				elif S[x]=="B": num[u][1]-=1
			
			if ( num[u][0]==0 or num[u][1]==0 ) and deleted[u]==0:
				delete(u)


for i in range(1,N+1):
	delete(i)


				

if sum(deleted[1:])==N:
	print "No"
else:
	print "Yes"



### FIXED CODE ###

from heapq  import heappush, heappop

N,M=map( int, raw_input().split() )
S="z"+raw_input()
num=[ [ 0 for i in range(2) ] for j in range(N+1) ] 

nl= [ [] for j in range(N+1) ] 

deleted=[ 0 for j in range(N+1) ] 

for i in range(M):
	a,b=map( int, raw_input().split() )
	if not b in nl[a]:
		nl[a].append(b)
		nl[b].append(a)
		if S[b]=="A":  num[a][0]+=1
		elif S[b]=="B":  num[a][1]+=1
		if S[a]=="A":  num[b][0]+=1
		elif S[a]=="B":  num[b][1]+=1

hq=[]

for i in range(1,N+1):
	if num[i][0]==0 or num[i][1]==0:
		heappush(hq,i)



while hq:
	x=heappop(hq)
	if deleted[x]==1: continue
	if num[x][0]==0 or num[x][1]==0:

		deleted[x]=1
		for u in nl[x]:
			if deleted[u]==0:
				if S[x]=="A": num[u][0]-=1						
				elif S[x]=="B": num[u][1]-=1
			
		#	print "x,u,num:::",x,u,num
			if ( num[u][0]==0 or num[u][1]==0 ) and deleted[u]==0:
				heappush(hq,u)
			#	print "x,u,hq:::",x,u,hq

				

	

#print "num:::",num
#print "deleted:::",deleted
#print "nl:::",nl

if sum(deleted[1:])==N:
	print "No"
else:
	print "Yes"
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split()]
b = [0] * (n)
b[0] = a[0]
for i in range(1, n):
    b[i] = b[i-1] + a[i]
ans = 0
for i in range(n):
    for j in range(i+1, n):
        if b[j] - b[i] == 0:
            ans += 1
ans += b.count(0)
print(ans)

### FIXED CODE ###

from itertools import accumulate
import collections
n = int(input())
a = [int(i) for i in input().split()]
b = list(accumulate(a))
c = collections.Counter(b)
ans = sum([((num * (num - 1)) // 2) for num in c.values()])
ans += c[0]
print(ans)
### BUGGY CODE ###

n = int(input())
P = list(map(int, input().split()))
ans = 0

for i in range(n):
  if P[i] <= min(P[0:i+1]):
    ans += 1
  else:
    ans += 0
    
print(ans)

### FIXED CODE ###

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

ans = 0
tmp = P[0]
for i in range(n):
  if P[i] <= tmp:
    ans += 1
    tmp = P[i]
  else:
    pass
print(ans)
### BUGGY CODE ###

n=int(input())
t=[]
a=[]

for i in range(n):
    ti,ai=map(int,input().split())
    t.append(ti)
    a.append(ai)
    
ti=t[0]
ai=a[0]

for i in range(n-1):
    ta=a[i+1]*t[i+1]
    for ii in range(1,10000000):
        if ta*ii//a[i+1]>=ti and ta*ii//t[i+1]>=ai:
            ti=ta*ii//a[i+1]
            ai=ta*ii//t[i+1]
            break
            
print(ai+ti)

### FIXED CODE ###

icase=0
if icase==0:
    n=int(input())
    t=[0]*n
    a=[0]*n

    for i in range(n):
        t[i],a[i]=map(int,input().split())
elif icase==1:
    n=5
    t=[3,48,31,231,3]
    a=[10,17,199,23,2]
    ans=6930

ti=t[0]
ai=a[0]
dt=1
for i in range(n-1):
    if ti/t[i+1]>ai/a[i+1]:
        ii=max((ti-dt)//t[i+1]+1,1)
        ti=ii*t[i+1]
        ai=ii*a[i+1]
    else:
        ii=max((ai-dt)//a[i+1]+1,1)
        ti=ii*t[i+1]
        ai=ii*a[i+1]

print(ai+ti)
### BUGGY CODE ###

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

    dpList = [0] * N
    dpList[1] = abs(field[0] - field[1])

    for i in range(2, N):
        tmpList = []
        minCost = -1

        for j in range(1, min(K, i) + 1):
            cost = dpList[i-j] + abs(field[i] - field[i - j])

            if(minCost == -1):
                minCost = dpList[i - j] + abs(field[i] - field[i - j])
            elif minCost > cost:
                minCost = cost

        dpList[i] = minCost

    print(dpList[-1])

if __name__ == "__main__":
    main()

### FIXED CODE ###

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

    dpList = [0] * N
    dpList[1] = abs(field[0] - field[1])

    for i in range(2, N):
        tmpList = []
        minCost = -1

        minS = max(0, i - K)

        for dpJ, fJ in zip(dpList[minS:i], field[minS:i]):
            cost = dpJ + abs(field[i] - fJ)

            if(minCost == -1):
                minCost = cost
            elif minCost > cost:
                minCost = cost

        dpList[i] = minCost

    print(dpList[-1])

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

N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    flag = []
    X.sort()
    for _ in range(1,M):
        flag.append(X[_] - X[_-1])
    for lp in range(N-1):
        flag.pop(flag.index(max(flag)))
    print(sum(flag))

### FIXED CODE ###

N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    X.sort()
    x_next = X[0]
    flag = [X[_] - X[_-1] for _ in range(1,M)]
    flag.sort()
    flag = flag[:M-N:]
    print(sum(flag))
### BUGGY CODE ###

import itertools
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
res = 0
for comb in itertools.combinations(L, 3):
    if comb[0] < comb[1] + comb[2]:
        res += 1
print(res)


### FIXED CODE ###

from bisect import bisect_left
N = int(input())
l = list(map(int, input().split()))
l.sort()
res = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        t = l[i] + l[j]
        idx = bisect_left(l, t)
        res += idx-j-1
print(res)
### BUGGY CODE ###

def a(n,k):
  ans = n
  while(True):
    if abs(ans-k) < ans:
      ans = abs(ans-k)
    else:
      break

  print(ans)
  
n, k = map(int, input().split())
a(n,k)

### FIXED CODE ###

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

d = n // k
ans = min(k-(n-k*d), (n-k*(d-1))-k)
print(ans)
### BUGGY CODE ###

import math
f=0
n=int(input())
a=list(map(int,input().split()))
p = [0]*10**6
for i in range(0, len(a)):
    for j in range(2, int(math.sqrt(a[i]))+2):
        if a[i] % j == 0:
            p[i] += 1
    if max(p)>1:
        f=1
        break
if f==0:
    print("pairwise coprime")
else:
    _gcd=a[0]
    for i  in range(1,len(a)):
        _gcd=math.gcd(_gcd,a[i])
    if _gcd==1:
        print("setwise coprime")
    else:
        print("not coprime")
    

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
M = max(a)+1
if M == 2:
    print("pairwise coprime")
    exit()
count = [0]*(M)
prime = [2,3,5,7,11,13]
for i in range(14,int(M**0.5)+2):
    check = True
    for j in prime:
        if i%j == 0:
            check = False
            break
    if check:
        prime.append(i)
 
for i in a:
    for j in prime:
        if i < j:
            break
        if i%j==0:
            while i%j == 0:
                i //= j
            count[j] += 1
    if i > 1:
        count[i] += 1
 
ans = max(count)
 
if ans == 1:
    print("pairwise coprime")
elif ans == n:
    print("not coprime")
else:
    print("setwise coprime")
### BUGGY CODE ###

a,b,c,k =map(int,input().split())
for i in range(k):
	e = b+c
	f = a+b
	g = a+c
	a = e
	c = f
	b = g
r =a-b
if abs(a-b)>10^18:
	print('Unfair')
else:
	print(a-b)


### FIXED CODE ###

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

if k%2==1:
    print(b-a)
else:
    print(a-b)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

H, W = map(int, input().split())
ans_array = [[10000] * W for i in range(H)]
ans = 10000
ans_check_flag = 0
for i in range(H):
    A_array = input()[:-1]
    for j, s in enumerate(A_array):
        # print(s)
        if s == ".":
            continue
        ans_check_flag = 0
        for h in range(max(0, i - ans + 1), min(H, i + ans - 1)):
            for w in range(max(0, j - ans + 1), min(W, j + ans - 1)):
                # print(i, j, h, w)
                distance = abs(h - i) + abs(w - j)
                if ans_array[h][w] == ans and distance < ans_array[h][w]:
                    ans_check_flag = 1
                    ans_array[h][w] = distance
                    continue
                ans_array[h][w] = min(ans_array[h][w], distance)
        if ans_check_flag:
            ans = max([max(ans_array[i]) for i in range(H)])
print(ans)

### FIXED CODE ###

from scipy import ndimage
import numpy as np
import sys
input = sys.stdin.readline

H, W = map(int, input().split())

A_array = np.array(
    [[0 if s == "#" else 1 for s in input()[:-1]] for i in range(H)])
# print(A_array)


# print(A_array)
b = ndimage.morphology.distance_transform_cdt(
    A_array, metric="taxicab")
print(np.max(b))
### BUGGY CODE ###

import math
import copy
import collections
def calc_combi2(n):
    if n<=1:
        return 0
    return math.factorial(n)/(math.factorial(n-2)*math.factorial(2))
n=int(input())
data=list(map(int,input().split()))
for i in range(n):
    count=0
    cp=copy.copy(data)
    cp.pop(i)
    cp_cnt=list(collections.Counter(cp).values())
    for j in cp_cnt:
        if 2<=j:
            count+=int(calc_combi2(j))
    print(count)
    

### FIXED CODE ###

import math
import collections
def calc_combi2(n):
    if n<=1:
        return 0
    return math.factorial(n)/(math.factorial(n-2)*math.factorial(2))
n=int(input())
data=list(map(int,input().split()))
data_cnt=collections.Counter(data)
count=0
for i in data_cnt.values():
    count+=calc_combi2(i)
for i in data:
    ans=count-data_cnt[i]+1
    print(int(ans))
### BUGGY CODE ###

quest = []
N, Q = input().split()
N = int(N)
Q = int(Q)
S = input()
for _ in range(Q):
    cnt = 0
    start, end = input().split()
    start = int(start)
    end = int(end)
    for i in range(start-1, end):
        s = S[i]
        if s != 'C':
            continue
        elif S[i-1] == 'A' and i-1 >= start-1:
            cnt += 1
    print(cnt)


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
ans = [0]*(N+1)
for i in range(N):
    ans[i+1] = ans[i]
    if S[i: i+2] == 'AC':
        ans[i+1] += 1
for _ in range(Q):
    start, end = map(int, input().split())
    cnt = ans[end-1] - ans[start-1]
    print(cnt)
### BUGGY CODE ###

N = int(input())
for h in range(3500):
  for n in range(3500):
    try:w = (N*h*n) / (4*n*h - N*n - N*h)
    except ZeroDivisionError: continue
    if w>0 and w.is_integer():
      print(h, n, int(w))
      exit()

### FIXED CODE ###

N = int(input())
for h in range(3500):
  for n in range(h):
    try:w = (N*h*n) / (4*n*h - N*n - N*h)
    except ZeroDivisionError: continue
    if w>0 and w.is_integer():
      print(h, n, int(w))
      exit()
### BUGGY CODE ###

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = float('-inf')
for i in range(2 ** N):
  t = 0
  for j in range(N):
    if i & (1 << j):
      t += V[j]
      t -= C[j]
  ans = ans if ans > t else t
print(ans)

### FIXED CODE ###

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
print(sum([max(v-c, 0) for v, c in zip(V, C)]))
### BUGGY CODE ###

import math

n=int(input())
s=input()
ng=len(s)
r=[]
g=[]
b=[]

for i in range(ng):
    if s[i]=='R':
        r.append(i)
    elif s[i]=='G':
        g.append(i)
    else:
        b.append(i)

kihon=math.factorial(n)%998244353
combo=0
list1=[]
list2=[]
list3=[]

deka=[]
tibi=[]

for i in range(n):
    moto=[r[i],g[i],b[i]]
    jun = sorted([r[i],g[i],b[i]])
    list1.append(jun[0])
    list2.append(jun[1])
    list3.append(jun[2])
    deka.append(moto.index(jun[2]))
    tibi.append(moto.index(jun[0]))

dekalist=[1]
tibilist=[1]
for i in range(n-1):
    next=max(1, dekalist[-1]-1)
    if i+next<n:
        while deka[i]==deka[i+next] and list3[i]>=list2[i+next]:
            next+=1
            if i+next==n:
                break
    dekalist.append(next)
    
    next2=max(1, tibilist[-1]-1)
    if i+next2<n:
        while tibi[n-1-i]==tibi[n-1-(i+next2)] and list1[n-1-i]<=list2[n-1-(i+next2)]:
            next2+=1
            if i+next2==n:
                break
    tibilist.append(next2)


for dl in dekalist:
    kihon*=dl
for tl in tibilist:
    kihon*=tl

print(kihon%998244353)

### FIXED CODE ###

import math

n=int(input())
s=input()
ng=len(s)
r=[]
g=[]
b=[]

for i in range(ng):
    if s[i]=='R':
        r.append(i)
    elif s[i]=='G':
        g.append(i)
    else:
        b.append(i)

kihon=math.factorial(n)%998244353
combo=0
list1=[]
list2=[]
list3=[]

deka=[]
tibi=[]

for i in range(n):
    moto=[r[i],g[i],b[i]]
    jun = sorted([r[i],g[i],b[i]])
    list1.append(jun[0])
    list2.append(jun[1])
    list3.append(jun[2])
    deka.append(moto.index(jun[2]))
    tibi.append(moto.index(jun[0]))

dekalist=[1]
tibilist=[1]
for i in range(n-1):
    next=max(1, dekalist[-1]-1)
    if i+next<n:
        while deka[i]==deka[i+next] and list3[i]>=list2[i+next]:
            next+=1
            if i+next==n:
                break
    dekalist.append(next)
    
    next2=max(1, tibilist[-1]-1)
    if i+next2<n:
        while tibi[n-1-i]==tibi[n-1-i-next2] and list1[n-1-i]<=list2[n-1-i-next2]:
            next2+=1
            if i+next2==n:
                break
    tibilist.append(next2)


for dl in dekalist:
    kihon=(kihon*dl)%998244353
for tl in tibilist:
    kihon=(kihon*tl)%998244353

print(kihon%998244353)