qyliang/CodeNanoFix huggingface dataset:
Problem A: Decimal Sequences

Hanako believes that all non-negative integers appear in the infinite digit sequence of the decimal representation of π = 3.14159265..., the ratio of a circle's circumference to its diameter. She counts non-negative integers whose decimal representations appear as subsequences in a given sequence of digits.

Write a program that, given a finite sequence of digits, outputs the smallest non-negative integer not appearing in the sequence.

Input:
The input consists of a single test case.
n
d1 d2 ... dn
n is a positive integer indicating the number of digits. Each dk (k = 1, ..., n) is a digit. There is a space or a newline between dk and dk+1 (k = 1, ..., n - 1).
You can assume that 1 ≤ n ≤ 1000.

Output:
Print the smallest non-negative integer not appearing in the sequence.

Sample Input 1:
3
3 0 1
Sample Output 1:
2

Sample Input 2:
11
9 8 7 6 5 4 3 2 1 1 0
Sample Output 2:
12

Sample Input 3:
10
9 0 8 7 6 5 4 3 2 1
Sample Output 3:
10

Sample Input 4:
100
3 6 7 5 3 5 6 2 9 1 2 7 0 9 3 6 0 6 2
6 1 8 7 9 2 0 2 3 7 5 9 2 2 8 9 7 3 6
1 2 9 3 1 9 4 7 8 4 5 0 3 6 1 0 6 3 2
0 6 1 5 5 4 7 6 5 6 9 3 7 4 5 2 5 4 7
4 4 3 0 7 8 6 8 8 4 3 1 4 9 2 0 6 8 9
2 6 6 4 9
Sample Output 4:
11

Sample Input 5:
100
7 2 7 5 4 7 4 4 5 8 1 5 7 7 0 5 6 2 0
4 3 4 1 1 0 6 1 6 6 2 1 7 9 2 4 6 9 3
6 2 8 0 5 9 7 6 3 1 4 9 1 9 1 2 6 4 2
9 7 8 3 9 5 5 2 3 3 8 4 0 6 8 2 5 5 0
6 7 1 8 5 1 4 8 1 3 7 3 3 5 3 0 6 0 6
5 3 2 2 2
Sample Output 5:
86

Sample Input 6:
1
3
Sample Output 6:
0

# Buggy version:
n = int(input())
length = int(n / 19) + 1 if n > 19 and n % 19 == 0 else int(n / 19)
d = []
for i in range(length):
    d += list(map(int, input().split()))

start, end = 1, 10
l = []
flag = False
for j in range(1, len(d)+1):
    for i in range(0, len(d)):
        tmp = ''.join(map(str, d[i:i+j]))
        if len(tmp) > 1 and tmp[0] == '0':
            pass
        elif len(tmp) == j:
            l.append(int(tmp))
    l = sorted(set(l))
    if start == 1:
        for k in range(0, 10):
            if k not in l:
                print(k)
                flag = True
                break
    else:
        for k in range(start, end):
            if k not in l:
                print(k)
                flag = True
                break
    if flag:
        break
    start, end = start*10, end*10
    l = []

# Fixed version:
n = int(input())
length = int(n / 19) + 1
if n > 19 and n % 19 == 0:
    length -= 1
d = []
for i in range(length):
    d += list(map(int, input().split()))
start, end = 1, 10
l = []
flag = False
for j in range(1, len(d)+1):
    for i in range(0, len(d)):
        tmp = ''.join(map(str, d[i:i+j]))
        if len(tmp) > 1 and tmp[0] == '0':
            pass
        elif len(tmp) == j:
            l.append(int(tmp))
    l = sorted(set(l))
    if start == 1:
        for k in range(0, 10):
            if k not in l:
                print(k)
                flag = True
                break
    else:
        for k in range(start, end):
            if k not in l:
                print(k)
                flag = True
                break
    if flag:
        break
    start, end = start*10, end*10
    l = []
The Impractically Complicated Products Corporation's factory has manufacturing lines, storage rooms, and conveyor lanes. Robot arms are placed between adjacent lanes to transfer goods, allowing mixing of goods from different manufacturing lines to the storage rooms. Given the number of conveyor lanes and positions of robot arms, the task is to find the number of manufacturing lines from which goods can be transferred to each storage room.

Input:
- The input consists of a single test case with the following format:
  - n m
  - x1 y1
  - ...
  - xm ym
