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 C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;


class Program
{
    public static double Jacc(HashSet<int> A,HashSet<int> B) {
        HashSet<int> tmp = new HashSet<int>();
        foreach (int e in A) tmp.Add(e);
        foreach (int e in B) tmp.Add(e);

        double OR_len = tmp.Count();
        double AND_len = A.Count() + B.Count() - OR_len;

        return AND_len / OR_len;
    }

    static void Main(string[] Args) {

        string S;
        S = ReadLine();

        int _a = int.Parse(S.Substring(0, 2));
        int _b = int.Parse(S.Substring(2, 2));

        bool a = (_a != 0) && (_a <= 12);
        bool b = (_b != 0) && (_b <= 12);

        if (a && b)
            WriteLine("AMBIGUOUS");
        else if (a && !b)
            WriteLine("MMYY");
        else if (!a && b)
            WriteLine("YYMM");
        else if(!a && !b)
            WriteLine("NA");



        ProgramEndPointLabel:;
        ReadLine();
    }




    class MyList<T> : List<T>
    {
        public override bool Equals(object obj) {
            List<T> obj_ = (List<T>)obj;
            if (this.Count != obj_.Count) return false;
            for (int i = 0; i < this.Count(); i++) {
                if (!this[i].Equals(obj_[i])) {
                    //WriteLine(this[i].Equals(obj_[i]));
                    //WriteLine(string.Format("this[{0}] = {1},obj_[{0}] = {2}", i, this[i], obj_[i]));
                    return false;
                }
            }
            return true;
        }
        public override int GetHashCode() {
            return base.GetHashCode();
        }
        //public static implicit operator MyList<T> (List<T> obj) {
        public static MyList<T> conv(List<T> obj) {
            MyList<T> res = new MyList<T>();
            foreach (T e in obj) res.Add(e);
            return res;
        }
        public MyList<T> Copy() {
            MyList<T> res = new MyList<T>();
            foreach(T e in this)
                res.Add(e);
            return res;
        }
    }

    static MyList<MyList<int>> GetIndex(MyList<Tuple<int,char,int>> Dict,int Count) {
        if(Count == 0) {
            MyList<MyList<int>> res = new MyList<MyList<int>>();
            MyList<int> res_ = new MyList<int>();
            res_.Add(-1);
            res.Add(res_);
            return res;
        }
        MyList<MyList<int>> res_indexes = new MyList<MyList<int>>();
        for(int i = 0;i < Dict.Count(); i++) {
            MyList<Tuple<int,char,int>> clone = Dict.Copy();
            clone.RemoveAt(i);
            MyList<MyList<int>> res = GetIndex(clone, Count - 1);
            MyList<int> temporary = new MyList<int>();
            foreach(MyList<int> ele in res) {
                temporary = new MyList<int>();
                temporary.Add(Dict[i].Item1);
                foreach(int ele_s_ele in ele) {
                    temporary.Add(ele_s_ele);
                }
                temporary.Sort();
                if(!res_indexes.Contains(temporary))
                    res_indexes.Add(temporary);
            }
        }
        
        //res_indexes = MyList<MyList<int>>.conv(res_indexes.Distinct().ToList());

        for (int i = 0; i < res_indexes.Count; i++)
            res_indexes[i].Remove(-1);
                
        return res_indexes;
    }

    static int div2(Dictionary<char,int> Dict,char without,int count) {
        if (count == 0) return 1;
        Dictionary<char, int> Dict_Copyed;
        Clone(Dict,out Dict_Copyed);
        Dict_Copyed.Remove(without);
        //foreach(var e in Dict_Copyed) 
        //    WriteLine(e.Key + ":" + e.Value + " ");
        //line();
        int result = 0;
        foreach(var e in Dict_Copyed) {
            result += div2(Dict_Copyed, e.Key, count - 1) * e.Value;
        }
        return result;
    }

    static void line() { WriteLine(); }

    static int kaizyo(int x) {
        int res = 1;
        for (int i = 1; i <= x; i++) res *= i;
        return res;
    }

    static void Clone(Dictionary<char,int> ori,out Dictionary<char,int> tar) {
        tar = new Dictionary<char, int>();
        foreach (KeyValuePair<char,int> e in ori)
            tar.Add(e.Key,e.Value);
    }

    static int div(Dictionary<char, int> _Dict,char without,int count) {
        if (count == 0) return 1;
        Dictionary<char, int> Dict = new Dictionary<char, int>();
        foreach (KeyValuePair<char,int> c in _Dict)
            Dict.Add(c.Key,c.Value);
        Dict.Remove(without);
        int Result = 0;
        foreach (KeyValuePair<char, int> c in Dict) {
            Result += div(Dict, c.Key, count - 1) * c.Value;
        }
        return Result;
    }

    static int C(int x,int y) {
        int Result = 1;
        for(int count = 0;count < y; count++)
            Result *= (x - count);
        for (int count = 0;count < y; count++)
            Result /= (y - count);
        return Result;
    }
}