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

from collections import Counter

n, m = map(int, input().split())
a = list(map(int, input().split()))
MAX = 10 ** 5

c = Counter(a)
scores = [0] * (2 * MAX + 1)

for k1, v1 in c.items():
    for k2, v2 in c.items():
        scores[k1 + k2] += v1 * v2

ans = 0
for i, e in enumerate(scores[::-1]):
    point = 2 * MAX - i
    cnt = min(e, m)
    ans += point * cnt
    m -= cnt

print(ans)


### FIXED CODE ###

from itertools import accumulate

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

a.sort(reverse=True)
a_acm = list(accumulate(a))

a_cnt = [0] * (10 ** 6 + 1)
for e in a:
    a_cnt[e] += 1

acm = list(accumulate(a_cnt))


def count_handshake(x):
    ret = 0
    for e in a:
        if x - e - 1 >= 0:
            cnt = acm[-1] - acm[x-e-1]
        else:
            cnt = n

        ret += cnt

    return ret


left = 0
right = 10 ** 6

while right - left > 1:
    mid = (left + right) // 2
    if count_handshake(mid) >= m:
        left = mid
    else:
        right = mid

ans = 0
handshake_cnt = 0
for e in a:
    if left - e - 1 >= 0:
        cnt = n - acm[left-e-1]
    else:
        cnt = n

    if cnt > 0:
        ans += e * cnt + a_acm[cnt-1]
        handshake_cnt += cnt

if handshake_cnt > m:
    ans -= left * (handshake_cnt - m)

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

n,m,k=map(int,input().split())
par=[i for i in range(n)]
rank=[0 for i in range(n)]
# this par & rank are initialized lists
def find_par(x):
    global par
    if par[x]==x:
        return x
    else:
        par[x]= find_par(par[x])
        return par[x]
def unite(x,y):
    x,y=find_par(x),find_par(y)
    global rank,par
    if x==y:return
    if rank[x]<rank[y]:
        par[x]=y
    else:
        par[y]=x
        if rank[x]==rank[y]:
            rank[x]+=1
def same(x,y):
    return find_par(x)==find_par(y)
friend=[set() for i in range(n)]
for i in range(m):
    a,s=map(int,input().split())
    a-=1;s-=1
    unite(a,s)
    friend[a].add(s)
    friend[s].add(a)
for i in range(n):
    find_par(i)
anti=[set() for i in range(n)]
for i in range(k):
    a,b=map(int,input().split())
    a-=1;b-=1
    anti[a].add(b)
    anti[b].add(a)
friends=[set() for i in range(n)]
for i in range(n):
    friends[par[i]].add(i)
psfriend=[friends[par[i]] for i in range(n)]

print(*[len(psfriend[i]-anti[i]-friend[i]-set([i])) for i in range(n)],sep=" ")

### FIXED CODE ###

n,m,k=map(int,input().split())
par=[-1]*n

# this par & rank are initialized lists
def find(x):
    global par
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
        
def unite(x,y):
    x,y=find(x),find(y)
    global par
    if x==y:return False
    else:
        if par[x]>par[y]:x,y=y,x
        par[x]+=par[y]
        par[y]=x
        return True

def size(x):
    return -par[find(x)]
def same(x,y):
    return find(x)==find(y)
from sys import stdin 
input=stdin.readline
friend=[0]*n
for i in range(m):
    a,s=map(int,input().split())
    a-=1;s-=1
    unite(a,s)
    friend[a]+=1
    friend[s]+=1
anti=[set() for i in range(n)]
for i in range(k):
    a,b=map(int,input().split())
    a-=1;b-=1
    anti[a].add(b)
    anti[b].add(a)

print(*[size(i)-1-sum(same(i,b) for b in anti[i])-friend[i] for i in range(n)],sep=" ")
### BUGGY CODE ###

import sys
n, m = map(int, input().split())
Gr = {}
R = []
for i in range(m):
    l, r, d = map(int, input().split())
    Gr[(l - 1, r - 1)] = d
    Gr[(r - 1, l - 1)] = -d
    if l - 1 not in R:
        R.append(l - 1)
    if r - 1 not in R:
        R.append(r - 1)


