peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
n = int(input())
res = [0] * n
for i in range(1, n):
  c, s, f = map(int, input().split())
  res[i-1] += s + c
  for j in range(i-1):
    if res[j] < s:
      res[j] = s + c
    elif res[j] == s:
      res[j] += c
    else:
      if (res[j] - s) % f == 0:
        res[j] += c
      else:
        res[j] = s + (((res[j] - s) // f) + 1) * f + c
for elem in res:
  print(elem)
# Judge status: Wrong Answer
A, B, C, X, Y = map(int, input().split())
ans = 2*(5000*10**5)
for Z in range(10**5+1):
    total = A*abs(X-Z)+B*abs(Y-Z)+2*C*Z
    ans = min(total,ans)
print(ans)
# Judge status: Accepted
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

l,r,d = readints()

ans = 0
for i in range(l,r+1):
    if i%d==0:
        ans += 1

print(ans)
# Judge status: Accepted
import math
n, x, t = list(map(int, input().split()))

print(math.ceil(n/x) * t)
# Judge status: Wrong Answer
print("YNeos"[len(set(input()))!=2::2])
# Judge status: Wrong Answer
n, p = map(int, input().split())
a = list(map(int, input().split()))

if n == 1:
    print(1 if a[0] % 2 == p else 0)
else:
    odd = [i for i in a if i % 2 == 1]
    even = [i for i in a if i % 2 == 0]
    ecnt = pow(2, len(even))
    ocnt = pow(2, max(len(odd)-1,0))
    print(ecnt * ocnt)
# Judge status: Accepted
n,k=[int(i) for i in input().split()]
if n <= k/2:
    print(n)
elif n % k == 0:
    print(0)
else:
    t1=n-(n//k*k)
    t2=abs(t1-k)
    print(min(t1,t2))
# Judge status: Wrong Answer
a, b, x = map(int, input().split())
if a + b >= x:
  print("YES")
else:
  print("NO")
# Judge status: Wrong Answer
N = list(map(int, input()))

if 7 in N:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
if N == 0 and A[0] == 1:
  print(1)
  quit()

if A[-1] == 0:
  print(-1)
  quit()

if A[0] != 0:
  print(-1)
  quit()

n = [0] * (N+1)
n[0] = 1
for i in range(1, N+1):
  a = A[i]
  m = n[i-1] * 2
  n[i] = m - a
  if n[i] < 0:
    print(-1)
    quit()

n[-1] = 0
for i in range(N-1, 0, -1):
  nn = n[i+1]
  a = A[i+1]
  n[i] = min(n[i], a + nn)

print(sum(n) + sum(A))
# Judge status: Wrong Answer
x = input()

if x == 1:
  print(0)
else:
  print(1)
# Judge status: Accepted
s = input()

if (s == "RRR"):
    print(3)
elif (s[0] == s[1] == 'R' or s[1] == s[2] == 'R'):
    print(2)
elif (s[0] == 'R' or s[1] == 'R' or s[2] == 'R'):
    print(1)
else:
    print(0)
# Judge status: Accepted
n = int(input())
s = []
five_num = []
ten_num = 0
for i in range(n):
    s.append(int(input()))
    if s[i] % 10 == 0:
        ten_num += 1
    else:
        five_num.append(s[i])

sum_s = sum(s)
if sum_s % 10 != 0:
    print(sum_s)
elif n == ten_num:
    print("0")
else:
    print(sum_s - min(five_num))
# Judge status: Wrong Answer
from sys import stdin
f_i = stdin

H, N = map(int, f_i.readline().split())

C = [10 ** 8] * (H * 2)
C[0] = 0
for line in f_i:
    A, B = map(int, line.split())
    for i, vals in enumerate(zip(C, C[A:]), start=A):
        v1, v2 = vals
        C[i] = min(v1 + B, v2)
        if i > H:
            break

print(min(C[H:]))
# Judge status: Wrong Answer
k,a,b = map(int,input().split())
if a >= b+2:
  print(k+1)
else:
  d = k-(a-1)
  e = a
  e += (b-a)*d//2
  e += d%2
  print(e)
# Judge status: Accepted
N, R = map(int, input().split())

#%%
if N >= 10:
    ans = R
else:
    ans = R + 100 * (10 - N)

print(ans)
# Judge status: Accepted
input = input().split(' ')
print(int(input[0]) * int(input[1]))
# Judge status: Accepted
import fractions
import math

a,b = map(int, input().split())

def factorize(n):#素因数分解
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append([b, e])
        b, e = b + 1, 0
    if n > 1:
        fct.append([n, 1])
    return fct

d = fractions.gcd(a, b)

l = factorize(d)

print(len(l) + 1)
# Judge status: Wrong Answer
from collections import Counter
n = int(input())
S = Counter([input() for i in range(n)])
m = int(input())
T = Counter([input() for i in range(m)])

ans = 0
for k, v in S.items():
    tmp = 0
    tmp += v
    for k2, v2 in T.items():
        if k2 == k:
            tmp -= v2
        ans = max(ans, tmp)
            
print(ans)
# Judge status: Accepted
import math
x=int(input())
print(int(math.sqrt(x))**2)
# Judge status: Accepted
print("bust" if sum(map(int, input().split())) >= 22 else "win")
# Judge status: Accepted
a,b,c = map(int,input().split(" "))
n = 0
if a % 2 == 1:
    print(0)
    exit()
if b % 2 == 1:
    print(0)
    exit()
if c % 2 == 1:
    print(0)
    exit()
if a == b == c:
  print(-1)
  exit()
for i in range(10**9):
  aa = a//2
  bb = b//2
  cc = c//2
  a = bb + cc
  b = aa + cc
  c = aa + bb
  n += 1
  if a % 2 == 1:
    break
  if b % 2 == 1:
    break
  if c % 2 == 1:
    break
print(n)
# Judge status: Wrong Answer
in_num = int(input())

if in_num % 2 == 0:
    print(-1)
    exit()
elif in_num % 5 == 0:
    print(-1)
    exit()

# 数列のスタート位置を探す
ans = 1
s = 1
while s * 7 < in_num:
    s = int(str(s) + "1")
    ans += 1

import math

while True:
    x = math.gcd(in_num, s * 7)
    if x == 1:
        s = int(str(s) + "1")
        ans += 1
    else:
        print(ans)
        exit()
# Judge status: Accepted
N = int(input())
sum = 0

for i  in range(N+1):
    sum += i

print(sum)
# Judge status: Accepted
N,K=map(int,input().split())
A=list(map(int,input().split()))
a=0
b=10**9+1
while a+1<b:
  mid=(a+b)//2
  ans=0
  for i in A:
    ans+=(i-1)//mid
  if K<ans:
    a=mid
  else:
    b=mid
print(b)
# Judge status: Wrong Answer
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
p1=min(l)
p2=max(l)
p3=min([l[i][::-1] for i in range(n)])
p4=max([l[i][::-1] for i in range(n)])
def f(a,b):
    return abs(a[0]-b[0])+abs(a[1]-b[1])
ans=0
for i in l:
    ans=max(ans,f(i,p1))
    ans = max(ans,f(i, p2))
    ans = max(ans,f(i, p3))
    ans = max(ans,f(i, p4))
print(ans)
# Judge status: Accepted
import math

N = int(input())

count = 0

for i in range(math.ceil(math.sqrt(N)))[1:]:
    if N % i == 0:
        tmp = N // i - 1
    else:
        tmp = N // i 
    count += (tmp - i) * 2 + 1
print(count)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))

two = 0
four = 0

for i in A:
    if i%4 == 0:
        four += 1
    elif i%2 == 0:
        two += 1

odd = N - two - four

if two == 1:
    odd += 1
    two = 0

if odd <= 2*four and (two == 0 or two >= 2):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())
ans = 0
d = 10
if n%2==1:
    print(0)
    import sys
    sys.exit()
