Problem:
Score : 200 points

Problem Statement

You have a digit sequence S of length 4. You are wondering which of the following formats S is in:

YYMM format: the last two digits of the year and the two-digit representation of the month (example: 01 for January), concatenated in this order

MMYY format: the two-digit representation of the month and the last two digits of the year, concatenated in this order

If S is valid in only YYMM format, print YYMM; if S is valid in only MMYY format, print MMYY; if S is valid in both formats, print AMBIGUOUS; if S is valid in neither format, print NA.

Constraints

S is a digit sequence of length 4.

Input

Input is given from Standard Input in the following format:

S

Output

Print the specified string: YYMM, MMYY, AMBIGUOUS or NA.

Sample Input 1

1905

Sample Output 1

YYMM

May XX19 is a valid date, but 19 is not valid as a month. Thus, this string is only valid in YYMM format.

Sample Input 2

0112

Sample Output 2

AMBIGUOUS

Both December XX01 and January XX12 are valid dates. Thus, this string is valid in both formats.

Sample Input 3

1700

Sample Output 3

NA

Neither 0 nor 17 is valid as a month. Thus, this string is valid in neither format.

Solution in Rust (1.15.1) (judge verdict: Wrong Answer)

#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(unknown_lints)]
#![allow(unused_variables)]
#![allow(unused_must_use)]
#![allow(unused_mut)]
#![allow(dead_code)]
#![allow(unused_assignments)]

use std::cmp;
use std::process::{
    exit,
    Command
};
use std::fs::OpenOptions;
use std::collections::{
    HashMap,
    VecDeque
};
use std::io::{
    stdin,
    stdout,
    stderr,
    Read,
    Write,
    BufReader,
    BufWriter
};

macro_rules! d {
    ($t:expr, $($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", $t, $e).unwrap()
        })*
    };
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

macro_rules! e {
    ($($arg:tt)*) => {
        #[cfg(debug_assertions)]
        {
            let mut err = stderr();
            let e = format!($($arg)*);
            write!(err, "\x1B[32m{}\x1B[0m", e).unwrap()
        }
    };
}

macro_rules! eln {
    ($($arg:tt)*) => {
        #[cfg(debug_assertions)]
        {
            let mut err = stderr();
            let e = format!($($arg)*);
            writeln!(err, "\x1B[32m{}\x1B[0m", e).unwrap()
        }
    };
}

macro_rules! stdin {
    () => ({
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    })
}

macro_rules! test {
    (name = $name:ident, $($input:expr => $output:expr),* $(,)*) => (
        #[test]
        fn $name() {
            $(
                assert_eq!(solve($input.to_string()), $output);
            )*
        }
    );
    ($($input:expr => $output:expr),* $(,)*) => (
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input.to_string()), $output);
            )*
        }
    );
}

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));
        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")
    };
}

pub trait VecUtils<T: Clone> {
    fn npop(&mut self, n: usize) -> Result<Vec<T>, String>;
    fn nget(&self, n: usize) -> Result<Vec<T>, String>;
    fn is_valid_range(&self, idx_a: usize, idx_b: usize) -> bool;
    fn get_range(&self, idx_a: usize, idx_b: usize) -> Result<Vec<T>, String>;
    fn pop_range(&mut self, idx_a: usize, idx_b: usize) -> Result<Vec<T>, String>;
    fn mul(&self, n: usize) -> Vec<T>;
}

pub trait StrUtils {
    fn npop(&mut self, n: usize) -> Result<String, String>;
    fn nget(&self, n: usize) -> Result<String, String>;
    fn is_valid_range(&self, idx_a: usize, idx_b: usize) -> bool;
    fn get_range(&self, idx_a: usize, idx_b: usize) -> Result<String, String>;
    fn pop_range(&mut self, idx_a: usize, idx_b: usize) -> Result<String, String>;
    fn mul(&self, n: usize) -> String;
}

impl<T: Clone> VecUtils<T> for Vec<T> {
    fn npop(&mut self, n: usize) -> Result<Vec<T>, String> {
        let len = self.len();
        if n > len {
            return Err("too large num".to_string());
        }
        let mut res: Vec<T> = Vec::new();
        for _ in 0..n {
            let x = self.pop().ok_or("".to_string())?;
            res.push(x);
        }
        res.reverse();
        Ok(res)
    }

    fn nget(&self, n: usize) -> Result<Vec<T>, String> {
        let len = self.len();
        if n > len {
            return Err("too large num".to_string());
        }
        let mut res: Vec<T> = Vec::new();
        for i in 0..n {
            res.push(self[len - 1 - i].clone());
        }
        Ok(res)
    }

    fn is_valid_range(&self, idx_a: usize, idx_b: usize) -> bool {
        let mut can = true;
        let self_len = self.len();
        if self_len < idx_a {
            can = false;
        }
        if self_len < idx_b {
            can = false;
        }
        can
    }

