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

n = int(input())
s = input()
ans = 0
for p1 in range(n-3):
    for p2 in range(p1+1, n-1):
        for p3 in range(p2+1, n):
            #print(s[p1], s[p2], s[p3])
            if (s[p1] != s[p2]) and (s[p1] != s[p3]) and (s[p2] != s[p3]) and (p1-p2 != p2-p3):
                ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
s = input()
dup = 0
r = s.count('R')
g = s.count('G')
b = s.count('B')

for i in range(n):
    for j in range(i+1, n):
        k = 2*j - i
        if k < n:
            #print(i,j,k)
            if (s[i] != s[j]) and (s[j] != s[k]) and (s[i] != s[k]):
                #print(s[i], s[j], s[k])
                dup += 1
print(r*g*b - dup)
### BUGGY CODE ###

import sys
def input():
	return sys.stdin.readline()[:-1]
from collections import deque
H, W, K = map(int, input().split())
sh, sw, gh, gw = map(int, input().split())
c = ["@" * (W+2)] + ["@" + input() + "@" for _ in range(H)] + ["@" * (W+2)]
INF = 10**7
dist = [[INF for _ in range(W+2)] for _ in range(H+2)]
dist[sh][sw] = 0
q = deque()
q.append(sh*(W+2)+sw)
DI = [1, 0, -1, 0]
DJ = [0, 1, 0, -1]
while q:
	l = q.popleft()
	i, j = l//(W+2), l%(W+2)
	if i == gh and j == gw:
		print(dist[i][j])
		sys.exit()
	for di, dj in zip(DI, DJ):
		for k in range(1, K+1):
			ii, jj = i+di*k, j+dj*k
			if c[ii][jj] == "." and dist[ii][jj] > dist[i][j]:
				dist[ii][jj] = dist[i][j] + 1
				q.append(ii*(W+2) + jj)
			else:
				break
print(-1)

### FIXED CODE ###

import sys
def input():
	return sys.stdin.readline()[:-1]
from collections import deque
H, W, K = map(int, input().split())
sh, sw, gh, gw = map(int, input().split())
c = ["@" * (W+2)] + ["@" + input() + "@" for _ in range(H)] + ["@" * (W+2)]
INF = 10**6+5
dist = [[INF for _ in range(W+2)] for _ in range(H+2)]
dist[sh][sw] = 0
q = deque()
q.append(sh*(W+2)+sw)
DI = [1, 0, -1, 0]
DJ = [0, 1, 0, -1]
while q:
	l = q.popleft()
	i, j = l//(W+2), l%(W+2)
	for di, dj in zip(DI, DJ):
		for k in range(1, K+1):
			ii, jj = i+di*k, j+dj*k
			if c[ii][jj] == "@":
				break
			if dist[ii][jj] <= dist[i][j]:
				break
			if dist[ii][jj] > dist[i][j] + 1:
				dist[ii][jj] = dist[i][j] + 1
				if ii == gh and jj == gw:
					print(dist[ii][jj])
					sys.exit()
				q.append(ii*(W+2) + jj)
print(-1)
### BUGGY CODE ###

N=int(input())

power=1
for i in range(N):
  power=power*(i+1)
  
print(power%(10**9+7))

### FIXED CODE ###

N=int(input())

power=1
for i in range(N):
  if power>10**9+7:
    power=(power%(10**9+7))*(i+1)
  else:
    power=power*(i+1)
 
print(power%(10**9+7))
#print(power%(10**9+7))
### BUGGY CODE ###

import math

X, Y = map(int, input().split())

if (X+Y) % 3 != 0:
    print(0)
else:
    m = (2*X - Y) / 3
    n = (2*Y - X) / 3
    if m < 0 or n < 0:
        print(0)
    else:
        ans = math.factorial(m+n) / (math.factorial(m) * math.factorial(n))
        print(int(ans))

### FIXED CODE ###

