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

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

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


-----Input-----

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


-----Output-----

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

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


-----Examples-----
Input
automaton
tomat

Output
automaton

Input
array
arary

Output
array

Input
both
hot

Output
both

Input
need
tree

Output
need tree



-----Note-----

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

Difficulty: MEDIUM

Solutions:
(s, t) = (input(), input())
if t in s:
	print('automaton')
else:
	(cnt1, cnt2) = ([0 for i in range(26)], [0 for i in range(26)])
	for i in s:
		cnt1[ord(i) - ord('a')] += 1
	for i in t:
		cnt2[ord(i) - ord('a')] += 1
	array = True
	for i in range(26):
		if cnt2[i] > cnt1[i]:
			array = False
			break
	if array == False:
		print('need tree')
	else:
		(i, j) = (0, 0)
		while i < len(s) and j < len(t):
			if s[i] == t[j]:
				i += 1
				j += 1
			else:
				i += 1
		if j == len(t):
			print('automaton')
		elif len(s) == len(t):
			print('array')
		else:
			print('both')


def check(s1, s2):
	for i in s1 + s2:
		if s1.count(i) < s2.count(i):
			return 0
	return 1

def aut(s1, s2):
	a1 = a2 = 0
	while a2 < len(s2):
		if a1 == len(s1):
			return 0
		while s1[a1] != s2[a2]:
			a1 += 1
			if a1 == len(s1):
				return 0
		a2 += 1
		a1 += 1
	return 1
s1 = input()
s2 = input()
if sorted(s1) == sorted(s2):
	print('array')
elif aut(s1, s2):
	print('automaton')
elif check(s1, s2):
	print('both')
else:
	print('need tree')


s = input()
t = input()
a = [0] * 26
for x in s:
	a[ord(x) - 97] += 1
flag = False
for x in t:
	if a[ord(x) - 97] > 0:
		a[ord(x) - 97] -= 1
	else:
		flag = True
		break
if flag:
	print('need tree')
else:
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			j += 1
		i += 1
	if len(s) != len(t):
		if j == len(t):
			print('automaton')
		else:
			print('both')
	else:
		print('array')


def solve():
	a = input()
	b = input()
	j = 0
	for i in a:
		if i == b[j]:
			j += 1
		if j == len(b):
			break
	if j == len(b):
		return 'automaton'
	num = [0] * 42
	for i in a:
		num[ord(i) - ord('a')] += 1
	for i in b:
		num[ord(i) - ord('a')] -= 1
	for i in num:
		if i < 0:
			return 'need tree'
	if sum(num) > 0:
		return 'both'
	else:
		return 'array'

def __starting_point():
	print(solve())
__starting_point()


s = input().strip()
r = input().strip()
sd = dict()
rd = dict()
for k in s:
	if k in sd:
		sd[k] += 1
	else:
		sd[k] = 1
for k in r:
	if k in rd:
		rd[k] += 1
	else:
		rd[k] = 1
can = True
for k in r:
	if not k in sd or rd[k] > sd[k]:
		can = False
if not can:
	print('need tree')
else:
	can = True
	for k in s:
		if not k in rd or rd[k] != sd[k]:
			can = False
	if can:
		print('array')
	else:
		ind = 0
		for i in range(len(s)):
			if s[i] == r[ind] and ind < len(r) - 1:
				ind += 1
		if ind == len(r) - 1:
			print('automaton')
		else:
			print('both')


from collections import Counter
first = input()
second = input()
cnt1 = Counter(first)
cnt2 = Counter(second)
array = True
for (k, v) in cnt2.items():
	if v > cnt1[k]:
		print('need tree')
		exit()
	if v != cnt1[k]:
		array = False
for (k, v) in cnt1.items():
	if v != cnt2[k]:
		array = False
		break
if array:
	print('array')
	exit()
stack = list(second[::-1])
for c in first:
	if c == stack[-1]:
		stack.pop()
	if not stack:
		print('automaton')
		exit()
print('both')


s = input()
t = input()
ind = 0
k = 0
l1 = [0] * 26
for i in s:
	l1[ord(i) - 97] += 1
for i in t:
	l1[ord(i) - 97] -= 1
for i in l1:
	if i < 0:
		k = -1
		break
	elif i > 0:
		k = 1
for i in s:
	if i == t[ind]:
		ind += 1
	if ind == len(t):
		break
if k == 0:
	print('array')
elif k == 1:
	if ind == len(t):
		print('automaton')
	else:
		print('both')
else:
	print('need tree')


import sys
import math as m

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l
mod = int(1000000000.0) + 7

def sinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def ninp():
	return map(int, sys.stdin.readline().strip().split())

def llinp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(a):
	print(a)

def p2(a, b):
	print(a, b)
s = sinp()
t = sinp()
a = [0] * 26
for c in s:
	a[ord(c) - 97] += 1
for c in t:
	a[ord(c) - 97] -= 1
aut = 0
arr = 0
cnt = 0
for i in a:
	if i < 0:
		print('need tree')
		exit()
	elif i > 0:
		aut = 1
		cnt += i
ind1 = 0
ind2 = 0
for j in range(len(s)):
	if s[ind1] == t[ind2]:
		ind1 += 1
		if ind1 >= len(s):
			ind1 = len(s) - 1
		ind2 += 1
		if ind2 >= len(t):
			ind2 = len(t) - 1
	elif cnt > 0:
		cnt -= 1
		ind1 += 1
		if ind1 >= len(s):
			ind1 = len(s) - 1
	else:
		arr = 1
		break
if aut == 1 and arr == 1:
	print('both')
elif aut == 1:
	print('automaton')
else:
	print('array')


(s, t) = (input(), input())
(sx, tx) = (str(sorted(s)), str(sorted(t)))

def subset(s, t):
	i = 0
	for c in s:
		if c == t[i]:
			i += 1
		if i == len(t):
			break
	return i == len(t)
if sx == tx:
	print('array')
elif subset(s, t):
	print('automaton')
elif subset(sx, tx):
	print('both')
else:
	print('need tree')


s = input()
t = input()
array = automaton = both = 1
let = set(s) | set(t)
if len(s) == len(t):
	for i in let:
		if s.count(i) != t.count(i):
			array = 0
else:
	array = 0
if array:
	print('array')
	exit()
f = s
i = 0
while i < min(len(t), len(f)):
	if f[i] != t[i]:
		f = f[:i] + f[i + 1:]
	else:
		i += 1
if f[:len(t)] == t:
	print('automaton')
	exit()
for i in let:
	if s.count(i) < t.count(i):
		both = 0
if both:
	print('both')
	exit()
print('need tree')


s = input()
t = input()
(ls, lt) = (len(s), len(t))
if lt <= ls:
	count = 0
	for i in range(ls):
		if count >= lt:
			break
		elif s[i] == t[count]:
			count += 1
	if count == lt:
		print('automaton')
	else:
		(ds, dt) = ({}, {})
		for i in s:
			if i in ds:
				ds[i] += 1
			else:
				ds[i] = 1
		for i in t:
			if i in dt:
				dt[i] += 1
			else:
				dt[i] = 1
		flag = 0
		spf = 0
		for i in dt:
			if i not in ds:
				flag = 1
				break
			elif ds[i] >= dt[i]:
				continue
			else:
				flag = 1
				break
		if flag == 1:
			print('need tree')
		elif ls == lt:
			print('array')
		else:
			print('both')
else:
	print('need tree')


from sys import *

def main():
	s = stdin.readline()
	t = stdin.readline()
	(sd, td) = ({}, {})
	for c in s:
		sd.setdefault(c, 0)
		sd[c] += 1
	for c in t:
		td.setdefault(c, 0)
		td[c] += 1
	ans = ''
	if len(s) == len(t) and td == sd:
		ans = 'array'
	else:
		check = 1
		for i in td:
			sd.setdefault(i, 0)
			if td[i] > sd[i]:
				check = 0
				break
		if check:
			pt = 0
			for c in s:
				if pt >= len(t):
					break
				if c == t[pt]:
					pt += 1
			if pt >= len(t):
				ans = 'automaton'
			else:
				ans = 'both'
		else:
			ans = 'need tree'
	print(ans)
main()


from collections import Counter
s = input()
t = input()

def is_subseq(t, s):
	it = iter(s)
	return all((c in it for c in t))
cs = sorted(Counter(s).most_common())
ct = sorted(Counter(t).most_common())
ces = sorted(Counter(s).elements())
cet = sorted(Counter(t).elements())
if len(s) > len(t) and is_subseq(t, s):
	print('automaton')
elif cs == ct:
	print('array')
elif is_subseq(cet, ces):
	print('both')
else:
	print('need tree')


word1 = input().strip()
word2 = input().strip()

def array(word1, word2):
	return ''.join(sorted(word1)) == ''.join(sorted(word2))

def automation(word1, word2):
	j = 0
	for i in range(len(word1)):
		if word1[i] == word2[j]:
			j += 1
		if j == len(word2):
			return True
	return False

def both(word1, word2):
	word1 = list(word1)
	for i in range(len(word2)):
		try:
			match = word1.index(word2[i])
		except:
			match = -1
			if match == -1:
				return False
		finally:
			word1[match] = '0'
	return True
if array(word1, word2):
	print('array')
elif automation(word1, word2):
	print('automaton')
elif both(word1, word2):
	print('both')
else:
	print('need tree')


s = input()
t = input()
(d1, d2) = ({}, {})
flag = 1
for ch in s:
	d1.setdefault(ch, 0)
	d1[ch] += 1
for ch in t:
	d2.setdefault(ch, 0)
	d2[ch] += 1
for e in d2:
	if e not in d1:
		flag = 0
		break
	elif d2[e] > d1[e]:
		flag = 0
		break
(i, j) = (0, 0)
while i < len(s) and j < len(t):
	if s[i] == t[j]:
		j += 1
	i += 1
if j == len(t):
	print('automaton')
elif len(s) == len(t) and flag == 1:
	print('array')
elif flag == 1:
	print('both')
else:
	print('need tree')


str1 = list(input())
str2 = list(input())
alp = 'abcdefghijklmnopqrstuvwxyz'
trav = dict()
for i in alp:
	trav[i] = False
for i in range(0, len(str2)):
	if trav[str2[i]] == False:
		if str1.count(str2[i]) < str2.count(str2[i]):
			print('need tree')
			exit(0)
		else:
			trav[str2[i]] = True
j = 0
for i in str1:
	if str2[j] == i:
		j += 1
	if j == len(str2):
		break
if len(str1) > len(str2) and j == len(str2):
	print('automaton')
elif len(str1) > len(str2) and j < len(str2):
	print('both')
else:
	print('array')


def automaton(s, t):
	(s, t) = (str(s), str(t))
	i = 0
	flag = True
	for e in t:
		if e in s[i:]:
			if i != s.index(e, i) or flag:
				flag = False
				i = s.index(e, i)
			elif e in s[i + 1:]:
				i = s.index(e, i + 1)
			else:
				return False
		else:
			return False
	return True

def need_tree(s, t):
	(s, t) = (str(s), str(t))
	(ds, dt) = ({}, {})
	for e in set(s):
		ds[e] = s.count(e)
	for e in set(t):
		dt[e] = t.count(e)
		if e not in ds or dt[e] > ds[e]:
			return True
	return False

def main():
	s = input()
	t = input()
	if need_tree(s, t):
		print('need tree')
	elif len(s) == len(t):
		print('array')
	elif automaton(s, t):
		print('automaton')
	else:
		print('both')
main()


s = input()
t = input()
dictS = {}
dictT = {}
for i in s:
	if i in dictS:
		dictS[i] += 1
	else:
		dictS[i] = 1
for i in t:
	if i in dictT:
		dictT[i] += 1
	else:
		dictT[i] = 1
if len(t) > len(s):
	print('need tree')
	exit(0)
for i in dictT.keys():
	if i in dictS:
		if dictT[i] > dictS[i]:
			print('need tree')
			exit(0)
	else:
		print('need tree')
		exit(0)
temp = ''
i = 0
j = 0
while i < len(t) and j < len(s):
	if t[i] == s[j]:
		temp += t[i]
		i += 1
		j += 1
	else:
		j += 1
if temp == t:
	print('automaton')
	exit(0)
elif len(t) == len(s):
	print('array')
	exit(0)
else:
	print('both')
	exit(0)


def substr(a, b):
	i = 0
	for x in a:
		if i < len(b) and x == b[i]:
			i += 1
	return i == len(b)
s = input()
t = input()
sa = sorted(s)
sb = sorted(t)
if sa == sb:
	print('array')
elif substr(s, t):
	print('automaton')
elif substr(sa, sb):
	print('both')
else:
	print('need tree')


def can_with_automaton(src, dst):
	sr = list(src)
	ds = list(dst)
	while ds and sr:
		if ds[-1] == sr[-1]:
			ds.pop()
		sr.pop()
	return bool(not ds)

def can_with_array(src, dst):
	return sorted(src) == sorted(dst)

def can_with_both(src, dst):
	for l in dst:
		if src.count(l) < dst.count(l):
			return False
	return True
s = input()
t = input()
if can_with_automaton(s, t):
	print('automaton')
elif can_with_array(s, t):
	print('array')
elif can_with_both(s, t):
	print('both')
else:
	print('need tree')


s = input()
t = input()

def is_subset(a, b):
	i = 0
	for letter in b:
		if letter == a[i]:
			i += 1
		if i == len(a):
			break
	return i == len(a)
if sorted(t) == sorted(s):
	print('array')
elif is_subset(t, s):
	print('automaton')
elif is_subset(sorted(t), sorted(s)):
	print('both')
else:
	print('need tree')


s = input().strip()
t = input().strip()
i = 0
j = 0
while i < len(s) and j < len(t):
	if t[j] != s[i]:
		i += 1
	else:
		i += 1
		j += 1
if j == len(t):
	print('automaton')
	exit()
c1 = [0] * 26
c2 = [0] * 26
for i in s:
	c1[ord(i) - ord('a')] += 1
for i in t:
	c2[ord(i) - ord('a')] += 1
boo = True
for i in range(26):
	if c1[i] > c2[i]:
		boo = False
	if c1[i] < c2[i]:
		print('need tree')
		exit()
if boo:
	print('array')
else:
	print('both')


import sys

def substring(s1, s2):
	s2copy = list(s2)
	s1copy = list(s1)
	for i in s1copy:
		try:
			s2copy.remove(i)
		except:
			return False
	return True

def sortedsubstring(s1, s2):
	if not substring(s1, s2):
		return False
	s2copy = s2[:]
	s1
	for i in s1:
		pos = s2copy.find(i)
		if pos == -1:
			return False
		s2copy = s2copy[pos + 1:]
	return True
words = sys.stdin.read().splitlines()
sorted0 = list(words[0])
sorted0.sort()
sorted1 = list(words[1])
sorted1.sort()
if not substring(words[1], words[0]):
	print('need tree')
elif sortedsubstring(words[1], words[0]):
	print('automaton')
elif sorted0 == sorted1:
	print('array')
else:
	print('both')


s = input()
t = input()

