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

A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]
INF = 10**12

def binary_search(query, arr):
    arr = [-INF] + arr + [INF]
    low = 0
    high = len(arr)
    t = (low+high)//2
    while low<high-1:
        if query>arr[t]:
            low = t
        else:
            high = t
        t = (low+high)//2
    return arr[low], arr[high]

def find(query):
    s1, s2 = binary_search(query, S)
    t1, t2 = binary_search(query, T)
    return s1, s2, t1, t2

def main():
    for x in X:
        s1, s2, t1, t2 = find(x)
        ss = [s1, s2]
        tt = [t1, t2]
        ans = INF
        for s in ss:
            for t in tt:
                d1 = abs(t-x) + abs(s-t)
                d2 = abs(s-x) + abs(t-s)
                ans = min(ans, d1, d2)
        print(ans)
    return

main()

### FIXED CODE ###

A, B, Q = map(int, input().split())
INF = 10**12
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]
X = [int(input()) for _ in range(Q)]


def binary_search(query, arr):
    low = 0
    high = len(arr)
    while high-low>1:
        mid = (low+high)//2
        if query>arr[mid]:
            low = mid
        else:
            high = mid
    return arr[low], arr[high]

def main():
    for x in X:
        s1, s2 = binary_search(x, S)
        t1, t2 = binary_search(x, T)
        ans = [ abs(t-s)+min(abs(t-x), abs(s-x)) \
            for t in [t1, t2] for s in [s1, s2] ]
        print(min(ans))
    return

main()
### BUGGY CODE ###

import numpy as np

n,k = map(int, input().split())
d = np.array(list(map(int, input().split())))
l = np.arange(n)
ans = np.array([0]*n)
cnt = 0

def func(x_left, x_right):
  for x_l,x_r in zip(x_left,x_right):
      ans[x_l:x_r] += 1

while True:
  if np.all(d==n):
    ans = d
    break

  if cnt == k or cnt==100:
    break

  ans *= 0
  x_left = l-d
  x_left[x_left < 0] = 0
  x_right = l+d+1
  x_right[x_left > n] = n
  func(x_left, x_right)
  cnt += 1
  d = ans.copy()

  
print(' '.join(map(str, ans)))


### FIXED CODE ###

import sys
import numpy as np
from numba import njit
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
@njit('(i8[::1],)', cache=True)
def update(A):
    N = len(A)
    B = np.zeros_like(A)
    for i, x in enumerate(A):
        l = max(0, i - x)
        r = min(N - 1, i + x)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1
    B = np.cumsum(B)
    return B
 
N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)
 
K = min(K, 100)
for _ in range(K):
    A = update(A)
print(' '.join(A.astype(str)))
### BUGGY CODE ###

import itertools

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

ans = 0
L.sort()

for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if L[i] < L[j] + L[k] and L[j] < L[k]+L[i] and L[k] < L[i]+L[j]:
                ans += 1
            else:
                break
print(ans)

### FIXED CODE ###

import bisect

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

ans = 0
L.sort()

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        idx = bisect.bisect_left(L, L[i] + L[j])
        ans += max(0, idx - j - 1)
print(ans)
### BUGGY CODE ###

import sys
import math
from fractions import Fraction
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict

MOD = 10**9+7
N = int(input())
dic = defaultdict(int)
gp = []
zero = 0
left_zero = 0
right_zero = 0
for i in range(N):
    a,b = map(int, input().split())
    if b < 0:
        a = -a
        b = -b
    if a == 0 and b != 0:
        left_zero += 1
    elif a != 0 and b == 0:
        right_zero += 1
    elif a == 0 and b == 0:
        zero += 1
    else:
        g = math.gcd(a, b)
        a //= g
        b //= g
        dic[Fraction(a, b)] += 1
        gp.append((a, b))
done = defaultdict(bool)
ans = 1
for a,b in gp:
    k = Fraction(a, b)
    if done[k]: continue
    rk = Fraction(-b, a)
    done[k] = True
    done[rk] = True
    cnt1 = pow(2, dic[k], MOD)-1
    cnt2 = pow(2, dic[rk], MOD)-1
    c = cnt1+cnt2+1
    ans *= c
    ans %= MOD
c1 = pow(2, left_zero, MOD)-1
c2 = pow(2, right_zero, MOD)-1
c = c1+c2+1
ans *= c
ans += zero
ans %= MOD
print((ans-1)%MOD)