for i in Gr:
    for k in R:
        if (i[0], k) in Gr and (k, i[1]) in Gr:
            if Gr[i] != Gr[(i[0], k)] + Gr[(k, i[1])]:
                print("No")
                sys.exit()

print("Yes")

### FIXED CODE ###

import sys
sys.setrecursionlimit(200002)
N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    l, r, q = map(int, input().split())
    G[l - 1].append((r - 1, q))
    G[r - 1].append((l - 1, -q))
X = [None] * N


def dfs(u):
    global X, G
    for w, d in G[u]:
        if X[w] is None:
            X[w] = X[u] + d
            if not dfs(w):
                return False
        else:
            if X[w] != X[u] + d:
                return False

    return True


flag = True
for i in range(N):
    if X[i] is None:
        X[i] = 0
        flag &= dfs(i)

if flag:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

class Multiset:
    def __init__(self, N):
        self.N = N
        self.tree = [0] * (N + 1)
        self.bisect_K = [1 << k for k in reversed(range(N.bit_length()))]

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def __str__(self):
        return "BIT: [{}]".format(
            ", ".join(str(self.sum(i + 1) - self.sum(i))
                      for i in range(self.N))
        )

    def bisect(self, w):
        if w <= 0:
            return 0
        bit, N = self.tree, self.N
        i = 0
        for k in self.bisect_K:
            ni = i + k
            if ni <= N and bit[ni] < w:
                w -= bit[ni]
                i = ni
        return i + 1

    def insert(self, i):
        while i <= self.N:
            self.tree[i] += 1
            i += i & -i

    def erase(self, i):
        while i <= self.N:
            self.tree[i] -= 1
            i += i & -i

    def lower_bound(self, x):
        return self.bisect(self.sum(x))

    def upper_bound(self, x):
        return self.bisect(self.sum(x) + 1)

    def size(self):
        return self.sum(self.N)


def main():

    N, *A = map(int, open(0).read().split())
    B = {a: i for i, a in enumerate(A, 2)}

    ms = Multiset(N + 2)
    ms.insert(1)
    ms.insert(N + 2)

    ans = 0
    for i in range(1, N + 1):
        b = B[i]
        ms.insert(b)
        l = ms.lower_bound(b - 1)
        r = ms.upper_bound(b)
        ans += i * (b - l) * (r - b)

    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

class Multiset:
    def __init__(self, N):
        self.N = N
        self.tree = [0] * (N + 1)
        self.bisect_K = [1 << k for k in reversed(range(N.bit_length()))]

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def __str__(self):
        return "BIT: [{}]".format(
            ", ".join(str(self.sum(i + 1) - self.sum(i))
                      for i in range(self.N))
        )

    def bisect(self, w):
        if w <= 0:
            return 0
        bit, N = self.tree, self.N
        i = 0
        for k in self.bisect_K:
            ni = i + k
            if ni <= N and bit[ni] < w:
                w -= bit[ni]
                i = ni
        return i + 1

    def insert(self, i):
        while i <= self.N:
            self.tree[i] += 1
            i += i & -i

    def erase(self, i):
        while i <= self.N:
            self.tree[i] -= 1
            i += i & -i

    def lower_bound(self, x):
        return self.bisect(self.sum(x))

    def upper_bound(self, x):
        return self.bisect(self.sum(x) + 1)

    def size(self):
        return self.sum(self.N)


def main():

    N, *A = map(int, open(0).read().split())
    B = {a: i for i, a in enumerate(A, 2)}

    ms = Multiset(N + 2)
    ms.insert(1)
    ms.insert(N + 2)

    ans = 0
    for i in range(1, N + 1):
        b = B[i]
        ms.insert(b)
        l = ms.lower_bound(b - 1)
        r = ms.upper_bound(b)
        ans += i * (b - l) * (r - b)

    print(ans)

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

n, m = map(int, input().split())
ab = set([tuple(map(int, input().split())) for _ in range(m)])

