Harryxun/stf_run huggingface dataset:
import sys
readline = sys.stdin.readline
from math import log2
N, M = map(int, readline().split())
A = [list(map(int, readline().split())) for i in range(N)]
B = max(max(Ai) for Ai in A)
if M == 1:
    if N == 1 or all(A[i][0] < A[i+1][0] for i in range(N-1)):
        print("0")
    else:
        print("-1")
    exit(0)
logB = log2(B)
logBi = int(logB)
INF = 10**18
def gen(P, t):
    if t <= logB:
        for k in range(t):
            for i in range(M-1):
                P[i+1] += P[i]
    else:
        for k in range(t):
            for i in range(min(logBi+2, M-1)):
                P[i+1] += P[i]
        for i in range(logBi+2, M):
            P[i] = INF
T = [0]*N
ans = 0
P = [0]*M
for i in range(N-1):
    a0, a1 = A[i][:2]
    b0, b1 = A[i+1][:2]
    if a0 < b0:
        continue
    if a0 > b0:
        ans = -1
        break
    t0 = T[i]
    v = max(t0*a0 + a1 - b1, 0)
    if v % b0 > 0:
        T[i+1] = t1 = (v + b0-1) // b0
        ans += t1
        continue

    t1 = v // b0
    if t0 <= t1:
        P[:] = A[i+1]
        gen(P, t1 - t0)
        if P <= A[i]:
            t1 += 1
    else:
        P[:] = A[i]
        gen(P, t0 - t1)
        if A[i+1] <= P:
            t1 += 1
    T[i+1] = t1
    ans += t1
print(ans)

### FIXED CODE ###

import sys
readline = sys.stdin.readline
from math import log2
from itertools import accumulate
N, M = map(int, readline().split())
A = [list(map(int, readline().split())) for i in range(N)]
B = max(max(Ai) for Ai in A)
if M == 1:
    if N == 1 or all(A[i][0] < A[i+1][0] for i in range(N-1)):
        print("0")
    else:
        print("-1")
    exit(0)
logB = log2(B)
logBi = int(logB)
INF = 10**18
INFL = [INF]*(M - logBi-2)
def gen(P, t, L = min(logBi+2, M)):
    if t <= logB:
        for k in range(t):
            P[:] = accumulate(P)
    else:
        V = [1]*L
        for k in range(1, L):
            V[k] = V[k-1] * (t + k - 1)//k

        for i in range(L-1, 0, -1):
            P[i] += sum(P[j] * V[i-j] for j in range(i))
        if logBi+2 < M:
            P[logBi+2:] = INFL
T = [0]*N
ans = 0
P = [0]*M
for i in range(N-1):
    a0, a1 = A[i][:2]
    b0, b1 = A[i+1][:2]
    if a0 < b0:
        continue
    if a0 > b0:
        ans = -1
        break
    t0 = T[i]
    v = max(t0*a0 + a1 - b1, 0)
    if v % b0 > 0:
        T[i+1] = t1 = (v + b0-1) // b0
        ans += t1
        continue

    t1 = v // b0
    if t0 <= t1:
        P[:] = A[i+1]
        gen(P, t1 - t0)
        if P <= A[i]:
            t1 += 1
    else:
        P[:] = A[i]
        gen(P, t0 - t1)
        if A[i+1] <= P:
            t1 += 1
    T[i+1] = t1
    ans += t1
print(ans)
H,W = map(int(x) for x in raw_input().split(""))
for height in range(H):
    if H == W == 0:
        break
    elif height == H-1 or height == 0:
        print "#"*W
    else:
        print "#"+ "."*(W-2)+"#"
print ""

### FIXED CODE ###

while True:
    h,w = tuple([int(x) for x in raw_input().split(" ")])
    if h==0 and w==0: break
 
    for ih in range(h):
        if ih==0 or ih==h-1 or w <= 2: print "#" * w
        else: print "#" + "." * (w-2) + "#"
 
    print ""
N = input()
S = input()
count = 0
for i in range(1,int(N)-1):
  if S[i-1] + S[i] + S[i+1] = "ABC":
    count = count + 1
print(count)

### FIXED CODE ###

N = int(input())
S = input()
print(S.count("ABC"))
if __name__ == "__main__":
    N = input()
    res = 0
    for x in range(N):
        a,b = map(int, input().split())
        res += b - a + 1
    print (res)


### FIXED CODE ###

if __name__ == "__main__":
    N = int(input())
    res = 0
    for x in range(N):
        a,b = map(int, input().split())
        res += b - a + 1
    print (res)
