Harryxun/stf_run huggingface dataset:
import numpy as np


def move_and_compute_cost(field, d, l, r, cost):
    if l == r:
        return cost

    curr_y, curr_x = np.where(field == l)
    curr_y, curr_x = curr_y[0], curr_x[0]

    next_y, next_x = np.where(field == l + d)
    next_y, next_x = next_y[0], next_x[0]

    cost += abs(next_y - curr_y) + abs(next_x - curr_x)
    return move_and_compute_cost(field, d, l + d, r, cost)


if __name__ == '__main__':
    h, w, d = [int(v) for v in input().split()]

    # read field
    field = np.empty((h, w), dtype=int)
    for i in range(h):
        line = [int(v) for v in input().split()]
        field[i, :] = line

    ls, rs = [], []
    q = int(input())
    for i in range(q):
        line = [int(v) for v in input().split()]
        ls.append(line[0])
        rs.append(line[1])

    costs = [move_and_compute_cost(field, d, l, r, 0) for l, r in zip(ls, rs)]
    for c in costs:
        print(c)


### FIXED CODE ###

if __name__ == '__main__':
    h, w, d = map(int, input().split())
    f = [list(map(int, input().split())) for _ in range(h)]

    # f => (y, x) mapping
    c_map = [0] * (h * w)
    for y in range(h):
        for x in range(w):
            c_map[f[y][x] - 1] = (y, x)

    # cost accumulation
    d_map = [0] * (h * w)
    for i in range(d, h * w):
        y, x = c_map[i]
        y2, x2 = c_map[i - d]
        d_map[i] = d_map[i - d] + abs(y2 - y) + abs(x2 - x)

    results = []
    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split())
        results.append(d_map[r - 1] - d_map[l - 1])

    print("\n".join(map(str, results)))
n=int(input())
if n!=1:
  a=input()
  b=input()
  m=[]
  for i in a:
    for j in b:
      if i==j:
        m.append(i)
  for _ in range(n-2):
    s=input()
    l=[]
    for i in s:
      for j in m:
        if i==j:
          l.append(i)
    m=l
  print(''.join(sorted(m)))  
else:
  print(a)

### FIXED CODE ###

n=int(input())
a=input()
if n!=1:
  b=input()
  m=[]
  if len(a)>len(b):
    a,b=b,a
  b=list(b)
  for i in a:
    for j in range(len(b)):
      if i==b[j]:
        m.append(i)
        b[j]=''
        break
  for _ in range(n-2):
    s=list(input())
    l=[]
    for i in m:
      for j in range(len(s)):
        if i==s[j]:
          l.append(i)
          s[j]=''
          break
    m=l
  print(''.join(sorted(m)))  
else:
  print(''.join(sorted(a)))
N = int(input())
L = list(map(int,inptut().split()))
while True:
  if len(L) == 1:
    print(L[0])
    quit()
  L = sorted(L)
  m = L[0]
  for i in range(1,len(L)):
    L[i] %= m
  L = list(filter(lambda x:x!=0,L))  
  

### FIXED CODE ###

N = int(input())
L = list(map(int,input().split()))
while True:
  if len(L) == 1:
    print(L[0])
    quit()
  L = sorted(L)
  m = L[0]
  for i in range(1,len(L)):
    L[i] %= m
  L = list(filter(lambda x:x!=0,L))
a=int(input())
b=int(input())
print(a*b)

### FIXED CODE ###

a, b = input().split(' ')
men = int(a) * int(b)
syu = int(a)*2 + int(b)*2
print(men, syu)
n,a=map(int,input().split())
print((n**2) -a )

### FIXED CODE ###

N = int(input())
A = int(input())
print(N**2-A)
N = int(input())

    XY = []

    for i in range(N):
        Xi, Yi = map (float, input().split())
        XY.append([Xi,Yi])

    Z  = 0
    for i in range(N-1):
        for j in range(i + 1, N):
            Z += ((XY[i][0] - XY[j][0])**2 + (XY[i][1] - XY[j][1])**2 ) ** 0.5
    
    print(Z * 2 / N)

