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

import numpy as np

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

for k in range(0, min(100, K)):
    work = [0] * N
    for i in range(0, N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        work[l] += 1
        if (r + 1 < N):
            work[r + 1] -= 1
    work = np.cumsum(work)
    A = work

print(" ".join([str(item) for item in work]))

### FIXED CODE ###

import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit('(i8[::1],)', cache=True)
def update(A):
    N = len(A)
    B = np.zeros_like(A)
    for i, x in enumerate(A):
        l = max(0, i - x)
        r = min(N - 1, i + x)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1
    B = np.cumsum(B)
    return B

N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)

K = min(K, 100)
for _ in range(K):
    A = update(A)
print(' '.join(A.astype(str)))
### BUGGY CODE ###

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

A = [(a, i) for i, a in enumerate(A)]
A.sort(reverse=1)

# dp[i][j] := 左にi人、右にj人確定した状態での最大値
dp = list2d(N+1, N+1, -INF)
dp[0][0] = 0
for i, (a, x) in enumerate(A):
    # j := 今左に確定してる人数
    for j in range(i+1):
        # k := 今右に確定してる人数
        k = i - j
        # このaを左にする遷移
        y = j
        dp[j+1][k] = max(dp[j+1][k], dp[j][k] + abs(x - y) * a)
        # このaを右にする遷移
        y = N - 1 - k
        dp[j][k+1] = max(dp[j][k+1], dp[j][k] + abs(x - y) * a)
ans = 0
for i in range(N+1):
    # 左右に計N人決まった状態での最大を取る
    ans = max(ans, dp[i][N-i])
print(ans)


### FIXED CODE ###

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

A = [(a, i) for i, a in enumerate(A)]
A.sort(reverse=1)

# dp[i][j] := 左にi人、右にj人確定した状態での最大値
dp = list2d(N+1, N+1, -INF)
dp[0][0] = 0
for i, (a, x) in enumerate(A):
    # j := 今左に確定してる人数
    for j in range(i+1):
        # k := 今右に確定してる人数
        k = i - j
        # このaを左にする遷移
        y = j
        dp[j+1][k] = max(dp[j+1][k], dp[j][k] + abs(x - y) * a)
        # このaを右にする遷移
        y = N - 1 - k
        dp[j][k+1] = max(dp[j][k+1], dp[j][k] + abs(x - y) * a)
ans = 0
for i in range(N+1):
    # 左右に計N人決まった状態での最大を取る
    ans = max(ans, dp[i][N-i])
print(ans)
### BUGGY CODE ###

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

for i in range(1, n + 1):
    print(a.index(i) + 1)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
output = [0] * n
for i, a in enumerate(a):
  output[a - 1] = i + 1
  
print(*output)
### BUGGY CODE ###

from collections import Counter as D, defaultdict as dd
from math import factorial as ft, ceil as aron
from fractions import gcd as pg 
from bisect import insort as ins, bisect_left as bl, bisect_right as br
import sys

#sys.stdin=open("./testfile1.py","r")
raw_input=sys.stdin.readline

f1=lambda : map(int,raw_input().split())
f2=lambda : map(int,list(raw_input()))
f3=lambda : int(raw_input())
f4=lambda : raw_input().rstrip()
def main():
	st=[]
	s=f4()
	n1=0
	ans=0
	for i in s:
		n1+=1
		st.append(i)
		if i=="C" and n1>=3:
			s1=[]
			n2=n1-1
			for i in xrange(3):
				s1.append(st[n2])
				n2-=1
			s1=s1[::-1]
			if s1==["A","B","C"]:
				ans+=1
				st[n1-1]="A"
				while n2>-1 and st[n2]=="A":
					ans+=1
					st[n2+2]="A"
					n2-=1
				st[n2+1],st[n2+2]="B","C"
	print ans


if __name__ == '__main__':
	main()


### FIXED CODE ###

from collections import Counter as D, defaultdict as dd
from math import factorial as ft, ceil as aron
from fractions import gcd as pg 
from bisect import insort as ins, bisect_left as bl, bisect_right as br
import sys

#sys.stdin=open("./testfile1.py","r")
raw_input=sys.stdin.readline

