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

N, K = map(int, input().split(" "))
H = [int(i) for i in input().split(" ")]

cost = [0] + [10**9 for _ in range(N-1)]
for i in range(1,N):
    for j in range(min(i, K)):
        cost[i] = min(cost[i], cost[i-j-1] + abs(H[i-j-1] - H[i]))

print(cost[-1])

### FIXED CODE ###

import numpy as np
N, K = map(int, input().split(" "))
H = np.array([int(i) for i in input().split(" ")])

cost = np.array([0] + [10**9 for _ in range(N-1)])
for i in range(1,N):
    cost[i] = np.min(cost[max(0,i-K):i] + np.abs(H[max(0,i-K):i] - H[i]))

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

import heapq

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
B = []
for _ in range(M):
    tmp = [int(b) for b in input().split()]
    B.append(tmp)

heapq.heapify(A)

for i in range(M):
    for j in range(B[i][0]):
        val = heapq.heappop(A)
        if val < B[i][1]:
            heapq.heappush(A, B[i][1])
        else:
            heapq.heappush(A, val)
            
print(sum(A))

### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = [int(a) * (-1) for a in input().split()]

B_array = []
for _ in range(M):
    B, C = map(int, input().split())
    B_array.append([C * (-1), B])
B_array.sort()

cnt = 0
i = 0
B_list = []
while cnt < N and i < M:
    B_list.extend([B_array[i][0]] * B_array[i][1])
    cnt += B_array[i][1]
    i += 1

A.extend(B_list)
heapq.heapify(A)

ans = 0
for _ in range(N):
    ans += heapq.heappop(A)
        
print(ans * (-1))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998244353

class BIT2:
    def __init__(self, N):
        self.N = (N+1)
        self.data0 = [0] * (N+1)
        self.data1 = [0] * (N+1)
        
    def _add(self, data, k, x):
        while k < self.N: #k <= Nと同義
            data[k] += x
            k += k & -k

    def _sum(self, data, k):
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s

    def add(self, l, r, x):
        self._add(self.data0, l, -x*(l-1))
        self._add(self.data0, r, x*(r-1))
        self._add(self.data1, l, x)
        self._add(self.data1, r, -x)

    def sum(self, l, r):
        return self._sum(self.data1, r-1) * (r-1) + self._sum(self.data0, r-1) \
                - self._sum(self.data1, l-1) * (l-1) - self._sum(self.data0, l-1) #改行

N, Q = map(int, readline().split())
bit1 = BIT2(N)
bit1.add(1,N+1,N-2)
bit2 = BIT2(N)
bit2.add(1,N+1,N-2)
total = (N-2)**2

right = N
low = N
cnt = 0
for _ in range(Q):
    cmd,t = map(int,readline().split())
    if cmd == 1:
        tmp = bit1.sum(t,t+1)
        cnt += tmp
        bit1.add(t,t+1,-tmp)
        if t < right:
            bit2.add(1,low,t-right) 
            right = t
    else:
        tmp = bit2.sum(t,t+1)
        cnt += tmp
        bit2.add(t,t+1,-tmp)
        if t < low:
            bit1.add(1,right,t-low)  
            low = t

ans = total - cnt
print(ans) 

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998244353

class BIT2:
    def __init__(self, N):
        self.N = (N+1)
        self.data0 = [0] * (N+1)
        self.data1 = [0] * (N+1)
        
    def _add(self, data, k, x):
        while k < self.N: #k <= Nと同義
            data[k] += x
            k += k & -k

    def _sum(self, data, k):
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s

    def add(self, l, r, x):
        self._add(self.data0, l, -x*(l-1))
        self._add(self.data0, r, x*(r-1))
        self._add(self.data1, l, x)
        self._add(self.data1, r, -x)

    def sum(self, l, r):
        return self._sum(self.data1, r-1) * (r-1) + self._sum(self.data0, r-1) \
                - self._sum(self.data1, l-1) * (l-1) - self._sum(self.data0, l-1) #改行

N, Q = map(int, readline().split())
bit1 = BIT2(N)
bit1.add(1,N+1,N-2)
bit2 = BIT2(N)
bit2.add(1,N+1,N-2)
total = (N-2)**2

right = N
low = N
cnt = 0
for _ in range(Q):
    cmd,t = map(int,readline().split())
    if cmd == 1:
        tmp = bit1.sum(t,t+1)
        cnt += tmp
        bit1.add(t,t+1,-tmp)
        if t < right:
            bit2.add(1,low,t-right) 
            right = t
    else:
        tmp = bit2.sum(t,t+1)
        cnt += tmp
        bit2.add(t,t+1,-tmp)
        if t < low:
            bit1.add(1,right,t-low)  
            low = t

