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

from collections import deque

H,W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1

squares = []
for i in range(H):
    squares.append([None]*(W))

for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == '#':
            squares[i][j] = -1  # Wall

squares[Ch][Cw]=0

d = deque()
d.append([Ch, Cw])

steps = [[-1,0],[1,0],[0,-1],[0,1]]

warps = 0

def visit(i1, j1, i2, j2):  # (i1,j1) to (i2,j2)
    if i2 < 0 or i2 >= H or j2 < 0 or j2 >= W:
        return
    sq2 = squares[i2][j2]
    if sq2 == -1:
        return
    if sq2 == None:
        squares[i2][j2] = warps  # sq2 = warps <- doesn't work
        d.append([i2, j2])
        if i2 == Dh and j2 == Dw:
            print(warps)
            exit()

while (len(d)>0):
    while (len(d)>0):
        src = d.popleft()
        for st in steps:
            visit(src[0], src[1], src[0]+st[0], src[1]+st[1])
    warps += 1
    for i in range(H):
        for j in range(W):
            sq = squares[i][j]
            if sq == warps - 1:
                for di in range(-2,3):
                    for dj in range(-2,3):
                        visit(i, j, i+di, j+dj)

print(-1)



### FIXED CODE ###

from collections import deque

H,W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1

squares = []
for i in range(H):
    squares.append([None]*(W))

for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == '#':
            squares[i][j] = -1  # Wall

squares[Ch][Cw]=0

d1 = deque()
d2 = deque()
d1.append([Ch, Cw])

warps = 0

def visit(i1, j1, i2, j2, with_warp = False):  # (i1,j1) to (i2,j2)
    if i2 < 0 or i2 >= H or j2 < 0 or j2 >= W:
        return
    sq2 = squares[i2][j2]
    if sq2 == None:
        if with_warp:
            squares[i2][j2] = warps + 1  # sq2 = warps + 1 <- doesn't work
        else:
            squares[i2][j2] = warps  # sq2 = warps <- doesn't work
        d1.append([i2, j2])
        if i2 == Dh and j2 == Dw:
            print(squares[i2][j2])
            exit()

while (len(d1)>0):
    while (len(d1)>0):
        src = d1.popleft()
        visit(src[0], src[1], src[0] - 1, src[1])
        visit(src[0], src[1], src[0] + 1, src[1])
        visit(src[0], src[1], src[0], src[1] - 1)
        visit(src[0], src[1], src[0], src[1] + 1)
        d2.append(src)

    while (len(d2)>0):
        src = d2.popleft()
        for i in range(-2,3):
            for j in range(-2,3):
                visit(src[0], src[1], src[0]+i, src[1]+j, True)

    warps += 1

print(-1)
### BUGGY CODE ###

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

dp = [[] for k in range(n+1)]

cost = [0,2,5,5,4,5,6,3,7,6]

#dpの初期化
for i in range(m):
    if cost[a[i]] <= n:
        dp[cost[a[i]]]= [a[i]]


for i in range(0,n+1):
    for k in range(m):
        if i > cost[a[k]]:
            #print(cost[a[k]])
            tmp = copy.copy(dp[i-cost[a[k]]])
            tmp.append(a[k])
            tmp.sort(reverse = True)
            #print(i,tmp)
            if len(tmp) > len(dp[i]) and len(tmp) != 1:
                dp[i] = tmp
            elif len(tmp) == len(dp[i]) and len(tmp) != 1:

                num1 = ""
                for cha in dp[i]:
                    num1 = num1 + str(cha)

                num2 = ""
                for cha in tmp:
                    num2 = num2 + str(cha)

                if num2 > num1:
                    dp[i] = tmp
            #print(dp)

ans = ""
for cha in dp[n]:
    ans = ans + str(cha)
print(ans)


### FIXED CODE ###

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

dp = [[] for k in range(n+1)]

cost = [0,2,5,5,4,5,6,3,7,6]

#dpの初期化
for i in range(m):
    if cost[a[i]] <= n:
        dp[cost[a[i]]]= [a[i]]


