<|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.

508. Black-white balls
Time limit per test: 0.25 second(s)
Memory limit: 262144 kilobytes
input: standard
output: standard

n black and white balls were put into a bag. Petya doesn't know exactly how many black balls are there among them. He knows, however, that there are 0, 1,..., n black balls among all balls in the bag with equal probability.

Petya took l balls from the bag at random, and l1 of them turned out black, while l2 other turned out white (l1 + l2 = l). Now he wants to predict how many black balls were there initially in the bag. Of course, if l < n, he can't be sure in his prediction, but he wants to predict a segment [a, b], such that the amount k of black balls belongs to it with probability at least p.

You are given n, l1, l2 and p, and you must find such a and b that b - a is minimal possible. If there are several such pairs (a, b), choose the one with the smallest a.

Input
In the first line there are four integer numbers: 1 ≤ n ≤ 50 — the number of balls in the bag, 0 ≤ l1 ≤ n — the number of black balls out of the l balls that Petya took from the bag, 0 ≤ l2 ≤ n - l1 — the number of white balls that Petya took from the bag, 0 ≤ p ≤ 100 — the required confidence in percent.

Output
Output numbers a and b separated by a space, 0 ≤ a ≤ b ≤ n.

Example(s)
sample input
sample output
50 1 24 100
1 26

sample input
sample output
50 1 49 100
1 1

sample input
sample output
50 1 10 95
1 15

<|response|>
1. Abridged Problem Statement
There are `n` balls in a bag; `k` of them are black (unknown). Before any draw, Petya assumes every `k ∈ {0,1,…,n}` is equally likely.

Petya draws `l = l1 + l2` balls uniformly at random without replacement and observes `l1` black and `l2` white.

Given `n, l1, l2` and required confidence `p%`, output an integer interval `[a, b]` (`0 ≤ a ≤ b ≤ n`) such that:

- P(a ≤ k ≤ b | observed) ≥ p/100
- the length `b - a` is minimal
- if multiple, choose the one with smallest `a`

`n ≤ 50`.

2. Key Observations

1. Uniform prior over `k`:
   P(k) = 1/(n+1)

2. Likelihood is hypergeometric (drawing without replacement): if there are `k` black balls total, the probability to see exactly `l1` black and `l2` white is:
   P(data|k) = C(k,l1)*C(n-k,l2) / C(n,l1+l2)

3. Posterior is proportional to the numerator: by Bayes,
   P(k|data) ∝ C(k,l1)*C(n-k,l2)
   because the prior is constant in `k` and C(n,l) doesn't depend on `k`.

4. Since `n ≤ 50`, we can compute all C(n,r) easily, compute posterior for all `k = 0..n`, and brute force all intervals `[a,b]` in O(n²).

3. Full Solution Approach

Step A: Compute unnormalized posterior weights
For each `k = 0..n`, define w_k = C(k,l1)*C(n-k,l2). If `l1 > k` or `l2 > n-k`, then `w_k = 0`.

Step B: Normalize to a probability distribution
Let S = sum_{k=0}^n w_k, then post_k = w_k/S.

Step C: Fast interval probability queries (prefix sums)
Compute pref[i] = sum_{k=0}^{i-1} post_k. Then P([a,b]) = pref[b+1] - pref[a].

Step D: Find the shortest interval meeting the confidence
Brute force all intervals by increasing length `len = b-a`. Keep the first (shortest, then smallest `a`) whose mass is ≥ p. Use a tiny epsilon (e.g. `1e-15`) for floating comparisons.

Complexity: binomial table O(n²), all intervals O(n²); trivial for n ≤ 50.

