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 (GCC 5.4.1) (judge verdict: Wrong Answer)

/*
	長さ4の英大文字からなる文字列Sが与えられます。
	Sがちょうど２種類の文字からなり、かつ現れる各文字は
	ちょうど２回ずつ現れているかどうか判定してください。
	<制約>
	・Sの長さは4である。
	・Sは英大文字からなる。
	
	例：ASSA -> YES   STOP -> No
	
	URL:https://atcoder.jp/contests/abc132/tasks/abc132_a
 */

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>

#define S_LEN (4)

static void bubble_sort(char* array, int n);

int main(void)
{
	bool result = true;
	char buf[S_LEN];
	
	scanf("%s", buf);
	
	if(strlen(buf) != 4)
	{
		printf("No");
		return 0;
	}
	
	bubble_sort(buf, strlen(buf));
	//printf("%s\n", buf);

	for(int i = 0; i < strlen(buf)/2; i += 2)
	{
		if(!isupper(buf[i+0]) || !isupper(buf[i+1]))
		{
			result = false;
			break;
		}
		if(buf[i+0] != buf[i+1])
		{
			result = false;
			break;
		}
	}
	
	if(result)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}

	return 0;
}

static void swap(char* a, char* b)
{
	char tmp = *a;
	*a = *b;
	*b = tmp;
}

static void bubble_sort(char* array, int n)
{
        for(int sorted_i = 0; sorted_i < n-1; sorted_i++)
        {
                for(int j = n-1; j > sorted_i; j--)
                {
                        if(array[j-1] > array[j])
                        {
                                swap(&array[j-1], &array[j]);
                        }       
                }
        }
}