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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, i, j, n;
  string s;
  cin >> n >> s >> k;
  for (i = 0; i < n; i++) {
    if (s.at(i) != s.at(k)) {
      s.at(i) = '*';
    }
  }
  cout << s << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, i, j, n;
  string s;
  cin >> n >> s >> k;
  for (i = 0; i < n; i++) {
    if (s.at(i) != s.at(k - 1)) {
      s.at(i) = '*';
    }
  }
  cout << s << endl;
}
Problem p03068 (C++)

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

#define N 1000
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define all(cont) cont.begin(), cont.end()
#define sortcmp(n, cmpfunc) sort(all(n), cmpfunc)
#define fastio                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)

ll powm(ll a, ll b);
ll divm(ll a, ll b);
ll multm(ll a, ll b);
ll subm(ll a, ll b);
ll addm(ll a, ll b);

int main() {
  int n, k;
  string s;
  fastio;
#ifndef LOCAL
  freopen("input.in", "r", stdin);
  freopen("output.out", "w", stdout);
#endif
  cin >> n >> s >> k;
  for (auto i : s) {
    if (i != s[k - 1])
      cout << '*';
    else
      cout << i;
  }
  cout << endl;
  return 0;
}

// template function
ll gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll powm(ll a, ll b) {
  ll x = 1, y = a;
  while (b > 0) {
    if (b % 2)
      x = (x * y) % mod;
    y = (y * y) % mod;
    b /= 2;
  }
  return x % mod;
}

ll multm(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }

ll divm(ll a, ll b) { return (a * powm(b, mod - 2)); }

ll subm(ll a, ll b) {
  a -= b;
  if (a < 0)
    a += mod;
  return a;
}

ll addm(ll a, ll b) {
  a += b;
  if (a >= mod)
    a -= mod;
  return a;
}

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

#define N 1000
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define all(cont) cont.begin(), cont.end()
#define sortcmp(n, cmpfunc) sort(all(n), cmpfunc)
#define fastio                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)

ll powm(ll a, ll b);
ll divm(ll a, ll b);
ll multm(ll a, ll b);
ll subm(ll a, ll b);
ll addm(ll a, ll b);

int main() {
  int n, k;
  string s;
  fastio;
  // #ifndef LOCAL
  //    	freopen("input.in", "r", stdin);
  //    	freopen("output.out", "w", stdout);
  // #endif
  cin >> n >> s >> k;
  for (auto i : s) {
    if (i != s[k - 1])
      cout << '*';
    else
      cout << i;
  }
  cout << endl;
  return 0;
}

// template function
ll gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll powm(ll a, ll b) {
  ll x = 1, y = a;
  while (b > 0) {
    if (b % 2)
      x = (x * y) % mod;
    y = (y * y) % mod;
    b /= 2;
  }
  return x % mod;
}

ll multm(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }

ll divm(ll a, ll b) { return (a * powm(b, mod - 2)); }

ll subm(ll a, ll b) {
  a -= b;
  if (a < 0)
    a += mod;
  return a;
}

ll addm(ll a, ll b) {
  a += b;
  if (a >= mod)
    a -= mod;
  return a;
}
Problem p03068 (C++)

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

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

  for (int i = 0; i < N; i++) {
    if (S.at(i) != S.at(K)) {
      S.at(i) = '*';
    }
  }

  cout << S << endl;
}

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

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

  for (int i = 0; i < N; i++) {
    if (S.at(i) != S.at(K - 1)) {
      S.at(i) = '*';
    }
  }

  cout << S << endl;
}
Problem p03068 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define str string
#define rep(x, y) for (int i = x; i < y; i++)
#define REP(x, y) for (int j = x; j < y; j++)
#define all(x) x.begin(), x.end()
signed main() {
  int A, B, C, N, K;
  str S, W, T;
  cin >> N >> S;
  cin >> K;
  rep(0, N) {
    if (S.at(i) != S.at(K)) {
      S.at(i) = '*';
    }
  }
  cout << S << endl;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define str string
#define rep(x, y) for (int i = x; i < y; i++)
#define REP(x, y) for (int j = x; j < y; j++)
#define all(x) x.begin(), x.end()
signed main() {
  int A, B, C, N, K;
  str S, W, T;
  cin >> N >> S;
  cin >> K;
  rep(0, N) {
    if (S.at(K - 1) != S.at(i)) {
      S.at(i) = '*';
    }
  }
  cout << S << endl;
}
Problem p03068 (C++)

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

int main() {
  string S;
  int N, K;
  cin >> N >> S >> K;
  for (int i = 0; i < N; i++) {
    if (S.at(i) != S.at(K)) {
      S.at(i) = '*';
    }
  }
  cout << S << endl;
}


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

int main() {
  string S;
  int N, K;
  cin >> N >> S >> K;
  for (int i = 0; i < N; i++) {
    if (S.at(i) != S.at(K - 1)) {
      S.at(i) = '*';
    }
  }
  cout << S << endl;
}
Problem p03068 (C++)

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

int main() {
  int k, n;
  string s;
  cin >> n >> s >> k;
  char hoge = s.at(k);
  for (auto &&i = s.begin(); i < s.end(); i++) {
    if (*i != hoge) {
      *i = '*';
    }
  }
  cout << s << endl;
}


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

int main() {
  int k, n;
  string s;
  cin >> n >> s >> k;
  char hoge = s.at(k - 1);
  for (auto &&i = s.begin(); i < s.end(); i++) {
    if (*i != hoge) {
      *i = '*';
    }
  }
  cout << s << endl;
}
Problem p03068 (C++)

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

int main() {
  int N, K;
  string S;
  char SelectedChar;
  cin >> N >> S >> K;
  SelectedChar = S.at(K);

  for (int i = 0; i < N; i++) {
    if (S.at(i) != SelectedChar) {
      S.at(i) = '*';
    }
  }
  cout << S << endl;
}

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

int main() {
  int N, K;
  string S;
  char SelectedChar;
  cin >> N >> S >> K;
  SelectedChar = S.at(K - 1);

  for (int i = 0; i < N; i++) {
    if (S.at(i) != SelectedChar) {
      S.at(i) = '*';
    }
  }
  cout << S << endl;
}
Problem p03068 (C++)

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

using namespace std;

int main() {
  int N, K;
  char S[N];
  cin >> N >> S >> K;
  char a = S[K - 1];
  for (int i = 0; i < N; i++) {
    if (S[i] != a) {
      S[i] = '*';
    }
  }
  std::cout << N << std::endl;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int N, K;
  char S[N];
  cin >> N >> S >> K;
  char a = S[K - 1];
  for (int i = 0; i < N; i++) {
    if (S[i] != a) {
      S[i] = '*';
    }
  }
  std::cout << S << std::endl;
  return 0;
}
Problem p03068 (C++)

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

string s;
int n, k;
char c;

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

  c = s.at(k);

  for (int i = 0; i < n; ++i) {
    if (s.at(i) != c) {
      s.at(i) = '*';
    }
  }

  cout << s << endl;
}

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

