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

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

int main() {
  int N, counter = 0;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  while (true) {

    bool exist_odd = false;
    for (int x : A) {
      if (x % 2 != 0) {
        exist_odd = true;
      }
    }

    if (exist_odd)
      break; // 奇数があったら break

    // 操作を行えるなら操作を実際に行う
    for (int i = 0; i < N; ++i) {
      A[i] /= 2;
    }
    ++counter; // 操作回数をインクリメント
  }
  cout << counter << endl;
}

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

int main() {
  int N, counter = 0;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  while (true) {

    bool exist_odd = false;
    for (int x = 0; x < A.size(); x++) {
      if (A[x] % 2 != 0) {
        exist_odd = true;
      }
    }

    if (exist_odd)
      break; // 奇数があったら break

    // 操作を行えるなら操作を実際に行う
    for (int i = 0; i < N; ++i) {
      A[i] /= 2;
    }
    ++counter; // 操作回数をインクリメント
  }
  cout << counter << endl;
}
Problem p03494 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a = 1e9, b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b;
    long long cnt = 0;
    while (b % 2 == 0) {
      cnt++;
    }
    a = min(a, cnt);
  }
  cout << a << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a = 1e9, b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b;
    long long cnt = 0;
    while (b % 2 == 0) {
      b /= 2;
      cnt++;
    }
    a = min(a, cnt);
  }
  cout << a << endl;
}
Problem p03494 (C++)

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

int main() {

  int n;
  cin >> n;
  int bb[n], i;
  for (i = 0; i < n; i++) {
    cin >> bb[i];
  }
  int k = 0, flag = 0;
  while (1) {
    for (i = 0; i < n; i++) {
      if (bb[i] % 2 == 0) {
        bb[i] %= 2;
      } else {
        flag = 1;
        break;
      }
    }
    if (flag)
      break;
    else
      k++;
  }
  cout << k << endl;
  return 0;
}


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

int main() {

  int n;
  cin >> n;
  int bb[n], i;
  for (i = 0; i < n; i++) {
    cin >> bb[i];
  }
  int k = 0, flag = 0;
  while (1) {
    for (i = 0; i < n; i++) {
      if (bb[i] % 2 == 0) {
        bb[i] /= 2;
      } else {
        flag = 1;
        break;
      }
    }
    if (flag)
      break;
    else
      k++;
  }
  cout << k << endl;
  return 0;
}
Problem p03494 (C++)

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

int main() {
  int N;
  cin >> N;
  int A[210];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  bool frag;
  frag = true;
  int count = 0;
  while (frag == true) {
    for (int i = 0; i < N; i++) {
      if (A[i] % 2 == 1) {
        frag = false;
      }
    }
    if (frag == true) {
      count++;
    }
  }
  cout << count << endl;
}

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

int main() {
  int N;
  cin >> N;
  int A[210];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  bool frag;
  frag = true;
  int count = 0;
  while (frag == true) {
    for (int i = 0; i < N; i++) {
      if (A[i] % 2 == 1) {
        frag = false;
      }
    }
    if (frag == true) {
      count++;
    }
    for (int i = 0; i < N; i++) {
      A[i] = A[i] / 2;
    }
  }
  cout << count << endl;
}
Problem p03494 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int count = 0;
  bool cond = true;
  while (cond) {
    for (int i = 0; i < n; i++) {
      if (a[i] %= 2 == 0) {
        a[i] /= 2;
      } else {
        cond = false;
        break;
      }
    }
    if (cond)
      count++;
  }

  cout << count << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int count = 0;
  bool cond = true;
  while (cond) {
    for (int i = 0; i < n; i++) {
      if (a[i] % 2 == 0) {
        a[i] /= 2;
      } else {
        cond = false;
        break;
      }
    }
    if (cond)
      count++;
  }

  cout << count << endl;
  return 0;
}
Problem p03494 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
ll div_2(ll a) {
  ll ans = 0;
  while (a % 2 == 0) {
    ans++;
    ans /= 2;
  }
  return ans;
}
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  ll min = 1000000000;
  rep(i, N) {
    cin >> A[i];
    if (min > div_2(A[i])) {
      min = div_2(A[i]);
    }
  }
  cout << min << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
ll div_2(ll a) {
  ll ans = 0;
  while (a % 2 == 0) {
    ans++;
    a /= 2;
  }
  return ans;
}
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  ll min = 1000000000;
  rep(i, N) {
    cin >> A[i];
    if (min > div_2(A[i])) {
      min = div_2(A[i]);
    }
  }
  cout << min << endl;
}
Problem p03494 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, j = 0;
  cin >> n;
  vector<int> a(n);
  int c = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  while (1) {
    j = 0;
    for (int i = 0; i < n; i++) {
      if (a.at(i) % 2 == 0) {
        j++;
        if (j == n)
          c++;
        continue;
      } else
        break;
    }
    if (j != n)
      break;
    else
      continue;
  }
  cout << c << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, j = 0;
  cin >> n;
  vector<int> a(n);
  int c = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  while (1) {
    j = 0;
    for (int i = 0; i < n; i++) {
      if (a.at(i) % 2 == 0) {
        a.at(i) /= 2;
        j++;
        if (j == n)
          c++;
        continue;
      } else
        break;
    }
    if (j != n)
      break;
    else
      continue;
  }
  cout << c << endl;
}
Problem p03494 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
while all(A % 2 == 0 for A in a):
    A = [i / 2 for i in a]
    ans += 1
