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

n = input()
a = [int(num)% (10**9 + 7)  for num in input().split(" ")]

total = 0
for i in range(len(a)-1):
    for j in range(i+1, len(a)):
        total += (a[i]*a[j])
print(total% (10**9 + 7))


### FIXED CODE ###

n = input()
a = [int(num) for num in input().split(" ")]

mod_value = 10**9 + 7

sum = 0
total = 0
for i in reversed(range(1, len(a))):
    sum += a[i]
    total += a[i-1] * sum

print(total%mod_value)
### BUGGY CODE ###

def notempty(b):
    return any(map(lambda x: len(x), b))


n = int(input())
a = [list(reversed(list(map(lambda x:int(x) - 1, input().split()))))
     for _ in range(n)]
cnt = 0
while notempty(a):
    flg = 0
    cnt += 1
    li = [True] * n
    for i in range(n):
        if len(a[i]) and li[i] and len(a[[i][-1]]) and li[a[i][-1]] and a[a[i][-1]][-1] == i:
            5
            tmp = a[i][-1]
            a[i].pop()
            a[tmp].pop()
            li[i], li[tmp] = False, False
            flg = 1
    if not flg:
        print(-1)
        exit(0)
print(cnt)

### FIXED CODE ###

n = int(input())
g = [[] for _ in range(n ** 2)]
inv = [0] * (n ** 2)
for i in range(n):
    a = list(map(lambda x: int(x)-1, input().split()))
    for j in range(n - 2):
        p, q = min(i, a[j]), max(i, a[j])
        r, s = min(i, a[j + 1]), max(i, a[j + 1])
        g[p * n + q].append(r * n + s)
        inv[r * n + s] += 1
s = []
for i in range(n):
    for j in range(i + 1, n):
        if inv[i * n + j] == 0:
            s.append(i * n + j)
d = [0] * (n ** 2)
while s:
    p = s.pop()
    for node in g[p]:
        d[node] = max(d[node], d[p] + 1)
        inv[node] -= 1
        if inv[node] == 0:
            s.append(node)
for i in range(n):
    for j in range(i + 1, n):
        if inv[i * n + j] > 0:
            print(-1)
            exit(0)
print(max(d) + 1)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
x = []
for i in range(n):
    x.append(0)
for j in range(n):
    x.pop(a[j] - 1)
    x.insert(a[j] - 1, j + 1)
print(" ".join(map(str, x)))


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
x = []
for i in range(n):
    x.append((a[i], i + 1))
x.sort()
y = []
for i in range(n):
    y.append(x[i][1])
print(" ".join(map(str, y)))
### BUGGY CODE ###

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

for i in range(n):
    print(a.count(i + 1))

### FIXED CODE ###

n = int(input())
l = [0] * n
a = list(map(int,input().split()))

for i in range(n - 1):
    l[a[i] - 1] += 1

for i in range(n):
    print(l[i])
### BUGGY CODE ###

n, m = map(int, input().split())
arr = []
for _ in range(m):
    x, y = map(int, input().split())
    arr.append([i for i in range(x, y + 1)])
ans = arr[0]
for ar in arr:
    tmp = []
    for ele in ar:
        if ele in ans:
            tmp.append(ele)
    ans = tmp
print(len(ans))

### FIXED CODE ###

n, m = map(int, input().split())
ans = [i for i in range(1, n + 1)]

l_max = 0
r_min = n

for _ in range(m):
    x, y = map(int, input().split())
    l_max = max(l_max, x)
    r_min = min(r_min, y)

print(len([i for i in range(l_max, r_min + 1)]))
### BUGGY CODE ###

def main():
    n = int(input())
    a = [int(input()) for i in range(n)]

    for i in range(n):
        res = a[:i] + a[i+1:]
        print(max(res))

if __name__ == '__main__':
    main()



### FIXED CODE ###

def main():
    n = int(input())
    a = [int(input()) for i in range(n)]
    b = sorted(a, reverse=True)

    for i in range(n):
        if a[i] == b[0]:
            print(b[1])
        else:
            print(b[0])

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

N,K=[int(i) for i in input().split(" " )]
s = []
for i  in  range(N):
  s.append([int(ii) for ii in input().split(" ")])