string s;
int n, k;
char c;

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

  c = s.at(k - 1);

  for (int i = 0; i < n; ++i) {
    if (s.at(i) != c) {
      s.at(i) = '*';
    }
  }

  cout << s << endl;
}
Problem p03068 (C++)

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

using namespace std;

int main() {
  int n, k;
  string s;
  cin >> n;
  cin >> s;
  cin >> k;
  char moji = s.at(k);
  for (int i = 0; i < n; i++) {
    if (s.at(i) != moji) {
      s.at(i) = '*';
    }
  }
  cout << s << endl;
}

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

using namespace std;

int main() {
  int n, k;
  string s;
  cin >> n;
  cin >> s;
  cin >> k;
  char moji = s.at(k - 1);
  for (int i = 0; i < n; i++) {
    if (s.at(i) != moji) {
      s.at(i) = '*';
    }
  }
  cout << s << endl;
}
Problem p03068 (C++)

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

int main() {

  int N, K;
  cin >> N;
  string s;
  cin >> s >> K;
  char x;
  x = s.at(K);

  for (int i = 0; i < N; i++) {
    if (x != s.at(i)) {
      cout << "*";
    } else {
      cout << x;
    }
  }
}

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

int main() {

  int N, K;
  cin >> N;
  string s;
  cin >> s >> K;
  char x;
  x = s.at(K - 1);

  for (int i = 0; i < N; i++) {
    if (x != s.at(i)) {
      cout << "*";
    } else {
      cout << x;
    }
  }
}
Problem p03068 (C++)

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

int main() {
  int n, k;
  string s;

  cin >> n >> s >> k;

  for (int i = 0; i < n; i++) {
    if (s.at(i) != s.at(k)) {
      s.at(i) = '*';
    }
  }

  cout << s << endl;
}

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

int main() {
  int n, k;
  string s;

  cin >> n >> s >> k;

  for (int i = 0; i < n; i++) {
    if (s.at(i) != s.at(k - 1)) {
      s.at(i) = '*';
    }
  }

  cout << s << endl;
}
Problem p03068 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  int n, k;
  string s;
  cin >> n >> s >> k;
  for (int i = 0; i < n; i++) {
    if (s.at(i) != s.at(k)) {
      s.at(i) = '*';
    }
  }
  cout << s << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  int n, k;
  string s;
  cin >> n >> s >> k;
  for (int i = 0; i < n; i++) {
    if (s.at(i) != s.at(k - 1)) {
      s.at(i) = '*';
    }
  }
  cout << s << endl;
}
Problem p03068 (C++)

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int K;
  cin >> K;
  for (int i = 0; i < N; i++) {
    if (S.at(i) != S.at(K)) {
      S.at(i) = '*';
    }
  }
  cout << S << endl;
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int K;
  cin >> K;
  for (int i = 0; i < N; i++) {
    if (S.at(i) != S.at(K - 1)) {
      S.at(i) = '*';
    }
  }
  cout << S << endl;
}
Problem p03068 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a, c;
  string b;
  cin >> a >> b >> c;
  for (int i = 0; i < a; i++) {
    if (b.at(i) != b.at(c))
      b.at(i) = '*';
  }
  cout << b << endl;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a, c;
  string b;
  cin >> a >> b >> c;
  for (int i = 0; i < a; i++) {
    if (b.at(i) != b.at(c - 1))
      b.at(i) = '*';
  }
  cout << b << endl;
}
Problem p03068 (C++)

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

int main() {
  int N, K;
  string S;
  cin >> N >> S >> K;
  for (int i = 0; i < N; i++) {
    if (S.at(i) != S.at(K)) {
      S.at(i) = '*';
    }
  }
  cout << S << endl;
}

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

int main() {
  int N, K;
  string S;
  cin >> N >> S >> K;
  for (int i = 0; i < N; i++) {
    if (S.at(i) != S.at(K - 1)) {
      S.at(i) = '*';
    }
  }
  cout << S << endl;
}
Problem p03068 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
s = str(input())
k = int(input())

char = s[k]
result = ""
for x in s:
    if x == char:
        result += char
    else:
        result += "*"
print(result)


Fixed submission:
n = int(input())
s = str(input())
k = int(input())

char = s[k - 1]
result = ""
for x in s:
    if x == char:
        result += char
    else:
        result += "*"
print(result)
Problem p03068 (Python)

Buggy submission (status: Runtime Error):
from functools import reduce

N = int(input())
S = input()
K = int(input())

print(reduce(lambda x, y: x + (y if y == S[K] else "*"), S, ""))


