After a long day, Alice and Bob decided to play a little game. The game board consists of $n$ cells in a straight line, numbered from $1$ to $n$, where each cell contains a number $a_i$ between $1$ and $n$. Furthermore, no two cells contain the same number. 

A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell $i$ to cell $j$ only if the following two conditions are satisfied:   the number in the new cell $j$ must be strictly larger than the number in the old cell $i$ (i.e. $a_j > a_i$), and  the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. $|i-j|\bmod a_i = 0$). 

Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.


-----Input-----

The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of numbers.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). Furthermore, there are no pair of indices $i \neq j$ such that $a_i = a_j$.


-----Output-----

Print $s$ — a string of $n$ characters, where the $i$-th character represents the outcome of the game if the token is initially placed in the cell $i$. If Alice wins, then $s_i$ has to be equal to "A"; otherwise, $s_i$ has to be equal to "B". 


-----Examples-----
Input
8
3 6 5 4 2 7 1 8

Output
BAAAABAB

Input
15
3 11 2 5 10 9 7 13 15 8 4 12 6 1 14

Output
ABAAAABBBAABAAB



-----Note-----

In the first sample, if Bob puts the token on the number (not position):   $1$: Alice can move to any number. She can win by picking $7$, from which Bob has no move.  $2$: Alice can move to $3$ and $5$. Upon moving to $5$, Bob can win by moving to $8$. If she chooses $3$ instead, she wins, as Bob has only a move to $4$, from which Alice can move to $8$.  $3$: Alice can only move to $4$, after which Bob wins by moving to $8$.  $4$, $5$, or $6$: Alice wins by moving to $8$.  $7$, $8$: Alice has no move, and hence she loses immediately.

Difficulty: MEDIUM_HARD
Tags: Dynamic programming

Game theory

Complete search
Skill types: Dynamic programming

Complete search
Expected Time Complexity: O(NLOG(N))

Starter code:

Solutions:
n = int(input())
a = list(map(int, input().split()))
pos = [0 for i in range(n + 1)]
for i in range(n):
	pos[a[i]] = i
dp = [0 for i in range(n + 1)]
for i in range(n - 1, 0, -1):
	j = pos[i]
	for k in range(j, n, i):
		if a[k] > i:
			if dp[a[k]] == 0:
				dp[i] = 1
	for k in range(j, -1, -i):
		if a[k] > i:
			if dp[a[k]] == 0:
				dp[i] = 1
for i in range(n):
	if dp[a[i]] == 0:
		print('B', end='')
	else:
		print('A', end='')


from functools import lru_cache

def read_int():
	return int(input().strip())

def read_ints():
	return list(map(int, input().strip().split(' ')))

def solve():
	N = read_int()
	a = read_ints()

	@lru_cache(None)
	def dp(i):
		for j in range(i % a[i], N, a[i]):
			if j == i:
				continue
			if a[j] > a[i] and (not dp(j)):
				return True
		return False
	return ''.join(('A' if dp(i) else 'B' for i in range(N)))
print(solve())


N = int(input())
a = list(map(int, input().split()))
rec = ['+'] * N
P = [0] * N
for i in range(N):
	P[a[i] - 1] = i
for i in range(N, 0, -1):
	j = P[i - 1]
	rec[j] = 'B'
	for k in range(j % i, N, i):
		if j != k and a[j] <= a[k] and (rec[k] == 'B'):
			rec[j] = 'A'
			break
print(''.join(map(str, rec)))


n = int(input())
a = [*map(int, input().split())]
b = [0] * n
for i in range(n):
	b[n - a[i]] = i
s = [0] * n
for (i, j) in enumerate(b):
	i = n - i
	s[j] = 'BA'[any((a[k] > a[j] and s[k] == 'B' for k in range(j % i, n, i)))]
print(''.join(s))


i = m = n = int(input())
a = [*map(int, input().split())]
s = [0] * n
r = [range(i % a[i], n, a[i]) for i in range(n)]
while m:
	i = (i - 1) % n
	if s[i] == 0:
		if all((a[j] <= a[i] or s[j] == 'A' for j in r[i])):
			s[i] = 'B'
			m -= 1
		if any((a[j] > a[i] and s[j] == 'B' for j in r[i])):
			s[i] = 'A'
			m -= 1
print(''.join(s))


import sys
input = sys.stdin.readline
n = int(input())
arr = [int(x) for x in input().split()]
both = []
for i in range(n):
	both.append([arr[i], i])
both.sort(reverse=True)
color = [-1] * n
for (val, index) in both:
	done = False
	for i in range(index + val, n, val):
		if done:
			break
		if color[i] == 1:
			done = True
			color[index] = 0
	for i in range(index - val, -1, -val):
		if done:
			break
		if color[i] == 1:
			done = True
			color[index] = 0
	if not done:
		color[index] = 1
ans = ''
for i in color:
	if i:
		ans += 'B'
	else:
		ans += 'A'
print(ans)


n = int(input())
x = list(map(int, input().split()))
dp = [0] * n
m = [0] * (n + 1)
for i in range(n):
	m[x[i]] = i
for i in range(n, 0, -1):
	for i2 in range(m[i] + i, n, i):
		if i < x[i2] and dp[i2] == 0:
			dp[m[i]] = 1
	for i2 in range(m[i] - i, -1, -i):
		if i < x[i2] and dp[i2] == 0:
			dp[m[i]] = 1
for i in range(n):
	if dp[i] == 0:
		print('B', end='')
	else:
		print('A', end='')


from sys import stdin
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
b = [0] * (n + 1)
for i in range(n):
	b[a[i]] = i
c = [False] * n
for i in range(n, 0, -1):
	j = i
	w = False
	while b[i] + j < n and w == False:
		w = c[b[i] + j]
		j += i
	j = i
	while b[i] - j >= 0 and w == False:
		w = c[b[i] - j]
		j += i
	c[b[i]] = not w
ans = []
for i in range(n):
	ans.append(['A', 'B'][c[i]])
print(*ans, sep='')


from sys import stdin, setrecursionlimit
from itertools import combinations
setrecursionlimit(200000)