print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
while all(A % 2 == 0 for A in a):
    a = [i / 2 for i in a]
    ans += 1
print(ans)
Problem p03494 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]

DA = []
for v in A:
    d = 0
    while v & 1 == 0:
        v = v << 2
        d += 1
    DA.append(d)

print(min(DA))


Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

DA = []
for v in A:
    d = 0
    while v & 1 == 0:
        v = v >> 1
        d += 1
    DA.append(d)

print(min(DA))
Problem p03494 (Python)

Buggy submission (status: Runtime Error):
kazu = int(input())
numbers_list = list(map(int, input().split()))
count = 0
seisu = 0
while True:
    for index in range(kazu):
        if numbers_list[index] % 2 != 0:
            seisu = 1
            break
        else:
            numbers_list[index] = numbers_list / 2
    if seisu == 1:
        break
    count += 1
print(count)


Fixed submission:
kazu = int(input())
numbers_list = list(map(int, input().split()))
count = 0
seisu = 0
while True:
    for index in range(kazu):
        if numbers_list[index] % 2 != 0:
            seisu = 1
            break
        else:
            numbers_list[index] = numbers_list[index] / 2
    if seisu == 1:
        break
    count += 1
print(count)
Problem p03494 (Python)

Buggy submission (status: Time Limit Exceeded):
n = input()
a = list(map(int, input().split()))

count = 0
odd = ""

while True:
    for i, n in enumerate(a):
        if n % 2 == 0:
            a[i] == n / 2
            count += 1
        else:
            odd = "finish"
            break
    if odd == "finish":
        break
print(count)


Fixed submission:
n = input()
a = list(map(int, input().split()))

ans = a[0]
for i in range(int(n)):
    count = 0
    while a[i] % 2 == 0:
        a[i] /= 2
        count += 1
    ans = min(ans, count)
print(ans)
Problem p03494 (Python)

Buggy submission (status: Runtime Error):
import sys

input = sys.stdin.readline

N = input()
B = map(int, input().split())

answer = None
for i in B:
    answer = min(answer, len(bin(i)) - bin(i).rfind("1") - 1)
print(answer)


Fixed submission:
import sys

input = sys.stdin.readline

N = input()
B = map(int, input().split())

answer = float("inf")
for i in B:
    answer = min(answer, len(bin(i)) - bin(i).rfind("1") - 1)
print(answer)
Problem p03494 (Python)

Buggy submission (status: Runtime Error):
N = int(input())

numbers = list(map(int, input()))
counter = 0

while all(number % 2 == 0 for number in numbers):
    numbers = [number / 2 for number in numbers]
    counter += 1

print(counter)


Fixed submission:
N = int(input())

numbers = list(map(int, input().split()))
counter = 0

while all(number % 2 == 0 for number in numbers):
    numbers = [number / 2 for number in numbers]
    counter += 1

