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

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

temp_prev = 0
temp_curr = 0
if b <= 100:
    x = 0.0
else:
    x = min(n, b - 100.0)

while x <= n:
    temp_prev = temp_curr
    temp_curr = int(a * x / b) - a * int(x / b)
    x += 1.0

    if temp_curr < temp_prev:
        break

print(max(temp_curr, temp_prev))

### FIXED CODE ###

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

temp_prev = 0
temp_curr = 0
x = min(n, b-1)

while x <= n:
    temp_prev = temp_curr
    temp_curr = int(a * x / b) - a * int(x / b)
    x += 1.0

    if temp_curr <= temp_prev:
        break

print(max(temp_curr, temp_prev))
### BUGGY CODE ###

import sys

if __name__ == "__main__":
    (X, Y, Z, K) = list(map(int, sys.stdin.readline().split()))
    A = list(map(int, sys.stdin.readline().split()))
    B = list(map(int, sys.stdin.readline().split()))
    C = list(map(int, sys.stdin.readline().split()))

    v = []
    for a in A:
        for b in B:
            v.append(a + b)

    v.sort(reverse=True)

    ans = []
    for i in range(min(len(v),3000)):
        for c in C:
            ans.append(v[i] + c)

    ans.sort(reverse=True)

    for i in range(K):
        sys.stdout.write("%d\n" % ans[i])

### FIXED CODE ###

import sys

if __name__ == "__main__":
    (X, Y, Z, K) = list(map(int, sys.stdin.readline().split()))
    A = list(map(int, sys.stdin.readline().split()))
    B = list(map(int, sys.stdin.readline().split()))
    C = list(map(int, sys.stdin.readline().split()))

    v = []
    for a in A:
        for b in B:
            v.append(a + b)

    v.sort(reverse=True)

    ans = []
    for i in range(min(len(v),3000)):
        for c in C:
            ans.append(v[i] + c)

    ans.sort(reverse=True)

    for i in range(K):
        sys.stdout.write("%d\n" % ans[i])
### BUGGY CODE ###

import sys
n = int(input())
x, y = [], []
for _i in range(n):
    s = input()
    p = 0
    m = 0
    for j in range(len(s)):
        if s[j]=="(":
            p += 1
        else:
            p -= 1
            m, _m = sorted([p, m])
    if p > 0:
        x.append([m, p])
    else:
        y.append([m-p, -p])

x.sort(reverse=True)
y.sort(reverse=True)
r = 0
for s, t in x:
    if r+s < 0:
        print("No")
        sys.exit()
    r += t
result = 0
for s, t in y:
    if result+s < 0:
        print("No")
        sys.exit()
    result += t
if r-result == 0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

import sys
n = int(input())
x, y = [], []
for _i in range(n):
    s = input()
    p = 0
    m = [0]
    for j in range(len(s)):
        if s[j]=="(":
            p += 1
        else:
            p -= 1
            m.append(p)
    if p > 0:
        x.append([min(m), p])
    else:
        y.append([min(m)-p, -p])

x.sort(reverse=True)
y.sort(reverse=True)
r = 0
for s, t in x:
    if r+s < 0:
        print("No")
        sys.exit()
    r += t
result = 0
for s, t in y:
    if result+s < 0:
        print("No")
        sys.exit()
    result += t
if r-result == 0:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

N,K = map(int,input().split())
p = list(map(int,input().split()))
want = sum(p[0:K])

for i in range(1,N-K+1):
    a = sum(p[i:i+K])
    want = max(a,want)

print((K+want)/2)

### FIXED CODE ###

N,K = map(int,input().split())
p = list(map(int,input().split()))
want = sum(p[0:K])
change = sum(p[0:K])

for i in range(1,N-K+1):
    change = change - p[i-1] + p[i+K-1]
    want = max(change,want)

print((K+want)/2)
### BUGGY CODE ###

