Harryxun/stf_run huggingface dataset:
n = int(input())
list1 = list(map(int,input().split()))

def count(n, list1):
    num0 = list1.count(0)
    if num0 == 2 or num0 == 3:
        statuslist = []
        answer = 1
        for i in range(len(list1)):
            if list1[i] == 0:
                statuslist.append(0)
            else:
                pos = statuslist.count(list1[i]-1)
                answer *= pos
                statuslist.remove(list1[i]-1)
                statuslist.append(list1[i])
        answer *= 6
        return (answer % 1000000007)
    else:
        return 3
        

print(count(n, list1))

### FIXED CODE ###

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

def count(n, list1):
    num0 = list1.count(0)
    statuslist = []
    answer = 1
    if num0 >= 4:
        return 0
    else:
        for i in range(len(list1)):
            if list1[i] == 0:
                    statuslist.append(0)
            else:
                pos = statuslist.count(list1[i]-1)
                answer *= pos
                try:
                    statuslist.remove(list1[i]-1)
                except ValueError:
                    return answer
                statuslist.append(list1[i])
        if num0 == 2 or num0 == 3:
            answer *= 6
        elif num0 == 1:
            answer *= 3  
        return (answer % 1000000007)
    # else:
    #     return 3
        

print(count(n, list1))
def main():
    N, W = map(int, input().split())
    WV = []
    for _ in range(N):
        w, v = map(int, input().split())
        WV.append((w, v))
    dp = [[0] * (W + 1) for _ in range(N + 1)]
    for i in range(N):
        for j in range(W + 1):
            if j >= WV[i][0]:
                dp[i + 1][j] = max(
                    dp[i][j],
                    dp[i][j - WV[i][0]] + WV[i][1]
                )
            else:
                dp[i + 1][j] = dp[i][j]
    print(dp[-1][-1])


main()


### FIXED CODE ###

