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

import math
N,K=map(int,input().split())

A=[i for i in range(N+1)]
wa=0
N=N+1
for i in range(K,N+1):
    mi=sum(A[0:i])
    ma=sum(A[N-i:N])


    wa=ma-mi+1+wa



print(wa)


### FIXED CODE ###

N,K=map(int,input().split())
wa=0
for i in range(N+1-K):
    n=i+K
    min=(n)*(0+n-1)/2
    max=(n)*(N-n+1+N)/2

    wa=max-min+wa+1


wa=wa+1
wa=wa%(10**9+7)
print(int(wa))
### BUGGY CODE ###

n = int(input())
a = [int(x) for x in input().split()]

ans = 1
for i in range(n):
    ans = ans * a[i]

if ans > 10 ** 18:
    print("-1")
else:
    print(ans)

### FIXED CODE ###

n = int(input())
a = [int(x) for x in input().split()]


ans = 1
a.sort()

for i in range(n):
    ans = ans * a[i]
    if a[i] == 0:
        print("0")
        exit(0)
    if ans > 10 ** 18:
        print("-1")
        exit(0)

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

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

MOD = 10**9 + 7

total = 0
for i in range(N):
  for j in range(i+1, N):
    total += A[i] * A[j]

print(total % MOD)

### FIXED CODE ###

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

MOD = 10**9 + 7

sum_a = sum(A)
sum_squares = sum([a*a for a in A])

ans = (sum_a**2 - sum_squares)//2
ans %= MOD

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

from queue import Queue

#入力
H, W = map(int, input().split())

lst = []
for i in range(H):
    lst += [list(input())]

count = 0 #白色のマスの総数
for i in range(H):
    for j in range(W):
        if lst[i][j] == '.':
            count += 1

sx, sy = 1, 1 #スタート位置
gx, gy = H, W #ゴール位置

move = [[1, 0], [0,1], [-1, 0], [0, -1]]

def bfs(x, y):
    q = Queue()
    INF = 10 ** 3
    d = [[INF]* W for _ in range(H)]
    q.put(x)
    q.put(y)
    d[x][y] = 0

    while True:
        px = q.get()
        py = q.get()
        if px == gx-1 and py == gy-1:
            break
        else:
            for dx, dy in move:
                nx = px + dx
                ny = py + dy

                if 0 <= nx and nx < H and 0 <= ny and ny < W and lst[nx][ny] == '.' and d[nx][ny] == INF:
                    q.put(nx)
                    q.put(ny)
                    d[nx][ny] = d[px][py] + 1
    return d[gx-1][gy-1]

a = bfs(sx-1, sy-1)

if a == 10 **9:
    print (-1)
else:
    print (count - a - 1)

### FIXED CODE ###

from queue import Queue

#入力
H, W = map(int, input().split())

#lst = [['a']*W for _ in range(H)]
count = 0 #白色のマスの総数
lst = []
row = []
for i in range(H):
    row = list(input())
    count += row.count('.')
    lst += [row]
 
#for i in range(H):
#    for j in range(W):
#        if lst[i][j] == '.':
#            count += 1

#sx, sy = 1, 1 #スタート位置
#gx, gy = H, W #ゴール位置

move = [[-1, 0], [1,0], [0, -1], [0, 1]]

def bfs():
    q = Queue()
    INF = 10 ** 9
    d = [[INF]* W for _ in range(H)]
    q.put(0)
    q.put(0)
    d[0][0] = 0

    while True:
        if q.empty():
            break
        else:
            px = q.get()
            py = q.get()
            if px == H-1 and py == W-1:
                break
            else:
                for dx, dy in move:
                    nx = px + dx
                    ny = py + dy

                    if 0 <= nx and nx < H and 0 <= ny and ny < W and lst[nx][ny] == '.' and d[nx][ny] == INF:
                        q.put(nx)
                        q.put(ny)
                        d[nx][ny] = d[px][py] + 1
    return d[H-1][W-1]

a = bfs()

if a == 10 **9:
    print (-1)
else:
    print (count - a - 1)