f1=lambda : map(int,raw_input().split())
f2=lambda : map(int,list(raw_input()))
f3=lambda : int(raw_input())
f4=lambda : raw_input().rstrip()
def main():
	
	s=f4()
	n1=0
	ans=0
	i=0
	while i<len(s)-1:
		if s[i]=="A":
			n1+=1
		elif s[i:i+2]=="BC":
			ans+=n1
			i+=1
		else:
			n1=0
		i+=1
	print ans

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

import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
l = na()
l.sort(reverse=True)
c = 0
for ll in range(n):
    for lm in range(ll+1, n):
        for lr in range(lm+1, n):
            if l[ll] < l[lm] + l[lr]:
                c += 1

print(c)


### FIXED CODE ###

import sys
import math
import bisect
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
l = na()
l.sort()


c = 0
for i_1 in range(n-2):
    for i_2 in range(i_1+1, n-1):
        m = l[i_1] + l[i_2]
        i_3max = bisect.bisect_left(l, m) - 1
        c += i_3max - i_2

print(c)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n-1, 0, -1):
    x = i - a[i]
    if x < 0:
        continue
    for j in range(i-1, -1, -1):
        if j + a[j] == x:
            cnt += 1
print(cnt)

### FIXED CODE ###

import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))

x = {}
y = {}
for i in range(n):
    t = i - a[i]
    s = i + a[i]
    if t in x:
        x[t] += 1
    else:
        x[t] = 1
    if s in y:
        y[s] += 1
    else:
        y[s] = 1
cnt = 0
for i in x.keys():
    if i in y:
        cnt += x[i]*y[i]
print(cnt)
### BUGGY CODE ###

a, b, c, k = map(int, input().split())
for i in range(k):
  a2 = b + c
  b2 = c + a
  c2 = a + b
  a = a2
  b = b2
  c = c2
if pow((a-b)**2,1/2) >= 10**18:
  print("Unfair")
else:
  print(a-b)

### FIXED CODE ###

a, b, c, k = map(int, input().split())
"""
for i in range(k):
  a2 = b + c
  b2 = c + a
  c2 = a + b
  a = a2
  b = b2
  c = c2
if pow((a-b)**2,1/2) >= 10**18:
  print("Unfair")
else:
  print(a-b)
"""
if abs(a-b) >= 10**18:
  print("Unfair")
else:
  if k%2==1:
    print(b-a)
  else:
    print(a-b)
### BUGGY CODE ###

import sys
input=sys.stdin.readline #文字列入力はするな！！

n=int(input())
a=list(map(int,input().split()))
z=[0]*(10**6+1)
ans=0
for i in a:
    z[i]+=1