def main():
    N, W = map(int, input().split())
    Ws = []
    Vs = []
    for _ in range(N):
        w, v = map(int, input().split())
        Ws.append(w)
        Vs.append(v)
    mv = sum(Vs)
    dp = [[float('INF')] * (mv + 1) for _ in range(N + 1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(mv + 1):
            if Vs[i] > j:
                dp[i + 1][j] = dp[i][j]
            else:
                dp[i + 1][j] = min(dp[i][j], dp[i][j - Vs[i]] + Ws[i])
    ans = 0
    for r in dp:
        for v, w in enumerate(r):
            if W >= w:
                ans = max(ans, v)
    print(ans)


main()
import math
x = int(input())
a = 10*10*10*10*10*10*10*10*10+7
print(math.fanctional(x) % a)

### FIXED CODE ###

import math
x = int(input())
a = 10*10*10*10*10*10*10*10*10+7
print(math.factorial(x) % a)
from sys import stdin
H,N = [int(x) for x in stdin.readline().rstrip().split()]
data = []
ans = 10**9
for i in range(N):
    A,B = [int(x) for x in stdin.readline().rstrip().split()]
    C = A / B
    if A >= H:
        ans = min(ans,B)
    data.append((C,A,B))


dp = [10**9]*(H+1)

c,a,b = sorted(data)[::-1][0]

cnt = 0
for i in range(1,H+1):
    cnt += 1
    if cnt*a >= H:
        dp[-1] = (b*cnt)
        break
    else:
        dp[cnt*a] = (b*cnt)
        

tmp = 10**9
for j in range(H,-1,-1):
    tmp = min(dp[j],tmp)
    dp[j] = tmp

for c,a,b in data:
    dp[-1] = min(dp[-a] + b ,dp[-1])
    
for c,a,b in data:
    dp[-1] = min(dp[-2*a] + (2*b) ,dp[-1])

tmp = 10**9
for j in range(H,-1,-1):
    tmp = min(dp[j],tmp)
    dp[j] = tmp
    
print(min(ans,dp[-1]))

### FIXED CODE ###

# 1-index
from sys import stdin
H, N = [int(x) for x in stdin.readline().rstrip().split()]

data = [0]*N

for i in range(N):
    A, B = [int(x) for x in stdin.readline().rstrip().split()]
    data[i] = (A, B)
dp = [10**9]*(H+1)
dp[0] = 0

for h in range(0,H+1):
    for a,b in data:
        if h+a >= H:
            dp[H] = min(dp[h]+b,dp[H])
        else:
            dp[h+a] = min(dp[h]+b,dp[h+a])
print(dp[H])
import math

n, m = map(int, input().split(" "))

remain = abs(n-m)
if remain <= 1:
	print(math.factorial(n) * math.factorial(m) * (2 if remain==0 else 1)) % (10**9+7))
else:
	print(0)


### FIXED CODE ###

import math

n, m = map(int, input().split(" "))

remain = abs(n-m)
if remain <= 1:
	print((math.factorial(n) * math.factorial(m) * (2 if remain==0 else 1)) % (10**9+7))
else:
	print(0)
from collections import defaultdict
N, M, P = map(int,input().split())
es = []
to = defaultdict(list)
rto = defaultdict(list)
rf = [False]*N
rt = [False]*N
for i in range(M):
  a, b, c = map(int, input().split())
  es += [(a-1,b-1,-c+P)]
  to[a-1] += [b-1]
  rto[b-1] += [a-1]

def dfs(v):
  if rf[v]:
    return
  rf[v] = True
  for u in to[v]:
    dfs(u)

def rdfs(v):
  if rt[v]:
    return
  rt[v] = True
  for u in rto[v]:
    rdfs(u)

dfs(0)
rdfs(N-1)
ok = [False]*N
for i in range(N):
  ok[i] = rf[i]&rt[i]

dist = [float('inf')]*N
dist[0] = 0
upd = True
cnt = 0
while upd:
  upd = False
  for j in range(M):
    f, t, c = es[j]
    if (not ok[f]) or (not ok[t]):
      continue
    if dist[t]>dist[f]+c:
      upd = True
      dist[t] = dist[f]+c
  cnt += 1
  if cnt>N:
    print(-1)
    break
else:
  print(max(0,-dist[N-1]))

### FIXED CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)
N, M, P = map(int,input().split())
es = []
to = defaultdict(list)
rto = defaultdict(list)
rf = [False]*N
rt = [False]*N
for i in range(M):
  a, b, c = map(int, input().split())
  es += [(a-1,b-1,-c+P)]
  to[a-1] += [b-1]
  rto[b-1] += [a-1]

def dfs(v):
  if rf[v]:
    return
  rf[v] = True
  for u in to[v]:
    dfs(u)

def rdfs(v):
  if rt[v]:
    return
  rt[v] = True
  for u in rto[v]:
    rdfs(u)

dfs(0)
rdfs(N-1)
ok = [False]*N
for i in range(N):
  ok[i] = rf[i]&rt[i]

dist = [float('inf')]*N
dist[0] = 0
upd = True
cnt = 0
while upd:
  upd = False
  for j in range(M):
    f, t, c = es[j]
    if (not ok[f]) or (not ok[t]):
      continue
    if dist[t]>dist[f]+c:
      upd = True
      dist[t] = dist[f]+c
  cnt += 1
  if cnt>N:
    print(-1)
    break
else:
  print(max(0,-dist[N-1]))
import copy
import bisect
import math

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

s = [a[0]]
for i in range(1, N):
    s.append(s[i-1] + a[i])
ps = copy.copy(s)
for i in range(N):
    ps = [ps[j] - ps[0] for j in range(1, N-i)]
    s += ps

ans = 0
s.sort()

while s[-1] != 0:
    n = int(math.log2(s[-1]))
    i = bisect.bisect_left(s, 2**n)
    update = False
    while len(s) - i < K - 1:
        n -= 1
        i = bisect.bisect_left(s, 2**n)
        update = True
    if not update:
        if len(s) - i == K - 1:
            temp = s[-1]
            for i in range(1, K):
                temp &= s[-i-1]
            print(ans + temp)
            exit()
        else:
            ans += 2**n
            s = [x & (2**n-1) for x in s[i:]]
    else:
        s = [x & (2**n-1) for x in s]
    s.sort()
print(ans)

### FIXED CODE ###

import copy
import bisect
import math

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

s = [a[0]]
for i in range(1, N):
    s.append(s[i-1] + a[i])
ps = copy.copy(s)
for i in range(N):
    ps = [ps[j] - ps[0] for j in range(1, N-i)]
    s += ps

ans = 0
s.sort()

while s[-1] != 0:
    n = int(math.log2(s[-1]))
    ind = bisect.bisect_left(s, 2**n)
    if len(s) - ind == K:
        temp = s[-1]
        for i in range(1, K):
            temp &= s[-i-1]
        print(ans + temp)
        exit()
    elif len(s) - ind > K:
        ans += 2**n
        s = [x & (2**n-1) for x in s[ind:]]
    else:
        s = [x & (2**n-1) for x in s]
    s.sort()
print(ans)
a, b = map(int, input().stirp().split())
print((a + b + 2 -1) // 2)

### FIXED CODE ###

a, b = map(int, input().strip().split())
print((a + b + 2 -1) // 2)
W = input()
print(W)
t=0

while(1):
	char_list = list(x.lower() for x in input().split())
	#print(char_list)
	if char_list[0] == 'END_OF_TEXT':
		break
	
	for i in range(len(char_list)):
		if W == char_list[i]:
			t += 1

print(t)

### FIXED CODE ###

W = input().lower()
#print(W)
t=0

while(1):
	char_list = list(x for x in input().split())
	#print(char_list)
	if char_list[0] == 'END_OF_TEXT':
		break
	
	for i in range(len(char_list)):
		if W == char_list[i].lower():
			t += 1

print(t)
black = 1
count = 0
flag = False
def check(board, now):
    global flag, count
    if now[0] > len(board) -2 or board[now[0]+1][now[1]]==black:
        if now[1] > len(board[0]) -2 or board[now[0]][now[1]+1]==black:
            if flag == False:
                count += 1
                flag = True
            if now[1] < len(board[0]) -1:
                return [now[0], now[1]+1]
            elif now[0] < len(board) -1:
                return [now[0]+1, now[1]]
        else:
            flag = False
            return [now[0], now[1]+1]
    else:
        flag = False
        return [now[0]+1, now[1]]
def main():
    global count, flag
    H, W = map(int, input().split())
    board = [[white for i in range(W)] for j in range(H)]
    for i in range(H):
        s = input()
        for j in range(W):
            if s[j] == ".":
                board[i][j] = white
            else:
                board[i][j] = black
    if board[0][0] == black:
        count += 1
        flag = True
    now = [0, 0]
    while now != [H-1, W-1]:
        now = check(board, now)
    print(count)
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
def main():
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]
    dp = [[10**5] * w for _ in range(h)]
    def func(temp, now, flag):
        x, y = now
        if y > h - 1 or x > w - 1:
            return 10**6
        if s[y][x] == "#":
            if not flag:
                temp += 1
            flag = True
        else:
            flag = False
        if x == w-1 and y == h-1:
            return temp
        if dp[y][x] <= temp:
            return 10**6
        dp[y][x] = temp
        piyo = []
        return min(func(temp, (x + 1, y), flag), func(temp, (x, y + 1), flag))
    print(func(0, (0, 0), False))
main()
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
    A = list(map(int,input().split()))
    for j in range(len(m)):
        ans = A_i[j]*b[j] + c
    if ans > 0:
        tmp += 1
print(tmp)


### FIXED CODE ###

n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
    A = list(map(int,input().split()))
    ans = 0
    for j in range(m):
        ans += A[j]*b[j]
    ans = ans + c
    if ans > 0:
        count+= 1
print(count)
S = str(input())

if len(S) == 2:
    print(S)
    
else:
    print(''.join(A))

### FIXED CODE ###

S = str(input())

if len(S) == 2:
    print(S)
    
else:
    A = list(reversed(S))
    print(''.join(A))
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)

nums = {}
nums[1] = 2
nums[2] = 5
nums[3] = 5
nums[4] = 4
nums[5] = 5
nums[6] = 6
nums[7] = 3
nums[8] = 7
nums[9] = 6

dp = [0]*(N+1)

for i in range(1, N+1):
    make = True
    for a in A:
        if i-nums[a] >= 0:
            dp[i] = max(dp[i], dp[i-nums[a]]+1)
            make = False
    if make:
        dp[i] = -float('inf')

ans = ""
i = N
while i > 0:
    for a in A:
        if dp[i]-1 == dp[i-nums[a]]:
            ans += str(a)
            i = i-nums[a]
            break
print(ans)


### FIXED CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)

nums = {}
nums[1] = 2
nums[2] = 5
nums[3] = 5
nums[4] = 4
nums[5] = 5
nums[6] = 6
nums[7] = 3
nums[8] = 7
nums[9] = 6

dp = [-float('inf')]*(N+1)
dp[0] = 0

for i in range(N+1):
    for a in A:
        if i-nums[a] >= 0:
            dp[i] = max(dp[i], dp[i-nums[a]]+1)

ans = ""
i = N
while i > 0:
    for a in A:
        if i >= nums[a] and dp[i]-1 == dp[i-nums[a]]:
            ans += str(a)
            i = i-nums[a]
            break
print(ans)
#include <bits/stdc++.h>
using namespace std;

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}
int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    vector<int> nums(N);
    int a=0,b=0,j=0;
    for(int i=0;i<N;i++) {
        cin >> P.at(i);
    }
    for(int i=0;i<N;i++) {
        cin >> Q.at(i);
    }
    for(int i=0;i<N;i++) {
        nums.at(i) = i+1;
    }
    do{
        j++;
        if(nums == P) {
            a = j;
        }
        if(nums == Q) {
            b = j;
        }
    }while(next_permutation(nums.begin(), nums.end()));
    cout << abs(b-a) << endl;
}

