Problem:
Score : 100 points

Problem Statement

You are given a 4-character string S consisting of uppercase English letters.
Determine if S consists of exactly two kinds of characters which both appear twice in S.

Constraints

The length of S is 4.

S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If S consists of exactly two kinds of characters which both appear twice in S, print Yes; otherwise, print No.

Sample Input 1

ASSA

Sample Output 1

Yes

S consists of A and S which both appear twice in S.

Sample Input 2

STOP

Sample Output 2

No

Sample Input 3

FFEE

Sample Output 3

Yes

Sample Input 4

FREE

Sample Output 4

No

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;

#define pb(x) push_back(x)
#define ppb() pop_back()
#define mp(x,y) make_pair(x,y)
#define mod 1000000007
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i = a; i < b; i++)
#define FORD(i,a,b) for(ll i=(a);i>=(int)(b);i--)
#define sf(n) scanf("%lld", &n)
#define sfc(x) scanf("%c", &x)
#define pf(x) printf("%lld", x)
#define pff(x) printf("%lf", x)
#define pfc(x) printf("%c", x)
#define pfs(x) printf("%s", x)
#define sf2(a,b) scanf("%lld %lld", &a, &b)
#define sf3(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define pfn(n) printf("%lld\n", n)
//#define pfs(n) printf("%lld ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define sz size()
#define ll long long
#define all(c) (c).begin(),(c).end()
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
const ll INF = 2e18;

bool prime[100010];
void SieveOfEratosthenes(ll n)
{
    memset(prime,true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}

ll power1(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1){
            res*=a;
        }
        a=a*a;
        b>>=1;
    }
    return res;
}



ll mod_power(ll a,ll b,ll m){
    ll res=1;
    a%=m;
    while(b){
        if(b&1){
            res=res*a%m;
        }
        a=a*a%m;
        b>>=1;
    }
    return res;
}
ll printDivisors(ll n) 
{ 
    ll count=0;
    for (ll i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            if (n/i == i) 
                count++; 
  
            else // Otherwise print both 
                printf("%d %d ", i, n/i); 
        } 
    } 
} 
bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}
ll par[1000001];
ll ranki[1000001]={0};

ll find(ll x){
    if(par[x]!=x){
        par[x] = find(par[x]);
    }
    return par[x];
}

void unionset(ll x,ll y){
    ll xr = find(x);
    ll yr = find(y);
    if(ranki[xr]>ranki[yr]){
        par[yr]=xr;
    }
    else if(ranki[xr]<ranki[yr]){
        par[xr]=yr;
    }
    else{
        par[yr] = xr;
        ranki[xr]++;
    }
}

// vector<pii> v[10001];
// ll vis[10001]={0};
//  ll dis[10001];
// void dijkstra(){
//     FOR0(i,10001)dis[i]=1e18;
//     multiset<pii > s;
//     s.insert({0,1});
//     dis[1]=0;
//     while(!s.empty()){
//         pii up = *s.begin();
//         ll u=up.ss;
//         s.erase(s.begin());
//         if(vis[u])continue;
//         vis[u]=1;
//         FOR0(i,v[u].size()){
//             ll e = v[u][i].ff,w=v[u][i].ss;
//             if(dis[u]+w<dis[e]){
//                 dis[e]=dis[u]+w;
//                 s.insert({dis[e],e});
//             }
//         }
//     }

// }

// void dijkstra(ll s){
//         FOR0(i,10001)dis[i]=INF;
//         dis[s] = 0;
//         priority_queue<pii , vpii , greater<pii >> pq;
//         //priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
//         pq.push({0, s});
//         while(!pq.empty())
//         {
//             int u = pq.top().ss;
//             //int d = pq.top().first;
//             pq.pop();
//             if(vis[u]) continue;
//             vis[u] = 1;
//             for(auto it: v[u])
//             {
//                 int e = it.ff;
//                 int w = it.ss;
//                 if(dis[u] + w < dis[e])
//                 {
//                     dis[e] = dis[u] + w;
//                     pq.push({dis[e], e});
//                 }
//             }
//         }
// }

// void dfs1(ll s,ll count){
//     vis[s]=1;
//     //val[s]=count;
//     FOR0(i,v[s].size()){
//         if(!vis[v[s][i]]){
//             dfs1(v[s][i],count);
//         }
//     }
// }

// void dfs(ll s){
//     stack<ll> st;
//     st.push(s);
//     vis[s]=1;
//     while(!st.empty()){
//         ll u = st.top();
//         st.pop();
//         FOR0(i,v[u].size()){
//             if(!vis[v[u][i]]){
//                 st.push(v[u][i]);
//                 vis[v[u][i]]=1;
//             }
//         }
//     }
// }


// ll bs(){
//     ll l,h,mid;
//     while(l<=h){
//         mid = (l+h)/2;
//         if(a[mid]==x)return mid;
//         else if(x>a[mid]){
//             l = mid+1;
//         }
//         else if(x<a[mid]){
//             h = mid-1;
//         }
//     }
// }

// ll lbs(){
//     ll l,h,mid;
//     while(l<h){
//         mid = (l+h)/2;
//         if(x<=a[mid]){
//             h = mid;
//         }
//         else{
//             l = mid-1;
//         }
//     }
//     if(a[l]==x)return l;
//     else return -1;
// }

// ll ubs(){
//     ll l,h,mid;
//     while(l<h){
//         mid = (l+h)/2;
//         if(a[mid]<=x)l = mid;
//         else{
//             h = mid-1;
//         }
//     }
//     if(a[h]==x)return h;
//     else return -1;
// }

int main(){
   fast
   string s;
   cin>>s;
   ll freq[26]={0};
   FOR0(i,s.length())freq[s[i]-'A']++;
   ll count=0,count1=0;
   FOR0(i,26){
    if(freq[i]>0)count++;
    if(freq[i]==2)count1++;
   }
   if(count==2&&count1==2)cout<<"Yes\n";
   else cout<<"No\n";
}