for i in range(0,n+1):
    for k in range(m):
        if i > cost[a[k]]:
            #print(cost[a[k]])
            tmp = copy.copy(dp[i-cost[a[k]]])
            tmp.append(a[k])
            tmp.sort(reverse = True)
            #print(i,tmp)
            if len(tmp) > len(dp[i]) and len(tmp) != 1:
                dp[i] = tmp
            elif len(tmp) == len(dp[i]) and len(tmp) != 1:
                big = 0

                for s in range(len(tmp)):
                    if tmp[s] > dp[i][s]:
                        big = 1
                        break
                    elif tmp[s] < dp[i][s]:
                        big = 0
                        break
                if(big):
                    dp[i] = tmp
            #print(dp)

ans = ""
for cha in dp[n]:
    ans = ans + str(cha)
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n, d, a = MAP()
xh = [LIST() for i in range(n)]

xh = sorted(xh, key=lambda x:(x[0], x[1]))
cnt = 0
for i in range(n):
    cx, ch = xh[i][0], xh[i][1]
    if ch <= 0:
        continue
    cn = (ch + a - 1) // a
    cnt += cn
    tmp = []
    j = i + 1
    while xh and j < len(xh):
        nx = xh[j][0]
        if nx <= cx + 2*d:
            xh[j][1] -= cn * a
            j += 1
        else:
            break
    
print(cnt)

### FIXED CODE ###

from collections import deque
import sys

input = sys.stdin.buffer.readline
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n, d, a = MAP()
xh = [LIST() for i in range(n)]

xh = sorted(xh, key=lambda x:(x[0]))
q = deque()
ca = 0
cnt = 0
for i in range(n):
    cx, ch = xh[i][0], xh[i][1]
    
    while q and q[0][0] < cx:
        qx, qa = q.popleft()
        ca -= qa
    
    if ch - ca <= 0:
        continue
    
    cn = (ch - ca + a - 1) // a
    cnt += cn
    ca += cn * a
    q.append([cx+2*d, cn*a])
    
print(cnt)
### BUGGY CODE ###

N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

now = 1
path = [1]

i = 0
while i < N + 2:
    now = A[now]
    i += 1
    if now in path: break
    path.append(now)

if i >= K:
    print(path[K])
    quit()

lo_start = path.index(now)
lo_len = i - lo_start
loop = path[lo_start:]

ans = loop[(K - lo_start) % lo_len]

print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

now = 1
path = [1]

for i in range(N + 2):
    now = A[now]
    path.append(now)

if i >= K:
    print(path[K])
    quit()

now = path.pop()
lo_start = i - 1
while path[lo_start] != now:
    lo_start -= 1

loop = path[lo_start:]

ans = loop[(K - path.index(now)) % len(loop)]

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

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

option = {(0, 0)}


def main():
    global option
    last_list = [0, 0, 0]
    N = int(input())
    for i in range(N):
        this_list = list(map(int, input().split()))
        add_option(this_list[0] - last_list[0])
        if (this_list[1], this_list[2]) not in option:
            print('No')
            return
        last_list = this_list
    print('Yes')


def add_option(step):
    global option
    for i in range(step):
        temp_option = set()
        for position in option:
            x, y = position
            temp_option.add((x + 1, y))
            temp_option.add((x, y + 1))
            if x > 0:
                temp_option.add((x - 1, y))
            if y > 0:
                temp_option.add((x, y - 1))
        option = temp_option


main()


### FIXED CODE ###

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

judge = 'Yes'

N = int(input())
for i in range(N):
    t, x, y = map(int, input().split())
    if t < (x + y) or t % 2 != (x + y) % 2:
        judge = 'No'

print(judge)
### BUGGY CODE ###

from math import ceil
from collections import defaultdict
t = int(input())