### FIXED CODE ###

import sys
import math
from fractions import Fraction
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict

MOD = 10**9+7
N = int(input())
dic = defaultdict(int)
gp = []
zero = 0
left_zero = 0
right_zero = 0
for i in range(N):
    a,b = map(int, input().split())
    if b < 0:
        a = -a
        b = -b
    if a == 0 and b != 0:
        left_zero += 1
    elif a != 0 and b == 0:
        right_zero += 1
    elif a == 0 and b == 0:
        zero += 1
    else:
        g = math.gcd(a, b)
        a //= g
        b //= g
        dic[str(Fraction(a, b))] += 1
        gp.append((a, b))
done = defaultdict(bool)
ans = 1
for a,b in gp:
    k = str(Fraction(a, b))
    if done[k]: continue
    rk = str(Fraction(-b, a))
    done[k] = True
    done[rk] = True
    cnt1 = pow(2, dic[k], MOD)-1
    cnt2 = pow(2, dic[rk], MOD)-1
    c = cnt1+cnt2+1
    ans *= c
    ans %= MOD
c1 = pow(2, left_zero, MOD)-1
c2 = pow(2, right_zero, MOD)-1
c = c1+c2+1
ans *= c
ans += zero
ans %= MOD
print((ans-1)%MOD)
### BUGGY CODE ###

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

cf=[(0, 0)]*(n+1)

for i in range(1, n+1):
    cf[i] = tuple( map(int, input().split()) )

dp=[0]*(we+1)

best=0

for i in range(1, n+1):
    for j in reversed(range(cf[i][0], we+1)):
        dp[j]=max( dp[j], dp[j-cf[i][0]]+ cf[i][1] )
        
    best=max(best, dp[we])


print(best)

# for i in range(1, n+1): print( dp[i], '\n' )

### FIXED CODE ###

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

cf=[(0, 0)]*(n+1)

for i in range(1, n+1):
    cf[i] = tuple( map(int, input().split()) )

dp=[[0]*(we+1) for _ in range(n+1)]

best=0

for i in range(1, n+1):
    for j in range(cf[i][0]):
        dp[i][j]=dp[i-1][j]
    for j in range(cf[i][0], we+1):
        dp[i][j]=max( dp[i][j-1], dp[i-1][j], dp[i-1][j-cf[i][0]]+ cf[i][1] )
    best=max(best, dp[i][we])


print(best)

# for i in range(1, n+1): print( dp[i], '\n' )
### BUGGY CODE ###

from collections import Counter

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