a,b=map(int, input().split())
total=500*a
if total=>X:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a,b=map(int, input().split())
total=500*a
if total>=b:
  print("Yes")
else:
  print("No")
import decimal
a,b = map(decimal,input().split())
print(int(a*b))

### FIXED CODE ###

import decimal
a,b = map(decimal.Decimal,input().split())
print(int(a*b))
import sys
import heapq
sys.setrecursionlimit(200000)
o=lambda:map(int,raw_input().split())
n=int(raw_input())
e=[[] for _ in range(n+1)]
for _ in range(n-1):
    a,b=o()
    e[a]+=[(b,1)];e[b]+=[(a,1)]
k=int(raw_input())
for _ in range(k):
    v,p=o()
    e[v]+=[(0,p)];e[0]+=[(v,p)]
vis=[False]*n
q=[(0,0)]
heapq.heapify(q)
while len(q):
    c,v=heapq.heappop(q)
    vis[v]=True
    cost[v]=c
    for (w,d) in e[v]:
        if not vis[w]:q+=[(c+d,w)]
for i in range(n):
    for w,d in e[i]:
        if abs(cost[i]-cost[w])!=1:print 'No';sys.exit()
print 'Yes'
for i in range(n):print cost[i]
        


### FIXED CODE ###

import sys
import heapq
o=lambda:map(int,raw_input().split())
n=int(raw_input())
e=[[] for _ in range(n+1)]
for _ in range(n-1):a,b=o();e[a]+=[(b,1)];e[b]+=[(a,1)]
k=int(raw_input())
for _ in range(k):v,p=o();e[v]+=[(0,p)];e[0]+=[(v,p)]
vis=[False]*(n+1)
cost=[10**9]*(n+1)
q=[(0,0)]
heapq.heapify(q)
while len(q):
    c,v=heapq.heappop(q)
    vis[v]=True
    cost[v]=c
    for (w,d) in e[v]:
        if not vis[w] and c+d<cost[w]:
            heapq.heappush(q,(c+d,w))
            cost[w]=c+d
for i in range(1,n+1):
    for w,d in e[i]:
        if w!=0 and abs(cost[i]-cost[w])!=1:print 'No';sys.exit()
print 'Yes'
for i in range(n):print cost[i+1]
N = int(input())
hist = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0 }
for i in range(N):
  tc = input()
    hist[tc] += 1

for k in ['AC', 'WA', 'TLE', 'RE']:
  print(f'{k} x {hist[k]}', flush=True)



### FIXED CODE ###

N = int(input())
hist = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0 }
for i in range(N):
  tc = input()
  hist[tc] += 1

for k in ['AC', 'WA', 'TLE', 'RE']:
  print(f'{k} x {hist[k]}', flush=True)
N,X = map(int, input().split())


def para(a,b):
    if  b == 0:
        return a
    if a >= b:
        return a+b + para(b,a-b)
    if a < b:
        return 2*a + para(a,b-a)

print(X+para(X,N-X))

### FIXED CODE ###

N,X = map(int,input().split(" "))
 
Y,X = sorted([N - X,X])
 
