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

H, W, M = map(int, input().split())

bomb = []
row = [0] * H
column = [0] * W

for i in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    
    bomb.append([h, w])
    
    row[h] += 1
    column[w] += 1
    
row_max = max(row)
col_max = max(column)

r_check = []
c_check = []
for i in range(H):
    if row[i] == row_max:
        r_check.append(i)

for i in range(W):
    if column[i] == col_max:
        c_check.append(i)

num = len(r_check) * len(c_check)

ans = row_max + col_max - 1
flg = False
if M < num:
    ans = row_max + col_max
else:
    for r in r_check:
        if flg:
            break
        for c in c_check:
            if not [r, c] in bomb:
                ans = row_max + col_max
                flg = True
                break

print(ans)


### FIXED CODE ###

H, W, M = map(int, input().split())

bomb = set()
row = [0] * H
column = [0] * W

for i in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    
    bomb.add((h, w))
    
    row[h] += 1
    column[w] += 1
    
row_max = max(row)
col_max = max(column)

r_check = []
c_check = []
for i in range(H):
    if row[i] == row_max:
        r_check.append(i)

for i in range(W):
    if column[i] == col_max:
        c_check.append(i)

num = len(r_check) * len(c_check)

ans = row_max + col_max - 1
flg = False
if M < num:
    ans += 1
else:
    for r in r_check:
        if flg:
            break
        for c in c_check:
            if not (r, c) in bomb:
                ans += 1
                flg = True
                break

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

import itertools

N = int(input())
A = tuple(map(int, input().split()))
S = [0] + list(itertools.accumulate(A))

dp = [[0] * (N + 1) for _ in range(N + 1)]
for length in range(2, N + 1):
    for l in range(N - length + 1):
        r = length + l
        dp[l][r] = min(dp[l][m] + dp[m][r] for m in range(l + 1, r)) + S[r] - S[l]
print(dp[0][N])


### FIXED CODE ###

import itertools

N = int(input())
A = tuple(map(int, input().split()))
S = [0] + list(itertools.accumulate(A))

dp = [[0] * (N + 1) for _ in range(N + 1)]
for length in range(2, N + 1):
    for l in range(N - length + 1):
        r = length + l
        dp[l][r] = min(dp[l][m] + dp[m][r] for m in range(l + 1, r)) + S[r] - S[l]
print(dp[0][N])
### BUGGY CODE ###

from collections import Counter
import re
import sys

s=input()

for i in range(len(s)):
    suffix=s[i:]
    f_len=len(suffix)
    for j in range(f_len):
        if(j==0):
            fact=suffix
        else:
            fact=fact[:-1]
        count=Counter(fact)
        count_max=max(count.values())
        moji=[moji for moji,j in count.items() if j==count_max]
        moji=moji[0]
        if(count[moji]>len(fact)/2 and len(fact)>1):
            span=(re.search(fact,s).span())
            print(span[0]+1,span[1])
            sys.exit()
print(-1,-1)

### FIXED CODE ###

arr = list(input())
tmp1 = arr[0]
tmp2 = arr[1]
 
i = 2
flg = True
if (tmp1 != tmp2):
    while i < len(arr):
        tmp3 = arr[i]
        if (tmp3 == tmp2):
            print(str(i) + " " + str(i + 1))
            flg = False
            break
        if (tmp3 == tmp1):
            print(str(i - 1) + " " + str(i + 1))
            flg = False
            break
 
        tmp1 = arr[i - 1]
        tmp2 = arr[i]
        i = i + 1
else:
    print("1 2")
    flg = False
 
if (flg):
    print("-1 -1")
### BUGGY CODE ###

import sys
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))


def solve():
    n, k =read(); arr = read()
    dp = [None for i in range(n)]; dp[0] = 0
    for i in range(n):
    	for j in range(1, k+1):
    		if i-j >-1:
    			tem = dp[i-j]+abs(arr[i-j] - arr[i])
    			if not dp[i]:
    				dp[i] = tem
    			else:
    				dp[i] = min(dp[i], tem)

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

    

if __name__ == "__main__":
	solve()

### FIXED CODE ###

import sys
# import numpy as np
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))
# import profile