if len(set(V)) == 1:
    print(len(V)//2)
    exit()

V_odd = [i for i in V[::2]]
V_even = [i for i in V[1::2]]
V_odd_counter = Counter(V_odd)
V_even_counter = Counter(V_even)

vodd = V_odd_counter.most_common()
veven = V_even_counter.most_common()
vlen = len(V)
while True:
    if vodd[0][0] != veven[0][0]:
        print(vlen - vodd[0][1] - veven[0][1])
        exit()
    else:
        print(min(vlen - vodd[1][1] - veven[0][1],
                    vlen - vodd[0][1] - veven[1][1]))

### FIXED CODE ###

from collections import Counter

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

if len(set(V)) == 1:
    print(len(V)//2)
    exit()

V_odd = [i for i in V[::2]]
V_even = [i for i in V[1::2]]
V_odd_counter = Counter(V_odd)
V_even_counter = Counter(V_even)

vodd = V_odd_counter.most_common()
veven = V_even_counter.most_common()
vlen = len(V)
while True:
    if vodd[0][0] != veven[0][0]:
        print(vlen - vodd[0][1] - veven[0][1])
        exit()
    else:
        print(min(vlen - vodd[1][1] - veven[0][1],
                    vlen - vodd[0][1] - veven[1][1]))
        exit()
### BUGGY CODE ###

from collections import deque
h, w, m = map(int, input().split())
hl=[0]*h
wl=[0]*w
mh=0
mw=0
mhi=[]
dic = {}
mwi=[]
#ans =[[0]*w for i in range(h)]
s = [list(map(int, input().split())) for i in range(m)]

for i in range(m):
  a, b = s[i]
  a-=1
  b-=1
  if not a in dic:
    dic[a] = deque([b])
  else:
    dic[a].append(b)

  hl[a]+=1
  if hl[a]>mh:
    mh=hl[a]
    mhi = [a]
  elif hl[a]==mh:
    mhi.append(a)
  
  wl[b]+=1
  if wl[b]>mw:
    mw=wl[b]
    mwi=[b]
  elif wl[b]==mw:
    mwi.append(b)

  #ans[a][b]+=1

for i in mhi:
  for j in mwi:
    if not j in dic[i]:
      print(mw+mh)
      quit()

print(mh+mw-1)

### FIXED CODE ###

from collections import deque
h, w, m = map(int, input().split())
hl=[0]*h
wl=[0]*w
mh=0
mw=0
mhi=deque([])
dic = {}
mwi=deque([])
#ans =[[0]*w for i in range(h)]
s = [list(map(int, input().split())) for i in range(m)]
 
for i in range(m):
  a, b = s[i]
  a-=1
  b-=1
  if not a in dic:
    dic[a] = {}
    dic[a][b]=1
  else:
    dic[a][b]=1
 
  hl[a]+=1
  if hl[a]>mh:
    mh=hl[a]
    mhi = [a]
  elif hl[a]==mh:
    mhi.append(a)
  
  wl[b]+=1
  if wl[b]>mw:
    mw=wl[b]
    mwi=[b]
  elif wl[b]==mw:
    mwi.append(b)
 
  #ans[a][b]+=1

for i in mhi:
  for j in mwi:
    if not j in dic[i]:
      print(mw+mh)
      quit()

print(mh+mw-1)
### BUGGY CODE ###

N,K = map(int,input().split())
R,S,P = map(int,input().split())
A = input()
List = [[]]*K
for x in range(N):
  y = x % K
  List[y] = List[y] + [A[x]]
 
s = 0
for i in range(K):
  for j in range(len(List[i])-1):
    if List[i][j] == List[i][j+1]:
      List[i][j+1] = 't'
    k = List[i][j]
    if k == 'r':
      s += P
    elif k == 's':
      s += R
    elif k == 'p':
      s += S
    else:
      s = s
  l = List[i][len(List[i])-1]  
  if l == 'r':
      s += P
  elif l == 's':
      s += R
  elif l == 'p':
      s += S
  else:
      s = s
   
print(s)        

### FIXED CODE ###

N,K = map(int,input().split())
R,S,P = map(int,input().split())
T= input()
def score(x):
  if x == 'r':
    return P
  elif x == 's':
    return R
  elif x == 'p':
    return S
  else:
    return 0
s = 0
List = [x for x in T]
for t in range(len(T)-K):
  if List[t] == List[t+K]:
    List[t+K] = 'z' 
for y in List:  
  s += score(y)
print(s)
### BUGGY CODE ###

from collections import defaultdict

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

PYlist = []
PYmap = defaultdict(list)

for _ in range(M):
    P, Y = map(int, input().split())
    PYlist.append((P, Y))
    PYmap[P].append(Y)
for Ylist in PYmap.values():
    Ylist.sort()

for P, Y in PYlist:
    print(format(P, '06') + format(PYmap[P].index(Y)+1, '06'))

### FIXED CODE ###

from collections import defaultdict

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

city = []

for i in range(M):
    P, Y = map(int, input().split())
    city.append([i, P, Y])
city.sort(key=lambda x: x[2])

count = defaultdict(lambda: 0)
for c in city:
    count[c[1]] += 1
    c.append(count[c[1]])
city.sort(key=lambda x: x[0])

for _, P, _, n in city:
    print(format(P, '06') + format(n, '06'))
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]
for index in lr:
    str = s[index[0]-1:index[1]]
    print(str.count('AC'))


### FIXED CODE ###

n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]
a = [0] * 100010
count = 0 
for i in range(1,len(s)):
    if s[i] == 'C' and s[i-1] == 'A':
        count += 1
    a[i] = count
# print(a)
for index in lr:
    # print(index)
    print(a[index[1]-1] - a[index[0]-1])
### BUGGY CODE ###

