Problem:


Score : 700 points

Problem Statement

For strings s and t, we will say that s and t are prefix-free when neither is a prefix of the other.

Let L be a positive integer. A set of strings S is a good string set when the following conditions hold true:

Each string in S has a length between 1 and L (inclusive) and consists of the characters 0 and 1.

Any two distinct strings in S are prefix-free.

We have a good string set S = \{ s_1, s_2, ..., s_N \}. Alice and Bob will play a game against each other. They will alternately perform the following operation, starting from Alice:

Add a new string to S. After addition, S must still be a good string set.

The first player who becomes unable to perform the operation loses the game. Determine the winner of the game when both players play optimally.

Constraints

1 \leq N \leq 10^5

1 \leq L \leq 10^{18}

s_1, s_2, ..., s_N are all distinct.

{ s_1, s_2, ..., s_N } is a good string set.

|s_1| + |s_2| + ... + |s_N| \leq 10^5

Input

Input is given from Standard Input in the following format:

N L
s_1
s_2
:
s_N

Output

If Alice will win, print Alice; if Bob will win, print Bob.

Sample Input 1

2 2
00
01

Sample Output 1

Alice

If Alice adds 1, Bob will be unable to add a new string.

Sample Input 2

2 2
00
11

Sample Output 2

Bob

There are two strings that Alice can add on the first turn: 01 and 10.
In case she adds 01, if Bob add 10, she will be unable to add a new string.
Also, in case she adds 10, if Bob add 01, she will be unable to add a new string.

Sample Input 3

3 3
0
10
110

Sample Output 3

Alice

If Alice adds 111, Bob will be unable to add a new string.

Sample Input 4

2 1
0
1

Sample Output 4

Bob

Alice is unable to add a new string on the first turn.

Sample Input 5

1 2
11

Sample Output 5

Alice

Sample Input 6

2 3
101
11

Sample Output 6

Bob



Sample input:
2 2
00
01


