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

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

# グルーピング
import copy
P2 = copy.copy(P)
Group = []
while len(P2)>0:
    temp = P2[0]
    tempGroup = []
    while temp in P2:
        tempGroup.append(temp)
        P2.remove(temp)
        temp = P[temp-1]
    Group.append(tempGroup)
Point = []
for x in Group:
    tempPoint = []
    for p in x:
        tempPoint.append(C[p-1])
    Point.append(tempPoint)

#print(Group)
#print(Point)

max00 = -10**9
for x in Point:
    sumx = sum(x)
    tempx = copy.copy(x)
    tempx.extend(x)
    lenx = len(x)
    max0 = -10**9
    dp = [0]*lenx
    if sumx <= 0 or K < lenx:
        for i in range(min(lenx-1,K)):
            for j in range(lenx):
                dp[j] = dp[j] + tempx[j+i]
            max0 = max(max0,max(dp))
            #print(dp)
    else:
        K2 = K % lenx
        SN = int(K/lenx)
        for i in range(lenx):
            for j in range(lenx):
                dp[j] = dp[j] + tempx[j+i]
            #print(dp)
            if i < K2:
                max0 = max(max0,max(dp) + sumx*SN)
                #print(max0)
            else:
                max0 = max(max0,max(dp) + sumx*(SN-1))
    max00 = max(max00,max0)
print(max00)


### FIXED CODE ###

def main():
 
    N,K = map(int,input().split())
    P = list(map(int,input().split()))
    C = list(map(int,input().split()))
 
    # グルーピング
    import copy
    P2 = set(P)
    Group = []
    while len(P2)>0:
        temp = list(P2)[0]
        tempGroup = []
        while temp in P2:
            tempGroup.append(temp)
            P2.remove(temp)
            temp = P[temp-1]
        Group.append(tempGroup)
    Point = []
    for x in Group:
        tempPoint = []
        for p in x:
            tempPoint.append(C[p-1])
        Point.append(tempPoint)
 
    #print(Group)
    #print(Point)
 
    max00 = -10**9
    for x in Point:
        sumx = sum(x)
        tempx = copy.copy(x)
        tempx.extend(x)
        lenx = len(x)
        max0 = -10**9
        dp = [0]*lenx
        if sumx <= 0 or K < lenx:
            for i in range(min(lenx-1,K)):
                for j in range(lenx):
                    dp[j] = dp[j] + tempx[j+i]
                max0 = max(max0,max(dp))
                #print(dp)
        else:
            K2 = K % lenx
            SN = int(K/lenx)
            for i in range(lenx):
                for j in range(lenx):
                    dp[j] = dp[j] + tempx[j+i]
                #print(dp)
                if i < K2:
                    max0 = max(max0,max(dp) + sumx*SN)
                    #print(max0)
                else:
                    max0 = max(max0,max(dp) + sumx*(SN-1))
        max00 = max(max00,max0)
    print(max00)
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

N = int(input())
S = list(map(int, input()))

ans = 0
for i in range(1000):
    A = i // 100
    B = i // 10 % 10
    C = i % 10
    a = False
    b = False
    for j in S:
        if a:
            if b:
                if j == C:
                    ans += 1
                    break
            elif j == B:
                b = True
        elif j == A:
            a = True

print(ans)

### FIXED CODE ###

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

ans = 0

def dfs(depth, id):
    global ans
    for i in range(10):
        for j in range(id, n):
            if i == s[j]:
                if depth < 2:
                    dfs(depth + 1, j + 1)
                else:
                    ans += 1
                break

dfs(0, 0)
print(ans)
### BUGGY CODE ###

import heapq


