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;
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		long a = long.Parse(input[0]);
		long b = long.Parse(input[1]);
    long x = 1;
    long y = 1;
    extGcd(a, b, ref x, ref y);
		Console.WriteLine(x + " " + y);//WriteLineをWriteとすると、改行なしで出力。
	}

  static long extGcd(long a, long b, ref long x, ref long y)
  {
    long answer = a;
    if(b == 0)
    {
      x = 1;
      y = 0;
    }else
    {
      answer = extGcd(b, a%b, ref y, ref x);
      y -= a/b*x;
    }
    return answer;
  }
  
}