Language: C++

#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//}

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];
int I[100][20];

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int>west(n);
	vector<int>north(n);
	if (s[0] == 'W')west[0]++;
	else north[0]++;
	for (int i = 1;i < n;++i) {
		if (s[i] == 'W') {
			west[i] += west[i - 1] + 1;
		}
		else north[i] += north[i - 1] + 1;
	}
	int ans = min(north[n - 1] - north[0], west[n - 1] - west[0]);
	for (int i = 1;i < n;++i) {
		int res = west[i - 1] + north[n - 1] - north[i];
		ans = min(ans, res);
	}
	cout << ans << endl;
	return 0;
}
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//}

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];
int I[100][20];

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int>west(n);
	vector<int>north(n);
	if (s[0] == 'W')west[0]++;
	else north[0]++;
	for (int i = 1;i < n;++i) {
		if (s[i] == 'W') {
			west[i] += west[i - 1] + 1;
		}
		else north[i] += north[i - 1] + 1;
	}
	int ans = min(north[n - 1] - north[0], west[n - 1] - west[0]);
	for (int i = 1;i < n;++i) {
		int res = west[i - 1] + north[n - 1] - north[i];
		ans = min(ans, res);
	}
	cout << ans << endl;
	return 0;
}


Compiler output:
a.cc:87:31: error: redefinition of 'template<class T> bool chmax(T&, T)'
   87 | template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
      |                               ^~~~~
a.cc:8:31: note: 'template<class T> bool chmax(T&, T)' previously declared here
    8 | template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
      |                               ^~~~~
a.cc:88:31: error: redefinition of 'template<class T> bool chmin(T&, T)'
   88 | template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
      |                               ^~~~~
a.cc:9:31: note: 'template<class T> bool chmin(T&, T)' previously declared here
    9 | template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
      |                               ^~~~~
a.cc:101:5: error: redefinition of 'int g [15][15]'
  101 | int g[15][15];
      |     ^
a.cc:22:5: note: 'int g [15][15]' previously declared here
   22 | int g[15][15];
      |     ^
a.cc:102:11: error: redefinition of 'const int INF'
  102 | const int INF = 1001001001;
      |           ^~~
a.cc:23:11: note: 'const int INF' previously defined here
   23 | const int INF = 1001001001;
      |           ^~~
a.cc:103:11: error: redefinition of 'const int dx [4]'
  103 | const int dx[4] = { -1,0,1,0 };
      |           ^~
a.cc:24:11: note: 'const int dx [4]' previously defined here
   24 | const int dx[4] = { -1,0,1,0 };
      |           ^~
a.cc:104:11: error: redefinition of 'const int dy [4]'
  104 | const int dy[4] = { 0,-1,0,1 };
      |           ^~
a.cc:25:11: note: 'const int dy [4]' previously defined here
   25 | const int dy[4] = { 0,-1,0,1 };
      |           ^~
a.cc:107:4: error: redefinition of 'll gcd(ll, ll)'
  107 | ll gcd(ll x, ll y) {
      |    ^~~
a.cc:28:4: note: 'll gcd(ll, ll)' previously defined here
   28 | ll gcd(ll x, ll y) {
      |    ^~~
a.cc:111:4: error: redefinition of 'll lcm(ll, ll)'
  111 | ll lcm(ll x, ll y) {
      |    ^~~
a.cc:32:4: note: 'll lcm(ll, ll)' previously defined here
   32 | ll lcm(ll x, ll y) {
      |    ^~~
a.cc:117:22: error: redefinition of 'std::vector<std::pair<long long int, int> > factorize(ll)'
  117 | vector<pair<ll, int>>factorize(ll n) {
      |                      ^~~~~~~~~
a.cc:38:22: note: 'std::vector<std::pair<long long int, int> > factorize(ll)' previously defined here
   38 | vector<pair<ll, int>>factorize(ll n) {
      |                      ^~~~~~~~~
a.cc:131:5: error: redefinition of 'int dp [1010][1010]'
  131 | int dp[1010][1010];
      |     ^~
a.cc:52:5: note: 'int dp [1010][1010]' previously declared here
   52 | int dp[1010][1010];
      |     ^~
a.cc:132:5: error: redefinition of 'int bingo [3][3]'
  132 | int bingo[3][3];
      |     ^~~~~
a.cc:53:5: note: 'int bingo [3][3]' previously declared here
   53 | int bingo[3][3];
      |     ^~~~~
a.cc:133:6: error: redefinition of 'bool flag [3][3]'
  133 | bool flag[3][3];
      |      ^~~~
a.cc:54:6: note: 'bool flag [3][3]' previously declared here
   54 | bool flag[3][3];
      |      ^~~~
a.cc:134:5: error: redefinition of 'int I [100][20]'
  134 | int I[100][20];
      |     ^
a.cc:55:5: note: 'int I [100][20]' previously declared here
   55 | int I[100][20];
      |     ^
a.cc:136:5: error: redefinition of 'int main()'
  136 | int main() {
      |     ^~~~
a.cc:57:5: note: 'int main()' previously defined here
   57 | int main() {
      |     ^~~~