jiahuimbzuai/CoQuIR huggingface dataset:
//  [go]
package main

import "fmt"

func main() {
	// Code for B - Snuke's Coloring 2 (ABC Edit)
	var W, H, N int
	fmt.Scanf("%d %d %d", &W, &H, &N)

	x := make([]int, N)
	y := make([]int, N)
	a := make([]int, N)

	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d %d", &x[i], &y[i], &a[i])
	}

	var X1, Y1, X2, Y2 int
	X1 = 0
	Y1 = 0
	X2 = W
	Y2 = H
	for i := 0; i < N; i++ {
		if a[i] == 1 {
			if X1 <= x[i] {
				X1 = x[i]
			}
		} else if a[i] == 2 {
			if X2 >= x[i] {
				X2 = x[i]
			}
		} else if a[i] == 3 {
			if Y1 <= y[i] {
				Y1 = y[i]
			}
		} else {
			if Y2 >= y[i] {
				Y2 = y[i]
			}
		}
	}

	S := (X2 - X1) * (Y2 - Y1)
	if S < 0 {
		fmt.Println("0")
	} else {
		fmt.Println(S)
	}
}
//  [go]
package main

import "fmt"

func main() {
	// Code for B - Snuke's Coloring 2 (ABC Edit)
	var W, H, N int
	fmt.Scanf("%d %d %d", &W, &H, &N)

	x := make([]int, N)
	y := make([]int, N)
	a := make([]int, N)

	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d %d", &x[i], &y[i], &a[i])
	}

	var X1, Y1, X2, Y2 int
	X1 = 0
	Y1 = 0
	X2 = W
	Y2 = H
	for i := 0; i < N; i++ {
		if a[i] == 1 {
			if X1 <= x[i] {
				X1 = x[i]
			}
		} else if a[i] == 2 {
			if X2 >= x[i] {
				X2 = x[i]
			}
		} else if a[i] == 3 {
			if Y1 <= y[i] {
				Y1 = y[i]
			}
		} else if a[i] == 4 {
			if Y2 >= y[i] {
				Y2 = y[i]
			}
		}
	}

	S := (X2 - X1) * (Y2 - Y1)
	if S < 0 {
		fmt.Println("0")
	} else {
		fmt.Println(S)
	}
}
//  [go]
package main

import "fmt"

func main() {
	// Code for B - Snuke's Coloring 2 (ABC Edit)
	var W, H, N int
	fmt.Scanf("%d %d %d", &W, &H, &N)

	x := make([]int, N)
	y := make([]int, N)
	a := make([]int, N)

	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d %d", &x[i], &y[i], &a[i])
	}

	var X1, Y1, X2, Y2 int
	X1 = 0
	Y1 = 0
	X2 = W
	Y2 = H
	for i := 0; i < N; i++ {
		if a[i] == 1 {
			if X1 < x[i] {
				X1 = x[i]
			}
		} else if a[i] == 2 {
			if X2 > x[i] {
				X2 = x[i]
			}
		} else if a[i] == 3 {
			if Y1 < y[i] {
				Y1 = y[i]
			}
		} else if a[i] == 4 {
			if Y2 > y[i] {
				Y2 = y[i]
			}
		}
	}
	S := (X2 - X1) * (Y2 - Y1)
	if S < 0 {
		fmt.Println("0")
	} else {
		fmt.Println(S)
	}
}
//  [ruby]
W,H,N = gets.split.map(&:to_i)
x_left = 0
x_right = W
y_bottom = 0
y_top = H
N.times do |i|
    x,y,a = gets.split.map(&:to_i)
    case a
    when 1
        x_left = x if x_left < x
    when 2
        x_right = x if x < x_right
    when 3
        y_bottom = y if y_bottom < y
    when 4
        y_top = y if y < y_top
    end
end
x = x_right - x_left
y = y_top - y_bottom
x = 0 if x < 0
y = 0 if y < 0
puts x*y
//  [ruby]
w,h,n = gets.split.map(&:to_i)
xl = 0
xr = w
yl = 0
yh = h
n.times do
  x,y,a = gets.split.map(&:to_i)
  if a == 1
    xl = x if x >= xl
  elsif a == 2
    xr = x if x <= xr
  elsif a == 3
    yl = y if y > yl
  else
    yh = y if y < yh
  end
end

ans = (yh-yl) * (xr - xl)
if yh -yl > 0 && xr - xl > 0
  puts ans
else
  puts 0
end
//  [ruby]
w, h, n = gets.split.map(&:to_i)
a = Array.new(n){gets.split.map(&:to_i)}
x0, y0, x1, y1 = 0, 0, w, h
n.times do |i|
  if a[i][2] == 1
    x0 = a[i][0] if x0 < a[i][0]
  elsif a[i][2] == 2
    x1 = a[i][0] if x1 > a[i][0]
  elsif a[i][2] == 3
    y0 = a[i][1] if y0 < a[i][1]
  elsif a[i][2] == 4
    y1 = a[i][1] if y1 > a[i][1]
  end