def reverse_check_big(string, index):
	temp = string[:index + 1]
	forward = ''.join(temp)
	reverse = ''.join(temp[::-1])
	if reverse > forward:
		return True
	else:
		return False

def change(string, index):
	temp = string[:index + 1]
	temp = temp[::-1]
	for i in range(index + 1):
		string[i] = temp[i]

def reverse_check_small(string, index):
	temp = string[:index + 1]
	forward = ''.join(temp)
	reverse = ''.join(temp[::-1])
	if reverse < forward:
		return True
	else:
		return False

def find_smaller_index(string, index):
	malph = 'z'
	ans = -1
	for i in range(index + 1):
		if string[i] <= malph:
			malph = string[i]
			ans = i
	return ans

def find_bigger_index(string, index):
	malph = 'a'
	ans = -1
	for i in range(index + 1):
		if string[i] >= malph:
			malph = string[i]
			ans = i
	return ans

def make(first, second):
	return str(first) + ' ' + str(second)
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
mydict = dict()
for i in range(n):
	mydict[arr[i]] = i + 1
ans = dict()
ans[mydict[n]] = 'B'
for i in range(n - 1, 0, -1):
	num = i
	index = mydict[num]
	flag = 0
	for j in range(index + num, n + 1, num):
		if j in ans and ans[j] == 'B':
			ans[index] = 'A'
			flag = 1
			break
	else:
		ans[index] = 'B'
	if flag == 0:
		for j in range(index - num, 0, -num):
			if j in ans and ans[j] == 'B':
				ans[index] = 'A'
				break
		else:
			ans[index] = 'B'
for i in range(1, n + 1):
	print(ans[i], end='')


n = int(input())
L = list(map(int, input().split()))
ans = [''] * n
revL = [0] * n
ans[-1] = 'B'
for i in range(n):
	revL[L[i] - 1] = i + 1
for i in range(n - 2, -1, -1):
	t = revL[i] - 1
	counter = 'B'
	for j in range(t, -1, -i - 1):
		if j == t:
			continue
		if ans[L[j] - 1] == 'B':
			counter = 'A'
			break
	if counter != 'A':
		for k in range(t, n, i + 1):
			if k == t:
				continue
			if ans[L[k] - 1] == 'B':
				counter = 'A'
				break
	ans[i] = counter
for i in range(n):
	print(ans[L[i] - 1], sep='', end='')


n = int(input())
a = [int(s) for s in input().split()]
ans = [None] * n

def get(p):
	if ans[p] is not None:
		return ans[p]
	elif a[p] == 1:
		ans[p] = 'A'
	elif a[p] == n:
		ans[p] = 'B'
	else:
		for i in range(p + a[p], n, a[p]):
			if a[i] > a[p]:
				if get(i) == 'B':
					ans[p] = 'A'
					return ans[p]
		for i in range(p - a[p], -1, -a[p]):
			if a[i] > a[p]:
				if get(i) == 'B':
					ans[p] = 'A'
					return ans[p]
		ans[p] = 'B'
	return ans[p]
if n == 1:
	print('B')
else:
	for i in range(n - 1, -1, -1):
		get(i)
	print(''.join(ans))


n = int(input())
a = [int(x) for x in input().split()]
a_reverse = a.copy()
status = []
for i in range(n):
	a_reverse[a[i] - 1] = i
	status.append(None)
pos = a_reverse[n - 1]
status[pos] = False
fails = set()
fails.add(pos)
for i in range(n - 1, 0, -1):
	i_ = i - 1
	pos = a_reverse[i_]
	for k in range((pos + 1) % i - 1, n, i):
		if k == pos:
			continue
		if k in fails:
			status[pos] = True
			break
	if not status[pos]:
		status[pos] = False
		fails.add(pos)
result = ''
for i in status:
	if i == True:
		result = result + 'A'
	else:
		result = result + 'B'
print(result)


n = int(input())
a = list(map(int, input().split(' ')))
if n == 1:
	print('B')
	exit()
indices = [0 for i in range(n + 1)]
for i in range(1, n + 1):
	indices[a[i - 1]] = i
steps = [0 for i in range(n + 1)]
steps[1] = 1
existing = {}
existing[indices[n]] = steps[n]
existing[indices[1]] = steps[1]
for i in range(n - 1, 1, -1):
	index = indices[i]
	k = i
	while True:
		if index - k < 1 and index + k > n:
			existing[index] = steps[i]
			break
		else:
			if existing.get(index - k) is not None and existing[index - k] == 0:
				steps[i] = 1
				existing[index] = steps[i]
				break
			if existing.get(index + k) is not None and existing[index + k] == 0:
				steps[i] = 1
				existing[index] = steps[i]
				break
		k += i
ans = ['A' for i in range(n)]
for i in existing.keys():
	if existing[i] == 0:
		ans[i - 1] = 'B'
print(''.join(ans))


n = int(input())
a = [*map(int, input().split())]
s = [0] * n
t = set(range(n))
while t:
	q = set()
	for i in t:
		x = a[i]
		r = range(i % x, n, x)
		if all((a[j] <= x or s[j] == 'A' for j in r)):
			s[i] = 'B'
			q |= {i}
		if any((a[j] > x and s[j] == 'B' for j in r)):
			s[i] = 'A'
			q |= {i}
	t -= q
print(''.join(s))


from __future__ import print_function
from collections import *
from sys import stdin
from bisect import *
from heapq import *
from math import log2, ceil, sqrt
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()]
rr = lambda x: reversed(range(x))
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
a = gil()
idx = list(range(n))
idx.sort(key=lambda x: a[x], reverse=True)
ans = [0] * n
for i in idx:
	j = i + a[i]
	while j < n and ans[i] == 0:
		if a[j] > a[i] and ans[j] == 0:
			ans[i] = 1
		j += a[i]
	j = i - a[i]
	while ans[i] == 0 and j >= 0:
		if a[j] > a[i] and ans[j] == 0:
			ans[i] = 1
		j -= a[i]
val = ['B', 'A']
for i in range(n):
	ans[i] = val[ans[i]]
print(''.join(ans))