def isSubSequence(string1, string2, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if string1[m - 1] == string2[n - 1]:
		return isSubSequence(string1, string2, m - 1, n - 1)
	return isSubSequence(string1, string2, m, n - 1)

def cal(s, t):
	if isSubSequence(t, s, len(t), len(s)):
		return 'automaton'
	else:
		z = []
		c = 0
		for i in range(len(t)):
			if t[i] in z:
				continue
			if s.count(t[i]) < t.count(t[i]):
				c += 1
			z.append(t[i])
		if c == 0 and len(s) == len(t):
			return 'array'
		elif c == 0 and len(s) != len(t):
			return 'both'
		return 'need tree'
print(cal(s, t))


def solve(s, t):
	s1 = list(s)
	for c in t:
		try:
			s1.remove(c)
		except ValueError:
			return 'need tree'
	if len(s1) == 0:
		return 'array'
	(i, j) = (0, 0)
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			j += 1
		i += 1
	if j == len(t):
		return 'automaton'
	else:
		return 'both'
res = solve(input(), input())
print(res)


s = input()
t = input()

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
if isSubSequence(t, s):
	print('automaton')
elif sorted(s) == sorted(t):
	print('array')
elif isSubSequence(sorted(t), sorted(s)):
	print('both')
else:
	print('need tree')


s = input()
t = input()
cnt = [0] * 257
avail = 0
j = 0
for i in range(len(s)):
	if t[j] == s[i]:
		j += 1
	if j == len(t):
		print('automaton')
		exit()
for i in range(len(s)):
	if cnt[ord(s[i])] == 0:
		avail += 1
	cnt[ord(s[i])] += 1
for i in range(len(t)):
	cnt[ord(t[i])] -= 1
	if cnt[ord(t[i])] == 0:
		avail -= 1
	if cnt[ord(t[i])] < 0:
		print('need tree')
		exit()
if avail > 0:
	print('both')
if avail == 0:
	if len(s) == len(t):
		print('array')


n = input()
b = input()
if len(n) < len(b):
	print('need tree')
elif len(n) > len(b):
	if b in n:
		print('automaton')
	else:
		f = 0
		c = list(set(b))
		count = 0
		e = 0
		s = '' + n
		while len(s) > 0:
			if b[e] in s:
				d = s.index(b[e])
				e += 1
				s = s[d + 1:] + ''
				count += 1
			else:
				break
			if count == len(b):
				break
		if count == len(b):
			print('automaton')
		else:
			for i in range(len(c)):
				d = n.count(c[i])
				e = b.count(c[i])
				if d >= e and e != 0:
					continue
				else:
					f = 1
					break
			if f == 1:
				print('need tree')
			else:
				print('both')
elif len(n) == len(b):
	f = 0
	c = list(set(b))
	for i in range(len(c)):
		d = n.count(c[i])
		e = b.count(c[i])
		if d >= e and e != 0:
			continue
		else:
			f = 1
			break
	if f == 1:
		print('need tree')
	else:
		print('array')


def main():
	s1 = input()
	s2 = input()
	ans = []
	(p1, p2, n1, n2) = (0, 0, len(s1), len(s2))
	while p1 < n1 and p2 < n2:
		if s1[p1] == s2[p2]:
			ans.append(s1[p1])
			p1 += 1
			p2 += 1
		else:
			p1 += 1
	ans = ''.join(ans)
	if ans == s2 and n2 < n1:
		return 'automaton'
	f1 = [0] * 26
	f2 = [0] * 26
	for i in s1:
		f1[ord(i) - ord('a')] += 1
	for i in s2:
		f2[ord(i) - ord('a')] += 1
	array = True
	for i in range(26):
		if f1[i] < f2[i]:
			array = False
			break
	if array and n1 == n2:
		return 'array'
	elif array and n1 > n2:
		return 'both'
	else:
		return 'need tree'
print(main())


def isSubSequence(string1, string2, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if string1[m - 1] == string2[n - 1]:
		return isSubSequence(string1, string2, m - 1, n - 1)
	return isSubSequence(string1, string2, m, n - 1)
s = input()
t = input()
if t in s or isSubSequence(t, s, len(t), len(s)):
	print('automaton')
else:
	dic1 = {}
	dic2 = {}
	S = list(s)
	T = list(t)
	flag = 0
	for x in S:
		dic1[x] = S.count(x)
	for y in T:
		dic2[y] = T.count(y)
	for z in dic2.keys():
		if z in S:
			if dic2[z] == dic1[z] and len(S) == len(T):
				flag = 2
			elif dic2[z] <= dic1[z]:
				flag = 0
			elif dic2[z] > dic1[z]:
				flag = 1
				break
		else:
			flag = 1
			break
	if flag == 0:
		print('both')
	if flag == 2:
		print('array')
	if flag == 3:
		print('automaton')
	if flag == 1:
		print('need' + ' ' + 'tree')


import sys
a = input()
b = input()
j = 0
for i in a:
	if i == b[j]:
		j += 1
	if j == len(b):
		break
if j == len(b):
	print('automaton')
	sys.exit()
num = [0] * 42
for i in a:
	num[ord(i) - ord('a')] += 1
for i in b:
	num[ord(i) - ord('a')] -= 1
for i in num:
	if i < 0:
		print('need tree')
		sys.exit()
if sum(num) > 0:
	print('both')
else:
	print('array')


from collections import Counter

def check(a, b):
	n = len(b)
	i = 0
	for c in a:
		if c == b[i]:
			i += 1
			if i == n:
				return True
	return False
a = input()
b = input()
if sorted(a) == sorted(b):
	print('array')
	exit(0)
if check(a, b):
	print('automaton')
	exit(0)
ca = Counter(a)
cb = Counter(b)
for (x, y) in ca.items():
	if y < cb[x]:
		print('need tree')
		exit(0)
for (x, y) in cb.items():
	if y > ca[x]:
		print('need tree')
		exit(0)
print('both')


d = {chr(ord('a') + i): 0 for i in range(26)}
d2 = {chr(ord('a') + i): 0 for i in range(26)}
s = input()
t = input()
for ch in s:
	d[ch] += 1
for ch in t:
	d2[ch] += 1
fl1 = fl2 = False
for ch in d.keys():
	if d[ch] > d2[ch]:
		fl1 = True
	if d[ch] < d2[ch]:
		fl2 = True
if not fl1 and (not fl2):
	print('array')
elif fl2:
	print('need tree')
else:
	i1 = 0
	i2 = 0
	for i1 in range(len(s)):
		if i2 == len(t):
			break
		if s[i1] == t[i2]:
			i2 += 1
	if i2 == len(t):
		print('automaton')
	else:
		print('both')


def array(a, b):
	aArray = list(a)
	bArray = list(b)
	aArray.sort()
	bArray.sort()
	aNew = ''.join(aArray)
	bNew = ''.join(bArray)
	return aNew == bNew

def automaton(a, b):
	aArray = list(a)
	bArray = list(b)
	la = len(a)
	lb = len(b)
	n = 0
	i = 0
	while i < la and n < lb:
		n += aArray[i] == bArray[n]
		i += 1
	return n == lb

def both(a, b):
	aArray = list(a)
	bArray = list(b)
	n = len(b)
	for i in range(n):
		if aArray.__contains__(bArray[i]):
			p = aArray.index(bArray[i])
			aArray[p] = '0'
		else:
			return False
	return True
s = input()
t = input()
if array(s, t):
	print('array')
elif automaton(s, t):
	print('automaton')
elif both(s, t):
	print('both')
else:
	print('need tree')


from collections import Counter
import re
s = input()
t = input()
a = Counter(s)
b = Counter(t)
flag = -1
for key in b:
	if b[key] > a[key]:
		flag = 1
		break
if flag == 1:
	print('need tree')
else:
	flag2 = -1
	for key in a:
		if b[key] < a[key]:
			flag2 = 1
	flag3 = -1
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			j += 1
		i += 1
	if j != len(t):
		flag3 = 1
	if flag2 == 1 and flag3 == 1:
		print('both')
	elif flag2 == 1:
		print('automaton')
	elif flag3 == 1:
		print('array')


s = input()
t = input()
dicts = {}
for i in s:
	if i not in dicts:
		dicts[i] = 1
	else:
		dicts[i] += 1
flag = 0
dicts1 = {}
notinarr = [0 for _ in range(len(s))]
for i in t:
	if i not in dicts1:
		dicts1[i] = 1
	else:
		dicts1[i] += 1
slen = len(s)
tlen = len(t)
for (k, v) in dicts1.items():
	if k not in dicts:
		flag = 1
		break
	if v > dicts[k]:
		flag = 1
		break
if len(s) < len(t):
	flag = 1
if flag == 1:
	print('need tree')
elif len(dicts1) == len(dicts) and slen == tlen:
	print('array')
elif t in s:
	print('automaton')
else:
	flag = 0
	slen = len(s)
	tlen = len(t)
	prev = 0
	for i in range(tlen):
		flag = 0
		for j in range(prev, slen):
			if t[i] == s[j]:
				flag = 1
				prev = j + 1
				break
		if flag == 0:
			break
	if flag == 0:
		print('both')
	else:
		print('automaton')


def convert(ch):
	return ord(ch) - ord('a')

def solve():
	s = input()
	t = input()
	n = len(s)
	m = len(t)
	cnt1 = [0] * 26
	cnt2 = [0] * 26
	for i in range(n):
		cnt1[convert(s[i])] += 1
	for i in range(m):
		cnt2[convert(t[i])] += 1
	for i in range(m):
		if cnt1[convert(t[i])] < cnt2[convert(t[i])]:
			print('need tree')
			return
	if s != t and n == m:
		print('array')
		return
	i = j = 0
	while i < n and j < m:
		if s[i] == t[j]:
			j += 1
		i += 1
	if j == m:
		print('automaton')
		return
	print('both')
solve()


a = input()
b = input()

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
c = a
s = 0
for i in b:
	if i not in c:
		s = -1
		break
	else:
		d = c.index(i)
		c = c[:d] + c[d + 1:]
if s == -1:
	print('need tree')
elif len(b) > len(a):
	print('need tree')
elif len(b) == len(a):
	print('array')
elif isSubSequence(b, a):
	print('automaton')
else:
	print('both')


def read(mode=2):
	inputs = input().strip()
	if mode == 0:
		return inputs
	if mode == 1:
		return inputs.split()
	if mode == 2:
		return [int(x) for x in inputs.split()]

def write(s='\n'):
	if isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='')
s = read(0)
t = read(0)
resstr = ['need tree', 'automaton', 'array', 'both']
res = -1
ars = [0] * 26
art = [0] * 26
for i in list(s):
	ars[ord(i) - 97] += 1
for i in list(t):
	art[ord(i) - 97] += 1
for i in range(26):
	if art[i] > ars[i]:
		res = 0
		break
if not res + 1:
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			j += 1
		i += 1
	if j == len(t):
		res = 0
	else:
		res = 2
	if ars != art:
		res += 1
print(resstr[res])


s = input()
t = input()
from collections import Counter
if len(s) < len(t):
	print('need tree')
	exit()
try:
	j = 0
	for i in t:
		j += s[j:].index(i) + 1
	print('automaton')
except:
	a = Counter(t)
	b = Counter(s)
	if a == b:
		print('array')
	else:
		for q in a:
			if a[q] > b[q]:
				print('need tree')
				exit()
		print('both')


MAX_CHAR = 256

def isPresent(s, q):
	freq = [0] * MAX_CHAR
	for i in range(0, len(s)):
		freq[ord(s[i])] += 1
	for i in range(0, len(q)):
		freq[ord(q[i])] -= 1
		if freq[ord(q[i])] < 0:
			return False
	return True

def isSubSequence(string1, string2, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if string1[m - 1] == string2[n - 1]:
		return isSubSequence(string1, string2, m - 1, n - 1)
	return isSubSequence(string1, string2, m, n - 1)
a = input()
b = input()
if isPresent(a, b):
	if isSubSequence(b, a, len(b), len(a)):
		print('automaton')
	elif len(a) > len(b):
		print('both')
	else:
		print('array')
else:
	print('need tree')


def issub(x, y):
	index = 0
	for counter in x:
		if index < len(y) and counter == y[index]:
			index += 1
	return index == len(y)
s = input()
t = input()
ss = sorted(s)
st = sorted(t)
if ss == st:
	print('array')
elif issub(s, t):
	print('automaton')
elif issub(ss, st):
	print('both')
else:
	print('need tree')


from collections import Counter
s = input()
t = input()
k = 0
ii = 0
jj = 0
while 1:
	if t[ii] == s[jj]:
		ii += 1
		jj += 1
	else:
		jj += 1
	if ii == len(t) or jj == len(s):
		break
if ii == len(t):
	print('automaton')
else:
	xt = Counter(t)
	xs = Counter(s)
	p = 1
	c = 1
	for i in xt:
		if i not in xs:
			c = 0
			break
		if xs[i] < xt[i]:
			p = 0
			break
	if c == 0:
		print('need tree')
	elif p:
		if len(s) == len(t):
			print('array')
		else:
			print('both')
	else:
		print('need tree')


import sys
s1 = input()
s2 = input()
mp1 = {}
mp2 = {}
for c in s1:
	if c in mp1:
		mp1[c] += 1
	else:
		mp1[c] = 1
for c in s2:
	if c in mp2:
		mp2[c] += 1
	else:
		mp2[c] = 1
isDel = False
for c in mp2:
	if not c in mp1 or int(mp2[c]) > int(mp1[c]):
		print('need tree')
		sys.exit()
	elif mp2[c] < mp1[c]:
		isDel = True
if len(mp1) > len(mp2):
	isDel = True
isSwap = False
i = 0
for c in s2:
	i = s1.find(c, i)
	if i == -1:
		isSwap = True
		break
	else:
		i += 1
if isSwap and isDel:
	print('both')
elif isSwap:
	print('array')
elif isDel:
	print('automaton')


s1 = input()
s2 = input()
if len(s1) != len(s2):
	a = sorted(list(s1))
	b = sorted(list(s2))
	automation = False
	(i, j) = (0, 0)
	while i < len(a) and j < len(b):
		if a[i] == b[j]:
			j += 1
		i += 1
	if j == len(b):
		automation = True
	if automation:
		array = True
		(i, j) = (0, 0)
		while i < len(s1) and j < len(s2):
			if s1[i] == s2[j]:
				j += 1
			i += 1
		if j == len(s2):
			array = False
		if array:
			print('both')
		else:
			print('automaton')
	else:
		print('need tree')
elif sorted(list(s1)) == sorted(list(s2)):
	print('array')
else:
	print('need tree')


def check_solution(_s, _t):
	is_array = False
	s_map = [0] * 26
	t_map = [0] * 26
	s_length = len(_s)
	t_length = len(_t)
	for i in range(s_length):
		s_map[ord(_s[i]) - 97] += 1
	for i in range(t_length):
		t_map[ord(_t[i]) - 97] += 1
	for i in range(26):
		if s_map[i] < t_map[i]:
			return 'need tree'
	if s_length == t_length:
		return 'array'
	s_left = 0
	t_left = 0
	while True:
		if s_left >= s_length or t_left >= t_length:
			break
		if _s[s_left] != _t[t_left]:
			s_left += 1
		else:
			s_left += 1
			t_left += 1
		if s_length - s_left < t_length - t_left:
			is_array = True
			break
	if is_array:
		return 'both'
	return 'automaton'
s = input()
t = input()
print(check_solution(s, t))


s = list(input())
t = list(input())
pos = 0
for i in range(len(s)):
	if s[i] == t[pos]:
		pos += 1
		if pos == len(t):
			break
if pos == len(t):
	print('automaton')
else:
	import collections
	a = collections.Counter(s)
	b = collections.Counter(t)
	ans = 'array'
	used = 0
	for i in b:
		if i in a:
			if b[i] > a[i]:
				ans = 'need tree'
				break
			elif b[i] < a[i]:
				ans = 'both'
			else:
				used += 1
		else:
			ans = 'need tree'
			break
	if ans == 'array' and used != len(a):
		ans = 'both'
	print(ans)


s = input()
t = input()
(n1, n2) = (len(s), len(t))
f = 0
(s1, s2) = (set(), set())
for a in s:
	s1.add(a)
for a in t:
	s2.add(a)
for i in s2:
	if t.count(i) > s.count(i):
		f = 1
		break
if f:
	print('need tree')
else:
	f = 0
	ctr = t[0]
	ctr1 = 0
	for i in range(n1):
		if s[i] == ctr:
			ctr1 += 1
			if ctr1 < n2:
				ctr = t[ctr1]
		if ctr1 == n2:
			f = 1
			break
	if f:
		print('automaton')
	elif len(t) == len(s):
		print('array')
	else:
		print('both')


from collections import Counter, defaultdict, deque
from math import factorial as fact

def primes(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors

def issubseq(s, t):
	if len(t) > len(s):
		return False
	lt = len(t)
	p = 0
	for el in s:
		if el == t[p]:
			p += 1
		if p == lt:
			return True
	return False
s = input()
t = input()
c1 = Counter(s)
c2 = Counter(t)
allc = Counter(s + t)
arr = True
if issubseq(s, t):
	print('automaton')
	exit()
if len(c1) < len(c2):
	print('need tree')
	exit()
else:
	for el in allc:
		if c2[el] > c1[el]:
			print('need tree')
			exit()
		if c1[el] > c2[el]:
			arr = False
if arr:
	print('array')
else:
	print('both')


from collections import defaultdict
s = input()
t = input()
s = list(s)
t = list(t)
s_freq = defaultdict(int)
t_freq = defaultdict(int)
for i in range(len(s)):
	s_freq[s[i]] += 1
for i in range(len(t)):
	t_freq[t[i]] += 1
letters = 0
for i in t_freq:
	if i not in s_freq:
		letters = 1
	elif i in s_freq and s_freq[i] < t_freq[i]:
		letters = 1
if letters == 1:
	print('need tree')
else:
	j = 0
	for i in range(len(s)):
		if s[i] == t[j]:
			j += 1
			if j == len(t):
				break
	if j == len(t):
		print('automaton')
	elif len(s) == len(t) and letters == 0:
		print('array')
	else:
		print('both')


s = input()
t = input()
if len(s) < len(t):
	print('need tree')
elif len(s) == len(t):
	a = dict()
	b = dict()
	for i in range(len(s)):
		if s[i] not in a:
			a.update({s[i]: s.count(s[i])})
	for i in range(len(t)):
		if t[i] not in b:
			b.update({t[i]: t.count(t[i])})
	if len(a) != len(b):
		print('need tree')
	else:
		x = 0
		for i in a:
			if i in b:
				if a[i] != b[i]:
					x = 1
					break
			else:
				x = 1
				break
		if x:
			print('need tree')
		else:
			print('array')
else:
	j = h = 0
	for i in range(len(t)):
		while j < len(s):
			if s[j] == t[i]:
				h += 1
				break
			j += 1
		j += 1
	if h == len(t):
		print('automaton')
	else:
		a = dict()
		b = dict()
		for i in range(len(s)):
			if s[i] not in a:
				a.update({s[i]: s.count(s[i])})
		for i in range(len(t)):
			if t[i] not in b:
				b.update({t[i]: t.count(t[i])})
		x = 0
		for i in b:
			if i in a:
				if a[i] < b[i]:
					x = 1
					break
			else:
				x = 1
				break
		if x:
			print('need tree')
		else:
			print('both')


def both_check(s, t):
	import collections
	s_letters = dict(collections.Counter(s))
	t_letters = dict(collections.Counter(t))
	t_keys = t_letters.keys()
	try:
		for c in t_keys:
			if s_letters[c] < t_letters[c]:
				return False
	except Exception:
		return False
	return True

def isSubSequence(string1, string2, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if string1[m - 1] == string2[n - 1]:
		return isSubSequence(string1, string2, m - 1, n - 1)
	return isSubSequence(string1, string2, m, n - 1)
s = str(input())
t = str(input())
if isSubSequence(t, s, len(t), len(s)):
	print('automaton')
elif sorted(s) == sorted(t):
	print('array')
elif both_check(s, t):
	print('both')
else:
	print('need tree')


s = input()
t = input()
ind = 0
for x in t:
	ind = s.find(x, ind) + 1
	if ind <= 0:
		break
if ind > 0 or len(t) == 0:
	print('automaton')
else:
	ss = list(s)
	tt = list(t)
	bb1 = True
	if len(ss) >= len(tt):
		for x in tt:
			bb = False
			for y in ss:
				if y == x:
					ss.remove(y)
					bb = True
					break
			if not bb:
				bb1 = False
				break
		if bb1:
			if len(s) > len(t):
				print('both')
			else:
				print('array')
		else:
			print('need tree')
	else:
		print('need tree')


def is_subsequence(x, y):
	x = list(x)
	for letter in y:
		if x and x[0] == letter:
			x.pop(0)
	return not x
s = str(input())
t = str(input())
if len(s) != len(t):
	if is_subsequence(t, s):
		print('automaton')
	else:
		check = ''.join(sorted(s))
		check2 = ''.join(sorted(t))
		if is_subsequence(check2, check):
			print('both')
		else:
			print('need tree')
else:
	check = ''.join(sorted(s))
	check2 = ''.join(sorted(t))
	if check2 in check:
		print('array')
	else:
		print('need tree')


s = input()
t = input()
if len(t) > len(s):
	print('need tree')
else:
	j = 0
	cnt = 0
	for i in t:
		while j < len(s):
			if i == s[j]:
				cnt += 1
				j += 1
				break
			j += 1
	if cnt == len(t):
		print('automaton')
		exit()
	l = list(t)
	for i in s:
		if i in l:
			l.remove(i)
	if l:
		print('need tree')
	elif len(s) == len(t):
		print('array')
	else:
		print('both')


def automaton_solvable(s, t):
	i = -1
	for ch in t:
		i = s.find(ch, i + 1)
		if i < 0:
			return False
	return True
(s, t) = (input(), input())
if automaton_solvable(s, t):
	print('automaton')
else:
	(s, t) = (''.join(sorted(s)), ''.join(sorted(t)))
	print((('need tree', 'both')[automaton_solvable(s, t)], 'array')[s == t])


s = input()
t = input()
np = 0
for c in s:
	if np < len(t) and c == t[np]:
		np += 1
if np == len(t):
	print('automaton')
else:
	ds = {}
	dt = {}
	for c in s:
		if c not in ds:
			ds[c] = 0
		ds[c] += 1
	for c in t:
		if c not in dt:
			dt[c] = 0
		dt[c] += 1
	flag = True
	for c in dt:
		if c not in ds or dt[c] > ds[c]:
			flag = False
	if flag:
		if len(s) == len(t):
			print('array')
		else:
			print('both')
	else:
		print('need tree')


def ss(s, t):
	j = 0
	for i in s:
		if t[j] == i:
			j += 1
		if j == len(t):
			return True
s = input()
t = input()
d1 = sorted(s)
d2 = sorted(t)
if d1 == d2:
	print('array')
elif ss(s, t):
	print('automaton')
elif ss(d1, d2):
	print('both')
else:
	print('need tree')


def yes(listx, desired):
	if len(listx) != len(desired):
		return False
	for char in desired:
		if char in listx:
			listx.remove(char)
		else:
			return False
	return True

def inside(listx, listx2):
	for element in listx2:
		if element in listx:
			ind = listx.index(element)
			listx = listx[ind + 1:]
		else:
			return False
	return True
sa = input()
sa2 = input()
array = 0
auto = 0
saxx = []
saxx2 = []
for char in sa:
	saxx.append(char)
for char in sa2:
	saxx2.append(char)
if sa2 in sa:
	auto = 1
if inside(saxx, saxx2):
	print('automaton')
else:
	saxx.sort()
	saxx2.sort()
	if saxx == saxx2:
		print('array')
	elif inside(saxx, saxx2):
		print('both')
	else:
		print('need tree')


s = input()
t = input()
res = ''
temp = ''
arr_t = []
for i in t:
	if i not in arr_t:
		arr_t.append(i)
arr_s_cnt = len(arr_t) * [0]
arr_t_cnt = len(arr_t) * [0]
for i in range(len(arr_t)):
	for j in s:
		if j == arr_t[i]:
			arr_s_cnt[i] += 1
	for j in t:
		if j == arr_t[i]:
			arr_t_cnt[i] += 1
for i in range(len(arr_s_cnt)):
	if arr_s_cnt[i] < arr_t_cnt[i]:
		res = 'need tree'
		break
if res == '':
	if len(s) == len(t):
		res = 'array'
	elif len(s) > len(t):
		if t in s:
			res = 'automaton'
		else:
			x = 0
			for i in range(len(t)):
				for j in range(x, len(s)):
					if t[i] == s[j]:
						temp += s[j]
						x = j + 1
						break
			if temp == t:
				res = 'automaton'
			else:
				res = 'both'
print(res)


def main():
	s = input()
	t = input()
	i = 0
	for j in s:
		if j == t[i]:
			i += 1
			if i == len(t):
				print('automaton')
				return
	for i in range(26):
		c = chr(ord('a') + i)
		if s.count(c) < t.count(c):
			print('need tree')
			return
	if len(s) == len(t):
		print('array')
	else:
		print('both')
main()


def suffix_structure(s, t):
	j = 0
	for i in range(len(s)):
		if j == len(t):
			break
		if s[i] == t[j]:
			j += 1
	if j == len(t):
		result = 'automaton'
	else:
		sorted_s = sorted(s)
		sorted_t = sorted(t)
		if sorted_s == sorted_t:
			result = 'array'
		else:
			k = 0
			for i in range(len(sorted_s)):
				if k == len(sorted_t):
					break
				if sorted_s[i] == sorted_t[k]:
					k += 1
			if k == len(sorted_t):
				result = 'both'
			else:
				result = 'need tree'
	return result
s = input()
t = input()
print(suffix_structure(s, t))


import collections

def is_subsequence(a, b):
	i = 0
	for c in b:
		if c == a[i]:
			i += 1
			if i == len(a):
				return True
	return False
s = input()
t = input()
c1 = collections.Counter(s)
c2 = collections.Counter(t)
if len(s) == len(t):
	print('array' if c1 == c2 else 'need tree')
elif is_subsequence(t, s):
	print('automaton')
else:
	for (k, v) in c2.items():
		if c1[k] < v:
			print('need tree')
			break
	else:
		print('both')


s = input()
t = input()
if len(s) == len(t):
	x = list(s)
	y = list(t)
	x.sort()
	y.sort()
	n = len(s)
	ntree = False
	for i in range(n):
		if x[i] != y[i]:
			ntree = True
			break
	if ntree:
		print('need tree')
	else:
		print('array')
else:
	x = list(s)
	y = list(t)
	n = len(x)
	m = len(y)
	j = 0
	nboth = False
	for i in range(m):
		while j < n:
			if x[j] != y[i]:
				j += 1
			else:
				break
		if j == n:
			nboth = True
			break
		j += 1
	if not nboth:
		print('automaton')
	else:
		x.sort()
		y.sort()
		ntree = False
		j = 0
		for i in range(m):
			while j < n:
				if x[j] != y[i]:
					j += 1
				else:
					break
			if j == n:
				ntree = True
				break
			j += 1
		if not ntree:
			print('both')
		else:
			print('need tree')


from collections import Counter

def isAnAutomatonSolution(s, t):
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			j += 1
		i += 1
	return j == len(t)

def isAnArraySolution(s, t):
	count = Counter(s)
	for char in t:
		count[char] -= 1
	for val in count.values():
		if val != 0:
			return False
	return True

def isAnArrayAndAutomatonSolution(s, t):
	count = Counter(s)
	for char in t:
		count[char] -= 1
	for char in s:
		if count[char] != 0:
			count[char] -= 1
	for val in count.values():
		if val != 0:
			return False
	return True
s = input()
t = input()
if len(s) == len(t):
	if isAnArraySolution(s, t):
		print('array')
	else:
		print('need tree')
elif isAnAutomatonSolution(s, t):
	print('automaton')
elif isAnArrayAndAutomatonSolution(s, t):
	print('both')
else:
	print('need tree')


def needTree(s, t):
	if len(s) < len(t):
		return 'need tree'
	p = 0
	q = 0
	while p < len(s) and q < len(t):
		if s[p] == t[q]:
			p += 1
			q += 1
		else:
			p += 1
	if q == len(t):
		return 'automaton'
	d = {}
	for c in s:
		d[c] = d.get(c, 0) + 1
	for c in t:
		d[c] = d.get(c, 0) - 1
	flag_1 = True
	flag_2 = True
	for k in d:
		if d[k] < 0:
			flag_2 = False
		if d[k] > 0:
			flag_1 = False
	if flag_1 and flag_2:
		return 'array'
	if not flag_1 and (not flag_2):
		return 'need tree'
	return 'both'
s = input()
t = input()
print(needTree(s, t))


import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(' '))
from collections import Counter

def solve():
	s = list(input().replace('\n', ''))
	t = list(input().replace('\n', ''))
	if sorted(s) == sorted(t):
		return 'array'
	matched = 0
	curr_s = 0
	for char in t:
		match = False
		while not match and curr_s < len(s):
			if s[curr_s] == char:
				match = True
			curr_s += 1
		if match:
			matched += 1
	if matched == len(t):
		return 'automaton'
	s_cnt = dict(Counter(s))
	t_cnt = dict(Counter(t))
	both = True
	for (k, v) in t_cnt.items():
		if s_cnt.get(k, 0) < v:
			both = False
	if both:
		return 'both'
	else:
		return 'need tree'
print(solve())


def check(s, t):
	i = 0
	for j in s:
		if j == t[i]:
			i += 1
		if i == len(t):
			break
	return i == len(t)
s = input()
t = input()
s2 = str(sorted(s))
t2 = str(sorted(t))
if s2 == t2:
	print('array')
elif check(s, t):
	print('automaton')
elif check(s2, t2):
	print('both')
else:
	print('need tree')


from collections import Counter
import sys

def tree():
	print('need tree')
	sys.exit()

def automaton():
	print('automaton')
	sys.exit()

def array():
	print('array')
	sys.exit()

def both():
	print('both')
	sys.exit()

def onlyAutomaton(s, t):
	table = [[False] * (1 + len(t)) for _ in range(1 + len(s))]
	table[0][0] = True
	for i in range(1, 1 + len(s)):
		table[i][0] = True
		for j in range(1, 1 + len(t)):
			table[i][j] = table[i - 1][j] or (s[i - 1] == t[j - 1] and table[i - 1][j - 1])
	return table[-1][-1]

def main():
	s = input()
	t = input()
	if len(s) < len(t):
		tree()
	elif onlyAutomaton(s, t):
		automaton()
	else:
		sc = Counter(s)
		tc = Counter(t)
		arraySuffices = len(s) == len(t)
		for char in tc:
			if sc[char] < tc[char]:
				tree()
			elif sc[char] > tc[char]:
				arraySuffices = False
		if arraySuffices:
			array()
		else:
			both()
main()


s = input()
t = input()
a = [0] * 26
for c in s:
	a[ord(c) - ord('a')] += 1
b = [0] * 26
for c in t:
	b[ord(c) - ord('a')] += 1
if any((a[i] < b[i] for i in range(26))):
	print('need tree')
else:
	needAutomaton = len(s) > len(t)
	needArray = False
	j = 0
	for i in range(len(t)):
		k = s.find(t[i], j)
		if k < j:
			needArray = True
			break
		j = k + 1
	if needAutomaton and needArray:
		print('both')
	elif needAutomaton:
		print('automaton')
	else:
		print('array')


def main():
	s = input()
	t = input()
	lastindex = 0
	foundlist = []
	slist = list(s)
	tlist = list(t)
	for item in range(0, len(tlist)):
		if tlist[item] in slist:
			try:
				finddex = slist.index(tlist[item], lastindex)
			except:
				finddex = slist.index(tlist[item])
			foundlist.append(finddex)
			slist[finddex] = '1'
			lastindex = finddex
	if len(foundlist) == len(tlist):
		sorte = foundlist.copy()
		sorte = sorted(sorte)
		if foundlist != sorted and len(slist) == len(tlist):
			print('array')
		elif foundlist == sorte:
			print('automaton')
		else:
			print('both')
	else:
		print('need tree')
main()


ll = lambda : map(int, input().split())
t = lambda : int(input())
ss = lambda : input()
s = ss()
pt = ss()
ls = len(s)
lt = len(pt)
a = [0] * 27
b = [0] * 27
f = 1
ps = ''
j = 0
for i in s:
	a[ord(i) - ord('a')] += 1
	if j < lt and i == pt[j]:
		ps += i
		j += 1
for i in pt:
	b[ord(i) - ord('a')] += 1
for i in range(27):
	if a[i] and b[i] and (a[i] < b[i]) or (b[i] and (not a[i])):
		f = 0
if ls > lt:
	if f:
		if ps == pt:
			print('automaton')
		else:
			print('both')
	else:
		print('need tree')
elif ls == lt:
	if f:
		print('array')
	else:
		print('need tree')
else:
	print('need tree')


s1 = input()
s2 = input()

def is_subseq(x, y):
	it = iter(y)
	return all((c in it for c in x))
f1 = is_subseq(s2, s1)
s1 = ''.join(map(str, sorted(s1)))
s2 = ''.join(map(str, sorted(s2)))
f2 = is_subseq(s2, s1) and s1 != s2
f3 = False
if s1 == s2:
	f3 = True
if f1:
	print('automaton')
elif f2:
	print('both')
elif f3:
	print('array')
else:
	print('need tree')


from collections import Counter
s1 = input()
s2 = input()
if len(s2) > len(s1):
	print('need tree')
else:
	c1 = Counter(s1)
	c2 = Counter(s2)
	f = 1
	for i in c2.keys():
		if i not in c1.keys() or c1[i] < c2[i]:
			f = 0
			break
	check = 0
	for i in range(len(s1)):
		if check == len(s2):
			break
		if s1[i] == s2[check]:
			check += 1
	if f:
		if len(s1) == len(s2):
			print('array')
		elif check == len(s2):
			print('automaton')
		else:
			print('both')
	else:
		print('need tree')


s = str(input())
t = str(input())
u = list(s)
v = list(t)
u.sort()
v.sort()
a = [0] * 26
b = [0] * 26
for _ in range(len(s)):
	a[ord(s[_]) - ord('a')] += 1
for _ in range(len(t)):
	b[ord(t[_]) - ord('a')] += 1

def check():
	for _ in range(len(b)):
		if a[_] < b[_]:
			return False
	return True

def check1():
	i = 0
	for j in range(len(s)):
		if i >= len(t):
			break
		if s[j] == t[i]:
			i += 1
	if i == len(t):
		return True
	else:
		return False
if check1():
	print('automaton')
elif u == v:
	print('array')
elif check():
	print('both')
else:
	print('need tree')


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def isSubSequence(str1, str2):
	(m, n) = (len(str1), len(str2))
	i = j = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
s = [char for char in input()]
t = [char for char in input()]
s1 = sorted(list(set(s)))
t1 = sorted(list(set(t)))
d1 = {c: s.count(c) for c in s1}
d2 = {c: t.count(c) for c in t1}
if len(s) == len(t):
	if d1 == d2:
		print('array')
	else:
		print('need tree')
else:
	flag = 0
	for item in d2:
		if item not in d1 or d2[item] > d1[item]:
			flag = 1
			print('need tree')
			break
	if flag == 0:
		if isSubSequence(''.join(t), ''.join(s)):
			print('automaton')
		else:
			print('both')


s = input()
t = input()
from collections import Counter
c1 = Counter(s)
c2 = Counter(t)

def isok(s, t):
	n = len(s)
	m = len(t)
	c = 0
	i = 0
	j = 0
	while i < n and j < m:
		if s[i] == t[j]:
			i += 1
			j += 1
			c += 1
		else:
			i += 1
	return c == m
if isok(s, t):
	print('automaton')
	exit()
if Counter(s) == Counter(t):
	print('array')
	exit()
if all((c1[chr(i)] >= c2[chr(i)] for i in range(97, 123))):
	print('both')
	exit()
print('need tree')


def solve_suffix_structures(s, t):
	cnt_s = [0] * 26
	cnt_t = [0] * 26
	for ch in s:
		index = ord(ch) - ord('a')
		cnt_s[index] += 1
	for ch in t:
		index = ord(ch) - ord('a')
		cnt_t[index] += 1
	for i in range(26):
		if cnt_s[i] < cnt_t[i]:
			return 'need tree'
	if len(s) == len(t):
		return 'array'
	i = 0
	j = 0
	auto = True
	while j < len(t):
		if s[i] == t[j]:
			j += 1
		i += 1
		if i == len(s) and j < len(t):
			auto = False
			break
	if auto:
		return 'automaton'
	return 'both'
s = input()
t = input()
print(solve_suffix_structures(s, t))


import sys
txt1 = input()
txt2 = input()
mem1 = dict()
mem2 = dict()
flag_auto = False

def piece_search(txt1, txt2):
	l = 0
	count = 0
	for item in txt2:
		while l < len(txt1):
			if item != txt1[l]:
				l += 1
			else:
				count += 1
				l += 1
				break
	if count != len(txt2):
		return False
	else:
		return True
if piece_search(txt1, txt2):
	print('automaton')
	sys.exit()
for item in txt1:
	if item not in mem1:
		mem1[item] = 1
	else:
		mem1[item] += 1
for item in txt2:
	if item not in mem2:
		mem2[item] = 1
	else:
		mem2[item] += 1
if len(txt1) != len(txt2):
	flag_auto = True
for item in mem2:
	try:
		if mem2[item] > mem1[item]:
			print('need tree')
			sys.exit()
	except KeyError:
		print('need tree')
		sys.exit()
if not flag_auto:
	print('array')
else:
	print('both')


s = input()
t = input()
cnt = [0] * 123
for c in t:
	cnt[ord(c)] += 1
for c in s:
	if cnt[ord(c)] > 0:
		cnt[ord(c)] -= 1
flag = True
for c in t:
	if cnt[ord(c)] > 0:
		flag = False
if flag and len(s) == len(t):
	print('array')
elif flag:
	i = 0
	count = 0
	for x in t:
		while i < len(s):
			if s[i] == x:
				count += 1
				i += 1
				break
			i += 1
	if count == len(t):
		print('automaton')
	else:
		print('both')
else:
	print('need tree')


s = input()
t = input()
flag1 = 0
flag2 = 0
flag3 = 0
for i in range(0, 26):
	if t.count(chr(97 + i)) > s.count(chr(97 + i)):
		flag3 = 1
		break
	if s.count(chr(97 + i)) > t.count(chr(97 + i)):
		flag2 = 1
x = 0
for i in range(0, len(t)):
	if t[i] not in s[x:]:
		flag1 = 1
		break
	else:
		x = x + s[x:].index(t[i]) + 1
if flag3 == 1:
	print('need tree')
elif flag1 == 1 and flag2 == 1:
	print('both')
elif flag1 == 1:
	print('array')
else:
	print('automaton')


def is_subsequence(child, parent, i, j, c):
	if i >= len(child) or j >= len(parent):
		return c
	if child[i] == parent[j]:
		return is_subsequence(child, parent, i + 1, j + 1, c + 1)
	else:
		return is_subsequence(child, parent, i, j + 1, c)
s = [c for c in input()]
t = [c for c in input()]
copy_s = [c for c in s]
copy_t = [c for c in t]
if len(s) < len(t):
	print('need tree')
	exit()
for c in t:
	if c not in s:
		print('need tree')
		exit()
	else:
		s.remove(c)
if len(s) == 0:
	print('array')
else:
	k = is_subsequence(copy_t, copy_s, 0, 0, 0)
	if k == len(copy_t):
		print('automaton')
	else:
		print('both')


s = input()
t = input()
a = list(s)
b = list(t)
j = 0
for i in range(len(b)):
	while j < len(a) and a[j] != b[i]:
		j += 1
	if j == len(a):
		break
	j += 1
else:
	print('automaton')
	exit()
num = [0] * 26
for x in a:
	num[ord(x) - ord('a')] += 1
for x in b:
	num[ord(x) - ord('a')] -= 1
if num == [0] * 26:
	print('array')
	exit()
for x in num:
	if x < 0:
		print('need tree')
		break
else:
	print('both')


s = input()
t = input()
(a, b) = ([0] * 26, [0] * 26)
(len_s, len_t) = (len(s), len(t))
for i in range(len_s):
	a[ord(s[i]) - 97] += 1
for i in range(len_t):
	b[ord(t[i]) - 97] += 1
remove = False
swap = False
need_tree = False
cnt = 0
for i in range(26):
	(x, y) = (a[i], b[i])
	if y > x:
		need_tree = True
check = s.find(t)
if check != -1:
	print('automaton')
elif need_tree == True:
	print('need tree')
else:
	j = 0
	for i in range(len_t):
		while j < len_s:
			if s[j] != t[i]:
				j += 1
			else:
				break
		if j == len_s:
			if len_s == len_t:
				print('array')
			else:
				print('both')
			exit()
		j += 1
	print('automaton')


def process():
	for i in t:
		cnt[ord(i) - ord('a')] -= 1
		if cnt[ord(i) - ord('a')] < 0:
			return 'need tree'
	if len(s) == len(t):
		return 'array'
	(i, j) = (0, 0)
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			i += 1
	if j == len(t):
		return 'automaton'
	else:
		return 'both'
s = input()
t = input()
cnt = [0] * 26
for i in s:
	cnt[ord(i) - ord('a')] += 1
print(process())


def isSubSequence(string1, string2, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if string1[m - 1] == string2[n - 1]:
		return isSubSequence(string1, string2, m - 1, n - 1)
	return isSubSequence(string1, string2, m, n - 1)
s1 = input()
s2 = input()
flag1 = 0
flag2 = 0
flag3 = 0
if isSubSequence(s2, s1, len(s2), len(s1)):
	flag3 = 1
for c in s2:
	if s2.count(c) > s1.count(c):
		flag2 = 1
for c in s1:
	if s2.count(c) != s1.count(c):
		flag1 = 1
if flag2 == 1:
	print('need tree')
elif flag1 == 1 and flag3 == 1:
	print('automaton')
elif flag1 == 0 and flag3 == 0:
	print('array')
else:
	print('both')


import itertools
import math
from collections import defaultdict

def input_ints():
	return list(map(int, input().split()))

def solve():
	s = input()
	t = input()
	if sorted(s) == sorted(t):
		print('array')
	elif t in s:
		print('automaton')
	else:
		i = 0
		for c in s:
			if c == t[i]:
				i += 1
				if i == len(t):
					break
		if i == len(t):
			print('automaton')
		else:
			f = True
			for c in 'abcdefghijklmnopqrstuvwxyz':
				if t.count(c) > s.count(c):
					f = False
			if f:
				print('both')
			else:
				print('need tree')
solve()


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
from math import ceil
s = input()
t = input()
(a, b) = (sorted(s), sorted(t))

def substr(s, t):
	i = j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			j += 1
			i += 1
		else:
			i += 1
	return j == len(t)
if substr(s, t):
	print('automaton')
elif a == b:
	print('array')
elif substr(a, b):
	print('both')
else:
	print('need tree')


def isAnagram(s, t):
	return sorted(s) == sorted(t)

def isSubseq(s, x):
	(i, j) = (0, 0)
	while True:
		if j == len(x):
			return True
		if i == len(s):
			return False
		if s[i] == x[j]:
			j += 1
		i += 1
s = input().strip()
t = input().strip()
if isAnagram(s, t):
	exit(print('array'))
if isSubseq(s, t):
	exit(print('automaton'))
(fs, ft) = ([0] * 26, [0] * 26)
for i in s:
	fs[ord(i) - ord('a')] += 1
for i in t:
	ft[ord(i) - ord('a')] += 1
for (i, j) in zip(fs, ft):
	if i < j:
		exit(print('need tree'))
print('both')


SIZE = 26
(s1, s2) = (input(), input())

def automat():
	j = 0
	for val in s2:
		while j < len(s1) and val != s1[j]:
			j += 1
		if j == len(s1):
			return False
		j += 1
	return True

def suffix_array():
	arr1 = [0] * SIZE
	arr2 = [0] * SIZE
	for i in s1:
		arr1[ord(i) - ord('a')] += 1
	for i in s2:
		arr2[ord(i) - ord('a')] += 1
	for i in range(26):
		if arr1[i] != arr2[i]:
			return False
	return True

def both():
	arr1 = [0] * SIZE
	arr2 = [0] * SIZE
	for i in s1:
		arr1[ord(i) - ord('a')] += 1
	for i in s2:
		arr2[ord(i) - ord('a')] += 1
	for i in range(26):
		if arr1[i] < arr2[i]:
			return False
	return True
if automat():
	print('automaton')
elif suffix_array():
	print('array')
elif both():
	print('both')
else:
	print('need tree')


(s, t) = (input(), input())
if sorted(t) == sorted(s):
	print('array')
else:
	i = 0
	f = 0
	for c in s:
		if c == t[i]:
			i += 1
		if i == len(t):
			print('automaton')
			f = 1
			break
	if f == 0:
		i = 0
		s1 = sorted(s)
		t1 = sorted(t)
		for c in s1:
			if c == t1[i]:
				i += 1
			if i == len(t1):
				print('both')
				f = 1
				break
		if f == 0:
			print('need tree')


from string import ascii_lowercase

def subsequence(t, s):
	n = len(s)
	m = len(t)
	i = 0
	j = 0
	while n and m:
		if s[i] == t[j]:
			j += 1
			m -= 1
		i += 1
		n -= 1
	if n == 0 and m > 0:
		return False
	return True

def main():
	s = input()
	t = input()
	s_count = dict.fromkeys(ascii_lowercase, 0)
	t_count = dict.fromkeys(ascii_lowercase, 0)
	for i in s:
		s_count[i] += 1
	for i in t:
		t_count[i] += 1
	tree = False
	automaton = False
	for i in ascii_lowercase:
		if s_count[i] < t_count[i]:
			tree = True
			break
		if s_count[i] > t_count[i]:
			automaton = True
	if tree:
		print('need tree')
	elif automaton:
		if subsequence(t, s):
			print('automaton')
		else:
			print('both')
	else:
		print('array')
main()


def check_subsequence():
	(n, m) = (len(s), len(t))
	(i, j) = (0, 0)
	while i < n and j < m:
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			i += 1
	if j != m:
		return False
	return True
s = input()
t = input()
flag = False
if len(s) < len(t):
	print('need tree')
else:
	for i in t:
		if t.count(i) > s.count(i):
			flag = True
			print('need tree')
			break
	if not flag:
		if not check_subsequence():
			if len(s) > len(t):
				print('both')
			else:
				print('array')
		elif check_subsequence():
			print('automaton')
		else:
			print('need tree')


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))

def count_chars(s):
	co = [0] * 26
	for c in s:
		co[ord(c) - ord('a')] += 1
	return co
s = input()
t = input()
sc = count_chars(s)
tc = count_chars(t)
if all((sci == tci for (sci, tci) in zip(sc, tc))):
	print('array')
elif any((tci > sci for (sci, tci) in zip(sc, tc))):
	print('need tree')
else:
	i = 0
	for c in t:
		while i < len(s) and s[i] != c:
			i += 1
		i += 1
	if i <= len(s):
		print('automaton')
	else:
		print('both')


import collections

def is_subsequence(s, t):
	(n, m) = (len(s), len(t))
	(i, j) = (0, 0)
	while i < n and j < m:
		if s[i] == t[j]:
			j += 1
		i += 1
	return j == m

def solve(s, t):
	n = len(s)
	m = len(t)
	freqt = collections.defaultdict(int)
	for c in t:
		freqt[c] += 1
	freqs = collections.defaultdict(int)
	if n < m:
		return 'need tree'
	for c in s:
		if c in t:
			freqs[c] += 1
	if all((freqs[c] >= freqt[c] for c in t)):
		if n == m:
			return 'array'
		elif is_subsequence(s, t):
			return 'automaton'
		else:
			return 'both'
	return 'need tree'
s = str(input())
t = str(input())
print(solve(s, t))


a = input()
b = input()
j = 0
c = 0
flag = True
for i in range(len(a)):
	if a[i] == b[j]:
		j += 1
	if j >= len(b):
		break
if j == len(b):
	print('automaton')
elif sorted(a) == sorted(b):
	print('array')
else:
	for i in b:
		if a.count(i) < b.count(i):
			flag = False
			break
	if flag == True:
		print('both')
	else:
		print('need tree')


s = input()
t = input()
flag = 0
ti = 0
for i in s:
	if t[ti] == i:
		ti = ti + 1
		if ti == len(t):
			flag = 1
			break
ts = sorted(t)
ss = sorted(s)
if ss == ts:
	flag = 2
l1 = [0] * 200
l2 = [0] * 200
for c in s:
	l1[ord(c)] += 1
for c in t:
	l2[ord(c)] += 1
flag2 = 0
for i in range(ord('a'), ord('z') + 1):
	if l1[i] < l2[i]:
		flag2 = 1
if flag == 1:
	print('automaton')
	exit(0)
elif flag == 2:
	print('array')
	exit(0)
if flag2 == 0:
	print('both')
else:
	print('need tree')


def che(s, t):
	j = 0
	for i in s:
		if t[j] == i:
			j += 1
		if j == len(t):
			return True
s = input()
t = input()
sa = sorted(s)
st = sorted(t)
if sa == st:
	print('array')
elif che(s, t):
	print('automaton')
elif che(sa, st):
	print('both')
else:
	print('need tree')


s = input()
t = input()
a = [0 for i in range(26)]
auto = False
j = 0
for i in s:
	if j < len(t):
		if i == t[j]:
			j += 1
	if j == len(t):
		auto = True
		break
for i in s:
	a[ord(i) - ord('a')] += 1
for j in t:
	a[ord(j) - ord('a')] -= 1
arr = True
both = True
for i in a:
	arr = arr and i == 0
	both = both and i >= 0
if auto:
	print('automaton')
elif arr:
	print('array')
elif both:
	print('both')
else:
	print('need tree')


s = input()
t = input()
A = [0] * 26
B = [0] * 26
res = None
for ch in s:
	A[ord(ch) - ord('a')] += 1
for ch in t:
	B[ord(ch) - ord('a')] += 1
for i in range(26):
	if B[i] > A[i]:
		res = 'need tree'
		break
if res == None and len(s) == len(t):
	if A == B:
		res = 'array'
	else:
		res = 'need tree'
elif res == None:
	flag = True
	suffix = False
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] != t[j]:
			i += 1
		else:
			i += 1
			j += 1
	if j == len(t):
		res = 'automaton'
	else:
		res = 'both'
print(res)


from sys import stdin, stdout
from collections import Counter

def check_automaton(s, t):
	if t in s:
		return True
	if len(s) == 1:
		return False
	i = 0
	while i < len(s) - 1:
		if s[i] != t[min(i, len(t) - 1)]:
			s = s[:i] + s[i + 1:]
			if s == t:
				return True
		else:
			i += 1
	return t in s

def solve(s, t):
	if len(s) < len(t):
		return 'need tree'
	count_s = Counter(s)
	count_t = Counter(t)
	if count_s == count_t:
		return 'array'
	if check_automaton(s, t):
		return 'automaton'
	for i in count_t:
		if i not in count_s.keys() or count_s[i] < count_t[i]:
			return 'need tree'
	return 'both'
s = str(stdin.readline().rstrip())
t = str(stdin.readline().rstrip())
stdout.write(str(solve(s, t)))


s1 = input()
s2 = input()
l1 = len(s1)
l2 = len(s2)
ans2 = False
ans1 = False
if sorted(s1) == sorted(s2):
	print('array')
	exit()
j = 0
for i in range(l1):
	if s1[i] == s2[j]:
		j += 1
	if j == l2:
		break
if j == l2:
	print('automaton')
	exit()
s1 = sorted(s1)
s2 = sorted(s2)
j = 0
for i in range(l1):
	if s1[i] == s2[j]:
		j += 1
	if j == l2:
		break
if j == l2:
	print('both')
	exit()
print('need tree')


s = input()
t = input()
C = 0
for c in t:
	cnt = 0
	for i in t:
		if i == c:
			cnt += 1
	for i in s:
		if i == c:
			cnt -= 1
	if cnt > 0:
		print('need tree')
		exit()
	C += cnt
if C == 0 and len(s) == len(t):
	print('array')
	exit()
id = 0
for c in t:
	ok = False
	for i in range(id, len(s)):
		if s[i] == c:
			id = i + 1
			ok = True
			break
	if ok == False:
		print('both')
		exit()
print('automaton')


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
s1 = si()
s2 = si()
l1 = len(s1)
l2 = len(s2)
l = []
b = [0] * l1
lst = 0
for i in range(l2):
	fg = 0
	for j in range(lst, l1):
		if s1[j] == s2[i] and b[j] == 0:
			fg = 1
			b[j] = 1
			l.append(j)
			lst = j
			break
	if fg == 0:
		for j in range(lst, -1, -1):
			if s1[j] == s2[i] and b[j] == 0:
				b[j] = 1
				l.append(j)
				lst = j
				break
l3 = len(l)
if l3 != l2:
	print('need tree')
elif l == sorted(l) and l3 < l1:
	print('automaton')
elif l != sorted(l) and l3 == l1:
	print('array')
else:
	print('both')


def check(a, b):
	for i in a:
		if i not in b:
			return False
		elif a[i] > b[i]:
			return False
	return True

def c(s, t):
	for i in range(len(s)):
		if s[i] != t[i]:
			return False
	return True

def lcs(X, Y):
	m = len(X)
	n = len(Y)
	L = [[None] * (n + 1) for i in range(m + 1)]
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				L[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				L[i][j] = L[i - 1][j - 1] + 1
			else:
				L[i][j] = max(L[i - 1][j], L[i][j - 1])
	return L[m][n]
s = input()
t = input()
dic1 = {}
dic2 = {}
for i in s:
	dic1[i] = dic1.get(i, 0) + 1
for i in t:
	dic2[i] = dic2.get(i, 0) + 1
if len(s) == len(t):
	if check(dic1, dic2):
		print('array')
	else:
		print('need tree')
elif len(s) < len(t):
	print('need tree')
elif check(dic2, dic1):
	if lcs(s, t) == len(t):
		print('automaton')
	else:
		print('both')
else:
	print('need tree')


s = input()
t = input()
lst1 = [0] * 26
lst2 = [0] * 26
for i in s:
	lst1[ord(i) - 97] += 1
for j in t:
	lst2[ord(j) - 97] += 1
if lst1 == lst2:
	print('array')
	quit()
for i in range(26):
	if lst1[i] < lst2[i]:
		print('need tree')
		quit()
j = 0
for i in s:
	if i == t[j]:
		j += 1
	if j == len(t):
		break
print(['both', 'automaton'][len(t) == j])


from collections import Counter
s = input()
t = input()
c = Counter(s)
d = Counter(t)
autom = False
array = False
for x in t:
	if x not in c or c[x] < d[x]:
		print('need tree')
		break
else:
	if len(s) > len(t):
		autom = True
	i = 0
	j = 0
	k = 0
	while i < len(s) and j < len(t):
		if s[i] != t[j]:
			i += 1
		else:
			k += 1
			i += 1
			j += 1
	if k != len(t):
		array = True
	if autom and array:
		print('both')
	elif autom:
		print('automaton')
	else:
		print('array')


src = input()
dest = input()
s = [0] * 26
for c in src:
	s[ord(c) - ord('a')] += 1
d = [0] * 26
for c in dest:
	d[ord(c) - ord('a')] += 1
diff = [y - x for (x, y) in zip(s, d)]
mx = max(diff)
mn = min(diff)
if mx > 0:
	print('need tree')
elif mx == mn == 0:
	print('array')
else:
	i = 0
	flag = True
	for c in dest:
		if i == len(src):
			flag = False
		for j in range(i, len(src)):
			if c == src[j]:
				i = j + 1
				break
			elif j == len(src) - 1:
				flag = False
		if not flag:
			break
	if flag:
		print('automaton')
	else:
		print('both')


def subseq(t, s):
	if len(t) == 0:
		return True
	for i in range(len(s)):
		if s[i] == t[0]:
			return subseq(t[1:], s[i + 1:])
	return False
s = str(input())
t = str(input())
s1 = []
t1 = []
for j in s:
	s1.append(str(j))
for j in t:
	t1.append(str(j))
flag = True
for i in t1:
	if not i in s1:
		print('need tree')
		flag = False
		break
	else:
		s1.remove(i)
if flag:
	if len(s) == len(t):
		print('array')
	elif subseq(t, s):
		print('automaton')
	else:
		print('both')


a = input()
b = input()
cnta = [0] * 27
cntb = [0] * 27
for i in range(len(a)):
	cnta[ord(a[i]) - ord('a')] += 1
for i in range(len(b)):
	cntb[ord(b[i]) - ord('a')] += 1
au = True
ar = True
both = True
j = -1
for i in range(len(b)):
	fl = 0
	while j + 1 < len(a):
		j += 1
		if a[j] == b[i]:
			fl = 1
			break
	if fl == 0:
		au = False
		break
for i in range(26):
	if cnta[i] != cntb[i]:
		ar = False
		break
for i in range(26):
	if cnta[i] < cntb[i]:
		both = False
		au = False
		ar = False
		break
if both == False:
	print('need tree')
	quit()
if au == True:
	print('automaton')
	quit()
if ar == True:
	print('array')
	quit()
if both == True:
	print('both')
	quit()


s = input()
t = input()

def both(s, t):
	for i in t:
		ind = s.find(i)
		if ind == -1:
			return False
		s = s[:ind] + '0' + s[ind + 1:]
	return True

def automaton(s, t):
	n = 0
	for i in range(len(s)):
		if n < len(t) and t[n] == s[i]:
			n += 1
	return n == len(t)
if automaton(s, t):
	print('automaton')
elif len(s) == len(t):
	if sorted(list(s)) == sorted(list(t)):
		print('array')
	else:
		print('need tree')
elif both(s, t):
	print('both')
else:
	print('need tree')


s = input()
t = input()
d = {}
e = {}
for c in t:
	d[c] = d.get(c, 0) + 1
for c in s:
	e[c] = e.get(c, 0) + 1
for i in d:
	if d[i] > e.get(i, 0):
		print('need tree')
		return
if len(s) == len(t):
	print('array')
	return
j = -1
for i in range(len(t)):
	while True:
		j += 1
		if j == len(s):
			print('both')
			return
		if s[j] == t[i]:
			break
print('automaton')


from collections import Counter
s = input().strip()
t = input().strip()
ls = len(s)
lt = len(t)
d = Counter()
table = [False] * lt
for c in t:
	d[c] += 1
i = 0
for c in s:
	d[c] -= 1
	if i < lt and c == t[i]:
		table[i] = True
		i += 1
auto = False
for c in d:
	if d[c] > 0:
		print('need tree')
		break
	if d[c] < 0:
		auto = True
else:
	array = not all(table)
	if auto and array:
		print('both')
	elif auto:
		print('automaton')
	elif array:
		print('array')
	else:
		print('need tree')


s = input()
t = input()
f = 1
m = list(s)
n = list(t)
if len(s) == len(t):
	p = sorted(m)
	p1 = sorted(n)
	if p == p1:
		print('array')
		f = 0
	else:
		f = 1
if f == 1:
	i = 0
	j = 0
	while j < len(n) and i < len(m):
		if s[i] == t[j]:
			j += 1
		i += 1
	if j == len(n):
		print('automaton')
	else:
		c = 0
		p = sorted(m)
		p1 = sorted(n)
		i = 0
		j = 0
		while j < len(n) and i < len(m):
			if p[i] == p1[j]:
				j += 1
			i += 1
		if j == len(n):
			print('both')
		else:
			print('need tree')


def is_aut(s, t):
	i = 0
	for c in s:
		if c == t[i]:
			i += 1
		if i == len(t):
			break
	return i == len(t)
s = input()
t = input()
ss = str(sorted(s))
st = str(sorted(t))
if ss == st:
	print('array')
elif is_aut(s, t):
	print('automaton')
elif is_aut(ss, st):
	print('both')
else:
	print('need tree')


def issub(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
first = input()
second = input()
f_dic = {}
for i in first:
	if i in f_dic:
		f_dic[i] += 1
	else:
		f_dic[i] = 1
s_dic = {}
for i in second:
	if i in s_dic:
		s_dic[i] += 1
	else:
		s_dic[i] = 1
f = 0
for i in s_dic:
	if i not in f_dic:
		f = 1
		break
	elif s_dic[i] > f_dic[i]:
		f = 1
		break
if f == 1:
	print('need tree')
elif len(second) == len(first):
	print('array')
elif issub(second, first):
	print('automaton')
else:
	print('both')


def automat(w1, w2):
	index = -1
	w1 = list(w1)
	for c in w2:
		found = False
		for i in range(len(w1)):
			if c == w1[i] and i > index:
				index = i
				found = True
				w1[i] = '.'
				break
		if not found:
			return False
	return True

def array(w1, w2):
	w1 = list(w1)
	for c in w2:
		found = False
		for i in range(len(w1)):
			if c == w1[i]:
				found = True
				w1[i] = '.'
				break
		if not found:
			return False
	return True
word1 = input()
word2 = input()
if automat(word1, word2):
	print('automaton')
else:
	arr_s = array(word1, word2)
	if arr_s and len(word1) == len(word2):
		print('array')
	elif arr_s and len(word1) != len(word2):
		print('both')
	else:
		print('need tree')


from collections import Counter

def dsRequired(s, t):
	temp = 0
	for i in range(len(s)):
		if temp < len(t) and s[i] == t[temp]:
			temp += 1
	if temp == len(t):
		return 'automaton'
	dict_s = dict(Counter(list(s)))
	dict_t = dict(Counter(list(t)))
	if dict_s == dict_t:
		return 'array'
	flag = True
	for (ch, freq) in dict_t.items():
		if ch in dict_s.keys() and dict_s[ch] < freq:
			flag = False
		if ch not in dict_s.keys():
			flag = False
	if flag:
		return 'both'
	else:
		return 'need tree'

def main():
	s = input()
	t = input()
	print(dsRequired(s, t))
main()


s1 = input()
s2 = input()

def isAutomaton(s1, s2):
	i1 = 0
	i2 = 0
	while i1 < len(s1) and i2 < len(s2):
		if s2[i2] == s1[i1]:
			i2 += 1
		i1 += 1
	if i2 == len(s2):
		return True
	else:
		return False

def isArray(s1, s2):
	arr = [0] * 26
	for c in s2:
		index = ord(c) - ord('a')
		arr[index] += 1
	for c in s1:
		index = ord(c) - ord('a')
		if arr[index] != 0:
			arr[index] -= 1
	return sum(arr) == 0
if isAutomaton(s1, s2):
	print('automaton')
elif isArray(s1, s2) and len(s1) == len(s2):
	print('array')
elif isArray(s1, s2) and len(s2) < len(s1):
	print('both')
else:
	print('need tree')


def getChar(x):
	return chr(x + ord('a'))
s = input()
t = input()
need_tree = array = automaton = False
for i in range(26):
	t_count = t.count(getChar(i))
	s_count = s.count(getChar(i))
	if t_count > s_count:
		need_tree = True
	elif t_count < s_count:
		automaton = True
(index_found, match) = (0, -1)
for i in range(len(t)):
	index_found = s.find(t[i], match + 1)
	if index_found > match:
		match = index_found
	else:
		array = True
		break
if need_tree:
	print('need tree')
elif automaton and array:
	print('both')
elif automaton:
	print('automaton')
else:
	print('array')


def issub(string1, string2, m, n):
	if m == 0:
		return True
	if n == 0:
		return False
	if string1[m - 1] == string2[n - 1]:
		return issub(string1, string2, m - 1, n - 1)
	return issub(string1, string2, m, n - 1)
s = input()
t = input()
if issub(t, s, len(t), len(s)):
	print('automaton')
else:
	dc = {}
	for i in s:
		if i in dc:
			dc[i] += 1
		else:
			dc[i] = 1
	flag = 0
	for i in t:
		if i in dc and dc[i] > 0:
			dc[i] -= 1
		else:
			flag = 1
			break
	if flag == 0:
		if len(t) == len(s):
			print('array')
		else:
			print('both')
	else:
		print('need tree')


import sys
import math
import collections
import bisect

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
for t in range(1):
	s1 = get_string()
	s2 = get_string()
	string1 = list(s1)
	string2 = list(s2)
	counter1 = collections.Counter(string1)
	counter2 = collections.Counter(string2)
	removed = 0
	np = 0
	for i in counter2:
		if i in counter1:
			val = counter1[i] - counter2[i]
			if val > 0:
				removed += 1
			elif val < 0:
				np += 1
		else:
			np += 1
	if sorted(string1) == sorted(string2):
		print('array')
	elif np > 0:
		print('need tree')
	elif isSubSequence(s2, s1):
		print('automaton')
	else:
		print('both')


dt = [0] * 128
flag = False
fl = True
arr = False
poss = 0
pos = -1
ds = [0] * 128
s = input()
t = input()
for i in range(len(t)):
	dt[ord(t[i])] += 1
for i in range(len(s)):
	ds[ord(s[i])] += 1
for i in range(128):
	if dt[i] > ds[i]:
		print('need tree')
		exit()
for i in range(len(t)):
	pos = s.find(t[i], pos + 1)
	if pos == -1:
		arr = True
		break
	else:
		poss = pos
for i in range(128):
	if dt[i] < ds[i]:
		flag = True
if flag == True and arr == True:
	print('both')
elif flag == True and arr == False:
	print('automaton')
else:
	print('array')


s = input()
t = input()
count_s = [0] * 30
count_t = [0] * 30
for ch in s:
	count_s[ord(ch) - ord('a')] += 1
for ch in t:
	count_t[ord(ch) - ord('a')] += 1
flag = True
for i in range(26):
	if count_s[i] < count_t[i]:
		flag = False
if not flag:
	print('need tree')
else:
	if len(s) == len(t) and s != t:
		print('array')
		exit()
	i = 0
	index = 0
	while i < len(s) and index < len(t):
		if s[i] == t[index]:
			index += 1
		i += 1
	if index == len(t):
		print('automaton')
	else:
		print('both')


def main():
	s = input()
	t = input()
	k = 0
	for i in range(len(s)):
		if k < len(t) and s[i] == t[k]:
			k += 1
	if k == len(t):
		print('automaton')
		return
	sd = {}
	for c in s:
		if c not in sd:
			sd[c] = 0
		sd[c] += 1
	td = {}
	for c in t:
		if c not in td:
			td[c] = 0
		td[c] += 1
	status = True
	for c in t:
		if c in sd and td[c] <= sd[c]:
			pass
		else:
			status = False
	if status:
		if len(s) == len(t):
			print('array')
		else:
			print('both')
	else:
		print('need tree')
main()


import sys
import math

def fn(s, t):
	s = list(s)
	x = s.copy()
	t = list(t)
	y = t.copy()
	s1 = []
	if len(s) < len(t):
		print('need tree')
		return 0
	if len(s) == len(t):
		s.sort()
		t.sort()
		if s == t:
			print('array')
			return 1
		else:
			print('need tree')
			return 0
	else:
		c = 0
		for i in range(len(t)):
			if t[i] in x:
				x.remove(t[i])
				c = 1
			else:
				c = 0
				break
		if c == 1:
			k = 0
			for i in range(len(s)):
				if k < len(t) and s[i] == t[k]:
					k = k + 1
					s1.append(s[i])
				else:
					continue
			if s1 == t:
				print('automaton')
				return 1
			else:
				print('both')
				return 1
		else:
			print('need tree')
			return 0
input = sys.stdin.read()
data = list(map(str, input.split()))
s = data[0]
t = data[1]
fn(s, t)


s = input()
t = input()
if len(s) < len(t):
	print('need tree')
else:
	sCnt = [0] * 26
	tCnt = [0] * 26
	for c in s:
		sCnt[ord(c) - ord('a')] += 1
	for c in t:
		tCnt[ord(c) - ord('a')] += 1
	extra = 0
	flag = True
	for i in range(26):
		if tCnt[i] > sCnt[i]:
			flag = False
			break
		else:
			extra += sCnt[i] - tCnt[i]
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			i += 1
			j += 1
		else:
			i += 1
	isAuto = True
	if j < len(t):
		isAuto = False
	if not flag:
		print('need tree')
	elif extra == 0:
		print('array')
	elif isAuto:
		print('automaton')
	else:
		print('both')


s = input()
t = input()
k1 = list(s)
count = 0
for i in t:
	if i not in k1:
		count += 1
	else:
		k1.remove(i)
if count >= 1 or len(t) > len(s):
	print('need tree')
elif count == 0:
	st = ''
	k = 0
	for i in t:
		for j in s[k:]:
			if i == j:
				k = s[k:].find(j) + 1 + k
				st += j
				break
	if (t in s or t in st) and len(s) > len(t):
		print('automaton')
	elif len(t) == len(s):
		print('array')
	else:
		print('both')


def suffix(s, t):
	mapp_t = {}
	for char in t:
		if char not in mapp_t:
			mapp_t[char] = 1
		else:
			mapp_t[char] += 1
	mapp_s = {}
	for char in s:
		if char not in mapp_s:
			mapp_s[char] = 1
		else:
			mapp_s[char] += 1
	for char in mapp_t.keys():
		if char not in mapp_s.keys() or mapp_s[char] < mapp_t[char]:
			return 'need tree'
	s_pointer = 0
	t_pointer = 0
	while s_pointer < len(s) and t_pointer < len(t):
		if s[s_pointer] != t[t_pointer]:
			s_pointer += 1
		elif s[s_pointer] == t[t_pointer]:
			s_pointer += 1
			t_pointer += 1
	if t_pointer == len(t):
		return 'automaton'
	elif len(s) == len(t):
		return 'array'
	else:
		return 'both'
s = input().strip()
t = input().strip()
print(suffix(s, t))


from collections import defaultdict

def sub(a, b):
	i = 0
	j = 0
	while i < len(a):
		if a[i] == b[j]:
			j += 1
			if j == len(b):
				return True
		i += 1
	return False

def compare(a, b):
	automaton = sub(a, b)
	array = True
	both = True
	m = [0] * 26
	for c in a:
		m[ord(c) - ord('a')] += 1
	for c in b:
		m[ord(c) - ord('a')] -= 1
	for i in range(26):
		if m[i] != 0:
			array = False
		if m[i] < 0:
			both = False
	if automaton:
		return 'automaton'
	elif array:
		return 'array'
	elif both:
		return 'both'
	return 'need tree'

def main():
	a = input()
	b = input()
	return compare(a, b)
print(main())


import sys

def getCharCount(string):
	strCount = dict()
	for char in string:
		strCount[char] = strCount.get(char, 0) + 1
	return strCount
str1 = input()
str2 = input()
useAutomaton = False
useArr = False
str1Count = getCharCount(str1)
str2Count = getCharCount(str2)
for char in str2:
	if str1Count.get(char, 0) < str2Count[char]:
		print('need tree')
		sys.exit()
for char in str1:
	if str1Count[char] > str2Count.get(char, 0):
		useAutomaton = True
idx = 0
while idx < len(str1):
	if str1[idx] not in str2Count:
		str1 = str1[:idx] + str1[idx + 1:]
		continue
	idx += 1
idx = 0
while idx < len(str2):
	if str1[idx] == str2[idx]:
		idx += 1
		continue
	if str1Count[str1[idx]] == str2Count[str1[idx]]:
		useArr = True
		break
	else:
		str1Count[str1[idx]] -= 1
		str1 = str1[:idx] + str1[idx + 1:]
if useArr and useAutomaton:
	print('both')
elif useArr:
	print('array')
else:
	print('automaton')


(a, b) = (input(), input())

def subset(a, t):
	i = 0
	for c in a:
		if c == t[i]:
			i += 1
		if i == len(t):
			break
	return i == len(t)
if str(sorted(a)) == str(sorted(b)):
	print('array')
elif subset(a, b):
	print('automaton')
elif subset(str(sorted(a)), str(sorted(b))):
	print('both')
else:
	print('need tree')


s = input()
t = input()
x = set(s)
s = list(s)
i = 0
j = 0
nt = 0
ar = 0
at = 0
while i <= len(s) and j < len(t):
	if i == len(s):
		i = 0
		ar = 1
	if t[j] in s:
		if s[i] == t[j]:
			s[i] = ':'
			j += 1
			i += 1
		else:
			i += 1
			at = 1
	else:
		nt = 1
		break
if nt == 0 and len(s) == len(t):
	at = 0
else:
	at = 1
if nt == 1:
	print('need tree')
elif at == ar == 1:
	print('both')
elif at == 1:
	print('automaton')
elif ar == 1:
	print('array')


from functools import reduce
from operator import *
from math import *
from sys import *
from string import *
from collections import *
setrecursionlimit(10 ** 7)
dX = [-1, 1, 0, 0, -1, 1, -1, 1]
dY = [0, 0, -1, 1, 1, -1, -1, 1]
RI = lambda : list(map(int, input().split()))
RS = lambda : input().rstrip().split()

def findMatch(s, t):
	(i, j) = (0, 0)
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			j += 1
		i += 1
	return j == len(t)
s = RS()[0]
t = RS()[0]
cnt = {c: 0 for c in ascii_lowercase}
for i in s:
	cnt[i] += 1
for i in t:
	cnt[i] -= 1
x = findMatch(s, t)
y = all((cnt[i] >= 0 for i in cnt))
if x:
	print('automaton')
elif y and len(s) == len(t):
	print('array')
elif y:
	print('both')
else:
	print('need tree')


import sys
s = input()
t = input()
s_count = [0] * 26
t_count = [0] * 26
for i in range(len(s)):
	s_count[ord(s[i]) - ord('a')] += 1
for i in range(len(t)):
	t_count[ord(t[i]) - ord('a')] += 1
tree = False
array = False
automation = False
for i in range(26):
	if s_count[i] < t_count[i]:
		tree = True
	if s_count[i] > t_count[i]:
		automation = True
i = 0
for j in range(len(t)):
	while i < len(s) and s[i] != t[j]:
		i += 1
	if i == len(s):
		array = True
	i += 1
if tree:
	print('need tree')
elif automation and array:
	print('both')
elif automation:
	print('automaton')
elif array:
	print('array')


def helper(s1, s2):
	a = 0
	b = 0
	n = len(s1)
	m = len(s2)
	while a < n and b < m:
		if s1[a] == s2[b]:
			b += 1
			a += 1
		else:
			a += 1
	if b == m:
		return True
	return False
s1 = input()
s2 = input()
d = {}
for i in s1:
	if i not in d:
		d[i] = 1
	else:
		d[i] += 1
f = False
for i in s2:
	if i not in d or d[i] == 0:
		f = True
		break
	else:
		d[i] -= 1
flag = False
for i in d:
	if d[i] > 0:
		flag = True
		break
if f:
	print('need tree')
elif helper(s1, s2) == False and flag:
	print('both')
elif helper(s1, s2):
	print('automaton')
else:
	print('array')


def contain(s, t):
	s = list(s)
	p = list(s)
	for i in t:
		if i in s:
			s.remove(i)
		else:
			return False
	return True

def find(s, t):
	t = list(t)
	j = 0
	while j < len(s):
		if t[0] == s[j]:
			t.pop(0)
			if len(t) == 0:
				return True
		j += 1
	return len(t) == 0
s = input()
t = input()
if find(s, t):
	print('automaton')
elif contain(s, t) and len(s) > len(t):
	print('both')
elif contain(s, t) and len(s) == len(t):
	print('array')
else:
	print('need tree')


__author__ = 'Rajan'

def anagram_check(s, t):
	s1 = [0 for i in range(26)]
	t1 = [0 for i in range(26)]
	for c in s:
		s1[ord(c) - ord('a')] += 1
	for c in t:
		t1[ord(c) - ord('a')] += 1
	for i in range(26):
		if s1[i] != t1[i]:
			return False
	return True

def third_test(s, t):
	s1 = [0 for i in range(26)]
	t1 = [0 for i in range(26)]
	for c in s:
		s1[ord(c) - ord('a')] += 1
	for c in t:
		t1[ord(c) - ord('a')] += 1
	for i in range(26):
		if t1[i] > s1[i]:
			return False
	return True
s = input()
t = input()
sp = 0
tp = 0
res1 = True
while tp < len(t) and sp < len(s):
	while s[sp] != t[tp]:
		sp += 1
		if sp >= len(s):
			res1 = False
			break
	tp += 1
	sp += 1
if tp < len(t):
	res1 = False
if res1 and len(s) >= len(t):
	print('automaton')
elif anagram_check(s, t):
	print('array')
elif third_test(s, t):
	print('both')
else:
	print('need tree')


from collections import defaultdict
s = input()
t = input()
(l, r) = (0, 0)
while l < len(s) and r < len(t):
	if s[l] == t[r]:
		r += 1
	l += 1
if r == len(t):
	print('automaton')
	quit()
if sorted(s) == sorted(t):
	print('array')
	quit()
m = defaultdict(int)
m2 = defaultdict(int)
for c in s:
	m[c] += 1
for c in t:
	m2[c] += 1
ok = True
for i in m2:
	if m[i] < m2[i]:
		ok = False
if ok:
	print('both')
else:
	print('need tree')


s = input().rstrip()
y = input().rstrip()
if len(s) == len(y):
	s1 = [i for i in s]
	y1 = [i for i in y]
	if sorted(s1) == sorted(y1):
		print('array')
	else:
		print('need tree')
elif len(s) > len(y):
	j = len(y) - 1
	flag = 0
	for i in range(len(s) - 1, -1, -1):
		if s[i] == y[j]:
			j -= 1
			if j == -1:
				flag = 1
				break
	if flag == 1:
		print('automaton')
		exit()
	else:
		p = dict()
		d = dict()
		for i in s:
			if i in p:
				p[i] += 1
			else:
				p[i] = 1
		for i in y:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		flag1 = 0
		for i in d:
			if i in p:
				if p[i] >= d[i]:
					pass
				else:
					flag1 = 1
					break
			else:
				flag1 = 1
				break
		if flag1 == 1:
			print('need tree')
		else:
			print('both')
else:
	print('need tree')


def array(s, t):
	if len(s) == len(t):
		sum1 = 0
		sum2 = 0
		for i in range(len(s)):
			sum1 += ord(s[i])
			sum2 += ord(t[i])
		return sum1 == sum2
	return False

def automation(s, t):
	j = 0
	i = 0
	while i < len(s) and j < len(t):
		if s[i] == t[j]:
			j += 1
		i += 1
	return j == len(t)

def find(arr, data):
	index = -1
	for i in range(len(arr)):
		if arr[i] == data:
			index = i
			break
	return index

def both(s, t):
	arr1 = list(s[:])
	for i in range(len(t)):
		index = find(arr1, t[i])
		if index == -1:
			return False
		arr1[index] = '0'
	return True
ss = input()
tt = input()
if array(ss, tt):
	print('array')
elif automation(ss, tt):
	print('automaton')
elif both(ss, tt):
	print('both')
else:
	print('need tree')


s = input()
t = input()
sorted_s = sorted(s)
sorted_t = sorted(t)

def subset(t, s):
	i = 0
	for char in s:
		if char == t[i]:
			i += 1
		if i == len(t):
			break
	return i == len(t)
if sorted_t == sorted_s:
	print('array')
elif subset(t, s):
	print('automaton')
elif subset(sorted_t, sorted_s):
	print('both')
else:
	print('need tree')


from collections import deque

def canPop(s1, s2):
	x = deque()
	for char in s2:
		x.append(char)
	for char in s1:
		if len(x) == 0:
			break
		if char == x[0]:
			x.popleft()
	if len(x) != 0:
		return False
	return True

def canFlip(s1, s2):
	charDict = {}
	for char in s1:
		if char in charDict:
			charDict[char] += 1
		else:
			charDict[char] = 1
	for char in s2:
		if char not in charDict:
			return False
		elif charDict[char] <= 0:
			return False
		else:
			charDict[char] -= 1
	return True

def main(s1, s2):
	if canPop(s1, s2):
		print('automaton')
	elif canFlip(s1, s2):
		if len(s1) == len(s2):
			print('array')
		else:
			print('both')
	else:
		print('need tree')
w1 = str(input())
w2 = str(input())
main(w1, w2)


import sys
s = input()
t = input()
j = 0
for l in s:
	if l == t[j]:
		j += 1
	if j == len(t):
		break
if j == len(t):
	print('automaton')
	sys.exit()
similar = [0] * 42
for l in s:
	similar[ord(l) - ord('a')] += 1
for l in t:
	similar[ord(l) - ord('a')] -= 1
for n in similar:
	if n < 0:
		print('need tree')
		sys.exit()
if sum(similar) > 0:
	print('both')
else:
	print('array')


s = input()
t = input()
ls = [0] * 26
lt = [0] * 26
automaton = False
array = False
check = True
for i in s:
	ls[ord(i) - ord('a')] += 1
for i in t:
	lt[ord(i) - ord('a')] += 1
for i in range(0, len(t)):
	if lt[ord(t[i]) - ord('a')] == ls[ord(t[i]) - ord('a')]:
		continue
	if lt[ord(t[i]) - ord('a')] > ls[ord(t[i]) - ord('a')]:
		check = False
if check and len(s) != len(t):
	automaton = True
st = 0
i = 0
while i < len(t) and st < len(s):
	if t[i] == s[st]:
		ls[ord(s[st]) - ord('a')] -= 1
		lt[ord(t[i]) - ord('a')] -= 1
		i += 1
		st += 1
	elif ls[ord(s[st]) - ord('a')] > lt[ord(s[st]) - ord('a')]:
		ls[ord(s[st]) - ord('a')] -= 1
		st += 1
	elif ls[ord(s[st]) - ord('a')] < lt[ord(s[st]) - ord('a')]:
		break
	else:
		array = True
		break
for i in range(0, len(t)):
	if ls[ord(t[i]) - ord('a')] < lt[ord(t[i]) - ord('a')]:
		array = False
		break
if automaton and array:
	print('both')
elif automaton:
	print('automaton')
elif array:
	print('array')
else:
	print('need tree')


s = input()
t = input()
s_dict = {}
t_dict = {}

def both(t_dict, s_dict):
	flag = False
	for i in t_dict:
		if i in s_dict:
			if t_dict[i] <= s_dict[i]:
				flag = True
			else:
				flag = False
				break
		else:
			flag = False
			break
	return flag

def check_sorted(t, s):
	j = 0
	flag = False
	for i in s:
		if i == t[j]:
			j += 1
		if j == len(t):
			break
	return True if len(t) == j else False
for i in s:
	if i in s_dict:
		s_dict[i] += 1
	else:
		s_dict[i] = 1
for i in t:
	if i in t_dict:
		t_dict[i] += 1
	else:
		t_dict[i] = 1
check = both(t_dict, s_dict)
if s_dict == t_dict:
	print('array')
elif check and check_sorted(t, s):
	print('automaton')
elif check:
	print('both')
else:
	print('need tree')


s = input()
t = input()
s_freq = {}
t_freq = {}
for i in s:
	try:
		s_freq[i] += 1
	except:
		s_freq[i] = 1
for i in t:
	try:
		t_freq[i] += 1
	except:
		t_freq[i] = 1
possible = True
for i in t_freq:
	try:
		if s_freq[i]:
			if t_freq[i] > s_freq[i]:
				possible = False
				break
	except:
		possible = False
		break
if possible:
	if len(s) == len(t):
		print('array')
	else:
		i = 0
		j = 0
		while i < len(s) and j < len(t):
			if s[i] == t[j]:
				j += 1
			i += 1
		if j >= len(t):
			print('automaton')
		else:
			print('both')
else:
	print('need tree')


a = input()
b = input()
c = sorted(a)
d = sorted(b)

def auto(a, b):
	i = 0
	for ch in a:
		if i < len(b) and ch == b[i]:
			i += 1
	return i == len(b)
if c == d:
	print('array')
elif auto(a, b):
	print('automaton')
elif auto(c, d):
	print('both')
else:
	print('need tree')


s = input()
t = input()
sor_s = sorted(s)
sor_t = sorted(t)

def Chek_automaton(s, t):
	j = 0
	for i in s:
		if t[j] == i:
			j += 1
		if j == len(t):
			return True
	return j == len(t)
if sor_t == sor_s:
	print('array')
elif Chek_automaton(s, t):
	print('automaton')
elif Chek_automaton(sor_s, sor_t):
	print('both')
else:
	print('need tree')


init2 = str(input(''))
final2 = str(input(''))
init = list(init2)
final = list(final2)
conversion = init[:]
possible = True

def automaton(final, conversion):
	i = 0
	if len(final) == len(conversion) and final != conversion:
		return False
	else:
		while final != conversion and i < len(final) and (len(conversion) >= len(final)):
			while final[i] != conversion[i] and conversion != [] and (len(conversion) >= len(final)):
				del conversion[i]
			i += 1
		if len(conversion) > len(final):
			del conversion[len(final):]
		if conversion == final:
			return True

def array(final, init):
	for i in final:
		if i in init and init.count(i) == final.count(i):
			if len(init) == len(final):
				return True
for i in final:
	if final.count(i) > init.count(i):
		possible = False
if possible:
	if automaton(final, conversion):
		print('automaton')
	elif array(final, init):
		print('array')
	else:
		print('both')
else:
	print('need tree')


s = input()
t = input()
sos = sorted(s)
sot = sorted(t)

def subseq(s, t):
	i = 0
	for x in s:
		if x == t[i]:
			i = i + 1
		if i == len(t):
			break
	return i == len(t)
if sos == sot:
	print('array')
elif subseq(s, t):
	print('automaton')
elif subseq(sos, sot):
	print('both')
else:
	print('need tree')


import sys
try:
	f = open('input.txt')
except IOError:
	f = sys.stdin
s = f.readline().rstrip()
t = f.readline().rstrip()
needTree = False
_s = s[:]
for c in t:
	if c in _s:
		_s = _s[:_s.index(c)] + _s[_s.index(c) + 1:]
	else:
		needTree = True
if needTree:
	print('need tree')
elif not t in s:
	if len(s) > len(t):
		j = 0
		both = False
		for i in range(len(t)):
			while j < len(s) and s[j] != t[i]:
				j += 1
			if j >= len(s):
				both = True
			j += 1
		if both:
			print('both')
		else:
			print('automaton')
	else:
		print('array')
else:
	print('automaton')


(S, T) = (list(input()), list(input()))
(p_t, lenT) = (0, len(T))
lenS = len(S)
for s in S:
	if s == T[p_t]:
		p_t += 1
		if p_t == lenT:
			print('automaton')
			exit(0)
for t in T:
	for (i, s) in enumerate(S):
		if S[i] != 0 and t == s:
			S[i] = 0
			break
	else:
		print('need tree')
		exit(0)
print('array' if lenS == lenT else 'both')


def issubsequence(x, y):
	m = len(y)
	n = len(x)
	j = 0
	for i in range(n):
		if j >= m:
			break
		if x[i] == y[j]:
			j += 1
	if j >= m:
		return True
	return False

def isshuffle(x, y):
	return ''.join(sorted(x)) == ''.join(sorted(y))
x = input()
y = input()
if issubsequence(x, y):
	print('automaton')
elif isshuffle(x, y):
	print('array')
elif issubsequence(sorted(x), sorted(y)):
	print('both')
else:
	print('need tree')


from collections import Counter

def isSubSequence(str1, str2, m, n):
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
s = input()
t = input()
d = Counter(s)
d1 = Counter(t)
if d == d1:
	print('array')
elif isSubSequence(t, s, len(t), len(s)):
	print('automaton')
else:
	count = 0
	for i in set(s).union(set(t)):
		if d[i] < d1[i]:
			count = 1
			break
	if count == 0:
		print('both')
	else:
		print('need tree')


from sys import stdin
input = stdin.readline

def issub(a, b):
	i = 0
	for ch in a:
		if i < len(b) and ch == b[i]:
			i += 1
	return i == len(b)
(s, t) = (input().strip(), input().strip())
if issub(s, t):
	print('automaton')
elif sorted(s) == sorted(t):
	print('array')
elif issub(sorted(s), sorted(t)):
	print('both')
else:
	print('need tree')


def subs(s, t):
	ti = 0
	for ch in s:
		if t[ti] == ch:
			ti += 1
			if ti == len(t):
				return True
	return False
(s, t) = (input(), input())
if subs(s, t):
	print('automaton')
elif sorted(s) == sorted(t):
	print('array')
elif subs(''.join(sorted(s)), ''.join(sorted(t))):
	print('both')
else:
	print('need tree')


(a, b) = (input(), input())
(c1, c2) = ({}, {})
for i in a:
	c1[i] = c1.get(i, 0) + 1
for i in b:
	c2[i] = c2.get(i, 0) + 1
if c1 == c2:
	print('array')
else:
	i = 0
	j = 0
	while i < len(a):
		if a[i] == b[j]:
			j += 1
		i += 1
		if j == len(b):
			break
	if j == len(b):
		print('automaton')
	elif set(b).issubset(set(a)):
		for i in c2:
			if c1[i] < c2[i]:
				print('need tree')
				break
		else:
			print('both')
	else:
		print('need tree')


import sys
from collections import *
input = sys.stdin.readline
s = input()[:-1]
t = input()[:-1]
h1 = Counter(s)
h2 = Counter(t)
if len(s) < len(t):
	print('need tree')
else:
	res = 0
	for i in range(97, 123):
		if h1[chr(i)] < h2[chr(i)]:
			res = 1
			break
	if res == 1:
		print('need tree')
	else:
		a = ''.join(sorted(s))
		b = ''.join(sorted(t))
		if a == b:
			print('array')
		else:
			j = 0
			for i in s:
				if i == t[j]:
					j += 1
					if j == len(t):
						break
			if j == len(t):
				print('automaton')
			else:
				print('both')


def solve(s1, s2, n, m):
	t = [[None for j in range(m + 1)] for i in range(n + 1)]
	for i in range(n + 1):
		for j in range(m + 1):
			if i == 0 or j == 0:
				t[i][j] = 0
			elif s1[i - 1] == s2[j - 1]:
				t[i][j] = 1 + t[i - 1][j - 1]
			else:
				t[i][j] = max(t[i - 1][j], t[i][j - 1])
	return t[n][m]
s = input()
t = input()
flag = True
for i in range(len(t)):
	if t[i] not in s:
		flag = False
		break
	elif t.count(t[i]) > s.count(t[i]):
		flag = False
		break
if flag:
	if len(s) == len(t):
		print('array')
	elif len(s) < len(t):
		print('need tree')
	else:
		lcs = solve(s, t, len(s), len(t))
		if lcs == len(t):
			print('automaton')
		else:
			print('both')
else:
	print('need tree')


import sys, math, bisect
inf = float('inf')
mod = 10 ** 9 + 7

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)

def gcd(a, b):
	return int(math.gcd(a, b))

def tobinary(n):
	return bin(n)[2:]

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def primesInRange(n):
	ans = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans
from collections import deque, defaultdict, Counter
import heapq
for _ in range(1):
	s = input()
	t = input()
	sa = sorted(s)
	ta = sorted(t)

	def subset(t, s):
		i = 0
		for x in s:
			if x == t[i]:
				i += 1
			if i == len(t):
				break
		return i == len(t)
	if sa == ta:
		print('array')
	elif subset(t, s):
		print('automaton')
	elif subset(ta, sa):
		print('both')
	else:
		print('need tree')


def obtain_array(temp):
	arr = []
	for char in temp:
		arr.append(char)
	return arr

def check_char(arr1, arr2):
	flag = 0
	if all((x in arr1 for x in arr2)):
		flag = 1
	if flag == 1:
		return True
	else:
		return False

def count_arr(arr1, arr2):
	flag = True
	for i in arr2:
		c = arr2.count(i)
		d = arr1.count(i)
		if c > d:
			flag = False
			break
	return flag

def check_in_order(arr1, arr2):
	a = len(arr1)
	b = len(arr2)
	c = []
	j = 0
	i = 0
	while j < b and i < a:
		if arr2[j] == arr1[i]:
			c.append(i)
			j += 1
		i += 1
	if len(c) == len(arr2):
		return True
	else:
		return False
s = str(input())
t = str(input())
if len(t) > len(s):
	print('need tree')
else:
	temp_s = obtain_array(s)
	temp_t = obtain_array(t)
	if check_char(temp_s, temp_t):
		if count_arr(temp_s, temp_t):
			if check_in_order(temp_s, temp_t):
				print('automaton')
			elif len(temp_t) == len(temp_s):
				print('array')
			else:
				print('both')
		else:
			print('need tree')
	else:
		print('need tree')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	s = S()
	t = S()
	sl = len(s)
	tl = len(t)
	ti = 0
	for c in s:
		if t[ti] == c:
			ti += 1
			if ti == tl:
				break
	if ti == tl:
		return 'automaton'
	sc = collections.Counter(s)
	tc = collections.Counter(t)
	if sc == tc:
		return 'array'
	for (k, v) in tc.items():
		if sc[k] < v:
			return 'need tree'
	return 'both'
print(main())


from collections import Counter

def check(s, w):
	i = 0
	for x in range(len(s)):
		if s[x] == w[i]:
			i += 1
			pass
		if i == len(w):
			return True
			pass
		pass
	return False
	pass

def charset(s, w):
	sets = set(s)
	setw = set(w)
	return sets == setw
	pass

def subset(s, w):
	countw = dict(Counter(w))
	counts = dict(Counter(s))
	semua = True
	for x in iter(countw):
		if x not in counts:
			semua = False
			break
			pass
		if counts[x] < countw[x]:
			semua = False
			break
			pass
		pass
	return semua
	pass

def occurence(s, w):
	return dict(Counter(s)) == dict(Counter(w))
	pass

def main():
	s = input()
	w = input()
	if check(s, w):
		print('automaton')
		return
	if occurence(s, w):
		print('array')
		return
	if subset(s, w):
		print('both')
		return
		pass
	print('need tree')
	pass
main()


s = input()
t = input()
n = len(s)
m = len(t)
dp = []
for i in range(n + 1):
	c = []
	for j in range(m + 1):
		c.append(0)
	dp.append(c)
for i in range(n + 1):
	for j in range(m + 1):
		if i == 0 or j == 0:
			dp[i][j] = 0
		elif s[i - 1] == t[j - 1]:
			dp[i][j] = 1 + dp[i - 1][j - 1]
		else:
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
x = dp[n][m]
if x == m:
	print('automaton')
else:
	c = 0
	d = []
	for i in t:
		if i not in d:
			d.append(i)
	for i in d:
		if t.count(i) <= s.count(i):
			c += 1
	if n == m and c == len(d):
		print('array')
	elif n > m and c == len(d):
		print('both')
	else:
		print('need tree')


from collections import Counter
s = input()
t = input()
if len(t) > len(s):
	print('need tree')
	exit()
elif len(s) == len(t):
	sc = Counter(s)
	tc = Counter(t)
	fl = True
	for i in s:
		fl = fl and sc[i] == tc[i]
	if fl and len(s) == len(t):
		print('array')
		exit()
i = 0
for j in s:
	if t[i] == j:
		i += 1
	if i == len(t):
		print('automaton')
		exit()
sc = Counter(s)
tc = Counter(t)
fl = True
cnt = 0
for i in t:
	fl = fl and sc[i] >= tc[i]
if fl:
	print('both')
else:
	print('need tree')


while True:
	try:

		def solution(s, t):
			tems = list(s)
			temt = list(t)
			tems.sort()
			temt.sort()
			ln1 = len(s)
			ln2 = len(t)
			if ln2 > ln1 or (ln1 == ln2 and tems != temt):
				print('need tree')
			elif ln2 == ln1:
				print('array')
			else:
				i = j = cunt = 0
				while i < ln2:
					while j < ln1:
						if t[i] == s[j]:
							cunt += 1
							break
						j += 1
					i += 1
					j += 1
				if cunt == ln2:
					print('automaton')
				else:
					i = j = cunt = 0
					while i < ln2:
						while j < ln1:
							if t[i] == tems[j]:
								cunt += 1
								tems[j] = 7
								break
							j += 1
						i += 1
						j = 0
					if cunt == ln2:
						print('both')
					else:
						print('need tree')

		def read():
			s = input()
			t = input()
			solution(s, t)
		if __name__ == '__main__':
			read()
	except EOFError:
		break


I = lambda : int(input())
IL = lambda : list(map(int, input().split()))
IF = lambda : list(map(float, input().split()))

def covers(a, b):
	for l in a:
		pos = b.find(l)
		if pos == -1:
			return False
		b = b[pos + 1:]
	return True
s = input()
t = input()
if sorted(s) == sorted(t):
	print('array')
elif covers(t, s):
	print('automaton')
elif all((s.count(l) >= t.count(l) for l in t)):
	print('both')
else:
	print('need tree')


s = input()
t = input()
cnt1 = [0] * 26
cnt2 = [0] * 26
for i in s:
	cnt1[ord(i) - ord('a')] += 1
for i in t:
	cnt2[ord(i) - ord('a')] += 1
for i in range(26):
	if cnt1[i] < cnt2[i]:
		print('need tree')
		exit()
p = 0
ok = 1
for i in t:
	while p < len(s) and s[p] != i:
		p += 1
	if p >= len(s):
		ok = 0
	p += 1
if ok == 1:
	print('automaton')
	exit()
if len(s) == len(t):
	print('array')
else:
	print('both')


s = input()
t = input()
ls = len(s)
lt = len(t)
flag = 0
ht = []
hs = []
for i in range(26):
	ht.append(0)
	hs.append(0)
for i in t:
	ht[ord(i) - 97] = ht[ord(i) - 97] + 1
for i in s:
	hs[ord(i) - 97] = hs[ord(i) - 97] + 1
for i in range(26):
	if ht[i] > hs[i]:
		print('need tree')
		flag = 1
		break
if flag == 0:
	if ls == lt:
		print('array')
		flag = 1
if flag == 0:
	index = 0
	match = 0
	for i in t:
		while 1:
			if index >= ls:
				break
			if i == s[index]:
				match = match + 1
				index = index + 1
				break
			else:
				index = index + 1
	if match == lt:
		print('automaton')
	else:
		print('both')


def aut(s, t):
	p = 0
	for i in t:
		f = False
		for j in range(p, len(s)):
			if i == s[j]:
				p = j + 1
				f = True
				break
		if not f:
			return False
	return True

def array(s, t):
	for i in t:
		if t.count(i) > s.count(i):
			return False
	return True
s = input()
t = input()
a = aut(s, t)
b = array(s, t)
if len(s) > len(t):
	if a:
		print('automaton')
	elif b:
		print('both')
	else:
		print('need tree')
elif b:
	print('array')
else:
	print('need tree')


s = input()
t = input()
if len(s) == len(t):
	c = 'array'
	for i in s:
		if i not in t or (i in t and s.count(i) != t.count(i)):
			c = 'need tree'
			break
	print(c)
elif t in s:
	print('automaton')
else:
	c = ''
	j = 0
	a = []
	for i in range(len(s)):
		if s[i] == t[j]:
			j += 1
			c += s[i]
		if j == len(t):
			break
	if c == t:
		print('automaton')
	elif len(c) == len(t):
		print('both')
	else:
		c = ''
		for i in t:
			for j in range(len(s)):
				if i == s[j] and j not in a:
					c += i
					a.append(j)
					break
		if c == t:
			print('both')
		else:
			print('need tree')


def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
s = input()
t = input()
ls = len(s)
lt = len(t)
fs = [0] * 26
ft = [0] * 26
for i in s:
	fs[ord(i) - 97] += 1
for i in t:
	ft[ord(i) - 97] += 1
flag = True
for i in range(0, 26):
	if ft[i] > fs[i]:
		flag = False
if s == t:
	print('array')
elif set(s).intersection(set(t)) == set(t) and ls >= lt and flag:
	if ls > lt:
		sett = set(t)
		st = ''
		for i in s:
			if i in sett:
				st += i
		if isSubSequence(t, st):
			print('automaton')
		else:
			print('both')
	else:
		print('array')
else:
	print('need tree')


def convert_number(x):
	return ord(x) - ord('a')

def solve():
	s1 = input()
	s2 = input()
	len1 = len(s1)
	len2 = len(s2)
	count1 = [0 for i in range(26)]
	count2 = [0 for i in range(26)]
	for i in range(len1):
		count1[convert_number(s1[i])] += 1
	for i in range(len2):
		count2[convert_number(s2[i])] += 1
	if any((count1[i] < count2[i] for i in range(26))):
		print('need tree')
		return
	pos = 0
	for i in range(len2):
		while pos < len1 and s1[pos] != s2[i]:
			pos += 1
		if pos == len1:
			if len1 == len2:
				print('array')
			else:
				print('both')
			return
		pos += 1
	print('automaton')
solve()


from collections import defaultdict
s = str(input())
t = str(input())
d1 = defaultdict(int)
for i in s:
	d1[i] += 1
d2 = defaultdict(int)
for i in t:
	d2[i] += 1
f = 0
for i in d2:
	if d1[i] < d2[i]:
		f = 1
		break
if f == 1:
	print('need tree')
else:
	lens = len(s)
	lent = len(t)
	j = i = 0
	while j != lent and i != lens:
		if s[i] == t[j]:
			j += 1
		i += 1
	if j == lent:
		print('automaton')
	elif lens == lent:
		print('array')
	else:
		print('both')


from collections import Counter

def is_subseq(x, y):
	it = iter(y)
	return all((any((c == ch for c in it)) for ch in x))

def get_ans(s, t):
	sd = Counter(s)
	td = Counter(t)
	if is_subseq(t, s):
		return 'automaton'
	if sd == td:
		return 'array'
	for (k, v) in td.items():
		if k not in sd or sd[k] < td[k]:
			return 'need tree'
	return 'both'
s = input()
t = input()
ans = get_ans(s, t)
print(ans)


def isSubsequence(s, t):
	(i, j) = (0, 0)
	(n, m) = (len(s), len(t))
	while i < n:
		if j < m and s[i] == t[j]:
			j += 1
		i += 1
	return j == m
s = input()
t = input()
(sortedS, sortedT) = (sorted(s), sorted(t))
if isSubsequence(s, t):
	print('automaton')
elif sortedS == sortedT:
	print('array')
elif isSubsequence(sortedS, sortedT):
	print('both')
else:
	print('need tree')


def automaton_solvable(s, t):
	i = -1
	for ch in t:
		i = s.find(ch, i + 1)
		if i < 0:
			return False
	return True
from collections import Counter
(a, b) = (input(), input())
c = Counter(b)
if automaton_solvable(a, b):
	print('automaton')
	exit()
else:
	for i in c:
		if c[i] > a.count(i):
			print('need tree')
			exit()
	print('array' if len(b) == len(a) else 'both')


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
from collections import defaultdict
getcontext().prec = 25
MOD = pow(10, 9) + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
a = input()
b = input()
al = len(a)
bl = len(b)
az = [0] * 26
bz = [0] * 26
for i in range(al):
	az[ord(a[i]) - ord('a')] += 1
for i in range(bl):
	bz[ord(b[i]) - ord('a')] += 1
if al == bl:
	ans = 'array'
	for i in range(26):
		if az[i] - bz[i] != 0:
			ans = 'need tree'
			break
	print(ans)
elif al > bl:
	auto = False
	j = 0
	for i in range(al):
		if j < bl and a[i] == b[j]:
			j += 1
	if j == bl:
		auto = True
	if auto:
		print('automaton')
	else:
		ans = 'both'
		for i in range(26):
			if az[i] - bz[i] < 0:
				ans = 'need tree'
				break
		print(ans)
else:
	print('need tree')


from collections import Counter

def isSubsequence(s, t):
	idx = 0
	for i in s:
		if idx == len(t):
			return True
		if i == t[idx]:
			idx += 1
	return True if idx >= len(t) else False
s = input()
t = input()
if sorted(s) == sorted(t):
	print('array')
elif isSubsequence(s, t):
	print('automaton')
else:
	counter1 = Counter(s)
	counter2 = Counter(t)
	for i in counter2:
		if counter2[i] > counter1[i]:
			print('need tree')
			break
	else:
		print('both')


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def find_parent(parent, i, cnt):
	cnt += 1
	if parent[i - 1] == i:
		return cnt
	if parent[i - 1] != i:
		find_parent(parent, parent[i - 1], cnt)
from collections import Counter
s = input()
t = input()
c1 = Counter(s)
c2 = Counter(t)
if c1 == c2:
	print('array')
else:
	f = 0
	for i in range(len(t)):
		if t[i] not in s:
			f = 1
			break
	if f == 1:
		print('need tree')
	else:
		ptr = 0
		cnt = 0
		f = 0
		for i in range(len(s)):
			if s[i] == t[ptr]:
				cnt += 1
				f = 1
				if ptr < len(t) - 1:
					ptr += 1
				else:
					break
			elif s[i] != t[ptr] and f == 0:
				pass
		if cnt == len(t):
			print('automaton')
		elif c1 & c2 == c2:
			print('both')
		else:
			print('need tree')


s = input()
t = input()
dp = [[0 for i in range(101)] for j in range(101)]
finish = False
for i in range(len(s)):
	for j in range(len(t)):
		if s[i] == t[j]:
			dp[i + 1][j + 1] = dp[i][j] + 1
		else:
			dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])