def solve():
    n, k =read(); arr = read()
    dp = [-1]*n; dp[0] = 0
    for i in range(n):
    	for j in range(1, k+1):
    		if i-j >-1:
    			tem = dp[i-j]+abs(arr[i-j] - arr[i])
    			if dp[i] == -1:
    				dp[i] = tem
    			elif dp[i] > tem:
    				dp[i] = tem
    				# dp[i] = min(dp[i], tem)
    print(dp[-1])

def one():
	l = [0]*10**7
def two():
	l = [0 for i in range(10**7)]

if __name__ == "__main__":
	solve()
	# cProfile.run(solve())
	# profile.run(one())
	# cProfile.run()
### BUGGY CODE ###

A, B = list(map(int, input().split()))
if A % 2 == 0:
	ja = "j0"
else:
	ja = "j1"

if B % 2 == 0:
	jb = "j0"
else:
	jb = "j1"

a = A
b = B
a2 = ""
b2 = ""

if a == 0:
	a2 = "0"
else:
	while True:
		if a % 2 == 0:
			a2 += "0"
		else:
			a2 += "1"
		a = int(a // 2)
		if a == 1:
			a2 += "1"
			break
if b == 0:
	b2 = "0"
else:
	while True:
		if b % 2 == 0:
			b2 += "0"
		else:
			b2 += "1"
		b = int(b // 2)
		if b == 1:
			b2 += "1"
			break

a2 += "0" * (len(b2) - len(a2))
c2 = 0

if a2[0] == "0":
	if (B - A) % 4 == 2 or (B - A) % 4 == 1:
		c2 += 1
	else:
		c2 += 0

if a2[0] == "1":
	if (B - A) % 4 <= 1:
		c2 += 1
	else:
		c2 += 0

for i in range(1, len(a2)):
	n = 0
	if a2[i] == "1":
		if ja == "j1":
			n += 1

	if b2[i] == "1":
		if jb == "j0":
			n += 1

	if n % 2 == 0:
		c2 += 0
	else:
		c2 += 2 ** i

print(c2)


### FIXED CODE ###

a, b = list(map(int, input().split()))
ba = b - a
if a % 2 == 0:
	ja = "j0"
else:
	ja = "j1"

if b % 2 == 0:
	jb = "j0"
else:
	jb = "j1"

a2 = format(a, "b")
b2 = format(b, "b")
a2 = str(a2[::-1])
b2 = str(b2[::-1])

a2 += "0" * (len(b2) - len(a2))
c2 = 0

if a2[0] == "0":
	if ba % 4 == 2 or ba % 4 == 1:
		c2 += 1

if a2[0] == "1":
	if ba % 4 <= 1:
		c2 += 1

for i in range(1, len(a2)):
	n = 0
	if a2[i] == "1":
		if ja == "j1":
			n += 1

	if b2[i] == "1":
		if jb == "j0":
			n += 1

	if n % 2 == 1:
		c2 += 2 ** i

print(c2)
### BUGGY CODE ###

N=int(input())
L=list()
for i in range(N):
  L.append(list(input())*2)
L=L*2
ans=0
for i in range(N):
  for j in range(N):
    a=0
    for t in range(N):
      for q in range(t):
        if L[i+t][j+q]!=L[i+q][j+t]:
          a=1
          break
      if a==1:
        break
    if a==0:
      ans+=1
print(ans)

### FIXED CODE ###

N=int(input())
L=list()
for i in range(N):
  L.append(list(input())*2)
L=L*2
ans=0
for o in range((2*N)-1):
  a=0
  if o<N:
    i=0
    j=o
    omomi=N-j
  else:
    j=0
    i=o-N+1
    omomi=N-i
  for t in range(N):
    for q in range(t):
      if L[i+t][j+q]!=L[i+q][j+t]:
        a=1
        break
    if a==1:
      break
  if a==0:
    ans+=omomi
print(ans)
### BUGGY CODE ###

n = int(input())
al = list(map(int, input().split()))
al_s = sorted(list(set(al)))

count = 0
for a in al_s:
    ai = al.count(a) + al.count(a + 1) + al.count(a - 1)
    if ai > count:
        count = ai
print(count)

### FIXED CODE ###

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

ans = [0] * (10 ** 5 + 2)
for a in al:
    ans[a] += 1
    ans[a + 1] += 1
    ans[a - 1] += 1

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

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


class Node(object):
    def __init__(self, key, prev=None, nex=None):
        self.key = key
        self.prev = prev
        self.next = nex


class DoublyLinkedLiset(object):
    def __init__(self):
        self.nil = Node(None)
        self.nil.next = self.nil
        self.nil.prev = self.nil

    def insert(self, x):
        X = Node(x)
        X.next = self.nil.next
        self.nil.next.prev = X
        self.nil.next = X
        X.prev = self.nil

    def listSearch(self, x):
        cur = self.nil.next
        while (cur != self.nil and cur.key != x):
            cur = cur.next

        return cur

    def deleteNode(self, X):
        #if X == self.nil:
        #    return
        X.prev.next = X.next
        X.next.prev = X.prev
        del X

    def deleteFirst(self):
        self.deleteNode(self.nil.next)

    def deleteLast(self):
        self.deleteNode(self.nil.prev)

    def deleteKey(self, x):
        self.deleteNode(self.listSearch(x))

    def printList(self):
        cur = self.nil.next
        ret = []

        while cur.key is not None:
            ret.append(cur.key)
            cur = cur.next

        print(' '.join(ret))


if __name__ == '__main__':

    n = int(input())
    dll = DoublyLinkedLiset()

    for _ in range(n):
        command = input().split(" ")
        if command[0] == "insert":
            dll.insert(command[1])
        elif command[0] == "delete":
            dll.deleteKey(command[1])
        elif command[0] == "deleteFirst":
            dll.deleteFirst()
        elif command[0] == "deleteLast":
            dll.deleteLast()

    dll.printList()



### FIXED CODE ###

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

from collections import deque

if __name__ == '__main__':
    n = int(input())
    L = deque()

    for _ in range(n):
        command = input().split(" ")
        if command[0] == "insert":
            L.appendleft(command[1])
        elif command[0] == "delete":
            try:
                L.remove(command[1])
            except:
                pass
        elif command[0] == "deleteFirst":
            L.popleft()
        elif command[0] == "deleteLast":
            L.pop()

    print(" ".join(L))
### BUGGY CODE ###

#input
h, w = map(int, input().split())
c_h, c_w = map(int, input().split())
d_h, d_w = map(int, input().split())
s = [input() for _ in range(h)]

#output
from collections import deque

INF = pow(10, 10)
dp = [[INF] * w for _ in range(h)]

trans_a = [(0, 1), (1, 0), (0, -1), (-1, 0)]
trans_b = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + trans_a]

q = deque([])
q.append((c_h-1, c_w-1))
dp[c_h-1][c_w-1] = 0

while q:
    x, y = q.popleft()

    for dx, dy in trans_a:
        nx, ny = x + dx, y + dy
        if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and dp[nx][ny] > dp[x][y]:
            q.appendleft((nx, ny))#ここを変更
            dp[nx][ny] = dp[x][y]#ここを変更

    for dxb, dyb in trans_b:
        nx2, ny2 = x + dxb, y + dyb
        if 0 <= nx2 < h and 0 <= ny2 < w and s[nx2][ny2] != "#" and dp[nx2][ny2] > dp[x][y]:
            q.append((nx2, ny2))
            dp[nx2][ny2] = dp[x][y] + 1

answer = dp[d_h-1][d_w-1]

# %%
if answer == INF:
    print(-1)
else:
    print(answer)

### FIXED CODE ###

from collections import deque


H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x) - 1, input().split())
Dh, Dw = map(lambda x: int(x) - 1, input().split())
maze = [input() for _ in range(H)]