import collections
N = int(input())
A = [int(x) for x in input().split()]
grev = collections.defaultdict(set)
g = collections.defaultdict(set)
degree = collections.defaultdict(int)
for i in range(N):
	d = 0
	for j in range(i + A[i], N, A[i]):
		if A[j] > A[i]:
			grev[j].add(i)
			g[i].add(j)
			d += 1
	for j in range(i - A[i], -1, -A[i]):
		if A[j] > A[i]:
			grev[j].add(i)
			g[i].add(j)
			d += 1
	degree[i] = d
ans = [0] * N
left = {i for i in range(N)}
while left:
	used = set()
	for v in left:
		if degree[v] == 0:
			if all([ans[i] == 2 for i in g[v]] or [True]):
				ans[v] = 1
			else:
				ans[v] = 2
			used.add(v)
	for v in used:
		for u in grev[v]:
			degree[u] -= 1
	left -= used
print(''.join(['B' if ans[i] == 1 else 'A' for i in range(N)]))


n = int(input())
l = [*map(int, input().split())]
p = [0] * n
for i in range(n):
	p[l[i] - 1] = i
res = ['?'] * n
for e in range(n, 0, -1):
	i = p[e - 1]
	res[i] = 'B'
	for j in range(i % e, n, e):
		if i != j and l[i] <= l[j] and (res[j] == 'B'):
			res[i] = 'A'
			break
print(''.join(res))


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
PLACE = [None] * (n + 1)
for i in range(n):
	PLACE[A[i]] = i
al = n
WINLIST = [None] * (n + 1)

def move(n, al):
	place = PLACE[n]
	for i in range(place, -1, -n):
		if A[i] > n and WINLIST[A[i]] == 'B':
			WINLIST[n] = 'A'
			return
	for i in range(place, al, n):
		if A[i] > n and WINLIST[A[i]] == 'B':
			WINLIST[n] = 'A'
			return
	else:
		WINLIST[n] = 'B'
		return
for j in range(n, 0, -1):
	move(j, al)
ANS = ''
for i in A:
	ANS += WINLIST[i]
print(ANS)


n = int(input())
arr = list(map(int, input().split()))
memo = [-1 for i in range(n + 1)]

def can_win(idx):
	if memo[idx] != -1:
		return memo[idx]
	res = False
	delta = arr[idx]
	nidx = idx + delta
	while nidx < n:
		if arr[nidx] > arr[idx] and (not can_win(nidx)):
			res = True
			break
		nidx += delta
	nidx = idx - delta
	while not res and nidx >= 0:
		if arr[nidx] > arr[idx] and (not can_win(nidx)):
			res = True
			break
		nidx -= delta
	memo[idx] = res
	return res
ans = ['A' if can_win(i) else 'B' for i in range(n)]
print(''.join(ans))


from math import ceil
n = int(input())
r = list(map(int, input().split()))
l = [-1]
l.extend(r)
a = [''] * (n + 1)
d = {}
rd = {}
ind = {}
for i in range(1, n + 1):
	x = l[i]
	ind[x] = i
	d.setdefault(i, [])
	s = x + i
	while s <= n:
		if l[s] > x:
			d[i].append(s)
			if s not in rd:
				rd[s] = []
			rd[s].append(i)
		s += x
	s = i - x
	while s >= 1:
		if l[s] > x:
			d[i].append(s)
		s -= x
ans = 0
for i in d:
	if len(d[i]) == 0:
		a[i] = 'B'
		ans += 1
while ans != n:
	for i in d:
		dont = False
		if a[i] != '':
			continue
		for j in d[i]:
			if a[j] == 'B':
				a[i] = 'A'
				ans += 1
				break
			if a[j] == '':
				dont = True
		else:
			if not dont:
				a[i] = 'B'
				ans += 1
print(''.join(a))


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(range(n), key=lambda x: a[x], reverse=True)
	dp = [0] * n
	for i in range(n):
		f = 1
		for j in range(b[i] % a[b[i]], n, a[b[i]]):
			if dp[j] == -1:
				f = 0
				break
		if f:
			dp[b[i]] = -1
	print(''.join(map(lambda x: 'B' if x == -1 else 'A', dp)))
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')
main()


def f(k):
	if an[k] != -1:
		return an[k]
	z = a[k]
	ans = 'B'
	for i in range(k, -1, -z):
		if a[i] > z:
			if f(i) == 'B':
				ans = 'A'
	for i in range(k, n, z):
		if a[i] > z:
			if f(i) == 'B':
				ans = 'A'
	an[k] = ans
	return ans
n = int(input())
a = list(map(int, input().split()))
an = [-1] * n
for i in range(n):
	f(i)
print(''.join(an))


n = int(input())
arr = [int(x) for x in input().split()]
pos = dict()
if n == 1:
	print('B')
else:
	for i in range(n):
		pos[arr[i]] = i
	ans = ['Q'] * n
	ans[pos[1]] = 'A'
	ans[pos[n]] = 'B'
	for i in range(n - 1, 0, -1):
		flag = 0
		p = pos[i]
		j = 1
		while p + j * i < n:
			if ans[p + j * i] == 'B':
				flag = 1
				ans[pos[i]] = 'A'
				break
			j += 1
		if flag == 0:
			j = 1
			while p - j * i >= 0:
				if ans[p - j * i] == 'B':
					flag = 1
					ans[pos[i]] = 'A'
					break
				j += 1
		if flag == 0:
			ans[pos[i]] = 'B'
	print(''.join(ans))


import sys
input = sys.stdin.readline
from collections import deque, defaultdict
n = int(input())
a = list(map(int, input().split()))
ins = [0] * n
outs = defaultdict(list)
for i in range(n):
	for j in range(i, n, a[i]):
		if a[j] > a[i]:
			ins[i] += 1
			outs[j].append(i)
	for j in range(i, -1, -a[i]):
		if a[j] > a[i]:
			ins[i] += 1
			outs[j].append(i)
q = deque([v for v in range(n) if ins[v] == 0])
res = [False] * n
while q:
	v = q.popleft()
	for nv in outs[v]:
		res[nv] |= not res[v]
		ins[nv] -= 1
		if ins[nv] == 0:
			q.append(nv)
