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

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

int main() {
  string s;
  cin >> s;
  int n = s.size();

  string t;
  vi id;

  rep(i, n) {
    if (s[i] != 'x') {
      t.pb(s[i]);
      id.pb(i);
    }
  }

  string rt = t;
  reverse(ALL(rt));

  if (t != rt) {
    puts("-1");
    return 0;
  }

  vi vx;

  int la = -1;
  n = t.size();

  rep(i, n) {
    vx.pb(id[i] - la - 1);
    la = id[i];
  }

  vx.pb((int)s.size() - 1 - id[n - 1]);

  vi rvx = vx;
  reverse(ALL(rvx));

  int ret = 0;
  rep(i, (n + 1) / 2) ret += max(vx[i], rvx[i]) - min(vx[i], rvx[i]);

  cout << ret << endl;

  return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

int main() {
  string s;
  cin >> s;
  int n = s.size();

  string t;
  vi id;

  rep(i, n) {
    if (s[i] != 'x') {
      t.pb(s[i]);
      id.pb(i);
    }
  }

  string rt = t;
  reverse(ALL(rt));

  if (t != rt) {
    puts("-1");
    return 0;
  }

  vi vx;

  int la = -1;
  n = t.size();

  rep(i, n) {
    vx.pb(id[i] - la - 1);
    la = id[i];
  }

  if (n > 0)
    vx.pb((int)s.size() - 1 - id[n - 1]);

  vi rvx = vx;
  reverse(ALL(rvx));

  int ret = 0;
  rep(i, (n + 1) / 2) ret += max(vx[i], rvx[i]) - min(vx[i], rvx[i]);

  cout << ret << endl;

  return 0;
}
Problem p03569 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;

signed main() {
  string s;
  cin >> s;
  int n = s.size();
  string t;
  rep(i, 0, n) {
    if (s[i] != 'x')
      t = s[i] + t;
  }
  string t_r = t;
  reverse(t_r.begin(), t_r.end());
  if (t != t_r) {
    cout << "-1\n";
    return 0;
  }
  int ans = 0;
  int i = 0, j = n - 1;
  while (j - i > 0) {
    // cout << i << " " << j << "\n";
    if (s[i] != 'x' && s[j] != 'x') {
      j--, i++;
    } else if (s[i] != 'x') {
      j--;
      ans++;
    } else if (s[j] != 'x') {
      i++;
      ans++;
    }
  }
  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;

signed main() {
  string s;
  cin >> s;
  int n = s.size();
  string t;
  rep(i, 0, n) {
    if (s[i] != 'x')
      t = s[i] + t;
  }
  string t_r = t;
  reverse(t_r.begin(), t_r.end());
  if (t != t_r) {
    cout << "-1\n";
    return 0;
  }
  int ans = 0;
  int i = 0, j = n - 1;
  while (j - i > 0) {
    // cout << i << " " << j << "\n";
    if (s[i] != 'x' && s[j] != 'x') {
      j--, i++;
    } else if (s[i] != 'x') {
      j--;
      ans++;
    } else if (s[j] != 'x') {
      i++;
      ans++;
    } else {
      j--, i++;
    }
  }
  cout << ans << "\n";
}
Problem p03569 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define INF (1LL << 50)
#define MOD 1000000007

int main() {
  string S;
  cin >> S;
  // 両端から見ていく
  int l = 0;
  int r = S.size() - 1;
  ll ans = 0;
  while (r - l > 0) {
    if (S[l] == S[r]) {
      l++;
      r--;
      continue;
    }
    if (S[l] == 'x') {
      ans++;
      l++;
    } else if (S[r] == 'x') {
      ans++;
      r--;
    } else {
      cout << -1 << endl;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define INF (1LL << 50)
#define MOD 1000000007

int main() {
  string S;
  cin >> S;
  // 両端から見ていく
  int l = 0;
  int r = S.size() - 1;
  ll ans = 0;
  while (r - l > 0) {
    if (S[l] == S[r]) {
      l++;
      r--;
      continue;
    }
    if (S[l] == 'x') {
      ans++;
      l++;
    } else if (S[r] == 'x') {
      ans++;
      r--;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03569 (C++)

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

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

  string a, b;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'x')
      continue;
    a += s[i];
    b += s[i];
  }

  reverse(b.begin(), b.end());

  if (a != b) {
    cout << -1 << endl;
    return 0;
  }

  int i = 0, j = s.size() - 1;
  int ans = 0;
  while (i != j) {
    if (s[i] == s[j]) {
      i++;
      j--;
      continue;
    }
    if (s[i] == 'x') {
      while (s[i] == 'x') {
        i++;
        ans++;
      }
    } else {
      while (s[j] == 'x') {
        j--;
        ans++;
      }
    }
  }

  cout << ans << endl;
}


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

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

  string a, b;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'x')
      continue;
    a += s[i];
    b += s[i];
  }

  reverse(b.begin(), b.end());

  if (a != b) {
    cout << -1 << endl;
    return 0;
  }

  int i = 0, j = s.size() - 1;
  int ans = 0;
  while (i < j) {
    if (s[i] == s[j]) {
      i++;
      j--;
      continue;
    }
    if (s[i] == 'x') {
      while (s[i] == 'x') {
        i++;
        ans++;
      }
    } else {
      while (s[j] == 'x') {
        j--;
        ans++;
      }
    }
  }

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

Buggy submission (status: Runtime Error):

// C - Inserting 'x'

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

  string t = "";
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != 'x')
      t.push_back(s[i]);
  }
  auto rev_t = t;
  reverse(rev_t.begin(), rev_t.end());
  if (t != rev_t) {
    cout << -1 << endl;
    return 0;
  }

  vector<int> cnt;

  int c = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'x')
      c++;
    else {
      cnt.push_back(c);
      c = 0;
    }
  }
  cnt.push_back(c);

  auto rev_cnt = cnt;
  reverse(rev_cnt.begin(), rev_cnt.end());

  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    ans += abs(cnt[i] - rev_cnt[i]);
  }
  ans /= 2;

  cout << ans << endl;

  return 0;
}