    fn get_range(&self, idx_a: usize, idx_b: usize) -> Result<Vec<T>, String> {
        if ! self.is_valid_range(idx_a, idx_b) {
            return Err("invalid range".to_string());
        }
        let mut res: Vec<T> = Vec::new();
        for (i,x) in self.into_iter().enumerate() {
            let i = i;
            if i < idx_a {
                continue;
            }
            if idx_b <= i {
                break;
            }
            res.push(x.clone());
        }
        Ok(res)
    }

    fn pop_range(&mut self, idx_a: usize, idx_b: usize) -> Result<Vec<T>, String> {
        if ! self.is_valid_range(idx_a, idx_b) {
            return Err("invalid range".to_string());
        }
        let mut res: Vec<T> = Vec::new();
        let mut pop_idxs: Vec<usize> = Vec::new();
        for (i,x) in self.iter().enumerate() {
            let i = i;
            if i < idx_a {
                continue;
            }
            if idx_b <= i {
                break;
            }
            res.push(x.clone());
            pop_idxs.push(i);
        }
        for _ in 0..pop_idxs.len() {
            match pop_idxs.pop() {
                Some(idx) => {
                    self.remove(idx as usize);
                },
                None => {}
            }
        }
        Ok(res)
    }

    fn mul(&self, n: usize) -> Vec<T> {
        let mut res: Vec<T> = Vec::new();
        for _ in 0..n {
            for x in self {
                res.push(x.clone());
            }
        }
        res
    }
}

impl StrUtils for String {
    fn npop(&mut self, n: usize) -> Result<String, String> {
        let mut self_chars: Vec<char> = self.chars().collect();
        match self_chars.npop(n) {
            Ok(poped) => {
                *self = self_chars.into_iter().collect::<String>();
                Ok(poped.into_iter().collect::<String>())
            },
            Err(e) => {
                Err(e)
            }
        }
    }
    fn nget(&self, n: usize) -> Result<String, String> {
        let self_chars: Vec<char> = self.chars().collect();
        match self_chars.nget(n) {
            Ok(v) => {
                Ok(v.into_iter().collect::<String>())
            },
            Err(e) => {
                Err(e)
            }
        }
    }
    fn is_valid_range(&self, idx_a: usize, idx_b: usize) -> bool {
        let self_chars: Vec<char> = self.chars().collect();
        self_chars.is_valid_range(idx_a, idx_b)
    }
    fn get_range(&self, idx_a: usize, idx_b: usize) -> Result<String, String> {
        let self_chars: Vec<char> = self.chars().collect();
        match self_chars.get_range(idx_a, idx_b) {
            Ok(v) => {
                Ok(v.into_iter().collect::<String>())
            },
            Err(e) => {
                Err(e)
            }
        }
    }
    fn pop_range(&mut self, idx_a: usize, idx_b: usize) -> Result<String, String> {
        let mut self_chars: Vec<char> = self.chars().collect();
        match self_chars.pop_range(idx_a, idx_b) {
            Ok(poped) => {
                *self = self_chars.into_iter().collect::<String>();
                Ok(poped.into_iter().collect::<String>())
            },
            Err(e) => {
                Err(e)
            }
        }
    }
    fn mul(&self, n: usize) -> String {
        let mut res: String = String::new();
        for _ in 0..n {
            res.push_str(self);
        }
        res
    }
}

fn main() {
    print!("{}", solve(stdin!()));
}

/* TEMPLATE END */

fn solve(src: String) -> String {
    let mut res = String::from("");
    input!{
        source = src,
        s: String
    }
    eln!("###########################################");
    d!(s);
    eln!("-------------------------------------------");
    let mut s = s;
    let len = s.len();
    if len != 4 {
        return String::from("NA\n");
    }
    let top2 = s.pop_range(0, 2).unwrap();
    let extra = s;
    let mut top2_num = 0;
    let mut extra_num = 0;
    match top2.parse::<i32>() {
        Ok(num) => {
            top2_num = num;
        },
        Err(_) => {
            return String::from("NA\n");
        }
    }
    match extra.parse() {
        Ok(num) => {
            extra_num = num;
        },
        Err(_) => {
            return String::from("NA\n");
        }
    }
    let mut is_yymm = true;
    let mut is_mmyy = true;
    if top2_num > 12 {
        is_mmyy = false;
    }
    if extra_num > 12 {
        is_yymm = false;
    }
    if is_yymm && is_mmyy {
        return String::from("AMBIGUOUS\n");
    }
    if is_yymm {
        return String::from("YYMM\n");
    }
    if is_mmyy {
        return String::from("MMYY\n");
    }
    return String::from("NA\n");
}