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

n,k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort(reverse=True)
f.sort()
af = [a[i]*f[i] for i in range(n)]
lower = 0
upper = max(af)
prev = 0
now = upper // 2
while now != prev:
  count = 0
  for i in range(n):
    if a[i]*f[i] > now:
      count += a[i] - now // f[i]
  if count <= k:
    upper = now
  else:
    lower = now
  prev = now
  now = (lower + upper) // 2

print(upper)

### FIXED CODE ###

n,k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort(reverse=True)
f.sort()
af = [a[i]*f[i] for i in range(n)]
lower = 0
upper = max(af)
prev = 0
now = upper // 2
while now != prev:
  count = 0
  for i in range(n):
    if a[i]*f[i] > now:
      count += a[i] - now // f[i]
  if count <= k:
    upper = now
  else:
    lower = now
  prev = now
  now = (lower + upper) // 2

print(upper)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
N, K = map(int, input().split())
H = sorted(list(map(int, input().split())), reverse=True)
l = len(H)
if K != 0:
    if len(H) <= K:
        print(0)
        sys.exit()
    for i in range(K):
        H.pop(0)
    if len(H)==0:
        print(0)
    else:
        print(sum(H))
else:
    print(sum(H))

### FIXED CODE ###

#!/usr/bin/env python3
import sys
N, K = map(int, input().split())
H = sorted(list(map(int, input().split())), reverse=True)
l = len(H)
if K != 0:
    if len(H) <= K:
        print(0)
    else:
        print(sum(H[K:]))
else:
    print(sum(H))
### BUGGY CODE ###

K, S = list(map(int,input().split()))
count = 0
for X in range(K+1):
  for Y in range(K+1):
    for Z in range(K+1):
      if X + Y + Z == S:
        count += 1
print(count)

### FIXED CODE ###

K, S = list(map(int,input().split()))
count = 0
#ZはXとYが決まった時点で自動的に決まる。
for X in range(K+1):
  for Y in range(K+1):
    Z = S - X - Y 
#範囲が条件ないならOK
    if 0 <= Z and Z <= K:
        count += 1
print(count)
### BUGGY CODE ###

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