while True:
    ans += n//d
    d *= 5
    if d>n:
        break
print(ans)
# Judge status: Accepted
n,x = map(int,input().split())
l = list(map(int,input().split()))
dist = [0]*(n+1)
for i in range(1,n+1):
    dist[i] = dist[i-1] + l[i-1]
    
cnt = 0
for i in range(n+1):
    if dist[i]<= x:
        cnt += 1
print(cnt)
# Judge status: Accepted
from fractions import gcd

Mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))

lm = A[0]
for a in A[1:]:
    lm = lm*a//gcd(lm,a)

ans = 0
for i in range(N):
    ans += lm//A[i]
ans %= Mod

print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
q = int(input())

cnt = {}
for i in a:
  if not i in cnt:
    cnt[i] = 0
  cnt[i] += 1
  
queries = []
for i in range(q):
  b, c = map(int, input().split())
  queries.append((b, c))

ans = sum(a)  
  
for (b, c) in queries:
  if b in cnt:
    ans -= cnt[b]*b
    ans += cnt[b]*c
    if not c in cnt:
      cnt[c] = 0
    cnt[c] += cnt[b]
    cnt[b] = 0
  print(ans)
# Judge status: Accepted
N, K, S = map(int, input().split())
if S!=10**9:
    A = [S+1]*N
    for i in range(K):
        A[i] -= 1

    for c in A:
        print(c, end=" ")
