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

A,B,C,K=map(int,input().split())
ans=0
if K >= A:
    ans+=A
    K-=A
    A=0
while K > 0 and A > 0:
    ans+=1
    K-=1
    A-=1
if K >= B:
    K-=B
    B=0
while K > 0 and B > 0:
    K-=1
    B-=1
if K >= C:
    ans-=C
    K-=C
    C=0
while K > 0 and C > 0:
    ans-=1
    K-=1
    C-=1
print(ans)

### FIXED CODE ###

A,B,C,K=map(int,input().split())
ans=0
if K >= A:
    ans+=A
    K-=A
    A=0
else:
    ans=K*1
    K=0
if K >= B:
    K-=B
    B=0
else:
    K=0
if K >= C:
    ans-=C
    K-=C
    C=0
else:
    ans=ans+K*(-1)
    C=0
print(ans)
### BUGGY CODE ###

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

mode = 0
for _ in range(q):
    query = input().split()
#     print(s, query, mode)
    if len(query) == 1:
        mode = 1 - mode
    else:
        if mode == 0:
            if query[1] == "1":
                s = query[2] + s
            else:
                s = s + query[2]
        else:
            if query[1] == "1":
                s = s + query[2]
            else:
                s = query[2] + s
if mode == 1:
    s = s[::-1]
print(s)

### FIXED CODE ###

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

pres = []
posts = []
mode = 0
for _ in range(q):
    query = input().split()
#     print(s, query, mode, pres, posts)
    if len(query) == 1:
        mode = 1 - mode
    else:
        if mode == 0:
            if query[1] == "1":
                pres.append(query[2])
            else:
                posts.append(query[2])
        else:
            if query[1] == "1":
                posts.append(query[2])
            else:
                pres.append(query[2])
s = "".join(pres[::-1]) + s + "".join(posts)
if mode == 1:
    s = s[::-1]
print(s)
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
now = [1]
ans =1
 
for i in range(k):
    if a[now[i]-1] in now:
        break
    now.append(a[now[i]-1])
 
    
t = len(now)-now.index(a[now[i]-1])
f = now.index(a[now[i]-1])


if k >= f + t:
    p = (k-f)%t
    k = f + p
    

print(now[k])

### FIXED CODE ###

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

visited = [None]*n
cur = 0
for i in range(k):
    if visited[cur] is None:
        visited[cur] = i
        cur = a[cur]-1
    else:
        break
else:
    print(cur+1)
    sys.exit()

k -= i
k %= i-visited[cur]

for i in range(k):
    cur = a[cur]-1

print(cur+1)
### BUGGY CODE ###

n = int(input())
def move(max_num,before):
  return min(max_num,before)

people = [n,0,0,0,0,0]
max_nums = []
for i in range(5):
  max_nums.append(int(input()))

time = 0
while True:
  time += 1
  move_p = [0] * 6
  for i in range(5):
    move_p[i] -= min(max_nums[i],people[i])
    move_p[i+1] += min(max_nums[i],people[i])
  people += move_p
  if people[-1] == n:
    break

print(time)

### FIXED CODE ###

n = int(input())

max_nums = []
for i in range(5):
  max_nums.append(int(input()))
max_nums.append(n)
a = n/min(max_nums)
print(int(a) +4+ (0 if a == int(a) else 1))
### BUGGY CODE ###

n = int(input())
a = []
for _ in range(n):
    a.append([int(i) - 1 for i in input().split()])

day = 0
while True:
    day += 1
    used = [0] * n
    for i in range(n):
        if a[i] and a[a[i][0]] and not used[i] and not used[a[i][0]] and a[a[i][0]][0] == i:
            used[i] = 1
            used[a[i][0]] = 1
            del a[a[i][0]][0]
            del a[i][0]
    if sum([len(i) for i in a]) == 0:
        print(day)
        break
    if sum(used) == 0:
        print(-1)
        break


### FIXED CODE ###

n = int(input())
e = [[] for _ in range(n * n)]
co = [0] * (n * n)
for i in range(n):
    a = [int(i)-1 for i in input().split()]
    for j in range(n - 2):
        aa, bb = min(i, a[j]), max(i, a[j])
        cc, dd = min(i, a[j+1]), max(i, a[j+1])
        e[aa * n + bb].append(cc * n + dd)
        co[cc * n + dd] += 1

