alexjercan/bugnet huggingface dataset:
Problem p00457 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;

int check(vector<int> character, int i, int color) {
  if (character[i] == color)
    return character.size();

  character[i] = color;
  bool vanished = true;
  while (vanished) {
    int count = 0;
    int top, bottom;
    for (top = i; top >= 0 && character[top] == color; top--) {
      count++;
    }
    for (bottom = i + 1;
         bottom < character.size() && character[bottom] == color; bottom++) {
      count++;
    }
    top++;
    bottom--;

    if (count < 4) {
      vanished = false;
    } else {
      character.erase(character.begin() + top, character.begin() + bottom + 1);
      i = min(top, (int)character.size() - 1);
      color = character[i];
    }
  }

  return character.size();
}

int main() {
  int N, M;
  while (cin >> N, N) {
    vector<int> character(N);
    for (int i = 0; i < N; i++)
      cin >> character[i];

    M = 100000;
    for (int i = 0; i < N; i++) {
      for (int color = 1; color <= 3; color++) {
        M = min(M, check(character, i, color));
      }
    }
    cout << M << endl;
  }
}

Error: TLE

Fixed submission:

#include <climits>
#include <iostream>
using namespace std;

int d[1000];

int check(int N) {
  bool f = 1;
  int cnt, i, j;
  while (f) {
    f = 0;
    cnt = 1;
    for (i = 1; i < N; i++) {
      if (d[i] == d[i - 1]) {
        cnt++;
      } else if (cnt < 4) {
        cnt = 1;
      } else {
        f = 1;
        N -= cnt;
        for (j = i - cnt; j < N; j++)
          d[j] = d[j + cnt];
        break;
      }
    }
  }
  return N;
}

int main() {
  int N, i, j, k, c[1000];
  int min, rest;
  while (cin >> N, N) {
    for (i = 0; i < N; i++)
      scanf("%d", c + i);
    min = INT_MAX;
    for (i = 0; i < N; i++) {
      for (j = 1; j <= 3; j++) {
        if (c[i] == j)
          continue;
        for (k = 0; k < N; k++)
          d[k] = c[k];
        d[i] = j;
        rest = check(N);
        if (min > rest)
          min = rest;
      }
    }
    printf("%d\\n", min);
  }
}
Problem p00457 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

int n;
int ans;
int a[10010];

void solve() {
  ans = n;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= 3; j++) {
      int s = i, e = i, cnt = 1, tmp = n, color = j;
      if (a[i] == j)
        continue;
      while (true) {
        while (true) {
          if (s - 1 >= 0 && a[s - 1] == color) {
            cnt++;
            s--;
          } else
            break;
        }
        while (true) {
          if (e + 1 < n && a[e + 1] == color) {
            cnt++;
            e++;
          } else
            break;
        }
        if (cnt >= 4) {
          tmp -= cnt;
          if (tmp <= 3)
            break;
          if (s - 1 >= 0)
            color = a[s - 1];
          else if (e + 1 < n)
            color = a[e + 1];
          cnt = 0;
        } else
          break;
      }
      if (ans > tmp)
        ans = tmp;
    }
  }
  printf("%d\\n", ans);
}

int main() {
  while (scanf("%d", &n), n)
    solve();
}

Error: TLE

Fixed submission:

#include <cstdio>

int n;
int ans;
int a[1010];

void solve() {
  ans = n;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= 3; j++) {
      int s = i, e = i, cnt = 1, tmp = n, color = j;
      if (a[i] == j)
        continue;
      while (true) {
        while (true) {
          if (s - 1 >= 0 && a[s - 1] == color) {
            cnt++;
            s--;
          } else
            break;
        }
        while (true) {
          if (e + 1 >= 0 && a[e + 1] == color) {
            cnt++;
            e++;
          } else
            break;
        }
        if (cnt >= 4) {
          tmp -= cnt;
          if (tmp <= 3)
            break;
          if (s - 1 >= 0)
            color = a[s - 1];
          else if (e + 1 < n)
            color = a[s - 1];
          cnt = 0;
        } else
          break;
      }
      if (ans > tmp)
        ans = tmp;
    }
  }
  printf("%d\\n", ans);
}

