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

N,M=map(int,input().split())
list1=list(map(int,input().split()))
list2=[]
for _ in range(M):
  B,C=map(int,input().split())
  list2+=[C]*B
  list2.sort(reverse=True)
list2=list2[:N]
list3=list1+list2
list3.sort(reverse=True)
list5=list3[:N]
SUM=sum(list5)
print(SUM)

### FIXED CODE ###

N,M = map(int, input().split())
listA = list(map(int, input().split()))
listA.sort()
 
listBC = [list(map(int, input().split())) for i in range(M)]
listBC = sorted(listBC, key=lambda x: x[1], reverse=True)
countB = 0
 
for i in range(M):
  B, C = listBC[i][0], listBC[i][1]
  listA += [C]*B
  countB += B
  if countB >= N:
    break

listA.sort(reverse=True)
print(sum(listA[:N]))
### BUGGY CODE ###

import bisect

A, B, Q = map(int, input().split())
s = [0]*(A+4)
t = [0]*(B+4)

for i in range(2, A+2):
    s[i] = int(input())

for i in range(2, B+2):
    t[i] = int(input())

s[0], s[1], s[-2], s[-1] = -10**11-1, -10**11, 10**11, 10**11+1
t[0], t[1], t[-2], t[-1] = -10**11-1, -10**11, 10**11, 10**11+1


for i in range(Q):
    x = int(input())
    sh_left = bisect.bisect(s, x) - 1
    sh_right = sh_left + 1
    ans = 10**12
    for i in range(2):
        loc_sh = s[[sh_left, sh_right][i]]
        dis = abs(x-loc_sh)
        te_left = bisect.bisect(t, loc_sh) - 1
        te_right = te_left + 1
        loc_te_l = t[te_left]
        loc_te_r = t[te_right]
        tmp = min(dis+abs(loc_sh-loc_te_l), dis+abs(loc_sh-loc_te_r))
        ans = min(ans, tmp)
    te_left = bisect.bisect(t, x) - 1
    te_right = te_left + 1
    for i in range(2):
        loc_te = t[[te_left, te_right][i]]
        dis = abs(x-loc_te)
        sh_left = bisect.bisect(s, loc_te) - 1
        sh_right = sh_left + 1
        loc_sh_l = s[sh_left]
        loc_sh_r = s[sh_right]
        tmp = min(dis+abs(loc_te-loc_sh_l), dis+abs(loc_te-loc_sh_r))
        ans = min(ans, tmp)
    print(ans)


### FIXED CODE ###

from bisect import bisect_right

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

for _ in range(Q):
    x = int(input())
    sh_r, te_r = bisect_right(s, x), bisect_right(t, x)
    sh_l, te_l = sh_r - 1, te_r - 1
    SR, SL, TR, TL = s[sh_r], s[sh_l], t[te_r], t[te_l]
    ans = INF
    for i in [SR, SL]:
        for j in [TR, TL]:
            dis = abs(i-x) + abs(i-j)
            dis = min(dis, abs(j-x) + abs(j-i))
            ans = min(ans, dis)
    print(ans)
### BUGGY CODE ###

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

# BFSで各点から到達可能な最も遠いところを探索する
# 1回探索はO(HW)なのでO(HHWW)
# BFSなのでdeque / queue使う・・・微妙に1つだけTLE残る

# 全ての地点から全ての地点への最短経路を求める

'''
3 5
...#.
.#.#.
.#...
'''

import sys
from collections import deque

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

H, W = na()
# data = [ns() for _ in range(H)]

data = [list("#" * (W + 2))]
# 周りを'#'で埋めておく
for _ in range(H):
    data.append(["#"] + list(input()) + ["#"])
data += [list("#" * (W + 2))]


def bfs(h, w):
    dist = [[-1] * (W+2) for _ in range(H+2)]
    q = deque()

    max_dist = 0
    dist[h][w] = 0
    q.append((h, w, 0))

    # while len(q) > 0:
    while len(q) > 0:
        h, w, val = q.popleft()

        m = [(1, 0), (-1, 0), (0, 1), (0, -1)]
        for dx, dy in m:
            h_new, w_new = h + dx, w + dy
            if data[h_new][w_new] == '.' and dist[h_new][w_new] == -1:
                q.append((h_new, w_new, val+1))
                dist[h][w] = val + 1
                max_dist = max(max_dist, val + 1)

    return max_dist


ans = 0
for h in range(H+2):
    for w in range(W+2):
        if data[h][w] == '.':
            res = bfs(h, w)
            if ans < res:
                ans = res

print(ans)


### FIXED CODE ###

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

