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

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

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  if (S.at(K) == 'A')
    S.at(K) = 'a';
  else if (S.at(K) == 'B')
    S.at(K) = 'b';
  else if (S.at(K) == 'C')
    S.at(K) = 'c';
  cout << S << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  if (S.at(K - 1) == 'A')
    S.at(K - 1) = 'a';
  else if (S.at(K - 1) == 'B')
    S.at(K - 1) = 'b';
  else if (S.at(K - 1) == 'C')
    S.at(K - 1) = 'c';
  cout << S << endl;
}
Problem p03041 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int number, count;
  string str;
  cin >> number >> count;
  cin >> str;
  str.at(count) += 0x20;
  cout << str << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int number, count;
  string str;
  cin >> number >> count;
  cin >> str;
  str.at(count - 1) += 0x20;
  cout << str << endl;
  return 0;
}
Problem p03041 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  char s[n];
  cin >> n >> k;
  cin >> s;
  s[k - 1] += 32;
  cout << s;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  char s[k];
  cin >> n >> k;
  cin >> s;
  s[k - 1] += 32;
  cout << s;
}
Problem p03041 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  S.at(K) = tolower(S.at(K));
  cout << S;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  S.at(K - 1) = tolower(S.at(K - 1));
  cout << S;
}
Problem p03041 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;
typedef unsigned long long ull;

// assert
template <typename T> void assert_between(T val, T min, T max) {
  assert(min <= val && val <= max);
}

// math
// 最大公約数(Gratest Common Divisor)を求める.
template <typename T> T gcd(T a, T b) {
  assert(a > 0 && b > 0);
  T num1 = max(a, b);
  T num2 = min(a, b);
  T mod = num1 % num2;
  return (mod == 0) ? num2 : gcd(num2, mod);
}

// 最小公倍数(Least Common Multiple)を求める.
template <typename T> T lcm(T a, T b) { return (a * b) / gcd(a, b); }

int N, K;
string S;

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

  scanf("%d %d", &N, &K);
  cin >> S;
  assert(S.length() == N);

  switch (S[K - 1]) {
  case 'A':
    S[K - 1] = 'a';
    break;
  case 'B':
    S[K - 1] = 'b';
    break;
  case 'C':
    S[K - 1] = 'c';
    break;
  default:
    assert(false);
    break;
  }

  printf("%s\n", S.c_str());
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;
typedef unsigned long long ull;

// assert
template <typename T> void assert_between(T val, T min, T max) {
  assert(min <= val && val <= max);
}

// math
// 最大公約数(Gratest Common Divisor)を求める.
template <typename T> T gcd(T a, T b) {
  assert(a > 0 && b > 0);
  T num1 = max(a, b);
  T num2 = min(a, b);
  T mod = num1 % num2;
  return (mod == 0) ? num2 : gcd(num2, mod);
}

// 最小公倍数(Least Common Multiple)を求める.
template <typename T> T lcm(T a, T b) { return (a * b) / gcd(a, b); }

int N = INT32_MAX;
int K = INT32_MAX;
string S = "";

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

  scanf("%d %d", &N, &K);
  cin >> S;
  assert(S.length() == N);

  switch (S[K - 1]) {
  case 'A':
    S[K - 1] = 'a';
    break;
  case 'B':
    S[K - 1] = 'b';
    break;
  case 'C':
    S[K - 1] = 'c';
    break;
  default:
    assert(false);
    break;
  }

  printf("%s\n", S.c_str());
}
Problem p03041 (C++)

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

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  if (s.at(k) == 'A')
    s.at(k) = 'a';
  else if (s.at(k) == 'B')
    s.at(k) = 'b';
  else if (s.at(k) == 'C')
    s.at(k) = 'c';
  cout << s;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  if (s.at(k - 1) == 'A')
    s.at(k - 1) = 'a';
  else if (s.at(k - 1) == 'B')
    s.at(k - 1) = 'b';
  else if (s.at(k - 1) == 'C')
    s.at(k - 1) = 'c';
  cout << s;
}
Problem p03041 (C++)

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

int main() {
  int n, k;
  char s[] = {};
  cin >> n >> k;
  cin >> s;
  s[k - 1] = s[k - 1] + 32;
  cout << s << endl;
  return 0;
}


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

int main() {
  int n, k;
  char s[256];
  cin >> n >> k;
  cin >> s;
  s[k - 1] = s[k - 1] + 32;
  cout << s << endl;
  return 0;
}
Problem p03041 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>

int main() {
  int n, k;
  std::string input, copy;
  std::cin >> n >> k >> input;

  copy = input;
  transform(copy.begin(), copy.end(), copy.begin(),
            [](unsigned char c) -> unsigned char { return std::tolower(c); });

  input[k - 1] = copy[k - 1];

  std::cout << input << std::endl;

  return 1;
}


Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>

int main() {
  int n, k;
  std::string input, copy;
  std::cin >> n >> k >> input;

  copy = input;
  transform(copy.begin(), copy.end(), copy.begin(),
            [](unsigned char c) -> unsigned char { return std::tolower(c); });

  input[k - 1] = copy[k - 1];

  std::cout << input << std::endl;

  return 0;
}
Problem p03041 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  s.at(k) = s.at(k) - ('A' - 'a');
  cout << s << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  s.at(k - 1) = s.at(k - 1) - ('A' - 'a');
  cout << s << endl;
}
Problem p03041 (C++)

