Harryxun/stf_run huggingface dataset:
from bisect import bisect_left, bisect_right
n, k = map(int, input().split())
a = tuple(map(int, input().split()))
a.sort()


def check(x):
    # k番目の数がx以下であるか
    # x以下の数字がk個以上あるか
    cnt = 0
    for i, ai in enumerate(a):
        if ai > 0:
            idx = bisect_right(a, x // ai)
            cnt += max(idx - i - 1, 0)
        elif ai < 0:
            idx = bisect_left(a, -(x // abs(ai)))
            # cnt += n - idx
            cnt += n - max(idx, i + 1)
        else:
            # ai == 0
            if x >= 0:
                cnt += n - i - 1

        if cnt >= k:
            return True
    # print('check', x, cnt)
    return cnt >= k


lb = -10**18  # False
ub = +10**18  # True
while ub - lb > 1:
    mid = (ub + lb) // 2
    # print(lb, ub)
    if check(mid):
        ub = mid
    else:
        lb = mid

print(ub)


### FIXED CODE ###

from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline

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

a_minus = a_zero = a_plus = 0
for i in range(n):
    if a[i] > 0:
        a_plus += 1
    elif a[i] == 0:
        a_zero += 1
    else:
        a_minus += 1

aa_minus = a_minus * a_plus
aa_zero = a_zero * (n - a_zero) + a_zero * (a_zero - 1) // 2


def check_minus(x):
    # k番目の数がx(<0)以下であるか
    # x以下の数字がk個以上あるか
    cnt = 0
    j = a_minus + a_zero
    for i in range(a_minus):
        # a[i] < 0
        while j < n and a[i] * a[j] > x:
            j += 1
        cnt += n - j

    return cnt >= k


def check_plus(x):
    # k番目の数がx(>0)以下であるか
    # x以下の数字がk個以上あるか

    def func(b, m):
        # 昇順ソート済みの数列b (長さm)
        # 掛け算してx以下となる数を求める
        c = 0
        j = m - 1
        for i in range(m):
            while j > 0 and b[i] * b[j] > x:
                j -= 1
            c += max(j - i, 0)
        return c

    cnt = aa_minus + aa_zero
    cnt += func(a[-a_plus:], a_plus)
    cnt += func(list(reversed(a[:a_minus])), a_minus)
    return cnt >= k


if k <= aa_minus:
    # k番目の数は負の数
    lb = a[0] * a[-1] - 1  # False
    ub = 0  # True
    while ub - lb > 1:
        mid = (ub + lb) // 2
        if check_minus(mid):
            ub = mid
        else:
            lb = mid

    ans = ub
elif k <= aa_minus + aa_zero:
    # k番目の数は0
    ans = 0
else:
    # k番目の数はプラス
    lb = 0  # False
    ub = max(a[0]**2, a[-1]**2) + 1  # True
    while ub - lb > 1:
        mid = (ub + lb) // 2
        if check_plus(mid):
            ub = mid
        else:
            lb = mid

    ans = ub

print(ans)
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import gcd
def main():
    n, m = map(int, input().split())
    s = tuple(input())
    t = tuple(input())

    if s[0] != t[0]:
        print(-1)
        sys.exit()
    if n == m:
        if s == t:
            print(n)
            sys.exit()
        else:
            print(-1)
            sys.exit()
    if n > m:
        l1 = n
        l2 = m
        s1 = s
        s2 = t
    else:
        l1 = m
        l2 = n
        s1 = t
        s2 = s
    if n % m == 0 or m % n == 0:
        ld = l1 // l2
        for i1 in range(1, l2):
            if s2[i1] != s1[i1*ld]:
                print(-1)
                sys.exit()
        print(l1)
        sys.exit()

    l = (n * m) // gcd(n, m)
    x = [0] * l
    ld1 = l // l1
    ld2 = l // l2
    for j1 in range(1, l1):
        x[j1 * ld1] = s1[j1]
    for k1 in range(1, l2):
        if x[k1 * ld2]:
            if x[k1 * ld2] != s2[k1]:
                print(-1)
                sys.exit()
    print(l)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import gcd
def main():
    n, m = map(int, input().split())
    s = tuple(input())
    t = tuple(input())

    if n > m:
        l1 = n
        l2 = m
        s1 = s
        s2 = t
    else:
        l1 = m
        l2 = n
        s1 = t
        s2 = s

    if s[0] != t[0]:
        r = -1
    elif n == m:
        if s == t:
            r = n
        else:
            r = -1
    elif n % m == 0 or m % n == 0:
        ld = l1 // l2
        for i1 in range(1, l2):
            if s2[i1] != s1[i1*ld]:
                r = -1
                break
        else:
            r = l1
    else:
        l = (n * m) // gcd(n, m)
        # x = [0] * l
        ld1 = l // l1
        ld2 = l // l2
        cnt = 1
        r = l
        while cnt < l1:
            cnt2 = cnt * ld1
            if cnt2 % ld2 == 0:
                if s1[cnt] != s2[cnt2 // ld2]:
                    r = -1
                    break
            cnt += 1
    print(r)

if __name__ == '__main__':
    main()
ok = True

NM = [map(int, input().split())]
N, M = [list(i) for i in zip(*NM)]
sc = [map(int, input().split()) for _ in range(M[0])]
s, c = [list(i) for i in zip(*sc)]

l = [-1] * N[0]


for i in range(M[0]):
    if l[s[i]-1] == -1:
        l[s[i]-1] = c[i]
    elif l[s[i]-1] != c[i]:
        ok = False
        break
        
if l[0] == 0:
    ok = False
elif l[0] == -1:
    l[0] = 1
    
for i in range(1,N[0]):
    if l[i] == -1:
        l[i] = 0
    
ans = ""   
if ok:
    for i in range(len(l)):
        ans = ans + str(l[i])
    print(ans)
else:
    print("-1")

#print(M[0],N[0])
#print(s[0],c[0])

### FIXED CODE ###

ok = True

NM = [map(int, input().split())]
N, M = [list(i) for i in zip(*NM)]

l = [-1] * N[0]

if M[0] != 0:
    sc = [map(int, input().split()) for _ in range(M[0])]
    s, c = [list(i) for i in zip(*sc)]

    for i in range(M[0]):
        if l[s[i]-1] == -1:
            l[s[i]-1] = c[i]
        elif l[s[i]-1] != c[i]:
            ok = False
            break
        
if l[0] == 0 and N[0] >= 2:
    ok = False
elif l[0] == -1:
    if N[0] >= 2:
        l[0] = 1
    else:
        l[0] = 0
    
for i in range(1,N[0]):
    if l[i] == -1:
        l[i] = 0
    
ans = ""   
if ok:
    for i in range(len(l)):
        ans = ans + str(l[i])
    print(ans)
else:
    print("-1")

#print(M[0],N[0])
#print(s[0],c[0])
import strutils

proc input: string =
  while true:
    let tmp = readChar stdin
    if not isSpace tmp:
      safeAdd result, tmp
    elif tmp != '\r': break

let
  A, B, C, D, E, F = parseInt input()
var
  best = -1.0
  ws, sg = 0

for a in countup(0, F, 100 * A):
  for b in countup(0, F - a, 100 * B):
    let
      w = a + b
      m = min(F - w, w * E div 100)

    if w == 0: continue
    for c in countup(0, m, C):
      for d in countup(0, m - c, D):
        let s = c + d
        if best < s / (w + s):
          best = s / (w + s)
          ws = w + s
          sg = s

echo ws, " ", sg


### FIXED CODE ###

A, B, C, D, E, F = map(int, input().split())

best = -1.0
a = ws = sg = 0

while 100 * a * A <= F:
    b = 0
    while True:
        w = 100 * (a * A + b * B)
        if w > F: break
        c = 0
        while w + c * C <= F and 100 * c * C <= w * E:
            d = 0
            while True:
                s = c * C + d * D
                if w + s > F or 100 * s > w * E:
                    break
                elif w + s != 0 and best < s / (w + s):
                    best = s / (w + s)
                    ws = w + s
                    sg = s
                d += 1
            c += 1
        b += 1
    a += 1
print(ws, sg)
cards = [[False in i in range(13)] for j in range(4)]
pattern = ['S','H','C','D']

n = int(input())

for i in range(n):
  x, y = input().split()
  y = int(y)
  cards[pattern.index(x)][y-1] = True
  
for i in range(4):
  for j in range(13):
    if cards[i][j] == False:
      print(pattern[i],[j-1])


### FIXED CODE ###

n = int(input())
card =[i+" "+str(j) for i in ["S","H","C","D"] for j in range(1,14)]
for i in range(n):
    card.remove(input())
for i in card:
    print(i)
N = int(input())
print (["No","Yes"][N[0] == N[2])

### FIXED CODE ###

N = input()
print (["No","Yes"][N[0] == N[2]])
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pysnooper # @pysnooper.snoop()
from pprint import pprint as pp
from pprint import pformat as pf

def solve():
    k = int(input())
    a, b = map(int, input().split())
    v = k
    while not (v > b):
        if a <= v <= b:
            print("OK")
            return 0
        v += k
    print("NG")
    return 0


if __name__ == '__main__':
    solve()


### FIXED CODE ###

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

from pprint import pprint as pp
from pprint import pformat as pf

def solve():
    k = int(input())
    a, b = map(int, input().split())
    v = k
    while not (v > b):
        if a <= v <= b:
            print("OK")
            return 0
        v += k
    print("NG")
    return 0


if __name__ == '__main__':
    solve()
import collections
N=int(input())
s=0
a=list(map(int,input().split()))
c=collections.Counter(a)
for i in  c.keys():
  if c.values(i)>i:
    s+=c.values(i)-i
  elif c.values(i)<i:
    s+=c.values(i)
print(s)
    
    

### FIXED CODE ###

import collections
N=int(input())
s=0
a=list(map(int,input().split()))
c=collections.Counter(a)
for i in  c.keys():
  if c[i]>i:
    s+=c[i]-i
  elif c[i]<i:
    s+=c[i]
print(s)
N = int(input())
S = [input() for _ in range(N)]
A = []
cnt = 0
for k in S:
   B = sorted(k)
   C = ''.join(B)
   A.append(C)
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        elif A[i] == A[j]:
            cnt += 1
print(cnt)

### FIXED CODE ###

A, B = map(int, input().split())
print(max([A + B, A - B, A * B]))
import math
A,B,H,M=map(int().split())
thetaA=(2*360*H/12)%360
thetaB=(2*360*M/60)%360
if theraA-thetaB<=180:
  theta=theraA-thetaB
else:
  theta=360-theraA-thetaB
print(A*B*math.cos(math.radians(theta)))

### FIXED CODE ###

import math
A,B,H,M=map(int,input().split())
thetaA=360/12*H+360/12*M/60
thetaB=360/60*M
theta=thetaA-thetaB
print(math.sqrt(A*A+B*B-2*A*B*math.cos(math.radians(theta))))
l = [int(input()) for i in range(5)]
if l <= int(input()):
    print('Yay!')
else:
    print(':(')

### FIXED CODE ###

l = [int(input()) for i in range(5)]
if l[4]-l[0] <= int(input()):
    print('Yay!')
else:
    print(':(')
s = list(str(input()))
for i in range(1, len(s)+1):
  if ((i+1)%2 and s[i]=='L') or ((i+1)%2==0 and s[i]=='R'):
    print('No')
    exit()
print('Yes')

### FIXED CODE ###

s = list(str(input()))
for i in range(len(s)):
  if ((i+1)%2 and s[i]=='L') or ((i+1)%2==0 and s[i]=='R'):
    print('No')
    exit()
print('Yes')
def main():
    n, k, *a = map(int, open(0).read().split())
    a = [0] + a
    root = [1]
    start = a[1]
    root.append(start)
    now = start
    roop = 0
    while True:
        next = a[now]
        if next in root:
            roop = next
            break
        else:
            root.append(next)
            now = next

    if roop == 0:
        ans = root[k]
    else:
        roop_start = root.index(roop)
        step = roop_start + 1
        if k <= step:
            ans = ans[k]
        else:
            m = len(root) - roop_start
            p, q = divmod(k - step + 1, m)
            index = roop_start + q
            ans = root[index]
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, k, *a = map(int, open(0).read().split())
    a = [0] + a
    root = [1]
    visited = [False for _ in range(n+1)]
    nx = 1
    visited[1] = True

    step = 0
    while True:
        step += 1
        now = nx
        nx = a[now]
        if step == k:
            print(nx)
            break
        if visited[nx]:
            end = step
            start = root.index(nx)
            d = end - start
            r = k - step
            index = start + r % d
            print(root[index])
            break

        visited[nx] = True
        root.append(nx)

if __name__ == '__main__':
    main()
import time


def main():

    N, Q = map(int, input().split())
    S = input()

    sum = [0] * (N + 100)

    for i in range(N):
        if S[i] == 'A' and S[i+1] == 'C': sum[i+1] = sum[i] + 1
        else: sum[i+1] = sum[i]

    for i in range(Q):
        l, r = map(int, input().split())
        print(sum[r-1] - sum[l-1])


if __name__ == '__main__':
    start = time.perf_counter()

    main()

    end = time.perf_counter()
    # print(end - start)


### FIXED CODE ###

import time


def main():

    N, Q = map(int, input().split())
    S = input()

    sum = [0] * (N + 1)

    for i in range(1, N):
        if S[i-1] == 'A' and S[i] == 'C': sum[i] = sum[i-1] + 1
        else: sum[i] = sum[i-1]

    for i in range(Q):
        l, r = map(int, input().split())
        print(sum[r-1] - sum[l-1])


if __name__ == '__main__':
    start = time.perf_counter()

    main()

    end = time.perf_counter()
    # print(end - start)
n = int(input())

s = ""

while n != 0:
	s = str(n%2) + s
	s = -(s//2)

print(s if s != "" else 0)

### FIXED CODE ###

n = int(input())

s = ""

while n != 0:
	s = str(n%2) + s
	n = -(n//2)

print(s if s != "" else 0)
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

counter = [0 for _ in range(n + 1)]
for i in a:
    counter[i] += 1


MAX = 10 ** 5
MOD = 10 ** 9 + 7
fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]

def comInit(mod):
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod


def com(n, r, mod):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod
comInit(MOD)

total = 0 
diff = [0 for _ in range(n + 1)]
for i, c in enumerate(counter):
    x = com(c, 2, MOD)
    total += x
    if c - 1 <= 0:
        diff[i] = x
    else:
        y = com(c - 1, 2, MOD)
        diff[i] = x - y

for i in range(n):
    print(total - diff[a[i]])

### FIXED CODE ###

import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

counter = [0 for _ in range(n + 1)]
for i in a:
    counter[i] += 1

total = 0 
diff = [0 for _ in range(n + 1)]
for i, c in enumerate(counter):
    x = c * (c - 1) // 2
    total += x
    if c - 1 <= 0:
        diff[i] = x
    else:
        y = (c - 1) * (c - 2) // 2
        diff[i] = x - y

for i in range(n):
    print(total - diff[a[i]])
n, m, k = map(int, input.split())
a = list(map(int, input.split()))
b = list(map(int, input.split()))

aa, bb = [0], [0]
for i in range(n):
	aa.append(aa[i]+a[i])

for i in range(m):
	bb.append(b[i]+bb[i])


ans, i = 0, m
for j in range(n+1):
	if aa[j] > k:
		break
	while b[i] > k-aa[j]:
		j -= 1

	ans = max(ans, i+j)


print(ans)


### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)



print(ans)
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
x=0
for i in range(0,n-1):
  if a[i]=a[i+1]:
    x+=int(c[int(a[i])-1])
y=sum(b)
print(x+y)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
x=0
for i in range(0,n-1):
  if a[i]+1==a[i+1]:
    x+=c[a[i]-1]
y=sum(b)
print(x+y)
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
if 0 in A:
	print(0)
	exit()

ans = 1

for a in A:
	ans *= a
	if ans > 10**18:
		print(-1)
		exit()
print(ans)


### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

if 0 in A:
	print(0)
	exit()
	
ans = 1
for a in A:
	ans *= a
	if ans > 10**18:
		print(-1)
		break
else:
	print(ans)
S = input()
N = len(S)
if S[:(N−1)/2] == S[N-((N−1)/2)::-1]:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

def kaibun(s):
  if s == s[::-1]:
    flg = True
  else:
    flg = False
  return flg

S = input()
N = len(S)
ans = 'Yes'
if kaibun(S):
  pass
else:
  ans = ('No')
if kaibun(S[:(N-1)//2]):
  pass
else:
  ans = ('No')
if kaibun(S[:(-(N-1)//2)-1:-1]):
  pass
else:
  ans = ('No')
print(ans)
import sys,math
W,H,x,y = map(int,input().split())
if W % x == 0 and H % y == 0:
    print(W*H/2,1)
else :
    print(W*H/2,0)

### FIXED CODE ###

import sys,math
W,H,x,y = map(int,input().split())
if W/2 == x and H/2 == y:
    print(W*H/2,'1')
else:
    print(W*H/2,'0')
n = int(input())
a = list(map(int, input().split(' ')))
b = list(range(n))
b.sort(key=lambda x: -a[x])
# print("b after:", b)
# print(list(map(lambda x:a[x],b)))

cache = [[-1 for x in range(n)] for y in range(n)]
# print(cache)


def dfs(left, right):
    if left > right:
        return 0
    if cache[left][right] != -1:
        return cache[left][right]
    which = n-(right-left+1)
    ans1 = dfs(left+1, right)+abs(left-b[which])*a[b[which]]
    ans2 = dfs(left, right-1)+abs(right-b[which])*a[b[which]]
    cache[left][right] = max(ans1, ans2)
    return cache[left][right]


print(dfs(0, n-1))


### FIXED CODE ###

import sys
import time

t = time.time()

n = int(input())
a = list(map(int, input().split(' ')))
b = list(range(n))
b.sort(key=lambda x: -a[x])
# print("b after:", b)
# print(list(map(lambda x:a[x],b)))
# print(time.time()-t)

cache = [[-1 for x in range(n)] for y in range(n)]
# print(cache)


def dfs(left, right):
    if left > right:
        return 0
    if cache[left][right] != -1:
        return cache[left][right]
    which = n-(right-left+1)
    ans1 = dfs(left+1, right)+abs(left-b[which])*a[b[which]]
    ans2 = dfs(left, right-1)+abs(right-b[which])*a[b[which]]
    cache[left][right] = max(ans1, ans2)
    return cache[left][right]


sys.setrecursionlimit(2010)
print(dfs(0, n-1))
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 14:33:00 2020

@author: liang
"""
from math import gcd

N, M = map(int, input().split())
A = [int(i) for i in input().split()]

flag = False
res = 1
for a in A:
    a /= 2
    res *= a//gcd(res,a)
    if res > M:
        flag = True
        break
    #print(res)
"""
存在チェック
２で割り切れる個数同じ？
"""

for a in A:
    if int(res/a) == res/a:
        flag = True
        
if flag:
    ans = 0
    print(ans)
else:
    #ans = (M - res(A)//2)//res + 1
    #ans = (M-1)//res//2 + 1
    ans= (M//res + 1)//2
    print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 14:33:00 2020

@author: liang
"""
from math import gcd

N, M = map(int, input().split())
A = [int(i) for i in input().split()]

flag = False
res = 1
for a in A:
    a //= 2
    res *= a//gcd(res,a)
    if res > M:
        flag = True
        break
    #print(res)
"""
存在チェック
２で割り切れる個数同じ？
"""

for a in A:
    if int(res/a) == res/a:
        flag = True
        
if flag:
    ans = 0
    print(ans)
else:
    #ans = (M - res(A)//2)//res + 1
    #ans = (M-1)//res//2 + 1
    ans= (M//res + 1)//2
    print(ans)
S = list(map(int,input().split()))
len(S)=p
t=0
for n in range(p):
  if S[n]=S[p-n-1]:
    continue
  else:
    t+=1
print(t)

### FIXED CODE ###

S = input()
p=len(S)
t=0
for n in range(p):
  if S[n]!=S[p-n-1]:
    t+=1
print(int(t/2))
def main():

    n = int(input())
    a = n//1000
    print(n%(a*1000))
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

import math
import sys

def main():

    input = sys.stdin.buffer.readline
    n = int(input())
    if(n%1000 == 0):
        print(0)
    else:
        a = n // 1000
        print((a+1)*1000-n)

if __name__ == "__main__":
    main()
N,M = map(int,input().split())

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

if N == 1:
    a = 0
else:
    a = cmb(N,2)
if M == 1:
    b = 0
else:
    b = cmb(M,2)
print(a+b)

### FIXED CODE ###

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

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

if N == 1 or N == 0:
    a = 0
else:
    a = cmb(N,2)
if M == 1 or M == 0:
    b = 0
else:
    b = cmb(M,2)
print(a+b)
import numpy as np

N = int(input())
H = np.array(input().split(), dtype=np.int32)

"""
A = [10,4,8,7,3]
left_idx = [0,0,2,2,2]
というものを作る
"""
left_idx = np.arrange(N)
left_idx[1:][A[:-1] >= A[1:]] = 0
np.maximum.accumulate(left_idx, out=left_idx)

ans = (np.arrange(N) - left_idx).max()
print(ans)

### FIXED CODE ###

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

cnt = 0
ans = 0
for i in range(N-1):
  if H[i+1] <= H[i]:
    cnt += 1
  else:
    ans = max(ans, cnt)
    cnt = 0
ans = max(ans, cnt)    
print(ans)
n = int(input())
a = list(map(int,input().split()))
pal =1
minabs = 10**9
for i in range(n):
    if a[i] <0:
        pal *=-1
        a[i] = -1*a[i]
    minabs = min(minabs,a[i])
if pal ==1:
    print(sum(a))
else:
    print(sum(a)-2*minabs)


### FIXED CODE ###

a,b,t = map(int,input().split())
s = t//a
print(b*s)
# Author : prayushd
# Language : Python

import re
import os
import sys
from math import ceil, inf
from fractions import gcd
from queue import Queue
from collections import defaultdict, Counter, deque
from bisect import bisect, insort, bisect_left, bisect_right

mod = int(1e9)+7
input = sys.stdin.readline

'''
Check for special cases (n=1)
One wrong submission = 10 mins penalty!
do smth instead of nothing and stay organized
'''

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [inf]*n
	for i in range(n-1):
		ans[i] = min(ans[i], arr[i])
		ans[i+1] = min(ans[i+1], arr[i])
	# print(ans)
	print(sum(ans))


if __name__ == '__main__':
	main()

### FIXED CODE ###

n = int(input())
arr = list(map(int, input().split()))
ans = [999999999]*n
for i in range(n-1):
	ans[i] = min(ans[i], arr[i])
	ans[i+1] = min(ans[i+1], arr[i])
print(sum(ans))
n = int(input())
array = []
for i in range(1,10):
    for j in range(1,10):
        array.append(i * j)
        
if n in array:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

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

if a >9 or b > 9:
    print("-1")
else:
    ans = a * b
    print(ans)
import math
 
N=int(input())
if N%1000==0:
  print(0)
else:
   N=(math.ceil(money/1000))*1000-N
  print(N)

### FIXED CODE ###

n = int(input())

if n % 1000 == 0:
  print(0)
else:
  print(1000-(n%1000))