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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
  while (a % b != 0) {
    int c = 0;
    c = a % b;
    a = b;
    b = c;
  }
  return b;
}

int main() {
  int N = 0, a[10009];
  long ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    while (a[i] % 2 == 0) {
      ans++;
      a[i] / 2;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
  while (a % b != 0) {
    int c = 0;
    c = a % b;
    a = b;
    b = c;
  }
  return b;
}

int main() {
  int N = 0, a[10009];
  long ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    while (a[i] % 2 == 0) {
      ans++;
      a[i] /= 2;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03325 (C++)

Buggy submission (status: Runtime Error):
/**
 *	  Name: Ajay
 *	  Institute: IIITH
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int, int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
#define fi first
#define se second
using namespace std;

void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void input() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
int f(int n) {
  int x = 0;
  while (n % 2 == 0) {
    n = n >> 1;
    x++;
  }
  return x;
}
int main() {
  fastio();
  input();
  int n, m, i, j, t;
  cin >> n;
  vi a;
  for (i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x % 2 == 0) {
      a.pb(x);
    }
  }

  LL mx = 0;
  for (i = 0; i < a.size(); i++) {
    mx += f(a[i]);
    ;
  }
  cout << mx;
  return 0;
}

Fixed submission:
/**
 *	  Name: Ajay
 *	  Institute: IIITH
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int, int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
#define fi first
#define se second
using namespace std;

void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void input() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
int f(int n) {
  int x = 0;
  while (n % 2 == 0) {
    n = n >> 1;
    x++;
  }
  return x;
}
int main() {

  int n, m, i, j, t;
  cin >> n;
  vi a;
  for (i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x % 2 == 0) {
      a.pb(x);
    }
  }

  LL mx = 0;
  for (i = 0; i < a.size(); i++) {
    mx += f(a[i]);
    ;
  }
  cout << mx;
  return 0;
}
Problem p03325 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#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 (1) {
    int tmp;
    for (int i = 0; i < n; i++) {
      tmp = 1e9;
      if (a[i] % 2 == 0) {
        tmp = i;
        a[i] /= 2;
        break;
      }
    }
    if (tmp == 1e9)
      break;
    for (int i = 0; i < n; i++) {
      if (i == tmp)
        continue;
      a[i] *= 3;
    }
    ans++;
  }

  cout << ans << endl;
}


Fixed submission:
#include <iostream>
#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 (1) {
    int tmp;
    for (int i = 0; i < n; i++) {
      tmp = 1e9;
      if (a[i] % 2 == 0) {
        tmp = i;
        a[i] /= 2;
        break;
      }
    }
    if (tmp == 1e9)
      break;
    ans++;
  }

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

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

int main() {
  int N;
  int a;
  int count = 0;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    while (a % 2 == 0) {
      count++;
    }
  }
  cout << count << endl;
}

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

int main() {
  int N;
  int a;
  int count = 0;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    while (a % 2 == 0) {
      a = a / 2;
      count++;
    }
  }
  cout << count << endl;
}
Problem p03325 (C++)

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

int main() {
  int a[10000];
  int n;

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a[i]);
  }

  int counter = 0;
  for (int i = 0; i < n; i++) {
    while ((a[i] & 1) == 0) {
      counter++;
      a[i] = a[i] >> 1;
    }
  }

  printf("%d\n", counter);
}

Fixed submission:
#include <stdio.h>

int main() {
  int a[10000];
  int n;

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  int counter = 0;
  for (int i = 0; i < n; i++) {
    while ((a[i] & 1) == 0) {
      counter++;
      a[i] = a[i] >> 1;
    }
  }

  printf("%d\n", counter);
}
Problem p03325 (C++)

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

int main() {
  int a, i = 0;
  cin >> a;
  int b[101];
  for (i = 0; i < a; i++)
    cin >> b[i];

  int cnt = 0;
  for (i = 0; i < a; i++) {
    while (b[i] % 2 == 0) {
      b[i] /= 2;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

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

int main() {
  int a, i = 0;
  cin >> a;
  int b[10001];
  for (i = 0; i < a; i++)
    cin >> b[i];

  int cnt = 0;
  for (i = 0; i < a; i++) {
    while (b[i] % 2 == 0) {
      b[i] /= 2;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p03325 (C++)

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

int main() {
  int n;
  cin >> n;
  int a;
  long long int c;
  for (int i = 0; i < n; i++) {
    cin >> a;
    while (a % 2 == 0) {
      a / 2;
      c++;
    }
  }
  cout << c << endl;
}

Fixed submission:
#include <algorithm> // sort
#include <bits/stdc++.h>
#include <map>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  int a;
  long long int c;
  for (int i = 0; i < n; i++) {
    cin >> a;
    while (a % 2 == 0) {
      a /= 2;
      c++;
    }
  }
  cout << c << endl;
}
Problem p03325 (C++)

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

int power(long i) {
  int counter = 0;
  while (i % 2 == 0) {
    counter++;
    i /= 2;
  }
  return counter;
}

int main() {
  int N;
  cin >> N;
  vector<long> data;
  int counter = 0;
  for (int i = 0; i < N; i++) {
    cin >> data[i];
    counter += power(data[i]);
  }
  cout << counter << endl;
}

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

int power(long i) {
  int counter = 0;
  while (i % 2 == 0) {
    counter++;
    i /= 2;
  }
  return counter;
}

int main() {
  int N;
  cin >> N;
  vector<long> data(N);
  int counter = 0;
  for (int i = 0; i < N; i++) {
    cin >> data[i];
    counter += power(data[i]);
  }
  cout << counter << endl;
}
Problem p03325 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;

void print(const std::vector<int> &v) {
  std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
  std::cout << std::endl;
}

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  ll cnt;
  REP(i, N) {
    cin >> a[i];
    while (a[i] % 2 == 0) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;

void print(const std::vector<int> &v) {
  std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
  std::cout << std::endl;
}

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  ll cnt;
  REP(i, N) {
    cin >> a[i];
    while (a[i] % 2 == 0) {
      cnt++;
      a[i] = a[i] / 2;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p03325 (C++)

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

int main() {

  int N;
  int *a;

  cin >> N;

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

  int count = 0;
  for (int i = 0; i < N; i++) {
    while (a[i] % 2 == 0) {
      a[i] = a[i] / 2;
      count++;
    }
  }

  cout << count << endl;
}

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

int main() {

  int N;
  int a[10000];

  cin >> N;

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

  int count = 0;
  for (int i = 0; i < N; i++) {
    while (a[i] % 2 == 0) {
      a[i] = a[i] / 2;
      count++;
    }
  }

  cout << count << endl;
}
Problem p03325 (C++)

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  long ans = 0;
  cin >> N;
  vector<long long> num(N);
  for (int i = 0; i < N; i++) {
    cin >> num.at(i);
    while (1) {
      if (num.at(i) % 2 == 0) {
        ans++;
        num.at(i) = num.at(i) / 2;
      } else {
        break;
      }
    }
  }
  cout << ans << endl;
}
Problem p03325 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
#include <stdlib.h>

static int cmpfunc(const void *a, const void *b) {
  return (*(long *)a - *(long *)b);
}

int main(int argc, char **argv) {
  int n, i = 0;
  long nr_cnt = 0;
  long odd_max = -1;
  long odd_index = -1;
  long *a;
  scanf("%d", &n);
  a = (long *)malloc(sizeof(long) * n);

  for (i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }

  qsort(a, n, sizeof(long), cmpfunc);

  while (1) {
    // find max
    odd_max = -1;
    odd_index = -1;
    for (i = n - 1; i >= 0; i--) {
      if ((a[i] % 2) == 0) {
        odd_max = a[i];
        odd_index = i;
        break;
      }
    }

    if (odd_max == -1) {
      break;
    }

    a[odd_index] /= 2;
    if (a[odd_index] == 0) {
      break;
    }

    for (i = 0; i < n; i++) {
      if (i != odd_index) {
        a[i] *= 3;
      }
    }
    nr_cnt++;
  }

  printf("%ld\n", nr_cnt);

  return 0;
}


Fixed submission:
#include <stdio.h>
#include <stdlib.h>

static int cmpfunc(const void *a, const void *b) {
  return (*(long *)a - *(long *)b);
}

int main(int argc, char **argv) {
  int n, i = 0;
  long nr_cnt = 0;
  long odd_max = -1;
  long odd_index = -1;
  long *a;
  scanf("%d", &n);
  a = (long *)malloc(sizeof(long) * n);

  for (i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }

  qsort(a, n, sizeof(long), cmpfunc);

  while (1) {
    // find max
    odd_max = -1;
    odd_index = -1;
    for (i = n - 1; i >= 0; i--) {
      if ((a[i] % 2) == 0) {
        odd_max = a[i];
        odd_index = i;
        break;
      }
    }

    if (odd_max == -1) {
      break;
    }

    a[odd_index] /= 2;
    if (a[odd_index] == 0) {
      break;
    }

    // for (i = 0; i < n; i++) {
    //       if (i != odd_index) {
    //               a[i] *= 3;
    //       }
    // }
    nr_cnt++;
  }

  printf("%ld\n", nr_cnt);

  return 0;
}
Problem p03325 (C++)

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

int main() {
  long n, sum = 0;
  cin >> n;
  vector<long> vec(n);
  for (int i = 0; i < n; i++) {
    long a;
    cin >> a;
    vec.at(i) = a;
  }
  int j = 0;
  int b;
  for (int i = 0; i < n; i++) {

    j = 0;
    b = vec.at(i);
    while (b % 2 == 0) {
      b = vec.at(i);
      b = b / 2;
      j++;
    }
    sum += j;
  }
  cout << sum << endl;
  return 0;
}

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

int main() {
  long n, sum = 0;
  cin >> n;
  vector<long> vec(n);
  for (int i = 0; i < n; i++) {
    long a;
    cin >> a;
    vec.at(i) = a;
  }
  int j = 0;
  int b;
  for (int i = 0; i < n; i++) {

    j = 0;
    b = vec.at(i);
    while (b % 2 == 0) {

      b = b / 2;
      j++;
    }
    sum += j;
  }
  cout << sum << endl;
  return 0;
}
Problem p03325 (C++)

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

int main() {
  int n;
  long long int a;
  long cnt = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a);
    while (a %= 2 == 0) {
      cnt++;
      a /= 2;
    }
  }
  printf("%ld\n", cnt);
}

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

int main() {
  int n;
  long long int a;
  long cnt = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a);
    while (a % 2 == 0) {
      cnt++;
      a /= 2;
    }
  }
  printf("%ld\n", cnt);
}
Problem p03325 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int a[105000], ans;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++) {
    for (long long j = 1; j <= 5000000; j++) {
      if (a[i] % 2 == 0) {
        ans++;
        a[i] /= 2;
      } else {
        continue;
      }
    }
  }
  cout << ans << endl;
  system("pause");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int a[105000], ans;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++) {
    {
      for (long long j = 1; j <= 29; j++) {
        if (a[i] % 2 == 0) {
          a[i] /= 2;
          ans++;
        }
      }
      if (a[i] % 2 != 0) {
        continue;
      }
    }
  }
  cout << ans << endl;
  system("pause");
  return 0;
}
Problem p03325 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> cnt(n);
  ll cnt_sum;
  for (ll i = 0; i < n; i++) {
    cin >> a.at(i);
    ll x = a.at(i);
    while (x % 2 != 1) {
      x %= 2;
      cnt.at(i)++;
    }
    cnt_sum += cnt.at(i);
  }
  cout << cnt_sum;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> cnt(n);
  ll cnt_sum;
  for (ll i = 0; i < n; i++) {
    cin >> a.at(i);
    ll x = a.at(i);
    while (x % 2 != 1) {
      x /= 2;
      cnt.at(i)++;
    }
    cnt_sum += cnt.at(i);
  }
  cout << cnt_sum;
}
Problem p03325 (Python)

Buggy submission (status: Time Limit Exceeded):
input()

a = list(map(int, input().split()))

count = 0
flag = True
while flag:
    flag = False
    for i, aa in enumerate(a):
        if aa % 2 == 0:
            a[i] = int(a[i] / 2)
            flag = True
            break
    if flag:
        count += 1
print(count)


Fixed submission:
input()

a = list(map(int, input().split()))

count = 0
for i, aa in enumerate(a):
    while aa % 2 == 0:
        aa = int(aa / 2)
        count += 1
print(count)
Problem p03325 (Python)

Buggy submission (status: Runtime Error):
def solve(N, As):
    def f(n):
        c = 0
        while n % 2 == 0:
            c += 1
            n //= 2
        return c

    return sum([f(a) for a in As])


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N))


Fixed submission:
def solve(N, As):
    def f(n):
        c = 0
        while n % 2 == 0:
            c += 1
            n //= 2
        return c

    return sum([f(a) for a in As])


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))
Problem p03325 (Python)

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

c = 0

while True:
    gusu = False

    for i, aa in enumerate(a):
        if gusu is False and a[i] % 2 == 0:
            a[i] /= 2
            gusu = True
            continue

    if gusu is False:
        break

    c += 1

print(c)


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

c = 0

for i, aa in enumerate(a):
    while a[i] % 2 == 0:
        a[i] /= 2
        c += 1

print(c)
Problem p03325 (Python)

Buggy submission (status: Time Limit Exceeded):
N, *a = map(int, open(0).read().split())
ans = 0
flag = True
while flag:
    cnt = 0
    for i in range(N):
        if a[i] % 2 == 0 and cnt == 0:
            a[i] //= 2
            cnt += 1
        else:
            a[i] *= 3
    else:
        if cnt == 0:
            flag = False
        else:
            ans += 1

print(ans)


Fixed submission:
N, *a = map(int, open(0).read().split())
ans = 0
for i in range(N):
    ans += len(bin(a[i])) - bin(a[i]).rfind("1") - 1
print(ans)
Problem p03325 (Python)

Buggy submission (status: Time Limit Exceeded):
N, *a = map(int, open(0).read().split())
ans = 0
flag = True
while flag:
    cnt = 0
    for i in range(N):
        if a[i] % 2 != 0:
            continue
        elif a[i] % 2 == 0 and cnt == 0:
            a[i] //= 2
            cnt += 1
            break

    if cnt == 0:
        flag = False
    else:
        ans += 1

print(ans)


Fixed submission:
N, *a = map(int, open(0).read().split())
ans = 0
for i in range(N):
    while a[i] % 2 == 0:
        a[i] //= 2
        ans += 1

print(ans)
Problem p03325 (C++)

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

int main() {
  int n, ans = 0;
  cin >> n;
  int a[10000];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] % 2 == 0) {
      ans++;
      i--;
    }
  }
  cout << ans;
  return 0;
}


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

int main() {
  int n, ans = 0;
  cin >> n;
  int a[10000];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] % 2 == 0) {
      ans++;
      a[i] /= 2;
      i--;
    }
  }
  cout << ans;
  return 0;
}
Problem p03325 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   //setprecision
#include <iostream>
#include <map> // map
#include <math.h>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  long long int a, b, c, d = 0;
  cin >> a;
  rep(i, a) {
    cin >> b;
    while (b % 2 == 0) {
      if (b == 0)
        break;
      d++;
      b / 2;
    }
  }
  cout << d;
}

Fixed submission:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   //setprecision
#include <iostream>
#include <map> // map
#include <math.h>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  long long int a, b, c, d = 0;
  cin >> a;
  rep(i, a) {
    cin >> b;
    while (b % 2 == 0) {
      if (b == 0)
        break;
      d++;
      b /= 2;
    }
  }
  cout << d;
}
Problem p03325 (C++)

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

int main() {
  int N, count;
  count = 0;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    while (vec.at(i) % 2 == 0) {
      count += 1;
      vec.at(i) /= 2;
    }
  }
  cout << count << endl;
}

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

int main() {
  int N, count;
  count = 0;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    while (vec.at(i) % 2 == 0) {
      count += 1;
      vec.at(i) /= 2;
    }
  }
  cout << count << endl;
}
Problem p03325 (C++)

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

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

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], b = 0, g;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    g = 0;
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      g++;
    }
    b += g;
  }
  cout << b;
}
Problem p03325 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const double PI = 3.14159265358979;
const ll INF = pow(10, 18);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n, cnt = 0;
  cin >> n;
  vl a(n);
  rep(i, n) {
    cin >> a[i];
    while (a[i] % 2 == 0) {
      a[i] / 2;
      cnt++;
    }
  }
  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const double PI = 3.14159265358979;
const ll INF = pow(10, 18);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n, cnt = 0;
  cin >> n;
  vl a(n);
  rep(i, n) {
    cin >> a[i];
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p03325 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <ctype.h>
#include <iostream>
#include <math.h>
#include <stack>
#include <string.h>
#include <string>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = (1 << 30);

int main() {
  int n, a[3100];
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      cnt++;
    }
  }

  cout << cnt << endl;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <ctype.h>
#include <iostream>
#include <math.h>
#include <stack>
#include <string.h>
#include <string>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = (1 << 30);

int main() {
  int n, a[20000];
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      cnt++;
    }
  }

  cout << cnt << endl;
}
Problem p03325 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int a;
  int c = 0;
  cin >> a;
  vector<int> b(a);
  for (int i = 0; i < a; i++)
    cin >> b.at(i);
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < 1000000000; i++) {
      if (b.at(i) % 2 == 0) {
        b.at(i) /= 2;
        c++;
      } else
        break;
    }
  }
  cout << c;
}


Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int a;
  int c = 0;
  cin >> a;
  vector<int> b(a);
  for (int i = 0; i < a; i++)
    cin >> b.at(i);
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < 1000000000; j++) {
      if (b.at(i) % 2 == 0) {
        b.at(i) /= 2;
        c++;
      } else
        break;
    }
  }
  cout << c;
}
Problem p03325 (C++)

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

int main(void) {

  int n;
  cin >> n;
  std::vector<unsigned long long> data(n);
  for (int i = 0; i < n; i++)
    cin >> data[i];

  unsigned long long result = 0;
  while (true) {
    bool even_finding = false;
    int index = -1;
    for (int i = 0; i < n; i++) {
      if (data[i] % 2 == 0) {
        even_finding = true;
        index = i;
        break;
      }
    }

    if (!even_finding)
      break;
    result++;

    for (int i = 0; i < n; i++) {
      if (i == index)
        data[i] /= 2;
    }
  }

  cout << result << endl;

  return 0;
}


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

int main(void) {

  int n;
  cin >> n;
  std::vector<unsigned long long> data(n);
  for (int i = 0; i < n; i++)
    cin >> data[i];

  unsigned long long result = 0;
  for (int i = 0; i < n; i++) {
    while (data[i] % 2 == 0) {
      data[i] /= 2;
      result++;
    }
  }

  cout << result << endl;

  return 0;
}
Problem p03325 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int x = 1, a, b[10001], c = 0;
  cin >> a;
  for (int i = 1; i <= a; i++) {
    cin >> b[i];
    x *= b[i];
  }
  while (x % 2 == 0) {
    x /= 2;
    c++;
  }
  cout << c;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int x = 1, a, b[10001], c = 0;
  cin >> a;
  for (int i = 1; i <= a; i++) {
    cin >> b[i];
    while (b[i] % 2 == 0) {
      b[i] /= 2;
      c++;
    }
  }
  cout << c;
}
Problem p03325 (C++)

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, cnt = 0;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    while (a[i] % 2 == 0) {
      cnt++;
      a[i] /= 2;
    }
  }
  cout << cnt;
}
Problem p03325 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  ll a[n];
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    while (a[i] % 2 == 0 && a[i] != 0) {
      a[i] / 2;
      ans++;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  ll a[n];
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    while (a[i] % 2 == 0 && a[i] != 0) {
      a[i] /= 2;
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03325 (C++)

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

int main() {
  int n;
  int even = 0;
  int cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  while (true) {
    for (int i = 0; i < n; i++) {
      if (a[i] % 2 != 0 || even != 0) {
        a[i] *= 3;
      } else {
        a[i] /= 2;
        even++;
      }
    }
    if (even != 0) {
      cnt++;
      even = 0;
      continue;
    } else if (even == 0) {
      cout << cnt << endl;
      break;
    }
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int a[10000];

int main() {
  int n;
  int even = 0;
  int cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  while (true) {
    for (int i = 0; i < n; i++) {
      if (a[i] % 2 != 0 || even != 0) {
        // a[i] *= 3;
      } else {
        a[i] /= 2;
        even++;
      }
    }
    if (even != 0) {
      cnt++;
      even = 0;
      continue;
    } else if (even == 0) {
      cout << cnt << endl;
      break;
    }
  }

  return 0;
}
Problem p03325 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    cin >> a[i];
    int tmp = a[i];
    while (tmp > 0) {
      if (tmp % 2 == 0) {
        sum++;
        tmp / 2;
      }
    }
    ans += sum;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    cin >> a[i];
    int tmp = a[i];
    while (tmp > 0) {
      if (tmp % 2 == 0) {
        sum++;
        tmp /= 2;
      } else
        break;
    }
    ans += sum;
  }
  cout << ans << endl;
  return 0;
}
Problem p03325 (C++)

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

using namespace std;
using LL = long long int;
const LL mod = 1000000007;

int N;
const int MAX_N = 1005;

int A[MAX_N];

int main() {

  cin >> N;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    while (A[i] % 2 == 0) {
      ans++;
      A[i] /= 2;
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;
using LL = long long int;
const LL mod = 1000000007;

int N;
const int MAX_N = 10005;

int A[MAX_N];

int main() {

  cin >> N;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    while (A[i] % 2 == 0) {
      ans++;
      A[i] /= 2;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03325 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(N) for (int i = 0; i < N; i++)

int main() {
  int N;
  cin >> N;
  vector<long> a(N);
  int max_divide_operate = 0;
  bool divided_flag;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  while (true) {
    divided_flag = false;
    for (int i = 0; i < N; i++) {
      if (a[i] % 2 == 0 && divided_flag == false) {
        a[i] = a[i] / 2;
        divided_flag = true;
        max_divide_operate++;
      }
    }
    if (divided_flag == false) {
      break;
    }
  }
  cout << max_divide_operate << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<long> a(N);
  int max_divide_operate = 0;
  bool divided_flag;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    while (a[i] % 2 == 0) {
      a[i] = a[i] / 2;
      max_divide_operate++;
    }
  }
  cout << max_divide_operate << endl;
}
Problem p03325 (C++)

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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int a;
    while (true) {
      if (a % 2 == 1)
        break;
      else {
        a = a / 2;
        sum += 1;
      }
    }
  }
  cout << sum;
}


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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    while (true) {
      if (a % 2 == 1)
        break;
      else {
        a = a / 2;
        sum += 1;
      }
    }
  }
  cout << sum;
}
Problem p03325 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int N, count = 0;
  bool f = true;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  while (f) {
    for (int j = 0; j < N; j++) {
      f = false;
      if (a[j] % 2 == 0) {
        a[j] == a[j] / 2;
        count++;
        f = true;
        break;
      }
    }
  }
  cout << count;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int N, count = 0;
  bool f = true;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int j = 0; j < N; j++) {
    if (a[j] % 2 == 0) {
      a[j] = a[j] / 2;
      count++;
      j = -1;
    }
  }
  cout << count;
}
Problem p03325 (C++)

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

int main() {
  using namespace std;
  int a = 0, b = 0, c = 0, count = 0, ans = 0;
  bool okada = true;
  std::cin >> a;
  long long int x[10000], y[100], z[100];
  for (int i = 1; i <= a; i++) {
    std::cin >> x[i];
  }

  for (int j = 1; j <= 10000000; j++) {

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

      if (x[i] % 2 == 0) {
        x[i] = x[i] / 2;
        ans++;
      }
    }
  }
  std::cout << ans << std::endl;
}


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

int main() {
  using namespace std;
  int a = 0, b = 0, c = 0, count = 0, ans = 0;
  bool okada = true;
  std::cin >> a;
  long long int x[10000], y[100], z[100];
  for (int i = 1; i <= a; i++) {
    std::cin >> x[i];
  }

  for (int j = 1; j <= 1000; j++) {

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

      if (x[i] % 2 == 0) {
        x[i] = x[i] / 2;
        ans++;
      }
    }
  }
  std::cout << ans << std::endl;
}
Problem p03325 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>

typedef long long ll;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int N;
  cin >> N;
  vl a(N);
  rep(i, 0, N) { cin >> a[i]; }
  int count = 0;
  int loop = 0;
  while (true) {
    count = 0;
    rep(i, 0, a.size()) {
      if (a[i] % 2 == 0 && count == 0) {
        a[i] = a[i] / 2;
        ++count;
      }
    }
    if (count == 0) {
      break;
    }
    ++loop;
  }
  cout << loop << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>

typedef long long ll;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int N;
  cin >> N;
  vl a(N);
  rep(i, 0, N) { cin >> a[i]; }
  int count = 0;
  int loop = 0;
  while (true) {
    count = 0;
    rep(i, 0, a.size()) {
      if (a[i] % 2 != 0) {
        a.erase(a.begin() + i);
      }
      if (a[i] % 2 == 0 && count == 0) {
        a[i] = a[i] / 2;
        ++count;
      }
    }
    if (count == 0) {
      break;
    }
    ++loop;
  }
  cout << loop << endl;
  return 0;
}
Problem p03326 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a, b;
  long long k[1005][5], ans = 0;
  cin >> a >> b;
  for (int i = 0; i < a; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> k[i][j];
    }
  }
  for (int i = 0; i < 8; ++i) {
    long long sum = 0, v[100005] = {};
    for (int j = 0; j < a; ++j) {
      for (int kk = 0; kk < 3; ++kk) {
        if (i / (1 << kk) % 2 == 0)
          v[j] += k[j][kk];
        else
          v[j] -= k[j][kk];
      }
    }
    sort(v, v + a);
    for (int j = a - 1; j >= a - b; ++j) {
      sum += v[j];
    }

    ans = max(ans, sum);
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a, b;
  long long k[1005][5], ans = 0;
  cin >> a >> b;
  for (int i = 0; i < a; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> k[i][j];
    }
  }
  for (int i = 0; i < 8; ++i) {
    long long sum = 0, v[100005] = {};
    for (int j = 0; j < a; ++j) {
      for (int kk = 0; kk < 3; ++kk) {
        if (i / (1 << kk) % 2 == 0)
          v[j] += k[j][kk];
        else
          v[j] -= k[j][kk];
      }
    }
    sort(v, v + a);
    for (int j = a - 1; j >= a - b; --j) {
      sum += v[j];
    }

    ans = max(ans, sum);
  }
  cout << ans << endl;
}
Problem p03326 (C++)

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

using namespace std;

typedef long long ll;
ll mod = 1000000007, oo = 1000000009;

void Emsawy() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

#define clr(v, d) memset(v, d, sizeof(v))
#define sz(v) ((int)((v).size()))
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define V vector
#define MP make_pair
#define bug(n) cout << #n << " = " << n << endl;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

V<V<int>> adj;
const ll N = 1000 + 5;
int n, m, k, w;
ll a[N][3];

ll go(int mask) {
  V<ll> ans;
  for (int i = 0; i < n; i++) {
    ans.push_back(0);
    for (int j = 0; j < 3; j++) {
      if ((mask & (1 << j)))
        ans.back() += a[i][j] * -1;
      else
        ans.back() += a[i][j];
    }
  }
  sort(allr(ans));
  ll ret = 0;
  for (int i = 0; i < m; i++) {
    ret += ans[i];
  }
  return ret;
}

int main() {

  Emsawy();
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++)
      cin >> a[i][0] >> a[i][1] >> a[i][2];
    ll ans = 0;
    for (int i = 0; i < 8; i++) {
      ans = max(ans, go(i));
    }
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
ll mod = 1000000007, oo = 1000000009;

void Emsawy() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

#define clr(v, d) memset(v, d, sizeof(v))
#define sz(v) ((int)((v).size()))
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define V vector
#define MP make_pair
#define bug(n) cout << #n << " = " << n << endl;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

V<V<int>> adj;
const ll N = 1000 + 5;
int n, m, k, w;
ll a[N][3];

ll go(int mask) {
  V<ll> ans;
  for (int i = 0; i < n; i++) {
    ans.push_back(0);
    for (int j = 0; j < 3; j++) {
      if ((mask & (1 << j)))
        ans.back() += a[i][j] * -1;
      else
        ans.back() += a[i][j];
    }
  }
  sort(allr(ans));
  ll ret = 0;
  for (int i = 0; i < m; i++) {
    ret += ans[i];
  }
  return ret;
}

int main() {

  // Emsawy();
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++)
      cin >> a[i][0] >> a[i][1] >> a[i][2];
    ll ans = 0;
    for (int i = 0; i < 8; i++) {
      ans = max(ans, go(i));
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p03326 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> a[3];
  rep(i, 3) a[i].resize(n);
  rep(i, n) rep(j, 3) cin >> a[j][i];
  ll ans = 0;
  for (int x : {-1, 1}) {
    for (int y : {-1, 1}) {
      for (int z : {-1, 1}) {
        set<ll, greater<ll>> st;
        rep(i, n) { st.insert(a[0][i] * x + a[1][i] * y + a[2][i] * z); }
        auto it = st.begin();
        ll temp = 0;
        rep(i, m) {
          temp += *it;
          it++;
        }
        ans = max(ans, temp);
      }
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> a[3];
  rep(i, 3) a[i].resize(n);
  rep(i, n) rep(j, 3) cin >> a[j][i];
  ll ans = 0;
  for (int x : {-1, 1}) {
    for (int y : {-1, 1}) {
      for (int z : {-1, 1}) {
        multiset<ll, greater<ll>> st;
        rep(i, n) { st.insert(a[0][i] * x + a[1][i] * y + a[2][i] * z); }
        auto it = st.begin();
        ll temp = 0;
        rep(i, m) {
          temp += *it;
          it++;
        }
        ans = max(ans, temp);
      }
    }
  }
  cout << ans << endl;
}
Problem p03326 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<long long int>> data(N, vector<long long int>(3));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data.at(i).at(j);
    }
  }
  long long ans = -1;
  // 求めるのは絶対値の合計ではなく合計の絶対値
  // どの要素を正，負どちらの方向に最大化させるかで8通り
  for (int bit = 0; bit < (1 << 3); bit++) {
    vector<long long int> svec;
    for (int j = 0; j < N; j++) {
      long long int S = 0;
      for (int k = 0; k < 3; k++) {
        if (1 & (bit >> k)) { // bitにk番目のフラグが立っているか
          svec.at(j) += data.at(j).at(k);
        } else {
          svec.at(j) -= data.at(j).at(k);
        }
      }
    }
    sort(svec.begin(), svec.end(), greater<long long int>());
    long long int sum = 0;
    for (int j = 0; j < M; j++) {
      sum += svec.at(j);
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<long long int>> data(N, vector<long long int>(3));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data.at(i).at(j);
    }
  }
  long long ans = -1;
  // 求めるのは絶対値の合計ではなく合計の絶対値
  // どの要素を正，負どちらの方向に最大化させるかで8通り
  for (int bit = 0; bit < (1 << 3); bit++) {
    vector<long long int> svec(N);
    for (int j = 0; j < N; j++) {
      long long int S = 0;
      for (int k = 0; k < 3; k++) {
        if (1 & (bit >> k)) { // bitにk番目のフラグが立っているか
          svec.at(j) += data.at(j).at(k);
        } else {
          svec.at(j) -= data.at(j).at(k);
        }
      }
    }
    sort(svec.begin(), svec.end(), greater<long long int>());
    long long int sum = 0;
    for (int j = 0; j < M; j++) {
      sum += svec.at(j);
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}