### BUGGY CODE ###

n, y = map(int, input().split())
while True:
    for i in range(1,n+1):
        for j in range(0, n+1-i):
            for k in range(0, n+1-i-j):
                if 10000*i + 5000*j + 1000*k == y:
                    print('i j k')
                    break
print('-1 -1 -1')

### FIXED CODE ###

n, y = map(int, input().split())
z = y/1000
for i in range(n+1):
    for j in range(n+1-i):
        k = n - i- j
        if 10*i + 5*j + k == z:
            print(i, j, k)
            exit(0)
print('-1 -1 -1')
### BUGGY CODE ###

n = int(input())
can = []
xyh = []
for _ in range(n):
  xyh.append(list(map(int,input().split())))
time = 0
while xyh[time][2] == 0:
  time += 1
x,y,h = xyh[time]
for i in range(101):
  for j in range(101):
    can.append([i, j, h + abs(x-i) + abs(y-j)])
step = 1
while len(can) != 1:
  x,y,h = xyh[(time + step) % n]
  if h != 0:
    cnt = 0
    while cnt < len(can):
      now = can[cnt]
      if now[2] != h + abs(x-now[0]) + abs(y-now[1]):
        del can[cnt]
      else:
        cnt += 1
  else:
    cnt = 0
    while cnt < len(can):
      now = can[cnt]
      if now[2] < abs(x-now[0]) + abs(y-now[1]):
        del can[cnt]
      else:
        cnt += 1
  step += 1
print(' '.join(list(map(str,can[0]))))

### FIXED CODE ###

n = int(input())
can = []
xyh = []
for _ in range(n):
  xyh.append(list(map(int,input().split())))
time = 0
while xyh[time][2] == 0:
  time += 1
x,y,h = xyh[time]
for i in range(101):
  for j in range(101):
    can.append([i, j, h + abs(x-i) + abs(y-j)])
step = 0
while len(can) != 1:
  x,y,h = xyh[(time + step) % n]
  if h != 0:
    cnt = 0
    while cnt < len(can):
      now = can[cnt]
      if now[2] != h + abs(x-now[0]) + abs(y-now[1]):
        del can[cnt]
      else:
        cnt += 1
  else:
    cnt = 0
    while cnt < len(can):
      now = can[cnt]
      if now[2] > abs(x-now[0]) + abs(y-now[1]):
        del can[cnt]
      else:
        cnt += 1
  step += 1
print(' '.join(list(map(str,can[0]))))
### BUGGY CODE ###

a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
for i in range(t):
    a += v
    b += w

if a >= b:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
flg = 1
if a > b:
    flg = -1

a = a+v*t*flg
b = b+w*t*flg

if flg == 1:
    if a >= b:
        print('YES')
    else:
        print('NO')
else:
    if a <= b:
        print('YES')
    else:
        print('NO')
### BUGGY CODE ###

A, B, C, K = map(int, input().split())
S = {'A': 1, 'B': 0, 'C': -1}
M = {'A': 0, 'B': 0, 'C': 0}
while K > 0:
    if A > 0:
        K -= 1
        A -= 1
        M['A'] += 1
    elif B > 0:
        K -= 1
        B -= 1
        M['B'] += 1
    elif C > 0:
        K -= 1
        C -= 1
        M['C'] += 1

ans = S["A"]*M["A"] + S["B"]*M["B"] + S["C"]*M["C"]
print(ans)


### FIXED CODE ###

a,b,c,k = map(int,input().split())
xa = min(a,k)
k -= xa
xb = min(b, k)
k -= xb
xc = k
print(xa-xc)
### BUGGY CODE ###

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

K, S = map(int, input().split())
count = 0

for x in range(0, K+1):
    for y in range(0, K+1):
        for z in range(0, K+1):
            if x + y + z == S:
                count += 1

print(count)


### FIXED CODE ###

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

K, S = map(int, input().split())
count = 0

for x in range(0, K+1):
    for y in range(0, K+1):
        z = S - x - y
        if z < 0 or z > K:
            continue
        if x + y + z == S:
            count += 1