### FIXED CODE ###

import itertools

N = int(input())
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]

a = 0
b = 0
j = 0
for i in itertools.permutations([int(x+1) for x in range(N)]):
    j += 1
    if(list(i) == P) :
        a = j
    if(list(i) == Q) :
        b = j

print(abs(a-b))
a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)

X.sort()
flag =1
n = 0
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += flag*(flag-1)//2
    flag = 1
    



### FIXED CODE ###

S = str(input())

#10**nのmod計算
A = []
p =1
for i in range(len(S)):
  A.append(p)
  p = p*10%2019

#左からi文字以降の数字列のmod計算
X = []
a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)
X.sort()
flag =1
n = 0

#modが同じになる組み合わせ、またはもともとmodが0になる数字列の個数の総和計算
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += int(flag*(flag-1)/2)
    flag = 1
n += int(flag*(flag-1)/2)
if X[len(X)-1]==0:
  n +=1
print(n)
n, m = map(int, input().split())
l = list(map(int,input().split()))
l = sorted(l)[::-1]
check = l[m - 1] > (sum(l) / 4 / m)
print("Yes" if check else "No")

### FIXED CODE ###

a, b, c = map(int, input().split())
print(c,a,b)
n = int(input())
p = [1] * n
q = [1] * n
r = [0] * n
for i in range(n):
  p[i] = i + 1
  q[i] = p[i] + 1
  r[i] = p[i] % q[i]
