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

def gcd(n,m):
  if n>m:
    return gcd(m,n);
  if n==0:
    return m;
  return gcd(m-n*(m//n),n)

def lcm(x, y):
    return (x * y) // gcd(x, y)
  
n=int(input())
a=list(map(int,input().split()))
s=1
for i in a:
  s=lcm(s,i)
ans=0
for i in a:
  ans+=s//i
print(ans % 1000000007)

### FIXED CODE ###

import collections
import math
n = int(input())
ai = [int(i) for i in input().split()]

mod = 10**9+7

if n == 1:
    print(1)
    exit()
    
    
# 素因数分解、辞書で返すやつ
# mathをimportする
def prime(n):
    factor = {}
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            if not num in factor.keys():
                factor[num] = 1
            else:
                factor[num] += 1
        if num > n:
            break
    if n != 1:
        if not n in factor.keys():
            factor[n] = 1
        else:
            factor[n] += 1
    return factor


dic = {}
for a in ai:
    pr = prime(a)
    for num, count in pr.items():
        if not num in dic.keys():
            dic[num] = count
        else:
            if dic[num] < count:
                dic[num] = count

kari = 1
for num,count in dic.items():
    kari *= pow(num,count,mod)
    kari %= mod

kari_old = kari
ans = 0

for i in range(n):
    kari = kari_old
    #com_ab_new = copy.deepcopy(com_ab)
    #print(com_ab,com_ab_new)
    #kari = 1
    #for j in range(kosu):
    #kari *= pow(sosu_li[j][0],com_ab[sosu_li[j][0]],mod)
    kari *= pow(ai[i],mod-2,mod)
    ans += kari
    ans %= mod
    #print(ans)
    #print(ans)
        
print(ans)
### BUGGY CODE ###

N = int(input())
A = [input() for _ in range(N)]

d = []
for i in A:
    if i in d:
        d.remove(i)
    else:
        d.append(i)
print(len(d))


### FIXED CODE ###

from collections import Counter
N = int(input())
A = [input() for _ in range(N)]

res = 0
#print(Counter(A))

c = Counter(A)
for i in c.values():
    res += i % 2
print(res)
### BUGGY CODE ###

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n
    self.ans = n*(n-1)//2
  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]
  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return

    if self.parents[x] > self.parents[y]:
      x, y = y, x
    sx = self.size(x)
    sy = self.size(y)
    self.ans += sx*(sx-1)//2 + sy*(sy-1)//2 - (sx+sy)*(sx+sy-1)//2

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x):
    return -self.parents[self.find(x)]

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = map(int,input().split())
pp = [list(map(int,input().split())) for i in range(M)]
uf = UnionFind(N)
ans = [uf.ans]
for i in range(M,1,-1):
  uf.union(pp[i-1][0]-1, pp[i-1][1]-1)
  ans = [uf.ans] + ans