print(counter)
Problem p03494 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define lper(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9;
const ll INF = 4e18;
const ll dy[4] = {1, 0, -1, 0};
const ll dx[4] = {0, -1, 0, 1};
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  rep(i, N) { cin >> vec.at(i); }
  int count = 0;

  repl(i, 1, inf) {
    int ans = 0;
    rep(i, N) {
      if (vec.at(i) % 2 == 0) {
        ans++;
      }
    }
    if (ans == N) {
      count++;
      rep(i, N) { vec.at(i) = vec.at(i) / 2; }
    }
  }
  cout << count << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define lper(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9;
const ll INF = 4e18;
const ll dy[4] = {1, 0, -1, 0};
const ll dx[4] = {0, -1, 0, 1};
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  rep(i, N) { cin >> vec.at(i); }
  int count = 0;

  repl(i, 1, 10000) {
    int ans = 0;
    rep(i, N) {
      if (vec.at(i) % 2 == 0) {
        ans++;
      }
    }
    if (ans == N) {
      count++;
      rep(i, N) { vec.at(i) = vec.at(i) / 2; }
    }
  }
  cout << count << endl;
}
Problem p03494 (C++)

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

int main() {
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++)
    cin >> a[i];
  int cnt = 0;
  while (1) {
    bool ndiv = false;
    for (int i = 0; i < N; i++) {
      if (a[i] % 2 != 0)
        ndiv = true;
    }
    if (ndiv)
      break;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++)
    cin >> a[i];
  int cnt = 0;
  while (1) {
    bool ndiv = false;
    for (int i = 0; i < N; i++) {
      if (a[i] % 2 != 0)
        ndiv = true;
      if (a[i] % 2 == 0)
        a[i] /= 2;
    }
    if (ndiv)
      break;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p03494 (C++)

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

int main() {
  int N, A[110], ans = 0;
  cin >> N;
  REP(i, N) cin >> A[i];
  bool is_continue = true;
  while (is_continue) {
    REP(i, N) {
      if (A[i] % 2 != 0) {
        is_continue = false;
        break;
      } else {
        A[i] /= 2;
      }
    }
    if (is_continue == true)
      ans++;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int N, A[210], ans = 0;
  cin >> N;
  REP(i, N) cin >> A[i];
  bool is_continue = true;
  while (is_continue) {
    REP(i, N) {
      if (A[i] % 2 != 0) {
        is_continue = false;
        break;
      } else {
        A[i] /= 2;
      }
    }
    if (is_continue == true)
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p03494 (C++)

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

int main() {
  int N;
  cin >> N;
  int num[N];
  for (int i = 0; i < N; i++) {
    cin >> num[i];
  }
  bool a = true;
  int ans = 0;
  while (a) {
    for (int i = 0; i < N; i++) {
      if (num[i] % 2 == 1) {
        a = false;
        break;
      }
      num[i] / 2;
    }
    if (a) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  int num[N];
  for (int i = 0; i < N; i++) {
    cin >> num[i];
  }
  bool a = true;
  int ans = 0;
  while (a) {
    for (int i = 0; i < N; i++) {
      if (num[i] % 2 == 1) {
        a = false;
        break;
      }
      num[i] /= 2;
    }
    if (a) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03494 (C++)

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

using namespace std;

int main(void) {

  int N, count, count2 = 0;

  cin >> N;

  int A[N];

  for (int i = 0; i < N; i++)
    cin >> A[i];

  for (int i = 0;; i++) {
    count = 0;
    for (int j = 0; j < N; j++) {
      if (A[j] % 2 == 0) {
        count++;
        A[j] /= 2;
      } else
        break;
    }
    if (count == N) {
      count2++;
    }
  }

  cout << count2;

  return 0;
}

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

using namespace std;

int main(void) {

  int N, count, count2 = 0;

  cin >> N;

  int A[N];

  for (int i = 0; i < N; i++)
    cin >> A[i];

  for (int i = 0; i < 200; i++) {
    count = 0;
    for (int j = 0; j < N; j++) {
      if (A[j] % 2 == 0) {
        count++;
        A[j] /= 2;
      } else
        break;
    }
    if (count == N) {
      count2++;
    }
  }

  cout << count2;

  return 0;
}
Problem p03494 (C++)

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

using namespace std;

int main() {
  int A[10];
  int N, cmp = 0, sum = 0;
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] % 2 != 0)
      cmp++;
  }

  while (cmp == 0) {
    for (int i = 0; i < N; i++) {
      A[i] /= 2;
      if (A[i] % 2 != 0)
        cmp++;
    }
    sum++;
  }

  cout << sum << endl;
}

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

using namespace std;

int main() {
  int A[200];
  int N, cmp = 0, sum = 0;
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] % 2 != 0)
      cmp++;
  }

  while (cmp == 0) {
    for (int i = 0; i < N; i++) {
      A[i] /= 2;
      if (A[i] % 2 != 0)
        cmp++;
    }
    sum++;
  }

  cout << sum << endl;
}
Problem p03494 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
  }
  int t = 0;
  int ans = 10000;
  for (int i = 0; i < n; i++) {
    while (d.at(i) > 0) {
      d.at(i) / 2;
      t++;
    }
    ans = min(ans, t);
  }
  cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
  }
  int t = 0;
  int ans = 10000;
  for (int i = 0; i < n; i++) {
    t = 0;
    while (d.at(i) % 2 == 0) {
      d.at(i) /= 2;
      t++;
    }
    ans = min(ans, t);
  }
  cout << ans << endl;
}
Problem p03494 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <iostream>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;
const ll INF = 100000000000000LL;

int main() {
  int n, a[101], mi = 1000000000;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    int k = a[i], l = 0;
    while (1) {
      if (k % 2 > 0)
        break;
      l++;
      k /= 2;
    }
    mi = min(mi, l);
  }

  cout << mi << endl;
  return 0;
}


Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;
const ll INF = 100000000000000LL;

int main() {
  int n, a[201], mi = 1000000000;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    int k = a[i], l = 0;
    while (1) {
      if (k % 2 > 0)
        break;
      l++;
      k /= 2;
    }
    mi = min(mi, l);
  }

  cout << mi << endl;
  return 0;
}
Problem p03494 (C++)

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