end
puts (x1 > x0 && y1 > y0 ? (x1 - x0) * (y1 - y0) : 0)
//  [ruby]
w, h, n = gets.split.map(&:to_i)
arr = [nil, 0, w, 0, h]

n.times do
  x, y, a = gets.split.map(&:to_i)
  
  arr[a] = a <= 2 ? x : y
end

puts (arr[1]...arr[2]).to_a.length * (arr[3]...arr[4]).to_a.length
//  [ruby]
W,H,N = gets.chomp.split(" ").map(&:to_i)
x,y,a = N.times.map{gets.split.map(&:to_i)}.transpose
x0 = 0
y0 = 0
x1 = W
y1 = H
N.times do |i|
  if a[i] == 1
    x0 = x[i] if x0 < x[i]
  elsif a[i] == 2
    x1 = x[i] if x1 > x[i]
  elsif a[i] == 3
    y0 = y[i] if y0 < y[i]
  else
    y1 = y[i] if y1 > y[i]
  end
end
puts [(x1-x0)*(y1-y0),0].max
//  [ruby]
w,h,n = gets.chomp.split(' ').map(&:to_i)
i = 0
hash = {1=>0, 2=>w, 3=>0, 4=>h}
# p hash
while i < n
  x,y,a = gets.chomp.split(' ').map(&:to_i)
  case a
  when 1
    if hash[a] < x # 存在し、xが大きい場合
      hash[a] = x
    end
  when 2
    if hash[a] > x # 存在し、xが大きい場合
      hash[a] = x
    end
  when 3
    if hash[a] < y # 存在し、yが大きい場合
      hash[a] = y
    end
  when 4
    if hash[a] > y # 存在し、yが大きい場合
      hash[a] = y
    end
  end
  i += 1
end

# p hash
# 縦 * 横
s = ((h-hash[3]) - (h-hash[4])) * ((h-hash[1]) - (h-hash[2])) >= 0 ? 
((h-hash[3]) - (h-hash[4])) * ((h-hash[1]) - (h-hash[2])) : 0
p s
//  [rust]
use std::io::{Read, stdin};
use std::str::FromStr;
use std::cmp;

fn main() {
    let w: i64 = read();
    let h: i64 = read();
    let n = read();
    let mut x_min: i64 = 0;
    let mut x_max: i64 = w;
    let mut y_min: i64 = 0;
    let mut y_max: i64 = h;

    for _i in 0..n {
        let x: i64 = read();
        let y: i64 = read();
        let a = read();
        match a {
            1 => x_min = cmp::max(x_min, x),
            2 => x_max = cmp::min(x_max, x),
            3 => y_min = cmp::max(y_min, y),
            4 => y_max = cmp::min(y_max, y),
            _ => (),
        }
    }
    let mut ans = 0;
    if y_max > y_min && x_max > x_min {
        ans = (y_max - y_min) * (x_max - x_min);
    }
    println!("{}", ans);
}


fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
//  [rust]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }

