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

n,m = map(int,input().split())
li = list(map(int,input().split()))
road = []
while True:
    try:
        road.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

#print(road)
cnt = 0
for i in range(len(li)):
    t = 0
    for j in range(len(road)):
        if road[j][0]==i+1:
            if li[road[j][1]-1]>=li[i]:
                t=1
        elif road[j][1]==i+1:
            if li[road[j][0]-1]>=li[i]:
                t=1
    #print(t)
    if t == 0:
        cnt += 1
print(cnt)

### FIXED CODE ###

n,m = map(int,input().split())
li = list(map(int,input().split()))
road = []
while True:
    try:
        road.append(list(map(int,input().split())))
 
    except:
        break;
        #または、quit(),os.exit()をして止める。
 
#print(road)

x = [0]*n
for i in range(m):
    if li[road[i][1]-1]>=x[road[i][0]-1]:
        x[road[i][0]-1]=li[road[i][1]-1]
    if li[road[i][0]-1]>=x[road[i][1]-1]:
        x[road[i][1]-1]=li[road[i][0]-1]
    
cnt = 0    
for i in range(n):
    if li[i]>x[i]:
        cnt += 1
#print(x)
#print(li)
print(cnt)
### BUGGY CODE ###


import numpy as np
X, Y, A, B, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

A = A[0:X]
B = B[0:Y]
C = np.array(C)

arr = A+B
_min = min(arr)
C = C[C>_min]

for c in C:
  _min = min(arr)
  if c >= _min:
    arr[arr.index(_min)] = c

print(sum(arr))

### FIXED CODE ###

import numpy as np
X, Y, A, B, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

A = A[0:X]
B = B[0:Y]
D = A+B+C

D.sort(reverse=True)

D = D[0:X+Y]
print(sum(D))
### BUGGY CODE ###

from collections import deque
import numpy as np
N = int(input())
A = [int(input()) for _ in range(N)]

# d = deque()
R = deque(A)
R.append(0)
L = deque([0])

maxA = np.max(R)
for i in A:
  R.popleft()
  if i >= maxA: 
    maxA = max(np.max(L), np.max(R))
  print(maxA)
  L.append(i)
  

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
B = A[:]
B.sort(reverse=True)
# print(A)
fmax = B[0]
smax = B[1]
for i in A:
  if i == fmax:
    print(smax)
  else:
    print(fmax)
### BUGGY CODE ###

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

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

tgcd = gcd_list(A)
if tgcd != 1:
  print('not coprime')
  exit()

for i,a in enumerate(A[:-1]):
  for a2 in A[i+1:]:
    if math.gcd(a,a2) != 1:
      print('setwise coprime')
      exit()
print('pairwise coprime')

### FIXED CODE ###

import math
from functools import reduce

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

N=int(input())
A=list(map(int,input().split()))
mA = max(A)
D = [-1]*(mA+1)
D[0]=1
D[1]=1
for i in range(2,mA+1):
  if D[i] != -1: continue
  D[i] = i
  cnt = 2*i
  while cnt < mA+1:
    if D[cnt] == -1:
      D[cnt]=i
    cnt += i
done = set()
for a in A:
  tmp = set()
  while a > 1:
    tmp.add(D[a])
    a //= D[a]
  if len(done&tmp) > 0:
    if gcd_list(A) == 1: print('setwise coprime')
    else: print('not coprime')
    exit()
  done |= tmp
print('pairwise coprime')
### BUGGY CODE ###

import sys

input = sys.stdin.readline
N, M = map(int, input().split())

import bisect

ABs = [[] for _ in range(M + 1)]
for i in range(N):
    A, B = map(int, input().split())
    if A <= M:
        ABs[A].append(B)
ABs[0].sort()

As = 0
for i in range(M + 1):
    if i > 0:
        for b in ABs[i]:
            bisect.insort_left(ABs[0], b)
    if len(ABs[0]) > 0:
        As += ABs[0].pop(-1)
print(As)

### FIXED CODE ###

import sys

input = sys.stdin.readline
N, M = map(int, input().split())