### FIXED CODE ###

N = int(input())

XY = []

for i in range(N):
    Xi, Yi = map (float, input().split())
    XY.append([Xi,Yi])

Z  = 0
for i in range(N-1):
    for j in range(i + 1, N):
        Z += ((XY[i][0] - XY[j][0])**2 + (XY[i][1] - XY[j][1])**2 ) ** 0.5

print(Z * 2 / N)
N, M = map(int, input().split())
A = [int(input()) for k in range(N)]

totalVote = sum(A)
border = totalVote / (4 * M)
A.sort(reverse = True)

if A[M-1] >= border:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

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

totalVote = sum(A)
border = totalVote / (4 * M)
A.sort(reverse = True)

if A[M-1] >= border:
    print("Yes")
else:
    print("No")
K, X = map(int, input())

print(" ".join(list(range(X - K, X + K + 1))))

### FIXED CODE ###

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

print(" ".join(list(map(str, range(X - K + 1, X + K)))))
N = int(input())

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

for i in N:
    a=A[i]
    if a%2==0 and (a%3!=0 or a%5!=0):
        print("DENIED")
        break

print("APPROVED")

### FIXED CODE ###

N = int(input())

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

n=0

for i in range(N):
    a=A[i]
    if a%2==0 and a%3!=0:
        if a%5!=0:
            n+=1

if n==0:
    print("APPROVED")
else:
    print("DENIED")
from math import sqrt
a, b, c = map(int,input().split())
if 4*a*b < (c - a - b)**2: print("Yes")
else: print("No")


### FIXED CODE ###

list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

print(list[K-1])
import numpy as np
m = 10**9 + 7
n = int(input())
an = list(map(int, input().split()))

an_np = np.array(an)
an_col = np.zeros((n-1,n-1))
summary = 0
zero = np.zeros((1,n-1))
for i in range(0, n-1):
    tmp = np.array(an_np[i+1: n])
    an_col[i] = np.append(tmp, zero)[:n-1]

print(int(sum(sum(np.multiply(an_np[:-1], an_col) % m)%m)%m))

### FIXED CODE ###

m = 10**9 + 7
n = int(input())
an = list(map(int, input().split()))
wa = []
total = 0
for i in reversed(range(1, len(an))):
    total = total + an[i]
    wa.append(total)
wa = sorted(wa, reverse=True)
ans = 0
for i in range(0, n-1):
#     print(an[i] * wa[i])
    ans = ans + an[i] * (wa[i]%m)
    ans = ans % m
print(ans)
n,a,b,c,d=map(int,input().split())
s=str(input())
s=s.replace('.','0')
s=s.replace('#','1')
x=0
y=0
f=0
g=0
for i in range(c-a-2):
    x=int(s[i+a+1])
    y=int(s[i+a+2])
    if(x*y==1):
        f=-1
for j in range(d-b-2):
    x=int(s[j+b+1])
    y=int(s[j+b+2])
    if(x*y==1):
        g=-1
x=s.replace('11','7')
x=x.replace('000','8')
x=x.replace('0','')
x=x.replace('1','')
if(d<c):
    if(s[b+1:d].find('000')==-1 and ):
        f=-1
if(f==0 and g==0):
    print('Yes')
else:
    print('No')




### FIXED CODE ###

n,a,b,c,d=map(int,input().split())
s=str(input())
s=s.replace('.','0')
s=s.replace('#','1')
x=0
y=0
f=0
g=0
for i in range(c-a-1):
    x=int(s[i+a])
    y=int(s[i+a+1])
    if(x*y==1):
        f=-1
for j in range(d-b-1):
    x=int(s[j+b])
    y=int(s[j+b+1])
    if(x*y==1):
        g=-1
if(d<c):
    if(s[b-2:d+1].find('000')==-1):
        f=-1
if(f==0 and g==0):
    print('Yes')
else:
    print('No')