Fixed submission:
from functools import reduce

N = int(input())
S = input()
K = int(input()) - 1

print(reduce(lambda x, y: x + (y if y == S[K] else "*"), S, ""))
Problem p03068 (Python)

Buggy submission (status: Runtime Error):
from re import sub

n = int(input())
s = input()
k = int(input())

print(sub(f"[^{s[k-1]}]", "*", s))


Fixed submission:
from re import sub

n = int(input())
s = input()
k = int(input())

print(sub("[^{}]".format(s[k - 1]), "*", s))
Problem p03068 (Python)

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

target = S[K]
ans = ""
for s in S:
    ans += s if s == target else "*"
print(ans)


Fixed submission:
N = int(input())
S = list(input())
K = int(input())

target = S[K - 1]
ans = ""
for s in S:
    ans += s if s == target else "*"
print(ans)
Problem p03068 (Python)

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

a = S[K + 1]

for i in range(len(S)):
    if S[i] != a:
        print("*", end="")
    else:
        print(S[i], end="")
print()


Fixed submission:
N = int(input())
S = input()
K = int(input())

a = S[K - 1]

for i in range(len(S)):
    if S[i] != a:
        print("*", end="")
    else:
        print(S[i], end="")
print()
Problem p03068 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
S = input()
K = int(input())
flag = S[K]
ans = []
for x in S:
    if x == flag:
        ans.append(x)
    else:
        ans.append("*")
print("".join(ans))


Fixed submission:
N = int(input())
S = input()
K = int(input())
flag = S[K - 1]
ans = []
for x in S:
    if x == flag:
        ans.append(x)
    else:
        ans.append("*")
print("".join(ans))
Problem p03068 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
s = input()
k = int(input())
result = []

for x in s:
    if x != s[k]:
        result.append("*")
    else:
        result.append(x)

print("".join(result))


Fixed submission:
n = int(input())
s = input()
k = int(input())
result = []

for x in s:
    if x != s[k - 1]:
        result.append("*")
    else:
        result.append(x)

print("".join(result))
Problem p03068 (Python)

Buggy submission (status: Runtime Error):
input()
S = input()
K = int(input())

c = S[K]

print("".join([v if v == c else "*" for v in S]))


Fixed submission:
input()
S = input()
K = int(input())

c = S[K - 1]

print("".join([v if v == c else "*" for v in S]))
Problem p03068 (C++)

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

int main() {
  int n, k;
  string s;
  cin >> n >> s >> k;
  char c = s.at(k);
  for (int i = 0; i < n; i++) {
    if (s.at(i) != c) {
      s.at(i) = '*';
    }
  }

  cout << s << endl;
}


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

int main() {
  int n, k;
  string s;
  cin >> n >> s >> k;
  char c = s.at(k - 1);
  for (int i = 0; i < n; i++) {
    if (s.at(i) != c) {
      s.at(i) = '*';
    }
  }

  cout << s << endl;
}
Problem p03068 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pll pair<ll, ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define lb(c, x) distance(c.begin(), lower_bound(all(c), x))
#define ub(c, x) distance(c.begin(), upper_bound(all(c), x))

using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const ll INF = 1e18;
const ll mod = 1e9 + 7;
const double eps = 0.000000001;

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> n;
  ll k;
  cin >> k;
  k--;
  char c = s[k];
  rep(i, n) {
    if (s[i] != c)
      s[i] = '*';
  }
  cout << s << endl;
  return 0;
}

Fixed submission:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pll pair<ll, ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define lb(c, x) distance(c.begin(), lower_bound(all(c), x))
#define ub(c, x) distance(c.begin(), upper_bound(all(c), x))

using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const ll INF = 1e18;
const ll mod = 1e9 + 7;
const double eps = 0.000000001;

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll k;
  cin >> k;
  k--;
  char c = s[k];
  rep(i, n) {
    if (s[i] != c)
      s[i] = '*';
  }
  cout << s << endl;
  return 0;
}
Problem p03068 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
s = input()
k = int(input())

s = list(map(lambda x: "*" if x != s[k] else x, s))

print(*s, sep="")


Fixed submission:
n = int(input())
s = input()
k = int(input()) - 1

s = list(map(lambda x: "*" if x != s[k] else x, s))

print(*s, sep="")
Problem p03069 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#define in(a) a = read()
#define REP(i, k, n) for (int i = k; i <= n; i++)
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      f = -1;
  for (; isdigit(ch); ch = getchar())
    x = x * 10 + ch - '0';
  return x * f;
}
int main() {
  int n;
  char ch[100010];
  int a[100010], b[100010];
  in(n);
  int flag = 0;
  scanf("%s", ch + 1);
  int ans = 999999;
  REP(i, 1, n) {
    b[i] = b[i - 1];
    if (ch[i] == '#')
      b[i]++;
  }
  for (int i = n; i >= 1; i--) {
    a[i] = a[i + 1];
    if (ch[i] == '.')
      a[i]++;
  }
  for (int i = 0; i <= n; i++) {
    ans = min(ans, b[i] + a[i + 1]);
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#define in(a) a = read()
#define REP(i, k, n) for (int i = k; i <= n; i++)
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      f = -1;
  for (; isdigit(ch); ch = getchar())
    x = x * 10 + ch - '0';
  return x * f;
}
int main() {
  int n;
  char ch[1000010];
  int a[1000010], b[1000010];
  in(n);
  int flag = 0;
  scanf("%s", ch + 1);
  int ans = 999999;
  REP(i, 1, n) {
    b[i] = b[i - 1];
    if (ch[i] == '#')
      b[i]++;
  }
  for (int i = n; i >= 1; i--) {
    a[i] = a[i + 1];
    if (ch[i] == '.')
      a[i]++;
  }
  for (int i = 0; i <= n; i++) {
    ans = min(ans, b[i] + a[i + 1]);
  }
  cout << ans;
  return 0;
}
Problem p03069 (C++)

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

using namespace std;

const int INF = 1001001001;
int sum[100001];

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

  for (int i = 0; i < n; ++i) {
    sum[i + 1] = sum[i];
    if (s[i] == '#') {
      ++sum[i + 1];
    }
  }

  int ans = INF;
  for (int i = 0; i <= n; ++i) {
    int cnt = 0;
    cnt += sum[i];
    cnt += n - i - (sum[n] - sum[i]);

    ans = min(ans, cnt);
  }

  cout << ans << endl;
}

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