# BFSで各点から到達可能な最も遠いところを探索する
# 1回探索はO(HW)なのでO(HHWW)
# BFSなのでdeque / queue使う・・・微妙に1つだけTLE残る

# 全ての地点から全ての地点への最短経路を求める

'''
3 5
...#.
.#.#.
.#...
'''

import sys
from collections import deque

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

H, W = na()
# data = [ns() for _ in range(H)]

data = [list("#" * (W + 2))]
# 周りを'#'で埋めておく
for _ in range(H):
    data.append(["#"] + list(input()) + ["#"])
data += [list("#" * (W + 2))]


def bfs(h, w):
    dist = [[-1] * (W+2) for _ in range(H+2)]
    q = deque()

    max_dist = 0
    dist[h][w] = 0
    q.append((h, w, 0))

    # while len(q) > 0:
    while len(q) > 0:
        h, w, val = q.popleft()

        m = [(1, 0), (-1, 0), (0, 1), (0, -1)]
        for dx, dy in m:
            h_new, w_new = h + dx, w + dy
            if data[h_new][w_new] == '.' and dist[h_new][w_new] == -1:
                q.append((h_new, w_new, val+1))
                dist[h_new][w_new] = val + 1
                max_dist = max(max_dist, val + 1)

    return max_dist


ans = 0
for h in range(H+2):
    for w in range(W+2):
        if data[h][w] == '.':
            res = bfs(h, w)
            if ans < res:
                ans = res

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

from itertools import combinations

S = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

a = 1
d = 0

for s in S:
    d = d + int(s)*a
    num = d%2019
    counts[num] += 1
    a *= 10

ans = 0

for i in counts:
    if i >=2:
        x = (i*(i-1))//2
        ans += x

print(ans)

### FIXED CODE ###

#ACの人のやつ丸パクリです。自分のソースコードがTLEになるので試しに使わせてもらいます。

s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力
### BUGGY CODE ###

from collections import deque

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

for _ in range(k):
  d.append(l.popleft())
now = sum(d)  
for i in range(n-k):
  d.popleft()
  d.append(l.popleft())
  now = max(sum(d), now)
  
print((now + k) / 2)

### FIXED CODE ###

n, k = map(int, input().split())
l = list(map(int, input().split()))
 
tmp = sum(l[:k])
now = tmp
 
for i in range(n-k):
  tmp -= l[i]
  tmp += l[i+k]
  now = max(tmp, now)
  
print((now + k) / 2)
### BUGGY CODE ###


class Node:
    def __init__(self, key=-1):
        self.key = key
        self.parent = -1
        self.left = -1
        self.right = -1
    
    def setKey(self, key):
        self.key = key


def insert(T_, z): #(T, Node)
    global T
    y = -1
    x = T_ #Node()
    while x != -1 :
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y == -1:
        T = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z


def preParse(T):
    #if T == -1 and T == -1:
    #    return
    print T.key,
    if T.left != -1:
        preParse(T.left)
    if T.right != -1:
        preParse(T.right)

def inParse(T):
    #if T == -1 and T == -1:
    #    return
    if T.left != -1:
        inParse(T.left) #Node() or -1
    print T.key,
    if T.right != -1:    
        inParse(T.right)


T = -1

def main():
    com = []
    m = int(raw_input())
    for i in xrange(m):
        com.append(raw_input())
    for i in xrange(m):
        if com[i][0] == 'i':
            insert(T,Node(key=int(com[i][7:])))
        else:
            print '',
            inParse(T)
            print
            print '',
            preParse(T)
            print 
    return 0

main()
            

### FIXED CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
  
  
class Node(object):
    def __init__(self, key=None):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None
  
  
def tree_insert(top, z):
    y = None
    x = top
    while isinstance(x, Node):
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        top = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z
    return top
  
  
def inorder_walk(node):
    if node.left:
        inorder_walk(node.left)
    print('', node.key, end='')
    if node.right:
        inorder_walk(node.right)
  
  
def preorder_walk(node):
    print('', node.key, end='')
    if node.left:
        preorder_walk(node.left)
    if node.right:
        preorder_walk(node.right)
  
  
n = int(stdin.readline())
  
top = None
for _ in range(n):
    cmd = stdin.readline()
    if cmd.startswith('i'):
        key = int(cmd[7:])
        #assert -2000000000 <= key <= 2000000000
        top = tree_insert(top, Node(key))
    else:
        inorder_walk(top)
        print()
        preorder_walk(top)
        print()
### BUGGY CODE ###

from collections import deque
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]


D = [[-1] * W for i in range(H)]
queue = deque([])
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            queue.append([h, w])
            D[h][w] = 0