def cmb(m, n):
    if m - n < n:
        n = m - n
    if n == 0:
        return 1
    if n == 1:
        return m
    
    numerator = [m - n + k + 1 for k in range(n)]
    denominator = [k + 1 for k in range(n)]

    for p in range(2, n+1):
        pivot = denominator[p-1]
        if pivot > 1:
            offset = (m-n) % p
            for k in range(p-1, n, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    
    result = 1
    for k in range(n):
        if numerator[k] > 1:
            result = result * int(numerator[k]) % (10**9 + 7)

    return result

X, Y = map(int, input().split())

if (X+Y) % 3 != 0:
    print(0)
else:
    m = int((2*X - Y) / 3)
    n = int((2*Y - X) / 3)
    if m < 0 or n < 0:
        print(0)
    else:
        ans = cmb(m+n, n)
        print(int(ans))
### BUGGY CODE ###

n = int(input())
a_list = list(map(int,input().split()))
b_list = []

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

for i in range(n):
    if a_list[-i-1] == 1:
        b_list.append(n-i)
        for j in make_divisors(n-i):
            a_list[j-1] = abs(a_list[j-1]-1)

b_list.reverse()
x = len(b_list)
print(x)
if x != 0:
    print(*b_list)

### FIXED CODE ###

n = int(input())
a_list = list(map(int,input().split()))
b_list = [0]*(n)

for i in range(n):
    k = int(n-i-1)
    if a_list[k] != sum(b_list[k::k+1])%2:
        b_list[k] = 1

b_list = [i+1 for i,x in enumerate(b_list) if x ==1]
x = len(b_list)
print(x)
if x != 0:
    print(*b_list)
### BUGGY CODE ###

from collections import Counter
N, M, K = map(int, input().split())
friend = [[] for _ in range(N)]
block = [[] for _ in range(N)]

for _ in range(M):
	a, b = map(int, input().split())
	friend[a - 1].append(b - 1)
	friend[b - 1].append(a - 1)
	
for _ in range(K):
	c, d = map(int, input().split())
	block[c - 1].append(d - 1)
	block[d - 1].append(c - 1)
	
# 同じ連結成分にラベルを振る（まだラベルを振っていない = -1 で初期化）
label = [-1] * N

cnt_label_num = 0

for i in range(N):
	if label[i] != -1: continue # もう振ってあったら飛ばす
	
	# 振ってなかったら幅優先でラベルを振る
	Q = [i]
	while Q:
		cur = Q.pop(0)
		if label[cur] != -1: continue
		label[cur] = cnt_label_num
		for adj in friend[cur]:
			if label[adj] != -1: continue
			Q.append(adj)
	
	cnt_label_num += 1
	
# お友達候補計算
cnt = Counter(label)
for i in range(N):
	friend_candidate = cnt[label[i]] - 1 # 同じグラフにいる人
	friend_candidate -= len(friend[i]) # 元から友達を引く
	# blockしている人が同じグラフにいるときはその分引く
	for block_man in block[i]:
		if label[i] == label[block_man]:
			friend_candidate -= 1
	print(friend_candidate, end = " ")

### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import Counter
N, M, K = map(int, input().split())
friend = [[] for _ in range(N)]
block = [[] for _ in range(N)]

for _ in range(M):
	a, b = map(int, input().split())
	friend[a - 1].append(b - 1)
	friend[b - 1].append(a - 1)
	
for _ in range(K):
	c, d = map(int, input().split())
	block[c - 1].append(d - 1)
	block[d - 1].append(c - 1)
	
# 同じ連結成分にラベルを振る（まだラベルを振っていない = -1 で初期化）
label = [-1] * N

cnt_label_num = 0

for i in range(N):
	if label[i] != -1: continue # もう振ってあったら飛ばす
	
	# 振ってなかったら幅優先でラベルを振る
	Q = [i]
	while Q:
		cur = Q.pop()
		if label[cur] != -1: continue
		label[cur] = cnt_label_num
		for adj in friend[cur]:
			if label[adj] != -1: continue
			Q.append(adj)
	
	cnt_label_num += 1
	
# お友達候補計算
cnt = Counter(label)
for i in range(N):
	friend_candidate = cnt[label[i]] - 1 # 同じグラフにいる人
	friend_candidate -= len(friend[i]) # 元から友達を引く
	# blockしている人が同じグラフにいるときはその分引く
	for block_man in block[i]:
		if label[i] == label[block_man]:
			friend_candidate -= 1
	print(friend_candidate, end = " ")
### BUGGY CODE ###

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

res = 0
cnt = [False] * a[-1]
for i in range(n):
    j = 1
    while j * j <= a[i]:
        if a[i] % j == 0 and (cnt[j-1] or cnt[a[i]//j-1]):
            res += 1
            break
        j += 1
    if j * j > a[i] and i + 1 < n and a[i] == a[i+1]:
        res += 1
    cnt[a[i]-1] = True

print(n - res)

### FIXED CODE ###

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

used = [False] * a[-1]
res = 0
for i in range(n):
    if used[a[i]-1]:
        continue
    if i == n - 1 or a[i] != a[i+1]:
        res += 1
    for j in range(a[i], a[-1]+1, a[i]):
        used[j-1] = True

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

S = input()

S = list(map(int, S.split()))

A = S[0]
B = S[1]
C = S[2]
D = S[3]

count = 0

for i in range(A, B+1, 1):
    if (i % C) != 0 and (i % D) != 0:
        count = count + 1

print(count)


### FIXED CODE ###

import fractions

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

E = (C*D)//fractions.gcd(C,D)

B_count = B-((B//C)+(B//D)-(B//E))
A_count = (A-1)-(((A-1)//C)+((A-1)//D)-((A-1)//E))

print(B_count-A_count)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N = int(input())
A = sorted([int(i) for i in input().split()])

dp = [-1] * (A[-1]+1)
ans = 0
for i in range(N):
    a = A[i]
    if dp[a] != -1:
        continue

    if A.count(a) == 1:
        ans += 1
        for j in range(a+a, A[-1]+1, a):
            dp[j] = 0

print(ans)

### FIXED CODE ###

from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]
num = set(A)
count = Counter(A)
dp = [True] * (10**6 + 1)

for a in num:
    for n in range(a+a, 10**6+1, a):
        dp[n] = False

ans = 0
for a in num:
    if count[a] == 1 and dp[a] == True:
        ans += 1

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

import bisect

n = int(input())
l = sorted(map(int, input().split()))

ans = 0
for i in range(2,n)[::-1]:
    for j in range(1,i)[::-1]:
        a = bisect.bisect_left(l, l[i] + l[j] - 1, 0, j-1)
        b = bisect.bisect_right(l, l[i] - l[j], 0, j-1)
        #print(l[i] + l[j], l[i] , l[j], a, l[i] - l[j], l[i] - l[j] < l[a], a, b, l[:j])
        if l[i] - l[j] < l[a]:
            ans += a - b + 1
print(ans)


### FIXED CODE ###

import bisect

n = int(input())
l = sorted(map(int, input().split()))

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        ans += bisect.bisect_left(l,l[j]+l[i])-j-1
print(ans)
### BUGGY CODE ###

N, M, K = map(int, input().split())
MOD =  998244353

dp = [ [0] * (K+1) for _ in range(N+1)]

# 1個目
dp[1][0] = M

for i in range(1,N):
    for k in range(min(K+1, i+1)):
        dp[i+1][k] += dp[i][k] * (M-1) % MOD  # 違う色
        if K > k:
            dp[i+1][k+1] += dp[i][k] % MOD # 同じ色

print(sum(dp[N]) % MOD)

### FIXED CODE ###

N, M, K = map(int, input().split())
MOD = 998244353

fac = [1, 1] # 元テーブル
facinv = [1, 1] #逆元テーブル
inv = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    fac.append( ( fac[-1] * i ) % MOD )
    inv.append( ( -inv[MOD % i] * (MOD//i) ) % MOD )
    facinv.append( (facinv[-1] * inv[-1]) % MOD )

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return fac[n] * facinv[r] * facinv[n-r] % MOD

sum = 0
for k in range(K+1):
    sum += M * pow(M-1,N-1-k, MOD) * cmb(N-1,k) % MOD
    sum %= MOD

print(sum % MOD)
### BUGGY CODE ###

a,b,c,d=map(int,input().split())
num=0
for i in range(a,b+1):
    if i%c==0:
        continue
    if i%d==0:
        continue
    else:
        num+=1
print(num)

### FIXED CODE ###

#a以上b以下の整数のうちcでもdでも割り切れないものの個数を求めてください
#1以上b以下の整数の条件を満たすものから1以上a-1以下のもので条件を満たすものを取り除くようにすればいい
import fractions

a,b,c,d=map(int,input().split())
x=c*d//fractions.gcd(c,d)
n=b-((b//c)+(b//d)-b//(x))
m=(a-1)-((a-1)//c+(a-1)//d-(a-1)//(x))
print(n-m)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)

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

def get_max_score(scores, i, j):
    if i == j:
        return scores[i]
    return max(scores[i] - get_max_score(scores, i+1, j), scores[j] - get_max_score(scores, i, j-1))

print(get_max_score(scores, 0, len(scores)-1))


### FIXED CODE ###

import numpy as np
from numba import njit

N = int(input())
scores = np.array(list(map(int, input().split())), dtype='int64')
dpt = np.full((N, N), -10**18, dtype='int64')

@njit('i8(i8[:],i8[:,:],i8,i8)', cache=True)
def get_max_score(scores, dpt, i, j):
    if i == j:
        dpt[i][j] = scores[i]
        return scores[i]
    else:
        if dpt[i][j] != -10**18:
            return dpt[i][j]
        result = max(scores[i] - get_max_score(scores, dpt, i+1, j), scores[j] - get_max_score(scores, dpt, i, j-1))
        dpt[i][j] = result
        return result

print(get_max_score(scores, dpt, 0, len(scores)-1))
### BUGGY CODE ###

n, m, q = map(int, input().split())
ll = [[0, 0] for i in range(m)]
p = [[0, 0] for i in range(m)]
for i in range(m):
    ll[i][0], ll[i][1] = map(int, input().split())
for i in range(q):
    p[i][0], p[i][1] = map(int, input().split())
for i in range(q):
    ans = 0
    for j in range(m):
        if p[i][0] <= ll[j][0] and ll[j][1] <= p[i][1]:
            ans += 1
    print(ans)


### FIXED CODE ###

# あらかじめ全ての区間における答えを求めておく
# 累積和が使える。
# 2次元累積和に関しては、下記のサイトを参照。
# https://paiza.hatenablog.com/entry/2014/05/28/もし女子大生プログラマに『アルゴリズム』を図
# p,qの値に関しての2次元座標系で考えると、値が存在するマスは限られてる
#
#
n, m, q = map(int, input().split())
ll = [[0, 0] for i in range(m)]
p = [[0, 0] for i in range(q)]
for i in range(m):
    ll[i][0], ll[i][1] = map(int, input().split())
for i in range(q):
    p[i][0], p[i][1] = map(int, input().split())
# for i in range(m):
#     print(ll[i])
# for i in range(q):
#     print(p[i])
sum = [[0 for i in range(n)] for i in range(n)]
# sum上でlをy成分＝行、rをx成分=列とする。
# 各区間の値を取り込み
for j in range(m):
    x = ll[j][0]-1
    y = ll[j][1]-1
    sum[y][x] += 1
# 2次元累積和の計算
# for j in range(n):
#     print(sum[j])
# print('-'*30)
for i in range(n):
    for j in range(1, n):
        sum[i][j] += sum[i][j-1]
for i in range(n):
    for j in range(1, n):
        sum[j][i] += sum[j-1][i]
# ans = [[0 for i in range(n)] for i in range(n)]
# for i in range(n):
#    for j in range(i, n):
#        for i2 in range(i, j+1):
#            for j2 in range(i, j+1):
#                ans[i][j] += sum[j2][i2]
# for j in range(n):
#     print(sum[j])


for i in range(q):
    x = p[i][0]-1
    y = p[i][1]-1
    if x != 0:
        print(sum[y][y] - sum[y][x-1] - sum[x-1][y]+sum[x-1][x-1])
    else:
        print(sum[y][y])
### BUGGY CODE ###

from sys import stdin

n, k = [int(x) for x in stdin.readline().rstrip().split()]
MOD = 1000000007

c = [[0 for i in range(4005)] for j in range(4005)]
c[0][0] = 1
for i in range(4000):
    for j in range(i+1):
        c[i+1][j] += c[i][j]
        c[i+1][j+1] += c[i][j]


def combination(x, y):
    return c[x][y]


def f2(n, k):
    return combination(n+k-1, k-1)


def f(n, k):
    if n < k:
        return 0
    if n == 0 and k == 0:
        return 1
    if k < 1:
        return 0
    return f2(n-k, k)


for i in range(1, k+1):
    blue = f(k, i)
    red = 0
    red += f(n-k, i-1)
    red += f(n-k, i)
    red += f(n-k, i)
    red += f(n-k, i+1)
    ans = blue * red
    print(ans % MOD)


### FIXED CODE ###

from sys import stdin
from math import factorial

n, k = [int(x) for x in stdin.readline().rstrip().split()]
MOD = 1000000007


def combination(x, y):
    return factorial(x) // (factorial(x-y) * factorial(y))


for i in range(1, k+1):
    if n - k + 1 < i:
        ans = 0
    else:
        blue = combination(k-1, i-1)
        red = combination(n-k+1, i)
        ans = blue * red
    print(ans % MOD)
### BUGGY CODE ###

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

### FIXED CODE ###

N=int(input())
S=input()
ans=S.count("R")*S.count("G")*S.count("B")
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if 2*j-i<N:
            if S[i]!=S[j] and S[j]!=S[2*j-i] and S[i]!=S[2*j-i]:
                ans-=1
print(ans)
### BUGGY CODE ###

import numpy as np

N,M = map(int,input().split())
P = np.zeros(M, dtype=int)
S = np.zeros(M, dtype=int)
for i in range(M):
    p,s = map(str,input().split())
    P[i] = int(p)
    if s == 'AC':
        S[i] = 1
    
cOK = 0
cNG = 0
for q in range(1,N+1):
    Q = list(S[P==q])
    if 1 in Q:
        cOK += 1
        cNG += Q.index(1)

print(cOK, cNG)

### FIXED CODE ###

import numpy as np

N,M = map(int,input().split())
OK = np.zeros(N, dtype = int)
NG = np.zeros(N, dtype = int)
for i in range(M):
    p,s = map(str,input().split())
    p = int(p)
    if s == 'AC':
        s = 1
        OK[p-1]=1
    else:
        if OK[p-1]==0:
            NG[p-1]+=1
    
cOK = sum(OK)
cNG = sum(NG[OK==1])

print(cOK, cNG)
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
  for j in range(n):
    if A[i] == j+1:
      ans[j] = str(i+1)
      
print(" ".join(ans))

### FIXED CODE ###

n = int(input())
A = map(int, input().split())
L = [0] * n

for i,val in enumerate(A):
    L[val-1] = i + 1

print(*L)
### BUGGY CODE ###

import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
def check(x):
  if x==0:
    return 0
  else:
    t=0
    for i in range(N):
      t+=math.ceil(A[i]/x)-1
    if t<=K:
      return 10
    else:
      return 0
low=1
high=max(A)
sig=(low+high)//2
while True:
  if check(sig)==10:
    if check(sig-1)==0:
      ans=sig
      break
    else:
      high=sig-1
      sig=(low+sig)//2
  else:
    low=sig+1
    sig=(high+sig)//2
print(ans)

### FIXED CODE ###

import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
def check(x):
  if x==0:
    return 0
  else:
    t=0
    for i in range(N):
      t+=math.ceil(A[i]/x)-1
    if t<=K:
      return 10
    else:
      return 0
low=0
high=max(A)
sig=(low+high)//2
tf=0
if K==0:
  tf=1
  ans=high
while tf==0:
  if check(sig)==10:
    if check(sig-1)==0:
      ans=sig
      break
    else:
      high=sig-1
      sig=(low+high)//2
  else:
    low=sig+1
    sig=(high+low)//2
print(ans)
### BUGGY CODE ###

n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
l = []
for _ in range(m):
    l.append(list(map(int, input().split())))
    
l = sorted(l, key=lambda x:x[1])

for bi, ci in l:
    for i in range(bi):
        if a[i] < ci:
            a[i] = ci
    a = sorted(a)
    
print(sum(a))

### FIXED CODE ###

# coding: utf-8
# Your code here!

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

l = []
for _ in range(m):
    l.append(list(map(int, input().split())))
    
l = sorted(l, key=lambda x:x[1], reverse=True)

top_n = []
flag = False
for bi, ci in l:
    for _ in range(bi):
        if len(top_n) < n:
            top_n.append(ci)
        else:
            flag = True
    if flag:
        break
a.extend(top_n)

print(sum(sorted(a, reverse=True)[:n]))
### BUGGY CODE ###

import math

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

C = list(set(A))
M = len(C)
t = []
for i in range(M):
  t.append(A.count(C[i]))


s = []  
for i in range(M):
  ans = 0
  for j in range(M):
    if i == j:
      p = t[j]-1
    else:
      p = t[j]
    if p >=2:
      ans += math.factorial(p)/(math.factorial(p-2)*2)
  s.append(int(ans))

for i in range(N):
  print(s[C.index(A[i])])

### FIXED CODE ###

import math

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

C = list(set(A))
M = len(C)
t = []
anst = 0
dic = {}
for i in A:
  if not i in dic:
    dic[i] = 0
  dic[i] += 1

jisyo = {}
for i in range(M):
  temp = dic[C[i]]
  jisyo[C[i]] = temp
  #t.append(A.count(C[i]))
  if temp >=2:
    anst += temp*(temp-1)/2

#jisyo = dict(zip(C, t))
#print(jisyo)   
for i in range(N):
  #print(t[C.index(A[i])])
  print(int(anst-jisyo[A[i]]+1))
### BUGGY CODE ###

n = int(input())
table = [[0 for i in range(3)] for k in range(n-1)]
for i in range(n-1):
	c,s,f = map(int,input().split())
	table[i][0] = c
	table[i][1] = s
	table[i][2] = f
sum = []
for i in range(n-1):
	total = table[i][1]+table[i][0]
	for k in range(i+1,n-1):
		if total <= table[k][1]:
			total = table[k][1] + table[k][0]
		else:
			times = 1
			while (times*table[k][2] + table[k][1]) < total:
				times += 1
			total = times*table[k][2] + table[k][1] + table[k][0]
	sum.append(total)
for i in range(n-1):
	print(sum[i])
print('0')

### FIXED CODE ###

n = int(input())
table = [[0 for i in range(3)] for k in range(n-1)]
for i in range(n-1):
	c,s,f = map(int,input().split())
	table[i][0] = c
	table[i][1] = s
	table[i][2] = f
for i in range(n-1):
	total = table[i][1]+table[i][0]
	for k in range(i+1,n-1):
		if total <= table[k][1]:
			total = table[k][1] + table[k][0]
		else:
			sur = total%table[k][2]
			if sur == 0:
				total = total + table[k][0]
			else:
				total = (total - sur) + table[k][2] + table[k][0]
	print(total)
print('0')
### BUGGY CODE ###

K = int(input())

ans = 0

import math

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

print(ans)

### FIXED CODE ###

K = int(input())

ans = 0

import math

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

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

from collections import Counter

N = int(input())
s = []
for i in range(N):
    s.append(input())
count = 0
for i in range(N):
    for j in range(N - i - 1):
        if Counter(s[i]) == Counter(s[i + j + 1]):
            count += 1
print(count)


### FIXED CODE ###

from collections import defaultdict

N = int(input())
s = defaultdict(lambda:0)
count=0

for i in range(N):
  a = "".join(sorted(input()))
  s[a] +=1
  
  if s[a] >1:
    count += s[a]-1
print(count)
### BUGGY CODE ###

import itertools
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,MOD = map(int,input().split())
if N == 1:
    print(1)
    exit()
graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    x,y = map(int,input().split())
    graph[x].append(y)
    graph[y].append(x)

def dfs_1(v=1,parent=None):
    # 子ごとに、そこを黒くして適切 or 完全白
    # dp_1 + 1 の積
    x = 1
    for w in graph[v]:
        if w == parent:
            continue
        x *= (dfs_1(w,v) + 1)
    dp_1[v] = x
    return x

dp_1 = [0] * (N+1) # 自分を黒く塗って、子側の部分木を適切に塗る方法
dfs_1()

def make_products(arr):
    # 左右からの積を作る方法
    f = lambda x,y: x*y%MOD
    L = [1] + list(itertools.accumulate(arr[:-1], f))
    R = list(itertools.accumulate(arr[::-1][:-1], f))[::-1] + [1]
    return [f(x,y) for x,y in zip(L,R)]

def dfs_2(v=1,parent=None,x=1):
    # それぞれの子以外の情報をマージして、子に渡さなければいけない
    arr = [1 + dp_1[w] if w != parent else x for w in graph[v]]
    products = make_products(arr)
    dp[v] = arr[0] * products[0] % MOD
    for w,p in zip(graph[v],products):
        if w==parent:
            continue
        dfs_2(w,v,p+1)

dp = [0] * (N+1)
dfs_2()

print('\n'.join(map(str,dp[1:])))



### FIXED CODE ###

import itertools
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,MOD = map(int,input().split())
if N == 1:
    print(1)
    exit()
graph = [set() for _ in range(N)]
for row in sys.stdin.readlines():
    x,y = map(int,row.split())
    graph[x-1].add(y-1)
    graph[y-1].add(x-1)

ldp = [None] * N
rdp = [None] * N

def dfs_1(v=0,parent=None):
    # 子ごとに、そこを黒くして適切 or 完全白
    graph[v].discard(parent)
    ldp[v] = [1] * (len(graph[v])+1)
    rdp[v] = [1] * (len(graph[v])+1)
    vals = [dfs_1(w,v)+1 for w in graph[v]]
    for i,x in enumerate(vals,1):
        ldp[v][i] = ldp[v][i-1] * x % MOD
    for i,x in enumerate(reversed(vals),1):
        rdp[v][-i-1] = rdp[v][-i] * x % MOD
    return ldp[v][-1]

dfs_1()

dp = [None] * N
q = [(0,1)]
while q:
    v,x = q.pop()
    dp[v] = x*ldp[v][-1]%MOD
    for w,L,R in zip(graph[v],ldp[v][:-1],rdp[v][1:]):
        q.append((w,x*L*R%MOD+1))

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

def main():
  import bisect
  import sys
  from itertools import accumulate
  input = sys.stdin.readline
  def hsnum(x):
    num = 0
    for i in a:
      y = x-i
      num += n-bisect.bisect_left(a,y)
    return num
  n,m = map(int, input().split())
  a = list(map(int, input().split()))
  a.sort()
  suma = [0]+list(accumulate(a))
  lx = 0
  rx = 2*10**5+2
  error = 0
  while lx < rx:
    mx = (lx+rx)//2
    if hsnum(mx) < m:
      rx = mx
    elif hsnum(mx) > m:
      if hsnum(mx+1) < m:
        error = hsnum(mx)-m
        lx = mx
        break
      lx = mx + 1
    else:
      lx = mx
      break
  ans = 0
  for i in a:
    rema = lx - i
    j = bisect.bisect_left(a,rema)
    ans += (n-j)*i-suma[j]
  ans += suma[n]*n
  print(ans-error*lx)
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
  import bisect
  import sys
  from itertools import accumulate
  input = sys.stdin.readline
  def hsnum(x):
    num = 0
    for i in a:
      y = x-i
      num += n-bisect.bisect_left(a,y)
    return num
  n,m = map(int, input().split())
  a = list(map(int, input().split()))
  a.sort()
  suma = [0]+list(accumulate(a))
  lx = 0
  rx = 2*10**5+2
  error = 0
  while lx+1 < rx:
    mx = (lx+rx)//2
    if hsnum(mx) < m:
      rx = mx
    elif hsnum(mx) > m:
      lx = mx + 1
    else:
      lx = mx
      break
  if hsnum(lx)<m:
    lx -= 1
  error = hsnum(lx)-m
  ans = 0
  for i in a:
    rema = lx - i
    j = bisect.bisect_left(a,rema)
    ans += (n-j)*i-suma[j]
  ans += suma[n]*n
  print(ans-error*lx)
if __name__ == "__main__":
    main()