CF1149B Three Religions

Description

During the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution of each of these beliefs, and you now wonder if the followers of each religion could coexist in peace. The Word of Universe is a long word containing the lowercase English characters only. At each moment of time, each of the religion beliefs could be described by a word consisting of lowercase English characters. The three religions can coexist in peace if their descriptions form disjoint subsequences of the Word of Universe. More formally, one can paint some of the characters of the Word of Universe in three colors: $ 1 $ , $ 2 $ , $ 3 $ , so that each character is painted in at most one color, and the description of the $ i $ -th religion can be constructed from the Word of Universe by removing all characters that aren't painted in color $ i $ . The religions however evolve. In the beginning, each religion description is empty. Every once in a while, either a character is appended to the end of the description of a single religion, or the last character is dropped from the description. After each change, determine if the religions could coexist in peace.

Input Format

N/A

Output Format

N/A

Explanation/Hint

In the first example, after the 6th evolution the religion descriptions are: ad, bc, and ab. The following figure shows how these descriptions form three disjoint subsequences of the Word of Universe: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1149B/d2161037f06cd41962d7459e510bbcc1eef61be4.png)