ans = total - cnt
print(ans)
### BUGGY CODE ###

import bisect
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
ans = 0

for i in range(n):
  for j in range(i+1, n):
    s = l[i]+l[j]
    tmpl = l[j+1:n]
    ans += bisect_left(l[j+1:n], s)

print(ans)

### FIXED CODE ###

import bisect
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
ans = 0

for i in range(n):
  for j in range(n-1, i, -1):
    s = l[i]+l[j]
    ans += bisect_left(l[j+1:n], s)

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

N, M = map(int, input().split())
A = sorted([int(a) for a in input().split()])
for num in range(M):
    b, c = map(int, input().split())
    b = min(b, N)
    if A[-1] < c:
        if b == N:
            A = [c] * b
        else:
            A = A[b:] + [c] * b
    elif A[0] < c:
        for index, a in enumerate(A):
            if a >= c:
                A = A[:index] + [c] * b + A[index:]
                A = A[b:]
                break
total = 0
for a in A:
    total += a
print(total)

### FIXED CODE ###

N, M = map(int, input().split())
A = sorted([int(a) for a in input().split()])[::-1]
BC = []
for num in range(M):
    b, c = map(int, input().split())
    BC.append((b, c))
lis = sorted(BC, key = lambda x: -x[1])
total = 0
counter = 0
while counter < N:
    if not lis == []:
        if lis[0][1] > A[0]:
            (b, c) = lis.pop(0)
            b = min(b, N - counter)
            total += c * b
            counter += b
        else:
            total += A.pop(0)
            counter += 1
    else:
        total += A.pop(0)
        counter += 1
print(total)
### BUGGY CODE ###

z,v,a=input,range,print
h,w,k=map(int,z().split())
r,s,t,u=map(lambda x:int(x)-1,z().split())
b=[z()for _ in v(h)]
l=[[-1]*w for _ in v(h)]
l[r][s]=0
from collections import*
d=deque([(r,s)])
while d:
  x,y=d.popleft()
  if(x==t)&(y==u):exit(a(l[x][y]))
  for e,f in[[1,0],[-1,0],[0,-1],[0,1]]:
    for i in v(1,k+1):
      p,q=x+e*i,y+f*i
      if not((0<=p<h)&(0<=q<w))or b[p][q]=="@" or 0<=l[p][q]<=l[x][y]:break
      d+=[(p,q)];l[p][q]=l[x][y]+1
a(-1)

### FIXED CODE ###

import sys
inf=1000002
sys.setrecursionlimit(inf)
from collections import deque
h,w,k=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
c=[input() for i in range(h)]
dp=[[inf if c[i][j]=="." else -1 for j in range(w)] for i in range(h)]
now=deque()
now.append([x1-1,y1-1])
dp[x1-1][y1-1]=0
#kの更新が遅い
def bfs(d):
    global h,w,k,dp,now,x2,y2
    l=len(now)
    if l==0:
        return
    dp_sub=deque()
    cand=set()
    for i in range(l):
        x,y=now.popleft()
        for j in range(1,min(k+1,w-y)):
            if dp[x][y+j]==inf:
                dp_sub.append([x,y+j,d])
                #dp[x][y+j]=d
                cand.add((x,y+j))
                #now.append([x,y+j])
            else:
                break
        for j in range(1,min(k+1,y+1)):
            if dp[x][y-j]==inf:
                dp_sub.append([x,y-j,d])
                #dp[x][y-j]=d
                cand.add((x,y-j))
                #now.append([x,y-j])
            else:
                break
        for j in range(1,min(k+1,h-x)):
            if dp[x+j][y]==inf:
                dp_sub.append([x+j,y,d])
                #dp[x+j][y]=d
                cand.add((x+j,y))
                #now.append([x+j,y])
            else:
                break
        for j in range(1,min(k+1,x+1)):
            if dp[x-j][y]==inf:
                dp_sub.append([x-j,y,d])
                #dp[x-j][y]=d
                cand.add((x-j,y))
                #now.append([x-j,y])
            else:
                break
    while dp_sub!=deque([]):
        e=dp_sub.popleft()
        dp[e[0]][e[1]]=e[2]
    for i in cand:
        now.append(i)
    bfs(d+1)
