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

from decimal import *
import itertools


def score(list):
    tl, dl = zip(*list)
    t_s = len(set(tl)) ** 2
    d_s = sum(dl)
    return t_s + d_s


def r(n, k, sl):
    s = 0
    for v in itertools.combinations(sl, k):
        cv = score(v)
        if cv > s:
            s = cv
    return s


def main():
    n, k = list(map(int, input().split()))
    sl = []
    for i in range(n):
        t, d = list(input().split())
        sl.append([int(t), Decimal(d)])

    print(r(n, k, sl))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

def r(n, k, sl):

    sl.sort(key=lambda x: -x[1])

    gmk = set()
    gop = 0
    ce = []
    for ti, di in sl[:k]:
        if ti in gmk:
            ce.append(di)
        gmk.add(ti)
        gop += di

    gscr = len(gmk)**2 + gop

    for ti, di in sl[k:]:
        if 0 >= len(ce):
            break
        if ti in gmk:
            continue
        gmk.add(ti)
        odi = ce.pop()
        gop = gop - odi + di
        nscr = len(gmk)**2 + gop
        gscr = max(gscr, nscr)

    return gscr


def main():
    input = sys.stdin.readline
    n, k = list(map(int, input().split()))
    sl = [tuple(map(int, input().split())) for _ in range(n)]
    print(r(n, k, sl))


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

n, q = list(map(int,input().split()))
s = input()
ka = []
for i in range(q) :
    l, r = list(map(int,input().split()))
    print(s[l - 1 : r].count("AC"))

### FIXED CODE ###

n,q= map(int,input().split())
s = input()
l = [list(map(int,input().split())) for i in range(q)]
sa = [0]*n
for i in range(0,len(s)-1):
    if s[i] == "A" and s[i+1] == "C":
        sa[i+1] = sa[i] + 1
    else:
        sa[i+1] = sa[i]

""" A C D D D A C A C """
"""0 1 1 1 1 1 2 2 3  """
for si, syu in l:
    print(sa[syu-1] - sa[si-1])