use std::cmp::max;
fn main() {
    input! {
        w: i64,
        h: i64,
        n: i64,
        xya: [(i64, i64, i8); n],
    }
    let mut p = (0,0,w,h);
    for (x,y,a) in xya {
        match a {
            1 => if p.0 < x { p.0 = x },
            2 => if p.2 > x { p.2 = x },
            3 => if p.1 < y { p.1 = y },
            4 => if p.3 > y { p.3 = y },
            _ => panic!()
        };
    }
    println!("{}", max(p.2-p.0,0) * max(p.3-p.1, 0));
}
//  [rust]
use std::cmp::max;
use std::cmp::min;
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|e| e.parse::<usize>().unwrap());
    let w = itr.next().unwrap();
    let h = itr.next().unwrap();
    let n = itr.next().unwrap();
    let mut xl = 0;
    let mut xh = w;
    let mut yl = 0;
    let mut yh = h;

    for _ in 0..n {
        let mut s = String::new();
        stdin().read_line(&mut s).ok();
        let mut itr = s.split_whitespace().map(|e| e.parse::<usize>().unwrap());
        let x = itr.next().unwrap();
        let y = itr.next().unwrap();
        let a = itr.next().unwrap();
        match a {
            1 => xl = max(xl, x),
            2 => xh = min(xh, x),
            3 => yl = max(yl, y),
            4 => yh = min(yh, y),
            _ => (),
        }
    }

    println!(
        "{}",
        if xl < xh && yl < yh {
            (xh - xl) * (yh - yl)
        } else {
            0
        }
    );
}
//  [rust]
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        w: usize,
        h: usize,
        n: usize,
    }

    let mut x: Vec<usize> = Vec::new();
    let mut y: Vec<usize> = Vec::new();
    let mut a: Vec<usize> = Vec::new();
    for i in 0..n {
        input!{
            x_tmp: usize,
            y_tmp: usize,
            a_tmp: usize,
        }
        x.push(x_tmp);
        y.push(y_tmp);
        a.push(a_tmp);
    }

    let mut sx = 0;
    let mut sy = 0;
    let mut dx = w;
    let mut dy = h;
    for i in 0..n {
        if a[i]==1 {
            sx = x[i];
        } else if a[i]==2 {
            dx = x[i];
        } else if a[i]==3 {
            sy = y[i];
        } else {
            dy = y[i];
        }
    }

    if sx<dx && sy<dy {
        println!("{}", (dx-sx)*(dy-sy));
    } else {
        println!("0");
    }

}
//  [rust]
#![allow(unused_imports)]

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use maplit::*;
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!(
        w: i32,
        h: i32,
        n: usize,
        xya: [(i32, i32, i32); n],
    );
    let (mut xl, mut xr, mut yb, mut ya) = (0, w, 0, h);
    for (x, y, a) in xya {
        match a {
            1 => { xl = max(xl, x); },
            2 => { xr = min(xr, x); },
            3 => { yb = max(yb, y); },
            _ => { ya = min(ya, y); },
        };
    };
    println!("{}", max(0, (xr - xl) * (ya - yb)));
}
//  [rust]
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());

    let (w, h, n) = (io.read::<i64>(), io.read::<i64>(), io.read::<i64>());

    let mut mn2 = w;
    let mut mx1 = 0i64;
    let mut mx3 = 0i64;
    let mut mn4 = h;
    for _ in 0..n {
        let (x, y, a) = (io.read::<i64>(), io.read::<i64>(), io.read::<i64>());
        match a {
            1 => mx1 = max(mx1, x),
            2 => mn2 = min(mn2, x),
            3 => mx3 = max(mx3, y),
            _ => mn4 = min(mn4, y),
        }
    }
    if mx1 > mn2 && mx3 > mn4 {
        io.writeln((mx1 - mn2) * (mx3 - mn4));
    } else {
        io.writeln(0);
    }
}

static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}
//  [swift]
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (W, H, N) = (input[0], input[1], input[2])
var (minX, minY, maxX, maxY) = (0, 0, W, H)
for _ in 0..<N {
    let input = readLine()!.characters.split(" ").map{Int(String($0))!}
    let (x, y, a) = (input[0], input[1], input[2])
  	switch a {
    case 1:
        minX = max(minX, x)
    case 2:
        maxX = min(maxX, x)
    case 3:
        minY = max(minY, y)
    case 4:
        maxY = min(maxY, y)
    default:
      	break
    }
}
print(max(0,maxX-minX) * max(0,maxY-minY))
//  [swift]
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (W, H, N) = (input[0], input[1], input[2])
var (minX, minY, maxX, maxY) = (0, 0, W, H)
for _ in 0..<N {
    let input = readLine()!.characters.split(" ").map{Int(String($0))!}
    let (x, y, a) = (input[0], input[1], input[2])
  	switch a {
    case 1:
        minX = max(minX, x)
    case 2:
        maxX = min(maxX, x)
    case 3:
        minY = max(minY, y)
    case 4:
        maxY = min(maxY, y)
    default:
      	break
    }
}
print((maxX-minX) * (maxY-minY))
//  [swift]
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (W, H, N) = (input[0], input[1], input[2])
var (minX, minY, maxX, maxY) = (0, 0, W, H)
for _ in 0..<N {
    let input = readLine()!.characters.split(" ").map{Int(String($0))!}
    let (x, y, a) = (input[0], input[1], input[2])
  	switch a {
    case 1:
        minX = max(minX, x)
    case 2:
        maxX = min(maxX, x)
    case 3:
        minY = max(minY, y)
    case 4:
        maxY = min(maxY, y)
    }
}
print(max(0, maxX-minX) * max(0,maxY-minY))
//  [typescript]
"use strict";