# (b,c,d) -> {A -> No/Yes, ...}
memo = defaultdict(dict)
for i in range(t):
    a,b,c,d = map(int, input().split())

    if a < b:
        print('No')
        continue

    if d >= b and c+1 >= b:
        print('Yes')
        continue

    key = (b,c,d)
    if key in memo:
        for A, ans in memo[key].items():
            #print(a,A)
            if a in A:
                print(ans)
                continue

    A = set([a])
    while(True):
        if (a-c)%b == 0:
            x = (a-c)//b
        else:
            x = ceil((a-c)/b)
        if a-b*x < 0:
            print('No')
            memo[key][frozenset(A)] = 'No'
            break
        next_a = a-b*x+d
        if next_a < b:
            print('No')
            memo[key][frozenset(A)] = 'No'
            break
        if next_a in A:
            print('Yes')
            memo[key][frozenset(A)] = 'Yes'
            break
        A.add(next_a)
        if len(A) >= d:
            print('No')
            memo[key][frozenset(A)] = 'No'
            break
        a = next_a


### FIXED CODE ###

from fractions import gcd
t = int(input())

for i in range(t):
    a,b,c,d = map(int, input().split())

    if a < b or b > d:
        print('No')
        continue

    if b <= c:
        print('Yes')
        continue

    g = gcd(b, d)
    if c >= b - g + (a % g):
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

N,K=[int(i) for i in input().split()]
S=input()
cur=0
line=[]
for i in range(len(S)):
	if i==0:
		line.insert(0,1)
	else:
		if S[i-1]!=S[i]:
			line.append(1)
		else:
			line[-1]+=1
c=0
if S[0]=="0":
	for i,num in enumerate(line):
		if i%2==0:
			if i+2*K<=len(line):
				c=max(c,sum(line[i:i+2*K]))
			else:
				c=max(c,sum(line[i:]))
				break
		else:
			if i+2*K+1<=len(line):
				c=max(c,sum(line[i:i+2*K+1]))
			else:
				c=max(c,sum(line[i:]))
				break
else:
	for i,num in enumerate(line):
		if i%2==1:
			if i+2*K<=len(line):
				c=max(c,sum(line[i:i+2*K]))
			else:
				c=max(c,sum(line[i:]))
				break
		else:
			if i+2*K+1<=len(line):
				c=max(c,sum(line[i:i+2*K+1]))
			else:
				c=max(c,sum(line[i:]))
				break
print(c)

### FIXED CODE ###

N,K=[int(i) for i in input().split()]
S=input()
cur=0
line=[]

for i in range(len(S)):
	if i==0:
		if S[0]=="0":
			line.append(0)
		line.append(1)
	else:
		if S[i-1]!=S[i]:
			line.append(1)
		else:
			line[-1]+=1
c=0
for i in range(len(line)):

	if i==0:
		if i+2*K+1<=len(line):
			s=sum(line[i:2*K+1])
			c=s
		else:
			s=sum(line[i:])
			c=s
	elif i%2==0:
		if i+2*K+1<=len(line):
			s=s-line[i-2]-line[i-1]+line[i+2*K-1]+line[i+2*K]
			c=max(c,s)
		else:
			c=max(c,sum(line[i:]))
			break
print(c)
### BUGGY CODE ###

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

mod = 10**9+7
ans = 0

for i in range(60):
  one=0
  for j in range(N):
    one += A[j]&1
    A[j] = A[j]>>1
  zero = N - one
  ans += one*zero*pow(2,i)
  ans %= mod
  #print(one,zero)

print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
import numpy as np
mod = 10**9+7
ans = 0
A = np.array(A)
for i in range(60):
  one = np.count_nonzero(A>>i&1)
  zero = N - one
  ans += one*zero*pow(2,i)
  ans %= mod
  #print(one,zero)

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

import sys
n,k=map(int,input().split())
w=list(map(int,sys.stdin.readlines()))
def check(P):
 i=0
 for _ in[0]*k:
  s=0
  while s+w[i]<=P:
   s+=w[i];i+=1
   if i==n: return n
 return i
l,r=max(w),sum(w)
while l<=r:
 m=(l+r)//2
 if check(m)>=n:r=m
 else:l=m
print(r)


### FIXED CODE ###

import sys
def s():
 n,k=map(int,input().split())
 w=list(map(int,sys.stdin.readlines()))
 def f():
  c=t=0
  for j in w:
   t+=j
   if t>m:
    t=j
    c+=1
    if c>=k:return 0
  return 1
 l,r=max(w),sum(w)
 while l<r:
  m=(l+r)//2
  if f():r=m
  else:l=m+1
 print(r)