p = []
for i in s:
  _  = [p.append(i[0]) for ii in range(i[1])]

p.sort()

print(p[K-1])


### FIXED CODE ###

N,K=[int(i) for i in input().split(" " )]
s = []
for i  in  range(N):
  s.append([int(ii) for ii in input().split(" ")])

s.sort( key=lambda x: x[0])  
countPush = 0
for i in s:
   countPush += i[1]
   if(countPush >= K ):
     print(i[0])
     break
### BUGGY CODE ###

import sys
MX = 10**5
def main():
    data = map(int, sys.stdin.buffer.read().split())
    N = next(data)
    IV, IW = [], []

    H = min(N + 1, 1 << 1)
    Hb = (H - 1).bit_length()
    dp = [[0] * (MX + 1) for _ in range(H)]
    i = 1
    for v, w in zip(data, data):
        if i < H:
            dpi = dp[i]
            dpip = dp[i >> 1]
            for j in range(w):
                dpi[j] = dpip[j]
            for j in range(w, MX + 1):
                dpi[j] = max(dpip[j], dpip[j - w] + v)
        else:
            IV.append(v)
            IW.append(w)
        i += 1
        if i > N:
            break

    Q = next(data)
    for v, L in zip(data, data):
        if v < H:
            print(dp[v][L])
            continue
        ans = []
        for i in range(1 << (v.bit_length() - Hb)):
            node = v
            value = weight = 0
            while node >= H:
                if i & 1:
                    value += IV[node - H]
                    weight += IW[node - H]
                    if weight > L:
                        break
                node >>= 1
                i >>= 1
            else:
                ans.append(value + dp[node][L - weight])
        print(max(ans))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
MX = 10**5
def main():
    data = map(int, sys.stdin.buffer.read().split())
    N = next(data)

    H = min(N + 1, 1 << 10)
    dp = [None] * H
    dp[0] = [0] * (MX + 1)
    IV, IW = [], []
    i = 1
    for v, w in zip(data, data):
        if i < H:
            dpi = dp[i >> 1][:]
            dp[i] = dpi
            for j in range(MX, w - 1, -1):
                dpi[j] = max(dpi[j], dpi[j - w] + v)
        else:
            IV.append(v)
            IW.append(w)
        i += 1
        if i > N:
            break

    Q = next(data)
    for v, L in zip(data, data):
        if v < H:
            print(dp[v][L])
            continue

        item_values = []
        item_weights = []
        while v >= H:
            item_values.append(IV[v - H])
            item_weights.append(IW[v - H])
            v >>= 1

        l = len(item_values)
        V = [0] * (1 << l)
        W = [0] * (1 << l)
        ans = dp[v][L]
        for i in range(1, 1 << l):
            msb = i & (-i)
            msbb = msb.bit_length() - 1
            wi = W[i - msb] + item_weights[msbb]
            W[i] = wi
            if wi <= L:
                vi = V[i - msb] + item_values[msbb]
                ans = max(ans, vi + dp[v][L - wi])
                V[i] = vi
        print(ans)

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

while True:
    num = int(input())

    index = 1
    for n in range(1, num):
        index += 1

        while True:
            str_index = str(index)
            if '4' in str_index or '6' in str_index:
                index += 1
            else:
                break

    print(index)

### FIXED CODE ###

""" Created by Jieyi on 9/20/16. """


def main():
    while True:
        num = int(input())
        if num == 0:
            break

        num = str(oct(num)[2:])
        ans = num.translate(str.maketrans('4567', '5789'))
        print(ans)


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

s = input()
c = 0

for i in range(len(s)+1):
    for j in range(i, len(s)+1):
        if s[i:j] != '':
            temp = int(s[i:j])
            if temp % 2019 == 0:
                c += 1

print(c)

### FIXED CODE ###

S = input()

mod = [0] * 2019
mod[0] = 1
digit = 1
temp = 0
 
for i in S[::-1]:
    temp = (temp + digit * int(i)) % 2019
    mod[temp] += 1
    digit = (digit * 10) % 2019

ans = 0
for m in mod:
    ans += m * (m - 1) // 2

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

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

count_table = [None, 2,5,5,4,5,6,3,7,6]