c = []
for i in ab:
    a, b = i[0], i[1]
    for i in c:
        if a in i or b in i:
            i.add(a)
            i.add(b)
            break
    else:
        c.append(set())
        c[-1].add(a)
        c[-1].add(b)
if m == 0:
    print(1)
else:
    print(max(map(len, c)))

### FIXED CODE ###

class Union:
    def __init__(self, n):
        self.parents = [-1] * n
    
    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            return self.root(self.parents[x])
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

uni = Union(n)
for a, b in ab:
    a -= 1
    b -= 1
    uni.unite(a, b)
print(-min(uni.parents))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import heapq
from collections import Counter

H,W,M = map(int, input().split())
BH = [[0,i] for i in range(H)]
BW = [[0,i] for i in range(W)]
Bomb = set()
for _ in range(M):
  h,w = map(int, input().split())
  h,w = h-1,w-1
  BH[h][0] += 1
  BW[w][0] += 1
  Bomb.add((h,w))
  
BH.sort(reverse=True)
BW.sort(reverse=True)
  
"""
print(BombC)
print(BH)
print(BW)
"""

h = []
ans = 0
nowh, noww = 0,0
i,j = 0,0
BHMAX, BWMAX = BH[i][0], BW[j][0]
heapq.heappush(h, (-BH[i][0] - BW[j][0], BH[i][1], BW[j][1], i,j))
while h:
  cost, nowh, noww,i,j = heapq.heappop(h)
  cost = -cost
  #print(cost,nowh,noww)
  if (nowh,noww) not in Bomb:
    ans = max(ans,cost)
    break
  else:
    ans = max(ans, cost-1)
    if i+1 < H and BH[i+1][0] == BHMAX:
      heapq.heappush(h, (-BH[i+1][0] - BW[j][0], BH[i+1][1], BW[j][1],i+1, j))
    if j+1 < W and BW[i+1][0] == BWMAX:
      heapq.heappush(h, (-BH[i][0] - BW[j+1][0], BH[i][1], BW[j+1][1],i, j+1))
      
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

H,W,M = map(int, input().split())
BH = [0 for i in range(H)]
BW = [0 for i in range(W)]
Bomb = set()
for _ in range(M):
  h,w = map(int, input().split())
  h,w = h-1,w-1
  BH[h] += 1
  BW[w] += 1
  Bomb.add((h,w))
  
BHMAX = max(BH)
BWMAX = max(BW)
HS = set()
WS = set()
for i in range(H):
  if BH[i] == BHMAX:
    HS.add(i)
for i in range(W):
  if BW[i] == BWMAX:
    WS.add(i)
    
ans = 0
cnt = 0
for h,w in Bomb:
  if h in HS and w in WS:
    ans = max(ans, BHMAX + BWMAX - 1)
    cnt += 1

if cnt < len(HS) * len(WS):
  ans = BHMAX + BWMAX
print(ans)
### BUGGY CODE ###

n,m = map(int,input().split())
c=10**9+7
a = [-1]
for i in range(1, m+1):
    a = a + [int(input())]
a =a+[n+1] 
for i in range(m+1):
    a[i]=a[i+1] - a[i]-1
b=[0]
b=b+[1]
for i in range(2, max(a)+1):
    b=b+[(b[i-1] + b[i-2])%c]
s=1
for i in range(m+1):
    s=(s*b[a[i]])%c
print(s)

### FIXED CODE ###

n,m = map(int,input().split())
c=10**9+7
a = [-1 for _ in range(m + 1)]
for i in range(1, m+1):
    a[i] = int(input())
a =a+[n+1] 
for i in range(m+1):
    a[i]=a[i+1] - a[i]-1
b=[0 for _ in range(max(a) + 1)]
b[1]=1
for i in range(2, max(a)+1):
    b[i] = (b[i-1] + b[i-2])%c
s=1
for i in range(m+1):
    s=(s*b[a[i]])%c
print(s)
### BUGGY CODE ###

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

for i in range(n):
    a[i] -= 1
    
visited = [0]
now = 0
flag = 0

