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

d = int(input())
C = list(map(int, input().split()))
S = list(list(map(int, input().split())) for _ in range(d))

out = []

def compute(task_list):
    res = 0
    kaisai = [0] * 26
    date = 0
    for t in task_list:
        date += 1
        kaisai[t-1] = date
        res += S[date - 1][t-1]
    
        for i in range(26):
            res -= C[i] * (date - kaisai[i])
        
    return res

for _ in range(d):
    score = 0
    best_task = 0

    for i in range(26):
        out.append(i)
        tmp = compute(out)

        if tmp > score:
            score = tmp
            best_task = i
        
        out.pop()

    out.append(best_task)

print(*out, sep = '\n')


### FIXED CODE ###

d = int(input())
c = list(map(int, input().split()))
s = list(map(int, input().split()) for _ in range(d))

import random
for i in range(d):
    print(int(random.uniform(1, 26)))
### BUGGY CODE ###

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

cnt = [0] * (max(a) + 1)
for i in a:
    cnt[i] += 1
for i in set(a):
    if cnt[i] >= 1:
        for j in range(i * 2, max(a) + 1, i):
            cnt[j] = 0
print(cnt.count(1))


### FIXED CODE ###

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

cnt = [0] * (a[-1] + 1)
for i in a:
    cnt[i] += 1
for i in set(a):
    if cnt[i] >= 1:
        for j in range(i * 2, a[-1] + 1, i):
            cnt[j] = 0
print(cnt.count(1))
### BUGGY CODE ###

#!/usr/bin/env python3
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))

for k in range(K):
    D = [0]*N

    for i in range(N):
        D[i] += 1
        if A[i] == 0:
            continue

        left = math.ceil(i - A[i] - 0.5)
        right = math.floor(i + A[i] + 0.5)
        if left < 0: left = 0
        if right > N-1: right = N-1
    
        for j in range(left, right+1):
            if i == j: continue
            D[j] += 1

    A = D


print(' '.join(map(str,A)))

    


### FIXED CODE ###

#!/usr/bin/env python3
N, K = map(int, input().split())
A = list(map(int, input().split()))

if K > 41:
    K = 41

for k in range(K):
    D = [0]*N

    for i in range(N):
        left = max(i - A[i], 0)
        right = min(i + A[i], N-1)
        D[left] += 1
        if right + 1 < N: D[right+1] -= 1
    

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


print(' '.join(map(str,A)))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().strip().split()))
flg = 0
for i in range(n):
  for j in range(n):
    if i != j:
      if a[i] == a[j]:
        flg += 1

if flg >= 1:
  print("NO")
else:
  print("YES")

### FIXED CODE ###

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

def has_duplicates(seq):
    return len(seq) != len(set(seq))

if has_duplicates(a):
  print("NO")
else:
  print("YES")
### BUGGY CODE ###

#A - AKIBA △
S = input()
S = list(S)

SS = []
for p in S:#Aを追加する空白を作る
    SS.append('')
    SS.append(p)
SS.append('')


result = 'NO'
if len(S) <= 9 and S.count('K') == S.count('I') == S.count('H') == S.count('B') == S.count('R') == 1 :
    for i in range(1<<(len(SS))):
        SSS = SS.copy()
        for j in range(len(SS)):
            mask = 1 << j
            if mask & i != 0:#処理を行う
                if SSS[j] == '':
                    SSS[j] = 'A'
        for k in SSS:
            if k == '':
                SSS.remove('')
        if SSS == ['A','K','I','H','A','B','A','R','A']:
            result = 'YES'
print(result)

### FIXED CODE ###

#A - AKIBA △
S = input()
S = list(S)

SS = []
for p in S:#Aを追加する空白を作る
    SS.append('')
    SS.append(p)
SS.append('')


result = 'NO'
if len(S) <= 9 and 'K' in S and 'I' in S and 'H' in S and 'B' in S and 'R' in S:
    for i in range(1<<(len(SS))):
        SSS = SS.copy()
        for j in range(len(SS)):
            mask = 1 << j
            if mask & i != 0:#処理を行う
                if SSS[j] == '':
                    SSS[j] = 'A'
        for k in SSS:
            if k == '':
                SSS.remove('')
        if SSS == ['A','K','I','H','A','B','A','R','A']:
            result = 'YES'
print(result)
### BUGGY CODE ###

n=int(input())
l =[]
for i in range(n):
        a = int(input())
        l.append(a)
        b = max(l)
for i in range(n):
        if l[i] == b:
                del l[i]
                print(max(l))
                l.insert(i,b)

        else:
                print(b)


