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

from math import sqrt
from decimal import *
import decimal
N=int(input())
getcontext().prec=30
"""
l=[]
pf={}
m=N
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1
print(pf)
keys=list(pf.keys())
values=list(pf.values())
for i in range(len(keys)):
    l.append([keys[i],values[i]])
print(l)
"""
a=1
while True:
    t=Decimal(1+8*a*N).sqrt()
    #print(t)
    #print(t.to_integral_value())
    n=t.to_integral_value()
    if (pow(n,Decimal(2),1+8*a*N)==0)and(int(t)%2==1):
        print((int(t)-1)//2)
        break
    a=a+1


### FIXED CODE ###

from math import sqrt
from collections import deque
def ggcd(a,b):
    if(b==0):
        return a
    return ggcd(b,a%b)
N=int(input())
def gcd_ext(a, b):
    x, y, lastx, lasty = 0, 1, 1, 0
    while b != 0:
        q = a // b
        a, b = b, a % b
        x, y, lastx, lasty = lastx - q * x, lasty - q * y, x, y
    return (lastx, lasty)
l=[]
pf={}
m=N*2
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1
#print(pf)
keys=list(pf.keys())
values=list(pf.values())
for i in range(len(keys)):
    l.append([keys[i],values[i]])
#print(l)
d=deque()
d.append([])

for i in range(len(l)):
    x=list(range(values[i]+1))
    d2 = deque()
    #print(x)
    while len(d)>0:
        l=d.popleft()
        for j in x:
            l2=l[:]
            l2.append(j)
            d2.append(l2)
    d=d2
    #print(d)
ans=float("inf")
x=0
y=0
while len(d)>0:
    l=d.popleft()
    num=1
    res=1
    for i in range(len(l)):
        num=num*pow(keys[i],l[i])
        res=res*pow(keys[i],values[i]-l[i])
    #print(num,res)
    #x*num=k+1のときを考える
    if ggcd(num,res)==1:
        #x*num+y*res=1
        x,y=gcd_ext(num,res)
        if (x==0)or(y==0):
            x1=x+num*res
            y1=y+num+res
            ans=min(ans,x1*num-1)
            x2=x-num*res
            y2=x-num*res
            ans=min(ans,-x2*num)
        else:#どっちかは+でどっちかは-
            if x>y:
                ans=min(ans,x*num-1)
                x1=x-num*res
                ans=min(ans,-x1*num)
            else:
                x1=x+num*res
                ans=min(ans,x1*num-1)
                ans=min(ans,-x*num)
print(ans)
### BUGGY CODE ###

import numpy as np
N,K = map(int,input().split())
a = list(map(int,input().split()))
res = [val for val in a]
for k in range(K):
    delta = [0]*(N+1)
    for i,val in enumerate(res):
        left = max(0, i-val)
        right = min(N-1, i+val)
        delta[left] += 1
        delta[right+1] -= 1
    res = list(np.cumsum(delta, dtype=np.int32))[:N]
    if sum(res) == N**2:
        break
print(*res)



### FIXED CODE ###

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

for k in range(K):
    delta = [0]*(N+1)
    for i,val in enumerate(res):
        left = max(0, i-val)
        right = min(N, i+val+1)
        delta[left] += 1
        delta[right] -= 1
    res = [0]*N
    res[0] = delta[0]
    for i in range(N-1):
        res[i+1] = res[i]+delta[i+1]
    if delta[0] == -delta[N] == N:
        break

print(*res)
### BUGGY CODE ###

n = int(input())

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

multiplicacao = 1

asdsd = True

for x in numeros:
    multiplicacao *= x
    
    
if multiplicacao > 1e18:
    print(-1)
    
else:
    print(multiplicacao)


### FIXED CODE ###

from functools import reduce

n = int(input())

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

sim = False
if 0 in numeros:
    print(0)

else:

    multiplicacao = 1

    for i in numeros:
        multiplicacao *= i
        if multiplicacao > 1e18:
            print(-1)
            sim = True
            break
    if sim == False:
        print(multiplicacao)
### BUGGY CODE ###

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

w, v = [0] * N, [0] * N

for i in range(N):
    w[i], v[i] = map(int, input().split())

def r(i, g):
    if i == N:
        return 0
    elif g < w[i]:
        return r(i + 1, g)
    else:
        return max(r(i + 1, g - w[i]) + v[i], r(i + 1, g))

print(r(0, W))

### FIXED CODE ###

N, W = map(int, input().split())
w, v = [0] * N, [0] * N

for i in range(N):
    w[i], v[i] = map(int, input().split())

memo = {i:{} for i in range(N)}

def r(i, g):
    global memo
    if i == N:
        return 0
    elif g in memo[i]:
        return memo[i][g]
    elif g < w[i]:
        a = r(i + 1, g)
    else:
        a = max(r(i + 1, g - w[i]) + v[i], r(i + 1, g))
    
    memo[i][g] = a
    return a

print(r(0, W))
### BUGGY CODE ###

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S=list(input())
N=len(S)

def rec(cur):
    global cnt
    if cur+2<N:
        if S[cur]=='A' and S[cur+1]=='B' and S[cur+2]=='C':
            S[cur]='B'
            S[cur+1]='C'
            S[cur+2]='A'
            cnt+=1
            rec(cur+2)
i=N-1
cnt=0
while i>=0:
    if i-2>=0:
        if S[i-2]=='A' and S[i-1]=='B' and S[i]=='C':
            S[i-2]='B'
            S[i-1]='C'
            S[i]='A'
            cnt+=1
            rec(i)
    i-=1
print(cnt)


### FIXED CODE ###

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S=list(input())
N=len(S)

cnt=cnta=0
i=0
while i<N:
    if S[i]=='A':
        cnta+=1
    else:
        cnta=0
    if i+2<N:
        if S[i]=='A' and S[i+1]=='B' and S[i+2]=='C':
            cnt+=cnta
            S[i]='B'
            S[i+1]='C'
            S[i+2]='A'
            i+=2
            cnta-=1
            continue
    i+=1
print(cnt)
### BUGGY CODE ###

import bisect
n,m=map(int, input().split())
a=sorted(map(int, input().split()))
for i in range(m):
    x,y=map(int, input().split())
    t=bisect.bisect_left(a,y)
    a=a[:t]+[y]*x+a[t:]
    a=a[-n:]
print(sum(a))

### FIXED CODE ###

from collections import Counter
n,m=map(int, input().split())
a=list(map(int, input().split()))
c=Counter(a)
for i in range(m):
    x,y=map(int, input().split())
    c[y]+=x
ans=0
for i in sorted(c, reverse=True):
    if n>c[i]:
        ans+=c[i]*i
        n-=c[i]
    else:
        ans+=n*i
        n=0
    if n<=0:break
print(ans)
### BUGGY CODE ###

def C_GreenBin():
    N = int(input())
    s = []
    for x in range(N):
        s.append(sorted(input()))
    result = 0
    for x in range(N):
        s.sort()
    for i in range(0, N - 1):
        for j in range(i + 1, N):
            if s[i] == s[j]:
                result += 1
            else:
                break
    print(result)
    
if __name__ == "__main__":
    C_GreenBin()

### FIXED CODE ###

def C_GreenBin():
    from collections import Counter
    N = int(input())
    s = []
    for x in range(N):
        list_tmp = sorted(input())
        s.append("".join(list_tmp))
    result = 0
    s_tmp = Counter(s)
    for x in s_tmp.values():
        if x > 1:
            result += ((x - 1) * x) // 2
    print(result)
    
if __name__ == "__main__":
    C_GreenBin()
### BUGGY CODE ###

H, W, M = map(int, input().split())
h_t = [0]*H
w_t = [0]*W
t = []
for i in range(M):
    h, w = map(int, input().split())
    t.append((h-1, w-1))
    h_t[h-1]+=1
    w_t[w-1]+=1
h_max = max(h_t)
h_max_list = [i for i, v in enumerate(h_t) if v == h_max]
w_max = max(w_t)
w_max_list = [i for i, v in enumerate(w_t) if v == w_max]

for h in h_max_list:
    for w in w_max_list:
        if (h, w) not in t:
            print(h_max + w_max)
            exit()
print(h_max + w_max - 1)

### FIXED CODE ###

import numpy as np

H, W, M = map(int, input().split())
h_t = [0]*H
w_t = [0]*W
t = {}
for i in range(M):
    h, w = map(int, input().split())
    t[(h-1, w-1)] = 1
    h_t[h-1]+=1
    w_t[w-1]+=1
h_max = max(h_t)
h_max_list = [i for i in range(len(h_t)) if h_t[i] == h_max]
w_max = max(w_t)
w_max_list = [i for i in range(len(w_t)) if w_t[i] == w_max]

for h in h_max_list:
    for w in w_max_list:
        if (h, w) not in t:
            print(h_max + w_max)
            exit()
print(h_max + w_max - 1)
### BUGGY CODE ###

import sys

H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]

