Harryxun/stf_run huggingface dataset:
from collections import Counter
N, K = map(int,input().split())
A = list(map(int,input().split()))
i = k = 0
B = [1]
for i in range(N):
    B.append(A[B[i]])
S = Counter(B)
idx = S.most_common(1)[0][0]
i = k = cnt = 0
k_s = None
while k < 10 ** 6:
    if B[k] == idx and cnt == 1:
        k_s = k
        break
    elif B[k] == idx:
        k_f = k
        cnt += 1
    k += 1
if k_s:
    k_max = K % (k_s - k_f)
else:
    k_max = K
i = k = 0
while k < k_max:
    i = A[i] - 1
    k += 1
print(i + 1)   

### FIXED CODE ###

from collections import Counter
N, K = map(int,input().split())
A = list(map(int,input().split()))
i = k = 0
B = [1]
while k <= 10 ** 6:
    i = A[i] - 1
    B.append(i + 1)
    k += 1
S = Counter(B)
idx = S.most_common(1)[0][0]
i = k = cnt = 0
k_s = None
while k < 10 ** 6:
    if B[k] == idx and cnt == 1:
        k_s = k
        break
    elif B[k] == idx:
        k_f = k
        cnt += 1
    k += 1
if k_s and k_s < K:
    k_max = (K - B.index(idx)) % (k_s - k_f) + B.index(idx)
else:
    k_max = K
i = k = 0
while k < k_max:
    i = A[i] - 1
    k += 1
print(i + 1)
N = int(input())
x,y = list(map(int,input().split()))
dis = 0
for i in range(N-1):
  dis = ((x[0])**2+(y[0])**2)**0.5
  dis += ((x[i]-x[i+1])**2+(y[i]-y[i+1])**2)**0.5
print(dis/N)

### FIXED CODE ###

N = int(input())
XY = [[0]*2]*N
dis = 0
for i in range(N):
  XY[i] = [int(_) for _ in input().split()]
for i in range(N):
  Xi = XY[i][0]
  Yi = XY[i][1]
  for j in range(N):
    Xj = XY[j][0]
    Yj = XY[j][1]
    dis += ((Xi-Xj)**2 + (Yi-Yj)**2)**0.5

print(dis/N)
N = int(input())