### FIXED CODE ###

n=int(input())
a = [int(input()) for _ in range(n)]
b = max(a)
c = a.index(b)
for i in range(n):
        if i == c:
                print(max(sorted(a)[:n-1]))
        else:
                print(b)
### BUGGY CODE ###

indices_expectation = {}
max_E = 0


def expectation(start_idx, dices):
    result = []
    for i, dice in enumerate(dices):
        if indices_expectation.get(start_idx + i) is None:
            indices_expectation[start_idx + i] = sum(list(range(1, dice + 1))) / dice
        result.append(indices_expectation[start_idx + i])
    return sum(result)


line = input().split(" ")
N, K = int(line[0]), int(line[1])
line = input().split(" ")
p = [int(c) for c in line]

for s_idx in range(0, N - K + 1):
    dices = p[s_idx:s_idx + K]
    E = expectation(s_idx, dices)
    if E < max_E:
        continue
    else:
        max_E = E

print(max_E)


### FIXED CODE ###

from collections import deque


line = input().split(" ")
N, K = int(line[0]), int(line[1])
line = input().split(" ")
dices = [int(c) for c in line]

max_E = 0
expectations = deque([0] * K, maxlen=K)
e_memo = {}
E = 0
for dice in dices:
    E -= expectations.popleft()
    if e_memo.get(dice) is None:
        e_memo[dice] = sum(range(1, dice + 1)) / dice
    e = e_memo[dice]
    expectations.append(e)
    E += e
    if E < max_E:
        continue
    else:
        max_E = E

print(max_E)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)


def dfs4t(a, par):
    for child in edge[a]:
        if child == par:
            continue
        else:
            cost4t[child] = cost4t[a] + 1
            dfs4t(child, a)
    return

def dfs4a(a, par):
    for child in edge[a]:
        if child == par:
            continue
        else:
            cost4a[child] = cost4a[a] + 1
            dfs4a(child, a)
    return


N, u, v = map(int, input().split())
edge = [[] for _ in range(N)]
cost4t = [10**5 for i in range(N)]
cost4a = [10**5 for i in range(N)]

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

u -= 1
v -= 1
cost4t[u] = 0
cost4a[v] = 0
dfs4t(u, 10**5)
dfs4a(v, 10**5)

ans = 0
for t, a, in zip(cost4t, cost4a):
    if a  >= t:
        ans = max(ans, t + a - (t + 1))
print(ans)





### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)


def dfs4t(a, par):
    for child in edge[a]:
        if child == par:
            continue
        else:
            cost4t[child] = cost4t[a] + 1
            dfs4t(child, a)
    return

def dfs4a(a, par):
    for child in edge[a]:
        if child == par:
            continue
        else:
            cost4a[child] = cost4a[a] + 1
            dfs4a(child, a)
    return


N, u, v = map(int, input().split())
edge = [[] for _ in range(N)]
cost4t = [10**5 for i in range(N)]
cost4a = [10**5 for i in range(N)]

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

u -= 1
v -= 1
cost4t[u] = 0
cost4a[v] = 0
dfs4t(u, 10**5)
dfs4a(v, 10**5)

ans = 0
for t, a, in zip(cost4t, cost4a):
    if a  >= t:
        ans = max(ans, t + a - (t + 1))
print(ans)
### BUGGY CODE ###

