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

import numpy as np
N=int(input())
L=np.array(list(map(int,input().split())))
L.sort()
#print(L)

#b-a < c < a+b
#a<=b<=c
ans=0
L_a=L[:N-2]
for i,a in enumerate(L_a):
    L_b=L[i+1:N-1]
    for j,b in enumerate(L_b,start=i+1):
        ans+=sum((b-a < L[j+1:]) & (L[j+1:] < a+b))
        
print(ans)

### FIXED CODE ###

import bisect
import collections
N=int(input())
L=list(map(int,input().split()))
L.sort()
c = collections.Counter(L)
#print(L)
 
#b-a < c < a+b

#a<=b<=c
ans=0
L_a=L[:N-2]
for i,a in enumerate(L_a):
    L_b=L[i+1:N-1]
    for j,b in enumerate(L_b,start=i+1):
        x=bisect.bisect(L[j+1:],a+b)
        ans+=x
        if a+b==L[j+x]:
            #print(a,b,L[j+x])
            ans-=c[a+b]
        #print(i,a,j,b,x,N-j-1,L[j+1:])
print(ans)
### BUGGY CODE ###

from itertools import product

X, Y, Z, K = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))
lst_A.reverse()
lst_B.reverse()
lst_C.reverse()
lst_C_K = lst_C[:K]


lst_AB = sorted([a+b for a, b in product(lst_A, lst_B)], reverse=True)
lst_AB_K = lst_AB[:K]

lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C_K)], reverse=True)
lst_ABC_K = lst_ABC[:K]

for i in range(K):
    print(lst_ABC_K[i])


### FIXED CODE ###

import sys
from itertools import product


X, Y, Z, K = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))
lst_A.sort(reverse=True)
lst_B.sort(reverse=True)
lst_C.sort(reverse=True)

# lst_A_K = lst_A[:K]
# lst_B_K = lst_B[:K]
lst_C_K = lst_C[:K]


lst_AB = sorted([a+b for a, b in product(lst_A, lst_B)], reverse=True)
lst_AB_K = lst_AB[:K]

lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C_K)], reverse=True)
lst_ABC_K = lst_ABC[:K]

print(*lst_ABC_K, sep="\n")
### BUGGY CODE ###

n,m=map(int,input().split())
lst=[[] for i in range(n+1)]
prev=[]

for i in range(m):
  x,y=map(int,input().split())
  lst[x].append(y)
  prev.append([x,y])
  
for i in lst:
  i.sort()
  
for i in prev:
  s,t=i[0],i[1]
  for j,v in enumerate(lst[s]):
    if v==t:
      x=j+1
  
  s,x=str(s),str(x)
  
  while len(s)<6:
    s='0'+s

  while len(x)<6:
    x='0'+x

  print(s+x)

### FIXED CODE ###

import bisect

n,m=map(int,input().split())

x=[list(map(int,input().split())) for i in range(m)]

lst=[[] for i in range(n)]

for i,v in x:
    lst[i-1].append(v)

for i in range(n):
    lst[i].sort()

for i,v in x:
    z=bisect.bisect_left(lst[i-1],v)+1

    print('0'*(6-len(str(i)))+str(i)+'0'*(6-len(str(z)))+str(z))
### BUGGY CODE ###

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

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

ans=[0]*N

ans[N-2]=abs(arr[-2]-arr[-1])

for i in range(N-3,-1,-1):
	minn=100000000000000
	for j in range(min(K,N-i-1)):
		minn = min(minn,abs(arr[i]-arr[i+j+1])+ans[i+j+1])
	ans[i]=minn

print(ans[0])

### FIXED CODE ###

import sys
import math
input = sys.stdin.readline

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

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

ans=[0]*N

ans[N-2]=abs(arr[-2]-arr[-1])

for i in range(N-3,-1,-1):
	minn=100000000000000
	for j in range(min(K,N-i-1)):
		minn = min(minn,abs(arr[i]-arr[i+j+1])+ans[i+j+1])
	ans[i]=minn

print(ans[0])
### BUGGY CODE ###

import math
x = int(input())