Sample output:
Alice

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    mod = (10**9+7) * 3
    mod2 = (10**9+9) * 3
    N, L = map(int, input().split())
    dic = defaultdict(int)
    dic2 = defaultdict(int)
    h_list = []
    h2_list = []
    M = 0
    for _ in range(N):
        s = input().rstrip('\n')
        h = 0
        h2 = 0
        for i in range(len(s)):
            M += 1
            h = (h*3 + int(s[i]) + 1) % mod
            h2 = (h2 * 3 + int(s[i]) + 1) % mod2
            dic[h] = i+1
            dic2[h2] = i+1
            h_list.append(h)
            h2_list.append(h2)

    g = 0
    for i in range(M):
        s, s2 = h_list[i], h2_list[i]
        if s%3 == 1:
            t = (s + 1)%mod
            t2 = (s2 + 1)%mod2
        else:
            t = (s - 1)%mod
            t2 = (s2 + 1)%mod2
        if not (dic[t] or dic[t2]):
            tmp = L - dic[s] + 1
            cnt = 0
            while tmp % 2 == 0:
                tmp //= 2
                cnt += 1
            g ^= (2**cnt)

    if g:
        print('Alice')
    else:
        print('Bob')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    mod = (10**9+7) * 3
    mod2 = (10**9+9) * 3
    N, L = map(int, input().split())
    dic = defaultdict(int)
    dic2 = defaultdict(int)
    h12 = {}
    for _ in range(N):
        s = input().rstrip('\n')
        h = 0
        h2 = 0
        for i in range(len(s)):
            h = (h*3 + int(s[i]) + 1) % mod
            h2 = (h2 * 3 + int(s[i]) + 1) % mod2
            dic[h] = i+1
            dic2[h2] = i+1
            h12[h] = h2

    g = 0
    key = list(dic.keys())
    for s in key:
        if s%3 == 1:
            t = (s + 1)%mod
            t2 = (h12[s] + 1)%mod2
        else:
            t = (s - 1)%mod
            t2 = (h12[s] - 1) % mod2
        if not (dic[t] or dic[t2]):
            tmp = L - dic[s] + 1
            cnt = 0
            while tmp % 2 == 0:
                tmp //= 2
                cnt += 1
            g ^= (2**cnt)

    if g:
        print('Alice')
    else:
        print('Bob')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    mod = (10**9+7) * 3
    N, L = map(int, input().split())
    dic = defaultdict(int)
    for _ in range(N):
        s = input().rstrip('\n')
        h = 0
        for i in range(len(s)):
            h = (h*3 + int(s[i]) + 1) % mod
            dic[h] = i+1

    g = 0
    key = list(dic.keys())
    for s in key:
        if s%3 == 1:
            t = (s + 1)%mod
        else:
            t = (s - 1)%mod
        if not dic[t]:
            tmp = L - dic[s] + 1
            cnt = 0
            while tmp % 2 == 0:
                tmp //= 2
                cnt += 1
            g ^= (2**cnt)

    if g:
        print('Alice')
    else:
        print('Bob')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    mod = 10**9+9
    N, L = map(int, input().split())
    dic = defaultdict(int)
    for _ in range(N):
        s = input().rstrip('\n')
        h = 0
        for i in range(len(s)):
            h = (h*3 + int(s[i]) + 1) % mod
            dic[h] = i+1

    g = 0
    key = list(dic.keys())
    for s in key:
        if s%3 == 1:
            t = (s + 1)%mod
        else:
            t = (s - 1)%mod
        if not dic[t]:
            tmp = L - dic[s] + 1
            cnt = 0
            while tmp % 2 == 0:
                tmp //= 2
                cnt += 1
            g ^= (2**cnt)

    if g:
        print('Alice')
    else:
        print('Bob')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    mod = 10**9+7
    N, L = map(int, input().split())
    dic = defaultdict(int)
    for _ in range(N):
        s = input().rstrip('\n')
        h = 0
        for i in range(len(s)):
            h = (h*3 + int(s[i]) + 1) % mod
            dic[h] = i+1

    g = 0
    key = list(dic.keys())
    for s in key:
        if s%3 == 1:
            t = (s + 1)%mod
        else:
            t = (s - 1)%mod
        if not dic[t]:
            tmp = L - dic[s] + 1
            cnt = 0
            while tmp % 2 == 0:
                tmp //= 2
                cnt += 1
            g ^= (2**cnt)

    if g:
        print('Alice')
    else:
        print('Bob')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    N, L = map(int, input().split())
    dic = defaultdict(int)
    for _ in range(N):
        s = input().rstrip('\n')
        for i in range(len(s)):
            dic[s] = 1
            s.rstrip(s[-1])

    g = 0
    key = list(dic.keys())
    for s in key:
        t = [si for si in s]
        t[-1] = '0' if t[-1] == '1' else '1'
        t = ''.join(t)
        if not dic[t]:
            tmp = L - len(s) + 1
            cnt = 0
            while tmp % 2 == 0:
                tmp //= 2
                cnt += 1
            g ^= (2**cnt)

    if g:
        print('Alice')
    else:
        print('Bob')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
S = [input() for _ in range(N)]
S.sort()
st = []
for s in S:
    st.append(s)
    while len(st)>=2:
        s1, s2 = st[-2:]
        if s1[:-1]==s2[:-1]:
            del st[-2:]
            st.append(s1[:-1])
        else:
            break
if st[0]=="":
    print("Bob")
    exit()
#st = list(map(list, st))

def add1(s):
    if s.count("0")==0:
        return ["0"]*len(s)
    i = 1
    while s[-i]=="1":
        i+=1
    return s[:-i] + ["1"] + ["0"]*(i-1)
s_p = st[0]
from collections import defaultdict
dd_ans = defaultdict(bool)
for i, c in enumerate(s_p):
    if c=="1":
        level, m = divmod(L - i - 1, 3)
        dd_ans[(level, m % 2)] ^= True