- n (2 ≤ n ≤ 200000) is the number of conveyor lanes, numbered from 1 to n.
- m (1 ≤ m < 100000) is the number of robot arms.
- The following m lines indicate the positions of the robot arms by two integers xi (0 < xi < 100000) and yi (1 ≤ yi < n).

Output:
- Output n integers separated by a space in one line. The ith integer is the number of manufacturing lines from which the storage room connected to the conveyor lane i can accept goods.

# Buggy version:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,q = LI()
    qa = sorted([LI() for _ in range(q)])
    u = [0] * (n+2)
    d = [0] * (n+2)

    for x,i in qa:
        u[i+1] = u[i] + 1
        d[i] = d[i+1] + 1
    rr = []
    for i in range(1,n+1):
        rr.append(u[i]+d[i]+1)


    return '\n'.join(map(str,rr))


print(main())




# Fixed version:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,q = LI()
    qa = sorted([LI() for _ in range(q)])
    u = [0] * (n+2)
    d = [0] * (n+2)

    for x,i in qa:
        u[i+1] = u[i] + 1
        d[i] = d[i+1] + 1
    rr = []
    for i in range(1,n+1):
        rr.append(u[i]+d[i]+1)


    return ' '.join(map(str,rr))


print(main())
Problem B: Grid

Given two coordinates (<i>a<sub>1</sub></i>, <i>a<sub>2</sub></i>) and (<i>b<sub>1</sub></i>, <i>b<sub>2</sub></i>) on a 2D grid of size <i>r</i> × <i>c</i>, find the number of shortest paths from the first coordinate to the second. Moving from one square (e,f) to (e+1,f), (e-1,f), (e,f+1), or (e,f-1) has a cost of 1. Additionally, moving between (e,c-1) and (e,0), or between (r-1,f) and (0,f) also has a cost of 1.

Input:
The input is given in the following format:
<i>r</i> <i>c</i> <i>a<sub>1</sub></i> <i>a<sub>2</sub></i> <i>b<sub>1</sub></i> <i>b<sub>2</sub></i>
The input satisfies the following constraints:
1 ≤ <i>r</i>, <i>c</i> ≤ 1,000
0 ≤ <i>a<sub>1</sub></i>, <i>b<sub>1</sub></i> < r
0 ≤ <i>a<sub>2</sub></i>, <i>b<sub>2</sub></i> < c

Output:
Output the value modulo 100,000,007.

Sample Input 1:
4 4 0 0 3 3

Sample Output 1:
2

Sample Input 2:
4 4 0 0 1 1

Sample Output 2:
2

Sample Input 3:
2 3 0 0 1 2

Sample Output 3:
4

Sample Input 4:
500 500 0 0 200 200

Sample Output 4:
34807775

# Buggy version:
def func (x):
	if x:
		return int(x)*func(x-1)
	else:
		return (1)
def comb (x,y):
	return func(x)//func(x-y)//func(y)

h,w,ax,ay,bx,by=map(int,input().split())
dx=min(w-abs(ax-bx),abs(ax-bx))
dy=min(h-abs(ay-by),abs(ay-by))
ans=1
if dx*2==w:ans*=2
if dy*2==h:ans*=2
ans*=comb(dx+dy,dx)
print(ans%100000007)

# Fixed version:
def func (x):
	if x:
		return int(x)*func(x-1)
	else:
		return (1)
def comb (x,y):
	return func(x)//func(x-y)//func(y)

import sys
sys.setrecursionlimit(10000)
w,h,ax,ay,bx,by=map(int,input().split())
dx=min(w-abs(ax-bx),abs(ax-bx))
dy=min(h-abs(ay-by),abs(ay-by))
ans=1
if dx*2==w:ans*=2
if dy*2==h:ans*=2
ans*=comb(dx+dy,dx)
print(ans%100000007)

# Buggy version:
import math
def comb (x,y):
	return factorial(x)//factorial(x-y)//factorial(y)

w,h,ax,ay,bx,by=map(int,input().split())
dx=min(w-abs(ax-bx),abs(ax-bx))
dy=min(h-abs(ay-by),abs(ay-by))
ans=1
if dx*2==w:ans*=2
if dy*2==h:ans*=2
ans*=comb(dx+dy,dx)
print(ans%100000007)

# Fixed version:
from math import factorial
def comb (x,y):
	return factorial(x)//factorial(x-y)//factorial(y)

w,h,ax,ay,bx,by=map(int,input().split())
dx=abs(ax-bx)
dx=min(dx,w-dx)
dy=abs(ay-by)
dy=min(dy,h-dy)
ans=1
if dx*2==w:ans*=2
if dy*2==h:ans*=2
ans*=comb(dx+dy,dx)
print(ans%100000007)