4. C++ Solution
```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;
};

const long double eps = 1e-15;

int n, l1, l2;
long double p;

void read() {
    cin >> n >> l1 >> l2 >> p;
    p /= 100;
}

void solve() {
    // We can solve the problem with a fairly simple bayesian approach:
    //     Prior: uniform over k = 0..n, P(k) = 1/(n+1)
    //     Likelihood: P(data | k) = C(k, l1) * C(n-k, l2) / C(n, l1+l2).
    //
    // Then we have:
    //     P(k | data) = (P(data | k) * P(k)) / P(data)
    //
    // All terms apart from P(data | k) are constant w.r.t k, so we have:
    //     P(k | data) ~ C(k, l1) * C(n-k, l2).
    //
    // We know that sum_{k=0 to n} P(k | data) = 1, so we can directly calculate
    // the P(k | data) by demeaning.
    //
    // We need the smallest-length contiguous interval [a, b] such that:
    //    sum_{k=a to b} P(k | data) >= p
    //
    // Among all such minimal-length intervals, choose the one with least a.
    // This can be done by iterating over all intervals and using prefix sums
    // for the probabilities. We should be careful about what epsilon we use, as
    // the probabilities might differ by very small amounts. Using 1e-15 works.

    vector<vector<long double>> C(n + 1, vector<long double>(n + 1, 0));
    for(int i = 0; i <= n; i++) {
        C[i][0] = C[i][i] = 1;
        for(int j = 1; j < i; j++) {
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
        }
    }

    vector<long double> weight(n + 1, 0.0);
    long double total = 0.0;
    for(int k = 0; k <= n; k++) {
        int64_t c1 = (l1 <= k ? C[k][l1] : 0);
        int64_t c2 = (l2 <= n - k ? C[n - k][l2] : 0);
        weight[k] = (long double)c1 * c2;
        total += weight[k];
    }

    vector<long double> post(n + 1);
    for(int k = 0; k <= n; k++) {
        post[k] = weight[k] / total;
    }

    vector<long double> pref_p(n + 2, 0.0);
    for(int k = 0; k <= n; k++) {
        pref_p[k + 1] = pref_p[k] + post[k];
    }

    int best_len = n + 1;
    pair<int, int> ans = {0, n};
    for(int len = 0; len <= n; len++) {
        for(int a = 0; a + len <= n; a++) {
            int b = a + len;
            long double prob = pref_p[b + 1] - pref_p[a];
            if(prob + eps >= p) {
                if(len < best_len || (len == best_len && a < ans.first)) {
                    best_len = len;
                    ans = {a, b};
                }
            }
        }
    }

    cout << ans << '\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 Solution
```python
import sys
from math import comb

EPS = 1e-15

def solve() -> None:
    data = sys.stdin.read().strip().split()
    n = int(data[0])
    l1 = int(data[1])
    l2 = int(data[2])
    p = float(data[3]) / 100.0  # percent -> probability

    # 1) Unnormalized posterior weights:
    #    w_k = C(k,l1) * C(n-k,l2)
    # Using math.comb which is exact integer arithmetic.
    w = [0.0] * (n + 1)
    total = 0.0

    for k in range(n + 1):
        if l1 <= k and l2 <= (n - k):
            wk = comb(k, l1) * comb(n - k, l2)
        else:
            wk = 0
        w[k] = float(wk)
        total += w[k]

    # 2) Normalize into posterior probabilities post[k]
    post = [wk / total for wk in w] if total > 0 else [0.0] * (n + 1)

    # 3) Prefix sums: pref[i] = sum_{k=0..i-1} post[k]
    pref = [0.0] * (n + 2)
    for k in range(n + 1):
        pref[k + 1] = pref[k] + post[k]

    # 4) Find minimal-length interval [a,b] with posterior mass >= p
    best_len = n + 1
    best_a, best_b = 0, n

    for length in range(n + 1):
        for a in range(0, n - length + 1):
            b = a + length
            prob = pref[b + 1] - pref[a]
            if prob + EPS >= p:
                if length < best_len or (length == best_len and a < best_a):
                    best_len = length
                    best_a, best_b = a, b

    print(best_a, best_b)

if __name__ == "__main__":
    solve()
```
