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>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char m = '1',t = '2';
    int est = 0,mc=0,tc=0;
    string S;
    bool arc = 0;
    cin >> S;
    REP(i,4){
        if(S[i] == m){
            mc++;
        }else if(S[i] == t){
            tc++;
        }else if(est == 0){
            m = S[i];
            mc++;
            est++;
        }else if(est == 1){
            t = S[i];
            tc++;
            est++;
        }else{
            arc = 1;
            break;
        }
    }
    if(tc > 2 || mc > 2)arc = 1;
    if(arc){
        cout <<"No"<< "\n";
    }else{
        cout <<"Yes"<< "\n";
    }
}