while queue:
    nh, nw = queue.pop()
    for dh, dw in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
        if not ((0 <= nh + dh < H) and (0 <= nw + dw < W)):
            continue

        if D[nh + dh][nw + dw] >= 0:
            continue

        D[nh + dh][nw + dw] = D[nh][nw] + 1
        queue.appendleft([nh + dh, nw + dw])


ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, D[h][w])

print(ans)


### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]


D = [[-1] * W for i in range(H)]
queue = deque([])
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            queue.append([h, w])
            D[h][w] = 0


while queue:
    nh, nw = queue.pop()
    for dh, dw in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
        if not ((0 <= nh + dh < H) and (0 <= nw + dw < W)):
            continue

        if D[nh + dh][nw + dw] >= 0:
            continue

        D[nh + dh][nw + dw] = D[nh][nw] + 1
        queue.appendleft([nh + dh, nw + dw])


ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, D[h][w])

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



if __name__ == "__main__":
    n = int(input())
    lst = []
    count = 0
    for i in range(n):
        lst.append(sorted(list(input())))
    for i in range(n):
        for j in range(i + 1, n):
            count += int(len([a for a, b in zip(lst[i], lst[j]) if a == b]) == 10)
    print(count)

### FIXED CODE ###

from collections import defaultdict
from math import factorial
if __name__ == "__main__":
    n = int(input())
    lst = []
    count = 0
    words = defaultdict(lambda: 0)
    for i in range(n):
        words[''.join(sorted(input()))] += 1
    sum = 0
    for word in words:
        sum += int(factorial(words[word]) / (factorial(2) * factorial(abs(words[word] - 2))))
    print(sum)
### BUGGY CODE ###

import math
kai = int(input())
for x in range(-1000,kai):
    for y in range(-1,kai):
        if x**5 - y**5 == kai:
            print(x,y)
    

### FIXED CODE ###

num = int(input())
for i in range(-128,128):
    for j in range(-128,128):
        if i ** 5 - j **5 == num:
            print(i,j)
            exit()
### BUGGY CODE ###

import math

def main():
  k = int(input())
  params = [1,1,0]
  count = 0
  
  while params[0] < k or params[1] < k or params[2] < k:
    if params[2] < k:
      params[2] = params[2]+1
    elif params[1] < k:
      params = [params[0],params[1]+1,1]
    elif params[0] < k:
      params = [params[0]+1,1,1]
      
    tmp = 0
    if 1 in params:
      tmp = 1
    else:
      tmp = math.gcd(params[0],params[1])
      if tmp > 1:
        tmp = math.gcd(tmp, params[2])
    
    count += tmp
    
  return count
 
def gcd(val1, val2):
  val3 = 0
  while True:
    val3 = val1 % val2
    val1 = val2
    if val3 == 0:
      break
    val2 = val3
  return val1

if __name__ == '__main__':
  print(main())

### FIXED CODE ###

import math

def main():
  k = int(input())
  params = [1,1,0]
  count = 0
  
  while params[0] < k or params[1] < k or params[2] < k:
    if params[2] < k:
      params[2] = params[2]+1
    elif params[1] < k:
      params = [params[0],params[1]+1,1]
    elif params[0] < k:
      params = [params[0]+1,1,1]
      
    tmp = 0
    if 1 in params:
      tmp = 1
    else:
      tmp = math.gcd(params[0],params[1])
      if tmp > 1:
        tmp = math.gcd(tmp, params[2])
    
    count += tmp
    
  return count
 
def gcd(val1, val2):
  val3 = 0
  while True:
    val3 = val1 % val2
    val1 = val2
    if val3 == 0:
      break
    val2 = val3
  return val1

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

n = int(input())
s = input()

MIN = n
for i in range(n):
    tmp = s[:i].count("W") + s[i+1:].count("E")
    MIN = min(MIN, tmp)
print(MIN)

### FIXED CODE ###

n = int(input())
s = input()

num = [0 for _ in range(n)]

num[0] = s[1:].count("E")
for i in range(1,n):
    num[i] = num[i-1] + int(s[i-1]=="W") - int(s[i]=="E")

print(min(num))
### BUGGY CODE ###

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

dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]
# dp[n][w] = n番目までの品物による重量w以下の価値の総和の最大値

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

print(dp[N][W])

### FIXED CODE ###

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

dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]
# dp[n][w] = n番目までの品物による重量w以下の価値の総和の最大値

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

print(dp[N][W])
### BUGGY CODE ###