else:
    A = [1]*N
    for i in range(K):
        A[i] = S
    for c in A:
        print(c, end=" ")
# Judge status: Accepted
import collections
S = input()
cnt = 0

mod = [0]
reverse_S = S[::-1]
for i in range(len(reverse_S)):
  now = int(reverse_S[i]) * pow(10,i,2019)
  mod.append((now + mod[i]) % 2019)


c = collections.Counter(mod)
hindo = sorted(c.values(),reverse=True)
for i in hindo:
  if i != 1:
    cnt += i*(i-1)//2


print(cnt)
# Judge status: Wrong Answer
n = int(input())
ans = int(((10 ** (n - 2)) * ((n - 1) * n)) % ((10 ** 9)+ 7))
print(ans)
# Judge status: Wrong Answer
import sys
import math
import statistics
import itertools
from collections import deque

n=int(input())
#l,r,d=map(int,input().split())
lis=list(map(int,input().split()))
ans=0
for i in range(n):
    if i%2==1 and lis[i]%2==1:
        ans+=1
print(ans)
# Judge status: Wrong Answer
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())

v=b-a
w=c-b
x=d-c
y=e-d

z=max(max(v,w),max(x,y))

if z >k:
  print(':')
else:
  print('Yay!')
# Judge status: Accepted
N = int(input())
S = ["".join(sorted(input())) for i in range(N)]
d = {}
ans = 0
for s in S:
  if s in d:
    ans += d[s]
    d[s] += 1
  else:
    d[s] = 1
print(ans)
# Judge status: Wrong Answer
c, a, b = map(int, input().split())
print(c*a/2)
# Judge status: Wrong Answer
str1 = input()
str2 = input()

i = 0
for _ in str1:
  if _ not in str2:
    i += 1
print(i)
# Judge status: Accepted
n = int(input())
if n > 999: print("ABD")
else: print("ABC")
# Judge status: Wrong Answer
import math
 
a, b, h, m = map(int, input().split())
 
r = abs((h * 30 + m * 0.5) - m * 6)
if r > 180:
    r = r - 180
 
c = float(math.sqrt(float(a**2 + b**2) - float(2 * a * b) * float(math.cos(math.radians(r)))))
print(c)
# Judge status: Accepted
x,a,b = list(map(int,input().strip().split()))

if a-b >= 0:
  print("delicious")
elif a-b >= -1*x:
  print("safe")
else:
  print("dangerous")