r[-1] = 0
print(sum(r))

### FIXED CODE ###

n = int(input())
print(n * (n - 1) // 2)
'''
ITP-1_3-C
 2 ????????°?????????
???????????´??° x, y ?????????????????????????????????????°?????????????????????????????????°?????????????????????????????????
?????????????????????????????\?????????????????????????????????????????????????????????????????????????????¨?????¨?????????????????????
???Input
??\???????????°????????????????????????????§?????????????????????????????????????????????????????????§??????????????????????????´??° x, y ?????????
?????????????§?????????????????????????
???Output
??????????????????????????¨??????x ??¨ y ????°????????????????????????????????????????????????????????????????x ??¨ y ????????????????????????????????\??????????????????
'''
# import
import sys

# input???????????????
for inputData in sys.stdin:
    inputData = inputData.split(" ")
    inputData01, inputData02 = int(inputData[0]), int(inputData[1])
    # 0?????´??? ????????????
    if inputData01 == 0:
        if inputData02 == 0:
            break

    if inputData01 > inputData02:
        outputData01 = inputData02
        outputData02 = inputData01
    elif inputData01 < inputData02:
        outputData01 = inputData01
        outputData02 = inputData02

    # ????????????
    print((outputData01),(outputData02)))

### FIXED CODE ###

