prithivMLmods/Coder-Stat huggingface dataset:
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i, m, n) for (lli i = m; i < n; i++)
#define rrep(i, m, n) for (lli i = m - 1; i >= n; i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(), N.end()), N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(), n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K, L, N, S) vector<L> K(N, S)
#define DV(K, L, N, M, R) vector<vector<L>> K(N, vector<L>(M, R))
#define pint pair<lli, lli>
#define Lower(v, X) lower_bound(v.begin(), v.end(), X) - v.begin();
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
vector<lli> divisor(lli N) {
  vector<lli> res;
  for (int i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      res.push_back(i);
      if (i * i != N)
        res.push_back(N / i);
    }
  }
  Sort(res);
  return res;
}
int main() {
  lli A, B, C, D, E, F, N, M, K, L, R, X, Y, H, W, sum = 0, num = 0, flag = 0;
  string S, T;
  cin >> N;
  auto Xq = divisor(N);
  M = Xq.size();
  if (M == 1)
    Y = Xq[0];
  else if (M % 2 == 1)
    Y = Xq[M / 2];
  else {
    Y = Xq[M / 2];
    L = Xq[M / 2 - 1];
    Y = max(L, Y);
  }
  sum = 1;
  while (Y > 9) {
    Y /= 10;
    sum++;
  }
  Out(sum);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i, m, n) for (lli i = m; i < n; i++)