# Buggy version:
from math import factorial
def comb (x,y):
	return factorial(x)//factorial(x-y)//factorial(y)

w,h,ax,ay,bx,by=map(int,input().split())
dx=abs(ax-bx)
dx=min(dx,w-dx)
dy=abs(ay-by)
dy=min(dy,h-dy)
an=1
if dx*2==w:an*=2
if dy*2==h:an*=2
an*=comb(dx+dy,dx)
print(an%int(1E9+7))

# Fixed version:
from math import factorial
def comb (x,y):
	return factorial(x)//factorial(x-y)//factorial(y)

w,h,ax,ay,bx,by=map(int,input().split())
dx=abs(ax-bx)
dx=min(dx,w-dx)
dy=abs(ay-by)
dy=min(dy,h-dy)
an=1
if dx*2==w:an*=2
if dy*2==h:an*=2
an*=comb(dx+dy,dx)
print(an%int(1E8+7))
Min-Max: Given three integers a, b, and c, output the minimum and maximum values. Input format: three integers a, b, and c separated by spaces. Output format: print the minimum and maximum values separated by a space. Constraints: -1,000,000,000 ≤ a, b, c ≤ 1,000,000,000. Example: Input: 4 5 3, Output: 3 5

# Buggy version:
nums = list(map(int, input().split(' ')))

max = -float('inf')
min = flaot('inf')
for num in nums:
    if num > max: max = num
    if num < min: min = num

print(min, max)



# Fixed version:
nums = list(map(int, input().split(' ')))

max = -float('inf')
min = float('inf')
for num in nums:
    if num > max: max = num
    if num < min: min = num

print(min, max)

# Buggy version:
a, b, c = list(map(int, input().split()))
print('{} {}'.format(min([a,b,c], max([a,b,c])))



# Fixed version:
a, b, c = list(map(int, input().split()))
print('{} {}'.format(min([a,b,c]), max([a,b,c])))
Title: Lexicographical Comparison

Compare two given sequences A = {a0, a1, ..., an-1} and B = {b0, b1, ..., bm-1} lexicographically.

Input:
The input is given in the following format:
n
a0 a1, ..., an-1
m
b0 b1, ..., bm-1
The number of elements in A and its elements ai are given in the first and second lines respectively. The number of elements in B and its elements bi are given in the third and fourth lines respectively. All input are given in integers.

Output:
Print 1 if B is greater than A, otherwise 0.

Constraints:
- 1 ≤ n, m ≤ 1,000
- 0 ≤ ai, bi ≤ 1,000

Sample Input 1:
3
1 2 3
2
2 4

Sample Output 1:
1

Sample Input 2:
4
5 4 7 0
5
1 2 3 4 5

Sample Output 2:
0

Sample Input 3:
3
1 1 2
4
1 1 2 2

Sample Output 3:
1

# Buggy version:
n = int(input())
a = list(map(int, input().split(' ')))
m = int(input())
b = list(map(int, input().split(' ')))

loop_num = n if n <= m else m
for i in range(loop_num):
    if a[i] < b[i]:
        print(1)
        break
    elif a[i] > b[i]:
        print(0)
        break

if len(a) < len(b):
    print(1)
else:
    print(0)


# Fixed version:
n = int(input())
a = list(map(int, input().split(' ')))
m = int(input())
b = list(map(int, input().split(' ')))

rst = None

loop_num = n if n <= m else m
for i in range(loop_num):
    if a[i] < b[i]:
        rst = 1
    elif a[i] > b[i]:
        rst = 0
    if rst != None: break

if rst == None:
    if len(a) < len(b):
        rst = 1
    else:
        rst = 0

print(rst)

# Buggy version:
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))

la = len(a)
lb = len(b)
l = min(la, lb)

for i in range(l):
    if a[i] > b[i]:
        print(0)
        break
    elif a[i] < b[i]:
        print(1)
        break
else:
    if la < lb:
        print(0)
    else:
        print(1)


# Fixed version:
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))

la = len(a)
lb = len(b)
l = min(la, lb)

for i in range(l):
    if a[i] > b[i]:
        print(0)
        break
    elif a[i] < b[i]:
        print(1)
        break
else:
    if la >= lb:
        print(0)
    else:
        print(1)
Binary Search:
For a given sorted sequence A = {a0, a1, ..., an-1}, find a specific value k given as a query.