s = list(input())
Q = int(input())
rev = 0
for i in range(Q):
    query = input()
    ti = list(query)[0]
    if ti == '1':
        rev = (rev + 1) % 2
    else:
        ti, fi, ci = query.split()
        if (int(fi) + rev) == 2:
            s.append(ci)
        else:
            s.insert(0, ci)
if rev == 1:
    s.reverse()
print(''.join(s))

### FIXED CODE ###

class Node:
    def __init__(self, char: str):
        self.before = None
        self.char = char
        self.next = None

class Linked_List:
    def __init__(self):
        self.head = None
        self.tail = None
    
    def add_head(self, node):
        if self.head is None:
            self.head = node
            self.tail = node
        else:
            node.next = self.head
            self.head.before = node
            self.head = node

    def add_tail(self, node):
        if self.tail is None:
            self.head = node
            self.tail = node
        else:
            node.before = self.tail
            self.tail.next = node
            self.tail = node

    def show(self, is_reversed: bool):
        ret = []
        node = self.tail if is_reversed else self.head
        while not node is None:
            c = ''.join(list(node.char)[::-1]) if is_reversed else node.char
            ret.append(c)
            node = node.before if is_reversed else node.next
        print(''.join(ret))

S = input()
Q = int(input())
ll = Linked_List()
ll.add_head(Node(S))
is_reversed = False

for _ in range(Q):
    query = input()
    if query[0] == '1':
        is_reversed = False if is_reversed else True
    else:
        t, f, c = query.split()
        if is_reversed:
            c = ''.join(list(c)[::-1])
        if f == '1':
            if is_reversed:
                ll.add_tail(Node(c))
            else:
                ll.add_head(Node(c))
        else:
            if is_reversed:
                ll.add_head(Node(c))
            else:
                ll.add_tail(Node(c))

ll.show(is_reversed)
### BUGGY CODE ###

N = int(input())

def F(a, b):
    a = len(str(a))
    b = len(str(b))
    if a > b:
        return a
    elif a < b:
        return b
    else:
        return b

elements = []

for i in range(1, N+1):
    if N % i == 0: elements.append(i)

a = elements[len(elements)//2]
b = N // a
print(F(a,b))

### FIXED CODE ###

import math

N = int(input())

def F(a, b):
    a = len(str(a))
    b = len(str(b))
    if a > b:
        return a
    elif a < b:
        return b
    else:
        return b

elements = []

for i in range(1, math.ceil(math.sqrt(N+1))):
    if N % i == 0: elements.append(i)

a = elements[-1]
b = N // a
print(F(a,b))
### BUGGY CODE ###

A,B,K=map(int,input().split())
for i in range(A,B+1):
    if i<A+K or i>B-K:
        print(i)

### FIXED CODE ###

A,B,K=map(int,input().split())
if B-A<=2*(K-1):
    for i in range(A,B+1):
        print(i)
else:
    for i in range(A,A+K):
        print(i)
    for j in range(B-K+1,B+1):
        print(j)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10000)


def input():
    return sys.stdin.readline().rstrip()


