Problem:
Score : 600 points

Problem Statement

There is a game that involves three variables, denoted A, B, and C.

As the game progresses, there will be N events where you are asked to make a choice.
Each of these choices is represented by a string s_i. If s_i is AB, you must add 1 to A or B then subtract 1 from the other; if s_i is AC, you must add 1 to A or C then subtract 1 from the other; if s_i is BC, you must add 1 to B or C then subtract 1 from the other.

After each choice, none of A, B, and C should be negative.

Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.

Constraints

1 \leq N \leq 10^5

0 \leq A,B,C \leq 10^9

N, A, B, C are integers.

s_i is AB, AC, or BC.

Input

Input is given from Standard Input in the following format:

N A B C
s_1
s_2
:
s_N

Output

If it is possible to make N choices under the condition, print Yes; otherwise, print No.

Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (A, B, or C) to which you add 1 in the i-th choice.

Sample Input 1

2 1 3 0
AB
AC

Sample Output 1

Yes
A
C

You can successfully make two choices, as follows:

In the first choice, add 1 to A and subtract 1 from B. A becomes 2, and B becomes 2.

In the second choice, add 1 to C and subtract 1 from A. C becomes 1, and A becomes 1.

Sample Input 2

3 1 0 0
AB
BC
AB

Sample Output 2

No

Sample Input 3

1 0 9 0
AC

Sample Output 3

No

Sample Input 4

8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB

Sample Output 4

Yes
C
B
B
C
C
B
A
A

Solution in Rust (1.42.0) (judge verdict: Accepted)

enum Choice { L, R }
impl Choice {
    fn choose<T>(self, l: T, r: T) -> T { match self { Choice::L => l, Choice::R => r } }
}
fn whatevr() -> Choice { Choice::L /* L or R, it doesn't matter */ }

const A: u8 = b'A';
const B: u8 = b'B';
const C: u8 = b'C';
const AB: (u8, u8) = (A, B);
const BC: (u8, u8) = (B, C);
const AC: (u8, u8) = (A, C);

fn mv(left: &mut usize, right: &mut usize, prefer: Choice) -> Result<Choice, ()> {
    let choice = match (*left, *right) {
        (0, 0) => return Err(()),
        (l, r) if l < r => Choice::L,
        (l, r) if l > r => Choice::R,
        _ => prefer,
    };

    match choice {
        Choice::L => { *left += 1; *right -= 1 },
        Choice::R => { *left -= 1; *right += 1 },
    }

    Ok(choice)
}

fn solve(
    mut a: usize,
    mut b: usize,
    mut c: usize,
    alts: Vec<(u8, u8)>
) -> Result<Vec<u8>, ()> {
    let mut solution = Vec::new();
    let mut alts = alts.into_iter().peekable();
    while let Some(current) = alts.next() {
        let next = *alts.peek().unwrap_or(&AB /* AB/BC/AC, it doesn't matter */);
        let choice = match (current, next) {
            (AB, AB) => mv(&mut a, &mut b, whatevr())?.choose(A, B),
            (AB, BC) => mv(&mut a, &mut b, Choice::R)?.choose(A, B),
            (AB, AC) => mv(&mut a, &mut b, Choice::L)?.choose(A, B),

            (BC, AB) => mv(&mut b, &mut c, Choice::L)?.choose(B, C),
            (BC, BC) => mv(&mut b, &mut c, whatevr())?.choose(B, C),
            (BC, AC) => mv(&mut b, &mut c, Choice::R)?.choose(B, C),

            (AC, AB) => mv(&mut a, &mut c, Choice::L)?.choose(A, C),
            (AC, BC) => mv(&mut a, &mut c, Choice::R)?.choose(A, C),
            (AC, AC) => mv(&mut a, &mut c, whatevr())?.choose(A, C),
            _ => unreachable!(),
        };
        solution.push(choice);
    }
    Ok(solution)
}

