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

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

D = 60 #10**18は60桁なので2の59乗まで見る
MAX_N = 200005 #頂点番号
to = [[0 for _ in range(MAX_N)] for _ in range(D)]

#to[i][j]:jから2^i個先の頂点
for i in range(n):
    to[0][i] = A[i]
    to[0][i] -= 1

#ダブリングの表
for i in range(D-1):
    for j in range(n):
        to[i+1][j] = to[i][to[i][j]]

v = 0
for i in range(D-1, -1, -1):
    l = 1<<i #2^i個先を見る
    if l <= k:
        v = to[i][v]
        k -= l

print(v+1)

### FIXED CODE ###

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

Town = []
#まだ訪れていない町は-1
rec = [-1] * (n+1)
idx = 1
#周期までループをまわす
while (rec[idx] == -1):
    rec[idx] = len(Town)
    Town.append(idx)
    idx = A[idx-1]

#周期前
Exce = rec[idx]
#周期内
Cycl = len(Town) - Exce

if Exce > k:
    print(Town[k])
else:
    Warp = (k - Exce) % Cycl
    print(Town[Exce+Warp])
### BUGGY CODE ###

N = int(input())
l  = []

for i in range(N):
	a = int(input())
	l.append(a)

for i in range(N):
	b = l.pop(0)
	print(max(l))
	l.append(b)

### FIXED CODE ###

N = int(input())
l  = []

for i in range(N):
	a = int(input())
	l.append(a)

l_max = max(l)
max_index = l.index(max(l))

for i in range(N):
	if i == max_index:
		b = l.pop(i)
		print(max(l))
	else:
		print(l_max)
### BUGGY CODE ###

N, M = map(int, input().split())
L = [list(input().split()) for i in range(M)]
AC = list(set([L[j][0] for j in range(M) if L[j][1] == 'AC']))
P = 0
for k in AC:
  P += L[:L.index([k, 'AC'])].count([k, 'WA'])
print(len(AC), P)

### FIXED CODE ###

N, M = map(int, input().split())
P = [0] * (N + 1)
S = [0] * (N + 1)
for i in range(M):
  x, p = input().split()
  s = int(x)
  if P[s] == 0:
    if p == 'AC':
      P[s] = 1
    else:
      S[s] += 1
A = sum([S[i] for i in range(N + 1) if P[i] == 1])
print(P.count(1), A)
### BUGGY CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
#dp[i] をiまでの最小コスト
INF = 10**9
# h.extend([INF for i in range(100)])
dp = [INF for i in range(N)]
dp[0] = 0
for i in range(N):
    for k in range(1,K+1):
        if i + k >= N:
            break
        mini = dp[i] + abs(h[i+k] - h[i])
        if dp[i + k] > mini:
            dp[i + k] = mini # i => i+k でのコストの更新
print(dp[-1])


### FIXED CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
#dp[i] をiまでの最小コスト
INF = 10**9
# h.extend([INF for i in range(100)])
dp = [INF for i in range(N)]
dp[0] = 0
for i in range(N):
    for k in range(1,K+1):
        if i + k >= N:
            break
        dp[i + k] = min(dp[i + k], dp[i] + abs(h[i+k] - h[i])) # i => i+k でのコストの更新
print(dp[N-1])
### BUGGY CODE ###

MOD = 10**9 + 7

s = input().strip()
ss = s[::-1]
rs = [10**i % 13 for i in range(6)]

n = len(s)
dp = [[0] * 13 for _ in range(n)]
for i, c in enumerate(ss):
    if i == 0:
        if c == '?':
            for j in range(10):
                dp[i][j] = 1
        else:
            dp[i][int(c)] = 1
    else:
        r = rs[i % 6]
        if c == '?':
            for j in range(13):
                for k in range(10):
                    l = (j + r * k) % 13
                    dp[i][l] += dp[i - 1][j]
                    dp[i][l] %= MOD
        else:
            for j in range(13):
                l = (j + r * int(c)) % 13
                dp[i][l] += dp[i - 1][j]
                dp[i][l] %= MOD
print(dp[n - 1][5] % MOD)

### FIXED CODE ###

MOD = 10**9 + 7

