{"raw_statement":[{"iden":"statement","content":"Peter likes to travel by train. He likes it so much that on the train he falls asleep.\n\nOnce in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.\n\nThe boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.\n\nAt the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.\n\nPeter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.\n\nPeter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours."},{"iden":"input","content":"The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.\n\nThe second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order."},{"iden":"output","content":"Output one of the four words without inverted commas:\n\n*   «_forward_» — if Peter could see such sequences only on the way from A to B;\n*   «_backward_» — if Peter could see such sequences on the way from B to A;\n*   «_both_» — if Peter could see such sequences both on the way from A to B, and on the way from B to A;\n*   «_fantasy_» — if Peter could not see such sequences."},{"iden":"examples","content":"Input\n\natob\na\nb\n\nOutput\n\nforward\n\nInput\n\naaacaaa\naca\naa\n\nOutput\n\nboth"},{"iden":"note","content":"It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B."}],"translated_statement":[{"iden":"statement","content":"彼得喜欢乘火车旅行。他非常喜欢火车，以至于在火车上他会睡着。\n\n有一次夏天，彼得从城市 A 乘火车前往城市 B，和往常一样，他睡着了。然后他醒来，透过窗户查看，发现每个火车站都有一个特定颜色的旗帜。\n\n男孩开始记忆他看到的旗帜颜色的顺序。但不久他又睡着了。不幸的是，他睡得不长，醒来后继续记忆颜色。然后他又睡着了，这一次一直睡到旅程结束。\n\n到站后，他向父母讲述了自己所做的事情，并写下了睡着前和睡着后看到的颜色序列。\n\n彼得的父母知道他们的儿子喜欢幻想。他们给你一个字符串，表示火车从 A 到 B 依次经过的车站的旗帜颜色，并让你判断彼得是否可能在从 A 到 B 的路上，或从 B 到 A 的路上看到这两个序列。请注意，彼得有两次清醒期。\n\n彼得的父母用小写拉丁字母表示颜色。相同的字母代表相同的颜色，不同的字母代表不同的颜色。\n\n输入数据包含三行。第一行包含一个非空字符串，长度不超过 #cf_span[105]，由小写拉丁字母组成——表示从 A 到 B 路线上车站的旗帜颜色。从 B 到 A 的路上，火车经过相同的车站，但顺序相反。\n\n第二行包含彼得在第一次清醒期记录的序列。第三行包含他在第二次清醒期记录的序列。两个序列均非空，由小写拉丁字母组成，每个序列长度不超过 100 个字母。每个序列均按时间顺序记录。\n\n请输出以下四个单词之一（不加引号）：\n\n假设火车始终在移动，因此每个旗帜只能被看到一次。车站 A 和 B 处没有旗帜。"},{"iden":"input","content":"输入数据包含三行。第一行包含一个非空字符串，长度不超过 #cf_span[105]，由小写拉丁字母组成——表示从 A 到 B 路线上车站的旗帜颜色。从 B 到 A 的路上，火车经过相同的车站，但顺序相反。第二行包含彼得在第一次清醒期记录的序列。第三行包含他在第二次清醒期记录的序列。两个序列均非空，由小写拉丁字母组成，每个序列长度不超过 100 个字母。每个序列均按时间顺序记录。"},{"iden":"output","content":"请输出以下四个单词之一（不加引号）：\n«_forward_» —— 如果彼得仅在从 A 到 B 的路上可能看到这两个序列；\n«_backward_» —— 如果彼得仅在从 B 到 A 的路上可能看到这两个序列；\n«_both_» —— 如果彼得在从 A 到 B 和从 B 到 A 的路上都可能看到这两个序列；\n«_fantasy_» —— 如果彼得不可能看到这两个序列。"},{"iden":"examples","content":"输入\natobab\n输出\nforward\n\n输入\naaacaa\naaacaa\n输出\nboth"},{"iden":"note","content":"假设火车始终在移动，因此每个旗帜只能被看到一次。车站 A 和 B 处没有旗帜。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ S \\in \\Sigma^* $ be the string representing the sequence of flag colours at stations along the route from A to B, where $ \\Sigma $ is the set of lowercase Latin letters.  \nLet $ P_1 \\in \\Sigma^* $ and $ P_2 \\in \\Sigma^* $ be the two non-empty sequences recorded by Peter during his two periods of wakefulness.\n\n**Constraints**  \n1. $ 1 \\leq |S| \\leq 10^5 $  \n2. $ 1 \\leq |P_1|, |P_2| \\leq 100 $  \n3. All strings consist solely of lowercase Latin letters.  \n4. Peter observes contiguous subsequences of $ S $ (in order) during each wakeful period, with no overlap and no revisiting of stations.  \n5. The two observed sequences $ P_1 $ and $ P_2 $ must appear as disjoint contiguous substrings of $ S $, in chronological order (i.e., $ P_1 $ occurs entirely before $ P_2 $).  \n6. Alternatively, $ P_1 $ and $ P_2 $ may appear as disjoint contiguous substrings of $ S^R $ (the reverse of $ S $), in chronological order.\n\n**Objective**  \nDetermine whether there exist indices $ i_1, j_1, i_2, j_2 \\in \\mathbb{Z} $ such that:  \n- $ 1 \\leq i_1 \\leq j_1 < i_2 \\leq j_2 \\leq |S| $,  \n- $ S[i_1:j_1] = P_1 $,  \n- $ S[i_2:j_2] = P_2 $,  \n\n**OR**\n\nThere exist indices $ i_1', j_1', i_2', j_2' \\in \\mathbb{Z} $ such that:  \n- $ 1 \\leq i_1' \\leq j_1' < i_2' \\leq j_2' \\leq |S| $,  \n- $ S^R[i_1':j_1'] = P_1 $,  \n- $ S^R[i_2':j_2'] = P_2 $.\n\nOutput:  \n- \"Yes\" if either condition holds,  \n- \"No\" otherwise.","simple_statement":null,"has_page_source":false}