for s in range(1, int(math.sqrt(x))+1):
    if x % s == 0:
        t = x // s
        #print(s, t)
        for b in range(-100000, 100000):
            if (b+s)**5 - b**5 == x:
                print(b+s, b)
                break
            elif (b+t)**5 - b**5 == x:
                print(b+t, b)
                break


### FIXED CODE ###

import math
import sys
x = int(input())

for s in range(1, int(math.sqrt(x))+1):
    if x % s == 0:
        t = x // s
        #print(s, t)
        for b in range(-1000, 1000):
            if (b+s)**5 - b**5 == x:
                print(b+s, b)
                sys.exit(0)
            elif (b+t)**5 - b**5 == x:
                print(b+t, b)
                sys.exit(0)
### BUGGY CODE ###

from collections import deque
import heapq
# 入力、初期化
N = int(input())
tree = [[] for _ in range(N)]
input_list = []
for _ in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    input_list.append([a, b])
    tree[a].append(b)
    tree[b].append(a)


# visitedにノードの色を格納する
visited_edge = [[0] * N for _ in range(N)]


# bfsによる色付けを行う
def bfs(now_node):
    queue = deque([[tree[now_node], 0, now_node]])
    while queue:
        next_nodes, before_color, now_node = queue.pop()
        now_color = 1
        for next_node in next_nodes:
            if visited_edge[now_node][next_node] != 0:
                continue
            if now_color == before_color:
                now_color += 1
            visited_edge[next_node][now_node] = now_color
            visited_edge[now_node][next_node] = now_color
            queue.appendleft([tree[next_node], now_color, next_node])
            now_color += 1


bfs(0)
ans = []
for a, b in input_list:
    ans.append(visited_edge[a][b])
max_val = 0
for row in visited_edge:
    row = list(map(lambda x: -1 * x, row))
    heapq.heapify(row)
    tmp_max = heapq.heappop(row) * (-1)
    if tmp_max > max_val:
        max_val = tmp_max
print(max_val)
print(*ans, sep="\n")

### FIXED CODE ###

from collections import deque
# 入力、初期化
N = int(input())
tree = [[] for _ in range(N)]
input_list = []
for _ in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    input_list.append([a, b])
    tree[a].append(b)
    tree[b].append(a)


# visitedにノードの色を格納する
# visited_edge = [[0] * N for _ in range(N)]
dict = {}
'''
# bfsによる色付けを行う
def bfs(now_node, max_val=0):
    queue = deque([[tree[now_node], -1, now_node]])
    while queue:
        next_nodes, before_color, now_node = queue.pop()
        now_color = 1
        for next_node in next_nodes:
            if visited_edge[now_node][next_node] != 0:
                continue
            if now_color == before_color:
                now_color += 1
            if max_val < now_color:
                max_val = now_color
            visited_edge[next_node][now_node] = now_color
            visited_edge[now_node][next_node] = now_color
            queue.appendleft([tree[next_node], now_color, next_node])
            now_color += 1
    return max_val
'''
def bfs(now_node, max_val=0):
    queue = deque([[tree[now_node], -1, now_node]])
    while queue:
        next_nodes, before_color, now_node = queue.pop()
        now_color = 1
        for next_node in next_nodes:
            key = tuple(sorted([now_node, next_node]))
            if not dict.get(key) is None:
                continue
            if now_color == before_color:
                now_color += 1
            if max_val < now_color:
                max_val = now_color
            dict[key] = now_color
            # visited_edge[now_node][next_node] = now_color
            queue.appendleft([tree[next_node], now_color, next_node])
            now_color += 1
    return max_val

ans = bfs(0)
print(ans)
for a, b in input_list:
    # print(visited_edge[a][b])
    print(dict[tuple(sorted([a,b]))])
### BUGGY CODE ###

N, Q = list(map(int, input().split()))
S = input()
li = [list(map(int, input().split())) for i in range(Q)]
t = [0] * N

for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        t[i] = 1

for i in range(Q):
    kazu = t[li[i][0] - 1 : li[i][1] -1]
    print(kazu.count(1))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
	t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
	l, r = map(int, input().split())
	print(t[r-1] - t[l-1])