int main() {
  int N, cnt = 0;
  int num[N];
  int flag = 0;

  for (int i = 0; i < N; i++) {
    cin >> num[i];
  }
  while (flag == 0) {
    for (int i = 0; i < N; i++) {
      if (num[i] % 2 != 0) {
        flag = 1;
        break;
      } else {
        num[i] /= 2;
      }
    }
    if (flag == 0)
      cnt++;
  }
  cout << cnt << endl;
}


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

int main() {
  int N, cnt = 0;
  int num[N];
  int flag = 0;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> num[i];
  }
  while (flag == 0) {
    for (int i = 0; i < N; i++) {
      if (num[i] % 2 != 0) {
        flag = 1;
        break;
      } else {
        num[i] /= 2;
      }
    }
    if (flag == 0)
      cnt++;
  }
  cout << cnt << endl;
}
Problem p03494 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int count = 0;
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  while (true) {
    bool exist_odd = false;
    for (int i = 0; i < N; i++) {
      if (vec.at(i) % 2 == 1) {
        exist_odd = true;
      }
    }
    if (exist_odd)
      break;
    for (int i = 0; i < N; i++) {
      vec.at(i) %= 2;
    }
    count++;
  }
  cout << count << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int count = 0;
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  while (true) {
    bool exist_odd = false;
    for (int i = 0; i < N; i++) {
      if (vec.at(i) % 2 == 1) {
        exist_odd = true;
      }
    }
    if (exist_odd)
      break;
    for (int i = 0; i < N; i++) {
      vec.at(i) /= 2;
    }
    count++;
  }
  cout << count << endl;
}
Problem p03494 (C++)

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

int main() {
  int n, i;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  while (true) {
    bool flag = false;
    for (i = 0; i < n; i++) {
      if (a[i] & 2 == 1) {
        flag = true;
        break;
      }
      a[i] /= 2;
    }
    if (flag) {
      break;
    }
    count++;
  }
  cout << count << endl;
}

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

int main() {
  int n, i;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  while (true) {
    bool flag = false;
    for (i = 0; i < n; i++) {
      if (a[i] % 2 == 1) {
        flag = true;
        break;
      }
      a[i] /= 2;
    }
    if (flag) {
      break;
    }
    count++;
  }
  cout << count << endl;
}
Problem p03494 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define __int64 long long
#define long __int64
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
const int Vec = 4;
const int Vecy[Vec] = {0, -1, 0, 1};
const int Vecx[Vec] = {1, 0, -1, 0};
const int Modd = 1000000007;

int a[200];

int main() {
  int n;
  cin >> n;
  rep(i, n) { cin >> a[i]; }

  int ans = 0;
  for (ans = 0; true; ans++) {
    rep(i, n) {
      if (a[i] % 2 != 0) {
        cout << ans << endl;
        return ans;
      }
    }

    rep(i, n) { a[i] /= 2; }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define __int64 long long
#define long __int64
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
const int Vec = 4;
const int Vecy[Vec] = {0, -1, 0, 1};
const int Vecx[Vec] = {1, 0, -1, 0};
const int Modd = 1000000007;

int a[200];

int main() {
  int n;
  cin >> n;
  rep(i, n) { cin >> a[i]; }

  int ans = 0;
  for (ans = 0; true; ans++) {
    rep(i, n) {
      if (a[i] % 2 != 0) {
        cout << ans << endl;
        return 0;
      }
    }

    rep(i, n) { a[i] /= 2; }
  }

  cout << ans << endl;

  return 0;
}
Problem p03494 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
  int N = 0;
  vector<int> vec(N);
  cin >> N;
  rep(i, N) cin >> vec[i];
  int counter = 0, odd = 0;
  while (true) {
    rep(i, N) {
      if (vec[i] % 2 == 1)
        odd++;
    }
    if (odd > 0)
      break;
    rep(i, N) vec[i] = vec[i] / 2;
    counter++;
  }
  cout << counter << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
  int N = 0;
  vector<int> vec(300);
  cin >> N;
  rep(i, N) cin >> vec[i];
  int counter = 0, odd = 0;
  while (true) {
    rep(i, N) {
      if (vec[i] % 2 == 1)
        odd++;
    }
    if (odd > 0)
      break;
    rep(i, N) vec[i] = vec[i] / 2;
    counter++;
  }
  cout << counter << endl;
}
Problem p03494 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long mod2 = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int divCeil(int A, int B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, int B) { return (A + (B - 1)) / B; }
long long divCeil(int A, long long B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, long long B) { return (A + (B - 1)) / B; }

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);

  int ans = 0;
  while (true) {
    bool fin = false;
    for (int i = 0; i < N; i++) {
      if (A.at(i) % 2 == 1) {
        fin = true;
        break;
      }
    }
    if (fin)
      break;

    for (int i = 0; i < N; i++) {
      A.at(i) %= 2;
    }
    ans++;
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long mod2 = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int divCeil(int A, int B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, int B) { return (A + (B - 1)) / B; }
long long divCeil(int A, long long B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, long long B) { return (A + (B - 1)) / B; }

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);

  int ans = 0;
  while (true) {
    bool fin = false;
    for (int i = 0; i < N; i++) {
      if (A.at(i) % 2 == 1) {
        fin = true;
        break;
      }
    }
    if (fin)
      break;

    for (int i = 0; i < N; i++) {
      A.at(i) /= 2;
    }
    ans++;
  }

  cout << ans << endl;
}
Problem p03494 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  while (true) {
    for (int i = 0; i < n; i++) {
      if (a[i] % 2 != 0) {
        cout << ans << endl;
        return 0;
      }
    }
    ans++;
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  while (true) {
    for (int i = 0; i < n; i++) {
      if (a[i] % 2 != 0) {
        cout << ans << endl;
        return 0;
      }
      a[i] /= 2;
    }
    ans++;
  }
  return 0;
}
Problem p03494 (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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int N;
  vector<int> A(N);
  rep(i, N) { cin >> A[i]; }

  int count = 0;
  while (true) {
    rep(i, N) {
      if (A[i] % 2 != 0) { // 偶数判定
        cout << count << endl;
        return 0;
      } else {
        A[i] /= 2;
      }
    }
    count++;
  }

  cout << count << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.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++)

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) { cin >> A[i]; }

  int count = 0;
  while (true) {
    rep(i, N) {
      if (A[i] % 2 != 0) { // 偶数判定
        cout << count << endl;
        return 0;
      } else {
        A[i] /= 2;
      }
    }
    count++;
  }

  cout << count << endl;
  return 0;
}
Problem p03494 (C++)

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