int main() {
  while (scanf("%d", &n), n)
    solve();
}
Problem p00457 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, p;
vector<int> a, b;
int solve(vector<int> x, int Y, int C) {
  int L = Y, R = Y;
  while (true) {
    if (L == R) {
      int a1 = 0;
      for (int i = L - 1; i >= 0; i--) {
        if (x[i] != C) {
          a1 = i + 1;
          break;
        }
      }
      int a2 = x.size() - 1;
      for (int i = R + 1; i < x.size(); i++) {
        if (x[i] != C) {
          a2 = i - 1;
          break;
        }
      }
      if (a2 - a1 <= 2) {
        return x.size();
      }
      L = a1;
      R = a2;
    } else {
      if (L == 0 || R == x.size() - 1 || x[L - 1] != x[R + 1]) {
        return x.size() - (R - L + 1);
      }
      int a1 = 0;
      C = x[L - 1];
      for (int i = L - 1; i >= 0; i--) {
        if (x[i] != C) {
          a1 = i + 1;
          break;
        }
      }
      int a2 = x.size() - 1;
      for (int i = R + 1; i < x.size(); i++) {
        if (x[i] != C) {
          a2 = i - 1;
          break;
        }
      }
      if ((a2 - a1) - (R - L) <= 3) {
        return x.size() - (R - L + 1);
      }
      L = a1;
      R = a2;
    }
  }
}
int main() {
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    a.clear();
    b.clear();
    for (int i = 0; i < n; i++) {
      cin >> p;
      a.push_back(p);
    }
    int maxn = n;
    b = a;
    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= 3; j++) {
        a[i] = j;
        maxn = min(maxn, solve(a, i, j));
        a[i] = b[i];
      }
    }
    cout << maxn << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, p;
vector<int> a, b;
int solve(vector<int> x) {
  int cnt = 0;
  while (true) {
    vector<int> y;
    int chain = 1;
    for (int i = 1; i < x.size(); i++) {
      if (x[i] == x[i - 1])
        chain++;
      else {
        if (chain <= 3) {
          for (int j = i - 1; j >= i - chain; j--) {
            y.push_back(x[j]);
          }
        }
        chain = 1;
      }
    }
    if (chain >= 1 && chain <= 3) {
      for (int j = x.size() - 1; j >= x.size() - chain; j--) {
        y.push_back(x[j]);
      }
    }
    if (x.size() == y.size()) {
      return y.size();
    }
    x = y;
    cnt++;
  }
}
int main() {
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> p;
      a.push_back(p);
    }
    int maxn = n;
    b = a;
    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= 3; j++) {
        a[i] = j;
        maxn = min(maxn, solve(a));
        a[i] = b[i];
      }
    }
    cout << maxn << endl;
  }
  return 0;
}
Problem p00457 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define MAX 10000
int arr[MAX + 2], N;

int solve(int p) {
  int lp = p, rp = p + 1;

  while (true) {
    if (lp <= 0 || rp >= N + 1)
      break;
    int color = arr[lp], l, r;
    for (l = lp; arr[l] == color; l--)
      ;
    for (r = rp; arr[r] == color; r++)
      ;
    if ((r - rp) + (lp - l) < 4)
      break;
    lp = l, rp = r;
  }
  return N - rp + lp + 1;
}