if (b-a)%2==0:
    print((b-a)//2)
else:
    if a < math.floor(n/2):
        i = 0
        while True:
            b -= i
            if a <= 1:
                a = 1
            else:
                a -= i
            if a == b:
                print(i)
                break
            i += 1
    else:
        i = 0
        while True:
            a += i
            if b >= n:
                b = n
            else:
              b += i
            if a == b:
                print(i)
                break
            i += 1

### FIXED CODE ###

n,a,b = map(int,input().split())
i = 1
p = 0
if (b-a)%2==0:
    print((b-a)//2)
else:
    if a-1 < n-b:
        print(min((1+b+(a-2))//2,b-1))
    else:
        print(min((n-a+(n-b+1))//2,n-a))
### BUGGY CODE ###

from collections import defaultdict
from collections import deque
N = int(input())
# A_i,j = A[i-1][j-1]
A = [list(map(int,input().split(' '))) for i in [0]*N]

dic = defaultdict(int)
ns = [0] * N

ls = range(1,N+1)
ans = 0
while(True):
	new_ls = set([])
	for i in ls:
		if ns[i-1] >= N-1:
			continue
		j = A[i-1][ns[i-1]]
		dic[(i*j,i+j)] += 1
		if dic[(i*j,i+j)] == 2:
			new_ls.add(i)
			new_ls.add(j)
	if not new_ls:
		break
	for ind in new_ls:
		ns[ind-1] += 1
	ls = new_ls
	ans += 1

for i in range(N):
	if ns[i] != N-1:
		print(-1)
		exit()
print(ans)








### FIXED CODE ###

from collections import defaultdict
from collections import deque
N = int(input())
# A_i,j = A[i-1][j-1]
A = [list(map(int,input().split(' '))) for i in [0]*N]

dic = defaultdict(int)
ns = [0] * N

ls = range(1,N+1)
ans = 0
while(True):
	new_ls = set([])
	for i in ls:
		if ns[i-1] >= N-1:
			continue
		j = A[i-1][ns[i-1]]
		dic[(i*j,i+j)] += 1
		if dic[(i*j,i+j)] == 2:
			new_ls.add(i)
			new_ls.add(j)
	if not new_ls:
		break
	for ind in new_ls:
		ns[ind-1] += 1
	ls = new_ls
	ans += 1

for i in range(N):
	if ns[i] != N-1:
		print(-1)
		exit()
print(ans)
### BUGGY CODE ###

[n,k] = list(map(int,input().split()))
li = list(map(int,input().split()))

point = []

for i in range(n-k+1):
    point_new = 1
    for j in range(i,k+i):
        point_new *= li[j]
    point.append(point_new)
    
for i in range(1,len(point)):
    if point[i] > point[i-1]:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

[n,k] = list(map(int,input().split()))
li = list(map(int,input().split()))

orl = li[0]

for i in range(1,n-k+1):
    in_num = li[i+k-1]
    if in_num>orl:
        print('Yes')
    else:
        print('No')
    orl = li[i]
### BUGGY CODE ###

n = int(input())
s = input()
S=str(s)
A = set([])
ans = 0
for i in range(n-2):
  for j in range(i+1, n-1):

    x = int(S[i])
    y = int(S[j])

    if not((10*x+y) in A):
      A.add(10*x+y)
      ans += len(set(list(S[j+1::])))
print(ans)


### FIXED CODE ###

def my_index2(l, x, default=-1):
    return l.index(x) if x in l else default
n = int(input())
S = list(input())
for i in range(n):
  S[i] = int(S[i])
ans = 0
for i in range(10):
  a = my_index2(S[0:n-2],i)
  if a != -1:
    for j in range(10):
      b = my_index2(S[a+1:n-1], j) 
      if b!=-1:
        for k in range(10):
          c = my_index2(S[a+1+b+1::], k)
          if c!= -1:
            ans+=1
print(ans)
### BUGGY CODE ###

L, R = map(int, input().split())
mn = 2020

for i in range(L, R):
    for j in range(i+1, R+1):
        if mn > (i*j)%2019:
            mn = (i*j)%2019
        elif mn == 0:
            break
print(mn)

### FIXED CODE ###

L, R = map(int, input().split())
mn = 2020

for i in range(L, R):
    for j in range(i+1, R+1):
        if R - L >= 2019:
            mn = 0
            break
        elif mn > (i*j)%2019:
            mn = (i*j)%2019
        elif mn == 0:
            break
    if R - L >= 2019:
            break
    elif mn == 0:
            break
print(mn)
### BUGGY CODE ###

n = int(input())
a = []
for _ in range(n):
    i = int(input())
    try:
        a.remove(i)
    except ValueError:
        a.append(i)
print(len(a))

### FIXED CODE ###

import collections
import numpy as np
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
ans = collections.Counter(a)
c=list(ans.values())
c=np.array(c)
print(sum(c%2))
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    a[i] = list(format(a[i],'0b').zfill(60))
g = [0 for i in range(60)]
for i in range(60):
    for j in range(n):
        if a[j][i] == '1':
            g[i] += 1
ans = 0
for i in range(len(g)):
    ans += g[i]*(n-g[i])*(pow(2,59-i,10**9+7))
print(ans%(10**9+7))

### FIXED CODE ###

import numpy as np

n = int(input())
arr = np.array([int(i) for i in input().split()])
mod = 10 ** 9 + 7
s = 0

for i in range(60):
    c1 = np.count_nonzero(arr & 1) # 自分がnp.sumを利用したがどうしても正解になれなかった。なぜ？
    s += 2 ** i * c1 * (n - c1)
    arr >>= 1

print(s % mod)
### BUGGY CODE ###

balls = input().split(" ")

n = int(balls[0])
b = int(balls[1])
r = int(balls[2])

if( b == 0 ):
  print( 0 )
else:
  cntb = 0
  while( n > 0 ):
    cntb += min( b, n )
    n -= (b + r)
    
  print( cntb )

### FIXED CODE ###

balls = input().split(" ")

n = int(balls[0])
b = int(balls[1])
r = int(balls[2])


if( b == 0 ):
  print( 0 )
else:
  
  step = b + r 
  cnt = n // step
  remain = n % step
  bcnt = cnt * b + min( remain, b)
  
  print( bcnt )
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n = int(input())

a = [int(input()) for _ in range(n)]

for i in range(n):
    print(max(a[:i]+a[i+1:]))


### FIXED CODE ###

# -*- coding: utf-8 -*-
n = int(input())

a = [int(input()) for _ in range(n)]

most = max(a)
most_idx = a.index(most)
second = max(a[:most_idx] + a[most_idx+1:])

for i in range(n):
    print(second if a[i] == most else most)
### BUGGY CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit
from collections import Counter


def keyfunc(data):
    return (data[1], -data[0])


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = tuple([i+1, 0] for i in range(n))
    midway = [[0, 0] for i in range(n//100 + 1)]

    for i in range(q):
        a, v = (int(s) for s in readline().split())
        a -= 1
        base[a][1] += v
        a -= a % 100
        source = max(base[a:a+100], key=keyfunc)
        dest = midway[a//100]
        dest[0] = source[0]
        dest[1] = source[1]
        print(*max(midway, key=keyfunc))
    exit()


if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = [0] * n
    midway = [0] * (n//100 + 1)
    last = [0] * (n//10000 + 1)

    for _ in range(q):
        a, v = (int(s) for s in readline().split())

        a -= 1
        base[a] += v

        b = a - a % 100

        index = b
        value = base[b]
        end = b + 100 if b + 100 < n else n
        for i in range(b, end):
            if value < base[i]:
                value = base[i]
                index = i
        midway[b//100] = index

        c = a - a % 10000
        cc = c // 100

        index = c
        value = base[c]
        for i in midway[cc:cc+100]:
            if value < base[i]:
                value = base[i]
                index = i
        last[c//10000] = index

        index = last[0]
        value = base[index]
        for i in last:
            if value < base[i]:
                value = base[i]
                index = i

        print(index+1, value)
    exit()


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

l,r = map(int,input().split())
li = []
ans = 2019
for i in range(l,r):
    for j in range(i+1,r+1):
        a = (i*j)%2019
        ans = min(ans,a)
        if a == 0:
            break
print(ans)

### FIXED CODE ###

l,r = map(int,input().split())
value = 2019
if r - l > 2019:
    print(0)
else:
    l1 = l%2019
    r1 = r%2019
    ans = 100000000
    if r1>l1:
        for i in range(l,r):
            for j in range(i+1,r+1):
                if ans>(i*j)%2019:
                    ans = (i*j)%2019
        print(ans)
    else:
        print(0)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N, W = map(int, input().split())
 
dpt = [0] * (W+1)
 
for i in range(N):
    w, v = map(int, input().split())
    for j in range(W, w-1, -1):
        a = dpt[j]
        b = dpt[j-w]+v
        if a > b:
            dpt[j] = a
        else:
            dpt[j] = b
 
print(dpt[W])

### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
    N, W = map(int, input().split())
    
    dpt = [0] * (W+1)
    
    for i in range(N):
        w, v = map(int, input().split())
        for j in range(W, w-1, -1):
            a = dpt[j]
            b = dpt[j-w]+v
            if a > b:
                dpt[j] = a
            else:
                dpt[j] = b
    
    print(dpt[W])

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

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

at = [0]
for i in range(len(A)):
    at.append(A[i])
    if i > 0:
        at[-1] += at[i]

bt = [0]
for i in range(len(B)):
    bt.append(B[i])
    if i > 0:
        bt[-1] += bt[i]


n = 0
time = 0

for i, a in enumerate(at):
    for j, b in enumerate(bt):
        if a+b <= K and a+b >= time:
            time = a+b
            n = i + j

print(n)


### FIXED CODE ###

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

at = [0]
for i in range(len(A)):
    at.append(A[i])
    if i > 0:
        at[-1] += at[i]

bt = [0]
for i in range(len(B)):
    bt.append(B[i])
    if i > 0:
        bt[-1] += bt[i]


n = 0
time = 0


for i, a in enumerate(at):
    if a > K:
        break
    l = 0
    r = len(bt)-1
    while r - l > 1:
        m = (l+r)//2
        if bt[m] < K-a:
            l = m
        else:
            r = m
    if bt[r] <= K -a:
        b = bt[r]
    else:
        r -= 1
        b = bt[r]
    if i + r >= n:
        n = i + r

print(n)
### BUGGY CODE ###

S=input()
x,y=map(int,input().split())
xmove=[]
ymove=[]
x_dir=True
import itertools
first=True
for key,g in itertools.groupby(S):
  g=list(g)
  if key=="F":
    if first:
      x-=len(g)
    elif x_dir:
      xmove.append(len(g))
    else:
      ymove.append(len(g))
  elif key=="T":
    if len(g)%2==1:
      x_dir^=True
  first=False
  
stackX=[]
# index, move
XisOK=False
stackX.append([0,0])
while stackX:
  node=stackX.pop()
  ind=node[0]
  move=node[1]
  if ind==len(xmove):
    if x==move:
      XisOK=True
      break
    else:
      continue
  stackX.append([ind+1,move+xmove[ind]])
  stackX.append([ind+1,move+xmove[ind]*(-1)])
  
if not XisOK:
  print("No")
  exit(0)

stackY=[]
# index, move
YisOK=False
stackY.append([0,0])
while stackY:
  node=stackY.pop()
  ind=node[0]
  move=node[1]
  if ind==len(ymove):
    if y==move:
      YisOK=True
      break
    else:
      continue
  stackY.append([ind+1,move+ymove[ind]])
  stackY.append([ind+1,move+ymove[ind]*(-1)])

if YisOK:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

S = input()
X,Y = map(int,input().split())

# [文字,その文字が連続する数]
from collections import deque
sumS = deque()
import itertools
for key,g in itertools.groupby(S):
  sumS.append([key,len(list(g))])
  
startx = 0 # Fで始まる場合はX軸の正の方向にあらかじめ進めて置く
# 最初のTが出るまではX軸正の方向に進む
if sumS[0][0] == "F":
  startx = sumS[0][1]
  sumS.popleft()

xdir = True # X軸方向を向いている
dpXcur = set()
dpXcur.add(startx)
dpYcur = set()
dpYcur.add(0) # Y軸は必ず0から始まる
dpXnex = set()
dpYnex = set()
for i in range(len(sumS)):
  if sumS[i][0] == "F":
    steps = sumS[i][1] # 進む数
    if xdir: # X軸方向を向いている場合
      for x in dpXcur:
        dpXnex.add(x + steps)
        dpXnex.add(x - steps)
      dpXcur = dpXnex
      dpXnex = set()
    else:
      for y in dpYcur:
        dpYnex.add(y + steps)
        dpYnex.add(y - steps)
      dpYcur = dpYnex
      dpYnex = set()
  elif sumS[i][0] == "T":
    turns = sumS[i][1] # 方向転換する数
    if turns % 2 == 1:
      # 奇数回の場合はX/Y軸の切り替え (偶数回の場合は何も起こらない)
      xdir ^= True
      
if X in dpXcur and Y in dpYcur:
  print("Yes")
else:
  print("No")
### BUGGY CODE ###

import collections
import sys
input=sys.stdin.readline

class BIT:
  def __init__(self,n):
    self.n=n+1
    self.BIT=[0]*self.n
  def add(self,i,x):
    idx=i
    while idx<self.n:
      self.BIT[idx]+=x
      idx+=(idx&-idx)
  def _sum(self,i):
    ret=0
    idx=i
    while idx>0:
      ret+=self.BIT[idx]
      idx-=(idx&-idx)
    return ret
  def sum(self,l,r):
    return self._sum(r)-self._sum(l-1)
  def value(self,i):
    return self._sum(i)-self._sum(i-1)

n,q=map(int,input().split())
arr=list(map(int,input().split()))
query=[list(map(int,input().split()))+[i] for i in range(q)]
query=sorted(query,key=lambda x:x[0])
ans=[0]*q
bit=BIT(n)
pos_now=[-1]*(n+1)
pos_next=[[] for _ in range(n+1)]
for i in range(n):
  val=arr[i]
  if pos_now[val]==-1:
    pos_now[val]=i+1
    bit.add(i+1,1)
  else:
    pos_next[val].append(i+1)
cnt=collections.Counter(arr)
prev=1
for l,r,id in query:
  while prev<l:
    val=arr[prev-1]
    if cnt[val]!=1:
      bit.add(pos_now[val],-1)
      if len(pos_next[val])!=0:
        pos_now[val]=pos_next[val][0]
        pos_next[val]=pos_next[val][1:]
        bit.add(pos_now[val],1)
    prev+=1
  ans[id]=bit.sum(l,r)
for val in ans:
  print(val)

### FIXED CODE ###

import sys
input=sys.stdin.readline

class BIT:
  def __init__(self,n):
    self.n=n+1
    self.BIT=[0]*self.n
  def add(self,i,x):
    idx=i
    while idx<self.n:
      self.BIT[idx]+=x
      idx+=(idx&-idx)
  def _sum(self,i):
    ret=0
    idx=i
    while idx>0:
      ret+=self.BIT[idx]
      idx-=(idx&-idx)
    return ret
  def sum(self,l,r):
    return self._sum(r)-self._sum(l-1)
  def value(self,i):
    return self._sum(i)-self._sum(i-1)

n,q=map(int,input().split())
arr=list(map(int,input().split()))
query=[]
for i in range(q):
  l,r=map(int,input().split())
  query.append((l,r,i))
query=sorted(query,key=lambda x:x[0])
ans=[0]*q
bit=BIT(n)
pos_now=[-1]*(n+1)
pos_prev=[-1]*(n+1)
dic={}
for i in range(n):
  val=arr[i]
  dic[i+1]=-1
  if pos_now[val]==-1:
    bit.add(i+1,1)
    pos_now[val]=i+1
  if pos_prev[val]!=-1:
    dic[pos_prev[val]]=i+1
  pos_prev[val]=i+1
prev=1
for l,r,id in query:
  while prev<l:
    val=arr[prev-1]
    if dic[pos_now[val]]!=-1:
      pos_now[val]=dic[pos_now[val]]
      bit.add(pos_now[val],1)
    prev+=1
  ans[id]=bit.sum(l,r)
for val in ans:
  print(val)
### BUGGY CODE ###

#coding:utf-8
import math
l, r = map(int, input().split())
ans = (l*r) % 2019

for i in range(l, r-1):
    for j in range(0, r-l):
        if (i + j <= r) and (i != (i+j)):
            mod = (i * (i+j))% 2019
            if mod < ans:
                ans = mod

print(ans)

### FIXED CODE ###

#coding:utf-8
#余りが0になった時点で以降の処理をやめる
import math
l, r = map(int, input().split())
ans = 2018

for i in range(l, r+1):
    for j in range(i+1, r+1):
        mod = (i * j) % 2019
        if mod < ans:
            ans = mod
        if mod == 0:
            ans = 0
            break
    else:
    #最小値が入れ替わらない、もしくは0が出なかった場合は次の数と比較
        continue
    break

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

from sys import stdin
s = stdin.readline().rstrip()
n = len(s)
dic = {}
dic[0] = 1
now = 0
mul = 0
for i in range(n-1,-1,-1):
    now = (now+(10**mul)*int(s[i]))%2019
    if now in dic:
        dic[now] += 1
    else:
        dic[now] = 1
    mul += 1
print(sum(dic[i]*(dic[i]-1)//2 for i in dic))

### FIXED CODE ###

from sys import stdin
s = stdin.readline().rstrip()
n = len(s)
dic = {}
dic[0] = 1
now = 0
mul = 1
for i in range(n-1,-1,-1):
    now = (now+(10*mul)*int(s[i]))%2019
    if now in dic:
        dic[now] += 1
    else:
        dic[now] = 1
    mul *= 10
    mul %= 2019
print(sum(dic[i]*(dic[i]-1)//2 for i in dic))
### BUGGY CODE ###

from collections import Counter


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    n = read_int()
    A = read_ints()
    MAX = max(A)+1 # 10**6+1
    count = [Counter() for i in range(MAX)]
    modulo = 10**9+7
    # disassemble all numbers up to 10**6
    for number in range(2, MAX):
        if len(count[number]) > 0: # not prime
            continue
        for step in range(number, MAX, number):
            temp = number
            while step%temp == 0:
                count[step][number] += 1
                temp *= number
    max_counter = Counter()
    for a in A:
        for k, v in count[a].items():
            max_counter[k] = max(max_counter[k], v)
    answer = 0
    for a in A:
        B = 1
        for k, v in max_counter.items():
            B = (B*k**(v-count[a][k]))%modulo
        answer = (answer+B)%modulo
    return answer


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


### FIXED CODE ###

import math
from typing import List, Counter, Tuple
from collections import Counter
from itertools import permutations, zip_longest, groupby


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))

modulo = 10**9+7


def merge(A, start, end, divisors):
    if start == end:
        return Counter(divisors[A[start]])
    mid = start+(end-start)//2
    left = merge(A, start, mid, divisors)
    right = merge(A, mid+1, end, divisors)
    for r in right:
        left[r] = max(left[r], right[r])
    return left

def solve() -> int:
    N = read_int()
    A = read_ints()
    M = 10**6+1
    divisors: List[List[int]] = [[] for _ in range(M)]
    for i in range(2, M):
        if len(divisors[i]) == 0:
            for j in range(i, M, i):
                temp = j
                while temp%i == 0:
                    divisors[j].append(i)
                    temp //= i
    lcd_counter = merge(A, 0, N-1, divisors)
    lcd = 1
    for k in lcd_counter:
        lcd = (lcd*pow(k, lcd_counter[k], modulo))%modulo
    answer = 0
    for a in A:
        answer = (answer+(lcd*pow(a, modulo-2, modulo))%modulo)%modulo
    return answer


if __name__ == '__main__':
    print(solve())
### BUGGY CODE ###

N, A = map(int,input().split())
X = list(map(int,input().split()))
dp = [[[0 for _ in range(50*N + 1)] for _ in range(N+1)] for _ in range(N+1)]

dp[0][0][0] = 1
for i in range(1, N+1):
    for j in range(i+1):
        for k in range(50*N+1):
            dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-X[i-1]]

ans = 0
for i in range(1, N+1):
    ans += dp[N][i][A * i]
print(ans)

### FIXED CODE ###

N, A = map(int,input().split())
X = list(map(int,input().split()))
dp = [[[0 for _ in range(50*50 + 1)] for _ in range(N+1)] for _ in range(N+1)]

dp[0][0][0] = 1
for i in range(1, N+1):
    for j in range(i+1):
        for k in range(50*j+1):
            dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-X[i-1]]

ans = 0
for i in range(1, N+1):
    ans += dp[N][i][A * i]
print(ans)
### BUGGY CODE ###

import numpy as np

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

target = sum(a)//2

a = np.array(a)
a = np.concatenate((a, a))

for i in range(n):
    num = target
    for j in range(n//2):
        num -= a[i + 2*j + 1]
    print(num*2)


### FIXED CODE ###

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

target = sum(a)//2

b = a[1:n:2]
a.append(a[0])

ans = []
ans.append((target-sum(b))*2)

for i in range(n-1):
    num = a[i] - ans[i]//2
    ans.append(num*2)

for i in range(n):
    print(ans[i], end=' ')
### BUGGY CODE ###

s = input()
n = len(s)
k = int(input())

dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]].append(i)
    else:
        dic[s[i]] = [i]

for i in range(97, 123):
    moji = chr(i)
    if moji not in dic:
        continue
    kouho = dic[moji]
    strings = set([])
    for idx in kouho:
        e = idx+1
        while e <= n:
            strings.add(s[idx:e])
            e += 1
    if len(strings) >= k:
        strings = list(strings)
        strings.sort()
        print(strings[k-1])
        exit()
    else:
        k -= len(strings)

### FIXED CODE ###

s = input()
n = len(s)
k = int(input())

dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]].append(i)
    else:
        dic[s[i]] = [i]

for i in range(97, 123):
    moji = chr(i)
    if moji not in dic:
        continue
    kouho = dic[moji]
    strings = set([])
    for idx in kouho:
        e = idx+1
        string = set([])
        while e <= n and len(string) <= k:
            string.add(s[idx:e])
            e += 1
        strings = strings | string
    if len(strings) >= k:
        strings = list(strings)
        strings.sort()
        print(strings[k-1])
        exit()
    else:
        k -= len(strings)
### BUGGY CODE ###

import math
N, M = map(int, input().split())
S = str(input())
T = str(input())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(x, y):
    return (x * y) // gcd(x, y)
X = lcm(N ,M)

if S[0] != T[0]:
    print(-1)
elif X == N*M:
    print(N*M)
else:
    for i in range(1,(N*M//X)+1):
        L = X * i
        counter = L
        y = L // N
        z = L // M
        match = lcm( y, z)
        for j in range(1, (L // match) ):
            if S[j * N * match // L] != T[ j * M * match // L]:
                counter = -1
                break
        if counter == L:
            break
    print(counter)

### FIXED CODE ###

N, M = map(int, input().split())
S = str(input())
T = str(input())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
 
def lcm(x, y):
    return (x * y) // gcd(x, y)
X = lcm(N ,M)
 
if S[0] != T[0]:
    print(-1)
elif X == N*M:
    print(N*M)
else:
        L = X
        match = lcm(  L // N,  L // M)
        for j in range(1, (L // match) ):
            if S[j * N * match // L] != T[ j * M * match // L]:
                L = -1
                break
        if L == X :
            print(L)
        else:
            print(-1)