bfs(1)
print(dp[x2-1][y2-1] if dp[x2-1][y2-1]!=inf else -1)
### BUGGY CODE ###

import math
import itertools

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

c = itertools.combinations(a,3)

ans = 0
for v in c:
    x,y,z = v[0],v[1],v[2]
    if x < y+z and y < x+z and z < x+y:
        ans += 1
print(ans)

### FIXED CODE ###

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

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

from collections import deque

H, W = map(int, input().split())
data = deque()

for y in range(H):
    for x, v in enumerate(input()):
        if v == '#':
            data.append([y, x, [], 0])

inf = H * W + 10
ans = [[inf for _ in range(W)] for __ in range(H)]

for v in data:
    ans[v[0]][v[1]] = 0

def check(destination, origin):
    return [destination[0], destination[1]] not in origin[2]

def cnt_update(ans, v):
    ans[v[0], v[1]] = v[3] + 1
"""
BFSまとめ
0. 現在位置、履歴、アクション数の3要素が必要
1. 更新する, アクション数を加算する
2. 条件を一致しているか、履歴に入っていないかを確認
3. popをループ
"""

fin = 0

while len(data):
    v = data.popleft()
    v[2].append([v[0], v[1]])

    if v[1] - 1 >= 0 and ans[v[0]][v[1] - 1] > v[3] + 1:
        v_left = [v[0], v[1] - 1, v[2], v[3] + 1]
        if check(v_left, v):
            ans[v_left[0]][v_left[1]] = v_left[3]
            data.append(v_left)
            if fin < v[3] + 1:
                fin = v[3] + 1

    if v[1] + 1 <= W - 1 and ans[v[0]][v[1] + 1] > v[3] + 1:
        v_right = [v[0], v[1] + 1, v[2], v[3] + 1]
        if check(v_right, v):
            ans[v_right[0]][v_right[1]] = v_right[3]
            data.append(v_right)
            if fin < v[3] + 1:
                fin = v[3] + 1

    if v[0] - 1 >= 0 and ans[v[0] - 1][v[1]] > v[3] + 1:
        v_up = [v[0] - 1, v[1], v[2], v[3] + 1]
        if check(v_up, v):
            ans[v_up[0]][v_up[1]] = v_up[3]
            data.append(v_up)
            if fin < v[3] + 1:
                fin = v[3] + 1

    if v[0] + 1 <= H - 1 and ans[v[0] + 1][v[1]] > v[3] + 1:
        v_down = [v[0] + 1, v[1], v[2], v[3] + 1]
        if check(v_down, v):
            ans[v_down[0]][v_down[1]] = v_down[3]
            data.append(v_down)
            if fin < v[3] + 1:
                fin = v[3] + 1

# print(max([a for aa in ans for a in aa]))
print(fin)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
data = deque()

for y in range(H):
    for x, v in enumerate(input()):
        if v == '#':
            data.append((y, x))

ans = [[-1 for _ in range(W)] for __ in range(H)]

for v in data:
    ans[v[0]][v[1]] = 0

"""
BFSまとめ

0. 
現在位置、履歴、アクション数の3要素が必要.
処理をLIFOでなく、FIFOでやる
そのため、collection.dequeを使う
更にソートしつつ、FIFOしたい場合は、heapqを使う

1. 
更新する, アクション数を加算する

2. 
条件を一致しているか、履歴に入っていないかを確認

3. 
popをループ
"""

d = 0
while len(data):
    y, x = data.popleft()
    d = ans[y][x]

    for i, j in ((-1, 0), (1, 0), (0, -1), (0, 1)):
        new_y = y + i
        new_x = x + j
        if new_y < 0 or H <= new_y or new_x < 0 or W <= new_x:
            continue
        if ans[new_y][new_x] == -1:
            ans[new_y][new_x] = d + 1
            data.append((new_y, new_x))

print(max([a for aa in ans for a in aa]))
### BUGGY CODE ###

H,W = map(int,input().split())
S = [input() for i in range(H)]

L = [[0]*W for i in range(H)]
R = [[0]*W for i in range(H)]
U = [[0]*W for i in range(H)]
D = [[0]*W for i in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w]==".":
            if h==0:D[h][w]=1
            else:D[h][w]=D[h-1][w]+1
            if w==0:R[h][w]=1
            else:R[h][w]=R[h][w-1]+1