if'__main__'==__name__:s()
### BUGGY CODE ###

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

S = set(A)
S2 = set(A)
for s in S:
    if A.count(s)%2 == 0:
        S2.remove(s)
print(len(S2))


### FIXED CODE ###

N = int(input())
S = set()
for i in range(N):
    S^={input()}
print(len(S))
### BUGGY CODE ###

from heapq import heappop, heappush
inputs = open(0).readlines()

n, m = map(int, inputs[0].split())
*A, = map(int, inputs[1].split())
BC = (map(int, bc.split()) for bc in inputs[2:])

D = []
for a in A:
    heappush(D, a)
for b, c in BC:
    for _ in range(b):
        heappush(D, max(heappop(D), c))
print(sum(D))

### FIXED CODE ###

from heapq import heapify, heappushpop
from operator import itemgetter
inputs = open(0).readlines()

n, m = map(int, inputs[0].split())
*A, = map(int, inputs[1].split())
heapify(A)
BC = [tuple(map(int, bc.split())) for bc in inputs[2:]]
BC.sort(key=itemgetter(1), reverse=True)

for b, c in BC:
    for _ in range(b):
        if c > A[0]:
            _ = heappushpop(A, c)
        else:
            break
print(sum(A))
### BUGGY CODE ###

def mergeSort(A, left, right, n):
    if left + 1 < right:
        mid = int((right + left ) / 2 )
        mergeSort(A, left, mid, n)
        mergeSort(A, mid, right, n)
        return (merge(A, left, mid, right, n))

def merge(A, left, mid, right, n):
    n1 = mid - left
    n2 = right - mid
    L = []
    R = []
    for i in range(n1):
        L.append(A[left + i])
    for i in range(n2):
        R.append(A[mid + i])
    L.append(1000000001)
    R.append(1000000001)
    i = j = 0
    for k in range(left, right):
        A[n] += 1
        if L[i] <= R[j]:
            key = L[i]
            A[k] = key
            i += 1
        else:
            key = R[j]
            A[k] = key
            j += 1
    return A

n = int(input())
A = list(map(int, input().split()))
A.append(0)
S = mergeSort(A, 0, len(A) - 1, n)
for i in range(n - 1):
    print(S[i], end = ' ')
print(S[n - 1])
print(S[n])



### FIXED CODE ###

def mergeSort(A, left, right, n):
    if left + 1 < right:
        mid = int((right + left ) / 2 )
        mergeSort(A, left, mid, n)
        mergeSort(A, mid, right, n)
        return (merge(A, left, mid, right, n))

def merge(A, left, mid, right, n):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]  + [10 ** 9 + 1]
    R = A[mid:right] + [10 ** 9 + 1]
    L.append(1000000001)
    R.append(1000000001)
    i = j = 0
    for k in range(left, right):
        A[n] += 1
        if L[i] <= R[j]:
            key = L[i]
            A[k] = key
            i += 1
        else:
            key = R[j]
            A[k] = key
            j += 1
    return A

n = int(input())
A = list(map(int, input().split()))
A.append(0)
S = mergeSort(A, 0, len(A) - 1, n)
print(' '.join(list(map(str, S[:n]))))
print(S[n])
### BUGGY CODE ###

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

for k in range(K):
    flag_all = True
    for i in range(N):
        if A[i] != N:
            flag_all = False
    if flag_all:
        break

    B = [0] * N
    for i in range(N):
        d = A[i]
        for j in range(-d, d+1):
            index = i + j
            if 0 <= index < N:
                B[index] += 1
    A = B
print(" ".join(map(str, A)))


### FIXED CODE ###

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

for k in range(K):
    for i in range(N):
        if A[i] != N:
            break
    else:
        break

    B = [0] * N
    for i in range(N):
        d = A[i]
        left = max(0, i - d)
        right = min(N-1, i + d)
        B[left] += 1
        if right + 1 < N:
            B[right+1] -= 1
    for i in range(1, N):
        B[i] += B[i-1]
    A = B
print(" ".join(map(str, A)))
### BUGGY CODE ###