x = []
for i in range(n * n):
    if co[i] == 0:
        x.append(i)

ans = 0
while x:
    y = []
    for i in x:
        for j in e[i]:
            co[j] -= 1
            if co[j] == 0:
                y.append(j)
    x = y
    ans += 1
if max(co) > 0:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=1
for i in a:
    ans*=i
print(-1 if ans>10**18 else ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
ans=0
if a[0]==0:
    print(0)
else:
    a=a[::-1]
    ans=a[0]
    for i in a[1:]:
        ans*=i
        if ans>10**18:
            print(-1)
            break
    else:
        print(ans)
### BUGGY CODE ###

from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

k=int(input())

if k%2==0 or k%5==0:
  print(-1)
  exit()

num=7
cnt=1
while num%k!=0:
  num=str(num)
  num+='7'
  num=int(num)
  cnt+=1

print(cnt)

### FIXED CODE ###

k=int(input())

if k%2==0 or k%5==0:
  print(-1)
  exit()

if k%7==0:
  l=9*k//7
else:
  l=9*k

ans=1
q=10%l

while q!=1:
  q*=10
  q%=l
  ans+=1

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

k = int(input())
ans = 0
import math
from functools import reduce
import itertools

def gcd(num):
    return reduce(math.gcd, num)
numlist = list(range(1, k+1))
l = list(itertools.product(numlist, repeat=3))

for v in l:
    ans += gcd(v)

print(ans)

### FIXED CODE ###

k = int(input())
ans = 0
import math
from functools import reduce

def gcd(*num):
    return reduce(math.gcd, num)

for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(a, b, c)
print(ans)
### BUGGY CODE ###


import bisect

"""
def wantp(n):

    wq = []
    while p[n] != n:
        wq.append(n)
        n = p[n]

    for i in wq:
        p[i] = n

    return n
"""


N = int(input())

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

"""
p = [i for i in range(N)]
rank = [1] * N
"""
used = [False] * N
ans = 0

for i in range(N):

    i = N - 1 - i
    now = 2 ** 33

    while A[i] * 2 < now:
        now //= 2

    na = A[-1]
    del A[-1]

    if used[i]:
        continue

    ind = bisect.bisect_left(A,now-na)

    while ind < i and used[ind]:
        ind += 1

    if ind < i and na + A[ind] == now:
        used[ind] = True
        ans += 1

    #print (now,na,ind)

print (ans)
        


### FIXED CODE ###


import bisect

"""
def wantp(n):

    wq = []
    while p[n] != n:
        wq.append(n)
        n = p[n]

    for i in wq:
        p[i] = n

    return n
"""


N = int(input())

B = list(map(int,input().split()))
B.sort()

A = []
AS = []
for i in range(N):
    if len(A) == 0:
        A.append(B[0])
        AS.append(1)
    else:
        if A[-1] == B[i]:
            AS[-1] += 1
        else:
            A.append(B[i])
            AS.append(1)


"""
p = [i for i in range(N)]
rank = [1] * N
"""
ans = 0

for i in range(len(A)):

    i = len(A) - 1 - i
    now = 2 ** 33

    while A[i] * 2 < now:
        now //= 2

    ind = bisect.bisect_left(A,now-A[i])

    if A[ind] + A[i] == now:

        if ind == i:
            ans += AS[i] // 2
            AS[i] = AS[i] % 2

        else:
            ans += min(AS[i],AS[ind])
            AS[ind] = max(AS[ind] - AS[i] , 0)



    #print (now,na,ind)

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

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

def o3gcd(array):
    x = array[0]
    for y in array:
        x = gcd(x, y)

    return x

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

result = 0

for i in range(N):
    array = A[:i]
    array.extend(A[i+1:])
    x = o3gcd(array)

    result = max(result, x)

print(result)

### FIXED CODE ###

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

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

L = [0]
for i in A:
    L.append(gcd(L[-1], i))

R = [0]
for i in range(N-1, -1, -1):
    R.append(gcd(R[-1], A[i]))
R.reverse()
M = []
for i in range(N):
    M.append(gcd(L[i], R[i+1]))

print(max(M))
### BUGGY CODE ###

R, C, K = map(int,input().split())
M = [[0] * C for i in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    M[r-1][c-1] = v

cost = [[[0]*4 for _ in range(C+1)] for _ in range(R+1)]
for x in range(R):
    for y in range(C):
        cost[x-1][y] = max(cost[x-1][y])
        for z in range(4):
            if z == 0:
                cost[x][y][z] = max(cost[x][y-1][z],cost[x-1][y]) 
            else:
                cost[x][y][z] = max(cost[x][y-1][z],cost[x][y-1][z-1]+M[x][y],cost[x-1][y]+M[x][y])

print(cost[-2][-2][-1])

### FIXED CODE ###

R, C, K = map(int,input().split())
V = [[]for i in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    V[r-1].append([c,v])
cost = [0]*(C+1)
for r in range(R):
    V[r].sort()
    hoge = [0,0,0,0]
    for c,v in V[r]:
        for i in range(3,0,-1):
            hoge[i] = max(cost[c]+v,hoge[i-1]+v,hoge[i])
        hoge[0] = cost[c]
        cost[c] = max(hoge)
    for i in range(1,C+1):
        cost[i] = max(cost[i],cost[i-1])

print(cost[-1])
### BUGGY CODE ###

b, w = map(int, input().split())
MOD = 10 ** 9 + 7
list_size = 200001

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)

def power(n, x):
	if x == 1:
		return n
	elif x % 2 == 0:
		return power(int((n * n) % MOD), int(x / 2))
	else:
		return int((n * power(n, x - 1)) % MOD)

f_r_list[-1] = power(f_list[-1], MOD - 2)

for i in range(2, list_size + 1):
	f_r_list[-i] = int((f_r_list[-i + 1] * (list_size + 2 - i)) % MOD)

def comb(n, r):
	if n < r:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD 

def calc(y, x):
	return (y * pow(x, MOD-2, MOD)) % MOD

ans = 500000004
print(ans)
for i in range(1, b+w):
	if i-1 >= b-1:
		ans -= calc(comb(i-1, b-1), pow(2, i+1))
	if i-w >= 0:
		ans += calc(comb(i-1, i-w), pow(2, i+1))
	ans %= MOD
	print(ans)

### FIXED CODE ###

b, w = map(int, input().split())
MOD = 10 ** 9 + 7
list_size = 200001

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)

f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)