s = input()
t = input()
n = len(s)
m = len(t)
dp = [[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]

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

ans = ''
i = n
j = m
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()
t = input()
n = len(s)
m = len(t)
dp = [[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]

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

ans = ''
i = n
j = m
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 ###

inf = input().split()
N = int(inf[0])
M = int(inf[1])
ls = []
m = 0
for i in range(M):
  inf = input().split()
  L = int(inf[0])-1
  R = int(inf[1])-1
  x = max(L,R)
  if x > m:
    m = x
  ls += [(L,R)]

ans = [True]*(m+1)

for s in ls:
  ans[:s[0]] = [False]*len(ans[:s[0]])
  ans[s[1]+1:] = [False]*len(ans[s[1]+1:])

print(sum(ans))

### FIXED CODE ###

inf = input().split()
N = int(inf[0])
M = int(inf[1])
ls = []
m = 0
pair = [0,N]
for i in range(M):
  inf = input().split()
  L = int(inf[0])
  R = int(inf[1])
  pair[0] = max(pair[0], L)
  pair[1] = min(pair[1], R)
  if pair[0]>pair[1]:
    print(0)
    break
else:
  print(pair[1]-pair[0]+1)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

class HashTable(list):
    def __init__(self, length):
        list.__init__(self)
        self.length = length
        self[:] = [None] * length

    def h1(self, key):
        return key % self.length

    def h2(self, key):
        return 1 + (key % (self.length - 1))

    def h(self, key, i):
        return (self.h1(key) + i*self.h2(key)) % self.length

    def insert(self, key):
        i = 0
        while True:
            j = self.h(key, i)
            if self[j] is None:
                self[j] = key
                return j
            else:
                i += 1
    
    def search(self, key):
        i = 0
        while True:
            j = self.h(key, i)
            if self[j] == key:
                return j
            elif self[j] is None or i >= self.length:
                return None
            else:
                i += 1

def getNum(char):
    char2num = str.maketrans("ACGT", "1234")
    return int(char.translate(char2num))

if __name__ == '__main__':

    n = int(input())
    T = HashTable(n)
    C = [input().split(" ") for i in range(n)]
    
    C = map(lambda x:(x[0], getNum(x[1])), C)
    
    for command, num in C:
        if command == "insert":
            T.insert(num)
        else:
            if T.search(num) is None:
                print("no")
            else:
                print("yes")



### FIXED CODE ###

# -*- coding: utf-8 -*-

class HashTable(list):
    def __init__(self, length):
        list.__init__(self)
        self.length = length
        self[:] = [None] * length

    def h(self, key, i):
        h1 = key % self.length
        h2 = 1 + (key % (self.length - 1))
        return (h1 + i*h2) % self.length

    def insert(self, key):
        i = 0
        while True:
            h1 = key % self.length
            h2 = 1 + (key % (self.length - 1))
            j = (h1 + i*h2) % self.length
            #j = self.h(key, i)
            if self[j] is None:
                self[j] = key
                return j
            else:
                i += 1
    
    def search(self, key):
        i = 0
        while True:
            h1 = key % self.length
            h2 = 1 + (key % (self.length - 1))
            j = (h1 + i*h2) % self.length
            #j = self.h(key, i)
            if self[j] == key:
                return j
            elif self[j] is None or i >= self.length:
                return None
            else:
                i += 1

def getNum(char):
    char2num = str.maketrans("ACGT", "1234")
    return int(char.translate(char2num), 5)

if __name__ == '__main__':

    n = int(input())
    T = HashTable(1046527)
    C = [input().split(" ") for i in range(n)]
    
    for command, char in C:
        num = getNum(char)
        if command[0] == "i":
            T.insert(num)
        else:
            if T.search(num) is None:
                print("no")
            else:
                print("yes")
### BUGGY CODE ###

import sys
input=sys.stdin.readline

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

dp = [0 for j in range(W + 1)]
items = []
for i in range(N):
  w, v = map(int, input().split())
  items.append((w, v))
  
for w, v in items:
  for wk in range(W, w - 1, -1):
    tv = dp[wk - w] + v
    if tv > dp[wk]:
      dp[wk] = tv
print(max(dp))


### FIXED CODE ###

def nap(n, cap):
    val = [0] * (cap + 1)
    for _ in range(n):
        w, v = map(int, input().split())
        for wk in range(cap, w - 1, -1):
            nv = val[wk - w] + v
            if val[wk] < nv:
                val[wk] = nv
    return max(val)


n, cap = map(int, input().split())
print(nap(n, cap))
### BUGGY CODE ###

import sys

N, Q = map(int, sys.stdin.readline().split())
S = sys.stdin.readline().strip()
for _ in range(Q):
    l, r = map(int, sys.stdin.readline().split())
    print(len(S[l - 1:r].split("AC")) - 1)


### FIXED CODE ###

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

cc = []

acc = 0

for idx in range(N):
    if S[idx - 1:idx + 1] == "AC":
        acc = acc + 1
    cc.append(acc)

for i in range(Q):
    l, r = map(int, input().split())
    print(cc[r - 1] - cc[l - 1])
### BUGGY CODE ###

n = int(input())
numlist = input().split()

for i in range(1,n+1):
	print(numlist.count(str(i)))


### FIXED CODE ###

n = int(input())
numlist = list(map(int, input().split()))
# print(numlist)
result = [0] * n
# print(result)

for i in numlist:
	result[i - 1] = result[i - 1] + 1

for j in range(len(result)):
	print(result[j])
# for i in range(1, n + 1):
#	print(numlist.count(i))
### BUGGY CODE ###

import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = i_list()

    ans = 1

    for num in num_list:
        ans *= num

    if ans > 10**18:
        print(-1)
    else:
        print(ans)
            
if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = i_list()

    zero_c = num_list.count(0)

    if zero_c >= 1:
        print(0)
        exit()

    ans = 1

    max_num = 10**18

    for num in num_list:
        ans *= num
        if ans > max_num:
            print(-1)
            exit()

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

def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
s = list(input())
baf = [i for i, x in enumerate(s) if x == 'B']
raf = [i for i, x in enumerate(s) if x == 'R']
gaf = [i for i, x in enumerate(s) if x == 'G']
bbf = []
rbf = []
gbf = []
ans = 0
for i,item in enumerate(s):
    if item == 'B':
        baf.remove(i)
        bbf.append(i)
        for j in rbf:
            if 2*i-j in gaf:
                ans += len(gaf)-1
            else:
                ans += len(gaf)
        for j in gbf:
            if 2*i-j in raf:
                ans += len(raf)-1
            else:
                ans += len(raf)
    elif item == 'R':
        raf.remove(i)
        rbf.append(i)
        for j in gbf:
            if 2*i-j in baf:
                ans += len(baf)-1
            else:
                ans += len(baf)
        for j in bbf:
            if 2*i-j in gaf:
                ans += len(gaf)-1
            else:
                ans += len(gaf)
    else:
        gaf.remove(i)
        gbf.append(i)
        for j in rbf:
            if 2*i-j in baf:
                ans += len(baf)-1
            else:
                ans += len(baf)
        for j in bbf:
            if 2*i-j in raf:
                ans += len(raf)-1
            else:
                ans += len(raf)

print(ans)


### FIXED CODE ###

def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
s = list(input())
baf = s.count('B')
raf = s.count('R')
gaf = s.count('G')
bbf = 0
rbf = 0
gbf = 0
ans = 0
for i,item in enumerate(s):
    if item == 'B':
        baf -= 1
        bbf += 1
        ans += rbf*gaf
        ans += raf*gbf
    elif item == 'R':
        raf -= 1
        rbf += 1
        ans += bbf*gaf
        ans += baf*gbf
    else:
        gaf -= 1
        gbf += 1
        ans += rbf*baf
        ans += raf*bbf
cnt = 0
for i in range(n):
    num = min(i,n-1-i)
    for j in range(1,num+1):
        if s[i-j] != s[i+j] and s[i-j] != s[i] and s[i+j] != s[i]:
            cnt += 1
print(ans-cnt)
### BUGGY CODE ###

# https://beta.atcoder.jp/contests/arc098/tasks/arc098_a
# C - Attention

# C_Attention.py

N = int(input())
S = input()

e = [0 for i in range(N)]
w = [0 for i in range(N)]

#print("累積和")

for i in range(N):
    # そこからE側の人で、Wを向くべきなのにEを向いている人
    if S[i] == "E":
        for j in range(0, i):
            e[j]+=1
    # そこからW側の人で、Eを向くべきなのにWを向いている人
    elif S[i] == "W":
        for j in range(i+1, N):
            w[j]+=1
    #print("i:", i)
    #print("w:", w)
    #print("e:", e)
    #print("")

#w[0] = 0
#e[-1] = 0

#print("w:", w)
#print("e:", e)
min = 10 ** 6

for i in range(N):
    total = e[i]+w[i]
    if total < min:
        min = total
print(min)


### FIXED CODE ###

# https://beta.atcoder.jp/contests/arc098/tasks/arc098_a
# C - Attention

# C_Attention.py

N = int(input())
S = input()

e = [0 for i in range(N)]
w = [0 for i in range(N)]
d = [0 for i in range(N)]
#print("累積和")

for i in range(N):
    # そこからE側の人で、Wを向くべきなのにEを向いている人
    #if S[i] == "E":
    #    for j in range(0, i):
    #        e[j]+=1
    #        d[j]+=1
    # そこからW側の人で、Eを向くべきなのにWを向いている人
    if i > 0:
        w[i] += w[i-1]
    if i < N-1:
        if S[i] == "W":
            w[i+1] += 1
    if i > 0:
        e[N-1-i] += e[N-1-(i-1)]
    if i < N-1:
        if S[N-1-i] == "E":
            e[N-1-(i+1)] += 1

    #print("i:", i)
    #print("w:", w)
    #print("e:", e)
    #print("")

#w[0] = 0
#e[-1] = 0

#print("w:", w)
#print("e:", e)
min = 10 ** 6
for i in range(N):
    total = e[i] + w[i]
    if total < min:
        min = total
print(min)
### BUGGY CODE ###

import bisect

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

for i in range(M):
  B, C = map(int, input().split())
  idx = bisect.bisect_left(A, C)
  if B < idx:
    A = A[B:idx] + [C]*B + A[idx:]
  else:
    A = [C]*idx + A[idx:]
  
print(sum(A))

### FIXED CODE ###

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

CB = []
for i in range(M):
  b, c = map(int, input().split())
  CB.append([c, b])

D = [[a, 1] for a in A] + CB

D.sort()

ans = 0
while N > 0:
  c, b = D.pop()
  ans += min(N, b)*c
  N -= b

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

N  = int(input())
p = 1
for i in range(1,N+1):
  p*=i
  
print(p%(10**9+7)  )

### FIXED CODE ###

N  = int(input())
#N = 10**5
p = 1
#x = [p*i for i in range(1,N+1)]
for i in range(1,N+1):
  p =i*p%(10**9+7)
#  print(p)
  
  
  
print(p)
### BUGGY CODE ###

import math
ans = 0
def gcd_list(a):
    tmp = math.gcd(a[0],a[1])
    return math.gcd(tmp,a[2])
k = int(input())
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            a = [i,j,k]
            ans += gcd_list(a)
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 k in range(1, K+ 1):
            ans += math.gcd(k, tmp)
 
print(ans)
### BUGGY CODE ###

from collections import defaultdict, deque
from itertools import combinations

N, M, Q = map(int, input().split())
ABCD = [tuple(map(int, input().split())) for _ in range(Q)]

D = defaultdict(dict)
for a, b, c, d in ABCD:
  D[b-1][(a-1, c)] = d

for j in range(N-1, 0, -1):
  for x, y in combinations(D[j], 2):
    if x[0] == y[0]:
      continue
    if x[0] > y[0]:
      x, y = y, x
    if x[1] > y[1]:
      if (x[0], x[1] - y[1]) not in D[y[0]]:
        D[y[0]][(x[0], x[1] - y[1])] = 0

for j in range(1, N):
  if (j-1, 0) not in D[j]:
    D[j][(j-1, 0)] = 0

que = deque([([1], 0)])
ans = 0
while que:
  L, score = que.popleft()
  if len(L) == N:
    if score > ans:
      ans = score
  else:
    for a, c in D[len(L)]:
      l = L[a] + c
      if L[-1] <= l <= M:
        que.append((L + [l], score + sum(d for v, d in D[len(L)].items() if l - L[v[0]] == v[1])))
print(ans)

### FIXED CODE ###

from collections import defaultdict, deque
from itertools import combinations

N, M, Q = map(int, input().split())
ABCD = [tuple(map(int, input().split())) for _ in range(Q)]

D = defaultdict(dict)
for a, b, c, d in ABCD:
  D[b-1][(a-1, c)] = d

for j in range(N-1, 0, -1):
  for x, y in combinations(D[j], 2):
    if x[0] == y[0]:
      continue
    if x[0] > y[0]:
      x, y = y, x
    if x[1] > y[1]:
      if (x[0], x[1] - y[1]) not in D[y[0]]:
        D[y[0]][(x[0], x[1] - y[1])] = 0

for j in range(1, N):
  if (j-1, 0) not in D[j]:
    D[j][(j-1, 0)] = 0

que = deque([([1], 0)])
memo = set([(1,)])
ans = 0
while que:
  L, score = que.popleft()
  if len(L) == N:
    if score > ans:
      ans = score
  else:
    for a, c in D[len(L)]:
      l = L[a] + c
      if L[-1] <= l <= M:
        x = tuple(L + [l])
        if x not in memo:
          memo.add(x)
          que.append((L + [l], score + sum(d for v, d in D[len(L)].items() if l - L[v[0]] == v[1])))
print(ans)
### BUGGY CODE ###

N=int(input())
S=list(map(str,input()))
ans=0

for i in range(N-2):
  for j in range(N-i-2):
    if S[i]!=S[i+j+1]:
      for k in range(N-i-j-2):
        if S[i]!=S[i+j+k+2] and S[i+j+1]!=S[i+j+k+2] and j!=k:
          ans+=1

print(str(ans))

### FIXED CODE ###

N=int(input())
S=list(map(str,input()))
L=[0,0,0]
for i in range(N):
  if S[i]=="R":
    L[0]+=1
  elif S[i]=="G":
    L[1]+=1
  elif S[i]=="B":
    L[2]+=1
ans=L[0]*L[1]*L[2]

for i in range(N-2):
  for j in range(int((N-i-1)/2)):
    if S[i]!=S[i+j+1] and S[i]!=S[i+2*j+2] and S[i+j+1]!=S[i+2*j+2]:
      ans-=1

print(str(ans))