const Main = args => {
  const input = args.trim().split("\n").map(e => e.split(' ').map(e => e - 0));
  const paints = input.slice(1);

  let xMin = 0;
  let xMax = input[0][0];
  let yMin = 0;
  let yMax = input[0][1];

  paints.forEach(e => {
    let xi = e[0];
    let yi = e[1];
    let ai = e[2];

    if (ai === 1) {
      if (xMin < xi) xMin = xi;
    } else if (ai === 2) {
      if (xMax > xi) xMax = xi;
    } else if (ai === 3) {
      if (yMin < yi) yMin = yi;
    } else if (ai === 4) {
      if (yMax > yi) yMax = yi;
    }
  });

  let x = xMax - xMin;
  let y = yMax - yMin;
  console.log((x > 0 && y > 0) ? x * y : 0);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
const main = (txt: any): void => {
  const input = txt.split('\n')
  let [W, H, N] = input[0].split(' ').map((i: string) => { return Number(i) })
  let Ma1 = 0
  let Ma2 = W
  let Ma3 = 0
  let Ma4 = H
  for (let i = 1; i <= N; i++) {
    let x: number
    let y: number
    let a: number
    [x, y, a] = input[i].split(' ').map((i: string) => { return Number(i) })
    if (a === 1 && x > Ma1) {
      Ma1 = x
    }
    if (a === 2 && x < Ma2) {
      Ma2 = x
    }
    if (a === 3 && y > Ma3) {
      Ma3 = y
    }
    if (a === 4 && y < Ma4) {
      Ma4 = y
    }
  }
  const Wn = Ma2 - Ma1
  const Hn = Ma4 - Ma3
  const sum = (Ma2 - Ma1) * (Ma4 - Ma3)
  if (sum >= 0 && Wn > 0 && Hn > 0) {
    console.log(sum)
  }
  else {
    console.log('0')
  }
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
const main = (txt: any): void => {
  const input = txt.split('\n')
  let [W, H, N] = input[0].split(' ').map((i: string) => { return Number(i) })
  let Ma1 = 0
  let Ma2 = W
  let Ma3 = 0
  let Ma4 = H
  for (let i = 1; i <= N; i++) {
    const [x, y, a] = input[i].split(' ').map((i: string) => { return Number(i) })
    if (a === 1 && x > Ma1) {
      Ma1 = x
    }
    if (a === 2 && x < Ma2) {
      Ma2 = x
    }
    if (a === 3 && y > Ma3) {
      Ma3 = y
    }
    if (a === 4 && y < Ma4) {
      Ma4 = y
    }
  }
  const Wn = Ma2 - Ma1
  const Hn = Ma4 - Ma3
  const sum = (Ma2 - Ma1) * (Ma4 - Ma3)
  if (sum >= 0 && Wn > 0 && Hn > 0) {
    console.log(sum)
  }
  else {
    console.log('0')
  }
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [W, H, N] = input[0].map(Number);

  let top = H;
  let bottom = 0;
  let left = 0;
  let right = W;

  for (let i = 1; i <= N; i++) {
    const [x, y, a] = input[i].map(Number);

    switch (a) {
      case 1: {
        left = x;
        break;
      }
      case 2: {
        right = x;
        break;
      }
      case 3: {
        bottom = y;
        break;
      }
      case 4: {
        top = y;
        break;
      }
    }
  }

  const height = Math.max(0, top - bottom);
  const width = Math.max(0, right - left);

  return height * width;
};

console.log(main(read()));
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [W, H, N] = input[0].map(Number);

  let top = H;
  let bottom = 0;
  let left = 0;
  let right = W;

  for (let i = 1; i <= N; i++) {
    const [x, y, a] = input[i].map(Number);

    switch (a) {
      case 1: {
        left = x;
        break;
      }
      case 2: {
        right = x;
        break;
      }
      case 3: {
        bottom = y;
        break;
      }
      case 4: {
        top = y;
        break;
      }
    }
  }

  return Math.max(0, (top - bottom) * (right - left));
};

console.log(main(read()));
//  [typescript]
"use strict";

const Main = args => {
  const input = args.trim().split("\n").map(e => e.split(' ').map(e => e - 0));
  const paints = input.slice(1);

  let xMin = 0;
  let xMax = input[0][0];
  let yMin = 0;
  let yMax = input[0][1];

  paints.forEach(e => {
    let xi = e[0];
    let yi = e[1];
    let ai = e[2];

    if (ai === 1) {
      if (xMin < xi) xMin = xi;
    } else if (ai === 2) {
      if (xMax > xi) xMax = xi;
    } else if (ai === 3) {
      if (yMin < yi) yMin = yi;
    } else if (ai === 4) {
      if (yMax > yi) yMax = yi;
    }
  });

  let area = (xMax - xMin) * (yMax - yMin);
  console.log(area > 0 ? area : 0);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [python]
s = input()
l = sorted(s)
if l[0] == l[1] and l[1] != l[2] and l[2] == l[3]:
    print('Yes')
else:
    print('No')
//  [python]
s_ll = sorted(list(input()))
if s_ll[0] == s_ll[1] and s_ll[2] == s_ll[3] and s_ll[1] != s_ll[2]:
    print('Yes')
else:
    print('No')
//  [python]
S = input()
D = {chr(i):0 for i in range(65, 65+26)}

f=0
for i in range(4):
  D[S[i]] += 1
  if D[S[i]] == 2:
    f +=1

if f ==2:
  print ("Yes")
else:
  print ("No")
//  [python]
s=input()
ans="No"
for i in range(4):
    if s.count(s[i])==2:
        ans="Yes"
print(ans)
//  [python]
s=input() 
if s[0]==s[1]==s[2]==s[3]:
  print("No")
elif s[0]!=s[1]!=s[2]!=s[3]:
  print("NO")
elif s[0]==s[1]==s[2]:
  print("No")
elif s[1]==s[2]==s[3]:
  print("No")
elif s[0]==s[2]==s[3]:
  print("No")
elif s[0]==s[1]==s[3]:
  print("No")
else:
  print("Yes")
//  [python]
s=input()

if s[0]==s[1]==s[2]==s[3]:
  print("No")
elif s[0]!=s[1]!=s[2]!=s[3]:
  print("NO")
elif s[0]==s[1]==s[2]:
  print("No")
elif s[1]==s[2]==s[3]:
  print("No")
elif s[0]==s[2]==s[3]:
  print("No")
elif s[0]==s[1]==s[3]:
  print("No")
else:
  print("Yes")
//  [java]
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.awt.Point;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        char[] c = new char[4];
        
        int count = 1;
        boolean flag = true;
        for (int i = 0; i < s.length(); i++) {
            count = 1;
            for (int j = 0; j < s.length(); j++) {
                if (i == j) continue;
                if (s.charAt(i) == s.charAt(j)) {
                    count++;
                }
            }
            if (count != 2) {
                flag = false;
                break;
            }
        }
        
        
        System.out.println(flag?"Yes":"No");
    }
}
//  [java]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		// String[] strArr = str.split("\\s+");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		HashMap<Character, Integer> hist = new HashMap<Character, Integer>();
		for (char c : str.toCharArray()) {
			if (hist.containsKey(c)) {
				hist.put(c, hist.get(c) + 1);
			} else {
				hist.put(c, 1);
			}
		}
		if (hist.size() == 2 && hist.get(str.charAt(0)) == 2)
			System.out.println("Yes");
		else
			System.out.println("No");
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}
//  [java]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	
	public static void main(String args[]) throws IOException {
		char c[] = getString().toCharArray();
		if (c[0]==c[1]&&c[2]==c[3]&&c[0]!=c[2] || c[0]==c[2]&&c[1]==c[3]&&c[0]!=c[1] || c[0]==c[3]&&c[1]==c[2]&&c[0]!=c[1] ) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		
	}
}
//  [java]
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		String S = stdIn.next();
		if(S.charAt(0) == S.charAt(1) && S.charAt(2) == S.charAt(3)){
			System.out.println("Yes");
		}
		else if(S.charAt(0) == S.charAt(2) && S.charAt(1) == S.charAt(3)){
			System.out.println("Yes");
		}
		else if(S.charAt(0) == S.charAt(3) && S.charAt(1) == S.charAt(2)){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
		stdIn.close();
	}
}
//  [cpp]
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int main(int argc, char* argv[])
{
    char str[5]={0};
    scanf("%s", str);
    sort(str+0, str+4);
    if(str[0]==str[1] && str[2]==str[3] && str[1]!=str[2]) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}