for i in range(2, list_size + 1):
	f_r_list[-i] = int((f_r_list[-i + 1] * (list_size + 2 - i)) % MOD)

def comb(n, r):
	if n < r:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD 

two_pow = [1]
for i in range(b+w+1):
	two_pow.append((two_pow[-1] * 500000004) % MOD)

ans = 500000004
print(ans)
for i in range(1, b+w):
	if i-1 >= b-1:
		ans -= comb(i-1, b-1) * two_pow[i+1]
	if i-w >= 0:
		ans += comb(i-1, i-w) * two_pow[i+1]
	ans %= MOD
	print(ans)
### BUGGY CODE ###

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

a=list(map(int, input().split()))
use=list(range(N))
# for x in range(N):
#     print(l[x])

for x in range(M):
    use[a.index(max(a))]+=1
    a[a.index(max(a))] //= 2

total = 0
for x in range(N):
    total+=a[x]

print(total)




### FIXED CODE ###

import math
import heapq
N,M = list(map(int, input().split()))
a=list(map(int, input().split()))

npA = []
for x in a:
    heapq.heappush(npA, -x)

# for x in range(N):
#     print(a[x])
npA.sort()


for x in range(M):
    # temp=heapq.heappop(npA)
    # print("{}//2={}".format(temp,math.ceil(temp/2)))
    heapq.heappush(npA, math.ceil(heapq.heappop(npA)/2))#get the max value!!
    

total = 0
for x in range(N):
    # temp = heapq.heappop(npA)
    # print(temp)
    total+=heapq.heappop(npA)

print(-total)
### BUGGY CODE ###

n = int(input())
s = [[]]*n
ans = 0

for i in range(n):
    s[i] = list(sorted(input()))
                
for i in range(n-1):
    for j in range(i+1,n):
        if s[i] == s[j]:
            ans += 1

print(ans)


### FIXED CODE ###

n = int(input())
a = {}
ans = 0

for i in range(n):
    s = sorted(input())
    s = ''.join(s)
    if s in a.keys():
        ans += int(a[s])
        a[s] += 1
    else:
        a[s] = 1

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

