<|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 eval(T) = floor(T/t1) + floor(T/t2).
b) Binary search on T in [0, 1e8] to find the minimal T with eval(T) ≥ n.
   - low = 0, high = 1e8.
   - while low ≤ high:
       mid = (low + high) // 2
       if eval(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 total = eval(ret). Let finalTime = ret.
d) If ret % t1 ≠ 0, Petya has a pending solution finishing at finishA = ret + (t1 − ret%t1).
   - total += 1
   - finalTime = max(finalTime, finishA)
e) If ret % t2 ≠ 0, Vasya has a pending solution finishing at finishB = ret + (t2 − ret%t2).
   - total += 1
   - finalTime = max(finalTime, finishB)
f) Output total and finalTime.

Time complexity: O(log(max_time)). Space: O(1).

4. C++ implementation with detailed comments
```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n, t1, t2;

void read() {
    cin >> n >> t1 >> t2;
}

int eval(int x) {
    return x / t1 + x / t2;
}

void solve() {
    // By time x the total number of fully written solutions is x / t1 + x / t2
    // (each author finishes one every t1, resp. t2 units), so eval(x) is
    // monotone in x. Binary search the earliest time `ret` at which at least n
    // solutions are finished; that is the moment the last started solution can
    // make the count reach n.
    //
    // Both authors keep working as long as the count is still below n when
    // they finish, so each may already have a solution in progress that
    // completes after `ret`. If `ret` is not a multiple of t1 (resp. t2), the
    // corresponding author had an unfinished solution at `ret` that adds one
    // to the count and finishes at the next multiple; the final finishing time
    // is the latest of those completions.

    int low = 0, high = 1e8, ret = 0;
    while(low <= high) {
        int mid = (low + high) / 2;
        if(eval(mid) >= n) {
            ret = mid;
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }

    int finish = ret, total = eval(ret);
    if(ret % t1 != 0) {
        finish = max(finish, ret + t1 - ret % t1);
        total++;
    }

    if(ret % t2 != 0) {
        finish = max(finish, ret + t2 - ret % t2);
        total++;
    }

    cout << total << ' ' << finish << '\n';
}

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

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}
```

5. Python implementation with detailed comments
```python
def main():
    import sys
    data = sys.stdin.read().split()
    n, t1, t2 = map(int, data)

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

    # Binary search minimal time 'ret' where finished(ret) >= n
    low, high = 0, 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()
```