Buggy submission (status: Runtime Error):
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE
PROHIBITED   **********************************
*/
#include <bits/stdc++.h>

#define int long long
#define double long double
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 998244353
#define PI 3.141592653589
using namespace std;

int gcd(int a, int b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
bool mod(double a, double b) { return a / b - floor(a / b); }
bool f(int a, int b) { return a < b ? 0 : 1; }

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

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int n, x;
  cin >> n >> x;
  string s;
  cin >> s;

  s[x - 1] = s[x - 1] + ('a' - 'A');
  cout << s;
}

Fixed submission:
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE
PROHIBITED   **********************************
*/
#include <bits/stdc++.h>

#define int long long
#define double long double
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 998244353
#define PI 3.141592653589
using namespace std;

int gcd(int a, int b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}
bool mod(double a, double b) { return a / b - floor(a / b); }
bool f(int a, int b) { return a < b ? 0 : 1; }

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

  int n, x;
  cin >> n >> x;
  string s;
  cin >> s;

  s[x - 1] = s[x - 1] + ('a' - 'A');
  cout << s;
}
Problem p03041 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  char s[10];
  cin >> n >> k;
  cin >> s;
  s[k - 1] += 32;
  cout << s;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  char s[49];
  cin >> n >> k;
  cin >> s;
  s[k - 1] += 32;
  cout << s;
}
Problem p03041 (C++)

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

int main() {
  int n, k;
  string s;
  char x = s.at(k - 1);
  if (x == 'A') {
    x = 'a';
  } else if (x == 'B') {
    x = 'b';
  } else {
    x = 'c';
  }
  s.at(k - 1) = x;
  cout << s << endl;
}


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

int main() {
  int n, k;
  string s;
  cin >> n >> k;
  cin >> s;
  char x = s.at(k - 1);
  if (x == 'A') {
    x = 'a';
  } else if (x == 'B') {
    x = 'b';
  } else {
    x = 'c';
  }
  s.at(k - 1) = x;
  cout << s << endl;
}
Problem p03041 (C++)

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

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  if (s.at(k) == 'A')
    s.at(k) = 'a';
  else if (s.at(k) == 'B')
    s.at(k) = 'b';
  else
    s.at(k) = 'c';
  cout << s << endl;
}

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

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  k = k - 1;
  if (s.at(k) == 'A')
    s.at(k) = 'a';
  else if (s.at(k) == 'B')
    s.at(k) = 'b';
  else
    s.at(k) = 'c';
  cout << s << endl;
}
Problem p03041 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  string S;
  cin >> N >> K;
  cin >> S;
  S.at(K) = tolower(S.at(K - 1));
  cout << S << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  string S;
  cin >> N >> K;
  cin >> S;
  S.at(K - 1) = tolower(S.at(K - 1));
  cout << S << endl;
}
Problem p03041 (C++)

Buggy submission (status: Runtime Error):
// TOPSIC001_0

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _loop_int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i)
#define FORR(i, a, b)                                                          \
  for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v)                                                           \
  cout << #v << ":";                                                           \
  REP(i, v.size()) cout << " " << v[i];                                        \
  cout << endl
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a) % MOD + MOD) % MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(a, b) (abs(a - b) < EPS)
typedef complex<Real> P;

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  S.at(K) = tolower(S.at(K));
  cout << S;

  return 0;
}

Fixed submission:
// TOPSIC001_0

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _loop_int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i)
#define FORR(i, a, b)                                                          \
  for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v)                                                           \
  cout << #v << ":";                                                           \
  REP(i, v.size()) cout << " " << v[i];                                        \
  cout << endl
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a) % MOD + MOD) % MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(a, b) (abs(a - b) < EPS)
typedef complex<Real> P;

int main() {
  int N, K;
  cin >> N >> K;
  K--;
  string S;
  cin >> S;

  S.at(K) = tolower(S.at(K));
  cout << S;

  return 0;
}
Problem p03041 (C++)

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

int main() {
  int N;
  int K;
  cin >> N;
  cin >> K;
  string S;
  cin >> S;
  S[K - 1] = S[K - 1] + 32;
  cout << S << endl;
  return 1;
}

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

int main() {
  int N;
  int K;
  cin >> N;
  cin >> K;
  string S;
  cin >> S;
  S[K - 1] = S[K - 1] + 32;
  cout << S << endl;
  return 0;
}
Problem p03041 (C++)

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

int main() {
  int N, B;
  cin >> N >> B;
  string S;
  B--;
  if (S.at(B) == 'A') {
    S.at(B) = 'a';
    cout << S << endl;
  } else if (S.at(B) == 'B') {
    S.at(B) = 'b';
    cout << S << endl;
  } else if (S.at(B) == 'C') {
    S.at(B) = 'c';
    cout << S << endl;
  }
}


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