s = 0
while Y:
    s += (X//Y)*Y*3
    Y,X = [X%Y,Y]
 
print(s)
n,k=map(int,input().split())
sum=k
tmp=k
for i in range(1,n):
  sum+=k+i
  if abs(tmp)>abs(k+i):
    tmp=k+i
print(sumtmp)

### FIXED CODE ###

n,k=map(int,input().split())
sum=k
tmp=k
for i in range(1,n):
  sum+=k+i
  if abs(tmp)>abs(k+i):
    tmp=k+i
print(sum-tmp)
# -*- coding: utf-8 -*-
# AtCoder Beginner Contest 125
# C - GCD on Blackboard

# N-1個の全パターンの最大公約数の最大値でOK

# 最大公約数を計算
# ユークリッドの互除法を用いる
def gcd(x, y):
    # 大きい方をaに
    a, b = (x,y) if x>y else (y,x)
    if a == b:
        return a
    else:
        return gcd(a-b,b)

# N個の整数に対する最大公約数の計算
def calc(n, an):
    if n == 2:
        return gcd(an[0], an[1])
    else:
        return gcd(an[0], calc(n-1, an[1:]))


n = int(input())
an = [int(x) for x in input().split(' ')]

if n == 2:
    print(max(an))
else:
    #N-1個の組み合わせに対する最大公約数で最大のものを選ぶ
    # N-1個の組み合わせ
    bn = [[j for j in an if i != j] for i in an]
    if len(bn) == 0:
        print(an[0])
    else:
        gcds = [calc(n-1, ary) for ary in bn]
        print(max(gcds))

### FIXED CODE ###

hoge = input()

a, b, t = [int(x) for x in hoge.split(' ')]

print(int(((t+0.5)//a)*b))
import sys


class RangeUpdateTree:
    def __init__(self, n, initial=-1, sentinel=-2):
        n2 = 1 << n.bit_length()
        self.n = n2
        self.offset = n2
        self.data = [initial] * (n2 << 1)
        self.sentinel = sentinel

    def update(self, a, b, x):
        stack = [(1, 0, self.n)]
        while stack:
            i, l, r = stack.pop()
            if a <= l and r <= b:
                self.data[i] = x
                continue
            y = self.data[i]
            j = i << 1
            if y != self.sentinel:
                self.data[i] = self.sentinel
                self.data[j] = self.data[j + 1] = y
            m = (l + r) // 2
            if a < m:
                stack.append((j, l, m))
            if m < b:
                stack.append((j + 1, m, r))

    def aggregate(self):
        stack = [1]
        ans = 0
        while stack:
            i = stack.pop()
            if self.data[i] != self.sentinel:
                ans += self.data[i] * (self.n >> i.bit_length() - 1)
                continue
            i <<= 1
            stack.append(i)
            stack.append(i + 1)
        return ans

    def debug_print(self):
        i = 1
        while i <= self.offset:
            print(self.data[i:2 * i])
            i <<= 1


n, q = list(map(int, input().split()))
lines = sys.stdin.readlines()
kkk = []
for line in lines[:n]:
    s, t, x = list(map(int, line.split()))
    kkk.append((x, s, t))
kkk.sort(reverse=True)
ddd = [int(line) for line in lines[n:]]
max_d = ddd[-1]
rut = RangeUpdateTree(max_d + 1)
for x, s, t in kkk:
    ss = max(0, s - x)
    tt = min(max_d + 1, t - x)
    rut.update(ss, tt, x)
data = rut.data[rut.offset:]
print('\n'.join(map(str, (data[d] for d in ddd))))


### FIXED CODE ###

import sys
from bisect import bisect_left

n, q = map(int, input().split())
lines = sys.stdin.readlines()
kkk = []
for line in lines[:n]:
    s, t, x = map(int, line.split())
    kkk.append((x, s, t))
kkk.sort()
ddd = list(map(int, lines[n:]))

ans = [-1] * q
skip = [-1] * q
for x, s, t in kkk:
    ss = bisect_left(ddd, s - x)
    tt = bisect_left(ddd, t - x)
    while ss < tt:
        if skip[ss] == -1:
            ans[ss] = x
            skip[ss] = tt
            ss += 1
        else:
            ss = skip[ss]
print('\n'.join(map(str, ans)))
N = int(input())
S = input()

print('Yes') if S[:len(S)/2] == S[len(S)/2:] else print('No')


### FIXED CODE ###

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

print('Yes') if S[:len(S)//2] == S[len(S)//2:] else print('No')
n=int(input())
temp=list(map(int,input().rstrip().split()))
a=temp[0]
b=temp[2]
if (b-a)>n :
    print("OK")
elif n==1 :
  print("OK")
else :
    print("NG")

### FIXED CODE ###

n=int(input())
temp=list(map(int,input().rstrip().split()))
a=temp[0]
b=temp[1]
rem=(a%n)
left=n-rem
if b>=(left+a) :
    print("OK")
elif a%n ==0 or b%n==0:
    print("OK")
else :
    print("NG")
a = input()
b = input()

l = [1,2,3]

l.remove(a)
l.remove(b)

print(l)


### FIXED CODE ###

a = int(input())
b = int(input())
l = [1,2,3]
l.remove(a)
l.remove(b)
print(''.join(map(str,l)))
def f(d,x,y):n=int("9"*x+"0"*y);return d==0if x<1else sum(f(d+i*n,x-2,y+1)*(10-abs(i)-(y<1))for i in range(-9,10)if abs(d+i*n)<n)
D=input();print sum(f(D,i,0)*(10-i%2*9)for i in range(1,21))

### FIXED CODE ###

import itertools as ite
import math
import random

INF = 10 ** 18
MOD = 10 ** 9 + 7

def func(diff, cnt9, cnt0):
    if cnt9 <= 0:
        return (diff == 0)
    num = int("9" * cnt9 + "0" * cnt0)
    ret = 0
    for i in range(-9, 10):
        if abs(diff + i * num) < num:
            MUL = 9 - abs(i) + 1
            MUL -= (cnt0 == 0)
            ret += func(diff + i * num, cnt9 - 2, cnt0 + 1) * MUL
    return ret

D = input()

ans = 0
for d in range(1, 21):
    MUL = 1 if d % 2 == 1 else 10
    ans += func(D, d, 0) * MUL
print ans
a=list(map(int,input().split()))
b=a.sorted()
print(b[0]+b[1])

### FIXED CODE ###

a=list(map(int,input().split()))
b=sorted(a)
print(int(b[0])+int(b[1]))
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())
    print(-1)
    xy = [list(map(int,input().split())) for i in range(N)]
    print(-1)

    xy = np.array(xy)
    # print(xy)

    diffs = xy - xy.T
    print(-1)
    md = np.sum(np.abs(diffs),axis=-1)
    res = md.max()

    # print(diffs)
    # print(md)

    print(res)



main()


### FIXED CODE ###

import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())
    xy = [list(map(int,input().split())) for i in range(N)]

    z_max = 0
    z_min = 2 * 10 **9

    w_max = - 10 ** 9
    w_min = 10 ** 9

    for i in range(N):
        z = xy[i][0] + xy[i][1]
        w = xy[i][0] - xy[i][1]
        z_max = max(z_max,z)
        z_min = min(z_min,z)
        w_max = max(w_max,w)
        w_min = min(w_min,w)

    res = max(z_max-z_min,w_max-w_min)

    print(res)



main()
while 1:
    a, b = map(int, input().split())
    for i in a:
        for j in b:
            p+="#"
        print(p)


### FIXED CODE ###

while True:
    a, b = map(int, input().split())
    if a == 0: break
    for i in range(a):
        print("#"*b)
    print()
import sys
import math

N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))

_min, _max = -math.inf, math.inf
for i in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    _min = max(_min, L)
    _max = min(_max, R)
print(_max - _min + 1)


### FIXED CODE ###

import sys

N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))