int N;
int A[210];

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i)
    cin >> A[i];

  int counter = 0;

  while (true) {
    bool flag_odd = false;

    for (int i = 0; i < N; ++i) {
      if (A[i] % 2 != 0)
        flag_odd = true;
      break;

      A[i] /= 2;
    }

    if (flag_odd)
      break;

    ++counter;
  }

  cout << counter << endl;

  return 0;
}

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

int N;
int A[210];

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i)
    cin >> A[i];

  int counter = 0;

  while (true) {
    bool flag_odd = false;

    for (int i = 0; i < N; ++i) {
      if (A[i] % 2 != 0)
        flag_odd = true;
      if (flag_odd)
        break;

      A[i] /= 2;
    }

    if (flag_odd)
      break;

    ++counter;
  }

  cout << counter << endl;

  return 0;
}
Problem p03494 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> a;
  for (int i = 0; i < N; i++)
    cin >> a[i];
  int ans = 0;
  while (true) {
    bool f = false;
    for (int i = 0; i < N; i++) {
      if (a[i] % 2 == 1)
        f = true;
      else
        a[i] /= 2;
    }
    if (f)
      break;
    ans++;
  }
  cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  int ans = 0;
  while (true) {
    bool f = false;
    for (int i = 0; i < N; i++) {
      if (a[i] % 2 == 1)
        f = true;
      else
        a[i] /= 2;
    }
    if (f)
      break;
    ans++;
  }
  cout << ans << endl;
}
Problem p03494 (C++)

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

int main() {
  int n, x, min = 32, count = 0;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> x;
    for (int j = x; j % 2 == 0; j / 2) {
      count++;
    }
    if (count < min) {
      min = count;
    }
    count = 0;
  }

  std::cout << min << '\n';

  return 0;
}


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

int main() {
  int n, x, min = 32, count = 0;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> x;
    for (int j = x; j % 2 == 0; j = j / 2) {
      count++;
    }
    if (count < min) {
      min = count;
    }
    count = 0;
  }

  std::cout << min << '\n';

  return 0;
}
Problem p03494 (C++)

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

int main() {
  int N, A[100], cnt = 0;
  cin >> N;

  for (int i = 0; i < N; i++)
    cin >> A[i];

  int flag = 0;
  while (flag == 0) {
    for (int i = 0; i < N; i++) {
      if (A[i] % 2 != 0) {
        flag = 1;
        break;
      }
      A[i] = A[i] / 2;

      if (i == N - 1)
        cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}

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

int main() {
  int N, A[250], cnt = 0;
  cin >> N;

  for (int i = 0; i < N; i++)
    cin >> A[i];

  int flag = 0;
  while (flag == 0) {
    for (int i = 0; i < N; i++) {
      if (A[i] % 2 != 0) {
        flag = 1;
        break;
      }
      A[i] = A[i] / 2;

      if (i == N - 1)
        cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}
Problem p03494 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
  int N, cm = 2147483647;
  cin >> N;
  priority_queue<int, vector<int>, greater<int>> Q;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    Q.push(a);
  }
  for (int i = 0; i < N; i++) {
    int x, c = 0;
    x = Q.top();
    Q.pop();
    while (true) {
      if ((double)x / (double)2 == double(x / 2)) {
        x >> 1;
        c++;
        if (c >= cm)
          break;
      } else {
        break;
      }
    }
    if (cm > c)
      cm = c;
  }
  cout << cm;
  return 0;
}

Fixed submission:
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
  int N, cm = 2147483647;
  cin >> N;
  priority_queue<int, vector<int>, greater<int>> Q;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    Q.push(a);
  }
  for (int i = 0; i < N; i++) {
    int x, c = 0;
    x = Q.top();
    Q.pop();
    while (true) {
      if (x % 2 == 0) {
        x = x / 2;
        c++;
        if (c >= cm)
          break;
      } else {
        break;
      }
    }
    if (cm > c)
      cm = c;
  }
  cout << cm;
  return 0;
}
Problem p03494 (C++)

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

