CF1685B Linguistics

题目描述

Alina 发现了一种只由 $\text{A, B, AB, BA}$ 四种单词组成的语言,这种语言不含有空格,书写句子时只需要将单词直接连接起来即可。 她很好奇是否可以用 $a$ 个 $\text{A}$,$b$ 个 $\text{B}$,$c$ 个 $\text{AB}$,$d$ 个 $\text{BA}$ 拼接形成句子 $s$。 换句话说,是否可以用 $a+b+c+d$ 个单词以某种顺序拼接出句子 $s$,这 $a+b+c+d$ 个单词都得被用到,他们的顺序可以由你决定。

输入格式

输出格式

说明/提示

In the first test case, the sentence $ s $ is $ \texttt{B} $ . Clearly, it can't consist of a single word $ \texttt{A} $ , so the answer is $ \texttt{NO} $ . In the second test case, the sentence $ s $ is $ \texttt{AB} $ , and it's possible that it consists of a single word $ \texttt{AB} $ , so the answer is $ \texttt{YES} $ . In the third test case, the sentence $ s $ is $ \texttt{ABAB} $ , and it's possible that it consists of one word $ \texttt{A} $ , one word $ \texttt{B} $ , and one word $ \texttt{BA} $ , as $ \texttt{A} + \texttt{BA} + \texttt{B} = \texttt{ABAB} $ . In the fourth test case, the sentence $ s $ is $ \texttt{ABAAB} $ , and it's possible that it consists of one word $ \texttt{A} $ , one word $ \texttt{AB} $ , and one word $ \texttt{BA} $ , as $ \texttt{A} + \texttt{BA} + \texttt{AB} = \texttt{ABAAB} $ . In the fifth test case, the sentence $ s $ is $ \texttt{BAABBABBAA} $ , and it's possible that it consists of one word $ \texttt{A} $ , one word $ \texttt{B} $ , two words $ \texttt{AB} $ , and two words $ \texttt{BA} $ , as $ \texttt{BA} + \texttt{AB} + \texttt{B} + \texttt{AB} + \texttt{BA} + \texttt{A}= \texttt{BAABBABBAA} $ .