_min, _max = 1, 100000
for _ in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    _min = max(_min, L)
    _max = min(_max, R)
if _min > _max:
    print(0)
else:
    print(_max - _min + 1)
s = input()
s = set(list(s))
if s in "N" != s in "S":
    print("No")
    exit()
if s in "W" != s in "E":
    print("No")
    exit()
print("Yes")

### FIXED CODE ###

s = input()
s = set(list(s))
if ("N" in s) != ("S" in s):
    print("No")
    exit()
if ("E" in s) != ("W" in s):
    print("No")
    exit()
print("Yes")
a,b,c,d,e,f=map(int,input().split())

rmax=0
for a100 in range(0,f+1,100*a):
#    for b100 in range(0,f-a100+1,100):
    for b100 in range(0,f+1,100*b):
        if a100+b100>0:
            fcd=f-a100-b100
            for ci in range(0,fcd+1,c):
                for di in range(0,fcd+1,d):
                    if a100+b100+ci+di <=f:
                        if (a100+b100)//100*e>=ci+di:
                            if rmax<(ci+di)/(a100+b100):
                                rmax=(ci+di)/(a100+b100)
                                rab=a100+b100+ci+di
                                rcd=ci+di
print(rab,rcd)
                

### FIXED CODE ###

a,b,c,d,e,f=map(int, input().split())

indxmax=0.0
wmax=0
emax=0
elimit=(100*e)/(100+e)
c31=int(f/c)+1
for ai in range(0,f+1,a):
    for bi in range(0,f-ai+1,b):
        w=100*ai+100*bi
#        print("a,b:",ai,bi,w)
        if w<=f and w>0:
#            c31=int(w/100*e/c)+1
#            c31=min(int(w/100*e/c)+1,31)
#            d31=int(w/100*e/d)+1
            c31=(w*e)//100+c
            for ci in range(0,c31,c):
#                for di in range(d31):
                for di in range(0,c31-ci,d):
                    indx=(ci+di)*100/w
                    if indxmax<indx and e-indx>=0.0 and w+ci+di<=f:
                        wmax=w+ci+di
                        indxmax=indx 
                        emax=ci+di
#                    print("c,d",ci,di,emax,wmax,diii)
if wmax>0:
    print(wmax,emax)
else:
    print(100*a,emax)