for i, c in enumerate(st[-1]):
    if c=="0":
        level, m = divmod(L - i - 1, 3)
        dd_ans[(level, m % 2)] ^= True
for s in st[1:]:
    #print(ans)
    s_copy = s
    if len(s_p) < len(s):
        s_p += "1" * (len(s)-len(s_p))
    else:
        s += "0" * (len(s_p)-len(s))
    a = 0
    f = True
    for i, (c1, c2) in enumerate(zip(s_p, s)):
        if f:
            if c1!=c2:
                f = False
        else:
            if c1=="0":
                level, m = divmod(L-i-1, 3)
                dd_ans[(level, m % 2)] ^= True
            if c2=="1":
                level, m = divmod(L - i - 1, 3)
                dd_ans[(level, m % 2)] ^= True
    #ans ^= a
    s_p = s_copy

print("Alice" if sum(dd_ans.values()) else "Bob")

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
S = [input() for _ in range(N)]
S.sort()
st = []
for s in S:
    st.append(s)
    while len(st)>=2:
        s1, s2 = st[-2:]
        if s1[:-1]==s2[:-1]:
            del st[-2:]
            st.append(s1[:-1])
        else:
            break
if st[0]=="":
    print("Bob")
    exit()
#st = list(map(list, st))

def add1(s):
    if s.count("0")==0:
        return ["0"]*len(s)
    i = 1
    while s[-i]=="1":
        i+=1
    return s[:-i] + ["1"] + ["0"]*(i-1)
s_p = st[0]
ans = 0
Ans = [0, 0]
for i, c in enumerate(s_p):
    if c=="1":
        ans^=1<<i
        Ans[i&1] ^= 1
for i, c in enumerate(st[-1]):
    if c=="0":
        ans^=1<<i
        Ans[i&1] ^= 1
for s in st[1:]:
    #print(ans)
    s_copy = s
    if len(s_p) < len(s):
        s_p += "1" * (len(s)-len(s_p))
    else:
        s += "0" * (len(s_p)-len(s))
    a = 0
    f = True
    for i, (c1, c2) in enumerate(zip(s_p, s)):
        if f:
            if c1!=c2:
                f = False
        else:
            if c1=="0":
                a^=1<<i
                Ans[i & 1] ^= 1
            if c2=="1":
                a^=1<<i
                Ans[i & 1] ^= 1
    ans ^= a
    s_p = s_copy

print("Alice" if sum(Ans)!=0 else "Bob")
#print("Alice" if ans==0 else "Bob")

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
S = [input() for _ in range(N)]
S.sort()
st = []
for s in S:
    st.append(s)
    while len(st)>=2:
        s1, s2 = st[-2:]
        if s1[:-1]==s2[:-1]:
            del st[-2:]
            st.append(s1[:-1])
        else:
            break

print("Alice" if len(st)%2 and not st[0]=="" else "Bob")

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
ss = [input() for _ in range(n)]
prefix = set()
for s in ss:
	u = ""
	for i in range(len(s)):
		u += s[i]
		prefix.add(u)
grundy = 0
for p in prefix:
	le = len(p)
	if p[le-1] == "0":
		t = p[:le-1] + "1"
	else:
		t = p[:le-1] + "0"
	#if t not in prefix:
		#grundy ^= (l-le+1) & (-l+le-1)

if grundy == 0:
	print("Bob")
else:
	print("Alice")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import heapq

def solve(n, l, s):

    heapq.heapify(s)

    r = 0
    while len(s):
        li, si = heapq.heappop(s)
        lp = li + 1
        sp = si[:-1]
        if len(s):
            lj, sj = heapq.heappop(s)
            if lj != li or sj[:-1] != sp:
                heapq.heappush(s, (lj, sj))
                r ^= (l + li) % 2 + 1
            if lp != 0:
                heapq.heappush(s, (lp, sp))
        else:
            r ^= (l + li) % 2 + 1
            break


    return r


