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: interview

Starter code:

Solutions:
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")


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()


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')
	return
 
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')
		return
if sum(num) > 0:
	print('both')
else:
	print('array')

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")				


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()
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')
    return
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')
    return
for x in num :
    if x < 0 :
        print('need tree')
        break
else :
    print('both')


"""
Codeforces Round 256 Div 2 Problem B

Author  : chaotic_iak
Language: Python 3.3.4
"""

def read(mode=2):
    # 0: String
    # 1: List of strings
    # 2: List of integers
    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="")

################################################### SOLUTION
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):

    # automaton check
    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])

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().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')
    return
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')
        return
if boo:
    print('array')
else:
    print('both')

s=input()
t=input()
array=automaton=both=1

# array swapaet
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')
    return

# automaton dalyaet
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')
    return

# both
for i in let:
    if s.count(i) < t.count(i):
        both=0
if both:
    print('both')
    return

# else
print('need tree')


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')


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")


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, 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()
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 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')

def isAuto(s, t):
    j = 0
    for i in range(len(s)):
        if s[i] == t[j]: j += 1
        if j == len(t):
            return True
    return False
def isArray(s, t):
    sarr = [0] * 256
    tarr = [0] * 256
    for i in range(len(s)): sarr[ord(s[i])] += 1
    for i in range(len(t)): tarr[ord(t[i])] += 1
    for i in range(256):
        if sarr[i] != tarr[i]:
            return False
    return True
def isBoth(s, t):
    sarr = [0] * 256
    tarr = [0] * 256
    for i in range(len(s)): sarr[ord(s[i])] += 1
    for i in range(len(t)): tarr[ord(t[i])] += 1
    for i in range(256):
        if sarr[i] < tarr[i]:
            return False
    return True

s = input()
t = input()
if isAuto(s, t):
    print("automaton")
elif isArray(s, t):
    print("array")
elif isBoth(s, t):
    print("both")
else:
    print("need tree")

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')

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")
else:
    if 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 = 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")

import sys

#ist s1 ein substring von s2, d.h. sind alle Buchstaben von s1 in s2 enthalten?
def substring(s1,s2):
  s2copy = list(s2)
  s1copy = list(s1)
  for i in s1copy:
    try:
      s2copy.remove(i)
    except:
      #print(i,s2copy)
      return False
  return True 

#ist s1 ein sortedsubstring von s2, d.h. kann man durch löschen von Buchstaben s1 aus s2 erzeugen?
def sortedsubstring(s1,s2):
  if not substring(s1,s2):
    return False #nicht mal substring
  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")

 


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()
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 f(a, b):
    j, n = 0, len(b)
    for i in a:
        if i == b[j]:
            j += 1
            if j == n: return True
    return False
a, b = input(), input()
t = [0] * 26
for i in a: t[ord(i) - 97] += 1
for i in b: t[ord(i) - 97] -= 1
if any(i < 0 for i in t): print('need tree')
elif len(b) == len(a): print('array')
elif f(a, b): print('automaton')
else: print('both')