### 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=0
sumsiai=0
end=n*(n-1)//2
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]]
        if i+1==a[nex-1][now[nex-1][0]] and now[nex-1][1] != day:
            siaisuu+=1
            now[i][0]+=1
            now[i][1],now[nex-1][1]=day,day
            now[nex-1][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 ###

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

ans = 0
for i in range (A, B+1):
    if (i%C)*(i%D) != 0:
        ans +=1
print(ans)

### FIXED CODE ###

import fractions
def CntMultiples(a, b, n):
    return b//n - a//n + int(a%n==0)

A,B,C,D = map(int,input().split())
print(B-A+1-(CntMultiples(A, B, C) + CntMultiples(A, B, D) - \
             CntMultiples(A, B, (C*D)//(fractions.gcd(C, D)))))
### BUGGY CODE ###

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

    S = 0
    for i in range(len(A)-1):
        for j in range(i+1,len(A)):
            S = (S + A[i]*A[j]%MOD)%MOD

    print(S)

main()


### FIXED CODE ###

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

    S = 0
    for i in range(len(A)-1):
        tmp = 0
        for j in range(i+1,len(A)):
            tmp+=A[j]
        S+= (tmp%MOD * A[i])%MOD


    print(S%MOD)



from itertools import accumulate

m = 10**9 + 7

N,*A = map(int,open(0).read().split())

result = 0

b = [0]*N
b[0] = A[0]
for i in range(1,N):
    b[i]= b[i-1] + A[i]




for i in range (N-1):
    result += A[i]*(b[N-1]-b[i])
    result %= m
print(result)
### BUGGY CODE ###

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

lst = []
for i in range(N):
    S, T , X = map(int, input().split())
    lst += [[X, max(0, S-X), max(0, T-X)]]

lst.sort()
#print (lst)

def check(a):
    for j in range(len(lst)):
            if lst[j][1] <= a and a < lst[j][2]:
                return lst[j][0]
            elif j == len(lst) - 1:
                return -1

for i in range(Q):
    D = int(input())
    print (check(D))

### FIXED CODE ###

import sys
input = sys.stdin.readline

from heapq import heappop, heappush
from collections import defaultdict

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

lst = []
for i in range(N):
    s, t, x = map(int, input().split())
    lst.append((t - x, 0, x)) #xで止まらなくなる
    lst.append((s - x, 1, x)) #xで止まる

for i in range(Q):
    lst.append((int(input()), 2, i))

lst.sort()
ans = [-1] * Q

#引っかかっている場所の管理
se = set()
se_hp = [] #heapで最小値を先頭に保つ

#小さい時刻から順に見ていく
for a, b, c in lst:
    if b == 0:
        se.remove(c)
    elif b == 1:
        se.add(c)
        heappush(se_hp, c)
    else:
        while se_hp and se_hp[0] not in se:
            heappop(se_hp)
        ans[c] = se_hp[0] if se_hp else -1

print ('\n'.join(map(str, ans)))
### BUGGY CODE ###

#! python3
# coding:utf-8

n = int(input())
for i in range(1,n+1):
    cnt=0

    for x in range(1,100):
        for y in range(1,100):
            for z in range(1,100):
                
                tmp2 = x*y + y*z + z*x
                if (tmp2>i):
                    continue
                tmp1 = x**2 + y**2 + z**2   
                if (tmp1 + tmp2) == i:
                    cnt+=1
    print(cnt)

### FIXED CODE ###

#! python3
# coding:utf-8
 
def main():
    n = int(input())
    ans = [0 for _ in range(n)]
    for x in range(1,100):
        for y in range(1,100):
            for z in range(1,100):
                eq = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if eq < n+1:
                    ans[eq-1]+=1
    for i in ans:   
        print(i)

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

n, q = map(int, input().split())
s = input()
ac_list = [0]*len(s)
i = 0
while True:
    ac_index = s[i:].find("AC")
    if ac_index == -1:
        break
    else:
        ac_list[ac_index+i] = 1
        i = ac_index + i + 2

for _ in range(q):
    lr = tuple(map(int, input().split()))
    print(sum(ac_list[lr[0]-1:lr[1]-1]))

### FIXED CODE ###

n, q = map(int, input().split())
s = input()
ac_list = [0]*len(s)

'''while True:
    ac_index = s[i:].find("AC")
    if ac_index == -1:
        break
    else:
        ac_list[ac_index+i] = 1
        i = ac_index + i + 2'''

for i in range(len(s)-1):
    if s[i:i+2] == 'AC':
        ac_list[i+1] = ac_list[i] + 1
    else:
        ac_list[i+1] = ac_list[i]
# print(ac_list)
for _ in range(q):
    l, r = map(int, input().split())
    print(ac_list[r-1] - ac_list[l-1])
### BUGGY CODE ###

n, m = map(int, input().split())
results = []
for i in range(m):
    results.append(input().split())
passed = 0
failed = 0
dicto = {}
for item in results:
    key = item[0]
    status = item[1]
    if key not in dicto.keys():
        dicto[key] = []
        dicto[key].append(status)
    else:
        # status exists in dicto[key] already
        if 'AC' not in dicto[key]:
            dicto[key].append(status)
for item in dicto:
    if 'AC' in dicto[item]:
        for i in dicto[item]:
            if i == 'WA':
                failed += 1
        passed += 1

print(passed, failed)


### FIXED CODE ###

n, m = map(int, input().split())
passed = 0
failed = 0
dicto = {}

for i in range(1, n+1):
    dicto[i] = [False, 0]

for i in range(m):
    key, status = input().split()
    key = int(key)
    if status == 'WA' and not dicto[key][0]:
        dicto[key][1] += 1
    else:
        dicto[key][0] = True

for i in dicto:
    if dicto[i][0]:
        failed += dicto[i][1]
        passed += 1

print(passed, failed)
### BUGGY CODE ###

n, k = [int(e) for e in input().split()]
divisor = 10 ** 9 + 7
cache = {}
def memoize(f):
    global cache
    def _(*args):
        if not args in cache:
            cache[args] = f(*args)
        return cache[args]
    return _
@memoize
def f(n, x):
  if x == 1:
    return 1
  if x == 2:
    return n + 1
  else:
    return sum(f(i, x - 1) for i in range(n + 1)) % divisor
for i in range(1, k + 1):
  print(f(k - i, i) * f(n - k - i + 1, i + 1) % divisor)


### FIXED CODE ###

def main():
    N, K = map(int, input().split())

    c = [[0] * 4000 for _ in range(4000)]
    c[0][0] = 1
    for i in range(1, 4000):
        ci = c[i]
        ci1 = c[i - 1]
        ci[0] = 1
        for j in range(1, i + 1):
            ci[j] = (ci1[j - 1] + ci1[j]) % 1000000007

    def f(n, k):
        return c[n+k-1][k-1]

    for i in range(1, K + 1):
        print((f(K-i, i) * f(N-K-(i-1), i+1)) % 1000000007)


main()
### BUGGY CODE ###

n = int(input())
l = input().split()
ans = 1
for i in range(n):
    ans = ans * int(l[i])
if ans <= 10**18:
    print(ans)
else:
    print(-1)


### FIXED CODE ###

n = int(input())
l = input().split()
ans = 1
T = True
for i in range(n):
    if l[i] == '0':
        ans = 0
        break
if ans != 0:
    for i in range(n):
        if ans <= 10**18:
            ans = ans * int(l[i])
        else:
            T = False
            break
if False:
    print(-1)
elif ans > 10**18:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

s = input()
n = len(s)
t = input()
m = len(t)

dp = [[0 for _ in range(m+1)] for _ in range(n+1)]

for i in range(n):
    for j in range(m):
        if t[j]!=s[i]:
            dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1])
        else :
            dp[i+1][j+1]=dp[i][j]+1

ans = ''

i = len(s)
j = len(t)
while (i>0  and j>0):
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans += s[i-1]
        i -= 1
        j -= 1

print(ans[::-1])


### FIXED CODE ###

s = input()
n = len(s)
t = input()
m = len(t)

dp = [[0 for _ in range(m+1)] for _ in range(n+1)]

for i in range(n):
    for j in range(m):
        if t[j]!=s[i]:
            dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1])
        else :
            dp[i+1][j+1]=dp[i][j]+1