int main() {
  int N, B;
  cin >> N >> B;
  string S;
  cin >> S;
  B--;
  if (S.at(B) == 'A') {
    S.at(B) = 'a';
    cout << S << endl;
  } else if (S.at(B) == 'B') {
    S.at(B) = 'b';
    cout << S << endl;
  } else if (S.at(B) == 'C') {
    S.at(B) = 'c';
    cout << S << endl;
  }
}
Problem p03042 (Python)

Buggy submission (status: Runtime Error):
s = input()
if s[:2] == "00" or s[2:] == "00":
    print("NA")
elif s[:2] > 12 and 0 <= s[2:] <= 12:
    print("YYMM")
elif 0 <= s[:2] <= 12 and 0 <= s[2:] <= 12:
    print("AMBIGUOUS")
else:
    print("MMYY")


Fixed submission:
s = input()

f = 0 < int(s[:2]) < 13
s = 0 < int(s[2:]) < 13
ans = "NA"
if f and s:
    ans = "AMBIGUOUS"
elif s:
    ans = "YYMM"
elif f:
    ans = "MMYY"
print(ans)
Problem p03042 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  while (1) {
    int a;
    cin >> a;
    int b = a / 100;
    int c = a % 100;
    if (b <= 12 && c <= 12 && b >= 1 && c >= 1) {
      cout << "AMBIGIOUS" << endl;
    } else if (b <= 12 && b >= 1 && c >= 1) {
      cout << "MMYY" << endl;
    } else if (b >= 1 && c >= 1 && c <= 12) {
      cout << "YYMM" << endl;
    } else
      cout << "NA" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  scanf("%d", &a);
  int L = a / 100;
  int R = a % 100;
  if (1 <= L && L <= 12) {
    if (1 <= R && R <= 12)
      printf("AMBIGUOUS\n");
    else
      printf("MMYY\n");
  } else {
    if (1 <= R && R <= 12)
      printf("YYMM\n");
    else
      printf("NA\n");
  }
}
Problem p03042 (C++)

Buggy submission (status: Runtime Error):
#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 pb(a) push_back(a)
using namespace std;
typedef long long ll;

int main() {
  int s;
  cin >> s;

  vector<int> S(2);
  S.at(0) = s / 100;
  s = s % 100;
  S.at(1) = s;

  bool yymm = false;
  bool mmyy = false;

  if ((S.at(0) > 12 || S.at(0) == 0) && (S.at(1) > 12 || S.at(1) == 0))
    cout << "NA";
  else if ((S.at(0) > 12 || S.at(0) == 0) && (S.at(1) > 0 && S.at(1) < 13))
    cout << "YYMM";
  else if ((S.at(1) > 12 || S.at(1) == 0) && (S.at(2) > 0 && S.at(2) < 13))
    cout << "MMYY";
  else
    cout << "AMBIGUOUS";
}

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 pb(a) push_back(a)
using namespace std;
typedef long long ll;

int main() {
  int s;
  cin >> s;

  vector<int> S(2);
  S.at(0) = s / 100;
  s = s % 100;
  S.at(1) = s;

  bool yymm = false;
  bool mmyy = false;

  if ((S.at(0) > 12 || S.at(0) == 0) && (S.at(1) > 12 || S.at(1) == 0))
    cout << "NA";
  else if ((S.at(0) > 12 || S.at(0) == 0) && (S.at(1) > 0 && S.at(1) < 13))
    cout << "YYMM";
  else if ((S.at(1) > 12 || S.at(1) == 0) && (S.at(0) > 0 && S.at(0) < 13))
    cout << "MMYY";
  else
    cout << "AMBIGUOUS";
}
Problem p03042 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

int syc(long i, long Min, long Max) {
  if (Min <= i && i <= Max) {
    return 1;
  } else {
    exit(1);
    // return 0;
  }
}

int main() {

  int x;
  cin >> x;
  syc(x, 1, 9999);
  int b, c;
  b = x / 100;
  c = x % 100;

  if ((1 <= b && b <= 12) && (1 <= c && c <= 12))
    cout << "AMBIGUOUS" << endl;
  else if (1 <= b && b <= 12)
    cout << "MMYY" << endl;
  else if (1 <= c && c <= 12)
    cout << "YYMM" << endl;
  else
    cout << "NA" << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

int syc(long i, long Min, long Max) {
  if (Min <= i && i <= Max) {
    return 1;
  } else {
    exit(1);
    // return 0;
  }
}

int main() {

  int x;
  cin >> x;
  syc(x, 0, 9999);
  int b, c;
  b = x / 100;
  c = x % 100;

  if ((1 <= b && b <= 12) && (1 <= c && c <= 12))
    cout << "AMBIGUOUS" << endl;
  else if (1 <= b && b <= 12)
    cout << "MMYY" << endl;
  else if (1 <= c && c <= 12)
    cout << "YYMM" << endl;
  else
    cout << "NA" << endl;

  return 0;
}
Problem p03042 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = m; i < n; i++)
#define rep(i, n) REP(i, 0, n)
template <class T> void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}
template <class T> void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}
using namespace std;