for i in range(k):
    now = a[now]
    
    if now in set(visited):
        loop_start = now
        flag = 1
        break
        
    else:
        visited.append(now)
        
if flag == 1:
    loop = visited[visited.index(loop_start):]
    m = len(loop)
    
    now = loop[(k-(len(visited)-m))%m]
    
print(now + 1)


### FIXED CODE ###

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

for i in range(n):
    a[i] -= 1
    
visited = [-1] * n
now = 0

for i in range(k):
    if visited[now] != -1:#訪れたことがあるか
        loop = i - visited[now]   #ループの大きさ
        k = (k-(i-loop)) % loop
        
        for _ in range(k):
            now = a[now]
        
        break
        
    visited[now] = i
    now = a[now] 
        
print(now + 1)
### BUGGY CODE ###

n, k = tuple(map(int, input().split()))

ans = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        x = i % j
        ans += 1 if x>=k else 0

print(ans)

### FIXED CODE ###

n, k = tuple(map(int, input().split()))

ans = 0
for b in range(max(1, k), n+1):
    ans += (b-k)*(n//b)
    if n%b >= k and k>0:
        ans += n%b-k+1
    elif n%b >= k:
        ans += n%b
print(ans)
### BUGGY CODE ###

import numpy as np
N=int(input())
a=list(map(int,input().split()))
b=np.prod(a,dtype='int64')
count=0
while b%2==0:
    if b%2==1:
        break
    b/=2
    count+=1
print(count)

### FIXED CODE ###

N=int(input())
a=list(map(int,input().split()))
count=0
for i in a:
    while i%2==0:
        i/=2
        count+=1
print(count)
### BUGGY CODE ###

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

for i in range(q):
    t = input()
    if len(t) == 1:        
        s = s[::-1]
    else:
        q2, f, c = t.split()
        if f == "1":
            s = c + s
        if f == "2":
            s = s + c

print(s)
            

### FIXED CODE ###

s = list(input())
q = int(input())
rev = False
fwd =[]

for i in range(q):
    t = input()
    if len(t) == 1:        
        if rev:
            rev = False
        else:
            rev = True
    else:
        q2, f, c = t.split()
        if f == "1":
            if rev:
                s.append(c)
            else:
                fwd.append(c)
        if f == "2":
            if rev:
                fwd.append(c)
            else:
                s.append(c)

s = list(reversed(fwd)) + s

if rev:
    s = "".join(list(reversed(s)))
else:
    s = "".join(s)

print(s)
### BUGGY CODE ###

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

A = [int(input()) for i in range(Q)]

for i in range(N):
    temp = A.count(i+1)
    if K > Q-temp:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

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

A = []

for i in range(Q):
    A.append(int(input()))

points = [K-Q]*N

for i in range(Q):
    points[A[i]-1] += 1

for i in range(N):
    if points[i] > 0:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import numpy as np
N = int(input())
S = input()

left = [0]*N
right = [0]*N
for i in range(N):
    tmp1 = S[:i]
    tmp2 = S[i+1:]
    left[i] = tmp1.count('W')
    right[i] = tmp2.count('E')

left = np.array(left)
right = np.array(right)
ans = (left+right).min()
print(ans)


### FIXED CODE ###

import numpy as np
N = int(input())
S = input()

left = [0]*N
right = [0]*N
for i in range(1,N):
    if S[i-1]=='W':
        left[i] += left[i-1] + 1
    else:
        left[i] += left[i-1]
left = np.array(left)

for i in range(1,N):
    if S[N-i]=='E':
        right[i] += right[i-1] + 1
    else:
        right[i] += right[i-1]
right = np.array(right[::-1])

ans = (left+right).min()
print(ans)
### BUGGY CODE ###

x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ls1= []
for i in range(x):
    for j in range(y):
        ls1.append(a[i]+b[j])

ls1 = sorted(ls1,reverse=True)

ls1 = ls1[:k]
ls2 = []
for i in range(z):
    for j in range(len(ls1)):
        ls2.append(c[i]+ls1[j])

ls2 = sorted(ls2,reverse=True)

for i in range(k):
    print(ls2[i])


### FIXED CODE ###

x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a,reverse = True)
b = list(map(int,input().split()))
b = sorted(b,reverse = True)
c = list(map(int,input().split()))
c = sorted(c,reverse = True)