def main():
    n, l = input().split()
    n = int(n)
    l = int(l)
    s = []
    for _ in range(n):
        si = input()
        s.append((-len(si), si))

    print('Alice' if solve(n, l, s) else 'Bob')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from collections import deque

class Node:
    def __init__(self,depth):
        self.depth=depth
        self.left=None
        self.right=None

def insert(node,s):
    n=node
    for i in range(len(s)):
        t=s[i]
        if t=='0':
            if n.left is None:
                n.left=Node(i+1)
            n=n.left
        else:
            if n.right is None:
                n.right=Node(i+1)
            n=n.right

class Trie:
    def __init__(self):
        self.root=Node(0)
    def insert(self,x):
        insert(self.root,x)

n,l=map(int,input().split())
S=[input() for _ in range(n)]
trie=Trie()
for s in S:
    trie.insert(s)
Data=[]

def dfs(node):
    if node.right is None and node.left is None:
        return
    if node.right is None or node.left is None:
        if node.depth<l:
            Data.append(l-node.depth)
    if node.right:
        q.append(node.right)
    if node.left:
        q.append(node.left)

q=deque([trie.root])
while q:
    dfs(q.popleft())
xor=0

def Grundy(n):
    x=1
    while n%2==0:
        n//=2
        x*=2
    return x

for i in Data:
    xor^=Grundy(i)
print('Alice' if xor else 'Bob')

Submission status: Wrong Answer

Solution code:
from collections import deque
# 節の定義
class Node:
    def __init__(self, x):
        self.data  = x
        self.left  = None
        self.right = None
# 挿入
def insert(node, x):
    ima = node
    for i in range(len(x)):
        y = x[i]
        if y == "1":
            if ima.right is None:
                ima.right = Node(x[:i+1])
            ima = ima.right
        else:
            if ima.left is None:
                ima.left = Node(x[:i+1])
            ima = ima.left



class Trie:
    def __init__(self):
        self.root = Node("")

    # 挿入
    def insert(self, x):
        insert(self.root, x)

n,l = map(int,input().split())
s = [input() for i in range(n)]

trie = Trie()
for i in s:
    trie.insert(i)
data = []
que = deque([trie.root])
def dfs(node):
    if node.right is None or node.left is None:
        if l-len(node.data):
            data.append(l-len(node.data))
    if node.right:
        que.append(node.right)
    if node.left:
        que.append(node.left)
    
while que:
    dfs(que.popleft())
xor = 0
def nimber(n):
    x = 1
    while n%2 == 0: n//= 2; x*= 2
    return x
for i in data:
    xor ^= nimber(i)
print("Alice" if xor else "Bob")

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
S = sorted([input() for _ in range(N)])
eo = [True, True]
prev = '_'
for s in S:
    for i in range(min(len(s), len(prev))):
        if s[i] != prev[i]:
            while i < len(s):
                eo[i & 1] = not(eo[i & 1])
                i += 1
            break
    prev = s
print('Bob' if eo == [True, True] else 'Alice')

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
S = [input() for _ in range(N)]
eo = [True, True]
prev = '_'
for s in S:
    for i in range(min(len(s), len(prev))):
        if s[i] != prev[i]:
            while i < len(s):
                eo[i & 1] = not(eo[i & 1])
                i += 1
            break
    prev = s
print('Bob' if eo == [True, True] else 'Alice')

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
S = [input() for _ in range(N)]

bits = dict()
for s in S:
    part = ''
    for i in range(len(s)):
        bits[part] = {s[i]} if not bits.get(part) else bits[part].add(s[i])
        part += s[i]
eo = [True, True]


def walk(current):
    ne = bits.get(current)
    if ne == {'0', '1'}:
        walk(current + '0')
        walk(current + '1')
    elif ne == {'0'}:
        eo[(L - len(current)) & 1] = not(eo[(L - len(current)) & 1])
        walk(current + '0')
    elif ne == {'1'}:
        eo[(L - len(current)) & 1] = not(eo[(L - len(current)) & 1])
        walk(current + '1')

