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: Time Limit Exceeded)

#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#define rep(i,n) for (int i = 0; i < (n);i++)
typedef long long ll;
using namespace std;
/*#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;*/


void Main()
{
	int n,k; cin>>n>>k;
	vector<int> pascal(k,0);
  	vector<int> primer(k,0);
	primer.at(0) = 1;
	primer.at(1) = 1;
  	pascal.at(0) = 1;
	for(int i = 1;i<k-1;i++) {
		for(int j = 1;j<k;j++){
			pascal.at(j) = primer.at(j-1)+primer.at(j);
		}
      	rep(j,k) primer.at(j) = pascal.at(j);
	}

	int red = n-k;
	for(int i = 1;i<=k;i++) {
		int und = 1;
		int ans = 1;
		for(int j = 1; j<=i;j++){
			ans*=(red + 1-(j-1));
			und*=j;
		}
		ans /= und;
		ans*= pascal.at(i-1);

		cout << ans%(1000000007) <<endl;
	}		
}
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}