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

#GL0000303. Vòng tròn các nhà hàng (The Beatles)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Vòng tròn các nhà hàng (The Beatles)

The Beatles

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A circular road passes through n⋅kn\cdot k cities numbered from 11 to n⋅kn\cdot k. Consecutive cities are one kilometer apart. Exactly nn restaurants are located in cities 1,k+1,2k+1,…,(n−1)k+11,k+1,2k+1,\ldots,(n-1)k+1.

Sergey starts in a city ss and always travels in one fixed direction around the circle. He stops after every ll kilometers, where ll is a positive integer. His trip ends when a stop brings him back to ss.

He has forgotten both ss and ll, but remembers that the shortest distance from ss to a restaurant was aa kilometers, and the shortest distance from his first stopping city to a restaurant was bb kilometers. Both clockwise and counterclockwise distances are allowed when measuring distance to a restaurant.

Determine the minimum and maximum possible numbers of stops until he returns to ss. Include the final stop at ss but do not count the initial starting position.

Input

The first line contains n,kn,k: the number of restaurants and the distance in kilometers between consecutive restaurants.

The second line contains a,ba,b: the shortest distances to a restaurant from the starting and first stopping cities.

Output

Print two integers x,yx,y on one line: the minimum and maximum possible numbers of stops.

Subtasks

  • Subtask 1 (20 points): 1≤n,k≤201\le n,k\le20; 0≤a,b≤⌊k/2⌋0\le a,b\le\lfloor k/2\rfloor.
  • Subtask 2 (30 points): 1≤n,k≤20001\le n,k\le2000; 0≤a,b≤⌊k/2⌋0\le a,b\le\lfloor k/2\rfloor.
  • Subtask 3 (50 points): 1≤n,k≤1051\le n,k\le10^5; 0≤a,b≤⌊k/2⌋0\le a,b\le\lfloor k/2\rfloor.

Examples

Example 1

Input

2 3
1 1

Output

1 6

Explanation

Restaurants are in cities 11 and 44; possible starting and first-stop cities are 2,3,5,62,3,5,6. Returning on the first stop is possible, so the minimum is 11. A step of 11 kilometer also fits the observations and needs all 66 stops before returning.

Example 2

Input

3 2
0 0

Output

1 3

Explanation

Since a=b=0a=b=0, both observed cities contain restaurants. The step is a multiple of 22 on a circle of length 66. Returning in 11 stop is possible; traversing all three restaurant locations needs 33 stops.

Example 3

Input

1 10
5 3

Output

5 5

Explanation

There is one restaurant in city 11. The starting city is 66; the first stop can be 44 or 88, giving a positive step congruent to 88 or 22 modulo 1010. Both need 10/gcd⁡(10,2)=510/\gcd(10,2)=5 stops to return.