n =int(input())
s =input()
a, b =0,0
mp = defaultdict(list)
mp[0]=[0]
res =0for i, c inenumerate(s):if c =="A":
a +=1else:
b +=1
mp[a-b].append(i +1)iflen(mp[a-b])>1:
res =max(res, i +1- mp[a-b][0])print(res)
t =int(input())
a =[]
res =0
y =10**9+7for _ inrange(t):
n, k =map(int,input().split())
a =list(map(int,input().split()))
s =sum(a)% y
ifmin(a)>0:
res =(s *pow(2, k, mod=y))elifmax(a)<=0:
res = s
else:
cur =0
mi =0
diff =-float('inf')for x in a:
cur += x
mi =min(mi, cur)
diff =max(diff, cur - mi)% y
res =(s + diff *pow(2, k -1, mod=y))print(int(res % y))
defgetSameNumMaxDistance(a)-> Tuple[int, Dict[int,int], Dict[int,int]]:
ds, de = defaultdict(lambda:-1), defaultdict(lambda:-1)
res =0for i,x inenumerate(a):if ds[x]==-1:
ds[x]= i
de[x]= i
res =max(res, de[x]-ds[x])return res,ds,de
a =[5,3,6,7,6,5,7,4]
res, ds, de = getSameNumMaxDistance(a)# 相似子数组的最大长度 就是首尾相同数字的最大距离# 如果修改的中间数字,不影响相似子数组的结果# 如果修改的是某个数字的起点或终点,则重新计算