Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб. Question by Ilir Capuni.
Moon algebra
We are given the set {a, b, c} on which
we define the following binary operations:
a * a = b |
a * b = b |
a * c = a |
b * a = c |
b * b = b |
b * c = a |
c * a = a |
c * b = c |
c * c = c |
Question:
We are given an expression containing N terms
from the above set and * between each. Check
if it is possible to place () such that the
result of the expression evaluates to a.
Input specification
An integer denoting N on the first line and the
expression on the second where 1 ≤ N ≤ 10.
Output specification
Print "Yes" or "No", if there is a way.
(No, resp., there is no way) to place the ()
such that the expression evaluates to a.
Sample Input I
4
a * c * c * b
|
Sample Input II
3
a * b * b
|
Sample Input III
4
c * b * a * c
|
Sample Output I
Yes
|
Sample Output II
No
|
Sample Output III
Yes
|
Explanation I
(a*c)*(c*b)=a*c=a
|
Explanation II
(a * b) * b = b, a*(b*b) = b
|
Explanation III
(c*b)*(a*c)
|
Для отправки решений необходимо выполнить вход.
|