import math

n=int(input())

def ts(x):
    return x*(x+1)
m=n
for i in range(math.ceil(math.sqrt(2*n)-2),math.floor(math.sqrt(2*n))+1,1):
    if ts(i)<=2*n<=ts(i+1):
        m=i+1
        break

a=n%(m+1)
b=n//(m+1)
if m%2==0:
    if a!=0:
        print(a)
    i=1
    c=0
    while c!=b:
        if i!=a and m+1-i!=a:
            print(i)
            print(m+1-i)
            c+=1
        i+=1
else:
  	"""
    check=[]
    if a!=0:
        check.append(a)
    i = 1
    c = 0
    while c!=b and i<(m+1)//2:
        if i!=a and m+1-i!=a:
            check.append(i)
            check.append(m+1-i)
            c+=1
        i+=1
    if c==b:
        for i in check:
            print(i)
    else:
        
        n-=(m+1)//2
        a = n % (m + 1)
        b = n // (m + 1)
        if m % 2 == 0:
            if a != 0:
                print(a)
            i = 1
            c = 0
            while c != b:
                if i != a and m + 1 - i != a:
                    print(i)
                    print(m + 1 - i)
                    c += 1
        """
    n-=m
    m-=1
    print(m)
    a = n % (m + 1)
    b = n // (m + 1)
    if m % 2 == 0:
      if a != 0:
        print(a)
        i = 1
        c = 0
        while c != b:
        	if i != a and m + 1 - i != a:
              print(i)
              print(m + 1 - i)
              c += 1
        	i+=1
			


### FIXED CODE ###

import math

n = int(input())


def ts(x):
    return x * (x + 1)


m = n
for i in range(math.ceil(math.sqrt(2 * n) - 2), math.floor(math.sqrt(2 * n)) + 1, 1):
    if ts(i) < 2 * n <= ts(i + 1):
        m = i + 1
        break



if m % 2 == 0:
    a = n % (m + 1)
    b = n // (m + 1)
    if a != 0:
        print(a)
    i = 1
    c = 0
    while c != b:
        if i != a and m + 1 - i != a:
            print(i)
            print(m + 1 - i)
            c += 1
        i += 1
else:
    """
  check=[]
  if a!=0:
      check.append(a)
  i = 1
  c = 0
  while c!=b and i<(m+1)//2:
      if i!=a and m+1-i!=a:
          check.append(i)
          check.append(m+1-i)
          c+=1
      i+=1
  if c==b:
      for i in check:
          print(i)
  else:

      n-=(m+1)//2
      a = n % (m + 1)
      b = n // (m + 1)
      if m % 2 == 0:
          if a != 0:
              print(a)
          i = 1
          c = 0
          while c != b:
              if i != a and m + 1 - i != a:
                  print(i)
                  print(m + 1 - i)
                  c += 1
      """
    print(m)
    n -= m
    m -= 1

    a = n % (m + 1)
    b = n // (m + 1)
    if a != 0:
        print(a)
    i = 1
    c = 0
    while c != b:
        if i != a and m + 1 - i != a:
            print(i)
            print(m + 1 - i)
            c += 1
        i += 1
#! bin/env/python python3
# -*- coding:utf-8 -*-

d,n = map(int, raw_input().split())


# print(d)
# print(n)

if d == 0:
	if n ==100:
		print(101)
	else:
		print(n)
elif d == 1:
	if n ==100:
		print(10100)
	else:
		print(n*100*d)


elif d == 2:
	print(n*10000)


### FIXED CODE ###




# import configparser
# import time


# class GetTime():
#     now = time.ctime()

    
#     def debug(self):
#         print('-------debug-begin---------------')
#         print(self.now)
#         parsed = time.strptime(self.now)
#         print(time.strftime("%a %b %d %H:%M:%S %Y", parsed))
#         print('-------debug-end---------------')


# class Person():
#     def __init__(self, name, id):
#         self.name = name
#         self.id = id


# class Greet(Person):
#     def morning(self):
#         print('Good morning ' + self.name)

#     def night(self):
#         print('Good night ' + self.name)


# hunter = Person('Hoge Fugo', 1)

# print('name:%s   id:%s' % (hunter.name, hunter.id))

# o = Greet('Bob', 4)
# o.morning()


# t = GetTime()
# t.debug()

# ##

# poem = 'Hello,friends'
# fout = open('relavity','wt')
# # print(poem, file=fout)
# fout.close()

# ##