for h in range(H-1,-1,-1):
    for w in range(W-1,-1,-1):
        if S[h][w]==".":
            if h==H-1:U[h][w]=1
            else:U[h][w]=U[h+1][w]+1
            if w==W-1:L[h][w]=1
            else:L[h][w]=L[h][w+1]+1

ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans,L[h][w]+R[h][w]+U[h][w]+D[h][w]-3)
print(ans)

### FIXED CODE ###

H,W = map(int,input().split())
S = [input() for i in range(H)]

L = [[0]*W for i in range(H)]
R = [[0]*W for i in range(H)]
U = [[0]*W for i in range(H)]
D = [[0]*W for i in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w]==".":
            if h==0:D[h][w]=1
            else:D[h][w]=D[h-1][w]+1
            if w==0:R[h][w]=1
            else:R[h][w]=R[h][w-1]+1
for h in range(H-1,-1,-1):
    for w in range(W-1,-1,-1):
        if S[h][w]==".":
            if h==H-1:U[h][w]=1
            else:U[h][w]=U[h+1][w]+1
            if w==W-1:L[h][w]=1
            else:L[h][w]=L[h][w+1]+1

ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans,L[h][w]+R[h][w]+U[h][w]+D[h][w]-3)
print(ans)
### BUGGY CODE ###

import numpy as np
import math
from itertools import permutations

N = int(input())
mati = np.array([list(map(int, input().split())) for _ in range(N)])
total = 0

for v in permutations(mati,N):
    for i in range(N-1):
        total += np.linalg.norm(v[i+1]-v[i])
print(total/math.factorial(N))

### FIXED CODE ###

import math
from itertools import permutations


def get_distance(a,b):
    d = math.sqrt((a[1] - b[1]) ** 2 + (a[0] - b[0]) ** 2)
    return d

N = int(input())
mati = [list(map(int, input().split())) for _ in range(N)]
total = 0

for v in permutations(mati,N):
    for i in range(N-1):
        total += get_distance(v[i+1], v[i])
print(total/math.factorial(N))
### BUGGY CODE ###

from heapq import heappush, heappop
sx,sy,gx,gy=map(int,input().split())
n=int(input())
g = [[] for i in range(n+2)]
data=[(sx+sy*1j,0)]
for i in range(n):
    a,b,c=map(int,input().split())
    data.append((a+b*1j,c))
data.append((gx+gy*1j,0))

for i in range(n+2):
    for j in range(i+1,n+2):
        tmp=abs(data[i][0]-data[j][0])-data[i][1]-data[j][1]
        g[i].append((tmp,j))
        g[j].append((tmp,i))

dist=[2828427127 for i in range(n+2)]
visited=[False for i in range(n+2)]
dist[0]=0
que=[]
heappush(que,(0,0))

while que:
    c,v=heappop(que)
    if visited[v]:
        continue
    visited[v]=True
    if v==n+1:
        break
    for i in range(len(g[v])):
        if visited[g[v][i][1]]:
            continue
        tmp=g[v][i][0]+c if not g[v][i][0]<0 else c
        if tmp<dist[g[v][i][1]]:
            dist[g[v][i][1]]=tmp
            heappush(que,(tmp,g[v][i][1]))
print(dist[n+1])


### FIXED CODE ###

from heapq import heappush, heappop
sx,sy,gx,gy=map(int,input().split())
n=int(input())
g = [[] for i in range(n+2)]
data=[(sx+sy*1j,0)]
for i in range(n):
    a,b,c=map(int,input().split())
    data.append((a+b*1j,c))
data.append((gx+gy*1j,0))

for i in range(n+2):
    for j in range(i+1,n+2):
        tmp=abs(data[i][0]-data[j][0])-data[i][1]-data[j][1]
        g[i].append((tmp,j))
        g[j].append((tmp,i))

dist=[2828427127 for i in range(n+2)]
visited=[False for i in range(n+2)]
dist[0]=0
que=[]
heappush(que,(0,0))

while que:
    c,v=heappop(que)
    if visited[v]:
        continue
    visited[v]=True
    for x in g[v]:
        if visited[x[1]]:
            continue
        tmp=x[0]+c if not x[0]<0 else c
        if tmp<dist[x[1]]:
            dist[x[1]]=tmp
            heappush(que,(tmp,x[1]))
print(dist[n+1])
### BUGGY CODE ###

n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]
dp = [0]*(n+1)
dp[0] = 1
if 1 in a:
  dp[1] = 0
else:
  dp[1] = 1
for i in range(2,n+1):
  if i in a:
    dp[i] = 0
  else:
    dp[i] = dp[i-1]+dp[i-2]