a = [input().split() for l in range(3)]

n=int(input())
b = [(input()) for i in range(n)]
s=[]
for i in range(n):
  for j in range(3):
    if b[i] in a[j]:
      k=a[j].index(b[i])
      s.append([j,k])
      if [j,0] in s and [j,1] in s and [j,2] in s:
        print("Yes")
        break
      elif [0,k] in s and [1,k] in s and [2,k] in s:
        print("Yes")
        break
      elif j==k:
        if [0,0] in s and [1,1] in s and [2,2] in s:
          print("Yes")
          break
        elif [0,2] in s and [1,1] in s and [2,0] in s:
          print("Yes")
          break
  else:
    continue
  break
else:
  print("No")
    

### FIXED CODE ###

a = int(input())
if a%2==0:
  print(int(a/2))
else:
  print(int((a+1)/2))
S = input()
T = input()

l = len(T)
for i in range (l):
    if T[:l-i] in S:
        ans = i
        break
    if T[i:] in S:
        ans = i
        break

print(ans)

### FIXED CODE ###

S = input()
T = input()

ans = len(T)
l = len(T)
for m in range (len(S)-l+1):
    diff = 0
    for i in range (l):
        if S[m+i] != T[i]:
            diff+=1
    ans = min(ans, diff)

print(ans)
W, a, b = map(int,input().split())
if abs(a - b) <= W:
    print(0)
else:
    print(min(abs(a - (b + W), abs(b - (a + W)))))

### FIXED CODE ###

W, a, b = map(int,input().split())
if abs(a - b) <= W:
    print(0)
else:
    print(min(abs(a - (b + W)), abs(b - (a + W))))
n, k = map(int, input().split())
X = list(map(int, input().split()))

count_0 = X.count(0)

if k <= count_0:
    print(0)
    exit()

k -= count_0

neg = [x for x in X if x < 0]
pos = [x for x in X if x > 0]

neg_count = len(neg)
pos_count = len(pos)

if not neg:
    print(pos[k-1])
    exit()

if not pos:
    print(neg[-k])
    exit()

res = []
for left in range(1, min(neg_count, k)):
    time1 = neg[-left]
    right = k - left - 1
    if right >= pos_count:
        continue
    elif right < 0:
        res.append(abs(time1))
    else:
        time2 = pos[right]
        res.append(time2-time1*2)

for right in range(min(pos_count, k)):
    time1 = pos[right]
    left = k - right - 1
    if left >= neg_count:
        continue
    elif left <= 0:
        res.append(abs(time1))
    else:
        time2 = neg[-left]
        res.append(time1*2-time2)

print(min(res))

### FIXED CODE ###

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

ans = []
for i in range(n-k+1):
    left = X[i]
    right = X[i+k-1]
    if left * right < 0:
        result = min(abs(left), abs(right)) * 2 + max(abs(left), abs(right))
    else:
        result = max(abs(left), abs(right))
    ans.append(result)

print(min(ans))
import math
A,B,H,M=map(int,input().split())

dA=(60*H+M)/2
dB=6*M
rad=dA-dB

C=math.radians(rad)

c=(A**2+B**2-2*A*B*math.cos(C))**0.5
print(format(c,'.10f'))


### FIXED CODE ###

N=int(input())
s=N%10
Hon=[2,4,5,7,9]
Pon=[0,1,6,8]
Bon=[3]
if s in Hon:
  print('hon')
elif s in Pon:
  print('pon')
else:
  print('bon')
int(X)
if X >= 30 :
  print("Yes")
else :
  print("No")

### FIXED CODE ###

X = int(input())
if X >= 30 :
  print("Yes")
else :
  print("No")
H,W,M=map(int,input().split())
row_boms=[0 for i in range(H)]
col_boms=[0 for i in range(W)]

boms=[[0 for j in range(W)] for i in range(H)]
for i in range(M):
  h,w=map(int,input().split())
  boms[h-1][w-1]=1
  row_boms[h-1]+=1
  col_boms[w-1]+=1