dp = [None for _ in range(n + 1)]
dp[0] = {0: 0}

for i in range(m):
    my_value = values[i]
    for j in range(n):
        dic = dp[j]
        if dic is not None and len(dic) > 0:
            my_count = 1
            while j + count_table[my_value] * my_count <= n:
                already = dp[j + count_table[my_value] * my_count] or {}
                new_dic = {k: v for k, v in dic.items()}
                new_dic[my_value] = my_count

                s = ''
                for value, cnt in reversed(sorted(already.items())):
                    s += str(value) * cnt
                s_already = s
                s = ''
                for value, cnt in reversed(sorted(new_dic.items())):
                    s += str(value) * cnt

                if s_already == '':
                    dp[j + count_table[my_value] * my_count] = new_dic
                elif s == '':
                    pass
                elif int(s_already) < int(s):
                    dp[j + count_table[my_value] * my_count] = new_dic

                my_count += 1

pin_dic = dp[n]

s = ''
for value, cnt in reversed(sorted(pin_dic.items())):
    s += str(value) * cnt
print(s)


### FIXED CODE ###

n, m = map(int, input().split())
aa = reversed(sorted(map(int, input().split())))

t = ['_', 2, 5, 5, 4, 5, 6, 3, 7, 6]

# n 本使ってできる最大の桁数
dp = [-1 for _ in range(n + 1)]
dp[0] = 0

for a in aa:
    for i in range(len(dp)):
        if dp[i] >= 0 and i + t[a] < len(dp):
            dp[i + t[a]] = max(dp[i + t[a]], dp[i] * 10 + a)

print(dp[n])
### BUGGY CODE ###

import heapq
x, y, z, k = map(int, input().split())

abc = []
heapq.heapify(abc)
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
for s in a:
    for t in b:
        for u in c:
            heapq.heappush(abc, -s-t-u)

for i in range(k):
    print(-heapq.heappop(abc))

### FIXED CODE ###

import heapq
import sys
x, y, z, k = map(int, input().split())

a, b, c = (sorted(map(int, sys.stdin.readline().split()), reverse=True) for _ in range(3))

abc = {(0,0,0)}

stu = [[-a[0]-b[0]-c[0], 0,0,0]]
heapq.heapify(stu)
result = []
while k > 0:
    out_p, n, m, l = heapq.heappop(stu)
    if n+1<x and not((n+1,m,l) in abc):
        abc.add((n+1,m,l))
        heapq.heappush(stu, [-a[n+1]-b[m]-c[l], n+1, m, l])
    if m+1<y and not((n,m+1,l) in abc):
        abc.add((n,m+1,l))
        heapq.heappush(stu, [-a[n]-b[m+1]-c[l], n, m+1, l])
    if l+1<z and not((n,m,l+1) in abc):
        abc.add((n,m,l+1))
        heapq.heappush(stu, [-a[n]-b[m]-c[l+1], n, m, l+1])
    result.append(-out_p)
    k -= 1
result.sort(reverse=True)
for i in result:
    print(i)
### BUGGY CODE ###

n,m=map(int, raw_input().split())
x=map(int, raw_input().split())
y=map(int, raw_input().split())

x1=[]
x_sum=0
for i in range(n):
	x_sum+=( len(x[:i])-len(x[i+1:]) )*x[i]

y_sum=0
for i in range(m):
	y_sum+=( len(y[:i])-len(y[i+1:]) )*y[i]


print x_sum*y_sum%(10**9+7)



### FIXED CODE ###

n,m=map(int, raw_input().split())
x=map(int, raw_input().split())
y=map(int, raw_input().split())

x1=[]
x_sum=0
for i in range(n):
	x_sum+=( (n-i-1)-i )*x[i]

y_sum=0
for i in range(m):
	y_sum+=( (m-i-1)-i )*y[i]


print x_sum*y_sum%(10**9+7)
### BUGGY CODE ###

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

max = (a*2)//b - a*(2//b)

for i in range(2,n+1):
    if (a*i)//b - a*(i//b) >= max:
        max = (a*i)//b - a*(i//b)

print(max)

### FIXED CODE ###

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

if n >= b-1:
    x = b-1
else:
    x = n