walk('')
print('Bob' if eo == [True, True] else 'Alice')

Submission status: Wrong Answer

Solution code:
def main():
    N,L = map(int,input().split())
    keys = []
    grundy_num=0
    for i in range(N):
        s = input()
        #merge node:
        while len(s)>0:
            if s[-1]=='1' and s[:-1]+'0' in keys:
                keys.remove(s[:-1]+'0')
                s = s[:-1]
            elif s[-1]=='0' and s[:-1]+'1' in keys:
                keys.remove(s[:-1]+'1')
                s = s[:-1]
            else:
                if s!="":
                    keys.append(s)
                break
    if len(keys)!=0:
        keys = sorted(keys,key=len,reverse=True)
        grundy_list = []
        while len(keys):
            j = keys[0]
            keys.remove(j)
            temp_s = list(reversed(bin(len(j))))
            grundy_list.append(1 << temp_s.index('1'))
            if j[:-1]!="":
                keys.append(j[:-1])
            j = j[:-1]
            #merge node
            while len(j)>0:
                if j[-1]=='1' and j[:-1]+'0' in keys:
                    keys.remove(j[:-1]+'0')
                    keys.remove(j)
                    j = j[:-1]
                    if j!="":
                        keys.append(j)
                elif j[-1]=='0' and j[:-1]+'1' in keys:
                    keys.remove(j[:-1]+'1')
                    keys.remove(j)
                    j = j[:-1]
                    if j!="":
                        keys.append(j)
                else:
                    break
            keys = sorted(keys,key=len,reverse=True)
        grundy_num = grundy_list[0]
        for i in range(1,len(grundy_list)):
            grundy_num = grundy_num^grundy_list[i]
    print("Bob" if grundy_num==0 else "Alice")


if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N,L = map(int,input().split())
    keys = []
    grundy_num=0
    for i in range(N):
        s = input()
        #merge node:
        while len(s)>0:
            if s[-1]=='1' and s[:-1]+'0' in keys:
                keys.remove(s[:-1]+'0')
                s = s[:-1]
            elif s[-1]=='0' and s[:-1]+'1' in keys:
                keys.remove(s[:-1]+'1')
                s = s[:-1]
            else:
                if s!="":
                    keys.append(s)
                break
    if len(keys)!=0:
        keys = sorted(keys,key=len,reverse=True)
        grundy_list = []
        while len(keys):
            j = keys[0]
            keys.remove(j)
            temp_s = list(reversed(bin(len(j))))
            grundy_list.append(1 << temp_s.index('1'))
            if j[:-1]!="":
                keys.append(j[:-1])
            j = j[:-1]
            #merge node
            while len(j)>0:
                if j[-1]=='1' and j[:-1]+'0' in keys:
                    keys.remove(j[:-1]+'0')
                    keys.remove(j)
                    j = j[:-1]
                    if j!="":
                        keys.append(j)
                elif j[-1]=='0' and j[:-1]+'1' in keys:
                    keys.remove(j[:-1]+'1')
                    keys.remove(j)
                    j = j[:-1]
                    if j!="":
                        keys.append(j)
                else:
                    break
            keys = sorted(keys,key=len,reverse=True)
            grundy_num = grundy_list[0]
        for i in range(1,len(grundy_list)):
            grundy_num = grundy_num^grundy_list[i]
    print("Bob" if grundy_num==0 else "Alice")