def main():
    from sys import stdin
    input = stdin.readline
    import numpy as np
    h, w, n = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in [0]*n]
    ab_d = {(a, b) for a, b in ab}

    ans = [set() for _ in range(10)]
    ans[0] = 0
    for a, b in ab:
        temp = np.zeros((5, 5), dtype=np.int8)
        yoko_0 = max(3-b, 0)
        yoko_1 = min(w-b+3, 5)
        tate_0 = max(3-a, 0)
        tate_1 = min(h-a+3, 5)
        for i in range(tate_0, tate_1):
            for j in range(yoko_0, yoko_1):
                if (a+i-2, b+j-2) in ab_d:
                    temp[i, j] = 1
        # print(temp)
        for i in range(tate_0, tate_1-2):
            for j in range(yoko_0, yoko_1-2):
                ans[np.sum(temp[i:i+3, j:j+3])].add((a+i, b+j))

    for i in range(9):
        ans[i+1] = len(ans[i+1])

    print((h-2)*(w-2)-sum(ans))
    for i in ans[1:]:
        print(i)


main()


### FIXED CODE ###

h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in [0]*n]
ab_d={a*(10**9)+b-1 for a,b in ab}

ans=[set() for _ in range(9)]
for a,b in ab:
    temp=[None for _ in [0]*25]
    for i in range(5):
        for j in range(5):
            if 0<a+i-2<=h and 0<b+j-2<=w:
                if (a+i-2)*(10**9)+b+j-3 in ab_d:
                    temp[i*5+j]=1
                else:
                    temp[i*5+j]=0
    for i in range(3):
        for j in range(3):
            cnt=[temp[(i+k)*5+j+l] for k in range(3) for l in range(3)]
            if None not in cnt:
                ans[sum(cnt)-1].add((a+i-2)*(10**9)+b+j-3)
                
for i in range(9):
    ans[i]=len(ans[i])

print((h-2)*(w-2)-sum(ans))
for i in ans:
    print(i)
### BUGGY CODE ###

# 数列aの最小値min_aの最大値はM//N
# 他の要素がmin_aの倍数であれば、min_aが最大公約数となる
# すなわち、(M-min_a)をmin_aで割った余りが0でありかつ、商がN-1以上

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