def dfs(a, m):
    if max(a) == 0:
        return 0
    if m == 0:
        return sum(a)
    a[a.index(max(a))] //= 2
    return dfs(a, m-1)


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

    #print(dfs(A, M))
    for i in range(M):
        A[A.index(max(A))] //= 2
        if max(A) == 0:
            print("0")
            exit()
    print(sum(A))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import heapq


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(N):
        A[i] *= -1
    heapq.heapify(A)

    for i in range(M):
        maxa = -1 * heapq.heappop(A)
        if maxa == 0:
            print("0")
            exit()
        heapq.heappush(A,  maxa // 2 * (-1))
    print(sum(A) * (-1))


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

def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import bisect
import sys
sys.setrecursionlimit(10**6)
mod=998244353
n=i1()
d=[]
N=1<<(n.bit_length())
t=[-1 for i in range(2*N-1)]

def ud(i,x):
  i+=N-1
  t[i]=x
  while i:
    i=(i-1)//2
    t[i]=max(t[i*2+1],t[i*2+2])

def qr(a,b,k,l,r):
  if r<=a or b<=l:
     return -1
  elif a<=l and r<=b:
     return t[k]
  else:
     return max(qr(a,b,k*2+1,l,(l+r)//2),qr(a,b,k*2+2,(l+r)//2,r))

for i in range(n):
  d.append(i2())
d=sorted(d)
dx=[]
dd=[]
for i,j in d:
  dx.append(i)
  dd.append(j)
r=[]
for i in range(n):
 j=bisect.bisect_left(dx,dx[i]+dd[i])-1
 r.append(j)
 ud(i,j)

for i in range(n)[::-1]:
 tt=qr(i,r[i]+1,0,0,N)
 ud(i,tt)
dp=[0 for i in range(n+1)]
dp[-1]=1
for i in range(n)[::-1]:
  dp[i]+=dp[i+1]
  dp[i]%=mod
  dp[i]+=dp[t[i+N-1]+1]
  dp[i]%=mod
print(dp[0])

### FIXED CODE ###

def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import bisect
mod=998244353
n=int(input())
d=[]
N=1<<(n.bit_length())
t=[-1 for i in range(2*N-1)]

def ud(i,x):
  i+=N-1
  t[i]=x
  while i:
    i=(i-1)>>1
    if t[i*2+1]>t[i*2+2]:t[i]=t[i*2+1]
    else:t[i]=t[i*2+2]
     

def qr(a,b):
    a+=N-1
    b+=N-1
    L = -1
    R = -1
    while a < b:
      if a&1==0:
         if L<t[a]:L = t[a]
      if b&1==0:
         b-=1
         if R<t[b]:R = t[b]
      
      a>>=1
      b>>=1
      
         
    return max(L, R)
 
for i in range(n):
  d.append([int(i) for i in input().split()])
d.sort()
dx=[]
dd=[]
for i,j in d:
  dx.append(i)
  dd.append(j)
for i in range(n)[::-1]:
 tx=dx[i]+dd[i]
 j=bisect.bisect_left(dx,tx)
 tt=qr(i,j)
 if j-1>tt:ud(i,j-1)
 else:ud(i,tt)
dp=[0 for i in range(n+1)]
dp[-1]=1
for i in range(n)[::-1]:
  dp[i]+=dp[i+1]
  dp[i]%=mod
  dp[i]+=dp[t[i+N-1]+1]
  dp[i]%=mod
print(dp[0])
### BUGGY CODE ###

N = int(input())
S = []
for i in range(N):
  S.append(input())

cnt = 0
for i in range(N):
  for j in range(i + 1, N):
    a = list((S[i]))
    b = list((S[j]))
    
    for k in range(10):
      if a[k] in b:
        b.remove(a[k])
      else:
        break
    else:
      cnt += 1
print (cnt)

### FIXED CODE ###

import math

N = int(input())
S = []
for i in range(N):
  S.append(''.join(sorted(input())))

from collections import Counter
Sc = Counter(S)

def com(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

cnt = 0
for i in Sc.values():
  if i >= 2:
    cnt += com(i,2)
  
print (cnt)
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
slis=[0]*n
for i in range(len(s)-1):
	if s[i]+s[i+1]=="AC":
		slis[i]='1'
for j in range(q):
	l,r=map(int,input().split())
	print(slis[l-1:r-1].count("1"))

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])
### BUGGY CODE ###

import math
K = int(input())

ans = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      ans += math.gcd( math.gcd(i,j) , k )

print(ans)

### FIXED CODE ###

import math, itertools
K = int(input())
#K = 2

a = [i for i in range(1,K+1)]

x = itertools.combinations(a,2)
y = itertools.combinations(a,3)

c = 0
for i,j in x:
  c += math.gcd(i,j)

d = 0
for i,j,k in y:
  d += math.gcd( math.gcd(i,j) , k)

ans = sum(a) + c*6 + d*6

if K == 1:
  ans = 1
elif K == 2:
  ans = 9

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

n, k = map(int, input().split())
graph = []
Y = []
X = []
for _ in range(n):
    x, y = map(int, input().split())
    graph.append([x, y])
    Y.append(y)
    X.append(x)

Y.sort()
X.sort()
ans = []
for sx in range(n):
    for ex in range(n-1, sx, -1):
        for sy in range(n):
            for ey in range(n-1, sy, -1):
                x1, x2, y1, y2 = X[sx], X[ex], Y[sy], Y[ey]
                count = len([True for x, y in graph if x1 <= x <= x2 and y1 <= y <= y2])
                if count >= k:
                    ans.append((x2-x1)*(y2-y1))
                else:
                    break

print(min(ans))

### FIXED CODE ###

n, k = map(int, input().split())
graph = []
Y = []
X = []
for _ in range(n):
    x, y = map(int, input().split())
    graph.append([x, y])
    Y.append(y)
    X.append(x)

Y.sort()
X.sort()
ans = []
for sx in range(n):
    for ex in range(n-1, sx, -1):
        for sy in range(n):
            for ey in range(n-1, sy, -1):
                x1, x2, y1, y2 = X[sx], X[ex], Y[sy], Y[ey]
                count = len([True for x, y in graph if x1 <= x <= x2 and y1 <= y <= y2])
                if count >= k:
                    ans.append((x2-x1)*(y2-y1))
                else:
                    break

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

n, m = map(int, input().split())
ab = []
c= []
keys = ["" for _ in range(m)]

for i in range(m):
    ab.append(list(map(int, input().split())))
    kari = list(map(int, input().split()))
    c.append(kari)
    for j in range(n):
        if j+1 in kari:
            keys[i] = keys[i]+"1"
        else:
            keys[i] = keys[i] + "0"
#%%
all_patterns = ["0","1"]
options = ["0", "1"]

for _ in range(n-1):
    all_patterns = [j+i for i in (options) for j in all_patterns]

dp_dict = dict()
for pattern in all_patterns:
    dp_dict[pattern] = 1e+10
dp_dict["0"*n] = 0

#%%

for j in range(m):
    for key in dp_dict.keys():    
        if dp_dict[key]+ab[j][0] < dp_dict[format(int(key,2)|int(keys[j],2),"0"+str(n)+"b")]:
            dp_dict[format(int(key,2)|int(keys[j],2),"0"+str(n)+"b")] = dp_dict[key]+ab[j][0]

if dp_dict["1"*n] != 1e+10:
    print(dp_dict["1"*n])
else:
    print(-1)

### FIXED CODE ###


n, m = map(int, input().split())
ab = []
c= []
keys = ["" for _ in range(m)]

for i in range(m):
    ab.append(list(map(int, input().split())))
    kari = list(map(int, input().split()))
    c.append(kari)
    for j in range(n):
        if j+1 in kari:
            keys[i] = keys[i]+"1"
        else:
            keys[i] = keys[i] + "0"

all_patterns = ["0","1"]
options = ["0", "1"]

for _ in range(n-1):
    all_patterns = [j+i for i in (options) for j in all_patterns]

dp = [1e+10 for i in range(2**n)]
dp[0] = 0

#%%
for j in range(m):
    for i in range(len(dp)):
        kari1 = dp[i]+ab[j][0]
        kari2 = dp[i|int(keys[j],2)]
        if kari1 < kari2:
            dp[i|int(keys[j],2)] = kari1

if dp[-1] != 1e+10:
    print(dp[-1])
else:
    print(-1)
### BUGGY CODE ###

k,s=map(int,input().split())
c=0
#x>=y>=z
for i in range(k+1):
    for j in range(i+1):
        for k in range(j+1):
            if i+j+k==s:
                if i==j==k:
                    c+=1
                elif i!=j and j!=k:
                    c+=6
                else:
                    c+=3
                
print(c)


### FIXED CODE ###

k,s=map(int,input().split())
c=0
#x>=y>=z
for i in range(k+1):
    for j in range(k+1):
        if 0<=s-i-j<=k:
          c+=1
print(c)
### BUGGY CODE ###

A,B,N = map(int,input().split())
max_ = 0
for x in range(1,N+1):
    C = (A*x)//B - A*(x//B)
    if C > max_:
        max_ = C
print(max_)

### FIXED CODE ###

A,B,N = map(int,input().split())
if B-1>N:
    x = N
else :
    x = B-1
print( (A*x)//B - A*(x//B))
### BUGGY CODE ###

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

a.sort()

arrived = []
score = 0
for i in range(n):
    x = a.pop()
    _max = [0, 0]
    for j in range(len(arrived)):
        if _max[0] < (_min := min(arrived[j - 1], arrived[j])):
            _max = [_min, j + 1]
    arrived.insert(_max[1], x)
    score += _max[0]
print(score)

### FIXED CODE ###

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

a.sort(reverse=True)

score = - a[0]
for i in range(n):
    score += a[i // 2]
print(score)
### BUGGY CODE ###

L,R = map(int,input().split())

ans = 2018

for i in range(L,min(R,L+2020)):
    for j in range(i+1,R+1):
        if (i*j) % 2019 <= ans:
            ans = (i*j) % 2019

print(ans)

### FIXED CODE ###

L,R = map(int,input().split())

ans = 2018

for i in range(L,min(R,L+2100)):
    for j in range(i+1,min(R+1,i+2100)):
        if (i*j) % 2019 <= ans:
            ans = (i*j) % 2019

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

N=int(input())
a=1
b=1
count=0
while a<N:
  while a*b<N:
    count=count+1
    b=b+1
  else:
    b=1
    a=a+1
else:
  print(count)

### FIXED CODE ###

N=int(input())
a=1
count=0
while a<N:
  count=count+(N-1)//a
  a=a+1
else:
  print(count)
### BUGGY CODE ###

n = input()
list = list(map(int, input().split()))
count = 0
end = 0
while True:
  for i in range(len(list)):
    list[i] /= 2
    if not list[i].is_integer():
      end += 1
  if end == 1:
    break
  count += 1
print(count)

### FIXED CODE ###

n = input()
nList = list(map(int,input().split()))
count = 0
while True:
  for i in range(len(nList)):
    nList[i] = nList[i]/2
    if not(nList[i].is_integer()):
      print(count)
      exit()
  count += 1
### BUGGY CODE ###

n, m = map(int, input().split())
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
p = 10 ** 9 + 7
ans = 0
for i in range(n - 1):
  for j in range(m - 1):
    S = (X[i + 1] - X[i]) * (Y[j + 1] - Y[j]) * (n - i - 1) * (i + 1) * (m - j - 1) * (j + 1)
    ans += S
print(ans % p)

### FIXED CODE ###

n, m = map(int, input().split())
p = 10 ** 9 + 7
X = [int(x) for x in input().split()]
Y = [int(x) for x in input().split()]
XX = [(X[i + 1] - X[i]) * (n - i - 1) * (i + 1) % p for i in range(n - 1)]
YY = [(Y[j + 1] - Y[j]) * (m - j - 1) * (j + 1) % p for j in range(m - 1)]
print(sum(XX) * sum(YY) % p)
### BUGGY CODE ###

import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline
S = S()
Q = I()
rev = False
for i in range(Q):
    q = LS()
    if q[0] == '1':
        rev = not rev
        continue
    if (q[1] == '1') ^ rev:
        S = ''.join([q[2],S])
    else:
        S = ''.join([S,q[2]])
if rev:
    ans = S[::-1]
else:
    ans = S

print(ans)


### FIXED CODE ###

import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline
S = S()
S = [S[i] for i in range(len(S))]
QS= deque(S)
S = QS
Q = I()
rev = False
for i in range(Q):
    q = LS()
    if q[0] == '1':
        rev = not rev
        continue
    if (q[1] == '1') ^ rev:
        S.appendleft(q[2])
    else:
        S.append(q[2])
if rev:
    ans = ''.join(reversed(S))
else:
    ans = ''.join(S)

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

#1:初期化
N, K = map(int,input().split())
#h = list(map(int, input().split()))
h = [int(x) for x in input().split()] #こっちのほうが早い？
#inf = float("inf")
dp = [0]*(N)

#2:初期値
dp[0] = 0

#3:dp実行部(貰うDP)
for i in range(1,N):
    L = [dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-K),i)]
    dp[i] = min(L)
#    for k in range(1,min(N-i-1,K)+1):
#        dp[i+k] = min(dp[i+k], dp[i] + abs(h[i] - h[i+k]))
        #print(dp,i,k)

#4:出力
print(dp[N-1])

### FIXED CODE ###

# -*- coding: utf-8 -*- 
def cost(h,N,K):
    dp=[0]*N
    dp[1]=abs(h[0]-h[1])
    for i in range(2,N):
        tmp=[abs(h[i]-h[j])+dp[j] for j in range(max(0,i-K),i)]
        dp[i]=min(tmp)
    return dp[-1]

N,K=map(int,input().split())
h=[int(num) for num in input().split()]

print(cost(h,N,K))
### BUGGY CODE ###

import sys
input = sys.stdin.readline 
sys.setrecursionlimit(10 ** 6) 
N,Q = map(int, input().split())

tree = [[] for _ in range(N)]

for i in range(N - 1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  if a == b:
    continue
  tree[a].append(b)
  tree[b].append(a)

ans = [0] * N

for i in range(Q):
  p,x = map(int, input().split())
  ans[p - 1] += x
  
def dfs(cur, par):
  for chl in tree[cur]:
    ans[chl] += ans[cur]
    dfs(chl,cur)

dfs(0, -1)

print(*ans)



### FIXED CODE ###

import sys
input = sys.stdin.readline 
sys.setrecursionlimit(10 ** 6) 
N,Q = map(int, input().split())

tree = [[] for _ in range(N)]

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

ans = [0] * N

for i in range(Q):
  p,x = map(int, input().split())
  ans[p - 1] += x
  
def dfs(cur, par):
  for chl in tree[cur]:
    if chl == par:
      continue
    ans[chl] += ans[cur]
    dfs(chl,cur)

dfs(0, -1)

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

S = input()
Q = int(input())
reverse_cnt = 0
tmp = "*"
for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse_cnt += 1
        tmp = tmp[::-1]
    else:
        if query[1] == "1":
            tmp =  query[2] + tmp
        else:
            tmp = tmp + query[2] 

if reverse_cnt % 2 != 0:
    S = S[::-1]
    
print(tmp.replace("*", S))

### FIXED CODE ###

from collections import deque

S = input()
Q = int(input())
reverse_cnt = 0
s = deque([i for i in S])

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse_cnt += 1
    else:
        if query[1] == "1":
            if reverse_cnt % 2 == 0:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if reverse_cnt % 2 == 0:
                s.append(query[2])
            else:
                s.appendleft(query[2])

if reverse_cnt % 2 == 0:
    while s:
        print(s.popleft(), end="")
else:
     while s:
        print(s.pop(), end="")
### BUGGY CODE ###

from collections import Counter
n = int(input())
s = []
for i in range(n):
    s.append(Counter(input()))



ans = 0
for i in range(n):
    for j in range(i+1,n):
        if s[i]==s[j]:
            ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
d = {}
for _ in range(n):
    s = ''.join(sorted(input()))
    if s not in d:
        d[s] = 0
    d[s] += 1



ans = 0
for i in d.values():
    ans += int(i*(i-1)/2)
print(ans)