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

def main():
    n = int(input())
    s = list(input())
    sr = [0] * n
    sg = [0] * n
    sb = [0] * n
    for i1 in range(n):
        ts = s[i1]
        if ts == 'R':
            sr[i1] = 1
        elif ts == 'G':
            sg[i1] = 1
        else:
            sb[i1] = 1
    if n <= 3:
        print(0)
        exit()
    r = 0
    for ia in range(0,n-3):
        ta = s[ia]
        if ta == 'R':
            for ib in range(ia+1,n-1):
                if sg[ib]:
                    r += sum(sb[ib+1:])
                    if ib * 2 - ia < n:
                        r -= sb[ib * 2 - ia]
                elif sb[ib]:
                    r += sum(sg[ib+1:])
                    if ib * 2 - ia < n:
                        r -= sg[ib * 2 - ia]
        elif ta == 'G':
            for ib in range(ia+1,n-1):
                if sb[ib]:
                    r += sum(sr[ib+1:])
                    if ib * 2 - ia < n:
                        r -= sr[ib * 2 - ia]
                elif sr[ib]:
                    r += sum(sb[ib+1:])
                    if ib * 2 - ia < n:
                        r -= sb[ib * 2 - ia]
        else:
            for ib in range(ia+1,n-1):
                if sr[ib]:
                    r += sum(sg[ib+1:])
                    if ib * 2 - ia < n:
                        r -= sg[ib * 2 - ia]
                elif sg[ib]:
                    r += sum(sr[ib+1:])
                    if ib * 2 - ia < n:
                        r -= sr[ib * 2 - ia]

    print(r)

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n = int(input())
    s = list(input())
    sr = [0] * n
    sg = [0] * n
    sb = [0] * n
    for i1 in range(n):
        ts = s[i1]
        if ts == 'R':
            sr[i1] = 1
        elif ts == 'G':
            sg[i1] = 1
        else:
            sb[i1] = 1
    if n <= 3:
        print(0)
        exit()
    r = 0
    for ia in range(0,n-3):
        ta = s[ia]
        if ta == 'R':
            r += sum(sg[ia+1:]) * sum(sb[ia+1:])
        elif ta == 'G':
            r += sum(sr[ia+1:]) * sum(sb[ia+1:])
        else:
            r += sum(sg[ia + 1:]) * sum(sr[ia + 1:])
        for ib in range((n - ia)//2+1):
            if ia + ib * 2 < n:
                if ta != s[ia + ib] and ta != s[ia + ib + ib] and s[ia+ib]!= s[ia + ib + ib]:
                    r -= 1
    print(r)

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

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

hako = [0 for i in range(N)]

for i in A:
    hako[i-1] += 1

for i in range(N):
    sum = 0
    tmp = A[i] - 1
    hako[tmp] -= 1

    for j in hako:
        if j > 1:
            sum += int(j * (j-1) / 2)
    
    print(sum)

    hako[tmp] += 1

### FIXED CODE ###

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

hako = [0 for i in range(N)]
sum = 0

c = collections.Counter(A)

for v in c.values():
    sum += int(v * (v-1) / 2)


for k in range(N):
    print(sum-(c[A[k]] - 1))
### BUGGY CODE ###

n,m=map(int,input().split())
ans = 0
wa = 0
li = [[i] for i in range(n)]
for i in range(m):
  p,s=map(str,input().split())
  p=int(p)
  if "AC" not in li[p-1]:
    li[p-1].append(s)
#print(li)
for i in li:
  if "AC" in i:
    ans += 1
    wa += i.count("WA")

print(ans,wa)

### FIXED CODE ###

n,m=map(int,input().split())
ans = 0
wa = 0
wa_list = [0] * n
ac_list = [0] * n
for i in range(m):
  p,s=map(str,input().split())
  p=int(p)-1
  if ac_list[p] == 0:
    if s == "AC":
      ac_list[p] += 1
    else:
      wa_list[p] += 1
a=0
for i in range(n):
  if ac_list[i]==0:
    wa_list[i]=0
print(sum(ac_list),sum(wa_list))
### BUGGY CODE ###

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

ls = P[0:K]
summ = sum(ls)
ans = [0]*K

for i in range(N-K+1):
    if summ < sum(P[i:i+K]):
        ls = P[i:i+K]
        summ = sum(ls)
for j in range(K):
    ans[j]=(ls[j]+1)*ls[j]/(2*ls[j])
print(sum(ans))

### FIXED CODE ###

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

summ = sum(P[0:K])
maxi = summ
idx = 0
ans = []
for i in range(N-K):
    summ = summ - P[i] + P[K+i]
    if summ > maxi:
        maxi = summ
        idx = i+1
for j in range(K):
    ans.append((P[idx+j]+1)/2)
print(sum(ans))
### BUGGY CODE ###

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

abr=[]
enabled=[]
removed=[]
for i in range(m):
    abr.append(range(ab[i][0],ab[i][1]))
    enabled.append(False)
    removed.append(False)

res=0
for i in range(n):
    for j in range(len(abr)):
        if i == abr[j][0] and not removed[j]:
            enabled[j]=True
    for j in range(len(abr)):
        if i == abr[j][-1] and enabled[j]:
            res+=1
            for k in range(len(abr)):
                if enabled[k] and not removed[k]:
                    enabled[k]=False
                    removed[k]=True

print(res)

### FIXED CODE ###

ab=[]

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

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
for z in range(len(ab)):
    x=ab[0][1]
    for j in range(len(ab)):
        if x > ab[0][0]:
            del ab[0]
        else:
            res+=1
            break
    if len(ab)==0:
        res+=1
        break
    
print(res)
### BUGGY CODE ###

N,K=map(int,input().split())
A=[]
B=[]
C=[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
for i in range(N):
    if len(C)>K:
            break
    for j in range(B[i]):
        C.append(A[i])
        C.sort()
        if len(C)>K:
            break
print(C[K-1])

### FIXED CODE ###

N,K=map(int,input().split())
A=[]
C=[]
for i in range(N):
    a,b=map(int,input().split())
    T=[a,b]
    A.append(T)
A.sort()
counter=0
for i in range(N):
     counter+=A[i][1]
     if counter>=K:
         counter=i
         break   
print(A[counter][0])
### BUGGY CODE ###

import copy
N = int(input())
X = list(map(int, input().split()))
for i in range(N):
    med = copy.deepcopy(X)
    med.pop(i)
    med.sort()
    print(med[int(N/2)-1])

### FIXED CODE ###

N = int(input())
X = list(map(int, input().split()))
Xsort = sorted(X)
med = (Xsort[N // 2] + Xsort[N // 2 - 1]) / 2
for i in range(N):
    if X[i] < med:
        print(Xsort[N // 2])
    else:
        print(Xsort[N // 2-1])
### BUGGY CODE ###

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

def E(n):
    return sum(range(1,n+1)) / n

l2 = list(map(E, l))

m = 0
for i in range(len(l2)-(K-1)):
    if m < sum(l2[i:i+K]):
        m = sum(l2[i:i+K])
print(m)

### FIXED CODE ###

N,K = map(int, input().split())
l = list(map(int,input().split()))
 
def E(n):
  return (1 + n) / 2
 
j = sum(l[0:0+K])
m = 0
if N == 1:
  l2 = list(map(E, l))
  print(sum(l2))
elif N == K:
  l2 = list(map(E, l))  
  print(sum(l2))
else:
  for i in range(1,len(l)-(K-1)):
      j = j - l[i-1] + l[i+K-1]
      if l[i] < l[i-1]:
          continue
      elif m < j:
          m = j
          t = l[i:i+K]

  l2 = list(map(E, t))
 
  print(sum(l2))
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
i = 0
j = 1
ans = 0
p = 0
nextj = 0
while True:
    if j == n:
        j = min(i+1,nextj)
        p = 0
        i += 1
    
    if p == 0 and a[i] + a[j] == j-i:
        ans += 1
        nextj = j
        p = 1
    elif p == 1 and a[i] + a[j] == j-i:
        ans += 1
    j += 1
    
    if i == n-1:
        print(ans)
        exit()

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
mae = {}
ans = 0
for i in range(n):
    mae[i+a[i]]=mae.get(i+a[i],0)+1
    ans += mae.get(i-a[i],0)
print(ans)
### BUGGY CODE ###

def f(m):
    ans = 0
    for a in aList:
        ans += m % a
    return ans

def check_finish(can):
    for a in aList:
        if(can % a != 0):
            return False
    return True
  
  
N = int(input().strip())
aList = list(map(int, input().strip().split(" ")))

count = 1
ans = 0
while(True):
    tmp_ans = f(count)
    ans = max(tmp_ans, ans)
    if(check_finish(count)):
        break
    count += 1
print(ans)

### FIXED CODE ###

N = int(input().strip())
aList = list(map(int, input().strip().split(" ")))

print(sum(aList) - N)
### BUGGY CODE ###

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

def dif(a, b):
	if a>=b:
		return a-b
	else:
		return b-a

dp = [0]*1000000
dp[0]=0
dp[1]=dif(h[0],h[1])
for i in range(n-2):
	x = i+2
	dp[x] = dp[x-1]+dif(h[x],h[x-1])
	for t in range(k):
		j=t+1
		if x-j < 0:
			break
		dp[x] = min(dp[x],dp[x-j]+dif(h[x],h[x-j]))
print(dp[n-1])
#print(dp[0:n])

### FIXED CODE ###

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

def dif(a, b):
	if a>=b:
		return a-b
	else:
		return b-a

dp = [0]*1000000
dp[0]=0
dp[1]=dif(h[0],h[1])
for i in range(n-2):
	x = i+2
	dp[x] = dp[x-1]+dif(h[x],h[x-1])
	for t in range(k):
		j=t+1
		if x-j < 0:
			break
		dp[x] = min(dp[x],dp[x-j]+dif(h[x],h[x-j]))
print(dp[n-1])
#print(dp[0:n])
### BUGGY CODE ###

S=input()
Q=int(input())
list=[]
mojiretu=[z for z in S]
for a in range(Q):
    b=input().split()
    list.append(b)
for c in list:
    if len(c)==1:
        mojiretu.reverse()
    else:
        if c[1]=='1':
            mojiretu.insert(0,c[2])
        else:
            mojiretu.append(c[2])
moji=''
for z in mojiretu:
    moji+=z
print(moji)


### FIXED CODE ###

from collections import deque
S=input()
Q=int(input())
words=[]
for a in range(Q):
    A=input().split()
    words.append(A)
T=[a for a in S]
answers=deque(T)
number=0
for a in words:
    if a[0]=='1':
        number+=1
    else:
        if number%2==0:
            if a[1]=='1':
                answers.appendleft(a[2])
            else:
                answers.append(a[2])
        else:
            if a[1]=='1':
                answers.append(a[2])
            else:
                answers.appendleft(a[2])
if number%2==0:
    kotae=list(answers)
    moji=''
    for a in kotae:
        moji+=a
    print(moji)
else:
    kotae = list(answers)
    kotae.reverse()
    moji = ''
    for a in kotae:
        moji += a
    print(moji)
### BUGGY CODE ###

A, B, Q = map(int, input().split())
sl = [int(input()) for _ in range(A)]
tl = [int(input()) for _ in range(B)]
ql = [int(input()) for _ in range(Q)]

def find(sl, tl, min_list):
  for s in sl:
    d = 0
    d += abs(q-s)
    d += min(list(map(lambda x: abs(x-s), tl)))
    min_list.append(d)
    
  return min_list
  
for q in ql:
  min_list = []
  min_list = find(sl, tl, min_list)
  min_list = find(tl, sl, min_list)
  print(min(min_list))

### FIXED CODE ###

from bisect import bisect_left
A, B, Q = map(int, input().split())
minf, inf = -(10**18), 10**18
jinja = [minf] + [int(input()) for _ in range(A)] + [inf]
tera = [minf] + [int(input()) for _ in range(B)] + [inf]
ans = []
append = ans.append

for q in [int(input()) for _ in range(Q)]:
    i = bisect_left(jinja, q)
    j = bisect_left(tera, q)
    left_jinja, right_jinja = q-jinja[i-1], jinja[i]-q
    left_tera, right_tera = q-tera[j-1], tera[j]-q
 
    append(min(
        left_jinja if left_jinja > left_tera else left_tera,
        left_jinja + right_tera + (left_jinja if left_jinja < right_tera else right_tera),
        right_jinja + left_tera + (right_jinja if right_jinja < left_tera else left_tera),
        right_jinja if right_jinja > right_tera else right_tera
    ))
 
print(*ans, sep="\n")
### BUGGY CODE ###

s = list(input())
n = len(s) + 1
a = [0]*n
for i in range(n):
    right = 0
    left = 0
    if i != n-1:
        j = i
        while True:
            if j == n-1 or s[j] != '>':
                break
            right += 1
            j += 1
    if i != 0:
        j = i-1
        while True:
            if j == -1 or s[j] != '<':
                break
            left += 1
            j -= 1
    a[i] = max(right, left)
print(sum(a))

### FIXED CODE ###

s = list(input())
n = len(s) + 1
left = [0]*n
right = [0]*n
for i in range(n-1):
    if s[i] == '<':
        left[i+1] = left[i] + 1
for i in range(n-2, -1, -1):
    if s[i] == '>':
        right[i] = right[i+1] + 1
a = [0]*n
for i in range(n):
    a[i] = max(left[i], right[i])
ans = sum(a)
print(ans)
### BUGGY CODE ###

if __name__ == "__main__":
    N, K = [int(n) for n in input().split()]
    h = [int(n) for n in input().split()]
    # dp[i]はi番目までたどり着くのに必要な最小コスト
    # dp[0] = 0
    # dp[1] = |h[1] - h[0]|
    # dp[i] = min(dp[0]+h[i]-h[0], dp[1]+h[i]-h[1], ...)
    dp = [0] * int(1e5)
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])
    for i in range(2, N):
        minimum = 1e10
        stop = K + 1
        if i - K < 0:
            stop = i + 1
        for k in range(1, stop):
            cost = dp[i - k] + abs(h[i] - h[i-k])
            if cost < minimum:
                minimum = cost
        # print(ary)
        dp[i] = minimum
    print(dp[N-1])


### FIXED CODE ###

def a():
    N, K = [int(n) for n in input().split()]
    h = [int(n) for n in input().split()]
    # dp[i]はi番目までたどり着くのに必要な最小コスト
    # dp[0] = 0
    # dp[1] = |h[1] - h[0]|
    # dp[i] = min(dp[0]+h[i]-h[0], dp[1]+h[i]-h[1], ...)
    dp = [0] * N
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])
    for i in range(2, N):
        dp[i] = min([dp[k] + abs(h[k] - h[i]) for k in range(max(i - K, 0), i)])
    print(dp[N-1])

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

import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
s = input() #sys.stdin.readlineは最後が改行
s = s[:-1]
n =len(s)

num=0
tmp=0

amari= [0]

for i in range(n):
    num = tmp + int(s[-1-i])*(10**(i))%2019
    tmp = num%2019
    amari.append(tmp)

from collections import Counter
ctr = Counter(amari)
ans = 0
for val in ctr.values():
        ans += val*(val-1)//2
print(ans)


### FIXED CODE ###

s = input() #sys.stdin.readlineは最後が改行
n =len(s)

from collections import defaultdict
amari = defaultdict(lambda:0)
amari[0]=1
num=0
tmp=0
ans =0

for i in range(n):
    num = tmp + int(s[-1-i])*pow(10,i,2019)
    tmp = num%2019
    amari[tmp]+=1

    if amari[tmp]>1:
        val = amari[tmp]
        ans -= (val-1)*(val-2)//2
        ans += (val)*(val-1)//2

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

from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from fractions import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)


N = inp()
S = input()

"""
    Conditions:
        1. S[i] \ne S[j] and S[j] \ne S[k] and S[k] \ne S[i]
        2. j - i \ne k - j
"""

r = S.count('R')
g = S.count('G')
b = S.count('B')
# 条件1を満たす組は rgb 個。それから「条件1を満たしてかつ条件 2 を満たさない」組を引く。条件を満たさないもののほうが多い。


cnt = 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 # 条件2を満たす場合は break
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                cnt += 1

print(r * g * b - cnt)


### FIXED CODE ###

from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
# import numpy as np
from fractions import gcd

sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inp_list(): return list(map(int, sys.stdin.readline().split()))


def lcm(x, y): return (x * y) // gcd(x, y)


N = inp()
S = input()

"""
    Conditions:
        1. S[i] \ne S[j] and S[j] \ne S[k] and S[k] \ne S[i]
        2. j - i \ne k - j
"""

r = S.count('R')
g = S.count('G')
b = S.count('B')
# 条件1を満たす組は rgb 個。それから「条件1を満たしてかつ条件 2 を満たさない」組を引く。条件を満たさないもののほうが多い。


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

print(r * g * b - cnt)
### BUGGY CODE ###

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

vv = list(set(v))

count = []
for i in vv:
    count.append((v.count(i), i))

count.sort(key=lambda x: x[0], reverse=True)
vv = [i[1] for i in count]

if len(vv) >= 2:
    vvv = vv.copy()

    min = 10**6
    for i in vv:
        vvv.remove(i)
        for j in vvv:
            if 10-(v.count(i)+v.count(j)) > min:
                pass
            else:
                ct = 0
                a = [i if k % 2 == 0 else j for k in range(n)]
                for k in range(n):
                    if a[k] != v[k]:
                        ct += 1
                if ct < min:
                    min = ct
        vvv.append(i)
    print(min)
else:
    print(int(n/2))


### FIXED CODE ###

import collections

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

e = [v[i] for i in range(n) if i % 2 == 0]
o = [v[i] for i in range(n) if i % 2 == 1]

c_e = collections.Counter(e).most_common()
c_o = collections.Counter(o).most_common()

e_0 = c_e[0]
o_0 = c_o[0]

if e_0 != o_0:
    print(len(e) - e_0[1] + len(o) - o_0[1])
else:
    if len(c_e) == 1:
        e_1 = [0, 0]
    else:
        e_1 = c_e[1]
    if len(c_o) == 1:
        o_1 = [0, 0]
    else:
        o_1 = c_o[1]
    print(min(len(e)-e_0[1]+len(o)-o_1[1], len(e)-e_1[1]+len(o)-o_0[1]))
### BUGGY CODE ###

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

class multiset:
    def __init__(self, L):
        self.dic = {}
        for a in L:
            if a not in self.dic:
                self.dic[a] = 0
            self.dic[a] += 1
    def has(self, x):
        return x in self.dic and self.dic[x] > 0
    def remove(self, x):
        if self.has(x):
            self.dic[x] -= 1

def check(x, y):
    a = x
    S = multiset(A)
    S.remove(x)
    S.remove(y)
    for i in range(N - 2):
        z = (x ^ y)
        if not S.has(z):
            return False
        S.remove(z)
        x, y = y, z
    return a == x ^ y

yes = any(check(A[0], a) for a in A[1:])
print('Yes' if yes else 'No')

### FIXED CODE ###

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

def yes():
    S = set(A)
    if A.count(0) == N:
        return True
    if N % 3 != 0:
        return False
    if len(S) == 3:
        a, b, c = tuple(S)
        return all(A.count(x) == N // 3 for x in S) and a ^ b == c
    if len(S) == 2:
        a, b = tuple(S)
        return (a == 0 or b == 0) and A.count(0) == N // 3

print('Yes' if yes() else 'No')
### BUGGY CODE ###

import fractions

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

# 公約数の中の素数の数を考えれば良いのではないか？

n = fractions.gcd(A, B)

data = [i + 1 for i in range(1, n)]
ans = []

while data != []:
  p = data[0]
  if A % p == 0 and B % p == 0:
    ans.append(p)
  data = [e for e in data if e % p != 0]

ans.insert(0, 1)

print(len(ans))


### FIXED CODE ###

import fractions

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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
a = set(prime_factorize(A))
b = set(prime_factorize(B))
c = a & b

print(len(c) + 1)
### BUGGY CODE ###

N,C = map(int,input().split())
STC = [[] for _ in range(C)]
for i in range(N):
    s,t,c = map(int,input().split())
    STC[c-1].append((s,t))

lenA = 200001
A = [[0]*lenA for _ in range(C)]
for i in range(N):
    a = 1

for i in range(C):
    for (s,t) in STC[i]:
        A[i][s*2-1] += 1
        A[i][t*2] -= 1

for i in range(C):
    for j in range(lenA-1):
        A[i][j+1] += A[i][j]

Ans = [0]*lenA
for i in range(C):
    for j in range(lenA):
        if A[i][j] > 0:
            Ans[j] += 1

print(max(Ans))


### FIXED CODE ###

N,C = map(int,input().split())
A = [[0 for _ in range(C)] for j in range(100001)]
for i in range(N):
    s,t,c = map(int,input().split())
    for j in range(s-1,t):
        A[j][c-1] = 1
R = 0
for i in range(100001):
    sumA = sum(A[i])
    if R < sumA:
        R = sumA
print(R)
### BUGGY CODE ###

import sys
N = int(input())
L = [i for i in map(int, input().split())]
ans = 0

L.sort()
#print(L)
if N == 3:
    if L[0] + L[1] > L[2]:
        print("1")
        sys.exit()

for i in range(len(L)-2):
    for j in range(i+1,len(L)-1):
        for k in range(j+1,len(L)):
            if L[i] + L[j] > L[k]:
                ans += 1
                #print(L[i], L[j], L[k])
            else:
                #print("break")
                break
print(ans)


### FIXED CODE ###

import sys
import bisect
N = int(input())
L = [i for i in map(int, input().split())]
ans = 0

L.sort()
#print(L)
if N == 3:
    if L[0] + L[1] > L[2]:
        print("1")
        sys.exit()

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

import sys
input = sys.stdin.buffer.readline
MOD = 998244353

N, S = map(int, input().split())
A = list(map(int, (input().split())))
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += dp[i][j]*2
        dp[i+1][j] %= MOD
        if j+A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= MOD
print(dp[-1][S])

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
MOD = 998244353

N, S = map(int, input().split())
A = list(map(int, (input().split())))
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += dp[i][j]*2
        dp[i+1][j] %= MOD
        if j+A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= MOD
print(dp[-1][S])
### BUGGY CODE ###


def read_input():
    n = int(input())
    alist = list(map(int, input().split()))
    blist = list(map(int, input().split()))
    clist = list(map(int, input().split()))

    return n, alist, blist, clist


def submit():
    n, alist, blist, clist = read_input()

    alist.sort(reverse=True)
    blist.sort(reverse=True)
    clist.sort(reverse=True)


    i = j = 0

    count = 0
    while i < n:
        # 下段を選ぶ
        c = clist[i]

        # 下段で選んだcよりも小さいb候補を探す
        while j < n and blist[j] >= c:
            j += 1
            if j == n:
                break
        bcand = blist[j:]

        for b in bcand:
            # b候補より小さいa候補を探す
            k = 0
            while k < n and alist[k] >= b:
                k += 1
                if k == n:
                    break
            # このkより右側は構成可能
            count += (n - k)
        i += 1

    print(count)
    return



if __name__ == '__main__':
    submit()

### FIXED CODE ###


def read_input():
    n = int(input())
    alist = list(map(int, input().split()))
    blist = list(map(int, input().split()))
    clist = list(map(int, input().split()))

    return n, alist, blist, clist


def submit():
    n, alist, blist, clist = read_input()

    alist.sort(reverse=True)
    blist.sort(reverse=True)
    clist.sort(reverse=True)

    b_a_n = [0] * n
    i = j = 0

    while j < n:
        while i < n and alist[i] >= blist[j]:
            i += 1
        b_a_n[j] = n - i
        j += 1

    b_a_sum = b_a_n.copy()
    for i in range(2, n + 1):
        b_a_sum[n - i] = b_a_sum[n - i + 1] + b_a_n[n - i]

    count = 0
    i = j = 0
    while i < n:
        while blist[j] >= clist[i]:
            j += 1
            if j == n:
                print(count)
                return
        count += b_a_sum[j]
        i += 1

    print(count)

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

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

dp = [0] * n


for i in range(1,n):
    a = []
    
    for j in range(max(0,i-k),i):
        a.append(dp[j] + abs(h[i] - h[j]))    
    
    dp[i] = min(a)
    
print(dp[-1])
              

### FIXED CODE ###

# numpy version

import numpy as np

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

dp = np.zeros(n)

for i in range(1,n): 
    j = max(0, i-k)
    dp[i] = np.min(dp[j:i] + np.abs(h[i] - h[j:i]))

print(int(dp[-1]))