ans = 0
for i in range(1, M//N+1):
    r, q = divmod((M - i), i)
    if r >= N - 1 and q == 0:
        ans = max(ans, i)
print(ans)

### FIXED CODE ###

# 数列aの最小値min_aの最大値はM//N
# 他の要素がmin_aの倍数であれば、min_aが最大公約数となる
# すなわち、(M-min_a)をmin_aで割った余りが0

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

if M%2 == 0:
    for i in range(M//N, 0, -1):
        if (M - i)%i == 0:
            break
    print(i)    
else:
    if M//N % 2 == 0:
        min_a = M//N - 1
    else:
        min_a = M//N
    for i in range(min_a, 0, -2):
        if (M - i)%i == 0:
            break
    print(i)
### BUGGY CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    start = time.time()
    n,m = LI()
    a = [LI() for _ in range(m)]
    e = [[] for _ in range(n)]
    for l,r,d in a:
        e[l-1].append((r-1,d))
        e[r-1].append((l-1,-d))

    b = [False] * n
    def g(i,c):
        gt = time.time() - start
        if gt > 1.7:
            return True
        if c == False:
            c = 0
        b[i] = c
        for r,d in e[i]:
            if b[r] != False:
                if b[r] != c+d:
                    return False
            else:
                if not g(r,c+d):
                    return False
        return True

    for i in range(n):
        if b[i] != False:
            continue
        if not g(i,False):
            return 'No'
    return 'Yes'


print(main())





### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    e = [[] for _ in range(n)]
    if m > 0:
        for _ in range(m):
            l,r,d = LI()
            e[l-1].append((r-1,d))
            e[r-1].append((l-1,-d))

    b = [None] * n

    for i in range(n):
        if not b[i] is None:
            continue
        b[i] = 0
        q = [i]
        qi = 0
        nq = []
        while True:
            if len(q) == qi:
                if not nq:
                    break
                q = nq
                qi = 0
                nq = []
            j = q[qi]
            qi += 1
            c = b[j]
            for r,d in e[j]:
                if b[r] is None:
                    b[r] = c+d
                    nq.append(r)
                else:
                    if b[r] != c+d:
                        return 'No'

    return 'Yes'


print(main())
### BUGGY CODE ###

x = int(input())

for a in range(10**4):
    for b in range(10**4):
        if(a**5 + b**5 == x):
            print(a, -b)
            break
        elif(a**5 - b**5 == x):
            print(a, b)
            break

### FIXED CODE ###

x = int(input())

for a in range(10**4):
    for b in range(10**4):
        if(a**5 + b**5 == x):
            print(a, -b)
            break
        elif(a**5 - b**5 == x):
            print(a, b)
            break
    else:
        continue
    break
### BUGGY CODE ###

times = int(raw_input())
numbers = []

for x in xrange(times):
    number = int(raw_input())
    if number not in numbers:
        numbers.append(number)
    else:
        numbers.remove(number)

print len(numbers)

### FIXED CODE ###

times = int(raw_input())
numbers = {}
result = 0

for x in xrange(times):
    number = int(raw_input())
    if number not in numbers:
        numbers[number] = 0
    numbers[number] += 1

for item in numbers:
    if numbers[item] % 2 != 0:
        result += 1

print result
### BUGGY CODE ###

from math import trunc, sqrt

def p(x,y,z):
    return x**2+y**2+z**2+x*y+y*z+z*x

def perm(x,y,z):
    if x==y and y==z and z==x:
        return 1
    if x!=y and y!=z and z!=x:
        return 6
    return 3

def eqn(n,x,y):
    s=4*n-3*x**2-2*x*y-3*y**2
    if s<0:
        return (False,0,0)

    t=sqrt(s)
    z1=(-t-x-y)/2
    z2=(t-x-y)/2
    return (True,z1,z2)
    

def is_int(x):
    return trunc(x)==x

def f(n):
    #print("==",n)
    mn=trunc(sqrt(n//3)+1)
    k=[]
    for x in range(1,mn+1):
        for y in range(1,mn+1):
            
            (f,z1,z2)=eqn(n,x,y)
            #print(f,z1,z2)
            
            if not f:
                continue

            if z1>0 and is_int(z1):
                k+=[(x,y,z1)]

            if z2!=z1:
                if z2>0 and is_int(z2):
                    k+=[(x,y,z2)]
            
    return len(k)

N=int(input())

for n in range(1,N+1):
    print(f(n))
    


### FIXED CODE ###

N=int(input())

a=[0]*N

x=1
while x*x<=N:
    y=1
    while x*x+y*y+x*y<=N:
        z=1
        while z*z+x*x+y*y+x*y+z*y+z*x<=N:
            a[z*z+x*x+y*y+x*y+z*y+z*x-1]+=1
            z+=1
        y+=1
    x+=1

for n in a:
    print(n)
### BUGGY CODE ###

# _*_ coding: utf-8 _*_

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

t = 0
bounds = [a, b, c, d, e]
nums = [n, 0, 0, 0, 0, 0]

while(nums[5] < n): # not all people have arrived at the destination
    for i in range(6):
        come = min(nums[i-1], bounds[i-1]) if i != 0 else 0
        go = min(nums[i], bounds[i]) if i != 5 else 0
        nums[i] = max(nums[i] + come - go, 0)

    t += 1

print(t)

### FIXED CODE ###

# _*_ coding: utf-8 _*_

n = int(input())

data = []
for i in range(5):
    data.append(int(input()))
flow = min(data)

if n % flow == 0:
    ans = n // flow + 4
else:
    ans = n // flow + 5

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

n, k = map(int, input().split())
A = list(map(int, input().split()))
score = []
wknum = 1
for i  in range(k):
    wknum *= A[i]

score.append(wknum)

for i in range(n - k):
    wknum //= A[i]
    wknum *= A[k + i]
    score.append(wknum)
    if score[i + 1] <= score[i]:
        print('No')
    else:
        print('Yes')


### FIXED CODE ###

import numpy as np

n, k = map(int, input().split())
A = np.array(input().split(), dtype = np.int64)
score = np.array([0 for i in range(n- k + 1)], dtype = np.int64)
wknum = 1
for i  in range(k):
    wknum *= A[i]

for i in range(n - k):
    wknum //= A[i]
    wknum *= A[k + i]
    if A[i] >= A[k + i]:
        print('No')
    else:
        print('Yes')
### BUGGY CODE ###

def main():
    N = int(input())
    li = [int(input()) for i in range(N)]
    li = sorted(li)
    # print(li)# 1 1 3 4 5 9
    result = [li[-1], li[0]]#9 1 
    diff_total = abs(li[-1] - li[0])
    del li[-1]
    del li[0]# 1 3 4 5
    index_l = None
    diff_l = -1
    while len(li) > 0:
        for ind, n in enumerate(li):
            diff = max(abs(n - result[0]), abs(n - result[-1]))
            # print(diff)
            if diff > diff_l:
                index_l = ind
                diff_l = diff
                # print("!")
        val = li[index_l]
        del li[index_l]
        a = abs(val - result[0])
        b = abs(val - result[-1])
        if a > b:
            result.insert(0, val)
            diff_total += a
        else:
            result.append(val)
            diff_total += b
        

        index_l = None
        diff_l = -1
        
        # print(result)
    print(diff_total)
    # print(" ".join([str(j) for  j in result]))
main()

### FIXED CODE ###

def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    A.sort()
    BIG, SMALL = -1, 0
    big_index = N-1
    small_index = 0

    left = A[big_index]
    left_sign = BIG
    right = A[big_index]
    right_sign = BIG
    big_index-=1
    result = 0
    for i in range(1, N):
        val1, val2 = 0, 0
        s = A[small_index]
        b = A[big_index]
        against1, against2 = 0, 0
        if left_sign == BIG:
            val1 = abs(left - s)
            against1 = SMALL
        else:
            val1 = abs(left - b)
            against1 = BIG
        if right_sign == BIG:
            val2 = abs(right - s)
            against2 = SMALL
        else:
            val2 = abs(right - b)
            against2 = BIG
        if val1 > val2:
            result += val1
            if against1 == BIG:
                left = b
                left_sign = against1
                # print(b)
                big_index -= 1
            else:
                left = s
                left_sign = against1
                # print(s)
                small_index += 1
        else:
            result += val2
            if against2 == BIG:
                right = b
                right_sign = against2
                # print(b)
                big_index -= 1
            else:
                right = s
                right_sign = against2
                # print(s)
                small_index += 1
    print(result)



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

from fractions import gcd

def solve():
    n = int(input())
    a = list(map(int,input().split()))
    x = 1
    for ai in a:
        x = (x * ai) // gcd(x, ai)
    ans = sum([x // ai for ai in a])
    print(ans % 1000000007)

if __name__ == "__main__":
    solve()


### FIXED CODE ###

from fractions import gcd

def solve():
    n = int(input())
    a = list(map(int,input().split()))
    x = 1
    for ai in a:
        x = (x * ai) // gcd(x, ai)
    ans = sum([x // ai for ai in a])
    print(ans % 1000000007)

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

n = int(input())
s = list(input())

ans = 0

for x in range(n):
  for y in range(n):
    if not x < y:
      continue
    if s[x] == s[y]:
      continue
    for z in range(n):
      if not x < y < z:
        # print("SKIP: ", x, y, z)
        continue

      if y-x == z-y:
        # print("SKIP: ", x, y, z)
        continue

      if not ((s[x] != s[y])  and (s[x] != s[z]) and (s[y] != s[z])):
        # print("SKIP: ", x, y, z)
        continue

      ans += 1
      # print(x, y, z)
      # print(s[x], s[y], s[z])

print(ans)


### FIXED CODE ###

n = int(input())
s = list(input())

ans = s.count("R") * s.count("G") * s.count("B")

for i in range(n):
  for j in range(n):
    if not i < j:
      continue
    k = j + (j-i)
    if k < n and "".join(sorted([s[i], s[j], s[k]])) == "BGR":
      ans -= 1

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

N=int(input())

A=list(map(int,input().split()))
B=[]
C=[]
ans=0

for i in range(N):
  B.append(A[i]+i+1)
  C.append(-A[i]+i+1)

for i in B:
  ans+=C.count(i)

print(ans)

### FIXED CODE ###

N=int(input())
 
A=list(map(int,input().split()))
#B=[]
#C=[]
D=[0]*1000000
E=[0]*1000000
 
ans=0
 
for i in range(N):
  if A[i]<500000:
  #B.append(A[i]+i+1)
  #C.append(-A[i]+i+1)
  #if -A[i]+i>=0:
  	D[A[i]+i]+=1
  	E[-A[i]+i]+=1
   #print(E[-A[i]+i],-A[i]+i)

for i in range(1000000):
  #ans+=C.count(i)
  ans+=D[i]*E[i]
 
print(ans)