import bisect

ABs = [[] for _ in range(M + 1)]
for i in range(N):
    A, B = map(int, input().split())
    if A <= M:
        ABs[A].append(B)
ABs[0].sort()

As = 0
for i in range(M + 1):
    if i > 0:
        for b in ABs[i]:
            bisect.insort_left(ABs[0], b)
    if len(ABs[0]) > 0:
        As += ABs[0].pop()
print(As)
### BUGGY CODE ###

n = int(input()) #長さ
s = str(input()) #文字列
cnt = 0 #暗証番号数
 
for a in range(10): #1文字目
  for b in range(10): #2文字目
    for c in range(10): #3文字目
        flg = False
        for i in range(n-2):
            if str(a) == s[i]:
                tmp_i = i + 1
                for j in range(tmp_i,n-1):
                    if str(b) == s[j]:
                        tmp_i = j + 1
                        for k in range(tmp_i,n):
                            if str(c) == s[k]:
                                cnt = cnt + 1
                                flg = True
                                break
                        else:
                        	break
                        if flg:
                            break
                if flg:
                    break
            
print(cnt)

### FIXED CODE ###

n = int(input()) #長さ
s = str(input()) #文字列
cnt = 0 #暗証番号数

for a in range(10): #1文字目
  for b in range(10): #2文字目
    for c in range(10): #3文字目
      flg = False
      check_a = s.find(str(a))
      if check_a != -1:
        tmp_s = s[check_a + 1:]
        check_b = tmp_s.find(str(b))
        if check_b != -1:
          tmp_t = tmp_s[check_b + 1:]
          check_c = tmp_t.find(str(c))
          if check_c != -1:
            cnt = cnt + 1            
print(cnt)
### BUGGY CODE ###

N = int(raw_input())
X = [map(int, raw_input().split()) for i in range(N)]

def update(n, x):
    t, a = x
    n1, n2 = n
    c = 1
    for i in xrange(10**18):
        if i * t >= n1 and i * a >=n2:
            c = i
            break
    return c * t, c* a

n = (1, 1)
for x in X:
    n = update(n, x)
print(sum(n))


### FIXED CODE ###

N = int(raw_input())
X = [map(int, raw_input().split()) for i in range(N)]

def update(n, x):
    t, a = x
    n1, n2 = n
    c = 1
    i0 = max(n1/t, n2/a)
    for i in xrange(i0, 10**18):
        if i * t >= n1 and i * a >=n2:
            c = i
            break
    return c * t, c* a

n = (1, 1)
for x in X:
    n = update(n, x)
print(sum(n))
### BUGGY CODE ###

def main():
    s = input()
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        temp = (int(s[-(1+i)])*10**i) % 2019 
        r[i] = (temp+r[i-1])%2019
 
    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    if cts[0]>0:
        ans+=1
 
    print(ans)
main()

### FIXED CODE ###

def main():
    s = list(map(int, list(input())))
    r = [0]*len(s)
    r[0] = int(s[-1])
    for i in range(1,len(s)):
        temp = s[-(1+i)]*pow(10,i,2019)
        r[i] = (temp+r[i-1])%2019

    ans = 0
    cts = [0]*2019
    for i in r:
        ans+=cts[i]
        cts[i]+=1
    
    ans+=cts[0]

    print(ans)

main()
### BUGGY CODE ###

import sys
readline = sys.stdin.readline
N, Q = map(int, readline().split())

data = [0]*(N+2)
def add(k, x):
    while k <= N:
        data[k] += x
        k += k & -k
def get(k):
    s = 0
    while k > 0:
        s += data[k]
        k -= k & -k
    return s
N0 = 2**(N-1).bit_length()
def lower_bound(x):
    w = i = 0
    k = N0
    while k:
        if i+k <= N+1 and w + data[i+k] <= x:
            w += data[i+k]
            i += k
        k >>= 1
    return i+1