print(count)
### BUGGY CODE ###

N, M = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
mod = 10 ** 9 + 7


a_list.sort(reverse=True)
b_list.sort(reverse=True)
a_list.append(-1)
b_list.append(-1)
ans = 1
a_i = 0
b_i = 0
for i in range(N*M, 0, -1):
    if i == a_list[a_i] and i == b_list[b_i]:
        a_i += 1
        b_i += 1
    elif i == a_list[a_i]:
        a_i += 1
        ans *= b_i % mod
    elif i == b_list[b_i]:
        b_i += 1
        ans *= a_i % mod
    else:
        ans *= (a_i*b_i - (N * M - i)) % mod
print(ans % mod)



### FIXED CODE ###

N, M = map(int, input().split())
a_list = tuple(map(int, input().split()))
b_list = tuple(map(int, input().split()))
mod = 10 ** 9 + 7

a_list = sorted(a_list, reverse=True)
b_list = sorted(b_list, reverse=True)
a_list.append(-1)
b_list.append(-1)
ans = 1
a_i = 0
b_i = 0
for i in range(N*M, 0, -1):
    if i == a_list[a_i] and i == b_list[b_i]:
        a_i += 1
        b_i += 1
    elif i == a_list[a_i]:
        a_i += 1
        ans *= b_i
        ans %= mod
    elif i == b_list[b_i]:
        b_i += 1
        ans *= a_i
        ans %= mod
    else:
        ans *= (a_i*b_i - (N * M - i))
        ans %= mod
print(ans % mod)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n,m=(int(i) for i in input().split())
a = [int(input()) for i in range(m)]
#print(n,m,a)

d=[0 for i in range(100000+10)]
p=1000000007
#n=100
#a=[1, 23, 45, 67, 89]
aa=[0 for i in range(100000+10)]

for i in range(10**5+10):
    if i in a:
        aa[i]=1
#print(aa)

d[0]=1
if aa[1] == 0:
    d[1]=1
else:
    d[1]=0
    
if aa[2] == 0:
    d[2]=d[1]+d[0]
else:
    d[2]=0
    
for i in range(2,n+1):
    if aa[i] == 0:
        d[i]=d[i-1]+d[i-2]
        d[i]=d[i]%p
    else:
        d[i]=0
#print(d)

print(d[n]%p)



### FIXED CODE ###

import sys
input = sys.stdin.readline
n,m=(int(i) for i in input().split())
a = [int(input()) for i in range(m)]
#print(n,m,a)

d=[0 for i in range(100000+10)]
p=1000000007
#n=100
#a=[1, 23, 45, 67, 89]
aa=[0 for i in range(100000+10)]

for i in a:
    aa[i]=1
#print(aa)

d[0]=1
if aa[1] == 0:
    d[1]=1
else:
    d[1]=0
    
if aa[2] == 0:
    d[2]=d[1]+d[0]
else:
    d[2]=0
    
for i in range(2,n+1):
    if aa[i] == 0:
        d[i]=d[i-1]+d[i-2]
        d[i]=d[i]%p
    else:
        d[i]=0
#print(d)

print(d[n]%p)
### BUGGY CODE ###

import queue
# class Queue:
#     def __init__(self, data=[]):
#         self.data = data
#
#     def enqueue(self, x):
#         self.data.append(x)
#
#     def dequeue(self):
#         return self.data.pop(0)
#
#     def is_Empty(self):
#         if len(self.data) == 0:
#             return True
#         else:
#             return False


H, W = map(int, input().split())  # H行W列

gridgraph = [list(input()) for _ in range(H)]  # H行W列のグリッドグラフ
visited = [[False]*W for _ in range(H)]
cnt = [[0]*W for _ in range(H)]

q = queue.Queue()

for i in range(H):
    for j in range(W):
        if gridgraph[i][j] == '#':
            q.put([i, j])  # 初期の時点で黒色のマスをqueueに追加する
            visited[i][j] = True