for i in a:
    j=2
    f=0
    if z[i]>=2:
        f=1
    if z[1]>=2:
        f=1
    if i!=1 and z[1]==1:
        f=1
    while j*j<=i:
        if i%j==0:
            if z[j]>=1 or z[i//j]>=1:
                f=1
        j+=1
    if f==0:
        ans+=1
print(ans)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
b=list(set(a))
m=len(b)

p=[0]*(10**6+1)
for i in b:
    if p[i]==0:
        j=2
        while i*j<=10**6:
            p[i*j]=1
            j+=1
a.append(-1)
a.insert(0,-1)
ans=0
for i in range(1,n+1):
    if a[i]!=a[i+1] and a[i]!=a[i-1] and p[a[i]]==0:
        ans+=1
print(ans)
### BUGGY CODE ###

import math

def calc(a, b, c):
    return a ** 2 + b ** 2 + c ** 2 + a * b + b * c + c * a

N = int(input())


for i in range(1, N+1):
    ans = 0
    for x in range(1, round(math.sqrt(i))):
        if x**2 > i:
            break
        t1 = i-x**2
        for y in range(1, round(math.sqrt(t1))):
            if y**2 > t1:
                break
            t2 = t1-y**2
            for z in range(1, round(math.sqrt(t2))):
                if z**2 > t2:
                    break
                tmp = calc(x, y, z)
                if tmp > i:
                    break
                if tmp == i:
                    ans += 1
    print(ans)

### FIXED CODE ###

N = int(input())

ans = [0 for _ in range(10**4+50)]

for x in range(1, 105):
    for y in range(1, 105):
        for z in range(1, 105):
            tmp = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if tmp < 10**4+50:
                ans[tmp] += 1

for i in range(1, N+1):
    print(ans[i])
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque
'''
d = deque([1,2,3])
d.append(1)であれば右(末尾)
d.appendleft(1)であれば左(先頭)
d.pop()であれば3、つまり末尾
d.popleft()であれば1、つまり先頭
'''
h,w = map(int,readline().split())
grid = '#'*(w+2)
A = []
A.append(grid)
for i in range(h):
    tmp = "#" + readline().rstrip().decode() + "#"
    A.append(tmp)
A.append(grid)

def bfs(i,j ):
    inf = 10 ** 7
    dist = [[inf]*(w+2) for i in range(h+2)]
    dist[i][j] = 0
    q = deque()
    q.append((i,j))
    ans = 0
    while q:
        hh, ww = q.popleft()
        dv = dist[hh][ww]
        for k,l in [(1,0),(0,1),(-1,0),(0,-1)]:
            if A[hh+k][ww+l] == "#":
                continue
            if dist[hh+k][ww+l] < dv +1:
                continue
            dist[hh+k][ww+l] = dv +1
            ans = dv + 1
            q.append((hh+k,ww+l))

    return ans

def main():
    anss = 0
    for i in range(h+2):
        for j in range(w+2):
            if A[i][j] == "#":
                continue
            anss = max(anss,bfs(i,j))
    print(anss)
            
main()
    



### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque
'''
d = deque([1,2,3])
d.append(1)であれば右(末尾)
d.appendleft(1)であれば左(先頭)
d.pop()であれば3、つまり末尾
d.popleft()であれば1、つまり先頭
'''
h,w = map(int,readline().split())
grid = '#'*(w+2)
A = []
A.append(grid)
for i in range(h):
    tmp = "#" + readline().rstrip().decode() + "#"
    A.append(tmp)
A.append(grid)

def bfs(i,j ):
    inf = 10 ** 9
    dist = [[inf]*(w+2) for i in range(h+2)]
    dist[i][j] = 0
    q = deque()
    q.append((i,j ))
    ans = 0
    while q:
        hh, ww = q.popleft()
        dv = dist[hh][ww]
        for k,l in [(1,0),(0,1),(-1,0),(0,-1)]:
            if A[hh+k][ww+l] == "#":
                continue
            if dist[hh+k][ww+l] <= dv +1:
                continue
            dist[hh+k][ww+l] = dv +1
            ans = dv + 1
            q.append((hh+k,ww+l))

    return ans

anss = 0
for i in range(h+2):
    for j in range(w+2):
        if A[i][j] == "#":
            continue
        anss = max(anss,bfs(i,j))
print(anss)
### BUGGY CODE ###

import bisect

N = int(input())
L = [int(i) for i in input().split()]
L.sort()
ans = 0

for ind_a, a in enumerate(L):
    for ind_b, b in enumerate(L[ind_a+1:]):

        x = bisect.bisect_left(L[ind_b+ind_a+2:], a+b)
        ans += x

print(ans)


### FIXED CODE ###

import bisect

N = int(input())
L = [int(i) for i in input().split()]
L.sort()
ans = 0

for ind_a, a in enumerate(L):
    for ind_b, b in enumerate(L[ind_a+1:]):
        x = bisect.bisect_left(L[ind_b+ind_a+2:], a+b)
        ans += x

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

#!/usr/bin/env python3
import sys


def solve(N: int, s: "List[str]"):

    count = 0
    str_list = []
    for s_i in s:

        s_i = list(s_i)
        s_i.sort()

        if s_i in str_list:
            # print(s_i)
            # print("True")
            count += str_list.count(s_i)
            str_list.append(s_i)

        else:
            # print(s_i)
            # print("False")
            str_list.append(s_i)

    print(count)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, s)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, s: "List[str]"):

    result = 0
    str_dict = dict()
    for s_i in s:

        s_i = list(s_i)
        s_i.sort()
        s_i = "".join(s_i)

        if s_i in str_dict:
            result += str_dict[s_i]
            str_dict[s_i] += 1
        else:
            str_dict[s_i] = 1

    print(result)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, s)


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

import sys
input = sys.stdin.readline
n, q = map(int, input().split())
c = list(map(lambda x:int(x)-1, input().split()))
query = []
for i in range(q):
    l, r = map(int, input().split())
    query.append((i, l-1, r-1))