print('\n'.join(map(str, ans)))

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.ans = n*(n-1)//2

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
    
        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x
        sx = self.size(x)
        sy = self.size(y)
        self.ans += sx*(sx-1)//2 + sy*(sy-1)//2
        self.ans -= (sx+sy)*(sx+sy-1)//2

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    def cnt(self):
        return sum([uf.size(i)*(uf.size(i)-1)//2 for i in self.roots()])

######
N,M = map(int,input().split())
ansal = int(N*(N-1)/2)
uf = UnionFind(N)
ans = [uf.ans]
pp = [list(map(int,input().split())) for i in range(M)]
for i in range(M,1,-1):
  uf.union(pp[i-1][0]-1, pp[i-1][1]-1)
  ans.append(uf.ans)
for i in range(M-1,-1,-1):
  print(ans[i])
### BUGGY CODE ###

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


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
checked = {"".join([str(v) for v in range(M)])}
while Q:
    sports_cand = Q.pop(0)
    n_sports = [0]*M
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                n_sports[mat[n][m]] += 1
                break
    max_val = max(n_sports)
    for i, v in enumerate(n_sports):
        if v == max_val:
            ans = min(ans, v)
            next_state = "".join(map(str, sports_cand-{i}))
            if len(sports_cand) > 2 and not next_state in checked:
                Q.append(sports_cand-{i})
                checked.add(next_state)
print(ans)


### FIXED CODE ###

from collections import Counter
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
mat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]

ans = N
Q = [set([v for v in range(M)])]
while Q:
    C = Counter()
    sports_cand = Q.pop(0)
    for n in range(N):
        for m in range(M):
            if mat[n][m] in sports_cand:
                C[mat[n][m]] += 1
                break
    tmp = 0
    for key, val in C.most_common():
        if val > tmp:
            tmp = val
            ans = min(ans, val)
            if len(sports_cand) > 2:
                Q.append(sports_cand-{key})
        else:
            break
print(ans)
### BUGGY CODE ###

N = int(input())
B = [int(input()) for i in range(N)]
A = [0]
A.extend(B)
past = [1]
next_l = 1
if not 2 in A:
  print(-1)
  exit(0)
for i in range(N):
  next_l = A[next_l]
  if next_l in past or next_l > N:
    print(-1)
    exit(0)
  if next_l == 2:
    print(len(past))
    exit(0)
  past.append(next_l)
print(-1)


### FIXED CODE ###

N = int(input())
B = [int(input()) for i in range(N)]
A = [0]
A.extend(B)
past = [1]
next_l = 1
#if not 2 in A:
#  print(-1)
#  exit(0)
for i in range(N):
  next_l = A[next_l]
  #if next_l in past or next_l > N:
  #  print(-1)
  #  exit(0)
  if next_l == 2:
    print(len(past))
    exit(0)
  past.append(next_l)
print(-1)
### BUGGY CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
from pprint import pprint



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


def digit_dp(n, f):
    dp = [[[0] * f for _ in range(2)] for _ in range(10002)]
    dp[0][0][0] = 1
    l = len(str(n))
    for i in range(l):
        max_d = int(str(n)[i])
        for j in range(2):
            for k in range(f):
                for d in range(10 if j else max_d + 1):
                    dp[i + 1][j or (d < max_d)][(k + d) % f] += dp[i][j][k]
                    dp[i + 1][j or (d < max_d)][(k + d) % f] %= mod
    return dp[l][0][0] + dp[l][1][0] - 1


k = I()
d = I()
print(digit_dp(k, d) % mod)


### FIXED CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
from pprint import pprint



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


def digit_dp(n, f):
    dp = [[[0] * f for _ in range(2)] for _ in range(10002)]
    dp[0][0][0] = 1
    l = len(n)
    for i in range(l):
        max_d = int(n[i])
        for j in range(2):
            for ki in range(f):
                for di in range(10 if j else max_d + 1):
                    dp[i + 1][j or (di < max_d)][(ki + di) % f] += dp[i][j][ki]
                    dp[i + 1][j or (di < max_d)][(ki + di) % f] %= mod
    return dp[l][0][0] + dp[l][1][0] - 1


k = input()
d = int(input())
print(digit_dp(k, d) % mod)
### BUGGY CODE ###

n = int(input())
lst = list()
num = 0
for i in range(n):

    s = input()
    s = list(s)
    s.sort()
    lst.append(s)


for i in range(n):
    for j in range(i+1, n):
        if (lst[i] == lst[j]):
            num = num + 1
print(num)


### FIXED CODE ###

import math
n = int(input())
lst = list()
num = 0
flag = 1
for i in range(n):

    s = input()
    s = list(s)
    s.sort()
    lst.append(s)

lst.sort()

for i in range(n-1):
    if (lst[i] == lst[i+1]):
        flag = flag + 1
    else:
        if (flag > 1):
            num = num + math.factorial(flag) // (math.factorial(flag - 2) * 2)
        flag = 1
if (flag > 1):
    num = num + math.factorial(flag) // (math.factorial(flag - 2) * 2)
print(num)
### BUGGY CODE ###

ans = 0
n = int(input())
l = [input() for _ in range(n)]
s = set(l)
for i in s:
  if l.count(i)%2 != 0:
    ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
l = [int(input()) for _ in range(n)]
l.sort()
c = 1
ans = 0
for i in range(1, n):
  if l[i-1] == l[i]:
    c += 1
  else:
    ans += c%2
    c = 1
if c != 1:
  ans += c%2
else:
  ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())
X = []
Y = []
P = []
for _ in range(N):
    x, y, p = map(int, input().split())
    X.append(x)
    Y.append(y)
    P.append(p)

DX = [[0] * (1 << N) for _ in range(N)]
DY = [[0] * (1 << N) for _ in range(N)]

for i, x in enumerate(X):
    for k in range(1 << N):
        d = abs(x)
        for j, xx in enumerate(X):
            if k & (1 << j):
                d = min(d, abs(xx - x))
        DX[i][k] = d * P[i]
for i, y in enumerate(Y):
    for k in range(1 << N):
        d = abs(y)
        for j, yy in enumerate(Y):
            if k & (1 << j):
                d = min(d, abs(yy - y))
        DY[i][k] = d * P[i]

