Description

Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.

At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more.

Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order.

Input

The first line contains a non-empty word s. The second line contains a non-empty word t. Words s and t are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters.

Output

In the single line print the answer to the problem. Print "need tree" (without the quotes) if word s cannot be transformed into word t even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem.

It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton.

Sample Input

Input
automaton
tomat
Output
automaton
Input
array
arary
Output
array
Input
both
hot
Output
both
Input
need
tree
Output
need tree

Hint

In the third sample you can act like that: first transform "both" into "oth" by removing the first character using the suffix automaton and then make two swaps of the string using the suffix array and get "hot".

#include <iostream>
#include <cstring>
using namespace std; int main()
{
char s[],t[];
int as[],at[],flag;
while(cin>>s>>t)
{
flag=;
memset(as,,sizeof(as));
memset(at,,sizeof(at));
int lens,lent;
lens=strlen(s);
lent=strlen(t);
for(int i=;i<lens;i++)
as[s[i]-'a']++;
for(int i=;i<lent;i++)
at[t[i]-'a']++;
for(int i=;i<;i++)
if(as[i]>=at[i])
continue;
else {flag=; break; }
if(flag==)
{
if(lens==lent)
cout<<"array"<<endl;
else
{
int r=;
for(int i=,j=;i<lens;i++)
{
if(s[i]==t[j])
j++;
if(j==lent)
{
r=;break;
}
}
if(r) cout<<"automaton"<<endl;
else cout<<"both"<<endl;
}
}
else
{
cout<<"need tree"<<endl;
}
}
return ;
}
#include <iostream>
#include <cstring>
using namespace std; int main()
{
char s[],t[];
int as[],at[],flag;
while(cin>>s>>t)
{
flag=;
memset(as,,sizeof(as));
memset(at,,sizeof(at));
int lens,lent;
lens=strlen(s);
lent=strlen(t);
for(int i=;i<lens;i++)
as[s[i]-'a']++;
for(int i=;i<lent;i++)
at[t[i]-'a']++;
for(int i=;i<;i++)
if(as[i]>=at[i])
continue;
else {flag=; break; }
if(flag==)
{
if(lens==lent)
cout<<"array"<<endl;
else
{
int r=;
for(int i=,j=;i<lens;i++)
{
if(s[i]==t[j])
j++;
if(j==lent)
{
r=;break;
}
}
if(r) cout<<"automaton"<<endl;
else cout<<"both"<<endl;
}
}
else
{
cout<<"need tree"<<endl;
}
}
return ;
}

Codeforces Round #256 (Div. 2) B Suffix Structures的更多相关文章

  1. Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)

    题目链接:http://codeforces.com/contest/448/problem/B --------------------------------------------------- ...

  2. Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)

    解题报告 四种情况相应以下四组数据. 给两字符串,推断第一个字符串是怎么变到第二个字符串. automaton 去掉随意字符后成功转换 array 改变随意两字符后成功转换 再者是两个都有和两个都没有 ...

  3. Codeforces Round #256 (Div. 2) 题解

    Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standar ...

  4. Codeforces Round #256 (Div. 2)

    A - Rewards 水题,把a累加,然后向上取整(double)a/5,把b累加,然后向上取整(double)b/10,然后判断a+b是不是大于n即可 #include <iostream& ...

  5. Codeforces Round #256 (Div. 2) B

    B. Suffix Structures Bizon the Champion isn't just a bison. He also is a favorite of the "Bizon ...

  6. Codeforces Round #256 (Div. 2) B (448B) Suffix Structures

    题意就是将第一个字符串转化为第二个字符串,支持两个操作.一个是删除,一个是更换字符位置. 简单的字符串操作!. AC代码例如以下: #include<iostream> #include& ...

  7. Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)

    转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...

  8. Codeforces Round #256 (Div. 2) A. Rewards

    A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  9. Codeforces Round #256 (Div. 2) D. Multiplication Table 二分法

     D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input st ...

随机推荐

  1. git的入门使用操作

    Git html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,addres ...

  2. 闹心的python编码

    说起编码,真是十分忧伤.每次听课都是绕了半天把自己搞糊涂.今天特意来整理一下思路. What 编码!? 基本概念很简单.首先,我们从一段信息即消息说起,消息以人类可以理解.易懂的表示存在.我打算将这种 ...

  3. CUDA开发存储器运用(包括存储器之间的转存)

    主机端内存(host memory) 主机端叶锁定内存(pinned memory) 显存 寄存器(register) 局部存储器(local memory) 共享存储器(shared memory) ...

  4. USACO 3.3 TEXT Eulerian Tour中的Cows on Parade一点理解

    Cows on Parade Farmer John has two types of cows: black Angus and white Jerseys. While marching 19 o ...

  5. crontab 添加sh文件定时

    (1)编写sh文件,比如/orcl/test/export.sh 编写crond文件 chmod 755 /orcl/test/*      //复制所有权限 [root@postest test]# ...

  6. Jquery几秒自动跳转

    $(document).ready(function() { function jump(count) { window.setTimeout(function(){ count--; if(coun ...

  7. openwrt 添加 应用(luci-application)

    openwrt 添加应用的几个步骤如下: (1)在目录 ./feeds/luci/applications 下添加要增加的应用,譬如 "luci-test" (2)里面应该包含以下 ...

  8. UltimateDefrag磁盘碎片整理软件 v3.0.100.19汉化版

    软件名称:UltimateDefrag磁盘碎片整理软件 v3.0.100.19汉化版软件类别:汉化软件运行环境:Windows软件语言:简体中文授权方式:免费版软件大小:3.25 MB软件等级:整理时 ...

  9. robotium如何定位控件?

    search类获取当前所有的view,然后根据类型或者文本去筛选,找到view后获取坐标,然后点击坐标.本质都是通过坐标点击.solo.clickonScreen方法,底层调用MotionEvent类 ...

  10. ubuntu enable all Ubuntu software (main universe restricted multiverse) repositories use

    sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe ...