Language: C++

#include <bits/stdc++.h>
#include <math.h>

#define rep(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>

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

  // LW[i]:i番目の人よりLeft にいる人のうち、Wを向いている人の数
  // RE[i]:i番目の人よりRightにいる人のうち、Lを向いている人の数
  // 求める答えは、LW[i]+RE[i]のうち最小のもの
  vi LW(n),RE(n);

  // LW の決定。LW[0]=0 としてよい
  for (int i = 1; i < n; i++) {
    if(s[i-1]=='W') LW[i] = LW[i-1] + 1;
    else LW[i] = LW[i-1];
  }
  // RE の決定。RE[n-1]=0
  for (int i = n-2; i >= 0; i--) {
    if(s[i+1]=='E') RE[i] = RE[i+1] + 1;
    else RE[i] = RE[i+1];
  }

  int ans = 1e9;
  rep(i, n) chmin(ans,LW[i]+RE[i]);
  std::cout << ans << '\n';
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:10: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    8 |   int n; cin >> n;
      |          ^~~
      |          std::cin
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:146,
                 from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:9:3: error: 'string' was not declared in this scope
    9 |   string s; cin >> s;
      |   ^~~~~~
a.cc:9:3: note: suggested alternatives:
In file included from /usr/include/c++/14/string:41,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/stringfwd.h:77:33: note:   'std::string'
   77 |   typedef basic_string<char>    string;
      |                                 ^~~~~~
/usr/include/c++/14/string:76:11: note:   'std::pmr::string'
   76 |     using string    = basic_string<char>;
      |           ^~~~~~
a.cc:9:20: error: 's' was not declared in this scope
    9 |   string s; cin >> s;
      |                    ^
a.cc:5:12: error: 'vector' was not declared in this scope
    5 | #define vi vector<int>
      |            ^~~~~~
a.cc:14:3: note: in expansion of macro 'vi'
   14 |   vi LW(n),RE(n);
      |   ^~
a.cc:5:12: note: suggested alternatives:
    5 | #define vi vector<int>
      |            ^~~~~~
a.cc:14:3: note: in expansion of macro 'vi'
   14 |   vi LW(n),RE(n);
      |   ^~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:5:19: error: expected primary-expression before 'int'
    5 | #define vi vector<int>
      |                   ^~~
a.cc:14:3: note: in expansion of macro 'vi'
   14 |   vi LW(n),RE(n);
      |   ^~
a.cc:18:21: error: 'LW' was not declared in this scope
   18 |     if(s[i-1]=='W') LW[i] = LW[i-1] + 1;
      |                     ^~
a.cc:19:10: error: 'LW' was not declared in this scope
   19 |     else LW[i] = LW[i-1];
      |          ^~
a.cc:23:21: error: 'RE' was not declared in this scope
   23 |     if(s[i+1]=='E') RE[i] = RE[i+1] + 1;
      |                     ^~
a.cc:24:10: error: 'RE' was not declared in this scope
   24 |     else RE[i] = RE[i+1];
      |          ^~
a.cc:28:23: error: 'LW' was not declared in this scope
   28 |   rep(i, n) chmin(ans,LW[i]+RE[i]);
      |                       ^~
a.cc:28:29: error: 'RE' was not declared in this scope
   28 |   rep(i, n) chmin(ans,LW[i]+RE[i]);
      |                             ^~
a.cc:28:13: error: 'chmin' was not declared in this scope
   28 |   rep(i, n) chmin(ans,LW[i]+RE[i]);
      |             ^~~~~