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

t = int(input())
abcd_list = [[int(i) for i in input().split()] for _ in range(t)]

for i in range(len(abcd_list)):
    a, b, c, d = abcd_list[i]
    _a = a
    is_ok = True
    for j in range(100000):
        if d < b:
            is_ok = False
            break
            
        if _a - b > c:
            _a -= (((_a - c) // b) - 1) * b
        _a -= b
        if _a < 0:
            is_ok = False
            break
        if _a <= c:
            _a += d
    if is_ok:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
t = int(input())
abcd_list = [[int(i) for i in input().split()] for _ in range(t)]

for i in range(len(abcd_list)):
    a, b, c, d = abcd_list[i]
    if b > a:
        print("No")
        continue
    if b > d:
        print("No")
        continue
    if c > b:
        print('Yes')
        continue
    g = gcd(b, d)
    max_mod_b = b - g + a % g
    if max_mod_b > c:
        print('No')
    else:
        print("Yes")
### BUGGY CODE ###

from collections import deque

INF = float("inf")

N, M, *AB = map(int, open(0).read().split())

E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    E[b].append(a)

dist = [INF] * (N + 1)
ans = [-1] * (N + 1)

Q = deque([1])
dist[1] = 0
while Q:
    v = Q.popleft()
    d = dist[v] + 1
    for u in E[v]:
        if dist[u] > d:
            dist[u] = d
            ans[u] = v
            Q.appendleft(u)

print("Yes")
for a in ans[2:]:
    print(a)

### FIXED CODE ###

from collections import deque

INF = float("inf")

N, M, *AB = map(int, open(0).read().split())

E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    E[b].append(a)

dist = [INF] * (N + 1)
ans = [-1] * (N + 1)

Q = deque([1])
dist[1] = 0
while Q:
    v = Q.popleft()
    d = dist[v] + 1
    for u in E[v]:
        if dist[u] > d:
            dist[u] = d
            ans[u] = v
            Q.append(u)

print("Yes")
for a in ans[2:]:
    print(a)
### BUGGY CODE ###

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


import functools
import operator
total_product = functools.partial(functools.reduce, operator.mul)
ans = total_product(a)

if ans > 10**18:
    ans = -1

if 0 in a:
    ans = 0
print(ans)

### FIXED CODE ###

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

ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        ans = -1
        break

if 0 in A:
    ans = 0

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

n = int(input())
a = [int(item) for item in input().split()]
a.sort()

ai = a[-1]
aj = 1
for item in a[:-1]:
  diff = 1
  for i in range(item - aj):
    diff *= ai - aj - i
    diff /= item - i
  if diff < 1:
    break
  aj = item

print(ai, aj)
  

### FIXED CODE ###

import bisect
import math

n = int(input())
a = [int(item) for item in input().split()]
a.sort()
ai = a[-1]

left = bisect.bisect(a, ai/2) - 1
right = left + 1

if a[right] - ai/2 >= ai/2 - a[left]:
  print(ai, a[left])
else:
  print(ai, a[right])
### BUGGY CODE ###

import heapq
import sys

input = sys.stdin.readline

def dijkstra(s,edge):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

n,x,y = map(int,input().split())

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(n-1):
    edge[i].append((1,i+1))
    edge[i+1].append((1,i))
edge[x-1].append((1,y-1))
edge[y-1].append((1,x-1))

for i in range(n):
    edge[i] = tuple(edge[i])
edge = tuple(edge)

ans = [0 for _ in range(n)]
for i in range(n):
    #dijkstra(始点,edge)
    res = dijkstra(i,edge)
    for j in range(i+1,n):
        ans[res[j]] += 1

for i in range(1,n):
    print(ans[i])


### FIXED CODE ###

from scipy.sparse.csgraph import dijkstra
import sys
def main():
	input = sys.stdin.readline

	n,x,y = map(int,input().split())

	route = [[0 for _ in range(n)]for _ in range(n)]
	for i in range(n-1):
		route[i][i+1] = 1

	route[x-1][y-1] = 1
	route[y-1][x-1] = 1
	route = tuple(route)
	#res = shortest_path(route, unweighted=False,directed=False)
	res = tuple(dijkstra(route, directed=False))

	ans = [0 for _ in range(n)]
	for i in range(n):
		for j in range(i,n):
			ans[int(res[i][j])] += 1

	for i in range(1,n):
		print(ans[i])
if __name__ == '__main__':
    main()
### BUGGY CODE ###

q = int(input())
for i in range(q):
    x = input()
    y = input()
    n = len(x)
    m = len(y)
    dp1 = [0]*(m+1)
    for i in range(n):
        dp2 = dp1[:]
        for j in range(m):
            if x[i] == y[j]:
                dp1[j+1] = dp2[j]+1
            elif dp1[j+1] < dp1[j]:
                dp1[j+1] = dp1[j]
    print(dp1[-1])


### FIXED CODE ###

def calc(x,y):
    n = len(x)
    m = len(y)
    dp1 = [0]*(m+1)
    for i in range(n):
        s = x[i]
        dp2 = dp1[:]
        for j in range(m):
            if s == y[j]:
                dp1[j+1] = dp2[j]+1
            elif dp1[j+1] < dp1[j]:
                dp1[j+1] = dp1[j]
    return dp1[-1]

q = int(input())
for i in range(q):
    x = input()
    y = input()
    print(calc(x,y))
### BUGGY CODE ###

import queue
import copy

H, W = map(int,input().split())
A = [input() for i in range(H)]
q1 = queue.Queue()
q2 = queue.Queue()
visit = [[False]*W for i in range(H)]
cnt = 0

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q1.put([i,j])
            visit[i][j] = True

while not q1.empty():
    while not q1.empty():
        index = q1.get()
        for i in [-1,1]:
            for j in [-1,1]:
                if index[0]+i >= 0 and index[0]+i < H:
                    if not visit[index[0]+i][index[1]]:
                        visit[index[0]+i][index[1]] = True
                        q2.put([index[0]+i,index[1]])
                if index[1]+j >= 0 and index[1]+j < W:
                    if not visit[index[0]][index[1]+j]:
                        visit[index[0]][index[1]+j] = True
                        q2.put([index[0],index[1]+j])
    q1.queue = copy.deepcopy(q2.queue)
    q2 = queue.Queue()
    cnt += 1
    
print(cnt-1)




### FIXED CODE ###

H, W = map(int,input().split())
A = [input() for i in range(H)]
q1 = []
q2 = []
visit = [[False]*W for i in range(H)]
cnt = 0

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q1.append([i,j])
            visit[i][j] = True

while q1:
    while q1:
        index = q1.pop()
        for i in [-1,1]:
            for j in [-1,1]:
                if index[0]+i >= 0 and index[0]+i < H:
                    if not visit[index[0]+i][index[1]]:
                        visit[index[0]+i][index[1]] = True
                        q2.append([index[0]+i,index[1]])
                if index[1]+j >= 0 and index[1]+j < W:
                    if not visit[index[0]][index[1]+j]:
                        visit[index[0]][index[1]+j] = True
                        q2.append([index[0],index[1]+j])
    q1 = q2[:]
    q2 = []
    cnt += 1
    
print(cnt-1)
### BUGGY CODE ###

def main():
    s = input()
    MOD = 2019
    r = [0]*MOD
    r[0] = 1
    z = 0
    t = 1
    for i in reversed(s):
        z = int(i) * t%MOD + z
        z %= MOD
        t *= 10
        r[z] += 1
    print(sum(i*(i-1)//2 for i in r))


if __name__ == '__main__':
    main()


### FIXED CODE ###

s = input()
n = len(s)
m = 2019

a = 0
r = [0 for _ in range(m+1)]
r[0] = 1
z = 0
j = 1
for i in range(0,n):
    j = j * 10 % m
    ss = int(s[n-i-1])*j + z
    z = ss%m



    a += r[z]
    r[z] += 1

print(a)
### BUGGY CODE ###

N = int(input())
students = [int(x) for x in input().split()]
for i in range(1, N + 1):
    trun = students.index(i) + 1
    print(str(trun) + ' ', end ='')
print()

### FIXED CODE ###

# coding: utf-8
N = int(input())
student_list = [0] * (N + 1)
turn_list = [int(x) for x in input().split()]

for i, s in enumerate(turn_list):
    student_list[s] = i + 1
student_list.pop(0)
for s in student_list:
    print(str(s), end=' ')
print()
### BUGGY CODE ###

import collections
import itertools

count = 0

n = int(input())

word_list = []
words = []

for i in range(n):
    word_list.append(input())

for i in range(n):
    c = collections.Counter(word_list[i])
    words.append(sorted(list(c.items())))

l = list(range(n))
d = list(itertools.combinations(l, 2))

for i, j in d:
    if words[i] == words[j]:
        count += 1


print(count)

### FIXED CODE ###

import collections
import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = int(input())
s = []
for i in range(n):
    a = sorted(input())
    s.append(a)

ss = []

for i in range(n):
    ss.append(''.join(s[i]))

c = collections.Counter(ss)
d = sorted(list(c.values()), reverse=True)

sum = 0

for i in d:
    if i == 1:
        print(sum)
        exit()
    else:
        a = combinations_count(i, 2)
        sum += a

print(sum)
### BUGGY CODE ###

from math import gcd

# = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
mA = max(A)
primenum = [2]
sgn = [-1 for _ in range(int(mA**0.5)+1)]
k = 3
while k**2 <= mA:
  if sgn[k] == -1:
    primenum.append(k)
    add = k*k
    ok = k
    while ok**2 <= mA:
      sgn[ok] = 1
      ok += add
  k += 2
#prime_num が用意されているとき
primecounter = [0 for _ in range(len(primenum))]
biggerprime = [0 for _ in range(mA+1)]
def factorization(n):
  M = n
  for k in range(len(primenum)):
    p = primenum[k]
    if p**2 > M:
      break
    else:
      if M%p == 0:
        if primecounter[k] == 0:
          primecounter[k] = 1
        else:
          return False
        while M%p == 0:
          M //= p

  if M > 1:
    if biggerprime[M] == 0:
      biggerprime[M] = 1
    else:
      return False
  return True



g = A[0]
flag = True
for k in range(N):
  a = A[k]
  g = gcd(g, a)
  if flag:
    flag = factorization(a)
  if flag == False:
    if g == 1:
      break


if flag:
  print('pairwise coprime')
  exit()
if g == 1:
  print('setwise coprime')
else:
  print('not coprime')


### FIXED CODE ###

from math import gcd

# = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
mA = max(A)
counter = [0 for _ in range(mA+1)]

primenum = [2]
sgn = [-1 for _ in range(int(mA**0.5)+1)]
k = 3
while k**2 <= mA:
  if sgn[k] == -1:
    primenum.append(k)
    add = k*k
    ok = k
    while ok**2 <= mA:
      sgn[ok] = 1
      ok += add
  k += 2
#prime_num が用意されているとき
def factorization(n):
  M = n
  for p in primenum:
    if p**2 > M:
      break
    else:
      if M%p == 0:
        if counter[p] == 0:
          counter[p] = 1
        else:
          return False
        while M%p == 0:
          M //= p

  if M > 1:
    if counter[M] == 0:
      counter[M] = 1
    else:
      return False
  return True



g = A[0]
flag = True
for k in range(N):
  a = A[k]
  g = gcd(g, a)
  if flag:
    flag = factorization(a)


if flag:
  print('pairwise coprime')
  exit()
if g == 1:
  print('setwise coprime')
else:
  print('not coprime')
### BUGGY CODE ###

from functools import lru_cache
from fractions import gcd
@lru_cache(maxsize=None)
def lcm(x, y):
    return (x // gcd(x, y)) * y
MOD = 10 ** 9 + 7  
n = int(input())
A = list(map(int, input().split()))
A.sort()
l = 1
for i in A:
  l = lcm(l, i)
  
B = [(l // i) % MOD for i in A]

ans = sum(B) % MOD

print(ans)

### FIXED CODE ###

from fractions import gcd

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

MOD = 10 ** 9 + 7  
n = int(input())
A = list(map(int, input().split()))

l = 1
for i in A:
  l = lcm(l, i)
l %= MOD

ans = 0
for i in A:
  ans += l * pow(i, MOD - 2, MOD)
  ans %= MOD
print(ans)
### BUGGY CODE ###

h,w=map(int,input().split())
a=[input() for _ in range(h)]

seen=[[-1]*w for _ in range(h)]
from collections import deque
todo=deque([])
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=='#':
      seen[hi][wi]=0
      todo.append((hi,wi,0))
while len(todo)>0:
  hi,wi,i=todo.popleft()
  if hi>0 and seen[hi-1][wi]==-1:
    todo.append((hi-1,wi,i+1))
    seen[hi-1][wi]=i+1
  if hi<h-1 and seen[hi+1][wi]==-1:
    todo.append((hi+1,wi,i+1))
    seen[hi+1][wi]=i+1
  if wi>0 and seen[hi][wi-1]==-1:
    todo.append((hi,wi-1,i+1))
    seen[hi][wi-1]=i+1
  if wi<w-1 and seen[hi][wi+1]==-1:
    todo.append((hi,wi+1,i+1))
    seen[hi][wi+1]=i+1
print(max([max(seeni) for seeni in seen]))


### FIXED CODE ###

h,w=map(int,input().split())
a=[input() for _ in range(h)]
seen=[[-1]*w for _ in range(h)]
from collections import deque
todo=deque([])
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=='#':
      seen[hi][wi]=0
      todo.append((hi,wi,0))
while len(todo)>0:
  hi,wi,i=todo.popleft()
  if hi>0 and seen[hi-1][wi]==-1:
    todo.append((hi-1,wi,i+1))
    seen[hi-1][wi]=i+1
  if hi<h-1 and seen[hi+1][wi]==-1:
    todo.append((hi+1,wi,i+1))
    seen[hi+1][wi]=i+1
  if wi>0 and seen[hi][wi-1]==-1:
    todo.append((hi,wi-1,i+1))
    seen[hi][wi-1]=i+1
  if wi<w-1 and seen[hi][wi+1]==-1:
    todo.append((hi,wi+1,i+1))
    seen[hi][wi+1]=i+1
print(max([max(seeni) for seeni in seen]))
### BUGGY CODE ###

from functools import lru_cache

n=int(input())
a=[int(i) for i in input().split(" ")]
b=[int(i) for i in input().split(" ")]
c=[int(i) for i in input().split(" ")]
a.sort
b.sort
c.sort

@lru_cache()
def e(x): 
  return len([j for j in c if j>x])
  
n=0
for i in a:
  n+=sum([e(j) for j in b if j>i])
print(n)

### FIXED CODE ###

import bisect

n=int(input())
a=[int(i) for i in input().split(" ")]
b=[int(i) for i in input().split(" ")]
c=[int(i) for i in input().split(" ")]

a.sort()
c.sort()
lc=len(c)
print(sum([(lc-bisect.bisect_right(c,j))*(bisect.bisect_left(a,j)) for j in b]))
### BUGGY CODE ###

import sys
import bisect
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    a.sort()

    cor_v = -1
    inc_v = a[-1] * 2 + 1
    while - cor_v + inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        p = n
        for v in a:
            p = bisect.bisect_left(a, bin_v - v, 0, p)
            cost += n - p
            if cost > m:
                break
        #costが制約を満たすか
        if cost >= m:
            cor_v = bin_v
        else:
            inc_v = bin_v
    acm = [0] + list(itertools.accumulate(a))
    c = 0
    t = 0
    for v in a:
        p = bisect.bisect_left(a, cor_v - v)
        c += n - p
        t += acm[-1] - acm[p] + v * (n - p)
    print(t - (c - m) * cor_v)
    for i in range(10 ** 10):
      t += i


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
import bisect
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    a.sort()
    cor_v = a[0] * 2
    inc_v = a[-1] * 2 + 1
    while - cor_v + inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for i in range(n-1, -1, -1):
            cost += n - bisect.bisect_left(a, bin_v - a[i])
        #costが制約を満たすか
        if cost >= m:
            cor_v = bin_v
        else:
            inc_v = bin_v
    acm = list(itertools.accumulate([0] + a))
    t = 0
    c = 0
    for i in range(n):
        p = bisect.bisect_left(a, cor_v - a[i])
        t += acm[-1] - acm[p] + a[i] * (n - p)
        c += n - p
    print(t - (c - m) * cor_v)


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

n = int(input())
an = list(map(int, input().split()))
check1 = []
check2 = []
ans = 0
for i, a in enumerate(an):
    check1.append(i+a)
    check2.append(i-a)
    ans += check1.count(i-a)
    ans += check2.count(i+a)
print(ans)


### FIXED CODE ###

from collections import defaultdict
N = int(input())
A = [int(n) for n in input().split()]
record = defaultdict(int)
count = 0
for i in range(len(A)):
    cur = i-A[i]
    count += record[cur]
    record[i+A[i]] += 1
print(count)
### BUGGY CODE ###

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

Wlist = [0] 
Elist = [0]

for i in range(N):
    Wlist.append(S.count('W',0,i+1))
    Elist.append(S.count('E',0,i+1))
    
ans = []

for i in range(1,N+1):
    ans.append((Elist[-1] - Elist[i]) + (Wlist[i-1]))
    
print(min(ans))

### FIXED CODE ###

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

Wlist = [0]*(N+1) 
Elist = [0]*(N+1) 

for i in range(1,N+1):
    if S[i-1] == 'W':
        Wlist[i] = Wlist[i-1] + 1
    else:
        Wlist[i] = Wlist[i-1]
        
    if S[i-1] == 'E':
        Elist[i] = Elist[i-1] + 1
    else:
        Elist[i] = Elist[i-1]

ans = []

for i in range(1,N+1):
    ans.append((Elist[-1] - Elist[i]) + (Wlist[i-1]))
    
print(min(ans))
### BUGGY CODE ###

n, k = map(int,input().split())
h = list(map(int,input().split()))
inf = float("inf")
dp = [0]+[inf]*(n-1)

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

print(dp[n-1])    

### FIXED CODE ###

n, k = map(int,input().split())
h = list(map(int,input().split()))
inf = float("inf")
dp = [0]+[inf]*(n-1)

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

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

import math
n = int(input())
a = list(map(int,input().split()))
nans = 0
for i in range(n):
    cnt = a.count(i)
    if cnt >= 2:
        nans += math.factorial(cnt)//(math.factorial(cnt-2)*math.factorial(2))
for i in range(n):
    num = a[i]
    numcnt = a.count(num)
    print(nans-(numcnt-1))

### FIXED CODE ###

import math
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
m = len(set(a))
nans = 0
tbl = list(Counter(a).values())
tbl2 = Counter(a)
for i in range(m):
    if tbl[i] >= 2:
        nans += math.factorial(tbl[i])//(math.factorial(tbl[i]-2)*math.factorial(2))
for i in range(n):
    num = a[i]
    numcnt = tbl2[num]
    print(nans-(numcnt-1))
### BUGGY CODE ###

N,K=map(int,input().split())
a =[0]*N
b =[0]*N
for i in range(0,N):
    a[i],b[i] =map(int,input().split())
a.sort()
c =[]
for i in range(0,N):
    for j in range(0,b[i]):
        c.append(a[i])
print(c[K-1])

### FIXED CODE ###

N,K=map(int,input().split())
a =[0]*N
b =[0]*N
for i in range(0,N):
    a[i],b[i] =map(int,input().split())
c=[0]*(10**6)
for i in range(0,N):
    c[a[i]]=c[a[i]]+b[i]
s=0
i=1
while s<K:
    s=s+c[i]
    x=i
    i=i+1
print(x)
### BUGGY CODE ###

n,c=map(int,input().split())
d=[list(map(int,input().split())) for i in range(c)]
g=[list(map(int,input().split())) for i in range(n)]
mod0=set()
mod1=set()
mod2=set()
for i in range(n):
  for j in range(n):
    if (i+j+2)%3==0:
      mod0.add((i,j))
    elif (i+j+2)%3==1:
      mod1.add((i,j))
    else:
      mod2.add((i,j))
cost1=[0]*c
for c1 in range(c):
  tmp=0
  for y,x in mod0:
    tmp+=d[g[y][x]-1][c1]
  cost1[c1]+=tmp
cost2=[0]*c
for c2 in range(c):
  tmp=0
  for y,x in mod1:
    tmp+=d[g[y][x]-1][c2]
  cost2[c2]+=tmp
cost3=[0]*c
for c3 in range(c):
  tmp=0
  for y,x in mod2:
    tmp+=d[g[y][x]-1][c3]
  cost3[c3]+=tmp
ans=10**18
for c1 in range(c):
  for c2 in range(c):
    for c3 in range(c):
      if c1==c2 or c2==c3 or c3==c1:
        continue
      ans=min(ans,cost1[c1]+cost2[c2]+cost3[c3])
print(ans)

### FIXED CODE ###

import sys
input=sys.stdin.readline
N,C=map(int,input().split())
d=[list(map(int,input().split())) for i in range(C)]
c=[list(map(int,input().split())) for i in range(N)]
ans=10**18
mod0=[]
mod1=[]
mod2=[]
for i in range(N):
  for j in range(N):
    k=(i+j+2)%3
    if k==0:
      mod0.append((i,j))
    elif k==1:
      mod1.append((i,j))
    else:
      mod2.append((i,j))
cnt0=[0]*(C+1)
cnt1=[0]*(C+1)
cnt2=[0]*(C+1)
for c0 in range(1,C+1):
  for x,y in mod0:
    cnt0[c0]+=d[c[x][y]-1][c0-1]
for c1 in range(1,C+1):
  for x,y in mod1:
    cnt1[c1]+=d[c[x][y]-1][c1-1]
for c2 in range(1,C+1):
  for x,y in mod2:
    cnt2[c2]+=d[c[x][y]-1][c2-1]
ans=10**18
for c0 in range(1,C+1):
  for c1 in range(1,C+1):
    for c2 in range(1,C+1):
      if c1==c2 or c2==c0 or c0==c1:
        continue
      cnt=cnt0[c0]+cnt1[c1]+cnt2[c2]
      ans=min(ans,cnt)
print(ans)
### BUGGY CODE ###

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

A_ = A[:]

ans = []

for _ in range(N):
    m = min(A)
    ans.append(A_.index(m) + 1)
    A.remove(m)

ans = list(map(str, ans))

print(" ".join(ans))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = list(range(1, N + 1))

A = dict(zip(A, B))
A = sorted(A.items())
ans = [str(x[1]) for x in A]


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

N, K = map(int, input().rstrip().split())
*h, = map(int, input().rstrip().split())
dp = [float("inf")] * N
dp[0] = 0
for i in range(1, N):
    for j in range(max(0, i-K), i):
        dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
print(dp[-1])

### FIXED CODE ###

import sys
input = sys.stdin.readline
N, K = map(int, input().rstrip().split())
*h, = map(int, input().rstrip().split())
dp = [0] + [float('inf')]*(N-1)
for j in range(1,N):
    for i in range(max(0,j-K),j):
        dp[j] = min(dp[j],dp[i] + abs(h[j]-h[i]))
        # print("j -> {} || i -> {} || dp -> {} || h[j] -> {} || h[i] -> {}".format(j, i, dp, h[j], h[i]))
print(dp[-1])
### BUGGY CODE ###

N, M = map(int, input().split())
_input = []
for i in range(M):
    _input.append(list(map(int,input().split())))

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

removed = []

for a,b in _input:
    flag = False
    for i in removed:
        if a <= i < b:
            flag = True
    if not flag:
        removed.append(b-1)

print(len(removed))

### FIXED CODE ###

N, M = map(int, input().split())
_input = []
for i in range(M):
    _input.append(list(map(int,input().split())))

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

removed = []

for a,b in _input:
    flag = False
    for i in removed:
        if a <= i < b:
            flag = True
            break
    if not flag:
        removed.append(b-1)

print(len(removed))
### BUGGY CODE ###

import itertools
 
s = str(input())
 
n = len(s)
dp = [[0]*13 for i in range(n+1)]
dp[0][0] = 1
      
for i in range(n):
  if s[n-1-i] == '?':
    for k, j in itertools.product(range(10), range(13)):
      x = (j+k*10**i)%13
      dp[i+1][x] += dp[i][j]
  else:
    for j in range(13):
      x = (j+int(s[n-1-i])*10**i)%13
      dp[i+1][x] += dp[i][j]

print(dp[-1][5]%(10**9+7))
#print(dp)

### FIXED CODE ###

import itertools
 
s = str(input())
 
n = len(s)
dp = [[0]*13 for i in range(n+1)]
dp[0][0] = 1

M = 1
INF = 10 ** 9 + 7
      
for i in range(n):
  if s[n-1-i] == '?':
    for k, j in itertools.product(range(10), range(13)):
      x = (j+k*M)%13
      dp[i+1][x] += dp[i][j]
      dp[i+1][x] %= INF
  else:
    for j in range(13):
      x = (j+int(s[n-1-i])*M)%13
      dp[i+1][x] += dp[i][j]
      dp[i+1][x] %= INF
  M = (M*10)%13

print(dp[-1][5])
#print(dp[-1][5]%(10**9+7))
#print(dp)
### BUGGY CODE ###

import math


N, K = map(int, input().split())
h = [int(i) for i in input().split()]
dp = [10**9] * N

dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    for j in range(1, K + 1):
        if i - j < 0:
            break

        if dp[i] > dp[i - j] + abs(h[i] - h[i - j]):
            dp[i] = dp[i - j] + abs(h[i] - h[i - j])

print(dp[-1])


### FIXED CODE ###

import numpy as np


N, K = map(int, input().split())
h = np.array([int(i) for i in input().split()])
dp = np.full(N, 10 ** 10)

# 初期条件
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    ik = max(0, i - K)
    dp[i] = np.min(dp[ik:i] + np.abs(h[i] - h[ik:i]))

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

a,b,k = map(int, input().split())
for i in range(a,b+1):
    if i<a+k or b-k<i:
        print(i)

### FIXED CODE ###

a,b,k = map(int, input().split())
for i in range(a,min(b+1,a+k)):
    print(i)
for i in range(max(b-k+1,(a+k)),b+1):
    print(i)