ans = (a*x)//b - a*(x//b)
print(ans)
### BUGGY CODE ###

import sys
from collections import deque

N = int(sys.stdin.readline())
A = sorted(list(map(int, sys.stdin.readline().split(' '))))

results = deque()
while len(A) > 0:
    if not (len(A) > 1 and A[0] == A[1]):
        results.append(A[0])
    A = [a for a in A if a % A[0] != 0]

print(len(results))


### FIXED CODE ###

from collections import Counter
import numpy as np

A_MAX = 10 ** 6 + 1

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

dp = np.zeros(shape=A_MAX, dtype=np.int64)

if A[1] == 1:
    print(1)
elif A[1] > 1:
    print(0)
else:
    for a in A.keys():
        multiples = np.arange(a, A_MAX, a)
        np.add.at(dp, multiples, 1)

    ans = 0
    for a, count in A.items():
        if count > 1:
            continue
        if dp[a] == 1:
            ans += 1

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

n = int(input())
s = input()
from itertools import combinations
nums = list(range(1,n+1))
p_list = list(combinations(nums, 3))

def remove_ele(tmp):
    final = []
    for i in tmp:
        if (i[1] - i[0]) != (i[2] - i[1]):
            final.append(i)
    return final
        
def spell_check(a,b,c):
    if a != b and b != c and c != a:
        return True
    else:
        return False
    
final_nums = remove_ele(p_list)
count = 0
for ele in final_nums:
    count += spell_check(s[ele[0]-1], s[ele[1]-1], s[ele[2]-1])
print(count)

### FIXED CODE ###

n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
total = r*g*b
for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            total -= 1
print(total)
### BUGGY CODE ###

n=int(input())
h=list(map(int,input().split()))
cnt=0
l=[]
while set(h)!={0}:
  if h.count(0)==0:
    cnt+=min(h)
    for i in range(len(h)):
      h[i]=h[i]-min(h)
  else:
    for i in range(len(h)):      
      if h[i]==0:
        l.append(h[i])
      else:
        l.append(h[i])
        continue
      cnt+=min(l)
      l=[]
print(cnt)

### FIXED CODE ###

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

ans = 0
pre = 0
for i in h:
    if pre < i:
        ans += i-pre

    pre = i

print(ans)
#copy code
### BUGGY CODE ###

import math
N = int(input())
A = 10
for n in range(1, N+1):
    num = 0
    for i in range(1, A):
        for j in range(1, A):
            for k in range(1, A):
                if math.pow(i + j + k, 2) == (i * j + j * k + k * i) + n:
                    num += 1
    print(num)


### FIXED CODE ###

# coding:utf-8
n = int(input())
ans = [0 for _ in range(10050)]
for i in range(1, 105):
    for j in range(1, 105):
        for k in range(1, 105):
            v = i*i+j*j+k*k+i*j+j*k+k*i
            if v < 10050:  #vはnを表していて、vのところで与式を満たす
                ans[v] += 1
for i in range(n):
    print(ans[i+1])
### BUGGY CODE ###

s = input()
q = int(input())

for i in range(q):
  query = list(input().split())
  if query[0] == "1":
    s = s[::-1]
  if query[0] == "2":
    if query[1] == "1":
      s = query[2] + s
    if query[1] == "2":
      s = s + query[2]
      
print(s)

### FIXED CODE ###

s = input()
q = int(input())

count = 0
top = []
bottom = []

for i in range(q):
  query = list(input().split())
  if query[0] == "1":
    count = (count + 1) % 2  
  if query[0] == "2":    
    if query[1] == "1":      
      if count == 0:        
        top.append(query[2])    
      else:
        bottom.append(query[2])
    if query[1] == "2":      
      if count == 0:        
        bottom.append(query[2])        
      else:       
        top.append(query[2])
  
t = "".join(top)
b = "".join(bottom)

lst = [t[::-1], s, b]
ans = "".join(lst)

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

N = int(input())
S = []
for i in range(N):
    S.append(str(input()))
words = []
for i in range(N):
    if S[i] not in words:
        words.append(S[i])
print(len(words))

### FIXED CODE ###

N = int(input())
S = []
for _ in range(N):
    s = str(input())
    S.append(s)