int main() {
  while (cin >> N, N) {
    memset(arr, 0, sizeof(arr));
    for (int i = 1; i <= N; i++) {
      cin >> arr[i];
    }
    int ans = MAX;
    for (int i = 1; i <= N; i++) {
      int tmp = arr[i];
      for (int j = 0; j < 3; j++) {
        if (arr[i] == j + 1)
          continue;
        arr[i] = j + 1;
        ans = min(ans, solve(i));
      }
      arr[i] = tmp;
    }
    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define MAX 10001
int arr[MAX], N;

int solve(int p) {
  int lp = p, rp = p + 1;

  while (true) {
    if (lp <= 0 || rp >= N + 1)
      break;
    int color = arr[lp], l, r;
    for (l = lp; arr[l] == color; l--)
      ;
    for (r = rp; arr[r] == color; r++)
      ;
    if (l <= 0 || r >= N + 1)
      return MAX;
    if ((r - rp) + (lp - l) < 4)
      break;
    lp = l, rp = r;
  }
  return N - rp + lp + 1;
}

int main() {
  while (cin >> N, N) {
    for (int i = 1; i <= N; i++) {
      cin >> arr[i];
      arr[i]--;
    }

    int ans = MAX;
    for (int i = 1; i <= N; i++) {
      int tmp = arr[i];
      for (int j = 0; j < 3; j++) {
        if (j == arr[i])
          continue;
        arr[i] = j;
        ans = min(ans, solve(i));
      }
      arr[i] = tmp;
    }
    cout << ans << endl;
  }

  return 0;
}
Problem p00457 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int inf = 99999;

int check(vector<int> vec, int n) {
  int c = 0, t = n;

  while (t - 1 >= 0 && vec[t - 1] == vec[t]) {
    t--;
  }

  for (int i = 1; i <= 3 && t + i < vec.size(); i++) {
    if (vec[t] != vec[t + i]) {
      break;
    }
    c++;
  }
  if (c == 3) {
    return t;
  }

  return -1;
}

int func(vector<int> vec, int n) {
  vector<int> v = vec;
  int t = n;

  while (v.size()) {
    t = check(v, t);
    if (t == -1) {
      break;
    }

    while (t + 1 < v.size() && v[t + 1] == v[t]) {
      v.erase(v.begin() + (t + 1));
    }
    v.erase(v.begin() + t);
  }

  return v.size();
}

int main() {
  int n, s, t;

  while (cin >> n && n) {
    vector<int> vec;
    while (n--) {
      cin >> t;
      vec.push_back(t);
    }
    s = inf;

    for (int i = 0; i < vec.size(); i++) {
      for (int j = 1; j <= 3; j++) {
        t = vec[i];
        vec[i] = j;
        s = min(s, func(vec, i));
        vec[i] = t;
      }
    }

    cout << s << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int inf = 99999;

int check(vector<int> vec) {
  int r = -1;

  for (int i = 0, c = 1; i < vec.size() - 1; i++, c = 1) {
    while (i + c < vec.size() && vec[i] == vec[i + c]) {
      c++;
    }
    if (c > 3) {
      r = i;
      break;
    }
  }

  return r;
}

int func(vector<int> vec) {
  vector<int> v = vec;

  while (1) {
    int t = check(v);
    if (t == -1) {
      break;
    }

    while (t + 1 < v.size() && v[t + 1] == v[t]) {
      v.erase(v.begin() + (t + 1));
    }
    v.erase(v.begin() + t);
  }

  return v.size();
}

int main() {
  int n, s, t;

  while (cin >> n && n) {
    vector<int> vec;
    while (n--) {
      cin >> t;
      vec.push_back(t);
    }
    s = inf;

    for (int i = 0; i < vec.size(); i++) {
      for (int j = 1; j <= 3; j++) {
        t = vec[i];
        vec[i] = j;
        s = min(s, func(vec));
        vec[i] = t;
      }
    }

    cout << s << endl;
  }

  return 0;
}
Problem p00457 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <stdio.h>

using namespace std;

int disp(int block[], int c, int n) {
  int p, q;
  int i, j;

  for (i = 1; block[c + i] == block[c]; i++)
    ;
  for (j = 1; block[c - j] == block[c]; j++)
    ;

  if (i + j - 1 >= 4) {
    p = c + i;
    q = c - j;
  } else {
    return (n);
  }

  while (block[p] != -1 && block[q] != -1) {
    if (block[p] != block[q]) {
      break;
    }
    for (i = 1; block[p + i] == block[p]; i++)
      ;
    for (j = 1; block[q - j] == block[q]; j++)
      ;

    if (i + j >= 4) {
      p += i;
      q -= j;
    } else {
      break;
    }
  }

  int ret = 0;
  for (int i = p; block[i] != -1; i++) {
    ret++;
  }
  for (int i = q; block[i] != -1; i--) {
    ret++;
  }

  return (ret);
}

int main(void) {
  int block[10002];
  int n;
  int ans;

  while (1) {
    scanf("%d", &n);

    if (n == 0) {
      break;
    }

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

    ans = 10000;
    for (int i = 1; i <= n; i++) {
      block[i] = (block[i] + 1) % 3;
      ans = min(disp(block, i, n), ans);
      block[i] = (block[i] + 1) % 3;
      ans = min(disp(block, i, n), ans);
      block[i] = (block[i] + 1) % 3;
    }

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

  return (0);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>

using namespace std;

#define RED (0)
#define BLUE (1)
#define YELLOW (2)

int ans;

void erase(int table[], int n) {
  list<int> l;
  list<int>::iterator it;
  list<int>::iterator it2;

  l.assign(table, table + n);

  it = l.begin();
  while (it != l.end()) {
    int count = 0;
    it2 = it;
    while (it2 != l.end() && *it2 == *it) {
      it2++;
      count++;
    }

    if (count >= 4) {
      l.erase(it, it2);
      it = l.begin();
    } else {
      it = it2;
    }
  }

  ans = min(ans, (int)(l.size()));
}

int main(void) {
  int table[10000];
  int n;

  while (1) {
    ans = 1000000;
    cin >> n;

    if (n == 0) {
      break;
    }

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

    for (int i = 0; i < n; i++) {
      int tmp = table[i];

      for (int j = 0; j < 3; j++) {
        table[i] = j;
        erase(table, n);
      }
      table[i] = tmp;
    }

    cout << ans << endl;
  }

  return (0);
}
Problem p00457 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int del(string s) {
  bool hoge = true;
  string temp;
  while (hoge) {
    hoge = false;
    int dt[s.size()];
    rep(i, s.size()) dt[i] = 0;
    rep(i, s.size()) {
      if (i == 0)
        dt[i] = 1;
      else {
        if (s[i - 1] == s[i])
          dt[i] = dt[i - 1] + 1;
        else
          dt[i] = 1;
      }
    }
    temp = "";
    for (int i = s.size() - 1; i >= 0; i--) {
      if (dt[i] > 3) {
        hoge = true;
        i -= dt[i];
        i++;
      } else
        temp += s[i];
    }
    s = temp;
  }
  return temp.size();
}

int func(string s) {
  int mians = s.size();
  rep(p, s.size()) {
    string alt = s;
    loop(c, 1, 4) {
      alt[p] = (char)(c + '0');
      int left, right;
      left = right = p;
      while (alt[right] == alt[p])
        right++;
      while (alt[left] == alt[p])
        left--;
      if ((right - 1 - left) < 4)
        continue;
      mians = min(mians, del(alt));
    }
  }
  return mians;
}

int main() {
  int n;
  while (cin >> n, n) {
    string s = "";
    char ch;
    rep(i, n) {
      cin >> ch;
      s += ch;
    }
    cout << func(s) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define INF 1e6
using namespace std;

int del(string s) {
  bool hoge = true;
  string temp;
  while (hoge) {
    hoge = false;
    int dt[s.size()];
    rep(i, s.size()) dt[i] = 0;
    rep(i, s.size()) {
      if (i == 0)
        dt[i] = 1;
      else {
        if (s[i - 1] == s[i])
          dt[i] = dt[i - 1] + 1;
        else
          dt[i] = 1;
      }
    }
    temp = "";
    for (int i = s.size() - 1; i >= 0; i--) {
      if (dt[i] > 3) {
        hoge = true;
        i -= dt[i];
        i++;
      } else
        temp += s[i];
    }
    s = temp;
  }
  return temp.size();
}

int func(string s) {
  int mians = INF;
  rep(p, s.size()) {
    string alt = s;
    loop(c, 1, 4) {
      alt[p] = (char)(c + '0');
      mians = min(mians, del(alt));
    }
  }
  return mians;
}

int main() {
  int n;
  while (cin >> n, n) {
    string s = "";
    char ch;
    rep(i, n) {
      cin >> ch;
      s += ch;
    }
    cout << func(s) << endl;
  }
  return 0;
}
Problem p00457 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

int n;
int a[10000];
int b[10001];
int ans = 1e9;

int c(int x, int y) { // change b[x] to y return remaining
  b[x] = y;
  int e = n;
  bool f = true;
  while (f) {
    f = false;
    int d = 1;
    int p = b[0];
    for (int i = 1; i < n + 1; ++i) {
      if (b[i] == 4)
        continue;
      if (b[i] == p)
        ++d;
      else {
        if (d > 3) {
          f = true;
          int j = 0, l = i - 1;
          while (j < d) {
            if (b[l] == 4) {
              --l;
              continue;
            }
            b[l] = 4;
            ++j;
            --l;
            --e;
/*						for(int k=0; k<n; ++k) printf("%d ", b[k]);
						printf("\\n");
*/					}
        }
        d = 1;
      }
      p = b[i];
    }
  }
  /*	if(x == 5){
                  for(int i=0; i<n; ++i) printf("%d ", b[i]);
                  printf("\\n");
          }
  */
  return e;
}

int main() {
  while (1) {
    memset(a, 0, sizeof(a));
    scanf("%d", &n);
    if (n == 0)
      return 0;
    for (int i = 0; i < n; ++i)
      scanf("%d", &a[i]);
    ans = 1e9;

    for (int i = 0; i < n; ++i)
      for (int j = 1; j < 4; ++j) {
        for (int k = 0; k < n; ++k)
b[k] = a[k];
        if (a[i] != j) {
ans = min(ans, c(i, j));
        }
        //				printf("%d %d\\n", i, j);
        //				printf("%d\\n", ans);
      }
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

int n;
int a[10000];
int b[10001];
int ans = 1e9;

int c(int x, int y) { // change b[x] to y return remaining
  b[x] = y;
  int e = n;
  bool f = true;
  while (f) {
    f = false;
    int d = 1;
    int p = b[0];
    for (int i = 1; i < n + 1; ++i) {
      if (b[i] == 4)
        continue;
      if (b[i] == p)
        ++d;
      else {
        if (d > 3) {
          f = true;
          int j = 0, l = i - 1;
          while (j < d) {
            if (b[l] == 4) {
              --l;
              continue;
            }
            b[l] = 4;
            ++j;
            --l;
            --e;
/*						for(int k=0; k<n; ++k) printf("%d ", b[k]);
						printf("\\n");
*/					}
        }
        d = 1;
      }
      p = b[i];
    }
  }
  /*	if(x == 5){
                  for(int i=0; i<n; ++i) printf("%d ", b[i]);
                  printf("\\n");
          }
  */
  return e;
}

int main() {
  while (1) {
    memset(a, 0, sizeof(a));
    scanf("%d", &n);
    if (n == 0)
      return 0;
    for (int i = 0; i < n; ++i)
      scanf("%d", &a[i]);
    ans = 1e9;

    for (int i = 0; i < n; ++i)
      for (int j = 1; j < 4; ++j) {
        for (int k = 0; k < n; ++k)
b[k] = a[k];
        ans = min(ans, c(i, j));
        //				printf("%d %d\\n", i, j);
        //				printf("%d\\n", ans);
      }
    printf("%d\\n", ans);
  }
}
Problem p00457 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int chain(int idx, int col);
int model[10002];
int n;
int main(void) {
  while (scanf("%d", &n), n) {
    int mi = n;
    memset(model, 0, sizeof(model));
    for (int i = 0; i < n; i++) {
      scanf("%d", &model[i]);
    }

    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= 3; j++) {
        mi = min(mi, chain(i, j));
      }
    }
    printf("%d\\n", mi);
  }
  return 0;
}

int chain(int idx, int col) {
  if (model[idx] == col)
    return n;
  int c[10002];
  int f[10002] = {0};
  for (int i = 0; i < n; i++) {
    if (idx == i)
      c[i] = col;
    else
      c[i] = model[i];
  }
  c[n] = 100;

  while (1) {
    int flag = 0;
    int curr = c[0], cnt = 1;
    for (int i = 1; i <= n; i++) {
      if (c[i] == 0)
        continue;
      if (c[i] == curr)
        cnt++;
      else {
        curr = c[i];
        if (cnt >= 4) {
          flag = 1;
          for (int j = 0; j < cnt; j++) {
            if (f[i - 1 - j] == 1)
              cnt++;
            f[i - 1 - j] = 1;
            c[i - 1 - j] = 0;
          }
          break;
        }
        cnt = 1;
      }
    }
    if (flag == 0)
      break;
  }

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (f[i] == 0)
      cnt++;
  }
  return cnt;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int chain(int idx, int col);
int model[102];
int n;
int main(void) {
  while (scanf("%d", &n), n) {
    int mi = n;
    memset(model, 0, sizeof(model));
    for (int i = 0; i < n; i++) {
      scanf("%d", &model[i]);
    }

    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= 3; j++) {
        mi = min(mi, chain(i, j));
      }
    }
    printf("%d\\n", mi);
  }
  return 0;
}

int chain(int idx, int col) {
  if (model[idx] == col)
    return n;
  int c[102];
  int f[102] = {0};
  for (int i = 0; i < n; i++) {
    if (idx == i)
      c[i] = col;
    else
      c[i] = model[i];
  }
  c[n] = 100;

  while (1) {
    int flag = 0;
    int curr = c[0], cnt = 1;
    for (int i = 1; i <= n; i++) {
      if (c[i] == 0)
        continue;
      if (c[i] == curr)
        cnt++;
      else {
        curr = c[i];
        if (cnt >= 4) {
          flag = 1;
          for (int j = 0; j < cnt; j++) {
            if (f[i - 1 - j] == 1)
              cnt++;
            f[i - 1 - j] = 1;
            c[i - 1 - j] = 0;
          }
          break;
        }
        cnt = 1;
      }
    }
    if (flag == 0)
      break;
  }

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (f[i] == 0)
      cnt++;
  }
  return cnt;
}