n=int(input())
a_list=list(map(int,input().split()))
count=0
for i in range(n):
    if i%2==0:
        count+=a_list[i]
    else:
        count-=a_list[i]
ans=''
ans=ans+str(count)
now=count//2
for i in range(n-1):
    now=a_list[i]-now
    ans=ans+' '+str(now*2)
print(ans)
            


### FIXED CODE ###

n=int(input())
a_list=list(map(int,input().split()))
count=0
for i in range(n):
    if i%2==0:
        count+=a_list[i]
    else:
        count-=a_list[i]
print(count,end='')
now=count//2
for i in range(n-1):
    now=a_list[i]-now
    print(' ',end='')
    print(now*2,end='')
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


if __name__ == '__main__':
    n = int(input())
    data = list(map(int, input().split()))
    ans = 1
    for d in data:
        ans *= d
    if ans > 10 ** 18:
        print(-1)
    else:
        print(ans)

    #print('\33[32m' + 'end' + '\033[0m') # debug


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


def solve(data):
    ans = 1
    if 0 in data:
        return 0
    for d in data:
        ans *= d
        if ans > 10 ** 18:
            return -1
    return ans


if __name__ == '__main__':
    n = int(input())
    data = list(map(int, input().split()))
    ans = solve(data)
    #print('ans') # debug
    print(ans)

    #print('\33[32m' + 'end' + '\033[0m') # debug
### BUGGY CODE ###

import math
from functools import reduce
import itertools
K = int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)
count = 0
for i, j , k in itertools.product(range(K), range(K), range(K)):
  count += gcd(i+1,j+1,k+1)
      
print(count)

### FIXED CODE ###

import math
K = int(input())
count = 0
for i in range(K):
  for j in range(K):
    x = math.gcd(i+1,j+1)
    for k in range(K):
      count += math.gcd(x,k+1)    
print(count)
### BUGGY CODE ###

A, B, Q = map(int, input().split())
S = [0] * A
T = [0] * B
for i in range(A):
  S[i] = int(input())
for i in range(B):
  T[i] = int(input())
def lr_find(x, Y):
  if x < Y[0]:
    return [0, Y[0]]
  if x >= Y[-1]:
    return [Y[-1], 0]
  l, r = 0, len(Y) - 1
  while r - l > 1:
    m = (l + r) // 2
    if x < Y[m]:
      r = m
    else:
      l = m
  return [Y[l], Y[r]]