using namespace std;

const int INF = 1001001001;
int sum[200005];

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

  for (int i = 0; i < n; ++i) {
    sum[i + 1] = sum[i];
    if (s[i] == '#') {
      ++sum[i + 1];
    }
  }

  int ans = INF;
  for (int i = 0; i <= n; ++i) {
    int cnt = 0;
    cnt += sum[i];
    cnt += n - i - (sum[n] - sum[i]);

    ans = min(ans, cnt);
  }

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

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

#include <algorithm>
#include <string>
using namespace std;

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

  // 境界を探索
  int min = n;
  for (int i = 0; i <= n; i++) {
    int c_b = 0, c_w = 0;
    for (int j = 0; j < n; i++) {
      string t = s.substr(j, 1);
      if (j < i && s == "#")
        c_b++;
      if (j >= i && s == ".")
        c_w++;
    }
    if (min > c_b + c_w)
      min = c_b + c_w;
  }

  cout << min << endl;
}

Fixed submission:
#include <iostream>

#include <algorithm>
#include <string>
using namespace std;

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

  // 境界を探索
  int c_b = 0, c_w = 0;

  for (int i = 0; i < n; i++) {
    string t = s.substr(i, 1);
    if (t == ".")
      c_w++;
  }

  int min = c_w;
  for (int i = 0; i < n; i++) {
    string t = s.substr(i, 1);
    if (t == "#")
      c_b++;
    if (t == ".")
      c_w--;
    if (min > c_b + c_w)
      min = c_b + c_w;
  }

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

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;
string s;

int white[MAX_N];
int black[MAX_N];

int ans;

int main(void) {
  // Here your code !
  scanf("%d", &n);
  cin >> s;

  for (int i = 0; i < n; ++i) {
    if (s[i] == '#') {
      black[i] = 1;
    } else {
      white[i] = 1;
    }
  }

  for (int i = 1; i < n; ++i) {
    black[i] = black[i] + black[i - 1];
  }

  for (int i = 1; i < n; ++i) {
    white[i] = white[i] + white[i - 1];
  }

  int all_black = black[n - 1];
  int all_white = white[n - 1];

  ans = min(n - all_black, n - all_white);

  for (int i = 0; i < n; ++i) {
    int left_b = black[i];
    int left_w = white[i];

    int right_b = all_black - left_b;
    int right_w = all_white - left_w;

    // case: w, w
    ans = min(ans, left_b + right_b);

    // case: w, b
    ans = min(ans, left_b + right_w);

    // case: b, b
    ans = min(ans, left_w + right_w);
  }

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

  return 0;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(2e5 + 5);

int n;
string s;

int white[MAX_N];
int black[MAX_N];

int ans;

int main(void) {
  // Here your code !
  scanf("%d", &n);
  cin >> s;

  for (int i = 0; i < n; ++i) {
    if (s[i] == '#') {
      black[i] = 1;
    } else {
      white[i] = 1;
    }
  }

  for (int i = 1; i < n; ++i) {
    black[i] = black[i] + black[i - 1];
  }

  for (int i = 1; i < n; ++i) {
    white[i] = white[i] + white[i - 1];
  }

  int all_black = black[n - 1];
  int all_white = white[n - 1];

  ans = min(n - all_black, n - all_white);

  for (int i = 0; i < n; ++i) {
    int left_b = black[i];
    int left_w = white[i];

    int right_b = all_black - left_b;
    int right_w = all_white - left_w;

    // case: w, w
    ans = min(ans, left_b + right_b);

    // case: w, b
    ans = min(ans, left_b + right_w);

    // case: b, b
    ans = min(ans, left_w + right_w);
  }

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

  return 0;
}
Problem p03069 (C++)

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int> vecB(N + 1), vecW(N + 1), ans(N + 1);
  for (int i = 0; i <= N; i++) {
    if (S[i] == '#') {
      vecB[i + 1] = vecB[i] + 1;
    } else {
      vecB[i + 1] = vecB[i];
    }
    if (S[N - 1 - i] == '.') {
      vecW[N - 1 - i] = vecW[N - i] + 1;
    } else {
      vecW[N - 1 - i] = vecW[N - i];
    }
  }
  for (int i = 0; i <= N; i++) {
    ans[i] = vecB[i] + vecW[i];
  }
  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;

  return 0;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int> vecB(N + 1), vecW(N + 1), ans(N + 1);
  for (int i = 0; i < N; i++) {
    if (S[i] == '#') {
      vecB[i + 1] = vecB[i] + 1;
    } else {
      vecB[i + 1] = vecB[i];
    }
    if (S[N - 1 - i] == '.') {
      vecW[N - 1 - i] = vecW[N - i] + 1;
    } else {
      vecW[N - 1 - i] = vecW[N - i];
    }
  }
  for (int i = 0; i <= N; i++) {
    ans[i] = vecB[i] + vecW[i];
  }
  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;

  return 0;
}
Problem p03069 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

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

  int b[30000], w[30000];

  int i;
  b[0] = 0;
  w[0] = 0;
  for (i = 1; i <= n; i++) {
    if (s[i - 1] == '.') {
      w[i] = w[i - 1] + 1;
      b[i] = b[i - 1];
    } else {
      w[i] = w[i - 1];
      b[i] = b[i - 1] + 1;
    }
  }

  int ans = 1000000;

  for (i = 0; i <= n; i++) {
    ans = min(ans, b[i] + (w[n] - w[i]));
  }

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

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

  int b[300000], w[300000];

  int i;
  b[0] = 0;
  w[0] = 0;
  for (i = 1; i <= n; i++) {
    if (s[i - 1] == '.') {
      w[i] = w[i - 1] + 1;
      b[i] = b[i - 1];
    } else {
      w[i] = w[i - 1];
      b[i] = b[i - 1] + 1;
    }
  }

  int ans = 1000000;

  for (i = 0; i <= n; i++) {
    ans = min(ans, b[i] + (w[n] - w[i]));
  }

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

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int b[100010] = {};
  int w[100010] = {};

  for (int i = 0; i < n; i++) {
    b[i + 1] += b[i];
    w[i + 1] += w[i];
    if (s[i] == '#') {
      b[i + 1]++;
    } else {
      w[i + 1]++;
    }
  }

  int ans = INT_MAX;
  for (int i = 0; i <= n; i++) {
    ans = min(ans, b[i] + w[n] - w[i]);
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int b[200010] = {};
  int w[200010] = {};

  for (int i = 0; i < n; i++) {
    b[i + 1] += b[i];
    w[i + 1] += w[i];
    if (s[i] == '#') {
      b[i + 1]++;
    } else {
      w[i + 1]++;
    }
  }

  int ans = INT_MAX;
  for (int i = 0; i <= n; i++) {
    ans = min(ans, b[i] + w[n] - w[i]);
  }
  cout << ans << endl;
  return 0;
}
Problem p03069 (C++)

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