ans = ''

i = len(s)
j = len(t)
while (i>0  and j>0):
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans += s[i-1]
        i -= 1
        j -= 1

print(ans[::-1])
### BUGGY CODE ###

"""

https://atcoder.jp/contests/arc100/tasks/arc100_c

情報を再利用するのがメイン
K=Xの時は,K=X-1の時の答えに加え、 i or j == K の場合を考えればいい
or がKとなる場合、0の桁は両方0で、1の桁は片方が1ならよい
1では3通りの分け方があるので、3^N…

大きいほうから考えてみる？
最後は、当然最大のやつ2個→その2つのindex のORまではそれが保持

dp[X] = X と orしてもXのままのindexの集合における最大 & 2番目
→とすれば、1の桁全てに関して0にしてみた奴とXを見れば推移できる

O(2^N * logMAX(A)) で解けそうだ

"""

from sys import stdin

N = int(stdin.readline())
A = list(map(int,stdin.readline().split()))
A.append(float("-inf"))

dp = []
ans = 0
aaa = []

for i in range(2**N):

    if i == 0:
        dp.append( ( 0,-1 ) )
        continue

    dic = {}
    lis = [(A[i],i)]
    
    for j in range(N):

        if (2**j) & i > 0:

            ta,tb = dp[i ^ (2**j)]
            if ta not in dic:
                dic[ta] = 1
                lis.append( (A[ta],ta) )
            if tb not in dic:
                dic[tb] = 1
                lis.append( (A[tb],tb) )

    lis.sort()
    lis.reverse()

    aa,ab = lis[0][1] , lis[1][1]
    ans = max(A[aa] + A[ab] , ans)
    aaa.append(ans)
    dp.append( ( aa,ab ) )
print ("\n".join(map(str,aaa)))

### FIXED CODE ###


"""

https://atcoder.jp/contests/arc100/tasks/arc100_c

情報を再利用するのがメイン
K=Xの時は,K=X-1の時の答えに加え、 i or j == K の場合を考えればいい
or がKとなる場合、0の桁は両方0で、1の桁は片方が1ならよい
1では3通りの分け方があるので、3^N…

大きいほうから考えてみる？
最後は、当然最大のやつ2個→その2つのindex のORまではそれが保持

dp[X] = X と orしてもXのままのindexの集合における最大 & 2番目
→とすれば、1の桁全てに関して0にしてみた奴とXを見れば推移できる

O(2^N * logMAX(A)) で解けそうだ

"""