if dp[len(s)][len(t)] >= len(t):
	print('automaton')
	finish = True
s = sorted(s, key=ord)
t = sorted(t, key=ord)
dp = [[0 for i in range(101)] for j in range(101)]
for i in range(len(s)):
	for j in range(len(t)):
		if s[i] == t[j]:
			dp[i + 1][j + 1] = dp[i][j] + 1
		else:
			dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])
if dp[len(s)][len(t)] >= len(t) and (not finish):
	if len(s) == len(t):
		print('array')
	else:
		print('both')
elif not finish:
	print('need tree')


(s, t) = (input(), input())
(u, v) = (sorted(s), sorted(t))

def subset(a, b):
	i = 0
	for c in a:
		if i < len(b) and c == b[i]:
			i += 1
	return i == len(b)
if u == v:
	print('array')
elif subset(s, t):
	print('automaton')
elif subset(u, v):
	print('both')
else:
	print('need tree')


def check_t_in_s(s, t):
	i = j = 0
	t_in_s = True
	while j < len(t):
		if s[i] == t[j]:
			j += 1
		i += 1
		if i == len(s) and j < len(t):
			t_in_s = False
			break
	return t_in_s

def solve_suffix_structures(s, t):
	if check_t_in_s(s, t):
		return 'automaton'
	ls = [c for c in s]
	lt = [c for c in t]
	ls.sort()
	lt.sort()
	if check_t_in_s(ls, lt):
		return 'array' if len(lt) == len(ls) else 'both'
	return 'need tree'