while not q.empty():
    cy, cx = q.get()

    for dy, dx in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
        if cy+dy >= H or cy+dy < 0 or cx+dx >= W or cx+dx < 0:
            continue
        if visited[cy+dy][cx+dx]:  # すでに訪問済みであればcontinue
            continue
        visited[cy+dy][cx+dx] = True  # 訪問済みにする
        cnt[cy+dy][cx+dx] = cnt[cy][cx] + 1
        q.put([cy+dy, cx+dx])


ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, cnt[i][j])

print(ans)


### FIXED CODE ###

import sys
from collections import deque
H, W = map(int, input().split())
gridgraph = []
for line in sys.stdin.readlines():
    line = line.rstrip()
    gridgraph.append(list(line))
q = deque()
visited = [[False]*W for _ in range(H)]
ans = [[1e+9]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if gridgraph[i][j] == "#":
            q.append((i, j))
            visited[i][j] = True
            ans[i][j] = 0

while len(q):
    cy, cx = q.popleft()

    for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        if not (cy+dy >= 0 and H-1 >= cy+dy and cx+dx >= 0 and W-1 >= cx+dx):
            continue
        if visited[cy+dy][cx+dx]:
            continue
        visited[cy+dy][cx+dx] = True
        ans[cy+dy][cx+dx] = min(ans[cy+dy][cx+dx], ans[cy][cx]+1)
        q.append((cy+dy, cx+dx))

min_value = 0
for a in ans:
    min_value = max(min_value, max(a))
print(min_value)
### BUGGY CODE ###

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

dp = [0]*N

dp[0] = 0

for j in range(1,N,1):
  dev_costs = []
  k = 1
  while j-k >= 0:
    dev_cost = dp[j-k] + abs(costs[j]-costs[j-k])
    dev_costs.append(dev_cost)
    if k ==  K:
      break
    k += 1
    
  dp[j] = min(dev_costs)
    
print(dp[-1])

### FIXED CODE ###

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

dp = [0]*N

dp[0] = 0

for j in range(1,N,1):
  dev_costs = []
  k = 1
  while j-k >= 0:
    dev_cost = dp[j-k] + abs(costs[j]-costs[j-k])
    dev_costs.append(dev_cost)
    if k ==  K:
      break
    k += 1
    
  dp[j] = min(dev_costs)
    
print(dp[-1])
### BUGGY CODE ###

import bisect
from itertools import product
import numpy as np

N = int(input())

dp = np.zeros(shape=(N, N), dtype=int)

for i in range(N):
    dp[i] = np.array(list(map(int, input().split(' '))))

original = dp.copy()

for k, i in product(range(N), repeat=2):
    dp[i] = np.minimum(dp[i], dp[i][k] + dp[k])

if not np.all(dp == original):
    print(-1)
else:
    costs = []
    for i in range(N):
        for j in range(i + 1, N):
            costs.append(dp[i][j])
    costs.sort()
    duplicated = set()
    for i in range(len(costs) - 1):
        if costs[i] in duplicated:
            continue
        for j in range(i + 1, len(costs)):
            if costs[j] in duplicated:
                continue
            index = bisect.bisect_left(costs, costs[i] + costs[j])
            if index < len(costs) and costs[index] == costs[i] + costs[j]:
                duplicated.add(costs[index])
    print(sum([cost for cost in costs if cost not in duplicated]))


### FIXED CODE ###

import copy
from itertools import product, combinations

N = int(input())

dp = []
for _ in range(N):
    dp.append(list(map(int, input().split(' '))))

original = copy.deepcopy(dp)

for k, i, j in product(range(N), repeat=3):
    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

if dp == original:
    cost = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(N):
                if k == i or k == j:
                    continue
                if dp[i][j] == dp[i][k] + dp[k][j]:
                    break
            else:
                cost += dp[i][j]
    print(cost)
else:
    print(-1)
### BUGGY CODE ###

s = input()
t = input()
moji = {}
for i in range(len(s)):
    if s[i] in moji.keys():
        moji[s[i]].append(i)
    else:
        moji[s[i]] = [i]

now = -1
kaisu = 0
flag = True
for i in range(len(t)):
    if t[i] in moji.keys():
        basho = moji[t[i]]
        for n in range(len(basho)):
            if basho[n] > now:
                now = basho[n]
                break
            elif n == len(basho) - 1 and basho[n] <= now:
                now = basho[0]
                kaisu += 1
    else:
        flag = False
        break
if flag:
    ans = kaisu * len(s) + now + 1
    print(ans)
else:
    print(-1)



### FIXED CODE ###

import bisect
s = input()
t = input()
moji = {}
for i in range(len(s)):
    if s[i] in moji.keys():
        moji[s[i]].append(i)
    else:
        moji[s[i]] = [i]

now = -1
kaisu = 0
flag = True
for i in range(len(t)):
    if t[i] in moji.keys():
        basho = moji[t[i]]
        lenbasho = len(basho)
        nowindex = bisect.bisect_right(basho, now)
        if nowindex == lenbasho:
            now = basho[0]
            kaisu += 1
        else:
            now = basho[nowindex]
    else:
        flag = False
        break
if flag:
    ans = kaisu * len(s) + now + 1
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

n = input()
l = []
l += [str(n) + ":"]
while 1:
    if n == 1:break
    for i in xrange(2,n+1):
        if n % i == 0:
            n /= i
            l += [i]
            break
print " ".join(map(str,l))

### FIXED CODE ###

n = input()
l = []
l += [str(n)+":"]
i = 2
while i * i <= n:
    while n % i == 0:
        l += [i]
        n /= i
    i += 1
if n > 1: l += [n]
print " ".join(map(str,l))
### BUGGY CODE ###

n=int(input())
x=list(map(int,input().split()))
import statistics
for i in range(n):
    y=x[i]
    x.pop(i)
    print(statistics.median(x))
    x.insert(i,y)

### FIXED CODE ###

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

lst = sorted(x)
small_med = lst[n // 2 - 1]
big_med = lst[n // 2]

for num in x:
    if num > small_med:
        print(small_med)
    else:
        print(big_med)
### BUGGY CODE ###

# coding: utf-8

# https://atcoder.jp/contests/abc102/tasks/arc100_a
# 13:03-13:20


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

    B = [A[i]-i for i in range(N)]
    
    b = sum(B) // N

    def sumb(x):
        return sum([abs(b-x) for b in B])
    
    dif = 0
    while sumb(b-(dif+1)) < sumb(b-dif):
        dif += 1
    ans1 = sumb(b-dif)
    
    dif = 0
    while sumb(b+(dif+1)) < sumb(b+dif):
        dif += 1
    ans2 = sumb(b+dif)

    return min(ans1, ans2)


print(main())


### FIXED CODE ###

# coding: utf-8

# https://atcoder.jp/contests/abc102/tasks/arc100_a
# 13:03-13:20


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

    B = sorted([A[i]-i for i in range(N)])
    
    b = B[N//2]

    return sum([abs(B[i]-b) for i in range(N)])


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

n, k = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [0]
for i in range(1, n):
    dp += [min([dp[-j] + abs(h[i] - h[i - j]) for j in range(1, min(i, k) + 1)])]
print(dp[-1])

### FIXED CODE ###

n, k = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [0]
for i in range(1, n):
    dp += [min([dp[-j] + abs(h[i] - h[i - j]) for j in range(1, min(i, k) + 1)])]
print(dp[-1])
### BUGGY CODE ###

def isOdd(num):
	if num % 2 == 0:
		return False
	else:
		return True

A, B, C = map(int, raw_input().split())
ans = 0
while not isOdd(A) and not isOdd(B) and not isOdd(C):
	ans += 1
	new1, new2, new3 = B/2 + C/2, A/2 + C/2, A/2 + B/2
	if A == new1 and B == new2 and C == new3:
		print -1
	else:
		A, B, C = new1, new2, new3
print ans


### FIXED CODE ###

A, B, C = map(int, raw_input().split())
[A, B, C] = sorted([A, B, C])
ans = 0
while A%2==0 and B%2==0 and C%2==0:
	ans += 1
	new1, new2, new3 = B/2 + C/2, A/2 + C/2, A/2 + B/2
	if new1 == new3:
		ans = -1
		break
	else:
		A, B, C = new1, new2, new3
print ans
### BUGGY CODE ###

L, R = map(int, input().split())
if R - L + 1 >= 2019:
    print(0)
    quit

for num in range(L, R + 1):
    if num % 2019 == 0:
        print(0)
        quit

ans = 2018
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        if (i * j) % 2019 <ans:
            ans = (i * j) % 2019
print(ans)


### FIXED CODE ###

L, R = map(int, input().split())
if R - L + 1 == 2:
    print((R * L) % 2019)
    quit()

if R - L + 1 >= 673:
    print(0)
    quit()

for num in range(L, R + 1):
    if num % 673 == 0:
        print(0)
        quit()


ans = 2018
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        amari = (i*j) % 2019
        if amari < ans:
            ans = amari
print(ans)
### BUGGY CODE ###

from collections import deque
while True:
    n, k = map(int, input().split())
    if n==0:break
    a = deque(int(input()) for _ in range(k))
    ans = sum(a)
    for _ in range(n-k):
        a.popleft()
        a.append(int(input()))
        tmp = sum(a)
        if ans < tmp: ans = tmp
    print(ans)

### FIXED CODE ###

from collections import deque
while True:
    n, k = map(int, input().split())
    if n==0:break
    a = deque(int(input()) for _ in range(k))
    ans=tmp=sum(a)
    for _ in range(n-k):
        x = a.popleft()
        y = int(input())
        a.append(y)
        tmp += y - x
        ans = max(ans, tmp)
    print(ans)
### BUGGY CODE ###

n,m = map(int, input().split())
PY = [list(map(int, input().split())) for _ in range(m)]
py = sorted(PY)

ans = [""] * m
b = ""
cnt = 1
for p,y in py:
  if b == p: cnt += 1
  else:
    b = p
    cnt = 1
  a = [str(p), str(cnt)]
  if len(str(p)) < 6: a[0] = "0"*(6-len(str(p))) + str(p)
  if len(str(cnt)) < 6: a[1] = "0"*(6-len(str(cnt))) + str(cnt)
  i = PY.index([p, y])
  ans[i] = a[0] + a[1]
for v in ans: print(v)

### FIXED CODE ###

n,m = map(int, input().split())
pyi = [list(map(int, input().split())) + [i] for i in range(m)]
pyi.sort()

pnow = pyi[0][0]
cnt = 1

ans = [-1 for _ in range(m)]

for p,y,i in pyi:
  if pnow != p:
    cnt = 1
    pnow = p
  ans[i] = str(p).zfill(6) + str(cnt).zfill(6)
  cnt += 1
print("\n".join(ans))
### BUGGY CODE ###

def solve(n, ga, sa, ba, gb, sb, bb):
    gd, sd, bd = gb - ga, sb - sa, bb - ba

    if bd <= 0:
        if sd <= 0:
            if gd <= 0:
                return n
            return n + n // ga * gd
        if gd <= 0:
            return n + n // sa * sd
        return max(n + g * gd + (n - g * ga) // sa * sd for g in range(n // ga + 1))
    if sd <= 0:
        if gd <= 0:
            return n + n // ba * bd
        return max(n + g * gd + (n - g * ga) // ba * bd for g in range(n // ga + 1))
    if gd <= 0:
        return max(n + s * sd + (n - s * sa) // ba * bd for s in range(n // sa + 1))
    (_, ga, gd), (_, sa, sd), (_, ba, bd) = \
        sorted([(gb / ga, -ga, gd), (sb / sa, -sa, sd), (bb / ba, -ba, bd)], reverse=True)
    ga, sa, ba = -ga, -sa, -ba
    return max(n + g * gd + s * sd + (n - g * ga - s * sa) // ba * bd
               for g in range(n // ga + 1)
               for s in range((n - g * ga) // sa + 1))


n = int(input())
ga, sa, ba = list(map(int, input().split()))
gb, sb, bb = list(map(int, input().split()))
n2 = solve(n, ga, sa, ba, gb, sb, bb)
n3 = solve(n2, gb, sb, bb, ga, sa, ba)
print(n3)


### FIXED CODE ###

def solve(n, ga, sa, ba, gb, sb, bb):
    ans = n
    for g in range(1 if ga >= gb else n // ga + 1):
        n2 = n - g * ga
        tmp1 = g * gb
        if ba >= bb:
            s = n2 // sa
            ans = max(ans, n2 + tmp1, n2 - s * sa + tmp1 + s * sb)
        elif sa >= sb:
            b = n2 // ba
            ans = max(ans, n2 + tmp1, n2 - b * ba + tmp1 + b * bb)
        else:
            for s in range(n2 // sa + 1):
                b = (n2 - s * sa) // ba
                ans = max(ans, n2 - s * sa - b * ba + tmp1 + s * sb + b * bb)
    return ans


n = int(input())
ga, sa, ba = list(map(int, input().split()))
gb, sb, bb = list(map(int, input().split()))
n2 = solve(n, ga, sa, ba, gb, sb, bb)
n3 = solve(n2, gb, sb, bb, ga, sa, ba)
print(n3)
### BUGGY CODE ###

from sys import stdin
import fractions

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

mod = 10 ** 9 + 7
g = 1
ans = 0

for i in range(N):
    d = fractions.gcd(A[i], g)
    g *= A[i]
    g //= d

for i in range(N):
    ans += (g * pow(A[i], mod - 2, mod)) % mod

print(ans % mod)


### FIXED CODE ###

from sys import stdin
from collections import defaultdict

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

mod = 10 ** 9 + 7
g = defaultdict(int)

for i in range(N):
    tmp = 1
    a = A[i]
    while tmp <= A[i] ** 0.5:
        cnt = 0
        while tmp > 1 and a % tmp == 0:
            a //= tmp
            cnt += 1
        if cnt > 0:
            g[tmp] = max(g[tmp], cnt)
        tmp += 1
    if a > 1:
        if a not in g:
            g[a] = 1

l = 1
ans = 0
for i in g:
    l *= pow(i, g[i], mod)
    l %= mod
for a in A:
    ans += l * pow(a, mod - 2, mod)
    ans %= mod

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

X,Y,Z,K= map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))


A.sort()
A.reverse()
B.sort()
B.reverse()
C.sort()
C.reverse()

ab_list = []

for i in range(X):
    for j in range(Y):
        ab_list.append(A[i]+B[j])

ab_list2 = sorted(ab_list,reverse = True)[:min(X*Y,K)]
abc_list = []

count = 0
count2 = 0

for i in range(min(X*Y,K)):
    for j in range(Z):
        abc_list.append(ab_list2[i]+C[j])


abc_list2 = sorted(abc_list,reverse = True)[:K]

for i in range(K):
    print(abc_list2[i])


### FIXED CODE ###

X,Y,Z,K= map(int,input().split())
A = sorted(list(map(int,input().split())), reverse=True)
B = sorted(list(map(int,input().split())), reverse=True)
C = sorted(list(map(int,input().split())), reverse=True)



ab_list = []

for i in range(X):
    for j in range(Y):
        ab_list.append(A[i]+B[j])

ab_list2 = sorted(ab_list,reverse = True)[:min(X*Y,K)]
abc_list = []

count = 0
count2 = 0

for i in range(min(X*Y,K)):
    for j in range(Z):
        abc_list.append(ab_list2[i]+C[j])


abc_list2 = sorted(abc_list,reverse = True)[:K]

for i in range(K):
    print(abc_list2[i])
### BUGGY CODE ###

n = int(input())
j=1
for i in range(n,0,-1):
  j*=i
print(j if j <= 10**5 else j%((10**9)+7))

### FIXED CODE ###

import math
n = int(input())
j=math.factorial(n)
print(j if j <= 10**5 else j%((10**9)+7))