#define rrep(i, m, n) for (lli i = m - 1; i >= n; i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(), N.end()), N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(), n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K, L, N, S) vector<L> K(N, S)
#define DV(K, L, N, M, R) vector<vector<L>> K(N, vector<L>(M, R))
#define pint pair<lli, lli>
#define Lower(v, X) lower_bound(v.begin(), v.end(), X) - v.begin();
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
vector<lli> divisor(lli N) {
  vector<lli> res;
  for (lli i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      res.push_back(i);
      if (i * i != N)
        res.push_back(N / i);
    }
  }
  Sort(res);
  return res;
}
int main() {
  lli A, B, C, D, E, F, N, M, K, L, R, X, Y, H, W, sum = 0, num = 0, flag = 0;
  string S, T;
  cin >> N;
  auto Xq = divisor(N);
  M = Xq.size();
  if (M == 1)
    Y = Xq[0];
  else if (M % 2 == 1)
    Y = Xq[M / 2];
  else {
    Y = Xq[M / 2];
    L = Xq[M / 2 - 1];
    Y = max(L, Y);
  }
  sum = 1;
  while (Y > 9) {
    Y /= 10;
    sum++;
  }
  Out(sum);
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll dig(ll n) {
  ll res = 0;
  while (n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

ll f(ll a, ll b) { return max(dig(a), dig(b)); }

vector<ll> enum_div(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
    }
  }
  return ret;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 100000000000;
  rep(i, enum_div(n).size()) {
    ll a = f(enum_div(n).at(i), n / enum_div(n).at(i));
    ans = min(ans, a);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll dig(ll n) {
  ll res = 0;
  while (n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

ll f(ll a, ll b) { return max(dig(a), dig(b)); }

vector<ll> enum_div(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
    }
  }
  return ret;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 100000000000;
  vector<ll> vec;
  vec = enum_div(n);
  rep(i, vec.size()) {
    ll a = f(vec.at(i), n / vec.at(i));
    ans = min(ans, a);
  }
  cout << ans << endl;
  return 0;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  int ans = 10;
  for (long long int i = 1; i <= n; i++) {
    if (n % i != 0)
      continue;
    long long int a = i;
    long long int b = n / i;
    string s = to_string(a);
    string m = to_string(b);
    int f = max(s.size(), m.size());
    ans = min(ans, f);
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  int ans = 10;
  for (long long int i = 1; i <= sqrt(n); i++) {
    if (n % i != 0)
      continue;
    long long int a = i;
    long long int b = n / i;
    string s = to_string(a);
    string m = to_string(b);
    int f = max(s.size(), m.size());
    ans = min(ans, f);
  }
  cout << ans;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

void fnInput(int64_t &rnNum) { cin >> rnNum; }

int fnDigitsCheck(int64_t nDivisor) {
  int nDigitCnt = 0;
  while (nDivisor) {
    nDigitCnt++;
    nDivisor /= 10;
  }

  return nDigitCnt;
}

int fnMultiplCheck(int64_t nNum) {
  int nMinDigit = fnDigitsCheck(nNum);

  for (int n = 1; n * n <= nNum; n++) {
    if (nNum % n != 0)
      continue;
    int64_t nOtr = nNum / n;
    nMinDigit = min(nMinDigit, fnDigitsCheck(nOtr));
  }
  return nMinDigit;
}

int main() {
  int64_t nNum;

  fnInput(nNum);
  cout << fnMultiplCheck(nNum) << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

void fnInput(int64_t &rnNum) { cin >> rnNum; }

int fnDigitsCheck(int64_t nDivisor) {
  int nDigitCnt = 0;
  while (nDivisor) {
    nDigitCnt++;
    nDivisor /= 10;
  }

  return nDigitCnt;
}

int fnMultiplCheck(int64_t nNum) {
  int nMinDigit = fnDigitsCheck(nNum);

  for (int64_t n = 1; n * n <= nNum; n++) {
    if (nNum % n != 0)
      continue;
    int64_t nOtr = nNum / n;
    nMinDigit = min(nMinDigit, fnDigitsCheck(nOtr));
  }
  return nMinDigit;
}

int main() {
  int64_t nNum;

  fnInput(nNum);
  cout << fnMultiplCheck(nNum) << endl;

  return 0;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

int digitdf(long long a, long long b) {
  int ac = 0;
  int bc = 0;
  while (a > 0) {
    a /= 10;
    ac++;
  }
  while (b > 0) {
    b /= 10;
    bc++;
  }
  // cout << "[" << ac << "," << bc << "]" << endl;
  return max(ac, bc);
}
int main() {
  long long n;
  cin >> n;
  for (long long i = sqrt(n); i <= n; i++) {
    if ((n / i) * i == n) {
      cout << digitdf(i, n / i) << endl;
      break;
    }
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

int digitdf(long long a, long long b) {
  int ac = 0;
  int bc = 0;
  while (a > 0) {
    a /= 10;
    ac++;
  }
  while (b > 0) {
    b /= 10;
    bc++;
  }
  // cout << "[" << ac << "," << bc << "]" << endl;
  return max(ac, bc);
}
int main() {
  long long n;
  cin >> n;
  for (long long i = sqrt(n); i >= 1; i--) {
    if ((n / i) * i == n) {
      cout << digitdf(i, n / i) << endl;
      break;
    }
  }

  return 0;
}
Problem p03775 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
int cnt_digits(ll n) {
  int digits = 0;

  while (n > 0) {
    n /= 10;
    digits++;
  }

  return digits;
}
int main(void) {
  ll n;
  cin >> n;
  int ans = cnt_digits(n);
  for (ll a = 0; a * a <= n; a++) {
    if (n % a != 0)
      continue;
    ll b = n / a;
    int iwa = max(cnt_digits(a), cnt_digits(b));
    if (iwa < ans) {
      ans = iwa;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
int cnt_digits(ll n) {
  int digits = 0;

  while (n > 0) {
    n /= 10;
    digits++;
  }

  return digits;
}
int main(void) {
  ll n;
  cin >> n;
  int ans = cnt_digits(n);
  for (ll a = 1; a * a <= n; a++) {
    if (n % a != 0)
      continue;
    ll b = n / a;
    int iwa = max(cnt_digits(a), cnt_digits(b));
    if (iwa < ans) {
      ans = iwa;
    }
  }
  cout << ans << endl;
}
Problem p03775 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  long N;
  cin >> N;

  long a, b, f;
  long ans = 100;

  for (long i = 0; i < 100001; i++) {
    if (N % i == 0) {
      a = i;
      b = N / i;
      string A = to_string(a);
      string B = to_string(b);
      f = max(A.length(), B.length());

      if (ans > f)
        ans = f;
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  long N;
  cin >> N;

  long a, b, f;
  long ans = 100;

  for (long i = 1; i < 100001; i++) {
    if (N % i == 0) {
      a = i;
      b = N / i;
      string A = to_string(a);
      string B = to_string(b);
      f = max(A.length(), B.length());

      if (ans > f)
        ans = f;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;

int scale(long long a, long long b) {
  int acount = 0;
  int bcount = 0;
  while (a > 0) {
    acount++;
    a /= 10;
  }
  while (b > 0) {
    bcount++;
    b /= 10;
  }
  return max(acount, bcount);
}
int main() {
  int ans = 1e9;
  long long N;
  cin >> N;
  for (long long i = 1; i <= N; ++i) {
    for (long long j = i; j <= N; ++j) {
      if (i * j == N) {
        ans = min(ans, scale(i, j));
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;

int scale(long long a, long long b) {
  int acount = 0;
  int bcount = 0;
  while (a > 0) {
    acount++;
    a /= 10;
  }
  while (b > 0) {
    bcount++;
    b /= 10;
  }
  return max(acount, bcount);
}
int main() {
  int ans = 1e9;
  long long N;
  cin >> N;
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i != 0)
      continue;
    else
      ans = min(ans, scale(i, N / i));
  }
  cout << ans << endl;
  return 0;
}
Problem p03775 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  int ans = n;
  for (int i = 0; i < sqrt(n); i++) {
    if (n % i == 0) {
      int j = n / i;
      int a = 0;
      for (int k = 0; k < 11; k++) {
        if (j / 10 == 0) {
          a++;
          ans = min(ans, a);
          break;
        }
        a++;
        j /= 10;
      }
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  int ans = 20;
  for (int i = 1; i < sqrt(n) + 1; i++) {
    if (n % i == 0) {
      int j = n / i;
      int a = 0;
      for (int k = 0; k < 11; k++) {
        if (j / 10 == 0) {
          a++;
          ans = min(ans, a);
          break;
        }
        a++;
        j /= 10;
      }
    }
  }
  cout << ans << endl;
}
Problem p03775 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {

  int64_t n;
  cin >> n;

  int64_t x = 0;

  while (x * 2 <= n) {
    x++;
  }

  int64_t a;

  for (int64_t i = x - 1; i >= 0; i--) {
    if (n % i == 0) {
      a = i;
      break;
    }
  }

  int64_t b;
  b = n / a;

  int answer = 0;

  while (b > 0) {
    b /= 10;
    answer++;
  }

  cout << answer << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {

  int64_t n;
  cin >> n;

  int64_t x = 0;

  while (x * x <= n) {
    x++;
  }

  int64_t a;

  for (int64_t i = x - 1; i >= 0; i--) {
    if (n % i == 0) {
      a = i;
      break;
    }
  }

  int64_t b;
  b = n / a;

  int answer = 0;

  while (b > 0) {
    b /= 10;
    answer++;
  }

  cout << answer << endl;
}
Problem p03775 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  ll n;
  cin >> n;
  long long int temp = 0;
  long long int limit = sqrt(n);
  for (long long int i = 0; i <= limit; i++) {
    if (n % i == 0)
      temp = i;
  }
  ll temptwo = n / temp;
  ll ans = 0;
  while (temptwo > 0) {
    temptwo /= 10;
    ans += 1;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  ll n;
  cin >> n;
  ll temp = 0;
  ll limit = sqrt(n);
  for (ll i = 1; i <= limit; i++) {
    if (n % i == 0)
      temp = i;
  }
  ll temptwo = n / temp;
  ll ans = 0;
  while (temptwo > 0) {
    temptwo /= 10;
    ans += 1;
  }
  cout << ans << endl;
}
Problem p03775 (Python)

Buggy submission (status: Runtime Error):
#!/usr/bin/env python3


def div_pairs(n):
    for i in range(1, n):
        if i * i > n:
            break
        d, m = divmod(n, i)
        if m == 0:
            yield (i, d)


def f(a, b):
    return max(len(str(a)), len(str(b)))


def solve(n):
    return min(f(a, b) for a, b in div_pairs(n))


def main():
    print(solve(int(input())))


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3


def div_pairs(n):
    for i in range(1, n + 1):
        if i * i > n:
            break
        d, m = divmod(n, i)
        if m == 0:
            yield (i, d)


def f(a, b):
    return max(len(str(a)), len(str(b)))


def solve(n):
    return min(f(a, b) for a, b in div_pairs(n))


def main():
    print(solve(int(input())))


if __name__ == "__main__":
    main()
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long int n;
  cin >> n;

  long long int a, b, f, min = 10000000000;

  // 整数/0をやるとfloatin point exceptionのエラーが出るのでi=1から始める
  for (int i = 1; i * i <= n; i++) {
    f = 1;
    if (n % i == 0) {
      a = i;
      b = n / a;
      while (b > 0) {
        if (b / 10 != 0) {
          f++;
        }
        b /= 10;
      }
      if (f < min)
        min = f;
    }
  }

  cout << min << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long int n;
  cin >> n;

  long long int a, b, f, min = 10000000000;

  // 整数/0をやるとfloatin point exceptionのエラーが出るのでi=1から始める
  // i*i<=nでやってもiはなぜかこの条件をすり抜ける
  for (int i = 1; i <= n / i; i++) {
    f = 1;
    if (n % i == 0) {
      a = i;
      b = n / a;
      while (b > 0) {
        if (b / 10 != 0) {
          f++;
        }
        b /= 10;
      }
      if (f < min)
        min = f;
    }
  }

  cout << min << endl;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <string>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long N;
  cin >> N;
  long long mx = 0;
  long long temp, answer;
  for (long long i = 1; i <= N; ++i) {
    if (N % i == 0) {
      if (i <= (N / i)) {
        temp = mx;
        mx = max(to_string(N / i).length(), to_string(i).length());
        if (temp == 0) {
          answer = mx;
        } else {
          answer = min(mx, answer);
        }
      } else {
        break;
      }
    }
  }
  cout << answer << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <string>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long N;
  cin >> N;
  long long mx = 0;
  long long temp, answer;
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      if (i <= (N / i)) {
        temp = mx;
        mx = max(to_string(N / i).length(), to_string(i).length());
        if (temp == 0) {
          answer = mx;
        } else {
          answer = min(mx, answer);
        }
      } else {
        break;
      }
    }
  }
  cout << answer << endl;
  return 0;
}
Problem p03775 (Python)

Buggy submission (status: Time Limit Exceeded):
import math

N = int(input())

min_length = -1
for i in range(int(math.sqrt(N))):
    for j in range(i + 1):
        A = j + 1
        if N % A == 0:
            B = int(N / A)
            len_a = len(str(A))
            len_b = len(str(B))
            length = len_a if len_a >= len_b else len_b
            if min_length == -1 or length < min_length:
                # print("len:{}, A:{}, B:{}".format(length, A, B))
                min_length = length
print(min_length)


Fixed submission:
import math

N = int(input())

min_length = -1
for A in range(1, int(math.sqrt(N)) + 1, 1):
    if N % A == 0:
        B = int(N / A)
        len_a = len(str(A))
        len_b = len(str(B))
        length = len_a if len_a >= len_b else len_b
        if min_length == -1 or length < min_length:
            # print("len:{}, A:{}, B:{}".format(length, A, B))
            min_length = length
print(min_length)
Problem p03775 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = 1
b = 1
mx = 10**10
while a <= b and a <= n:
    if n % a == 0:
        b = int(n / a)
        mx = min(mx, max(a, b))
    a += 1
print(len(str(mx)))


Fixed submission:
n = int(input())
a = 1
b = 1
mx = 10**10
while a <= b and a <= 10**5:
    if n % a == 0:
        b = int(n / a)
        mx = min(mx, max(a, b))
    a += 1
print(len(str(mx)))
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n;
  cin >> n;
  int ans = 1e9;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ll a = i;
      ll b = n / i;
      string sa = to_string(a);
      string sb = to_string(b);

      int f = max(sa.length(), sb.length());
      ans = min(ans, f);
    }
  }
  cout << ans << '\n';
  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n;
  cin >> n;
  int ans = 1e9;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ll a = i;
      ll b = n / i;
      string sa = to_string(a);
      string sb = to_string(b);

      int f = max(sa.length(), sb.length());
      ans = min(ans, f);
    }
  }
  cout << ans << '\n';
  return 0;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int INF = 100000000;
const int MOD = 1000000007;
std::vector<long> enum_div(long n) // nの約数を列挙
{
  std::vector<long> ret;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i != 1 && i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  return ret;
}
int main() {
  long n;
  std::cin >> n;
  vector<long> v;
  v = enum_div(n);
  sort(all(v));
  int mi = 10000;
  for (int i = 0; i < v.size() / 2 + 1; i++) {
    /* code */
    long a, b;
    a = n / v[i];
    b = n / a;
    if (mi > max((int)log10(a), (int)log10(b)) + 1)
      mi = max((int)log10(a), (int)log10(b)) + 1;
  }
  std::cout << mi << std::endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int INF = 100000000;
const int MOD = 1000000007;
std::vector<long> enum_div(long n) // nの約数を列挙
{
  std::vector<long> ret;
  for (long i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i != 1 && i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  return ret;
}
int main() {
  long n;
  std::cin >> n;
  vector<long> v;
  v = enum_div(n);
  sort(all(v));
  int mi = 10000;
  for (int i = 0; i < v.size() / 2 + 1; i++) {
    /* code */
    long a, b;
    a = n / v[i];
    b = n / a;
    if (mi > max((int)log10(a), (int)log10(b)) + 1)
      mi = max((int)log10(a), (int)log10(b)) + 1;
  }
  std::cout << mi << std::endl;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

int GetDigit(long long int num) {
  long long int digit = 0;
  while (num > 0) {
    num /= 10;
    digit++;
  }
  return digit;
}

int main(void) {

  long long int a;

  cin >> a;

  int abc = GetDigit(a);

  for (int i = 1; i * i <= a; i++) {

    if (a % i != 0)
      continue;

    const long long int j = a / i;

    const int def = max(GetDigit(i), GetDigit(j));

    if (abc > def) {
      abc = def;
    }
  }

  cout << abc << endl;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

int GetDigit(long long int num) {
  long long int digit = 0;
  while (num > 0) {
    num /= 10;
    digit++;
  }
  return digit;
}

int main(void) {

  long long int a;

  cin >> a;

  int abc = GetDigit(a);

  for (long long int i = 1; i * i <= a; i++) {

    if (a % i != 0)
      continue;

    const long long int j = a / i;

    const int def = max(GetDigit(i), GetDigit(j));

    if (abc > def) {
      abc = def;
    }
  }

  cout << abc << endl;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  // 入力
  int64_t N;
  cin >> N;

  // 1から割っていてNを二つに分ける
  // 桁数の最小値を更新していく
  int64_t res = 99;
  for (int64_t a = 1; a <= N; a++) {
    if (N % a == 0) {
      int64_t b = N / a;
      int c = max(to_string(a).length(), to_string(b).length());
      if (c < res) {
        res = c;
      }

      // A, B の桁数が同じか、A の方が大きくなったら終了（計算コスト削減）
      // if(to_string(a).length() >= to_string(b).length())
      if (a >= b) {
        // cout << "a: " << a << " b: " << b << endl;
        break;
      }
    }
  }

  // 出力
  cout << res << endl;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  // 入力
  int64_t N;
  cin >> N;

  // 1から割っていてNを二つに分ける
  // 桁数の最小値を更新していく
  int64_t res = 99;
  for (int64_t a = 1; a <= N; a++) {
    if (N % a == 0) {
      int64_t b = N / a;
      int c = max(to_string(a).length(), to_string(b).length());
      if (c < res) {
        res = c;
      }
    }
    // A, B の桁数が同じか、A の方が大きくなったら終了（計算コスト削減）
    // if(to_string(a).length() >= to_string(b).length())
    if (to_string(a).length() >= to_string(N).length() / 2 + 2) {
      // cout << "a: " << a << " b: " << b << endl;
      break;
    }
  }

  // 出力
  cout << res << endl;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int Digits(ll x) {
  int ans = 0;
  while (x != 0) {
    x /= 10;
    ans++;
  }
  return ans;
}

int Fanction(ll a, ll b) {
  int ans = max(Digits(a), Digits(b));
  return ans;
}

int main() {
  ll N;
  cin >> N;
  ll m = sqrtl(N);
  for (ll i = m; i <= N; i++) {
    if (N % i == 0) {
      int ans = Fanction(i, N / i);
      cout << ans << endl;
      return 0;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int Digits(ll x) {
  int ans = 0;
  while (x != 0) {
    x /= 10;
    ans++;
  }
  return ans;
}

int Fanction(ll a, ll b) {
  int ans = max(Digits(a), Digits(b));
  return ans;
}

int main() {
  ll N;
  cin >> N;
  ll m = sqrtl(N);
  for (ll i = m; i > 0; i--) {
    if (N % i == 0) {
      int ans = Fanction(i, N / i);
      cout << ans << endl;
      return 0;
    }
  }
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {
  long long int n, k = 0, ans = 0;
  cin >> n;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      k = n / i;
    }
  }
  for (int i = 1; i < 10000; i++) {
    if (k < 10) {
      ans = i;
      break;
    }
    k = k / 10;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {
  long long int n, k = 0, ans = 0;
  cin >> n;
  for (long long int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      k = n / i;
    }
  }
  for (int i = 1; i < 10000; i++) {
    if (k < 10) {
      ans = i;
      break;
    }
    k = k / 10;
  }
  cout << ans << endl;
  return 0;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a = sqrt(n);
  while (n % a)
    a++;
  int d = 0;
  while (a) {
    d++;
    a /= 10;
  }
  cout << d << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a = sqrt(n);
  while (n % a)
    a--;
  a = n / a;
  int d = 0;
  while (a) {
    d++;
    a /= 10;
  }
  cout << d << endl;
  return 0;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string>

using namespace std;

int MOD = 1000000007;

int main() {
  long long N, sq = 0;
  cin >> N;
  sq = sqrt(N);
  while (sq != 0) {
    if (N % sq == 0) {
      long long co = 0, cou = 0;
      N = N / sq;
      while (N != 0) {
        N /= 10;
        cou += 1;
      }
      while (sq != 0) {
        sq /= 10;
        co += 1;
      }
      cout << max(co, cou) << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string>

using namespace std;

int MOD = 1000000007;

int main() {
  long long N, sq = 0;
  cin >> N;
  sq = sqrt(N);
  while (sq != 0) {
    if (N % sq == 0) {
      long long co = 0, cou = 0;
      N = N / sq;
      while (N != 0) {
        N /= 10;
        cou += 1;
      }
      while (sq != 0) {
        sq /= 10;
        co += 1;
      }
      cout << max(co, cou) << endl;
      return 0;
    }
    sq -= 1;
  }
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll F(ll a, ll b) {
  string s;
  stringstream ss;
  ss.clear();
  ss << a;
  ss >> s;
  ll l = s.size();
  s = "";
  ss.clear();
  ss << b;
  ss >> s;
  return max(l, ll(s.size()));
}
int main() {
  ll a, b, i = 0x3f3f3f3f, n;
  cin >> n;
  for (a = 1; a <= n; a++) {
    if (n % a != 0) {
      continue;
    }
    b = n / a;
    i = min(i, F(a, b));
  }
  cout << i;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll F(ll a, ll b) {
  string s;
  stringstream ss;
  ss.clear();
  ss << a;
  ss >> s;
  ll l = s.size();
  s = "";
  ss.clear();
  ss << b;
  ss >> s;
  return max(l, ll(s.size()));
}
int main() {
  ll a, b, i = 0x3f3f3f3f, n;
  cin >> n;
  for (a = 1; a <= sqrt(n); a++) {
    if (n % a != 0) {
      continue;
    }
    b = n / a;
    i = min(i, F(a, b));
  }
  cout << i;
  return 0;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

int Digits(llong num) {
  int cnt = 0;
  while (num > 0) {
    num / 10;
    cnt++;
  }
  return cnt;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  llong N;
  cin >> N;
  llong A, B;
  int ans = Digits(N);
  for (A = 1; A * A <= N; A++) {
    if (N % A != 0)
      continue;
    B = N / A;
    const int cur = max(Digits(A), Digits(B));

    if (ans > cur)
      ans = cur;
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

int Digits(llong num) {
  int cnt = 0;
  while (num > 0) {
    num /= 10;
    cnt++;
  }
  return cnt;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  llong N;
  cin >> N;
  llong A, B;
  int ans = Digits(N);
  for (A = 1; A * A <= N; A++) {
    if (N % A != 0)
      continue;
    B = N / A;
    const int cur = max(Digits(A), Digits(B));

    if (ans > cur)
      ans = cur;
  }

  cout << ans << endl;
  return 0;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define MOD 1000000007
#define all(c) c.begin(), c.end()
#define peek(v)                                                                \
  for (auto i : v)                                                             \
    cout << i << ' ';

void solve() {
  ll n;
  cin >> n;
  int d = sqrt(n);
  while (n % d != 0)
    d++;
  int digits = (int)log10(d) + 1;
  cout << digits;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  cerr << "\n\n~" << 500 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define MOD 1000000007
#define all(c) c.begin(), c.end()
#define peek(v)                                                                \
  for (auto i : v)                                                             \
    cout << i << ' ';

void solve() {
  ll n;
  cin >> n;
  ll minn = log10(n) + 1;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    ll m = n / i;
    ll d = max(log10(i) + 1, log10(m) + 1);
    if (d < minn)
      minn = d;
  }
  cout << minn;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  cerr << "\n\n~" << 500 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
Problem p03775 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <math.h>

using namespace std;

int main() {
  long long n;
  cin >> n;
  long long tmp;
  for (int i = 1; i < sqrt(n); i++) {
    if (n % i == 0) {
      tmp = i;
      // cout << "#" << i;
    }
  }
  tmp = n / tmp;
  int ans = 0;
  while (tmp > 0) {
    tmp /= 10;
    ans++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <iostream>
#include <math.h>

using namespace std;

int main() {
  long long n;
  cin >> n;
  long long tmp;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      tmp = i;
      // cout << "#" << i;
    }
  }
  tmp = n / tmp;
  int ans = 0;
  while (tmp > 0) {
    tmp /= 10;
    ans++;
  }
  cout << ans << endl;
}
Problem p03775 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<ll>;
using vec2 = vector<vector<ll>>;
ll inf = pow(2, 62);

ll keta(ll x) {
  ll digits = 0;
  while (x > 0) {
    x /= 10;
    digits++;
  }
  return digits;
}

int main() {
  ll n;
  cin >> n;
  ll ans = keta(n);
  for (int i = 1; i <= n; i++) {
    if (n % i != 0) {
      continue;
    } else {
      ll a = i;
      ll b = n / a;
      if (a > b) {
        break;
      }
      ll f = max(keta(a), keta(b));
      ans = min(ans, f);
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<ll>;
using vec2 = vector<vector<ll>>;
ll inf = pow(2, 62);

ll keta(ll x) {
  ll digits = 0;
  while (x > 0) {
    x /= 10;
    digits++;
  }
  return digits;
}

int main() {
  ll n;
  cin >> n;
  ll ans = keta(n);
  for (ll i = 1; i * i <= n; i++) {
    if (n % i != 0) {
      continue;
    } else {
      ll a = i;
      ll b = n / a;
      if (a > b) {
        break;
      }
      ll f = max(keta(a), keta(b));
      ans = min(ans, f);
    }
  }
  cout << ans << endl;
}
Problem p03776 (Python)

Buggy submission (status: Runtime Error):
from math import factorial

N, A, B = map(int, input().split())
V = sorted(list(map(int, input().split())), reverse=True)

print(sum(V[:A]) / A)
if V[0] == V[A - 1]:
    n = sum([1 for v in V if v == V[0]])
    print(
        sum([factorial(n) // factorial(r) // factorial(n - r) for r in range(A, B + 1)])
    )
else:
    n = sum([1 for v in V if v == V[A - 1]])
    r = sum([1 for v in V[:A] if v == V[A - 1]])
    print(factorial(n) // factorial(r) // factorial(n - r))


Fixed submission:
from math import factorial

N, A, B = map(int, input().split())
V = sorted(list(map(int, input().split())), reverse=True)

print(sum(V[:A]) / A)
if V[0] == V[A - 1]:
    n = sum([1 for v in V if v == V[0]])
    print(
        sum(
            [
                factorial(n) // factorial(r) // factorial(n - r)
                for r in range(A, min(n, B) + 1)
            ]
        )
    )
else:
    n = sum([1 for v in V if v == V[A - 1]])
    r = sum([1 for v in V[:A] if v == V[A - 1]])
    print(factorial(n) // factorial(r) // factorial(n - r))
Problem p03776 (Python)

Buggy submission (status: Runtime Error):
import math

N, A, B = map(int, input().split())
V = list(map(int, input().split()))

# print(N, A, B, V)

V.sort(reverse=True)

max_list = V[:A]
max_sum = sum(max_list)
print(max_sum / A)

replace = max_list[-1]

num_replace = 0
for v in V:
    if v == replace:
        num_replace += 1

if num_replace == 1:
    print(1)
    exit()

num_replace_in_list = 0
for v in max_list:
    if v == replace:
        num_replace_in_list += 1

if replace * A != max_sum:
    ans = 0
    for i in range(A, B + 1):
        # print(i, num_replace_in_list, num_replace)
        if i - A + num_replace_in_list > num_replace:
            break
        ans += math.factorial(num_replace) // (
            math.factorial(num_replace - i) * math.factorial(i)
        )
    print(ans)
    exit()


ans = 0
for i in range(A, B + 1):
    if i > num_replace:
        break
    ans += math.factorial(num_replace) // (
        math.factorial(num_replace - i) * math.factorial(i)
    )

print(ans)


Fixed submission:
import math

N, A, B = map(int, input().split())
V = list(map(int, input().split()))

# print(N, A, B, V)

V.sort(reverse=True)

max_list = V[:A]
max_sum = sum(max_list)
print(max_sum / A)

replace = max_list[-1]

num_replace = 0
for v in V:
    if v == replace:
        num_replace += 1

if num_replace == 1:
    print(1)
    exit()

num_replace_in_list = 0
for v in max_list:
    if v == replace:
        num_replace_in_list += 1

if replace * A != max_sum:
    ans = math.factorial(num_replace) // (
        math.factorial(num_replace - num_replace_in_list)
        * math.factorial(num_replace_in_list)
    )
    print(ans)
    exit()


ans = 0
for i in range(A, B + 1):
    if i > num_replace:
        break
    ans += math.factorial(num_replace) // (
        math.factorial(num_replace - i) * math.factorial(i)
    )

print(ans)
Problem p03776 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define modulo ll(1e9 + 7)

typedef long long ll;
typedef pair<int, int> pii;

void init() {
  cin.tie(0);
  cin.sync_with_stdio(0);
}

const int N = 59, M = 5e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int n, l, r;

ll a[N];

ll iterativeChoose(ll n, ll k) {
  if (k > n)
    return 0;
  ll ret = 1;
  for (ll i = k + 1; i <= n; i++) {
    ll d = (i - k);
    ll q = i / d;
    ll r = i - q * d;
    ret = ret * q + ret * r / d;
  }
  return ret;
}

int main() {
  init();

  freopen("in.in", "r", stdin);

  cin >> n >> l >> r;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  sort(a, a + n);
  reverse(a, a + n);

  long double sum = 0;

  int cnt1 = 0, cnt2 = 0;

  for (int i = 0; i < n; i++)
    cnt1 += a[i] == a[l - 1];

  for (int i = 0; i < l; i++)
    sum += a[i], cnt2 += a[i] == a[l - 1];
  ;

  cout << fixed << setprecision(7) << 1.0 * sum / l << '\n';

  ll ans = 0;
  if (a[0] == a[l - 1]) {
    for (int i = l; i <= r; i++)
      ans += iterativeChoose(cnt1, i);
    return cout << ans, 0;
  }

  cout << iterativeChoose(cnt1, cnt2);
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define modulo ll(1e9 + 7)

typedef long long ll;
typedef pair<int, int> pii;

void init() {
  cin.tie(0);
  cin.sync_with_stdio(0);
}

const int N = 59, M = 5e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int n, l, r;

ll a[N];

ll iterativeChoose(ll n, ll k) {
  if (k > n)
    return 0;
  ll ret = 1;
  for (ll i = k + 1; i <= n; i++) {
    ll d = (i - k);
    ll q = i / d;
    ll r = i - q * d;
    ret = ret * q + ret * r / d;
  }
  return ret;
}

int main() {
  init();

  cin >> n >> l >> r;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  sort(a, a + n);
  reverse(a, a + n);

  long double sum = 0;

  int cnt1 = 0, cnt2 = 0;

  for (int i = 0; i < n; i++)
    cnt1 += a[i] == a[l - 1];

  for (int i = 0; i < l; i++)
    sum += a[i], cnt2 += a[i] == a[l - 1];
  ;

  cout << fixed << setprecision(7) << 1.0 * sum / l << '\n';

  ll ans = 0;
  if (a[0] == a[l - 1]) {
    for (int i = l; i <= r; i++)
      ans += iterativeChoose(cnt1, i);
    return cout << ans, 0;
  }

  cout << iterativeChoose(cnt1, cnt2);
}
Problem p03776 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

using int64 = long long;

int64 comb_[55][55];
int64 Comb(int64 n, int64 r) {
  if (comb_[n][r])
    return comb_[n][r];
  if (n == r || r == 0)
    return comb_[n][r] = 1;
  return comb_[n][r] = Comb(n - 1, r) + Comb(n - 1, r - 1);
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  vector<int64> v(N);
  for (int i = 0; i < N; ++i)
    cin >> v[i];
  sort(v.begin(), v.end());

  double average = 0;
  for (int i = N - 1; i >= N - A; --i)
    average += v[i];
  average /= A;
  cout << fixed << setprecision(10) << average << "\n";

  int even = lower_bound(v.begin(), v.end(), v[N - A]) - v.begin();
  int above = upper_bound(v.begin(), v.end(), v[N - A]) - v.begin();
  even = above - even;
  above = N - above;

  int64 ret = 0;
  if (v[N - A] == v[N - 1]) {
    for (int r = A; r <= B; ++r)
      ret += Comb(even, r);
  } else {
    ret = Comb(even, A - above);
  }
  cout << ret << "\n";

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

using int64 = long long;

int64 comb_[55][55];
int64 Comb(int64 n, int64 r) {
  if (comb_[n][r])
    return comb_[n][r];
  if (n == r || r == 0)
    return comb_[n][r] = 1;
  return comb_[n][r] = Comb(n - 1, r) + Comb(n - 1, r - 1);
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  vector<int64> v(N);
  for (int i = 0; i < N; ++i)
    cin >> v[i];
  sort(v.begin(), v.end());

  double average = 0;
  for (int i = N - 1; i >= N - A; --i)
    average += v[i];
  average /= A;
  cout << fixed << setprecision(10) << average << "\n";

  int even = lower_bound(v.begin(), v.end(), v[N - A]) - v.begin();
  int above = upper_bound(v.begin(), v.end(), v[N - A]) - v.begin();
  even = above - even;
  above = N - above;

  int64 ret = 0;
  if (v[N - A] == v[N - 1]) {
    for (int r = A; r <= B && r <= even; ++r)
      ret += Comb(even, r);
  } else {
    ret = Comb(even, A - above);
  }
  cout << ret << "\n";

  return 0;
}
Problem p03776 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <random>
#include <time.h>
#include <tuple>
#include <vector>
using namespace std;

int64_t comb(int n, int k) {
  static int64_t memo[51][51];
  if (k == 0 || k == n)
    return 1;
  if (memo[n][k])
    return memo[n][k];
  return memo[n][k] = comb(n - 1, k - 1) + comb(n - 1, k);
}

int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;
  vector<int64_t> V(N);
  for (auto &v : V)
    cin >> v;
  sort(V.begin(), V.end(), greater<int64_t>());
  double sum = 0;
  for (int i = 0; i < A; i++)
    sum += V[i];
  printf("%.10f\n", sum / A);
  int64_t cnt = 0;
  int n = 0, k = 0;
  if (V[0] != V[A - 1]) {
    for (int i = 0; i < N; i++)
      n += V[i] == V[A - 1];
    for (int i = 0; i < A; i++)
      k += V[i] == V[A - 1];
    cnt = comb(n, k);
  } else {
    for (int i = 0; i < N; i++)
      n += V[i] == V[A - 1];
    for (int k = A; k <= B; k++)
      cnt += comb(n, k);
  }
  cout << cnt << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <random>
#include <time.h>
#include <tuple>
#include <vector>
using namespace std;

int64_t comb(int n, int k) {
  static int64_t memo[51][51];
  if (k == 0 || k == n)
    return 1;
  if (memo[n][k])
    return memo[n][k];
  return memo[n][k] = comb(n - 1, k - 1) + comb(n - 1, k);
}

int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;
  vector<int64_t> V(N);
  for (auto &v : V)
    cin >> v;
  sort(V.begin(), V.end(), greater<int64_t>());
  double sum = 0;
  for (int i = 0; i < A; i++)
    sum += V[i];
  printf("%.10f\n", sum / A);
  int64_t cnt = 0;
  int n = 0, k = 0;
  if (V[0] != V[A - 1]) {
    for (int i = 0; i < N; i++)
      n += V[i] == V[A - 1];
    for (int i = 0; i < A; i++)
      k += V[i] == V[A - 1];
    cnt = comb(n, k);
  } else {
    for (int i = 0; i < N; i++)
      n += V[i] == V[0];
    for (int k = A; k <= n && k <= B; k++)
      cnt += comb(n, k);
  }
  cout << cnt << endl;

  return 0;
}
Problem p03776 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/STACK:256000000")

#include <algorithm>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>

#define ll long long
#define ld long double
#define fi(n) for (int i = 0; i < (n); i++)
#define FOR(i, k, n) for (int i = (k); i < (n); i++)

// const int INF = 2147483647;
const int INF = 1e9;
const long long lINF = 9223372036854775807;

using namespace std;

// #define cin in
// #define cout out

ifstream in;
ofstream out;

ll soch(ll n, ll k) {
  if (n == k)
    return 1;
  if (k == 1)
    return n;
  return soch(n - 1, k - 1) + soch(n - 1, k);
}

int main() {
  in.open("input.txt");
  out.open("output.txt");
  ll n, a, b;
  cin >> n >> a >> b;
  vector<ll> v(n);
  fi(n) cin >> v[i];
  sort(v.rbegin(), v.rend());
  ll sum = 0;
  set<ll> el;
  fi(a) el.insert(v[i]), sum += v[i];
  ll answ = 0;
  if (el.size() == 1) {
    ll cnt = 0;
    fi(n) if (v[i] == v[0]) cnt++;
    FOR(i, a, min(b, cnt) + 1) { answ += soch(cnt, i); }
  } else {
    ll k = 0, m = 0;
    fi(a) if (v[i] == v[a - 1]) k++;
    fi(n) if (v[i] == v[a - 1]) m++;
    answ = soch(m, k);
  }
  double answ1 = (double)sum / (double)a;
  cout << fixed << setprecision(6) << answ1 << endl;
  cout << answ << endl;
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/STACK:256000000")

#include <algorithm>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>

#define ll long long
#define ld long double
#define fi(n) for (int i = 0; i < (n); i++)
#define FOR(i, k, n) for (int i = (k); i < (n); i++)

// const int INF = 2147483647;
const int INF = 1e9;
const long long lINF = 9223372036854775807;

using namespace std;

// #define cin in
// #define cout out

ifstream in;
ofstream out;

ll soch(ll n, ll k) {
  vector<vector<ll>> v(n + 1, vector<ll>(n + 1));
  v[0][0] = 1;
  FOR(i, 1, n + 1) {
    v[i][0] = 1;
    v[i][n] = 1;
    FOR(j, 1, n + 1) { v[i][j] = v[i - 1][j - 1] + v[i - 1][j]; }
  }
  return v[n][k];
}

int main() {
  in.open("input.txt");
  out.open("output.txt");
  ll n, a, b;
  cin >> n >> a >> b;
  vector<ll> v(n);
  fi(n) cin >> v[i];
  sort(v.rbegin(), v.rend());
  ll sum = 0;
  set<ll> el;
  fi(a) el.insert(v[i]), sum += v[i];
  ll answ = 0;
  if (el.size() == 1) {
    ll cnt = 0;
    fi(n) if (v[i] == v[0]) cnt++;
    FOR(i, a, min(b, cnt) + 1) { answ += soch(cnt, i); }
  } else {
    ll k = 0, m = 0;
    fi(a) if (v[i] == v[a - 1]) k++;
    fi(n) if (v[i] == v[a - 1]) m++;
    answ = soch(m, k);
  }
  double answ1 = (double)sum / (double)a;
  cout << fixed << setprecision(6) << answ1 << endl;
  cout << answ << endl;
  return 0;
}