eolymp
bolt
Try our new interface for solving problems
Məsələlər

Guess the Numbers

Guess the Numbers

John has never been very good at maths. Due to his bad grades, his parents have sent him to the Academic Coalition of Mathematics (ACM). Despite the large amount of money his parents are spending on the ACM, John does not pay much attention during classes. However, today he has begun to think about all the e ffort his parents are putting into his education, and he has started to feel somewhat... guilty. So he has made a decision: he is going to improve his maths grades! \includegraphics{https://static.e-olymp.com/content/83/834dce7fbcfe788e3eea5b3659e2fa798c7f804e.jpg} However, no sooner had he resolved to pay attention than the lesson ended. So the only thing he has been able to do is to hurriedly copy the content of the blackboard in his notebook. Today, the teacher was explaining basic arithmetic expressions with unknowns. He vaguely remembers that his classmates have been substituting values into the unknowns to obtain the expressions' results. However, in all the hurry, John has only written down expressions, values and results in a messy fashion. So he does not know which value comes with each unknown, or which result goes with each expression. That is the reason he needs your help: he wants to know, given an expression, some values and a result, whether it is possible or not to assign those values to the unknowns in order for the expression to evaluate to the given result. The particular assignment of values does not matter to John, as he wants to do it by himself. He only wants to know whether it is possible or not. \InputFile Each test case in the input le consists of two lines: \begin{itemize} \item The fi rst line contains a sequence of natural numbers. The first one (\textbf{1} ≤ \textbf{n} ≤ \textbf{5}) is the number of unknowns that will occur in the expression. It is followed by a sequence of \textbf{n} integers \textbf{v_1} ... \textbf{v_n} (\textbf{0} ≤ \textbf{v}_i ≤\textbf{ 50}), which are the values to be assigned to the unknowns. Finally, there is an integer \textbf{m} (\textbf{0} ≤ \textbf{m} ≤ \textbf{1000}) representing the desired result of the evaluation of the expression. \item The second line contains an arithmetic expression composed of lowercase letters (\textbf{a-z}), brackets (\textbf{(} and \textbf{)}) and binary operators (\textbf{+}, \textbf{-}, \textbf{*}). This expression will contain n unknowns, represented by \textbf{n} di fferent lowercase letters, without repetitions. The expression will not contain any blanks and will always be syntactically correct, i.e. it is just an unknown or has the form (\textbf{e_1 op e_2} ), where \textbf{e_1} and \textbf{e_2} are expressions and \textbf{op} is one of the three possible binary operators. \end{itemize} The input will finish with a dummy test case of just one line containing \textbf{0 0}, which must not be processed. \OutputFile For each test case, print a single line with \textbf{YES} if there exists an assignment of the values \textbf{v_1} ... \textbf{v_n} to the unknowns such that the expression evaluates to \textbf{m}, and \textbf{NO} otherwise. Notice that each value \textbf{v_i} must be assigned to exactly one unknown.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
3 2 3 4 14
((a+b)*c)
2 4 3 11
(a-b)
1 2 2
a
0 0
Çıxış verilənləri #1
YES
NO
YES