INF = 10 ** 12
path = [[INF] * W for _ in range(H)]  # path: 各マスへの移動コスト

# walk:移動A, warp:移動B
walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

q = deque()
path[Ch][Cw] = 0
q.append((Ch, Cw, 0))

while q:
    x, y, s = q.popleft()
    for dx, dy in walk:  # 移動A
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s:
            path[nx][ny] = s
            q.appendleft((nx, ny, s))  # 移動Aの場合はコスト0. キューの先頭に追加する.
    for dx, dy in warp:  # 移動B
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s + 1:
            path[nx][ny] = s + 1
            q.append((nx, ny, s + 1))  # 移動Bの場合はコスト1. キューの最後尾に追加する.
    
ans = path[Dh][Dw] if path[Dh][Dw] < INF else '-1'
print(ans)
### BUGGY CODE ###

from collections import Counter

def main():
    n = int(input())
    balls = [int(i) for i in input().split()]

    # v - value written on ball
    # b - ball index in [0, n)
    # ct - number of times a value occurs

    # hist[v] = ct
    hist = Counter(balls)
    diff_counts = set(hist.values())
    combos1 = { ct: 0 if ct == 1 else (ct-1) * (ct-2) // 2 for ct in
            diff_counts }
    combos = { ct: ct * (ct-1) // 2 for ct in diff_counts  }

    for b in range(n):
        v = balls[b]
        ct = hist[v]
        tot = sum(combos[hist[v2]] for v2 in hist.keys())
        print(tot - combos[ct] + combos1[ct])

main()


### FIXED CODE ###

from collections import Counter

def main():
    n = int(input())
    balls = [int(i) for i in input().split()]

    # v - value written on ball
    # b - ball index in [0, n)
    # ct - number of times a value occurs

    # hist[v] = ct
    hist = Counter(balls)
    diff_counts = set(hist.values())
    combos1 = { ct: 0 if ct == 1 else (ct-1) * (ct-2) // 2 for ct in
            diff_counts }
    combos = { ct: ct * (ct-1) // 2 for ct in diff_counts  }

    tot = sum(combos[hist[v2]] for v2 in hist.keys())

    for b in range(n):
        v = balls[b]
        ct = hist[v]
        print(tot - combos[ct] + combos1[ct])

main()
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [1<<30] * n
dp[0] = 0
for i in range(n):
    for j in range(min(k, n) + 1):
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print(dp[-1])


### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [1<<30] * n
dp[0] = 0
for i in range(n):
    for j in range(min(k, n) + 1):
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print(dp[-1])
### BUGGY CODE ###

import sys

#@profile
def max_heapify(A, i):
    j = i
    largest = i
    H = len(A) -1
    while True:
        l = j * 2
        r = l + 1
        if l <= H and A[l] > A[j]:
            largest = l
        if r <= H and A[r] > A[largest]:
            largest = r
        if largest != j:
            A[j], A[largest] = A[largest], A[j]
            #max_heapify(A, largest)
            j = largest
            
        else:
            break
        

#@profile
def build_max_heap(A):
    for i in range(len(A)-1 // 2, 0, -1):
        max_heapify(A, i)

#@profile
def extract(A):
    print(A[1])
    A[1] = A[-1]
    del A[-1]
    max_heapify(A, 1)
    
A = [0]

#@profile
def main():
    out = ""
    for l in sys.stdin.readlines():
        if l[0] == "i":
            #insert k
            A.append(int(l[7:]))
            build_max_heap(A)
        #print(A)
        elif l[1] == "n":
            #end
            print(out, end = "")
            return
        else:
            if len(A) <= 1:
                pass
            elif len(A) == 2:
                out += str(A.pop()) + "\n"
                #print(A.pop())
            #extract(A)
            else:
                out += str(A[1]) + "\n"
                A[1] = A.pop()
                max_heapify(A, 1)
                
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys

#@profile
def max_heapify(A, i):
    j = i
    largest = i
    H = len(A) -1
    while True:
        l = j * 2
        r = l + 1
        if l <= H and A[l] > A[j]:
            largest = l
        if r <= H and A[r] > A[largest]:
            largest = r
        if largest != j:
            A[j], A[largest] = A[largest], A[j]
            #max_heapify(A, largest)
            j = largest
            
        else:
            break
        

#@profile
def build_max_heap(A):
    i = len(A)-1
    last = A[i]
    parent = i//2
    while  parent > 0 and A[parent] < last:
        A[i] = A[parent]
        i = parent
        parent = i //2
    A[i] = last

#@profile
def extract(A):
    print(A[1])
    A[1] = A[-1]
    del A[-1]
    max_heapify(A, 1)
    
A = [0]

#@profile
def main():
    out = ""
    for l in sys.stdin.readlines():
        if l[0] == "i":
            #insert k
            A.append(int(l[7:]))
            build_max_heap(A)
        #print(A)
        elif l[1] == "n":
            #end
            print(out, end = "")
            return
        else:
            if len(A) <= 1:
                pass
            elif len(A) == 2:
                out += str(A.pop()) + "\n"
                #print(A.pop())
            #extract(A)
            else:
                out += str(A[1]) + "\n"
                A[1] = A.pop()
                max_heapify(A, 1)
                
if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

### FIXED CODE ###

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

def calc(i):
  ans = [0 for _ in range(40)]
  i += 1
  for j in range(1,41):
    
    loop = 2**j
    c = (i//loop)*(loop/2)
    c += max(0,(i%loop)-(loop/2))
    if c%2 == 1:
      ans[-j]+=1
  ans = int(''.join(str(_) for _ in ans),2)
  return ans

if a<1:
  print(calc(b))
else:
  print(calc(a-1)^calc(b))
### BUGGY CODE ###

N, M = [ int(it) for it in input().split() ]
MOD = 1000000007

import math
sM = int(math.sqrt(M)+1)

p_li = []
m = M
for i in range(sM):
  for j in range(2,sM+1):
    if (m%j)==0:
      p_li.append(j)
      m//=j
      break
  if (m==1):
    break
if (m!=1):
  p_li.append(m)
    
    
import collections
co = collections.Counter(p_li)
vec = co.values()

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

s = 1
for v in vec:
  X=N-1+v
  Y=N-1
  if (X-Y<Y):
    Y=X-Y
  ss = 1
  sd = 1
  for i in range(X,X-Y,-1):
    ss = (ss*i)%MOD
  for i in range(Y,0,-1):
    sd = (sd*i)%MOD
  
  ss = (ss*mod_inv(sd,MOD))%MOD
  s = (s*ss)%MOD
print (s%MOD)
      




### FIXED CODE ###

N, M = [ int(it) for it in input().split() ]
MOD = 1000000007

import math
sM = int(math.sqrt(M)+1)

p_li = []
m = M
for j in range(2,sM+1):
  for i in range(sM):
    if (m%j)==0:
      p_li.append(j)
      m//=j
    else:
      break
  if (m==1):
    break
if (m!=1):
  p_li.append(m)
    
    
import collections
co = collections.Counter(p_li)
vec = co.values()

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

s = 1
for v in vec:
  X=N-1+v
  Y=N-1
  if (X-Y<Y):
    Y=X-Y
  ss = 1
  sd = 1
  for i in range(X,X-Y,-1):
    ss = (ss*i)%MOD
  for i in range(Y,0,-1):
    sd = (sd*i)%MOD
  
  ss = (ss*mod_inv(sd,MOD))%MOD
  s = (s*ss)%MOD
print (s%MOD)
### BUGGY CODE ###

import numpy as np

N = int(input())
B = [int(i)*2 for i in input().split()]

a = [[0]*N for i in range(N)]

for i in range(N-1):
    for j in range(N):
        if j == i:
            a[i][j] += 1
        if j == i+1:
            a[i][j] += 1

a[-1][0] += 1
a[-1][-1] += 1

A = np.array(a, dtype=np.int)
b = np.array(B, dtype=np.int)

x = np.linalg.solve(A, b)

for i in x:
    print(int(i), end=" ")

### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
a = [int(i) for i in input().split()]

s = sum(a)
x = [None]*N
x[0] = s - 2 * (sum(a[1::2]))

for i in range(1,N):
    x[i] = 2 * a[i-1] - x[i-1]

print(*x)
### BUGGY CODE ###

from collections import deque
inf = 1001001001
H, W = map(int, input().split())
s = []
for _ in range(H):
    s.append(input())
queue = deque([[0,0]])
count = [[inf for i in range(W)] for j in range(H)]
if s[0][0] == "#":
    count[0][0] = 1
else:
    count[0][0] = 0
dh = [0,1]
dw = [1,0]
while len(queue) != 0:
    now = queue.popleft()
    h = now[0]
    w = now[1]
    for i in range(2):
        nh = h + dh[i]
        nw = w + dw[i]
        if nh >= H or nw >= W:
            continue
        else:
            queue.append([nh,nw])
            number = count[h][w]
            if s[h][w] == "." and s[nh][nw] == "#":
                number += 1
            count[nh][nw] = min(number, count[nh][nw])
print(count[H-1][W-1])

### FIXED CODE ###

inf = 1001001001
h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(input())
dp = [[inf for j in range(w)] for j in range(h)]
if s[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0
for i in range(h):
    for j in range(w):
        if i+1 < h:
            count = dp[i][j]
            if s[i][j] == "." and s[i+1][j] == "#":
                count += 1
            dp[i+1][j] = min(dp[i+1][j], count)
        if j+1 < w:
            count = dp[i][j]
            if s[i][j] == "." and s[i][j+1] == "#":
                count += 1
            dp[i][j+1] = min(dp[i][j+1], count)
print(dp[h-1][w-1])
### BUGGY CODE ###

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

card = A.copy()
for i in range(M):
    B,C = map(int, input().split())
    card += [C]*B

card.sort(reverse=True)
print(sum(card[:len(A)]))

### FIXED CODE ###

N, M = map(int,input().split())
A = [[1,int(a)] for a in input().split()]
BC = A + [list(map(int,input().split())) for _ in range(M)]

BC.sort(key=lambda x:x[1], reverse=True)

i = 0
ans = 0
for B,C in BC:
    if i + B <= N:
        ans += B*C
        i += B
    else:
        ans += (N - i) * C
        break

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

k = int(input())

que = [1,2,3,4,5,6,7,8,9]

for i in range(k):
    x = que[0]
    del que[0]
    if x%10 != 0:
        que.append(10*x+(x%10)-1)
    que.append(10*x+(x%10))
    if x%10 != 9:
        que.append(10*x+(x%10)+1)
print(x)

### FIXED CODE ###

from collections import deque
k = int(input())
q = deque(list(range(1, 10)))
for _ in range(k-1):
	d = q.popleft()
	if d%10 > 0:
		q.append(d*10 + d%10 - 1)
	q.append(d*10 + d%10)
	if d%10 < 9:
		q.append(d*10 + d%10 + 1)
print(q.popleft())
### BUGGY CODE ###

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

if 0 in a:
  print(0)
  exit()

ans = 1
for i in a:
  ans *= i

if ans > 10**18:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

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

from functools import reduce
from operator import mul

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

ans = reduce(mul, a_li)

if ans > 1000000000000000000:
    print(-1)
    exit()
else:
    print(ans)


### FIXED CODE ###

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

if 0 in a_li:
    print(0)
    exit()

ans = 1
a_li = [a for a in a_li if a != 1 and a != 0]
a_li.append(1)
for a in a_li:
    ans *= a
    if ans > 1000000000000000000:
        print(-1)
        exit()
print(ans)
### BUGGY CODE ###

N = int(input())
answer = 0
print(sum([ i % (i + 1) for i in range(1, N)]))

### FIXED CODE ###

N = int(input())
print(N*(N-1)//2)
### BUGGY CODE ###

N=int(input())
A=[i for i in map(int,input().split())]
k=0
while k!=len(A):
    k=0
    for i in range(len(A)):
        if A[i]%min(A)!=0:
            A[i]=A[i]%min(A)
        else:
            k+=1  
print(min(A))

### FIXED CODE ###

N = int(input())
A = [int(_) for _ in input().split()]
m = min(A)
while m > 0:
    for i in range(0,len(A)):
        if A[i] != m:
            A[i] = A[i]%m
    z = A.count(0)
    A = sorted(A)[z:]
    m = A[0]
    if m == 1:
        break
    else:
        if [_%m for _ in A] == [0]*len(A):
            break
print(m)
### BUGGY CODE ###

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

ans = 0
for i in range(1, len(a)):
    while True:
        if a[i-1] + a[i] > x:
            if a[i] > 0:
                a[i] -= 1
                ans += 1
            else:
                a[i-1] -= 1
                ans += 1
        else:
            break

print(ans)


### FIXED CODE ###

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

ans = 0
for i in range(1, len(a)):
    # 2組の合計がxよりも大きいなら
    if a[i-1] + a[i] > x:
        # 右側の数が0より大きいなら食べる
        if a[i] > 0:
            # 右側の箱の飴をすべて食べてもx以上ならすべて食べる
            if (a[i-1] + a[i] - x) > a[i]:
                ans += a[i]
                a[i] = 0
            # 右側の箱の飴を食べるだけでx以下になるならその分だけ食べる
            else:
                ans += (a[i-1] + a[i] - x)
                a[i] = a[i] - (a[i-1] + a[i] - x)

        # 右の箱を食べただけでx以下にならない時は左側の箱の飴も食べる
        if a[i-1] + a[i] > x:
            # 左側の箱の飴をすべて食べる
            if (a[i-1] + a[i] - x) > a[i-1]:
                ans += a[i-1]
                a[i-1] = 0
            # 左側の箱の飴をx以下になるだけ食べる
            else:
                ans += (a[i-1] + a[i] - x)
                a[i-1] = a[i-1] - (a[i-1] + a[i] - x)

print(ans)