if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N,L = map(int,input().split())
    if N==1:
        print("Bob")
        exit()
    keys = []
    count = 0
    for i in range(N):
        s = input()
        #merge node:
        while len(s)>0:
            if s[-1]=='1' and s[:-1]+'0' in keys:
                keys.remove(s[:-1]+'0')
                s = s[:-1]
            elif s[-1]=='0' and s[:-1]+'1' in keys:
                keys.remove(s[:-1]+'1')
                s = s[:-1]
            else:
                if s!="":
                    keys.append(s)
                break
    if len(keys)!=0:
        keys = sorted(keys,key=len,reverse=True)
    while len(keys)>0:
        j = keys[0]
        keys.remove(j)
        if j[:-1]!="":
            keys.append(j[:-1])
        j = j[:-1]
        #merge node
        while len(j)>0:
            if j[-1]=='1' and j[:-1]+'0' in keys:
                keys.remove(j[:-1]+'0')
                keys.remove(j)
                j = j[:-1]
                if j!="":
                    keys.append(j)
            elif j[-1]=='0' and j[:-1]+'1' in keys:
                keys.remove(j[:-1]+'1')
                keys.remove(j)
                j = j[:-1]
                if j!="":
                    keys.append(j)
            else:
                break
        keys = sorted(keys,key=len,reverse=True)
        count+=1
    print("Bob" if count&1 ==0 else "Alice")


if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N,L = map(int,input().split())
    if N==1:
        print("Alice")
        exit()
    keys = []
    count = 0
    for i in range(N):
        s = input()
        #merge node:
        while len(s)>0:
            if s[-1]=='1' and s[:-1]+'0' in keys:
                keys.remove(s[:-1]+'0')
                s = s[:-1]
            elif s[-1]=='0' and s[:-1]+'1' in keys:
                keys.remove(s[:-1]+'1')
                s = s[:-1]
            else:
                if s!="":
                    keys.append(s)
                break
    if len(keys)!=0:
        keys = sorted(keys,key=len,reverse=True)
    while len(keys)!=0:
        j = keys[0]
        keys.remove(j)
        if j[:-1]!="":
            keys.append(j[:-1])
        j = j[:-1]
        #merge node
        while len(j)>0:
            if j[-1]=='1' and j[:-1]+'0' in keys:
                keys.remove(j[:-1]+'0')
                keys.remove(j)
                j = j[:-1]
                if j!="":
                    keys.append(j)
            elif j[-1]=='0' and j[:-1]+'1' in keys:
                keys.remove(j[:-1]+'1')
                keys.remove(j)
                j = j[:-1]
                if j!="":
                    keys.append(j)
            else:
                break
        keys = sorted(keys,key=len,reverse=True)
        count+=1
    print("Bob" if count&1 ==0 else "Alice")


if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def solve(l, ss):
    xor = 0
    for d in range(min(ss), l + 1):
        sl = ss[d]
        sl.sort()
        while sl:
            s = sl.pop()
            ps = s[:-1]
            ss[d + 1].append(ps)
            if s[-1] == '1':
                if sl and sl[-1][:-1] == ps:
                    sl.pop()
                else:
                    xor ^= d & -d
        del ss[d]
    return xor


n, l = map(int, input().split())
ss = defaultdict(list)
for s in (input() for _ in range(n)):
    ss[l - len(s) + 1].append(s)

print('Alice' if solve(l, ss) else 'Bob')

Submission status: Wrong Answer

Solution code:
N, L = map(int, input().split())
s = sorted([int('1' + input(), 2) for _ in range(N)])

bits = set()
while s != []:
    i = s.pop()
    while i != 1:
        if i in bits:
            bits.discard(i)
        else:
            bits.add(i ^ 1)
        i >>= 1
eo = [True, True]
for bit in bits:
    eo[(L - len(bin(bit))) & 1] = not(eo[(L - len(bin(bit))) & 1])
print('Bob' if eo == [True, True] else 'Alice')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2 * 10 ** 5)

class TrieNode:
    def __init__(self, char):
        self.char = char
        self.nextnode = dict()
        self.is_indict = False