fn main() {
    let mut io = IO::new();

    let n = io.read();
    let a = io.read();
    let b = io.read();
    let c = io.read();
    let alts = gen(n, || (io.read_ascii(), io.read_ascii())).collect();

    let ans = solve(a, b, c, alts);
    match ans {
        Err(_) => io.writeln("No"),
        Ok(vs) => {
            io.writeln("Yes");
            io.write_many(vs.iter().map(|&v| v as char));
        }
    }
}


// PROCON LIBRARY //

pub trait Num: Sized {
    fn to_i(self) -> isize;
    fn to_u(self) -> usize { self.to_i() as usize }
    fn off<T: Num>(self, other: T) -> usize { (self.to_i() + other.to_i()).to_u() }
}
impl Num for usize { fn to_i(self) -> isize { self as isize } }
impl Num for isize { fn to_i(self) -> isize { self as isize } }
impl Num for u32 { fn to_i(self) -> isize { self as isize } }
impl Num for i32 { fn to_i(self) -> isize { self as isize } }
impl Num for u64 { fn to_i(self) -> isize { self as isize } }
impl Num for i64 { fn to_i(self) -> isize { self as isize } }

pub struct IdxIterMut<'a, T> {
    iter: std::iter::Enumerate<std::slice::IterMut<'a, T>>,
}

impl<'a, T> Iterator for IdxIterMut<'a, T> {
    type Item=(usize, &'a mut T);
    fn next(&mut self) -> Option<(usize, &'a mut T)> {
        self.iter.next().map(|(i, v)| (i+1, v))
    }
}

pub struct IdxIter<'a, T> {
    iter: std::iter::Enumerate<std::slice::Iter<'a, T>>,
}

impl<'a, T> Iterator for IdxIter<'a, T> {
    type Item=(usize, &'a T);
    fn next(&mut self) -> Option<(usize, &'a T)> {
        self.iter.next().map(|(i, v)| (i+1, v))
    }
}

pub trait SliceExt<T> {
    fn at<I: Num>(&mut self, i: I) -> &mut T;
    fn iter_idx(&self) -> IdxIter<'_, T>;
    fn iter_idx_mut(&mut self) -> IdxIterMut<'_, T>;
}
impl<T> SliceExt<T> for [T] {
    fn at<I: Num>(&mut self, i: I) -> &mut T {
        &mut self[i.to_u() + 1]
    }
    fn iter_idx(&self) -> IdxIter<'_, T> {
        IdxIter {
            iter: self.iter().enumerate(),
        }
    }
    fn iter_idx_mut(&mut self) -> IdxIterMut<'_, T> {
        IdxIterMut {
            iter: self.iter_mut().enumerate(),
        }
    }
}

pub fn gen<T, F: FnMut() -> T>(n: usize, mut f: F) -> impl Iterator<Item=T> {
    (0..n).map(move |_| f())
}

pub struct IO(
    std::io::BufReader<std::io::StdinLock<'static>>,
    std::io::BufWriter<std::io::StdoutLock<'static>>
);
 
impl IO {
    pub fn new() -> IO {
        IO(
            std::io::BufReader::new(Box::leak(Box::new(std::io::stdin())).lock()),
            std::io::BufWriter::new(Box::leak(Box::new(std::io::stdout())).lock())
        )
    }
    pub fn write<D: std::fmt::Display>(&mut self, v: D) {
        use std::io::Write;
        write!(self.1, "{}", v).unwrap();
    }
    pub fn writeln<D: std::fmt::Display>(&mut self, v: D) {
        use std::io::Write;
        writeln!(self.1, "{}", v).unwrap();
    }
    pub fn write_many<D: std::fmt::Display>(&mut self, vs: impl std::iter::IntoIterator<Item=D>) {
        for v in vs {
            self.writeln(v);
        }
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_ascii(&mut self) -> u8 {
        use std::io::Read;
        self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .next()
            .expect("Parse error")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
}