Input:
The input consists of:
- The number of elements n and each element ai in the first and second lines respectively.
- The number of queries q in the third line, followed by q integers ki as queries.

Output:
For each query, print 1 if any element in A is equivalent to k, and 0 otherwise.

Constraints:
- 1 ≤ n ≤ 100,000
- 1 ≤ q ≤ 200,000
- 0 ≤ a0 ≤ a1 ≤ ... ≤ an-1 ≤ 1,000,000,000
- 0 ≤ ki ≤ 1,000,000,000

Sample Input 1:
4
1 2 2 4
3
2
3
5

Sample Output 1:
1
0
0

# Buggy version:
n = int(input())
a = list(map(int, input().split(' ')))

def binary_search(val):
    left, right = 0, n-1
    while right - left >= 1:
        mid = (right+left)//2
        if a[mid] == val: return 1
        if a[mid] < val:
            left = mid
        elif val < a[mid]:
            right = mid
    return 0

q = int(input())
for i in range(q):
    k = int(input())
    print(binary_search(k))



# Fixed version:
n = int(input())
a = list(map(int, input().split(' ')))

def binary_search(val):
    left, right = 0, n-1
    while right - left >= 0:
        mid = int((right+left)/2)
        if a[mid] == val: return 1
        if a[mid] < val:
            left = mid+1
        elif val < a[mid]:
            right = mid-1
    return 0

q = int(input())
for i in range(q):
    k = int(input())
    print(binary_search(k))

# Buggy version:
input()

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

def nibu(low,high,i):
	middle = (low+high)//2
	if b[middle] <= i:
		low = middle
	else:
		high = middle

	if low == high:
		if i == b[low]:
			return 1 
		else:
			return 0
a = int(input())
for i in range(a):
	k = int(input())
	print(nibu(0,len(b)-1,k))


# Fixed version:
input()

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

def nibu(low,high,i):
	middle = int((low+high)/2)
	if low == high:
		if i == b[low]:
			return 1 
		else:
			return 0

	if b[middle] < i:
		low = middle + 1
		return nibu(low,high,i)
	elif b[middle] >= i:
		high = middle
		return nibu(low,high,i)

a = int(input())
for i in range(a):
	k = int(input())
	print(nibu(0,len(b)-1,k))
Multi-Set

For a set S of integers, perform a sequence of the following operations. Note that multiple elements can have equivalent values in S.

- insert(x): Insert x to S and report the number of elements in S after the operation.
- find(x): Report the number of x in S.
- delete(x): Delete all x from S.
- dump(L, R): Print elements x in S such that L ≤ x ≤ R.

Input

The input is given in the following format.

q
query_1
query_2
:
query_q

Each query query_i is given by

0 x

or

1 x

or

2 x

or

3 L R

where the first digits 0, 1, 2, and 3 represent insert, find, delete, and dump operations respectively.

Output

For each insert operation, print the number of elements in S.
For each find operation, print the number of specified elements in S.
For each dump operation, print the corresponding elements in ascending order. Print an element in a line.

Constraints

- 1 ≤ q ≤ 200,000
- 0 ≤ x ≤ 1,000,000,000
- The total number of elements printed by dump operations does not exceed 1,000,000
- The sum of numbers printed by find operations does not exceed 2,000,000

Sample Input 1

10
0 1
0 1
0 2
0 3
2 2
1 1
1 2
1 3
0 4
3 1 4

Sample Output 1

1
2
3
4
2
0
1
4
1
1
3
4

# Buggy version:
# AOJ ITP2_7_D: Multi-Set
# Python3 2018.6.24 bal4u

from bisect import bisect_left, bisect_right, insort_left
dict = {}
keytbl = []
cnt = 0
q = int(input())
for i in range(q):
	a = list(input().split())
	ki = int(a[1])
	if a[0] == '0':
		if ki not in dict:
			dict[ki] = 1
			insort_left(keytbl, ki)
		else: dict[ki] += 1
		cnt += 1
		print(cnt)
	elif a[0] == '1': print(dict[ki] if ki in dict else 0)
	elif a[0] == '2':
		if ki in dict:
			cnt -= dict[ki]
			dict[ki] = 0
	else:
		L = bisect_left (keytbl, int(a[1]))
		R = bisect_right(keytbl, int(a[2]), L)
		for j in range(L, R):
			if dict[keytbl[j]] > 0: print(keytbl[j])


# Fixed version:
# AOJ ITP2_7_D: Multi-Set
# Python3 2018.6.24 bal4u