class Trie:
    def __init__(self, charset):
        self.charset = charset
        self.root = TrieNode('')

    def add(self, a_str):
        node = self.root
        for i, char in enumerate(a_str):
            if char not in node.nextnode:
                node.nextnode[char] = TrieNode(char)
            node = node.nextnode[char]
            if i == len(a_str) - 1:
                node.is_indict = True

    def dfs(self, node, dep):
        ret, cnt = 0, 0
        if node.is_indict:
            return 0
        for s in '01':
            if s not in node.nextnode:
                cnt += 1
            else:
                ret ^= self.dfs(node.nextnode[s], dep + 1)
        dep += 1
        if cnt % 2:
            power2 = 0
            while dep > 0 and dep % 2 == 0:
                power2 += 1
                dep //= 2
            ret ^= 2 ** power2
        return ret

    def debug_output(self, node, now):
        print(node.char, list(node.nextnode.items()), node.is_indict, now)
        if node.is_indict:
            print(now)
        for n in node.nextnode.values():
            self.debug_output(n, now + n.char)

N, L = map(int, input().split())
T = Trie('01')
for _ in range(N):
    T.add(input())
# T.debug_output(T.root, '')
print("Alice" if T.dfs(T.root, 0) else "Bob")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2 * 10 ** 5)

class TrieNode:
    def __init__(self, char):
        self.char = char
        self.nextnode = dict()
        self.is_indict = False


class Trie:
    def __init__(self, charset):
        self.charset = charset
        self.root = TrieNode('')

    def add(self, a_str):
        node = self.root
        for i, char in enumerate(a_str):
            if char not in node.nextnode:
                node.nextnode[char] = TrieNode(char)
            node = node.nextnode[char]
            if i == len(a_str) - 1:
                node.is_indict = True

    def dfs(self, node, dep):
        ret, cnt = 0, 0
        for s in '01':
            if s not in node.nextnode:
                cnt += 1
            else:
                ret ^= self.dfs(node.nextnode[s], dep + 1)
        dep += 1
        if cnt % 2:
            power2 = 0
            while dep > 0 and dep % 2 == 0:
                power2 += 1
                dep //= 2
            ret ^= 2 ** power2
        return ret

    def debug_output(self, node, now):
        print(node.char, list(node.nextnode.items()), node.is_indict, now)
        if node.is_indict:
            print(now)
        for n in node.nextnode.values():
            self.debug_output(n, now + n.char)

N, L = map(int, input().split())
T = Trie('01')
for _ in range(N):
    T.add(input())
# T.debug_output(T.root, '')
print("Alice" if T.dfs(T.root, 0) else "Bob")

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
ss = [input() for _ in range(n)]

ds = set()
bs = set()
for s in ss:
    i = int(s, 2) + (1 << len(s))
    while i >= 1:
        if i in ds:
            bs.add(i << 1)
            bs.add((i << 1) + 1)
            break
        ds.add(i)
        i >>= 1
xor = 0
for r in ds - bs:
    level = r.bit_length() - 1
    xor ^= level & -level

print('Alice' if xor else 'Bob')

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
ss = [input() for _ in range(n)]

ds = set()
bs = set()
for s in ss:
    i = int(s, 2) + (1 << len(s))
    while i >= 2:
        if i in ds:
            bs.add(i << 1)
            bs.add((i << 1) + 1)
            break
        ds.add(i)
        i >>= 1
xor = 0
for r in ds - bs:
    level = r.bit_length() - 1
    xor ^= level & -level

print('Alice' if xor else 'Bob')

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
ss = [input() for _ in range(n)]

rs = set()
ns = set()
for s in ss:
    i = int(s, 2) + (1 << len(s))
    while i >= 2:
        if i in ns:
            break
        if i in rs:
            rs.discard(i)
            break
        j = i ^ 1
        rs.add(j)
        ns.add(i)
        i >>= 1
xor = 0
for r in rs:
    level = r.bit_length() - 1
    xor ^= level & -level

print('Alice' if xor else 'Bob')

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
ss = [input() for _ in range(n)]

rs = set()
ns = set()
for s in ss:
    i = int(s, 2) + (1 << len(s))
    while i >= 2:
        j = i ^ 1
        if j not in ns:
            rs.add(j)
        ns.add(i)
        if i in rs:
            rs.discard(i)
            break
        i >>= 1
xor = 0
for r in rs:
    level = r.bit_length() - 1
    xor ^= level & -level