from sys import stdin

N = int(stdin.readline())
A = list(map(int,stdin.readline().split()))
A.append(float("-inf"))

dp = []
ans = 0
aaa = []

for i in range(2**N):

    if i == 0:
        dp.append( ( 0,-1 ) )
        continue

    na,nb = i,-1
    
    for j in range(N):

        if (2**j) & i > 0:

            ta,tb = dp[i ^ (2**j)]
            if A[na] < A[ta]:
                nb = na
                na = ta
            elif A[nb] < A[ta] and ta != na:
                nb = ta

            if A[nb] < A[tb]:
                nb = tb

    #print (i,na,nb)
    ans = max(A[na] + A[nb] , ans)
    aaa.append(ans)
    dp.append( ( na,nb ) )

print ("\n".join(map(str,aaa)))
### BUGGY CODE ###

n=int(input())
A=[int(input()) for i in range(n)]


for i in range(n):
  p=A[i]
  A[i]=0
  print(max(A))
  A[i]=p

### FIXED CODE ###

n=int(input())
A=[int(input()) for i in range(n)]
B=sorted(A)
f=B[-1]
s=B[-2]
q=A.index(f)

for i in range(q):
  print(f)
print(s)
for i in range(n-q-1):
  print(f)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

a, b, n = [int(x) for x in input().split()]

i = 0
ans = 0
flag = 0

