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 <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <cmath>
#include <climits>
using namespace std;

#define rep(i,beg,end)   for (int i=(beg);i<(end);i++)
#define rrep(i,beg,end)   for (int i=(beg);i>=(end);i--)
#define all(cont)           begin(cont), end(cont)
#define INFMAX                   LLONG_MAX
#define INFMIN                   LLONG_MIN
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef list<ll> li;
typedef pair<ll, ll> pii;
typedef pair<ll, string> pis;
typedef pair<string, ll> psi;

string gets(bool skipnewline);
vi get_n_array(int n);


ll right(ll d[], int n, int k, ll v)
{
    if (k < 0) return 0;
    else if (k == 0 || n == 0) return v;

    ll m = v;
    ll t = d[n - 1];
    m = max(right(d, n - 1, k - 1, v + t), m);
    if (t < 0) m = max(right(d, n - 1, k - 2, v), m);
    return m;
}

ll left(ll d[], int n, int k, ll v)
{
    if (k < 0) return 0;
    else if (k == 0 || n == 0) return v;

    ll m = v;
    ll t = d[0];
    m = max(left(d+1, n - 1, k - 1, v + t), m);
    if (t < 0) m = max(left(d+1, n - 1, k - 2, v), m);
    return max(right(d, n, k, v), m);
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    char s[4];
    rep(i, 0, 4) { cin >> s[i]; }
    sort(s, s + 4);
    if (s[0] == s[1] && s[2] == s[3] && s[0]!=s[2]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

string gets(bool skipToNextline)
{
    if (skipToNextline) gets(false);
    const int BUFF_MAX = 1024;
    char buf[BUFF_MAX];
    cin.getline(buf, sizeof(buf));
    return buf;
}

vi get_n_array(int n)
{
    vi v;
    while (n-- > 0) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    return v;
}