print('Alice' if xor else 'Bob')

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
ss = [input() for _ in range(n)]
max_d = max(map(len, ss))

tree = [0] * (2 * max_d)

rs = set()
ns = set()
for s in ss:
    i = int(s, 2) + (1 << len(s))
    while i >= 2:
        if i in rs:
            rs.discard(i)
        j = i ^ 1
        if j not in ns:
            rs.add(j)
        ns.add(i)
        i //= 2
xor = 0
for r in rs:
    level = r.bit_length() - 1
    xor ^= level & -level

print('Alice' if xor else 'Bob')

Submission status: Wrong Answer

Solution code:
n,l = map(int, input().split())
s = [input() for i in range(n)]
s.sort()

inputs = []
if s[0][0] != '0':
    inputs.append('0')
if s[-1][0] != '1':
    inputs.append('1')

for i in range(n):
    if s[i][-1] == '0':
        if (i==n-1 or s[i+1] != s[i][:-1]+'1'):
            inputs.append(s[i][:-1]+'1')
    elif s[i][-1] == '1':
        if (i==0 or s[i-1] != s[i][:-1]+'0'):
            inputs.append(s[i][:-1]+'0')
inputs.sort()
lt = len(inputs)
trees = []
for i in range(lt):
    if i==lt-1 or inputs[i] != inputs[i+1][:len(inputs[i])]:
        trees.append(inputs[i])
lt = len(trees)
if lt == 0:
    print('Bob')
    exit()
elif lt == 1:
    print('Alice')
    exit()


g = 0
for t in trees:
    lt = len(t)
    gi = 1
    while lt%gi == 0:
        gi *=2
    g = g ^ gi
if g%2 == 0:
    print('Bob')
    exit()
else:
    print('Alice')
    exit()

Submission status: Wrong Answer

Solution code:
n,l = map(int, input().split())
s = [input() for i in range(n)]
s.sort()

inputs = []
if s[0][0] != '0':
    inputs.append('0')
if s[-1][0] != '1':
    inputs.append('1')

for i in range(n):
    if s[i][-1] == '0':
        if (i==n-1 or s[i+1] != s[i][:-1]+'1'):
            inputs.append(s[i][:-1]+'1')
    elif s[i][-1] == '1':
        if (i==0 or s[i-1] != s[i][:-1]+'0'):
            inputs.append(s[i][:-1]+'0')
inputs.sort()
lt = len(inputs)
trees = []
for i in range(lt):
    if i==lt-1 or inputs[i] != inputs[i+1][:len(inputs[i])]:
        trees.append(inputs[i])
lt = len(trees)
if lt == 0:
    print('Bob')
    exit()
elif lt == 1:
    print('Alice')
    exit()


g = 0
for t in trees:
    g = g ^ (len(t)&-len(t))
if g%2 == 0:
    print('Bob')
    exit()
else:
    print('Alice')
    exit()

Submission status: Wrong Answer

Solution code:
n,l = map(int, input().split())
s = [input() for i in range(n)]
s.sort()

inputs = []
if s[0][0] != '0':
    inputs.append('0')
if s[-1][0] != '1':
    inputs.append('1')

for i in range(n):
    if s[i][-1] == '0':
        if (i==n-1 or s[i+1] != s[i][:-1]+'1'):
            inputs.append(s[i][:-1]+'1')
    elif s[i][-1] == '1':
        if (i==0 or s[i-1] != s[i][:-1]+'0'):
            inputs.append(s[i][:-1]+'0')
inputs.sort()
lt = len(inputs)
trees = []
for i in range(lt):
    if i==lt-1 or inputs[i] != inputs[i+1][:len(inputs[i])]:
        trees.append(inputs[i])
lt = len(trees)
if lt == 0:
    print('Bob')
    exit()
elif lt == 1:
    print('Alice')
    exit()


g = 0
for t in trees:
    g = g ^ (len(t)-1)
if g%2 == 0:
    print('Bob')
    exit()
else:
    print('Alice')
    exit()