h, w, d = map(int, input().split())

p = [[] for _ in range(h * w)]

for i in range(h):
    temp = list(map(int, input().split()))
    for j in range(w):
        p[temp[j] - 1] = [i, j]

q = int(input())
a = [[int(x) - 1 for x in input().split()] for _ in range(q)]

for i in range(q):
    temp = 0
    j = a[i][1]
    while j > a[i][0]:
        temp += abs(p[j][0] - p[j - d][0]) + abs(p[j][1] - p[j - d][1])
        j -= d
    print(temp)


### FIXED CODE ###

h, w, d = map(int, input().split())

p = [[] for _ in range(h * w)]

for i in range(h):
    temp = list(map(int, input().split()))
    for j in range(w):
        p[temp[j] - 1] = [i, j]

q = int(input())
a = [[int(x) - 1 for x in input().split()] for _ in range(q)]

s = [0 for _ in range(h * w)]
for i in range(d, h * w):
    s[i] = s[i - d] + abs(p[i][0] - p[i - d][0]) + abs(p[i][1] - p[i - d][1])

for i in range(q):
    print(s[a[i][1]] - s[a[i][0]])
### BUGGY CODE ###

N = int(input())
x = 0
a = []
for i in range(N):
    while i % 2 == 0:
        i //= 2
        x += 1
    a.append(x)
    x = 0
a = sorted(a)
a = a[::-1]
print(a[0])


### FIXED CODE ###

N = int(input())
x = 1

while x <= N:
    x *= 2
    
 