def reduce_mul(s,e):
     a = 1
     for i in range(s,e+1):
          a = a*i
     return a
     
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce_mul(n-r+1,n)
    under = reduce_mul(1,r)
    return over // under

n,m,k = map(int,input().split())
a = (cmb(n*m-2,k-2)%(10**9+7))*(n*m*(m*(n**2-1)+n*(m**2-1)))//6
print(a%(10**9+7))

### FIXED CODE ###

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n,m,k = map(int,input().split())
nm = n*m%(10**9+7)
k = k%(10**9+7)
a = (cmb(nm-2,k-2,mod)%(10**9+7))*(nm*(m*(n**2-1)+n*(m**2-1)))//6
print(a%(10**9+7))
### BUGGY CODE ###

s = input()
x, y = map(int, input().split())
a = 0
t = [[0], [0]]
n = 0
for i in range(len(s)):
    if s[i] == 'F':
        t[n][-1] += 1
    else:
        n = 1 - n
        t[n].append(0)
flag = [False, False]
for k in range(2):
    tt = t[k]
    z = [x, y]
    if k == 0:
        p = [tt[0]]
    else:
        p = [tt[0], -tt[0]]
    for i in range(1, len(tt)):
        pp = []
        for j in range(len(p)):
            pp.append(p[j] + tt[i])
            pp.append(p[j] - tt[i])
        p = pp
    if z[k] in p:
        flag[k] = True
if flag[0] and flag[1]:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

from collections import defaultdict

s = input()
x, y = map(int, input().split())
a = 0
t = [[0], []]
n = 0
for i in range(len(s)):
    if s[i] == 'F':
        t[n][-1] += 1
    else:
        n = 1 - n
        t[n].append(0)
flag = [False, False]
z = [x, y]
for k in range(2):
    tt = t[k]
    zk = z[k]
    if len(tt) == 0:
        if zk == 0:
            flag = True
            continue
        else:
            print(1, k)
            flag = False
            break
    p = sum(tt)
    dp = defaultdict(bool)
    i = 1
    if k == 0:
        dp[tt[0]] = True
    else:
        dp[tt[0]] = True
        dp[-tt[0]] = True
    if len(tt) > 1:
        for tj in tt[1:]:
            dp2 = defaultdict(bool)
            for xj in dp.keys():
                dp2[xj + tj] = True
                dp2[xj - tj] = True
            dp = dp2
    flag = dp[zk]
    if not flag:
        break
if flag:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

s=str(input())
c=len(s)

for _ in range(10**5):
        s=s.replace('01','')
        s=s.replace('10','')
print(c-len(s))

### FIXED CODE ###

s=str(input())

a=s.count('0')
b=s.count('1')
print(min(a,b)*2)
### BUGGY CODE ###

T_HP,T_Atk,A_HP,A_Atk = map(int,input().split())

Takahashi = [T_HP,T_Atk]
Asakura = [A_HP,A_Atk]

    
while True:    
    Asakura[0] - Takahashi[1]
    if Asakura[0] < 0:
        print("Yes")
        exit()
    
    
    Takahashi[0] - Asakura[1]
    if Takahashi[0] < 0:
        print("No")
        exit()


### FIXED CODE ###

T_HP,T_Atk,A_HP,A_Atk = map(int,input().split())

Takahashi = [T_HP,T_Atk]
Asakura = [A_HP,A_Atk]

    
while True:    
    Asakura[0] -= Takahashi[1]
    if Asakura[0] < 1:
        print("Yes")
        exit()
    
    
    Takahashi[0] -= Asakura[1]
    if Takahashi[0] < 1:
        print("No")
        exit()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)

def get_cost(arr, n, k, dp):
  if dp[n] is not None:
    return dp[n]
  elif n-k <= 0:
    dp[n] = abs(arr[n] - arr[0])
    return dp[n]
  elif n == 0:
    dp[0] = 0
    return dp[0]
  elif n == 1:
    dp[1] = abs(arr[1] - arr[0])
    return dp[1]
  else:
    dp[n] = min(((abs(arr[n] - arr[n-i]) + get_cost(arr, n-i, k, dp)) for i in range(1, k+1)))
    return dp[n]

N, K = input().split()
N = int(N)
K = int(K)
arr = [int(num) for num in input().split()]

dp = [None]*N
print(get_cost(arr, N-1, K, dp))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

def get_cost(arr, n, k, dp):
  min_ = -1
  for i in range(2, n):
    dp[i] = min([(abs(arr[s] - arr[i]) + dp[s]) for s in range(max(0, i-k), i)])
  return dp[-1]
    

N, K = input().split()
N = int(N)
K = int(K)
arr = [int(num) for num in input().split()]