S1 = sorted(S)
counter=1
for i in range(N-1):
    if S1[i]!=S1[i+1]:
        counter+=1
print(counter)
### BUGGY CODE ###

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = [list(map(int, input().split())) for _ in range(M)]

for bc in BC:
    f = True
    for i in range(bc[0]):
        if A[i] > bc[1]:
            f = False
    if f:
        for i in range(bc[0]):
            A[i] = bc[1]
    A.sort()
print(sum(A))


### FIXED CODE ###

def cD():
    D = []
    for bc in BC:
        for i in range(bc[1]):
            D.append(bc[0])
            if len(D) > N:
                return D
    return D


N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = []
for _ in range(M):
    b, c = map(int, input().split())
    BC.append([c, b])
BC.sort(reverse=True)
D = cD()
for i in range(min(len(A), len(D))):
    if A[i] < D[i]:
        A[i] = D[i]
    else:
        break
print(sum(A))
### BUGGY CODE ###

s=input()
count_1=0
l=[]
num =int(input())
for i in range(num):
    q=input().rstrip().split()
    l.append(q)

for i in l:
    if i[0]=="1":
        s=s[::-1]
        
    else:
        if i[1]=="1":
            s=i[2]+s
        else:
            s=s+i[2]
print(s)

### FIXED CODE ###

s=input()
s1=""
s2=""
count_1=0
l=[]
num =int(input())
 
 
for x in range(num):
    i=input().rstrip().split()
    if i[0]=="1":
        count_1+=1
        
    elif i[1]=="1" and count_1%2==0:
        s1=i[2]+s1
   
    elif i[1]=="1" and count_1%2==1:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==0:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==1:
        s1=i[2]+s1
s=s1+s+s2
 
if count_1%2==1:
    s=s[::-1]
print(s)
### BUGGY CODE ###

import copy
import numpy as np
from math import factorial

def num_choice_2(N):
    if N > 1:
        return factorial(N) // (factorial(N - 2)* 2)
    else:
        return 0

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

nums = np.zeros(N, dtype=int)
for a_i in A:
    nums[a_i - 1] += 1

for i in range(N):
    nums[A[i] - 1] -= 1
    ans = np.sum([num_choice_2(x) for x in nums])
    nums[A[i] - 1] += 1
    print(ans)

### FIXED CODE ###

def n_c_2(n):
    if n < 1:
        return 0
    else:
        return n * (n - 1) // 2

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

n_balls = [0 for _ in A]
for a_i in A:
    n_balls[a_i - 1] += 1

n_combinations = [n_c_2(n) for n in n_balls]
total_combinations = sum(n_combinations)

for i, a_i in enumerate(A):
    diff = n_c_2(n_balls[a_i - 1]) - n_c_2(n_balls[a_i - 1] - 1)
    print(total_combinations - diff)
### BUGGY CODE ###

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

max_e=0
for i in range(N-(K-1)):
  v=p[i:K+i]
  smin=len(v)
  smax=sum(v)
  kou=smax-(smin-1)
  e=(smin+smax)/2

  if max_e<e:
    max_e=e
    
print(max_e)

### FIXED CODE ###

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

p = [(n+1)/2 for n in p]
import numpy as np
s = np.cumsum(p)

e=s[K-1]
max_e=e
for i in range(1,N-K):
  e=s[i+K]-s[i]
  max_e = max(max_e, e)
    
print(max_e)
### BUGGY CODE ###

A,B,Q=map(int,input().split())
s=[int(input()) for _ in range(A)]
t=[int(input()) for _ in range(B)]