ans = ['A' if res_i else 'B' for res_i in res]
print(''.join(ans))


n = int(input())
a = [int(i) for i in input().split()]
indx = [0] * n
winners = [''] * n
for (i, ai) in enumerate(a):
	indx[ai - 1] = i
for ai in range(n, 0, -1):
	i = indx[ai - 1]
	can_win = False
	for j in range(i + ai, n, ai):
		if a[j] > ai and 'B' == winners[j]:
			can_win = True
			break
	if not can_win:
		for j in range(i - ai, -1, -ai):
			if a[j] > ai and 'B' == winners[j]:
				can_win = True
				break
	if can_win:
		winners[i] = 'A'
	else:
		winners[i] = 'B'
print(''.join(winners))


def f(k):
	if mem[k] != -1:
		return mem[k]
	t = a[k]
	ans = 'B'
	for i in range(k, -1, -t):
		if a[i] > t:
			if f(i) == 'B':
				ans = 'A'
	for i in range(k, n, t):
		if a[i] > t:
			if f(i) == 'B':
				ans = 'A'
	mem[k] = ans
	return ans
n = int(input())
a = list(map(int, input().split()))
mem = [-1] * n
for i in range(n):
	f(i)
print(''.join(mem))


import sys
cin = sys.stdin
n = int(next(cin))
a = list(map(int, next(cin).split()))
n2idx = {a[i]: i for i in range(n)}
f = [False] * (n + 1)
for i in range(n, 0, -1):
	idx_lg = n2idx[i]
	win_flag = False
	for j in range(idx_lg % i, n, i):
		if a[j] > i and (not f[a[j]]):
			win_flag = True
			break
	f[i] = win_flag
f = ''.join(['A' if f[a_i] else 'B' for a_i in a])
print(f, flush=True)


n = int(input())
a = [int(x) for x in input().split()]
ans = [''] * n
b = [0] * n
for i in range(n):
	b[n - a[i]] = i
for i in range(len(b)):
	t = b[i] % (n - i)
	f = 0
	for j in range(t, n, n - i):
		if ans[j] == 'B' and a[j] > n - i:
			ans[b[i]] = 'A'
			f = 1
			break
	if f == 0:
		ans[b[i]] = 'B'
print(''.join(ans))


import sys
input = sys.stdin.readline
out = sys.stdout
n = int(input())
a = list(map(int, input().split()))
pos = [0] * n
for i in range(n):
	a[i] -= 1
	pos[a[i]] = i
win = ['?'] * n
for x in range(n - 1, -1, -1):
	i = pos[x]
	win[i] = 'B'
	j = i
	while True:
		j -= x + 1
		if j < 0:
			break
		if win[j] == 'B':
			win[i] = 'A'
			break
	j = i
	while True:
		j += x + 1
		if j >= n:
			break
		if win[j] == 'B':
			win[i] = 'A'
			break
for k in win:
	out.write(k)


n = int(input())
a = list(map(int, input().split()))
b = sorted(((x, i) for (i, x) in enumerate(a)))
c = ['B'] * n
while b:
	(x, i) = b.pop()
	for j in range(i % x, n, x):
		if a[j] > a[i] and 'B' == c[j]:
			c[i] = 'A'
			break
print(''.join(c))


from collections import deque
from sys import stdin
lines = deque((line.strip() for line in stdin.readlines()))

def nextline():
	return lines.popleft()

def types(cast, sep=None):
	return tuple((cast(x) for x in strs(sep=sep)))

def ints(sep=None):
	return types(int, sep=sep)

def strs(sep=None):
	return tuple(nextline()) if sep == '' else tuple(nextline().split(sep=sep))

def main():
	n = int(nextline())
	a = ints()
	bs = set()
	moves = {}
	for i in range(n):
		moves[a[i]] = list((a[j] for j in range(i % a[i], n, a[i]) if a[j] > a[i]))
	winners = {}
	for i in range(n, 0, -1):
		winner = 'A' if any((winners[j] == 'B' for j in moves[i])) else 'B'
		if winner == 'B':
			bs.add(i)
		winners[i] = winner
	print(''.join((winners[ai] for ai in a)))

def __starting_point():
	main()
__starting_point()


(n, a) = (int(input()), list(map(int, input().split())))
(mem, arr) = ([''] * (n + 1), [0] * n)
for i in range(n):
	arr[a[i] - 1] = i
	if a[i] == n:
		mem[i] = 'B'
for i in arr[n - 2::-1]:
	flag = -1
	for j in range(i + a[i], n, a[i]):
		if mem[j] == 'B':
			flag = j
			break
	if flag != -1:
		mem[i] = 'A'
	else:
		for j in range(i - a[i], -1, -a[i]):
			if mem[j] == 'B':
				flag = j
				break
	if flag != -1:
		mem[i] = 'A'
	else:
		mem[i] = 'B'
print(''.join(mem))


import sys
n = int(input())
arr = list(map(int, input().split()))
if n == 1:
	print('B')
	sys.exit()
ind = [0] * (n + 1)
for i in range(n):
	ind[arr[i]] = i
l = [False] * (n + 1)
l[1] = True
for i in range(n - 1, 1, -1):
	f = ind[i] - i
	trig = False
	while f >= 0:
		if arr[f] > i:
			if l[arr[f]] == False:
				l[i] = True
				break
		f -= i
	f = ind[i] + i
	while f <= n - 1:
		if arr[f] > i:
			if l[arr[f]] == False:
				l[i] = True
				break
		f += i
s = ['B'] * n
for i in range(n):
	if l[arr[i]]:
		s[i] = 'A'
print(''.join(s))


n = int(input())
a = [int(i) for i in input().split()]
s = ['.' for _ in range(n)]
v = 0
t = set(range(n))
while v < n:
	for i in range(n):
		if s[i] != '.':
			continue
		r = range(i % a[i], n, a[i])
		if all((a[j] <= a[i] or s[j] == 'A' for j in r)):
			s[i] = 'B'
			v += 1
		if any((a[j] > a[i] and s[j] == 'B' for j in r)):
			s[i] = 'A'
			v += 1