dp = [0] * (H + 1)

for x in range(1, H + 1):
    dp[x] = min(dp[max(x - damage, 0)] + cost for damage, cost in magic)

print(dp[H])

### FIXED CODE ###

H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]

max_damage = max(damage for damage, cost in magic)
dp = [0] * (H + max_damage)

for x in range(1, H + max_damage):
    dp[x] = min(dp[x - damage] + cost for damage, cost in magic)

print(min(dp[H:]))
### BUGGY CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    N, *A = map(int, read().split())
    dic = defaultdict(lambda:0)
    for a in A:
        dic[a] += 1
    G = {}

    for key in sorted(list(dic.keys())):
        G[N] = key
        N -= dic[key]

    criteria = 0
    for key in G.keys():
        for _ in range(G[key]):
            criteria ^= key

    if not criteria:
        print('second')
    else:
        print('first')
if __name__ == "__main__":
    run()


### FIXED CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    N, *A = map(int, read().split())
    dic = defaultdict(lambda:0)
    for a in A:
        dic[a] += 1
    G = {}

    for key in sorted(list(dic.keys())):
        G[N] = key
        N -= dic[key]

    criteria = 0
    for key in G.keys():
        if G[key] % 2:
            criteria ^= key

    if not criteria:
        print('second')
    else:
        print('first')