//  [cpp]
#include<stdio.h>

int main(){
    char str[4] ;
    scanf("%s",&str);
    int count = 0  , i , j;
    for(i = 0 ; i < 3 ; i++){
        for(j = i+1 ; j<4 ; j++){
            if(str[i]==str[j]){
                count++ ;
                break ;
            }
        }
    }
    if(count==2){
        printf("Yes");
    }else{
        printf("No");
    }

}
//  [cpp]
#include <cstdio>
#include <unordered_set>
const int MAXA = 26;
const int MAXS = 4;
const int TWO = 2;
int cnt[MAXA]{ };
char S[MAXS + 5];

int main() {
  scanf("%s", S);
  int two = 0;
  for (int i = 0; i < MAXS; ++i) {
    int c = S[i] - 'A';
    ++cnt[c];
    if (cnt[c] == TWO) {
      ++two;
    } else if (cnt[c] > TWO) {
      --two;
    }
  }
  puts((two == TWO) ? "Yes" : "No");
  return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s[0]==s[1]==s[2]==s[3]){
        cout<<"No"<<endl;
        return 0;
    }
    if((s[0]==s[1] && s[2]==s[3]) || (s[0]==s[2] && s[1]==s[3]) || (s[0]==s[3] && s[1]==s[2]))cout << "Yes"<<endl;
    else cout<<"No"<<endl;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    if((s[0]==s[1] && s[2]==s[3]) || (s[0]==s[2] && s[1]==s[3]) || (s[0]==s[3] && s[1]==s[2]))cout << "Yes"<<endl;
    else cout<<"No"<<endl;
}
//  [cpp]
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;

/*----------macros----------*/

//input, output================
#define fastio                          \
std::ios::sync_with_stdio(false);       \
std::cin.tie(nullptr);                  \
std::cout.tie(nullptr)