print(''.join(s))


n = int(input())
a = list(map(int, input().split()))
p = [0] * (n + 2)
m = [0] * (n + 2)
for i in range(n):
	p[a[i]] = i
for i in range(n, 0, -1):
	j = p[i] % i
	while j < n and m[i] == 0:
		m[i] = i < a[j] and m[a[j]] == 0
		j += i
for i in range(n):
	print('BA'[m[a[i]]], end='')


import sys
from functools import lru_cache
n = int(input())
a = [int(x) for x in input().split()]
m = a.index(max(a))
if n == 1:
	print('B')
	exit()
sys.setrecursionlimit(100000)

@lru_cache(None)
def dp(i):
	if i == m:
		return 0
	else:
		for j in range(i + a[i], n, a[i]):
			if a[j] > a[i] and dp(j) == 0:
				return 1
		for j in range(i - a[i], -1, -a[i]):
			if a[j] > a[i] and dp(j) == 0:
				return 1
		return 0
an = ['B', 'A']
for j in range(len(a)):
	print(an[dp(j)], end='')
print()


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
p = [[a[i], i] for i in range(n)]
p.sort(reverse=True)
lose = [0] * n
for (v, x) in p:
	lose[x] = 1
	for i in range(1, n):
		y = x + i * a[x]
		if y >= n:
			break
		if a[y] > a[x] and lose[y]:
			lose[x] = 0
	for i in range(1, n):
		y = x - i * a[x]
		if y < 0:
			break
		if a[y] > a[x] and lose[y]:
			lose[x] = 0
ans = []
for i in range(n):
	if lose[i]:
		ans.append('B')
	else:
		ans.append('A')
print(''.join(ans))


n = int(input())
a = list(map(int, input().split()))
res = []
dp = [-1] * n

def helper(i):
	if dp[i] != -1:
		return dp[i]
	cur = True
	std = a[i]
	while i + std < n:
		if a[i] < a[i + std]:
			cur = cur and helper(i + std)
		std += a[i]
	std = a[i]
	while i - std >= 0:
		if a[i] < a[i - std]:
			cur = cur and helper(i - std)
		std += a[i]
	if cur:
		dp[i] = 0
	else:
		dp[i] = 1
	return dp[i]
for i in range(n):
	if helper(i):
		res.append('A')
	else:
		res.append('B')
print(''.join(res))


import sys
input = sys.stdin.readline

def find(x):
	global dp
	if len(adj[x]) == 0:
		dp[x] = False
		return False
	else:
		if dp[x] != -1:
			return dp[x]
		ans = False
		for neighbor in adj[x]:
			ans |= not find(neighbor)
		dp[x] = ans
		return dp[x]
n = int(input().strip())
arr = list(map(int, input().strip().split()))
adj = {}
for i in range(n):
	lis = []
	for j in range(i + arr[i], n, arr[i]):
		if arr[j] > arr[i] and (j - i) % arr[i] == 0:
			lis.append(arr[j])
	for j in range(i - arr[i], -1, -arr[i]):
		if arr[j] > arr[i] and (i - j) % arr[i] == 0:
			lis.append(arr[j])
	adj[arr[i]] = lis
dp = [-1 for i in range(n + 1)]
for i in range(n):
	dp[arr[i]] = find(arr[i])
for x in arr:
	print('A' if dp[x] else 'B', end='')


n = int(input())
a = [int(x) for x in input().split()]
h = [-1] * n
b = [(a[i], i) for i in range(n)]
b.sort(reverse=True)
for e in b:
	(num, idx) = e
	flag = True
	allNeg = True
	foundLosing = False
	foundWin = False
	for i in range(idx % num, n, num):
		if i == idx:
			continue
		if h[i] != -1:
			allNeg = False
		if h[i] == 0:
			foundLosing = True
			break
		if h[i] == 1:
			foundWin = False
	if allNeg:
		h[idx] = 0
	elif foundLosing:
		h[idx] = 1
	else:
		h[idx] = 0
for i in range(n):
	if h[i] == 0:
		print('B', end='')
	else:
		print('A', end='')


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
pos = [0] * n
for i in range(n):
	a[i] -= 1
	pos[a[i]] = i
win = ['?'] * n
for x in range(n - 1, -1, -1):
	i = pos[x]
	win[i] = 'B'
	j = i
	while True:
		j -= x + 1
		if j < 0:
			break
		if win[j] == 'B':
			win[i] = 'A'
			break
	j = i
	while True:
		j += x + 1
		if j >= n:
			break
		if win[j] == 'B':
			win[i] = 'A'
			break
for k in win:
	print(k, end='')


def solve(n, a):
	ainv = {}
	for i in range(1, n + 1):
		ainv[a[i - 1]] = i
	sol = {}
	for i in range(n, 0, -1):
		ai = ainv[i]
		j = (ai - 1) % i + 1
		while j <= n:
			if j in sol and sol[j] == 'B':
				sol[ai] = 'A'
				break
			j += i
		else:
			sol[ai] = 'B'
	return ''.join([sol[i] for i in range(1, n + 1)])
n = int(input().strip())
a = list(map(int, input().strip().split()))
print(solve(n, a))


n = int(input())
arr = list(map(int, input().strip().split()))
dicti = {}
for i in range(n):
	dicti[arr[i]] = i + 1
ans = [-1 for i in range(n + 1)]
if n > 1:
	ans[dicti[1]] = 1
for i in range(n, 1, -1):
	for j in range(dicti[i] % i - 1, n, i):
		if arr[j] > i:
			if ans[j + 1] == 0:
				ans[dicti[i]] = 1
				break
	else:
		ans[dicti[i]] = 0
print(''.join(['A' if i == 1 else 'B' for i in ans[1:]]))


