Factorial Products

For the purpose of this problem, we will define a “factorial product” to be a multiplication of several factorials of single digit numbers. For example, the expression 5! * 3! * 4! * 3! is a product of four factorials, where each factorial is generated by a single digit. Given two factorial products, are they equal? Input The input will contain multiple test cases (at most 450). Each case starts with two integers N and M on a line (1 ≤ N, M ≤ 1, 000), the number of factors in each factorial product. The next line contains N digits, each digit being between 0 and 9 inclusive, specifying the generators of the N factorial factors in the first product. The third line contains M digits, also between 0 and 9, specifying the generators of the M factorial factors in the second product. Forinstance5! *3! *4! *3! wouldbegivenas‘5 3 4 3’. Input will end with a line containing two zeroes. Output For each expression print on a separate line either ‘YES’ or ‘NO’, the answer to the question “Are the two factorial products equal?” Sample Input 11 9 9 12 5 36 00 Sample Output YES NO