'''
ITP-1_3-C
 2 ????????°?????????
???????????´??° x, y ?????????????????????????????????????°?????????????????????????????????°?????????????????????????????????
?????????????????????????????\?????????????????????????????????????????????????????????????????????????????¨?????¨?????????????????????
???Input
??\???????????°????????????????????????????§?????????????????????????????????????????????????????????§??????????????????????????´??° x, y ?????????
?????????????§?????????????????????????
???Output
??????????????????????????¨??????x ??¨ y ????°????????????????????????????????????????????????????????????????x ??¨ y ????????????????????????????????\??????????????????
'''
# import
import sys

# input???????????????
for inputData in sys.stdin:
    inputData = inputData.split(" ")
    inputData01, inputData02 = int(inputData[0]), int(inputData[1])
    # 0?????´??? ????????????
    if inputData01 == 0:
        if inputData02 == 0:
            break

    if inputData01 > inputData02:
        outputData01 = inputData02
        outputData02 = inputData01
    else:
        outputData01 = inputData01
        outputData02 = inputData02

    # ????????????
    print((outputData01), (outputData02))
import sys
from io import StringIO
import unittest
import os
import bisect
import numpy

### FIXED CODE ###

import sys
from io import StringIO
import unittest
import os
import bisect

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


def cumsum(target: []):
    result = []
    for cnt, a in enumerate(target):
        result.append(a) if cnt == 0 else result.append(result[cnt - 1] + a)
    return result


# 実装を行う関数
def resolve(test_def_name=""):
    n, m, k = map(int, input().split())
    a_s = list(map(int, input().split()))
    b_s = list(map(int, input().split()))

    sum_a_s = [0] + cumsum(a_s)
    sum_b_s = [0] + cumsum(b_s)

    # k=100として AをX冊読んだ場合の残時間のリストを作る。
    # つまり・・0=100 1=80 2=40 という感じ。
    remain_time_s = []
    for sum_a in sum_a_s:
        if sum_a > k:
            break
        remain_time_s.append(k - sum_a)

    ans = 0
    b_start = 0
    sum_b_s_rev = list(reversed(list(enumerate(sum_b_s))))

    # 最適解を求める。
    for cnt_a, remain_time in enumerate(remain_time_s):
        # Bは逆から見ていく。
        for i in range(b_start, len(sum_b_s_rev)):
            if sum_b_s_rev[i][1] > remain_time:
                b_start += 1
                continue
            ans = max(ans, cnt_a + sum_b_s_rev[i][0])
            break

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3 4 240
60 90 120
80 150 80 150"""
        output = """3"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3 4 730
60 90 120
80 150 80 150"""
        output = """7"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000"""
        output = """0"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def test_origin_1(self):
        test_input = """2 3 100
90 10
10 10 10"""
        output = """3"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()
str = [int(input()) for i in range(3)]
input_sum = sum(str)
if input_sum >= 22:
    print("true")
else:
    print("win")


### FIXED CODE ###

str = [int(i) for i in input().split(" ")]
input_sum = sum(str)
if input_sum >= 22:
    print("bust")
else:
    print("win")
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a = Counter(a)
b = []
for i,j in a:
    if j >=4:
        b.append(i)
        b.append(i)
    elif j >= 2:
        b.append(i)
b.sort()
if len(b)>=2:
    print(b[-1]*b[-2])
else:
    print(0)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a = Counter(a).most_common()
b = []
for i,j in a:
    if j >=4:
        b.append(i)
        b.append(i)
    elif j >= 2:
        b.append(i)
b.sort()
if len(b)>=2:
    print(b[-1]*b[-2])
else:
    print(0)
a,b,c=map(int,input.split());print(["No","Yes"][(a==b+c or b==a+c or c==a+b)])

### FIXED CODE ###

a,b,c=map(int,input().split());print(["No","Yes"][(a+b==c)+(b+c==a)+(c+a==b)])
import numpy as np

# N = 3
# M = 7
# x_list = sorted([-10, -3, 0, 9, -100, 2, 17])

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