if __name__ == "__main__":
    run()
### BUGGY CODE ###

def ex(x):
    s = 0
    p = 1/x
    for i in range(1, x+1):
        s = s + p*i
    return s

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

m = 0
px = list(map(ex, p))

for j in range(n-k+1):
    sum = 0
    for i in range(j, j+k):
        sum = sum + px[i]
    m = max(sum, m)

print(m)

### FIXED CODE ###

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

temp= sum(p[:k])
ans = temp

for i in range(n-k):
    temp = temp - p[i]
    temp = temp + p[i+k]
    ans = max(temp, ans)
    
ans = (ans+k) / 2

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

import numpy as np
n=int(input())
s=list(input())
sr=[0]*n
sg=[0]*n
sb=[0]*n
for ii in range(n):
    if s[ii]=="R":
        sr[ii]=1
    if s[ii]=="G":
        sg[ii]=1
    if s[ii]=="B":
        sb[ii]=1

r=0
"""
print(sr)
print(sg)
print(sb)
"""
for ii in np.arange(1,n+1):
  for jj in np.arange(ii+1,n+1):
    if s[ii-1]!=s[jj-1] and jj<n:
        kk=2*jj-ii-1
        if (s[ii-1]=="R" and s[jj-1]=="G") or (s[jj-1]=="R" and s[ii-1]=="G"):
            r+=sum(sb[jj+1-1:n])
            if kk<n:
                r-=sb[kk]
        if (s[ii-1]=="R" and s[jj-1]=="B") or (s[jj-1]=="R" and s[ii-1]=="B"):
            r+=sum(sg[jj+1-1:n])
            if kk<n:
                r-=sg[kk]
        if (s[ii-1]=="B" and s[jj-1]=="G") or (s[jj-1]=="B" and s[ii-1]=="G"):
            r+=sum(sr[jj+1-1:n])
            if kk<n:
                r-=sr[kk]
        """
      for kk in np.arange(jj+1,n+1):
        #print(ii,jj,kk)
        if jj-ii!=kk-jj:
          if s[jj-1]!=s[kk-1] and s[ii-1]!=s[kk-1]:
            r+=1
        """