using namespace std;

#define N_TIMES(i, n) for (uint64_t i = 0; i < n; ++i)
#define N_TIMES_REV(i, n) for (int64_t i = n - 1; i >= 0; --i)

int main(int argc, char **argv) {
  uint64_t N;
  cin >> N;

  string S;
  cin >> S;

  vector<uint64_t> black(N + 1, 0), white(N + 1, 0);
  N_TIMES(n, N + 1) {
    black[n + 1] = ((S[n] == '#') ? 1 : 0) + black[n];
    white[n + 1] = ((S[n] == '.') ? 1 : 0) + white[n];
  }

  uint64_t count = -1;
  N_TIMES(n, N + 1) {
    uint64_t pw = n, pb = N - n;
    uint64_t qw = white[n] - white[0];
    uint64_t qb = black[N] - black[n];

    count = min(count, (pw - qw) + (pb - qb));
  }
  cout << count << endl;

  return 0;
}

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

using namespace std;

#define N_TIMES(i, n) for (uint64_t i = 0; i < n; ++i)
#define N_TIMES_REV(i, n) for (int64_t i = n - 1; i >= 0; --i)

int main(int argc, char **argv) {
  uint64_t N;
  cin >> N;

  string S;
  cin >> S;

  vector<uint64_t> black(N + 1, 0), white(N + 1, 0);
  N_TIMES(n, N) {
    black[n + 1] = ((S[n] == '#') ? 1 : 0) + black[n];
    white[n + 1] = ((S[n] == '.') ? 1 : 0) + white[n];
  }

  uint64_t count = -1;
  N_TIMES(n, N + 1) {
    uint64_t pw = n, pb = N - n;
    uint64_t qw = white[n] - white[0];
    uint64_t qb = black[N] - black[n];

    count = min(count, (pw - qw) + (pb - qb));
  }
  cout << count << endl;

  return 0;
}
Problem p03069 (C++)

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  S = S + '#';
  vector<int> a(S.size(), 0);
  int i, j, J;
  int b;
  char c = S.at(0);
  for (i = j = 0; i < S.size(); i++) {
    if (S.at(i) != c) {
      c = S.at(i);
      j++;
    }
    if (c == '.')
      a.at(j)++;
    else
      a.at(j)--;
  }
  J = j + 1;
  // for (i=0; i<J; i++) cout <<a.at(i) <<endl;////
  b = 0;
  for (i = 0; i < J; i++) {
    if (a.at(i) > 0)
      b += a.at(i);
  }
  // cout << "b=" << b << endl;////////////////
  if (a.at(0) < 0) {
    i = 0;
  } else {
    i = 1;
    b -= a.at(0);
  }
  // cout << "b=" << b << endl;////////////////
  int B = b;
  for (; i < J; i += 2) {
    // cout << "Before " << a.at(i) << ':' << a.at(i+1) << ':' << b << endl;
    b = b - a.at(i) - a.at(i + 1);
    // cout << "After  " << a.at(i) << ':' << a.at(i+1) << ':' << b << endl;
    B = min(B, b);
  }
  cout << B << endl;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  S = S + '#';
  vector<int> a(S.size(), 0);
  int i, j, J;
  int b;
  char c = S.at(0);
  for (i = j = 0; i < S.size(); i++) {
    if (S.at(i) != c) {
      c = S.at(i);
      j++;
    }
    if (c == '.')
      a.at(j)++;
    else
      a.at(j)--;
  }
  J = j + 1;
  // for (i=0; i<J; i++) cout <<a.at(i) <<endl;////
  b = 0;
  for (i = 0; i < J; i++) {
    if (a.at(i) > 0)
      b += a.at(i);
  }
  // cout << "b=" << b << endl;////////////////
  if (a.at(0) < 0) {
    i = 0;
  } else {
    i = 1;
    b -= a.at(0);
  }
  // cout << "b=" << b << endl;////////////////
  int B = b;
  for (; i < J - 1; i += 2) {
    // cout << "Before " << a.at(i) << ':' << a.at(i+1) << ':' << b << endl;
    b = b - a.at(i) - a.at(i + 1);
    // cout << "After  " << a.at(i) << ':' << a.at(i+1) << ':' << b << endl;
    B = min(B, b);
  }
  cout << B << endl;
}
Problem p03069 (C++)

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

