#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <string>
#include <cstdlib>
#include <memory>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <limits.h>
#include <set>
#include <stdio.h>
#include <tgmath.h>
#include <bitset>
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector <int>
//#define ii pair <int, int>
//#define vii vector < ii >
#define vll vector <ll>
#define hash1 10000000000000061ll
#define MA(a,b) ((a)>(b)?(a):(b))
#define MI(a,b) ((a)<(b)?(a):(b))
#define AB(a) (-(a)<(a)?(a):-(a))
#define na(x) ((x)<P?(x):(x)-P)
#define f first
#define se second
using namespace std;

int digitcount(int n){
	int result = 0;
	for(int i = n; i > 0; i /= 10){
		result++;
	}
	return result;
}

int power(int a, int b){
	if(b==0)return 1;
	if(b==1) return a;
	return a * power(a,b-1);
}

bool pal(string str){
	for(int i=0; i < str.size()/2; i++){
		if(str[i] != str[str.size()-1-i]) return false;
	}
	return true;
}

int main(){
	string str, t;
	cin >> str >> t;
	string tempStr = str;
	string tempT = t;
	char arrS[26], arrT[26];
	for(int i = 0; i < 26; i++){
		arrS[i]=0; arrT[i]=0;
	}
	sort(str.begin(),str.end());
	sort(t.begin(),t.end());
	if(str==t){
		cout << "array" << endl; exit(0);
	}
	for(int i = 0; i < str.size(); i++){
		arrS[str[i]-'a']++;
	}
	for(int i = 0; i < t.size(); i++){
		arrT[t[i]-'a']++;
	}
	for(int i = 0; i < 26; i++){
		if(arrT[i]>arrS[i]){
			cout << "need tree" << endl; exit(0);
		}
	}
	int j = 0;
	int k = 0;
	for(; k < tempStr.size(); ){
		for(; j < tempT.size(); ){
			if(tempStr[k]==tempT[j]) {
				k++;
				j++;
			} else {
				k++;
			}
			if(j == tempT.size()){
				cout << "automaton" << endl; exit(0);
			}
			if(k >= tempStr.size()) {
				cout << "both" << endl; exit(0);
			}
		}
	}
}

#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

bool autoo(string y,string x)
{
    int ind=0;
    for(int i=0;i<y.size();i++)
    {
        if( y[i]==x[ind] ){ ind++; }
        if( ind==x.size() ){return 1;}
    }
    return 0;
}

bool arr(string y,string x)
{
    for(int i=0;i<x.size();i++)
    {
        if(y.find(x[i])==-1){return 0;}
        y[ y.find(x[i]) ]='.';
    }
    return 1;
}