using namespace std;

int howdividetwo(int n) {

  int sum = 0;

  while (n > 0 || n % 2 == 0) {

    ++sum;

    n /= 2;
  }

  return sum;
}

int main() {
  int n;
  cin >> n;
  int a[200];

  int mi = 999999999;
  for (int i = 0; i < n; i++) {

    int buf;

    cin >> buf;

    mi = min(mi, howdividetwo(buf));
  }

  cout << mi << endl;

  return 0;
}


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

using namespace std;

int howdividetwo(int n) {

  int sum = 0;

  while (n > 0 && n % 2 == 0) {

    ++sum;

    n /= 2;
  }

  return sum;
}

int main() {
  int n;
  cin >> n;
  int a[200];

  int mi = 999999999;
  for (int i = 0; i < n; i++) {

    int buf;

    cin >> buf;

    mi = min(mi, howdividetwo(buf));
  }

  cout << mi << endl;

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, k;
  unordered_map<int, int> mp;
  cin >> n >> k;
  REP(i, n) {
    int work;
    cin >> work;
    mp[work]++;
  }
  vector<pair<int, int>> v;
  for (auto e : mp)
    v.push_back(make_pair(e.second, e.first));
  sort(v.begin(), v.end(), greater<pair<int, int>>());
  int t = 0;
  REP(i, k) { t += v[i].first; }
  cout << n - t << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, k;
  unordered_map<int, int> mp;
  cin >> n >> k;
  REP(i, n) {
    int work;
    cin >> work;
    mp[work]++;
  }
  vector<pair<int, int>> v;
  for (auto e : mp)
    v.push_back(make_pair(e.second, e.first));
  sort(v.begin(), v.end(), greater<pair<int, int>>());
  int t = 0;
  REP(i, v.size()) {
    if (i == k)
      break;
    t += v[i].first;
  }
  cout << n - t << endl;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, c = 0;
  cin >> n >> k;
  int a[n];
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  vector<int> b;
  for (auto s : mp) {
    b.push_back(s.second);
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < b.size() - k; i++) {
    c += b[i];
  }
  cout << c;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, c = 0;
  cin >> n >> k;
  int a[n];
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  vector<int> b;
  for (auto s : mp) {
    b.push_back(s.second);
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < (int)b.size() - k; i++) {
    c += b[i];
  }
  cout << c;
}
Problem p03495 (Python)

Buggy submission (status: Time Limit Exceeded):
n, k = (int(i) for i in input().split())
balls = list(int(i) for i in input().split())
ball_set = set(balls)
freqs = list(balls.count(i) for i in ball_set)
freqs.sort(reverse=True)
print(sum(freqs[k:]))


Fixed submission:
n, k = (int(i) for i in input().split())
balls = (int(i) for i in input().split())
freqs = {}
for ball in balls:
    freqs[ball] = freqs[ball] + 1 if ball in freqs else 1
freq_hist = list(freqs.values())
freq_hist.sort(reverse=True)
print(sum(freq_hist[k:]))
Problem p03495 (Python)

Buggy submission (status: Runtime Error):
n, k = map(int, input().split())
aList = list(map(int, input().split()))
num = [0 for _ in range(n)]
for i in aList:
    num[i] += 1
num.sort()
num = num[:-k]
print(sum(num))


Fixed submission:
n, k = map(int, input().split())
aList = list(map(int, input().split()))
num = [0 for _ in range(n + 1)]
for i in aList:
    num[i] += 1
num.sort()
num = num[:-k]
print(sum(num))
Problem p03495 (Python)

Buggy submission (status: Time Limit Exceeded):
from collections import Counter

n, k = map(int, input().split())
a = list(map(int, input().split()))
b = 0
for t in range(n):
    if len(set(a)) <= k:
        print(b)
        break
    else:
        c = Counter(a)
        d = min(c, key=c.get)
        e = max(c, key=c.get)
        a = [e if i == d else i for i in a]
        b = b + c[d]


Fixed submission:
from collections import Counter

n, k = map(int, input().split())
a = list(map(int, input().split()))
if len(set(a)) <= k:
    print(0)
else:
    b = Counter(a)
    t = len(set(a)) - k
    c = b.most_common()[: -t - 1 : -1]
    d = 0
    for e in c:
        d = d + e[1]
    print(d)