Fixed submission:

// C - Inserting 'x'

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

  string t = "";
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != 'x')
      t.push_back(s[i]);
  }
  auto rev_t = t;
  reverse(rev_t.begin(), rev_t.end());
  if (t != rev_t) {
    cout << -1 << endl;
    return 0;
  }

  vector<int> cnt;

  int c = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'x')
      c++;
    else {
      cnt.push_back(c);
      c = 0;
    }
  }
  cnt.push_back(c);

  auto rev_cnt = cnt;
  reverse(rev_cnt.begin(), rev_cnt.end());

  int ans = 0;
  for (int i = 0; i < cnt.size(); i++) {
    ans += abs(cnt[i] - rev_cnt[i]);
  }
  ans /= 2;

  cout << ans << endl;

  return 0;
}
Problem p03569 (Python)

Buggy submission (status: Runtime Error):
s = input()
sr = s[-1::-1]
left = 0
right = 0
ans = 0
while 1:
    if left + right == len(s) - 1:
        break
    if s[left] != sr[right]:
        if s[left] == "x":
            left += 1
        elif sr[right] == "x":
            right += 1
        else:
            print(-1)
            exit()
        ans += 1
    elif s[left] == sr[right]:
        left += 1
        right += 1

print(ans)


Fixed submission:
s = input()
sr = s[-1::-1]
left = 0
right = 0
ans = 0
while 1:
    if left + right >= len(s) - 1:
        break
    if s[left] != sr[right]:
        if s[left] == "x":
            left += 1
        elif sr[right] == "x":
            right += 1
        else:
            print(-1)
            exit()
        ans += 1
    elif s[left] == sr[right]:
        left += 1
        right += 1

print(ans)
Problem p03569 (Python)

Buggy submission (status: Runtime Error):
import sys

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    s = input()
    n = len(s)
    ss = "".join(s.replace("x", ""))
    if ss != ss[::-1]:
        print(-1)
        exit()

    res = 0
    left = 0
    right = n - 1
    while left != right:
        if s[left] == s[right]:
            left += 1
            right -= 1
        else:
            if s[left] == "x":
                left += 1
            else:
                right -= 1
            res += 1
    print(res)


if __name__ == "__main__":
    resolve()


Fixed submission:
import sys

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    s = input()
    n = len(s)
    ss = "".join(s.replace("x", ""))
    if ss != ss[::-1]:
        print(-1)
        exit()

    res = 0
    left = 0
    right = n - 1
    while left <= right:
        if s[left] == s[right]:
            left += 1
            right -= 1
        else:
            if s[left] == "x":
                left += 1
            else:
                right -= 1
            res += 1
    print(res)


if __name__ == "__main__":
    resolve()
Problem p03569 (C++)

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

string dat;
vi V;

bool check() {
  int cur1 = sz(V) / 2 - 1;
  int cur2 = (sz(V) & 1 ? cur1 + 2 : cur1 + 1);

  while (cur1 != -1) {
    if (dat[V[cur1]] != dat[V[cur2]])
      return 0;
    --cur1;
    ++cur2;
  }
  return 1;
}

int get_ans() {
  int ret = 0;
  int cur1 = sz(V) / 2 - 1;
  int cur2 = (sz(V) & 1 ? cur1 + 2 : cur1 + 1);
  while (cur1 != -1) {
    int len1 = V[cur1 + 1] - V[cur1];
    int len2 = V[cur2] - V[cur2 - 1];
    ret += abs(len1 - len2);
    --cur1;
    ++cur2;
  }
  ret += abs(V[cur1 + 1] - ((int)dat.length() - 1 - V[cur2 - 1]));
  return ret;
}

int main() {
  cin >> dat;
  for (int i = 0; i < (int)dat.length(); ++i) {
    if (dat[i] != 'x') {
      V.push_back(i);
    }
  }

  if (!check()) {
    printf("-1\n");
    return 0;
  }

  printf("%d\n", get_ans());
  return 0;
}

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

string dat;
vi V;

bool check() {
  int cur1 = sz(V) / 2 - 1;
  int cur2 = (sz(V) & 1 ? cur1 + 2 : cur1 + 1);

  while (cur1 != -1) {
    if (dat[V[cur1]] != dat[V[cur2]])
      return 0;
    --cur1;
    ++cur2;
  }
  return 1;
}

int get_ans() {
  int ret = 0;
  int cur1 = sz(V) / 2 - 1;
  int cur2 = (sz(V) & 1 ? cur1 + 2 : cur1 + 1);
  while (cur1 != -1) {
    int len1 = V[cur1 + 1] - V[cur1];
    int len2 = V[cur2] - V[cur2 - 1];
    ret += abs(len1 - len2);
    --cur1;
    ++cur2;
  }
  ret += abs(V[cur1 + 1] - ((int)dat.length() - 1 - V[cur2 - 1]));
  return ret;
}

int main() {
  cin >> dat;
  for (int i = 0; i < (int)dat.length(); ++i) {
    if (dat[i] != 'x') {
      V.push_back(i);
    }
  }

  if (V.empty()) {
    printf("0\n");
    return 0;
  }

  if (!check()) {
    printf("-1\n");
    return 0;
  }

  printf("%d\n", get_ans());
  return 0;
}
Problem p03569 (Python)

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

s = deque(input())

ans = 0
while len(s) > 1:
    if s[0] == s[-1]:
        s.pop()
        s.popleft()
    elif s[0] == "x":
        s.popleft()
        ans += 1
    elif s[-1] == "x":
        s.pop()
        ans += 1
    elif s[0] != s[1]:
        print(-1)
        break
else:
    print(ans)


Fixed submission:
from collections import deque

s = deque(input())