print(r)
    

### FIXED CODE ###

import numpy as np
n=int(input())
s=list(input())
sr=set()
sg=set()
sb=set()
for ii in range(n):
    if s[ii]=="R":
        sr.add(ii)
    if s[ii]=="G":
        sg.add(ii)
    if s[ii]=="B":
        sb.add(ii)
l=[len(sr),len(sg),len(sb)]
l.sort()

if l[0]==len(sr):
  s1=sr
  if l[1]==len(sg):
    s2=sg
    s3=sb
  else:
    s2=sb
    s3=sg
elif l[0]==len(sg):
  s1=sg
  if l[1]==len(sr):
    s2=sr
    s3=sb
  else:
    s2=sb
    s3=sr
else:
  s1=sb
  if l[1]==len(sr):
    s2=sr
    s3=sg
  else:
    s2=sg
    s3=sr
  
r=0
for ii in s1:
  for jj in s2:
    r+=len(s3)
    dt=abs(ii-jj)
    if ii+dt in s3:
      r-=1
    if ii-dt in s3:
      r-=1
    if jj+dt in s3:
      r-=1
    if jj-dt in s3:
      r-=1
    if (ii+jj)%2==0:
      if (ii+jj)//2 in s3:
        r-=1
      
print(r)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
import copy
for i in range(10**4):
  a.sort()
  wari=a[-2]
  if wari==0:
    print(a[-1])
    break
  a[-1]=a[-1]%wari
  



### FIXED CODE ###

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

def gcd(a,b):
  aa=max(a,b)
  bb=min(a,b)
  cc=aa%bb
  return gcd(bb,cc) if cc else bb
  
p=gcd(a[0],a[1])
for i in range(2,n):
  p=gcd(p,a[i])
print(p)
### BUGGY CODE ###

S = input()
N = len(S)

ans=0
for i in range(N):
    for j in range(i+4,N+1):
        if int(S[i:j])%2019==0:
            #print("i,j=>",i,j)
            #print(S[i:j])
            ans+=1
print(ans)





### FIXED CODE ###

from collections import defaultdict
S = input()
N = len(S)

DP=[0]*(N+1)
for i,s in enumerate(reversed(S)):
    DP[i+1]=(DP[i]+pow(10,i,2019)*int(s))%2019

D=defaultdict(int)
for dp in DP:
    D[dp]+=1

ans=0
for dp in D.values():
    ans += dp*(dp-1)//2

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

N,K = map(int,input().split())
max_total = 0
p = list(map(int,input().split()))
for i in range(N-K+1):
  total = sum(p[i:i+K])
  if total >= max_total:
    max_total = total
    res = 0
    for j in range(i,i+K):

      res += (p[j]+1)/2
      
print(res)

### FIXED CODE ###

N,K = map(int,input().split())
max_total = 0
res = 0
p = list(map(int,input().split()))
for _ in range(len(p)):
  p[_] = (p[_]+1)/2
  
total = sum(p[0:K])
max_total = total
for i in range(K,N):
  if p[i] > p[i-K]:
    total = total + p[i] - p[i-K]
    max_total = max(max_total,total)
  else:
    total = total + p[i] - p[i-K]

print(max_total)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = str(input())

l_list = []
r_list = []

for x in range(Q):
    l, r = map(int, input().split())
    sub_str = S[l-1:r]
    ac_count = 0
    
    for i in range(len(sub_str) - 1):
        if sub_str[i:i+2] == 'AC':
            ac_count += 1
    
    print(ac_count)
    
    




### FIXED CODE ###

N, Q = map(int, input().split())
S = str(input())

l_list = []
r_list = []

s_count = [0]
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        s_count.append(1)
    else:
        s_count.append(0)
#print(s_count)

n_count = []
n_sum = 0
for n in s_count:
    n_sum = n_sum + n
    n_count.append(n_sum)

#print(n_count)