ANS = [1 << 100] * (N + 1)
PC = [0] * (1 << N)
for i in range(1, 1 << N):
    j = i ^ (i & (-i))
    PC[i] = PC[j] + 1

for i in range(1 << N):
    m = i ^ ((1 << N) - 1)
    j = m
    while 1:
        ans = 0
        for k in range(N):
            ans += min(DX[k][i], DY[k][j])
        
        pc = PC[i] + PC[j]
        ANS[pc] = min(ANS[pc], ans)
        
        if not j:
            break
        j = m & (j - 1)

print(*ANS, sep = "\n")


### FIXED CODE ###

N = int(input())
X = []
Y = []
P = []
for _ in range(N):
    x, y, p = map(int, input().split())
    X.append(x)
    Y.append(y)
    P.append(p)

DX = [[0] * (1 << N) for _ in range(N)]
DY = [[0] * (1 << N) for _ in range(N)]

for i, x in enumerate(X):
    for k in range(1 << N):
        d = abs(x)
        for j, xx in enumerate(X):
            if k & (1 << j):
                d = min(d, abs(xx - x))
        DX[i][k] = d * P[i]
for i, y in enumerate(Y):
    for k in range(1 << N):
        d = abs(y)
        for j, yy in enumerate(Y):
            if k & (1 << j):
                d = min(d, abs(yy - y))
        DY[i][k] = d * P[i]

ANS = [1 << 100] * (N + 1)
PC = [0] * (1 << N)
for i in range(1, 1 << N):
    j = i ^ (i & (-i))
    PC[i] = PC[j] + 1

RA = []
for i in range(1 << N):
    t = []
    for j in range(N):
        if i & (1 << j):
            t.append(j)
    RA.append(tuple(t))


mm = (1 << N) - 1
for i in range(1 << N):
    m = i ^ mm
    j = m
    while 1:
        ans = 0
        for k in RA[i^j^mm]:
            ans += min(DX[k][i], DY[k][j])
        
        pc = PC[i] + PC[j]
        ANS[pc] = min(ANS[pc], ans)
        
        if not j:
            break
        j = m & (j - 1)

print(*ANS, sep = "\n")
### BUGGY CODE ###

n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    maxv = max(n)
    winner = n.index(maxv)
    print(winner, maxv)

### FIXED CODE ###

n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0 and a == winner:
        maxv = max(n)
        winner = n.index(maxv)
    elif n[a] > maxv:
            maxv, winner = n[a], a
    elif n[a] == maxv:
            winner = min(winner, a)
    print(winner, maxv)
### BUGGY CODE ###

if __name__ == '__main__':
    N = int(input())
    L = sorted(list(map(int, input().split())))
    res = 0
    for i, li in enumerate(L[:-2]):
        for j, lj in enumerate(L[i+1:-1]):
            k = 0
            for k, lk in enumerate(L[i+j+2+k:]):
                if lk-lj >= li:
                    res += k
                    break
            else:
                res += k + 1
    print(res)


### FIXED CODE ###

import bisect


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

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

N = int(input())
tempM = 0
M = []

for i in range(N):
    for p in range(i+1):
        temp = p % (i+1)
        if temp > tempM:
            tempM = temp
    M.append(tempM)

print(sum(M))

### FIXED CODE ###

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

N = int(input())