print(x // 2)
### BUGGY CODE ###

from collections import Counter
n=int(input())
l=list(map(int,input().split()))
f=l[0::2]
s=l[1::2]
ans=[]
if len(Counter(l).values()) == 1:
  ans.append(len(f))
elif len(Counter(f).values()) == len(Counter(s).values()) == 1:
  ans.append(0)
else:
  for fk,fv in Counter(f).items():
    fdk=fk
    a=sum(Counter(f).values())-fv
    for sk,sv in Counter(s).items():
      if fk != sk:
        ans.append(a+sum(Counter(s).values())-sv)
print(min(ans))

### FIXED CODE ###

from collections import Counter
n=int(input())
l=list(map(int,input().split()))
f=l[0::2]
s=l[1::2]
fn=sorted(Counter(f).items(),key=lambda x:x[1],reverse=True) + [(0, 0)]
sn=sorted(Counter(s).items(),key=lambda x:x[1],reverse=True) + [(0, 0)]
if fn[0][0]!=sn[0][0]:
  ans=n-fn[0][1]-sn[0][1]
else:
  ans=n-max(fn[1][1]+sn[0][1],fn[0][1]+sn[1][1])
print(ans)
### BUGGY CODE ###

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

n = int(input())
l = list(map(int, input().split()))
l.sort()
n = l.pop()
ans = 0
M = 0
for r in l:
  if com(n, r) > M:
    M = com(n, r)
    ans = r
print(n, ans)

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
l.sort()
m = l.pop()
a = m
ans = 0
for r in l:
  if abs((m / 2) - r) < a:
    a = abs((m / 2) - r)
    ans = r
print(m, ans)
### BUGGY CODE ###

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

MOD = 10 ** 9 + 7

fact = [1 for _ in range(N*M+1)]
for i in range(1, N*M+1):
    fact[i] = fact[i-1] * i

def inv(val):
    return pow(val, MOD-2, MOD)

def combination(n, m):
    return fact[n] * inv(fact[n-m]*fact[m]) % MOD

pattern = combination(N*M-2, K-2) % MOD

def diff_x_pattern(val):
    # for d in range(1, val):
    #     ret += (val - d) * d
    return (val * (val - 1) * val // 2 - (val - 1) * (2 * val - 1) * val // 6) % MOD

ans = (M * M * diff_x_pattern(N)) % MOD
ans += (N * N * diff_x_pattern(M)) % MOD
print((ans*pattern)%MOD)


### FIXED CODE ###

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

MOD = 10 ** 9 + 7

def combination(n, m):
    c = 1
    m = min(n-m, m)
    for i in range(m):
        c = c * (n-i) * pow(m-i, MOD-2, MOD) % MOD
    return c

pattern = combination(N*M-2, K-2)

def diff_x_pattern(val):
    ret = 0
    for d in range(1, val):
        ret += ((val - d) * d) % MOD
    return ret

ans = (M * M * diff_x_pattern(N)) % MOD
ans += (N * N * diff_x_pattern(M)) % MOD
print((ans*pattern)%MOD)
### BUGGY CODE ###

#!/usr/bin/env python3
import numpy as np


def main():
    n = int(input())
    abc = [list(map(int, input().split() )) for _ in range(n)]
    abc = np.array(abc, dtype='int')

    dp = np.empty((n, 3), dtype='int')
    dp[0, :] = abc[0, :]

    for i in range(1, n):
        dp[i, 0] = abc[i, 0] + np.max(dp[i - 1, 1:3])
        dp[i, 1] = abc[i, 1] + np.max(dp[i - 1, 0:3:2])
        dp[i, 2] = abc[i, 2] + np.max(dp[i - 1, 0:2])
    print(max(dp[-1, :]))


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n = int(input())
    abc = [list(map(int, input().split())) for _ in range(n)]

    dp = [[- float('inf') for i in range(3)] for j in range(n + 1)]
    dp[0] = [0] * 3
    for i in range(n):
        for j in range(3):
            for k in range(3):
                if (j == k):
                    continue
                dp[i + 1][k] = max(dp[i + 1][k],
                                   dp[i][j] + abc[i][k])
    print(max(dp[-1]))


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

#http://www.geocities.jp/m_hiroi/light/pyalgo61.html
class UF(object):
    def __init__(self, n):
        self.table = [None for i in range(n)]
    def find(self, x):
        if self.table[x] is None:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            self.table[s2] = s1

n, k, l = [int(x) for x in raw_input().split()]
d = UF(n)
t = UF(n)
for i in range(k):
    p, q = [int(x) - 1 for x in raw_input().split()]
    d.union(p, q)
for i in range(l):
    r, s = [int(x) - 1 for x in raw_input().split()]
    t.union(r, s)
d2 = [[] for i in range(n)]
t2 = [[] for i in range(n)]
for i in range(n):
    d2[d.find(i)].append(i)
    t2[t.find(i)].append(i)
for i in range(n):
    print len(set(d2[d.find(i)]).intersection(t2[t.find(i)])),


### FIXED CODE ###

#http://www.geocities.jp/m_hiroi/light/pyalgo61.html
class UF(object):
    def __init__(self, n):
        self.table = [None for i in range(n)]
    def find(self, x):
        if self.table[x] is None:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            self.table[s2] = s1

n, k, l = [int(x) for x in raw_input().split()]
d = UF(n)
t = UF(n)
for i in range(k):
    p, q = [int(x) - 1 for x in raw_input().split()]
    d.union(p, q)
for i in range(l):
    r, s = [int(x) - 1 for x in raw_input().split()]
    t.union(r, s)
res = {}
for i in range(n):
    key = (d.find(i), t.find(i))
    res[key] = res.get(key, 0) + 1
for i in range(n):
    print res[(d.find(i), t.find(i))],
### BUGGY CODE ###

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

for i in range(n):
    lists[i]-=(i+1)
mini=10**100
for k in range(-10**9,10**9):
    sub=0
    for _ in range(n):
        sub+=abs(lists[_]-k)
    mini=min(mini,sub)
           
print(mini)


### FIXED CODE ###

n=int(input())
lists=list(map(int,input().split()))
uselists=[]
for _ in range(n):
    uselists.append(lists[_]-_-1)
uselist=sorted(uselists)
if n%2==0:
    num1=int(n/2-1)
    num2=int(n/2)
    numbers=min(uselist[num1],uselist[num2])
    
if n%2!=0:
    num1=int((n-1)/2)
    numbers=uselist[num1] 
ans=0
for x in range(n):
    ans+=abs(uselist[x]-numbers)
print(ans)
### BUGGY CODE ###

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

# c(i)をiのaにおける個数とする
res = 0

for i in set(a):
    # aにおけるiの個数
    ci = a.count(i)
    # c(i) > iの時は c(i) = i になるまで取り除くしかない
    if ci > i:
        res += ci - i
    # c(i) < iの時は，ci個取り除く
    elif ci < i:
        res += ci

print(res)

### FIXED CODE ###

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

res = 0

num = [0]*(N)
cnt = [0]*(N)

for i in range(N):
    if A[i] > N:
        res += 1
    else:
        cnt[A[i]-1] += 1

for i in range(N):
    if cnt[i] < i+1:
        res += cnt[i]
    else:
        res += cnt[i] - (i+1)

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

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

### FIXED CODE ###

a,b,c=map(int, input().split())
if a!=0:print(b//c-(a-1)//c)
else: print(b//c+1)
### BUGGY CODE ###

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

### FIXED CODE ###

N=int(input())
S=input()
# N=int(Input[0][0])
# S=Input[1][0]
import math
count=0
counter={'R':0,'G':0,'B':0}
for i in S:
    counter[i]+=1
s=counter['R']*counter['G']*counter['B']
for i in range(1,N-1):
    for j in range(i+1,N):
        k=2*j-i
        if k<=N and (S[i-1]!=S[j-1] and S[i-1]!=S[k-1] and S[j-1]!=S[k-1]):
                count+=1
print(s-count)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(300000)
n,k=map(int,input().split())
a=list(map(int,input().split()))

def dfs(index, lx):
  if index < 1:
    return lx
  b=[0]*n
  for i in range(n):
    l=max(0,i-lx[i])
    g=min(n-1,i+lx[i])
    b[l]+=1
    if g+1<n:
      b[g+1]-=1
  for i in range(1,n):
    b[i]+=b[i-1]
  return dfs(index-1,b)
    
print(*dfs(min(k,44),a))



### FIXED CODE ###

import sys
sys.setrecursionlimit(300000)
n,k=map(int,input().split())
a=list(map(int,input().split()))

def dfs(index, lx):
  if index < 1:
    return lx
  b=[0]*n
  for i in range(n):
    l=max(0,i-lx[i])
    g=min(n-1,i+lx[i])
    b[l]+=1
    if g+1<n:
      b[g+1]-=1
  for i in range(1,n):
    b[i]+=b[i-1]
  return dfs(index-1,b)
  
    
print(*dfs(min(k,44),a))
### BUGGY CODE ###

N = int(input())
S_list = []
for _ in range(N):
    S_list.append(input())

S_dict = {}
for s in S_list:
    S_dict[s]=0
for s in S_list:
    S_dict[s]+=1

max_k_list = [kv[0] for kv in S_dict.items() if kv[1] == max(S_dict.values())]
max_k_list.sort()
for k in max_k_list:
    print(k)


### FIXED CODE ###

def main():
    N = int(input())
    S_list = []
    for _ in range(N):
        S_list.append(input())

    S_dict = {}
    for s in S_list:
        S_dict[s]=0
    for s in S_list:
        S_dict[s]+=1

    max_v = max(S_dict.values())

    max_k_list = [kv[0] for kv in S_dict.items() if kv[1] == max_v]
    max_k_list.sort()
    for k in max_k_list:
        print(k)

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

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

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

print(dp[-1])

### FIXED CODE ###

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

dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(n-1):
    for j in range(1, k+1):
        if i+j <= n-1:
            temp = dp[i] + abs(l[i+j] - l[i])
            if temp < dp[i+j]:
                dp[i+j] = temp

print(dp[-1])
### BUGGY CODE ###

import numpy as np

mod = 998244353
n, s = map(int, input().split())
arr = list(map(int, input().split()))
dp = np.zeros((n + 1, s + 1))
dp[0, 0] = 1

for i in range(1, n + 1):
    var = arr[i - 1]
    for j in range(s, -1, -1):
        dp[i, j] = 2 * dp[i - 1, j]
        dp[i, j] %= mod
        if j - var >= 0 and dp[i - 1, j - var] != 0:
            dp[i, j] += dp[i - 1, j - var]
            dp[i, j] %= mod
print(int(dp[n, s]))


### FIXED CODE ###

mod = 998244353
n, s = map(int, input().split())
arr = list(map(int, input().split()))
dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1

for i in range(1, n + 1):
    var = arr[i - 1]
    for j in range(0, s + 1):
        dp[i][j] = 2 * dp[i - 1][j]
        dp[i][j] %= mod
        if j - var >= 0 and dp[i - 1][j - var] != 0:
            dp[i][j] += dp[i - 1][j - var]
            dp[i][j] %= mod
print(int(dp[n][s]))