for x in range(Q):
    l, r = map(int, input().split())
    ans = n_count[r-1] - n_count[l-1]
    print(ans)
### BUGGY CODE ###

from collections import deque
n,m,k=map(int,input().split())
fr=[[]]
bl=[[]]
for i in range(n-1):
  fr.append([])
  bl.append([])
for i in range(m):
  a,b=map(int,input().split())
  fr[a-1].append(b)
  fr[b-1].append(a)
for i in range(k):
  a,b=map(int,input().split())
  bl[a-1].append(b)
  bl[b-1].append(a)

def bfs(k):
  use=deque()
  use.append(k)
  ans=0
  aldic={}
  for i in range(1,n+1):
    aldic[i]=0
  for x in bl[k-1]:
    aldic[x]=-1
  for i in range(0,10**100):
    if not bool(use):
      if k!=n:
        print(ans-len(fr[k-1])-1,end=" ")
      else:
        print(ans-len(fr[k-1])-1)
      break
    else:
      check=use.popleft()
      if aldic[check]==0:
        aldic[check]=1
        for x in fr[check-1]:
          if aldic[x]!=1:
            use.append(x)
        ans+=1
      elif aldic[check]==-1:
        for x in fr[check-1]:
          if aldic[x]!=1:
            use.append(x)
for i in range(1,n+1):
  bfs(i)

### FIXED CODE ###

from collections import deque
n,m,k=map(int,input().split())
fr=[[]]
for i in range(n-1):
  fr.append([])
for i in range(m):
  a,b=map(int,input().split())
  fr[a-1].append(b)
  fr[b-1].append(a)

belong=[0]*n
anslist=[0]*n
count=0
def bfs(k):
  global count
  if belong[k-1]==0:
    count+=1
    use=deque()
    use.append(k)
    ans=0
    aldic={}
    while use:
      if not bool(use):
        break
      else:
        check=use.popleft()
        if check not in aldic:
          aldic[check]=1
          for x in fr[check-1]:
            use.append(x)
    for x in aldic:
      belong[x-1]=count
      anslist[x-1]=len(aldic)-len(fr[x-1])-1

for i in range(1,n+1):
  bfs(i)
for i in range(k):
  a,b=map(int,input().split())
  if belong[a-1]==belong[b-1]:
    anslist[a-1]-=1
    anslist[b-1]-=1
for i in range(0,len(anslist)):
  if i!=len(anslist)-1:
    print(anslist[i],end=" ")
  else:
    print(anslist[i])
### BUGGY CODE ###

n,k = map(int, input().split())
a = list(map(int,input().split()))
ans = [0]*(n+1)
ans[0] = 1
p = 1
for i in range(n):
    ans[i+1] = ans[i]*a[i]
#print(ans)
for j in range(n-k):
    #print(ans[k]//ans[j],ans[k+1]//ans[j+1])
    if ans[k+j]//ans[j] < ans[k+j+1]//ans[j+1]:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

n,k = map(int, input().split())
a=list(map(int,input().split()))
for i in range(n-k):
    #print(i,k+i)
    if a[i] < a[k+i]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

import numpy as np

n, m = map(int, input().strip().split())
full_mask = 0
for i in range(n):
    full_mask |= 0b1 << i

key_costs = []
box = []
for i in range(m):
    a, b = map(int, input().strip().split())
    c = np.array(list(map(int, input().strip().split()))) - 1
    key_costs.append(a)
    box_mask = 0b0
    for i in c:
        box_mask |= 0b1 << i
    box.append(box_mask)

arr = [-2] * (1 << n)
arr[0] = 0
def calc_min_cost(mask, memo):
    if memo[mask] >= -1:
        return memo[mask]
    
    costs = []
    for idx in range(len(key_costs)):
        if mask & box[idx] == 0:
            continue
        submask = mask & ~box[idx]
        c = calc_min_cost(submask, memo)
        if c == -1:
            costs.append(-1)
        else:
            costs.append(key_costs[idx] + c)

    costs = np.array(costs)
    feasible_costs = costs[costs >= 0]
    if feasible_costs.size == 0:
        memo[mask] = -1
    else:
        memo[mask] = min(feasible_costs)
    
    return memo[mask]