int main(void) {
  int s;
  cin >> s;

  int upper_half = s / 100;
  int lower_half = s % (s / 100 * 100);

  if (upper_half <= 12 && upper_half >= 1 && lower_half >= 1 &&
      lower_half <= 12) {
    cout << "AMBIGUOUS" << endl;
  } else if (upper_half <= 12 && upper_half >= 1) {
    cout << "MMYY" << endl;
  } else if (lower_half >= 1 && lower_half <= 12) {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = m; i < n; i++)
#define rep(i, n) REP(i, 0, n)
template <class T> void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}
template <class T> void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}
using namespace std;

int main(void) {
  int s;
  cin >> s;

  int upper_half = s / 100;
  int lower_half = upper_half == 0 ? s % 100 : s % (s / 100 * 100);

  if (upper_half <= 12 && upper_half >= 1 && lower_half >= 1 &&
      lower_half <= 12) {
    cout << "AMBIGUOUS" << endl;
  } else if (upper_half <= 12 && upper_half >= 1) {
    cout << "MMYY" << endl;
  } else if (lower_half >= 1 && lower_half <= 12) {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }
}
Problem p03042 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  char s[4];
  scanf("%s", s);

  int i1 = (s[0] - '0') * 10 + (s[1] - '0');
  int i2 = (s[2] - '0') * 10 + (s[3] - '0');

  if (1 <= i1 && i1 <= 12) {
    if (1 <= i2 && i2 <= 12) {
      printf("AMBIGUOUS\n");
    } else {
      printf("MMYY\n");
    }
  } else {
    if (1 <= i2 && i2 <= 12) {
      printf("YYMM\n");
    } else {
      printf("NA\n");
    }
  }
}


Fixed submission:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  char s[10];
  scanf("%s", s);

  int i1 = (s[0] - '0') * 10 + (s[1] - '0');
  int i2 = (s[2] - '0') * 10 + (s[3] - '0');

  if (1 <= i1 && i1 <= 12) {
    if (1 <= i2 && i2 <= 12) {
      printf("AMBIGUOUS\n");
    } else {
      printf("MMYY\n");
    }
  } else {
    if (1 <= i2 && i2 <= 12) {
      printf("YYMM\n");
    } else {
      printf("NA\n");
    }
  }
}
Problem p03042 (C++)

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

#define int long long
#define ll long long
#define f1(i, a, b) for (i = a; i < b; i++)
#define f2(i, a, b) for (i = a; i >= b; i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod = 1000000007;
int i, j;
ll temp;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  string s;
  cin >> s;
  int m, y;
  m = (s[0] - '0') * 10 + (s[1] - '0');
  y = (s[2] - '0') * 10 + (s[3] - '0');
  if (m >= 1 && m <= 12 && y <= 12 && y >= 1) {
    cout << "AMBIGUOUS";
    return 0;
  } else if (m >= 1 && m <= 12) {
    cout << "MMYY";
    return 0;
  } else if (y >= 1 && y <= 12) {
    cout << "YYMM";
    return 0;
  } else
    cout << "NA";
  return 0;
}

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

#define int long long
#define ll long long
#define f1(i, a, b) for (i = a; i < b; i++)
#define f2(i, a, b) for (i = a; i >= b; i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod = 1000000007;
int i, j;
ll temp;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // #ifndef ONLINE_JUDGE
  //     freopen("in.txt","r",stdin);
  //     freopen("out.txt","w",stdout);
  // #endif
  string s;
  cin >> s;
  int m, y;
  m = (s[0] - '0') * 10 + (s[1] - '0');
  y = (s[2] - '0') * 10 + (s[3] - '0');
  if (m >= 1 && m <= 12 && y <= 12 && y >= 1) {
    cout << "AMBIGUOUS";
    return 0;
  } else if (m >= 1 && m <= 12) {
    cout << "MMYY";
    return 0;
  } else if (y >= 1 && y <= 12) {
    cout << "YYMM";
    return 0;
  } else
    cout << "NA";
  return 0;
}
Problem p03042 (C++)

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

int main(void) {
  int num[2] = {0, 0};
  string mes[4] = {"NA", "MMYY", "YYMM", "AMBIGUOUS"};

  for (int i = 0; i < 3; i++) {
    char c;
    cin >> c;
    num[i / 2] = num[i / 2] * 10 + (c - '0');
    if (i % 2) {
      num[i / 2] = (num[i / 2] > 0 && num[i / 2] <= 12) ? 1 : 0;
    }
  }
  cout << mes[num[0] + num[1] * 2] << endl;
  return 0;
}


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