ls1= []
for i in range(min(x,k)):
    for j in range(min(y,k)):
        ls1.append(a[i]+b[j])

ls1 = sorted(ls1,reverse=True)

ls1 = ls1[:k]
ls2 = []
for i in range(min(z,k)):
    for j in range(len(ls1)):
        ls2.append(c[i]+ls1[j])

ls2 = sorted(ls2,reverse=True)

for i in range(k):
    print(ls2[i])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,q=MI()
s=input().rstrip()
lis=[]
for i in range(n-1):
    u=s[i:i+2]
    if u=="AC":
        lis.append(i+1)
#print(lis)

for i in range(q):
    a,b=MI()
    count=0
    for j in lis:
        if a<=j and b>=j+1:
            count+=1
    print(count)
        

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t=[0]*(N+1) 
for i in range(N):
	t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0) 
for i in range(Q):
	l, r = map(int, input().split())
	print(t[r-1] - t[l-1])
### BUGGY CODE ###

from numba import njit
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)

@njit
def solve(N, L):
    cnt = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            b = L[j]
            for k in range(j+1, N):
                c = L[k]
                if b > c and a < b+c:
                    cnt += 1
    return cnt
print(solve(N, L))

### FIXED CODE ###

from numba import njit
N = int(input())
L = list(map(int, input().split()))
L.sort()

@njit
def solve(L):
    cnt = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            b = L[j]
            for k in range(j+1, N):
                cnt += a+b > L[k]
    return cnt
print(solve(L))
### BUGGY CODE ###

N = int(input())
S = []
for i in range(N):
    s = input()
    if not(s in S):
        S.append(s)

print(len(S))


### FIXED CODE ###

from collections import Counter

N = int(input())
S = []
for i in range(N):
    S.append(input())

cnt = Counter(S)


print(len(cnt.keys()))
### BUGGY CODE ###

from collections import Counter
N = int(input())
A = sorted([int(x) for x in input().split()])
if A[0] == 1:
    if N == 1:
        print(1)
        exit()
    elif A[1] == 1:
        print(0)
        exit()
    print(1)
    exit()
cA = Counter(A)

cand = set()
ans = 0
for a, val in cA.items():
    if len(cand) != 0 and val == 1:
        for t in cand:
            if a % t == 0:
                break
        else:
            #print(a)
            cand.add(a)
            ans += 1
    elif val == 1:
        #print(a)
        cand.add(a)
        ans += 1
    else:
        continue
print(ans)


### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split()]
count = [0 for _ in range(10**6+10)]
for a in A:
    if count[a] > 1:
        continue
    for x in range(0, 10**6+10, a):
        count[x] += 1
ans = 0
for a in A:
    if count[a] == 1:
        ans += count[a]
print(ans)
### BUGGY CODE ###

import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict

N,M=map(int, input().split())
city = defaultdict(list)
p = [0] * M
y = [0] * M

for i in range(M):
    p[i],y[i]=map(int, input().split())
    city[p[i]].append(y[i])

city_sorted = defaultdict(list)
year = defaultdict(list)
for key,v in city.items():
    city_sorted[key] = sorted(v)
    for X in city_sorted.values():
        for i,x in enumerate(X):
            year[x] = i+1

for a in range(M):
    print(str(p[a]).zfill(6)+str(year[y[a]]).zfill(6))

### FIXED CODE ###

import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict

N,M=map(int, input().split())
city = defaultdict(list)
p = [0] * M
y = [0] * M

for i in range(M):
    p[i],y[i]=map(int, input().split())
    city[p[i]].append(y[i])

year = defaultdict(list)
for key,v in city.items():
    for i,x in enumerate(sorted(v)):
        year[x] = i+1

for a in range(M):
    print(str(p[a]).zfill(6)+str(year[y[a]]).zfill(6))
### BUGGY CODE ###