int main() {
  int N;
  scanf("%d", &N);
  string S;
  cin >> S;
  int counta = 0;
  int countb = 0;
  int countc = 0;
  int max = N;

  for (int i = 0; i < N; ++i) {
    if (S[i] == '#')
      ++counta;
  }

  for (int i = 0; i < N; ++i) {
    if (S[i] == '.')
      ++countb;
  }

  if (counta < max)
    max = counta;
  if (countb < max)
    max = countb;

  for (int ii = 0; ii < N; ++ii) {
    countc = 0;
    for (int iii = 0; iii < ii; ++iii) {
      if (S[iii] == '#')
        ++countc;
      if (countc >= max)
        break;
    }
    for (int iii = ii; iii < N; ++iii) {
      if (S[iii] == '.')
        ++countc;
      if (countc >= max)
        break;
    }
    if (countc < max)
      max = countc;
  }

  cout << max << endl;
}

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

int main() {
  int N;
  scanf("%d", &N);
  string S;
  cin >> S;
  int counta = 0;
  int countb = 0;
  int countc = 0;
  int max = N;

  for (int i = 0; i < N; ++i) {
    if (S[i] == '#')
      ++counta;
  }

  for (int i = 0; i < N; ++i) {
    if (S[i] == '.')
      ++countb;
  }

  if (counta < max)
    max = counta;
  if (countb < max)
    max = countb;

  for (int i = 0; i < N; ++i) {
    if (S[i] == '#')
      ++countb;
    else
      --countb;
    if (countb < max)
      max = countb;
  }

  cout << max << endl;
}
Problem p03069 (C++)

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

using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> vtL(n + 1, 0);
  vector<int> vtR(n + 1, 0);

  for (int i = 0; i < n; ++i) {
    vtL[i + 1] = vtL[i];
    if (s[i] == '#')
      vtL[i + 1]++;
    vtR[n - 2 - i] = vtR[n - 1 - i];
    if (s[n - 1 - i] == '.')
      vtR[n - 2 - i]++;
  }

  int ans = INT_MAX;
  for (int i = 0; i < n; ++i) {
    ans = min(ans, vtL[i] + vtR[i]);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> vtL(n + 1, 0);
  vector<int> vtR(n + 1, 0);

  for (int i = 0; i < n; ++i) {
    vtL[i + 1] = vtL[i];
    if (s[i] == '#')
      vtL[i + 1]++;

    if (n - 2 - i < 0)
      continue;
    vtR[n - 2 - i] = vtR[n - 1 - i];
    if (s[n - 1 - i] == '.')
      vtR[n - 2 - i]++;
  }

  int ans = INT_MAX;
  for (int i = 0; i < n; ++i) {
    ans = min(ans, vtL[i] + vtR[i]);
  }
  cout << ans << endl;
  return 0;
}
Problem p03069 (C++)

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