int main(void) {
  int num[2] = {0, 0};
  string mes[4] = {"NA", "MMYY", "YYMM", "AMBIGUOUS"};

  for (int i = 0; i < 4; i++) {
    char c;
    cin >> c;
    num[i / 2] = num[i / 2] * 10 + (c - '0');
    if (i % 2) {
      num[i / 2] = (num[i / 2] > 0 && num[i / 2] <= 12) ? 1 : 0;
    }
  }
  cout << mes[num[0] + num[1] * 2] << endl;
  return 0;
}
Problem p03042 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int, int>
#define pdd pair<ld, ld>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack<int>
#define stll stack<ll>
#define mseti multiset<ll>
#define msetd multiset<ll, greater<ll>>
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define stp setprecision(20) // use fixed before stp
#define endl '\n'
ll a[2000000];
int main() {
  FAST
#ifndef ONLINE_JUDGE
      freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
#endif
  ll n;
  cin >> n;
  ll a = n % 100;
  ll b = n / 100;
  if ((a <= 12 && a != 0) && (b <= 12 && b != 0)) {
    cout << "AMBIGUOUS";
  } else if (a <= 12 && a != 0) {
    cout << "YYMM";
  } else if (b <= 12 && b != 0) {
    cout << "MMYY";
  } else
    cout << "NA";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int, int>
#define pdd pair<ld, ld>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack<int>
#define stll stack<ll>
#define mseti multiset<ll>
#define msetd multiset<ll, greater<ll>>
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define stp setprecision(20) // use fixed before stp
#define endl '\n'
ll a[2000000];
int main() {
  FAST ll n;
  cin >> n;
  ll a = n % 100;
  ll b = n / 100;
  if ((a <= 12 && a != 0) && (b <= 12 && b != 0)) {
    cout << "AMBIGUOUS";
  } else if (a <= 12 && a != 0) {
    cout << "YYMM";
  } else if (b <= 12 && b != 0) {
    cout << "MMYY";
  } else
    cout << "NA";
}
Problem p03042 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>

using namespace std;

int strtoint(string str) {
  int res = 0;
  int i = 0;
  while (i < str.length() && str[i] >= '0' && str[i] <= '9') {
    res *= 10;
    res += str[i];
  }

  return res;
}

int main() {
  string str;
  cin >> str;
  int former = strtoint(str.substr(0, 2));
  int latter = strtoint(str.substr(2, 4));
  if (former >= 1 && former <= 12) {
    if (latter >= 1 && latter <= 12) {
      cout << "AMBIGUOUS";
    } else {
      cout << "MMYY";
    }
  } else {
    if (latter >= 1 && latter <= 12) {
      cout << "YYMM";
    } else {
      cout << "NA";
    }
  }
}

Fixed submission:
#include <iostream>
#include <string>

using namespace std;

int strtoint(string str) {
  int res = 0;
  int i = 0;
  while (i < str.length() && str[i] >= '0' && str[i] <= '9') {
    res *= 10;
    res += str[i] - 48;
    i++;
  }

  return res;
}

int main() {
  string str;
  cin >> str;
  int former = strtoint(str.substr(0, 2));
  int latter = strtoint(str.substr(2, 4));
  if (former >= 1 && former <= 12) {
    if (latter >= 1 && latter <= 12) {
      cout << "AMBIGUOUS";
    } else {
      cout << "MMYY";
    }
  } else {
    if (latter >= 1 && latter <= 12) {
      cout << "YYMM";
    } else {
      cout << "NA";
    }
  }
}
Problem p03043 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<pll> vplll;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  double n, k;
  cin >> n >> k;
  double ans = 0;
  for (double i = 1; i <= n; ++i) {
    if (i < k) {
      double x = ceil(k / i);
      x = ceil(log(x) / log(2));
      ans += pow(0.5, x);
    } else {
      ans += 1;
    }
  }
  ans *= 1 / n;
  cout << setprecision(20) << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<pll> vplll;

int main() {
  // #ifndef ONLINE_JUDGE
  //    freopen("input.txt", "r", stdin);
  // #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  double n, k;
  cin >> n >> k;
  double ans = 0;
  for (double i = 1; i <= n; ++i) {
    if (i < k) {
      double x = ceil(k / i);
      x = ceil(log(x) / log(2));
      ans += pow(0.5, x);
    } else {
      ans += 1;
    }
  }
  ans *= 1 / n;
  cout << setprecision(20) << ans << endl;
  return 0;
}
Problem p03043 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define ALL(x) (x).begin(), (x).end()
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int N, K;
  scanf("%d%d", N, K);
  double ans = 0;

  for (int i = 1; i <= N; i++) {
    int Point = i;
    double rate = 1.0 / N;
    while (Point < K) {
      Point *= 2;
      rate *= 0.5;
    }
    ans += rate;
  }

  printf("%.12f\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define ALL(x) (x).begin(), (x).end()
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  double ans = 0;

  for (int i = 1; i <= N; i++) {
    int Point = i;
    double rate = 1.0 / N;
    while (Point < K) {
      Point *= 2;
      rate *= 0.5;
    }
    ans += rate;
  }

  printf("%.12f\n", ans);
}
Problem p03043 (C++)

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<double> p(n, 1);
  rep(i, n) p[i] /= n;
  rep(i, k - 1) {
    ll r = i + 1;
    while (r < k) {
      r *= 2;
      p[i] /= 2;
    }
  }
  double ans = 0;
  rep(i, n) ans += p[i];
  cout << fixed << setprecision(12);
  cout << ans << endl;
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<double> p(n, 1);
  rep(i, n) p[i] /= n;
  ll q = min(n, k - 1) rep(i, q) {
    ll r = i + 1;
    while (r < k) {
      r *= 2;
      p[i] /= 2;
    }
  }
  double ans = 0;
  rep(i, n) ans += p[i];
  cout << fixed << setprecision(12);
  cout << ans << endl;
}
Problem p03043 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Map = map<string, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF = 1LL << 60;
ll MOD = 1000000007;