s = input()
t = input()
print(solve_suffix_structures(s, t))


s = input()
t = input()
x = 0
for i in range(len(s)):
	if s[i] == t[x]:
		x += 1
		if x == len(t):
			print('automaton')
			exit()
T = sorted(t)
S = sorted(s)
if T == S:
	print('array')
	exit()
x = 0
for i in range(len(S)):
	if S[i] == T[x]:
		x += 1
		if x == len(t):
			print('both')
			exit()
print('need tree')


s = input()
t = input()
if len(s) < len(t):
	print('need tree')
elif len(s) == len(t):
	d = {}
	for i in s:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	for j in t:
		if j not in d:
			break
		elif d[j] >= 1:
			d[j] -= 1
		else:
			break
	if sum(d.values()) == 0:
		print('array')
	else:
		print('need tree')
elif t in s:
	print('automaton')
else:
	count = int(len(t))
	d = {}
	for i in s:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	for j in t:
		if j not in d:
			break
		elif d[j] >= 1:
			d[j] -= 1
			count -= 1
		else:
			break
	if count == 0:
		s_t = []
		i = 0
		j = 0
		while i < len(s) and j < len(t):
			if s[i] == t[j]:
				s_t.append(s[i])
				i += 1
				j += 1
			else:
				i += 1
		if ''.join(s_t) == t:
			print('automaton')
		else:
			print('both')
	else:
		print('need tree')


