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 Rust (1.15.1) (judge verdict: Accepted)

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::Read;
use std::io::{stdout, BufWriter, Write};
 
fn main() {
    let mut buf = String::new();
    
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
 
    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
 
    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();
 
    /*
    let n: u32 = iter.next().unwrap().parse().unwrap();
    let a: i64 = iter.next().unwrap().parse().unwrap();
    let b: i64 = iter.next().unwrap().parse().unwrap();
    let c: i64 = iter.next().unwrap().parse().unwrap();
    */
    
    let s: String = iter.next().unwrap().parse().unwrap();
    let s = s.into_bytes();
    
    let mut cnt = 1;
    let mut flg = false;
    
    //let mut s1cnt = 1;
    //let mut s2cnt = 1;
    
    let s1 = s[0];
    let mut s2 = s[0];
    
    for i in 1..4 {
        let a = s[i];
        //println!("{}, {}",a, cnt);
        if a != s1 && a != s2 {
            if s1 == s2 { // hajimedake
                //println!("s2 change");
                s2 = a;
            }
            else{
                //println!("flg change");
                flg = true;
                break;
            }
        }
        if a == s1{
            cnt += 1;
        }else if a == s2{
            cnt -= 1;
        }
    }
    if cnt != 0 {
        flg = true;
    }
    
    //println!("{:?}",s);
    
    if flg == true {
        println!("No");
    }else{
        println!("Yes");
    }
}