ll N, K;
// dp[i]はiからコインふって勝つ確率
vector<double> dp(100005, -1);
double F(ll e) {
  if (dp[e] != -1) {
    return dp[e];
  }
  if (e >= K) {
    return 1.0;
  }
  if (e <= 0) {
    return 0.0;
  } else
    return dp[e] = 0.5 * F(2 * e);
}

int main() {
  cin >> N;
  cin >> K;
  double ans = 0;
  for (ll i = 1; i <= N; i++) {
    ans += F(i) / N;
    ;
  }
  cout << fixed << setprecision(12);
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Map = map<string, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF = 1LL << 60;
ll MOD = 1000000007;

ll N, K;
// dp[i]はiからコインふって勝つ確率
vector<double> dp(100005, -1);
double F(ll e) {
  if (e >= 0 && e <= 100003 && dp[e] != -1) {
    return dp[e];
  }
  if (e >= K) {
    return 1.0;
  }
  if (e <= 0) {
    return 0.0;
  } else
    return dp[e] = 0.5 * F(2 * e);
}

int main() {
  cin >> N;
  cin >> K;
  double ans = 0;
  for (ll i = 1; i <= N; i++) {
    ans += F(i) / N;
    ;
  }
  cout << fixed << setprecision(12);
  cout << ans << endl;

  return 0;
}
Problem p03043 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>

#include <iomanip>

using namespace std;

vector<int> db;

int rec(int i, int K) {
  if (db[i] != -1)
    return db[i];
  if (i >= K) {
    db[i] = 0;
    return 0;
  }
  db[i] = rec(i * 2, K) + 1;
  return db[i];
}

int main() {
  int i, N, K, a, b, c;
  double ans = 0.0;
  cin >> N >> K;
  db.resize(N * 2 + 10);
  fill(db.begin(), db.end(), -1);

  for (i = 1; i <= N; i++) {
    a = rec(i, K);
    b = 1 << a;
    ans += 1.0 / (N * b);
  }

  // cout << std::fixed;
  cout << std::setprecision(12) << ans << endl;
  // cout << ans << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
#include <vector>

#include <iomanip>

using namespace std;

vector<int> db;

int rec(int i, int K) {
  if (db[i] != -1)
    return db[i];
  if (i >= K) {
    db[i] = 0;
    return 0;
  }
  db[i] = rec(i * 2, K) + 1;
  return db[i];
}

int main() {
  int i, N, K, a, b, c;
  double ans = 0.0;
  cin >> N >> K;
  db.resize(max(N * 2 + 10, K * 2 + 10));
  fill(db.begin(), db.end(), -1);

  for (i = 1; i <= N; i++) {
    a = rec(i, K);
    b = 1 << a;
    ans += 1.0 / (N * b);
  }

  // cout << std::fixed;
  cout << std::setprecision(12) << ans << endl;
  // cout << ans << endl;
  return 0;
}
Problem p03043 (C++)

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

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

  int N, K;
  cin >> N >> K;

  double ans = 0.0;
  long long cnt_abs_win = 0LL;
  int mx_bunbo = 0;
  vector<int> bunbo, bunsi;
  for (int i = 1; i <= N; i++) {
    if (i >= K) {
      cnt_abs_win++;
      // ans += 1.0 / N;
    } else {
      int tmp = i;
      int cnt = 0;
      while (tmp < K) {
        tmp *= 2;
        cnt++;
      }

      int tmp_bunbo = pow(2, cnt);
      if (tmp_bunbo >= mx_bunbo) {
        bunbo.push_back(tmp_bunbo);
        bunsi.push_back(1);
        mx_bunbo = tmp_bunbo;
      } else {
        int tmp_bunsi = 1;
        while (tmp_bunbo != mx_bunbo) {
          tmp_bunbo *= 2;
          tmp_bunsi *= 2;
        }
        bunbo.push_back(tmp_bunbo);
        bunsi.push_back(tmp_bunsi);
      }
    }
  }

  int ans_bunbo = bunbo[0] * N;
  int ans_bunsi =
      accumulate(bunsi.begin(), bunsi.end(), 0) + cnt_abs_win * bunbo[0];
  cout << fixed << setprecision(12) << (double)ans_bunsi / (double)ans_bunbo
       << endl;

  return 0;
}

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

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

  int N, K;
  cin >> N >> K;

  double ans = 0.0;
  long long cnt_abs_win = 0LL;
  int mx_bunbo = 0;
  vector<int> bunbo, bunsi;
  for (int i = 1; i <= N; i++) {
    if (i >= K) {
      cnt_abs_win++;
      // ans += 1.0 / N;
    } else {
      int tmp = i;
      int cnt = 0;
      while (tmp < K) {
        tmp *= 2;
        cnt++;
      }

      int tmp_bunbo = pow(2, cnt);
      if (tmp_bunbo >= mx_bunbo) {
        bunbo.push_back(tmp_bunbo);
        bunsi.push_back(1);
        mx_bunbo = tmp_bunbo;
      } else {
        int tmp_bunsi = 1;
        while (tmp_bunbo != mx_bunbo) {
          tmp_bunbo *= 2;
          tmp_bunsi *= 2;
        }
        bunbo.push_back(tmp_bunbo);
        bunsi.push_back(tmp_bunsi);
      }
    }
  }

  int ans_bunbo;
  int ans_bunsi;

  if (bunbo.size() > 0) {
    ans_bunbo = bunbo[0] * N;
    ans_bunsi =
        accumulate(bunsi.begin(), bunsi.end(), 0) + cnt_abs_win * bunbo[0];
  } else {
    ans_bunbo = 1;
    ans_bunsi = 1;
  }

  cout << fixed << setprecision(12) << (double)ans_bunsi / (double)ans_bunbo
       << endl;

  return 0;
}
Problem p03043 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  int cnt[200000];
  for (int i = k * 2 - 1; i >= 1; i--) {
    if (i % 2 == 0) {
      cnt[i / 2] = cnt[i] + 1;
    }
  }
  double p[25];
  p[0] = 1.0;
  for (int i = 0; i < 25 - 1; i++) {
    p[i + 1] = p[i] * 0.5;
  }
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    // cout << p[cnt[i]];
    ans += (1.0 / n) * p[cnt[i]];
  }
  printf("%.12lf\n", ans);
  return 0;
}