print(int(N*(N-1)//2))
### BUGGY CODE ###

def main():
    s=input()
    q=int(input())
    queryy=[]

    for i in range(q):
        queryy.append(tuple(input().split()))
    check=-1
    for query in queryy:
    #   print(query)
        if query[0]=="1":
            check*=-1
        else:
            if query[1]=="1":
                if check==-1:
                    s=str(query[2])+s
                else:
                    s+=str(query[2])
                    
            else:
                if check==-1:
                    s+=str(query[2])
                else:
                    s=str(query[2])+s
    if check==1:
        print(s[::-1]) 
    else:
        print(s)

if __name__=="__main__":
    main()      


### FIXED CODE ###

def main():
    s=input()
    q=int(input())
    queryy=[]
    sent="a"
    back="a"
    for i in range(q):
        queryy.append(tuple(input().split()))
    check=-1
    for query in queryy:
    #   print(query)
        if query[0]=="1":
            check*=-1
        else:
            if query[1]=="1":
                if check==-1:
                    sent+=str(query[2])
                   # s=str(query[2])+s
                else:
                    back+=str(query[2])
                   # s+=str(query[2])
                    
            else:
                if check==-1:
                    back+=str(query[2])
                    #s+=str(query[2])
                else:
                    sent+=str(query[2])
                    #s=str(query[2])+s
   # print(type(sent))
    #if sent[0]=="1":
     #   sent=sent[1:]
    sent=sent[1:]
    sent=sent[::-1]   
    back=back[1:]

    if check==1:
        s=sent+s+back        
        print(s[::-1]) 
    else:
        s=sent+s+back
        print(s)

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

from copy import deepcopy
dx=[0,0,1,-1]
dy=[1,-1,0,0]

def dfs(y,x):
    global cnt
    Ice_cp[y][x]=0
    cnt+=1
    for i in range(4):
        mx=x+dx[i]
        my=y+dy[i]
        if 0<=mx<m and 0<=my<n and Ice_cp[my][mx]==1:
            dfs(my,mx)
            if Ice_cp[y][x]==0:
                return cnt
    return cnt

while True:
    m=input()
    n=input()
    if n==m==0:break
    maxInt=0
    Ice=[map(int,raw_input().split()) for i in range(n)]
    for i in range(n):
        for j in range(m):
            cnt=0
            Ice_cp=deepcopy(Ice)
            if Ice_cp[i][j]==1:
                maxInt=max(maxInt,dfs(i,j))
    print maxInt

### FIXED CODE ###

dx=[0,0,1,-1]
dy=[1,-1,0,0]

def dfs(y,x,cnt):
    global maxInt
    maxInt=max(maxInt,cnt)
    Ice[y][x]=0
    for i in range(4):
        mx=x+dx[i]
        my=y+dy[i]
        if mx<0 or m<=mx or my<0 or n<=my:
            continue
        if Ice[my][mx]==1:
            dfs(my,mx,cnt+1)
            Ice[my][mx]=1

while True:
    m=input()
    n=input()
    if n==m==0:break
    maxInt=0
    Ice=[map(int,raw_input().split()) for i in range(n)]
    for y in range(n):
        for x in range(m):
            if Ice[y][x]==1:
                dfs(y,x,1)
                Ice[y][x]=1
    print maxInt
### BUGGY CODE ###

def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, k = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    Unique = list(set(A))
    Dic = {x:A.count(x) for x in set(A)}

    if len(set(A)) <= k:
        print(0)
    else:
        Dicsort = sorted(Dic.items(), key=lambda x: x[1])
        cnt = 0
        for i in range(len(set(A)) - k):
            cnt += Dicsort[i][1]
        print(cnt)
resolve()

### FIXED CODE ###

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

Ad = {x:0 for x in set(A)}
if len(set(A)) <= K:
    print(0)
else:
    count = 0
    for a in A:
        Ad[a] += 1
    Ad = sorted(Ad.items(), key=lambda x:x[1])
    for i in range(len(set(A))-K):
        count += Ad[i][1]
    print(count)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
h,w,d = map(int,input().split())
ans = 0
x = [0]*(h*w+1)
y = [0]*(h*w+1)
for i in range(h):
    a = list(map(int,input().split()))
    for j in range(w):
        x[a[j]] = j
        y[a[j]] = i
q = int(input())
for i in range(q):
    l,r = map(int,input().split())
    ans = 0
    for i in range((r-l)//d): 
        ans += abs(x[l+d*i]-x[l+d*(i+1)])+abs(y[l+d*i]-y[l+d*(i+1)])
    print(ans)

### FIXED CODE ###

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
h,w,d = map(int,input().split())
ans = 0
x = [0]*(h*w+1)
y = [0]*(h*w+1)
for i in range(h):
    a = list(map(int,input().split()))
    for j in range(w):
        x[a[j]] = j
        y[a[j]] = i
q = int(input())
#飛び飛びの累積和をとる　視点と
cum_sum_d = [0]*(h*w+1)
for i in range(d,h*w+1):
    cum_sum_d[i] =  cum_sum_d[i-d] + abs(x[i]-x[i-d])+abs(y[i]-y[i-d])
for i in range(q):
    l,r = map(int,input().split())
    ans = cum_sum_d[r] - cum_sum_d[l]
    
    """ #TLE解
    for i in range((r-l)//d): 
        ans += abs(x[l+d*i]-x[l+d*(i+1)])+abs(y[l+d*i]-y[l+d*(i+1)])
        """
    print(ans)
### BUGGY CODE ###

s = str(input())
appeared = []
buff = [0 for i in range(27)]
appeared.append(buff)
for i in s:
    buff = [j for j in appeared[-1]]
    buff[ord(i)-ord("a")] += 1
    appeared.append(buff)


for i in range(0,len(s)):
    for j in range(i+1,len(s)+1):
        buff = [sj-si for sj,si in zip(appeared[j],appeared[i])]
        if max(buff) > (j-i)/2 and j-i>=2:
            print(i+1,j)
            exit()
print("-1 -1")

### FIXED CODE ###

s = str(input())

if len(s)==2 and s[0]==s[1]:
    print(1,2)
    exit()

for i in range(0,len(s)-2):
    buff = s[i:i+3]
    if buff[0]==buff[2]:
        print(i+1,i+3)
        exit()
    elif buff[0]==buff[1]:
        print(i+1,i+2)
        exit()
    elif buff[1]==buff[2]:
        print(i+2,i+3)
        exit()
print(-1,-1)
### BUGGY CODE ###

import numpy as np

N = int(input())
A = np.array([0] + input().split(), np.int32)
B = np.append(A[1:], 0)
S = np.abs(A - B).sum()

ans = [0] * (N + 1)
for i in range(1, N + 1):
    j = (i + 1) % (N + 1)
    d0 = A[i] - A[i - 1]
    d1 = A[j] - A[i - 1]
    f0 = d0 >= 0
    f1 = d1 >= 0
    # print(d0, d1)
    # i - 1, i, i + 1の並び
    if f0 == f1 and abs(d0) <= abs(d1):
        ans[i] = S
    # i - 1, i + 1, iの並び
    elif f0 == f1 and abs(d0) > abs(d1):
        ans[i] = S - 2 * abs(A[j] - A[i])
    # i, i - 1, i + 1の並び
    else:
        ans[i] = S - 2 * abs(d0)
print('\n'.join(str(x) for x in ans[1:]))


### FIXED CODE ###

N = int(input())
A = [0] + [int(i) for i in input().split()]

S = abs(A[N] - A[0])
for i in range(N):
    S += abs(A[i] - A[i + 1])

for i in range(1, N + 1):
    j = (i + 1) % (N + 1)
    ans = S - abs(A[i - 1] - A[i]) - abs(A[i] - A[j]) + abs(A[i - 1] - A[j])
    print(ans)
### BUGGY CODE ###

# coding: utf-8
n=int(input())
A=list(map(int,input().split()))
b=[]
for i in range(n):
    if i%2==0:
        b.append("{}".format(A[i]))
    else:
        b.insert(0,"{}".format(A[i]))

if n%2==1:
    b.reverse()
    print(" ".join(b))
else:
    print(" ".join(b))



### FIXED CODE ###

# coding: utf-8
n=int(input())
A=list(map(int,input().split()))
l=[]
r=[]
k=1
for i in range(n):
    if i%2==0:
        r.append("{}".format(A[i]))
    else:
        l.append("{}".format(A[i]))
l.reverse()

b=l+r

if n%2==1:
    b.reverse()

print(" ".join(b))
### BUGGY CODE ###

S = input()
T = input()
n = len(S)
m = len(T)

DP = [[''] * (m+1) for i in range(n+1)]

for i in range(n):
    for j in range(m):
        if S[i] == T[j]:
            DP[i+1][j+1] = DP[i][j] + S[i]
        else:
            DP[i+1][j+1] = DP[i+1][j] if len(DP[i+1][j]) > len(DP[i][j+1]) else DP[i][j+1]
        
print(DP[n][m])

### FIXED CODE ###

S = input()
T = input()
n = len(S)
m = len(T)

DP = [[0] * (m+1) for i in range(n+1)]
for i in range(n):
    for j in range(m):
        if S[i] == T[j]:
            DP[i+1][j+1] = DP[i][j] + 1
        else:
            DP[i+1][j+1] = max(DP[i+1][j], DP[i][j+1])

ans = ''
while n > 0 and m > 0:
    if S[n-1] == T[m-1]:
        n -= 1
        m -= 1
        ans += S[n]
    elif DP[n][m-1] > DP[n-1][m]:
        m -= 1
    else:
        n -= 1

print(ans[::-1])
### BUGGY CODE ###

k = int(input())
c = 0
if k%2 ==0 or k%5==0:
    print(-1)
    c=1
elif k==1:
    print(1)
    c=1
if c==0:
    t = 7

    for i in range(k):
        if int(t)%k==0 :
            print(i+1)
            break
        t = (10*t+7)

### FIXED CODE ###

k = int(input())
c = 0
if k%2 ==0 or k%5==0:
    print(-1)
    c=1
elif k==1:
    print(1)
    c=1
if c==0:
    t = 7

    for i in range(k):
        if int(t)%k==0 :
            print(i+1)
            break
        t = (10*t+7)%k