def rl_dist(x_point):

    p_num = len(x_point)
    d_list = []
    d_dict = {}
    for num, (a, b) in enumerate(zip(x_point, x_point[1:])):
        d = (b-a)
        if x_point[num] not in d_dict.keys():
            d_dict[x_point[num]] = [d]
            if num==0:
                d_dict[x_point[num]] = np.mean(d_dict[x_point[num]])
        else:
            d_dict[x_point[num]].append(d)
            
            if len(d_dict[x_point[num]])==2:
                d_dict[x_point[num]] = np.mean(d_dict[x_point[num]])
                
            
        if x_point[num+1] not in d_dict.keys():
            d_dict[x_point[num+1]] = [d]
            
            if num+1==p_num-1:
                d_dict[x_point[num+1]] = np.mean(d_dict[x_point[num+1]])
                
    return d_dict
            
    
rl_dict = rl_dist(x_list)
        
first_set = list(set([p[0] for p in sorted(rl_dict.items(), key=lambda x: x[1])[-1*N:] ]))
print(first_set)

rem = list(set(x_list) - set(first_set))
print(rem)

cost = 0

while len(rem)>0:
    d_list = []
    best = 10**5
    best_list = []
    
    if cost==0:
        candidate = first_set
    else:
        candidate = [new_set]
    
    for fp in list(candidate):
        for r in rem:
            d = abs(fp-r)
            if d<best:
                best = d
                best_list = [fp, r]
    
    print(best, best_list)
    cost += best
    
    new_set = best_list[1]
    rem = set(rem) - set([new_set])
print(cost)

### FIXED CODE ###

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

if N>=M:
    print(0)
else: 
    dist = [b-a for a, b  in zip(X, X[1:])]
    dist.sort()
    print(sum(dist[:M-N]))
s=input()
if A,B in s:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s=input()
if 'A' in s and 'B' in s:
  print('Yes')
else:
  print('No')
import collections
N = int(input())
A = list(map(int , input().split()))
a = collections.Counter(A)
for i in range(N):
    K =[]
    K.extend(A)
    K.pop(i)
    a = collections.Counter(K)
    S = len(list(set(K)))
    k = 0
    for j in range (S):
        b =a.most_common()[j][1]
        k = b * (b-1)/2 + k
    print(int(k))
    K.clear()
    K.extend(A)

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int , input().split()))
a = collections.Counter(A)
k = 0
def comb(n):
    return n * (n - 1) // 2
for j in a.values():
    k += comb(j)
    
for i in range(N):
    s = A[i]
    p = a[s]
    print(int(k - p + 1))
S = input()
abs = 1000
for i in range(len(S)-2):
    abs = min(abs, abs(753-S[i:i+3]))
print(abs)


### FIXED CODE ###

S = input()
diff = 1000
for i in range(len(S)-2):
    S_int = int(S[i:i+3])
    diff = min(diff, abs(753-S_int))
print(diff)
s=list(input())
count=0

indexes = [i for i, x in enumerate(s) if x == "B"]
if len(s)%2==1:
  ideal=[i for i in range(len(s)//2+1,len(s))]
else:
  ideal=[i for i in range(len(s)//2,len(s))]

for i in range(len(s)//2):
  count+= ideal[i]-indexes[i]
print(count)

### FIXED CODE ###

s=list(input())
count=0
# print('lens',len(s))
indexes = [i for i, x in enumerate(s) if x == "B"]
ideal=sorted([len(s)-i-1 for i in range(len(indexes))])
# print(indexes)
# print(ideal)
for i in range(len(indexes)):
  count+=ideal[i]-indexes[i]

print(count)
n=int(input())
i=0
while True:
    i+=1
    if (26**i-1)/25*26>=n:
        n-=(26**i-1)/25*26
        break
def sisu(n, b):
　if (int(n/b)):
　　return sisu(int(n/b), b) + chr(n%b+65)
　return chr(n%b+65)
aa=sisu(n,26)
aa="a"*(i-len(aa))+aa
print(aa)

### FIXED CODE ###

n=int(input())
a=''
while n != 0:
  n-=1
  a=chr(int(97+n%26))+a
  n//=26
print(a)