print((N*(N+1)//2)

### FIXED CODE ###

N = int(input())

print((N*(N+1)//2))
N,M=map(int,input().split())
numbers=[' ',]*N
kotae=0
for a in range(M):
    suuji=[]
    s,c=input().split()
    if numbers[int(s)-1]==' ':
        numbers[int(s)-1]=int(c)
    else:
        if numbers[int(s)-1]==int(c):
            continue
        else:
            print('-1')
            kotae+=1
            break

for a in range(N):
    if numbers[a]==' ':
        numbers[a]=0
if N>=2:
    if numbers[0] == 0:
        del numbers[0]
        if numbers[0] == 0:
            del numbers[0]
            if numbers[0] == 0:
                del numbers[0]
if kotae==0:
    if len(numbers)!=N:
        print('-1')
    else:
       moji=''
       for a in numbers:
           moji+=str(a)
       print(moji)


### FIXED CODE ###

N,M=map(int,input().split())
numbers=[' ',]*N
kotae=0
for a in range(M):
    suuji=[]
    s,c=input().split()
    if numbers[int(s)-1]==' ':
        numbers[int(s)-1]=int(c)
    else:
        if numbers[int(s)-1]==int(c):
            continue
        else:
            print('-1')
            kotae+=1
            break
if numbers[0]==' ' and N==3:
    numbers[0]=1
if N==2 and numbers[0]==' ':
    numbers[0]=1
for a in range(N):
    if numbers[a]==' ':
        numbers[a]=0
if N==3:
    if numbers[0] == 0:
        del numbers[0]
        if numbers[0] == 0:
            del numbers[0]
            if numbers[0] == 0:
                del numbers[0]
if N==2:
    if numbers[0] == 0:
        del numbers[0]
        if numbers[0] == 0:
            del numbers[0]
if kotae==0:
    if len(numbers)!=N:
        print('-1')
    else:
       moji=''
       for a in numbers:
           moji+=str(a)
       print(int(moji))
s=input()
t=input()
sl = [s[i] for i in range(len(s))]
tl = [t[i] for i in range(len(t))]
n = len(sl)
m = len(tl)
sl.sort()
tl.sort(reverse=True)
flg = False

if n < m:
    for i in range(n):
        if sl[i] != tl[i]:
            flg = False
            break
        flg = True
for i in range(n):
    if sl[i] < tl[i]:
        flg = True
        break
if flg:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

s=input()
t=input()
sl = [s[i] for i in range(len(s))]
tl = [t[i] for i in range(len(t))]
n = len(sl)
m = len(tl)
sl.sort()
tl.sort(reverse=True)
s_ans = ''.join(sl)
t_ans = ''.join(tl)
if s_ans < t_ans:
    print("Yes")
else:
    print("No")
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)

ans=A[0]
if N>2:
    p = (N-2)//2
    q = (N-2)%2
#print(p,q)

ans += 2*sum(A[1:1+p])
if q==1:
    ans += A[1+p]

print(ans)

### FIXED CODE ###

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

ans=A[0]
if N>2:
    p = (N-2)//2
    q = (N-2)%2
    ans += 2*sum(A[1:1+p])
    if q==1:
        ans += A[1+p]

print(ans)
N=int(input())
A=[int(i) for i in input().split()]
Q=int(input())
X=[i+1 for i in range((10**5))]
dic={}
ans=sum(A)
for i in A:
	try:
		dic[i]+=1
	except:
		dic.setdefault(i,1)
for i in range(Q):
	[B,C]=[int(i) for i in input().split()]
	try:
		ans+=dic[B]*(C-B)
		try:
			dic[C]+=dic[B]
		except:
			dic.setdefault(C,dic[B])
		dic[B]=0
	except:
		ans+=0

	print(ans)


### FIXED CODE ###

N=input()
X=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
if N in X:
  print("A")
else:
  print("a")
n = int(input())
a = list(map(int, input().split()))
max_a = 20 ** 2
MOD = 10 ** 9 + 7

ru = [0] * (n + 1)
for i in range(n):
    ru[i + 1] = ru[i] ^ a[i]

ptn = [0] * (max_a)
ptn[0] = 1
tot_ex0 = 0
if ru[-1] != 0:
    for i in range(n):
        if i == n - 1:
            print(tot_ex0)
            exit()
        if ru[i + 1] == 0:
            ptn[0] += tot_ex0
            ptn[0] %= MOD
        elif ru[i + 1] == ru[-1]:
            ptn[ru[i + 1]] += ptn[0]
            ptn[ru[i + 1]] %= MOD
            tot_ex0 += ptn[0]
            tot_ex0 %= MOD
print(re)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
max_a = 2 ** 20
MOD = 10 ** 9 + 7

ru = [0] * (n + 1)
for i in range(n):
    ru[i + 1] = ru[i] ^ a[i]


if ru[-1] != 0:
    # 0, ru[-1], 0, ru[-1], 0, ..., ru[-1]
    dp = [0] * (max_a)
    dp[0] = 1
    tot_ex0 = 0
    for i in range(n):
        if i == n - 1:
            print(dp[0])
            exit()
        if ru[i + 1] == 0:
            dp[0] += tot_ex0
            dp[0] %= MOD
        elif ru[i + 1] == ru[-1]:
            dp[ru[i + 1]] += dp[0]
            dp[ru[i + 1]] %= MOD
            tot_ex0 += dp[0]
            tot_ex0 %= MOD
else:
    # 0, x, 0, x, 0, x, ..., 0 (x != 0)
    dp = [0] * max_a
    dq = [1] * max_a
    set_evaled = [0] * max_a
    times = 0
    ans = 0
    for i in range(n):
        if i == n - 1:
            ans = sum(dp)
            break
        elif ru[i + 1] == 0:
            # これを遅延評価する
            # for j in range(max_a):
            #     dq[j] += dp[j]
            times += 1
        else:
            dq[ru[i + 1]] += (times - set_evaled[ru[i + 1]]) * dp[ru[i + 1]]
            dq[ru[i + 1]] %= MOD
            set_evaled[ru[i + 1]] = times
            dp[ru[i + 1]] += dq[ru[i + 1]]
            dp[ru[i + 1]] %= MOD
    # 0, 0, 0, 0, 0, 0, ..., 0
    cnt_0 = sum([1 for i in range(n) if ru[i + 1] == 0])
    ans = (ans + pow(2, cnt_0 - 1, MOD)) % MOD
    print(ans)
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
e=[]
flag=0
for i in range(h):
  if i%2:
    for j in range(w-1,-1,-1):
      if a[i][j]%2:
        flag=1
        break
  else:
    for j in range(w):
      if a[i][j]%2:
        flag=1
        break
  if flag:break
else:
  exit()
flag=0
y,x=i,j
while True:
  nx,ny=x,y
  if y%2:
    if x:nx=x-1
    else:ny=y+1
  else:
    if x<w-1:nx=x+1
    else:ny=y+1
  if a[y][x]%2:flag=1-flag
  if flag:e.append((y+1,x+1,ny+1,nx+1))
  if h%2:
    if (ny,nx)==(h-1,w-1):break
  else:
    if (ny,nx)==(h-1,0):break
  x,y=nx,ny
print(len(e))
for i in e:
  print(*i)

### FIXED CODE ###

h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
ans=[]
for i in range(h):
  for j in range(w-1):
    if a[i][j]%2:
      a[i][j]-=1
      a[i][j+1]+=1
      ans+=[(i+1,j+1,i+1,j+2)]
for i in range(h-1):
  if a[i][w-1]%2:
    a[i][w-1]-=1
    a[i+1][w-1]+=1
    ans+=[(i+1,w,i+2,w)]
print(len(ans))
for i in ans:
  print(*i)
A=int(input())
B=int(input())
C=int(input())
if A*C<=B:
    print(C)
else:
    n=B//A
    print(n)

### FIXED CODE ###

A,B,C= map(int, input().split())
if A*C<=B:
    print(C)
else:
    n=B//A
    print(n)
#!/usr/bin/env python3
# coding=utf-8

import sys


def become_a(a, start, numbers):
    if numbers is None:
        return a == start
    if len(numbers) == 1:
        return a == start + numbers[0] or a == start - numbers[0]
    return become_a(a, start + numbers[0], numbers[1:]) or become_a(a, start - numbers[0],
                                                                    numbers[1:])


s = sys.stdin.readline().strip().split("T")
x, y = sys.stdin.readline().strip().split(" ")
x = int(x)
y = int(y)
move_all = [len(_s) for _s in s]
move_x = move_all[::2]
move_y = move_all[1::2] or None
if become_a(x, move_x[0], move_x[1:] or None) and become_a(y, 0, move_y):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

#!/usr/bin/env python3
# coding=utf-8

import sys

s = sys.stdin.readline().strip().split("T")
x, y = sys.stdin.readline().strip().split(" ")
x = int(x)
y = int(y)
move_all = [len(_s) for _s in s]
pos_x = set([move_all[0]])
pos_y = set([0])
move_x = move_all[2::2] or None
move_y = move_all[1::2] or None
if move_x:
    for move in move_x:
        pos_x = {_x + move for _x in pos_x} | {_x - move for _x in pos_x}
if move_y:
    for move in move_y:
        pos_y = {_y + move for _y in pos_y} | {_y - move for _y in pos_y}
if x in pos_x and y in pos_y:
    print("Yes")
else:
    print("No")
import unittest


def solve_small(n):
    total = 0
    for m in range(1, n):
        if n // m == n % m:
            total += m
    return total


def solve(n):
    conds = set()
    conds.add(n-1)
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            conds.add(i-1)
            conds.add(n // i - 1)
    total = 0
    for m in list(conds):
        if n // m == n % m:
            total += m
    return total


def main():
    n = int(input())
    result = solve(n)
    print(result)


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def test_solve_1(self):
        n = 8
        actual = solve(n)
        expected = 10
        self.assertEqual(actual, expected)

    def test_solve_2(self):
        n = 1000000000000
        actual = solve(n)
        expected = 2499686339916
        self.assertEqual(actual, expected)


### FIXED CODE ###

import unittest


def solve(n):
    used = set()
    total = 0
    for i in range(1, int(n ** 0.5)+1):
        if n % i > 0:
            continue
        d = n // i
        cand = [i-1, d-1]
        for c in cand:
            if c not in used and c > 0 and n % c == n // c:
                total += c
                used.add(c)

    return total


def main():
    n = int(input())
    result = solve(n)
    print(result)


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def test_solve_1(self):
        n = 8
        actual = solve(n)
        expected = 10
        self.assertEqual(actual, expected)

    def test_solve_2(self):
        n = 1000000000000
        actual = solve(n)
        expected = 2499686339916
        self.assertEqual(actual, expected)
i = 0
x = input()
y = 100
while x >= y:
  y = int(y * 101 /100)
  i += 1
print(i)

### FIXED CODE ###

i = 0
x = int(input())
y = 100
while x > y:
  y = int(y * 101 /100)
  i += 1
print(i)
N,M = map(int,input().split())
A = list(map(int,input().split()))

R = [A[0]%M]


for i in range(1,N):
  R.append((R[-1]+A[i])%M)

k = set(R)
dic = {i:0 for i in k}
for item in R:
  dic[item]+=1

ans = dic[0]
#ans = (dic[0]*(dic[0]+1))/2

#for i in k:
 # if i !=0 :
  #  ans += (dic[i]*(dic[i]-1))/2
    

    
print(int(ans))


### FIXED CODE ###

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

R = [A[0]%M]


for i in range(1,N):
  R.append((R[-1]+A[i])%M)



import collections
c = collections.Counter(R)


ans = 0
for key in c:
  if key == 0:
    ans += (c[key]*(c[key]+1))/2
  else:
    ans += (c[key]*(c[key]-1))/2
  



print(int(ans))
N = int(input())
to = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b, c = map(int, input().split())
    a, b, = a - 1, b - 1
    to[a].append((c, b))
    to[b].append((c, a))

Q, K = map(int, input().split())
K -= 1
query = [list(map(lambda x:int(x) - 1, input().split())) for _ in range(Q)]
depth = [0] * N


def dfs(v, d, p=-1):
    depth[v] = d
    for cost, nv in to[v]:
        if nv == p:
            continue
        dfs(nv, d + cost, v)


def main():
    dfs(K, 0)
    for x, y in query:
        print(depth[x] + depth[y])


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)


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

for _ in range(N - 1):
    a, b, c = map(int, input().split())
    a, b, = a - 1, b - 1
    to[a].append((c, b))
    to[b].append((c, a))

Q, K = map(int, input().split())
K -= 1
query = [list(map(lambda x:int(x) - 1, input().split())) for _ in range(Q)]
depth = [0] * N

def dfs(v, d, p=-1):
    depth[v] = d
    for cost, nv in to[v]:
        if nv == p:
            continue
        dfs(nv, d + cost, v)


def main():
    dfs(K, 0)
    for x, y in query:
        print(depth[x] + depth[y])


if __name__ == "__main__":
    main()
# 正解ではない

from queue import Queue


def main():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    S = [list(input()) for i in range(H)]
    q = Queue()
    q.put((0, Ch - 1, Cw - 1))
    S[Ch - 1][Cw - 1] = '1'

    answer = resolve(q, S, (Dh - 1, Dw - 1), H, W)
    print(answer)


def resolve(q, S, D, H, W):
    cell_list = list()
    while not q.empty():
        worp_count, x, y = q.get()
        S[x][y] = '2'
        cell_list.append((x, y))

        if (x, y) == D:
            return worp_count

        for i, j in [(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)]:
            if 0 <= i < H and 0 <= j < W and S[i][j] == '.':
                q.put((worp_count, i, j))
                S[i][j] = '1'

    if not cell_list:
        return -1

    for x, y in cell_list:
        for i, j in [(a, b) for a in range(-2, 3) for b in range(-2, 3)]:
            if 0 <= x + i < H and 0 <= y + j < W and S[x + i][y + j] == '.':
                q.put((worp_count + 1, x + i, y + j))
                S[x + i][y + j] = '1'

    return resolve(q, S, D, H, W)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque


def main():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    d = [[-1 for _ in range(W)] for _ in range(H)]

    q = deque([])
    q.appendleft((0, Ch - 1, Cw - 1))

    while len(q):
        worp_count, x, y = q.popleft()

        if d[x][y] != -1:
            continue
        d[x][y] = worp_count

        for i, j in ((a, b) for a in range(-2, 3) for b in range(-2, 3)):
            nx = x + i
            ny = y + j
            if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.':
                if i == 0 and j == 0:
                    continue
                elif abs(i) + abs(j) == 1:
                    q.appendleft((worp_count, nx, ny))
                else:
                    q.append((worp_count + 1, nx, ny))

    print(d[Dh - 1][Dw - 1])


if __name__ == "__main__":
    main()
import numpy as np
import sys

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

L = int(np.ceil(np.log2(B)))
result = 0

for i in range(L+1):
    am = 0
    zen = 2**(i+1)
    han = zen//2

    s = A%zen
    e = B%zen+1

    b = (max(e-han,0) + max(s-han,0) ) %2
    # print(s,e,b)
    result += han*b

print(result)

### FIXED CODE ###

import numpy as np
import sys

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

def f(x):
    if x%4 == 0:
        return x
    elif x%4 == 1:
        return x^(x-1)
    elif x%4 == 2:
        return x^1
    else:
        return x^(x-1)^1

print(f(A-1)^f(B))
temp=input()
b=int(temp)
print(48-temp)


### FIXED CODE ###

temp=input()
b=int(temp)
print(48-b)
s=input()
k=int(input())
c=[]
for i in range(len(s)):
    for j in range(min(len(s)-i,k)):
        t=s[i:i+j+1]
        if t not in cnt:
            c.append(t)
print(sorted(c)[k-1])

### FIXED CODE ###

s=input()
k=int(input())
cnt=[]
for i in range(len(s)):
    for j in range(min(len(s)-i,k)):
        t=s[i:i+j+1]
        if t not in cnt:
            cnt.append(t)
print(sorted(cnt)[k-1])
import math
import random
import time
stime = time.time
N, K = map(int, input().split())
X = []
for _ in range(N):
    x, y, c = map(int, input().split())
    X.append((x, y, c))

def f(x0, y0):
    
    L = []
    for x, y, c in X:
        L.append(math.sqrt((x-x0)**2+(y-y0)**2) * c)
    return sorted(L)[K-1]


mi = 1 << 100
for x1, y1, _ in X:
    for x2, y2, __ in X:
        x0, y0 = (x1+x2*2) / 3, (y1+y2*2) / 3
        a = f(x0, y0)
        mi = min(mi, a)
        r = 100
        for i in range(300):
            dx, dy = random.randrange(-10, 11) * r, random.randrange(-10, 11) * r
            nx0, ny0 = x0 + dx, y0 + dy
            b = f(nx0, ny0)
            if a > b:
                mi = min(mi, b)
                x0, y0 = nx0, ny0
                a = b
            r *= 0.85
    if time.time - stime() > 1.75:
        break

print(mi)

### FIXED CODE ###

import math
def intersectionCC0(x1, y1, r1, r2):
    r = x1**2 + y1**2
    t = (r + r1**2 - r2**2) / (2*r)
    dd = r1**2/r - t**2
    if - (10**-16) < dd < 0: dd = 0
    if dd < 0: return []
    x, y = t * x1, t * y1
    if dd == 0: return [(x, y)]
    sq = math.sqrt(dd)
    dx, dy = y1 * sq, -x1 * sq
    return [(x+dx, y+dy), (x-dx, y-dy)]

def intersectionCC(x1, y1, x2, y2, r1, r2):
    return [(x1+x, y1+y) for x, y in intersectionCC0(x2-x1, y2-y1, r1, r2)]

def chk(t):
    L = [a for a in L0]
    for i, (x1, y1, c1) in enumerate(X):
        for x2, y2, c2 in X[:i]:
            L += intersectionCC(x1, y1, x2, y2, t/c1, t/c2)
    for x0, y0 in L:
        cnt = 0
        for x, y, c in X:
            if math.sqrt((x-x0) ** 2 + (y-y0) ** 2) * c <= t + 10**-8:
                cnt += 1
        if cnt >= K: return 1
    return 0

N, K = map(int, input().split())
X = []
L0 = []
for _ in range(N):
    x, y, c = map(int, input().split())
    X.append((x, y, c))
    L0.append((x, y))

l, r = 0, 1 << 30
while (r-l) * (1<<25) > max(1, l):
    m = (l+r) / 2
    if chk(m):
        r = m
    else:
        l = m
    
print(l)
DIV = 100000
n, m = map(int, raw_input().split())
l = [input() for _ in range(n-1)]
ans = [0]*(n-1)
pos = 0
for _ in range(m):
    k = input()
    if k > 0:
        for i in range(k): ans[pos+i] += 1
    else:
        for i in range(-1, k-1, -1):       
            ans[pos+i] += 1
    pos += k
print sum((ans[i] * l[i]) % DIV for i in range(n-1)) % DIV

### FIXED CODE ###

DIV = 100000
n, m = map(int, raw_input().split())
l = [0]*n
for i in range(n-1):
    k = input()
    l[i+1] = l[i] + k
ans = pos = 0
for _ in xrange(m):
    k = input()
    ans = (ans + abs(l[pos + k] - l[pos])) % DIV
    pos += k
print ans
# -*- coding utf-8 -*-

n, k = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]
sushi.sort(key = lambda x: x[1], reverse = True)    # sort by d

mp_max = 0
op = 0
taberu_ind = set()
pop_cands = []
t_taberu = set()
# greedy for delicious point
for i in range(k):
    op += sushi[i][1]

    t = sushi[i][0]
    if t_taberu.isdisjoint({t}):    # new type
        t_taberu.add(t)
    else:
        pop_cands.append(i)

    taberu_ind.add(i)
mp_max = op + len(t_taberu)**2

# reduce dericious, gain variety
i += 1
j = i
for i in range(i, n):
    pop_ind = pop_cands.pop()
    taberu_ind.remove(pop_ind)

    for j in range(j, n):
        t = sushi[j][0]
        if t_taberu.isdisjoint({t}):
            t_taberu.add(t)
            break
    else:
        break
    
    # calc points
    op -= sushi[pop_ind][1]
    op += sushi[j][1]
    mp = op + len(t_taberu)**2
    mp_max = max(mp_max, mp)

    taberu_ind.add(i)

print(mp_max)



### FIXED CODE ###

# -*- coding utf-8 -*-

n, k = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]
sushi.sort(key = lambda x: x[1], reverse = True)    # sort by d

mp_max = 0
op = 0
taberu_ind = set()
pop_cands = []
t_taberu = set()
# greedy for delicious point
for i in range(k):
    op += sushi[i][1]

    t = sushi[i][0]
    if t_taberu.isdisjoint({t}):    # new type
        t_taberu.add(t)
    else:
        pop_cands.append(i)

    taberu_ind.add(i)
mp_max = op + len(t_taberu)**2

# reduce dericious, gain variety
i += 1
j = i
for i in range(i, n):
    if len(pop_cands) == 0:
        break

    pop_ind = pop_cands.pop()
    taberu_ind.remove(pop_ind)

    for j in range(j, n):
        t = sushi[j][0]
        if t_taberu.isdisjoint({t}):
            t_taberu.add(t)
            break
    else:
        break
    
    # calc points
    op -= sushi[pop_ind][1]
    op += sushi[j][1]
    mp = op + len(t_taberu)**2
    mp_max = max(mp_max, mp)

    taberu_ind.add(i)    # not necessary actually
print(mp_max)
import heapq
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
d=[]
for i in range(m):
  b,c=map(int,input().split())
  d.append([b,c])
d=sorted(d, key=lambda x: x[1], reverse=True)
i=0
j=d[0][1]
k=0
while a[i]<j and i<n:
  a[i]=j
  d[k][0]-=1
  if d[k][0]==0:
    k+=1
    if k==m:
      print(sum(a))
      exit()
    else:
      j=d[k][1]
  i+=1
print(sum(a))

### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
d=[]
for i in range(m):
  b,c=map(int,input().split())
  d.append([b,c])
d=sorted(d, key=lambda x: x[1], reverse=True)
i=0
j=d[0][1]
k=0
while a[i]<j:
  a[i]=j
  d[k][0]-=1
  if d[k][0]==0:
    k+=1
    if k==m:
      break
    else:
      j=d[k][1]
  i+=1
  if i==n:
    break
print(sum(a))
import numpy as np
h, w, m = map(int, input().split())
arr = np.zeros([h,w])
for _ in range(m):
    c_h, c_w = map(int, input().split())
    arr[c_h-1, c_w-1] = 1
    
row_sum = np.sum(arr, axis=1)
col_sum = np.sum(arr, axis=0)
row_max_pos = np.argwhere(row_sum == np.max(row_sum))
col_max_pos = np.argwhere(col_sum == np.max(col_sum))
    
row_max = int(max(row_sum))
col_max = int(max(col_sum))
ans = row_max + col_max

if sum(sum(arr[row_max_pos, col_max_pos] == 0)) > 0:
    print(ans)
else:
    print(ans-1)

### FIXED CODE ###

h, w, m = map(int, input().split())
h_cnt = [0 for i in range(h)]
w_cnt = [0 for i in range(w)]
bomb = set()

for i in range(m):
    _h, _w = map(int, input().split())
    h_cnt[_h-1] += 1
    w_cnt[_w-1] += 1
    bomb.add(((_h-1),(_w-1))) #爆破対象の位置を判断

h_max = max(h_cnt)
w_max = max(w_cnt)

max_h = []
max_w = []

for i in range(h):
    if h_cnt[i] == h_max:
        max_h.append(i)

for i in range(w):
    if w_cnt[i] == w_max:
        max_w.append(i)

flg = True

for i in max_h:
    for j in max_w:
        if (i,j) not in bomb:
            flg = False
            break
print(h_max+w_max-1 if flg else h_max+w_max)
# -*- coding:utf-8 -*-

n,l = map(int,input().strip().split())

ringo=[]

for i in range(n):
	ringo.append(l+i)
min = abs(ringo[0])
min_nim = 0
for i in range(len(ringo)):
	if min > abs(ringo[i]):
		min = abs(ringo[i])
		min_num = i
out = 0
for i in range(len(ringo)):
	if i != min_num:
		out = out + ringo[i]
print(out)





### FIXED CODE ###

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

n,l = map(int,input().strip().split())

ringo=[]

for i in range(n):
	ringo.append(l+i)
min = abs(ringo[0])
min_num = 0
for i in range(len(ringo)):
	if min > abs(ringo[i]):
		min = abs(ringo[i])
		min_num = i
out = 0
for i in range(len(ringo)):
	if i != min_num:
		out = out + ringo[i]
print(out)
print(''.join([o+e for o,e in zip(input(), input()+[''])]))

### FIXED CODE ###

print(''.join([o+e for o,e in zip(input(), input()+'\n')]))
a, b = map(int(), raw_input().split())
if ((a*b)%2) == 0:
  print('Even')
else:
  print('Odd')

### FIXED CODE ###

a, b = map(int, input().split())
if ((a*b)%2) == 0:
  print('Even')
else:
  print('Odd')
N,x = map(int,input().split())
a = list(map(int,input().split()))
i = 0
answer = 0
if a[0] > x:
  answer = a[0] - x
  a[0] = x
for i in range(N-1)
    if a[i] + a[i+1] > x:
        answer += a[i] + a[i+1] - x
        a[i+1] = x - a[i]
print(answer)


### FIXED CODE ###

N,x = map(int,input().split())
a = list(map(int,input().split()))
i = 0
answer = 0
if a[0] > x:
  answer = a[0] - x
  a[0] = x
for i in range(N-1):
    if a[i] + a[i+1] > x:
        answer += a[i] + a[i+1] - x
        a[i+1] = x - a[i]
print(answer)