class UnionFindTree:
    def __init__(self):
        self.p = {}
        self.rank = {}

    def make(self, x):
        self.p[x] = x
        self.rank[x] = 0

    def find(self, x):
        if x in self.p:
            if self.p[x] != x:
                # 経路圧縮
                self.p[x] = self.find(self.p[x])
            return self.p[x]
        return None

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

    def unite(self, x, y):
        return self._unite(self.find(x), self.find(y))

    def _unite(self, x, y):
        if self.rank[x] < self.rank[y]:
            self.p[x] = y
            return y
        else:
            self.p[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            return x


N = int(input())
x, y = [], []
for i in range(N):
    a, b = map(int, input().split())
    x.append([a, i])
    y.append([b, i])
x.sort()
y.sort()

e = []
for i in range(N-1):
    heapq.heappush(e, [abs(x[i][0]-x[i+1][0]), x[i][1], x[i+1][1]])
    heapq.heappush(e, [abs(y[i][0]-y[i+1][0]), y[i][1], y[i+1][1]])

uft = UnionFindTree()
for i in range(N):
    uft.make(i)

ans = 0
while len(e) > 0:
    w, s, t = heapq.heappop(e)
    if not uft.same(s, t):
        uft.unite(s, t)
        ans += w

print(ans)


### FIXED CODE ###

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

    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

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

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


N = int(input())
x, y = [], []
for i in range(N):
    a, b = map(int, input().split())
    x.append([a, i])
    y.append([b, i])
x.sort()
y.sort()

e = []
for i in range(N-1):
    e.append([abs(x[i][0]-x[i+1][0]), x[i][1], x[i+1][1]])
    e.append([abs(y[i][0]-y[i+1][0]), y[i][1], y[i+1][1]])

e.sort()

uft = UnionFind(N)

ans = 0
for w, s, t in e:
    if not uft.same(s, t):
        uft.union(s, t)
        ans += w

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

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


def is_anagram(s_i, s_j):
    for k in range(10):
        if s_i[k] != s_j[k]:
            return False
    return True


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


### FIXED CODE ###

n = int(input())
s = [sorted(input()) for _ in range(n)]
sorted_s = sorted(s)

num = 0
num_same = 1
prev = sorted_s[0]
for i in range(1, len(sorted_s)):
    if prev != sorted_s[i]:
        num += int(num_same * (num_same - 1) / 2)
        num_same = 1
        prev = sorted_s[i]
    else:
        num_same += 1
num += int(num_same * (num_same - 1) / 2)
print(num)
### BUGGY CODE ###

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

for i in range(N, M//2+1):
    if M % i == 0:
        print(M // i)
        exit()

print(1)


### FIXED CODE ###

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


def get_divisor(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if n // i != i:
                divisors.append(n // i)

    return sorted(divisors)


divisors = get_divisor(M)
for d in divisors:
    if d >= N:
        print(M // d)
        exit()

print(1)
### BUGGY CODE ###

import sys
#import numpy as np
import bisect
sys.setrecursionlimit(10 ** 7)

N, Q = map(int, input().split())
STX = []
for _ in range(N):
    s, t, x = map(int, input().split())
    STX.append((s, t, x))

PEOPLE = []
for _ in range(Q):
    d = int(input())
    PEOPLE.append(d)

ans = [str(-1)] * Q

STX.sort(key=lambda x: x[2])

for s, t, x in STX:
    #print("s,t,x", s, t, x)
    #i = np.searchsorted(PEOPLE, s - x)
    #j = np.searchsorted(PEOPLE, t - x)
    i = bisect.bisect_left(PEOPLE, s - x)
    j = bisect.bisect_left(PEOPLE, t - x)
    #print("i,j", i, j)

    for k in range(i, j):
        if ans[k] == '-1':
            ans[k] = str(x)

    # print(ans)

print("\n".join(ans))


### FIXED CODE ###

#D in [S_i-X_i,T_i-X_i) → Xiで止まる
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
from collections import defaultdict

N,Q = map(int,input().split())
task = []

STX = [[int(x) for x in input().split()] for _ in range(N)]
for s,t,x in STX:
  task.append((t-x,0,x)) # xで止まらなくなる
  task.append((s-x,1,x)) # xで止まる

for i in range(Q):
  d = int(input())
  task.append((d,2,i)) # 止まる位置を答える
answer = [-1]*Q

task.sort()

# 引っかかってる場所の管理
se = set()
se_hp = [] # heapで最小値を先頭に保つ

# 小さい時刻から順に見ていく
for a,b,c in task:
  if not b: # b == 0
    se.remove(c)
  elif b&1: # b == 1
    se.add(c)
    heappush(se_hp,c)
  else: # b == 2
    while se_hp and se_hp[0] not in se:
      heappop(se_hp)
    answer[c] = se_hp[0] if se_hp else -1

print('\n'.join(map(str,answer)))
### BUGGY CODE ###

import fractions
from functools import reduce 
def gcd(*numbers):
  return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
  return(x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

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

mod = 1000000000 + 7
min = lcm_list(a)
sum = 0
for i in range(n):
  sum = sum + (min//a[i])%mod 
  
print(sum%mod)



### FIXED CODE ###

from fractions import gcd
from functools import reduce
     
mod = 10 ** 9 + 7
     
def lcm_base(x, y):
    return (x * y) // gcd(x, y)
     
def lcm(numbers):
    return reduce(lcm_base, numbers, 1)
     
    # print('input >>')
N = int(input())
A = list(map(int,(input().split())))
     
lcmn = lcm(A)
    
ans = 0
for i in range(len(A)):
    ans += lcmn // A[i]
     
    # print('-----output-----')
print(int(ans%mod))
### BUGGY CODE ###

#python3.4
def inpul(): return list(map(int, input().split()))

N, K = inpul()
A = inpul()

f = 0
f_ans = 0
for num in range(K+1):
    for item_A in A:
        f = f + (num ^ item_A)
    if(f > f_ans):
        f_ans = f
    f = 0
print(f_ans)


### FIXED CODE ###

n,k = list(map(int, input().split()))
a=list(map(int, input().split()))
x=0
ans = 0
for i in range(45,-1,-1):
  c=0
  for p in a:
    if (p >> i) & 1:
      c += 1
  if n - c > c and x + (1<<i) <= k:
    ans += (n-c) * (1<<i)
    x += 1<<i
  else:
    ans += c * (1<<i)
print(ans)
### BUGGY CODE ###

N = int(input())
A = []
for i in range(N):
        a = int(input())
        A.append(a)

remain = N
color = 0

while len(A) != 0:
        num = A[0]
        B = []
        for i in range(1, len(A)):
                if num >= A[i]:
                        B.append(A[i])
                else:
                        num = A[i]
        
        color += 1
        A = B

print(color)

### FIXED CODE ###

N = int(input())
A = [-1 for i in range(N)]

color = 1
A[0] = int(input())


def search(A, color, a):
        left = 0
        right = color - 1
        signal = 0
        while left < right:
                mid = (left + right) // 2
                if A[mid] == a - 1:
                        return mid
                        signal = 1
                elif a <= A[mid]:
                        left = mid + 1
                else:
                        right = mid
        if signal == 0:
                return left


for i in range(N - 1):
        
        a = int(input())
        num = search(A, color, a)
        if num == color - 1 and a <= A[num]:
                A[color] = a
                color += 1
        else:
                A[num] = a

print(color)
### BUGGY CODE ###

from collections import Counter
from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 7)

@lru_cache(maxsize=None)
def dp(N, c1, c2, c3):
    if c1 + c2 + c3 == 0:
        return 0
    r = N
    if c1:
        r += c1 * dp(N, c1 - 1, c2, c3)
    if c2:
        r += c2 * dp(N, c1 + 1, c2 - 1, c3)
    if c3:
        r += c3 * dp(N, c1, c2 + 1, c3 - 1)
    return r / (c1 + c2 + c3)

def main():
    N = int(input())
    a = list(map(int, input().split()))
    a = Counter(a)
    print(dp(N, a.get(1, 0), a.get(2, 0), a.get(3, 0)))


main()


### FIXED CODE ###

from collections import Counter

def main():
    N = int(input())
    a = Counter(map(int, input().split()))
    a1, a2, a3 = a.get(1, 0), a.get(2, 0), a.get(3, 0)
    a123 = a1 + a2 + a3 + 1
    u = [[0.0] * (a123 - c2) for c2 in range(a123)]
    v = [[0.0] * (a123 - c2) for c2 in range(a123)]
    t1 = 0.0
    v2 = v[0]
    for c1 in range(1, a123):
        v2[c1] = t1 = N / c1 + t1
    for c2 in range(1, a123):
        v2 = v[c2]
        for c1, t2 in zip(range(301 - c2), v[c2 - 1][1:]):
            v2[c1] = t1 = (N + c1 * t1 + c2 * t2) / (c1 + c2)

    for c3 in range(1, a3 + 1):
        u, v = v, u
        v2 = v[0]
        for c1, t3 in zip(range(a123 - c3), u[1]):
            v2[c1] = t1 = (N + c1 * t1 + c3 * t3) / (c1 + c3)
        for c2 in range(1, a123 - c3):
            v2 = v[c2]
            c23 = c2 + c3
            for c1, t2, t3 in zip(range(a123 - c3 - c2), v[c2 - 1][1:], u[c2 + 1]):
                v2[c1] = t1 = (N + c1 * t1 + c2 * t2 + c3 * t3) / (c1 + c23)

    print(v[a2][a1])
main()
### BUGGY CODE ###

a,b,k = map(int, input().split())
l = [i for i in range(a,b+1)]
#print(l)
c = len(l)
d = min(c,k)
x = []

if k*2 > c:
    x = l
else:
    for p in range(k):
        x.append(l[p])
        x.append(l[-(p+1)])

print(*sorted(x), sep='\n')


### FIXED CODE ###

a,b,k = map(int, input().split())
#print(l)
c = b-a+1

x = []
if k*2 > c:
    for i in range(a, b+1):
        x.append(i)
else:
    for j in range(a, a+k):
        x.append(j)
    for j in range(b-k+1, b+1):
        x.append(j)

print(*sorted(x), sep='\n')
### BUGGY CODE ###

import sys

def isEmpty(S):
  if len(S) == 0:
    return True

def isFull(S):
  if len(S) >= 100000:
    return True

def enqueue(x):
  if isFull(x_list_list):
    print 'Error'
  x_list_list.append(x)

def dequeue(x_list_list):
  if isEmpty(x_list_list):
    print 'Error'
  del_list = x_list_list[0]
  x_list_list.pop(0)
  return(del_list)

y = sys.stdin.readline()
a, b = y.split(" ")
a = int(a)
b = int(b)

S = []
x_list_list = []

for i in range(a):
  text = raw_input()
  x_list = text.split()
  x_list[1] = int(x_list[1])
  x_list.append(0)
  x_list_list.append(x_list)

flag = a
while flag != 0:
  if x_list_list[0][1] > b:
    x_list_list[0][1] -= int(b)
    for j in range(flag):
      x_list_list[j][2] += b
    del_list = dequeue(x_list_list)
    enqueue(del_list)
  elif x_list[0][1] <= b:
    for j in range(flag):
      x_list_list[j][2] += x_list_list[0][1]
    x_list_list[0][1] = 0
    flag -= 1
    print x_list_list[0][0],x_list_list[0][2]
    dequeue(x_list_list)

### FIXED CODE ###

import sys

def isEmpty(S):
  if len(S) == 0:
    return True

def isFull(S):
  if len(S) >= 100000:
    return True

def enqueue(x):
  if isFull(x_list_list):
    print 'Error'
  x_list_list.append(x)

def dequeue(x_list_list):
  if isEmpty(x_list_list):
    print 'Error'
  del_list = x_list_list[0]
  x_list_list.pop(0)
  return(del_list)

y = sys.stdin.readline()
a, b = y.split(" ")
a = int(a)
b = int(b)

S = []
x_list_list = []
run_time = 0

for i in range(a):
  text = raw_input()
  x_list = text.split()
  x_list[1] = int(x_list[1])
  x_list.append(0)
  x_list_list.append(x_list)

flag = a
while flag != 0:
  if x_list_list[0][1] > b:
    x_list_list[0][1] -= int(b)
    run_time += b
    del_list = dequeue(x_list_list)
    enqueue(del_list)
  else:
    run_time += x_list_list[0][1]
    x_list_list[0][2] = run_time
    x_list_list[0][1] = 0
    flag -= 1
    print x_list_list[0][0],x_list_list[0][2]
    dequeue(x_list_list)
### BUGGY CODE ###

Q = int(input())

import heapq
import sys
input = sys.stdin.readline

INF = 10**18
L = []
R = []
heapq.heappush(L,INF)
heapq.heappush(R,INF)
L_size = 0
R_size = 0
sum_b = 0
sum_L = 0
sum_R = 0

def f1(a,b):
  global sum_b,L_size,R_size,sum_L,sum_R
  sum_b += b
  L_max = -heapq.heappop(L)
  R_min = heapq.heappop(R)
  sum_L -= L_max
  sum_R -= R_min
  X = sorted([L_max,a,R_min])
  if L_size == R_size:
    heapq.heappush(L,-X[0])
    heapq.heappush(L,-X[1])
    heapq.heappush(R,X[2])
    L_size += 1
    sum_L += X[0] + X[1]
    sum_R += X[2]
  else:
    heapq.heappush(L,-X[0])
    heapq.heappush(R,X[1])
    heapq.heappush(R,X[2])
    R_size += 1
    sum_L += X[0]
    sum_R += X[1] + X[2]
  return

def f2():
  min_value = sum_b
  min_x = -heapq.nsmallest(1,L)[0]
  if L_size == R_size:
    min_value += sum_R - sum_L
  else:
    min_value += sum_R - sum_L + min_x
  print(min_x,min_value)

QUERY = [[int(x) for x in input().split()] for _ in range(Q)]
for q in QUERY:
  if q[0]&1:
    f1(q[1],q[2])
  else:
    f2()


### FIXED CODE ###

Q = int(input())

import heapq
import sys
input = sys.stdin.readline

INF = 10**18
L = []
R = []
heapq.heappush(L,INF)
heapq.heappush(R,INF)
L_size = 0
R_size = 0
sum_b = 0
sum_L = 0
sum_R = 0

def f1(a,b):
  global sum_b,L_size,R_size,sum_L,sum_R
  sum_b += b
  L_max = -heapq.heappop(L)
  R_min = heapq.heappop(R)
  sum_L -= L_max
  sum_R -= R_min
  X = sorted([L_max,a,R_min])
  if L_size == R_size:
    heapq.heappush(L,-X[0])
    heapq.heappush(L,-X[1])
    heapq.heappush(R,X[2])
    L_size += 1
    sum_L += X[0] + X[1]
    sum_R += X[2]
  else:
    heapq.heappush(L,-X[0])
    heapq.heappush(R,X[1])
    heapq.heappush(R,X[2])
    R_size += 1
    sum_L += X[0]
    sum_R += X[1] + X[2]
  return

def f2():
  min_value = sum_b
  min_x = -L[0]
  if L_size == R_size:
    min_value += sum_R - sum_L
  else:
    min_value += sum_R - sum_L + min_x
  print(min_x,min_value)

QUERY = [[int(x) for x in input().split()] for _ in range(Q)]
for q in QUERY:
  if q[0]&1:
    f1(q[1],q[2])
  else:
    f2()
### BUGGY CODE ###

N = int(input())
G = [[20 ** 9 for _ in range(N + 1)] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    G[a - 1][b - 1] = c
    G[b - 1][a - 1] = c
Q, K = map(int, input().split())

def dijkstra(s, N, G, x, y):
    d = [20 ** 9] * N
    used = [False] * N
    d[s] = 0

    while True:
        v = -1
        for i in range(N):
            if not used[i] and v == -1:
                v = i
            elif not used[i] and d[i] < d[v]:
                v = i
        if v == -1:
            break
        used[v] = True

        for i in range(N):
            d[i] = min(d[i], d[v] + G[v][i])
    
    return d[x] + d[y]

dist = [0] * Q
for i in range(Q):
    x, y = map(int, input().split())
    dist[i] = dijkstra(K - 1, N, G, x - 1, y - 1)

for d in dist:
    print(d)

### FIXED CODE ###

import heapq
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    G[a - 1].append([c, b - 1])
    G[b - 1].append([c, a - 1])
Q, K = map(int, input().split())

def dijkstra(s, N, G):
    d = [float('inf')] * N
    d[s] = 0
    hq = [[0, s]]
    heapq.heapify(hq)
    while len(hq) > 0:
        v, i = heapq.heappop(hq)
        if d[i] < v:
            continue
        for c, j in G[i]:
            if d[j] > d[i] + c:
                d[j] = d[i] + c
                heapq.heappush(hq, [d[j], j])
    return d

D = dijkstra(K - 1, N, G)

dist = [0] * Q
for i in range(Q):
    x, y = map(int, input().split())
    dist[i] = D[x - 1] + D[y - 1]

for d in dist:
    print(d)
### BUGGY CODE ###

n,m = map(int,input().split())
a = [int(input()) for i in range(m)]
dp = [1]*2 + [0]*(n-1)
mod = 1000000007
 
for i in range(n-1):
  if i+1 in a:
    dp[i+2] = dp[i]
    dp[i+1] = 0
  else:
    dp[i+2] = dp[i]+dp[i+1]

print(dp[-1]%mod)  


### FIXED CODE ###

import sys
input = sys.stdin.readline
n,m = map(int,input().split())
hole = [0]*(n+1)
for i in range(m):
  hole[int(input())] = 1

dp = [0]*(n+1)
dp[0] = 1
MOD = 10**9+7
   
for i in range(1,n+1):
  if hole[i]==1:
    dp[i] = 0
  else:
    dp[i] = dp[i-1]+dp[i-2]
    dp[i] %= MOD

print(dp[-1])
### BUGGY CODE ###

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

cnt = 0

b = set(a)

for i in b:
    c = a.count(i)
    if c > i:
        cnt += c - i
    elif c == i:
        continue
    else:
        cnt += c

print(cnt)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int,input().split()))
cnt = Counter(a)

c = 0
for k,v in cnt.items():
    if v >= k:
        c += v-k
    else:
        c += v
print(c)
### BUGGY CODE ###

# Acceptance of input
import sys

file_input = sys.stdin

V, E = map(int, file_input.readline().split())

max_d = 1001
adj = [[] for i in range(V)]

for line in file_input:
    s, t, d = map(int, line.split())
    adj[s].append((t, d))

max_path = 15001
dp = [[max_path] * (1 << V) for i in range(V)]
dp[0][0] = 0

# Full search with bit mask
def tsp(v, b):
    if b == (1 << V) - 1:
        return None
    
    for t, d in adj[v]:
        if b & (1 << t):
            continue
        mask = b | (1 << t)
        t_d = dp[v][b] + d
        if dp[t][mask] > t_d:
            dp[t][mask] = t_d
            tsp(t, mask)

# Output
tsp(0, 0)

ans = dp[0][-1]
if ans == max_path:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

import sys

file_input = sys.stdin

V, E = map(int, file_input.readline().split())

no_route = 15001

# (v-1) th vertex is excluded
dp = [[no_route] * (V - 1) for i in range(1 << (V - 1))]

adj = [[] for i in range(V)]

for line in file_input:
    s, t, d = map(int, line.split())
    if s == V - 1:
        # Record the distance from the (v-1) th vertex to the adjacent vertex
        dp[1 << t][t] = d
    else: 
        # Store distance from source, not target
        adj[t].append((s, d))

# DP
for b in range(1, 1 << (V - 1)):
    for i in range(V - 1):
        b_i = 1 << i
        if b & b_i:
            pre_bit = b ^ b_i
            dp_pre = dp[pre_bit]
            for s, d in adj[i]:
                pre_rec = dp_pre[s]
                if pre_rec != no_route:
                    dp[b][i] = min(dp[b][i], pre_rec + d)

ans = no_route

# A state where all vertices other than (v-1) have been visited.
dp_comp = dp[(1 << (V - 1)) - 1]

for s, d in adj[V - 1]:
    comp_rec = dp_comp[s]
    if comp_rec != no_route:
        ans = min(ans, comp_rec + d)

if ans == no_route:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]
import fractions
from functools import reduce

n=int(input())
c = list(map(int, input().split()))
mod=10**9+7

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

v=lcm(*c)
ans=0

for i in range(n):
    ans+=v//c[i]
    ans%=mod
print(ans)


### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]
import fractions
from functools import reduce

n=int(input())
c = list(map(int, input().split()))
mod=pow(10,9)+7

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

v=lcm(*c)%mod
ans=0

for i in range(n):
    ans += v * pow(c[i],mod-2,mod)
    ans%=mod

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

n = int(input())
goukei = 1
for i in input().split():
    goukei *= int(i)
if goukei > 1000000000000000000:
    print(-1)
else:
    print(goukei)

### FIXED CODE ###

n = int(input())
goukei = 1
ok = 0
arr = [int(x) for x in input().split()]
if 0 in arr:
    print(0)
else:
    for i in arr:
        goukei *= int(i)
        if goukei > 1000000000000000000:
            print(-1)
            ok = 1
            break
    if ok == 0:
        print(goukei)
### BUGGY CODE ###

n,*l=map(int,open(0).read().split());a=0;M=10**9+7
for i in range(60):t=sum(j>>i&1 for j in l);a+=t*(n-t)*pow(2,i,M)
print(a%M)

### FIXED CODE ###

M=10**9+7
n=int(input())
l=list(map(int,input().split()))
a=0
for i in range(60):
  t=sum((l[j]>>i)%2 for j in range(n))
  a+=(t*(n-t)<<i)%M
print(a%M)
### BUGGY CODE ###

def main():
    N = 10**9
    s = int(input())
    a,b = 0,0
    i = 1
    while True:
        if s % i == 0:
            if s // i <= N:
                a = i
                b = s//i
                break
        if i * i > s:break
        i+= 1
    print("0 0 {0} 0 0 {1}".format(str(a),str(b))) 


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    s = int(input())
    N = 10**9

    y2 = 1
    y3 = s // N + 1
    x3 = N - s % N
    if y3 == N+1:
        y2 = 0
        y3 = N
        x3 = N
    
    print("0 0 1000000000 {} {} {}".format(str(y2),str(x3),str(y3))) 

if __name__ == '__main__':
    main()