int main() {
  int N;
  int black[100002] = {};
  int n_black = 0;
  string S;
  cin >> N >> S;

  for (int i = 1; i <= N; i++) {
    black[i] = black[i - 1];
    if (S[i - 1] == '#')
      black[i]++;
  }
  n_black = black[N];

  int ans = 2e5 + 1;
  for (int i = 0; i <= N; i++) {
    ans = min(ans, black[i] + (N - i) - (n_black - black[i]));
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N;
  int black[200002] = {};
  int n_black = 0;
  string S;
  cin >> N >> S;

  for (int i = 1; i <= N; i++) {
    black[i] = black[i - 1];
    if (S[i - 1] == '#')
      black[i]++;
  }
  n_black = black[N];

  int ans = 2e5 + 1;
  for (int i = 0; i <= N; i++) {
    ans = min(ans, black[i] + (N - i) - (n_black - black[i]));
  }
  cout << ans << endl;
  return 0;
}
Problem p03069 (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 reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i, size) cin >> arr[i];

int main() {
  int N;
  string S;
  cin >> N >> S;
  bitset<200000> pattern, stones;
  pattern.set();
  stones.set();
  rep(i, N) { stones[N - 1 - i] = S[i] == '.'; }
  int minimum = INT_MAX;
  rep(i, N + 1) {
    minimum = min(minimum, (int)((pattern << i) ^ stones).count());
  }
  cout << minimum << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i, size) cin >> arr[i];

int main() {
  int N;
  string S;
  cin >> N >> S;
  int left_black = 0, right_white = 0;
  rep(i, N) if (S[i] == '.') right_white++;

  int minimum = right_white;
  rep(i, N) {
    if (S[i] == '.')
      right_white--;
    if (S[i] == '#')
      left_black++;
    minimum = min(minimum, left_black + right_white);
  }
  cout << minimum << endl;
}
Problem p03069 (Python)

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

W = [0] * N
W[-1] += S[-1] == "."
for i in range(N - 2, -1, -1):
    W[i] = W[i + 1] + (S[i] == ".")

B = [0] * N
B[0] += S[0] == "#"
for i in range(1, N):
    B[i] = B[i - 1] + (S[i] == "#")

T = [w + b for w, b in zip(W, B)]
print(min(*T, W[0], B[-1]))


Fixed submission:
N = int(input())
S = input()

W = [0] * N
W[-1] += S[-1] == "."
for i in range(N - 2, -1, -1):
    W[i] = W[i + 1] + (S[i] == ".")

B = [0] * N
B[0] += S[0] == "#"
for i in range(1, N):
    B[i] = B[i - 1] + (S[i] == "#")

T = [w + b - 1 for w, b in zip(W, B)]
T = min(T)
print(min(T, W[0], B[-1]))
Problem p03069 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
S = list(input())
c = 0
a = 0
cw = [0] * N
cb = [0] * N
tw = 0
tb = 0
for i in range(N):
    if S[i] == ".":
        tw += 1
        cw[i] = tw
        cb[i] = tb
    else:
        tb += 1
        cb[i] = tb
        cw[i] = tw
A = cw[N]
for i in range(N):
    A = min(A, cb[i] + cw[N - 1] - cw[i])
print(A)


Fixed submission:
N = int(input())
S = list(input())
c = 0
a = 0
cw = [0] * N
cb = [0] * N
tw = 0
tb = 0
for i in range(N):
    if S[i] == ".":
        tw += 1
        cw[i] = tw
        cb[i] = tb
    else:
        tb += 1
        cb[i] = tb
        cw[i] = tw
A = cw[N - 1]
for i in range(N):
    A = min(A, cb[i] + cw[N - 1] - cw[i])
print(A)
Problem p03069 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
S = input()
ans = 0
if N == 1:
    print(0)
    exit()
elif N == 2 and (S[0] == "." and S[1] == "#"):
    print(0)
    exit()
else:
    S = S[0] + S + S[N - 1]
    S = list(S)
    for n in range(N):
        if S[n] == "." and S[n + 2] == "." and S[n + 1] == "#":
            ans += 1
            S[n + 1] = "."
        elif S[n] == "#" and S[n + 2] == "#" and S[n + 1] == ".":
            ans += 1
            S[S + 1] = "#"
print(ans)


Fixed submission:
N = int(input())
S = input()
ans = N
sumB = [0] * (N + 1)
tmp = 0
for i in range(N):
    if S[i] == "#":
        tmp += 1
    sumB[i + 1] = tmp
for i in range(N + 1):
    ans = min(sumB[i] + (N - i) - (sumB[N] - sumB[i]), ans)
    # print(sumB[i] , (N - i), (sumB[N] - sumB[i]), ans)
print(ans)
Problem p03069 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MAX 2001
using namespace std;
int main() {
  int n;
  char s[MAX];
  cin >> n >> s;
  int a[MAX + 1], b[MAX + 1];
  memset(a, 0, (n + 1) * sizeof(int));
  memset(b, 0, (n + 1) * sizeof(int));
  for (int i = 0; i < n; i++) {
    if (s[i] == '#')
      b[i + 1] = b[i] + 1;
    else
      b[i + 1] = b[i];
  }
  for (int i = n - 1; i >= 0; i--)
    if (s[i] == '.')
      a[n - i] = a[n - 1 - i] + 1;
    else
      a[n - i] = a[n - 1 - i];
  int ans = MAX + 1;
  for (int i = 0; i <= n; i++)
    ans = min(ans, b[i] + a[n - i]);
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define MAX 200001
using namespace std;
int main() {
  int n;
  char s[MAX];
  cin >> n >> s;
  int a[MAX + 1], b[MAX + 1];
  memset(a, 0, (n + 1) * sizeof(int));
  memset(b, 0, (n + 1) * sizeof(int));
  for (int i = 0; i < n; i++) {
    if (s[i] == '#')
      b[i + 1] = b[i] + 1;
    else
      b[i + 1] = b[i];
  }
  for (int i = n - 1; i >= 0; i--)
    if (s[i] == '.')
      a[n - i] = a[n - 1 - i] + 1;
    else
      a[n - i] = a[n - 1 - i];
  int ans = MAX + 1;
  for (int i = 0; i <= n; i++)
    ans = min(ans, b[i] + a[n - i]);
  cout << ans;
  return 0;
}
Problem p03069 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
S = input()
ans = N
for i in range(N + 1):
    ans = min(ans, S[:i].count("#") + S[i:].count("."))
print(ans)


Fixed submission:
N = int(input())
S = input()
ws = S.count(".")
bs = 0
ans = ws + bs
for i in range(N):
    if S[i] == "#":
        bs += 1
    else:
        ws -= 1
    ans = min(ans, ws + bs)
print(ans)
Problem p03069 (C++)

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

using namespace std;

int white[100005], black[100005];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  string s;
  cin >> n >> s;

  white[n - 1] = (int)(s[n - 1] == '.');
  black[0] = (int)(s[0] == '#');

  for (int i = n - 2; i >= 0; i--)
    white[i] += white[i + 1] + (int)(s[i] == '.');
  for (int i = 1; i < n; i++)
    black[i] += black[i - 1] + (int)(s[i] == '#');

  int result = white[0];

  for (int i = 0; i < n; i++)
    result = min(result, black[i] + white[i + 1]);

  cout << result << endl;

  return 0;
}


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

using namespace std;

int white[200005], black[200005];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  string s;
  cin >> n >> s;

  white[n - 1] = (int)(s[n - 1] == '.');
  black[0] = (int)(s[0] == '#');

  for (int i = n - 2; i >= 0; i--)
    white[i] += white[i + 1] + (int)(s[i] == '.');
  for (int i = 1; i < n; i++)
    black[i] += black[i - 1] + (int)(s[i] == '#');

  int result = white[0];

  for (int i = 0; i < n; i++)
    result = min(result, black[i] + white[i + 1]);

  cout << result << endl;

  return 0;
}
Problem p03069 (C++)

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

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

  string S;
  cin >> S;

  vector<int> res(N + 1);

  for (int i = 0; i <= N; i++) {
    res.at(i) = count(S.begin(), S.begin() + i, '#') +
                count(S.begin() + i, S.end(), '.');
  }

  cout << *min_element(res.begin(), res.end()) << endl;
}


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

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

  string S;
  cin >> S;

  vector<int> res(N + 1);

  int left = 0;
  int right = count(S.begin(), S.end(), '.');
  res.at(0) = left + right;

  for (int i = 0; i < N; i++) {
    if (S.at(i) == '#')
      left++;
    else
      right--;

    res.at(i + 1) = left + right;
  }

  cout << *min_element(res.begin(), res.end()) << endl;
}
Problem p03069 (C++)

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