P = [list(map(int, readline().split())) for i in range(N)]
S = sorted(set(x for s, t, x in P))
mp = {e: i for i, e in enumerate(S)}
D = [int(readline()) for i in range(Q)]
que = []
for s, t, x in P:
    y = mp[x]
    que.append((s-x, y, 1))
    que.append((t-x, y, -1))
que.sort()
ans = []
i = 0
for d in D:
    while i < 2*N and que[i][0] <= d:
        _, j, f = que[i]
        add(j+1, f)
        i += 1
    k = lower_bound(0)
    if k == N+2:
        ans.append("-1\n")
    else:
        ans.append("%d\n" % S[k-1])
sys.stdout.writelines(ans)

### FIXED CODE ###

from heapq import heappush, heappop
import sys
from __pypy__ import builders
readline = sys.stdin.readline
N, Q = map(int, readline().split())
qs = [0]*N
for i in range(N):
    s, t, x = map(int, readline().split())
    qs[i] = (s-x, t-x, x)
qs.sort()

b = builders.StringBuilder(Q)
que = []
D = [int(readline()) for i in range(Q)]
j = 0
for d in D:
    while j < N and qs[j][0] <= d:
        s, t, x = qs[j]
        heappush(que, (x, t))
        j += 1
    while que and que[0][1] <= d:
        heappop(que)
    if que:
        b.append("%d\n" % que[0][0])
    else:
        b.append("-1\n")
sys.stdout.write(b.build())
### BUGGY CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
now=[[0,0] for i in range(n)]
day,sumsiai=0,0
end=n*(n-1)//2
nex,minusnex=0,0
while 1:
    day+=1
    siaisuu=sumsiai
    for i in range(n):
        if now[i][0]==n-1 or now[i][1] == day:
            continue
        nex=a[i][now[i][0]]
        minusnex=nex-1
        if i+1==a[nex-1][now[minusnex][0]] and now[minusnex][1] != day:
            siaisuu+=1
            now[i][0]+=1
            now[i][1],now[minusnex][1]=day,day
            now[minusnex][0]+=1
    if siaisuu-sumsiai==0:
        print(-1)
        quit()
    if siaisuu==end:
        print(day)
        quit()
    sumsiai=siaisuu

### FIXED CODE ###

from collections import deque

n=int(input())
a=[list(map(int,input().split())) for i in range(n)]

for i in range(n):
    for j in range(n-1):
        a[i][j]-=1
    a[i].reverse()
# print(a)
day=[0]*n
pair=[-1]*n

q=deque(range(n))

while q:
    me=q.popleft()
    if not a[me]:
        continue
    oppo=a[me].pop()
    if pair[oppo]==me:
        now=max(day[me],day[oppo])+1
        day[me]=now
        day[oppo]=now
        q.append(me)
        q.append(oppo)
    else:
        pair[me]=oppo


for i in range(n):
    if a[i]:
        print(-1)
        break
else:
    print(max(day))
### BUGGY CODE ###

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

def main():
    for k in range(K):
        li = [0 for i in range(N+1)]
        rsl = [0 for i in range(N+1)]


        for i in range(N):
            if A[i] != 0:
                li[max(0,i-A[i])]+= 1
                li[min(N,i+A[i]+1)]-= 1
        
        mm = 0
        for i in range(N):
            mm += li[i]
            if A[i]>0:
                A[i] = mm
            else:
                A[i] = mm +1
        # print(A)

        if min(A)>=N:
            break
    print(*A)



main()



    





### FIXED CODE ###

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

def main():
    for k in range(K):
        li = [0 for i in range(N+1)]
        rsl = [0 for i in range(N+1)]


        for i in range(N):
            if A[i] != 0:
                li[max(0,i-A[i])]+= 1
                li[min(N,i+A[i]+1)]-= 1
        
        mm = 0
        for i in range(N):
            mm += li[i]
            if A[i]>0:
                A[i] = mm
            else:
                A[i] = mm +1
        # print(A)

        if min(A)>=N:
            break
    print(*A)



main()
### BUGGY CODE ###

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
ab.sort()

ans = 0
m = 0
while m < M:
    a, b = ab.pop(0)
    tm = min([b, M - m])
    ans += tm * a
    m += tm
