PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000299. Định lý số dư Trung Hoa tổng quát (General Chinese Remainder)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Định lý số dư Trung Hoa tổng quát (General Chinese Remainder)

General Chinese Remainder

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

Consider the two congruences with positive moduli:

x≡a(modn),x≡b(modm).x\equiv a\pmod n,\qquad x\equiv b\pmod m.

Unlike the coprime case, nn and mm need not be relatively prime. Thus, a common solution may not exist.

When a solution exists, all solutions differ by multiples of L=lcm⁡(n,m)L=\operatorname{lcm}(n,m). Find the unique representative xx satisfying 0≤x<L0\le x<L and output it together with LL. Otherwise, print the specified impossibility message.

Input

One line containing the four integers a,n,b,ma,n,b,m, in this order.

Output

If a solution exists, print x,Lx,L separated by one space. If none exists, print exactly no solution.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤501\le n,m\le 50; 0≤a<n0\le a<n; 0≤b<m0\le b<m; lcm⁡(n,m)≤1018\operatorname{lcm}(n,m)\le10^{18}.
  • Subtask 2 (30 points): 1≤n,m≤1000001\le n,m\le 100000; 0≤a<n0\le a<n; 0≤b<m0\le b<m; lcm⁡(n,m)≤1018\operatorname{lcm}(n,m)\le10^{18}.
  • Subtask 3 (50 points): 1≤n,m≤10000000001\le n,m\le 1000000000; 0≤a<n0\le a<n; 0≤b<m0\le b<m; lcm⁡(n,m)≤1018\operatorname{lcm}(n,m)\le10^{18}.

Examples

Examples 1

Input

2 4 4 6

Output

10 12

Explanation

The number 1010 leaves remainder 22 modulo 44 and remainder 44 modulo 66. The combined modulus is lcm⁡(4,6)=12\operatorname{lcm}(4,6)=12.

Examples 2

Input

1 4 2 6

Output

no solution

Explanation

Numbers congruent to 11 modulo 44 are odd, while those congruent to 22 modulo 66 are even. No common solution exists.