from bisect import bisect_left, bisect_right, insort_left
dict = {}
keytbl = []
cnt = 0
q = int(input())
for i in range(q):
	a = list(input().split())
	ki = int(a[1])
	if a[0] == '0':
		if ki not in dict:
			dict[ki] = 1
			insort_left(keytbl, ki)
		else: dict[ki] += 1
		cnt += 1
		print(cnt)
	elif a[0] == '1': print(dict[ki] if ki in dict else 0)
	elif a[0] == '2':
		if ki in dict:
			cnt -= dict[ki]
			dict[ki] = 0
	else:
		L = bisect_left (keytbl, int(a[1]))
		R = bisect_right(keytbl, int(a[2]), L)
		for j in range(L, R):
			for k in range(dict[keytbl[j]]): print(keytbl[j])
Title: Power

For given integers m and n, compute m^n (mod 1,000,000,007). Here, A (mod M) is the remainder when A is divided by M.

Input
Two integers m and n are given in a line.

Output
Print m^n (mod 1,000,000,007) in a line.

Constraints
- 1 ≤ m ≤ 100
- 1 ≤ n ≤ 10^9

Sample Input 1
2 3

Sample Output 1
8

Sample Input 2
5 8

Sample Output 2
390625

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

"""
input:
5 8

output:
390625
"""

import sys


def mod_pow(x, n, _mod):
    res = 1
    while n > 0:
        # check n is odd number
        if n % 2:
            res = res * x % _mod
        x = pow(x, 2) % _mod
        n //= 1
    return res


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    n1, n2 = map(int, _input[0].split())
    M = 1000000007
    # print(pow(n1, n2, M))
    print(mod_pow(n1, n2, M))

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

"""
input:
5 8

output:
390625
"""

import sys


def mod_pow(x, n, _mod):
    res = 1
    while n > 0:
        # check n is odd number
        if n % 2:
            res = res * x % _mod
        x = pow(x, 2) % _mod
        n //= 2
    return res


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    n1, n2 = map(int, _input[0].split())
    M = 1000000007
    # print(pow(n1, n2, M))
    print(mod_pow(n1, n2, M))

# Buggy version:
d = 1000000007

