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

import sys
input = sys.stdin.readline
import heapq as hp

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

A.sort()
l = -1
r = max(A)*max(F)+1
while r-l > 1:
    m = (r+l)//2
    q = []
    for f in F:
        hp.heappush(q, m//f)
    cost = 0
    for a in A:
        f = hp.heappop(q)
        cost += max(0, a-f)
    if cost <= K:
        r = m
    else:
        l = m

print(r)

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

    F.sort(reverse=True)
    A.sort()
    l = -1
    r = 0
    for i in range(N):
        if A[i]*F[i] > r:
            r = A[i]*F[i]
    r += 1
    while r-l > 1:
        m = (r+l)//2
        q = []
        cost = 0
        for i in range(N):
            if F[i]*A[i] > m:
                cost += (F[i]*A[i]-m)//F[i]
                if (F[i]*A[i]-m)%F[i] != 0:
                    cost += 1
        if cost <= K:
            r = m
        else:
            l = m

    print(r)


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

n, p = map(int, input().split())
s = input()

def nC2(n):
    if n == 0:
        return 0
    return n*(n-1)//2

if p != 2 and p != 5:
    u = []
    for i in range(n):
        u.append(int(s[i:])%p)
    onaji = {}
    for i in u:
        if not i in onaji:
            onaji[i] = 1
        else:
            onaji[i] += 1
    ans = 0
    for key, r in onaji.items():
        ans += nC2(r)
        if key == 0:
            ans += r
    print(ans)

elif p == 2:
    ans = 0
    for i in range(n):
        if int(s[i]) in [0,2,4,6,8]:
            ans += i+1
    print(ans)

else:
    ans = 0
    for i in range(n):
        if int(s[i]) in [0,5]:
            ans += i+1
    print(ans)


### FIXED CODE ###

n, p = map(int, input().split())
s = input()

def nC2(n):
    if n == 0:
        return 0
    return n*(n-1)//2

p_joyo = [] # 10^m % p は p_joyo[m]に対応
r = 1
for i in range(n):
    p_joyo.append(r)
    r = r*10 % p

if p != 2 and p != 5:
    u = []
    r = int(s[n-1])%p
    for i in range(1,n):
        u.append(r)
        j = n-i-1
        r = (r + int(s[j])*p_joyo[i])%p
    u.append(r)
    onaji = {}
    for i in u:
        if not i in onaji:
            onaji[i] = 1
        else:
            onaji[i] += 1
    ans = 0
    for key, r in onaji.items():
        ans += nC2(r)
        if key == 0:
            ans += r
    print(ans)

elif p == 2:
    ans = 0
    for i in range(n):
        if int(s[i]) in [0,2,4,6,8]:
            ans += i+1
    print(ans)

else:
    ans = 0
    for i in range(n):
        if int(s[i]) in [0,5]:
            ans += i+1
    print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
import bisect

N,Q = map(int,input().split())
# STX = [list(map(int,input().split())) for _ in range (N)]
STX = []
vals = set()
for _ in range(N):
    s,t,x = map(int,input().split())
    STX.append([max(0,s-x), max(0,t-x), x])
    vals.add(max(0,s-x))
    vals.add(max(0,t-x))
D = [int(input()) for _ in range(Q)]
for d in D:
    vals.add(d)
vals = list(vals)
vals.sort()
L = len(vals)
mapping = [-1]*(L+1)
imos = [[] for _ in range(L+1)]
STX.sort(key=lambda x:x[2])
priority = 0 
for s,t,x in STX:
    s1 = bisect.bisect_left(vals, s)
    t1 = bisect.bisect_left(vals, t)
    imos[s1].append([1, priority, x])
    imos[t1].append([0, priority, x])
    priority += 1

import heapq
cur = -1
cur_priority = 10**9
que = [[cur_priority, cur]]
valid_priority = [True]*(N+1)
for i in range(L+1):
    for f,p,x in  imos[i]:
        if f:
            heapq.heappush(que, [p, x])
        else:
            valid_priority[p] = False
    idx = 0
    while que[idx][0]!=10**9 and valid_priority[que[idx][0]]==False:
        heapq.heappop(que)
    mapping[i] = que[0][1]



        
for d in D:
    d1 = bisect.bisect_left(vals, d)
    print(mapping[d1])



### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
import bisect

N,Q = map(int,input().split())
# STX = [list(map(int,input().split())) for _ in range (N)]
STX = []
vals = set()
for _ in range(N):
    s,t,x = map(int,input().split())
    STX.append((max(0,s-x), max(0,t-x), x))
    vals.add(max(0,s-x))
    vals.add(max(0,t-x))
D = [int(input()) for _ in range(Q)]
for d in D:
    vals.add(d)
vals = list(vals)
vals.sort()
L = len(vals)
mapping = [-1]*(L+1)
imos = [[] for _ in range(L+1)]
STX.sort(key=lambda x:x[2])
priority = 0 
for s,t,x in STX:
    s1 = bisect.bisect_left(vals, s)
    t1 = bisect.bisect_left(vals, t)
    imos[s1].append([1, priority, x])
    imos[t1].append([0, priority, x])
    priority += 1

import heapq
cur = -1
cur_priority = 10**9
que = [(cur_priority, cur)]
valid_priority = [True]*(N+1)
for i in range(L+1):
    for f,p,x in  imos[i]:
        if f:
            heapq.heappush(que, (p, x))
        else:
            valid_priority[p] = False
    
    while que[0][1]!=-1 and valid_priority[que[0][0]]==False:
        heapq.heappop(que)
    mapping[i] = que[0][1]

for d in D:
    d1 = bisect.bisect_left(vals, d)
    print(mapping[d1])
### BUGGY CODE ###

from fractions import gcd
class SegmentTree(object):
    def __init__(self, sequence, function, identity):
        N = len(sequence)
        self.length = (1 << (N - 1)).bit_length()
        self.data = [identity] * (self.length << 1)
        self.function = function
        self.identity = identity
        for i in range(N):
            self.data[i + self.length - 1] = sequence[i]
        for i in range(self.length - 2, -1, -1) :
            self.data[i] = self.function(self.data[(i << 1) + 1], self.data[(i << 1) + 2])

    def update(self, idx, x):
        idx += self.length - 1
        self.data[idx] = x
        while idx:
            idx = (idx - 1) >> 1
            self.data[idx] = self.function(self.data[(idx << 1) + 1], self.data[(idx << 1) + 2])

    def query(self, p, q):
        if q <= p:
            return self.identity
        p += self.length - 1
        q += self.length - 2
        res = self.identity
        while q - p > 1:
            if not p & 1:
                res = self.function(res, self.data[p])
            if q & 1:
                res = self.function(res, self.data[q])
                q -= 1
            p >>= 1
            q = (q - 1) >> 1
        return self.function(res, self.data[p]) if p == q else self.function(self.function(res, self.data[p]), self.data[q])

N, *A = map(int, open(0).read().split())
seg_tree = SegmentTree(A, gcd, 0)
ans = 0
for i in range(N):
    seg_tree.update(i, 0)
    ans = max(ans, seg_tree.query(0, N))
    seg_tree.update(i, A[i])
print(ans)

### FIXED CODE ###

from fractions import gcd

n = int(input())
list_ = list(map(int, input().strip().split()))

gcd_from_left = [0]
gcd_from_right = [0]
for i in range(n):
    gcd_from_left.append(gcd(gcd_from_left[i], list_[i]))
    gcd_from_right.append(gcd(gcd_from_right[i], list_[-(i + 1)]))

gcd_from_left.insert(0, 0)
gcd_from_right.insert(0, 0)
gcd_from_right.reverse()

print(max(gcd(gcd_from_left[i], gcd_from_right[i]) for i in range(n + 2)))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
q = int(input())
oper = [list(map(int, input().split())) for _ in range(q)]
a.sort()
res = sum(a)

for i in range(q):
    b, c = oper[i]
    if b in a:
        bCount = a.count(b)
        idx = a.index(b)

        a = a[:idx] + a[idx+bCount:]
        a.extend([c]*bCount)
        dif = c-b

        res += dif*bCount

    print(res)

### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
q = int(input())
oper = [list(map(int, input().split())) for _ in range(q)]
dic = {}
for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1
        
res = sum(a)

for i in range(q):
    b, c = oper[i]
    if b in dic:
        bCount = dic[b]
        del(dic[b])
        if c in dic:
            dic[c] += bCount
        else:
            dic[c] = bCount

        dif = c-b

        res += dif*bCount

    print(res)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()

	A.sort()
	A = A[::-1]
	ans = 0
	maxs = 0
	cnt = 0

	ansans = []
	pgt = Queue()
	for i,val in enumerate(A):
		if i == 0:
			pgt.enqueue(val)
		else:
			tmp = pgt.dequeue()
			ansans.append(tmp)

			pgt.enqueue(val)

			if tmp == val:
				pass
			else:
				pgt.enqueue(val)

	print(sum(ansans))


class Queue:
    def __init__(self, queue = None):
        if type(queue) is type([]):
            self.queue = queue
        else:
            self.queue = []

    def enqueue(self, e):
        self.queue.append(e)
        return self.queue

    def dequeue(self):
        try:
            qEl = self.queue[0]
            del self.queue[0]
            return qEl
        except IndexError:
            return None

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from collections import deque
from decimal import *
import queue

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()

	A.sort()
	A = A[::-1]
	ans = 0
	maxs = 0
	cnt = 0
	fst = True

	ansans = []
	pgt = queue.Queue()
	for i,val in enumerate(A):
		if i == 0:
			pgt.put(val)
		else:
			tmp = pgt.get()
			ansans.append(tmp)

			pgt.put(val)

			if tmp == val:
				pgt.put(val)
			else:
				pgt.put(val)

	#print(ansans)
	print(sum(ansans))


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

s=input()
q=int(input())
flg=True
for _ in range(q):
    t=list(input().split())
    if t[0]=='1':
        flg=not flg
    else:
        if t[1]=='1':
            if flg:
                s=t[2]+s
            else:
                s=s+t[2]
        else:
            if flg:
                s=s+t[2]
            else:
                s=t[2]+s
if flg:
    print(s)
else:
    print(s[::-1])

### FIXED CODE ###

from collections import deque
s=input()
q=int(input())
flg=True
s1=deque()
s2=deque()
for _ in range(q):
    t=list(input().split())
    if t[0]=='1':
        flg=not flg
    else:
        if t[1]=='1':
            if flg:
                s1.appendleft(t[2])
            else:
                s2.append(t[2])
        else:
            if flg:
                s2.append(t[2])
            else:
                s1.appendleft(t[2])
if flg:
    print(''.join(s1)+s+''.join(s2))
else:
    print(''.join(s2)[::-1]+s[::-1]+''.join(s1)[::-1])
### BUGGY CODE ###

h,n=map(int,input().split())
dp=[10**9]*(h+1)
dp[0]=0
for i in range(n):
    a,b=map(int,input().split())
    for j in range(h):
        k=min(j+a,h)
        dp[k]=min(dp[k],dp[j]+b)
print(dp[h])
#写経ABC153E

### FIXED CODE ###

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

Q,s = [],[]
flag = 0
while(flag==0):
  c = input()
  if c == "end":
    break
  elif c == "extract":
    print(Q.pop(0))
  else:
    s = c.split()
    Q.append(int(s[1]))
    Q.sort(reverse = True)
  


### FIXED CODE ###

import heapq
Q,s = [],[]
flag = 0
while(flag==0):
  c = input()
  if c == "end":
    break
  elif c == "extract":
    print(heapq.heappop(Q) * (-1))
  else:
    s = c.split()
    heapq.heappush(Q, int(s[1])*(-1))
### BUGGY CODE ###

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

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

C = [0] * M
if N == 1:
    for i in range(M):
        A[0] = A[0] // 2
    print(A[0])
    exit(0)

while(M > 0):
    A.sort(reverse=True)
    A[0] = A[0] // 2
    M -= 1
print(sum(A))


### FIXED CODE ###

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

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

hq = []

for i in range(N):
    heapq.heappush(hq, -(A[i]))


while(M):
    k = heapq.heappop(hq) * -1
    k = k // 2
    heapq.heappush(hq, -k)
    M -= 1
ans = 0
for i in range(N):
    ans += heapq.heappop(hq)

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

#!/usr/bin/env python3
import sys
from collections import Counter
MOD = 1000000007  # type: int


def eratosthenes_sieve(n):
    table = [0] * (n + 1)
    prime_list = []

    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1

    return prime_list


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

    primes = eratosthenes_sieve(10**3)

    def factorial(n):
        # 試し割りによる素因数分解
        prime_count = Counter()
        for i in primes:
            while n % i == 0:
                n /= i
                prime_count[i] += 1
        if n > 1:
            prime_count[int(n)] += 1
        return prime_count

    C = [factorial(a) for a in A]

    K = Counter()
    for c in C:
        for k in c:
            K[k] = max(K[k], c[k])

    B = [0]*N
    for i in range(N):
        b = Counter()
        for k in K:
            b[k] = K[k] - C[i][k]
        a = 1
        for k in b:
            if b[k] != 0:
                a *= k**b[k]
                a %= MOD
        B[i] = a
    print(sum(B) % MOD)

    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
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import Counter
import math
MOD = 1000000007  # type: int


def factorial(n):
    prime_count = Counter()

    for i in range(2, int(math.sqrt(n)) + 2):
        while n % i == 0:
            n /= i
            prime_count[i] += 1
    if n > 1:
        prime_count[int(n)] += 1

    return prime_count


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % MOD
    elif y % 2 == 0:
        return power(x, y//2)**2 % MOD
    else:
        return power(x, y//2)**2 * x % MOD


def div(a, b):
    return (a * power(b, MOD-2)) % MOD


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

    lcm = Counter()
    for a in A:
        c = factorial(a)
        for k in c:
            lcm[k] = max(c[k], lcm[k])
    # print(lcm)

    LCM = 1
    for k, v in lcm.items():
        LCM *= power(k, v)
        LCM %= MOD
    # print(LCM)

    tot = 0
    for a in A:
        tot += div(LCM, a)
    print(tot % MOD)

    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
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


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

n, k, q = list(map(int, input().split()))
b = []

for _ in range(n):
    b.append(k)

for i in range(q):
    a = int(input())
    b[a-1] += 1
    b = list(map(lambda x: x-1, b))

while len(b) > 0:
    if b[0] > 0:
        print('Yes')
    else:
        print('No')
    del b[0]

### FIXED CODE ###

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

b = [k]*n

for i in range(q):
    a = int(input())
    b[a-1] += 1

b = list(map(lambda x: x-q, b))

for i in range(len(b)):
    if b[i] > 0:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

N = int(input())
S = input()

ans = 0

for i in range(1000):
    t = str(i).zfill(3)
    ti = 0
    for si in range(N):
        if t[ti] == S[si]:
            ti += 1
            if ti == 3:
                break
    if ti == 3:
        ans += 1

print(ans)

### FIXED CODE ###

N = int(input())
S = input()

ans = 0

for i in range(10):
    a = S.find(str(i))
    if -1 == a:
        continue
    for j in range(10):
        b = S.find(str(j), a + 1)
        if -1 == b:
            continue
        for k in range(10):
            c = S.find(str(k), b + 1)
            if -1 == c:
                continue
            ans += 1
            # print(''.join(map(str, [i, j, k])))

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

#C-Poll
import collections
n=int(input())
words = [input() for _ in range(n)]
count = collections.Counter(words)
leng = len(count)
ansallay = []
#抽出用に何回出てればansに出すかを変数に突っ込む
record = count.most_common()[0][1]
for num in range(leng):
    if(count.most_common()[num][1] == record):
        ansallay.append(count.most_common()[num][0])
    else:
        break
ansallay.sort()
for word in ansallay:
    print(word)

### FIXED CODE ###

#C-Poll
import collections
n=int(input())
words = [input() for _ in range(n)]
count = collections.Counter(words)
leng = len(count)
ansallay = []
#抽出用に何回出てればansに出すかを変数に突っ込む
record = count.most_common()[0][1]
ms=count.most_common()
for num in range(leng):
    if(ms[num][1] == record):
        ansallay.append(ms[num][0])
    else:
        break
ansallay.sort()
for word in ansallay:
    print(word)
### BUGGY CODE ###

n = int(input())
l = [input() for i in range(n)]

from collections import Counter
ans = 0
for i in range(n):
  for j in range((i+1),n):
    if Counter(l[i]) == Counter(l[j]):
      ans += 1
print(ans)

### FIXED CODE ###

N=int(input())
l=[]
from collections import Counter
for i in range(N):
  l.append(''.join(sorted(input())))
l1=Counter(l).values()
from math import factorial
ans=0
for a in l1:
  if a >= 2:
    ans+=int(factorial(a)/(factorial(a-2)*factorial(2)))
print(ans)
### BUGGY CODE ###

s = input()
Q = int(input())

cnt = 0
for i in range(Q):
    q = input().split()
    if q[0] == '1':
        cnt += 1
    else:
        reverse = cnt % 2
        if q[1] == '1':
            if reverse == 0:
                s = q[2] + s
            else:
                s = s + q[2]
        else:
            if reverse == 0:
                s = s + q[2]
            else:
                s = q[2] + s

if cnt % 2 == 0:
    print(s)
else:
    print(s[::-1])

### FIXED CODE ###

from collections import deque
s = input()
Q = int(input())
que = deque(s)
cnt = 0
for i in range(Q):
    q = input().split()
    if q[0] == '1':
        cnt += 1
    else:
        reverse = cnt % 2
        if q[1] == '1':
            if reverse == 0:
                s = que.appendleft(q[2])
            else:
                s = que.append(q[2])
        else:
            if reverse == 0:
                s = que.append(q[2])
            else:
                s = que.appendleft(q[2])

ans = ''.join(que)
if cnt % 2 == 0:
    print(ans)
else:
    print(ans[::-1])
### BUGGY CODE ###

n = int(input())
s = input()
r = []
g = []
b = []
for i in range(n):
	if s[i] == "R":
		r.append(i)
	elif s[i] == "G":
		g.append(i)
	else:
		b.append(i)
count = 0
x = []
y = []
z = []
for i in [r,g,b]:
	if len(i) == min([len(r),len(g),len(b)]) and x == []:
		x = i
	elif len(i) == max([len(r),len(g),len(b)]) and z == []:
		z = i
	else:
		y = i
for i in x:
	for j in y:
		u = abs(i-j)
		count += [0,1][(max(i,j)+u) in z] + [0,1][(min(i,j)-u) in z] + [0,1][u%2 == 0 and (i+j)//2 in z]
print(len(r)*len(g)*len(b)-count)

### FIXED CODE ###

from collections import Counter
# これは, u749194f さんの改造です。
# オリジナルではございません。
# https://atcoder.jp/contests/abc162/submissions/11825963
n = int(input())
s = input()
flag = True
if len(set(s))<=2:
    print(0)
    flag = False
if flag:
    r = [i+1 for i in range(n) if s[i]=='R']
    b = [i+1 for i in range(n) if s[i]=='B']
    g = [i+1 for i in range(n) if s[i]=='G']
    minus = 0
    def cnt_cmb(a, b, c):
        cnt = 0
        set_c = set(c)
        for i in a:
            for j in b:
                if (i+j)/2 in set_c:
                    cnt += 1
        return cnt
    minus += cnt_cmb(r, b, g)
    minus += cnt_cmb(b, g, r)
    minus += cnt_cmb(g, r, b)
    a = Counter(s)
    rslt = 1
    for value in a.values():
        rslt *= value
    print(len(r)*len(b)*len(g)-minus)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
h, w = [int(x) for x in input().strip().split()]
g = [[x for x in list(input().strip())] for _ in range(h)]

ans = -1
q = []
for i in range(h):
    for j in range(w):
        if g[i][j] == '#':
            q.append((i, j))
vec = [(0, 1), (1, 0), (0, -1), (-1, 0)]
while q:
    q_ = q[:]
    q = []
    ans += 1
    while q_:
        i, j = q_.pop()
        for x, y in vec:
            ti, tj = i+x, j+y
            if 0 <= ti < h and 0 <= tj < w:
                if g[ti][tj] == '.':
                    g[ti][tj] = '#'
                    q.append((ti, tj))
print(ans)

### FIXED CODE ###

import sys
from collections import deque
input = sys.stdin.readline
h, w = [int(x) for x in input().strip().split()]
g = [[x for x in list(input().strip())] for _ in range(h)]

ans = -1
q = []
for i in range(h):
    for j in range(w):
        if g[i][j] == '#':
            q.append((i, j))
vec = [(0, 1), (1, 0), (0, -1), (-1, 0)]
while q:
    q_ = deque(q)
    q = deque([])
    ans += 1
    while q_:
        i, j = q_.pop()
        for x, y in vec:
            ti, tj = i+x, j+y
            if 0 <= ti < h and 0 <= tj < w:
                if g[ti][tj] == '.':
                    g[ti][tj] = '#'
                    q.append((ti, tj))
print(ans)
### BUGGY CODE ###

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

ans=0
for i in range(0,n):
  for j in range(i+1,n):
    flag=True
    for k in range(10):
      if ss[i].count(ss[i][k])!=ss[j].count(ss[i][k]):
        flag=False
    if flag:
      ans+=1
print(ans)

### FIXED CODE ###

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

samedic={}
for s in ss:
  sort_s=''.join(sorted(list(s)))
  if sort_s in samedic:
    samedic[sort_s]+=1
  else:
    samedic[sort_s]=1

ans=0
for v in samedic.values():
  ans+=((v-1)*1)*(v/2)
print(int(ans))
### BUGGY CODE ###


n = int(input())

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

#mid = n//2 + n%2

ans = [0]*n
for i, a in enumerate(an[::-1]):

    ta = [x for ii,x in enumerate(an) if i % (n-ii) == 0]
    t = sum(ta)
#    print(ta,t,i,a)
    ans[-i] = t%2

m = sum(ans)
print(m)

if m > 0:
    print(*[x for x in ans if x >0])

### FIXED CODE ###


n = int(input())

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

#mid = n//2 + n%2

#print(* range(10)[::2] )

ans = [0]*(n+1)

for _ in range(n):# 0 ... n-1
    i = n-_ # n ... 1

    ta = sum(ans[i::i])
    ans[i] = 0 if ta%2 == an[i-1] else 1

#    print(i, an[i-1::i])


m = sum(ans)
print(m)

if m > 0:
    print(*[i for i, x in enumerate(ans) if x >0])
### BUGGY CODE ###

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

mini = float('inf')

for i in range(N):
    if abs(sum(A[0:i]) - sum(A[i:N])) < mini:
        mini = abs(sum(A[0:i]) - sum(A[i:N]))

print(mini)


### FIXED CODE ###

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

mini = float('inf')

cumsum = list(itertools.accumulate(A))
A.reverse()
rev = list(itertools.accumulate(A))
rev.reverse()
cumsum.pop()
rev.pop(0)

for i, j in zip(cumsum,rev):
    if abs(i-j) < mini:
        mini = abs(i-j)

print(mini)