print(ans)

### FIXED CODE ###

from collections import deque
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
ab.sort()

ab = deque(ab)

ans = 0
m = 0
while m < M:
    a, b = ab.popleft()
    tm = min([b, M - m])
    ans += tm * a
    m += tm
print(ans)
### BUGGY CODE ###

import collections

n=int(input())
l=[]
for i in range(n):
    l.append(input())
l2=collections.Counter(l)


max_k_list = [kv[0] for kv in l2.items() if kv[1] == max(l2.values())]
l3=sorted(max_k_list)
print("\n".join(l3))

### FIXED CODE ###

import collections

n=int(input())
l=[]
for i in range(n):
    l.append(input())
l2=collections.Counter(l)
max=max(l2.values())

max_k_list = [kv[0] for kv in l2.items() if kv[1] == max]
l3=sorted(max_k_list)
print("\n".join(l3))
### BUGGY CODE ###

from collections import deque
N = input()
A = [int(input()) for i in range(N)]

A = sorted(A)
res = []
begin = 0
end = len(A) - 1
res = deque()
res.append(A[begin])
res.append(A[end])
begin += 1
end -= 1
for i in range(N - 2):
	l = [abs(res[0] - A[begin]), abs(res[0] - A[end]), abs(res[-1] - A[begin]), abs(res[-1] - A[end])]
	cand = l.index(max(l))
	if cand == 0:
		res.appendleft(A[begin])
		begin += 1
	elif cand == 1:
		res.appendleft(A[end])
		end -= 1
	elif cand == 2:
		res.append(A[begin])
		begin += 1
	elif cand == 3:
		res.append(A[end])
		end -= 1
sum_diff = 0
for i in range(N - 1):
	 sum_diff += abs(res[i] - res[i + 1])
print sum_diff


### FIXED CODE ###

from collections import deque
N = input()
A = [int(input()) for i in range(N)]
coef = [2] * N
coef[0] = 1
coef[-1] = 1
coef1 = [coef[i] if i % 2 == 0 else coef[i] * -1 for i in range(N)]
coef2 = [coef[i] if i % 2 != 0 else coef[i] * -1 for i in range(N)]

A = sorted(A)
coef1 = sorted(coef1)
coef2 = sorted(coef2)
res1 = 0
for i in range(N):
	res1 += A[i] * coef1[i]
res2 = 0
for i in range(N):
	res2 += A[i] * coef2[i]
print max(res1, res2)
### BUGGY CODE ###

N, P = [int(x) for x in input().split()]
S = input()

res = 0

if P in [2,5]:
    for i in range(N):
        if int(S[i])% P == 0:
            res += i+1
else:
    dic = {0:1}
    for i in range(N-1,-1,-1):
        tmp = int(S[i:N])
        t = tmp % P
        if t in dic:
            res += dic[t]
            dic[t] += 1
        else:
            dic[t] = 1

print(res)


### FIXED CODE ###

N, P = [int(x) for x in input().split()]
S = input()

res = 0

if P in [2,5]:
    for i in range(N):
        if int(S[i])% P == 0:
            res += i+1
else:
    dic = {0:1}
    t1 = 0
    t2 = 1
    for i in range(N):
        t2 = (10*t2) % P
        t1 = (int(S[N-1-i])*t2 + t1) % P
        if t1 in dic:
            res += dic[t1]
            dic[t1] += 1
        else:
            dic[t1] = 1

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


N = int(input())
S0 = input()
S = [S0[i] for i in range(N)]
minimum = N + 1

for i in range(N+1):
    T = ['.' for j in range(i)] + ['#' for j in range(N-i)]
    m = 0
    for k in range(N):
        if S[k] != T[k]:
            m += 1
    if m < minimum:
        minimum = m

print(minimum)

### FIXED CODE ###

from copy import deepcopy

N = int(input())
S = input()
M = [0 for i in range(N+1)]

for i in range(N):
    if S[i] != '#':
        M[0] += 1

mini = deepcopy(M[0])
    