s = input().strip()
ss = s[::-1]
rs = [10**i % 13 for i in range(6)]

n = len(s)
dp = [[0] * 13 for _ in range(n)]
for i, c in enumerate(ss):
    if i == 0:
        if c == '?':
            for j in range(10):
                dp[i][j] = 1
        else:
            dp[i][int(c)] = 1
    else:
        r = rs[i % 6]
        if c == '?':
            for j in range(13):
                for k in range(10):
                    dp[i][(j + r * k) % 13] += dp[i - 1][j]
        else:
            for j in range(13):
                dp[i][(j + r * int(c)) % 13] += dp[i - 1][j]
        for j in range(13):
            dp[i][j] %= MOD
print(dp[n - 1][5] % MOD)
### BUGGY CODE ###

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


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

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

l = A[0]
for a in A:
  if l%a != 0:
    l = lcm(l, a)

B = []
for a in A:
  B.append((l//a) % MOD)

print(sum(B)%MOD)

### FIXED CODE ###

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


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


def power(n, r, mod=10**9+7):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod


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

l = A[0]
for a in A:
  t = l%a
  if t != 0:
    l = lcm(l, a)

l %= MOD
ans = 0
for a in A:
  ans += (l * power(a, MOD-2)) % MOD
  ans %= MOD

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

k = int(input())

svn = 7
cnt = 1
for i in range(10**7):
    svn %= k
    if svn == 0:
        print(cnt)
        exit()
    svn *= 10
    svn += 7
    cnt += 1
print(-1)

### FIXED CODE ###

k = int(input())

svn = 7
cnt = 1
for i in range(10**7):
    svn %= k
    if svn == 0:
        print(cnt)
        exit()
    svn *= 10
    svn += 7
    cnt += 1
print(-1)
### BUGGY CODE ###

MAX = 10**6+100
MOD = 10**9+7
fact = [0]*MAX #fact[i]: i!
inv = [0]*MAX #inv[i]: iの逆元
finv = [0]*MAX #finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
    
for i in range(2, MAX):
    fact[i] = fact[i-1]*i%MOD
    inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
    finv[i] = finv[i-1]*inv[i]%MOD

def Com(n, r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD

N, A, B, C, D = map(int, input().split())
dp = [[0]*(N+1) for _ in range(B-A+2)]
dp[0][0] = 1

for i in range(B-A+1):
    for j in range(N+1):
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= MOD
        
        for k in range(C, D+1):
            if j+(i+A)*k>N:
                break
            
            t = pow(pow(fact[i+A], k, MOD), MOD-2, MOD)*finv[k]
            dp[i+1][j+(i+A)*k] += Com(N-j, (i+A)*k)*fact[(i+A)*k]*t*dp[i][j]
            dp[i+1][j+(i+A)*k] %= MOD

print(dp[B-A+1][N])

### FIXED CODE ###

MAX = 10**6+100
MOD = 10**9+7
fact = [0]*MAX #fact[i]: i!
inv = [0]*MAX #inv[i]: iの逆元
finv = [0]*MAX #finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
    
for i in range(2, MAX):
    fact[i] = fact[i-1]*i%MOD
    inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
    finv[i] = finv[i-1]*inv[i]%MOD

def Com(n, r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD

N, A, B, C, D = map(int, input().split())
dp = [[0]*(N+1) for _ in range(B-A+2)]
dp[0][0] = 1

for i in range(B-A+1):
    for j in range(N+1):
        m = 1
        
        for k in range(min(D, (N-j)//(i+A))+1):
            if k==0 or C<=k:
                dp[i+1][j+(i+A)*k] += m*finv[k]*dp[i][j]
                dp[i+1][j+(i+A)*k] %= MOD
            
            m *= Com(N-j-(i+A)*k, i+A)
            m %= MOD
            
print(dp[B-A+1][N])
### BUGGY CODE ###

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

LR = [[0]*(N+1-i) for i in range(N+1)]
for i in range(M):
  L, R = map(int, input().split())
  for l in range(L):
    for j in range(R-l, N-l+1):
      LR[l][j] += 1

for i in range(Q):
  p, q = map(int, input().split())
  print(LR[p-1][q-p+1]-LR[q][0])


### FIXED CODE ###

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

LR = [[0]*(N+2-i) for i in range(N+2)]
for i in range(M):
  L, R = map(int, input().split())
  LR[L][R-L+1] += 1

  
for i in range(2,N+2):
  for j in range(1,N-i+2):
    LR[j][i] += LR[j][i-1] + LR[j+1][i-1] - LR[j+1][i-2]
    
for i in range(Q):
  p, q = map(int, input().split())
  print(LR[p][q-p+1]-LR[q+1][0])
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    print(A.count(i + 1))


### FIXED CODE ###

N = int(input())
s = [0 for i in range(N)]
A = list(map(int, input().split()))
for i in A:
    s[i - 1] += 1
print(*s, sep='\n')
### BUGGY CODE ###

n = int(input())
cnt = 0
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

for i in range(n - 1, -1, -1):
    if a[i] % b[i] != 0:
        r = b[i] - a[i] % b[i]
        cnt += r
        for j in range(i + 1):
            a[j] += r

print(cnt)


### FIXED CODE ###

n = int(input())
cnt = 0
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

for i in range(n - 1, -1, -1):
    r = b[i] - (a[i] + cnt) % b[i]
    if  r != b[i]:
        cnt += r
print(cnt)
### BUGGY CODE ###

n, m, L = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]
q = int(input())
st = [list(map(int, input().split())) for _ in range(q)]

d = [[float('inf') for _ in range(n)] for _ in range(n)]
for a, b, c in abc:
    if c > L:
        continue
    d[a-1][b-1] = c
    d[b-1][a-1] = c

def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            if i == k:
                continue
            for j in range(n):
                if i == j:
                    continue
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

warshall_floyd(d)

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif d[i][j] <= L:
            d[i][j] = 1
        else:
            d[i][j] = float('inf')

warshall_floyd(d)

for s, t in st:
    if d[s-1][t-1] == float('inf'):
        print(-1)
    else:
        print(d[s-1][t-1] - 1)


### FIXED CODE ###

n, m, L = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]
q = int(input())
st = [list(map(int, input().split())) for _ in range(q)]

d = [[float('inf') for _ in range(n)] for _ in range(n)]
for a, b, c in abc:
    if c > L:
        continue
    d[a-1][b-1] = c
    d[b-1][a-1] = c

def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            if i == k or d[i][k] > L:
                continue
            for j in range(n):
                if i == j:
                    continue
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

warshall_floyd(d)

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif d[i][j] <= L:
            d[i][j] = 1
        else:
            d[i][j] = float('inf')

warshall_floyd(d)

for s, t in st:
    if d[s-1][t-1] == float('inf'):
        print(-1)
    else:
        print(d[s-1][t-1] - 1)
### BUGGY CODE ###

s = input()
K = int(input())
S = set(s)
SK2 = []
for a in range(len(S)):
  mn_S = min(S)
  SK2.append(mn_S)
  idx_mnS = [i for i, x in enumerate(s[:-1]) if x==mn_S]
  for i in idx_mnS:
    for j in range(i+2, len(s)+1):
      SK2.append(s[i:j])
  SK2 = list(set(SK2))
  if len(SK2)>=K:
    break
  else:
    S.remove(mn_S)
SK2.sort()
print(SK2[K-1])

### FIXED CODE ###

s = input()
K = int(input())

S = [ss for ss in s]
S_set = list(set(S))
S_set.sort()

substring = []
for c in S_set:
  idx_c = [i for i, x in enumerate(s) if x == c]
  substring_c = []
  for x in idx_c:
    for dx in range(1, min(5, len(s)-x)+1):
      substring_c.append(s[x:x+dx])
  substring_c = list(set(substring_c))
  substring += substring_c
  if len(substring) >= 5:
    break

substring.sort()
print(substring[K-1])
### BUGGY CODE ###

from math import log2
n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
while a:
    m = a.pop()
    k = (1<<m.bit_length()) - m
    if k in a:
        a.remove(k)
        ans += 1
print(ans)


### FIXED CODE ###

from collections import Counter
n = int(input())
A = sorted(list(map(int, input().split())))[-1::-1]
c = Counter(A)
ans = 0
for a in A:
    b = (1<<a.bit_length()) - a
    if a == b and c[a] > 1:
        c[a] -= 2
        ans += 1
    elif a != b and c[a] > 0 and c[b] > 0:
        c[a] -= 1
        c[b] -= 1
        ans += 1
print(ans)
### BUGGY CODE ###

import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

MOD = 10 ** 9 + 7

N, M = list(map(int, sys.stdin.readline().split()))
X = list(map(int, sys.stdin.readline().split()))
Y = list(map(int, sys.stdin.readline().split()))


def ModInt(mod):
    class _ModInt:
        def __init__(self, value):
            self.value = value % mod

        def __add__(self, other):
            return _ModInt(self.value + other.value)

        def __mul__(self, other):
            return _ModInt(self.value * other.value)

        def __repr__(self):
            return str(self.value)

    return _ModInt


MI = ModInt(MOD)
X = np.diff(X)
Y = np.diff(Y)
X = np.array([MI(x) for x in X])
Y = np.array([MI(y) for y in Y])

#  あるエリアが何回カウントされるか
xc = np.cumsum([MI(x) for x in range(len(X), -len(X), -2)])
yc = np.cumsum([MI(y) for y in range(len(Y), -len(Y), -2)])

print(np.dot(X, xc) * np.dot(Y, yc))


### FIXED CODE ###

import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

MOD = 10 ** 9 + 7

N, M = list(map(int, sys.stdin.readline().split()))
X = list(map(int, sys.stdin.readline().split()))
Y = list(map(int, sys.stdin.readline().split()))


def ModInt(mod):
    class _ModInt:
        def __init__(self, value):
            self.value = value % mod

        def __add__(self, other):
            if isinstance(other, _ModInt):
                return _ModInt(self.value + other.value)
            else:
                return _ModInt(self.value + other)

        def __radd__(self, other):
            return self.__add__(other)

        def __mul__(self, other):
            if isinstance(other, _ModInt):
                return _ModInt(self.value * other.value)
            else:
                return _ModInt(self.value * other)

        def __truediv__(self, other):
            # TODO: 実装
            raise NotImplementedError()

        def __repr__(self):
            return str(self.value)

    return _ModInt


MI = ModInt(MOD)
X = np.diff(X)
Y = np.diff(Y)
X = np.array([MI(x) for x in X])
Y = np.array([MI(y) for y in Y])

#  あるエリアが何回カウントされるか
xc = np.arange(len(X), -len(X), -2).cumsum()
yc = np.arange(len(Y), -len(Y), -2).cumsum()

print(np.dot(X, xc) * np.dot(Y, yc))
### BUGGY CODE ###

import sys

input = sys.stdin.readline

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

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
# for i in range(1, N):
#     for j in range(1, K+1):
#         if i-j >= 0:
#             DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))

for i in range(1, N):
    DP[i] = min([chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i])) for j in range(1, K+1) if i-j >= 0])

print(int(DP[-1]))

### FIXED CODE ###

import sys
import numpy as np

input = sys.stdin.readline

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

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
"""
# 2重for文ではTLE
for i in range(1, N):
    for j in range(1, K+1):
        if i-j >= 0:
            DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))
"""
"""
# list内包表記でもTLE (2重for文よりはマシ)
for i in range(1, N):
    DP[i] = min([chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i])) for j in range(1, K+1) if i-j >= 0])
"""

DP = np.zeros(N, dtype=int)
T = np.array(T)

for i in range(1, N):
    start = max(0, i-K)
    DP[i] = min(DP[start:i] + np.abs(T[i] - T[start:i]))

print(int(DP[-1]))
### BUGGY CODE ###

from collections import deque
import numpy as np
 
 
H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)
 