from fractions import gcd
k = int(input())
total = 0
ab_gcd = []
for a in range(1,k+1):
    for b in range(1,k+1):
        ab_gcd.append(gcd(a,b))
for ab in ab_gcd:
    for c in range(1,k+1):
        abc = gcd(ab,c)
        total += abc
print(total)

### FIXED CODE ###

from math import gcd
k = int(input())
total = 0
ab_gcd = []
for a in range(1,k+1):
    for b in range(1,k+1):
        ab_gcd.append(gcd(a,b))
for ab in ab_gcd:
    for c in range(1,k+1):
        abc = gcd(ab,c)
        total += abc
print(total)
### BUGGY CODE ###

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

b = 10**9+7
ans = 0
for i in range(n-1):
    ans += a[i]*sum(a[i+1:])
    ans %= b
print(ans)

### FIXED CODE ###

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

b = 10**9+7
s = sum(a)
ans = 0
for i in range(n-1):
    s -= a[i]
    ans += a[i]*(s%b)
    ans %= b
print(ans)
### BUGGY CODE ###

a,b=map(int,input().split())
tmp = 0
for i in range(a,b+1):
  tmp = tmp ^ i
print(tmp)

### FIXED CODE ###

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

def xorsum(x):
  if x % 4 == 1:
    return 1
  elif x % 4 == 3:
    return 0
  elif x % 4 == 0:
    return x
  else:
    return 1 ^ x

print(xorsum(b)^xorsum(a-1))
### BUGGY CODE ###

N = int(input())

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

for i in range(N):
    print(A.index(i+1)+1,end=" ")

### FIXED CODE ###

N = int(input())

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

B = [0]*N

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

print(*B)
### BUGGY CODE ###

import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

ans = 0
for a in A:
    b_index = bisect.bisect_right(B, a)
    for b in B[b_index:]:
        ans += len(C[bisect.bisect_right(C,b):])
print(ans)

### FIXED CODE ###

import bisect
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for b in B:
    a_ind = bisect.bisect_left(A, b)
    c_ind = bisect.bisect_right(C, b)
    ans += a_ind*(n-c_ind)
    
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
n,q=[int(_) for _ in input().split()]
ki=[[] for _ in range(n)]
ans=[0]*n

def dfs(numQ,parent):
    for child in ki[numQ]:
        if child==parent:
            continue
        ans[child]+=ans[numQ]
        dfs(child,numQ)

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

for i in range(q):
    p,x=[int(_) for _ in input().split()]
    ans[p-1]+=x

dfs(0,-1)
print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
n,q=map(int,input().split())
ki=[[] for _ in range(n)]
ans=[0]*n

def dfs(numQ,parent):
    for child in ki[numQ]:
        if child==parent:
            continue
        ans[child]+=ans[numQ]
        dfs(child,numQ)

for i in range(n-1):
    a,b=map(int,input().split())
    ki[a-1].append(b-1)
    ki[b-1].append(a-1)

for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x

dfs(0,-1)
print(*ans)
### BUGGY CODE ###

K, S = map(int, input().split())

ans = 0
for X in range(0, K+1):
    for Y in range(0, K+1):
        for Z in range(0, K+1):
            if X + Y + Z == S:
                ans += 1

print(ans)

### FIXED CODE ###

#ABC951B/Sum_of_Three_Integers

K, S = map(int, input().split())
ans = 0
for x in range(0, K+1):
    for y in range(0, K+1):
        z = S - x - y
        if 0 <= z and z <= K:
            ans += 1
print(ans)
### BUGGY CODE ###

INF = 10**9

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

dp = [INF] * n
dp[0] = 0

for i in range(1, n):
    l = i if i < k else k
    a = INF
    hsi = hs[i]
    for m in range(1, l + 1):
        v = dp[i - m] + abs(hs[i - m] - hsi)
        if a > v:
            a = v
    dp[i] = a
print(dp[-1])


### FIXED CODE ###

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

hs = list(map(int, input().split(' ')))

dp = [float('inf')] * (n + k + 1)
dp[0] = 0

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

print(dp[n - 1])