#define endl '\n'
#define fcout(a)                        \
cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef vector<int>     Vi;
typedef vector<ll>      Vl;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF    = (ll)1e9 + 1;
constexpr ll INFll  = (ll)1e18 + 1;
constexpr ll MOD1   = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define psb push_back
#define epb emplace_back
#define psf push_front
#define mkp make_pair
#define fst first
#define snd second

//others================
#define sz(x)                           \
(int) x.size()

#define all(x)                          \
(x).begin(), (x).end()

#define rall(x)                         \
(x).rbegin(), (x).rend()

#define rep(i, n)                       \
for(int i = 0; (i) < (n); ++(i))

#define reps(i, n)                      \
for(int i = 1; (i) <= (n); ++(i))

#define rrep(i, n)                      \
for(int i = n - 1; (i) >= 0 ; --(i))

#define repbit(bit, n)                  \
for(int bit = 0; (bit) < (1 << (n)); ++(bit))

#define ifbit(bit, i)                   \
if((bit) & (1 << (i)))

#define CtoI(c)                         \
int((c)) - int('0')

#define ItoC(c)                         \
char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b)
{ return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b)
{ return a > b && (a = b, true); }

// Vi  dx = {1, 0, -1, 0},
//     dy = {0, 1, 0, -1};

// Vi  dx2 = { 1,1,0,-1,-1,-1,0,1 },
//     dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
fastio;

    string s; cin >> s;
    if((s[0] == s[1] && s[2] == s[3]) ||
       (s[0] == s[2] && s[1] == s[3]) ||
       (s[0] == s[3] && s[1] == s[2]) ||
       (s[1] == s[3] && s[0] == s[2]) ||
       (s[2] == s[3] && s[0] == s[1])){
           cout << "Yes" << endl;
           return 0;
       }

       cout << "No" << endl;

return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
int asc(const void *a, const void *b){
    return *(char*)a-*(char*)b;
}
int main(void){
    char s[5];
    scanf("%s",s);
    qsort(s,4,sizeof(char),asc);
    if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]) printf("Yes");
    else printf("No");
    return 0;
}
//  [c]
#include <stdio.h>
int main(){
    char S[4];
    scanf("%s",S);
    if(S[0]==S[1]){
        if(S[2]==S[3]){
            if(S[0]!=S[2]){
                printf("Yes");
                return 0;
            }
        }
    }
    if(S[0]==S[2]){
        if(S[1]==S[3]){
            if(S[0]!=S[1]){
                printf("Yes");
                return 0;
            }
        }
    }
    if(S[0]==S[3]){
        if(S[1]==S[2]){
            if(S[0]!=S[1]){
                printf("Yes");
                return 0;
            }
        }
    }
    printf("No");
}
//  [c]
#include <stdio.h>

int main(void) {
    char s[5];

    scanf("%s", s);

    if (s[0] == s[1] && s[1] == s[2] && s[2] == s[3]) {
        printf("No\n");
    }
    else if (s[0] == s[1] && s[2] == s[3]) {
        printf("Yes\n");
    }
    else if (s[0] == s[2] && s[1] == s[3]) {
        printf("Yes\n");
    }
    else if (s[0] == s[3] && s[1] == s[2]) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef char keytype;

void quicksort_des(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] > x) i++;
        while (x > a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort_des(a, first , i - 1);
    if (j + 1 < last) quicksort_des(a, j + 1, last);
}

int main(){
    char s[5];

    scanf("%s", s);

    quicksort_des(s, 0, 3);

    if(s[0] == s[1] && s[2] == s[3]) puts("Yes");
    else puts("No");

    return 0;
}
//  [c]
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
	
	string s;
	int cnt = 0;
	cin >> s;
	sort(s.begin(), s.end());
	for (int i = 0; i < s.length()-1; i++)
		if (s[i] == s[i + 1])
			cnt++;
	if (cnt == 2)
		cout << "Yes";
	else
		cout << "No";
}
//  [c]
#include<stdio.h>
int main()
{
	char s[4];
	scanf("%s",s);
	if(s[0]!=s[1]&&s[0]!=s[2]){
		if(s[0]==s[1]&&s[2]==s[3]||s[0]==s[2]&&s[1]==s[3]||s[0]==s[3]&&s[1]==s[2]){
			printf("Yes\n");
		}
	}
	else{
		printf("No\n");
	}
	return 0;
}
//  [javascript]
"use strict";
    