class BinaryIndexedTree():
    def __init__(self, n):
        self.n = n
        self.bit = [0]*n
    
    def add(self, i, w):
        x = i+1
        while x<=self.n:
            self.bit[x-1] += w
            x += x & -x
    
    def sum(self, i):
        ret = 0
        x = i+1
        while x>0:
            ret += self.bit[x-1]
            x -= x & -x
        return ret

bit = BinaryIndexedTree(n+1)
query.sort(key=lambda x:x[2])
last = [None]*n
ans = [None]*q
nr = -1
for idx, l, r in query:
    for cr in range(nr+1, r+1):
        if last[c[cr]] is not None:
            bit.add(last[c[cr]]+1, -1)
        last[c[cr]] = cr
        bit.add(cr+1, 1)
    nr = r
    ans[idx] = bit.sum(r+1) - bit.sum(l)
print(*ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n, q = map(int, input().split())
c = list(map(lambda x:int(x)-1, input().split()))
query = []
for i in range(q):
    l, r = map(int, input().split())
    query.append((i, l-1, r-1))

class BinaryIndexedTree():
    def __init__(self, n):
        self.n = n
        self.bit = [0]*n
    
    def add(self, i, w):
        x = i+1
        while x<=self.n:
            self.bit[x-1] += w
            x += x & -x
    
    def sum(self, i):
        ret = 0
        x = i+1
        while x>0:
            ret += self.bit[x-1]
            x -= x & -x
        return ret

bit = BinaryIndexedTree(n+1)
query.sort(key=lambda x:x[2])
last = [None]*n
ans = [None]*q
nr = -1
for idx, l, r in query:
    for cr in range(nr+1, r+1):
        if last[c[cr]] is not None:
            bit.add(last[c[cr]]+1, -1)
        last[c[cr]] = cr
        bit.add(cr+1, 1)
    nr = r
    ans[idx] = bit.sum(r+1) - bit.sum(l)
for i in ans:
    print(i)
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split()))
ans=0
for d in range(61):
    n_1 = 0
    for a in A:
        if (a>>d)&1 == 1:
            n_1 += 1
    n_0 = n - n_1
        
    ans += n_0*n_1 * 2**d
    ans %= 10**9+7
print(ans)

### FIXED CODE ###


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import numpy as np
 
mod = 10 ** 9 + 7
 
N = int(input())
A = np.array(list(map(int, input().split())))
 
 
ans = 0
for n in range(len(bin(max(A)))):   # 最大桁数は、最も大きい数値の2進数の桁数
    num_1 = np.count_nonzero((A >> n)&1)   # 1の数をカウント
    num_0 = N - num_1                      # 0の数をカウント
    mul = num_1 * num_0   # 0 XOR 1の回数
    ans += ((2 ** n)*mul) % mod
ans %= mod
print(ans)
### BUGGY CODE ###

h,w=map(int,input().split())
s=[]
for _ in range(h):
    s.append(list(input()))

