Problem p03341 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf 40000000007
#define eps 1e-8
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.8lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define ios                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define endl '\n'
using namespace std;
#define N 1000006
#define M 100006
#define T 200001
int v[T];
int main() {
  ios;
  int n;
  cin >> n;
  string s;
  cin >> s;
  // int n=s.size();
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'E')
      v[i + 1] = v[i] + 1;
    else
      v[i + 1] = v[i];
  }
  int ans = n;
  for (int i = 1; i <= n; i++) {
    int w = (i - 1) - v[i - 1] + (v[n] - v[i]);
    ans = min(ans, w);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf 40000000007
#define eps 1e-8
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.8lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define ios                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define endl '\n'
using namespace std;
#define N 1000006
#define M 100006
#define T 300001
int v[T];
int main() {
  ios;
  int n;
  cin >> n;
  string s;
  cin >> s;
  // int n=s.size();
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'E')
      v[i + 1] = v[i] + 1;
    else
      v[i + 1] = v[i];
  }
  int ans = n;
  for (int i = 1; i <= n; i++) {
    int w = (i - 1) - v[i - 1] + (v[n] - v[i]);
    ans = min(ans, w);
  }
  cout << ans << endl;
}