const main = arg => {
    let text = arg.trim().split("");
  	let ans = "No";
  	// 全部同じだった時の処理
  	if(text.every(elm => { return elm == text[0]})){
    	ans = "No"; 
    } 
  	else if(
      (text[0] == text[1] && text[2] == text[3])
      ||
      (text[0] == text[2] && text[1] == text[3])
      ||
      (text[0] == text[3] && text[1] == text[2])
  	)
    {
    	ans = "Yes";
    }
  	console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
'use strict'
const Main = (arg) => {
  let input = arg.trim().split('\n');
  let S = input[0].split('');
  // console.log({ S });
  let Ans = 'No';
  if (S[0] === S[1] && S[2] === S[3] && S[0] !== S[2]) {
    Ans = 'Yes'
  } else if (S[0] === S[2] && S[1] === S[3] && S[0] !== S[1]) {
    Ans = 'Yes'
  } else if (S[0] === S[3] && S[1] === S[2] && S[0] !== S[1]) {
    Ans = 'Yes'
  }
  
  console.log(Ans)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input) {
  var a = input.slice(0, 1);
  var b = input.slice(1, 2);
  var c = input.slice(2, 3);
  var d = input.slice(3, 4);
  
  if((a == b && c == d && a != c)
    || (a != b && a == c && b == d)
    || (a != b && b == c && a == d)){
     console.log("Yes");
     }else{
       console.log("No");
     }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
const fs = require('fs')

const input = fs.readFileSync('/dev/stdin', 'utf8')

const S = input.trim()

const counter = {}

for (let i=0; i<4; i++) {
  const c = S.substr(i, 1)
  if (c in counter) {
    counter[c] = counter[c] + 1
  } else {
    counter[c] = 1    
  }
}

if (counter[S.substr(0, 1)] === 2) {
  console.log('Yes')
} else {
  console.log('No')
}
//  [javascript]
"use strict";
function main(input) {
    let S = input.replace("\n", "");
    let ans = countBy([...S]);
    console.log(Object.values(ans)[0] == 2 ? "Yes" : "No");
    return;
}
function countBy(data, keyGetter) {
    var keyResolver = {
        'function': function (d) { return keyGetter(d); },
        'string': function (d) { return d[keyGetter]; },
        'undefined': function (d) { return d; }
    };

    var result = {};

    data.forEach(function (d) {
        var keyGetterType = typeof keyGetter;
        var key = keyResolver[keyGetterType](d);

        if (result.hasOwnProperty(key)) {
            result[key] += 1;
        } else {
            result[key] = 1;
        }
    });

    return result;
}
// list1 = ['a', 'b', 'c', 'b', 'a', 'b', 'c', 'a', 'a', 'a'];
// console.log(countBy(list1));  // {'a':5, 'b':3, 'c':2}
// list2 = ['abc', 'aa', 'b3', 'abcd', 'cd'];
// console.log(countBy(list2, 'length'));  // {2: 3, 3: 1, 4: 1}
// list3 = [1.2, 7.8, 1.9];
// console.log(countBy(list3, Math.floor));  // {1: 2, 7: 1}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
'use strict'
const Main = (arg) => {
  let S = arg.trim().split('\n');
  console.log({ S });
  Ans = 'No';
  if (S[0] === S[1] && S[2] === S[3] && S[0] !== S[2]) {
    Ans = 'Yes'
  } else if (S[0] === S[2] && S[1] === S[3] && S[0] !== S[1]) {
    Ans = 'Yes'
  } else if (S[0] === S[3] && S[1] === S[2] && S[0] !== S[1]) {
    Ans = 'Yes'
  }
  
  
  console.log(Ans)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	s := getString()

	m := make(map[byte]int)
	for _, v := range s {
		m[byte(v)]++
	}
	if len(m) == 2 {
		for _, v := range m {
			if v != 2 {
				out("No")
				return
			}
		}
		out("Yes")
		return
	}
	out("No")
	return
}
//  [go]
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	a, b       int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func FactoredPrimeNumber(num int) map[int]int {
	m := map[int]int{}
	return factor(m, num, 2)
}

func factor(result map[int]int, num, pnum int) map[int]int {
	if pnum*pnum > num {
		if num != 1 {
			result[num] += 1
		}
		return result
	}

	if num%pnum == 0 {
		num /= pnum
		result[pnum]++
	} else {
		pnum++
	}
	return factor(result, num, pnum)
}

func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

type P struct {
	l, r int
}

func main() {
	var S string
	fmt.Scanf("%s\n", &S)

	m := map[string]int{}

	for _, s := range []rune(S) {
		m[string(s)]++
	}
	if len(m) == 2 {
		for _, v := range m {
			if v == 2 {
				fmt.Println("Yes")
				return
			}
		}
	}

	fmt.Println("No")
}

func Reverse(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}
//  [go]
package main

import (
	"fmt"
)

func main() {

	var S string
	fmt.Scanf("%s", &S)

	if (S[0] == S[1] && S[2] == S[3]) || (S[0] == S[2] && S[1] == S[3]) || (S[0] == S[3] && S[1] == S[2]) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	S := getStdin()
	var ch1 byte = ' '
	var ch2 byte = ' '
	for idx := range S {
		if ch1 == ' ' {
			ch1 = S[idx]
		} else if ch2 == ' ' && ch1 != S[idx] {
			ch2 = S[idx]
		} else {
			if ch1 != S[idx] && ch2 != S[idx] {
				fmt.Printf("No\n")
				return
			}
		}
	}
	fmt.Printf("Yes\n")
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
//  [ruby]
len = gets.chomp.split('').uniq.length
puts len == 2 ? 'Yes' : 'No'
//  [ruby]
inputs = gets.chomp.split("")

result = {}

inputs.uniq.each { |x|
	result[x] = inputs.count(x)
}

if result.keys.size == 2 && result.values[0] == 2 && result.values[1] == 2 then
	puts 'Yes'
else
	puts 'No'
end

STDOUT.flush
//  [ruby]
s = gets.chomp.chars
count = Hash.new(0)
s.each do |c|
  count[c] += 1 
  if count[c] > 2
    print("No\n")
    exit
  end
end

if count.length > 2
  print("No\n") 
else
  print("Yes\n")
end
//  [ruby]
a,b,c,d=gets.chars.sort
puts a==b&&c==d&&b!=c ? "Yes":"No"
//  [ruby]
a,b,c,d=gets.chars.sort
puts a==b&&c==d ? "Yes":"No"
//  [ruby]
puts gets.chop.chars.tally.values.all{_1==2}?:Yes: :No
//  [rust]
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let mut S = rl().chars().collect::<Vec<_>>();
    S.sort();
    let ok = S[0] == S[1] && S[1] != S[2] && S[2] == S[3];
    println!("{}", if ok { "Yes" } else { "No" })
}
//  [rust]
use std::cmp;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    	n:chars
    }
    let mut nn = n.to_vec();
    nn.sort();
       
    println!("{}", if nn[0]==nn[1]&&nn[2]==nn[3]&&nn[1]!=nn[2] { "Yes" } else { "No" });
}
//  [rust]
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


