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

#GL0000063. Phân số kề một giá trị hữu tỉ (Rational Approximation)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Phân số kề một giá trị hữu tỉ (Rational Approximation)

Rational Approximation

Source: Library Checker

Version: Phuoc Hung OJ Extended

Problem Statement

Given positive integers N, x, y, let S contain all reduced positive fractions a/b with numerator and denominator at most N. Find the greatest element of S not exceeding x/y, and the smallest element of S not less than x/y. Use 0/1 for a nonexistent lower answer and 1/0 for a nonexistent upper answer. Comparisons must be mathematically exact.

Input

Three positive integers N x y.

Output

Four integers a b c d describing the lower and upper fractions.

Subtasks

  • Subtask 1 (20 points): 1≤N,x,y≤301\le N,x,y\le 30.
  • Subtask 2 (30 points): 1≤N,x,y≤1051\le N,x,y\le 10^5.
  • Subtask 3 (50 points): 1≤N,x,y≤1091\le N,x,y\le 10^9.

Examples

Input

5 7 3

Output

2 1 5 2

Explanation

Among fractions with numerator and denominator at most 5, 2/1 is the largest at most 7/3 and 5/2 is the smallest at least 7/3.