for i in range(N):
    if S[i] == '#':
        M[i+1] = M[i] + 1
    else:
        M[i+1] = M[i] - 1
        if mini > M[i+1]:
            mini = deepcopy(M[i+1])

print(mini)
### BUGGY CODE ###

import math
N=int(input())
total=[]
candi=[]

for i in range(1,N+1):
  for j in range(1,N+1):
    for k in range(1,N+1):
      candi.append([i,j,k])
for l in candi:
  ans=l[0]
  for m in l[1:]:
    ans=math.gcd(ans,m)
  else:
    total.append(ans)
print(sum(total))
    

### FIXED CODE ###

from math import gcd
N=int(input())
total=0

for i in range(1,N+1):
  for j in range(1,N+1):
    for k in range(1,N+1):
      total+=gcd(gcd(i,j),k)
      
print(total)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ls = [a[0]]
for i in range(1,n):
    ls.append(a[i]+ls[i-1])
    
ans = 0
k = 1
for i in range(n):
    if ls[i] == 0:
      ans += 1
    for j in range(k,n):
        if ls[i] == ls[j]:
            ans += 1
    k += 1

print(ans)

### FIXED CODE ###

import collections
n = int(input())
a = list(map(int,input().split()))
ls = [a[0]]
for i in range(1,n):
    ls.append(a[i]+ls[i-1])
    
ans = 0
ans += ls.count(0)
c = collections.Counter(ls)
c = (c.most_common())
i = 0
while True:
  if i == len(c):
    break
  else:
    ans += c[i][1]*(c[i][1]-1)/2
  i += 1
    
print(round(ans))
### BUGGY CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
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()))

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

n = I()
a = LI()
l = lcm(a)
ans = 0
for i in a:
    ans += l*pow(i,mod-2,mod)
    ans %= mod
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
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()))

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

n = I()
a = LI()
l = lcm(a)
ans = 0
l %= mod
for i in a:
    ans += l*pow(i,mod-2,mod)
    ans %= mod
print(ans)
### BUGGY CODE ###

N = int(input())
E = [[int(l) for l in input().split()] for _ in range(N-1)]
M = int(input())
L = [[int(l) for l in input().split()] for _ in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
        
    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
        
    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1
                
    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)

C = [set([]) for _ in range(M)]
for i in range(N-1):
    uf = UnionFind(N)
    for e in E:
        if e == E[i]:
            continue
        uf.unite(e[0], e[1])
    for l in range(M):
        if uf.isSameGroup(L[l][0], L[l][1]):
            continue
        C[l].add(i)

import itertools

ans = 0
L = [int(i) for i in range(M)]
for m in range(M+1):
    for P in itertools.combinations(L, m):
        white = set([])
        for j in P:
            white = white | C[j]
        if m%2:
            ans -= 1 << N-1-len(white)
        else:
            ans += 1 << N-1-len(white)
print(ans)

### FIXED CODE ###

N = int(input())
E = [[int(l) for l in input().split()] for _ in range(N-1)]
M = int(input())
L = [[int(l) for l in input().split()] for _ in range(M)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
        
    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
        
    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1
                
    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)

C = [0]*M
for i in range(N-1):
    uf = UnionFind(N)
    for e in E:
        if e == E[i]:
            continue
        uf.unite(e[0], e[1])
    for l in range(M):
        if uf.isSameGroup(L[l][0], L[l][1]):
            continue
        C[l] |= 1 << i

import itertools

ans = 0
L = [int(i) for i in range(M)]
for m in range(M+1):
    for P in itertools.combinations(L, m):
        white = 0
        for j in P:
            white |= C[j]
        if m%2:
            ans -= 1 << N-1-bin(white).count("1")
        else:
            ans += 1 << N-1-bin(white).count("1")
print(ans)
### BUGGY CODE ###

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

for i in range(A, B+1, 1):

    if i <= A+K-1:
        print(i)
    elif i>=B-K+1:
        print(i)

### FIXED CODE ###

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

l       = range(A, B+1)

s       = sorted(set(l[:K])|set(l[-K:]))