print(dp[-1] % (10**9+7))

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]
a = set(a)
dp = [0]*(n+1)
dp[0] = 1
mod = 10**9 + 7
if 1 in a:
  dp[1] = 0
else:
  dp[1] = 1
for i in range(2,n+1):
  if i in a:
    continue
  else:
    dp[i] = (dp[i-1]+dp[i-2]) % mod
print(dp[-1] % mod)
### BUGGY CODE ###

import sys
input=sys.stdin.readline


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

DP=[10000000000]*N

DP[0]=0
for i in range(1,N):
    temp=[]
    if i<K:
        for j in range(i):
            temp.append(DP[j]+abs(h[j]-h[i]))
    else:
        for j in range(1,K+1):
            temp.append(DP[i-j]+abs(h[i]-h[i-j]))
    DP[i]=min(temp)

print(DP[N-1])

### FIXED CODE ###

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

DP=[10000000000]*N

DP[0]=0
for i in range(1,N):
    temp=[]
    if i<K:
        for j in range(i):
            temp.append(DP[j]+abs(h[j]-h[i]))
    else:
        for j in range(1,K+1):
            temp.append(DP[i-j]+abs(h[i]-h[i-j]))
    DP[i]=min(temp)

print(DP[N-1])
### BUGGY CODE ###

from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
N = int(input())

A = []
for _ in range(N):
  A.append(list(map(int, input().split())))
  
G = csgraph_from_dense(A)
D = floyd_warshall(G)

ans = 0
for i in range(N):
  for j in range(i+1,N):
    if D[i][j] < A[i][j]:
      print(-1)
      exit(0)
      
for i in range(N):
  for j in range(i+1,N):
    flg = True
    for k in range(N):
      if i == k or j == k:
        continue
      if D[i][j] == D[i][k] + D[k][j]:
        flg = False
        break
    if flg:
      ans += D[i][j]
      
print(int(ans))

### FIXED CODE ###

#from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
import copy
N = int(input())

A = []
for _ in range(N):
  A.append(list(map(int, input().split())))
  
D = copy.deepcopy(A)
for i in range(N):
  D[i][i] = 0
  
for k in range(N):
  for i in range(N):
    for j in range(N):
      D[i][j] = min(D[i][j], D[i][k] + D[k][j])
      
#G = csgraph_from_dense(A)
#D = floyd_warshall(G)

ans = 0
for i in range(N):
  for j in range(i+1,N):
    if D[i][j] < A[i][j]:
      print(-1)
      exit(0)
      
for i in range(N):
  for j in range(i+1,N):
    flg = True
    for k in range(N):
      if i == k or j == k:
        continue
      if D[i][j] == D[i][k] + D[k][j]:
        flg = False
    if flg:
      ans += D[i][j]
      
print(int(ans))
### BUGGY CODE ###

import math
import itertools

def read():
    N, K = list(map(int, input().strip().split()))
    A = list(map(int, input().strip().split()))
    return N, K, A


def solve(N, K, A):
    S = [0 for _ in range(N+1)]
    for i in range(N):
        S[i+1] = (S[i] + A[i]) % K
    count = 0
    for j in range(N+1):
        for i in range(j):
            if (S[j] - S[i]) % K == (j - i):
                count += 1
    return count
    
if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print("%d" % output)


### FIXED CODE ###

def read():
    N, K = list(map(int, input().strip().split()))
    A = list(map(int, input().strip().split()))
    return N, K, A

def solve(N, K, A):
    if K == 1:
        return 0
    
    S = [0 for _ in range(N+1)]
    for i in range(N):
        S[i+1] = S[i] + A[i]
    
    count_sum = 0
    count = dict()
    for j in range(1, N+1):
        j_mod_k = (S[j] - j) % K  # 0 <= jmodk < K
        if j == 1:
            for i in range(max(0, j-K+1), j):
                # (S[i] - i) % K の値 i_mod_k は、次のループでもほぼ重複する
                # i = max(0, j-K+1) の時の i_mod_k は、i+1で破棄する
                # i = j の時の i_mod_k は、i+1で生成する
                i_mod_k = (S[i] - i) % K
                if i_mod_k in count:
                    count[i_mod_k] += 1
                else:
                    count[i_mod_k] = 1
        else:
            if max(0, j-K+1) != max(0, (j-1)-K+1):
                i = max(0, (j-1)-K+1)
                i_mod_k = (S[i] - i) % K
                if i_mod_k in count:
                    if count[i_mod_k] == 1:
                        count.pop(i_mod_k)
                    else:
                        count[i_mod_k] -= 1
            i = j-1
            i_mod_k = (S[i] - i) % K
            if i_mod_k in count:
                count[i_mod_k] += 1
            else:
                count[i_mod_k] = 1
        if j_mod_k in count:
            count_sum += count[j_mod_k]
    return count_sum

