Harryxun/stf_run huggingface dataset:
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 = sorted(A, key = lambda x:-x)
B = sorted(B, key = lambda x:-x)
C = sorted(C, key = lambda x:-x)

AB = [0] * (X * Y)

index = 0
for i in range(len(A)):
    for j in range(len(B)):
        AB[index] = A[i] + B[j]
        index += 1

AB = sorted(AB, key = lambda x:-x)

ABC = [0] * min(3000, X * Y * Z)
index = 0
for i in AB:
    for j in C:
        ABC[index] = i + j
        index += 1

ABC = sorted(ABC, key = lambda x:-x)
for i in range(0,K):
    print(ABC[i])

### FIXED 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 = sorted(A, key = lambda x:-x)
B = sorted(B, key = lambda x:-x)
C = sorted(C, key = lambda x:-x)

AB = [0] * (X * Y)

ABC = []

for i in range(X):
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for k in range(Z):
            if (i + 1) * (j + 1) * (k + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[k])

ABC = sorted(ABC, key = lambda x:-x)
for i in range(0, K):
    print(ABC[i])
N=input()
A=input()

print((N**2)-A)



### FIXED CODE ###

N=int(input())

print((N*N)-int(input()))
N,M=map(int,input().split())

class UnionFind:
  def __init__(self, n):
    self.n = n
    self.parents = [i for i in range(n)]
 
  def find(self, x):
    if self.parents[x]==x:
      return x
    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.size(x) < self.size(y):
      x, y = y, x
    self.parents[x] += self.parents[y]
    self.parents[y] = x
    
  def size(self, x):
    return self.parents[self.find(x)]
  
  def cnt(self):
    par=self.parents
    return len(set(par))

uf=UnionFind(N)
for i in range(M):
  x,y,z=map(int,input().split())
  uf.union(x-1,y-1)
print(uf.cnt())

### FIXED CODE ###

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.p = [e for e in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

    def unite(self, u, v):
        u = self.find_set(u)
        v = self.find_set(v)

        if u == v:
            return

        if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])

        return self.p[u]

    def update_p(self):
        for u in range(self.n):
            self.find_set(u)

    def get_size(self, u):
        return self.size[self.find_set(u)]


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

uf = UnionFind(n)

for x, y, _ in xyz:
    x -= 1
    y -= 1
    uf.unite(x, y)

uf.update_p()
ans = len(set(uf.p))
print(ans)
while 1:
 H, W = map(int,raw_input().split())
 if H + W == 0:
???break
 for h in range(H):
  if h % 2 == 0:
   if W % 2 == 0:
    print ('#.'*(W//2))
   else:
    print ('#.'*(W//2)+'#')
  else:
   if: W % 2 == 0:
    print ('.#'*(W//2))
   else:
    print ('.#'*(W//2)+'.')
 print ''

### FIXED CODE ###

while 1:
 H, W = map(int,raw_input().split())
 if H + W == 0:break
 for h in range(H):
  if h % 2 == 0:
   if W % 2 == 0:
    print ('#.'*(W//2))
   else:
    print ('#.'*(W//2)+'#')
  else:
   if W % 2 == 0:
    print ('.#'*(W//2))
   else:
    print ('.#'*(W//2)+'.')
 print ''
a = input()

if a>=400 and a<600:print(8)
elif a>=600 and a<800:print(7)
elif a>=800 and a<1000:print(6)
elif a>=1000 and a<1200:print(5)
elif a>=1200 and a<1400:print(4)
elif a>=1400 and a<1600:print(3)
elif a>=1600 and a<1800:print(2)
elif a>=1800 and a<2000:print(1)

### FIXED CODE ###

a = int(input())
 
if a>=400 and a<600:print(8)
elif a>=600 and a<800:print(7)
elif a>=800 and a<1000:print(6)
elif a>=1000 and a<1200:print(5)
elif a>=1200 and a<1400:print(4)
elif a>=1400 and a<1600:print(3)
elif a>=1600 and a<1800:print(2)
elif a>=1800 and a<2000:print(1)
import sys

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

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    icnt=0
    for i in range(n):
        if a[i]%mm==0:
            icnt+=a[i]//mm
        else:
            icnt+=a[i]//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if rf(m)==(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=int((um+lm)//2)-1
    elif rf(m)<(n+k):
        um=m
        m=int((um+lm)//2)+1
    else:
        um=m-1
        m=int((um+lm)//2)
#    if rf(m)==(n+k) and um-lm<5:

for mi in range(um,max(0,lm-1),-1):
#for mi in range(m+5,max(0,m-10),-1):
    if rf(mi)==(n+k) and rf(mi-1)>(n+k):
#    if rf(mi)!=rf(mi-1):
        break

print(mi)

### FIXED CODE ###

import sys

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

if k==0:
    print(max(a))
    sys.exit()

def rf(mm):
    if mm==0:
        mm=1
    icnt=0
    for i in range(n):
        icnt+=(a[i]-1)//mm+1
    return icnt

asum=sum(a)
m=asum//(n+k)
um=asum
lm=1
for ii in range(60):
    if m==1:
        break
    if rf(m)<=(n+k) and rf(m-1)>(n+k):
        break
    if um-lm<5:
        break
    if rf(m)>(n+k):
        lm=m
        m=(um+lm)//2-1
    elif rf(m)<(n+k):
        um=m
        m=(um+lm)//2-1
    else:
        um=m-1
        m=(um+lm)//2-1
#    if rf(m)==(n+k) and um-lm<5:

if um<1:
    print(1)
    sys.exit()
    
for mi in range(um,max(0,lm-1),-1):
    if rf(mi)<=(n+k) and rf(mi-1)>(n+k):
        break

print(mi)
n=int(input())
m=int(input())

for i in range(n-1):
    x=int(input())
    d=max(x-m,d)
    m=min(m,x)
print(d)


### FIXED CODE ###

n=int(input())
m=int(input())
d=-10**9

for i in range(n-1):
    x=int(input())
    d=max(x-m,d)
    m=min(m,x)
print(d)
i=input;x=i().split();print('No '*(max(map(int,i().split().append(x[2])))<min(map(int,i().split().append(x[3]))))+'War')

### FIXED CODE ###

i=input;x=i().split();print('No '*(max(map(int,i().split()+x[2:3]))<min(map(int,i().split()+x[3:4])))+'War')
n, a, b = map(int, input().split())

if a == 0 and b == 0:
    print(0)
    exit()

count = n // (a+b)
mod = n % (a+b)


if mod != 0:
    ball = ('b'* a + 'r'* b) * (count + 1)
else:
    ball = ('b'* a + 'r'* b) * count

ans_ball = ball[:n]


print(ans_ball.count('b'))

### FIXED CODE ###

#coding:utf-8
n, a, b = map(int, input().split())

if a == 0 and b == 0:
    print(0)
    exit()

count = n // (a+b)
mod = n % (a+b)

ans = a * count + min(mod, a)
print(ans)
N = int(input())
es = [[] for _ in range(N)]

for i in range(N-1):
    u,v,w = map(int, input().split())
    u,v = u-1, v-1
    es[u].append((v,w))
    es[v].append((u,w))


ans = [-1] * N

def dfs(node, c):

    ans[node] = c
    for next,w in es[node]:
        # 未着色であれば
        if ans[next] == -1:
            if w % 2 == 0:
                # 距離が偶数なら同じ色
                dfs(next, c)
            else:
                # 距離が異なるなら違う色
                if c == 0:
                    dfs(next, 1)
                else:
                    dfs(next, 0)

dfs(0,0)

print(ans, sep="\n")



### FIXED CODE ###

N = int(input())

es = [[] for _ in range(N)]

for i in range(N-1):
    u,v,w = map(int, input().split())

    es[u-1].append((v-1,w))
    es[v-1].append((u-1,w))

ans = [-1] * N

ans[0] = 0

queue = [0]

while len(queue) > 0:
    next_queue = []
    for curr in queue:
        for next,w in es[curr]:
            if ans[next] == -1:
                    next_queue.append(next)
                    if w % 2 == 0:
                        ans[next] = ans[curr]
                    else:
                        ans[next] = 1 if ans[curr] == 0 else 0

    if len(next_queue) > 0:
        queue = next_queue
    else:
        queue = []

print(*ans, sep="\n")
import math
n,k = map(int,input().split())
s = input()
#print(n-1,k-1)
print(math.ceil((n-1)/(k-1)))

### FIXED CODE ###

S = list(input())
ans = 0
for i in range(len(S)):
    if S[i] =="+":
        ans += 1
    elif S[i] == "-":
        ans -= 1
print(ans)
import math
import functools
n = int(input())

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

g = functools.reduce(math.gcd, a)

print(g)

### FIXED CODE ###

import math
import functools


def gcd(a, b):
    if b == 0:
        return a

    return gcd(b, a%b)
n = int(input())

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

g = functools.reduce(gcd, a)

print(g)
import collections
import functools
DIVISOR = 10 ** 9 + 7
n = int(input())

prime_factor = collections.defaultdict(int)

for i in range(1, n + 1):
    tmp = i
    for j in range(2, int(n ** 0.5) + 1):
        while tmp % j == 0:
            prime_factor[j] += 1
            tmp //= j

    if tmp > 1:
        prime_factor[tmp] += 1

# print(prime_factor)
prime_factor_num = [prime_factor[key] + 1 for key in prime_factor]

print((functools.reduce(lambda x, y: (x % DIVISOR) * y, prime_factor_num)) % DIVISOR)

### FIXED CODE ###

import collections
import functools
DIVISOR = 10 ** 9 + 7
n = int(input())

if n == 1:
    print(1)
else:
    prime_factor = collections.defaultdict(int)
    for i in range(1, n + 1):
        tmp = i
        for j in range(2, int(n ** 0.5) + 1):
            while tmp % j == 0:
                prime_factor[j] += 1
                tmp //= j

        if tmp > 1:
            prime_factor[tmp] += 1

    # print(prime_factor)
    prime_factor_num = [prime_factor[key] + 1 for key in prime_factor]

    print((functools.reduce(lambda x, y: (x % DIVISOR) * y, prime_factor_num)) % DIVISOR)
n, k = map(int, input())
l = sorted([int(x) for x in input().split()])

print(sum(l[:k]))

### FIXED CODE ###

n, k = map(int, input().split())
l = sorted([int(x) for x in input().split()])

print(sum(l[:k]))
N,A,B=map(int,input().split())
if A==B:
  print(1)
else:
  if N==1:
    ptint(0)
  else:
    if A<B:
      print((N-2)*(B-A)+1)
    else:
      print(0)

### FIXED CODE ###

N,A,B=map(int,input().split())
if A==B:
  print(1)
else:
  if N==1:
    print(0)
  else:
    if A<B:
      print((N-2)*(B-A)+1)
    else:
      print(0)
import itertools
def getCombList(xList):
  N = len(xList)
  result = []
  for n in range(1,N):
    for conb in itertools.combinations(xList, n):
      result.append(list(conb)) #タプルをリスト型に変換
  return result

import numpy as np
L1 = input()
H, W, K = map(int, L1.split(" "))
mat = np.zeros([H,W], dtype="int32")
for i in range(H):
  Li = input()
  for j, s in enumerate(Li):
    if s == "#":
      mat[i,j] = 1

if np.sum(np.sum(mat)) < K:
  print(0)
else:
  c = 0
  matp = mat.copy()
  HList = list(range(H))
  WList = list(range(W))
  HcombList = getCombList(HList)
  WcombList = getCombList(WList)
  for Hcomb in HcombList:
    for Wcomb in WcombList:
      matp[Hcomb, :] = 0
      matp[:, Wcomb] = 0
      if np.sum(np.sum(matp)) == K:
        c = c + 1
      matp = mat.copy()
      
  for Hcomb in HcombList:
    matp[Hcomb, :] = 0
    if np.sum(np.sum(matp)) == K:
      c = c + 1
    matp = mat.copy()

  for Wcomb in WcombList:
    matp[:, Wcomb] = 0
    if np.sum(np.sum(matp)) == K:
      c = c + 1
    matp = mat.copy()

print(c)

### FIXED CODE ###

import itertools
def getCombList(xList):
  N = len(xList)
  result = []
  for n in range(1,N+1):
    for conb in itertools.combinations(xList, n):
      result.append(list(conb)) #タプルをリスト型に変換
  #print(result)
  return result

import numpy as np
L1 = input()
H, W, K = map(int, L1.split(" "))
mat = np.zeros([H,W], dtype="int32")
for i in range(H):
  Li = input()
  for j, s in enumerate(Li):
    if s == "#":
      mat[i,j] = 1

if np.sum(np.sum(mat)) < K:
  print(0)
else:
  if np.sum(np.sum(mat)) == K:
    c = 1
  else:
    c = 0
  matp = mat.copy()
  HList = list(range(H))
  WList = list(range(W))
  HcombList = getCombList(HList)
  WcombList = getCombList(WList)
  for Hcomb in HcombList:
    for Wcomb in WcombList:
      matp[Hcomb, :] = 0
      matp[:, Wcomb] = 0
      if np.sum(np.sum(matp)) == K:
        c = c + 1
      matp = mat.copy()
      
  for Hcomb in HcombList:
    matp[Hcomb, :] = 0
    if np.sum(np.sum(matp)) == K:
      c = c + 1
    matp = mat.copy()

  for Wcomb in WcombList:
    matp[:, Wcomb] = 0
    if np.sum(np.sum(matp)) == K:
      c = c + 1
    matp = mat.copy()

  print(c)
from collections import deque
A, B = [int(x) for x in input().split()]

def gcd(x, y):
  if y == 0:
    return x
  return gcd(y, x % y)

t = gcd(A, B)
l = deque([1])
sqrt_t = t ** 0.5 + 1
for i in range(2, sqrt_t + 1):
  if t % i == 0:
    l.append(i)
    while t % i == 0:
      t //= i
print(len(set(l)))


### FIXED CODE ###

from collections import deque
A, B = [int(x) for x in input().split()]

def gcd(x, y):
  if y == 0:
    return x
  return gcd(y, x % y)

t = gcd(A, B)
l = deque([1])
sqrt_t = int(t ** 0.5) + 1
for i in range(2, sqrt_t + 1):
  if t % i == 0:
    l.append(i)
    while t % i == 0:
      t //= i
      
l.append(t)
print(len(set(l)))
a,b = map(int,input().split())
n  = int(str(a)+str(b)
m = n**(1/2)
if int(m**2) ==n:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a,b = input().split()
s = a+b
print("Yes" if int((int(s)**(1/2)))**2 == int((int(s)**(1/2))**2) else "No")
#input
H, W = map(int, input().split())
import numpy as np

S = np.full((H, W), ".")
for i in range(H):
    x = input()
    for j in range(W):
        if x[j] == "#":
            S[i, j] = "#"

#output
INF = 10**5
dp = np.full((H, W), INF)

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

def clear_maze(sx, sy, gx, gy, maze):
    def bfs():
        q = []
        q.insert(0, (sx, sy))
        dp[sx, sy] = 0

        while len(q):
            x, y = q.pop()

            if x == gx and y == gy:
                break

            for i in range(0, 4):
                nx, ny = x + dx[i], y + dy[i]

                if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] != "#" and dp[nx, ny] == INF:
                    q.insert(0, (nx, ny))
                    dp[nx, ny] = dp[x, y] + 1
        return dp[gx, gy]
    return bfs()

L = []
for h1 in range(H):
    for h2 in range(H):
        for w1 in range(W):
            for w2 in range(W):
                dp = np.full((H, W), INF)
                p = clear_maze(h1, w1, h2, w2, S)
                if p != INF:
                    L.append(p)

print(max(L))

### FIXED CODE ###

#input
H, W = map(int, input().split())
import numpy as np
S = [input() for _ in range(H)]

#output
import numpy as np

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

answer = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != "#":
            dp = np.full((H, W), INF)
            q = []
            q.insert(0, (i, j))
            dp[i, j] = 0
            while len(q):
                x, y = q.pop()

                for t in range(4):
                    nx, ny = x + dx[t], y + dy[t]

                    if (0 <= nx < H) and (0 <= ny < W) and (S[nx][ny] != "#") and (dp[nx, ny] == INF):
                        q.insert(0, (nx, ny))
                        dp[nx, ny] = dp[x, y] + 1
            for row in dp:
                answer = max(answer, max(row))
print(int(answer))
NK = input().split();
N,K = int(NK[0]),int(NK[1]);
min = N;

#桁が大きい時の処理
while(int(len(str(N))) > 2):
    N = int(N - K * (N / 2));

flag = True;
while flag == True:
    N = abs(N - K);
    if(N <= min):
        min = N;
    else:
        flag = False;
    
print(min);

### FIXED CODE ###

import math

NK = input().split();
N,K = int(NK[0]),int(NK[1]);
min = N;

#桁が大きい時の処理
if(K == 1):
    while(int(len(str(N))) > 2):
        N = int(N - K * (N / 2));
else:
    border = math.floor(N / K);
    N = N - K * border;
        
flag = True;
while flag == True:
    N = abs(N - K);
    if(N <= min):
        min = N;
    else:
        flag = False;
    
print(min);
s = input()
t = input()

dp = [0] * (len(s)+1)
dps = [[] for _ in range(len(s)+1)]
for i in range(1, len(t)+1):
    ti = t[i-1]
    for j in range(1, len(s)+1):
        sj = s[j-1]
        if ti == sj:
            dp[j] = dp[j-1] + 1
            dps[j] = (dps[j-1] + [ti]).copy()
        else:
            if dp[j-1] >= dp[j]:
                dp[j] = dp[j-1]
                dps[j] = dps[j-1][:]
print(''.join(dps[-1]))

### FIXED CODE ###

s = input()
t = input()
dp = [[0] * (len(s)+1) for _ in range(len(t)+1)]
for i in range(1, len(t)+1):
    ti = t[i-1]
    dp[i] = dp[i-1][:]
    for j in range(1, len(s)+1):
        if ti == s[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])

ans = ''
sl = len(s)
tl = len(t)
while sl > 0 and tl > 0:
    if s[sl-1] == t[tl-1]:
        sl -= 1
        tl -= 1
        ans = s[sl] + ans
        continue
    if dp[tl][sl] == dp[tl][sl-1]:
        sl -= 1
    elif dp[tl][sl] == dp[tl-1][sl]:
        tl -= 1
print(ans)
ans=-1
nums=input().split(" ")
t8,t10=int(nums[0]),int(nums[1])
value_f=int(max(round(t8*100/8),round(t10*100/10))+1)
while True:
  tax8,tax10=value_f*8/100,value_f*10/100
  if tax8>=t8 and tax8<t8+1 and tax10>=t10 and tax10<t10+1:
    ans=value_f
  elif tax8<t8 or tax10<t10:
    print(ans)
    break
  value_f-=1
  if value_f<0:
    break

### FIXED CODE ###

letter=input()
if "A" not in letter:
  print("No")
elif "B" not in letter:
  print("No")
else:
  print("Yes")
n, y = map(int, input().split())
yen = [1000, 5000, 10000]

def f():
  for i range(n):
    r = yen[2] * i
    if r > y:
      continue
    for j range(n):
      if i + j > n:
        continue
      r += yen[1] * j  + yen[1] * (n - i -j)
      if r == y:
        print('{} {} {}".format(i, j, n - i - j))
        return
  print('-1 -1 -1')

f()

### FIXED CODE ###

n, y = map(int, input().split())
yen = [1000, 5000, 10000]

def f():
    for i in range(n+1):
        r = yen[2] * i
        if r > y:
            continue
        for j in range(n+1):
            if i + j > n:
                continue
            if r + yen[1] * j + yen[0] * (n - i -j)== y:
                print('{} {} {}'.format(i, j, n - i - j))
                return
    print('-1 -1 -1')

f()
N = int(input())
A = sorted(map(int, input().split()))
ans = sum(A)
nums = [A.count(num) for num in range(10 ** 5)]

Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    ans += (C - B) * nums[B]
    nums[C] += nums[B]
    nums[B] = 0
    print(ans)

### FIXED CODE ###

import collections

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

cnt = collections.defaultdict(int)
for a in A:
    cnt[a] += 1
ans = sum(A)

Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    ans += (C - B) * cnt[B]
    cnt[C] += cnt[B]
    cnt[B] = 0
    print(ans)
N, K = map(int, input().split())
S = list(input())

arr = [0 for _ in range(N)]
idx = 0
pre = '1'
if S[0] == '0':
    idx += 1
    arr[0] = 0
    pre = '0'

for i in range(N):
    if pre == S[i]:
        arr[idx] += 1
    else:
        idx += 1
        arr[idx] += 1
    pre = S[i]

max_lensum = 0
for i in range(0, idx+1, 2):
    #print("arr", arr)
    #print("arr", arr[i:min(i+2*K+1, idx+1)])
    lensum = sum(arr[i:min(i+2*K+1, idx+1)])
    if lensum > max_lensum:
        max_lensum = lensum
    if i+2*K+1 > idx: break
print(max_lensum)

### FIXED CODE ###

S = input()
cnt = 0
s = S[0]
for i in range(1, len(S)):
    si = int(S[i])
    #print(s, si)
    if int(s) == int(si):
        #print("hit")
        s = 1 - si
        cnt += 1
    else:
        s = si

# reverse first
cnt2 = 1
s = 1 - int(S[0])
for i in range(1, len(S)):
    si = int(S[i])
    #print(s, si)
    if int(s) == int(si):
        #print("hit")
        s = 1 - si
        cnt2 += 1
    else:
        s = si

#print(cnt, cnt2)
print(min(cnt, cnt2))
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))


ans = -1e18

for i in range(n):
    now = i
    score = []
    while True:
        now = p[now] - 1
        score.append(c[now])
        if now == i:
            break
    print(score)
    loopsum = sum(score)
    if loopsum <= 0:
        point = 0
        for j in range(len(score)):
            if j > k - 1:
                break 
            point = point + score[j]
            ans = max(ans,point)
    else:
        point = 0      
        for j in range(len(score)-1):
            if j > k - 1:
                break
            point = point + score[j]
            loopnum = (k - (j + 1))//len(score)
            ans = max(ans,point+loopnum*loopsum)
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

lastans = -1e20

for i in range(n):
    now = p[i] - 1 
    score = [c[now]]
    while True:
        now = p[now] - 1
        score.append(score[-1] + c[now])
        if now == i:
            break
    loopsum = score[-1]
    looplen = len(score)
#    print(score)
    if looplen >= k:
        ans = max(score[:k])
    elif loopsum <= 0:
        ans = max(score)
    else:
        loopnum = k//looplen
        loopnum_mod = k % looplen
        ans1 = loopsum * (loopnum - 1) + max(score)
        ans2 = loopsum * loopnum
        if loopnum_mod != 0:
            ans2 = ans2 +max(0,max(score[:loopnum_mod]))
        ans =max(ans1,ans2)
    lastans = max(lastans,ans)

print(lastans)
X = int(input())
Y = int(input())
Z = int(input())
r = X
X = Y
Y = r
r = X
X = Z
Z = r
print(X,Y,Z)

### FIXED CODE ###

a,b,c = input().split()
print(c,a,b)
k,x = map(int,input().split())
a = x+k-1
b = x-k+1
l = rane[b:a+1]
print(l)


### FIXED CODE ###

k,x = map(int,input().split())
for a in range(x-k+1,x+k):
    print(a ,end=" ")
import collections

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

for i in range(N):
  print(a[i])

### FIXED CODE ###

import collections
 
N = int(input())
A = list(map(int,input().split()))
a = collections.Counter(A)
 
for i in range(N):
  print(a[i+1])
a=int(input())
b=int(input())
print(max([a+b,a-b,a*b]))

### FIXED CODE ###

a, b = map(int, input().split())
print(max([a+b,a-b,a*b]))
# math.gcd()を使う
import math
N, X = map(int, input().split())
# 一行の入力をリストxに入れる
x = list(map(int, input().split()))
# すべての(x[i]-X)の最大公約数が答え
# 最初の最大公約数
t = x[0] - X
for a in x:
    # 最大公約数を更新
    t = math.gcd(t, abs(a - X))
print(t)


### FIXED CODE ###

A, B = map(int, input().split())
if A % 2 is 0 or B % 2 is 0:
    print('No')
else:
    print("Yes")
N,M=[int(x) for x in input().split()]
I=[[] for n in range(N)]
ans = int(N * (N-1) / 2)
E=[]
result=[]
G=[n for n in range(N)]
W=[1 for n in range(N)]

def union(i,g):
    if(G[i]!=g):
        G[i]=g
        for n in I[i]:
            union(n,g)

for m in range(M):
    A,B=[int(x) for x in input().split()]
    E.append((A-1,B-1))

for m in range(M):
    result.append(ans)
    if(ans>0):
        A,B=E.pop()
        Ga,Gb=G[A],G[B]
        Wa,Wb=W[Ga],W[Gb]
        if (Wb>Wa):
            union(Ga,Gb)
            W[Gb]=Wa+Wb
        else:
            union(Gb,Ga)
            W[Ga]=Wa+Wb
        ans=ans-(Wa*Wb)
        I[A].append(B)
        I[B].append(A)

for r in reversed(result):
    print(r)


### FIXED CODE ###

N,M=[int(x) for x in input().split()]
G=[-1] * N
W=[0] * N
E=[]

result=[]
ans = int(N * (N-1) / 2)

def union(i,j):
    gi=find(i)
    gj=find(j)

    if(gi!=gj):
        if W[gi] > W[gj]:
            G[gi]+=G[gj]
            G[gj]=gi
        else:
            G[gj]+=G[gi]
            G[gi]=gj
            if W[gi]==W[gj]:
                W[gj]+=1

def find(i):
    if G[i]<0:
        return i;
    else:
        G[i]=find(G[i])
        return G[i]

for m in range(M):
    A,B=[int(x) for x in input().split()]
    E.append((A-1,B-1))

for m in range(M):
    result.append(ans)
    if(ans>0):
        A,B=E.pop()
        ga,gb=find(A),find(B)
        if (ga!=gb):
            ans=ans-(G[ga]*G[gb])
            union(A,B)

for r in reversed(result):
    print(r)