//main function
fn main() {
    let n: String = read();
    let ch: Vec<char> = n.chars().collect();
    let mut count: i32;
    for i in 0..ch.len(){
	count = 0;
	for j in 0..ch.len(){
	    if ch[i]==ch[j] {
		count+=1;
	    }
	}
	if count != 2 {
	    println!("No");
	    return;
	}
    }
    println!("Yes");
}
//  [rust]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;


#[fastout]
fn main() {
    input! {
    mut s: Chars
    }
    s.sort();
    let ans = if s[0] == s[1] && s[2] == s[3] {"Yes"} else {"No"};
    println!("{}", ans);
}
//  [rust]
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        s:Bytes,
    }
    if s[0] ^ s[1] ^ s[2] ^ s[3] == 0 {
        if s[0] != s[1] || s[1] != s[2] || s[2] != s[3] {
            println!("Yes");
            return;
        }
    }
    println!("No");
}
//  [rust]
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        s:Bytes,
    }
    if (s[0] != s[1] || s[1] != s[2] || s[2] != s[3]) && s[0] ^ s[1] ^ s[2] ^ s[3] == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}
//  [swift]
import Foundation
 
let input = readLine()!
 
let S = Array(input.characters)

if S[0] == S[1] && S[1] == S[2] && S[2] == S[3] {
	print("No")
}else if S[0] == S[2] && S[1] == S[3] {
    print("Yes")
} else if S[1] == S[2] && S[0] == S[3] {
    print("Yes")
} else if S[0] == S[1] && S[2] == S[3] {
    print("Yes")
} else {
    print("No")
}
//  [swift]
let str=String((readLine()!).sorted())

let a=str.index(str.startIndex,offsetBy:0)
let b=str.index(str.startIndex,offsetBy:1)
let c=str.index(str.startIndex,offsetBy:2)
let d=str.index(str.startIndex,offsetBy:3)

if (str[a]==str[b])&&(str[b] != str[c])&&(str[c]==str[d]){
  print("Yes")
}else{
  print("No")
}
//  [swift]
let s=readLine()!
var seta:Set<Character>=[]
var judge=0
for x in s{
  seta.insert(x)
}
if seta.count==2{
  judge+=1
}
for x in seta{
  var count=0
  for y in s{
    if x==y{
      count+=1
    }
  }
  if count==2{
    judge+=1
  }
}

if judge==3{
  print("Yes")
}else{
  print("No")
}
//  [swift]
var str = String((readLine()!).sorted())

  let a = str.index(str.startIndex, offsetBy: 0)
  let b = str.index(str.startIndex, offsetBy: 1)
  let c = str.index(str.startIndex, offsetBy: 2)
  let d = str.index(str.startIndex, offsetBy: 3)
  
  if str [a]==str [b] && str [c]==str[d] {
    print("Yes")
  }
  else {
    print("No")
  }