left=[[0 for _ in range(w)] for _ in range(h)]
right=[[0 for _ in range(w)] for _ in range(h)]
up=[[0 for _ in range(w)] for _ in range(h)]
down=[[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    count=1
    for j in range(w):
        if(s[i][j]=='.'):
            left[i][j]=count
            count+=1
        else:
            left[i][j]=0
            count=1

for i in range(h):
    count=1
    for j in range(w-1,-1,-1):
        if(s[i][j]=='.'):
            right[i][j]=count
            count+=1
        else:
            right[i][j]=0
            count=1

for j in range(w):
    count=1
    for i in range(h):
        if(s[i][j]=='.'):
            up[i][j]=count
            count+=1
        else:
            up[i][j]=0
            count=1

ans=0
for j in range(w):
    count=1
    for i in range(h-1,-1,-1):
        if(s[i][j]=='.'):
            down[i][j]=count
            count+=1
        else:
            down[i][j]=0
            count=1

        ans=max(ans,left[i][j]+right[i][j]+up[i][j]+down[i][j]-3)

print(ans)


### FIXED CODE ###

import numpy as np
h,w=map(int,input().split())
s=[]
for _ in range(h):
    si=input()
    si=si.replace('.', '1')
    si=si.replace('#', '0')
    s.append(list(map(int,si)))
s=np.array(s)

left=np.zeros((h,w))
right=np.zeros((h,w))
up=np.zeros((h,w))
down=np.zeros((h,w))

for i in range(w):
    if(i==0):
        left[:,i]=s[:,i]
        right[:,w-i-1]=s[:,w-i-1]
    else:
        left[:,i]=(left[:,i-1]+1)*s[:,i]
        right[:,w-i-1]=(right[:,w-i]+1)*s[:,w-i-1]

for i in range(h):
    if(i==0):
        down[i,:]=s[i,:]
        up[h-i-1,:]=s[h-i-1,:]
    else:
        down[i,:]=(down[i-1,:]+1)*s[i,:]
        up[h-i-1,:]=(up[h-i,:]+1)*s[h-i-1,:]

ans=left+right+up+down-3
print(int(np.max(ans)))
### BUGGY CODE ###

# D - Multiple of 2019

s = input()

# pow[k] = 10 ** k % 2019
pow = [1]
while len(pow) <= 1 or pow[-1] > 1:
    pow.append(pow[-1] * 10 % 2019)
n = len(pow) - 1  # 10 ** n == 1 mod 2019

# memo[i % n][m] = (int(s[:i+1]) % 2019 == mであるiの個数)
memo = [{} for i in range(n)]
memo[n - 1][0] = 1  # memo[-1][0] = 1

count = 0  # int(s[i:j+1]) == 0 mod 2019 である(i,j)の個数
mod = 0
for j, c in enumerate(s):
    mod = (mod * 10 + int(c)) % 2019  # mod = int(s[:j+1]) % 2019
    for i in range(1, n + 1):
        m = mod * pow[n - i] % 2019  # m == mod * 10 ** (-i) mod 2019
        if m in memo[(j - i + n) % n]:
            count += memo[(j - i + n) % n][m]
    if mod not in memo[j % n]:
        memo[j % n][mod] = 0
    memo[j % n][mod] += 1

print(count)


### FIXED CODE ###

# D - Multiple of 2019

s = input()

# pow[k] = 10 ** k % 2019
pow = [1]
while len(pow) <= 1 or pow[-1] > 1:
    pow.append(pow[-1] * 10 % 2019)
n = len(pow) - 1  # 10 ** n == 1 mod 2019

# memo[i % n][m] = (int(s[:i+1]) % 2019 == mであるiの個数)
memo = [[0] * 2019 for i in range(n)]
memo[n - 1][0] = 1  # memo[-1][0] = 1

count = 0  # int(s[i:j+1]) == 0 mod 2019 である(i,j)の個数
mod = 0
for j, c in enumerate(s):
    mod = (mod * 10 + int(c)) % 2019  # mod = int(s[:j+1]) % 2019
    for i in range(1, n + 1):
        m = mod * pow[n - i] % 2019  # m == mod * 10 ** (-i) mod 2019
        count += memo[(j - i + n) % n][m]
    memo[j % n][mod] += 1

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

def is_rect_in_HW(H, W, s1, s2, mem):
  s2_factors = factorize(s2, H, W, mem)
  
  res = []
  for  s2_factor in s2_factors:
    if s1[0] == s2_factor[0]: res.append([s1[0], s1_factor[1] + s1[1]])
    elif s1[0] != s1[1] and s1[1] == s2_factor[1]: res.append([s1[0] + s2_factor[0], s1[1]])
  return res

def factorize(num, H, W, mem):
  if num in mem:
    return mem[num]

  factors = set([])
  for i in range(1, min(num+1, max(H+1,W+1))):
    i2 = num//i
    if min(i,i2) > min(H,W) or max(i,i2) > max(H,W): continue
    if num % i == 0: factors.add(tuple(sorted([i,i2])))
  mem[num] = factors
  return factors


H, W = map(int, input().split())
S = int(H*W)
mem = {}
for del_s in range(S-2):
  for s1 in range(1,S-1):
    s3 = s1 + del_s
    s2 = S - s1 - s3
    if not (s1 <= s2 and s2<= s3): continue
    
    for s1_factor in factorize(s1, H, W, mem):
      res = is_rect_in_HW(H, W, s1_factor, s2, mem)
      if len(res) == 0: continue
      for tmp_s in res:
        res = is_rect_in_HW(H, W, sorted(tmp_s), s3, mem)
        #print(del_s, tmp_s, s1, s2, s3, res)
        if len(res) == 0: continue
        else:
          print(del_s)
          exit()

### FIXED CODE ###

from math import floor, ceil

H,W = map(int,input().split())
ans = float('inf')

if H%3==0 or W%3==0:
  print(0)
  exit()

for x in range(1,H):
  S = [W*x, (H-x)*floor(W/2), (H-x)*ceil(W/2)]
  ans = min(ans, max(S)-min(S))

for x in range(1,W):
  S = [H*x, (W-x)*floor(H/2), (W-x)*ceil(H/2)]
  ans = min(ans, max(S)-min(S))

print(min(ans,H,W))
### BUGGY CODE ###

n=int(input())

v=list(map(int,input().split()))

count=0

a=[v[i] for i in range(0,n,2)] 
b=max(a,key=lambda x:a.count(x))
c=[v[i] for i in range(1,n,2)] 
d=max(c,key=lambda x:c.count(x))

if a == c:
    print(min(len(a),len(c)))
    exit()

for i in a:
    if i != b:
        count +=1

for j in c:
    if j != d:
        count +=1
        

print(count)


### FIXED CODE ###

import collections
n=int(input())
v=list(input().split())
ans=0

even=[v[i] for i in range(n) if i%2 == 0]
odd=[v[i] for i in range(n) if i%2 == 1]

ep=collections.Counter(even).most_common()
op=collections.Counter(odd).most_common()
ep.append((0,0))
op.append((0,0))

if ep[0] != op[0]:
    ans=n-(ep[0][1]+op[0][1])
else:
    if len(even)-ep[1][1]<len(odd)-op[1][1]:
        ans=n-ep[1][1]-op[0][1]
    else:
        ans=n-ep[0][1]-op[1][1]
print(ans)
### BUGGY CODE ###

from collections import deque

h, w = map(int, input().split())
a = [input() for _ in range(h)]

q = deque()
done = set()
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            q.append((i, j, 0))
            done.add((i, j))

while q:
    # print(q)
    i, j, k = q.popleft()
    if i > 0 and (i - 1, j) not in done:
        q.append((i - 1, j, k + 1))
        done.add((i - 1, j))
    if i < h - 1 and (i + 1, j) not in done:
        q.append((i + 1, j, k + 1))
        done.add((i + 1, j))
    if j > 0 and (i, j - 1) not in done:
        q.append((i, j - 1, k + 1))
        done.add((i, j - 1))
    if j < w - 1 and (i, j + 1) not in done:
        q.append((i, j + 1, k + 1))
        done.add((i, j + 1))

print(k)


### FIXED CODE ###

import numpy as np
from scipy.ndimage.morphology import distance_transform_cdt

h, w = map(int, input().split())
a = [input() for _ in range(h)]

a = np.array([[(ai[j] != "#") for j in range(w)] for ai in a])
d = distance_transform_cdt(a, metric="taxicab").max()
print(d)
### BUGGY CODE ###

def isok(A_, F_, N_, K_, x):
  _K_ = 0
  for i in range(N_):
    a_ = A_[i]-x//F_[i]
    if a_ > 0:
      _K_ += a_
  if _K_ > K_:
  	return False
  else:
    return True

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse = True)
ok = 10**12
ng = 0
while abs(ok-ng)>1:
  mid_x = (ok+ng)//2
  if isok(A, F, N, K, mid_x):
    ok = mid_x
  else:
    ng = mid_x
if isok(A, F, N, K, ng):
  print(ng)
else:
  print(ok)

### FIXED CODE ###

def isok(A_, F_, N_, K_, x):
  _K_ = 0
  for i in range(N_):
    a_ = A_[i]-x//F_[i]
    if a_ > 0:
      _K_ += a_
  if _K_ > K_:
  	return False
  else:
    return True

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse = True)
ok = 10**12
ng = 0
while abs(ok-ng)>1:
  mid_x = (ok+ng)//2
  if isok(A, F, N, K, mid_x):
    ok = mid_x
  else:
    ng = mid_x
if isok(A, F, N, K, ng):
  print(ng)
else:
  print(ok)