int N, ans;
char S[100100];
int titik[100100], pagar[100100];

int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> S[i];
    if (S[i] == '.') {
      titik[i] = titik[i - 1] + 1;
      pagar[i] = pagar[i - 1];
    } else {
      titik[i] = titik[i - 1];
      pagar[i] = pagar[i - 1] + 1;
    }
  }
  ans = N;
  for (int i = 0; i <= N; i++) {
    ans = min(ans, pagar[i] + titik[N] - titik[i]);
  }
  cout << ans << endl;
  return 0;
}

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

int N, ans;
char S[200100];
int titik[200100], pagar[200100];

int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> S[i];
    if (S[i] == '.') {
      titik[i] = titik[i - 1] + 1;
      pagar[i] = pagar[i - 1];
    } else {
      titik[i] = titik[i - 1];
      pagar[i] = pagar[i - 1] + 1;
    }
  }
  ans = N;
  for (int i = 0; i <= N; i++) {
    ans = min(ans, pagar[i] + titik[N] - titik[i]);
  }
  cout << ans << endl;
  return 0;
}
Problem p03069 (C++)

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

using namespace std;

typedef long long ll;

vector<int> x;
int c[100001];

int main(int, char **) {
  ll a, w = 0, b = 0, ans = 0;
  string s;
  cin >> a >> s;

  c[0] = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '#') {
      b++;
    } else {
      w++;
    }
    c[i + 1] = b;
  }
  ans = a - c[a];
  for (int i = 0; i <= s.length(); i++) {
    ll x = c[i] + (a - i) - (c[a] - c[i]);
    ans = min(ans, x);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

vector<int> x;
int c[200010];

int main(int, char **) {
  ll a, w = 0, b = 0, ans = 0;
  string s;
  cin >> a >> s;

  c[0] = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '#') {
      b++;
    } else {
      w++;
    }
    c[i + 1] = b;
  }
  ans = a - c[a];
  for (int i = 0; i <= s.length(); i++) {
    ll x = c[i] + (a - i) - (c[a] - c[i]);
    ans = min(ans, x);
  }
  cout << ans << endl;
  return 0;
}
Problem p03070 (C++)

Buggy submission (status: Time Limit Exceeded):
// written by NewbieChd
#include <cctype>
#include <cstdio>
#define BUF 1000000
using namespace std;
const int N = 301, M = 45001, yyb = 998244353;
char buf[BUF], *p1, *p2;
inline char getChar() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  register int f = 0;
  register char c;
  while (!isdigit(c = getChar())) {
  }
  do
    f = f * 10 + (c ^ 48);
  while (isdigit(c = getChar()));
  return f;
}
int a[N], f[N][M], g[N][M];
inline int power(int x, int y) {
  register int o = 1;
  for (; y; y >>= 1, x = 1ll * x * x % yyb)
    if (y & 1)
      o = 1ll * o * x % yyb;
  return o;
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("a.in", "r", stdin);
  // freopen("a.out", "w", stdout);
#endif
  register int n = read(), i, j, sum = 0, ans = 0;
  for (i = 1; i <= n; ++i)
    sum += a[i] = read();
  sum /= 2, f[0][0] = g[0][0] = 1;
  for (i = 1; i <= n; ++i) {
    for (j = sum; j >= a[i]; --j)
      f[i][j] = (2ll * f[i - 1][j - a[i]] + f[i - 1][j]) % yyb,
      g[i][j] = (g[i - 1][j - a[i]] + g[i - 1][j]) % yyb;
    for (j = a[i] - 1; ~j; --j)
      f[i][j] = f[i - 1][j], g[i][j] = g[i - 1][j];
  }
  for (j = 1; j <= sum; ++j)
    ans = (-2ll * g[n][j] + f[n][j] + ans) % yyb;
  ans = (-3ll * power(2, n) + power(3, n) + 3 - 3ll * ans) % yyb,
  printf("%d\n", (ans + yyb) % yyb);
  return 0;
}


Fixed submission:
// written by NewbieChd
#include <cctype>
#include <cstdio>
#define BUF 1000000
using namespace std;
const int N = 301, M = 45001, yyb = 998244353;
char buf[BUF], *p1, *p2;
inline char getChar() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int read() {
  register int f = 0;
  register char c;
  while (!isdigit(c = getChar())) {
  }
  do
    f = f * 10 + (c ^ 48);
  while (isdigit(c = getChar()));
  return f;
}
int a[N], f[N][M], g[N][M];
inline int power(int x, int y) {
  register int o = 1;
  for (; y; y >>= 1, x = 1ll * x * x % yyb)
    if (y & 1)
      o = 1ll * o * x % yyb;
  return o;
}
int main() {
  register int n = read(), i, j, sum = 0, ans = 0;
  for (i = 1; i <= n; ++i)
    sum += a[i] = read();
  sum /= 2, f[0][0] = g[0][0] = 1;
  for (i = 1; i <= n; ++i) {
    for (j = sum; j >= a[i]; --j)
      f[i][j] = (2ll * f[i - 1][j - a[i]] + f[i - 1][j]) % yyb,
      g[i][j] = (g[i - 1][j - a[i]] + g[i - 1][j]) % yyb;
    for (j = a[i] - 1; ~j; --j)
      f[i][j] = f[i - 1][j], g[i][j] = g[i - 1][j];
  }
  for (j = 1; j <= sum; ++j)
    ans = (-2ll * g[n][j] + f[n][j] + ans) % yyb;
  ans = (-3ll * power(2, n) + power(3, n) + 3 - 3ll * ans) % yyb,
  printf("%d\n", (ans + yyb) % yyb);
  return 0;
}