Fixed submission:
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  int cnt[500000];
  for (int i = k * 2 - 1; i >= 1; i--) {
    if (i % 2 == 0) {
      cnt[i / 2] = cnt[i] + 1;
    }
  }
  double p[25];
  p[0] = 1.0;
  for (int i = 0; i < 25 - 1; i++) {
    p[i + 1] = p[i] * 0.5;
  }
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    // cout << p[cnt[i]];
    ans += (1.0 / n) * p[cnt[i]];
  }
  printf("%.12lf\n", ans);
  return 0;
}
Problem p03043 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
double dp[10000]; // dp[i]: 現在の得点がiのときの勝率
int main() {
  int N, K;
  cin >> N >> K;
  for (int i = K - 1; i >= 1; i--) {
    dp[i] = 0.5 * (i * 2 >= K ? 1.0 : dp[i * 2]) + 0.5 * 0;
  }
  double ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += (i >= K ? 1.0 : dp[i]) / N;
  }
  cout << fixed << setprecision(12) << ans << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
double dp[100000]; // dp[i]: 現在の得点がiのときの勝率
int main() {
  int N, K;
  cin >> N >> K;
  for (int i = K - 1; i >= 1; i--) {
    dp[i] = 0.5 * (i * 2 >= K ? 1.0 : dp[i * 2]) + 0.5 * 0;
  }
  double ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += (i >= K ? 1.0 : dp[i]) / N;
  }
  cout << fixed << setprecision(12) << ans << '\n';
  return 0;
}
Problem p03043 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define intv vector<v>
#define llv vector<long long>
#define intvv vector<vector<int>>
#define llvv vector<vector<long long>>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    double temp = 1.0 / n;
    int j = i;
    while (j < k) {
      j *= 2;
      temp /= 2;
    }
    ans += temp;
  }
  return printf("%.12f\n", ans);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define intv vector<v>
#define llv vector<long long>
#define intvv vector<vector<int>>
#define llvv vector<vector<long long>>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    double temp = 1.0 / n;
    int j = i;
    while (j < k) {
      j *= 2;
      temp /= 2;
    }
    ans += temp;
  }
  printf("%.12f\n", ans);
}
Problem p03043 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll, ll>
#define pii pair<ll, pi>
#define pb push_back
#define mk make_pair
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  double long ans = 0.0;
  for (int i = 1; i <= n; i++) {
    if (i >= k)
      ans += (1.0) / n;
    else {
      int t = i;
      int count = 1;
      while (t < k) {
        t = 2 * t;
        count *= 2;
      }
      ans += 1.0 / (n * count);
    }
  }
  cout << fixed << setprecision(10) << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll, ll>
#define pii pair<ll, pi>
#define pb push_back
#define mk make_pair
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
int main() {
  // #ifndef ONLINE_JUDGE
  // 	freopen("input.txt", "r", stdin);
  // 	freopen("output.txt", "w", stdout);
  // #endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  double long ans = 0.0;
  for (int i = 1; i <= n; i++) {
    if (i >= k)
      ans += (1.0) / n;
    else {
      int t = i;
      int count = 1;
      while (t < k) {
        t = 2 * t;
        count *= 2;
      }
      ans += 1.0 / (n * count);
    }
  }
  cout << fixed << setprecision(10) << ans << endl;
}
Problem p03043 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  double sum = 0;
  for (int i = 0; i < N; i++) {
    double kaku = 1.0 / N;
    int now = i;
    while (K > now) {
      now *= 2;
      kaku /= 2;
    }
    sum += kaku;
  }
  cout << setprecision(12) << sum << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  double sum = 0;
  for (int i = 1; i <= N; i++) {
    double kaku = 1.0 / N;
    int now = i;
    while (K > now) {
      now *= 2;
      kaku /= 2;
    }
    sum += kaku;
  }
  cout << setprecision(12) << sum << endl;
}
Problem p03043 (Python)