def pow_rem(x, n):
    if n == 0:
        return x ** n % d
    if n % 2 == 0:
        return pow_rem(x, n // 2) ** 2 % d
    else:
        return ((pow_rem(x , n // 2) ** 2) * x) % d

def solve():
    m, n = map(int, input().split())
    print(pow_rem(m, n)

solve()

# Fixed version:
d = 1000000007

def pow_rem(x, n):
    if n == 0:
        return x ** n % d
    if n % 2 == 0:
        return pow_rem(x, n // 2) ** 2 % d
    else:
        return ((pow_rem(x , n // 2) ** 2) * x) % d

def solve():
    m, n = map(int, input().split())
    print(pow_rem(m, n))

solve()

# Buggy version:
m,n=map(int,input().split())
print(pow,m,n,1000000007)


# Fixed version:
m, n = map(int, input().split())
a = pow(m, n, 1000000007)
print(a)
Euler's Phi Function

For a given integer "n", count the totatives of "n", which are the positive integers less than or equal to "n" that are relatively prime to "n".

Input
An integer "n" (1 ≤ n ≤ 1000000000).

Output
The number of totatives in a line.

Sample Input 1
6

Sample Output 1
2

Sample Input 2
1000000

Sample Output 2
400000

# Buggy version:
import sys
def euler(a):
    i = 2
    res = a
    #standard = a
    while i * i <= a:
        if a % i == 0:
            res = res - res//i
            while a % i == 0:
                a //= i

        i += 1
   
    res = res - res//a

    return res


x = int(input())


print(euler(x))

# Fixed version:
import sys
def euler(a):
    i = 2
    res = a
    #standard = a
    while i * i <= a:
        if a % i == 0:
            res = res - res//i
            while a % i == 0:
                a //= i

        i += 1
    if a != 1:
        res = res - res//a

    return res


x = int(input())


print(euler(x))

# Buggy version:
p=1;a=[]
n=int(input());s=n**.5
while n%2==0 and n>3:a+=[2];n//=2
d=3
while s>d and n>d:
 if n%d==0:a+=[d];n//=d
 else:d+=2
a+=[n]
for f in set(a):
 p*=f**a.count(f)*(1-1/f)
print(int(p)


# Fixed version:
a=[]
n=int(input());s=n**.5
while n%2==0 and n>3:a+=[2];n//=2
d=3
while s>d and n>d:
 if n%d>0:d+=2
 else:a+=[d];n//=d
a+=[n]
p=1
for f in set(a):
 p*=f**a.count(f)*(1-1/f)
print(int(p))
Extended Euclid Algorithm

Given positive integers a and b, find the integer solution (x, y) to ax + by = gcd(a, b), where gcd(a, b) is the greatest common divisor of a and b.

Input
Two positive integers a and b are given separated by a space in a line.

Output
Print two integers x and y separated by a space. If there are several pairs of such x and y, print that pair for which |x| + |y| is the minimal (primarily) and x ≤ y (secondarily).

Constraints
1 ≤ a, b ≤ 10^9

Sample Input 1
4 12
Sample Output 1
1 0

Sample Input 2
3 8
Sample Output 2
3 -1

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


"""
input:
3 8

output:
3 -1
"""

import sys


def ext_euclid(a, b):
    if b == 0:
        return 1, 0, a
    else:
        x, y, q = ext_euclid(b, a % b)
        x, y = y, (x - (a // b) * y)
        return x, y


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    n1, n2 = map(int, _input[0].split())
    print(*ext_euclid(n1, n2))

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


"""
input:
3 8

output:
3 -1
"""

import sys


def ext_euclid(a, b):
    if b == 0:
        return 1, 0
    else:
        x, y = ext_euclid(b, a % b)
        x, y = y, (x - (a // b) * y)
        return x, y


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    n1, n2 = map(int, _input[0].split())
    print(*ext_euclid(n1, n2))

# Buggy version:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def solve():
    #a, b = map(int, input().split())
    a,b = 999999937, 123
    if a == b or a % b == 0:
        print(0, 1)
    elif b % a == 0:
        print(1, 0)
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        coe = [[1, 0], [0, 1]]
        while b != 1:
            quo = a // b
            coe_d1 = coe[1]
            coe_d2 = [coe[0][0] - coe[1][0] * quo, coe[0][1] - coe[1][1] * quo]
            coe = [coe_d1, coe_d2]
            a, b = b, a % b
        print(*coe[1])

solve()

# Fixed version:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def solve():
    a, b = map(int, input().split())
    if a == b or a % b == 0:
        print(0, 1)
    elif b % a == 0:
        print(1, 0)
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        coe = [[1, 0], [0, 1]]
        while b != 1:
            quo = a // b
            coe_d1 = coe[1]
            coe_d2 = [coe[0][0] - coe[1][0] * quo, coe[0][1] - coe[1][1] * quo]
            coe = [coe_d1, coe_d2]
            a, b = b, a % b
        print(*coe[1])

solve()

# Buggy version:
r,s=map(int,input().split())
a=d=1,b=c=0
while r:
 q=r//s
 r,s,a,c,b,d=s,r%s,c,a-q*c,d,b-q*d
print(a,b)


# Fixed version:
r,s=map(int,input().split())
a=d=1;b=c=0
while s:q=r//s;r,s,a,c,b,d=s,r%s,c,a-q*c,d,b-q*d
print(a,b)
Title: Addition of Big Integers

Given two integers A and B, compute the sum, A + B.

Input:
Two integers A and B separated by a space character are given in a line.

Output:
Print the sum in a line.

Constraints:
-1 x 10^100000 <= A, B <= 10^100000

Sample Input 1:
5 8

Sample Output 1:
13

Sample Input 2:
100 25

Sample Output 2:
125

Sample Input 3:
-1 1

Sample Output 3:
0

Sample Input 4:
12 -3

Sample Output 4:
9

# Buggy version:
sum([int(i) for i in input().split()])


# Fixed version:
print(sum([int(i) for i in input().split()]))

# Buggy version:
a,b = map(int,input.split())
print(a + b)


# Fixed version:
a,b=map(int, input().split())
print(a+b)
Title: Difference of Big Integers

Given two integers A and B, compute the difference, A - B.

Input:
Two integers A and B separated by a space character are given in a line.

Output:
Print the difference in a line.

Constraints:
-1 x 10^100000 <= A, B <= 10^100000

Sample Input 1:
5 8

Sample Output 1:
-3

Sample Input 2:
100 25

Sample Output 2:
75

Sample Input 3:
-1 -1

Sample Output 3:
0

Sample Input 4:
12 -3

Sample Output 4:
15

# Buggy version:
a, b = [int(i) for i in input().split()])
print(a-b)


# Fixed version:
a, b = [int(i) for i in input().split()]
print(a-b)