Problem p02836 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;
using namespace std::chrono;

// VARS
#define int long long
#define ld long double
#define mod1 1000000007
#define mod2 998244353
#define pi 3.14159265358979323846
// #define hs                100006
#define inf 1e18
#define ninf -1 * (1e18)

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vc vector
#define pii pair<int, int>
#define msi map<string, int>
#define mii map<int, int>
#define psi pair<string, int>
#define pis pair<int, string>
#define endl "\n"

// INPUT
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repe(i, a, b) for (int i = a; i <= b; i++)
#define bac(i, a, b) for (int i = a; i > b; i--)
#define bace(i, a, b) for (int i = a; i >= b; i--)

// FAST
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);

// FUNCTIONS
#define DECIMAL(n) std::cout << std::fixed << std::setprecision(n)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define REVERSE(v) reverse(ALL(v))
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define init(x, a) memset(x, a, sizeof(x))
#define trav(a, x) for (auto &a : x)
#define display(x)                                                             \
  trav(a, x) cout << a << " ";                                                 \
  cout << endl
#define pow(i, n) (int)pow((int)i, n)
#define pow2(n) ((int)1 << n)

void swp(int &a, int &b) {
  auto temp = a;
  a = b;
  b = temp;
}

int ans(string s) {

  int n = s.length();
  int p = 0;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[n - i - 1]) {
      p += 1;
      if (s[i] < s[n - i - 1])
        s[n - i - 1] = s[i];
      else
        s[i] = s[n - i - 1];
    }
  }
  return p;
}

void solve() {
  string s;
  cin >> s;
  int t = ans(s);
  cout << t;
  return;
}

signed main() {
  ios
#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int q = 1;
  // cin>>q;
  while (q--) {
    solve();
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;
using namespace std::chrono;

// VARS
#define int long long
#define ld long double
#define mod1 1000000007
#define mod2 998244353
#define pi 3.14159265358979323846
// #define hs                100006
#define inf 1e18
#define ninf -1 * (1e18)

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vc vector
#define pii pair<int, int>
#define msi map<string, int>
#define mii map<int, int>
#define psi pair<string, int>
#define pis pair<int, string>
#define endl "\n"

// INPUT
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repe(i, a, b) for (int i = a; i <= b; i++)
#define bac(i, a, b) for (int i = a; i > b; i--)
#define bace(i, a, b) for (int i = a; i >= b; i--)

// FAST
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);

// FUNCTIONS
#define DECIMAL(n) std::cout << std::fixed << std::setprecision(n)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define REVERSE(v) reverse(ALL(v))
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define init(x, a) memset(x, a, sizeof(x))
#define trav(a, x) for (auto &a : x)
#define display(x)                                                             \
  trav(a, x) cout << a << " ";                                                 \
  cout << endl
#define pow(i, n) (int)pow((int)i, n)
#define pow2(n) ((int)1 << n)

void swp(int &a, int &b) {
  auto temp = a;
  a = b;
  b = temp;
}

int ans(string s) {

  int n = s.length();
  int p = 0;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[n - i - 1]) {
      p += 1;
      if (s[i] < s[n - i - 1])
        s[n - i - 1] = s[i];
      else
        s[i] = s[n - i - 1];
    }
  }
  return p;
}

void solve() {
  string s;
  cin >> s;
  int t = ans(s);
  cout << t;
  return;
}

signed main() {
  ios int q = 1;
  // cin>>q;
  while (q--) {
    solve();
  }

  return 0;
}