n = int(input())
p = [int(x) for x in input().split()]
dp = ['B' for _ in range(n)]
idx = sorted([[p[i], i] for i in range(n)], reverse=True)
idx = [x[1] for x in idx]
for i in idx:
	for j in range(1, n):
		ind = i + j * p[i]
		ind1 = i - j * p[i]
		if ind >= n and ind1 < 0:
			break
		if ind < n and p[ind] > p[i] and (dp[ind] == 'B'):
			dp[i] = 'A'
			break
		if ind1 >= 0 and p[ind1] > p[i] and (dp[ind1] == 'B'):
			dp[i] = 'A'
			break
print(''.join(dp))


n = int(input())
board = list(map(int, input().strip().split()))
board.insert(0, 0)
hashed = [0] * (n + 1)
for i in range(n + 1):
	hashed[board[i]] = i
answer = ['C'] * (n + 1)
for i in range(n, 0, -1):
	flag = 0
	k = hashed[i] - board[hashed[i]]
	while k > 0:
		if answer[k] == 'B':
			flag = 1
			break
		k -= board[hashed[i]]
	k = hashed[i] + board[hashed[i]]
	while k <= n and k != 0:
		if answer[k] == 'B':
			flag = 1
			break
		k += board[hashed[i]]
	if flag == 1:
		answer[hashed[i]] = 'A'
	else:
		answer[hashed[i]] = 'B'
answer.pop(0)
print(''.join(answer))


from sys import stdin
from collections import defaultdict
n = int(input())
arr = list(map(int, stdin.readline().split()))
ind = {}
val = {}
val = dict(enumerate(arr))
ind = dict([(y, x) for (x, y) in enumerate(arr)])
ans = ['B' for i in range(n)]
for v in range(n, 0, -1):
	temp = []
	ii = ind[v]
	for a in range(ii % v, n, v):
		if val[a] > v:
			temp.append(a)
	for i in temp:
		if ans[i] == 'B':
			ans[ind[v]] = 'A'
			break
print(''.join(ans))


n = int(input())
arr = [int(x) for x in input().split()]
d = {x: i for (i, x) in enumerate(arr)}
ans = ['B'] * len(arr)
for x in reversed(range(1, n + 1)):
	(i, k) = (d[x], 1)
	while x * k <= n - 1:
		y1 = i + k * x
		y2 = i - k * x
		if y1 <= n - 1:
			if arr[y1] > x and ans[y1] == 'B':
				ans[i] = 'A'
				break
		if y2 >= 0:
			if arr[y2] > x and ans[y2] == 'B':
				ans[i] = 'A'
				break
		k += 1
print(''.join(ans))


import sys
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
dp = [-1 for _ in range(n)]

@bootstrap
def compute(i, dp):
	if a[i] == n:
		dp[i] = 0
		yield
	to_check = []
	for j in range(i, n, a[i]):
		if j == i or a[j] < a[i]:
			continue
		if dp[j] == -1:
			yield compute(j, dp)
		to_check.append(j)
	for j in range(i, -1, -a[i]):
		if j == i or a[j] < a[i]:
			continue
		if dp[j] == -1:
			yield compute(j, dp)
		to_check.append(j)
	to_check_sum = sum([dp[j] for j in to_check])
	if len(to_check) == 0:
		dp[i] = 0
		yield
	elif to_check_sum == len(to_check):
		dp[i] = 0
		yield
	else:
		dp[i] = 1
		yield
for i in range(0, len(a)):
	if dp[i] != -1:
		continue
	else:
		compute(i, dp)
ans = ''
for i in range(0, n):
	if dp[i] == 0:
		ans += 'B'
	else:
		ans += 'A'
print(ans)


a = int(input())
lister = input().split()
lister = [int(i) for i in lister]
ans = dict()

def findans(n):
	if n in ans:
		return ans[n]
	mod = n % lister[n]
	ok = True
	if n + lister[n] >= a and n - lister[n] < 0:
		ok = False
	else:
		for i in range(mod, a, lister[n]):
			if i != n and lister[i] > lister[n]:
				ok = ok and findans(i)
		ok = not ok
	ans[n] = ok
	return ok
for i in range(len(lister)):
	findans(i)
level = []
for i in range(a):
	if ans[i] == True:
		level.append('A')
	else:
		level.append('B')
print(''.join(level))


from sys import stdin, setrecursionlimit
setrecursionlimit(10 ** 7)

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))
dp = [-1] * (10 ** 5 + 10)

def check(n, idx, a):
	global dp
	if dp[idx] != -1:
		return dp[idx]
	step = a[idx]
	ans = 0
	odd = 0
	for i in range(idx + step, n, step):
		if a[i] > a[idx]:
			x = check(n, i, a) + 1
			if x % 2:
				odd = x
			ans = max(x, ans)
	for i in range(idx - step, -1, -step):
		if a[i] > a[idx]:
			x = check(n, i, a) + 1
			if x % 2:
				odd = x
			ans = max(x, ans)
	dp[idx] = ans if odd == 0 else odd
	return dp[idx]

def main():
	n = iin()
	a = lin()
	for i in range(n):
		check(n, i, a)
	ans = []
	for i in range(n):
		ans.append(['B', 'A'][dp[i] % 2])
	print(''.join(ans))
main()


import sys
next(sys.stdin)
positions = {}
pos2x = {}
for (i, x) in enumerate(next(sys.stdin).split()):
	x = int(x)
	positions[x] = i
	pos2x[i] = x
answers = ['' for _ in range(len(positions))]
for x in range(len(positions), 0, -1):
	position = positions[x]

	def can_go_to_looser():
		next_position = position + x
		while next_position < len(positions):
			if pos2x[next_position] > x and answers[next_position] == 'B':
				return True
			next_position += x
		next_position = position - x
		while next_position >= 0:
			if pos2x[next_position] > x and answers[next_position] == 'B':
				return True
			next_position -= x
		return False
	if can_go_to_looser():
		answers[position] = 'A'
	else:
		answers[position] = 'B'
print(''.join(answers))


import math
import time
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import PriorityQueue
import sys