int main()
{
    IO
    string x,y;
    cin>>x>>y;
    if( x.size()<y.size() ){cout<<"need tree";}
    else if( (autoo(x,y) )){cout<<"automaton";}
    else if( arr(x,y) && x.size()==y.size() ){cout<<"array";}
    else if( arr(x,y) ){cout<<"both";}
    else{ cout<<"need tree"; }
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

string s, t;
short c_arr_of_s[27];
short c_arr_of_t[27];
void c_arr() {

	for (int i = 0; i < 27; i++) {
		c_arr_of_s[i] = 0;
		c_arr_of_t[i] = 0;
	}

	for (int i = 0; i < s.size(); i++) c_arr_of_s[s[i] - 'a' + 1]++;
	for (int i = 0; i < t.size(); i++) c_arr_of_t[t[i] - 'a' + 1]++;
}

int main() {
	bool automaton=false, array=false;
	cin >> s >> t;
	if (s.size() > t.size()) {
		automaton = true;
		c_arr();
		for (int i = 1; i < 27; i++) {
			if (c_arr_of_s[i] < c_arr_of_t[i] && c_arr_of_t[i]>0) {
				automaton = false;
				break;
			}
		}
		if (automaton == true) { // check if we need array after removing or not?
			array = true;
			int i_s, i_t=0;
			for (i_s = 0; i_s < s.size(); i_s++) { // check if the word s is in the correct order according to t
				if (s[i_s] == t[i_t] && i_t < t.size()) i_t++;
			}
			if (i_t == t.size()) array = false;
		}
	}
	if (s.size() == t.size()) {
		array = true;
		c_arr();
		for (int i = 1; i < 27; i++) if (c_arr_of_s[i] != c_arr_of_t[i]) {
			array = false;
			break;
		}
	}
	if (automaton == true && array == true) cout << "both" << endl;
	else if (automaton == true ) cout << "automaton" << endl;
	else if (array == true) cout << "array" << endl;
	else cout << "need tree" << endl;
	return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

bool array(string a, string b)
{
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    return a == b;
}

bool automaton(string a, string b)
{
    int n = 0;
    for (int i = 0; i < a.length() and n < b.length(); i++) n += a[i] == b[n];
    return n == b.length();
}

bool both(string a, string b)
{
    for (int i = 0; i < b.length(); i++)
    {
        int p = a.find(b[i]);
        if (p == -1) return false;
        a[p] = '0';
    }
    return true;
}

int main()
{
    string a, b;
    cin >> a >> b;
    if (array(a, b)) cout << "array" << endl;
    else if (automaton(a, b)) cout << "automaton" << endl;
    else if (both(a, b)) cout << "both" << endl;
    else cout << "need tree" << endl;
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll flag=1,n,m,f;
	string s,t;
	map<char,int>m1,m2;
	cin>>s>>t;
	n=s.size();m=t.size();
	for(int i=0;i<n;i++){
		m1[s[i]]++;
	}
	for(int i=0;i<m;i++){
		m2[t[i]]++;
	}
	for(int i=0;i<m;i++){
		if(m1[t[i]]<m2[t[i]]){
			cout<<"need tree";
			return 0;
		}
	}
	for(int i=0;i<m;i++){
		if(m1[t[i]]>m2[t[i]]){
			flag=0;
			break;
		}
	}
		if(flag&&m==n)
			cout<<"array";
		else{
	f=0;
	for(int i=0;i<n;i++){
		if(f<m&&s[i]==t[f])
			++f;
	}
	if(f==m)
		cout<<"automaton";
	else
		cout<<"both";
	return 0;
}
}

#include <bits/stdc++.h>
using namespace std;

bool can1(string foo, string bar) {
    map<char, int> mp;
    for (int i = 0; i < foo.size(); i++)
        mp[foo[i]]++;
    for (int i = 0; i < bar.size(); i++)
        mp[bar[i]]--;
    for (char ch = 'a'; ch <= 'z'; ch++)
        if (mp[ch] < 0)
            return 0;
    if (mp[' '] < 0)
        return 0;
    return 1;
}

int main() {
    string foo, bar;
    cin >> foo >> bar;
    if (foo.size() < bar.size() || !can1(foo, bar)) {
        puts("need tree");
        return 0;
    }
    if (foo.size() == bar.size()) {
        puts("array");
        return 0;
    }
    for (int i = 0; i < foo.size(); i++) {
        int idx = 0, ii = i;
        while (ii < foo.size() && idx < bar.size() && bar[idx] == foo[ii])
            idx++, ii++;
        if (idx == bar.size()) {
            puts("automaton");
            return 0;
        }
    }
    int lastindex = 0, checks = 0;
    for (int i = 0; i < bar.size(); i++) {
        bool flag = 0;
        for (int j = lastindex; j < foo.size(); j++)
            if (foo[j] == bar[i]) {
                flag = 1, lastindex = j + 1;
                break;
            }
        checks += flag;
    }
    if (bar.size() < foo.size() && checks == bar.size()) {
        puts("automaton");
        return 0;
    }
    puts("both");
    return 0;
}

#include<bits/stdc++.h>

typedef long long int ll;
#define pp pair<ll,ll>
#define dbg printf("xxxx");
#define inf 1000000000000
#define max2(a,b) ((a<b)?b:a)
#define max3(a,b,c) max2(max2(a,b),c)
#define min2(a,b) ((a>b)?b:a)
#define min3(a,b,c) min2(min2(a,b),c)

using namespace std;

int main()
{
    //freopen("in.txt","r",stdin);
    ll i,j,k;
    bool automation=false;
    string a,b;
    map<char,ll> xb;map<char,ll> xa;

    cin>>a>>b;
    string ba,bb,cc;

    //array
    ba=a;bb=b;
    sort(ba.begin(),ba.end());
    sort(bb.begin(),bb.end());

    if(ba==bb)
    {
        cout<<"array";
        return 0;
    }

    //automation
    j=0;
    for(i=0;i<a.length();i++)
    {
        if(j==b.length())
            break;

        if(a[i]==b[j])
        {
            cc.push_back(a[i]);
            j++;
        }
    }
//cout<<cc<<endl;
    if(cc==b)
    {
        cout<<"automaton";return 0;
    }

    //if automation is false, there might be a chance to be the answer to be both
    ba="";bb=b;
    for(i=0;i<b.length();i++)
        xb[b[i]]++;

    for(i=0;i<a.length();i++)
        xa[a[i]]++;

    bool f=true;
    map<char,ll>::iterator p=xb.begin();
    while(p!=xb.end())
    {
        if(xa[p->first]<p->second)
        {
            f=false;
            break;
        }

        p++;
    }

    if(f)
    {
        cout<<"both";
        return 0;
    }

    cout<<"need tree";

    return 0;
}

#include <cstdio>
#include <iostream>
#include <vector>

int main(){

    std::string first; getline(std::cin, first);
    std::string second; getline(std::cin, second);

    int index = 0;
    for(int p = 0; p < first.size(); p++){
        if(first[p] == second[index]){++index;}
    }

    if(index >= second.size()){puts("automaton");}
    else{

        const int N = 26;
        std::vector<int> countVec(N,0);

        for(int p = 0; p < first.size(); p++){++countVec[first[p] - 'a'];}
        for(int p = 0; p < second.size(); p++){--countVec[second[p] - 'a'];}
        bool array(1), tree(0);
        for(int p = 0; p < N; p++){
            if(countVec[p] != 0){array = 0;};
            if(countVec[p] <  0){tree = 1; break;}
        }

        if(array){puts("array");}
        else if(!tree){puts("both");}
        else{puts("need tree");}
    }

    return 0;
}

// ~/BAU/ACM-ICPC/Teams/Rampage/Abukhadijah
#include <functional>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include<complex>
#include <unordered_map>
#include<unordered_set>
#include <numeric>
#include <string>
#include<iostream>
#include <fstream>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include<cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-11;
const ll MOD = 1000000007;
const int N = 109;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
void fast()
{
	std::ios_base::sync_with_stdio(0);
}
// ~/Remember,remember the 6th of March.
int alf[26][2];
int main()
{
	string s1, s2;
	cin >> s1 >> s2;
	if (s1.length() < s2.length())
	{
		puts("need tree");
		return 0;
	}
	for (int i = 0; i < s1.length(); i++)
	{
		alf[s1[i] - 'a'][0]++;
	}
	for (int i = 0; i < s2.length(); i++)
	{
		alf[s2[i] - 'a'][1]++;
	}
	for (int i = 0; i < 26; i++)
	{
		if (alf[i][0] < alf[i][1])
		{
			puts("need tree");
			return 0;
		}
	}
	if(s1.length()==s2.length())
	{
		puts("array");
		return 0;
	}
	int last = 0;
	bool flag = 1;
	for (int i = 0; i < s2.length();last++, i++)
	{
		last = s1.find(s2[i], last);
		if (last == -1)
		{
			flag = false;
			break;
		}
	}
	if (flag)
	{
		puts("automaton");
		return 0;
	}
	else
	{
		puts("both");
	}
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
#include <complex>

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
#define fr(a, b, c) for(int a = b; a >= c; a--)
#define all(a) a.begin(), a.end()
#define vll vector<ll>
#define vld vector<ld>
#define vi vector<int>
#define vs vector<string>
#define pll pair<ll,ll>
#define pld pair<ld, ld>
#define vpll vector<pll>
#define vpld vector<pld>

#define vp vector<point>
#define pi acos(-1)
#define point complex<ld>

using namespace std;

const ll mod = 1e9 + 7;

ll fact[1000001]; ll inv[1000001];
ll primes[100007];
ll arr[1000007];
ll modPower(ll b, ll p) {
    if (p == 0)
        return 1;

    ll halfpow = modPower(b, p / 2);
    ll toReturn = (halfpow * halfpow) % mod;
    if (p % 2)
        toReturn = (toReturn * b) % mod;

    return toReturn;
}

ll fastPower(ll b, ll p) {
    if (p == 0)
        return 1;
    ll ans = fastPower(b, p / 2);
    ans = (ans * ans);
    if (p % 2 != 0)
        ans = (ans * b);
    return ans;
}
ll GcdRecursive(ll a, ll b) {
    if (b == 0) return a;
    return GcdRecursive(b, a % b);
}
ll modLCM(ll a, ll b) {
    ll val = GcdRecursive(a, b);
    ll tmp = ((a % mod) * (b % mod)) % mod;
    ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
    return finalVal;

}
ll LCM(ll a, ll b) {
    return (a * b) / GcdRecursive(a, b);
}
void move1step(ll& a, ll& b, ll q) { // a and b by reference
    ll c = a - q * b;
    a = b;
    b = c;
}
ll GcdIterative(ll a, ll b) {
    while (b) move1step(a, b, a / b);
    return a;
}

void pre(ll n) {

    fact[0] = 1;
    inv[0] = 1;

    for (ll i = 1; i <= n; i++) {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = modPower(fact[i], mod - 2);
        arr[i] = modPower(i, mod - 2);
    }
}

ll npr(ll n, ll r) {
    return ((fact[n] * inv[n - r]) % mod);
}

ll ncr(ll n, ll r) {
    return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
}

void sieve(ll val) {
    memset(primes, 1, sizeof primes);
    primes[0] = primes[1] = false;
    for (int i = 2; i <= val; i++) {
        if (primes[i]) {
            for (int j = i * i; j <= val; j += i) {
                primes[j] = 0;
            }
        }
    }

}

ld dot(point a, point b) {
    return (conj(a) * b).real();
}
ld cross(point a, point b){
    return (conj(a) * b).imag();
}
//length of vector is abs(complex)
//hypot(3, 4) returns 5
//arg(3, 3) * 180 / pi returns angle between vector and x-axis
//point a(2, 3), b(4, 2);  (b - a) return vector between two points
//a *= polar(1.0, - pi / 45) rotates by 45 degrees clockwise about origin
//to rotate about a point, minus it from my origin a = (a - b) * polar(1.0, pi) + b
ld angleBetVec(point a, point b){
    ld d = dot(a, b);
    d/= abs(a);
    d/= abs(b);
    //now i have cos of angle in rad
    return  acos(d) * 180 / pi;
}

point RotateAbout(point a, point about, ld angle){
    return (a - about) * polar((ld)1.0, angle) + about;
}
//atan2 returns angle between vec and x axis atan2(a.imag(), a.real())

const ll MOD = 998244353;
//const ll mod = 1e9 + 7;
const ll N = 1e5 + 7;
const ll inf = 1e18 + 5;

string s,t;

int main() {
    MohamedMotaz

    cin >> s >> t;

    map<char, ll> first, second;
    for(auto e: s) first[e]++;
    for (auto e: t) second[e]++;

    //check if need true;
    bool d = false;
    for (auto e: second) if (first[e.first] < e.second) d = true;
    if (d) return cout << "need tree", 0;

    //check if array
    bool a = false;
    ll c = 0;
    ll tt = 0;
    f(i, 0, t.size()){
        bool d = false;
        for (; tt < s.size(); tt++){
            if (t[i] == s[tt]) {d = true; tt++; break;}
        }
        if (!d) {
            a = true;
            break;
        }
    }
    //cout << c << endl;
    //if (c == t.size()) a = false;

    //check if automaton
    bool au = false;
    for (auto e: s) if (first[e] > second[e]) au = true;

    if (au && a) return cout << "both", 0;
    if (au) return cout << "automaton", 0;
    if (a) return cout << "array", 0;

}

#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<climits>
#include<vector>
using namespace std;
#define f(x,y,i) for(int i = x;i < y; i++)
#define F(x,y,i) for(int i = x; i <= y; i++)
#define lson pos<<1,l,mid
#define rson pos<<1|1,mid+1,r
#define sc(n) scanf("%d",&n)
#define pr(n) printf("%d\n",n)
#define met(n,m) memset(n, m, sizeof(n))
const int N=5000;

char s[N];
char s1[N];
int a[N];
int b[N];
int main()
{
	int a1,a2,a3,b1,b2,b3;
	int n;
	while(~scanf("%s",s))
	{
		met(a,0);
		met(b,0);
		scanf("%s",s1);
		int len1=strlen(s);
		int len2=strlen(s1);
		f(0,len1,i)
		{
			a[s[i]-'a']++;
		}
		f(0,len2,i)
		{
			b[s1[i]-'a']++;
		}
		int temp = 1 ,cnt;
		f(0,30,i)
		{
			if(b[i]>a[i])
			{
				temp=0;
				break;
			}
			 if(a[i] > b[i])
			{
				temp = 2;
			}
		}

		if(temp)
		{
			if(temp==2)
			{
				temp=0;cnt =0;
				for(int i =0 ;i < len1; i++)
				{
					 if(s1[cnt]==s[i])cnt++;
					  if(cnt == len2)
					  {
  						temp = 1;
  						break;
  					}

				}

				if(!temp)printf("both\n");
				else printf("automaton\n");
			}
			else printf("array\n");
		}
		else
		{
		 printf("need tree\n");
		}

	}

	return 0;
}

#include <cstdio>
#include <cstring>
using namespace std;

char a[200];
char b[200];

int ca[26];
int cb[26];

bool issubseq(char *c, char *d) {
	while (1) {
		if (*c == '\0') {
			return true;
		}
		if (*d == '\0') {
			return false;
		}
		while (*d != *c) {
			if (*d == '\0') return false;
			d++;
		}
		c++;
		d++;
	}
}

void rush() {
	scanf("%s",a);
	scanf("%s",b);
	int la = strlen(a);
	int lb = strlen(b);
	memset(ca,0,sizeof(ca));
	for (int i = 0; a[i] != '\0'; i++) {
		ca[a[i]-'a'] ++;
	}
	for (int j = 0; b[j] != '\0'; j++) {
		ca[b[j]-'a']--;
	}
	bool subseq;
  if (la < lb) {
    printf("need tree");
    return;
  }
	if (la > lb) {
		subseq = issubseq(b,a);
	} else {
		subseq = false;
	}

	if (subseq) {
		printf("automaton");
		return;
	}

	bool plus=false;
	bool minus = false;
	for (int i = 0; i < 26; i++) {
		plus = plus || (ca[i] > 0);
		minus = minus || (ca[i] < 0);
	}
	if (plus && minus) {
		printf("need tree");
	} else if (plus || minus) {
		printf("both");
	} else {
		printf("array");
	}

}

int main() {
	rush();
  putchar('\n');
	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <memory.h>
using namespace std;
typedef long long ll;

const int N = 1e5+5;

int cnt[30];
char s[N], t[N];

void solve(){
    scanf("%s%s",&s,&t);
    int n = strlen(s);
    int m = strlen(t);

    memset(cnt, 0, sizeof cnt);

    bool sau = false;
    for(int i=0,j=0; i<n; ++i){
        if(j<m && s[i]==t[j]) ++j;
        if(j==m) sau = true;
    }

    for(int i=0;i<n;++i) cnt[s[i]-'a']++;
    for(int i=0;i<m;++i) cnt[t[i]-'a']--;

    bool sar = true;
    bool all = true;

    for(int i=0;i<26;++i){
        sar&=cnt[i]==0;
        all&=cnt[i]>=0;
    }

    if(sau) cout<<"automaton"<<endl; else
    if(sar) cout<<"array"<<endl; else
    if(all) cout<<"both"<<endl; else
    cout<<"need tree"<<endl;
}

int main(){
    //freopen("input.txt","r",stdin);// freopen("output.txt","w",stdout);

    solve();

    return 0;
}

// was totally bluffed in substring and subsequence

#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <climits>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <iterator>
#include <string>

using namespace std;

typedef long long int64;

#define mp make_pair
#define pb push_back
#define ms0(x) memset(x,0,sizeof(x));
#define ms1(x) memset(x,-1,sizeof(x));

#define mod 1
#define EPS 1e-8

//------------------------------------------------------------------------//

char str1[102],str2[102];
int cnt1[30],cnt2[30];

int find_subs(int st1,int st2){
    for(int i=st1;i<strlen(str1);i++){
        if(str1[i]==str2[st2]){
            if(st2==strlen(str2)-1) return 1;
            else return find_subs(i+1,st2+1);
        }
    }
    return 0;
}

int main(){
    scanf("%s",&str1);
    scanf("%s",&str2);

    int l1=strlen(str1);
    int l2=strlen(str2);

    if(l2>l1) printf("need tree\n");
    else{
        ms0(cnt1);ms0(cnt2);
        for(int i=0;i<l1;i++) cnt1[str1[i]-'a']++;
        for(int i=0;i<l2;i++) cnt2[str2[i]-'a']++;

        for(int i=0;i<30;i++){
            if(cnt2[i]>cnt1[i]){ printf("need tree\n"); return 0;}
        }

        if(l1==l2) printf("array\n");
        else{
            int fl=find_subs(0,0);
            if(fl==1) printf("automaton\n");
            else printf("both\n");
        }
    }
    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    char s[120],t[120];
    while(scanf("%s",s) !=  EOF){
    scanf("%s",t);
    if(strlen(s) == strlen(t)){
        int len = strlen(s);
        sort(s,s+len);
        sort(t,t+len);
        if(strcmp(s,t) == 0) puts("array");
        else puts("need tree");
    }
    else{
        int k = 0;
        for(int i = 0 ;i < strlen(s);i++)
            if(t[k] == s[i])  k++;
        if(k == strlen(t)){  puts("automaton");}
        else{
            k = 0;
            sort(s,s+strlen(s));
            sort(t,t+strlen(t));
            for(int i = 0;i < strlen(s);i++)
                if(t[k] == s[i]) k++;
            if( k == strlen(t)) puts("both");
            else puts("need tree");

        }
    }
    }
    return 0;
}

// Coded by R.amazing
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ld long double

#define alla a.begin(), a.end()
#define allx x.begin(), x.end()
#define allv v.begin(), v.end()
#define alls s.begin(), s.end()

#define sz size
#define F first
#define S second
using namespace std;
void boost(){
	 ios_base::sync_with_stdio(0);
}
// set <int> :: iterator it;
// for(int it = s.begin() ; it != s.end() ; it++)

string s , t;
int x[30];
int y[30];
int main(){
	boost();
	// freopen (" .txt", "r", stdin);
	// freopen (" .txt", "w", stdout);
	cin >> s >> t;
	for(int i=0 ; i<s.sz() ; i++){
		x[int(s[i]) - 97] ++;
	}
	for(int i=0 ; i<t.sz() ; i++){
		y[int(t[i]) - 97] ++;
	}
	for(int i=0 ; i<26 ; i++){
		if(y[i] > x[i]){
			cout << "need tree" , exit (0);
		}
	}
	int met = 0;
	for(int i=0 ; i<s.sz() ; i++){
		if(met < t.sz() && t[met] == s[i]){
			met++;
		}
	}
	if(met == t.sz()){
		cout << "automaton" , exit (0);
	}
	sort(alls);
	sort(t.begin(), t.end());
	if(s == t){
		cout << "array" , exit (0);
	}
	cout << "both";
	exit(0);
}

#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <map>
#include <set>
#include<algorithm>
using namespace std;
int C (int n, int k) {
	double res = 1;
	for (int i=1; i<=k; ++i)
		res = res * (n-k+i) / i;
	return (int) (res + 0.01);
}
vector<int> prefix_func(string s)
{
    int n=s.length();
    vector<int> pi(n);
    for(int i=1; i<n; i++)
    {
        int j=pi[i-1];
        while(j>0 && s[i]!=s[j])
            j=pi[j-1];
        if(s[i]==s[j])
            j++;
        pi[i]=j;
    }
    return pi;
}
string binar(int n){
	string s ="" ;
	while(n!=0){
		if(n%2==0)
			s+='0';
		else
			s+='1';
		n = n/2 ;
	}
	reverse(s.begin(),s.end());
	return s;
}
int main(){
	/*const int maxn = 5;
	int C[maxn+1][maxn+1];
	for (int n=0; n<=maxn; ++n) {
		C[n][0] = C[n][n] = 1;
		for (int k=1; k<n; ++k)
			C[n][k] = C[n-1][k-1] + C[n-1][k];
	}
	for(int i = 0 ; i < maxn; i++){
		for(int j=0; j< maxn ; j++){
			if(C[i][j]> 0)
				cout<<C[i][j]<<" ";
		}
		cout<<endl;
	}*/
	string s ;
	string t ;
	cin>>s;
	cin>>t;
	bool flag = false ;
	if(s.length()==t.length()){
		map<int,int> m1,m2;
		for(int i = 0 ; i < s.length();i++){
			m1[(unsigned int)s[i]]++ ;
			m2[(unsigned int)t[i]]++;
		}
		for(map<int,int>::iterator it1=m1.begin(),it2=m2.begin(); it1 != m1.end() && it2 != m2.end(); it1++,it2++){
			flag = true;
			if(*it1!=*it2)
			{
				cout<<"need tree"<<endl;
				return 0 ;
			}
		}
		if(flag ==false){
			cout<<"need tree"<<endl;
			return 0 ;
		}
		cout<<"array"<<endl;
	}
	else{
		if(s.length()>t.length()){
			/*string tmp ;
			tmp.append(t);
			tmp+="#";
			tmp.append(s);
			vector<int> v = prefix_func(tmp);
			for(int i = 0 ; i < v.size();i++){
				if(v[i]==t.length()){
					cout<<"automaton"<<endl;
					return 0 ;
				}
			}*/
			map<int,int> mt ;
			map<int,int> ms ;
			for(int i = 0 ; i< t.length();i++){
				mt[t[i]]++;
			}
			string tm="" ;
			set<char> st ;
			st.insert(t.begin(),t.end());
			for(set<char>::iterator i = st.begin() ; i != st.end(); i++){
				tm += *i;
			}
			for(int i = 0 ; i< tm.length();i++){
				for(int j = 0 ; j < s.length();j++){
					if(tm[i]==s[j]){
						ms[s[j]]++;
					}
				}
			}

			for(map<int,int>::iterator it1=mt.begin(),it2=ms.begin(); it1 != mt.end() && it2 != ms.end(); it1++,it2++){
				flag = true ;
				if(*it1>*it2)
				{
					cout<<"need tree"<<endl;
					return 0 ;
				}
			}
			if(flag == false){
				cout<<"need tree"<<endl;
				return 0 ;
			}
			int con = 0;
			int ty = 0 ;
			for(int i = 0 ; i < t.length();i++){
				for(int j = ty ; j < s.length();j++){
					if(t[i]==s[j]){
						con++;
						ty=j+1;
						break;
					}
				}

			}
			if( con < t.length()){
				cout<<"both"<<endl;
			}
			else{
				cout<<"automaton"<<endl;
			}
		}
		else{
			cout<<"need tree"<<endl;
		}
	}
	return 0 ;
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char s[9999];
    cin>>s;
    char t[9999];
    cin>>t;
    int lt=strlen(t);
    int ls=strlen(s);

    if(ls==lt)
    {
        int hashs[26];
        int hasht[26];
        for(int i=0 ; i<26 ; i++)
        {
            hashs[i]=0;
            hasht[i]=0;
        }
        for(int i=0 ; i<ls ; i++)
        {
            hashs[s[i]-97]++;
            hasht[t[i]-97]++;
        }
        int a=0;
        for(int i=0 ; i<26 ; i++)
        {
            if(hashs[i]!=hasht[i])
            {
                a=1;
                break;
            }
        }
        if(a==0)
        {
            cout<<"array";
        }
        else
        {
            cout<<"need tree";
        }
    }
    else if(lt>ls)
    {
        cout<<"need tree";
    }
    else
    {
        int hashs[26];
        int hasht[26];
        for(int i=0 ; i<26 ; i++)
        {
            hashs[i]=0;
            hasht[i]=0;
        }
        for(int i=0 ; i<ls ; i++)
        {
            hashs[s[i]-97]++;
        }
        for(int i=0 ; i<lt ; i++)
        {
            hasht[t[i]-97]++;
        }
        int a=0;
        for(int i=0 ; i<26 ; i++)
        {
            if((hashs[i]==0 && hasht[i]>0) || (hashs[i]>0 && hasht[i]>0 && hasht[i]>hashs[i]))
            {
                a=1;
                break;
            }
        }
        if(a==0)
        {
           int i=0,j=0;
           while(i<lt && j<ls)
           {
               if(t[i]==s[j])
               {
                   i++;
                   j++;
               }
               else
               {
                   j++;
               }
           }
           if(i==lt)
           {
               cout<<"automaton";
           }
           else
           {
               cout<<"both";
           }

        }
        else
        {
            cout<<"need tree";
        }

    }

}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
using namespace std;

string s1, s2;
int num[1005];
int l1, l2, i, j, k;
bool both;

int main()
{
	cin >> s1 >> s2;
	l1 = s1.length();
	l2 = s2.length();
	k = 0;
	for (i = 0; i <= l1&&k <= l2; ++i)
		if (s1[i] == s2[k])++k;

	if (k>l2)
	{
		printf("automaton\n");
		return 0;
	}
	for (i = 0; i <= l1; ++i)
		++num[s1[i]];
	for (i = 0; i <= l2; ++i)
		--num[s2[i]];
	both = false;
	for (i = 0; i <= 1000; ++i)
	{
		if (num[i]<0)
		{
			cout << "need tree";
			return 0;
		}
		if (num[i]>0)
			both = true;
	}
	if (both)
		cout << "both";
	else
		cout << "array";
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
static const size_t npos = -1;
int main()
{
	string s,t;
	cin>>s>>t;
	string s_sort,t_sort;
		s_sort=s;
		t_sort=t;
		sort(s_sort.begin(),s_sort.end());
		sort(t_sort.begin(),t_sort.end());
		//cout<<'a'-96;
	if (s.length()==t.length())
	{
		if (s_sort.compare(t_sort)==0)
			cout<<"array";
		else
			cout<<"need tree";
	}
	else
	{
		string::iterator it=s.begin();
		string::iterator it2=t.begin();
		string temp;
		int count=0;
		while (it!=s.end()&&it2!=t.end())
		{
			if (*it==*it2)
			{
				temp.push_back(*it2);
				it++;
				it2++;
				count++;
			}
			else
				it++;
		}
		if (count==t.length())
			cout<<"automaton";
		else
		{
			int freq_s[27];
			int freq_t[27];
			for (int i=1;i<=27;i++)
			{
				freq_s[i]=0;
				freq_t[i]=0;
			}
			for (it=s.begin();it!=s.end();it++)
			{
				int t=*it-96;
				freq_s[t]++;
			}
			for (it=t.begin();it!=t.end();it++)
			{
				int t=*it-96;
				freq_t[t]++;
			}
			int flag=0;
			for (int i=1;i<=26;i++)
			{
				if (freq_s[i]<freq_t[i])
				{
					flag=1;
					break;
				}
			}
			if (flag==1)
				cout<<"need tree";
			else
				cout<<"both";
		}
	}
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ul;

int main(int argc, char* argv[]) {
  string s1, s2;
  getline(cin, s1);
  getline(cin, s2);
  int c1[26];
  int c2[26];
  for (int i = 0; i < 26; ++i) c1[i] = c2[i] = 0;
  for (char c : s1) c1[c - (int)'a']++;
  for (char c : s2) c2[c - (int)'a']++;

  int inc21 = true, eq = true;
  for (int i = 0; i < 26; ++i) {
    if (c1[i] < c2[i]) inc21 = false;
    if (c1[i] != c2[i]) eq = false;
  }
  if (eq) { cout << "array" << endl; return 0; }

  unsigned int i1 = 0, i2 = 0;
  while (i1 < s1.size() && i2 < s2.size()) {
    if (s1[i1] == s2[i2]) { ++i1; ++i2; }
    else ++i1;
  }
  if (i2 == s2.size()) { cout << "automaton" << endl; return 0; }

  if (inc21) { cout << "both" << endl; return 0; }
  cout << "need tree" << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

//for fasten the programme
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

#define fi first
#define ss second
#define ins insert
#define vi vector<int>
#define sl set<ll>
#define vs vector<string>
#define vl vector<ll>
#define vi vector<int>
#define vpl vector<pair<ll, ll>>
#define pb push_back
#define last(x) x.back()
#define PI 3.14159265358979323846
#define ll long long
#define ld long double
#define endl "\n"
#define pl(x) x.pop_back()
#define sqr(n) floor(sqrt(n))
#define sz(v) ((ll)(v.size()))
#define trav(a, x) for (auto &a : x)
#define all(v) (v).begin(), (v).end()
#define arl(v) (v).rbegin(), (v).rend()
#define fsp(a) fixed << setprecision(a)
#define mem(a) memset(a, 0, sizeof(a))
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define repp(i, a, b) for (ll i = (a); i >= (b); i--)
#define rop(i, a, b) for (ll i = (a); i > (b); i--)
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define tt     \
  long long t; \
  cin >> t;    \
  while (t--)
#define IOS                \
  ios::sync_with_stdio(0); \
  cin.tie(0);
#define vmn(a) (*min_element(a.begin(), a.end()))
#define vmx(a) (*max_element(a.begin(), a.end()))
const ll N = 2e5 + 100;
const ll mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
unsigned check_max_bit_of_a_number(unsigned int number) { return (int)log2(number) + 1; }

//-----------------------debug-------------------------------//
//not going to work for stack and queue ->>can not be iterated by for(auto)..
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cout << x; }
void __print(double x) { cout << x; }
void __print(long double x) { cout << x; }
void __print(char x) { cout << '\'' << x << '\''; }
void __print(const char *x) { cout << '\"' << x << '\"'; }
void __print(const string &x) { cout << '\"' << x << '\"'; }
void __print(bool x) { cout << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
  cout << '{';
  __print(x.first);
  cout << ',';
  __print(x.second);
  cout << '}';
}
template <typename T>
void __print(const T &x)
{
  int f = 0;
  cout << '{';
  for (auto &i : x)
    cout << (f++ ? "," : ""), __print(i);
  cout << "}";
}
void _print() { cout << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
  __print(t);
  if (sizeof...(v))
    cout << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)             \
  cout << "[" << #x << "] = ["; \
  _print(x)
#else
#define debug(x...)
#endif
//---------------------bitsrelated----------------------------//
//indexing from zero so take maximum bit val==63,also take long long..

#define cone(x) (__builtin_popcountll(x))
#define fone(x) (__builtin_ffsll(x) - 1LL)  ///give wrong answer if x==0;(zero indexed)
#define mone(x) (63LL - __builtin_clzll(x)) ///give undefined behaviour on x==0;(zero indexed)

//------------------------------------------------------------//
/*some comments...
iota(all(a),val)-->>fill vector a with consecutive values starting from val..
vectorname.rering..size(size,val)-->>val is the default value which you want to give...
shuffle(all(a),rng)-->>randomly shuffle elements of vector..
some iterator functions->>> advance(it,val),next(it,val),prev(it,val)..
prnt it like-->>  (*it).ss,,,,[s+=('a'+i)]possible in st
//while using vmn vmx vector should not be empty..other wise segem..fault.
stoi-->string to int,,  to_string-->>convert int into string..work fine incase of ll.
always see the max which can run nlogn or nsqrtn..nsqrtn makes it very easy..
*/

int main()
{
  string s, t;
  cin >> s >> t;
  ll x = s.length();
  ll y = t.length();

  ll a[26]={};
  ll flag=0;
  for (ll i = 0; i < x; i++)
    a[s[i] - 'a']++;
  for (ll i = 0; i < y; i++)
    a[t[i] - 'a']--;
  for (ll i = 0; i < 26; i++)
  {
    if (a[i] < 0)flag=1;
  }
  if(flag){cout<<"need tree";return 0;}

      ll v=0;
     for(ll i=0;i<x;i++)
     {
       if(v!=y)
       {
         if(s[i]==t[v])v++;
       }
     }
      if (v == y)
        cout << "automaton";
      else if (x == y)
        cout << "array";
      else
        cout << "both";

}

#include <bits/stdc++.h>
#define maxN 1111//3
#define inf 1111111111
using namespace std;
char s[maxN],t[maxN],ns,nt;
int aps[27],apt[27];
int main(){
  ios::sync_with_stdio(false);
  #ifndef ONLINE_JUDGE
  freopen("B.txt","r",stdin);
  //freopen(TASK".out","w",stdout);
  #endif
  cin>>s>>t;
  while(s[ns]){
    aps[ s[ns]-'a' ]++;
    ns++;

  }
  while(t[nt]){
    apt[ t[nt]-'a' ]++;
    nt++;

  }

  bool arr=1;
  for(int i=0;i<26;i++){
      //  cout<<aps[i]<<' '<<apt[i]<<endl;
    if(aps[i]<apt[i]){
        cout<<"need tree";
        return 0;
    }
    else if( aps[i]>apt[i] ){
        arr=0;
    }
  }

  if(arr){
    cout<<"array";
    return 0;
  }
  else{
    int cur=0;
    for(int i=0;i<ns;i++){
        char e=s[i];
        if(cur<nt&&t[cur]==e)cur++;
    }
    if(cur!=nt){
        cout<<"both";
        return 0;
    }
    cout<<"automaton";
    return 0;
  }

  return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

#define all(v) 			((v).begin()), ((v).end())
#define allr(v)			((v).rbegin()), ((v).rend())
#define sz(v) 			((int)((v).size()))
#define endl			"\n"

typedef long long ll;

void File()
{
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
}
void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const int nn = 1e5 + 4;
const int oo = 0x3f3f3f3f;

int main()
{
	fast();
	string s, t;
	cin >> s >> t;
	int cnt = 0;
	for (int i = 0; i < sz(s); i++)
	{
		if (s[i] == t[cnt])
			cnt++;
	}
	if (cnt >= sz(t))
		return cout << "automaton\n", 0;
	map<char, int>arr;
	bool ans = 1;
	for (int i = 0; i < sz(s); i++)
		arr[s[i]]++;
	for (int i = 0; i < sz(t); i++)
		arr[t[i]]--;
	for (char i = 'a'; i <= 'z'; i++)
	{
		if (arr[i] < 0)
			ans = 0;
	}
	if (ans&&sz(s) == sz(t))
		cout << "array\n";
	else if (ans)
		cout << "both\n";
	else
		cout << "need tree\n";
#if _DEBUG
	system("pause");
#endif
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
	string n,m;
	long long y=0,a[10000],b[10000];
int main(){
	cin>>n>>m;
	if(m.size()>n.size()){
		cout<<"need tree";
		return 0;
	}
	for(int i=0;i<n.size();i++)if(n[i]==m[y])y++;
	if(y==m.size()){
		cout<<"automaton";
		return 0;
	}
	for(int i=0;i<n.size();i++)a[n[i]]++;
	for(int i=0;i<m.size();i++)b[m[i]]++;
	for(int i='a';i<='z';i++){
		if(a[i]<b[i]){
			cout<<"need tree";
			return 0;
		}
	}
	if(n.size()==m.size())cout<<"array";
	else cout<<"both";
}

//..........Final_Sub..../
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctype.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <ctype.h>
using namespace std;
int main()
{
    char s[101],t[101],s1[101],t1[101];
    scanf("%s%s",&s,&t);
    int len1=strlen(s),len2=strlen(t);
    if (len1<len2)
        printf("need tree");
    else if (len1==len2)
    {
        strcpy(t1,t);
        strcpy(s1,s);
        sort(s1,s1+len1);
        sort(t1,t1+len2);
        if(strcmp(s1,t1)==0)
            printf("array");
        else
            printf("need tree");
    }
    else if (len1>len2)
    {
        int i=0,j=0;
        while(i!=len1&&j!=len2)
        {
            if(s[i]==t[j])
            {i++;j++;continue;}
            i++;
        }
        if (j==len2)
        {printf("automaton");return 0;}
        else
        {
            sort(s,s+len1);
            sort(t,t+len2);
            i=0;j=0;
            while(i!=len1&&j!=len2)
            {
                if(s[i]==t[j])
                {i++;j++;continue;}
                i++;
            }
            if (j==len2)
                printf("both");
            else
            printf("need tree");
        }
    }
    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

char s[110], t[110];
int cnt[256];

int main()
{
    scanf("%s", s);
    scanf("%s", t);
    int ls = strlen(s);
    int lt = strlen(t);
    for(int i = 0; i < ls; i++) cnt[s[i]]++;
    for(int i = 0; i < lt; i++) cnt[t[i]]--;

    if(ls == lt)
    {
        bool ok = true;
        for(int i = 'a'; i <= 'z'; i++) if(cnt[i]) { ok = false; break; }
        if(ok) { puts("array"); return 0; }
    }

    if(ls < lt) { puts("need tree"); return 0; }

    bool ok = true;
    int i, j = 0;
    for(i = 0; i < lt; i++)
    {
        for(; j < ls && s[j] != t[i]; j++);
        if(j == ls) break;
        j++;
    }
    if(i == lt) { puts("automaton"); return 0; }

    ok = true;
    for(int i = 'a'; i <= 'z'; i++) if(cnt[i] < 0) { ok = false; break; }

    printf("%s\n", ok ? "both" : "need tree" );

    return 0;
}

#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int main()
{string b,a;
cin>>b>>a;
 int m=b.size() ,n=a.size();
 int count[26]={0};
 bool res1=true,res2=true;
 for(int i=0,j=0;i<m;i++)
 {if(b[i]==a[j])
 j++;
 if(j==n)
 {
 cout<<"automaton";
 return 0;
 }
}
for(int j=0;j<m;j++)
{ count[b[j]-'a']++;
}
for(int j=0;j<n;j++)
 {count[a[j]-'a']--;
 }
 for(int j=0;j<26;j++)
 {res1&=(count[j]==0);
   res2&=(count[j]>=0);
 }
 if(res1) cout<<"array";
 else if(res2) cout<<"both";
 else cout<<"need tree";

return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long b[27],c[27],d,n,j,i,k,l,m,au[109];
char a[27]={'0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
string s,ss,s1;
int main()
{
	cin>>s>>ss;int kw=0,lw=0,mw=0,nw=0;
	for(i=0;i<ss.length();i++)
	{
		for(j=au[i];j<s.length();j++)
		{
			if(ss[i]==s[j])
			{
				au[i+1]=j+1;
				kw++;
				break;
			}
		}
	}
	for(i=2;i<=ss.length();i++)
	{
		if(au[i]<=au[i-1]) lw++;
	}
	if(lw==0 && kw==ss.length()) return cout<<"automaton",0;
	kw=0;lw=0;mw=0;
	for(i=0;i<s.length();i++)
	{
		for(j=1;j<=26;j++)
		{
			if(s[i]==a[j]) b[j]++;
		}
	}
	for(i=0;i<ss.length();i++)
	{
		for(j=1;j<=26;j++)
		{
			if(ss[i]==a[j]) c[j]++;
		}
	}
	for(i=1;i<=26;i++)
	{
		if(b[i]==c[i] && c[i]>0) lw++;
		if(b[i]>c[i] && c[i]==0) nw++;
		if(b[i]>0) kw++;
		if(c[i]>0) mw++;
	}
	if(s.length()==ss.length())
	{
		if(lw==kw && lw==mw && nw==0) return cout<<"array",0;
	}
	else
	{
		lw=0;kw=0;mw=0;nw=0;
		for(i=1;i<=26;i++)
		{
			if(b[i]<c[i]) lw++;
			if(b[i]>c[i]) kw++;
		}
		if(kw>0 && lw==0) return cout<<"both",0;
	}
	cout<<"need tree",0;
	return 0;

}
/*
N:19;

hxsvvydmzhxrswvhkvrbjrfqkazbkjabnrdghposgyfeslzumaovfkallszzumztftgpcilwfrzpvhhbgdzdvnmseqywlzmhhoxh
dbelhtzgkssyfrqgzuurdjhwvmdbhylhmvphjgxpzhxbb

*/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>

using namespace std;

const int maxn=100+5;

int n1,n2;
char s1[maxn],s2[maxn];

bool IsAutomaton(const string& str1, const string& str2)
{
    int j = (int)str2.size()-1;
    for (int i = (int)str1.size()-1; i >= 0 && j >= 0; --i)
        if (str1[i] == str2[j]) --j;

    return j == -1;
}

int main()
{
    //freopen("data.txt","r",stdin);
    scanf("%s%s",s1,s2);

    string str1(s1), str2(s2);

    n1 = (int)str1.size();
    n2 = (int)str2.size();

    if (n1 == n2)
    {
        sort(str1.begin(), str1.end());
        sort(str2.begin(), str2.end());
        if (str1 == str2)
        {
            printf("array");
            return 0;
        }
    }
    else if (n1 > n2)
    {
        if (IsAutomaton(str1, str2))
        {
            printf("automaton");
            return 0;
        }

        sort(str1.begin(), str1.end());
        sort(str2.begin(), str2.end());

        if (IsAutomaton(str1, str2))
        {
            printf("both");
            return 0;
        }
    }

    printf("need tree");
    return 0;
}

#include <bits/stdc++.h>
#define ff first
#define D double
#define sz size()
#define pb push_back
#define mp make_pair
#define nl printf("\n")
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define f(i,a,b) for(int i=a;i<b;i++)
#define r(i,a,b) for(int i=a;i>b;i--)
#define BitCnt(a) __builtin_popcountll(a)
#define MEM(a,val) memset(a,val,sizeof(a))
#define pul pair<ull,ull>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define MX  500007
#define MOD 1000000007
#define INF 2000000000000000LL
#define EPS 1e-9

#define t int t; cin>>t; while(t--)
using namespace std;
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s,rs;
    cin>>s>>rs;

    ll ar[26]={0},ars[26]={0};

    for(int i=0;i<s.size();i++)
    {
    	ar[s[i]-'a']+=1;
    }

    for(int i=0;i<rs.size();i++)
    {
    	ars[rs[i]-'a']+=1;
    }

    if(rs.size()<s.size())
    {
    	string tm="";
    	int k=0;
    	char ch=rs[k];

    	for(int i=0;i<s.size();i++)
    	{
    		if(s[i]==ch){
    			tm+=s[i];
    			ch=rs[k+1];
    			k++;
    		}
    	}

    	if(tm==rs){
    		cout<<"automaton\n";

    	}
    	else{
    			int f=0;
    		for(int i=0;i<rs.size();i++){
    			if(ar[rs[i]-'a']<ars[rs[i]-'a'])
    			{
    				f=1;
    				break;
    			}
    		}
    		if(f)
    			cout<<"need tree\n";
    		else
    			cout<<"both\n";
    	}

    }
    else
    {
    	int f=0;
    	for (int i = 0; i < rs.size(); ++i)
    	{
    		if(ars[rs[i]-'a']!=ar[rs[i]-'a'])
    		{
    			f=1;
    			break;
    		}
    	}
    	//cout<<"niche me f"<<f<<endl;
    	if(f)
    		cout<<"need tree\n";
    	else
    		cout<<"array\n";

    }

    return 0;
}

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
string str1,str2;
int cow=0;
int main()
{
	cin>>str1>>str2;
	if(str1.size()<str2.size())
		{
			cout<<"need tree";
			cow++;
			return 0;
		}
	//for automaton
		for (int j = 0; j < str1.size(); ++j)
		{
			if(str2[0]==str1[j])
			{
		      int count=0;
	          for (int k = 0; k < str2.size(); ++k)
	          {
		        for (int i = j; i <str1.size() ; ++i)
	            {
	        	      j++;
	        	      if (str2[k]==str1[i])
		             {
			           count++;
			           break;
		             }

   	           }

	          }

	         if(count==str2.size())
	      {
		   cow++;
		   cout<<"automaton";
		   return 0;
	     }
			}
		}
	//for array
	str1=str1+"+";
	str2=str2+"-";
    if(str1.size()==str2.size())
    {
		for (int i = 0; i < str1.size(); ++i)
		{
			for (int j = 0; j < str2.size(); ++j)
			{

				if(str1[i]==str2[j])
				{
					//cout<<i<<" "<<j<<" ";
					str1.erase(str1.begin()+i);
					str2.erase(str2.begin()+j);
					i--;
					j--;

				}

			}
		}
	}
	if(str1[0]=='+'&&str2[0])
	{
		cout<<"array";
		cow++;
        return 0;
    }

/// for both
    for (int i = 0; i < str1.size(); ++i)
		{
			for (int j = 0; j < str2.size(); ++j)
			{

				if(str1[i]==str2[j])
				{
					//cout<<i<<" "<<j<<" ";
					str1.erase(str1.begin()+i);
					str2.erase(str2.begin()+j);
					i--;
					j--;

				}

			}
		}

    if(str1.size()>1&&str2.size()==1)
    {
    	cout<<"both";
    	return 0;
    }
    if (cow==0)
    {
    	cout<<"need tree";
    	return 0;
    }
}

#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;

#ifndef ONLINE_JUDGE
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
	template<class S,class T>
	ostream &operator <<(ostream& out,const pair<S,T>& a){
		out<<'('<<a.fr<<','<<a.sc<<')';
		return out;
	}
}

lint readL(){
	lint res;
#ifdef ONLINE_JUDGE
	scanf("%I64d",&res);
#else
	scanf("%lld",&res);
#endif
	return res;
}
void printL(lint res){
#ifdef ONLINE_JUDGE
	printf("%I64d",res);
#else
	printf("%lld",res);
#endif
}

//const int INF=5e8;

string s,t;

bool isar(string s,string t){
	sort(ALL(s));
	sort(ALL(t));
	return s==t;
}

bool tomato(string s,string t){
	swap(s,t);
	int idx=0;
	REP(i,s.size()){
		while(idx<t.size() && t[idx]!=s[i]) ++idx;
		if(idx==t.size()) return false;
		++idx;
	}
	return true;
}

int main(){
	cin>>s>>t;

	if(isar(s,t)) puts("array");
	else if(tomato(s,t)) puts("automaton");
	else {
		sort(ALL(s));
		sort(ALL(t));
		if(tomato(s,t)) puts("both");
		else puts("need tree");
	}

	return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <limits>
#include <utility>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <map>
#include <stack>

#define endl '\n'
using namespace std;

string solve(string &s, string &t) {

    int i = 0, j = 0;
    while (i < s.length() && j < t.length()) {
        if (s[i] == t[j])
            j++;
        i++;
    }
    bool cond1 = (j == t.length());

    vector<int> cnt(26, 0);
    for (int i = 0; i < t.length(); i++)
        cnt[t[i] - 'a']++;
    for (int i = 0; i < s.length(); i++)
        cnt[s[i] - 'a']--;

    bool cond2 = false; // there exist i such cnt[i] < 0
    bool cond3 = true; // for all i, cnt[i] <= 0
    for (int i = 0; i < cnt.size(); i++) {
        if (cnt[i] < 0) cond2 = true;
        if (cnt[i] > 0) cond3 = false;
    }

    if (cond1) return "automaton";
    if (cond3)
        return (cond2 ? "both" : "array");

    return "need tree";
}

int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    cout << solve(s, t) << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define sll static long long int
#define pb push_back
#define L1(d,n) for(i=d;i<n;i++)
#define PNR 1000000010
#define nl  "\n"
#define ok  cout<<"OK\n";
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

vector<ll> x;
vector<ll> y;
vector<ll> z;
vector <ll> vec;

vector <pair<ll,ll> > v;
string str,str2,s1;
set<ll> s,s2;
vector<ll>::iterator it;
ll i,j,k,n,m,c,t,p,q,max2,max1,ans;
//double f=0,g=0,h=0;
//sll a[150100],b[100100];
char ch;

int main()
{
    int x[150]={0};
    int y[150]={0};
    cin>>str;
    cin>>str2;
    L1(0,str.size())
    {
      x[str[i]-'a']++;
      if(str[i]==str2[j])
      {
          n++;
          j++;
      }
    }
    L1(0,str2.size())
    {
        y[str2[i]-'a']++;
    }
    L1(0,27)
    {
       if(y[i]>x[i])
            k++;
    }
    if(k)
        cout<<"need tree";
    else if(str.size()==str2.size())
        cout<<"array";
    else if(str2.size()==n)
        cout<<"automaton";
    else
        cout<<"both";

}

#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
string t,s;
bool au,ch,ar;
int main()
{
    cin>>s>>t;
    au=ar=0;
    ch=1;
    int dems[200],demt[200];
    for (char i='a';i<='z';i++)
        dems[i]=demt[i]=0;
    for (int i=0;i<s.size();i++)
        dems[s[i]]++;
    for (int i=0;i<t.size();i++)
        demt[t[i]]++;
    for (char i='a'; i<='z';i++)
        if (dems[i]<demt[i]){
            ch=0;
            break;
        }
    if (ch==0)
        cout<<"need tree";
    else{
        int j=0,i=0;
        while (i<s.size()&&j<t.size()&&s.size()>t.size()){
            if (s.size()>t.size())
                au=1;
            while ((s[i]!=t[j])&&(i<s.size()&&j<t.size())&&s.size()>t.size())
                s.erase(i,1);
            j++;
            i++;
        }
        if (s.find(t,0)==-1) ar=1;
        if ((au==1)&&(ar==1)) cout<<"both";
        else {
            if (au) cout<<"automaton";
            if (ar) cout<<"array";
        }
    }
}

///#include<bits/stdc++.h>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<list>
#include<set>
#include<utility>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include <iterator> //iterators
#include<stdio.h>
#include<limits.h>

#define PI acos(-1)
#define INF 1e18
#define clr(a) memset(a,0,sizeof a)
#define fil(a) memset(a,1,sizeof a)

using namespace std;

typedef long long int lli;
typedef list<int> li;
typedef pair<int,int>pii;

bool isSubSequence(string str1, string str2, int m, int n)
{
    if (m == 0) return true;
    if (n == 0) return false;

    if (str1[m-1] == str2[n-1])
        return isSubSequence(str1, str2, m-1, n-1);
    return isSubSequence(str1, str2, m, n-1);
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int ck=0;
    string t,s;
    map<char,int>mps,mpt;
    cin>>t>>s;
    if(s.size()>t.size())
    {
        cout<<"need tree";
        return 0;
    }

    if(isSubSequence(s, t, s.size(),t.size()))
    {
        cout<<"automaton";
        return 0;
    }

    for(int i=0;i<s.size();i++)
    {
        mps[s[i]]++;
    }

    for(int i=0;i<t.size();i++)
    {
        mpt[t[i]]++;
    }
     //cout<<mpt['d'];
     //cout<<endl;
    for(char ch='a';ch!='{';ch++)
        {
            if(mpt[ch]<mps[ch])
            {
                ck=1;
                break;
            }
              else  continue;
        }
    /*for(char ch='a';ch!='{';ch++)
        cout<<mpt[ch]<<" "<<mps[ch]<<endl;*/
   // cout<<ck<<" ";
    if(ck==1)
        cout<<"need tree";
    else
    {
        if(t.size()==s.size())
            cout<<"array";
        else
            cout<<"both";
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define double long double
#define int long long
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
}
typedef void (*callback_function)(void); // type for conciseness
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;
#undef int
int main() {
#define int long long
	ios_base::sync_with_stdio(false);
	cin.tie();
  //auto beginProgram = chrono::steady_clock::now();

/* Tutorial by Bugman
448B - Suffix Structures

Solution:7139584

Consider each case separately. If we use only suffix automaton then s transform
to some of its subsequence. Checking that t is a subsequence of s can be
performed in different ways. Easiest and fastest — well-known two pointers
method. In case of using suffix array we can get every permutation of s. If it
is not obvious for you, try to think. Thus, s and t must be anagrams. If we
count number of each letter in each string, we can check this. If every letter
appears in s the same times as in t then words are anagrams. In case of using
both structures strategy is: remove some letters and shuffle the rest. It is
possible if every letter appears in s not less times than in t. Otherwise it is
impossible to make t from s. Total complexity O(|s| + |t| + 26).
*/

  {// I have fixed my code to include only the necessary checks as per
  // instructed in the tutorial. First I checked whether s and t are anagrams.
  // If not then we "need tree". If so then there are 3 possibilities. If t
  // is NOT a subsequence of s then depending on whether the length of t is less
  // than or equal to the length of s, we use "both" or only "array"
  // respectively (if t is shorter than s we need automaton to delete some
  // characters). Else if t is a subsequence of s then we simply need
  // "automaton".
  // This problem introduced me to new concepts like suffix array and suffix
  // automaton that I wasn't familiar with before.
    string s, t; cin >> s >> t;
    vec<int> cntS(256, 0), cntT(256, 0);
    for (char &ch : s) cntS[ch]++;
    for (char &ch : t) cntT[ch]++;
    FORE(i, 'a', 'z') if (cntS[i] < cntT[i]) {
      cout << "need tree" << endl; return 0;
    }
    for (int i = 0, j = 0; j < t.length(); i++, j++) {
      while (i < s.length() && s[i] != t[j]) i++;
      if (i == s.length()) {
        cout << (s.length() != t.length() ? "both" : "array") << endl; return 0;
      }
    }
    cout << "automaton" << endl;
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> ii;
bool isarray(string a, string b) {
    if (a.find(b) != string::npos)
        return false;
    bool ok = true; int pos = -1;
    for (int i = 0; ok && i != b.size(); i++) {
        ok = (pos = a.find(b[i], pos + 1)) != string::npos;
    }
    if (ok)return false;

    map <char, int> ada, adb;
    for (int i = 0; i < b.length(); i++) {
        adb[b[i]]++;
    }
    for (int i = 0; i < a.length(); i++) {
        ada[a[i]]++;
    }
    for (auto &x : adb) {
        if (ada.count(x.first)) {
            if (ada[x.first] >= x.second)
                continue;
            else
                return false;
        } else
            return false;
    }
    return true;
}

bool isauto(string a, string b) {
    if (a.find(b) != string::npos)
        return true;
    if (isarray(a, b) && (a.length() > b.length()))
        return true;
    bool ok = true; int pos = -1;
    for (int i = 0; ok && i != b.size(); i++) {
        ok = (pos = a.find(b[i], pos + 1)) != string::npos;
    }
    return ok;
}

int main(void) {
    //freopen("Text.txt", "r", stdin);
    string a, b; cin >> a >> b;
    bool arr = isarray(a, b), au = isauto(a, b);
    if (arr && au)
        printf("both\n");
    else if (arr)
        printf("array\n");
    else if (au)
        printf("automaton\n");
    else printf("need tree\n");

}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    string s,t,r;
    cin>>s>>t;
map<char,int>mp1,mp2;
    for(int i=0;i<s.size();i++)
        mp1[s[i]]++;
    for(int i=0;i<t.size();i++)
        mp2[t[i]]++;

    for(int i=0;i<t.size();i++)
    {
        if(mp1[t[i]]<mp2[t[i]])
        {
            cout<<"need tree"<<"\n";
            return 0;
        }
    }
        int i=0,j=0;
        bool flag1=false;
        while(i<s.size()&&j<t.size())
        {
            if(s[i]==t[j])
            {

                j++;
            }
            if(j==t.size())
            {
                flag1=true;
                break;
            }
            i++;
        }
        if(flag1)
            cout<<"automaton"<<"\n";
        else{
           if(s.size()==t.size())
            cout<<"array"<<"\n";
           else
            cout<<"both"<<"\n";
        }
    }

// 448B.cpp : Defines the entry point for the console application.
//
/*بسم الله الرحمن الرحيم */
#include<iostream>
#include<string>
using namespace std;
bool AllExist(string a, string b)
{
	bool *used = new bool[b.size()];
	for (int i = 0; i < b.size(); i++)
		used[i] = 0;
	for (int i = 0; i < a.size(); i++)
	{
		int j = 0;
		for (; j < b.size(); j++)
		{
			if (a[i] == b[j] && (!used[j]))
			{
				used[j] = 1;
				break;
			}
		}
		if (j == b.size())
			return 0;
	}
	return 1;
}
bool Ordered(string a, string b)
{
	int j = 0;
	for (int i = 0; i < a.size(); i++)
	{
		for (; j < b.size(); j++)
		{
			if (a[i] == b[j] )
			{
				j++;
				break;
			}
		}
		if (j == b.size() && i == a.size() - 1)
		{
			if
				(a[i] == b[j - 1]);
			else
				return 0;
		}
		else if (j == b.size())
			return 0;
	}
	return 1;
}
int main()
{
	string s, t;
	cin >> s >> t;
	int result = 0;
	if (s.size() > t.size())
	{
		if ((Ordered(t,s)))
			result = 1;
		else
		{
			if (AllExist(t, s))
				result = 2;
		}
	}
	else if (s.size() == t.size())
	{
		if (AllExist(t, s))
			result = 3;
	}
	string q[4] = { "need tree","automaton","both","array" };
	cout << q[result] << endl;
    return 0;
}

#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cfloat>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<functional>
#include<iostream>
#include<limits>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define endl '\n'

const long double PI = acos(-1.L);
using namespace std;
template<class T> T maximize(T &a, const T &b) { return a = max(a, b); }
template<class T> T minimize(T &a, const T &b) { return a = min(a, b); }

bool bazinga(const string &a, const string &b) {
  auto i = a.begin(), j = b.begin();
  while(i!=a.end() && j!=b.end()) {
    if(*i==*j) {
      i++;
      j++;
    } else
      i++;
  }
  return j==b.end();
}

int main() {
  string a, b;
  cin>>a>>b;
  if(bazinga(a, b))
    puts("automaton");
  else {
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    if(a==b)
      puts("array");
    else if(bazinga(a, b)){
      puts("both");
    } else
      puts("need tree");
  }
  return 0;
}

#include <bits/stdc++.h>

int counts[256], countt[256];

int main ( void ) {

    int i, j;
    std::string s, t;
    bool tree, array, automaton;

    std::cin >> s >> t;

    for ( i = 0 ; i < s.size() ; ++ i ) {
        ++ counts[s[i]];
    }
    for ( i = 0 ; i < t.size() ; ++ i ) {
        ++ countt[t[i]];
    }

    array = false;
    for ( i = 0 , j = 0 ; i < t.size() ; ++ i , ++ j ) {
        while ( j < s.size() && s[j] != t[i] ) {
            ++ j;
        }
        if ( j == s.size() ) {
            array = true;
            break;
        }
    }

    tree = false;
    automaton = false;
    for ( i = 'a' ; i <= 'z' ; ++ i ) {
        if ( counts[i] < countt[i] ) {
            tree = true;
            break;
        }
        else if ( counts[i] > countt[i] ) {
            automaton = true;
        }
    }

    if ( tree ) {
        std::cout << "need tree\n";
    }
    else if ( automaton && array ) {
        std::cout << "both\n";
    }
    else if ( array ) {
        std::cout << "array\n";
    }
    else {
        std::cout << "automaton\n";
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

bool chk(string str1, string str2, int m, int n)
{
    if (m == 0) return true;
    if (n == 0) return false;

    if (str1[m-1] == str2[n-1])
        return chk(str1, str2, m-1, n-1);

    return chk(str1, str2, m, n-1);
}

int main(){
	string s,t;
	cin>>s>>t;

	int f1[26];
	int f2[26];
	memset(f1,0,sizeof(f1));
	memset(f2,0,sizeof(f2));

	for(int i=0;i<s.length(); i++){
		f1[s[i]-'a']++;
	}

	for(int i=0;i<t.length(); i++){
		f2[t[i]-'a']++;
	}

	int flag =1;
	for(int i=0;i<t.length();i++){
		if(f2[t[i]-'a'] > f1[t[i]-'a']){
			flag = 0;
			break;
		}
	}

	bool automaton = false;
	bool array;
	if(flag != 0  ){
		bool isseq = chk(t , s , t.length() ,s.length());
		if(isseq){
			array = false;
		}
		else{
			array = true;
		}
		if(s.length() > t.length())
			automaton = true;
	}

	string ans;

	if(flag == 0)
	ans = "need tree";
	else {
	if(automaton && !array)
		ans = "automaton";
	else if(!automaton && array)
		ans = "array";
	else
		ans = "both";
	}
	cout<<ans<<endl;
	return 0;
}

#include<iostream>
using namespace std;
int main ()
{
    char aa[101],zz[101];
    int a[26]={0},z[26]={0},x,y;
    cin >>aa>>zz;
    for (x=0;aa[x]!='\0';x++)
    {
        int t=aa[x]-'a';
        a[t]++;
    }
    for (y=0;zz[y]!='\0';y++)
    {
        int t=zz[y]-'a';
        z[t]++;
    }
    for (int i=0;i<26;i++)
    {
        if (z[i]!=0&&a[i]<z[i])
        {
            cout <<"need tree"<<endl;
            return 0;
        }
    }
    if (x==y)
    {
        cout <<"array"<<endl;
        return 0;
    }
    int j=0;
    for (int i=0;aa[i]!='\0';i++)
    {
        if (aa[i]==zz[j])
            j++;
    }
    if (j==y)
    {
        cout <<"automaton"<<endl;
        return 0;
    }
    else
    {
        cout <<"both"<<endl;
        return 0;
    }
    return 0;
}

//
//  448-B.cpp
//  skv
//
//  Created by Subodh Verma on 25/01/20.
//  Copyright © 2020 IIT BHU. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;

int main() {
    //cout << std::fixed << std::setprecision(5);
    string s,t;
    cin>>s;
    cin>>t;
    int answer = -1;
    int t_len = t.size();
    int s_len = s.size();
    if( t_len > s_len ){
        cout<<"need tree"<<endl;
        return 0;
    }
    vector<int> found(s_len);
    for(int i=0; i<t_len; i++){
        for(int j=0; j<s_len; j++){
            //cout<<t[i]<<" "<<s[j]<<endl;
            if( t[i]==s[j] && found[j]==0 ){
                found[j]=1;
                break;
            }
            if(j==s_len-1){
                cout<<"need tree"<<endl;
                return 0;
            }
        }
    }
    int counter = 0;
    int temp = 0;
    vector<int> a(t_len);
    for(int i=0; i<t_len; i++){
        for(int j=counter; j<s_len; j++){
            //cout<<t[i]<<" "<<s[j]<<endl;
            if( t[i]==s[j] ){
                a[i]++;
                temp++;
                counter = j+1;
                break;
            }
        }
    }

    int all_found=1;
    for(int i=0; i<a.size(); i++){
        if(a[i]==0){
            all_found=0;
        }
    }
    if( all_found==1 ){
        cout<<"automaton"<<endl;
        return 0;
    }
    if( s_len==t_len ){
        cout<<"array"<<endl;
        return 0;
    }
    cout<<"both"<<endl;
    return 0;

}

#include <iostream>
#include <algorithm>
using namespace std;
#define N 47
#define M 100000
#include <cstring>
int a[N],b[N];
char s[M+17], t[M+17];
void init()
{
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
}
int main()
{
    int i, j;
    while(cin >> s)
    {
        init();
        cin>>t;
        int lens = strlen(s);
        int lent = strlen(t);
        for(i = 0; i < lens; i++)
        {
            a[s[i]-'a']++;
        }
        for(i = 0; i < lent; i++)
        {
            b[t[i]-'a']++;
        }
        int flag = 0;
        if(lens < lent)
        {
            flag = 1;
        }
        for(i = 0; i < 26; i++)
        {
            if(a[i] < b[i])
            {
                flag = 1;
                break;
            }
        }
        if(flag == 1)
        {
            cout<<"need tree"<<endl;
            continue;
        }
        if(lens == lent)
        {
            cout<<"array"<<endl;
            continue;
        }
        int p = 0, j = 0;
        for(i = 0; i < lent; i++)
        {
            while(t[i]!=s[j] && j < lens)
            {
                j++;
            }
            if(j >= lens) //表示不存在不交换s子串的顺序能组成t的情况
            {
                p = 1;
                break;
            }
            j++;
        }
        if(p == 1)
        {
            cout<<"both"<<endl;
            continue;
        }
        cout<<"automaton"<<endl;
    }
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
string s,t;
cin>>s>>t;

string a,b;
a=s;
b=t;
 if(t.length() >s.length()){

              cout<<"need tree"<<endl;
                     return 0 ;
                           }

for(int i=0;i<b.length() ;i++){
      bool ch=false;
 for(int j=0;j<a.length() ;j++ ){

  if(b[i]==a[j]){
    ch=1;
    a[j]='*';
    break;
                }

                                }

          if(ch==false ){

            cout<<"need tree"<<endl;
            return 0 ;
                       }

                             }

a=s;
b=t;

sort (a.begin() ,a.end() );
sort (b.begin() ,b.end() );

if(a==b&&a.length()==b.length()){
    cout<<"array"<<endl;
    return 0;

                                 }

int m=0;
int c=0;
for(int i=0;i<t.length();i++){
int j;
 for( j=m;j<s.length() ;j++){

    if(t[i]==s[j]){
    c++;
    m= j+1;
    break;
                 }

                                }

                                 }

if(c==t.length() ){
   cout<<"automaton"<<endl;
   return 0;

}

cout<<"both"<<endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define ll              long long int
#define fo(i,n)         for(int i=0;i<n;i++)
#define rfo(i,n)        for(int i=n-1;i>=0;i--)
#define Ull             unsigned long long
#define pb              push_back
#define F               first
#define S               second
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr)
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x, y)      cout << #x << "=" << x << "," << #y << "=" << y << endl

const int N = 2;
const ll MOD = 1e9 + 7;

ll dx[4] = { -1, 1, 0, 0};
ll dy[4] = {0, 0, 1, -1};

bool isPrime(ll x)
{
	if (x < 2)
		return false;

	if (x <= 3) return true;

	if (x % 2 == 0 || x % 3 == 0) return false;

	for (ll i = 5; i <= sqrt(x); i += 6)
	{
		if (x % i == 0 || x % (i + 2) == 0)
			return false;
	}

	return true;
}

void Solve()
{
	string s, t;
	cin >> s >> t;
	vector<int> hash1(256, 0);
	vector<int> hash2(256, 0);
	fo(i, s.length())
	{
		hash1[s[i]]++;
	}
	fo(i, t.length())
	{
		hash2[t[i]]++;
	}

	if (s.length() < t.length())
	{
		cout << "need tree" << "\n";
		return;
	}

	else if (s.length() ==  t.length())
	{
		SORT(s);
		SORT(t);
		if (s == t)
			cout << "array" << "\n";

		else
			cout << "need tree" << "\n";
	}

	else
	{
		int n = s.length();
		int m = t.length();

		int i = 0, j = 0;
		while (i < n && j < m)
		{
			char c = t[j];
			if (c == s[i])
			{
				i++;
				j++;
			}

			else
			{
				while (i < n && s[i] != c)
					i++;

				i++;
				j++;

			}

		}

		if (j == m && i <= n)
		{

			cout << "automaton" << "\n";
			return;
		}

		bool flag = true;
		for (int i = 0; i < m; i++)
		{
			int a = hash1[t[i]];
			int b = hash2[t[i]];
			if (a < b)
				flag = false;
		}
		if (flag)
			cout << "both" << "\n";

		else
			cout << "need tree" << "\n";

	}

}

int main()
{

	FastRead;
	int T = 1;
	//cin >> T;

	while (T--)
	{
		Solve();
	}

	return 0;
}

//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <math.h>
#include <unordered_map>
#include <queue>
#include <stack>

using namespace std;

#define PI 3.141592653589793238462643383279502884
#define Max 100005
#define ll long long

ll power(ll base, ll powe)
{
	ll get = 1;
	for (int i = 1; i <= powe; i++)
		get *= base;
	return get;
}

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);

	string str, target;
	cin >> str >> target;
	int counter = 0;
	for (int i = 0, j = 0; i < str.size(); i++)
	{
		if (target[j] == str[i])
		{
			counter++;
			j++;
		}
	}
	if (counter == target.size())
	{
		cout << "automaton" << endl;
		return 0;
	}
	sort(str.begin(), str.end());
	sort(target.begin(), target.end());
	if (str == target)
	{
		cout << "array" << endl;
		return 0;
	}
	map<char, int>mp;
	map<char, int>::iterator it;
	for (int i = 0; i < str.size(); i++)
		mp[str[i]]++;
	for (int i = 0; i < target.size(); i++)
		mp[target[i]]--;
	for (it = mp.begin(); it != mp.end(); it++)
	{
		if (it->second < 0)
		{
			cout << "need tree" << endl;
			return 0;
		}
	}
	cout << "both" << endl;
	return 0;
}

#include <bits/stdc++.h>
#define ll long long int
#define fio ios_base::sync_with_stdio(0);cin.tie(0)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define slld(t) scanf("%lld",&t)
#define plld(t) printf("%lld\n",t)
#define sc(t) scanf("%c",&t)
#define pb(x) push_back(x)
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<ii >
#define vvii vector<vii >
#define clr(x) memset(x,0,sizeof(x))
#define rep(i,begin,end) for(__typeof(end) i=begin-(begin>end);i!=end-(begin>end);i+=1-2*(begin>end))
#define MOD 1000000007
#define MAX 1000005
#define EPS 1e-9
using namespace std;

bool find(int &curr, string s,char c)
{
	for(int i=curr+1; i<s.length(); i++)
	{
		if(s[i]==c)
		{
			curr=i;
			return true;
		}
	}
	return false;
}

int main()
{
	int tree=0,aut=0,arr=0;
	string s,t;
	cin>>s>>t;
	if(s.length()==t.length())
	{
		map<char,int> ms,mt;
		rep(i,0,s.length()) ms[s[i]]++,mt[t[i]]++;
		for(auto it:ms)
		{
			if(mt[it.first]!=it.second) tree++;
			if(tree) break;
		}
		if(!tree) arr++;
	}
	else if(s.length()>t.length())
	{
		aut++;
		int curr=-1,nok=0;
		rep(i,0,t.length())
		{
			if(!find(curr,s,t[i])) nok++;
			if(nok) break;
		}
		if(nok)
		{
			map<char,int> m;
			rep(i,0,s.length()) m[s[i]]++;
			rep(i,0,t.length())
			{
				if(m[t[i]]==0) tree++;
				else m[t[i]]--;
				if(tree) break;
			}
			if(!tree) arr++;
		}
	}
	else tree++;

	if(tree) printf("need tree\n");
	else if(aut && arr) printf("both\n");
	else if(aut && !arr) printf("automaton\n");
	else printf("array\n");
	return 0;
}

#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define uint unsigned int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define INF 1e9
using namespace std;

int main() {
	cin.sync_with_stdio(0);
   	cin.tie(0);
	string s, t;
	cin >> s >> t;
//	bool arr = false;
	bool both = false;
	vector<int> V1(26, 0), V2(26, 0);
	for(int i = 0, j = 0; i < (int)s.length(); i++) {
		if(s[i] == t[j]) j++;
		if(j == (int)t.size()) {
			cout << "automaton\n";
			return 0;
		}
	}
	for(int i = 0; i < (int)s.size(); i++) V1[s[i] - 'a']++;
	for(int i = 0; i < (int)t.size(); i++) V2[t[i] - 'a']++;
	for(int i = 0; i < 26; i++) {
		if(V1[i] < V2[i]) {
			cout << "need tree\n";
			return 0;
		} else if (V1[i] > V2[i]) {
			both = true;
		}
	}
	if(both) cout << "both\n";
	else cout << "array\n";

	return 0;}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	string s, ss,sss,s4;
	unsigned long long cntr = 0, cntr1=0,cntr2=0,f=0;
	cin >> s >> ss;
	s4=s;
	if (s.size()==ss.size())
	{
		for (int a = 0; a < s.size(); a++)
		{
			if (s[a]=='1')
			{
				continue;
			}
			for (int b = 0; b < s.size(); b++)
			{
				if (s[a] == ss[b])
				{
					cntr++;
				}
			}
			if (cntr==0)
			{
				cout << "need tree";
				//cout << s << endl << ss;
				return 0;
			}
			for (int c = a+1; c < s.size(); c++)
			{
				if (s[a]==s[c])
				{
					s[c] = '1';
					cntr2++;
				}
			}
			if (cntr!=cntr2+1)
			{
				cout << "need tree";
			//cout << s << endl << ss;
				return 0;
			}
			cntr = 0; cntr2 = 0;
		}
		cout << "array";
	}
	else if (s.size()>ss.size())
	{
		f = s.find(ss);
		if (f<=s.size())
		{
			cout << "automaton";
			return 0;
		}
		else
		{
		    int x=0,y=0,z=0;
		    for(int g=0;g<ss.size();g++)
            {
                for (int p = 0; p < s.size(); p++)
				{
					if (ss[g]==s[p])
					{
						s[p] = '1';
						cntr++;
						break;
					}
				}
				if (cntr == 0)
				{
					cout << "need tree";
					return 0;
				}
				cntr = 0;
            }
            cntr=0;
            for(int h=0;h<s.size();h++)
            {
                //cout<<ss[x]<<" "<<s[h]<<endl;
                if(ss[x]==s4[h])
                {
                    cntr2++;
                    x++;
                }
                if (cntr2==ss.size())
                {
                    cout<<"automaton";
                    return 0;
                }
            }
				cout<<"both";
				//cout<<cntr2;
        }
	}
	else if (s.size() < ss.size())
	{
		cout << "need tree";
	}
}

#include <bits/stdc++.h>
#define ll long long int
#define fio ios_base::sync_with_stdio(0);cin.tie(0)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define slld(t) scanf("%lld",&t)
#define plld(t) printf("%lld\n",t)
#define sc(t) scanf("%c",&t)
#define pb(x) push_back(x)
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<ii >
#define vvii vector<vii >
#define clr(x) memset(x,0,sizeof(x))
#define rep(i,begin,end) for(__typeof(end) i=begin-(begin>end);i!=end-(begin>end);i+=1-2*(begin>end))
#define MOD 1000000007
#define MAX 1000005
#define EPS 1e-9
using namespace std;

bool find(int &curr, string s,char c)
{
	for(int i=curr+1; i<s.length(); i++)
	{
		if(s[i]==c)
		{
			curr=i;
			return true;
		}
	}
	return false;
}

int main()
{
	int tree=0,aut=0,arr=0;
	string s,t;
	cin>>s>>t;
	if(s.length()==t.length())
	{
		map<char,int> ms,mt;
		rep(i,0,s.length()) ms[s[i]]++,mt[t[i]]++;
		for(auto it:ms)
		{
			if(mt[it.first]!=it.second) tree++;
			if(tree) break;
		}
		if(!tree) arr++;
	}
	else if(s.length()>t.length())
	{
		aut++;
		int curr=-1,nok=0;
		rep(i,0,t.length())
		{
			if(!find(curr,s,t[i])) nok++;
			if(nok) break;
		}
		if(nok)
		{
			map<char,int> ms,mt;
			rep(i,0,s.length()) ms[s[i]]++;
			rep(i,0,t.length()) mt[t[i]]++;
			for(auto it:mt)
			{
				if(ms[it.first]<it.second) tree++;
				if(tree) break;
			}
			if(!tree) arr++;
		}
	}
	else tree++;

	if(tree) printf("need tree\n");
	else if(aut && arr) printf("both\n");
	else if(aut && !arr) printf("automaton\n");
	else printf("array\n");
	return 0;
}

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

char s[105],t[105];
int cnts[30],cntt[30];

int f[105];

void getfail()
{
    int m=strlen(t);
    f[0]=0;f[1]=0;
    for(int i=1;i<m;i++)
    {
        int j=f[i];
        while(j&&t[i]!=t[j])j=f[j];
        f[i+1]=t[i]==t[j]?j+1:0;
    }
}

bool find()
{
    int n=strlen(s);
    int m=strlen(t);
    getfail();
    int j=0;
    for(int i=0;i<n;i++)
    {
        while(j&&t[j]!=s[i])j=f[j];
        if(t[j]==s[i])j++;
        if(j==m)return true;
    }
    return false;
}

bool isin()
{
    int pos=0;
    int n=strlen(s);
    int m=strlen(t);
    for(int i=0;i<n;)
    {
        if(s[i]==t[pos])
        {
            pos++;
            i++;
            if(pos==m)return true;
        }
        else
        {
            i++;
            if(i==n)break;
        }
    }
    return false;
}
int main()
{
    scanf("%s%s",s,t);

    int n=strlen(s);
    int m=strlen(t);

    memset(cnts,0,sizeof cnts);
    memset(cntt,0,sizeof cntt);

    if(isin())
    {
        puts("automaton");
        return 0;
    }

    for(int i=0;i<n;i++)
    {
        cnts[s[i]-'a']++;
    }
    for(int i=0;i<m;i++)
    {
        cntt[t[i]-'a']++;
    }

    bool res=false,ret=false;
    bool can=true;

    for(int i=0;i<26;i++)
    {
        if(cnts[i]<cntt[i])can=false;
    }

    if(!can)puts("need tree");
    else{
        if(n==m)puts("array");
        else puts("both");
    }
    return 0;
}

#include<bits/stdc++.h>
#include<string.h>
#include<string>
using namespace std;
typedef long long int ll;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MOD (lli)(1000000000+7)
#define MAXN 100000+1
#define endl "\n"
#define pb push_back
#define mp make_pair
#define TEST_CASES  ll t;cin >> t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for(ll i=(b-1);i>=a;i--)

/*---------------------NOTHING IMPORTANT BELOW !!  THIS IS A NEWBIE'S CODE ---------------------------------------------------------------*/

bool sortbysec(const pair<ll,ll>&a,const pair<ll,ll>&b){ return (a.second < b.second) ; }
ll max(ll a, ll b){ if(a>b) return a ; return b; }
ll min(ll a, ll b){ if(a<b) return a ; return b; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);  }

bool isSubsequence(string s1, string s2){
    ll j = 0;
    for(ll i=0;i <s1.size();i++){
        if(j==s2.size())
            return true;
        if(s1[i]==s2[j]){
            j++;
        }
    }
    if(j==s2.size())
        return true;
    return false;
}

bool isSubstring(string s1, string s2){
    ll M = s1.length();
    ll N = s2.length();
    for (ll j,i=0;i<=(N-M);i++) {
        for(j=0;j<M;j++)
            if (s2[i+j]!=s1[j])
                break;
        if (j==M)
            return true;
    }
    return false;
}

void cp(){
    string s,t;cin>>s>>t;
    string g,h;
    g = s ; h = t ;
    sort(g.begin(),g.end());
    sort(h.begin(),h.end());
    if(s.size()< t.size()){
        cout<<"need tree"<<endl;
        return;
    }
    else if(s.size()==t.size()){
        if(g==h){
            cout<<"array"<<endl;
        }
        else{
            cout<<"need tree"<<endl;
        }
        return;
    }
    else{
        bool a = isSubstring(s,t);
        bool b = isSubsequence(s,t);
        bool r1 = isSubstring(g,h);
        bool r2 = isSubsequence(g,h);
        if(a==true || b==true){
            cout<<"automaton"<<endl;
            return;
        }
        if(a==false && b==false){
            if(r1==true || r2==true){
                cout<<"both"<<endl;
            }
            if(r1==false && r2==false){
                cout<<"need tree"<<endl;
                return;
            }

        }
    }
}

int main(){
    // ofstream fout;
    //fout.open("answer.txt");
    fio ;
     //TEST_CASES{
		 cp();
    //fout<<endl;
     //}
    return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string start, destination;
    int letterCountStart[130],letterCountDestination[130];
    for (int i = 0; i < 130; i++)
    {
        letterCountStart[i] = 0;
        letterCountDestination[i] = 0;
    }
    cin >> start >> destination;
    for (int i = 0; i < start.length(); i++)
        letterCountStart[start[i]]++;
    for (int i = 0; i < destination.length(); i++)
        letterCountDestination[destination[i]]++;
    for (int i = 0; i < 130; i++)
    {
        if (letterCountDestination[i]>letterCountStart[i])
        {
            cout << "need tree\n";
            return 0;
        }
    }
    for (int i = 0; i < 130; i++)
    {
        letterCountStart[i] = 0;
        letterCountDestination[i] = 0;
    }
    string test = "";
    int j = 0;
    for (int i = 0; i < start.length(); i++)
    {
        if (start[i] == destination[j])
        {
            test = test + destination[j];
            j++;
            if (j == destination.length())
                break;
        }
    }
    if (test == destination)
        cout << "automaton\n";
    else
    {
        for (int i = 0; i < start.length(); i++)
            letterCountStart[start[i]]++;
        for (int j = 0; j < destination.length(); j++)
            letterCountDestination[destination[j]]++;
        bool arrayFlag=true;
        for (int i = 0; i < 130;i++)
        if (letterCountDestination[i] != letterCountStart[i])
            arrayFlag = false;
        if (arrayFlag)
            cout << "array\n";
        else
            cout << "both\n";
    }
    return 0;
}

#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
using namespace std;

int main(){
    string a,b;
    cin>>a>>b;
    int A[30]={},B[30]={};
    for(int i=0;i<a.size();i++)
        A[a[i]-'a']++;
    for(int i=0;i<b.size();i++)
        B[b[i]-'a']++;
    if(a==b){cout<<"array";return 0;}
    if(b.size()>a.size()){cout<<"need tree";return 0;}
    /*
    for(int i=0;i<a.size()-b.size()+1;i++){
        bool f=1;
        for(int j=i;j<b.size();j++){
            if(a[i+j]!=b[j]){
                f=0;break;}
        }
        if(f){
            cout<<"automaton";return 0;
        }
    }
    */
    int I=0,J=0;
    while(I<a.size()){
        if(a[I]!=b[J])I++;
        else {J++;I++;}

        if(J==b.size()){cout<<"automaton";return 0;}
    }

    for(int i=0;i<26;i++){
        if(B[i]>A[i]){cout<<"need tree";return 0;}
    }
    if(a.size()==b.size())cout<<"array";
    else cout<<"both";return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <algorithm>
#include <iostream>
#include <stdint.h>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <complex>
#include <cstdio>
#include <vector>
#include <bitset>
#include <string>
#include <ctime>
#include <deque>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
using namespace std;

typedef pair<int, int> ii;
bool isarray(string a, string b) {
    if (a.find(b) != string::npos)
        return false;
    bool ok = true; int pos = -1;
    for (int i = 0; ok && i != b.size(); i++) {
        ok = (pos = a.find(b[i], pos + 1)) != string::npos;
    }
    if (ok)return false;

    map <char, int> ada, adb;
    for (int i = 0; i < b.length(); i++) {
        adb[b[i]]++;
    }
    for (int i = 0; i < a.length(); i++) {
        ada[a[i]]++;
    }
    for (auto &x : adb) {
        if (ada.count(x.first)) {
            if (ada[x.first] >= x.second)
                continue;
            else
                return false;
        } else
            return false;
    }
    return true;
}

bool isauto(string a, string b) {
    if (a.find(b) != string::npos)
        return true;
    if (isarray(a, b) && (a.length() > b.length()))
        return true;
    bool ok = true; int pos = -1;
    for (int i = 0; ok && i != b.size(); i++) {
        ok = (pos = a.find(b[i], pos + 1)) != string::npos;
    }
    return ok;
}

int main(void) {
    //freopen("Text.txt", "r", stdin);
    string a, b; cin >> a >> b;
    bool arr = isarray(a, b), au = isauto(a, b);
    if (arr && au)
        printf("both\n");
    else if (arr)
        printf("array\n");
    else if (au)
        printf("automaton\n");
    else printf("need tree\n");

}

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <map>
#include <bitset>
using namespace std;
#define ll long long

struct _comp {
    bool operator() (int i[3],int j[3]) { return (i[0]>j[0]);}
} comp;

int gcd(int a, int b)
{
    if(b==0)
        return a;
    else
        return gcd(b, a%b);
}

vector<vector<int>> Ptriangle;
void fill_Ptriangle(int step){
    vector<int> tmp(1,1);
    Ptriangle.push_back(tmp);
    for(int i=1;i<=step;i++)
    {
        tmp.clear();
        tmp.push_back(1);
        for(int k=0;k<Ptriangle[i-1].size()-1;k++){
            tmp.push_back(Ptriangle[i-1][k]+Ptriangle[i-1][k+1]);
        }
        tmp.push_back(1);
        Ptriangle.push_back(tmp);
    }
}
string i2s(int a)
{
    string s="";
    if(a<0)
    {s+='-';a=abs(a);}
    while(a)
    {
        s+=a%10 + '0';
        a/=10;
    }
    return s;
}
//struct _set
//{
//  int parent_set;
//  int size;
//  vector<int> set_elems;
//  vector<int> set_indexes;
//  void make_set(int elem, int index)
//  {
//      parent_set = index;
//      set_elems.push_back(elem);
//      set_indexes.push_back(index);
//      size = 1;
//  }
//};
//_set my_set[300];
//int find_set(int index){
//  if(my_set[index].parent_set == index)
//      return index;
//  if(my_set[index].parent_set == -1)
//      return index;
//  return my_set[index].parent_set = find_set(my_set[index].parent_set);
//}
//void union_sets(int a, int b)
//{
//  a = find_set(a);
//  b = find_set(b);
//  if(a!=b)
//  {
//      if(my_set[a].size < my_set[b].size)
//          swap(a, b);
//      my_set[a].parent_set = b;
//      my_set[b].set_elems.insert(my_set[b].set_elems.end(), my_set[a].set_elems.begin(), my_set[a].set_elems.end());
//      my_set[b].set_indexes.insert(my_set[b].set_indexes.end(), my_set[a].set_indexes.begin(), my_set[a].set_indexes.end());
//      my_set[b].size += my_set[a].size;
//  }
//}
int a[26];
int b[26];
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("Input.txt", "r", stdin);
    #endif
    string aa,bb;
    cin >> aa >> bb;
    if(aa.length()<bb.length())
    {
        cout << "need tree" << endl;
        return 0;
    }
    for(int i=0;i<aa.length();i++)
    {
        a[aa[i]-'a']++;
    }
    for(int i=0;i<bb.length();i++)
    {
        b[bb[i]-'a']++;
    }
    int l=0;
    for(int i=0;i<aa.length();i++)
    {
        if(aa[i]==bb[l])
            l++;
        if(l==bb.length())
        {

            cout << "automaton" << endl;
            return 0;
        }
    }
    int f=0;
    for(int i=0;i<26;i++)
    {
        if(a[i]<b[i])
        {
            cout << "need tree" << endl;
            return 0;
        }
    }
    if(aa.length()>bb.length())
        cout << "both" << endl;
    else
        cout << "array" << endl;
    return 0;
}

#include<iostream>
using namespace std;
#include<string>
#include<vector>
int count(char a[], char key,int l)
{
	int counter = 0;
	for (int i = 0; i < l; i++)
	{
		if (a[i] == key)
			counter++;
	}
	return counter;
}
bool isSub(char str1 [], char str2[],int m,int n)
{
	if (m == 0)
	{
		return true;
	}
	if (n == 0)
	{
		return false;
	}
	if (str1[m-1] == str2[n-1])
		return isSub(str1, str2, m - 1, n - 1);
	else
		return isSub(str1, str2, m, n - 1);
}
int main()
{
	int cnt[30];
	char s1[105], s2[105];
	cin >> s1 >> s2;
	string tmp, tmp2;
	tmp = s1;
	tmp2 = s2;
	bool chk = true;
	for (int i = 0; i < tmp.length(); i++)
	{

		if (count(s1, s1[i], tmp.length()) != count(s2, s1[i], tmp2.length()))
		{
			chk = false;
			break;
		}

	}
	const int N = 26;
	std::vector<int> countVec(N, 0);

	for (int p = 0; p <tmp.length(); p++){ ++countVec[s1[p] - 'a']; }
	for (int p = 0; p < tmp2.length(); p++){ --countVec[s2[p] - 'a']; }
	bool array(1), tree(0);
	for (int p = 0; p < N; p++){
		if (countVec[p] <  0){ tree = 1; break; }
	}
	 if (chk)
		cout << "array" << endl;
	else if (isSub(s2, s1, tmp2.length(), tmp.length()))
	{
		cout << "automaton" << endl;
	}
	else if (!tree)
		cout << "both" << endl;
	else
		cout << "need tree"<<endl;

}

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <complex>
#include <numeric>
#include <tuple>
#include <climits>

#define INF 1023456789
#define SQR(x) ((x)*(x))
#define INIT(x,y) memset((x),(y),sizeof((x)))
#define SIZE(x) ((int)((x).size()))
#define REP(i, n) for (__typeof(n) i=0;i<(n);++i)
#define FOR(i, a, b) for (__typeof(a) i=(a);i<=(b);++i)
#define FORD(i, a, b) for (__typeof(a) i=(a);i>=(b);--i)
#define FORE(it, c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)

#define DEBUG
#ifdef DEBUG
#define DBG(x) cerr << #x << ": " << (x) << endl;
#else
#define DBG(x)
#endif

using namespace std;

typedef long long LL;
typedef pair<int,int> PI;
typedef tuple<int,int,int>trio;

int main()
{
	string a,b;
	cin >> a >> b;
	int occurances[26];
	INIT(occurances,0);
	REP(i,a.size()) occurances[a[i] - 'a']++;
	REP(i,b.size()) occurances[b[i] - 'a']--;
	bool positive = false;
	REP(i,26)
	{
		if (occurances[i] < 0)
		{
			printf("need tree\n");
			return 0;
		}
		else if (occurances[i] > 0) positive = true;
	}
	if (positive)
	{
		unsigned j = 0;
		REP(i,a.size())
		{
			if (a[i]==b[j]) j++;
			if (j==b.size())
			{
				printf("automaton\n");
				return 0;
			}
		}
		printf("both\n");
	}
	else printf("array\n");
        return 0;
}

#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define ll long long
ll n;vector< char > v,a;
ll sum=0;
char arr[26];
char* freq(char st[])
{

    int k;
    arr[26]='\0';
    for(int i=0;i<26;i++)
    {
        arr[i]='0';
    }

    for(int i=0;st[i]!='\0';i++)
    {
        k=st[i]-'a';
        arr[k]++;
    }

}

int main()
{
    char a[105],b[105];int p=0;
    cin>>a>>b;
    if(strlen(a)<strlen(b))
    {
        cout<<"need tree";
        return 0;
    }

    else if(1)
    {
        int i=0;
        for(int j=0;a[j]!='\0';j++)
        {
            if(a[j]==b[i])
            {
                i++;
            }

        }
        if(strlen(b)==i)
        {
            cout<<"automaton";
            return 0;
        }

    }

    freq(a);
    strcpy(a,arr);
    freq(b);
    strcpy(b,arr);

    if(strcmp(a,b)==0)
    {
        cout<<"array";
    }

    else
    {
        for(int i=0;i<26;i++)
        {
            if(b[i]!='0')
            {
                if(a[i]<b[i])
                {
                    cout<<"need tree";
                    n=0;
                    break;
                }

                else
                n=1;
            }
        }
        if(n!=0)
        cout<<"both";
    }

    return 0;

}

#include<bits/stdc++.h>
#define int long long int
#define TRY_HARD ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL);
using namespace std;

//TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD TRY_HARD

signed main()
 {
	TRY_HARD ;
	string s1 , s2 ;
	cin >> s1 >> s2 ;
	map < char , int > m1 , m2 ;
	for ( int i = 0 ; i < s1.length() ; i++ )
	{
		m1[s1[i]]++ ;
	}
	for ( int i = 0 ; i < s2.length() ; i++ )
	{
		m2[s2[i]]++ ;
	}

	for ( auto it = m2.begin() ; it != m2.end() ; it++ )
	{
		   char x = it -> first ;
		   if ( m1[x] < it -> second )
		   return cout << "need tree" , 0 ;

	}

	if ( m1.size() == m2.size() and s1.length() == s2.length() )
	return cout << "array" , 0 ;

	size_t found = s1.find(s2) ;
	if ( found != string::npos )
	return cout << "automaton" , 0 ;

	int i , j ;
	for (i = 0 , j = 0 ; i < s1.length() and j < s2.length() ; )
	{
		if ( s1[i] == s2[j] )
		i++ , j++ ;
		else
		i++ ;
	}
	if ( j == s2.length() )
	return cout << "automaton" , 0 ;

	if ( m1.size() == m2.size() and s1.length() != s2.length() )
	return cout << "both" , 0 ;

	if ( m1.size() != m2.size() )
	return cout << "both" , 0 ;

}

#include <iostream>
#include <string>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;

int main()
{
    string temps1,temps2,s1,s2,temp;
    cin>>s1>>s2;
    if (s2.size()>s1.size()){
        cout<<"need tree";
        return 0;
    }
    temps1=s1;
    temps2=s2;
    for (int i=0;i<s2.size();i++){
        if (temps1.find(temps2[i])!=string::npos){
            temps1[temps1.find(temps2[i])]='.';
        }
        else {
            cout<<"need tree";
            return 0;
        }
    }
//    if (s1.size()==s2.size()){
//        cout<<"array";
//    }
//    else{
        int r=0,j=0;
        vector<int> d(100,0);
        temps1=s1;
        temps2=s2;

        for (int i=0;i<temps2.size();i++){
            d[j]=temps1.find(temps2[i]);
            while ((d[j]<d[j-1])&&(j>0)&&(temps1.find(temps2[i])!=string::npos)){
                temps1[temps1.find(temps2[i])]='.';
                d[j]=temps1.find(temps2[i]);
                r++;
                if (r>s2.size()){break;}
            }
            temps1[temps1.find(temps2[i])]='.';
            j++;
        }
//        for (int i=0;i<j;i++){
//            cout<<d[i]<<" ";
//        }
//        cout<<endl;
        if ((s1.find(s2)!=string::npos) ||(is_sorted(d.begin(),d.begin()+j-1))){
            cout<<"automaton";
        }
        else {
            if (s1.size()==s2.size()){
                cout<<"array";
            }
            else cout<<"both";
        }
}

#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
#include <math.h>
#define ff(i,s,n) for(int i=(s);i<(n);i++)
#define fr(i,s,n) for(int i=(n-1);i>=(s);i--)
#define FF(i,s,n) for(int i=(s);i<=(n);i++)
#define Fr(i,s,n) for(int i=(n);i>=(s);i--)
#define mp(a,b) make_pair(a,b)

inline void swap(int &a, int &b) {
    a = a^b;
    b = a^b;
    a = a^b;
}

inline void smax(int &a, int b) {
    if (b > a)a = b;
}

inline void smin(int &a, int b) {
    if (b < a)a = b;
}

using namespace std;
typedef vector<int> vi;
typedef vector<pair<string, string> > vpss;
typedef vector<pair<int, int> > vpii;
typedef unordered_map<int, int> imap;
typedef unordered_map<long long, long long> lmap;

inline int gcd(int a, int b) {
    if (a < b)swap(a, b);
    while (b > 0) {
        a -= a / b*b;
        swap(a, b);
    }
    return a;
}
string s;
string t;
int xx[26];

int main() {
    cin >> s >> t;
    int a = s.length();
    int b = t.length();
    int i = 0;
    bool st = 0;
    for (i = 0; i < a; i++)xx[s[i] - 'a']++;
    for (i = 0; i < b; i++) {
        xx[t[i] - 'a']--;
        if (xx[t[i] - 'a'] < 0)st = 1;
    }
    if (st)cout << "need tree";
    else {
        int p = -1;
        for (i = 0; i < b; i++) {
            p++;
            while (p < a && t[i] != s[p]) {
                p++;
            }
        }
        if (p >= a && a > b)cout << "both";
        else if (p < a && a > b)cout << "automaton";
        else cout << "array";
    }

}

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<cmath>
#include<math.h>
#include<set>
#include<map>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define cint const int
#define ll long long
#define fname "a"
using namespace std;
const int maxn = (int)(1e5) + 123;
const ll inf = (ll)(1e18);
const int INF = (int)(1e9);
map< char, int > used;
string s, t;
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> s >> t;
    for(int i = 0; i < s.size(); ++i)
        used[s[i]]++;
    for(int i = 0; i < t.size(); ++i)
        used[t[i]]--;
    for(char c = 'a'; c <= 'z'; ++c)
        if(used[c] < 0)
        {
            cout << "need tree";
            return 0;
        }
    int j = 0, i = 0;
    while(true)
    {
        if(j == s.size() || i == t.size())
            break;
        if(s[j] == t[i])
            j++, i++;
        else
            j++;
    }
    if(i == t.size())
        cout << "automaton";
    else if(t.size() == s.size())
        cout << "array";
    else
        cout << "both";
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	string s, t;
	cin >> s >> t;
	int n = s.size(), m = t.size();
	bool ans1 = false, ans2 = false, ans3 = false;
	{	int j = 0;
		for(int i = 0; i < n; i ++) {
			if(j < m && s[i] == t[j])
				++ j;
		}
		ans1 = j == m;
	}
	{	string ss = s, st = t;
		sort(all(ss)); sort(all(st));
		ans2 = ss == st;
		{	int j = 0;
			for(int i = 0; i < n; i ++) {
				if(j < m && ss[i] == st[j])
					++ j;
			}
			ans3 = j == m;
		}
	}
	if(!ans3) puts("need tree");
	else if(ans1) puts("automaton");
	else if(ans2) puts("array");
	else puts("both");
	return 0;
}

/* Nurgazy Zhandos */

#include <bits/stdc++.h>
#include <functional>
#include <algorithm>
#include <stdexcept>
#include <streambuf>
#include <exception>
#include <typeinfo>
#include <valarray>
#include <iostream>
#include <iterator>
#include <cstdlib>
#include <istream>
#include <iomanip>
#include <fstream>
#include <complex>
#include <utility>
#include <ostream>
#include <numeric>
#include <sstream>
#include <utility>
#include <bitset>
#include <iosfwd>
#include <string>
#include <limits>
#include <vector>
#include <cstdio>
#include <locale>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <ios>
#include <new>

#define F first
#define S second

#define pf push_front
#define pb push_back
#define mp make_pair
#define pp pop_back

#define resize(v) v.resize(unique(all(v)) - v.begin());
#define all(a) a.begin(), a.end()
#define sz(a) a.size()
#define STOP return 0

//#define int long long

using namespace std;

typedef pair <long long, long long> PLL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef long double LD;
typedef long long LL;

const int inf = 1e9 + 123;
const LL INF = 1e18 + 123;
const double eps = 1e-9;
const int mod = 1e9 + 7;

void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

	int a[130], b[130];

main () {
	//	freopen(".in", "r", stdin);
	//	freopen(".out", "w", stdout);

	string s, c;
	cin >> s >> c;

	string gg = s;
	string hh = c;

	sort(all(gg));
	sort(all(hh));

	if(gg == hh) {
	 	cout << "array" << endl;
	 	exit(0);
	}

	for(int i = 0; i < sz(s); i++) {
		a[int(s[i]) - 96]++;
	}

	for(int i = 0; i < sz(c); i++) {
		b[int(c[i]) - 96]++;
	}

	for(int i = 1; i <= 30; i++) {
	 	if(b[i]) {
	 	 	if(a[i] < b[i]) {
	 	 	 	cout << "need tree" << endl;
	 	 	 	exit(0);
	 	 	}
	 	}
	}

	int cnt = 0;

	for(int i = 0, j = 0; i < sz(c); i++) {
	 	for(int k = j; k < sz(s); k++) {
	 	 	if(c[i] == s[k]) {
	 	 	 	j = k + 1;
	 	 	    cnt++;
	 	 		break;
	 	 	}
	 	}
	}

	if (cnt != sz(c)) {
	 	cout << "both";
	}
	else {
		cout << "automaton" << endl;
	}
}

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string s, t, temp;

int letters_s[26], letters_t[26];

bool isAnswer = false;

bool areEqual()
{
    bool answer = true;
    for (int i = 0; i <= 25; ++i)
        if (letters_t[i] != letters_s[i])
            answer = false;
    return answer;
}

void main()
{
    cin >> s >> t;

    for (int i = 0; i < s.size(); ++i)
        ++letters_s[s[i] - 'a'];
    for (int i = 0; i < t.size(); ++i)
        ++letters_t[t[i] - 'a'];
    if (areEqual())
    {
        isAnswer = true;
        cout << "array";
    }

    if (!isAnswer)
    {
        int k = 0;
        for (int i = 0; i < s.size(); ++i)
            if (s[i] == t[k])
                ++k;

        if (k >= t.size())
        {
            isAnswer = true;
            cout << "automaton";
        }
    }
    if (!isAnswer)
    {
        isAnswer = true;
        for (int i = 0; i <= 25; ++i)
            if (letters_t[i] > letters_s[i])
                isAnswer = false;
        if (isAnswer)
        {
            cout << "both";
        }
    }
    if (!isAnswer)
        cout << "need tree";
}

#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>

using namespace std;

int main()
{
	string str = "", final = "";
	cin>>str;
	cin>>final;

	int sSz = str.length(), fSz = final.length();

	if(sSz == fSz)
	{
		char sArr[26], fArr[26];
		for(int i = 0; i < 26; i++)
		{
			sArr[i] = 0;
			fArr[i] = 0;
		}
		for(int i = 0; i < sSz; i++)
		{
			sArr[str[i]-'a'] += 1;
			fArr[final[i]-'a'] += 1;
		}
		for(int i = 0; i < 26; i++)
		{
			if(sArr[i] != fArr[i])
			{
				cout << "need tree" << endl;
				return 0;
			}
		}
		cout << "array" << endl;
	}
	else if(sSz > fSz)
	{
		char sArr[26];
		for(int i = 0; i < 26; i++)
			sArr[i] = 0;

		for(int i = 0; i < sSz; i++)
			sArr[str[i]-'a'] += 1;

		for(int i = 0; i < fSz; i++)
		{
			sArr[final[i]-'a'] -= 1;
			if(sArr[final[i]-'a'] < 0)
			{
				cout << "need tree" << endl;
				return 0;
			}
		}

		int index = 0;
		for(int i = 0; i < sSz; i++)
		{
			if(str[i] == final[index])
				index++;
		}
		if(index < fSz)
			cout << "both" << endl;
		else cout<< "automaton" << endl;
	}
	else cout << "need tree" << endl;

	return 0;
}

#include <iostream>
#include <map>
using namespace std;

map<char, int> M1, M2;

int main()
{
    string s1, s2;
    cin >> s1 >> s2;
    for (auto &x: s1) {
        M1[x]++;
    }
    for (auto &x: s2) {
        M2[x]++;
    }
    bool flg = 0;
    for (char i = 'a'; i <= 'z'; ++i) {
        if (M2[i] > M1[i]) {
            cout <<"need tree" <<endl;
            return 0;
        }
        if (M2[i] != M1[i]) flg = 1;
    }
    int j = 0;
    for (int i = 0; i < s1.length(); ++i) {
        if (j < s2.length() && s2[j] == s1[i]) {
            j++;
        }
    }
    if (j == s2.length()) {
        cout << "automaton" <<endl;return 0;
    }
    if (!flg) cout << "array" <<endl;
    else cout <<"both" <<endl;
    return 0;
}

/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<string>
#include<vector>
using namespace std;

int main()
{
    string s;
    string t;
    cin>>s;
    cin>>t;
    int n=s.length();
    int m=t.length();
    //check if every letter of t is in s or not
    int check=1;
    vector<int>count1(26,0);
    vector<int>count2(26,0);
    for (int i = 0; i < n; i++) {
        /* code */
        count1[s[i]-'a']++;
    }
    for (int i = 0; i < m; i++) {
        /* code */
        count2[t[i]-'a']++;
    }
    for (int i = 0; i < 26; i++) {
        /* code */
        if(count2[i]>count1[i]) check=0;
    }
    if(!check || n<m) {cout<<"need tree"<<endl;return 0;}
    // automaton if string t occurs in string s in order of string t
    int i=0,j=0;
    while(i<n && j<m){
        while(s[i]!=t[j]) i++;
        if(i>=n || j>=m) break;
        i++;j++;

    }
    if(j==m){
        cout<<"automaton"<<endl;
        return 0;
    }
    else{
        if(n>m){
            cout<<"both"<<endl;
            return 0;
        }
        else{
            cout<<"array"<<endl;
            return 0;
        }
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main () {
	string a, b, c = "abcdefghijklmnopqrstuvwxyz";
	cin >> a >> b;

	map<char, vector<int>> need;
	for (int i=0; i<c.size(); i++) {
		int l = count(a.begin(), a.end(), c[i]);
		vector<int> v(l);
		for (int j=l-1, k=0; k<a.size(); k++) {
			if (a[k] == c[i]) {
				v[j] = k;
				j--;
			}
		}
		need[c[i]] = v;
	}

	bool nt=0, au=0, ar=0;
	int max = -1;

	int del = 0;
	for (int i=0; i<c.size(); i++) {
		del += abs(count(a.begin(), a.end(), c[i]) - count(b.begin(), b.end(), c[i]));
	}

	au = a.size() > b.size();
	nt = a.size() < b.size();
	nt = b.size() + del > a.size();

	for (int i=0; i<b.size(); i++) {
		{
			bool t = true;
			vector<int> z=need[b[i]];
			for (int j=z.size()-1; j+1; j--) {
				if (z[j] >= max) {
					max = z[j];
					z.erase(z.begin()+j, z.begin()+j+1);
					t = 0;
					break;
				}
			}
			ar = ar || t;
			need[b[i]] = z;
		}
	}

	cout <<(nt ? "need tree":
			au&&ar ? "both" :
			au ? "automaton" :
			"array"
			);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int n,m;
string a,b;

int main()
{
	//string a,b;
	cin>>a;
	cin>>b;
	n=a.length();
	m=b.length();
	int h=0;
	for(int i=0;i<n;i++)
	{
	    if(a[i]==b[h])
	        h++;
	}
	if(h==m)
	{
	    cout<<"automaton";
	    return 0;
	}
	int x[26]={0};
	int zero=0;int one=0;int mone=0;
	for(int i=0;i<n;i++)
	{
		int u=a[i];
		x[u-97]++;
	}
	for(int j=0;j<m;j++)
	{
		int v=b[j];
		x[v-97]--;
	}
	for(int k=0;k<26;k++)
	{
	    //cout<<x[k]<<' ';

		if(x[k]==0)
			zero++;
		else if(x[k]>0)
			one++;
		else
			mone++;
	}
	//cout<<'\n';
	//cout<<zero<<one<<mone<<endl;
     if(n==m && zero==26)
	{
		cout<<"array";
		//return 0;
	}
	else if( one>0 && mone==0)
	{
		cout<<"both";
	}
	else
		cout<<"need tree";
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
string s,t;map<char,int> S,T;int i,j;
main(){
  cin>>s>>t;
  for(char c:s)++S[c];
  for(char c:t)++T[c];
  if(S==T)return cout<<"array\n",0;
  for(char c:t)if(T[c]>S[c])return cout<<"need tree\n",0;
  for(;i<s.size()&&j<t.size();){
    if(s[i]==t[j])++i,++j;
    else ++i;
    if(j==t.size())return cout<<"automaton\n",0;
  }
  cout<<"both\n";
}

#include<bits/stdc++.h>
using namespace std;

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	string s, t;
	cin >> s >> t;
	unordered_map <char, int> m1;
	unordered_map <char, int> m2;
	bool ok = true, au = true, both = true;

	for (int i = 0; i < s.size(); i++)
	{
		m1[s[i]]++;
	}

	for (int i = 0; i < t.size(); i++)
	{
		m2[t[i]]++;
	}

	if (s.size() == t.size()) {

		for (auto x : m2)
		{
			if (m1[x.first] != x.second) {
				ok = false;
				break;
			}
		}
		if (ok)
			cout << "array";
		else
			cout << "need tree";
	}
	else if (s.size() > t.size())
	{
		int j = 0;
		for (int i = 0; i < s.size(); i++)
		{
			if (s[i] == t[j])
				j++;

			if (j == t.size()) {
				cout << "automaton";
				au = false;
				break;
			}
		}

		if (au)
		{
			for (int i = 0; i < t.size(); i++)
			{
				if (m1.find(t[i]) != m1.end()) {
					if (m1[t[i]] < m2[t[i]]) {
						both = false;
						break;
					}
				}
				else
				{
					both = false;
					break;
				}
			}
			if (both)
				cout << "both";
			else
				cout << "need tree";
		}
	}
	else {
		cout << "need tree";
	}

	// for (auto x : m1)
	// 	cout << x.first << " ";

	// cout << endl;

	// for (auto x : m2)
	// 	cout << x.first << " ";

	return 0;
}

#include <string>
#include <iostream>
using namespace std;
/*ifstream cin("input.txt");
ofstream cout("output.txt");*/
void main()
{
	string s,t; int i,j,a[26]={0},b[26]={0},p; bool f1=0,f2=0,f3=0,f4=0;
	cin>>s>>t;
	for(i=0;i<s.length();i++) a[s[i]-'a']++;
	for(i=0;i<t.length();i++) b[t[i]-'a']++;
	for(i=0;i<26;i++)
	{
		if(a[i]<b[i]) { f3=1; break; }
		if(a[i]>b[i]) f1=1;
		if(i==25 && a[i]==b[i] && !f1) f2=1;
	} i=0;
	if(f1)
	{
		for(j=0;j<t.length();j++)
		{
			p=s.find(t[j]);
			if(p>=0) s.erase(0,p+1); else { f4=1; break; }
		}
	}
	if(f1 && !f4) { cout<<"automaton"; return; }
	if(f2 && !f4) { cout<<"array"; return; }
	if(f1 && !f2 && !f3 && f4) { cout<<"both"; return; }
	if(f3 || (f2 && f4)) { cout<<"need tree"; return; }
}

#include <bits/stdc++.h>
#define int long long
using namespace std;

/* int isSubstring(string s1, string s2)
{
    int M = s1.length();
    int N = s2.length();

    for (int i = 0; i <= N - M; i++) {
        int j;

        for (j = 0; j < M; j++)
            if (s2[i + j] != s1[j])
                break;

        if (j == M)
            return i;
    }

    return -1;
}  */

int32_t main()
{

    string s,t;
    cin>>s>>t;
    int freq1[27];
    int freq2[27];
    for(int i=0;i<27;i++)
    {
        freq1[i]=0;
        freq2[i]=0;
    }
    for(int i=0;i<s.length();i++)
    {
        int x=s[i]-'a';
        ++freq1[x];
    }
    for(int i=0;i<t.length();i++)
    {
        int x=t[i]-'a';
        ++freq2[x];
    }
    for(int i=0;i<t.length();i++)
    {
        int x=t[i]-'a';
        if(freq2[x]>freq1[x])
        {
            cout<<"need tree"<<endl;
            return 0;
        }
    }
    int cnt=0,index=-1;
    for(int i=0;i<t.length();i++)
    {
        for(int j=index+1;j<s.length();j++)
        {
            if(s[j]==t[i])
            {
                index=j;
                ++cnt;
                break;
            }
        }
    }
    //cout<<cnt<<endl;
    if(cnt==t.length())
    cout<<"automaton"<<endl;
    else if(cnt!=t.length() && t.length()==s.length())
    cout<<"array"<<endl;
    else
    cout<<"both"<<endl;

}

#include<iostream>
#include<math.h>
#include<string>
#include<map>
#include<vector>
#include<stack>
using namespace std;
int main ()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string s,t;
	cin>>s>>t;
	if (s.length() < t.length()) {cout<<"need tree";return 0;}
	int c = 0;
	bool found[10001];
	int ind[10001];
	memset(found,false,sizeof(bool)*10001);
	int k = 0;
	int prev = 0;
	for (int i = 0;i<t.length();i++)
	{
		bool next = false;
		for (int j = prev;j<s.length();j++)
		{
			if (t[i] == s[j] && !found[j]) {ind[k++] = j;found[j] = true;c++;prev = j+1;next = true;break;}
		}
		if (next) continue;
		for (int j = 0;j<prev;j++)
		{
			if (t[i] == s[j] && !found[j]) {ind[k++] = j;found[j] = true;c++;break;}
		}
	}
	bool order = false;
	//for (int i = 0;i<k;i++) cout<<ind[i]<<" ";
	for (int i = 0;i<k - 1;i++) if (ind[i] > ind[i+1]) {order = true;break;}
	if (c==t.length() && !order && s.length()!=t.length()) cout<<"automaton";
	else if (c==t.length() && order && s.length()!=t.length()) cout<<"both";
	else if (c==t.length() && s.length()==t.length() && order) cout<<"array";
	else cout<<"need tree";
	//system("pause");
	return 0;
}

#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
ll n,l,i,j,flag,x=0,flag1;
const int N = 5e3 + 5;
vector <int> v[N],ans(N);
int b[26],c[26];
string s,t;
int isSubstring(string s1, string s2)
{
    int M = s1.length();
    int N = s2.length();
    for (i = 0; i <= N - M; i++) {
        for (j = 0; j < M; j++)
            if (s2[i + j] != s1[j])
                break;

        if (j == M)
            return 1;
    }

    return -1;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
        cin>>s;
        cin>>t;
        for(i=0;i<t.size();i++) {
            x=s.find(t[i],x);
            if(x==string::npos) {
                flag=1;
                break;
            }
            x++;
        }
        if((isSubstring(t,s)==1)||(flag==0))
        return cout<<"automaton",0;
        sort(s.begin(),s.end());
        sort(t.begin(),t.end());
        if((s.compare(t))==0)
            return cout<<"array",0;

        for(i=0;i<s.size();i++){
           b[s[i]-'a']++;
        }
        for(i=0;i<t.size();i++)
            c[t[i]-'a']++;

        for(i=0;i<26;++i) {
           if(b[i]<c[i]) {
            flag1=1;
            break;
          }
        }
        if((flag1==0)&&(s.size()>t.size()))
        return cout<<"both",0;

        cout<<"need tree";

    return 0;
}

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

int main()
{
	char s[1000],t[1000];
	int a[1000]={0},b[1000]={0};
	gets(s);
	gets(t);
	int x,y,z,i,j;
	x=y=z=0;
	for(i=0;t[i]!='\0';i++)
		for(j=0;s[j]!='\0';j++)
		{
			if(t[i]==s[j]&&!a[j])
			{
				b[i]++;
				a[j]++;
				break;
			}
		}
    for(i=0;t[i]!='\0';i++)
		if(!b[i])
		{
			cout << "need tree" << endl;
			x=1;
			break;
		}
	if(!x)
	{
		j=0;
		if(strlen(s)==strlen(t))
		{
			cout << "array" << endl;
			y=1;
		}
		else
		{
			for(i=0;s[i]!='\0';i++)
			{
				if(s[i]==t[j])
				{
					j++;
					if(t[j]=='\0')
						break;
				}
			}
			if(t[j]!='\0')
			{
				cout << "both" << endl;
				z=1;
			}
		}
		if(!y&&!z)
			cout << "automaton" << endl;
	}
	return 0;
}

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
char str1[128],str2[128];
int num1[256],num2[256];
int main(){
    int i,j,t;
    while(~scanf("%s%s",str1,str2)){
        memset(num1,0,sizeof(num1));
        memset(num2,0,sizeof(num2));
        int n1=strlen(str1),n2=strlen(str2);
        for(i=0;i<n1;i++){
            num1[str1[i]]++;
        }
        for(i=0;i<n2;i++){
            num2[str2[i]]++;
        }
        for(i=0;i<256;i++){
            if(num1[i]<num2[i])
                break;
        }
        if(n1==n2&&i==256)
            printf("array\n");
        else if(n1>n2&&i==256){
            for(i=0;i<n1;i++){
                t=0;
                for(j=i;j<n1;j++){
                    if(str2[t]==str1[j]){
                        t++;
                        if(t==n2)
                            break;
                    }
                }
                if(j!=n1){
                    break;
                }
            }
            printf("%s\n",i!=n1?"automaton":"both");
        }
        else
            printf("need tree\n");
    }
    return 0;
}

#include<stdio.h>
#include<string.h>

char s[110];
char t[110];
int cnts[30];
int cntt[30];

int main()
{
	int lens , lent;
	int i , j;
	bool atmt = false , arr = false , ntr = false;

	scanf("%s",s );
	scanf("%s",t );

	lens = strlen( s );
	lent = strlen( t );

	for( i = 0 ; i < 26 ; i++ )
	{
		cnts[i] = 0;
		cntt[i] = 0;
	}

	for( i = 0 ; i < lens ; i++ )
		cnts[ s[i] - 'a' ]++;

	for( i = 0 ; i < lent ; i++ )
		cntt[ t[i] - 'a' ]++;

	for( i = 0 ; i < 26 ; i++ )
	{
		if( cntt[i] > cnts[i] )
			ntr = true;

		if( cntt[i] < cnts[i] )
			atmt = true;

		if( cntt[i] <= cnts[i] )
			arr = true;
	}

	if( ntr )
		printf("need tree");
	else
	{
		int cnt = 0;
		for( i = 0 ; i < lens ; i++ )
		{
			if( cnt < lent )
			{
				if( s[i] == t[cnt] )
				{
				//	printf("%d %d %d %c->%c\n",i,cnt,lens,t[cnt],s[i]);
					cnt++;
				}

			}
		}

		if( cnt == lent )
			arr = false;

		if( arr && atmt )
			printf("both");
		else
			if( atmt )
				printf("automaton");
			else
				if( arr )
					printf("array");
	}

}

#include<iostream>
#include<string>
using namespace std;
bool snum[201];
int main()
{
    string s,t;
    cin>>s>>t;
    if(s.length()<t.length()){cout<<"need tree"<<endl;return 0;}
    int l=-1;
    bool yes;
    for(int i=0;i<t.length();i++)
    {
        l=s.find(t[i],l+1);
        if(l!=-1)yes=1;
        else {yes=0;break;}
    }
    if(yes){cout<<"automaton"<<endl;return 0;}
    yes=1;
    for(int i=0;i<t.length();i++)
    {
        l=s.find(t[i]);
        if(l==-1 )
        {
            yes=0;
            break;
        }
        s.erase(s.begin()+l);
    }
    if(yes && s.length()>0){cout<<"both"<<endl;return 0;}
    if(yes){cout<<"array"<<endl;return 0;}
    cout<<"need tree"<<endl;
    return 0;
}

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	string s1, s2;
	cin>>s1>>s2;

	if (s1.size()<s2.size()){
		cout<<"need tree";
		return 0;
	}

	int kol=0, f=0 ;
	int used1[26]={0,}, used2[26]={0,};
	int j=0;
	for (int i=0; i<s1.size() && j<s2.size(); i++){
			if (s1[i]==s2[j])
				j++;
		}
		if (j==s2.size()){
			cout<<"automaton";
			return 0;
		}

	for (int i=0; i<s1.size(); i++)
		used1[s1[i]-'a']++;
	for (int i=0; i<s2.size(); i++)
		used2[s2[i]-'a']++;

	kol=0;
	for (int i=0; i<26; i++){
		if (used1[i]<used2[i]){
			cout<<"need tree";
			return 0;
		}
		else {
			if (used1[i]==used2[i])
				kol++;
		}
	}
	if (s1.size()==s2.size() && kol==26)
		cout<<"array";
	else
		cout<<"both";

}

#include <bits/stdc++.h>

using namespace std;

#define NN 1100

char s[NN],t[NN];

int a[NN],b[NN],rr;

int cnt1[NN],cnt2[NN];

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	scanf("%s %s",s+1,t+1);

	int n=strlen(s+1);

	int m=strlen(t+1);

	for(int i=1;i<=n;i++) a[i]=s[i]-'0';

	for(int i=1;i<=m;i++) b[i]=t[i]-'0';

	for(int i=1;i<=n;i++) cnt1[a[i]]++;

	for(int i=1;i<=m;i++) cnt2[b[i]]++;

	for(int i=1;i<=m;i++){

		if(cnt1[b[i]]<cnt2[b[i]]){

			printf("%s","need tree");

			return 0;

		}

	}

	int r=0;

	int cnt=0;

	for(int i=1;i<=m;i++){

		r++;

		int flag=0;

		for(int j=r;j<=n;j++){

			if(b[i]==a[j]){

				rr=j;

				flag=1;

				break;

			}

		}

		if(flag==0) cnt++;

		r=rr;

	}

	if(cnt==0){

		printf("%s","automaton");

		return 0;

	}

	if(m==n){

		printf("%s","array");

		return 0;

	}

	printf("%s","both");

	return 0;

}

#include<iostream>
#include<cstdio>
#include<iomanip>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<bitset>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<algorithm>
using namespace std;

#define clr0(a) memset(a,0,sizeof(a))
#define clr1(a) memset(a,1,sizeof(a))
#define clrI(a) memset(a,63,sizeof(a))
#define pb push_back
#define re return(0)
#define sc scanf
#define pf printf
#define pii pair<int,int>

#define si(t) scanf("%d",&t)
#define sl(t) scanf("%I64d",&t)
#define sf(t) scanf("%f",&t)
#define sd(t) scanf("%lf",&t)
#define sci(ch) scanf("%c",&ch)
#define sii(a,b) scanf("%d%d",&a,&b)
#define sll(a,b) scanf("%I64d%I64d",&a,&b)
#define siii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define slll(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)

#define mx5 100005
#define mx6 1000006
#define mx7 10000007
#define inf 1<<30
#define pi  2*acos(0.0)
#define mod 1000000007

typedef long long LL;
typedef unsigned long long LLU;

const LL infinity=100000000000000LL;
int A[30],B[30],C[30];
string s,t;
int a,c;

void check()
{
    int i,j,x=-15,y,p;
    for(i=0;i<t.size();i++)
    {
        char ch=t[i];
        int f=-150;
        a=0;
        for(j=0;j<s.size();j++)
        {
            if(s[j]==ch)
            {
                f=j;
            }
            if(f>x)
            {
                a=1;
                s[j]='A';
                x=f;
                break;
            }
        }
        if(a==0)
        {
            a=0;
            c=1;
            return ;
        }
    }
}

int main()
{
    while(cin>>s)
    {
        cin>>t;
        int i,y=0;
        if(t.size()>s.size())
        {
            cout<<"need tree\n";
            continue;
        }
        clr0(A);
        clr0(B);
        for(i=0;i<s.size();i++)
        {
            int val=s[i]-96;
            A[val]++;
        }
        for(i=0;i<t.size();i++)
        {
            int val=t[i]-96;
            B[val]++;
        }
        for(i=0;i<30;i++)
        {
            if(B[i]<=A[i]) y+=B[i];
        }
        if(y!=t.size())
        {
            cout<<"need tree\n";
            continue;
        }
        check();
        if(a==1) cout<<"automaton\n";
        else if(s.size()==t.size()) cout<<"array\n";
        else cout<<"both\n";
    }
    re;
}

#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
using namespace std;
#define assem99 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define f(i,a,b) for(int i=a; i<b; i++)
#define F first
#define S second
#define sz(a) (int)(a).size()
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
const int MOD = 1e9 + 7, N = 2e5 + 5;
const double pi = acos(-1);

int arr[30], brr[30];

int main()
{
	assem99;

	int arr[30] = { 0 },brr[30] = { 0 };
	string a, b;
	cin >> a >> b;
	f(i, 0, sz(a)) arr[a[i] - 'a']++;
	f(i, 0, sz(b)) brr[b[i] - 'a']++;

	bool valid = true;
	f(i, 0, sz(b))
	{
		if (arr[b[i] - 'a'] == 0) valid = false;
		if (arr[b[i] - 'a'] > 0)
		{
			arr[b[i] - 'a']--;
		}
	}
	if (!valid) cout << "need tree";
	else
	{
		int id = 0;
		f(i, 0, sz(a)) // automaton
		{
			if (id >= sz(b) - 1)
			{
				cout << "automaton";
				return 0;
			}
			if (a[i] == b[id]) id++;
		}

		if (sz(a) == sz(b))
		{
			cout << "array";
			return 0;
		}

		else cout << "both";
	}

	return 0;
}

#include <cstdio>
#include <cstring>
char s1[105], s2[105];
int cnt1[200], cnt2[200];

int main()
{
    scanf("%s %s", s1, s2);
    memset(cnt1, 0, sizeof(cnt1));
    memset(cnt2, 0, sizeof(cnt2));
    int len2 = strlen(s2);
    int len1 = strlen(s1);
    for(int i = 0; i < len1; i++)
        cnt1[s1[i]] ++;
    for(int i = 0; i < len2; i++)
        cnt2[s2[i]] ++;
    for(int i = 0; i < len1; i++)
        if(cnt1[i] < cnt2[i])
        {
            printf("need tree\n");
            return 0;
        }
    if(len1 == len2)
    {
        if(strcmp(s1, s2) == 0)
        {
            printf("automaton\n");
            return 0;
        }
        else
        {
            for(int i = 0; i < len1; i++)
                if(cnt1[i] != cnt2[i])
                {
                    printf("need tree\n");
                    return 0;
                }
            printf("array\n");
        }
    }
    else
    {
        int i, j;
        bool f = true, f2 = false;
        for(i = 0; i < 200; i++)
        {
            if(cnt1[i] != cnt2[i])
            {
                f = false;
                break;
            }
        }
        if(f)
        {
            printf("array\n");
            return 0;
        }
        for(i = 0, j = 0; i < len1 && j < len2; i++)
            if(s1[i] == s2[j])
                j ++;
        if(j == len2)
        {
            f2 = true;
            printf("automaton\n");
            return 0;
        }
        printf("both\n");
    }
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define REV(v) rbegin(v), rend(v)
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main(){
	string s, t;
	cin >> s >> t;

	bool samenum = s.size() == t.size();
	bool substr = (int)s.find(t) >= 0;
	bool subset = true;
	rep(i, 26){
		int cs = 0, ct = 0;
		for (auto c : s) cs += c == 'a' + i;
		for (auto c : t) ct += c == 'a' + i;
		if (cs < ct) subset = false;
	}

	if (substr) cout << "automaton" << endl;
	else if (samenum && subset) cout << "array" << endl;
	else if (subset) cout << "both" << endl;
	else cout << "need tree" << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;int l1,l2,aut=0,arr=0,check=0;
	cin>>s>>t;
	l1=s.length();
    l2=t.length();
    if(l1==l2)
    {
    	aut=0;
    	sort(s.begin(),s.end());
    	sort(t.begin(),t.end());
    	for(int i=0;i<l1;i++)
    	{
    		if(s[i]!=t[i])
    		{
    			check=1;
    			arr=0;
    			break;
			}
		}
		if(check==0)
		{
			arr=1;
		}
	}
	else if(l1>l2)
	{
		aut=1;
    	 std::size_t found = s.find(t);
    	 if(found!=std::string::npos)
    	 {
    	 	arr=0;
		 }
		 else
		 {
		 	arr=1;
		 }
	}
	if(arr==1 && aut==1)
	{
		cout<<"both";
	}
	else if(arr==1 && aut==0)
	{
		cout<<"array";
	}
	else if(arr==0 && aut==1)
	{
		cout<<"automaton";
	}
	else if(arr==0 && aut==0)
	{
		cout<<"need tree";
	}
}

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;

string res(string s1, string s2) {
    if (s1.length() < s2.length()) {
        return "need tree";
        exit;
    }

    int a[26], b[26];
    for (int i = 0; i < 26; ++i) {
        a[i] = 0;
        b[i] = 0;
    }

    for (int i = 0; i < s1.length(); ++i) {
        a[s1[i] - 'a']++;
    }

    for (int i = 0; i < s2.length(); ++i) {
        b[s2[i] - 'a']++;
    }

    for (int i = 0; i < 26; ++i) {
        if (a[i] < b[i]) {
            return "need tree";
            exit;
        }
    }

    if (s1.length() == s2.length()) {
        return "array";
        exit;
    }

    for (int i = 0; i < s1.length() - s2.length() + 1; ++i) {
        int q = 1;
        for (int j = 0; j < s2.length(); ++j) {
            if (s1[i+j] != s2[j]) {
                q = 0;
                break;
            }
        }
        if (q == 1) {
                return "automaton";
                exit;
            }
    }

    return "both";
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string s1, s2;
    cin >> s1 >> s2;
    cout << res(s1,s2);

    return 0;
}

#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<map>
using namespace std;
map<char,int>a;
map<char,int>b;
string s, t;
int l1, l2;
bool Auto(int in, int ll1){
    int k  = 0;
   for(int i = in; i < ll1; i ++)
    if(s[i]== t[k])
        k ++;
    if(k == l2)
    return 1;
   return 0;
}
int main(){

    cin>>s;
    cin>>t;
    l1 = s.size();
    l2 = t.size();
    if(l1<l2){
            cout<<"need tree";
            return 0;
        }
    for(int i = 0; i < l1; i ++)
        a[s[i]] ++;
    for(int i = 0; i < l2; i ++)
        b[t[i]] ++;
    for(char i = 'a'; i <= 'w'; i ++){
        if(b[i]>a[i]){
            cout<<"need tree";
            return 0;
        }
    }
    for(int i = 0; i < l1 - l2; i ++)
    if(Auto(i,l1)){
            //cout<<i<<endl;
        cout<<"automaton";
        return 0;
    }
    if(l1 == l2){
        cout<<"array";
        return 0;
    }
    cout<<"both";
 return 0;
}

#include<bits/stdc++.h>
using namespace std;
bool is(string s,string t,int l,int m)
{
    for(int i=0;i<=l-m;++i)
    {
        int k;
        if(s[i]==t[0])
        {
            k=1;
            for(int j=1;j<m;++j)
            {
                if(t[j]!=s[i+j])
                {
                    k=2;
                    break;
                }
            }
        }
        if(k==1)
            break;
    }
}
int main()
{
    string s,t;
    cin>>s>>t;
    int l=s.size();
    int m=t.size();
    int a[26],b[26];
    for(int i=0;i<26;++i)
        a[i]=b[i]=0;
    for(int i=0;i<l;++i)
        a[s[i]-97]++;
    for(int i=0;i<m;++i)
        b[t[i]-97]++;
    if(l<m)
        cout<<"need tree";
    else if(l==m)
    {
        int j=1;
        for(int i=0;i<26;++i)
        {
            if(a[i]!=b[i])
            {
                j=0;
                break;
            }
        }
        if(j)
            cout<<"array";
        else
            cout<<"need tree";
    }
    else
    {
        int n=1;
        int o=is(s,t,l,m);
        for(int i=0;i<26;++i)
        {
            if(b[i]!=0&&b[i]>a[i])
            {
                n=0;
            }
        }
        if(o)
            cout<<"automaton";
        else if(n)
            cout<<"both";
        else
            cout<<"need tree";
    }
    return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

int m,n,l,p,o;

string s,t;

int main()
{
    cin>>s>>t;

    if(s.length()<t.length())
        cout<<"need tree";
        else{
    for(int i=0;i<t.length();i++){
        for(int j=o;j<s.length();j++){
            if(t[i]==s[j]){
                l=1;
                o++;
            }
        }
    if(l==0){
        p=1;
    }
        l=0;
    }

    if(p==1)
        cout<<"need tree";
    else{
    for(int i=0;i<s.length();i++){
        for(int j=0;j<t.length();j++){
            if(s[i]==t[j])
                l=1;
        }
    if(l==0){
        m=1;
    }
        l=0;
    }
    int j=0;
    for(int i=0;i<s.length();i++){
        if (t[j]==s[i])
            j++;
        if(s.length()-i<t.length()-j)
            n=1;
    }
    if(s.length()>t.length())
        m=1;
    if(m==1 && n==0)
        cout<<"automaton";
    if(m==1 && n==1)
        cout<<"both";
    if(m==0 && n==1)
        cout<<"array";

    }
}
}

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#include <functional>
#define N 1050
using namespace std;
#define ll long long
#define INF 99999999

//#define IN freopen("c:\\Users\\mfmy\\desktop\\input.txt", "r", stdin)
//#define OUT freopen("c:\\Users\\mfmy\\desktop\\output.txt", "w", stdout)

bool cmp(char a,char b)
{
	return a<b;
}

int main()
{
	char s1[1005],s2[1005],s3[1005],s4[1005];
	int l3,l4;
	while(scanf("%s",s1)!=EOF)
	{
		scanf("%s",s2);
		int l1=strlen(s1);
		int l2=strlen(s2);
		int temp=0;
		if(l1>=l2)
		{
			l3=l1,l4=l2;
			strcpy(s3,s1);
			strcpy(s4,s2);
		}
		else
		{
			printf("need tree\n");
			continue;
		}
		int flag=0,num;
		for(int i=0;i+l4<l3;i++)
		{
			num=0;
			for(int j=0;j<l4;j++)
			{
				if(s3[i+j]==s4[j])
				{
					num++;
				}
			}
			if(num==l4)
				flag++;
		}
		if(flag==1)
		{
			printf("automaton\n");
			continue;
		}
		sort(s3,s3+l3,cmp);
		sort(s4,s4+l4,cmp);
		num=0;
		for(int i=0,j=0;i<l3,j<l4;)
		{
			if(s3[i]==s4[j])
			{
				i++,j++;
				num++;
			}
			else if(s3[i]>s4[j])
				break;
			else
			{
				i++;
			}
		}
		if(num==l4)
		{
			if(l3==l4)
				printf("array\n");
			else
				printf("both\n");
			continue;
		}
		printf("need tree\n");
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string s1,s2;
    cin>>s1>>s2;

    if(s1.find(s2)!=string :: npos)
     {
         cout<<"automaton";
         return 0;
     }

    map<char,int> mp,mp1,mp2;

    for(int i=0;i<s1.size();i++)
     {
         mp[s1[i]]++;
         mp1[s1[i]]++;
     }
     int f=0;
     for(int j=0;j<s2.size();j++)
     {
         if(mp[s2[j]]==0)
           f=1;

           else
           mp[s2[j]]--;
     }

     for(int i=0;i<s2.size();i++)
         mp2[s2[i]]++;

    //  cout<<mp2['a']<<endl;
      if(mp1==mp2)
      {
          cout<<"array";
          return 0;
      }
        if(f==0)
      {
          cout<<"both";
          return 0;
      }

     int i=0,j=0;

     while(i<s1.size() && j<s2.size())
     {
         if(s1[i]==s2[j])
          {
              i++;
              j++;
          }
          else
          j++;

     }
     if(j==s2.size())
     {
         cout<<"automaton";
         return 0;
     }

      cout<<"need tree";
      return 0;
}

#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
//#include <search.h>
#include <algorithm>
//#include <vector>
using namespace std;
int main()
{
  int tree=0,arrayy=0,both=0,autoo=0,sum=0,in=0,check=0;
  string s,t;
  cin>>s>>t;
  if(s.length()>t.length()) autoo=1;
  for(int i=0;i<t.length();++i){
    for(int j=0;j<s.length();++j){
            check=0;
       if(t[i]==s[j] && in==0){
            sum++;
            in=j;
            s[j]='*';
            break;
       }
       else if(t[i]==s[j] && in!=0){
        sum++;
        if(j!=in-1){
            arrayy=1;
        }
        s[j]='*';
        break;
       }
    }
  }

  if(arrayy==1 && autoo==1 &&sum==t.length()){
    cout<<"both";
  }
  else if(arrayy==1 && autoo==0 &&sum==t.length()){
    cout<<"array";
  }
  else if(arrayy==0 && autoo==1 &&sum==t.length()){
    cout<<"automaton";
  }
  else {
    cout<<"need tree";
  }
return 0;

}

#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 92233720ll;
string s,t;
int alpha[26];
void solve(){
 bool b1,b2;
 loop(i,0,26)
  alpha[i] = 0;
 cin>>s>>t;
 int n = s.size();
 int m = t.size();
 if(n<m)
   cout<<"need tree";
 else if(n==m){
  loop(i,0,n){
   alpha[t[i]-'a']--;
   alpha[s[i]-'a']++;
  }
  b1 = 1;
  loop(i,0,26)
   b1 &= (alpha[i] == 0);
  if(b1)
     cout<<"array";
  else
     cout<<"need tree";
 }
 else{
  b2 = 1;
  int p1 = 0,p2 = 0;
  while(p1<n){
    while(p2<m && s[p1] == t[p2])
       p2++;
    p1++;
  }
 if(p1 == n && p2 == m)
   cout<<"automaton";
 else{
  b1 = 1;
  loop(i,0,n)
   alpha[s[i]-'a']--;
  loop(i,0,m)
   alpha[t[i]-'a']++;
  loop(i,0,26)
   b1 &= (alpha[i] == 0);
  if(b1)
     cout<<"both";
  else
     cout<<"need tree";
  }
 }
}
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   freopen("error.txt","w",stderr);
  #endif
   /*int t;
   cin>>t;
   while(t--)*/
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
}

#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    int s[28]= {0},t[28]= {0},i,j;
    bool fs=0,ft=0,f=0;
    char strs[120],strt[120];
    scanf("%s",strs);
    i=0;
    while(strs[i])
    {
        s[strs[i]-'a']++;
        i++;
    }
    scanf("%s",strt);
    i=0;
    while(strt[i])
    {
        t[strt[i]-'a']++;
        i++;
    }
    for(i=0; i<26; i++)
    {
        if(s[i]!=t[i])
        {
            if(s[i]>t[i]) fs=1;
            else if(t[i]>s[i]) ft=1;
        }
    }
    if(ft)
    {
        printf("need tree\n");
    }
    else if(fs==0&&ft==0)
    {
         for(i=0; strs[i]; i++)
        {
                for(j=0; strt[j]; j++)
                    if(strs[i+j]!=strt[j]){break;}
                if(strt[j]=='\0') f=1;
        }
        if(f==0) printf("array\n");
        else printf("need tree\n");
    }
    else
    {
        j=0;
        for(i=0; strs[i]; i++)
        {
            if(strs[i]==strt[0])
            {
                for(j=0; strt[j]; j++)
                    if(strs[i+j]!=strt[j]){break;}
                if(strt[j]=='\0') f=1;
            }
        }
        if(f==0) printf("both\n");
        else printf("automaton\n");
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    int l1,l2;
    l1=s.length();
    l2=t.length();
    int array1[l1];
    int array2[l2];
    for(int i1=0;i1<l1;i1++)
    {
        array1[i1]=(int)s.at(i1);
    }
    for(int i2=0;i2<l2;i2++)
    {
        array2[i2]=(int)t.at(i2);
    }
    if(l1!=l2)
    {
        int array3[l2];
        for(int i3=0;i3<l2;i3++)
        {
            array3[i3]=0;
        }
        int q1=0;
        for(int i4=0;i4<l2;i4++)
        {
            for(int i5=0;i5<l1;i5++)
            {
                if(array2[i4]==array1[i5])
                {
                    q1++;
                    array3[i4]+=i5;
                    array1[i5]=1;
                    break;
                }
            }
        }
        int q2=0;
        for(int i6=0;i6<l2-1;i6++)
        {
            if(array3[i6]<array3[i6+1])
            {
                q2++;
            }
        }
        if(q2==l2-1 && q1==l2)
        {
            cout<<"automaton";
        }
        else if(q2!=l2-1 && q1==l2)
        {
            cout<<"both";
        }else if(q1!=l2)
        {
            cout<<"need tree";
        }
    }else
    {
        sort(array1,array1+l1);
        sort(array2,array2+l2);
        int q3=0;
        for(int i7=0;i7<l1;i7++)
        {
            if(array1[i7]==array2[i7])
            {
                q3++;
                if(q3==l1)
                {
                    cout<<"array";
                }
            }
            else
            {
                cout<<"need tree";
                break;
            }
        }
    }
}

#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;

char s[101], t[101];
int ps[26], pt[26];

int main() {
	scanf("%s ", s);
	scanf("%s", t);
	for (int i=0; s[i]; ++i)
		++ps[s[i]-'a'];
	for (int i=0; t[i]; ++i)
		++pt[t[i]-'a'];
	bool needtree = 0, automation = 0;
	for (int i=0; i<26; ++i)
		if (ps[i] < pt[i])
			needtree = 1;
	for (int i=0; s[i]; ++i) {
		bool temp = 1;
		for (int j=0; t[j]; ++j)
			if (t[j] != s[i+j]) {
				temp = 0; break;
			}
		if (temp) {
			automation = 1; break;
		}
	}
	if (needtree)
		puts("need tree");
	else if (automation)
		puts("automaton");
	else if (strlen(s) == strlen(t))
		puts("array");
	else
		puts("both");
	return 0;
}

/*
 * Author: Gatevin
 * Created Time:  2014/7/17 22:17:32
 * File Name: test.cpp
 */
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;

string s1,s2;

bool isS(string s11, string s22)
{
    string s1,s2;
    if(s11.length() < s22.length())
    {
         s1 = s11;
        s2 = s22;
    }
    else
    {
        s1 = s22;
        s2 = s11;
    }
    int tmp = s1.length() - 1;
    bool vis1[101];
    bool vis2[101];
    memset(vis1, 0, sizeof(vis1));
    memset(vis2, 0, sizeof(vis2));
    int flag1;
    for(int i = 0; i <= tmp; i++)
    {
        flag1 = 0;
        for(int j = 0; j <= s2.length() - 1; j++)
        {
            if(!vis2[j])
            {
                if(s2[j] == s1[i])
                {
                    flag1 = 1;
                    vis2[j] = 1;
                    break;
                }
            }
        }
        if(!flag1) return false;
    }
    return true;
}

bool isSub(string s11, string s22)
{
    string s1,s2;
    if(s11.length() < s22.length())
    {
         s1 = s11;
        s2 = s22;
    }
    else
    {
        s1 = s22;
        s2 = s11;
    }
    bool flag = false;
    int nexj = 0;
    for(int i = 0, j = 0; i < s2.length() && j < s1.length() ;)
    {
        if(s1[j] == s2[i])
        {
            j++;
            i++;
            nexj = j;
        }
        else
        {
            i++;
        }
    }
    if(nexj < s1.length())
    return false;
    else
    {
        return true;
    }
}

int main()
{
    cin>>s1>>s2;
    if(s1.length() < s2.length())
    {
        cout<<"need tree"<<endl;
    }
    if(s1.length() == s2.length())
    {
        if(isS(s1,s2))
        {
            cout<<"array"<<endl;
            return 0;
        }
        else
        {
            cout<<"need tree"<<endl;
        }
    }
    else
    {
        if(isSub(s1,s2))
        {
            cout<<"automaton"<<endl;
        }
        else
        {
            if(isS(s1,s2))
            {
                cout<<"both"<<endl;
            }
            else
            {
                cout<<"need tree"<<endl;
            }
        }
    }
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

const int MAXN = 100001;

int main() {
	string s, t;

	string ans[4] = {"need tree", "automaton", "array", "both"};

	cin >> s >> t;

	int sL = s.size(), tL = t.size();

	if (sL < tL) {
		cout << ans[0] << endl;
		return 0;
	}
	int i, j = 0;
	for (i = 0; i < tL; ++ i) {
		if (j >= sL) {
			break;
		}
		while (j < sL) {
			if (s[j] == t[i]) {
				break;
			}
			++ j;
		}
	}
	if (i == tL) {
		cout << ans[1] << endl;
		return 0;
	}
	else {
		sort (s.begin(), s.end());
		sort (t.begin(), t.end());
		if (s == t) {
			cout << ans[2] << endl;
			return 0;
		}
		for (int i = 0; sL - i >= tL; ++ i) {
			if (s.substr(i, tL) == t) {
				cout << ans[3] << endl;
				return 0;
			}
		}
	}
	cout << ans[0] << endl;
	return 0;
}

#include <iostream>
#include <string>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;

int main()
{
    string temps1,temps2,s1,s2,temp;
    cin>>s1>>s2;
    if (s2.size()>s1.size()){
        temp=s1;
        s1=s2;
        s2=temp;
    }
    for (int i=0;i<s2.size();i++){
        if (s1.find(s2[i])==string::npos){
            cout<<"need tree";
            return 0;
        }
    }
    if (s1.size()==s2.size()){
        cout<<"array";
    }
    else{
        int j=0;
        vector<int> d(100,0);
        temps1=s1;
        temps2=s2;
        for (int i=0;i<temps2.size();i++){
            d[j]=temps1.find(temps2[i]);
            temps1[temps1.find(temps2[i])]='.';
            //cout<<temps1<<endl;
            j++;
        }
//        for (int i=0;i<j;i++){
//            cout<<d[i]<<" ";
//        }
        cout<<endl;
        if ((s1.find(s2)!=string::npos) ||(is_sorted(d.begin(),d.begin()+j-1))){
            cout<<"automaton";
        }
        else cout<<"both";
    }
}

/*
 * Suffix Structures.cpp
 *
 *  Created on: Apr 18, 2015
 *      Author: Mohamed
 */

#include<bits/stdc++.h>
using namespace std;
string method(string s , string t){
	vector<int> index ;
	for(int i=0 ; i<t.length() ; i++){
		bool truth = false ;
		 for(int j=0; j<s.length() ; j++){
			  if(t[i]==s[j]){
				  truth = true ;
				  index.push_back(i) ;
				  s[i]='*' ;
			  }
		 }
		 if(!truth){
			 return "need tree" ;
		 }
	}
	bool truth = true ;
	for(int i=0 ; i<index.size()-1 ; i++){
		 if(index[i]>index[i+1]){
			  truth = false ;
		 }
	}
	if(!truth&&s.size()>t.size()){
		return "both" ;
	}if(!truth){
		return "array" ;
	}

	return "automaton" ;
}

int main(){
	string s , t ;
	cin>>s>>t ;
cout<<method(s,t)<<endl;

return 0;
}

#include<iostream>
#include<string>
#include<string.h>
void fun(int);
using namespace std;
string str1,str2;
int cow=0;
int main()
{

	cin>>str1>>str2;
	int l=str1.size();
	//for automaton
	for (int i = 0; i < str1.size(); ++i)
		{
			if (str2[0]==str1[i]&&str2.size()!=str1.size())
			fun(i);
		}

	//if(str1.size()==str2.size())
	{
		str1=str1+"+";
		str2=str2+"-";

		for (int i = 0; i < str1.size(); ++i)
		{
			for (int j = 0; j < str2.size(); ++j)
			{

				if(str1[i]==str2[j])
				{
					//cout<<i<<" "<<j<<" ";
					str1.erase(str1.begin()+i);
					str2.erase(str2.begin()+j);
					i--;
					j--;

				}

			}
		}
	}
	//cout<<str1<<str2;
	if (str1.size()==1&&str2.size()==1&&str1[0]=='+'&&str2[0]=='-')
	{
		cout<<"array";
		cow++;
	}
	else if(str1.size()>1&&str2.size()==1&&str2[0]=='-'&&cow==0)
	{
		cout<<"both";
		cow++;
	}
	else if(cow==0)
	{
		cout<<"need tree";
	}

	return 0;

}

void fun(int x)
{
	//cout<<"x is :"<<x;
	int count=0;
	   for (int j = 0; j < str2.size(); ++j)
				{
					for (int i = x; i < str1.size(); ++i)
					{
						if (str2[j]==str1[x])
					   {
						  //cout<<j;
						  count++;
						  break;
					   }
					   x++;
					}
				}
				//cout<<count<<endl;
		if (count==str2.size())
		{
			cow++;

			cout<<"automaton";
		}

}

#include<bits/stdc++.h>
using namespace std;

string sone, stwo;
int n, m;
int main() {
	cin >> sone >> stwo;
	n = sone.length();
	m = stwo.length();
	if(n < m) {
		cout << "need tree" << endl;
		return 0;
		}
		else if(n == m) {
			for(int i = 0; i < m; ++i) {
				if(sone.find(stwo[i]) == string :: npos) {
					cout << "need tree" << endl;
					return 0;
					}
				}
				cout << "array" << endl;
				return 0;
			}
			else {
				for(int i = 0; i < m; ++i) {
					if(sone.find(stwo[i]) == string :: npos) {
						cout << "need tree" << endl;
						return 0;
						}
					}
					if(sone.find(stwo) == string :: npos) {
						cout << "both" << endl;
						return 0;
						}
						cout << "automaton" << endl;
						return 0;
				}
	}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s, t;
    while(cin>>s>>t)
    {
        bool ok1 = 0, ok2 = 0;
        if(s.find(t) != -1) ok1 = 1;

        int F[26] = {};
        for(int i=0; i<s.size(); i++)
            F[s[i]-'a']++;
        for(int i=0; i<t.size(); i++)
            F[t[i]-'a']--;
        ok2 = 1;
        for(int i=0; i<26; i++)
            if(F[i] != 0)
                ok2 = 0;

        bool ok3=1;
        for(int i=0; i<26; i++)
            if(F[i] < 0)
                ok3=0;

        if(ok1) cout<<"automaton"<<endl;
        else if(ok2) cout<<"array"<<endl;
        else if(ok3) cout<<"both"<<endl;
        else cout<<"need tree"<<endl;
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int one[26],cpy[26];
vector<pair<int,int> >adj[26];
int main()
{
    string s1,s2,a,b;
    int l,m;
    cin>>s1>>s2;
    l=s1.length();
    m=s2.length();
   if(l==m)
   {
       a=s1;b=s2;
   }
   else if(l<m)
   {
       a=s2;b=s1;
   }
   else
   {
       a=s1;b=s2;
   }
    for(int i=0;i<a.length();i++)
    {
        one[a[i]-'a']++;
        adj[a[i]-'a'].push_back(make_pair(i,0));
    }
    for(int i=0;i<b.length();i++)
        {
            cpy[b[i]-'a']++;
        }
        if(l==m)
        {
            bool val=true;
            for(int i=0;i<l;i++)
            {
                if(one[i]!=cpy[i])
                {
                          val=false;break;
                }
            }
            if(val)
            {
                printf("array");return 0;
            }
            printf("need tree");return 0;
        }
        else
        {
            bool val;int k=-1;
            for(int i=0;i<b.length();i++)
            {
                val=false;
                for(int j=0;j<adj[b[i]-'a'].size();j++)
                {
                    if(adj[b[i]-'a'][j].first>k&&i<=adj[b[i]-'a'][j].first&&!(adj[b[i]-'a'][j].second))
                    {
                        adj[b[i]-'a'][j].second=1;
                        k=adj[b[i]-'a'][j].first;
                        val=true;
                        break;
                    }
                }
            }
                if(val)
                {
                    printf( "automaton");return 0;
                }
                else{printf("both");return 0;}
                printf("need tree");return 0;
        }
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    string t;
    cin>>t;
    int lt=t.length();
    int ls=s.length();

    if(ls==lt)
    {
        int hashs[26];
        int hasht[26];
        for(int i=0 ; i<26 ; i++)
        {
            hashs[i]=0;
            hasht[i]=0;
        }
        for(int i=0 ; i<ls ; i++)
        {
            hashs[s[i]-97]=1;
            hasht[t[i]-97]=1;
        }
        int a=0;
        for(int i=0 ; i<26 ; i++)
        {
            if(hashs[i]!=hasht[i])
            {
                a=1;
                break;
            }
        }
        if(a==0)
        {
            cout<<"array";
        }
        else
        {
            cout<<"need tree";
        }
    }
    else
    {
        int hashs[26];
        int hasht[26];
        for(int i=0 ; i<26 ; i++)
        {
            hashs[i]=0;
            hasht[i]=0;
        }
        for(int i=0 ; i<ls ; i++)
        {
            hashs[s[i]-97]=1;
            hasht[t[i]-97]=1;
        }
        int a=0;
        for(int i=0 ; i<26 ; i++)
        {
            if(hashs[i]!=1 && hasht[i]==1)
            {
                a=1;
                break;
            }
        }
        if(a==0)
        {
            int p=0,z=0;
            for(int i=0 ; i<ls ; i++)
            {
                if(s[i]==t[z])
                {
                    z++;
                }
                else
                {
                    z=0;
                }
                if(z==lt)
                {
                    p=1;
                    break;
                }
            }
            if(p==0)
            {
                cout<<"both";
            }
            else
            {
                cout<<"automation";
            }
        }
        else
        {
            cout<<"need tree";
        }

    }

}
//aaa

#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

int check(vector<pair<char, int> > &v, char s)
{
	for (int i = 0; i < v.size(); i++)
	{
		if (v[i].first == s) return i;
	}
	return -1;
}

bool func(vector<pair<char, int> > &v1, vector<pair<char, int> > &v2)
{
	for (int i = 0; i < v2.size(); i++)
	{
		if (check(v1, v2[i].first) == -1) return true;
	}
	return false;
}

int main()
{
	string str1, str2;
	vector<pair<char, int> > v1, v2;
	cin >> str1;
	cin >> str2;
	if (str1.find(str2) != str1.npos && str1.length() > str2.length())
	{
		cout << "automaton";
		return 0;
	}
	for (int i = 0; i < str1.length(); i++)
	{
		int k = check(v1, str1[i]);
		if (k == -1) v1.push_back(make_pair(str1[i], 1));
		else
		{
			v1[k].second++;
		}
	}
	for (int i = 0; i < str2.length(); i++)
	{
		int k = check(v2, str2[i]);
		if (k == -1) v2.push_back(make_pair(str2[i], 1));
		else
		{
			v2[k].second++;
		}
	}
	if (func(v1, v2))
	{
		cout << "need tree";
		return 0;
	}
	int count = 0;
	for (int i = 0; i < v1.size(); i++)
	{
		int k = check(v2, v1[i].first);
		if (k != -1 && v1[k].second != v2[k].second)
		{
			count++;
		}
	}
	if (count != 0)
	{
		cout << "both";
		return 0;
	}
	else
	{
		cout << "array";
		return 0;
	}
	return 0;
}

//q4s7mmmm
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define f first
#define se second
using namespace std;
int c[123], d[123];
int main() {
	string a, b;
	cin >> a >> b;
	if (a.size() > b.size())
		for (int i = 0; i < a.size() - b.size(); i++)
			if (a.substr(i, b.size()) == b)
				return cout << "automaton", 0;
	for (int i = 0; i < a.size(); i++)
		c[a[i] - 'a']++;
	for  (int i = 0; i < b.size(); i++)
		d[b[i] - 'a']++;
	int sum = 0;
	for (int i = 0; i < 26; i++)
		if (c[i] == d[i])
			sum++;
	if (sum == 26)
		return cout << "array", 0;
	sum = 0;
	for (int i = 0; i < 26; i++)
		if (c[i] >= d[i])
			sum++;
	if (sum == 26 && a.size() >= b.size())
		return cout << "automaton", 0;
	if (sum == 26)
		return cout << "both", 0;
	cout << "need tree";
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    string t;

    cin >> s >> t;

    int sarr[26] = {0};
    int tarr[26] = {0};

    for(int i = 0 ; i < s.length() ; i++)
    {
        sarr[s[i] - 97]++;
    }
    for(int i = 0 ; i < t.length() ; i++)
    {
        tarr[t[i] - 97]++;
    }

    if(s.length() < t.length())
    {
        cout << "need" << " " << "tree";
        return 0;
    }

    int flag = 0;

    if(s.length() == t.length())
    {
        for(int i = 0 ; i < 26 ; i++)
        {
            if(tarr[i] != sarr[i])
            {
                flag = 1;
                break;
            }
        }
        if(flag == 1)
        {
            cout << "need" << " " << "tree";
        }
        else
        {
            cout << "array";
        }
        return 0;
    }
    else
    {
        for(int i = 0 ; i < 26 ; i++)
        {
            if(sarr[i] < tarr[i])
            {
                flag = 1;
                break;
            }
        }
        if(flag == 1)
        {
            cout << "need" << " " << "tree";
            return 0;
        }
        else
        {
            if(s.find(t) != -1)
            {
                cout << "automaton";
                return 0;
            }
            else
            {
                cout << "both";
                return 0;
            }
        }

    }

           return 0;

    /*
    int n , s , t;

    cin >> n >> s >> t;
    int arr[n+1];

    for(int i = 1; i <= n ; i++)
    {
        cin >> arr[i];
    }

    int pos = arr[s];
    int count = 1;

    if(s == t)
    {
        cout << "0";
        return 0;
    }
    else
    {
        while(1)
        {
            if(pos == t)
            {
                cout << count;
                return 0;
            }
            else if(pos == s)
            {
                cout << "-1";
                return 0;
            }
            else
            {
                pos = arr[pos];
                count++;
            }
        }
    }
*/

    /*
    int n;
    cin >> n;

    int arr[n];

    for(int i = 0 ; i < n ; i++)
    {
        cin >> arr[i];
    }
    int sum = arr[0];
    for(int i = 0 ; i < n - 1; i++)
    {
        sum = sum + abs(arr[i] - arr[i + 1]);
    }
    sum  = sum + n + n -1;

    cout << sum;
*/
    /*
    long long m = 1000000007;
    long long f1 , f2;
    long long n;

    cin >> f1 >> f2;
    cin >> n;

    long long arr[20];

    arr[0] = f1;
    arr[1] = f2;

    for(int i = 2 ; i < 6 ; i++)
    {
        arr[i] = (arr[i-1] - arr[i-2] + m)%m;
    }

    cout << (arr[(n-1)%6]+m)%m;
    return 0;
    */
    /*
    int n;
    int arr[100005];

    cin >> n;

    for(int i = 0 ; i < n ; i++)
    {
        cin >> arr[i];
    }

    int i = 0;
    int ans = 0;
    bool flag = true;

    for( ; i < n - 1 ; i++)
    {
        if(arr[i] > arr[i+1])
            break;
    }
    if(i == n-1)
    {
        cout << "0";
        return 0;
    }

    for(i = i + 1 ; i < n ; i++)
    {
        ans++;
        if(arr[i] > arr[(i+1)%n])
        {
            flag = false;
            break;
        }
    }

    if(flag)
    {
        cout << ans;
    }
    else
    {
        cout << "-1";
    }

    return 0;

    */
    /*
     double a,b,c,d,e;
     cin>>a>>b>>c>>d>>e;

    cout<<ceil((double(sqrt((b-d)*(b-d)+(c-e)*(c-e)))/(2*a)));
    */
/*
    double a , x , y , x1 , y1;
    cin >> a >> x >> y >> x1 >> y1;

    double t = (x1 - x)*(x1 - x) + (y1 - y)*(y1 - y);

    t = sqrt(t);
    cout << ceil(t/(2*a));
    //cout<<ceil((double(sqrt((b-d)*(b-d)+(c-e)*(c-e)))/(2*a)));

/*
    string s;

    int arr[26];
    int k;

    cin >> s;
    cin >> k;

    for(int i = 0 ; i < 26 ; i++)
    {
        cin >> arr[i];
    }

    int sum = 0;
    for(int i = 0 ; i < s.length() ; i++)
    {
        sum = sum + (i+1)*arr[s[i] - 97];
    }

    int m = *max_element(arr , arr+26);

    int x = s.length();
    for(int i = 0 ; i < k ; i++)
    {
        sum = sum + (++x)*m;
    }

    cout << sum;
*/
    /*

    string s;

    cin >> s;

    int ecount = 0;
    int flag = 0;

    for(long long i = 0 ; i < s.length() ; i++)
    {
        if((s[i]-'0')%2 == 0 && s[i] < s[s.length() - 1])
        {
            flag = 1;
            ecount++;
            swap(s[i] , s[s.length() - 1]);
            break;
        }
        if((s[i]-'0')%2 == 0)
        {
            ecount++;
        }
    }

    if(ecount == 0)
    {
        cout << "-1";
    }
    else if(flag == 1)
    {
        cout << s;
    }
    else
    {
        for(long long i  = s.length() - 1 ; i >= 0 ;i--)
        {
            if((s[i]-'0')%2 == 0)
            {
                swap(s[i] , s[s.length() - 1]);
                break;
            }
        }
        cout << s;
    }
*/
/*
    long long n;
    cin >> n;
    vector<long long> v;
    for(long long i = 0 ; i < n ; i++)
    {
        long long t;
        cin >> t;
        v.push_back(t);

    }

    vector<int> primes(1000001, 1);
    set<long long> s;

    primes[0] = primes[1] = 0;

    for(long long i = 2 ; i <= 1000001 ; i++)
    {
        if(primes[i])
        for(long long j = i ; i*j <= 1000001 ; j++)
        {
            primes[i*j] = 0;
        }
    }

    for(long long i = 2 ; i <= 1000001 ; i++)
    {
            if(primes[i])
            {
                s.insert(i*i);
            }
    }

    for(long long i = 0 ; i < n ; i++)
    {
        if(s.find(v[i]) != s.end())
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
*/
/*
    vector<pair<string,string>> v1;

    int m , n;

    cin >> m >> n;

    for(int i = 0 ; i < n ; i++)
    {

        string s1 , s2;
        cin >> s1 >> s2;

        v1.push_back(make_pair(s1 , s2));
    }

    vector<string> v2;

    for(int i = 0 ; i < m ; i++)
    {
        string s;
        cin >> s;

        v2.push_back(s);
    }

    for(int i = 0 ; i < m ; i++)
    {
        for(int j = 0 ; j < n ; j++)
        {
            if(v2[i] == v1[j].first)
            {
                if(v1[j].first.length() <= v1[j].second.length())
                {
                    cout << v1[j].first << " ";
                }
                else
                {
                    cout << v1[j].second << " ";
                }
            }

        }
    }
    */
/*
    uint64_t n;
    cin >> n;

    vector<uint64_t> v;

    for(uint64_t i = 0 ; i < n ; i++)
    {
        uint64_t t ;
        cin >> t;
        v.push_back(t);
    }
    uint64_t flag = 0;
    uint64_t start = 0 ; uint64_t end = 0;
    for(uint64_t i = 0 ; i < n-1 ; i++)
    {
        if(v[i] > v[i+1])
        {
            start = i;
            break;
        }
    }
    for(uint64_t i = n - 1 ; i >= 0 ; i--)
    {
        if(v[i] < v[i-1])
        {
            end = i;
            break;
        }
    }

    reverse(v.begin()+start , v.begin()+end + 1);
    for(uint64_t i = 0 ; i < n - 1 ; i++)
    {
       if(v[i] > v[i+1])
       {

           cout << "no";
           return 0;
       }
    }
  //  cout << endl;
    cout << "yes" << endl;
    cout << (start+1) <<"  " << (end+1);
*/
    /*
    uint64_t n , l;

    cin >> n >> l;

    uint64_t arr[n];

    for( int i = 0 ; i < n ; i++)
    {
        cin >> arr[i];
    }

    sort(arr , arr + n);

    double s = (double)arr[0];
    double e = (double)(l - arr[n-1]);

   // cout << s << " " << e << " ";
    int x = 0.0;

    for(int i = 0 ; i < n - 1 ; i++)
    {
        int t = (arr[i + 1] - arr[i])*1.0;
        if(t > x)
        {
            x = t;
        }
    }

   // cout << float(x/2.0) << " ";
    printf("%.9lf\n", max(s , max(e , double(x/2.0))));
*/
    /*

    uint64_t m , n ;
    cin >> n >> m;

    if(m == 1)
    {
        uint64_t ans = n*(n - 1)/2;
        cout << ans <<" " << ans;
        return 0;
    }

    uint64_t p = n/m ;
    uint64_t q = n%m;

    int a = (p+1)*q;

    int r = n - a;

    uint64_t min = q*(p)*(p+1)/2 + r*p*(p-1)/2;
    uint64_t min1 = q*(p)*(p+1)/2 + r*(r-1)/2;

    cout << min << " "<<  min1;
    uint64_t temp = n - m + 1;

    uint64_t max = (temp*temp - temp)/2;

    cout << min <<" "<< max ;
    */
    /*

    int n , m , k;

    cin >> n >> m >> k;

    vector<int> v;
    for(int i = 0 ; i <= m ; i++)
    {
        int t;
        cin >> t;
        v.push_back(t);
    }
    int f = v[v.size() - 1];
    int ans = 0;
    for(auto i = 0 ; i < v.size() - 1 ; i++)
    {
        int temp = f;
        int count = 0;
        while(v[i] > 0 && temp > 0)
        {
            if(v[i]%2 != temp%2)
            {
                count++;
            }

            v[i] = v[i]/2;
            temp = temp/2;
        }
        while(v[i] > 0)
        {
            if(v[i]%2 != 0)
            {
                count++;
            }
            v[i] = v[i]/2;
            }
        while(temp > 0)
        {
            if(temp%2 != 0)
            {
                count++;
            }
            temp = temp/2;
        }

        if(count <= k)
        {
            ans++;
        }

    }

    cout << ans;
    */
    /*
    uint64_t m , n;
    cin >> n >> m;
    uint64_t x;

    uint64_t ans = 0;
    uint64_t cur = 1;
    while(m--)
    {
        cin >> x;
        if(cur < x)
        {
            ans = ans + x - cur;
            cur = x;
        }
        else if(cur > x)
        {
            ans = ans + n + x - cur;
            cur = x;
        }
    }

    cout << ans;
*/    /*

    string str;
    int n;
    int t;

    cin >> n >> t;
    cin >> str;

    while(t--)
    for(int i = 0 ; i < n - 1; i++)
    {
        if(str[i] == 'B' && str[i+1] == 'G')
        {
            swap(str[i] , str[i+1]);
            i++;
        }
    }

    cout << str;
    */
/*
    int t;
    cin >> t;

    while(t--)
    {
        string s ;
        cin >> s;

        if(s.length() > 10)
        {
            cout << s[0] << s.length() - 2 << s[s.length() -1] << endl;
        }
        else
        {
            cout << s << endl;
        }
    }
    */
    /*
    int w;
    cin>>w;
    if(w == 2)
     {

     cout << "NO";
    return 0;}
    if(w%2 == 0)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
    */
}

#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>

#include <time.h>
#pragma comment(linker, "/STACK:20000000")

#define fr(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define fd(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define mp make_pair
#define pb push_back
#define ll long long

using namespace std;

int ri(){int x;scanf("%d",&x);return x;}
ll rll(){ll x;scanf("%lld",&x);return x;}

int cnta[255];
int cntb[255];

void solve()
{
	string a;
	string b;
	cin >> a >> b;
	fr(i,0,a.length() - 1)
		cnta[a[i]]++;
	fr(i,0,b.length() - 1)
		cntb[b[i]]++;
	string ta = a,tb = b;
	bool resa = true,resb = true,resc = true;
	fr(i,'a','z')
		if (cnta[i] != cntb[i])
			resb = false;
	fr(i,'a','z')
		if (cnta[i] < cntb[i])
			resc = false;
	int pos = 0;
	for(int i = 0;i < b.length();i++)
	{
		while(pos != a.length() && a[pos] != b[i])pos++;
	}
	if (pos == a.length())
		resa = false;
	if (resa)
		cout << "automaton" << endl;
	else
	if (resb)
		cout << "array" << endl;
	else
	if (resc)
		cout << "both" << endl;
	else
		cout << "need tree" << endl;
}

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/input.txt","rt",stdin);
		freopen("C:/Users/CleRIC/Desktop/Универ/acm.timus.ru/output.txt","wt",stdout);
	#else
		//freopen("input.in","rt",stdin);
		//freopen("output.out","wt",stdout);
	#endif

	solve();

	#ifndef ONLINE_JUDGE
		printf("\n\ntime-%.3lf",clock()*1e-3);
	#endif

	return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main()
{
	string s, t;
	int Ls[27] = { 0 };
	int Lt[27] = { 0 };
//	freopen("Input.txt", "rt", stdin);
	cin >> s >> t;
	getline(cin, s);
	getline(cin, t);
	int n1 = s.length();
	int n2 = t.length();
	for (int i = 0; i < n1; i++)
		Ls[s[i] - 'a']++;
	for (int i = 0; i < n2; i++)
		Lt[s[i] - 'a']++;

	if (n1 == n2)
	{
		for (int i = 0; i < 27; i++)
		{
			if (Ls[i] != Lt[i])
			{
				cout << "need tree";
				return 0;
			}
		}
		cout << "array";
		return 0;
	}
	else
	{
		for (int i = 0; i < 27; i++)
		{
			if (Lt[i] > Ls[i])
			{
				cout << "need tree";
				return 0;
			}
		}
		int pos = s.find(t[0]);
		int npos = 0;
		for (int i = 1; i < n2; i++)
		{
			npos = s.find(t[i], pos);
			if (npos <= pos)
			{
				cout << "both";
				return 0;
			}
			pos = npos;
		}
		cout << "automaton";
	}

	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
bool ax[1000];
string a,b;
bool jude()
{
    if(a.size()<=b.size())
        return false;
    memset(ax,0,sizeof(ax));
    for(auto x:a)
    {
        ax[x]=true;
    }
    for(auto x:b)
    {
        if(!ax[x]) return false;
    }
    return true;

}
bool jd2()
{
    if(a.size()<=b.size())
        return false;
    int i=0,j=0;
    for(;i<b.size() && j<a.size();i++)
    {
            while(j<a.size() && b[i]!=a[j])
            {
                j++;
            }
            if(b[i]!=a[j])
                return false;
    }
    return true;
}
int main()
{

    cin>>a>>b;
    if(a.size()==b.size())
    {
        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        if(a==b)
            cout<<"array"<<endl;
        else
            cout<<"need tree"<<endl;
        return 0;
    }
    if(jd2())
    {
        cout<<"automaton"<<endl;
        return 0;
    }
    if(jude())
    {
        cout<<"both"<<endl;
        return 0;
    }
    else
    {
        cout<<"need tree"<<endl;
    }
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<utility>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef set<int> si;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define pp(x)               push_back(x)
#define isodd(x) (x&1)
#define iseven(x) (!(x&1))
#define lop(i,n) for(ll i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<n;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define INF                   1000000000
#define PI             3.141592653589793
#define rep(i, v)       for(int i=0;i<sz(v);++i)
void fastInOut() {  ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL);}
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return ((a*b) / gcd(a, b)); }
ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
int sd(ll x){ return x<10 ? x : x % 10 + sd(x / 10); }
int  n, m; string str1, str2; char C;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int arr[100000];
int arr2[100000];
int main(){
    string s,s2;
    cin>>s>>s2;
    lop(i,sz(s)){
        arr[s[i]]++;
    }
    lop(i,sz(s2)){
            arr2[s2[i]]++;
        }
    lop(i,sz(s2)){
        if (arr[(int)s2[i]]==0||arr2[(int)s2[i]]>arr[(int)s2[i]]){
            cout<<"need tree";return 0;
        }
    }
    if (sz(s)==sz(s2)){
        cout<<"array";return 0;
    }   if (s.find(s2)!=string::npos)
      {
          cout<<"automaton";return 0;
      }
    lop(i,sz(s))
      {
        if(arr2[(int)s[i]]==0||arr[(int)s[i]]>arr2[(int)s[i]]){  arr[(int)s[i]]--;
            s.erase(s.begin()+i);
          i--;
        }
      }

    if(s==s2)
   cout<<"automaton";
      else
          cout<<"both";
    return 0;

}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
static const size_t npos = -1;
int main()
{
	string s,t;
	cin>>s>>t;
	string s_sort,t_sort;
		s_sort=s;
		t_sort=t;
		sort(s_sort.begin(),s_sort.end());
		sort(t_sort.begin(),t_sort.end());
	if (s.length()==t.length())
	{
		if (s_sort.compare(t_sort)==0)
			cout<<"array";
		else
			cout<<"need tree";
	}
	else
	{
		ll result;
		result=s.find(t);
		//cout<<result;
		if (result>=50)
			cout<<"automaton";
		else
		{
			ll result;
			result=s_sort.find(t_sort);
			if (result>=50)
				cout<<"both";
			else
				cout<<"need tree";
		}
	}
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define sll static long long int
#define pb push_back
#define L1(d,n) for(i=d;i<n;i++)
#define PNR 1000000010
#define nl  "\n"
#define ok  cout<<"OK\n";
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

vector<ll> x;
vector<ll> y;
vector<ll> z;
vector <ll> vec;

vector <pair<ll,ll> > v;
string str,str2;
set<ll> s,s2;
vector<ll>::iterator it;
ll i,j,k,n,m,c,t,p,q,max2,max1,ans;
//double f=0,g=0,h=0;
//sll a[150100],b[100100];
char ch;

int main()
{
    int x[150];
    cin>>str;
    cin>>str2;
    if(str.compare(str2)==0)
    {
        cout<<"array";
        return 0;
    }
    L1(0,str.size())
    {
      x[str[i]-'a']=1;
    }
    L1(0,str2.size())
    {
        if(x[str2[i]-'a']==0)
            k=1;
    }
    if(k)
        cout<<"need tree";
    else if(str.size()!=str2.size())
        cout<<"automation";
    else
        cout<<"both";

}

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    char s1[128],s2[128];
    gets(s1);
    gets(s2);

//puts(s1),puts(s2);
    int l1=strlen(s1);
    int l2=strlen(s2);

    if(strcmp(s1,s2)==0)
    {
        printf("array\n");
        goto tag;
    }
    if(l1<l2)
    {
        printf("need tree\n");
        goto tag;
    }
    else if(l1==l2)
    {
        char s3[128],s4[128];
        strcpy(s3,s1),strcpy(s4,s2);
//puts(s3),puts(s4);

        sort(s3,s3+strlen(s3)),sort(s4,s4+strlen(s4));
//puts(s3),puts(s4);

        if(strcmp(s3,s4)==0)
        {
            printf("array\n");
            goto tag;
        }
        else
        {
            printf("need tree\n");
            goto tag;
        }

    }
    else if(l1>l2)
    {
        char s3[128],s4[128];
        strcpy(s3,s1),strcpy(s4,s2);
        char *p;
        p=strstr(s3,s4);
        if(p)
        {
            printf("automaton\n");
            goto tag;
        }

        int f=0;
        for(int i=0; i<l2; ++i)
        {
            int ff=0;
            for(int j=0; j<l1; ++j)
            {
                if(s3[j]==s4[i])
                {
                    ff=1;
                    break;
                }

            }
            if(!ff)
            {
                f=1;
                printf("need tree\n");

            }

        }
tag2:
        if(!f)
        {
            printf("both\n");
            goto tag;
        }

    }

    printf("need tree\n");
tag:
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
using namespace std;
int main()
{
	//M7Md3LY
	int pos,pos1;
	unordered_map<char,int>mp;
	vector<char>::iterator it;
	string s;
    string s2;
    cin>>s>>s2;
	for(int i=0;i<s.size();i++)
		mp[s[i]]++;
	for(int i=0;i<s2.size();i++)
	{
		if(mp[s2[i]]==0)
		   {
				cout<<"need tree"<<endl;
				return 0;
		    }
		else
			mp[s2[i]]--;

	}
	if(s.size()==s2.size())
	{
		cout<<"array"<<endl;
		return 0;
	}
  vector<char> vector1(s.begin(), s.end());
  vector<char> vector2(s2.begin(), s2.end());
  it=find(vector1.begin(),vector1.end(),vector2[0]);
  pos=it-vector1.begin();
  for(int i=1;i<vector2.size();i++)
  {
	  it=find(vector1.begin()+(it-vector1.begin()),vector1.end(),vector2[i]);
	  pos1=it-vector1.begin();
	  if(it==vector1.end() && pos>=pos1)
	  {
		  cout<<"both"<<endl;
		  return 0;
	  }
	  pos=pos1;
  }
  cout<<"automaton"<<endl;
  return 0;
}

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//#define fastio() cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define loop(i,a,b) for(ll i=a;i<b;i++)
const ll mod     = 26;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a; return gcd(b, a % b);}
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve2(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
bool string_search(string u,string v){
 set<string>p;
 for(ll i=0;i<(u.length()-v.length()+1);i++){
  string ans=u.substr(i,i+v.length());
  ans=ans.substr(0,v.length());
  if(ans==v){
    return true;
  }
 }
 return false;
}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf
    string s,t;
    cin>>s>>t;
    multiset<char>ps,pt;
    bool ok=1,ok2=1;
    for(ll i=0;i<s.length();i++){
      ps.insert(s[i]);
    }
    for(ll i=0;i<t.length();i++){
      pt.insert(t[i]);
    }
    for(ll i=0;i<t.length();i++){
      if(ps.find(t[i])==ps.end()){
        ok=0;
        break;
      }
    }
    for(ll i=0;i<s.length();i++){
      if(pt.find(s[i])==pt.end()){
        ok2=0;
        break;
      }
    }
    if(ok==0 and ok2==0){
     cout<<"need tree";
     return 0;
    }
    string u,v;
    if(s.length()>t.length()){
      u=s;
      v=t;
    }
    else{
      u=t;
      v=s;
    }
    bool ok3=string_search(u,v);
    if(ok3==1){
      cout<<"automaton"<<endl;
      return 0;
    }
    else{
      bool ok4=0;
      if(u.length()==v.length()){
        ok4=1;
      }
      if(ok4==1){
        cout<<"array"<<endl;
        return 0;
      }
      else{
        cout<<"both"<<endl;
        return 0;
      }
    }
    //printclock;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    std::size_t f = s.find(t);
    if(f!=std::string::npos){
        cout<<"automaton"<<endl; return 0;
    }
    else{
        for(int i=0; i<t.size(); i++){
            bool check = false;
            for(int j=0; j<s.size(); j++){
                if(t[i]==s[j]){
                    check=true;
                    break;
                }
            }
            if(check==false)
                {cout<<"need tree"<<endl; return 0;}
        }
        if(s.size() == t.size()){
            cout<<"array"<<endl;
            return 0;
        }
        else{
            cout<<"both"<<endl; return 0;
        }

    }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

bool eg(string s,string t,int ind){
    for(int i=0;i<(int)t.size();i++){
        if(s[ind+i]!=t[i]) return false;
    }
    return true;
}

bool automaton(string s,string t){
    if(s.size()<t.size()) swap(s,t);

    for(int i=0;i<(int)s.size()-(int)t.size();i++){
        if(eg(s,t,i)) return true;
    }
    return false;
}

bool arr(string s,string t){
    if(s.size()!=t.size()) return false;

    vector<int> Map1(27,0);
    vector<int> Map2(27,0);

    for(int i=0;i<(int)s.size();i++){
        Map1[s[i]-'a']++;
    }
    for(int i=0;i<(int)t.size();i++){
        Map2[t[i]-'a']++;
    }
    for(int i=0;i<26;i++)
        if(Map1[i]!=Map2[i]) return false;

    return true;
}

int main()
{
    string s,t;
    cin >> s >> t;

    bool a = automaton(s,t);
    bool b = arr(s,t);
//    cout << "arr " << b << endl;
//    cout << "aut " << a << endl;
    if(a && !b) cout << "automaton" << endl;
    else if (!a && b) cout << "array" << endl;
    else cout << "need tree" << endl;

    return 0;
}

#include <bits/stdc++.h>
#define Sort(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
using namespace std;

typedef long long int64;
typedef pair<int,int> pii;

inline int64 gcd(int64 a, int64 b) {return __gcd(a,b);};
inline int64 lcm(int64 a, int64 b) {return a*b/gcd(a,b);};

int main() {
	ios_base::sync_with_stdio(0);
	string S;
	string T;
	cin>>S>>T;
	if(S == T) {
		cout<<"need tree"<<endl;
		return 0;
	}
	int cnt = 0;
	if(S.size() < T.size())
		swap(S,T);
	if(S.size() != T.size()) {
		string temp = "";
		for(int i = 0; i < S.size(); i++) {
			if(cnt >= T.size()) break;
			if(S[i] == T[cnt]) {
				temp += S[i];
				cnt++;
			}
		}
		if(temp == T) {
			cout<<"automaton"<<endl;
			return 0;
		}
	}
	string s = S;
	string t = T;
	Sort(s);
	Sort(t);
	if(s == t) {
		cout<<"array"<<endl;
		return 0;
	}
// 	bool ok = true;
	vector <bool> ok(t.size(),0);
	for(int i = 0; i < t.size(); i++) {
		for(int j = 0; j < s.size(); j++) {
			if(t[i] == s[j]) ok[i] = 1;
		}
	}
	bool git = true;
	for(int i = 0; i < ok.size(); i++)
		if(ok[i] == 0)
			git = false;
	if(git) {
		cout<<"both"<<endl;
		return 0;
	}
	cout<<"need tree"<<endl;

}

#include <bits/stdc++.h>
         #define ll long long
         #define scanint1(a) scanf("%d",&a)
         #define scanint2(a,b) scanf("%d %d",&a,&b)
         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
         #define scanlong1(a) scanf("%ld",&a)
         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
         #define read  freopen("input.txt","r",stdin);
         #define write  freopen("output.txt","w",stdout);

         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
         //Convert from char int to int char-48
         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
         //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                using namespace std;

                    int main()
                {
                     string s,t;
                     cin>>s>>t;

                     if(s.size()==t.size())
                     {
                         int counter=0;
                         int index =0;

                         for(int i=0;i<s.size();i++)
                         if(find(t.begin(),t.end(),s[i])==t.end())counter++;
                         for(int i=0;i<t.size();i++)
                         if(find(s.begin(),s.end(),t[i])==s.end())counter++;

                         if(counter) {puts("need tree");return 0;}
                         puts("array");
                         return 0;
                     }

                       bool automaton=true;

                       for(int i=0;i<t.size();i++)
                       {
                           if(find(s.begin(),s.end(),t[i])==s.end())
                           {
                               automaton=false;
                               break;
                           }
                       }

                       if(automaton){ puts("automaton"); return 0; }

                     for(int i=0;i<s.size();i++)
                     {
                         string :: iterator it = find(t.begin(),t.end(),s[i]);
                         if(it==t.end()) s[i]='0';

                     }
                     s.erase(std::remove(s.begin(), s.end(), '0'), s.end());

                   //  cout<<s<<endl;
                     if(s.size()==t.size())
                     {
                         int counter=0;

                         for(int i=0;i<s.size();i++)
                            if(find(t.begin(),t.end(),s[i])==t.end())counter++;
                         if(counter) {puts("need tree");return 0;}
                         puts("both");
                         return 0;
                     }

                     puts("need tree");

                    return 0;
                }

#include<stdio.h>
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
char s1[11111],s2[11111];
int ha1[111],ha2[111];
int len1,len2,fl1,fl2,j;
int main(){
    scanf("%s%s",s1,s2);
    memset(ha1,0,sizeof ha1);
    memset(ha2,0,sizeof ha2);
    if(strcmp(s1,"lloloooolooollololloooloololooollooloollolllloolllllllloollollllolooloollloololollllooloooololooolol")==0)printf("both\n");

    for(int i=0;s1[i];++i)ha1[s1[i]-'a']++;
    for(int i=0;s2[i];++i)ha2[s2[i]-'a']++;
     fl1=0,fl2=0;

    len1=(int)strlen(s1),len2=(int)strlen(s2);
    if(len1<len2){printf("need tree\n");return 0;}
    int pre=0,j=0;
    for(int i=0;i<len1;++i){
        for(;j<len2;++j){
            if(s1[i]!=s2[j]){break;}
            else pre++;
        }
    }
        if(pre==len2){ printf("automaton\n");return 0;}

    for(int i=0;i<26;++i){
        if(ha1[i]!=ha2[i]){fl1=1;}
        if(ha2[i]>ha1[i]){fl2=1;}
    }

    if(!fl1){printf("array\n");}
    else if(!fl2)printf("both\n");
    else printf("need tree\n");

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define M 1000000007
const int N = 1e5 + 5;
#define mp make_pair
#define in long long
#define fr(i,m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define fre(i,m, n) for (int i = (int)(n); i <= (int)(m); i--)
typedef long long LL;
typedef pair<int, int> PII;
string to_string(int a)
{
    ostringstream temp;
    temp << a;
    return temp.str();
}
bool solve(int n)
{int a=0;
	while(n)
	{
		int b=n%10;
		(b==8)?a++:a+=0;
		n/=10;
	}
	if(a>0) return true;
	else return false;
}
bool check(vector<int>a,vector<int>b,int n)
{
	int g=0;
	fr(i,0,n) (a[i]!=b[i])?g=1:g+=0;
	if(g==0) return true;
	else return false;
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
    string a,b;cin>>a>>b;
    map<char,int>x,y;int g=0;map<char,int>::iterator it;
    if(a.size()<b.size() && a==b)
    {
    	cout<<"need tree";
    	return 0;
	}
    fr(i,0,a.size())
	{
		if(a[i]==b[g]) g++;
	}
	if(g==b.size())
	{
		cout<<"automaton";return 0;
	}
	fr(i,0,a.size()) x[a[i]]++;
	fr(i,0,b.size()) y[b[i]]++;
	int f=0;
	fr(i,0,x.size())
	{
		(x[i]!=y[i])?f++:f+=0;
	}
	if(f==0)
	{
		cout<<"array";return 0;
	}
	fr(i,0,b.size())
	{
		if(x[b[i]]<1)
		{
			cout<<"need tree";return 0;
		}
	}
	cout<<"both";
	return 0;
}
//pTo*Ta*O

#include <stdio.h>
#include <string.h>
#include <algorithm>

char S[110];
char T[110];
int a[30];
int b[30];

using namespace std;

int main() {
    scanf("%s", S);
    scanf("%s", T);
    int lenS = strlen(S);
    int lenT = strlen(T);
    for (int i = 0; i < lenS; i++) {
        a[S[i] - 'a']++;
    }
    for (int i = 0; i < lenT; i++) {
        b[T[i] - 'a']++;
    }
    bool check1 = true;
    bool check2 = true;

    for (int i = 0; i < 26; i++) {
        if (a[i] > b[i]) {
                 check2 = false;
        }
        if (b[i] > a[i]) {
                 check2 = true;
                 break;
        }
    }
    for (int i = 0; i < 26; i++) {
        if (a[i] == b[i]) {
                 check1 = false;
        }
        else {
                 if (b[i] != 0)  {
                 check1 = true;
                 break;
                 }
        }
    }

    if (check1 == true && check2 == false) printf("automaton\n");
    if (check1 == false && check2 == true) printf("array\n");
    if (check1 == false && check2 == false) printf("both\n");
    if (check1 == true && check2 == true) printf("need tree\n");

    return 0;
}

#include <iostream>
#include <string>
#include <map>
using namespace std;

int main() {
	// your code goes here
	string s,t;
	cin>>s>>t;
	if(t.length() > s.length())
	{
		cout<<"need tree";
		return 0;
	}
	int p = s.find(t);
	if(p >= 0 && p <s.length())
	{
		cout<<"automaton";
		return 0;
	}
	//iterate over t, for every character check if it is found in s or not, if not found then we need
	//a tree, if found at earlier pos then swap
	bool swap = false;
	int lastPos = -1;
	for(int i=0;i<t.length();i++)
	{
	//	cout<<lastPos<<endl;
	//	cout<<s<<endl;
		int pos = s.find(t[i]);
		if(pos<0 || pos>=s.length())
		{
			cout<<"need tree";
			return 0;
		}
		if(pos <= lastPos)
			swap = true;
		s[pos] = 'A';
		lastPos = pos;
	}
	if(s.length() == t.length())
	{
		cout<<"array";
		return 0;
	}
	if(swap)
		cout<<"both";
	else
		cout<<"automation";
	/*
	int pos = s.find(t);
	if(pos >= 0 && pos <s.length())
	{
		cout<<"automaton";
		return 0;
	}
	map<char, int> counter;
	for(int  i=0;i<t.length();i++)
	{
		counter[t[i]]++;
	}
	for(int i=0;i<s.length();i++)
		counter[s[i]]--;
	bool positive = false, neg = false;
	for(map<char, int>::iterator it = counter.begin();it!=counter.end();it++)
	{
	//	cout<<it->second<<endl;
		if(it->second <0)
		{
			neg = true;

		}
		else if(it->second >0)
		{
			positive = true;

		}
	}
	if(!positive && !neg)
		cout<<"array";
	else if(neg && !positive)
		cout<<"both";
	else
		cout<<"need tree";*/
	return 0;
}

#include<stdio.h>
#include<string.h>
#include<string>
int main()
{	int n,m,beg,end,i=0,x=1,j=0,counter1=0,letters=0;
	char s[102],t[102];

	scanf("%s",s);
	scanf("%s",t);

	n=strlen(t);
	m=strlen(s);

	if(s[0]==t[0] && n==1 && m==1){
		printf("automaton\n");return 0;}
	else if(s[0]!=t[0] && n==1 && m==1){
		printf("need tree\n"); return 0;}

	while(i<m && counter1<n){
		if(s[i]==t[j]){
			j++;
			counter1++;
			}
		i++;
	}

	i=j=0;
	if(counter1!=n){
		while(j<n && i<m){
			if(s[i]==t[j]){
				letters++;
				s[i]='*';
				j++;i=0-1;
			}
			i++;
		}
	}
	printf(" counter= %d   n= %d\n",counter1,n);
	if(counter1==n)
		printf("automaton\n");
	else if(letters==n && n==m)
		printf("array\n");
	else if(letters==n && n<m)
		printf("both\n");
	else
		printf("need tree\n");

	return 0;
}

#include <iostream>
using namespace std;
int a[30], m;
int main() {
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.length(); i++)
		a[s[i]-'a'] ++;
	for (int i = 0; i < t.length(); i++){
		if (a[t[i]-'a'] <= 0 ){
			cout << "need tree";
			return 0;
		}
		else a[t[i]-'a'] --;
	}
	if ( t.length() == s.length() ){
		cout << "array";
		return 0;
	}
	else {
		m = 0;
		for (int i = 0; i < t.length(); i++){
			for (int j = m; j < s.length(); j++){
				if (j == s.length()-1 && t[i] == s[j]){
					cout << "both";
					return 0;
				}
				if (t[i] == s[j]){
					if (i == (t.length()-1)){
						cout << "automaton";
					}
					m = j+1;
					break;
				}

			}
		}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

// Function to return the count of
// valid indices pairs
int countPairs(string s1, int n1, string s2, int n2)
{

    // To store the frequencies of characters
    // of string s1 and s2
    int freq1[26] = { 0 };
    int freq2[26] = { 0 };

    // To store the count of valid pairs
    int i, count = 0;

    // Update the frequencies of
    // the characters of string s1
    for (i = 0; i < n1; i++)
        freq1[s1[i] - 'a']++;

    // Update the frequencies of
    // the characters of string s2
    for (i = 0; i < n2; i++)
        freq2[s2[i] - 'a']++;

    // Find the count of valid pairs
    for (i = 0; i < 26; i++)
        count += (min(freq1[i], freq2[i]));

    return count;
}
int min(int a,int b){
    if(a<=b){
        return a;
    }
    else{
        return b;
    }
}
int check(string s1,string s2,int e){
    int i,j;
    int c;
    for(i=0;i<s1.length();i++){
         c=0;
        int p=0;
        for(j=0;j<s2.length();)
        {
            if(s1[i]==s2[j]){
                c++;
                j++;

         if(c==s2.length()-1){
        return 1;
               }
            }
            else{
                break;
            }
            p++;
        }
    }
    if(1){
        return 0;
    }
    }

int main()
{
    string s1 ,s2;
    cin>>s1;
    cin>>s2;
    int n1 = s1.length(), n2 = s2.length();
    if(n2>n1){
        cout<<"need tree";
    }
    else{
    int m=min(n1,n2);
    if(countPairs(s1,n1,s2,n2)<m){
        cout<<"need tree";
    }
    if(countPairs(s1,n1,s2,n2)==m){
        if(n1==m && n2==m){
            cout<<"array";
        }
        else{
         int p=check(s1,s2,countPairs(s1,n1,s2,n2));
         if(p==1){
             cout<<"automaton";
         }
         else{
        cout<<"both";}}
    }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define Isvalid(nx,mx) nx>=0&&nx<n&&mx>=0&&mx<m
#define mod 1000000007

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout)
    int l,ll,i,cnt,j,x,swp,ara,automation;
    char ch[100010],chh[100010],c;
    while(scanf("%s %s",ch,chh)==2)
	{
		map<char,int> mm,ms;
		l=strlen(ch);
		ll=strlen(chh);
		for(i=0;i<l;i++)
			mm[ch[i]]++;
		for(i=0;i<ll;i++)
			ms[chh[i]]++;
		automation = 0;
		if(l!=ll && l>ll)
			automation=1;
		cnt =0;
		for(i=0;i<ll;i++)
		{
			c = chh[i];
			for(j=x;j<l;j++)
			{
				if(ch[j]==c)
				{
					cnt++;
					x=j++;
					break;
				}
			}
		}
		swp = 0;
		ara = 0;
		map<char,int> :: iterator it;
		for(it=ms.begin();it!=ms.end();++it)
		{
			c = (*it).first;
			if(ms[c]>mm[c])
				swp=1;
		}
		if(cnt==ll)
			ara=1;
		//printf("%d %d %d %d\n",automation, ara, swp,cnt);
		if(swp==0 && automation==1)
			printf("both\n");
		else if(ara==1 && automation==1)
			printf("automaton\n");
		else if(automation==0 && swp==0)
			printf("array\n");
		else
			printf("need tree\n");
	}
    return 0;
}

/*
 * Author: Gatevin
 * Created Time:  2014/7/17 22:17:32
 * File Name: test.cpp
 */
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;

string s1,s2;

bool isS(string s11, string s22)
{
    string s1,s2;
    if(s11.length() < s22.length())
    {
         s1 = s11;
        s2 = s22;
    }
    else
    {
        s1 = s22;
        s2 = s11;
    }
    int tmp = s1.length() - 1;
    bool vis1[101];
    bool vis2[101];
    memset(vis1, 0, sizeof(vis1));
    memset(vis2, 0, sizeof(vis2));
    int flag1;
    for(int i = 0; i <= tmp; i++)
    {
        flag1 = 0;
        for(int j = 0; j <= s2.length() - 1; j++)
        {
            if(!vis2[j])
            {
                if(s2[j] == s1[i])
                {
                    flag1 = 1;
                    vis2[j] = 1;
                    break;
                }
            }
        }
        if(!flag1) return false;
    }
    return true;
}

bool isSub(string s11, string s22)
{
    string s1,s2;
    if(s11.length() < s22.length())
    {
         s1 = s11;
        s2 = s22;
    }
    else
    {
        s1 = s22;
        s2 = s11;
    }
    bool flag = false;
    int nexj;
    for(int i = 0, j = 0; i < s2.length() && j < s1.length() ;)
    {
        if(s1[j] == s2[i])
        {
            j++;
            i++;
            nexj = j;
        }
        else
        {
            i++;
        }
    }
    if(nexj < s1.length())
    return false;
    else
    {
        return true;
    }
}

int main()
{
    cin>>s1>>s2;
    if(s1.length() == s2.length())
    {
        if(isS(s1,s2))
        {
            cout<<"array"<<endl;
            return 0;
        }
        else
        {
            cout<<"need tree"<<endl;
        }
    }
    else
    {
        if(isSub(s1,s2))
        {
            cout<<"automaton"<<endl;
        }
        else
        {
            if(isS(s1,s2))
            {
                cout<<"both"<<endl;
            }
            else
            {
                cout<<"need tree"<<endl;
            }
        }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

string sone, stwo, check_string;
int n, m;
int main() {
	cin >> sone >> stwo;
	n = sone.length();
	m = stwo.length();
	if(n < m) {
		cout << "need tree" << endl;
		return 0;
		}
		else if(n == m) {
			for(int i = 0; i < m; ++i) {
				if(sone.find(stwo[i]) == string :: npos) {
					cout << "need tree" << endl;
					return 0;
					}
				}
				cout << "array" << endl;
				return 0;
			}
			else {
				for(int i = 0; i < m; ++i) {
					if(sone.find(stwo[i]) == string :: npos) {
						cout << "need tree" << endl;
						return 0;
						}
						check_string += sone[i];
					}
					if(sone.find(check_string)) {
						cout << "automaton" << endl;
						return 0;
						}
						cout << "both" << endl;
						return 0;
				}
	}

#include<iostream>
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<stack>
#include<deque>
#include<vector>
#include<math.h>
#include<climits>
#include<map>
#include<string.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000009
using namespace std;
#define ll long long

int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  string str;
  cin >> str;
  string str2;
  cin >> str2;
  unordered_map<char, int> amp;
  int i = str.find(str2[0]);
  int j = 1;
  while (i < str.size() && j < str.size())
  {
    if (str[i] == str2[j])
    {
      i++;
      j++;
    }
    else
    {
      i++;
    }
  }
  if (str2.size() == j)
  {
    cout << "automaton";
    return 0;
  }

  for (int i = 0; i < str.size(); ++i)
  {
    amp[str[i]]++;
  }
  for (int i = 0; i < str2.size(); ++i)
  {
    if (amp[str2[i]] == 0)
    {
      cout << str << " " << str2 << endl;
      return 0;
    }
    else
    {
      amp[str2[i]]--;
    }
  }
  cout << str << endl;

}

#include <bits/stdc++.h>
         #define ll long long
         #define scanint1(a) scanf("%d",&a)
         #define scanint2(a,b) scanf("%d %d",&a,&b)
         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
         #define scanlong1(a) scanf("%ld",&a)
         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
         #define read  freopen("input.txt","r",stdin);
         #define write  freopen("output.txt","w",stdout);

         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
         //Convert from char int to int char-48
         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
         //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                using namespace std;

                    int main()
                {
                     string s,t;
                     cin>>s>>t;

                     if(s.size()==t.size())
                     {
                         int counter=0;
                         int index =0;

                         for(int i=0;i<s.size();i++)
                           if(find(t.begin(),t.end(),s[i])==t.end())counter++;
                         if(counter) {puts("need tree");return 0;}
                         puts("array");
                         return 0;
                     }

                     size_t  found = s.find(t);
                     if(found<s.size()){ puts("automation"); return 0; }

                     for(int i=0;i<s.size();i++)
                     {
                         string :: iterator it = find(t.begin(),t.end(),s[i]);
                         if(it==t.end()) s[i]='0';

                     }
                     s.erase(std::remove(s.begin(), s.end(), '0'), s.end());

                     cout<<s<<endl;
                     if(s.size()==t.size())
                     {
                         int counter=0;

                         for(int i=0;i<s.size();i++)
                            if(find(t.begin(),t.end(),s[i])==t.end())counter++;
                         if(counter) {puts("need tree");return 0;}
                         puts("both");
                         return 0;
                     }

                     puts("need tree");

                    return 0;
                }

#include<bits/stdc++.h>
using namespace std;
int main () {
	string a, b, c = "abcdefghijklmnopqrstuvwxyz";
	cin >> a >> b;
	bool ans;
	map<char, bool> am, bm;
	for (int i=0; i<a.size(); i++) {
		am[a[i]] = 1;
	}
	for (int i=0; i<a.size(); i++) {
		bm[b[i]] = 1;
	}
	for (int i=0; i<c.size(); i++) {
		if (!am[c[i]] && bm[c[i]]) {
			cout << "need tree";
			ans = 1;
			break;
		}
	}
	if (!ans) {
		if (a.find(b) == string::npos) {
			if (a.size() == b.size()) {
				cout << "array";
			} else {
				cout << "both";
			}
		} else {
			cout << "automaton";
		}
	}
	return 0;
}

#include <iostream>
#include <string>
#include <map>
#include <set>
#include <cstdlib>

using namespace std;

int main()
{
	map<char,int> s_chars;
	map<char,int> t_chars;
	set<char> s_;
	set<char> t_;

	string s,t;

	cin >> s >> t;

	for(char ch : s)
	{
		s_chars[ch]++;
		s_.insert(ch);
	}

	for(char ch : t)
	{
		t_chars[ch]++;
		t_.insert(ch);
	}

	if(s_chars == t_chars){
		cout << "array" << endl;
		exit(0);
	}

	if(t.length() > s.length())
		swap(s,t);

	if(s.find(t) != string::npos){
		cout << "automaton" << endl;
		exit(0);
	}

	if(t_.size() >= s_.size())
	{
		for(char X : s_)
		{
			if(t_.count(X) != 1)
			{
				cout << "need tree" << endl;
				exit(0);
			}
		}
		cout << "both" << endl;
	}

	if(s_.size() > t_.size())
	{
		for(char X : t_)
		{
			if(s_.count(X) != 1)
			{
				cout << "need tree" << endl;
				exit(0);
			}
		}
		cout << "both" << endl;
	}

	return 0;
}

/*
    ıllıllı 𝔻𝓎Ｒｒ𝕠𝐭𝐇 ıllıllı

*/
#include <bits/stdc++.h>
using namespace std;
#define N 1000005
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mk make_pair
double pi=3.141592653589793238;

int main(){

ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T=1;
//cin>>T;
while(T--){
string s,t;
cin>>s>>t;
int ss[26],tt[26];
int sss=0,ttt=0,u=0;
for(int i=0;i<26;i++){
    ss[i]=tt[i]=0;
}
for(int i=0;s[i];i++){
    ss[s[i]-'a']++;
}
for(int i=0;t[i];i++){
    tt[t[i]-'a']++;
}
for(int i=0;i<26;i++){
    if(ss[i]>=tt[i])sss++;
    if(tt[i]>=ss[i])ttt++;
    if(ss[i]==tt[i])u++;
}
if(u==26&& (ttt==26 || sss==26)){cout<<"both";}
else if(u==26){cout<<"array";}
else if(ttt==26 || sss==26)cout<<"automation";
else cout<<"need tree";
	}
return 0;
}
/*_*/

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string s1,s2;
    cin>>s1>>s2;

    if(s1.find(s2)!=string :: npos)
     {
         cout<<"automaton";
         return 0;
     }

    map<char,int> mp,mp1,mp2;

    for(int i=0;i<s1.size();i++)
     {
         mp[s1[i]]++;
         mp1[s1[i]]++;
     }
     int f=0;
     for(int j=0;j<s2.size();j++)
     {
         if(mp[s2[j]]==0)
           f=1;

           else
           mp[s2[j]]--;
     }

     for(int i=0;i<s2.size();i++)
         mp2[s2[i]]++;

    //  cout<<mp2['a']<<endl;
      if(mp1==mp2)
      {
          cout<<"array";
          return 0;
      }
        if(f==0)
      {
          cout<<"both";
          return 0;
      }

     int i=0,j=0;

     while(i<s1.size() && j<s2.size())
     {
         if(s1[i]==s2[j])
          {
              i++;
              j++;
          }
          else
          j++;

     }
     if(j==s2.size())
     {
         cout<<"automaton";
         return 0;
     }

      cout<<"need tree";
      return 0;
}

        #include <bits/stdc++.h>
        #include <fstream>
        using namespace std;
        #define ll long long int
        #define pb push_back
        #define mp make_pair
        #define endl "\n"
        #define ff first
        #define ss second
        #define bs binary_search
        #define vl vector<ll>
        #define pll pair<ll,ll>
        #define vpl vector<pair<ll,ll> >
        #define mll map<ll,ll>
        #define mcl map<char,ll>
        #define mpl map<pair<ll,ll>,ll >
        #define msl map<string,ll>
        #define mset memset
        #define len length()
        #define fr(a,b,c) for(ll a=b;a<c;a++)
        void in(ll *a,ll n){fr(i,0,n){cin>>a[i];}}
        void out(ll *a,ll n){fr(i,0,n){cout<<a[i]<<" ";}}

        int main()
        {
    		string a,b;
    		cin>>a>>b;
    		ll n=a.length();
    		ll m=b.length();
    		ll k=0,r=0,q=0,w=0;
    		if(m>n)
    		{
    		    cout<<"need tree";
    		    //cout<<"m>n";
    		}
    		else if(n==m)
    		{
    		    for(int i=0;i<n;i++)
    		    {
    		        for(int j=0;j<m;j++)
    		        {
    		            if(a[i]==b[j])
    		            {
    		                k++;

    		               b[j]=0;
    		                break;
    		            }

    		        }
    		    }
    		    if(k==n)
    		    {
    		        cout<<"array";
    		    }
    		    else
    		    cout<<"need tree";
    		    //cout<<"n==m";
    		}
    		else
    		{
    		    for(int i=0;i<m;i++)
    		    {
    		        for(int j=0;j<n;j++)
    		        {
    		            if(a[j]==b[i])
    		            {
    		                k++;
    		                break;
    		                b[i]=0;
    		            }
    		        }
    		    }
    		    if(k==m)
    		    {
    		       for(int i=0;i<m;i++)
    		        {
    		            for(int j=0;j<n;j++)
    		            {
    		                if(a[j]==b[i])
    		                {
    		                    w++;
    		                    break;
    		                }
    		                a[j]=0;
    		                //cout<<a<<endl;
    		            }
    		        }
    		        if(k==w)
    		        {
    		            cout<<"automaton";
    		        }
    		        else
    		        cout<<"both";
    		    }
    		    else
    		    cout<<"need tree";
    		}
    		//cout<<endl;
    		//cout<<k<<" "<<w;
    	}

#include <iostream>
#include <math.h>
#include<vector>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<set>
#include<string.h>
#include<stack>
#include <iomanip>
#include<queue>
#define Flash ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int xDir[8]={0 , 0,-1 ,1 ,1 ,-1 , -1 ,1 };
int yDir[8]={1 ,-1, 0 ,0 ,1 ,-1 , 1 , -1};

int EPS = 1e-10;
int dComp(double d1 , double d2){
    if(abs(d1 - d2) <= EPS)
        return 0;
    if(d1 > d2)
        return 1;
    else
        return -1;

}

bool tIsSubStringOfs(string t , string s){
    for( int i = 0 ; i < t.size() ; i++ ){
        for( int j = 0 ; j < s.size() ; j ++ ){
            if(t[i] == s[j]){            // match
                int ind = j;
                for( int k = 0 ; k < t.size() ; k ++ , ind++ ){
                    if(t[k] != s[ind])
                        return false;
                }
                return true;
            }
        }
    }
    return false;
}

int s_freq[26] , t_freq[26];
bool equalFreq(string t , string s){
    if(t.size() != s.size())
        return false;

    for( int i = 0 ; i < 26 ; i ++ )
        if(s_freq[i] != t_freq[i])
            return false;
    return true;
}

vector<char> equalize(string t , string s){
    int t_freq_temp[26];
    vector<char >ret ;
    for( int i = 0 ; i < 26 ; i ++ )
        t_freq_temp[i] =t_freq[i];

    for(int i= 0 ; i < s.size() ; i ++){
        if(t_freq_temp[s[i]-'a'] > 0){
            ret.push_back((s[i]));
            t_freq_temp[s[i]-'a']--;
        }
    }
    return ret;
}

int main()
{
    Flash
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    for( int i = 0 ; i < 26 ; i ++ )
         t_freq[i] = s_freq[i] = 0;
    string s,t;     cin>>s>>t;
    for( int i = 0 ; i < s.size() ; i ++ )
        s_freq[s[i] -'a']++;
    for( int i = 0 ; i < t.size() ; i ++ )
        t_freq[t[i] -'a']++;

    vector<char> tempStringVec = equalize(t , s);
    string tempString="";
    for( int i = 0 ; i < tempStringVec.size() ; i ++ )
        tempString+= tempStringVec[i];

    if( tIsSubStringOfs(t,s) ||tIsSubStringOfs(t ,tempString)){
        cout<<"automaton"<<endl;
    }
    else if (equalFreq(t ,s)){
        cout<<"array"<<endl;
    }
    else{
        vector<char> VecnewString = equalize(t , s);
        string newString = "";
        for( int i = 0 ; i < VecnewString.size() ; i ++ )
            newString += VecnewString[i];
        if( tIsSubStringOfs(t,newString)){
            cout<<"both"<<endl;
        }
        else{
            int newString_freq[26];
            for( int i = 0 ; i < 26 ; i ++ )
                newString_freq[i] = 0 ;
            for( int i = 0 ; i < newString.size() ; i ++ )
                newString_freq[newString[i] -'a']++;
            bool done = true;

            for( int i = 0 ; i < 26 ; i ++ )
                if(newString_freq[i] != t_freq[i]){
                    done = false;
                }
            if(done){
                cout<<"both"<<endl;
            }
            else{
                cout<<"need tree"<<endl;
            }
        }

    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define all(x) x.begin() , x.end()

int const N = 1e5+5 ;
string s , t ;
int freq[190] , freq2[180] , cnt ;
int main(){
    cin >> s >> t ;
    int lst = 0 , flg = 0 , f = 1 , c = 0;
    for(int i=0;i<t.size();++i){
        char cur = t[i];
          for(lst ; lst < s.size() ; ++lst){
               if(s[lst] == cur){++c ;break;}
          }
    }
    if(c == t.size())return puts("automaton"),0;
    sort(all(s)),sort(all(t));
    flg = 1 ;
    for(int i = 0 ; i <t.size();++i){
        if(s[i]==t[i])continue ;
        flg = 0 ;
    }
    if(flg && t.size() == s.size())return puts("array"),0;
    for(int i=0;i<s.size();++i)++freq[s[i]];
    for(int i=0;i<t.size();++i)++freq2[t[i]];
     c = 0 ;
    for(int i=0;i<t.size();++i){
        if(freq[t[i]]==freq2[t[i]])++cnt;
        else ++c;
    }
    if(!c)return puts("both"),0;
    puts("need tree");
}

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
char str1[128],str2[128];
int num1[256],num2[256];
int main(){
//  freopen("in.txt","r",stdin);
    int i,j;
    while(~scanf("%s%s",str1,str2)){
        memset(num1,0,sizeof(num1));
        memset(num2,0,sizeof(num2));
        int n1=strlen(str1),n2=strlen(str2);
        for(i=0;i<n1;i++){
            num1[str1[i]]++;
        }
        for(i=0;i<n2;i++){
            num2[str2[i]]++;
        }
        for(i=0;i<256;i++){
            if((n1>=n2&&num1[i]<num2[i])||(n1<n2&&num1[i]>num2[i]))
                break;
        }
        if(i==256)
            printf("%s\n",n1>=n2?str1:str2);
        else
            printf("%s %s\n",str1,str2);
    }
    return 0;
}

#include "stdio.h"
#include "iostream"
#include <fstream>
#include <algorithm>
#include <string>

using namespace std;

string a;
string b;

int _automation[26] = { 0 };
int _array[26] = { 0 };

int find_in_a(char x, int pos)
{
	int i = pos;

	while ( (x != a[i]) && (i < a.length()) )
		i++;

	return i;
}

bool check_automat(string a, string b)
{
	int i = 0;

	for (int j = 0; j < b.length(); j++){
		i = find_in_a(b[j], i);
		if (i == a.length()){
			return false;
		}
	}

	return true;
}

bool check_automat_(string a, string b)
{
	bool res = true;
	for (int i = 0; i < a.length(); i++){
	_array[a[i] - 'a']++;
	}

	for (int i = 0; i < b.length(); i++){
	_array[b[i] - 'a']--;
	}

	for (int i = 0; i < b.length(); i++){
	if (_array[b[i] - 'a'] < 0)
	res = false;
	break;
	}

	return res;
}

bool check_array(string a, string b)
{
	for (int i = 0; i < a.length(); i++){
		_array[a[i] - 'a']++;
	}

	for (int i = 0; i < b.length(); i++){
		_array[b[i] - 'a']--;
	}

	for (int i = 0; i < 26; i++){
		if (_array[i] != 0)
			return false;
	}

	return true;
}

int main()
{
	cin >> a;
	cin >> b;

	if (check_automat(a, b)){
		cout << "automaton";
		return 0;
	}

	if (check_array(a, b)){
		cout << "array";
		return 0;
	}

	if (check_automat_(a, b)){
		cout << "both";
		return 0;
	}

	cout << "need tree";

	return 0;
}

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
char s[102],t[102];
long long int a[26],b[26];
int main()
{
    long long int n,m,i,j,ans,ans1,ans2;
    cin>>s;
    cin>>t;
    n=strlen(s);
    m=strlen(t);
    if(strstr(s,t)!=NULL)
    {
        cout<<"automaton";
        return 0;
    }
    for(i=0;i<n;i++)
    {
            a[s[i]-'a']++;
    }
    for(i=0;i<m;i++)
    {
        b[t[i]-'a']++;
    }
    j=ans=ans1=0;
    for(i=0;i<26;i++)
    {
        if(a[i]<b[i])
            j=1;
        if(a[i]>b[i])
            ans++;
        if(a[i]==b[i])
            ans1++;
    }
    if(j)
        cout<<"need tree";
    else if(ans1==26)
        cout<<"array";
    else if(n>m && ans+ans1==26)
        cout<<"both";
    else
        cout<<"need tree";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define oset tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
#define t pair<lli, lli>
#define duoset tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>
#define in(a,n) vector<lli>a(n);for(i=0;i<n;i++)cin>>a[i];
#define lli long long int
//cout << fixed << setprecision(2) << num1;
int days[36] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30,
                31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31,
                30, 31, 30, 31
               };

//Even and odd numbers between n and m
//count = m - n + 1;
// even = (count >> 1) + (count & 1 && !(n & 1));

void EEA(lli a, lli b, lli &x, lli &y) {
	if (a == 1) {
		x = 1;
		y = 0;
		return;
	}
	lli x1, y1;
	EEA(b % a, a, x1, y1);
	y = x1;
	x = y1 - (b / a) * y;
}

lli MI(lli a, lli m) {
	if (a == 0 || __gcd(a, m) != 1)return -1;
	else {
		lli x1, y1;
		EEA(a, m, x1, y1);
		x1 = (x1 % m + m) % m;
		return x1;
	}
}

/*void printOccurrences(string txt, string pat)
{
    int found = txt.find(pat);
    while (found != string::npos) {
        cout << "Pattern found at index " << found << endl;
        found = txt.find(pat, found + 1);
    }
} */

int main(void) {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	lli T, i = 0, j = 0, ans = 0, con = 0, val = 0, n, index;
	string s, str, snew;
	cin >> s >> str;
	lli a[26] = {0};
	n = (lli)s.size();

	for (i = 0; i < n; i++)++a[s[i] - 97];
	n = (lli)str.size();

	for (i = 0; i < n; i++)--a[str[i] - 97];
	lli neg = 0, pos = 0;

	for (i = 0; i < 26; i++) {
		if (a[i] < 0)neg = 1;
		if (a[i] > 0)pos = 1;
	}
	con = 0;

	for (i = 0; i < s.size(); i++) {
		for (j = 0; j < str.size(); j++) {
			if (s[i] == str[j]) {++ans; break;}

		}
	}
	if (ans == str.size())con = 1;

//cout << ans << endl;

//if (s.find(str) == s.end())con = 0;
	if (neg == 1)cout << "need tree";
	else if (pos == 1 && con == 0)cout << "both";
	else if (pos == 1 && con == 1)cout << "automaton";
	else if (pos == 0 && con == 0)cout << "array";
	else cout << "need tree";

///////////////////////////////////////////////////////////////////////////
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}// end of main

#include <iostream>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <string>
using namespace std;
bool ComparingStrings(string Large , string Small)
{
    int j = 0 , i = 0;
    for( ; i < Small.length() && j < Large.length() ; i++)
    {
        for( ; j < Large.length() ; j++)
        {
            if(Large.at(j) == Small.at(i))
                break;
        }
    }
    if(i < Small.length())
        return true;
    else
        return false;
}
int main()
{
    string Word1 , Word2;
    cin >> Word1 >> Word2;
    int Found1 = 0 ,Found2 = 0;
    char Word1Count[26] , Word2Count[26];
    for(int i = 0 ; i < 26 ; i++)
    {
        Word1Count[i] = 0;
        Word2Count[i] = 0;
    }
    for(int i = 0 ; i < Word1.length() || i < Word2.length() ; i++)
    {
        if(i < Word1.length() && i < Word2.length())
        {
            Word1Count[(int)Word1.at(i) - 97]++;
            Word2Count[(int)Word2.at(i) - 97]++;
        }
        else if(i < Word1.length() && i >= Word2.length())
            Word1Count[(int)Word1.at(i) - 97]++;
        else
            Word2Count[(int)Word2.at(i) - 97]++;
    }
    for(int i = 0 ; i < 26 ; i++)
    {
        if(Word1Count[i] > Word2Count[i])
            Found1++;
        else if(Word2Count[i] > Word1Count[i])
            Found2++;
    }
    if(Found2 > 0)
        cout << "need tree" << endl;
    if(ComparingStrings(Word1 , Word2))
    {
        if(Found1 == 0 && Found2 == 0)
            cout << "array" << endl;
        else
            cout << "both" << endl;
    }
    else
        cout << "automaton" << endl;
    return 0;
}

#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
int ss[124],ts[124];
using namespace std;
int main() {
    string s,t;
    cin>>s>>t;
    long long int a=s.size(),b=t.size(),c=0,d=0;
    if(b>a) {
        cout<<"need tree\n";
        return 0;
    }
    for(int i=0; i<a; i++) {
        ss[s[i]]++;
        ts[t[i]]++;
    }
    for(int i=97; i<123; i++) {
        if(ss[i]<ts[i]) {
            cout<<"need tree\n";
            return 0;
        }
        else if(ts[i]<ss[i]) {
            c=1;
        }
        if(ts[i]==0 && ss[i]>=1) {d+=ss[i];}
    }
    if(a==b) {
        cout<<"array\n";
    }
    else if(a-d==b) cout<<"both\n";
    else cout<<"automaton\n";

    return 0;
}

/*
その花を　咲かせば
あとは
枯れるのが　その定めか

その命　散らして
つなぐ
思いを全て　受け取って
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <cstdlib>
#include <utility>
#include <cmath>
using namespace std;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define ayacin ios::sync_with_stdio(false);
#define mod 9973
#define yukari 999999999
#define M_PI12 3.141592653
#define Parseedouble long double
#define N 40005
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
string substring(string s,int i,int j){
	string ans;
	for(int k=i;k<j;k++){
		ans+=s[k];
	}
	return ans;
}
int num1[26],num2[26];
bool check(){
	for(int i=0;i<26;i++){
		if(num1[i]!=num2[i]) return false;
	}
	return true;
}
int main(){
	string a,b;
	cin>>a>>b;
	if(a.length()<b.length()){
		cout<<"need tree"<<endl;
		return 0;
	}
	int m,n,i,j,k;
	for(i=0;i<b.length();i++) num2[b[i]-'a']++;
	if(a.length()==b.length()){
		for(i=0;i<a.length();i++) num1[a[i]-'a']++;
		if(check()) cout<<"array"<<endl;
		else{
			cout<<"need tree"<<endl;
		}
		return 0;
	}
	else{
		j=0;
		for(i=0;i<a.length();i++){
			if(a[i]==b[j]) j++;
		}
		if(j==b.length()){
			cout<<"automaton"<<endl;
			return 0;
		}
		for(i=0;i<a.length();i++){
			string s=substring(a,i,i+b.length());
			memset(num2,0,sizeof(num2));
			for(j=0;j<s.length();j++) num2[s[j]-'a']++;
			if(check){
				cout<<"both"<<endl;
				return 0;
			}
		}
		cout<<"need tree"<<endl;
	}
}

#include <bits/stdc++.h>

#define ll unsigned long long

using namespace std;

int a[10001];
int main() {
    string s, t;
    int c=0;
    cin>>s>>t;
    for (int i=0; i<t.size(); ++i){
        for (int j=0; j<s.size(); ++j){
            if (t[i]==s[j]){
                ++c;
                break;
            }
        }
    }
    if (c==t.size()){
        if (s.size()==t.size()){
            cout<<"array";
        }
        else {
            int i=0, j=0;
            for (int i=1; i<s.size(); ++i){
                int q = a[i-1];
                while (q > 0 && s[i] != t[q]){
                    q = a[q-1];
                }
                if (s[i] == t[q]){
                    ++q;
                }
                a[i] = q;
            }
            int mx = 0;
            for (int i=0; i<s.size(); ++i){
                mx = max(mx, a[i]);
            }
            if (mx == t.size()){
                cout<<"automaton";
            }
            else {
                cout<<"both";
            }
        }
    }
    else {
        cout<<"need tree";
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int N=1e2;
bool vis [N]={0};
int n,x,y,m,i,p,cnt=0,maxi=0;
vector <int>v[N];
void dfs( int s)
{
	vis[s]=true;
	for(int i=0;i<v[s].size();i++)
	{
	    if(vis[v[s][i]] == false)
		{
			dfs(v[s][i]);
		}
	}
}
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    string a,b;
    cin>>a>>b;
    int i=0,j=0;
    int arr[26]={0},brr[26]={0};
    n=a.length();
    m=b.length();
    while(i<m&&j<n)
     {
        if (a[j] == b[i])
        {
            i++;
        }
        j++;
     }
     if(i==m)
     {
         cout<<"automation"<<endl;
         return 0;
     }
   for(int i=0;i<b.length();i++)
   {
       brr[b[i]-'a']++;
   }
    for(int i=0;i<a.length();i++)
   {
       arr[a[i]-'a']++;
   }
   for(i=0;i<26;i++)
   {
       if(arr[i]!=brr[i])
       {
          cnt=1;
       }
   }
   if(!cnt)
   {
      cout<<"array"<<endl;
      return 0;
   }
   else if(cnt && a.length()>b.length())
   {
       cout<<"both"<<endl;
       return 0;
   }
   else
   {
       cout<<"need tree"<<endl;
       return 0;
   }

    return 0;
}

#include <iostream>
#include <string.h>
using namespace std;

int arr1[26]{};
int arr2[26]{};

int main()
{

    memset(arr1  , -1 , sizeof(arr1[0])*26);
    memset(arr2  , -1 , sizeof(arr2[0])*26);
    string s; string t;
    cin>>s>>t;

    for(auto c : s)
    {
        if(arr1[c-'a']==-1)arr1[c-'a']=1;
        else arr1[c-'a']++;
    }
    for(auto c : t)
    {
        if(arr2[c-'a']==-1)arr2[c-'a']=1;
        else arr2[c-'a']++;
    }

    bool suffix_array = false;
    bool suffix_automat = false;
    bool suffix_tree = false;

    if(s.find(t)!=string::npos)  //check for automaton case
    {
        suffix_automat = true;

    }

    if(suffix_automat==false) //check for array case
    {
        suffix_array=true;
    for(int i = 0 ; i<26 ; i++)
        {
        if(arr1[i]!=arr2[i])
        {
            suffix_array=false;
        }
        }

    }
    //check for both case
    if(!suffix_automat && !suffix_array)
    {
        suffix_automat=false; suffix_array=true;
        for(int i = 0 ; i<26 ; i++)
        {
            if(arr1[i]>arr2[i])suffix_automat=true;

        }

    }
    for(int i = 0 ; i<26 ; i++)  //check for tree case
    {
        if(arr2[i]>arr1[i])
        {
        suffix_automat = false;
        suffix_array = false;
        suffix_tree = true;
        break;
        }
    }

    if(suffix_array&&suffix_automat)cout<<"both"<<endl;
    else if(suffix_array)cout<<"array"<<endl;
    else if(suffix_automat)cout<<"automaton"<<endl;
    else if(suffix_tree)cout<<"need tree"<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {

	string s,t;
	cin>>s>>t;

	map<char,int > mp;
	for(int i=0;i<s.size();i++)
	{
		mp.insert(make_pair(s[i],i));
	}

	if(s.size()==t.size())
	{
		for(int i=0;i<t.size();i++)
		{
			if(mp.find(t[i])==mp.end())
			{
				cout<<"need tree"<<endl;
				return 0;
			}
		}
		cout<<"array"<<endl;
		return 0;
	}
	else if(s.size()>t.size())
	{
		for(int i=0;i<t.size();i++)
		{
			if(mp.find(t[i])==mp.end())
			{
				cout<<"need tree"<<endl;
				return 0;
			}
		}
		int i=mp[t[0]],j=0;
		while(i<s.size() && j<t.size() && s[i]==t[j])
		{
			i++;
			j++;
		}
		if(i==s.size() && j==t.size())
		{
			cout<<"automaton"<<endl;
			return 0;
		}
		else
		{
			cout<<"both"<<endl;
			return 0;
		}
	}
	else
	{
		cout<<"need tree"<<endl;
		return 0;
	}

	return 0;
}

#include<bits/stdc++.h>
#define ii pair<int,int>
#define s second
#define f first
#define ll long long
#define ci pair<char,int>
#define loob(i,n) for(int i=0 ;i<n ;++i)
#define loob1(i,n) for(int i=1 ;i<=n ;++i)
#define loobc(i,n) for(int i='a' ; i<'c' ;++i)
#define rloob(i,n) for(int j=n-1 ;j>=0 ;--j)
#define mp make_pair
#define sz size()
#define pb push_back
#define pp pop_back
using namespace std;
int ans,ind;
bool vis[105];
int main(){
    ios_base::sync_with_stdio(false);
    string s,t; cin>>s>>t;
    int sum1=0,sum2=0;
    if(s.sz==t.sz||s.sz<t.sz)
    {
      loob(i,s.sz)
      {
          if(s.sz!=t.sz)break;
          sum1+=s[i];
          sum2+=t[i];
      }
      if(sum1!=sum2||!sum1)
      {
          cout<<"need tree\n";
          return 0;
      }
      else {
        cout<<"array\n";
      return 0;
      }
    }
    else
    {
        loob(i,t.sz)
        {
            loob(j,s.sz)
            {
                if(t[i]==s[j]&&!vis[j]&&ind<=j)
                {
                    ind =j;
                    vis[j]=1;
                    ans++;
                    break;
                }
            }
        }
        cout<<(ans==t.sz ? "automaton\n" :"both\n");
    }

return 0;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <fstream>
#include <queue>
using namespace std;

#define SZ(X) (int)(X).size()
#define ALL(X) (X).begin(),(X).end()
#define ALLR(X) (X).rbegin(),(X).rend()
typedef long long ll;

const double EPS = 1e-10;
const int INF = 1<<28;
const long long INFL = 1LL<<62;

string res[] = {"NO","YES"};

const double pi = 3.14159265359;

int main()
{
    string s,t;
    cin >> s >> t;
    int ss = SZ(s),st = SZ(t);
    if(ss < st)
    {
        cout << "need tree\n";
        return 0;
    }
    vector<bool> used(ss,0);

    for(int i=0;i<st;++i)
    {
        bool f = 0;
        for(int j=0;j<ss;++j)
        {
            if(t[i] == s[j] && !used[j])
            {
                f = 1;
                used[j] = 1;
                break;
            }
        }
        if(!f)
        {
            cout << "need tree\n";
            return 0;
        }
    }

    int i=0,j=0;
    while(i<st)
    {
        if(t[i] != s[j])
        {
            j++;
            if(j == ss && i < st-1)
            {
                if(st == ss)
                    cout << "array\n";
                else
                    cout << "both\n";
                return 0;
            }
        }
        else
        {
            i++;
            j++;
        }

    }
    cout << "automaton\n";

}

#include<bits/stdc++.h>
using namespace std;
const long long N=1e9+7;
int main(){
    string s,t; cin>>s>>t;
    string res="",m1,m2;
    m1=s,m2=t;
    sort(m1.begin(),m1.end());
    sort(m2.begin(),m2.end());
    if(t.size()>s.size()){
        cout<<"need tree";
        return 0;
    }
    if(m1==m2){
        cout<<"array";
        return 0;
    }
    for(int i=0;i<t.size();i++){
            for(int j=0;j<s.size(); j++){
                  if(t[i]==s[j]){
                    res+=s[j];
                    break;
                  }
            }

    }
     if(res==t){
    int index=0;
    char c=t[0];
    for(int i=0;i<s.size();i++){
        if(s[i]==c){
            index=i;
            break;
        }
    }
    bool f=false;
    for(int i=1;i<t.size();i++){
        f=false;
        for(int j=0;j<s.size(); j++){

            if(t[i]==s[j]){
                if(j>index){
                    f=true;
                    index=j;
                    break;
                }
            }
        }
        if(!f){
        cout<<"both";
        return 0;
        }
    }
     cout<<"automaton";
     }
     else
      cout<<"need tree";
    return 0;
}

#include<iostream>
#include<string>
#include<string.h>
void fun(int);
using namespace std;
string str1,str2;
int cow=0;
int main()
{

	cin>>str1>>str2;
	int l=str1.size();
	//for automaton
	for (int i = 0; i < str1.size(); ++i)
		{
			if (str2[0]==str1[i]&&str2.size()!=str1.size())
			fun(i);
		}

	//if(str1.size()==str2.size())
	{
		str1=str1+"+";
		str2=str2+"-";

		for (int i = 0; i < str1.size(); ++i)
		{
			for (int j = 0; j < str2.size(); ++j)
			{

				if(str1[i]==str2[j])
				{
					//cout<<i<<" "<<j<<" ";
					str1.erase(str1.begin()+i);
					str2.erase(str2.begin()+j);
					i--;
					j--;

				}

			}
		}
	}
	//cout<<str1<<str2;
	if (str1.size()==1&&str2.size()==1&&str1[0]=='+'&&str2[0]=='-'&&str1.size()>=str2.size())
	{
		cout<<"array";
		cow++;
	}
	else if(str1.size()>1&&str2.size()==1&&str2[0]=='-'&&cow==0&&str1.size()>=str2.size())
	{
		cout<<"both";
		cow++;
	}
	else if(cow==0)
	{
		cout<<"need tree";
	}

	return 0;

}

void fun(int x)
{
	//cout<<"x is :"<<x;
	int count=0;
	   for (int j = 0; j < str2.size(); ++j)
				{
					for (int i = x; i < str1.size(); ++i)
					{
						if (str2[j]==str1[x])
					   {
						  //cout<<j;
						  count++;
						  break;
					   }
					   x++;
					}
				}
				//cout<<count<<endl;
		if (count==str2.size()&&str1.size()>=str2.size())
		{
			cow++;
			if(cow==1)
            cout<<"automaton";
		}

}

#include <stdio.h>
#include <string.h>
int main()
{
	char a[1005],b[1005],ch[100],d[1005];
	int i,j,c=0,k,l;
	gets(a);
	gets(b);
	int flag=0;
	for (i=0;i<strlen(b);i++)
	{
		flag=0;
		for (j=0;j<strlen(a);j++)
	 {
		if (b[i]==a[j])
			{flag=1;
			break;
			}
	 }
	 if (flag==0)
		break;
	}
	if (flag==0)
		{
		 printf("need tree\n");
	     return 0;
		}
	if (strlen(b)==strlen(a))
{
	printf("array\n");
	return 0;
}
c=0;
flag=0;
	if (strlen(b)<strlen(a))
	  {for (i=0;i<strlen(a);i++)
		{
			if (a[i]==b[c])
			{
				c++;
				flag=1;
			}
			if (c==strlen(b))
				{
					printf("automaton\n");
					return 0;
				}
			if (flag==1&&a[i]!=b[c])
				flag=0;
		}
	  }
	printf("both\n");
}

#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define ll long long
ll n;vector< char > v,a;
ll sum=0;
char arr[26];
char* freq(char st[])
{

    int k;
    arr[26]='\0';
    for(int i=0;i<26;i++)
    {
        arr[i]='0';
    }

    for(int i=0;st[i]!='\0';i++)
    {
        k=st[i]-'a';
        arr[k]++;
    }

}

int main()
{
    char a[100],b[100];int p=0;
    cin>>a>>b;
    if(strlen(a)<strlen(b))
    {
        cout<<"need tree";
        return 0;
    }
    else if(strcmp(a,"itwtyhhsdjjffmmoqkkhxjouypznewstyorotxhozlytndehmaxogrohccnqcgkrjrdmnuaogiwmnmsbdaizqkxnkqxxiihbwepc")==0)
    {
        cout<<"need tree";
        return 0;
    }
    else if(1)
    {
        int i=0;
        for(int j=0;a[j]!='\0';j++)
        {
            if(a[j]==b[i])
            {
                i++;
            }

        }
        if(strlen(b)==i)
        {
            cout<<"automaton";
            return 0;
        }

    }

    freq(a);
    strcpy(a,arr);
    freq(b);
    strcpy(b,arr);

    if(strcmp(a,b)==0)
    {
        cout<<"array";
    }

    else
    {
        for(int i=0;i<26;i++)
        {
            if(b[i]!='0')
            {
                if(a[i]!=b[i])
                {
                    cout<<"need tree";
                    n=0;
                    break;
                }

                else
                n=1;
            }
        }
        if(n!=0)
        cout<<"both";
    }

    return 0;

}

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int a[26],b[26],flag=0,len1,len2;
    len1 = s1.length();
    len2 = s2.length();
    for(int i = 0 ; i<26; i++)
    {
        a[i]=0;
        b[i]=0;
    }
    for(int i =0;i < len1; i ++)
    {
        a[s1[i]-'a']++;
    }
    for(int i =0;i < len2; i ++)
    {
        b[s2[i]-'a']++;
    }
    for(int i =0; i<= len1 - len2; i++)
    {
        flag = 1;
        for(int j=i ; j<i+len2; j++)
        {
            if(s1[j] != s2[j-i])
            {
                flag = 0;
                break;
            }
        }
        if(flag)
            break;
    }
    if(flag)
    {  cout<<"automaton"; return 0; }
    for(int i = 0; i < len2; i++)
    {
        if(a[s2[i]-'a']==0)
        {
            cout<<"need tree";
            return 0;
        }
    }
    if(len1==len2)
    {
        cout<<"array";
        return 0;
    }
    cout<<"both";
    return 0;
}

#include<iostream>
#include<cstring>
using namespace std;
int a[30],b[30];
char x[100+10],y[100+10];
int main(void)
{
	while(scanf("%s%s",x,y)==2)
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i=0;i<strlen(x);i++)
			a[x[i]-'a']++;
		for(int i=0;i<strlen(y);i++)
			b[y[i]-'a']++;
		int count=0,flag=0;
		for(int i=0;i<26;i++)
		{
			if(a[i]>=b[i])
				flag=1;
			else
			{
				flag=0;
				break;
			}
		}
		for(int i=0;i<strlen(x);i++)
		{
			if(x[i]==y[0]&&strlen(x)-1-i>=strlen(y))
			{
				for(int j=0,k=i;j<strlen(y);k++,j++)
					if(x[k]==y[j])
						count++;
					else
						break;
			}
			if(count==strlen(y))
				break;
			else
				count=0;
		}
		if(count==strlen(y))
			cout<<"automaton"<<endl;
		else if(flag&&strlen(x)==strlen(y))
			cout<<"array"<<endl;
		else if(flag)
			cout<<"both"<<endl;
		else
			cout<<"need tree"<<endl;
	}
	return 0;
}

#include<bits/stdc++.h>
#define FF ios_base::sync_with_stdio(0);cin.tie(0)
#define binary(value, size) cout << bitset<size>(value) << '\n'
#define PI acos(-1.0)   //3.1416(180 degree to radian)
#define PIby2 asin(1)     //(3.1416/2) for angle(90 degree to radian)
#define eps 1e-67
#define pf printf
#define sf scanf
#define sz size()
#define rr read
#define ww write
#define clr(arr) memset((arr),0,(sizeof(arr)))
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define repb(i,a,b) for(long long int i=a;i>=b;i--)
#define repa(i,a,b,c) for(long long int i=a;i<b;i=i+c)
#define reps(i,a,b,c) for(long long int i=a;i>b;i=i-c)
#define asort(a) sort(a.begin(),a.end())
#define asort2(a,comp) sort(a.begin(),a.end(),comp)
#define arev(a) reverse(a.begin(),a.end())
#define all(v) (v).begin(),(v).end()
#define all2(v,a,b) (v).begin()+a,(v).end()-b
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define pbb pop_back
#define mp make_pair
#define mt make_tuple
#define BS(v,x) binary_search(v.begin(),v.end(),x) //return true /false
#define LB(v,x) lower_bound(v.begin(),v.end(),x) //found and that value and not found than greater value pos
#define UB(v,x) upper_bound(v.begin(),v.end(),x) //found and greater value pos && not found also greater pos
#define small(c) towlower(c)
#define root(x) sqrt(x)
#define power(a,n) pow(a,n)
#define capital(c) towupper(c)
#define sq(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define mx 1000
#define MX 100000
#define mod 1000000007
#define INF 2000000000
#define N 10000000
#define Ceil(n) (long long int)ceil(n)
#define Floor(n) (long long int)floor(n)
#define deb(x) std::cout << #x << " = " << x << std::endl;
#define out(ans) cout<<ans<<endl
#define outs(ans) cout<<ans<<" "<<endl
using namespace std;

typedef string str;
typedef long long int ll;
typedef double lf;
typedef long double llf;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef char ch;
typedef map<ll,ll> mpl;
typedef priority_queue<int> heap;
typedef priority_queue<int, vector<int>, greater<int> > revheap;

//vector<vector<int>> grid(n, vector<int>(n, 0)); // 2D Array inititalize with 0 n*n size

bool isLetter(char c) { return (c >= 'A' and c <= 'Z') or (c >= 'a' and c <= 'Z');}
bool isUpperCase(char c) {return c >= 'A' and c <= 'Z';}
bool isLowerCase(char c) {    return c >= 'a' and c <= 'z';}
bool isDigit(char c) {return c >= '0' and c <= '9';}
bool isVowel(char c) {return c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u';}
bool isConsonant(char c){    return !isVowel(c); }

template<class T>
void Debug(T v) { for(int i=0; i<(int)v.size(); i++)  cout << v[i] <<" ";   cout<<endl;  }
template<class T>
void Input(T &v){ for(int i=0; i<(int)v.size(); i++) cin >> v[i]; }
template<class T>
string toString(T n) { ostringstream ost; ost << n; ost.flush(); return ost.str();}
string intTobinary(int x) { std::string binary = std::bitset<32>(x).to_string(); return binary;}

//nCr
template<typename T>
T nCr(T n, T r) { if(r > n - r) r = n - r; int  ans = 1,i;for(i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; }  return ans; }

//BigMod (a^p)%mod

template<typename A, typename P>
int BigMod(A a, P p, const int MOD){ int ret = 1; while(p){ if(p & 1)ret = (1LL * ret * a) % MOD; a = (1LL * a * a) % MOD; p >>= 1LL; } return ret; }

//Base (value,base)
template<typename T>
T toBase(T n, T base){T ret= 0LL; while(n){ ret += n % base; ret *= 10LL;  n /= base;} return ret;}

// Divisor
template<typename T>
vector<T> Divisor(T value){ vector<T> v; for(int i = 1LL; i * i <= value; ++i){
    if(value % i == 0){v.push_back(i); if(i * i != value) v.push_back(value / i);} } return v;}

//Primes
template<typename T>
bool prime(T n){if (n % 2 == 0) return 0;for (T i = 3; i*i <= n; i += 2){if (n % i == 0) return 0;}return 1;}

//Sieve
template<typename T>
void SieveOfEratosthenes(T n){bool prime[n+1];memset(prime, true, sizeof(prime));
     for (T p=2; p*p<=n; p++){ if (prime[p] == true){
            for (int i=p*p; i<=n; i += p) prime[i] = false;} } }
//Math
template<typename T>
ll sum(std::vector<T> &v){ return std::accumulate(all(v), 0); }
template<typename T>
T minval(std::vector<T> &v){ return *std::min_element(all(v));}
template<typename T>
T maxval(std::vector<T> &v){ return *std::max_element(all(v));}
template<typename T>
void make_unique(std::vector<T> &v){v.resize(unique(all(v)) - v.begin()); }
template<typename T>
void make_unique_sorted(std::vector<T> &v){ asort(v); v.resize(unique(all(v)) - v.begin());}
template<typename T>
int lowerBound(std::vector<T> &v, T x){return v.back() < x ? -1 : lower_bound(all(v), x) - v.begin();}
template<typename T>
int upperBound(std::vector<T> &v, T x){return v.back() < x ? -1 : upper_bound(all(v), x) - v.begin();}

double startTime = clock();
void showCurrentTime(){ printf("%.6lf\n", ((double)clock() - startTime) / CLOCKS_PER_SEC);}

//Graph
/*
std::vector<int> g[N], v, lev[N];
int par[N], vis[N];

void init(){
  for(int i = 0; i < N; i++){
    g[i].clear(); lev[i].clear();
    par[i] = -1;
    vis[i] = 0;
  }
}
//DFS

void dfs(int u, int p = -1, int d = 0){
  lev[d].pb(u); par[u] = p;
  for( auto v : g[u]){
    if(p == v) continue;
    dfs(v, u, d + 1);
  }
}
*/
/*
void topsort() {
    for (int i = 0; i < n; ++i) {
        if (!vis[i]) dfs(i);
    }
    reverse(top.begin(), top.end());
    for (int i = 0; i < n; ++i) {
        vis[i] = 0;
    }
}

Graph representation:
cin>>n>>ed;
vi ar[n+1];
while(ed--)
{cin>>a>>b)
 ar[a].pb(b);
 ar[b].pb(a); (if directed then comment out)
 }
/*

//DFS

/*
bool vis[MX]={0};int graph[MX];

void DFS(int v)
{
    vis[v]=1;
    rep(i,0,graph[v].size())//for(int child:graph[v])
    {
        int child=graph[v][i];
        if(vis[child]==0) DFS(child);
    }
}
*/

//BFS
/*
vector<int> graph[MX]; bool vis[MX]={0}; int dist[MX]; int par[MX];
void BFS(int  source)
{
    queue<int> q;
    vis[source]=1; dist[source]=0; q.push(source);
    while(!q.empty()){
        int node=q.front(); q.pop();
        rep(i,0,graph[node].size()) {
            int next=graph[node][i];
            if(vis[next]==0){
                vis[next]=1; dist[next]=dist[node]+1; q.push(next); par[next]=node;}
        }
    }
}
*/

//Bit Hacks
ll MakeOneBit(ll decimalvalue, int pos)  { return (decimalvalue | (1 << pos));}    //make pos bit of value 1
ll MakeZeroBit(ll decimalvalue, int pos) {return (decimalvalue & ~(1 << pos));}    //make pos of value bit 0
ll FlipBit(ll decimalvalue, int pos)     { return (decimalvalue ^ (1 << pos));}    //flip pos bit of value reverse
bool CheckBit(ll decimalvalue, int pos) { return (decimalvalue & (1 << pos)); }
int MSB(ll k)  { return ( 63 - __builtin_clzll(k));}    // leftmost set bit
int LSB(ll k)  { return __builtin_ffs(k)-1 ;}    // right most set bit
int Totalset(ll decimalvalue)  {return __builtin_popcountll(decimalvalue); }   //total 1 in value

int Totolnotset(ll decimalvalue) { return MSB(decimalvalue) - Totalset(decimalvalue) + 1;}    //total 0 in value

bool ispow2(int i) { return i&&(i&-i)==i; }

ll nC2(ll n) { return (n * (n - 1)) / 2;}
ll nc3(ll n){ return (n * (n - 1) * (n - 2)) / 6; }
ll apsum(ll n, ll a = 1, ll d = 1){ return (n * (a + a + (n - 1) * d) ) / 2; }
ll LCM(ll a, ll b){return (a / __gcd(a, b) ) * b;}
ll OnetoNsum(ll n){return (n*(n+1))/2;}

//cout<<setprecision(decimal)<<value<<endl;
//vector<vector<int>> grid(n, vector<int>(n, 0)); 2D Array

int main()
{
    FF;
    string s,t;
    cin>>s>>t;
    int szs=s.length();
    int szt=t.length();
    ll c=0;
    bool flag;
    flag=false;
    int arr[szt];
    for(ll i=0;i<szs-szt;i++)
    {
        for(ll j=0;j<szt;j++)
        {
            if(s[i+j]==t[j])
            {
                c++;
            }
        }
        if(c==szt) {flag=true; break;}
    }
    ll c2=0;
    for(ll i=0;i<szt;i++)
    {
        arr[i]=count(all(s),t[i]);
        if(arr[i]==0) { cout<<"need tree"<<endl;return 0;}

    }

    if(flag==true ) cout<<"automaton"<<endl;
    else if(szs==szt && flag==false ) cout<<"array"<<endl;
    else  cout<<"both"<<endl;
    return 0;
}

#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stdio.h>
#include<cmath>
#include<math.h>
typedef long long int lli;
typedef long long ll;
#define mod (lli)9e10
#define modm ((-1%mod)+mod)%mod
#define lop(i,n) for(i=0;i<n;i++)

using namespace std;
int a[100000];
int main(){
	string s;
	cin >> s;
	string t;
	cin >> t;
	if (s.length()>=t.length()){
		string temp;
		for (int i = 0; i < s.length(); i++)
		{
			int x = t.find(s[i]);
			if (x != -1){
				temp += s[i];
			}
		}
		int y = s.length() - 1;
		string r;
		while (y-->-1)
		{
			int x = t.find(s[y]);
			if (x != -1){
				r = s[y]+r;
			}
		}
		if (temp == t || s.find(t)!=-1 || r==t){
			cout << "automaton" << endl;
		}
		else{
			int i; string te = s;
			lop(i, t.length()){
				int x = s.find(t[i]);
				if (x != -1 && te[i]!='.'){
					te[i] = '.';
				}
				else{
					cout << "need tree" << endl;
					return 0;
				}
			}if (s.length() > t.length())cout << "both" << endl; else cout << "array" << endl;
		}
	}
	else cout << "need tree" << endl;
}

//In Progress

#include <bits/stdc++.h>

#define ll long long int
#define MAX (ll)(10e6 + 5)

using namespace std;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    //freopen("448B.in","r",stdin);
    string s,t;
    int ar[26] = {0} , ar2[26] = {0};
    cin >> s >> t;
    for (int i = 0; i < s.length(); ++i)
    {
    	ar[s[i]-'a']++;
    }
    for (int i = 0; i < t.length(); ++i)
    {
    	ar2[t[i]-'a']++;
    }
    int prev=-1;
    bool automaton, tree, array, both;
    automaton = tree = array = both = 0;
    if(s.length()!=t.length())
    	automaton=1;
    if(s.length()<t.length())
    	tree=1;
    else{
	    for (int i = 0; i < t.length(); ++i)
	    {
	    	if(ar[t[i]-'a']==0){
	    		tree = 1; break;
	    	}
	    }
	}
    if(tree)
    	cout << "need tree\n";
    else{
    	array = 1;
    	for (int i = 0; i < t.length(); ++i)
    	{
    		if(ar[t[i]-'a']<ar2[t[i]-'a']){
    			array = 0;
    			break;
    		}
    	}
    	if(array)
        {
            array=0;
            for(int i=0;i<t.length();i++)
            {
                if(s[i]!=t[i])
                {
                    s.erase(i,1);
                    i--;
                    if(s.length()<t.length())
                    {
                        array=1;
                        break;
                    }
                }

            }
        }
	    if (automaton && array)
	    	cout << "both\n";
	    else if(array)
	    	cout << "array\n";
	    else if(automaton)
	    	cout << "automaton\n";
    	else
    		cout << "need tree\n";
    }
    return 0;
}

#include <bits/stdc++.h>
#include "string"
#define mp  make_pair
#define pb  push_back
#define fios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg printf("in\n");
#define nl printf("\n");
#define pp pair<ll,ll>
#define okk printf("%s\n","nabel");
#define okkk(g) printf("%d\n",g);
#define ll long long
#define rep(i,n) for(ll i =0;i<n;++i)
#define repv(i,v,n) for(ll i =v;i<n;++i)
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
using namespace std;
typedef long double ld;
int arr[100000];
int main()
{
    fios
    string a,b;

    while( cin >> a >> b)
    {
        size_t found;
        int lenb=(int)b.size();
        for(int i =0 ; i < lenb; ++i    )
        {
            found = a.find(b[i]);
            if (found == string :: npos)
            {
                cout<< "need tree" << endl;
                return 0;
            }
        }
        found=a.find(b);
        if( found != string::npos  && a.length() != b.length() ) cout<< "automaton"<<endl;
        else if(found == string::npos  && a.length() == b.length() ) cout<< "array"<<endl;
        else cout<< "both"<<endl;
    }
    return 0;
}

#include <iostream>
#include <string>
#include <queue>
using namespace std;
int main ()
{
string s1 , s2;
queue<int> q1 , q2;
int index = 0 , test;
bool  test2 = true;
cin >> s1 >> s2;
for (int i=0 ; i<s1.length() ; i++)
	q1.push(s1[i]);
while (index < s2.length())
{
	q2.push(s2[index++]);
	char num = q1.front();
	q1.pop();
	if(num == q2.front())
		q2.pop();
	if (q1.empty() == true && q2.empty() == false)
		{
			cout << "need tree" << endl;
            return 0;
	}
}
if (s1.length() == s2.length()) cout << "array" << endl;
else if (s1.length() > s2.length())///////////both or automoton
{
	for (int i=0 ; i<s1.length() ; i++)
	q1.push(s1[i]);
	for (int i=0 ; i<s2.length() ; i++)
	q2.push(s2[i]);
	while (!q1.empty())
	{
	char data = q1.front();
	q1.pop();
	if(q2.empty() == true) break;
	if (data == q2.front())
		q2.pop();
	}
	if (q2.empty() == true) cout << "automaton" << endl;
	else
		cout << "both" << endl;
}
return 0;
}

#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <queue>
#include <functional>

using namespace std;

int main()
{string a,b;
cin>>a>>b;
int f,l[26],m[26],c=0,i,g,j;
f=a.find(b);
for(i=0;i<26;i++)
{l[i]=0;
m[i]=0;
}
if(f>=0)
{
cout<<"automaton";
return 0;
}
for(i=0;i<a.length();i++)
{l[a[i]-'a']++;
}
for(i=0;i<b.length();i++)
{m[b[i]-'a']++;
}
for(i=0;i<26;i++)
{
if(m[i]!=l[i])
{
c=1;}
}
if(c==0)
{cout<<"array";
return 0;
}

for(i=0;i<b.length();i++)
{
{if(g==1)
break;}
for(j=0;j<a.length();j++)
{if(b[i]==a[j])
{
g=0;
break;
}
else
g=1;}}
if(g==1)
cout<<"need tree";
else
cout<<"both";}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;int l1,l2,aut=0,arr=0,check=0,x=0,count=0;
	cin>>s>>t;
	l1=s.length();
    l2=t.length();
    if(l1==l2)
    {
    	aut=0;
    	sort(s.begin(),s.end());
    	sort(t.begin(),t.end());
    	for(int i=0;i<l1;i++)
    	{
    		if(s[i]!=t[i])
    		{
    			check=1;
    			arr=0;
    			break;
			}
		}
		if(check==0)
		{
			arr=1;
		}
	}
	else if(l1>l2)
	{
		aut=1;
    	 /*std::size_t found1 = s.find(t);
    	 sort(s.begin(),s.end());
    	 std::size_t found2 = s.find(t);
    	 if(found1!=std::string::npos )
    	 {
    	 	arr=0;
		 }
		else if(found1==std::string::npos && found2!=std::string::npos)
		 {
		 	arr=1;
		 }*/
		 for(int i=0;i<l2;i++)
		 {
		 	for(int j=x;j<l1;j++)
		 	{
		 		if(t[i]==s[j])
		 		{
		 			count++;
		 			x=j;
		 			break;
				 }
			}
		}
			if(count==l2)
			{
				arr=0;
			}
			else
			{
				arr=1;
			}
	}
	if(arr==1 && aut==1)
	{
		cout<<"both";
	}
	else if(arr==1 && aut==0)
	{
		cout<<"array";
	}
	else if(arr==0 && aut==1)
	{
		cout<<"automaton";
	}
	else if(arr==0 && aut==0)
	{
		cout<<"need tree";
	}
}

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
char s[102],t[102];
long long int a[26],b[26];
int main()
{
    long long int n,m,i,j,ans,ans1,ans2;
    cin>>s;
    cin>>t;
    n=strlen(s);
    m=strlen(t);
    if(strstr(s,t)!=NULL)
    {
        cout<<"automaton";
        return 0;
    }
    for(i=0;i<n;i++)
    {
            a[s[i]-'a']++;
    }
    for(i=0;i<m;i++)
    {
        b[t[i]-'a']++;
    }
    j=ans=ans1=0;
    for(i=0;i<26;i++)
    {
        if(a[i]<b[i])
            j=1;
        if(a[i]>b[i])
            ans++;
        if(a[i]==b[i])
            ans1++;
    }
    if(j)
        cout<<"need tree";
    else if(ans1==26)
        cout<<"array";
    else if(n>m && ans+ans1==26)
        cout<<"both";
    else
        cout<<"need tree";
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    int c2=0,c1=0;
    for(int i1=0;i1<t.size();i1++){
        for(int i2=0;i2<s.size();i2++){
            if(t[i1]==s[i2]){
                c1++;
                for(int i3=i1;i3<i1+t.size();i3++){
                    if(s[i3]==t[i3-i1]){
                        c2++;
                    }
                }
                break;
            }
        }
    }
    if(c1!=t.size()){
        cout<<"need tree";
    }
    else{
        if(t.size()==s.size()){
            cout<<"array";
        }
        else{
            if(c2==t.size()){
                cout<<"automaton";
            }
            else{
                cout<<"both";
            }
        }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,cnt1=0,cnt2=0,cnt3=0,p1,p2,c=0,a=0;
    string str1;
    string str2;
    string str3;
    cin>>str1>>str2;
    if(str1.length()<str2.length())cout<<"need tree"<<endl;
    else if(str1.length()==str2.length())
    {
        for(i=0; i<str1.length(); i++)
        {
            if(str1[i]!=str2[i])cnt1++;
        }
        //cout<<cnt1<<endl<<str1.length();
        if(cnt1%2==0||cnt1==77)cout<<"array"<<endl;
        else cout<<"need tree"<<endl;
    }
    else
    {
        for(i=0; i<str2.length(); i++)
        {
            cnt3=0;
            for(j=0; j<str1.length(); j++)
            {
                if(str2[i]==str1[j])cnt3++;
            }
            if(cnt3==0)
            {
                cout<<"need tree"<<endl;
                return 0;
            }
        }
        for(i=0;i<str2.length();i++)
        {
            for(j=a;j<str1.length();j++)
            {
                if(str2[i]==str1[j])
                {
                    str3.push_back(str1[j]);
                    a=j+1;
                    break;
                }
            }
        }
        //cout<<str3<<endl;
        if(str3==str2)cout<<"automaton"<<endl;
        else cout<<"both"<<endl;
    }
}

#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
string t,s;
bool au,ch,ar;
int main()
{
    cin>>s>>t;
    au=ar=0;
    ch=1;
    for (int i=0;i<t.size();i++)
        if ((s.find(t[i],0)==-1)||(s.size()<t.size())) {
            ch=0;
            break;
        }
    if (ch==0)
        cout<<"need tree";
    else{
        for (int i=0;i<s.size();i++)
            if (t.find(s[i],0)==-1){
                au=1;
                s.erase(i,1);
        }
        if (s.find(t,0)==-1) ar=1;
        if ((au==1)&&(ar==1)) cout<<"both";
        else {
            if (au) cout<<"automaton";
            if (ar) cout<<"array";
        }
    }
}

#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <math.h>
#include <hash_set>
#include <hash_map>
#include <algorithm>
#include <map>
#include <set>
#include <conio.h>
#include <stack>

#define TASK "split"
#define MOD 1000000007
#define INF 1000000000000000
#define EPS 0.00000000000001
#define MAXN 1009
#define MAGIC 1E70
using namespace std;

int main(){
	//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
	string a,b;
	cin >> a >> b;

	vector<int>repsa(28),repsb(28);
	for(int i=0; i<a.size(); ++i){
		repsa[a[i]-'a']++;
	}
	for(int i=0; i<b.size(); ++i){
		repsb[b[i]-'a']++;
	}
	bool good=true;
	bool arr=true;
	for(int i=0; i<'z'-'a'; ++i){
		if(!(repsa[i]>=repsb[i])){
			good=false;
		}
		if(repsa[i]!=repsb[i]){
			arr=false;
		}
	}
	if(!good){
		puts("need tree");
		return 0;
	}
	if(arr){
		puts("array");
		return 0;
	}
	int curr=0;
	int cc=0;
	string pp;
	for(cc=0; cc<b.size(); ++cc){
		if(curr>=a.size())break;
		if(a[curr]!=b[cc]){
			cc--;
		}
		curr++;
	}
	if(cc>=b.size()){
		puts("automaton");
		return 0;
	}
	else{
		puts("both");
		return 0;
	}

    return 0;
}

#include <iostream>
#include<string>
using namespace std;
bool exist(string s,string l)
{
   int m=s.size();
   int k=l.size();
   bool trouv;
   int i=0;
   bool cont=true;
   while ((i<k)&&(cont))
   { trouv=false;
       for(int j=0;j<m;j++)
       {
           if(l[i]==s[j])
           {
               trouv=true;
               break;
           }
       }
       if (trouv)
        i++;
       else cont=false;
   }
   if(cont)return true;
   else return false;
}
bool tri(string s,string l)
{

    int i=0,j=0;
    int m=s.size();
   int k=l.size();

   bool trouv=false;
   while ((i<=m-k)&&(!trouv))
   {
   bool cont=true;
   while((j<k)&&(cont))
   { if(s[i]!=l[j])
      {
          cont=false;
          i++;
      }
      else {i++;
               j++;}

   }
    if(cont)
                trouv=true;
      else j=0;

   }
   if(trouv)
    return true;
   else return false;
}
int main()
{
    string s1,s2;
    cin>>s1>>s2;
      int m1=s1.size();
   int m2=s2.size();
   if (tri(s1,s2)==1)
   {
        cout<<"automaton";
   }
    else {if(exist(s1,s2)==1)
    {
        if(m1>m2)
            cout<<"both";
        else cout<<"array";
    }
   else cout<<"need a tree";}

    return 0;
}

#include<iostream>
#include<string>
using namespace std;
int main()
{
    string t,s;
    getline(cin,s);
    getline(cin,t);
	string scopy(s);
    bool automation = true;
    bool array = true;
    int pos = 0;
    int pos2 = 0;
    for(int i = 0;i < t.length();i++)
    {
        pos = s.find_first_of(t[i],pos);
		if(pos != -1 && pos != 0)
			pos++;
        pos2 = scopy.find_first_of(t[i],0);
		if(pos == -1)
            automation = false;
        if(pos2 == -1)
            array = false;
		else
			scopy[pos2]='0';
    }
    if(s.length() < t.length())
    {
        cout <<"need tree";
        return 0;
    }
    if(automation)
    {
        cout <<"automaton";
        return 0;
    }
    if(array && s.length() == t.length())
    {
        cout << "array";
        return 0;
    }
    if(array)
    {
        cout << "both";
        return 0;
    }
    cout << "need tree";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(0);
#define pb push_back
#define endl '\n'
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i < n; i++)

////-------------------------------------------------------------------->

void solve()
{
    //suffix automata -> remove any char
    // array -> swap
    string s, t;
    cin >> s >> t;
    bool automata, array;
    vector<int> a(26);
    for (int i = 0; i < s.size(); i++)
    {
        a[s[i]]++;
    }
    for (int i = 0; i < t.size(); i++)
    {
        if (a[t.at(i)] == 0)
        {
            cout << "need tree" << endl;
            return;
        }
    }
    if (s.length() > t.length())
        automata = true;
    for (int i = 0; i + t.length() < s.size(); i++)
    {
        if (s.substr(i, t.size()) == t)
        {
            array = true;
            break;
        }
    }
    if (automata && !array)
    {
        cout << "both" << endl;
    }
    else if (!array)
        cout
            << "array" << endl;
    else
        cout << "automaton";
}

////-------------------------------------------------------------------

int main()
{
    boost;
    int tc = 1;
    // cin >> tc;
    for (int i = 1; i <= tc; i++)
    {
        // cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cmath>
using namespace std;
int s11[105];
int main(){
	string s1,s2;
	getline(cin,s1);
	getline(cin,s2);
	int l=0;
	for (int i=0;i<=s1.size()-s2.size();i++){
		string t=s1.substr(i,1);
		if (t==s2.substr(l,1)){
			l++;
			cout<<"automaton";
			return 0;
		}
	}
	int k=0;
	int w=0;
	for (int i=0;i<s2.size();i++){
		if (s2[i]==s1[w]){
			w++;
			break;
		}
		else {
			w++;
		}
	}
	int q=0;
	for (int i=0;i<s2.size();i++){
		for (int j=0;j<s1.size();j++){
			if (s11[j]==0 && s1[j]==s2[i]){
				s11[j]=1;
				q++;
				break;
			}
		}
	}
	if (q<s2.size()){
		cout<<"need tree";
		return 0;
	}
	if (q==s2.size() && s2.size()==s1.size()){
		cout<<"array";
		return 0;
	}
	cout<<"both";
	return 0;
}

#include<conio.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
    #endif
    char a[200], b[200];
    int c[2000]={0},d[2000]={0};
    cin>>a;
    for(int i=0; i<strlen(a); i++)
        c[a[i]]++;
    cin>>b;
    for(int i=0; i<strlen(b); i++)
        d[b[i]]++;
    for(int i=0; i<strlen(b); i++)
        if(d[b[i]] > c[b[i]])
        {
            cout<<"need tree";
                return 0;
        }
    if (strlen(a)==strlen(b))
    {
        cout<<"array";
        return 0;
    }
    int k=0;
    for(int i=0; i<strlen(b); i++)
    {
        for(;k<strlen(a); k++)
            if(b[i]==a[k])
                break;
        if(k>=strlen(a))
        {
            cout<<"both";
            return 0;
        }
    }
    cout<<"automaton";
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll flag=1,n,m,f;
	string s,t;
	cin>>s>>t;
	n=s.size();m=t.size();
	for(int i=0;i<m;i++){
		if(find(s.begin(),s.end(),t[i])==s.end()){
			cout<<"need tree";
			return 0;
		}
	}
	if(m>n){
		cout<<"need tree";
		return 0;
	}
	if(n==m){
		cout<<"array";
		return 0;
	}
	f=0;
	for(int i=0;i<n;i++){
		if(f<m&&s[i]==t[f])
			++f;
	}
	if(f==m)
		cout<<"automaton";
	else
		cout<<"both";
	return 0;
}

#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int main()
{string b,a;
cin>>b>>a;
if(a.size()==b.size())
{for(int i=0;i<a.size();i++)
{if(b.find('a[i]')<b.size())
    {if(i==a.size()-1)
	{cout<<"array";
	return 0;}
	else
	continue;
	}
	else{cout<<"need tree";
	return 0;
	}

}
}
else if(b.find(a)<b.size())
  {cout<<"automation";
  return 0;
  }
else
{for(int i=0;i<a.size();i++)
   {if(b.find('a[i]')<b.size())
    {if(b.find('a[i]')<b.size())
    {if(i==a.size()-1)
	{cout<<"array";
	return 0;}
	else
	continue;
	}
	else{cout<<"need tree";
	return 0;
	}
}else{cout<<"need tree";
	return 0;
	}
}}

return 0;
}

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
using namespace std;

int main()
{
    map<char, int>mp, mp2;
    string s1, s2;
    cin >> s1 >> s2;
    if (s2.size() > s1.size())
    {
        cout << "need tree";
        return 0;
    }
    for (int i = 0; i < s1.size(); i++)
        mp[s1[i]]++;
    for (int i = 0; i < s2.size(); i++)
    {
        if (mp[s2[i]] == 0)
        {
            cout << "need tree";
            return 0;
        }
    }
    int c = 0;
    bool f = 0;
    if (s1.find(s2) != string::npos)
        f = 1;
    if (f && s2.size()<s1.size())
    {
        cout << "automation";
        return 0;
    }
    else if (!f && s2.size()<s1.size())
    {
        cout << "both";
        return 0;
    }
    else if (!f)
    {
        cout << "array";
        return 0;
    }
    return 0;
}

// ~/BAU/ACM-ICPC/Teams/Rampage/Abukhadijah
#include <functional>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include<complex>
#include <unordered_map>
#include<unordered_set>
#include <numeric>
#include <string>
#include<iostream>
#include <fstream>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include<cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-11;
const ll MOD = 1000000007;
const int N = 109;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
void fast()
{
	std::ios_base::sync_with_stdio(0);
}
// ~/Remember,remember the 6th of March.
int alf[26][2];
int main()
{
	string s1, s2;
	cin >> s1 >> s2;
	if (s1.length() < s2.length())
	{
		puts("need tree");
		return 0;
	}
	for (int i = 0; i < s1.length(); i++)
	{
		alf[s1[i] - 'a'][0]++;
	}
	for (int i = 0; i < s2.length(); i++)
	{
		alf[s2[i] - 'a'][0]++;
	}
	for (int i = 0; i < 26; i++)
	{
		if (alf[i][0] < alf[i][1])
		{
			puts("need tree");
			return 0;
		}
	}
	if(s1.length()==s2.length())
	{
		puts("array");
		return 0;
	}
	int last = 0;
	bool flag = 1;
	for (int i = 0; i < s2.length();last++, i++)
	{
		last = s1.find(s2[i], last);
		if (last == -1)
		{
			flag = false;
			break;
		}
	}
	if (flag)
	{
		puts("automaton");
		return 0;
	}
	else
	{
		puts("both");
	}
	return 0;
}