from collections import Counter

def check(s, t):
	length = 0
	for i in range(len(s)):
		if length < len(t) and s[i] == t[length]:
			length += 1
	if length == len(t):
		return True
	else:
		return False
s = input()
t = input()
automaton = False
array = False
if check(s, t) is True:
	automaton = True
elif len(s) - len(t) == sum((Counter(s) - Counter(t)).values()):
	if len(s) > len(t):
		automaton = True
	array = True
if automaton and array:
	print('both')
elif automaton:
	print('automaton')
elif array:
	print('array')
else:
	print('need tree')


s = input().strip()
t = input().strip()
a = [s.count(chr(ord('a') + i)) for i in range(26)]
b = [t.count(chr(ord('a') + i)) for i in range(26)]
c = 0
for i in s:
	if c < len(t) and t[c] == i:
		c += 1
if c == len(t):
	print('automaton')
elif all((a[i] == b[i] for i in range(26))):
	print('array')
elif all((a[i] >= b[i] for i in range(26))):
	print('both')
else:
	print('need tree')


from sys import stdin
import sys
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
from collections import Counter
(s, t) = (g(), g())
ans = 'need tree'
match = True
(fs, ft) = (Counter(s), Counter(t))
for char in ft:
	if ft[char] > fs.get(char, 0):
		match = False
		break