for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
B=T.copy()    
d=0
c=deque() 
for i in range(H):
    for j in range(W):
         
        if T[i][j] ==1:continue

        s=0
        c+=[i,j]
        t=len(c)//2
        while t>0:
                s+=1
                t=len(c)//2
                for k in range(t):
                        m = c.popleft()
                        n = c.popleft()
                        T[m][n]=s
                        if m != H-1:
                                if T[m+1][n]==0:c+=[m+1,n]
                        if m != 0:
                                if T[m-1][n]==0:c+=[m-1,n] 
                        if n != W-1:
                                if T[m][n+1]==0:c+=[m,n+1]
                        if n != 0:
                                if T[m][n-1]==0:c+=[m,n-1]
                        #c += (chk_route([c.popleft(),c.popleft()]))
                
        #print(T)
        d = max(d,s)
        T=B.copy()
        
print(d-2)

### FIXED CODE ###

from collections import deque
import numpy as np
 
 
H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)
#T=[]
S=np.zeros_like(T,dtype=int) 
for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
#B=T.copy()    
d=0
c=deque()  
for i in range(H):
    for j in range(W):
         
        if T[i][j] ==1:continue
 
          
        c.append((i,j))
        S[i][j] = 1
        #c.append(j)
        
        #t=len(c)
        while True:

                try:
                  m,n = c.popleft()
                except IndexError: break
                
                
                for kk in [(m+1,n),(m-1,n),(m,n+1),(m,n-1)]:
                  if not (0<=kk[0]<H and 0<= kk[1] <W): continue
                  if T[kk]==1:continue
                  if S[kk] == 0:
                    c.append(kk)
                    S[kk] = S[m][n]+1        
                        
 
        #print(T)
        d = max(d,np.max(S))
        S=np.zeros_like(T,dtype=int)
        