row_max=max(row_boms)
col_max=max(col_boms)

rowmax_h=[]
colmax_w=[]
for i in range(H):
  if row_boms[i]==row_max:
    rowmax_h+=[i]
for i in range(W):
  if col_boms[i]==col_max:
    colmax_w+=[i]
rows=len(rowmax_h)
cols=len(colmax_w)
tf=0
for i in rowmax_h:
  for j in colmax_w:
    if boms[i][j]==0:
      tf=1
      break

if tf==1:
  print(row_max+col_max)
else:
  print(row_max+col_max-1)


### FIXED CODE ###

import math
N,X,T=map(int,input().split())
n=math.ceil(N/X)
print(n*T)
s = sorted(list(input()))

if a[0] == a[1] and a[2] == a[3] and a[0] != a[2]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = sorted(list(input()))

if s[0] == s[1] and s[2] == s[3] and s[0] != s[2]:
  print("Yes")
else:
  print("No")
n, m = map(int, input().split())
L = [0] * m
R = [0] * def funcname(self, parameter_list):
    pass
for i in range(m):
    L[i], R[i] = map(int, input().split())
print(min(R) - max(L) + 1)

### FIXED CODE ###


n, m = map(int, input().split())
L = [0] * m
R = [0] * m
for i in range(m):
    L[i], R[i] = map(int, input().split())
print(min(R) - max(L) + 1 if min(R) >= max(L) else 0)
def main():
  N=int(input())
  list=[]
  for i in range(1:10)
    for j in range(1:10):
      list.append(i*j)
  if N in list:
    print("Yes")
  else:
    print"No")
main()

### FIXED CODE ###

N=int(input())
list=[]
for i in range(1,10):
  for j in range(1,10):
    list.append(i*j)
if N in list:
   print("Yes")
else:
   print("No")
A, B, C D = map(int, input())
ans = 0
for i in range(A, B):
  if i % C == 0 and i % D == 0:
    ans = ans + 1

### FIXED CODE ###

def bbb(x, y):
    return (x * y) // aaa(x, y)
 
 