if __name__ == '__main__':
    inputs = read()
    print('%d' % solve(*inputs))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n, m = map(int, input().split())

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

for i in range(m):
  l, r = map(int, input().split())
  lst = [l + j for j in range(r - l + 1)]
  lst1 = lst if len(lst1) == 0 else list(set(lst1) & set(lst))

print(len(lst1))


### FIXED CODE ###

# -*- coding: utf-8 -*-
n, m = map(int, input().split())
max_value, min_value = -1, -1
for i in range(m):
  tmp_min_value, tmp_max_value = map(int, input().split())
  min_value = max([min_value, tmp_min_value]) if min_value >= 0 else tmp_min_value
  max_value = min([max_value, tmp_max_value]) if max_value >= 0 else tmp_max_value

min_value = min_value if min_value <= n else n
max_value = max_value if max_value <= n else n

ret = max_value - min_value + 1
if ret < 0:
  ret = 0
print(ret)
### BUGGY CODE ###

from sys import stdin
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
prime_list=[i for i in range(1,100000) if is_prime(i)]
oppai=[0]*100000
for i in range(2, 100000,2):
    if i in prime_list and (i+1)//2 in prime_list:
        oppai[i-1]=oppai[i-3]+1
    else:oppai[i-1]=oppai[i-3]
N=list(map(int,stdin.readline().strip().split()))[0]
for _ in range(N):
    count = 0
    a,b=map(int,(input().split()))
    if a==b:
        bb = oppai[b - 1]
        aa = oppai[a - 2]
        count = bb - aa
        print(count)
    else:
        if a>=2:
            bb=oppai[b-1]
            aa=oppai[a-2]
            count = bb - aa
            print(count)
        else:
            bb = oppai[b - 1]
            count = bb
            print(count)





### FIXED CODE ###

from sys import stdin
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
prime_list=[i for i in range(2,100000) if is_prime(i)]
oppai=[0]*100000
oppai[1]=0
before=1
for num in prime_list:
    if (num+1)//2 in prime_list:
        oppai[before:num - 2] = [oppai[before]] * (num-1 - before)
        oppai[num-1]=oppai[before]+1
    else:oppai[before:num-1]=[oppai[before]]*(num-before)
    before=num-1
oppai[99991:99999]=[oppai[99990]]*8
N=list(map(int,stdin.readline().strip().split()))[0]
for _ in range(N):
    count = 0
    a,b=list(map(int,stdin.readline().strip().split()))
    if a==b:
        bb = (oppai[b - 1])
        aa = (oppai[a - 2])
        count = bb - aa
        print(count)
    else:
        if a>=2:
            bb = oppai[b - 1]
            aa = oppai[a - 2]
            count = bb - aa
            print(count)
        else:
            bb = oppai[b - 1]
            count = bb
            print(count)
### BUGGY CODE ###

N=int(input())
S=input()

D=[0]*100
C=0
W=[0]*10
R=len(set(S))**3

for i in range(N-2):
    if(C==R):
        break
    if(W[int(S[i])]<10):
        for j in range(i+1,N-1):
            s=str(S[i])+str(S[j])
            if(D[int(s)]==0):
                D[int(s)]=1
                W[int(S[i])]+=1
                C+=len(set(S[j+1:N]))
print(C)



### FIXED CODE ###

n = int(input())
s = input()
ans = 0
for a in range(10):
  for b in range(10):
    for c in range(10):
      a, b, c = str(a), str(b), str(c)
      a_find = s.find(a)
      if a_find == -1:
        continue
      b_find = s.find(b, a_find + 1)
      if b_find == -1:
        continue
      c_find = s.find(c, b_find + 1)
      if c_find == -1:
        continue
      ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())

lst = []
for i in range(N):
    num = int(input())
    if (num in lst):
        lst.remove(num)
    else:
        lst.append(num)

print (len(lst))

### FIXED CODE ###

import collections as c

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

d = c.Counter()
for i in a:
    d[i] += 1

ans = 0
for k, v in d.items():
    ans += v % 2

print (ans)