for q in range(Q):
  x = int(input())
  D = [lr_find(x, S), lr_find(x, T)]
  ans = 10 ** 12
  for i in range(8):
    s = D[0][i % 2]
    t = D[1][(i // 2) % 2]
    if s and t:
      dist = abs(s - t) + abs(x - [s, t][(i // 4) % 2])
      ans = min(dist, ans)
  print(ans)

### FIXED CODE ###

A, B, Q = map(int, input().split())
S = [0] * A
T = [0] * B
for i in range(A):
  S[i] = int(input())
for i in range(B):
  T[i] = int(input())
def lr_find(x, Y):
  if x < Y[0]:
    return [0, Y[0]]
  if x >= Y[-1]:
    return [Y[-1], 0]
  l, r = 0, len(Y) - 1
  while r - l > 1:
    m = (l + r) // 2
    if x < Y[m]:
      r = m
    else:
      l = m
  return [Y[l], Y[r]]
for q in range(Q):
  x = int(input())
  D = [lr_find(x, S), lr_find(x, T)]
  ans = 10 ** 12
  for i in range(8):
    s = D[0][i % 2]
    t = D[1][(i // 2) % 2]
    if s and t:
      dist = abs(s - t) + abs(x - [s, t][(i // 4) % 2])
      ans = min(dist, ans)
  print(ans)
### BUGGY CODE ###

import itertools

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

candi = list(itertools.product(range(10),repeat=3))

cnt = 0

for i in candi:
    flag1 = False
    flag2 = False
    flag3 = False
    for j in S:
        if flag1 == False and int(j) == i[0]:
            flag1 = True
            continue
        if flag1 == True and flag2 == False and int(j)==i[1]:
            flag2 = True
            continue
        if flag2 == True and flag3 == False and int(j)==i[2]:
            flag3 = True
            cnt += 1    
            break

print(cnt)



### FIXED CODE ###

import itertools

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

candi = list(itertools.product(range(10),repeat=3))

cnt = 0

for i in candi:
    if str(i[0]) in S:
        T = S[S.find(str(i[0]))+1:]
        if str(i[1]) in T:
            U = T[T.find(str(i[1]))+1:]
            if str(i[2]) in U:
                cnt += 1

print(cnt)
### BUGGY CODE ###

from copy import deepcopy

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

all_score = sum(V)
memo = {}

def dfs(queue, hand, depth):
    # print(queue, hand, depth)
    if depth == K:
        score = all_score - sum(queue)
        memo[queue] = score
        # print('return', queue, score)
        return score
    if queue in memo:
        # print('memo')
        return memo[queue]

    max_score = all_score - sum(queue)
    if len(queue) > 0:
        # A
        A_queue = queue[1:]
        A_hand = deepcopy(hand)
        A_hand.append(queue[0])
        score = dfs(A_queue, A_hand, depth + 1)
        if score > max_score:
            max_score = score
        # B
        B_queue = queue[:-1]
        B_hand = deepcopy(hand)
        B_hand.append(queue[-1])
        score = dfs(B_queue, B_hand, depth + 1)
        if score > max_score:
            max_score = score

    for i in range(len(hand)):
        # C
        C_queue = (hand[i],) + queue
        C_hand = deepcopy(hand)
        C_hand = C_hand[:i] + C_hand[i+1:]
        score = dfs(C_queue, C_hand, depth + 1)
        if score > max_score:
            max_score = score

        # D
        D_queue = queue + (hand[i],)
        D_hand = deepcopy(hand)
        D_hand = D_hand[:i] + D_hand[i + 1:]
        score = dfs(D_queue, D_hand, depth + 1)
        if score > max_score:
            max_score = score

    memo[queue] = max_score
    # print(queue, max_score)
    return max_score

ans = dfs(V, [], 0)
print('0' if ans < 0 else ans)

### FIXED CODE ###

from copy import deepcopy

N, K = map(int, input().split())
V = tuple(map(int, input().split()))
max_score = -1000000000
for i in range(K+1):
    for j in range(K - i + 1):
        if i + j > N:
            continue
        # 左からi個取る
        hand = list(V[:i])
        # 右からj個取る
        hand.extend(V[N-j:])
        # 最大(K - i - j)個戻せる
        # print(i, j, hand)
        score = sum(hand)
        counter = 0
        for h in sorted(hand):
            counter += 1
            if K - i - j - counter < 0:
                break
            if h < 0:
                score -= h
        if max_score < score:
            max_score = score
print(max_score)
### BUGGY CODE ###

n = int(input())
a = []
b = []
for i in range(n):
  tmp = "".join(sorted(input()))
  if tmp in a:
    b[a.index(tmp)] += 1
  else:
    a.append(tmp)
    b.append(1)
res = [i*(i-1)//2 for i in b]
print(sum(res))


### FIXED CODE ###

n = int(input())
a = {}
for i in range(n):
  tmp = "".join(sorted(input()))
  if tmp in a:
    a[tmp] += 1
  else:
    a[tmp] = 1
res = [i*(i-1)//2 for i in a.values()]
print(sum(res))
### BUGGY 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
 
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)

for _ in range(K):
  A = update(A)
  if np.all(A==N):
    break
print(' '.join(A.astype(str)))

### 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 ###

N = int(input())
list1 = [str(input()) for  _ in range(N)]
list2 =  ["".join(sorted(list1[i])) for i in range(N)]
ans = 0
for i in range(N):
  for j in range(i+1,N):
    if list2[i] == list2[j]:
      ans += 1
print(ans)

### FIXED CODE ###

N=int(input())
dictionary={}
count=0
for i in range(N):
    s="".join(sorted(input()))
    if s in dictionary:
        dictionary[s]+=1
        count+=dictionary[s]
    else:
        dictionary[s]=0
print(count)