print(d-1)
### BUGGY CODE ###

N=int(input())
T=[0]+[int(x) for x in str(input()).split()]+[0]
V=[0]+[int(x) for x in str(input()).split()]+[0]

time=0
t=[0]
for i in T:
  time+=i
  t.append(time)
ans=0

for j in range(0,2*time):
  m1=1000000000
  m2=1000000000
  t1=j/2
  t2=(j+1)/2
  for i in range(N+2):
    if t1<=t[i]:
      m1=min(m1,V[i]+(t[i]-t1))
    elif t1<=t[i+1]:
      m1=min(m1,V[i])
    else:
      m1=min(m1,V[i]+t1-t[i+1])

    if t2<=t[i]:
      m2=min(m2,V[i]+(t[i]-t2))
    elif t2<=t[i+1]:
      m2=min(m2,V[i])
    else:
      m2=min(m2,V[i]+t2-t[i+1])
    
  #print(1,m1,m2)
  ans+=0.25*(m1+m2)
print(ans)





### FIXED CODE ###

N=int(input())
T=[0]+[int(x) for x in str(input()).split()]+[0]
V=[0]+[int(x) for x in str(input()).split()]+[0]
 
time=0
t=[0]
for i in T:
  time+=i
  t.append(time)
ans=0
 
for j in range(0,2*time):
  m1=1000000000
  m2=1000000000
  t1=j/2
  t2=(j+1)/2
  for i in range(N+2):
    if t1<=t[i]:
      m1=min(m1,V[i]+(t[i]-t1))
    elif t1<=t[i+1]:
      m1=min(m1,V[i])
    else:
      m1=min(m1,V[i]+t1-t[i+1])
 
    if t2<=t[i]:
      m2=min(m2,V[i]+(t[i]-t2))
    elif t2<=t[i+1]:
      m2=min(m2,V[i])
    else:
      m2=min(m2,V[i]+t2-t[i+1])
    
  #print(1,m1,m2)
  ans+=0.25*(m1+m2)