### BUGGY CODE ###

X,Y=map(int,input().split())
for i in range(X+1,Y+1):
    X = X ^ i
print(X)

### FIXED CODE ###

X,Y=map(int,input().split())
if X % 2 ==0:
    if (Y-X) % 4 == 0:
        print(0^Y)
    elif (Y-X) % 4 == 1:
        print(1)
    elif (Y-X) % 4 == 2:
        print(1^Y)
    elif (Y-X) % 4 == 3:
        print(0)
elif X % 2 ==1:
    if (Y-X) % 4 == 0:
        print(X^0)
    elif (Y-X) % 4 == 1:
        print(X^Y)
    elif (Y-X) % 4 == 2:
        print(X^1)
    elif (Y-X) % 4 == 3:
        print(X^1^Y)
### BUGGY CODE ###

n,k = map(int,input().split())
lis = list(map(int,input().split()))
num = 0
ans = 0
for i in range(n):num += max(0,lis[i])
li = [0 for i in range(n-k+1)]
for i in range(n-k+1):
  cou = 0
  co = 0
  for nu in lis[i:i+k]:
    if nu >= 0:cou += nu
    else:co -= nu
  if cou >= co:ans = max(ans,num-co)
  else:ans = max(ans,num-cou)
print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
lis = list(map(int,input().split()))
num = 0
ans = 0
cou = 0
co = 0
for i in range(n):num += max(0,lis[i])
li = [0 for i in range(n-k+1)]
for i in range(k-1):
  cou += max(0,lis[i])
  co += max(0,-lis[i])
for i in range(n-k+1):
  cou += max(0,lis[i+k-1])
  co += max(0,-lis[i+k-1])
  if cou >= co:ans = max(ans,num-co)
  else:ans = max(ans,num-cou)
  cou -= max(0,lis[i])
  co -= max(0,-lis[i])
print(ans)
### BUGGY CODE ###

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