ans = 0
while len(s) > 1:
    if s[0] == s[-1]:
        s.pop()
        s.popleft()
    elif s[0] == "x":
        s.popleft()
        ans += 1
    elif s[-1] == "x":
        s.pop()
        ans += 1
    else:
        print(-1)
        break
else:
    print(ans)
Problem p03569 (Python)

Buggy submission (status: Runtime Error):
s = list(input())
l, r = 0, len(s) - 1
ans = 0
while l != r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        if s[l] == "x":
            l += 1
            ans += 1
        elif s[r] == "x":
            r -= 1
            ans += 1
        else:
            ans = -1
            break

print(ans)


Fixed submission:
s = list(input())
l, r = 0, len(s) - 1
ans = 0
while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        if s[l] == "x":
            l += 1
            ans += 1
        elif s[r] == "x":
            r -= 1
            ans += 1
        else:
            ans = -1
            break

print(ans)
Problem p03569 (Python)

Buggy submission (status: Time Limit Exceeded):
value = list(input())
res = 0
while len(value) != 1 and len(value) != 0:
    zero = value[0]
    one = value[-1]
    if zero == one:
        value.pop(0)
        value.pop()
    else:
        if zero != "x" and one != "x":
            res = -1
            break
        value.extend("x") if zero == "x" else value.insert(0, "x")
        value.pop(0)
        value.pop()
        res += 1
print(res)


Fixed submission:
s = input()
ns = s.replace("x", "")
if s == s[::-1]:
    print(0)
elif ns != ns[::-1]:
    print(-1)
else:
    cnt = 0
    i = 0
    j = len(s) - 1
    while i < j:
        if s[i] == "x" and s[j] != "x":
            cnt += 1
            j += 1
        elif s[i] != "x" and s[j] == "x":
            cnt += 1
            i -= 1
        i += 1
        j -= 1
    print(cnt)
Problem p03569 (Python)

Buggy submission (status: Runtime Error):
S = list(input())
i, j = 0, len(S) - 1
ans = 0

while i != j:
    if S[i] == S[j]:
        i += 1
        j -= 1

    elif S[i] == "x":
        i += 1
        ans += 1

    elif S[j] == "x":
        j -= 1
        ans += 1

    else:
        print("-1")
        break

else:
    print(ans)


Fixed submission:
S = list(input())
i, j = 0, len(S) - 1
ans = 0

while i < j:
    if S[i] == S[j]:
        i += 1
        j -= 1

    elif S[i] == "x":
        i += 1
        ans += 1

    elif S[j] == "x":
        j -= 1
        ans += 1

    else:
        print("-1")
        break

else:
    print(ans)
Problem p03569 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main(void) {

  string s;
  cin >> s;
  vector<char> test;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] != 'x')
      test.push_back(s[i]);
  }

  // for(int i=0;i<test.size();i++){
  //     cout<<test[i];
  // }

  int i = 0;
  int j = test.size() - 1;
  while (i != j) {
    if (test[i] == test[j]) {
      i++;
      j--;
      if (i > j)
        break;
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }

  i = 0;
  j = s.size() - 1;
  int count = 0;

  while (i != j) {
    if (j < i)
      break;
    if (s[i] == s[j]) {
      i++;
      j--;
    } else if (s[i] == 'x') {
      count++;
      i++;
    } else {
      count++;
      j--;
    }
  }

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

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main(void) {

  string s;
  cin >> s;
  vector<char> test;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] != 'x')
      test.push_back(s[i]);
  }

  // for(int i=0;i<test.size();i++){
  //     cout<<test[i];
  // }

  int i = 0;
  int j = test.size() - 1;
  while (i != j && j >= 0) {
    if (test[i] == test[j]) {
      i++;
      j--;
      if (i > j)
        break;
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }

  i = 0;
  j = s.size() - 1;
  int count = 0;

  while (i != j) {
    if (j < i)
      break;
    if (s[i] == s[j]) {
      i++;
      j--;
    } else if (s[i] == 'x') {
      count++;
      i++;
    } else {
      count++;
      j--;
    }
  }

  cout << count << endl;
  return 0;
}
Problem p03569 (Python)

Buggy submission (status: Runtime Error):
s = input()
count = 0
if len(set(s)) == 1:
    print(0)
    exit()
left = 0
right = len(s) - 1

ans = 0
while True:
    if (s[left] == "x" and s[right] == "x") or s[left] == s[right]:
        left += 1
        right -= 1
    elif s[left] == "x" and s[right] != "x":
        ans += 1
        left += 1
    elif s[left] != "x" and s[right] == "x":
        ans += 1
        right -= 1
    elif s[left] != "x" and s[right] != "x" and s[left] != s[right]:
        print(-1)
        exit()
    if left == right:
        break
print(ans)


Fixed submission:
s = input()
count = 0
if len(set(s)) == 1:
    print(0)
    exit()
left = 0
right = len(s) - 1

ans = 0
while True:
    if (s[left] == "x" and s[right] == "x") or s[left] == s[right]:
        left += 1
        right -= 1
    elif s[left] == "x" and s[right] != "x":
        ans += 1
        left += 1
    elif s[left] != "x" and s[right] == "x":
        ans += 1
        right -= 1
    elif s[left] != "x" and s[right] != "x" and s[left] != s[right]:
        print(-1)
        exit()
    if right <= left:
        break
print(ans)
Problem p03570 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
using namespace std;
// std::ios::sync_with_stdio(false);
typedef long long LL;
const int N = 150000;
const int M = 12;
const int INF = 0x3f3f3f3f;
const LL MOD = 1e9 + 7;
const double Pi = acos(-1);
int n, m;
char s[N];
int dp[1 << 26];
int main() {
  while (~scanf("%s", s)) {
    memset(dp, INF, sizeof dp);
    int tmp = 0;
    dp[0] = 0;
    int l = strlen(s);
    for (int i = 0; i < l; i++) {
      tmp ^= 1 << (s[i] - 'a');
      for (int j = 0; j < 26; j++)
        dp[tmp] = min(dp[tmp], dp[tmp ^ (1 << j)] + 1);
    }
    printf("%d\n", max(1, dp[tmp]));
  }
  return 0;
}