Problem p03495 (Python)

Buggy submission (status: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

numlist = {}
for i in A:
    if i in numlist:
        numlist[i] += 1
    else:
        numlist[i] = 1
numbers = numlist.values()
numbers = sorted(numbers)

change = 0
while len(numbers) > K:
    change += numbers[0]
    del numbers[0]
print(change)


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

numlist = {}
for i in A:
    if i in numlist:
        numlist[i] += 1
    else:
        numlist[i] = 1
numbers = numlist.values()
numbers = sorted(numbers)

change = 0
vari = len(numbers)
for i in range(vari):
    if K >= vari - i:
        break
    change += numbers[i]

print(change)
Problem p03495 (C++)

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

int main() {
  int n, k;
  int x;
  int a[N] = {0};
  int cnt = 0;
  cin >> n >> k;
  rep(i, n) {
    scanf("%d", &x);
    if (a[x] == 0)
      cnt++;
    a[x]++;
  }
  sort(a, a + N);
  if (cnt <= k) {
    cout << 0 << endl;
    return 0;
  }
  int sum = 0;
  for (int i = N - cnt; i < N - k; i++)
    sum += a[i];
  cout << sum << endl;

  return 0;
}


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

int main() {
  int n, k;
  int x;
  int a[N] = {0};
  int cnt = 0;
  cin >> n >> k;
  rep(i, n) {
    scanf("%d", &x);
    if (a[x] == 0)
      cnt++;
    a[x]++;
  }
  sort(a, a + N);
  if (cnt <= k) {
    cout << 0 << endl;
    return 0;
  }
  int sum = 0;
  for (int i = N - cnt; i < N - k; i++)
    sum += a[i];
  cout << sum << endl;

  return 0;
}
Problem p03495 (Python)

Buggy submission (status: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A1 = set(A)
AN = {}
for a in A1:
    AN[a] = A.count(a)
AN = sorted(AN.items(), key=lambda x: x[1])
ans = 0
K1 = len(A1) - K
if K1 > 0:
    for k in range(K1):
        ans += AN[k][1]
    print(ans)
else:
    print("0")


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A1 = set(A)
AN = {}
for a in A:
    if not a in AN:
        AN[a] = 0
    AN[a] += 1
AN = sorted(AN.items(), key=lambda x: x[1])
ans = 0
K1 = len(A1) - K
if K1 > 0:
    for k in range(K1):
        ans += AN[k][1]
    print(ans)
else:
    print("0")
Problem p03495 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const int MAX_N = 200010;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    mp[x]++;
  }
  int ans = 0;
  while (mp.size() > k) {
    int min_x = INF;
    int point = -1;
    for (auto itr : mp) {
      if (itr.second < min_x) {
        min_x = itr.second;
        point = itr.first;
      }
    }
    ans += min_x;
    mp.erase(point);
  }
  cout << ans << "\n";
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const int MAX_N = 200010;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    mp[x]++;
  }
  int ans = 0;
  vector<P> v;
  for (auto itr : mp) {
    v.push_back(P(itr.second, itr.first));
  }
  sort(v.begin(), v.end());
  int cnt = v.size() - k;
  for (int i = 0; i < v.size(); i++) {
    if (cnt <= 0)
      break;
    ans += v[i].first;
    cnt--;
  }
  cout << ans << "\n";
  return 0;
}
Problem p03495 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    mp[A[i]]++;
  }
  vector<int> B;
  for (auto p : mp) {
    B.push_back(p.second);
  }
  // cout << "Yes"<<endl;

  sort(B.begin(), B.end());
  int sum = 0;
  int f = B.size();
  // cout << B.size() << "  " << K << endl;
  if ((B.size() - K) <= 0) {
    cout << 0 << endl;
    return 0;
  } else {
    for (int i = 0; i < B.size() - K; i++) {
      sum += B[i];
    }
    cout << sum << endl;
  }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    mp[A[i]]++;
  }
  vector<int> B;
  for (auto p : mp) {
    B.push_back(p.second);
  }
  // cout << "Yes"<<endl;

  sort(B.begin(), B.end());
  int sum = 0;
  int f = B.size();
  // cout << B.size() << "  " << K << endl;
  if ((f - K) <= 0) {
    cout << 0 << endl;
    return 0;
  } else {
    for (int i = 0; i < B.size() - K; i++) {
      sum += B[i];
    }
    cout << sum << endl;
  }
}
Problem p03495 (C++)

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

using namespace std;

int main() {
  int N, K;
  // vector<int> A = vector<int>(200001, 0);
  vector<int> A;

  cin >> N >> K;

#if 1
  for (int i = 0; i <= N; i++)
    A.push_back(0);
#else
  A.resize(N + 1);
#endif

  for (int i = 0; i < N; i++) {
    int temp;
    cin >> temp;
    A[temp]++;
  }

  int numVal = 0;
  for (int i = 0; i <= N; i++) {
    if (A[i])
      numVal++;
    else
      A[i] = 200100;
  }

  int modifyCount = 0;

  if (numVal > K) {
    sort(A.begin(), A.end()); // sortする
    for (int n = 0; n < numVal - K; n++) {
      // sortする
      sort(A.begin(), A.end());
      modifyCount += A[n];
    }
  }

  cout << modifyCount << endl;
}


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