def aaa(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return aaa(y, x % y)
 
 
a, b, c, d = map(int, input().split())
bc = b // c
bd = b // d
ac = (a-1) // c
ad = (a-1) // d
aw = (a-1) // bbb(c, d)
bw = b // bbb(c, d)
print((b - a + 1) - (bc - ac) - (bd - ad) + (bw - aw))
#!/usr/bin/env python3
import sys
import itertools

def cf(x1,x2):
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            yield i

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return set(i for i in range(n + 1) if is_prime[i])

def solve(A: int, B: int):
    P = primes(min(A,B))

    n = 1
    for p in P:
        if A % p == 0 and B % p == 0:
            n += 1

    print(n)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import math

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(n+1):
        if is_prime[i]:
            yield i

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

def cf(x1,x2):
    for i in range(1,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            yield i

def gcd(a,b):
    while b != 0:
        a,b = b,a%b
    return a

def prime_factorize(n):
    a = set()
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.add(n)
    return a


def solve(A: int, B: int):
    AP = prime_factorize(A)
    BP = prime_factorize(B)
    print(len(AP & BP) + 1)

    return



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()
X Y = map(int, input().split())

print(X + int(Y / 2))

### FIXED CODE ###

X, Y = map(int, input().split())

print(X + int(Y / 2))
a,b = int(input())
ls = [str(a) * b, str(b) * a]
ls.sort()
print(ls[0])

### FIXED CODE ###

a,b = map(int,input().split())
ls = [str(a) * b, str(b) * a]
ls.sort()
print(ls[0])
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n,x = list(map(int, input().split()))
pos = list(map(int, input().split()))

pos.append(x)
pos.sort()

dist = []
for i in range(len(pos)-1):
    dist.append(pos[i+1]-pos[i])

print(gcd_list(dist))

### FIXED CODE ###

import math
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n,x = list(map(int, input().split()))
pos = list(map(int, input().split()))

pos.append(x)
pos.sort()

dist = []
for i in range(len(pos)-1):
    dist.append(pos[i+1]-pos[i])

print(gcd_list(dist))
g = [[-1] * 15 for _ in range(15)]
n = int(input())
for i in range(n):
    m = int(input())
    for j in range(m):
        a, x = map(int, input().split())
        a -= 1
        g[i][a] = x
def count_ones_by_minus(num):
    count = 0
    while num:
        num &= num -1
        count += 1
    return count
for i in range(1 << n):
    for j in range(n):
        if i >> j & 1:
            d[j] = 1
    ok = True
    for j in range(n):
        if d[j]:
            for k in range(n):
                if g[j][k] == -1:
                    continue
                if g[j][k] != d[k]:
                    ok = False
        if ok:
            ans = max(ans, count_ones_by_minus(i))
    print(ans)  

### FIXED CODE ###

g = [[-1] * 15 for _ in range(15)]
n = int(input())
for i in range(n):
    m = int(input())
    for j in range(m):
        a, x = map(int, input().split())
        a -= 1
        g[i][a] = x
def count_ones_by_minus(num):
    count = 0
    while num:
        num &= num -1
        count += 1
    return count
ans = 0
for i in range(1 << n):
    d = [0] * n
    for j in range(n):
        if i >> j & 1:
            d[j] = 1
    ok = True
    for j in range(n):
        if d[j]:
            for k in range(n):
                if g[j][k] == -1:
                    continue
                if g[j][k] != d[k]:
                    ok = False
    if ok:
        ans = max(ans, count_ones_by_minus(i))
print(ans)
s = input()
t = input()

s_len = len(s)
count = 0
for i in range(s):
  if s[i] !=  t[i]:
    count += 1
print(count)

### FIXED CODE ###

s = input()
t = input()

s_len = len(s)
count = 0
for i in range(s_len):
  if s[i] !=  t[i]:
    count += 1
print(count)
o=input()
e=input()
for i in range(len(o)):
    print(o[i],end='')
    print(e[i],end='')
    

### FIXED CODE ###

o=input()
e=input()
for i in range(len(e)):
    print(o[i],end='')
    print(e[i],end='')
if len(o)>len(e):print(o[len(o)-1])
a, b = float(input().split)

print(a//b, a%b, a/b)


### FIXED CODE ###

x, y = map(int, input().split())

print(x//y, x%y, "{0:10.20f}".format(x/y))
n,s = map(int, input().split())

for x in range(n):
    for y in range(n):
        tmp = n-x-y
        tmp2 = s-x*10000-y*5000
        if tmp*1000 == tmp2:
            print(f'{x} {y} {tmp}')
            exit(0)

print('-1 -1 -1')

### FIXED CODE ###

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

for x in range(n+1):
    for y in range(n+1-x):
        tmp = n-x-y
        if (x*10000+y*5000+tmp*1000) == s:
            print('{} {} {}'.format(x,y,tmp))
            exit(0)

print('-1 -1 -1')
import sys
for e in sys.stdin:
 e=sorted(map(int,e.split(',')))
 print([['null','straight'][e[4]-e[0]==4 or e[0]*10==e[1]],'one pair','two pair','three card','full house',0,'four card'][(sum(e.count(s)for s in e)//2-2])


### FIXED CODE ###

import sys
for e in sys.stdin:
 e=sorted(map(int,e.split(',')))
 print([['null','straight'][e[0]*9<e[1]or e[4]-e[0]<5],'one pair','two pair','three card','full house',0,'four card'][sum(e.count(s)for s in e)//2-2])
S = input()
print('Heisei' if S <= 2019/4/30 else 'TBD')

### FIXED CODE ###

year, month, day = map(int, input().split("/"))
if year <= 2019 and month <= 4 and day <= 30:
    print("Heisei")
else:
    print("TBD")
x=int(input)
if x >=30:
  print("Yes")
else:
  print('No')

### FIXED CODE ###

x=int(input())
if x >=30:
  print("Yes")
else:
  print('No')
n,m=map(int,input().split())
road=[0]*n
for _ in range(m):
  a,b=map(int,input().split())
  road[a]+=1
  road[b]+=1

for i in range(n):
  print(road[i])

### FIXED CODE ###

n,m=map(int,input().split())
road=[0]*n
for _ in range(m):
  a,b=map(int,input().split())
  road[a-1]+=1
  road[b-1]+=1

for i in range(n):
  print(road[i])
N = int(input())
H = list(map(int,input().split()))
ans ="Yes"
highest = H[0]
for i in range(N-1):
    if H[i+1]<highest-1:
        ans ="No"
        break
    highest = max(highest,H[i+1])

print(ans)

### FIXED CODE ###

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

if (A+B)%2 == 0:
    print((A+B)//2)
else:
    print("IMPOSSIBLE")
input=int(x)
x=3
print (x**3)


### FIXED CODE ###

num = int(input())
print(num**3)
n, h, w = map(int, input().split())
ans = 0
for i in range(n):
    a, b = map(int, input().split())
    if a >= h and b >= w:
        ans += 1
print(ans

### FIXED CODE ###

n, h, w = map(int, input().split())
ans = 0
for i in range(n):
    a, b = map(int, input().split())
    if a >= h and b >= w:
        ans += 1
print(ans)
from numba import njit
@njit

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

if k >= 50:
    k = 50

dp = [[0] * 2 for i in range(n)]

ans = l[:]

for i in range(k):
    for j in range(n):
        tmp = ans[j] + 0.5
        dp[j][0] = (j+1 - tmp)
        dp[j][1] = (j+1 + tmp)

    ans = [0] * n

    for x in range(n):
        for y in range(n):
            if dp[y][0] <= x+1 <= dp[y][1]:
                ans[x] += 1

else:
    print(*ans)


### FIXED CODE ###

import numpy as np
from numba import njit

@njit #処理の並列化

def imos(n, a):
    
    l=np.zeros((n+1), dtype = np.int64)

    for i in range(n):
        ai = a[i] # 光の強さ_これにより照らせる範囲が決まる
        start = max(0, i - ai) #StartIndex_照らせる範囲
        end = min(n, i + ai + 1) #EndIndex + 1_照らせる範囲
        l[start] += 1 # 各々を'+1'と'-1'で表し...
        l[end] -= 1
    return np.cumsum(l)[:n] # 累積和をとる_cumulative sum

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

for _ in range(k):
    a = imos(n, a)
    if a.min() == n: # すべての要素が最大値'n'になるとbreak
        break

print(*a)
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
N = 10**4
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))

n = onem()
a =[]

for i in range(n):
    k = list(input())
    k.sort()
    a.append(k)

a.sort()
b = s(a)

co = 0

for i in range(len(b)):
    if b[i][1] != 1:
        co += cmb(b[i][1],2)
print(co)




### FIXED CODE ###

import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))

n = onem()
a =[]

for i in range(n):
    k = list(input())
    k.sort()
    a.append(k)

a.sort()
b = s(a)

co = 0

for i in range(len(b)):
    if b[i][1] != 1:
        co += cmb(b[i][1],2)
print(co)
n,k,x,y=map(int,input().split())

if n>=k:
  print(round(k*x+(n-k)*y))

else:
  print(round(k*x))
      

### FIXED CODE ###

n = int(input())
k = int(input())
x= int(input())
y= int(input())

if n>k:
  print(k*x+(n-k)*y)

else:
  print(n*x)
# ABC119B

n = int(input())

z = 0
for i in range(n):
    x, y = input().split()
    x = int(x)
    if y == 'JPY':
        z += x
    else:
        z += x*380000
print(z)


### FIXED CODE ###

# ABC119B

n = int(input())

z = 0
for i in range(n):
    x, y = input().split()
    x = float(x)
    if y == 'JPY':
        z += x
    else:
        z += x*380000
print(z)