/*

aabxyyzz
byebye
abcdefghijklmnopqrstuvwxyz
abcabcxabcx

*/

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
using namespace std;
// std::ios::sync_with_stdio(false);
typedef long long LL;
const int N = 250000;
const int M = 12;
const int INF = 0x3f3f3f3f;
const LL MOD = 1e9 + 7;
const double Pi = acos(-1);
int n, m;
char s[N];
int dp[1 << 26];
int main() {
  while (~scanf("%s", s)) {
    memset(dp, INF, sizeof dp);
    int tmp = 0;
    dp[0] = 0;
    int l = strlen(s);
    for (int i = 0; i < l; i++) {
      tmp ^= 1 << (s[i] - 'a');
      for (int j = 0; j < 26; j++)
        dp[tmp] = min(dp[tmp], dp[tmp ^ (1 << j)] + 1);
    }
    printf("%d\n", max(1, dp[tmp]));
  }
  return 0;
}

/*

aabxyyzz
byebye
abcdefghijklmnopqrstuvwxyz
abcabcxabcx

*/
Problem p03570 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define maxn (1 << 27) + 1
#define maxm (int)2e5 + 2
int dp[maxn];
char s[maxm];
#define INF 0x7f7f7f
int main() {
  scanf("%s", s);
  int n = strlen(s);
  memset(dp, INF, sizeof(dp));
  long long now = 0;
  dp[now] = 0;
  for (int i = 0; i < n; i++) {
    now ^= (1 << (s[i] - 'a'));
    for (int j = 0; j <= 25; j++)
      if ((now ^ (1 << j)) != now)
        dp[now] = min(dp[now], dp[now ^ (1 << j)] + 1);
  }
  if (now == 0)
    dp[now] = 1;
  printf("%d\n", dp[now]);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define maxn (1 << 26) + 1
#define maxm (int)2e5 + 2
int dp[maxn];
char s[maxm];
#define INF 0x7f7f7f
int main() {
  scanf("%s", s);
  int n = strlen(s);
  memset(dp, INF, sizeof(dp));
  long long now = 0;
  dp[now] = 0;
  for (int i = 0; i < n; i++) {
    now ^= (1 << (s[i] - 'a'));
    for (int j = 0; j <= 25; j++)
      if ((now ^ (1 << j)) != now)
        dp[now] = min(dp[now], dp[now ^ (1 << j)] + 1);
  }
  if (now == 0)
    dp[now] = 1;
  printf("%d\n", dp[now]);
}
Problem p03570 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define forn(i, n) for (ll i = 0; i < (ll)n; ++i)
#define sz(a) static_cast<int>(a.size())

char buff[(int)2e6 + 17];
const ll inf = (ll)1e9 + 7ll;

const int maxn = (int)1e5 + 17;

int n;
string s;
int ps[maxn];

bool read() {
  if (scanf("%s", buff) != 1)
    return false;

  return true;
}

void solve() {
  s = buff;
  n = sz(s);
  s = "#" + s;
  unordered_map<int, int> dp;
  dp.rehash(2281488);
  dp[0] = 0;

  for (int i = 1; i <= n; ++i) {
    ps[i] = ps[i - 1] ^ (1 << (s[i] - 'a'));

    if (!dp.count(ps[i]))
      dp[ps[i]] = inf;

    for (int j = 0; j < 26; ++j) {
      auto t = ps[i] ^ (1 << j);

      if (dp.count(t))
        dp[ps[i]] = min(dp[ps[i]], dp[t] + 1);
    }
  }

  printf("%d\n", max(1, dp[ps[n]]));
}

int main() {
#if SEREZHKA
  freopen("file.in", "r", stdin);
#endif

  while (read())
    solve();

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define forn(i, n) for (ll i = 0; i < (ll)n; ++i)
#define sz(a) static_cast<int>(a.size())

char buff[(int)2e6 + 17];
const ll inf = (ll)1e9 + 7ll;

const int maxn = (int)2e5 + 17;

int n;
string s;
int ps[maxn];

bool read() {
  if (scanf("%s", buff) != 1)
    return false;

  return true;
}

void solve() {
  s = buff;
  n = sz(s);
  s = "#" + s;
  unordered_map<int, int> dp;
  dp.rehash(2281488);
  dp[0] = 0;

  for (int i = 1; i <= n; ++i) {
    ps[i] = ps[i - 1] ^ (1 << (s[i] - 'a'));

    if (!dp.count(ps[i]))
      dp[ps[i]] = inf;

    for (int j = 0; j < 26; ++j) {
      auto t = ps[i] ^ (1 << j);

      if (dp.count(t))
        dp[ps[i]] = min(dp[ps[i]], dp[t] + 1);
    }
  }

  printf("%d\n", max(1, dp[ps[n]]));
}

int main() {
#if SEREZHKA
  freopen("file.in", "r", stdin);
#endif

  while (read())
    solve();

  return 0;
}
Problem p03570 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
const int mod = 1000000007, MAX = 200003, INF = 1 << 30;

int dp[MAX];

int main() {

  string S;
  cin >> S;
  int N = S.size();

  int bit = 0;
  vector<int> data(N + 1, 0);
  map<int, vector<int>> MA;
  for (int i = 0; i < N; i++) {
    bit ^= (1 << (S[i] - 'a'));
    MA[bit].push_back(i + 1);
    data[i + 1] = bit;
  }
  for (int i = 1; i <= N; i++)
    dp[i] = INF;
  dp[0] = 0;

  for (int i = 0; i < N; i++) {
    if (dp[i] >= INF)
      continue;
    for (auto to : MA[data[i]])
      dp[to] = min(dp[to], dp[i] + 1);
    // if(i<MA[data[i]]) dp[MA[data[i]]]=min(dp[MA[data[i]]],dp[i]+1);

    for (int j = 0; j < 26; j++) {
      data[i] ^= (1 << j);
      // if(i==0) cout<<j<<" "<<data[i]<<endl;
      // if(i<MA[data[i]]) dp[MA[data[i]]]=min(dp[MA[data[i]]],dp[i]+1);
      for (auto to : MA[data[i]])
        dp[to] = min(dp[to], dp[i] + 1);
      data[i] ^= (1 << j);
    }
  }

  cout << dp[N] << endl;

  // for(int i=0;i<=N;i++) cout<<i<<" "<<data[i]<<" "<<dp[i]<<endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
const int mod = 1000000007, MAX = 200003, INF = 1 << 30;

int dp[MAX];

int main() {

  string S;
  cin >> S;
  int N = S.size();

  int bit = 0;
  vector<int> data(N + 1, 0);
  map<int, vector<int>> MA;
  for (int i = 0; i < N; i++) {
    bit ^= (1 << (S[i] - 'a'));
    if (MA[bit].size() == 2)
      MA[bit].pop_back();
    MA[bit].push_back(i + 1);
    data[i + 1] = bit;
  }
  for (int i = 1; i <= N; i++)
    dp[i] = INF;
  dp[0] = 0;

  for (int i = 0; i < N; i++) {
    if (dp[i] >= INF)
      continue;
    for (auto to : MA[data[i]])
      dp[to] = min(dp[to], dp[i] + 1);
    // if(i<MA[data[i]]) dp[MA[data[i]]]=min(dp[MA[data[i]]],dp[i]+1);

    for (int j = 0; j < 26; j++) {
      data[i] ^= (1 << j);
      // if(i==0) cout<<j<<" "<<data[i]<<endl;
      // if(i<MA[data[i]]) dp[MA[data[i]]]=min(dp[MA[data[i]]],dp[i]+1);
      for (auto to : MA[data[i]])
        dp[to] = min(dp[to], dp[i] + 1);
      data[i] ^= (1 << j);
    }
  }

  cout << dp[N] << endl;

  // for(int i=0;i<=N;i++) cout<<i<<" "<<data[i]<<" "<<dp[i]<<endl;
}
Problem p03570 (C++)

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

using namespace std;

const int MAXN = (int)2e5;
const int INF = (int)1e9;

int sp[MAXN + 1][26];

string str;

map<int, int> dp;

inline int check(int x) {
  if (dp[x] == 0) {
    if (x == 0)
      return 0;
    return INF;
  }
  return dp[x];
}

int main() {
  // ifstream cin("A.in");
  // ofstream cout("A.out");
  int i, j;
  ios::sync_with_stdio(false);
  cin >> str;
  int n = str.size();
  str = " " + str;
  for (i = 1; i <= n; i++) {
    for (j = 0; j < 26; j++)
      sp[i][j] = sp[i - 1][j];
    sp[i][str[i] - 'a']++;
    sp[i][str[i] - 'a'] %= 2;
  }
  int ans = MAXN + 1;
  for (i = 1; i <= n; i++) {
    int cnf = 0;
    for (j = 0; j < 26; j++)
      cnf += (1 << j) * sp[i][j];
    int val = check(cnf);
    for (j = 0; j < 26; j++)
      val = min(val, check(cnf ^ (1 << j)) + 1);
    dp[cnf] = val;
    //  printf("%d\n" ,val);
    if (i == n) {
      if (val == 0)
        val = 1;
      cout << val;
      return 0;
    }
  }
  // cin.close();
  // cout.close();
  return 0;
}


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

using namespace std;

const int MAXN = (int)2e5;
const int INF = (int)1e9;

int sp[MAXN + 1][26];

string str;

unordered_map<int, int> dp;

inline int check(int x) {
  if (dp[x] == 0) {
    if (x == 0)
      return 0;
    return INF;
  }
  return dp[x];
}

int main() {
  // ifstream cin("A.in");
  // ofstream cout("A.out");
  int i, j;
  ios::sync_with_stdio(false);
  cin >> str;
  int n = str.size();
  str = " " + str;
  for (i = 1; i <= n; i++) {
    for (j = 0; j < 26; j++)
      sp[i][j] = sp[i - 1][j];
    sp[i][str[i] - 'a']++;
    sp[i][str[i] - 'a'] %= 2;
  }
  int ans = MAXN + 1;
  for (i = 1; i <= n; i++) {
    int cnf = 0;
    for (j = 0; j < 26; j++)
      cnf += (1 << j) * sp[i][j];
    int val = check(cnf);
    for (j = 0; j < 26; j++)
      val = min(val, check(cnf ^ (1 << j)) + 1);
    dp[cnf] = val;
    //  printf("%d\n" ,val);
    if (i == n) {
      if (val == 0)
        val = 1;
      cout << val;
      return 0;
    }
  }
  // cin.close();
  // cout.close();
  return 0;
}
Problem p03570 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

string S, str[1000000];
bitset<26> bi = {}, B[1000000] = {};
LL dp[1 << 26];
char c;
int main() {
  cin >> S;
  for (LL i = 0; i < S.size(); i++) {
    if (i > 0)
      B[i] = B[i - 1];
    B[i][S[i] - 'a'].flip();
  }
  for (LL i = 0; i < (1 << 26); i++)
    dp[i] = INF;
  dp[0] = 0;
  for (LL i = 0; i < S.size(); i++) {
    LL BB = B[i].to_ullong();
    if (B[i].count() < 2) {
      dp[BB] = 1;
      continue;
    }
    for (int j = 0; j < 26; j++) {
      dp[BB] = min(dp[BB ^ (1 << j)] + 1, dp[BB]);
    }
  }
  LL Bi = B[S.size() - 1].to_ullong();
  cout << dp[Bi] << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

string S;
bitset<26> B[1000000] = {};
int dp[1 << 26];
int main() {
  cin >> S;
  for (LL i = 0; i < S.size(); i++) {
    if (i > 0)
      B[i] = B[i - 1];
    B[i][S[i] - 'a'].flip();
  }
  for (LL i = 0; i < (1 << 26); i++)
    dp[i] = INF;
  dp[0] = 0;
  for (LL i = 0; i < S.size(); i++) {
    LL BB = B[i].to_ullong();
    if (B[i].count() < 2) {
      dp[BB] = 1;
      continue;
    }
    for (int j = 0; j < 26; j++) {
      dp[BB] = min(dp[BB ^ (1 << j)] + 1, dp[BB]);
    }
  }
  LL Bi = B[S.size() - 1].to_ullong();
  cout << dp[Bi] << endl;
  return 0;
}
Problem p03570 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int maxn = 1e5;
const int inf = 1e6;
map<int, int> mp;
char s[maxn + 10];
int f[maxn + 10];
int main() {
  // freopen("in","r",stdin);
  scanf("%s", s);
  int n = strlen(s);
  mp[0] = 0;
  int state = 0;
  for (int i = 0; i < n; i++) {
    state ^= 1 << (s[i] - 'a');
    f[i] = inf;
    for (int j = 0; j < 26; j++)
      if (mp.find(state ^ (1 << j)) != mp.end())
        f[i] = min(f[i], mp[state ^ (1 << j)] + 1);
    if (mp.find(state) != mp.end())
      f[i] = min(f[i], mp[state] + 1);
    if (mp.find(state) == mp.end())
      mp[state] = f[i];
    else if (mp[state] > f[i])
      mp[state] = f[i];
  }
  printf("%d\n", f[n - 1]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int maxn = 2e5;
const int inf = 1e6;
map<int, int> mp;
char s[maxn + 10];
int f[maxn + 10];
int main() {
  // freopen("in","r",stdin);
  scanf("%s", s);
  int n = strlen(s);
  mp[0] = 0;
  int state = 0;
  for (int i = 0; i < n; i++) {
    state ^= 1 << (s[i] - 'a');
    f[i] = inf;
    for (int j = 0; j < 26; j++)
      if (mp.find(state ^ (1 << j)) != mp.end())
        f[i] = min(f[i], mp[state ^ (1 << j)] + 1);
    if (mp.find(state) != mp.end())
      f[i] = min(f[i], mp[state] + 1);
    if (mp.find(state) == mp.end())
      mp[state] = f[i];
    else if (mp[state] > f[i])
      mp[state] = f[i];
  }
  printf("%d\n", f[n - 1]);
  return 0;
}
Problem p03570 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#define ll long long
using namespace std;
int read() {
  char c;
  int s = 0, t = 1;
  while (!isdigit(c = getchar()))
    if (c == '-')
      t = -1;
  do {
    s = s * 10 + c - '0';
  } while (isdigit(c = getchar()));
  return s * t;
}
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a < b ? b : a; }
int abs(int x) { return x > 0 ? x : -x; }
void mins(int &a, int b) {
  if (a > b)
    a = b;
}
void maxs(int &a, int b) {
  if (a < b)
    a = b;
}
// void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
/*------------------------------------------------------------*/
const int inf = 0x3f3f3f3f, maxn = 100010, maxN = 70000010;

int n, p[maxN], f[maxn], sum;
char s[maxn];

int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  f[0] = 0;
  memset(p, 0x3f, sizeof(p));
  p[0] = 0;
  for (int i = 1; i <= n; i++) {
    int x = 1 << (s[i] - 'a');
    sum ^= x;
    f[i] = inf;
    f[i] = min(f[i], p[sum] + 1);
    for (int j = 0; j < 26; j++)
      f[i] = min(f[i], p[sum ^ (1 << j)] + 1);
    p[sum] = min(p[sum], f[i]);
    // printf("p[%d]=%d\n",sum,p[sum]);
  }
  printf("%d", f[n]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#define ll long long
using namespace std;
int read() {
  char c;
  int s = 0, t = 1;
  while (!isdigit(c = getchar()))
    if (c == '-')
      t = -1;
  do {
    s = s * 10 + c - '0';
  } while (isdigit(c = getchar()));
  return s * t;
}
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a < b ? b : a; }
int abs(int x) { return x > 0 ? x : -x; }
void mins(int &a, int b) {
  if (a > b)
    a = b;
}
void maxs(int &a, int b) {
  if (a < b)
    a = b;
}
// void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
/*------------------------------------------------------------*/
const int inf = 0x3f3f3f3f, maxn = 200010, maxN = 70000010;

int n, p[maxN], f[maxn], sum;
char s[maxn];

int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  f[0] = 0;
  memset(p, 0x3f, sizeof(p));
  p[0] = 0;
  for (int i = 1; i <= n; i++) {
    int x = 1 << (s[i] - 'a');
    sum ^= x;
    f[i] = inf;
    f[i] = min(f[i], p[sum] + 1);
    for (int j = 0; j < 26; j++)
      f[i] = min(f[i], p[sum ^ (1 << j)] + 1);
    p[sum] = min(p[sum], f[i]);
    // printf("p[%d]=%d\n",sum,p[sum]);
  }
  printf("%d", f[n]);
  return 0;
}
Problem p03570 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int dp[1 << 26];
int val[214514];
int ans[214514];
signed main() {
  string str;
  cin >> str;
  int n = str.size();
  for (int i = 1; i <= n; i++) {
    int cur = str[i - 1] - 'a';
    val[i] = val[i - 1] ^ (1 << cur);
  }
  for (int i = 0; i < (1 << 26); i++) {
    dp[i] = inf;
  }
  dp[0] = 0;
  for (int i = 1; i <= n; i++) {
    vector<int> v;
    int cur = val[i];
    v.pb(dp[cur]);
    for (int j = 0; j < 26; j++) {
      v.pb(dp[cur ^ (1 << j)]);
    }
    sort(v.begin(), v.end());
    ans[i] = v[0] + 1;
    // cout<<ans[i]<<endl;
    dp[cur] = min(dp[cur], ans[i]);
  }
  cout << ans[n] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int dp[1 << 26];
int val[214514];
int ans[214514];
signed main() {
  string str;
  cin >> str;
  int n = str.size();
  for (int i = 1; i <= n; i++) {
    int cur = str[i - 1] - 'a';
    val[i] = val[i - 1] ^ (1 << cur);
  }
  for (int i = 0; i < (1 << 26); i++) {
    dp[i] = inf;
  }
  dp[0] = 0;
  for (int i = 1; i <= n; i++) {
    vector<int> v;
    int cur = val[i];
    v.pb(dp[cur]);
    for (int j = 0; j < 26; j++) {
      v.pb(dp[cur ^ (1 << j)]);
    }
    sort(v.begin(), v.end());
    ans[i] = v[0] + 1;
    // cout<<ans[i]<<endl;
    dp[cur] = min(dp[cur], ans[i]);
  }
  cout << ans[n] << endl;
  return 0;
}
Problem p03570 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int n, i, j, f[1 << 27], ans, c[212345];
string s;
int main() {
  cin >> s;
  s = " " + s;
  n = s.size();
  for (i = 1; i < n; i++) {
    c[i] = c[i - 1] ^ (1 << (s[i] - 'a'));
  }
  if (!c[n - 1]) {
    cout << "1\n";
    return 0;
  }
  memset(f, 50, sizeof(f));
  f[0] = 0;
  for (i = 1; i < n; i++) {
    ans = n + n + n + n + 345;
    for (j = 0; j < 26; j++) {
      ans = min(ans, f[c[i] ^ (1 << j)] + 1);
    }
    f[c[i]] = min(f[c[i]], ans);
  }
  cout << f[c[n - 1]] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int n, i, j, f[(1 << 26) + 5], ans, c[212345];
string s;
int main() {
  cin >> s;
  s = " " + s;
  n = s.size();
  for (i = 1; i < n; i++) {
    c[i] = c[i - 1] ^ (1 << (s[i] - 'a'));
  }
  if (!c[n - 1]) {
    cout << "1\n";
    return 0;
  }
  memset(f, 50, sizeof(f));
  f[0] = 0;
  for (i = 1; i < n; i++) {
    ans = n + n + n + n + 345;
    for (j = 0; j < 26; j++) {
      ans = min(ans, f[c[i] ^ (1 << j)] + 1);
    }
    f[c[i]] = min(f[c[i]], ans);
  }
  cout << f[c[n - 1]] << endl;
  return 0;
}
Problem p03570 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-10
// #define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template <class T> void read(T &res) {
  res = 0;
  T f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  res *= f;
}
template <class T> void out(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x >= 10) {
    out(x / 10);
  }
  putchar('0' + x % 10);
}
char s[MAXN];
int sum[MAXN], N;
int dp[MAXN];
map<int, int> zz;
void Init() {
  scanf("%s", s + 1);
  N = strlen(s + 1);
  for (int i = 1; i <= N; ++i) {
    sum[i] = sum[i - 1];
    sum[i] ^= (1 << s[i] - 'a');
  }
}
void Solve() {
  zz[0] = 0;
  for (int i = 1; i <= N; ++i) {
    dp[i] = i;
    if (zz.count(sum[i]))
      dp[i] = min(dp[i], zz[sum[i]] + 1);
    for (int j = 0; j < 26; ++j) {
      if (zz.count(sum[i] ^ (1 << j)))
        dp[i] = min(dp[i], zz[sum[i] ^ (1 << j)] + 1);
    }
    if (!zz.count(sum[i]))
      zz[sum[i]] = dp[i];
    else
      zz[sum[i]] = min(zz[sum[i]], dp[i]);
  }
  out(dp[N]);
  enter;
}
int main() {
#ifdef ivorysi
  freopen("f1.in", "r", stdin);
#endif
  Init();
  Solve();
}


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-10
// #define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template <class T> void read(T &res) {
  res = 0;
  T f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  res *= f;
}
template <class T> void out(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x >= 10) {
    out(x / 10);
  }
  putchar('0' + x % 10);
}
char s[MAXN];
int sum[MAXN], N;
int dp[MAXN];
map<int, int> zz;
void Init() {
  scanf("%s", s + 1);
  N = strlen(s + 1);
  for (int i = 1; i <= N; ++i) {
    sum[i] = sum[i - 1];
    sum[i] ^= (1 << s[i] - 'a');
  }
}
void Solve() {
  zz[0] = 0;
  for (int i = 1; i <= N; ++i) {
    dp[i] = i;
    if (zz.count(sum[i]))
      dp[i] = min(dp[i], zz[sum[i]] + 1);
    for (int j = 0; j < 26; ++j) {
      if (zz.count(sum[i] ^ (1 << j)))
        dp[i] = min(dp[i], zz[sum[i] ^ (1 << j)] + 1);
    }
    if (!zz.count(sum[i]))
      zz[sum[i]] = dp[i];
    else
      zz[sum[i]] = min(zz[sum[i]], dp[i]);
  }
  out(dp[N]);
  enter;
}
int main() {
#ifdef ivorysi
  freopen("f1.in", "r", stdin);
#endif
  Init();
  Solve();
}
Problem p03570 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vpii vector<pair<int, int>>
#define gph map<int, vector<int>>
#define mp make_pair
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for (; i < (int)(n); i++)
#define debug(X)                                                               \
  { cout << #X << " = " << (X) << endl; }
#define printArr(A, n)                                                         \
  {                                                                            \
    cout << #A << " = ";                                                       \
    FOR(i, n) cout << A[i] << ' ';                                             \
    cout << endl;                                                              \
  }
using namespace std;
int m[(1 << 27)];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  memset(m, -1, sizeof m);
  string s;
  cin >> s;
  //    unordered_map<int, int> m;

  m[0] = 0;
  int xr = 0;
  FOR(i, s.length()) {
    xr ^= (1 << (s[i] - 'a'));
    int ans = 1e9;
    for (int bi = 0; bi < 26; bi++) {
      if (m[xr ^ (1 << bi)] != -1) {
        ans = min(ans, m[(xr ^ (1 << bi))] + 1);
      }
    }
    if (ans <= s.length()) {
      if (xr != 0)
        m[xr] = ans;
    }
  }
  if (xr == 0)
    cout << 1;
  else
    cout << m[xr];
}


Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vpii vector<pair<int, int>>
#define gph map<int, vector<int>>
#define mp make_pair
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for (; i < (int)(n); i++)
#define debug(X)                                                               \
  { cout << #X << " = " << (X) << endl; }
#define printArr(A, n)                                                         \
  {                                                                            \
    cout << #A << " = ";                                                       \
    FOR(i, n) cout << A[i] << ' ';                                             \
    cout << endl;                                                              \
  }
using namespace std;
int m[(1 << 26)];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  memset(m, -1, sizeof m);
  string s;
  cin >> s;
  //    unordered_map<int, int> m;

  m[0] = 0;
  int xr = 0;
  FOR(i, s.length()) {
    xr ^= (1 << (s[i] - 'a'));
    int ans = 1e9;
    for (int bi = 0; bi < 26; bi++) {
      if (m[xr ^ (1 << bi)] != -1) {
        ans = min(ans, m[(xr ^ (1 << bi))] + 1);
      }
    }
    if (ans <= s.length()) {
      if (xr != 0)
        m[xr] = ans;
    }
  }
  if (xr == 0)
    cout << 1;
  else
    cout << m[xr];
}
Problem p03570 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 50;
char a[maxn];
int f[maxn], sum[1 << 27];
int main() {
  scanf("%s", a + 1);
  int n = strlen(a + 1);
  memset(sum, 0x3f, sizeof(sum));
  int g = 0;
  f[0] = 0;
  sum[0] = 0;
  for (int i = 1; i <= n; ++i) {
    int x = 1 << (a[i] - 'a');
    g ^= x;
    f[i] = sum[g];
    for (int j = 0; j < 26; ++j)
      f[i] = min(sum[g ^ (1 << j)], f[i]);
    ++f[i];
    sum[g] = min(sum[g], f[i]);
  }
  cout << f[n] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 50;
char a[maxn];
int f[maxn], sum[1 << 26];
int main() {
  scanf("%s", a + 1);
  int n = strlen(a + 1);
  memset(sum, 0x3f, sizeof(sum));
  int g = 0;
  f[0] = 0;
  sum[0] = 0;
  for (int i = 1; i <= n; ++i) {
    int x = 1 << (a[i] - 'a');
    g ^= x;
    f[i] = sum[g];
    for (int j = 0; j < 26; ++j)
      f[i] = min(sum[g ^ (1 << j)], f[i]);
    ++f[i];
    sum[g] = min(sum[g], f[i]);
  }
  cout << f[n] << endl;
  return 0;
}
Problem p03570 (C++)

Buggy submission (status: Runtime Error):
/*
Author: CNYALI_LK
LANG: C++
PROG: Cf2017C_D.cpp
*/
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define all(x) x.begin(), x.end()
using namespace std;
const double eps = 1e-8;
const double PI = acos(-1.0);
typedef long long ll;
template <class T> int chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <class T> int chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <class T> T sqr(T a) { return a * a; }
template <class T> T mmin(T a, T b) { return a < b ? a : b; }
template <class T> T mmax(T a, T b) { return a > b ? a : b; }
template <class T> T aabs(T a) { return a < 0 ? -a : a; }
#define min mmin
#define max mmax
#define abs aabs
char s[102000];
int a[102000], f[102000], smn[70000000];
void js(int x) {
  int s = a[x];
  f[x] = smn[s] + 1;
  for (int i = 0; i < 26; ++i)
    chkmin(f[x], smn[s ^ (1 << i)] + 1);
  chkmin(smn[s], f[x]);
}
int main() {
#ifdef cnyali_lk
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  int n;
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1, t = 1 << 26; i < t; ++i)
    smn[i] = 0x3f3f3f3f;

  for (int i = 1; i <= n; ++i) {
    a[i] = a[i - 1] ^ (1 << (s[i] - 'a'));
    js(i);
  }
  printf("%d\n", f[n]);
  return 0;
}


Fixed submission:
/*
Author: CNYALI_LK
LANG: C++
PROG: Cf2017C_D.cpp
*/
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define all(x) x.begin(), x.end()
using namespace std;
const double eps = 1e-8;
const double PI = acos(-1.0);
typedef long long ll;
template <class T> int chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <class T> int chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <class T> T sqr(T a) { return a * a; }
template <class T> T mmin(T a, T b) { return a < b ? a : b; }
template <class T> T mmax(T a, T b) { return a > b ? a : b; }
template <class T> T aabs(T a) { return a < 0 ? -a : a; }
#define min mmin
#define max mmax
#define abs aabs
char s[202000];
int a[202000], f[202000], smn[70000000];
void js(int x) {
  int s = a[x];
  f[x] = smn[s] + 1;
  for (int i = 0; i < 26; ++i)
    chkmin(f[x], smn[s ^ (1 << i)] + 1);
  chkmin(smn[s], f[x]);
}
int main() {
#ifdef cnyali_lk
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  int n;
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1, t = 1 << 26; i < t; ++i)
    smn[i] = 0x3f3f3f3f;

  for (int i = 1; i <= n; ++i) {
    a[i] = a[i - 1] ^ (1 << (s[i] - 'a'));
    js(i);
  }
  printf("%d\n", f[n]);
  return 0;
}