Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
N=int(input())
idx=[[0,0]for _ in[0]*N]
a=b=0
for k,x in enumerate(input()):
    if x=='a':
        idx[a][0]=k
        a+=1
    else:
        idx[b][1]=k
        b+=1
res=[]
for i in range(1,2**N):
    tmp=[0]*2*N
    for k in range(N):
        if (i>>k)&1:
            a,b=idx[k]
            tmp[a]='a'
            tmp[b]='b'
    res+=[''.join(c for c in tmp if c)]
print(max(res))

# Example run
# Input:
10
[k*
# Output:
bbb
class Solver:

    def __init__(self):
        self.move_map = [{} for _ in range(51)]
        self.calc_one_step()
        self.compress()
        self.best_cost = float('inf')

    @staticmethod
    def cost(a):
        return sum(2 ** i for i in a)

    @staticmethod
    def prod(now, aa, bb):
        for a in aa:
            for b in bb:
                now.add(a + b)
        return now

    def calc_one_step(self):
        for i in range(51):
            for j in range(1, i + 1):
                m = i % j
                if m not in self.move_map[i]:
                    self.move_map[i][m] = {(j,)}
                else:
                    self.move_map[i][m].add((j,))

    def compress(self):
        for i in range(51):
            self.move_map[i] = self._comp(i)

    def _comp(self, n):
        new = self.move_map[n].copy()
        for m, a in self.move_map[n].items():
            for mm, aa in self.move_map[m].items():
                if mm not in new:
                    new[mm] = aa
                else:
                    self.prod(new[mm], a, aa)
        return new

    def solve(self, start, goal):
        path_list = []
        for s, g in zip(start, goal):
            if s == g:
                continue
            path = self.move_map[s].get(g)
            if path is None:
                self.best_cost = -1
                return
            path_list.append(path)
        self._solve(0, path_list, [])

    def _solve(self, cost, path_list, divs):
        if not path_list:
            if cost < self.best_cost:
                self.best_cost = cost
            return
        for one, new_list in self.iter_one(path_list):
            d = divs + [one]
            c = cost + 2 ** one
            if c >= self.best_cost:
                break
            elif not new_list and c < self.best_cost:
                self.best_cost = c
            else:
                self._solve(c, new_list, d)

    def iter_one(self, path_list):
        ones = set()
        for path_set in path_list:
            for path in path_set:
                ones.add(path[0])
        for one in sorted(ones):
            new_list = []
            for path_set in path_list:
                new_set = set()
                for path in path_set:
                    if path[0] == one:
                        path = path[1:]
                        if not path:
                            break
                    new_set.add(path)
                else:
                    new_list.append(new_set)
            yield one, new_list


def main():
    solver = Solver()
    int(input())
    start = list(map(int, input().split()))
    goal = list(map(int, input().split()))
    solver.solve(start, goal)
    print(solver.best_cost)


if __name__ == '__main__':
    main()


# Example run
# Input:
173921
5
-7606
# Output:
-1
def solve(a, b):
    if a == b:
        yield []
    if a > b:
        for i in range(1, a+1):
            for x in solve(a % i, b):
                yield [i] + x

def subseq(a, b):
    if len(b) == 0: return True
    x = 0
    for t in a:
        if t == b[x]:
            x += 1
            if x == len(b):
                return True
    return False

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

R = []

for i in range(n):
    R.append(list(solve(A[i], B[i])))
    if len(R[-1]) == 0:
        print(-1)
        exit(0)

L = []
answer = 0

for i in range(50, 0, -1):
    T = L + list(range(i - 1, 0, -1))

    ok = True

    for j in range(n):
        cur = False

        for seq in R[j]:
            if subseq(T, seq):
                cur = True
                break

        if not cur:
            ok = False
            break

    if not ok:
        L.append(i)
        answer += 2**i

print(answer)


# Example run
# Input:
-1273
0
1
# Output:
0
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    d = [[None]*51 for _ in [0]*51]  # 目的のあまり、現在の数値
    for i in range(51):
        d[i][i] = [[]]
    for i in range(51):  # あまり
        for j in range(i+1, 51):  # 現在の数値
            temp = []
            for kk in range(1, j+1):  # 割る数
                k = j % kk
                if d[i][k] is None:
                    continue
                for l in d[i][k]:
                    temp += [l+[kk]]
            if temp == []:
                temp = None
            d[i][j] = temp
    c = [d[bb][aa] for aa, bb in zip(a, b)]
    if None in c:
        print(-1)
        return
    ans = 0
    while True:
        M = -1
        for i in range(n):
            if [] in c[i]:
                c[i] = [[]]
            else:
                m = min([j[-1] for j in c[i]])
                M = max(M, m)
        if M == -1:
            break
        ans += 2**M
        for i in range(n):
            temp = []
            if c[i] == [[]]:
                continue
            for j in c[i]:
                if j[-1] == M:
                    temp.append(j[:-1])
                elif j[-1] < M:
                    temp.append(j)
            c[i] = temp
    print(ans)


main()


# Example run
# Input:
159824875
-3
24
# Output:
-1
def solve(bit_state, num, mod):
    for div in range(1, num + 1):
        if num % div == mod:
            cand[i].append(bit_state | (1 << div))
        if num % div > mod:
            solve(bit_state | (1 << div), num % div, mod)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cand = [[] for i in range(n)]
for i in range(n):
    solve(0, a[i], b[i])
    if a[i] == b[i]:
        cand[i].append(0)

ans = 0
while True:
    max_ = 0
    for j in range(n):
        min_ = 10 ** 5
        for num in cand[j]:
            min_ = min(min_, num.bit_length() - 1)
        max_ = max(max_, min_)

    if max_ == 0:
        print(ans)
        break
    if max_ == 10 ** 5:
        print(-1)
        break
    ans += 2 ** max_
    
    tmp = [[] for i in range(n)]
    for j in range(n):
        for num in cand[j]:
            if num & (1 << max_):
                tmp[j].append(num - (1 << max_))
            else:
                tmp[j].append(num)
    cand = tmp[0:]
            

# Example run
# Input:
-46896159
2561
-1
# Output:
0
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = [[False] * 51 for i in range(51)]
use = []


def calc(a, b, D):
    if a == b:
        return True
    d = {}
    stack = [a]
    while stack:
        u = stack.pop()
        if u == b:
            return True
        d[u] = 1
        for w in range(1, 51):
            if (u % w) in d:
                continue
            if D[u][u % w]:
                stack.append(u % w)

    return False


def check(n):
    D = [[False] * 51 for i in range(51)]
    for i in range(51):
        for k in range(1, n):
            D[i][i % k] = True
        D[i][i] = True

    for i in range(51):
        for j in use:
            D[i][i % j] = True

    for a, b in zip(A, B):
        if not calc(a, b, D):
            return True
    return False


if check(51):
    print(-1)
    exit()

ans = 0
for j in range(50, 0, -1):
    if check(j):
        use.append(j)
        ans += 2 ** j

print(ans)


# Example run
# Input:
-372018900
11
112430
# Output:
-1
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# a->b, possible with using at most c as max
T = [[[None] * 51 for _ in range(51)] for _ in range(51)]

def dp(a, b, c):
  if T[a][b][c] is not None:
    return T[a][b][c]
  if a == b:
    T[a][b][c] = True
    return T[a][b][c] 
 # if c == 0:
 #   T[a][b][c] = b == 0
 #   return T[a][b][c] 
  if b >= c or a < b:
    T[a][b][c] = False
    return T[a][b][c] 
  if dp(a, b, c-1):
    T[a][b][c] = True
    return T[a][b][c] 
  else:
    T[a][b][c] = dp(a % c, b, c-1)
    return T[a][b][c]

T2 = [[None] * 51 for _ in range(51)]
def min_c(a, b):
  if T2[a][b] is not None:
    return T2[a][b]
  for c in range(51):
    if dp(a,b,c):
      T2[a][b] = c
      return T2[a][b]
  T2[a][b] = 51
  return T2[a][b]

#print(min_c(14,0))
#print(min_c(14,4))
  
def solve():
  count = 0
  for a, b in zip(A,B):
    if a < b:
      print(-1)
      return
    if a > b:
      count += 1
#  print(count)
#  print(list(zip(A, B)))
 # return
  
  cost = 0
  ABs = [{(a, b)} if a > b else set() for a, b in zip(A,B)]
  while count:
    # min->max
    mm = [min(min_c(a, b) for a, b in s) if s else 0 for s in ABs]
    m = max(mm)
    if m > 50:
      print(-1)
      return
    
    cost += 2 ** m
    for i in range(len(ABs)):
      if mm[i] == m:
        new_s = set()
        done = False
        for a, b in ABs[i]:
          if min_c(a % m, b) == 0:
            done = True
            break
          elif min_c(a, b) == m:
            new_s.add((a % m, b))
        if done:
          count -= 1
          ABs[i] = set()
        else:
          ABs[i] = new_s
      else:  # optional
        new_s = set()
        done = False
        for a, b in ABs[i]:
          if min_c(a % m, b) == 0:
            done = True
            break
          elif min_c(a % m, b) < m:
            new_s.add((a % m, b))
        if done:
          count -= 1
          ABs[i] = set()
        else:
          ABs[i].update(new_s)
        
  print(cost)
    
    
    

solve()
  


# Example run
# Input:
141725276
-109089799
-74270783
# Output:
-1
import sys

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

same = 0
for i in range(n):
	if b[i]*2 >= a[i]:
		print(-1)
		sys.exit()
	elif a[i] == b[i]:
		same += 1
if same == n:
	print(0)
	sys.exit()

edges = [[] for _ in range(51)]
for i in range(1, 51):
	for j in range(1, i+1):
		edges[i].append([i%j, j])

available = [True for _ in range(51)]
visited = [False for _ in range(51)]

def dfs(start, goal, cur):
	global visited
	if cur == goal:
		return True
	for e, k in edges[cur]:
		if visited[e] == False and available[k] == True:
			visited[e] = True
			if dfs(start, goal, e) == True:
				return True
	return False

ans = 0
for k in range(50, 0, -1):
	available[k] = False
	ok = True
	for i in range(n):
		visited = [False for _ in range(51)]
		visited[a[i]] = True
		if dfs(a[i], b[i], a[i]) == False:
			ok = False
			break
	if not ok:
		ans += 2**k
		available[k] = True

print(ans)

# Example run
# Input:
-1654029
-3
322
# Output:
0
import sys

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

same = 0
for i in range(n):
	if a[i] == b[i]:
		same += 1
	elif b[i]*2 >= a[i]:
		print(-1)
		sys.exit()

if same == n:
	print(0)
	sys.exit()

edges = [[] for _ in range(51)]
for i in range(1, 51):
	for j in range(1, i+1):
		edges[i].append([i%j, j])

available = [True for _ in range(51)]
visited = [False for _ in range(51)]

def dfs(start, goal, cur):
	global visited
	if cur == goal:
		return True
	for e, k in edges[cur]:
		if visited[e] == False and available[k] == True:
			visited[e] = True
			if dfs(start, goal, e) == True:
				return True
	return False

ans = 0
for k in range(50, 0, -1):
	available[k] = False
	ok = True
	for i in range(n):
		visited = [False for _ in range(51)]
		visited[a[i]] = True
		if dfs(a[i], b[i], a[i]) == False:
			ok = False
			break
	if not ok:
		ans += 2**k
		available[k] = True

print(ans)

# Example run
# Input:
-49
-82802
14559
# Output:
0
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
kai = set()
ans = 0
for m in range(N):
  for i in range(50,0,-1):
    kai.add(i)
  amari = [] 
  for i in kai:
    are = a[m] % i
    amari.append(are)
  for k in range(len(amari)):
    for i in kai:
      are = amari[k] % i
      amari.append(are)
  if b[m] in amari:
    ann = 0
  else:
    ans = -1

for p in range(50,0,-1):
  kai.remove(p)
  for j in range(N):
    amari = [] 
    for i in kai:
      are = a[j] % i
      amari.append(are)
    for k in range(len(amari)):
      for i in kai:
        are = amari[k] % i
        amari.append(are)
    if b[j] in amari:
      ann = 0
    else:
      kai.add(p)
if ans == -1:
   print(-1)
elif a == b:
  print(0)
else:
  ans = 0
  for i in kai:
    ans += 2 ** i
  print(ans)

# Example run
# Input:
1
126
-76
# Output:
-1
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
kai = set()
ans = 0
for m in range(N):
  for i in range(50,0,-1):
    kai.add(i)
  amari = [] 
  for i in kai:
    are = a[m] % i
    amari.append(are)
  for k in range(len(amari)):
    for i in kai:
      are = amari[k] % i
      amari.append(are)
  if b[m] in amari:
    ann = 0
  else:
    ans = -1

for p in range(50,0,-1):
  kai.remove(p)
  for j in range(N):
    amari = [] 
    for i in kai:
      are = a[j] % i
      amari.append(are)
    for k in range(len(amari)):
      for i in kai:
        are = amari[k] % i
        amari.append(are)
    if b[j] in amari:
      ann = 0
    else:
      kai.add(p)
if ans == -1:
   print(-1)
else:
  ans = 0
  for i in kai:
    ans += 2 ** i
  print(ans)

# Example run
# Input:
1
-816653
-7191
# Output:
-1
#!/usr/bin/env python3

import copy

huge = 100

def get_k(a, b):
    assert b >= 0 and a >= 0
    if b == a:
        return 0
    if b == 0:
        return 1
    if 2 * b >= a:
        return huge
    for k in range(b + 1, a):
        if a % k == b:
            return k
    return huge

n = int(input())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
assert len(ai) == len(bi) == n

achievable = [{ai[i]} for i in range(n)]

res = 0
for roop in range(49):
    max_k = 0
    for i in range(n):
        min_k = huge
        for a in achievable[i]:
            k = get_k(a, bi[i])
            min_k = min(min_k, k)
        max_k = max(max_k, min_k)
    if max_k == huge:
        res = -1
        break
    if max_k == 0:
        break
    for i in range(n):
        ach_pre = copy.deepcopy(achievable[i])
        for a in ach_pre:
            achievable[i].add(a % max_k)
    res += 2 ** max_k

print(res)    


# Example run
# Input:
1
42872
7
# Output:
-1
from itertools import chain

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

IMP = 100

dp = [[IMP for _ in range(51)] for _ in range(51)]

for i in range(51):
  dp[i][i] = 0
  for j in range(i):
    for m in range(1,51):
      if dp[i%m][j] != IMP:
        dp[i][j] = m
        break


if max(dp[x][y] for x,y in zip(A,B)) == IMP:
  print(-1)
else:
  cost = 0
  m = max(dp[x][y] for x,y in zip(A,B))
  AL = [{a} for a in A]

  def candmin(al,b):
    m = min(dp[a][b] for a in al)
    al.discard(a for a in al if dp[a][b] > m)
    return m

  while m != 0:
    for i,(al,b) in enumerate(zip(AL,B)):
      AL[i] |= set(a%m for a in al)
    cost += 2**m

    m = max(candmin(al,b) for al,b in zip(AL,B))

  print(cost)

# Example run
# Input:
119
-14
0
# Output:
2
#!/usr/bin/env python
from collections import defaultdict

hoge = {}
for a in range(1, 51):
    hoge[a] = defaultdict(list)
    for b in range(1, 51):
        hoge[a][a % b].append(b)


def main():
    N = int(input().strip())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    ans = 0

    while True:
        k = []
        for i in range(N):
            if A[i] != 0 and A[i] != B[i]:
                if not hoge[A[i]][B[i]]:
                    return -1
                k.append(hoge[A[i]][B[i]])
        if not k:
            break
        k = min(map(lambda a: min(a), k))
        ans += 2**k
        for i in range(N):
            if A[i] % k == B[i]:
                A[i] = B[i]
    return ans


if __name__ == '__main__':
    ans = main()
    print(ans)

# Example run
# Input:
-5
-64
-13902095
# Output:
0
N=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
flag=0
for i in range(N):
    if (a[i]-1)//2<b[i]:
        flag=1
        break
if flag==1:
    print(-1)
else:
    k=[0 for i in range(N)]
    #それぞれに１回ずつやった場合
    for i in range(N):
        for j in range(1,a[i]+1):
            if a[i]%j==b[i]:
                k[i]=j
                break
    S=set(k)
    T=0
    for n in S:
        T+=2**n
    print(T)


# Example run
# Input:
2
-1168909
0
# Output:
-1
from collections import deque


def bfs(adj, s, t, use):
    if s == t:
        return 1
    que = deque()
    seen = [0] * len(adj)
    que.append(s)
    seen[s] = 1
    while que:
        v = que.popleft()
        for u, cost in adj[v]:
            if seen[u] == 0 and use[cost] == 1:
                if u == t:
                    return 1
                seen[u] = 1
                que.append(u)
    return 0


N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

adj = [[] for _ in range(51)]
for i in range(51):
    for j in range(1, i+1):
        adj[i].append((i%j, j))

use = [1] * 51
use[0] = 0
for i in range(50, 0, -1):
    use[i] = 0
    for ai, bi in zip(a, b):
        if not bfs(adj, ai, bi, use):
            use[i] = 1
            break

if sum(use) == 50:
    print(-1)
    exit()

print(sum([(2**i) * use[i] for i in range(51)]))


# Example run
# Input:
-45
-16
-224231
# Output:
-1
import sys

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

minimum = [[51 for _ in range(51)] for _ in range(51)]
for i in range(50, 0, -1):
	minimum[i][i] = 50
	for j in range(1, 51):
		for k in range(51):
			if minimum[i][k] <= 50:
				minimum[i][k%j] = min(j, minimum[i][k%j])

ans = 0
for k in range(51, 0, -1):
	needed = False
	for i in range(n):
		if a[i] == b[i]:
			continue
		elif b[i] >= (a[i]+1)//2:
			print(-1)
			sys.exit()
		else:
			if minimum[a[i]][b[i]] == k:
				needed = True
	if needed:
		ans += 2**k
		for i in range(n):
			if a[i]%k == b[i]:
				a[i] %= k
			elif minimum[a[i]][b[i]] >= minimum[a[i]%k][b[i]]:
				a[i] %= k
		#print(k, a)
print(ans)

# Example run
# Input:
17
410684364
810667242
# Output:
-1
from collections import deque
import sys

N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

isEssentials = [False] * 51
for k in reversed(range(1, 52)):
    adjL = [set() for _ in range(51)]
    for v in range(1, 51):
        for t in range(1, v+1):
            if t < k or isEssentials[t]:
                adjL[v].add(v%t)
        adjL[v] = list(adjL[v])

    for A, B in zip(As, Bs):
        isOK = False
        useds = [False] * 51
        Q = deque([A])
        while Q:
            vNow = Q.popleft()
            if vNow == B:
                isOK = True
                break
            useds[vNow] = True
            for v2 in adjL[vNow]:
                if not useds[v2]:
                    Q.append(v2)
        if not isOK:
            if k == 51:
                print(-1)
                sys.exit()
            isEssentials[k] = True
            break

ans = sum([2**k for k in range(1, 51) if isEssentials[k]])
print(ans)


# Example run
# Input:
-473
-7
-7737
# Output:
-1
#!/usr/bin/env python3

huge = 100

def get_k(a, b):
    assert b >= 0 and a >= 0
    if b == a:
        return 0
    if b == 0:
        return 1
    if 2 * b >= a:
        return huge
    for k in range(b + 1, a):
        if a % k == b:
            return k
    return huge

n = int(input())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
assert len(ai) == len(bi) == n

achievable = [{ai[i]} for i in range(n)]

res = 0
for roop in range(49):
    max_k = 0
    print(achievable)
    for i in range(n):
        min_k = huge
        for a in achievable[i]:
            k = get_k(a, bi[i])
            min_k = min(min_k, k)
        max_k = max(max_k, min_k)
    if max_k == huge:
        res = -1
        break
    if max_k == 0:
        break
    for i in range(n):
        achievable[i].add(a % max_k)
    res += 2 ** max_k

print(res)    


# Example run
# Input:
1
2590712
1699112
# Output:
[{2590712}]
-1
def solve(bit_state, num, mod):
    for div in range(1, num + 1):
        if num % div == mod:
            cand[i].append(bit_state | (1 << div))
        if num % div > mod:
            solve(bit_state | (1 << div), num % div, mod)


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

cand = [[] for i in range(n)]
for i in range(n):
    solve(0, a[i], b[i])

ans = 0
for i in range(50):
    max_ = 0
    for j in range(n):
        min_ = 10 ** 5
        for num in cand[j]:
            min_ = min(min_, num.bit_length() - 1)
        max_ = max(max_, min_)

    if max_ == 0:
        print(ans)
        break
    if max_ == 10 ** 5:
        print(-1)
        break
    ans += 2 ** max_
    
    tmp = [[] for i in range(n)]
    for j in range(n):
        for num in cand[j]:
            if num & (1 << max_):
                tmp[j].append(num - (1 << max_))
            else:
                tmp[j].append(num)
    cand = tmp[0:]
            

# Example run
# Input:
0
-3
24
# Output:
0
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

candidate = [(a, b, 0, 0)]
best_score = (False, 2**(max(a)))

while candidate != []:
    c = candidate.pop(0)
    A, B, prev_k, score = c
    if score >= best_score[1]:
        continue
    index = [i for i in range(len(A)) if A[i] != B[i]]
    if index == []:
        best_score = (True, min(score, best_score[1]))
        continue
    K = [ (i, [k for k in range(B[i] + 1, A[i] + 1) if A[i] % k >= B[i]])  for i in index]
    is_valid = True
    for (i, ks) in K:
        if ks == []:
            is_valid = False
            break
    if not is_valid:
        continue

    for (i, ks) in K:
        for k in ks:
            A2 = A.copy()
            A2[i] %= k
            if k == prev_k:
                candidate.append((A2, B, k, score))
            else:
                candidate.append((A2, B, k, score + 2**k))
                
if not best_score[0]:
    print(-1)
else:
    print(best_score[1])


# Example run
# Input:
-1
-3439167
0
# Output:
-1
#!/usr/bin/env python
from collections import defaultdict
from collections import Counter

hoge = {}
for a in range(1, 51):
    hoge[a] = defaultdict(list)
    for b in range(1, 51):
        hoge[a][a % b].append(b)


def main():
    N = int(input().strip())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    ans = 0

    while True:
        k = []
        for i in range(N):
            if A[i] != 0 and A[i] != B[i]:
                if not hoge[A[i]][B[i]]:
                    return -1
                k.append(hoge[A[i]][B[i]])
        if not k:
            break
        # k = min(map(lambda a: min(a), k))
        ks = Counter()
        for x in k:
            for y in x:
                ks[y] += 1
        k = ks.most_common(1)[0][0]

        ans += 2**k
        for i in range(N):
            if A[i] % k == B[i]:
                A[i] = B[i]
    return ans


if __name__ == '__main__':
    ans = main()
    print(ans)

# Example run
# Input:
-3
1541
1
# Output:
0