print(calc_min_cost(full_mask, arr))

### FIXED CODE ###

n,m = input().split(' ')
n = int(n)
m = int(m)
dp = [float('inf')]*2**n
dp[0] = 0
for i in range(m):
    a,b = input().split(' ')
    a = int(a)
    b = int(b)
    ngo = 0
    for j in input().split(' '):
        ngo += 2**(int(j)-1)
    for j in range(2**n):
        if dp[j|ngo] > dp[j]+a:
            dp[j|ngo] = dp[j]+a
    
if dp[2**n-1] == float('inf'):
    print(-1)
    exit(0)
print(dp[2**n-1])
### BUGGY CODE ###

k = int(input())

li = []

for i in range(k):
    li.append(int('7'*(i+1)) % k)
count = -1
for i in range(k):
    if(li[k-i-1] == 0):
        count = k-i

print(count)


### FIXED CODE ###

k = int(input())

ans = -1
memo = 7 % k
a = 7 % k
for i in range(k):
    if a == 0:
        ans = i+1
        break
    a = (10*a+7) % k
print(ans)
### BUGGY CODE ###

import sys
import math
sys.setrecursionlimit(1000000000)

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        sys.exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#ABC138 E

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
t = input()
n = len(s)
m = len(t)
f = [False]*26
f2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(n):
    f[alpha.index(s[i])] = True
for i in range(m):
    f2[alpha.index(t[i])] = True
for i in range(26):
    if not f[i] and f2[i]:
        print(-1)
        quit()
ans = 0
inde = s.index(t[0])
ans += inde+1
for i in range(1,m):
    s = s[inde+1:] + s[:inde+1]
    inde = s.index(t[i])
    ans += inde+1
print(ans)
### BUGGY CODE ###

import sys
import bisect
input=sys.stdin.readline

N=int(input())
A=[int(input()) for _ in range(N)]
l=[]
n=-1
for x in A:
    if n<x:
        n=x
    elif len(l)>0:
        tmp=bisect.bisect_left(l,x)
        if tmp==0:l=[x]+l
        else:
            l[tmp-1]=x
    else:l.append(x)
print(len(l)+1)

### FIXED CODE ###

import sys
import bisect
input=sys.stdin.readline

N=int(input())
A=[-int(input()) for _ in range(N)]
l=[A[0]]
for x in A[1::]:
    tmp=bisect.bisect(l,x)
    if tmp==len(l):l.append(x)
    else: l[tmp]=x
print(len(l))
### BUGGY CODE ###

# AGC005A

# TLE 2/13
x = input()
while 'ST' in x:
    x = x.replace('ST', '', 1)
print(len(x))


### FIXED CODE ###

x = input()
while 'ST' in x:
    x = x.replace('ST', '')
    n = len(x) // 2
    if ('T' not in x[:n]) and ('S' not in x[n:]):
        x = ''
        break
print(len(x))
### BUGGY CODE ###

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

for i in(range(1,N+1)):
    print(A.count(i))    


### FIXED CODE ###

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

from collections import Counter

cnt = Counter(A)

for i in(range(1,N+1)):
    print(cnt[i])
### BUGGY CODE ###

import sys


def main():
    readline = sys.stdin.readline
    N = int(readline())
    li = []
    for _ in range(N):
        S = readline()
        if S not in li:
            li.append(S)
    print(len(li))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


def main():
    readline = sys.stdin.readline
    N = int(readline())
    se = set([readline() for _ in range(N)])
    print(len(se))


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

N = int(input())
my_list = [None] * N
for i in range(N):
    s_i = sorted(input())
    my_list[i] = s_i
sum = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        for k in range(10):
            if not(my_list[i][k] == my_list[j][k]):
                break
            elif k == 9:
                sum += 1
print(sum)


### FIXED CODE ###

n = int(input())
dict = {}
ans = 0

for i in range(n):
    s = str(sorted(input()))
    if s in dict.keys():
        ans += dict[s]
        dict[s] += 1
    else:
        dict[s] = 1
print(ans)