Problem p02837 (python)

Fixed submission:

def main():
    
    n = int(input())

    n_list = []
    for i in range(n):
        a_list = []
        a = int(input())
        for j in range(a):
            x,y = map(int, input().split())
            x -= 1
            a_list.append([x,y])
        if a == 0:
            a_list.append([0])
        n_list.append(a_list)

    #print(n_list)
    ans = [0]
    for j in range(0,2**n):
        tmp = bin(j)
        tmp = str(int(tmp[2:])).zfill(n)
        #print('tmp')
        #print(tmp)
        
        
        break_on = 0
        for k in range(n):
            if tmp[k] == '1':
                #print(n_list[k])
                if n_list[k][0] != [0]:
                    for h in n_list[k]:
                        #print('########')
                        #print(k)
                        #print(h[1])
                        #print(tmp[h[0]])
                        if h[1] != int(tmp[h[0]]):
                            break_on = 1
                            break
                    if break_on == 1:
                        break
            if break_on == 1:
                break
            
            if tmp[k] == '0':
                continue
        
        if break_on == 0:
            #print('tmp.count()')
            #print(tmp.count('1'))
            ans.append(tmp.count('1'))
    
    #print(ans)
    print(max(ans))
    


            



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

def main():
    
    n = int(input())

    n_list = []
    for i in range(n):
        a_list = []
        a = int(input())
        for j in range(a):
            x,y = map(int, input().split())
            x -= 1
            a_list.append([x,y])
        if a == 0:
            a_list.append([0])
        n_list.append(a_list)

    #print(n_list)
    ans = [0]
    for j in range(0,2**n):
        tmp = bin(j)
        tmp = str(int(tmp[2:])).zfill(n)
        #print('tmp')
        #print(tmp)
        
        
        break_on = 0
        for k in range(n):
            if tmp[k] == '1':
                if n_list[k][0] != 0:
                    for h in n_list[k]:
                        #print('########')
                        #print(k)
                        #print(h[1])
                        #print(tmp[h[0]])
                        if h[1] != int(tmp[h[0]]):
                            break_on = 1
                            break
                    if break_on == 1:
                        break
            if break_on == 1:
                break
            
            if tmp[k] == '0':
                continue
        
        if break_on == 0:
            #print('tmp.count()')
            #print(tmp.count('1'))
            ans.append(tmp.count('1'))
    
    #print(ans)
    print(max(ans))
    


            



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

def main():
    
    n = int(input())

    n_list = []
    for i in range(n):
        a_list = []
        a = int(input())
        for j in range(a):
            x,y = map(int, input().split())
            x -= 1
            a_list.append([x,y])
        if a == 0:
            a_list.append([0])
        n_list.append(a_list)

    #print(n_list)
    ans = [0]
    for j in range(0,2**n):
        tmp = bin(j)
        tmp = str(int(tmp[2:])).zfill(n)
        #print('tmp')
        #print(tmp)
        
        
        break_on = 0
        for k in range(n):
            if tmp[k] == '1':
                for h in n_list[k]:
                    #print('########')
                    #print(k)
                    #print(h[1])
                    #print(tmp[h[0]])
                    if h[1] != int(tmp[h[0]]):
                        break_on = 1
                        break
                if break_on == 1:
                    break
            if break_on == 1:
                break
            
            if tmp[k] == '0':
                continue
        
        if break_on == 0:
            #print('tmp.count()')
            #print(tmp.count('1'))
            ans.append(tmp.count('1'))
    
    #print(ans)
    print(max(ans))
    


            



if __name__ == '__main__':
    main()