while i <= n:
    x = (a*i//b) - (a*(i//b))
    if x > 0:
        flag = 1
    if flag and x == 0:
        print(ans)
        sys.exit()
    ans = max(ans, x)
    i += 1
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

a, b, n = [int(x) for x in input().split()]

if n >= b - 1:
    print((a*(b - 1)//b) - (a*((b - 1)//b)))
else:
    print((a*n//b) - (a*(n//b)))
### BUGGY CODE ###

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

from functools import reduce

def g():
  n = int(input())
  vs = list(map(int, input().split()))
  
  mr = 0
  for i in range(len(vs)):
    r = reduce(gcd, vs[:i]+vs[i+1:])
    mr = max(mr, r)
  return mr
  
print(g())


### FIXED CODE ###

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


def g():
  from functools import reduce
  n = int(input())
  vs = list(map(int, input().split()))
  
  while True:
    n = len(vs)
    
    if n < 10:
      mrr = 0
      for i, v in enumerate(vs):
        rr = reduce(gcd, vs[:i]+vs[i+1:])
        mrr = max(rr, mrr)
      return mrr
    
    v1 = vs[:n//2]
    v2 = vs[n//2:]
    
    r1 = reduce(gcd, v1)
    r2 = reduce(gcd, v2)
    if r1 == r2:
      return r1
    if r1 > r2:
      vs = v2
    else:
      vs = v1
  
  
print(g())
### BUGGY CODE ###

# import numpy as np
from sys import exit
import copy
from collections import deque, Counter


class BIT:
    def __init__(self, a=0):
        self.n = a
        self.d = [0] * (a + 1)

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.d[i] += x
            i += i & (-i)

    def sum(self, *i):
        if len(i) == 1:
            x = 0
            tmp = i[0] + 1
            while tmp:
                x += self.d[tmp]
                tmp -= tmp & (-tmp)
            return x
        else:
            return sum(self, i[1] - 1) - sum(self, i[0] - 1)


N, Q = map(int, input().split())
C = list(map(int, input().split()))

app = [-1] * (N + 1)
ps = [[] for _ in range(N)]
for i in range(N):
    tmp = app[C[i]]
    if tmp != -1:
        ps[tmp].append(i)
    app[C[i]] = i

qs = [[] for _ in range(N)]
for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    qs[l].append(copy.deepcopy([r, i]))

ans = [0] * Q
d = BIT(N)
for x in range(N - 1, -1, -1):
    for y in ps[x]:
        d.add(y, 1)
    for p in qs[x]:
        r = p[0]
        i = p[1]
        ans[i] = (r - x + 1) - d.sum(r)

for re in ans:
    print(re)


### FIXED CODE ###

# import numpy as np
from sys import exit, stdin
import copy
from collections import deque, Counter


class BIT:
    def __init__(self, a=0):
        self.n = a
        self.d = [0] * (a + 1)

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.d[i] += x
            i += i & (-i)

    def sum(self, *i):
        if len(i) == 1:
            x = 0
            tmp = i[0] + 1
            while tmp:
                x += self.d[tmp]
                tmp -= tmp & (-tmp)
            return x
        else:
            return sum(self, i[1] - 1) - sum(self, i[0] - 1)


N, Q = map(int, stdin.readline().split())
C = list(map(int, stdin.readline().split()))

app = [-1] * (N + 1)
ps = [[] for _ in range(N)]
for i in range(N):
    tmp = app[C[i]]
    if tmp != -1:
        ps[tmp].append(i)
    app[C[i]] = i

qs = [[] for _ in range(N)]
for i in range(Q):
    l, r = map(int, stdin.readline().split())
    l -= 1
    r -= 1
    qs[l].append(copy.deepcopy([r, i]))

ans = [0] * Q
d = BIT(N)
for x in range(N - 1, -1, -1):
    for y in ps[x]:
        d.add(y, 1)
    for p in qs[x]:
        r = p[0]
        i = p[1]
        ans[i] = (r - x + 1) - d.sum(r)

for re in ans:
    print(re)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline


def ps(i, k):
    if k == 1:
        return len(ko[i])
    t = (i, k)
    if t in memo:
        return memo[t]
    re = 0
    for ki in ko[i]:
        re += ps(ki, k - 1)
        re %= md
        memo[t] = re
    return re


md = 10 ** 9 + 7
n, k = map(int, input().split())
ko = [[]]
memo = {}
for _ in range(n):
    s = input()
    st = 0
    kk = []
    while 1:
        i = s.find("1", st)
        if i == -1: break
        kk += [i // 2 + 1]
        st = i + 1
    ko += [kk]

ans = 0
for i in range(1, n + 1):
    ans += ps(i, k)

print(ans)


### FIXED CODE ###

import sys

input = sys.stdin.readline


def dot(a, b):
    c = [[0] * n for _ in range(n)]
    for i, ai in enumerate(a):
        for j, bj in enumerate(zip(*b)):
            c[i][j] = sum(ak * bk for ak, bk in zip(ai, bj)) % md
    return c


def pwr(a, k):
    c = None
    while c == None:
        if k & 1:
            c = a
        a = dot(a, a)
        k >>= 1

    while k > 0:
        if k & 1:
            c = dot(a, c)
        a = dot(a, a)
        k >>= 1
    return c


md = 10 ** 9 + 7
n, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
print(sum([sum(pk) % md for pk in pwr(a, k)]) % md)
### BUGGY CODE ###

def resolve():
  N = int(input())
  A = [int(x) for x in input().split(" ")]
  if N == 0 and A[0] != 1:
    print(-1)
    return True
  max_node_in_depth = [sum(A[i:]) for i in range(len(A))]

  # 各 depth における最小値
  min_node_in_depth = [0] * (len(A))
  min_node_in_depth[-1] = max_node_in_depth[-1]
  index = -1
  for i in range(1, len(A)):
    min_node_in_depth[index] = -(-min_node_in_depth[index + 1] // 2) + A[index]
    index = index - 1

  result = 1
  recent = 1
  for min_node, max_mode, a in zip(min_node_in_depth[1:], max_node_in_depth[1:], A):
    # print(min_node, max_mode, a)
    num_of_node = (recent - a) * 2
    if num_of_node < min_node:
      print(-1)
      return True
    
    result += min(num_of_node, max_mode)
    recent = min(num_of_node, max_mode)

  print(result)


if __name__ == "__main__":
    resolve()

### FIXED CODE ###


def resolve():
  N = int(input())
  A = [int(x) for x in input().split(" ")]
  if N == 0 and A[0] != 1:
    print(-1)
    return True
  min_maxs = {}
  min_maxs[len(A)-1] = [A[-1], A[-1]]

  for index in reversed(range(len(A)-1)):
    min_maxs[index] = [min_maxs[index+1][0] // 2 + A[index], min_maxs[index+1][1] + A[index]]
  # print(min_maxs)
    # min_maxs.insert(0, [min_maxs[0][0] // 2 + a, min_maxs[0][1] + a])
  # print(min_maxs)
  # max_node_in_depth = [sum(A[i:]) for i in range(len(A))]

  # # 各 depth における最小値
  # min_node_in_depth = [0] * (len(A))
  # min_node_in_depth[-1] = max_node_in_depth[-1]
  # index = -1
  # for i in range(1, len(A)):
  #   min_node_in_depth[index] = -(-min_node_in_depth[index + 1] // 2) + A[index]
  #   index = index - 1

  # for min_max in min_maxs:
  #   print(min_max)

  result = 1
  recent = 1
  for index in range(1, len(A)):
    num_of_node = (recent - A[index-1]) * 2
    # print(min_max, num_of_node)
    if num_of_node < min_maxs[index][0]:
      print(-1)
      return True
    
    result += min(num_of_node, min_maxs[index][1])
    recent = min(num_of_node, min_maxs[index][1])

  print(result)

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

import collections

def make_hist(s):
  hist = collections.Counter()
  for c in s:
    hist[c] += 1
  return hist

ans = 0
s_hist = []
N = int(input())
for n in range(N):
  new_hist = make_hist(input().strip())
  for s in s_hist:
    if(s == new_hist):
      ans += 1
  s_hist.append(new_hist)
print(ans)

### FIXED CODE ###

import collections

N = int(input())
s_hist = collections.Counter()

for n in range(N):
    s = input().strip()
    s_hist[" ".join(sorted(s))] += 1

ans = 0
for pair in s_hist.most_common():
    ans += s_hist[pair[0]]*(s_hist[pair[0]]-1)/2
    if(pair[1] == 1):
        break
print(int(ans))
### BUGGY CODE ###

N = int(input())

A = [int(input()) for _ in range(N)]

for i in range(N):
  print(max([elem for idx,elem in enumerate(A) if idx != i])) 

### FIXED CODE ###

N = int(input())

A = [(i,int(input())) for i in range(N)]

A.sort(key=lambda x :x[1],reverse=True)

for i in range(N):
  if A[0][0] != i:
    print(A[0][1])
  else:
    print(A[1][1])
### BUGGY CODE ###

s = input()
K = int(input())
w = []
for i in range(len(s)):
  for j in range(i,len(s)):
    temp = s[i:j+1]
    if temp not in w:
      w.append(temp)
      
w.sort()
print(w[K-1])

### FIXED CODE ###

s = input()
K = int(input())
w = []
for i in range(len(s)):
  for j in range(i,i+K):
    temp = s[i:j+1]
    if temp not in w:
      w.append(temp)
      
w.sort()
print(w[K-1])
### BUGGY CODE ###

def resolve():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(0, N-3):
        si = S[i]
        for a in retA(si):
            idx1 = S.find(a, i)
            while idx1 != -1:
                b = retB(a, si)
                cnt += S[idx1+1:].count(b)
                if 2*idx1 - i < N:
                    if S[2*idx1 - i] == b:
                        cnt -= 1
                idx1 = S.find(a, idx1+1)

    print(cnt)

def retA(a):
    if a == 'R':
        A = ('G', 'B')
    elif a == 'G':
        A = ('R', 'B')
    elif a == 'B':
        A = ('R', 'G')
    return A

def retB(a, x):
    if (a == 'R' or x == 'R') and (a == 'G' or x == 'G'):
        b = 'B'
    elif (a == 'B' or x == 'B') and (a == 'G' or x == 'G'):
        b = 'R'
    elif (a == 'B' or x == 'B') and (a == 'R' or x == 'R'):
        b = 'G'
    return b

if __name__ == '__main__':
    resolve()

### FIXED CODE ###

def resolve():
    N = int(input())
    S = input()
    rc = S.count('R')
    bc = S.count('B')
    gc = S.count('G')

    cnt = rc * bc * gc

    for i in range(0, N):
        for d in range(0, N):
            j = i + d
            k = j + d
            if N < k+1:
                break
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                cnt -= 1
    print(cnt)

if __name__ == '__main__':
    resolve()