for i in s:
    print(i)
### BUGGY CODE ###

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

for i in range(q):
    ans = 0
    b, c = map(int, input().split())
    for j in range(n):
        A[j] = c if A[j] == b else A[j]
        ans += A[j]
    print(ans)

### FIXED CODE ###

from collections import Counter

n = int(input())
A = list(map(int, input().split()))
q = int(input())
cnt_A = dict(Counter(A))
ans = sum(A)
for i in range(q):
    b, c = map(int, input().split())
    if b in cnt_A and cnt_A[b] > 0:
        count = cnt_A[b]
        cnt_A[b] = 0
        if c not in cnt_A:
            cnt_A[c] = count
        else:
            cnt_A[c] += count
        ans += ((c - b) * count)
    print(ans)
### BUGGY CODE ###

import math
n1 = int(input())
f1 = [str(input()) for _ in range(n1)]

ans_sum = 0
ans_exa = []

for i in range(len(f1)):
    y1 = "".join(sorted(list(str(f1[i]))))
    y2 = [j for j, e in enumerate(ans_exa) if e == y1]
    ans_sum = ans_sum + int(len(y2))
    ans_exa.append(y1)

print(ans_sum)


### FIXED CODE ###

import math
n1 = int(input())
f1 = [str(input()) for _ in range(n1)]

ans_sum = 0
ans_exa = {}

for i in range(len(f1)):
    y1 = "".join(sorted(list(str(f1[i]))))
    if y1 in ans_exa:
        ans_sum = ans_sum + ans_exa[y1]
        ans_exa[y1] = ans_exa[y1] + 1
    else:
         ans_exa[y1] = 1

print(ans_sum)
### BUGGY CODE ###

while 1:
    n = input()
    if n==0: break
    s = [0 for i in xrange(7)]
    for i in xrange(n):
        age = input()
        s[min(6, age/10)] += 1
    for i in xrange(7):
        print s[i]

### FIXED CODE ###

while 1:
    n = input()
    if n==0: break
    s = [0 for i in range(13)]
    for i in range(n):
        s[int(raw_input())/10] += 1
    for i in range(6):
        print s[i]
    print sum(s[6:])
### BUGGY CODE ###

import bisect

s=input()
t=input()

index=list()
for a in range(len(t)):
 index.append([i for i, x in enumerate(s) if x == t[a]])

b=0
loop=0
condition=0

for j in range(len(t)):
  c=bisect.bisect_left(index[j],b)
  #print(j,index[j],b,c,loop)
  if len(index[j])<1:
    print(-1)
    condition=1
    break
  elif j<1:
    b=index[0][0]    
  elif c<len(index[j])  and c != index[j][len(index[j])-1]:
     b=index[j][c]
     #print(j,b,loop)
  else:
     loop +=1
     b=index[j][0]
     #if loop == len(s)*(10**100):
     #  print(-1)
     #  break

if condition==0:
 print(b+loop*len(s)+1)


        



### FIXED CODE ###

import bisect

s=input()
t=input()

#index=list()
#for a in range(len(t)):
# index.append([i for i, x in enumerate(s) if x == t[a]])

char_appear = {ch: [] for ch in 'abcdefghijklmnopqrstuvwxyz'}
for i, ch in enumerate(s):
    char_appear[ch].append(i)
#print(char_appear['a'])
      
b=0
loop=0
condition=0

for j in range(len(t)):
  if len(char_appear[t[j]])<1:
    print(-1)
    condition=1
    break
  c=bisect.bisect(char_appear[t[j]],b)
 # print(j,char_appear[t[j]],b,c,loop)
  if j<1:
    b=char_appear[t[0]][0]    
  elif c == len(char_appear[t[j]]): #or c==char_appear[t[j]][len(char_appear[t[j]])-1]: 
     loop +=1
     b=char_appear[t[j]][0]
     if loop==10**100:
        print(-1)
        condition=1
        break
  else:
     b=char_appear[t[j]][c]
     #print(j,b,loop)


if condition==0:
 print(b+loop*len(s)+1)