#二分探索関数
def bin_search(x,seq):
	width=[0,len(seq)-1]
	if len(seq)<=1:
		return [0,0]
	if x<=seq[0]:
		return [0,0]
	elif x>=seq[width[1]]:
		return [width[1],width[1]]
	else:
		while(width[1]-width[0]>1):
			center=(sum(width)//2)
			if x>=seq[center]:
				width=[center,width[1]]
			else:
				width=[width[0],center]
	if x==seq[width[0]]:
		return [width[0],width[0]]
	elif x==seq[width[1]]:
		return [width[1],width[1]]
	else:
		return width

for i in range(Q):
	x=int(input())
	Nb_s0=s[bin_search(x,s)[0]]
	Nb_s1=s[bin_search(x,s)[1]]
	Nb_t0=t[bin_search(x,t)[0]]
	Nb_t1=t[bin_search(x,t)[1]]

	k1=abs(Nb_s0-x)+abs(Nb_t0-Nb_s0)
	k2=abs(Nb_s1-x)+abs(Nb_t0-Nb_s1)
	k3=abs(Nb_s0-x)+abs(Nb_t1-Nb_s0)
	k4=abs(Nb_s1-x)+abs(Nb_t1-Nb_s1)
	k5=abs(Nb_t0-x)+abs(Nb_t0-Nb_s0)
	k6=abs(Nb_t1-x)+abs(Nb_t1-Nb_s1)
	k7=abs(Nb_t0-x)+abs(Nb_t0-Nb_s1)
	k8=abs(Nb_t1-x)+abs(Nb_t1-Nb_s0)
	print(min(k1,k2,k3,k4,k5,k6,k7,k8))


### FIXED CODE ###

inf=10**11
A,B,Q=map(int,input().split())
s=[-inf]+[int(input()) for _ in range(A)]+[inf]
t=[-inf]+[int(input()) for _ in range(B)]+[inf]
x=[[i,int(input())] for i in range(Q)]

x.sort(key=lambda x:x[1])
i,s_i,t_i=0,0,0
ans=[]

for i in range(Q):
    while(1):
        if x[i][1]>=s[s_i]:
            s_i+=1
        else:
            break
    while(1):
        if x[i][1]>=t[t_i]:
            t_i+=1
        else:
            break
    ans.append([x[i][0],x[i][1],s[s_i-1],s[s_i],t[t_i-1],t[t_i]])
ans.sort(key=lambda x:x[0])
for i in range(Q):
    xx=ans[i][1]
    Nb_s0=ans[i][2]
    Nb_s1=ans[i][3]
    Nb_t0=ans[i][4]
    Nb_t1=ans[i][5]

    p1=abs(Nb_s0-xx)
    p2=abs(Nb_s1-xx)
    p3=abs(Nb_t0-xx)
    p4=abs(Nb_t1-xx)
    q1=abs(Nb_t0-Nb_s0)
    q2=abs(Nb_t0-Nb_s1)
    q3=abs(Nb_t1-Nb_s0)
    q4=abs(Nb_t1-Nb_s1)
    print(min(p1+q1,p2+q2,p1+q3,p2+q4,p3+q1,p4+q4,p3+q2,p4+q3))
### BUGGY CODE ###

N = int(input())
S = input()
count = 0

for i in range(N):
  for j in range(i+1,N):
    for k in range (j+1,N):
      if j-i == k-j:
        continue
      else:
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
          count+=1
          
print(count)

### FIXED CODE ###

N = int(input())
S = input()
ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N-2):
  for j in range(i+1,N-1):
      k = 2*j-i
      if k>=N:
        break
      if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
        ans-=1
          
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
a_list = list(map(int, input().split()))
prev = 1

for i in range(n - k + 1):
    score = 1
    for j in range(k):
        score *= a_list[i + j]
    if i != 0:
        if prev < score:
            print("Yes")
        else:
            print("No")
    prev = score


### FIXED CODE ###

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

for i in range(n - k):
    if a_list[i] < a_list[i + k]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    q = deque([])
    l = [input() for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j, 0))
    
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]

    while q:
        y, x, cost = q.popleft()
        m[y][x] = cost

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1, cost+1))

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()


### FIXED CODE ###

from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    l = [list(input()) for _ in range(H)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j))
                m[i][j] = 0
    
    while q:
        y, x = q.popleft()

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1))
                m[y1][x1] = m[y][x] + 1

    print(max(map(max, m)))


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

k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for h in range(1,k+1):
      p=i
      q=j
      r=h
      while q>=1:
        bk=p%q
        p=q
        q=bk
      while p>=1:
        bk=r%p
        r=p
        p=bk
      ans+=r
print(ans)

### FIXED CODE ###

import math
k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    tmp=math.gcd(i,j)
    for h in range(1,k+1):
      ans+=math.gcd(tmp,h)
print(ans)