using namespace std;

int main() {
  int N, K;
  // vector<int> A = vector<int>(200001, 0);
  vector<int> A;

  cin >> N >> K;

#if 1
  for (int i = 0; i <= N; i++)
    A.push_back(0);
#else
  A.resize(N + 1);
#endif

  for (int i = 0; i < N; i++) {
    int temp;
    cin >> temp;
    A[temp]++;
  }

  int numVal = 0;
  for (int i = 0; i <= N; i++) {
    if (A[i])
      numVal++;
    else
      A[i] = 200100;
  }

  int modifyCount = 0;

  if (numVal > K) {
    sort(A.begin(), A.end()); // sortする
    for (int n = 0; n < numVal - K; n++) {
      modifyCount += A[n];
    }
  }

  cout << modifyCount << endl;
}
Problem p03495 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N = 0;
  int K = 0;
  cin >> N >> K;

  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A.at(i);
  }

  vector<int> count(N, 0);
  for (int i = 0; i < N; ++i) {
    count.at(A.at(i) - 1)++;
  }

  for (int i = 0; i < N; ++i) {
    sort(count.begin(), count.end());
  }

  // 整数の種類数を数える
  int notzero = 0;
  for (int i = 0; i < N; ++i) {
    if (count.at(i) != 0)
      notzero++;
  }

  int result = 0;
  // ボールの数を書き換える回数を判定
  for (int i = 0; i < N; ++i) {
    // 書き換えの必要なし
    if (notzero <= K) {
      break;
    }
    if (count.at(i) > 0) {
      result += count.at(i);
      notzero--;
    }
  }
  cout << result;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N = 0;
  int K = 0;
  cin >> N >> K;

  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A.at(i);
  }

  vector<int> count(N, 0);
  for (int i = 0; i < N; ++i) {
    count.at(A.at(i) - 1)++;
  }

  sort(count.begin(), count.end());

  // 整数の種類数を数える
  int notzero = 0;
  for (int i = 0; i < N; ++i) {
    if (count.at(i) != 0)
      notzero++;
  }

  int result = 0;
  // ボールの数を書き換える回数を判定
  for (int i = 0; i < N; ++i) {
    // 書き換えの必要なし
    if (notzero <= K) {
      break;
    }
    if (count.at(i) > 0) {
      result += count.at(i);
      notzero--;
    }
  }
  cout << result;
  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>

#define SIZE 20000

using namespace std;

int main(void) {
  int K, N;
  int a;
  int dif_a = 0;
  int cnt[SIZE] = {0};
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> a;
    cnt[a] += 1;
  }
  sort(cnt, cnt + N + 1, greater<int>());
  int not_kakikae = 0;
  for (int i = 0; i < K; i++) {
    not_kakikae += cnt[i];
  }
  cout << N - not_kakikae;
  return EXIT_SUCCESS;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>

#define SIZE 200000

using namespace std;

int main(void) {
  int K, N;
  int a;
  int dif_a = 0;
  int cnt[SIZE] = {0};
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> a;
    cnt[a] += 1;
  }
  sort(cnt, cnt + N + 1, greater<int>());
  int not_kakikae = 0;
  for (int i = 0; i < K; i++) {
    not_kakikae += cnt[i];
  }
  cout << N - not_kakikae;
  return EXIT_SUCCESS;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll n, k, a;
  in2(n, k);
  vector<ll> c(n), d(300000, 0);
  rep(i, n) in(c[i]);
  a = 1;
  rep(i, n) {
    if (c[i] != c[i + 1])
      a++;
  }
  if (a <= k) {
    out(0);
    memi;
    return 0;
  }
  a = a - k;
  rep(i, n) d[c[i]]++;
  sort(all(d));
  n = k = 0;
  while (a > 0) {
    if (d[k] != 0) {
      n = n + d[k];
      a--;
    }
    k++;
  }
  out(n);
  memi;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main() {
  ll n, k, a;
  in2(n, k);
  vector<ll> c(n), d(300000, 0);
  rep(i, n) in(c[i]);
  a = 1;
  sort(all(c));
  rep(i, n - 1) {
    if (c[i] != c[i + 1])
      a++;
  }
  if (a <= k) {
    out(0);
    memi;
    return 0;
  }
  a = a - k;
  rep(i, n) d[c[i]]++;
  sort(all(d));
  n = k = 0;
  while (a > 0) {
    if (d[k] != 0) {
      n = n + d[k];
      a--;
    }
    k++;
  }
  out(n);
  memi;
}