Problem:
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

a b

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 ≤ 109

Sample Input 1

4 12

Sample Output 1

1 0

Sample Input 2

3 8

Sample Output 2

3 -1

Solution in C# (judge verdict: Accepted)

using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Trim().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long gcd(long x, long y) => y == 0 ? x : gcd(y, x % y);

        //https://qiita.com/drken/items/b97ff231e43bce50199a
        static long  extGCD(long a, long b, out long x, out long y)
        {
            if (b == 0)
            {
                x = 1;
                y = 0;
                return a;
            }
            long d = extGCD(b, a % b, out y, out x);
            y -= a / b * x;
            return d;
        }
        static void Main(string[] args)
        {
            var ab = Sarray();
            long x, y;
            extGCD(ab[0], ab[1],out x, out y);
            WriteLine($"{x} {y}");
        }
    }
}