print(ans)
### BUGGY CODE ###

from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    S = input()
    cnt = 0
    start = 0
    while start+4 < len(S):
        for i in range(start+4,len(S)+1):
            #print(S[start:i])
            if int(S[start:i]) % 2019 == 0:
                cnt += 1
        start += 1
    print(cnt)
if __name__ == '__main__':
  main()


### FIXED CODE ###

S = input()
lenS = len(S)
count = [0] * 2019
count[0] = 1
num = 0
d = 1
for i in range(lenS):
    num += int(S[lenS - i - 1]) * d
    count[num%2019] += 1
    d *= 10
    d %= 2019
ans = 0
for i in count:
    ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

n = int(input())
s = []
for i in range(n):
    p = list(input())
    p.sort()
    s.append(p)

ans = 0
for i in range(n):
    first = s[i]
    for j in range(n):
        if i >= j:
            continue
        second = s[j]
        for k in range(10):
            if first[k] == second[k]:
                if k==9:
                    ans += 1
                continue
            else:
                break


print(ans)

### FIXED CODE ###

n = int(input())
dic = {}
for i in range(n):
    p = list(input())
    p.sort()
    p = ''.join(p)
    if p in dic.keys():
        dic[p] += 1
    else:   
        dic[p] = 1

ans = 0
for i in dic.keys():
    if dic[i] == 1:
        continue
    else:
        ans += (dic[i]*(dic[i] - 1))//2

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