class Graph:

	def __init__(self, n):
		self.graph = defaultdict(lambda : [])
		self.vertices = n
		self.edges = 0
		self.toposorted = []

	def addEdge(self, a, b):
		self.graph[a].append(b)
		self.edges += 1

	def cycleUntill(self, visited, curr, parent):
		visited[curr] = True
		for i in self.graph[curr]:
			if not visited[i]:
				if self.cycleUntill(visited, i, curr):
					return True
			elif i != parent:
				return True
		return False

	def cycle(self):
		n = self.vertices
		visited = [False] * (n + 2)
		for i in range(1, n + 1):
			if not visited[i]:
				if self.cycleUntill(visited, i, -1):
					return True
		return False

	def topologicalSort(self):
		in_degree = [0] * (self.vertices + 10)
		for i in self.graph:
			for j in self.graph[i]:
				in_degree[j] += 1
		queue = deque()
		for i in range(1, self.vertices + 1):
			if in_degree[i] == 0:
				queue.append(i)
		cnt = 0
		while queue:
			u = queue.popleft()
			self.toposorted.append(u)
			for i in self.graph[u]:
				in_degree[i] -= 1
				if in_degree[i] == 0:
					queue.append(i)
			cnt += 1
		if cnt != self.vertices:
			return False
		else:
			return True

	def connected(self):
		visited = [False] * (self.vertices + 2)
		ans = []
		for i in range(1, self.vertices + 1):
			if not visited[i]:
				comp = []
				q = deque()
				visited[i] = True
				q.append(i)
				while len(q) > 0:
					temp = q.popleft()
					comp.append(temp)
					for j in self.graph[temp]:
						if not visited[j]:
							visited[j] = True
							q.append(j)
				ans.append(comp)
		return ans
n = int(input())
a = list(map(int, stdin.readline().split()))
g = Graph(n)
for i in range(n):
	for j in range(i + a[i], n, a[i]):
		if a[j] > a[i]:
			g.addEdge(i + 1, j + 1)
	for j in range(i - a[i], -1, -a[i]):
		if a[j] > a[i]:
			g.addEdge(i + 1, j + 1)
ans = [0] * n
g.topologicalSort()
for i in g.toposorted[::-1]:
	temp = 1
	for j in g.graph[i]:
		temp &= ans[j - 1]
	ans[i - 1] = 1 - temp
for i in ans:
	if i == 1:
		print('A', end='')
	else:
		print('B', end='')


n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n + 1)]
for (i, x) in enumerate(a):
	b[x] = i
dp = [False for i in range(n + 1)]
for i in range(n, 0, -1):
	ci = b[i]
	for j in range(ci + i, n, i):
		if a[j] > i and dp[a[j]] == False:
			dp[i] = True
			continue
	for j in range(ci - i, -1, 0 - i):
		if a[j] > i and dp[a[j]] == False:
			dp[i] = True
			continue
s = ''
for i in range(n):
	if dp[a[i]]:
		s += 'A'
	else:
		s += 'B'
print(s)


from operator import itemgetter
n = int(input())
ai = list(map(int, input().split()))
ai2 = [[ai[i], i] for i in range(n)]
answer = [0] * n
ai2.sort(key=itemgetter(0))
answer[ai2[0][1]] = 1
answer[ai2[-1][1]] = 0
for i in range(n - 2, 0, -1):
	num = ai2[i][1] % ai2[i][0]
	for j in range(num, n, ai2[i][0]):
		if ai[j] > ai2[i][0] and answer[j] == 0:
			answer[ai2[i][1]] = 1
			break
for i in range(n):
	if answer[i] == 1:
		print('A', end='')
	else:
		print('B', end='')


n = int(input())
a = list(map(int, input().split()))
p = [0] * (n + 2)
m = [0] * (n + 2)
for i in range(n):
	p[a[i]] = i
for i in range(n, 0, -1):
	j = p[i] % i
	while j < n:
		if i < a[j] and m[a[j]] == 0:
			m[i] = 1
			break
		j += i
for i in range(n):
	print('A' if m[a[i]] else 'B', end='')


n = int(input())
l = [0] + list(map(int, input().split()))
from collections import defaultdict
ans = ['A', 'B']
x = defaultdict(int)
table = [-1] * (n + 1)
for i in range(1, n + 1):
	x[l[i]] = i
table[x[n]] = 1
for i in range(n - 1, 0, -1):
	if x[i] - i > 0:
		for j in range(x[i], 0, -i):
			if l[j] > i:
				if table[j] == 1:
					table[x[i]] = 0
					break
	if n - i > 0 and table[x[i]] == -1:
		for j in range(x[i], n + 1, i):
			if l[j] > i:
				if table[j] == 1:
					table[x[i]] = 0
					break
	if table[x[i]] == -1:
		table[x[i]] = 1
for i in table[1:]:
	print(ans[i], end='')


n = int(input())
l = [-1 for i in range(n + 1)]
s = input().split()
ll = [int(i) for i in s]
for i in range(n):
	j = ll[i]
	l[j] = i
res = ['.' for i in range(n + 1)]
res[n] = 'B'
for i in range(n - 1, 0, -1):
	toadd = 'B'
	pos = l[i] % i
	while pos < n:
		j = ll[pos]
		if j <= i:
			pos += i
			continue
		if abs(l[i] - l[j]) % i == 0 and res[j] == 'B':
			toadd = 'A'
			break
		pos += i
	res[i] = toadd
for i in ll:
	print(res[i], end='')
print('')


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')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

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

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def main():
	n = N()
	arr = RLL()
	dic = {v: i for (i, v) in enumerate(arr)}
	dp = [1] * n
	for i in range(n - 1, 0, -1):
		for p in range(dic[i] % i, n, i):
			if arr[p] > i and dp[dic[arr[p]]] == 1:
				dp[dic[i]] = 0
				break
	print(''.join(['B' if i == 1 else 'A' for i in dp]))
main()


R = lambda : map(int, input().split())
n = int(input())
a = list(R())
arr = sorted(([x, i] for (i, x) in enumerate(a)), reverse=True)
res = [-1] * n
for (x, i) in arr:
	res[i] = 0 if any((res[j] == 1 for j in range(i + x, n, x) if a[j] > a[i])) or any((res[j] == 1 for j in range(i - x, -1, -x) if a[j] > a[i])) else 1