if N % 2 == 1:
  if A.count(0) != 1:
    print(0)
  else:
    if not all([A.count(i) == 2 for i in range(2, N, 2)]):
      print(0)
    else:
      print(2 ** ((N - 1) // 2) % (10**9 + 7))
else:
  if not all([A.count(i) == 2 for i in range(1, N, 2)]):
    print(0)
  else:
    print(2 ** ((N // 2) % (10**9 + 7)))


### FIXED CODE ###

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

if N % 2 == 0:
  for i in range(0, N, 2):
    if A[i] != A[i+1]:
      print(0)
      break
  else:
    print(2**(N // 2) % 1000000007)
else:
  if A[0] != 0:
    print(0)
  else:
    for i in range(1, N, 2):
      if A[i] != A[i+1]:
        print(0)
        break
    else:
      print(2**((N-1)//2) % 1000000007)
### BUGGY CODE ###

S = list(input())
ans = 0
num = 0
x = len(S)
sub = []
for i in range(x):
  for j in range(i,x):
    if i == j and S[i] == '0':
      ans += 1
    elif j-i >=  3:
      sub = S[i:j+1]
      num = ''.join(map(str,sub))
      if int(num) % 2019 == 0:
        ans += 1
print(ans)

### FIXED CODE ###

S = list(str(input()))
S.reverse()
mod = 2019
rem = [0]*mod
num = 0
rem[num] += 1
d = 1
ans = 0
for s in S:
  num += int(s) * d
  num %= mod
  d *= 10
  d %= mod
  rem[num] += 1
for r in rem:
  ans += r*(r-1)//2
print(ans)
### BUGGY CODE ###

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

while True:
    A-=1
    K-=1
    if A==0 or K==0:
        break
while True:
    B-=1
    K-=1
    if B==0 or K==0:
        break
print(A,B)


### FIXED CODE ###

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

if A-K>=0:
    A=A-K
elif B-(K-A)>=0:

    B=B-(K-A)
    A=0
else:
    A=0
    B=0
print(A,B)
### BUGGY CODE ###

from collections import deque
h,w = map(int, input().split())
c = tuple(map(int, input().split()))
d = tuple(map(int, input().split()))
m = ['#' for _ in range(h+2)]
m[0] += '#'*(w+1)
m[h+1] += '#'*(w+1)
que = deque()
que.append(c)
INF = 10**7
warp = [[INF for _ in range(w+1)] for _ in range(h+1)]
for i in range(1,h+1):  m[i] += input()+'#'
up = lambda x,y: 1 if 0<x-1 and m[x-1][y]=='.' else 0
down = lambda x,y: 1 if x+1<=h and m[x+1][y]=='.' else 0
right = lambda x,y: 1 if y+1<=w and m[x][y+1]=='.' else 0
left = lambda x,y: 1 if 0<y-1 and m[x][y-1]=='.' else 0

def jump(x,y,cost):
  deq = deque()
  for i in range(x-2,x+3):
    if i<=0 or h<i:  continue
    for j in range(y-2,y+3):
      if j<=0 or w<j:  continue
      if m[i][j] == '.' and warp[i][j]>cost+1:
        warp[i][j] = cost+1
        if (i,j) not in que:
          deq.append((i,j))
  return deq
  
warp[c[0]][c[1]] = 0
while que:
  q = que.popleft()
  row,col = q[0],q[1]
  cost = warp[row][col]
  if up(row,col) and warp[row-1][col]>cost:
    que.appendleft((row-1,col))
    warp[row-1][col] = cost
  if down(row,col) and warp[row+1][col]>cost:
    que.appendleft((row+1,col))
    warp[row+1][col] = cost
  if right(row,col) and warp[row][col+1]>cost:
    que.appendleft((row,col+1))
    warp[row][col+1] = cost
  if left(row,col) and warp[row][col-1]>cost:
    que.appendleft((row,col-1))
    warp[row][col-1] = cost
  que.extend(jump(row,col,cost))
if warp[d[0]][d[1]] != INF: print(warp[d[0]][d[1]])
else: print(-1)

### FIXED CODE ###

from collections import deque
h,w = map(int, input().split())
c = tuple(map(int, input().split()))
d = tuple(map(int, input().split()))
m = ['#' for _ in range(h+2)]
m[0] += '#'*w
m[h+1] += '#'*w
que = deque()
que.append(c)
warp = [[10**6 for _ in range(w+1)] for _ in range(h+1)]
for i in range(1,h+1):  m[i] += input()+'#'
up = lambda x,y: 1 if 0<x-1 and m[x-1][y]=='.' else 0
down = lambda x,y: 1 if x+1<=h and m[x+1][y]=='.' else 0
right = lambda x,y: 1 if y+1<=w and m[x][y+1]=='.' else 0
left = lambda x,y: 1 if 0<y-1 and m[x][y-1]=='.' else 0

def jump(x,y,cost):
  deq = deque()
  for i in range(x-2,x+3):
    if i<=0 or h<i:  continue
    for j in range(y-2,y+3):
      if j<=0 or w<j:  continue
      if m[i][j] == '.' and warp[i][j]>cost+1:
        warp[i][j] = cost+1
        deq.append((i,j))
  return deq
  
warp[c[0]][c[1]] = 0
while que:
  q = que.popleft()
  row = q[0]
  col = q[1]
  cost = warp[row][col]
  if up(row,col) and warp[row-1][col]>cost:
    que.appendleft((row-1,col))
    warp[row-1][col] = cost
  if down(row,col) and warp[row+1][col]>cost:
    que.appendleft((row+1,col))
    warp[row+1][col] = cost
  if right(row,col) and warp[row][col+1]>cost:
    que.appendleft((row,col+1))
    warp[row][col+1] = cost
  if left(row,col) and warp[row][col-1]>cost:
    que.appendleft((row,col-1))
    warp[row][col-1] = cost
  que.extend(jump(row,col,cost))

if warp[d[0]][d[1]] != 10**6:  print(warp[d[0]][d[1]])
else:  print(-1)
### BUGGY CODE ###

import math
H, W, A, B = map(int, input().split())
MOD = 10 ** 9 + 7


def f(h, w):

    return math.factorial(h+w-2) // (math.factorial(h-1) * math.factorial(w-1))

answer = 0
for i in range(B+1, W+1):
    answer += f(H-A, i) * f(A, W-i+1)
    answer %= MOD

print(int(answer))

### FIXED CODE ###

import math
H, W, A, B = map(int, input().split())
MOD = 10 ** 9 + 7

factorial = [1]
inv_factorial = [1]


for i in range(1, H+W+1):
    factorial.append(factorial[-1] * i % MOD)
    inv_factorial.append(pow(factorial[-1], MOD-2, MOD))


def f(h, w):
    return (factorial[h+w-2] * inv_factorial[h-1] * inv_factorial[w-1]) % MOD


answer = 0
for i in range(B+1, W+1):
    answer += f(H-A, i) * f(A, W-i+1)
    answer %= MOD

print(int(answer))
### BUGGY CODE ###

def warshal_floyd(m, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                c_ij = m[i][j]
                c_ikj = m[i][k] + m[k][j]
                m[i][j] = min(c_ij, c_ikj)
    return m


def main():
    from collections import Counter
    n, x, y = map(int, input().split())
    m = [[float("Inf")] * n for _ in range(n)]
    for i in range(n):
        m[i][i] = 0
    for i in range(n - 1):
        m[i][i + 1] = 1
        m[i + 1][i] = 1

    m[x - 1][y - 1] = 1
    m[y - 1][x - 1] = 1

    wm = warshal_floyd(m, n)

    mm = sum(m, [])
    c = Counter(mm)
    ans = ''
    for i in range(1, n):
        d = c.get(i)
        if d is None:
            ans += "0\n"
        else:
            ans += str(d // 2) + '\n'
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, x, y = map(int, input().split())
    m = [0] * (n - 1)
    for i in range(1, n):
        for j in range(i + 1, n + 1):
            p = min([abs(i - j), abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x)])
            m[p - 1] += 1

    ans = "\n".join(map(str, m))
    print(ans)


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

import sys
input = sys.stdin.readline
from collections import defaultdict
from itertools import compress 
N = int(input())
S = input()
S1,S2 = S[:N],S[N:]

Ls = defaultdict(lambda : defaultdict(int))
Rs = defaultdict(lambda : defaultdict(int))

def int2bin(x,N): 
    res = [0]*N
    for i in range(N):
        res[N-1-i] = x % 2
        x >>= 1
    return res

for i in range(2**N):
    bs = int2bin(i,N)
    n = sum(bs)
    R = ""
    L = ""
    for s,b in zip(S1,bs):
        if b == 1:
            R += s
        else:
            L += s
    Ls[n][(R,L[::-1])] += 1
    R = ""
    L = ""
    for s,b in zip(S2,bs):
        if b == 1:
            R += s
        else:
            L += s
    Rs[n][(R,L[::-1])] += 1

ans = 0
for i in range(N+1):
    for (lr,lb),n in Ls[i].items():
        for (rr,rb),m in Rs[N-i].items():
            if lr+rr == rb+lb:
                ans += n*m

print(ans)







### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict
from itertools import compress 
N = int(input())
S = input().strip()
#N = 18
#S = 'abc' * 12
S1 = S[:N]
S2 = S[N:][::-1]

Ls = defaultdict(lambda : defaultdict(int))

def int2bin(x,N): 
    res = [0]*N
    for i in range(N):
        res[N-1-i] = x % 2
        x >>= 1
    return res

for i in range(2**N):
    bs = int2bin(i,N)
    n = sum(bs)
    R = ""
    B = ""
    for s,b in zip(S1,bs):
        if b == 1:
            R += s
        else:
            B += s
    Ls[n][(R,B[::-1])] += 1

ans = 0
for i in range(2**N):
    bs = int2bin(i,N)
    n = sum(bs)
    R = ""
    B = ""
    for s,b in zip(S2,bs):
        if b == 1:
            B += s
        else:
            R += s
    R = R[::-1]
    ans += Ls[n][(B,R)]

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

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

n=100

from fractions import gcd
from functools import reduce
gs = [reduce(gcd, A[100*i:100*(i+1)]) for i in range((N-1)//100 + 1)]

answer = 0

for i in range(N):
  k = i%100
  i = (i//100)
  
  g = reduce(gcd, A[i*100:k] + A[k+1:(i+1)*100] + gs[0:i] + gs[i+1:])

  answer = max(answer, g)

print(answer)


### FIXED CODE ###

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

L = len(A)
from functools import reduce
from fractions import gcd

def lcm(a,b):
  return (a*b)//gcd(a,b)

g = reduce(gcd, A)
l = reduce(lcm, A)

def _gcd(a,b):
  if a is None and b is None:
    return None
  if a is None:
    return b
  if b is None:
    return a
  else:
    return gcd(a,b)

class SegTree():
  import math
  def __init__(self, func, A, identity=1):
    self._func = func
    self._N = 1
    while self._N < len(A):
      self._N *= 2
       # 長さ 7 なら N=3 (2^3=8)
    self._identity = identity # maxなら-1e9, sumなら0, productなら1

    self._tree = [self._identity] * (2*self._N -1) 
    self._tree[self._N-1:self._N-1+ len(A)] = A #最下段に元の配列を
    for i in range(self._N-2, -1, -1):
      self._update_single_node(i)
    ########
    # N=3: #
    # 0000 #
    # 1122 #
    # 3456 #
    ########
    self._node_range = [(i-self._N+1,i-self._N+2) for i in range(2*self._N-1)] #right_exclusive
    for i in range(self._N-2, -1, -1):
      self._node_range[i] = (self._node_range[2*i+1][0], self._node_range[2*i+2][1])

  def _update_single_node(self,i):
    self._tree[i] = self._func(self._tree[2*i+1], self._tree[2*i+2])

  def point_update(self,i,x):
    # A[i] = x (addではないので注意)
    j = self._N-1+i
    self._tree[j] = x
    while j>0:
      j = (j-1)//2
      self._update_single_node(j)

  def range_query(self, l, r, on=0):
    # reduce(func, A[l:r])
    # onはノード[on]上と重なる部分の，ということ
    onl, onr = self._node_range[on]
    
    # ノード[on]上はすべて覆う
    if l<=onl and onr<=r:
      return self._tree[on]
    
    # 重なりなし
    elif onr<=l or r<=onl:
      return self._identity
    
    else:
      return self._func(self.range_query(l, r, on=2*on+1),
                        self.range_query(l, r, on=2*on+2))

st = SegTree(_gcd, A, identity=None)

answer = 0
for i in range(len(A)):
  st.point_update(i, A[i-1])
  answer = max(answer, st._tree[0])
  st.point_update(i, A[i])

print(answer)
### BUGGY CODE ###

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

min_a = min(a)
x = [i for i in range(min_a, max(a)+1)]
for i in range(n):
   if x[a[i]-min_a] == -1:
      print('NO')
      exit()
   else:
      x[a[i]-min_a] = -1

print('YES')


### FIXED CODE ###

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

a.sort()
for i in range(n-1):
   if a[i] == a[i+1]:
      print('NO')
      exit()

print('YES')
### BUGGY CODE ###

import queue
import sys
input = sys.stdin.readline
def main():
    q = queue.Queue()
    h,w=map(int,input().split())
    a=[list(input()) for i in range(h)]
    x=[[-1,0],[1,0],[0,-1],[0,1]]
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                a[i][j]=0
                for k in x:
                    if 0<=i+k[0]<h and 0<=j+k[1]<w and a[i+k[0]][j+k[1]]==".":
                        a[i+k[0]][j+k[1]]=1
                        q.put([i+k[0],j+k[1],1])
    ans=0
    while not q.empty():
        v=q.get()
        for k in x:
            if 0<=v[0]+k[0]<h and 0<=v[1]+k[1]<w and a[v[0]+k[0]][v[1]+k[1]]==".":
                a[v[0]+k[0]][v[1]+k[1]]=v[2]+1
                q.put([v[0]+k[0],v[1]+k[1],v[2]+1])
                ans=v[2]+1
    print(ans)
if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import deque 
import sys
input = sys.stdin.readline
def main():
    q = deque([])
    h,w=map(int,input().split())
    a=[list(input()) for i in range(h)]
    x=[[-1,0],[1,0],[0,-1],[0,1]]
    for i in range(h):
        for j in range(w):
            if a[i][j]=="#":
                for k in x:
                    if 0<=i+k[0]<h and 0<=j+k[1]<w and a[i+k[0]][j+k[1]]==".":
                        a[i+k[0]][j+k[1]]="0"
                        q.append([i+k[0],j+k[1],1])
    ans=0
    while q:
        v=q.popleft()
        for k in x:
            if 0<=v[0]+k[0]<h and 0<=v[1]+k[1]<w and a[v[0]+k[0]][v[1]+k[1]]==".":
                a[v[0]+k[0]][v[1]+k[1]]="0"
                q.append([v[0]+k[0],v[1]+k[1],v[2]+1])
                ans=v[2]+1
    print(ans)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N=int(input())
L=[]
for i in range(N):
  S=input()
  tmp=[0]*26
  for s in S:
    tmp[ord(s)-ord('a')]+=1
  L.append(tmp)
ans=0
for i in range(N):
  for j in range(i+1,N):
    if L[i]==L[j]:
      ans+=1
print(ans)

### FIXED CODE ###

n = int(input())
S=[input() for _ in range(n)]
S=[''.join(sorted(i)) for i in S]
d={}
rslt=0
for s in S:
    if s in d:
        rslt+=d[s]
        d[s]+=1
    else:
        d[s]=1
print(rslt)
### BUGGY CODE ###

N = int(input())
li = input().split()
a = 1
for i in range(N):
  a *= int(li[i])
if a > 10 ** 18:
  print(-1)
else:
  print(a)


### FIXED CODE ###

N = int(input())
li = input().split()
a = 1
sikataganai = False
try:
  h = li.index('0')
  print(0)
  sikataganai = True
except:
  for i in range(N):
    a *= int(li[i])
    if a > 10 ** 18:
      print(-1)
      exit()
  if not sikataganai :
    print(a)
### BUGGY CODE ###

n, m = map(int, input().split())
s = [int(input()) for _ in range(m)]
s.append(n+1)

dp = [0] * (n + 1)
dp[0] = 1

for i in range(1,n+1):
    if i not in s:
        dp[i] += dp[i - 1]
        if i > 1:dp[i] += dp[i - 2]

print(dp[n] % (10 ** 9 + 7))



### FIXED CODE ###

n, m = map(int, input().split())
s = [int(input()) for _ in range(m)]
s.append(n+1)

dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1

for i in range(n - 1):
    dp[i + 2] = dp[i + 1] + dp[i]
mae = 0
ans = 1
for i in s:
    if i == mae:
        ans=0
    else:
        ans *= dp[i - 1 - mae]

    mae = i + 1
print(ans % (10 ** 9 + 7))
### BUGGY CODE ###

K,S = (int(x) for x in input().split())
result = [(x,y,z) for x in range(K+1) for y in range(K+1) for z in range(K+1) if (x + y + z) == S]

print(len(result))

### FIXED CODE ###

K,S = (int(x) for x in input().split())

count = 0
for x in range(K+1):
    for y in range(K+1):
            if  0 <= S - (x + y) <= K:
                count += 1
print(count)
### BUGGY CODE ###

n, a, b = map(int, input().split())
red = 0 ; blue = 0
while n >= 0 :
    if n > a :
        n -= a
        blue += a
    else :
        blue += n
        break
    if n > b :
        n -= b
        red += b
    else :
        red += b
        break
print(blue)


### FIXED CODE ###

n, a, b = map(int, input().split())
red = 0 ; blue = 0
if n >= a + b :
    stack = n // (a+b)
    red += b * stack
    blue += a * stack
    n -= (a+b) * stack
if n > a :
    n -= a
    blue += a
else :
    blue += n
if n > b :
    n -= b
    red += b
else :
    red += n
print(blue)