def main():
    x,y = map(int,input().split())
    count = num_cal(x,y)
    print(count)
    return

def num_cal(x,y):
    if x < 0 and y < 0:
        if x < y:
            swap = x
            x = y
            y = swap
    count = 0
    if x < 0:
        count += 1
        x = -x
    if -x == y:
        return count+1
    while True:
        x = x+1
        count = count+1
        if x == y:
            return count
        if -x == y:
            return count+1
    return count

if __name__ == '__main__':
    main()


### FIXED CODE ###

[x,y]=[int(i) for i in input().split(" ")]
d=[y-x]
c={-1:1,1:0}
for i in [-1,1]:
 for j in [-1,1]:
   d.append(y*i-x*j+c[i]+c[j])
c=min(i for i in d if i>0)
print(c)
### BUGGY CODE ###

N=int(input())
L=list(map(int,input().split()))
L_i=[i+1 for i in range(len(L))]

cnt=0
for i in range(N):
    X= sum([m+L[i]==x for (m,x) in zip(L[i:],range(N-i))])
    cnt = cnt + X
    
print(cnt)

### FIXED CODE ###

def main():
    N=int(input())
    L=list(map(int,input().split()))
    L_i,L_j=[],[]
    L_memo = [0]*N
    cnt=0
    for i, j in enumerate(L):
        if i+j<N:
            L_memo[i+j]+=1
        if i-j>0:
            cnt+=L_memo[i-j]        
    print(cnt)
main()
### BUGGY CODE ###

def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            if S[i] != S[j]:
                for k in range(j + 1, N):
                    if S[j] != S[k] and S[i] != S[k]:
                        if j - i != k - j:
                            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import collections


def main():
    N = int(input())
    S = input()
    RGB = ('R', 'G', 'B')
    cnt = collections.Counter(S)
    ans = cnt['R'] * cnt['G'] * cnt['B']

    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            if S[i] != S[j]:
                if 2 * j - i < N:
                    if S[2 * j - i] == RGB[3 - RGB.index(S[i]) - RGB.index(S[j])]:
                        ans -= 1

    print(ans)


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

import numpy as np

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

dp = np.array([[[0] * 3 for _ in range(s + 1)] for _ in range(n + 1)], dtype=np.int64)
dp[0][0][0] = 1

for i, e in enumerate(a):
    dp[i+1, :, 0] += dp[i, :, 0]
    dp[i+1, :, 1] += dp[i, :, 0] + dp[i, :, 1]
    dp[i+1, :, 2] += dp[i, :, 0] + dp[i, :, 1] + dp[i, :, 2]

    dp[i+1, e:, 1] += dp[i, :-e, 0] + dp[i, :-e, 1]
    dp[i+1, e:, 2] += dp[i, :-e, 0] + dp[i, :-e, 1]

    dp[i+1, :, :] %= mod

ans = dp[n][s][2]
print(ans)


### FIXED CODE ###

import numpy as np

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

dp = np.array([[0] * 3 for _ in range(s + 1)], dtype=np.int64)
dp[0][0] = 1

for i, e in enumerate(a):
    cp = dp.copy()
    dp[:, 1] += cp[:, 0]
    dp[:, 2] += cp[:, 0] + cp[:, 1]

    dp[e:, 1] += cp[:-e, 0] + cp[:-e, 1]
    dp[e:, 2] += cp[:-e, 0] + cp[:-e, 1]

    dp %= mod

ans = dp[s][2]
print(ans)