print(''.join(('B' if x else 'A' for x in res)))


from sys import stdin
n = int(stdin.readline().strip())
s = list(map(int, stdin.readline().strip().split()))
dp = ['B' for i in range(n)]
visited = [False for i in range(n)]
import sys
sys.setrecursionlimit(10 ** 9)

def dfs(i):
	x = s[i]
	visited[i] = True
	for j in range(i - x, -1, -x):
		if s[j] > x:
			if not visited[j]:
				dfs(j)
			if dp[j] == 'B':
				dp[i] = 'A'
				return
	for j in range(i + x, n, x):
		if s[j] > x:
			if not visited[j]:
				dfs(j)
			if dp[j] == 'B':
				dp[i] = 'A'
				return
for i in range(n):
	if not visited[i]:
		dfs(i)
ans = ''
for i in dp:
	ans += i
print(ans)


n = int(input())
arr = [0] + list(map(int, input().split()))
indx = [0 for i in range(n + 1)]
for i in range(1, n + 1):
	indx[arr[i]] = i
ans = [-1 for i in range(n + 1)]
for i in range(n, 0, -1):
	ind1 = indx[i] - i
	(count_zero, count_one, count_min_one) = (0, 0, 0)
	while ind1 >= 1:
		if ans[ind1] == -1:
			count_min_one += 1
		if ans[ind1] == 0:
			count_zero += 1
		if ans[ind1] == 1:
			count_one += 1
		ind1 -= i
	ind2 = indx[i] + i
	while ind2 <= n:
		if ans[ind2] == -1:
			count_min_one += 1
		if ans[ind2] == 0:
			count_zero += 1
		if ans[ind2] == 1:
			count_one += 1
		ind2 += i
	if count_zero >= 1:
		ans[indx[i]] = 1
	else:
		ans[indx[i]] = 0
for i in range(1, n + 1):
	if ans[i] == 1:
		print('A', end='')
	else:
		print('B', end='')


n = int(input())
a = list(map(int, input().split()))
ans = [-1] * n
loc = {}
for i in range(n):
	loc[a[i]] = i
for i in range(n):
	if a[i] > i and a[i] >= n - i:
		ans[i] = 'B'
prev = 0
while ans.count(-1) != prev:
	prev = ans.count(-1)
	for i in range(n):
		if ans[i] == -1:
			for j in range(i % a[i], n, a[i]):
				if a[j] > a[i] and ans[j] == 'B':
					ans[i] = 'A'
					break
while ans.count(-1) != 0:
	for i in range(n):
		if ans[i] == -1:
			ans[i] = 'B'
			for j in range(i % a[i], n, a[i]):
				if a[i] >= a[j]:
					continue
				if ans[j] == 'B':
					ans[i] = 'A'
					break
				elif ans[j] == -1:
					ans[i] = -1
					break
for i in ans:
	print(i, end='')
print()


from collections import defaultdict

def turn(i, a):
	if a[i] > i - 1 and a[i] > n - i:
		return [0]
	start = 0
	for j in range(i, 0, -a[i]):
		if j > 0:
			start = j
	if start == 0:
		return [0]
	out = []
	for j in range(start, len(a), a[i]):
		if abs(j - i) % a[i] == 0 and a[j] > a[i]:
			out.append(j)
	if out == []:
		out = [0]
	return out
n = int(input())
a = [int(el) for el in input().split()]
a.insert(0, 0)
if n == 1:
	print('B')
	raise SystemExit
tree = defaultdict(list)
count = defaultdict(int)
for i in range(1, n + 1):
	if a[i] > i - 1 and a[i] > n - i:
		tree[0].append(i)
		continue
	start = 0
	for j in range(i, 0, -a[i]):
		if j > 0:
			start = j
	if start == 0:
		tree[0].append(i)
		continue
	for j in range(start, len(a), a[i]):
		if abs(j - i) % a[i] == 0 and a[j] > a[i]:
			tree[j].append(i)
			count[i] += 1
	if count[i] == 0:
		tree[0].append(i)
winpos = defaultdict(int)

def graf(i):
	global winpos
	global count
	for k in tree.get(i, []):
		if len(winpos) == n + 1:
			for i in range(1, n + 1):
				if winpos[i] == 1:
					print('A', end='')
				else:
					print('B', end='')
			raise SystemExit
		if winpos[k] != 1:
			winpos[k] = 1
			for l in tree.get(k, []):
				count[l] = count[l] - 1
				if count[l] == 0:
					winpos[l] = 2
					graf(l)
	return
for j in tree[0]:
	winpos[j] = 2
	graf(j)
for i in range(1, n + 1):
	if winpos[i] == 1:
		print('A', end='')
	else:
		print('B', end='')


n = int(input())
line = list(map(int, input().split()))
a = [0 for i in range(n)]
ans = [0 for _ in range(n)]
ans[0] = 1
ans[-1] = -1
for i in range(n):
	a[line[i] - 1] = i
for i in range(n - 2, 0, -1):
	cur = -1
	num = i + 1
	k = 0
	start = a[i] % num
	while start + num * k < n:
		temp = start + num * k
		if line[temp] > num:
			if ans[line[temp] - 1] == -1:
				cur = 1
				break
		k += 1
	ans[i] = cur
answer = ''
for i in line:
	if ans[i - 1] == 1:
		answer += 'A'
	else:
		answer += 'B'
print(answer)


n = int(input())
board = list(map(int, input().split(' ')))
index = list(range(0, n))
ascending = [x for (_, x) in sorted(zip(board, index))]
winners = n * ['']
for c in reversed(ascending):
	if board[c] == n:
		winners[c] = 'B'
	toCheck = c - board[c]
	while toCheck >= 0:
		if winners[toCheck] == 'B':
			winners[c] = 'A'
		toCheck = toCheck - board[c]
	if winners[c] == '':
		toCheck = c + board[c]
		while toCheck < n:
			if winners[toCheck] == 'B':
				winners[c] = 'A'
			toCheck = toCheck + board[c]
	if winners[c] == '':
		winners[c] = 'B'
for i in range(n):
	print(winners[i], end='')
print()