Language: C++

#include<iostream>
#include<map>
#include<string>
#include<vector>

int main(){
  string S;
  cin>>S;
  map<char, int> amap;
  vector<char> arr;
  for(int i=0;i<4;++i){
    if(amap[S[i]]==0) arr.push_back(S[i]);
    amap[S[i]]++;
  }
  bool ok = true;
  if(arr.size()!=2) ok = false;
  else{
    if(amap[arr[0]]!=amap[arr[1]]) ok = false;
  }
  if(ok) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:3: error: 'string' was not declared in this scope
    7 |   string S;
      |   ^~~~~~
a.cc:7:3: note: suggested alternatives:
In file included from /usr/include/c++/14/iosfwd:41,
                 from /usr/include/c++/14/ios:40,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stringfwd.h:77:33: note:   'std::string'
   77 |   typedef basic_string<char>    string;
      |                                 ^~~~~~
In file included from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44:
/usr/include/c++/14/string:76:11: note:   'std::pmr::string'
   76 |     using string    = basic_string<char>;
      |           ^~~~~~
a.cc:8:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    8 |   cin>>S;
      |   ^~~
      |   std::cin
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:8:8: error: 'S' was not declared in this scope
    8 |   cin>>S;
      |        ^
a.cc:9:3: error: 'map' was not declared in this scope
    9 |   map<char, int> amap;
      |   ^~~
a.cc:9:3: note: suggested alternatives:
In file included from /usr/include/c++/14/map:63,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_map.h:102:11: note:   'std::map'
  102 |     class map
      |           ^~~
/usr/include/c++/14/map:89:13: note:   'std::pmr::map'
   89 |       using map
      |             ^~~
a.cc:9:7: error: expected primary-expression before 'char'
    9 |   map<char, int> amap;
      |       ^~~~
a.cc:10:3: error: 'vector' was not declared in this scope
   10 |   vector<char> arr;
      |   ^~~~~~
a.cc:10:3: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:4:
/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:10:10: error: expected primary-expression before 'char'
   10 |   vector<char> arr;
      |          ^~~~
a.cc:12:8: error: 'amap' was not declared in this scope
   12 |     if(amap[S[i]]==0) arr.push_back(S[i]);
      |        ^~~~
a.cc:12:23: error: 'arr' was not declared in this scope
   12 |     if(amap[S[i]]==0) arr.push_back(S[i]);
      |                       ^~~
a.cc:13:5: error: 'amap' was not declared in this scope
   13 |     amap[S[i]]++;
      |     ^~~~
a.cc:16:6: error: 'arr' was not declared in this scope
   16 |   if(arr.size()!=2) ok = false;
      |      ^~~
a.cc:18:8: error: 'amap' was not declared in this scope
   18 |     if(amap[arr[0]]!=amap[arr[1]]) ok = false;
      |        ^~~~
a.cc:20:10: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   20 |   if(ok) cout<<"Yes"<<endl;
      |          ^~~~
      |          std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:20:23: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   20 |   if(ok) cout<<"Yes"<<endl;
      |                       ^~~~
      |                       std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc:21:8: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   21 |   else cout<<"No"<<endl;
      |        ^~~~
      |        std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:21:20: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   21 |   else cout<<"No"<<endl;
      |                    ^~~~
      |                    std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~