# # config.read('exe.ini')
# # print(MySQL_setting['Port'])
# # config.read('exe.ini')
# # print(MySQL_setting['Port'])

# class init_setting():
#     def input(self):
#         print('input port number:')
#         port=input()
#         print('input user name:')
#         user=input()

#         print(port,user)

        
#         with open('example.ini','w') as conf:
#             config.write(conf)

#         config=configparser.ConfigParser()
#         config['MySQL_setting']={}
#         MySQL_setting=config['MySQL_setting']


#         MySQL_setting['Port']=port
#         MySQL_setting['user']=user

#         config.sections()


# MakeSetting=init_setting()
# MakeSetting.input()


# MySQL_setting['Port']=port
# # MySQL_setting['user']=user

# empty_list = []
# print(empty_list)

# weekdays=['monday','Tuesday','Wednesday','Thursday','Friday']

# for i in weekdays:
#     print(weekdays)

# print(weekdays[0])

# for i in weekdays:
# 	print(i)

# a_tuple=('ready','fire','class')


# list('cat')


#! bin/env/python python3
# -*- coding:utf-8 -*-

d,n = map(int, input().split())


# print(d)
# print(n)

if d == 0:
	if n ==100:
		print(101)
	else:
		print(n)
elif d == 1:
	if n ==100:
		print(10100)
	else:
		print(n*100*d)


elif d == 2:
	if(n == 100):
		print(1010000)
	else:
		print(n*10000)
import sys
input=sys.stdin.readline
import bisect

def main():
    _,M= map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    
    B = []
    for _ in range(M):
        b,c = map(int,input().split())
        B.append((b,c))
    B.sort(key=lambda x: x[1])

    x = 0
    while B:
        b,c = B.pop()
        n = bisect.bisect(A,c,hi=b)
        x += n*c
        A = A[n:]

    print(x + sum(A))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input=sys.stdin.readline
import bisect

def main():
    _,M= map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    
    B = []
    for _ in range(M):
        b,c = map(int,input().split())
        B.append((b,c))
    B.sort(key=lambda x: x[1])

    x = 0
    m = 0
    while B:
        b,c = B.pop()
        n = bisect.bisect(A,c,lo=m,hi=min(m+b,len(A)))
        x += (n-m)*c
        m = n

    print(x + sum(A[n:]))

if __name__ == '__main__':
    main()
n = input()
m = n.split()
l = m[2:]
a = sorted(l, reverse=True)
p = 0
for i in range(0,int(m[1])):
    p = p + int(c[i])
print(int(p))

### FIXED CODE ###

n = input()
m = n.split()
a = [input() for l in range(0,1)]
b = a[0].split()
for i in range(0, len(b)):
    b[i] = int(b[i])
c = sorted(b, reverse=True)
p = 0
for i in range(int(m[0]) - int(m[1]),int(m[0])):
    p = p + int(c[i])
print(p)
x,n=map(int,input().split())
a=list(map(int,input().split()))
if not x in a:
    print(x)
else:
    a.sort()
    i=a.index(x)-1
    j=i+2
    d=1
    ans=0
    while(True):
        if(a[i]!=x-d):
            ans=a[i]
            break
        else:
            i-=1
        if(a[j]!=x+d):
            ans=a[j]
            break
        else:
            j+=1
        d+=1
    print(ans)

### FIXED CODE ###

x,n=map(int,input().split())
if(n!=0):
    a=list(map(int,input().split()))
else:
    a=[]

if x not in a:
    print(x)
else:
    a.sort()
    idx=a.index(x)
    i=max(idx-1,0)
    j=min(idx+1,n-1)
    d=1
    ans=0
    while(True):
        if(a[i]!=x-d):
            ans=x-d
            break
        else:
            i=max(i-1,0)
        if(a[j]!=x+d):
            ans=x+d
            break
        else:
            j=min(j+1,n-1)
        d+=1
    print(ans)
from math import gcd
from math import sqrt
A, B = map(int, input().split())

n = gcd(A, B)

ans = set()
for i in range(2, int(sqrt(n)+1)+1):
    while n % i == 0:
        n = n // i
        ans.add(i)

print(len(ans)+1)




### FIXED CODE ###

from fractions import gcd
from math import sqrt
A, B = map(int, input().split())

n = gcd(A, B)

ans = set()
for i in range(2, int(sqrt(n)+1)+1):
    while n % i == 0:
        n = n // i
        ans.add(i)
if n > 1:
    ans.add(n)

print(len(ans)+1)