<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

551. Preparing Problem
Time limit per test: 1 second(s)
Memory limit: 262144 kilobytes
input: standard
output: standard



It is not easy to prepare a problem for a programming contest. Petya and Vasya decided that problem "A+B" needs at least n distinct solutions to be written. It doesn't matter how many solutions each of them will write, they need to write at least n solutions in total. We know that Petya needs t1 units of time to write a solution, and Vasya needs t2 units of time. They start to work simultaneously at time 0. Thus, for example, Petya finishes writing his first solution at time t1, his second solution at 2 · t1 and so on.

Petya and Vasya are working by the same algorithm. Each time Petya (Vasya) finishes writing a solution, he checks on how many solutions have already been written up to the current time moment t. Ready solutions are the solutions that have been fully written by this time. The solutions that were fully finished exactly at time t are also considered ready. If the number of such solutions is strictly less than n, then Petya (Vasya) starts writing the next solution. If a member of the jury began working on a problem, he doesn't stop working under any circumstances, and he will surely finish it.

Petya and Vasya realize that if they act on this algorithm, they will not necessarily write exactly n solutions in total. Maybe they'll write more solutions.

Considering that Petya and Vasya work non-stop, find, how many solutions they wrote in total and the moment when the latest solution was finished. The latest solution is one which was finished last.

Input
The only input line contains three integers n, t1 and t2 (1 ≤ n, t1, t2 ≤ 5000).

Output
Print two integers — m and f, where m is the number of written solutions, and f is the moment when the last solution was finished.

Example(s)
sample input
sample output
5 2 3
5 6

sample input
sample output
5 2 4
6 8

sample input
sample output
3 30 50
4 100



Note
In the first sample Petya finished his solutions at time 2, 4 and 6, and Vasya — at time 3 and 6. They finished writing their last solutions simultaneously, at time 6, and at this exact moment they already had the total of 5 written solutions and stopped working.

<|response|>
1. Abridged problem statement  
Given three integers n, t1, t2. Two writers, Petya (speed t1) and Vasya (speed t2), start at time zero. Petya finishes solutions at times t1, 2·t1, 3·t1, …; Vasya at t2, 2·t2, 3·t2, …. Whenever one of them finishes a solution at time T, he looks at how many solutions are completed up to T (including those finishing exactly at T). If that total is strictly less than n, he immediately starts another solution; otherwise he stops. Already started solutions are never aborted. Compute:  
  • m = total number of solutions they eventually write (may exceed n),  
  • f = the time when the very last solution is finished.

2. Key observations  
- By time T, Petya has completed floor(T/t1) solutions and Vasya floor(T/t2).  
- We want to find the earliest time T such that floor(T/t1) + floor(T/t2) ≥ n. Let this T be the stopping checkpoint.  
- At exactly time T, they may finish multiple solutions (some exactly at T). After counting those, total ≥ n so nobody starts a new job exactly at T.  
- However, if T is not a multiple of t1, Petya must have been in the middle of a solution at time T (because his last finish was before T and total then was < n), so he will finish one more at time T + (t1 − T%t1). Same for Vasya if T%t2 ≠ 0.  
- Those in-progress solutions will also finish, adding to the final count and possibly pushing the final finish time beyond T.

3. Full solution approach  
a) Define finished(T) = floor(T/t1) + floor(T/t2).  
b) Binary search on T in the range [0, n·min(t1, t2)] to find the minimal T with finished(T) ≥ n.  
   - low = 0, high = n · min(t1, t2).  
   - while low ≤ high:  
       mid = (low + high) // 2  
       if finished(mid) ≥ n: ret = mid; high = mid − 1  
       else: low = mid + 1  
   - After the loop, ret is the minimal time when at least n solutions are done.  
c) Let baseCount = finished(ret). Let finalTime = ret, totalCount = baseCount.  
d) If ret % t1 ≠ 0, Petya has a pending solution finishing at finishA = ret + (t1 − ret%t1).  
   - totalCount += 1  
   - finalTime = max(finalTime, finishA)  
e) If ret % t2 ≠ 0, Vasya has a pending solution finishing at finishB = ret + (t2 − ret%t2).  
   - totalCount += 1  
   - finalTime = max(finalTime, finishB)  
f) Output totalCount and finalTime.

Time complexity: O(log(n·min(t1,t2))). Space: O(1).

4. C++ implementation with detailed comments  
// Preparing Problem (p551)  
#include <bits/stdc++.h>  
using namespace std;

// Count how many solutions are completed by time x
inline int finished(int x, int t1, int t2) {
    return x / t1 + x / t2;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, t1, t2;
    cin >> n >> t1 >> t2;

    // Binary search for the minimal time 'ret' where finished(ret) >= n
    int low = 0;
    int high = n * min(t1, t2);
    int ret = high;

    while (low <= high) {
        int mid = (low + high) / 2;
        if (finished(mid, t1, t2) >= n) {
            ret = mid;
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }

    // Base count of solutions done by time ret
    int baseCount = finished(ret, t1, t2);
    int totalCount = baseCount;
    int finalTime = ret;

    // Check if Petya has a pending solution
    int r1 = ret % t1;
    if (r1 != 0) {
        // He must finish the current solution at next multiple of t1
        int finishA = ret + (t1 - r1);
        totalCount += 1;
        finalTime = max(finalTime, finishA);
    }

    // Check if Vasya has a pending solution
    int r2 = ret % t2;
    if (r2 != 0) {
        int finishB = ret + (t2 - r2);
        totalCount += 1;
        finalTime = max(finalTime, finishB);
    }

    // Output the total number of solutions and the last finish time
    cout << totalCount << " " << finalTime << "\n";
    return 0;
}

5. Python implementation with detailed comments  
# Preparing Problem (p551)
import sys

def main():
    data = sys.stdin.read().split()
    n, t1, t2 = map(int, data)

    # Function to count solutions finished by time x
    def finished(x):
        return x // t1 + x // t2

    # Binary search on time
    low = 0
    high = n * min(t1, t2)
    ret = high

    while low <= high:
        mid = (low + high) // 2
        if finished(mid) >= n:
            ret = mid
            high = mid - 1
        else:
            low = mid + 1

    # Count how many done by ret
    baseCount = finished(ret)
    totalCount = baseCount
    finalTime = ret

    # Pending solution for Petya?
    rem1 = ret % t1
    if rem1 != 0:
        finishA = ret + (t1 - rem1)
        totalCount += 1
        finalTime = max(finalTime, finishA)

    # Pending solution for Vasya?
    rem2 = ret % t2
    if rem2 != 0:
        finishB = ret + (t2 - rem2)
        totalCount += 1
        finalTime = max(finalTime, finishB)

    # Print results
    print(totalCount, finalTime)

if __name__ == "__main__":
    main()

Explanation of key steps:  
- We never simulate each solution one by one; instead we jump directly to the critical time T when the count reaches n.  
- Binary search exploits the monotonicity of finished(T).  
- Any in-progress solution at T must complete, because the writer never abandons a started solution.