dp = [0]*N
dp[1] = abs(arr[1] - arr[0])
print(get_cost(arr, N, K, dp))
### BUGGY CODE ###

A,B = map(int,input().split())
import numpy as np
def seachPrimeNum(N):
  max_ = int(np.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  if len(seachList) == 0:
    return 0
  while seachList[0] <= max_:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

p_list = []
max_n = max(A,B)
min_n = min(A,B)
list_ = seachPrimeNum(min_n)
if list_ == 0:
  print(1)
else:
  for i in list_:
    if A%i == 0 and B%i == 0:
      p_list.append(i)
  print(len(p_list)+1)
    

  

### FIXED CODE ###

import fractions
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])


    return arr

A,B = map(int,input().split())
print(len(factorization(fractions.gcd(A,B)))+1)
### BUGGY CODE ###

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

lis = [i for i in range(a,b+1)]

if a>0 and b>0:
  print("Positive")
  exit()
elif a<=0 and b>=0:
  print("Zero")
  exit()

cnt = 0
for i in lis:
  if i<0:
    cnt +=1
  else:
    break
    
if cnt%2==0:
  print("Positive")
else:
  print("Negative")

### FIXED CODE ###

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

if a>0 and b>0:
  print("Positive")
  exit()
elif a<=0 and b>=0:
  print("Zero")
  exit()
elif a==0 or b==0:
  print("Zero")
elif a<0 and b<0:
  if (abs(a-b)+1)%2==0:
    print("Positive")
    exit()
  else:
    print("Negative")
    exit()
### BUGGY 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())))
counter = 0
for i in range(len(A)):
    b_index = bisect.bisect(B,A[i])
    if b_index >= len(B):
        break
    b_diam = B[b_index]
    for j in range(b_index,len(B)):
        c_index = bisect.bisect(C,B[j])
        if c_index >= len(C):
            break
        counter += len(C)-c_index
print(counter)


### 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())))
counter = 0
for i in range(len(B)):
    #Bより小さいAの探索
    Ind_A = bisect.bisect_left(A,B[i])
    if A[Ind_A-1] == B[i]:
        Ind_A -= 1
    
    #Bより大きいCの探索
    Ind_C = bisect.bisect_right(C,B[i])
    num_C = len(C)-Ind_C
    counter += round(Ind_A*num_C)
    #print('B[i] =' +str(B[i]),end='')
    #print(' Ind_A =' +str(Ind_A),end='')
    #print(' Ind_C =' +str(Ind_C),end = '')
    #print(' num_C =' +str(num_C),end = '')    
    #print(' 総数 ' + str(Ind_A*num_C))
print(counter)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 9)


def dp_func(i):

    if dp[i] < float('inf'):return dp[i]

    if i==0 :return 0
    #print(i)
    if dp[i] < float('inf'):return dp[i]

    for _ in range(1,K+1):
        if i==1:
            a[i].append(abs(h[i]-h[i-1]))
            break

        if((i-_) >= 0):
            #print(i,_,i-_,h[i],h[i-_])
            a[i].append((dp_func(i-_) + abs(h[i]-h[i-_])))


    #print(i,a[i])
    dp[i] = min(a[i])
    return dp[i]



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

dp = [float('inf')]*N
dp[0] = 0
a = [[] for _ in range(N)]

print(dp_func(N-1))
#print(dp)


### FIXED CODE ###

import sys
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

n, k = map(int, input().split())
h = [int(i) for i in input().split()]
h = np.array(h)

dp = np.zeros(n, dtype=int)

#print(dp)
#print(h)

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

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

s = list(input())
num_s = len(s)

while True:
    new_s = []
    len_s = len(s)
    while s:
        if len(s)==1:
            new_s.append(s[0])
            break
        x=s.pop(0)
        if s[0]!=x:
            y=s.pop(0)
        else:
            new_s.append(x)
    
    s = new_s
    if len(new_s)==len_s:
        print(num_s-len_s)
        break



### FIXED CODE ###

s = input()
print(2*min(s.count('0'),s.count('1')))
### BUGGY CODE ###

n = int(input())
s = input()
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            if (j - i) != (k - j):
                if ((s[i] != s[j]) & (s[i] != s[k]) & (s[j] != s[k])):
                    ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = n - r - g

ans = r * g * b
for i in range(1, (n // 2) + 1):
    for j in range(0, n - (2 * i) + 1):
        if j + (2 * i) >= n:
            break
        if ((s[j] != s[j + i]) & (s[j] != s[j + (2 * i)]) & (s[i + j] != s[j + (2 * i)])):
            ans -= 1
        
print(ans)