Buggy submission (status: Time Limit Exceeded):
from functools import reduce
from operator import mul


def main():
    N, K = map(int, input().split())
    print(
        sum(
            [
                reduce(mul, [0.5 for j in range(K) if i << j < K], 1 / N)
                for i in range(1, N + 1)
            ]
        )
    )
    return


main()


Fixed submission:
from functools import reduce
from operator import mul


def main():
    N, K = map(int, input().split())
    ans = []
    lst = []
    for i in range(1, N + 1):
        lst.clear()
        for j in range(K):
            if K <= i << j:
                break
            lst.append(0.5)
        ans.append(reduce(mul, lst, 1 / N))
    print(sum(ans))
    return


main()
Problem p03043 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main(void) {
  int a, b;
  scanf("%d %d", &a, &b);
  double ret = 0;
  for (int loop = 0; loop <= a; loop++) {
    double tmp = 1.0 * a;
    int now = loop;
    while (now < b) {
      now *= 2;
      tmp /= 2;
    }
    ret += tmp;
  }
  printf("%.12f\n", ret);
  return 0;
}

Fixed submission:
#include <stdio.h>
int main(void) {
  int a, b;
  scanf("%d %d", &a, &b);
  double ret = 0;
  for (int loop = 1; loop <= a; loop++) {
    double tmp = 1.0 / a;
    int now = loop;
    while (now < b) {
      now *= 2;
      tmp /= 2;
    }
    ret += tmp;
  }
  printf("%.12f\n", ret);
  return 0;
}
Problem p03043 (C++)

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

using namespace std;

long gcd(long a, long b) {
  if (a < 0) {
    a = -a;
  }
  if (b < 0) {
    b = -b;
  }
  if (a == 0) {
    return b;
  }
  if (b == 0) {
    return a;
  }
  if (a < b) {
    return gcd(a, b % a);
  }
  return gcd(b, a % b);
}

int main() {
  long n, N, K;
  long s = 0;
  cin >> N >> K;
  n = N;
  double p = 0;
  if (K <= N) {
    s = N - K + 1;
    n = K - 1;
  }

  long *r = new long[n];
  long rate = 1;
  long rmax = 0;
  for (long i = n; i > 0; i--) {
    while (i * rate < K) {
      rate *= 2;
    }
    r[i - 1] = rate;
    rmax = max(rmax, rate);
  }

  long sum = s * rmax;
  long buf = -1;
  for (long i = 0; i < n; i++) {
    if (i == n - 1 || r[i] != r[i + 1]) {
      sum += (i - buf) * (rmax / r[i]);
      buf = i;
    }
  }
  s = rmax * N;

  long g = gcd(sum, s);
  sum /= g;
  s /= g;
  p = (long double)sum / (long double)s;

  printf("%.20lf\n", p);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

long gcd(long a, long b) {
  if (a < 0) {
    a = -a;
  }
  if (b < 0) {
    b = -b;
  }
  if (a == 0) {
    return b;
  }
  if (b == 0) {
    return a;
  }
  if (a < b) {
    return gcd(a, b % a);
  }
  return gcd(b, a % b);
}

int main() {
  long n, N, K;
  long s = 0;
  cin >> N >> K;
  n = N;
  double p = 0;
  if (K <= N) {
    s = N - K + 1;
    n = K - 1;
  }
  if (n == 0) {
    cout << 1 << endl;
    return 0;
  }
  long *r = new long[n];
  long rate = 1;
  long rmax = 0;
  for (long i = n; i > 0; i--) {
    while (i * rate < K) {
      rate *= 2;
    }
    r[i - 1] = rate;
    rmax = max(rmax, rate);
  }

  long sum = s * rmax;
  long buf = -1;
  for (long i = 0; i < n; i++) {
    if (i == n - 1 || r[i] != r[i + 1]) {
      sum += (i - buf) * (rmax / r[i]);
      buf = i;
    }
  }
  s = rmax * N;

  long g = gcd(sum, s);
  sum /= g;
  s /= g;
  p = (long double)sum / (long double)s;

  printf("%.20lf\n", p);
  return 0;
}
Problem p03043 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

int main() {
  double n, k, ans;
  cin >> n >> k;
  ans = 0.0;
  for (int i = 0; i < n; i++) {
    ll point = i;
    int p = 0;
    while (point < k) {
      point *= 2;
      p++;
    }
    ans += (1 / n) * pow(0.50, p);
  }
  cout << fixed << setprecision(15) << ans << endl;
}


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

int main() {
  double n, k, ans;
  cin >> n >> k;
  ans = 0.0;
  for (int i = 1; i <= n; i++) {
    ll point = i;
    int p = 0;
    while (point < k) {
      point *= 2;
      p++;
    }
    ans += (1 / n) * pow(0.50, p);
  }
  cout << fixed << setprecision(15) << ans << endl;
}