if match:
	idx = 0
	for i in range(len(s)):
		if idx == len(t):
			break
		elif t[idx] == s[i]:
			idx += 1
	if idx == len(t):
		ans = 'automaton'
	elif len(s) == len(t):
		ans = 'array'
	else:
		ans = 'both'
print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.setrecursionlimit(int(pow(10, 6)))
	sys.stdin = open('input.txt', 'r')
except:
	pass
s = input()
t = input()
i = 0
j = 0
while j < len(t) and i < len(s):
	if s[i] == t[j]:
		i += 1
		j += 1
	else:
		i += 1
if j == len(t):
	print('automaton')
else:
	d = {}
	d1 = {}
	for c in s:
		d[c] = d.get(c, 0) + 1
	for c in t:
		d1[c] = d1.get(c, 0) + 1
	pos = 1
	for k in d1:
		if d.get(k, 0) < d1[k]:
			pos = 0
			break
	if pos:
		if len(s) == len(t):
			print('array')
		else:
			print('both')
	else:
		print('need tree')
endtime = time.time()


def main():
	(s, t) = (input(), input())
	(ls, lt) = (sorted(s), sorted(t))
	if ls == lt:
		print('array')
		return
	it = iter(s)
	res = False
	try:
		for b in t:
			a = next(it)
			while a != b:
				a = next(it)
		print('automaton')
		return
	except StopIteration:
		pass
	it = iter(ls)
	try:
		for b in lt:
			a = next(it)
			while a != b:
				a = next(it)
		print('both')
		return
	except StopIteration:
		print('need tree')
main()


s = input()
t = input()
i = 0
j = 0
ans = ''
while i < len(s) and j < len(t):
	if s[i] == t[j]:
		i += 1
		j += 1
	elif s[i] != t[j]:
		i += 1
	if j == len(t):
		ans = 'automaton'
		break
if not len(ans):
	B = list(s)
	C = list(t)
	B.sort()
	C.sort()
	if B == C:
		ans = 'array'
if not len(ans):
	a = 0
	for i in t:
		if s.count(i) >= t.count(i):
			a += 1
	if len(s) > len(t) and a == len(t):
		ans = 'both'
if not len(ans):
	ans = 'need tree'
print(ans)


def f(s, t):
	c = 0
	a = len(s)
	b = len(t)
	for i in range(a):
		if c < b and s[i] == t[c]:
			c += 1
	return c == b
s = input()
t = input()
ss = sorted(s)
st = sorted(t)
ss = ''.join(ss)
st = ''.join(st)
if f(s, t):
	print('automaton')
elif ss == st:
	print('array')
elif f(ss, st):
	print('both')
else:
	print('need tree')