# Judge status: Wrong Answer
k,x = map(int,input().split())
a = x - k + 1
b = x + k
c = list(range(a,b))
print(''.join(str(c)))
# Judge status: Wrong Answer
import math
n,m = map(int,input().split())
ans = math.floor((n*2+m)//4)
print(ans)
# Judge status: Accepted
N = int(input())
h = list(map(int, input().split()))

dp = [0]*N
dp[N-1], dp[N-2] = 0, abs(h[N-1] - h[N-2])
for i in range(N-3,-1,-1):
    dp[i] = min(abs(h[i] - h[i+1]) + dp[i+1], abs(h[i] - h[i+2]) + dp[i+2])
print(dp[0])
# Judge status: Wrong Answer
import math
import itertools

def calculate_distance(x1, x2):
    l2_norm = (x1[0] - x2[0])**2 + (x1[1] - x2[1])**2
    return math.sqrt(l2_norm)

N = int(input())
point = []
for i in range(N):
    a,b = map(int,input().split())
    point.append([a, b])
    

distance = 0
for a in itertools.permutations(range(N)):
    for i in range(N-1):
        distance += calculate_distance(point[i], point[i+1])
print(distance/N)
# Judge status: Accepted
N = int(input())
S = [i for i in input()]
ANS = []

for i in range(1, N+1):
    ans = 0
    A = []
    B = []
    A = list(set(S[:i]))
    B = list(set(S[i:]))
    for a in A:
        for b in B:
            if a == b:
                ans += 1
    ANS.append(ans)
print(max(ANS))
# Judge status: Accepted
import sys

n, m, *ab = map(int, sys.stdin.read().split())
graph = [set() for _ in range(n + 1)]
for a, b in zip(*[iter(ab)] * 2):
    graph[a].add(b); graph[b].add(a)

def main():
    ans = 'IMPOSSIBLE'
    for x in graph[1]:
        if n in graph[x]:
            ans = 'POSSIBLE'
            break
    print(ans)

if __name__ ==  '__main__':
    main()
# Judge status: Wrong Answer
S = str(input())
N = len(S)

def f():
    for erase in range(1, N + 1):
        new = S[0 : N - erase]
        if len(new) % 2 == 1: continue
        flg = 1
        for i in range((N - erase) // 2):
            if new[i] != new[(N - erase) // 2 + i]: flg = 0
            break
        if not flg: continue
        return len(new)

print(f())
# Judge status: Accepted
i=1
import copy
X=int(input())
s=0
while True:
    s+=copy.copy(i)
    if s>=X:
        print(i)
        exit()
    i+=1
# Judge status: Wrong Answer
n = int(input())
if n % 2 == 1:
    print(0)
else:
    n //= 2
    ans = 0
    while n > 5:
        n //= 5
        ans += n
    print(ans)
# Judge status: Accepted
a=input()
b=input()
if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
N = int(input())

ans = ''
m = 2
i = 0

while 1:
  if N % m != 0:
    ans += '1'
    N = N - (-2)**i
  else:
    ans += '0'
  m *= 2
  i += 1
  if N == 0:
    break

print(ans[::-1])
# Judge status: Accepted
h = int(input())

counter = 0
while h > 0 :
    h //= 2
    counter += 1

print(pow(2, counter) - 1)
# Judge status: Accepted
a,b,c,d = list(map(int,input().split()))

print(max(a*c,a*d,b*c,b*d))
# Judge status: Accepted
x, y = map(int, input().split())
cnt = 0
for i in range(x+1):
    for j in range(x+1):
        if i + j == x and i*2+j*4 == y:
            cnt += 1
print("Yes") if cnt > 0 else print("No")
# Judge status: Accepted
def gcd(a, b):
    if(a == 0):
        return b
    return gcd(b % a, a)
def lcm(a, b):
    return a // gcd(a, b) * b
t = int(input())
ans = 1
while(t != 0):
    t -= 1
    n = int(input())
    ans = lcm(ans, n)
print(int(ans))
# Judge status: Wrong Answer
n=int(input())

ans=""

while n!=0:
    ans+=chr(96+n%26)
    n//=26
    
print(ans[::-1])
# Judge status: Accepted
x = list(map(int,input().split()))
print(x.index(0) + 1)
# Judge status: Accepted
A,B,T=map(int,input().split())
a=T//A
print(a*B)
# Judge status: Accepted
S = input()
if S.count('A') == 3 or S.count('B') == 3:
  print('No')
else:
  print('Yes')
# Judge status: Accepted
import sys
N = int(input())

for i in range(1,10):
    if N <= int(str(i)*3):
        print(str(i)*3)
        sys.exit()
# Judge status: Wrong Answer
import math
MOD = 10**9+7
n, m = map(int, input().split())
if abs(n-m) > 1:
    print(0)
else:
    nn = math.factorial(n)%MOD
    mm = math.factorial(m)%MOD
    if n == m:
        print((nn * mm * 2) % MOD)
    else:
        print(nn * mm)
# Judge status: Accepted
S = input()
N = len(S)
A = []
for s in range(N):
    A.append(S[s])
B = []
C = []
B = A[:(N-1)//2]
C = A[(N+3)//2-1:N]
if B == C:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
k, s = map(int, input().split())

cnt = 0
for l in range(k+1):
  for m in range(k+1):
    n = s - l - m
    if 0 <= n <= k:
      cnt += 1
print(cnt)
# Judge status: Accepted
s = input().strip()
t = input().strip()

for i in range(len(s)):
    if s == t:
        print("Yes")
        exit()
    else:
        s = s[-1] + s[:-1]
print("No")
# Judge status: Accepted
N = int(input())
al = [chr(ord('a') + i) for i in range(26)]
li = ['a']
for i in range(1,N):
    k = []
    li = set(li)
    for s in li:
        count = len(set(list(s)))
        for m in range(count+1):
            nk = s+al[m]
            k.append(nk)
    li = k
n = len(li)
li.sort()
for i in range(n):
    print(li[i])
# Judge status: Wrong Answer
s = input()
count = [0, 0, 0, 1]
for i in range(len(s)):
  if s[i] == "N":
    count[0] = 1
  if s[i] == "S":
    count[1] = 1
  if s[i] == "W":
    count[2] = 1
  if s[i] == "E":
    count[3] = 1
if count[0] or count[1] or count[2] or count[3]:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
plus = lambda a,b:a+b
minus = lambda a,b:a-b

bit = 0

nums = [int(c) for c in input()]

for bit in range(8):
  op_lst = [(plus if bit >> i & 1 else minus) for i in [2,1,0]]
  temp = nums[0]
  for i in range(len(op_lst)):
    temp = op_lst[i](temp,nums[i+1])
  if temp == 7:
    break

op_strings = {plus:"+",minus:"-"}

s = str(nums[0]) + op_strings[op_lst[0]] + str(nums[1]) + op_strings[op_lst[1]] + str(nums[2]) + op_strings[op_lst[2]] + str(nums[3])

print(s)
# Judge status: Wrong Answer
N = int(input())
l = [0] * (10**5+1)
for i in range(N):
  l[i+1] = l[i]+1
  for j in range(1, N):
    if i+6**j <= N:
      l[i+6**j] = l[i]+1
    else:
      break
  for j in range(1, N):
    if i+9**j <= N:
      l[i+9**j] = l[i]+1
    else:
      break
  if l[N] > 0:
    break
  print(l)
print(l[N])
# Judge status: Wrong Answer
import numpy as np
import random

D=int(input())
c=[int(i) for i in input().split()]
s=[]
for i in range(D):
    s.append([int(j) for j in input().split()])

t=[random.randint(0, 26) for i in range(D)]

for i in range(D):
    print(t[i])
# Judge status: Accepted
n,a,b,c,d = [int(x) for x in input().split()]
s = input()

if s[a-1:c].count("##") > 0 or s[a-1:d].count("##") > 0:
    print("No")
elif d < c:
    if s[b-2:d+1].count("..."):
        print("Yes")
    else:
        print("No")
else:
    print("Yes")
# Judge status: Accepted
N = int(input())
ans = 0
for i in range(1, N+1):
  keta = 0
  n = i
  for j in range(6):
    if n > 0:
      keta += 1
    n //= 10
  if keta % 2 == 1:
    ans += 1
print(ans)
# Judge status: Accepted
def resolve():
    n,q = map(int, input().split())
    s = input()
    num = [0]*n
    k = 0
    for i in range(n):
        if i > 0:
            if s[i-1] == "A" and s[i] == "C":
                k += 1
            num[i] = k
    for i in range(q):
        l,r = map(int, input().split())
        test = num[r-1]-num[l-1]
        print(test)
resolve()
# Judge status: Accepted
a, b, c = map(int, input().split())

print(max(c - (a - b), 0))
# Judge status: Accepted
s=input()
t=input()
mini=10000
for i in range(len(s)-len(t)+1):
    cnt=0
    for j in range(len(t)):
        if s[i+j]!=t[j]:
            cnt+=1
    mini=min(mini, cnt)
print(mini)
# Judge status: Accepted
#ABC055

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

print((m-2*n)//4+n) if 2*n <= m else print(m//2)
# Judge status: Accepted
n=int(input())
s = input()
ls = len(s)
ans = 0
for i in range(1,ls+1):
    ans = max(ans, s[:i].count('I')-s[:i].count('D'))
print(ans)
# Judge status: Wrong Answer
n=int(input())
if len(set(map(int,input().split())))==n:
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
n  = int(input())
c = list(input())


rcnt = c.count('R')
wcnt = c.count('W')

ans = 0
if set(c) == {'R'} or set(c) == {'W'}:
    print(0)
else:
    cnt = 0
    for i in range(n//2):
        if c[i] == 'R':
            cnt += 1
    
    print(rcnt - cnt)
# Judge status: Accepted
import fractions

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

g = fractions.gcd(A, B)

def prime_decompose(x):
    decomposed = []
    for i in range(2,int(pow(x,0.5))+1):
        while x % i == 0:
            x //= i
            decomposed.append(i)
    if x > 1:
        decomposed.append(x)
    return decomposed

g_dec = set(prime_decompose(g))
print(len(g_dec)+1)
# Judge status: Wrong Answer
N = int(input()) 

while N > 0:
  N = N - 1000

print(N)
# Judge status: Accepted
a, b = map(int, input().split())
if a%3 and b%3 and (a+b)%3:
  print("Impossible")
else:
  print("Possible")
# Judge status: Accepted
import sys
import math
import bisect

def main():
    x, a, b = map(int, input().split())
    if -a + b <= 0:
        print('delicious')
    elif -a + b <= x:
        print('safe')
    else:
        print('dangerous')

if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
D = int(input())
C = list(map(int,input().split()))
S = [list(map(int,input().split())) for _ in range(D)]
for i in range(D):
  print(i+1)
# Judge status: Wrong Answer
a,b,c=sorted(list(map(int,input().split())))
ans=c-b
if (c-a)%2==0:
  print(ans+(c-a)//2)
else:
  print(ans+(c-a)//2+2)
# Judge status: Wrong Answer
a, b = [int(i) for i in input().split()]
A = int(a/0.08)
B = int(b/0.1)
if A == B:
  print(A)
else:
  print(-1)
# Judge status: Wrong Answer
n = int(input())
ans = ''
for i in range(30):
    r = n%2
    n = (n-r) // (-2)
    ans += str(r)
    if n==0:
        break
print(ans[::-1])
# Judge status: Accepted
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    print(a[0] // (2 ** m))
    exit()
a = list(map(lambda x: x * (-1), a))
heapq.heapify(a)
while m > 0:
    m -= 1
    i = heapq.heappop(a) * (-1)
    i //= 2
    heapq.heappush(a, i * (-1))

print(sum(a) * (-1))
# Judge status: Accepted
import numpy as np

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

print(np.floor(np.log2(y//x,dtype=np.longdouble)).astype(np.int)+1)
# Judge status: Accepted
def q3():
    N = int(input())
    from collections import deque
    S = deque()
    for _ in range(N):
        S.append(''.join(sorted(list(input()))))

    ans = 0
    d = {}  # key:文字列 value:出現回数
    for s in S:
        if s in d:
            ans += d[s]
            d[s] += 1
        else:
            d[s] = 1

    print(ans)


if __name__ == '__main__':
    q3()
# Judge status: Accepted
K = int(input())
A,B = map(int, input().split())

syou = A // K
mod = A % K

if mod == 0:
    print("OK")
    exit()
if (syou*K)+K <= B:
    print("OK")
else:
    print("NG")
# Judge status: Accepted
d = {"a":0,"b":0,"c":0}
for s in input():
  d[s] += 1
  
a,b,c = d.values()
if abs(a-b)<2 and abs(b-c)<2 and abs(c-a)<2:
  print("YES")
else:
  print("NO")
# Judge status: Wrong Answer
N = int(input())

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

a = sorted(a, reverse=True)



SUM = 0

for i in range(1, N*2, 2):
    
    SUM = SUM + a[i]
    print(SUM)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))

n2 = 0
n4 = 0

for ai in a:
  if ai % 4 == 2:
    n2 += 1
  if ai % 4 == 0:
    n4 += 1

if n4:
  n4 += 1

if n2 + n4 * 2 >= n:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
import bisect
import copy
import heapq
import sys
import itertools
import math
from functools import lru_cache
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    T = [400, 600, 800, 1000, 1200, 1400, 1600, 1800]
    i = bisect.bisect_right(T, N)
    print(9 - i)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
import collections
from collections import defaultdict

n,m=map(int,input().split())
h=[int(i) for i in input().split()]
graph=defaultdict(list)
for i in range(m):
    a,b=map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)
count=0
print(graph)
for i in graph:
  for j in graph[i]:
      if h[j-1]>=h[i-1]:
          break
  else:
      count+=1
print(count)
# Judge status: Wrong Answer
s = int(input())

if s % 10 == 9 or s / 10 == 9:
  print('Yes\n')
else:
  print('No\n')
# Judge status: Wrong Answer
def function (x):
  if x == x.upper():
    return "A"
  elif x == x.lower():
    return "a"
# Judge status: Accepted
import numpy as np

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

A = np.zeros(N,dtype=int)
A[0] = B[0]
A[-1] = B[-1]

if N == 2:
    print(A.sum())
    exit(0)

for i in range(len(B)-1):
    A[i+1] = min(B[i],B[i+1])

print(A.sum())
# Judge status: Accepted
n, m = map(int, input().split())
print(abs((n-2)*(m-2)))
# Judge status: Accepted
N, Y = map(int, input().split())

x, y, z = -1, -1, -1

for a in range(N+1):
    for b in range(N+1-a):
        if 10000*a + 5000*b + 1000*(N-a-b) == Y:
            x, y, z = a, b, N-a-b
        
print("{} {} {}".format(x,y,z))
# Judge status: Accepted
from bisect import bisect_left, bisect_right

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

a = sorted(a)
c = sorted(c)
ans = 0
for i in range(n):
    ans += (bisect_left(a, b[i])) * (n - bisect_right(c, b[i]))
print(ans)
# Judge status: Accepted
O = list(input())
E = list(input())
if len(O) == len(E) :
    pas = ['8'] * (2 * len(O))
    for i in range(len(O)) :
        pas[2*i] = O[i]
        pas[2*i + 1] = E[i]
    p = ''.join(pas)
    print(p)
else :
    pas = ['0'] * (2 * len(E) + 1)
    for i in range(len(E)) :
        pas[2*i] = O[i]
        pas[2*i +1] = E[i]
    pas[2 * len(E)] = O[-1]
    p = ''.join(pas)
    print(p)