Buggy python submission (verdict: Runtime Error):
n=int(input())

ans=-10**9
f=[[0 for i in range(10)] for j in range(n)]
p=[[0 for i in range(11)] for j in range(n)]

for i in range(n):
  f[i]=[int(i) for i in input().split()]
for i in range(n):
  p[i]=[int(i) for i in input().split()]


for i1 in range(2):
  for i2 in range(2):
    for i3 in range(2):
      for i4 in range(2):
        for i5 in range(2):
          for i6 in range(2):
            for i7 in range(2):
              for i8 in range(2):
                for i9 in range(2):
                  for i10 in range(2):
                    sumi=i1+i2+i3+i4+i5+i6+i7+i8+i9+i10
                    count=[0 for i in range(11)]
                    for ii in range(n):
                        if i1==f[ii][0] and i1==1:
                          count[ii]=count[ii]+1
                        if i2==f[ii][1] and i2==1:
                          count[ii]=count[ii]+1
                        if i3==f[ii][2] and i3==1:
                          count[ii]=count[ii]+1
                        if i4==f[ii][3] and i4==1:
                          count[ii]=count[ii]+1   
                        if i5==f[ii][4] and i5==1:
                          count[ii]=count[ii]+1
                        if i6==f[ii][5] and i6==1:
                          count[ii]=count[ii]+1
                        if i7==f[ii][6] and i7==1:
                          count[ii]=count[ii]+1
                        if i8==f[ii][7] and i8==1:
                          count[ii]=count[ii]+1
                        if i9==f[ii][8] and i9==1:
                          count[ii]=count[ii]+1   
                        if i10==f[ii][9] and i10==1:
                          count[ii]=count[ii]+1                          
                    
                    if sumi>0:
                      ans_0=0
                      #print(count)
                      for i in range(n):
                         ans_0=ans_0+p[i][count[i]]
                      ans=max(ans,ans_0)
                          
                                                                            
print(ans)                     
                      
                      
                      
                      
                      
                      
                      
                      
                      

Fixed submission:
n=int(input())

ans=-10**9
f=[[0 for i in range(10)] for j in range(n)]
p=[[0 for i in range(11)] for j in range(n)]

for i in range(n):
  f[i]=[int(i) for i in input().split()]
for i in range(n):
  p[i]=[int(i) for i in input().split()]


for i1 in range(2):
  for i2 in range(2):
    for i3 in range(2):
      for i4 in range(2):
        for i5 in range(2):
          for i6 in range(2):
            for i7 in range(2):
              for i8 in range(2):
                for i9 in range(2):
                  for i10 in range(2):
                    sumi=i1+i2+i3+i4+i5+i6+i7+i8+i9+i10
                    count=[0 for i in range(n)]
                    for ii in range(n):
                        if i1==f[ii][0] and i1==1:
                          count[ii]=count[ii]+1
                        if i2==f[ii][1] and i2==1:
                          count[ii]=count[ii]+1
                        if i3==f[ii][2] and i3==1:
                          count[ii]=count[ii]+1
                        if i4==f[ii][3] and i4==1:
                          count[ii]=count[ii]+1   
                        if i5==f[ii][4] and i5==1:
                          count[ii]=count[ii]+1
                        if i6==f[ii][5] and i6==1:
                          count[ii]=count[ii]+1
                        if i7==f[ii][6] and i7==1:
                          count[ii]=count[ii]+1
                        if i8==f[ii][7] and i8==1:
                          count[ii]=count[ii]+1
                        if i9==f[ii][8] and i9==1:
                          count[ii]=count[ii]+1   
                        if i10==f[ii][9] and i10==1:
                          count[ii]=count[ii]+1                          
                    
                    if sumi>0:
                      ans_0=0
                      #print(count)
                      for i in range(n):
                         ans_0=ans_0+p[i][count[i]]
                      ans=max(ans,ans_0)
                          
                                                                            
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())

ans=-10**9
f=[[0 for i in range(10)] for j in range(n)]
p=[[0 for i in range(11)] for j in range(n)]

for i in range(n):
  f[i]=[int(i) for i in input().split()]
for i in range(n):
  p[i]=[int(i) for i in input().split()]


for i1 in range(2):
  for i2 in range(2):
    for i3 in range(2):
      for i4 in range(2):
        for i5 in range(2):
          for i6 in range(2):
            for i7 in range(2):
              for i8 in range(2):
                for i9 in range(2):
                  for i10 in range(2):
                    sumi=i1+i2+i3+i4+i5+i6+i7+i8+i9+i10
                    count=[0 for i in range(10)]
                    for ii in range(n):
                        if i1==f[ii][0] and i1==1:
                          count[ii]=count[ii]+1
                        if i2==f[ii][1] and i2==1:
                          count[ii]=count[ii]+1
                        if i3==f[ii][2] and i3==1:
                          count[ii]=count[ii]+1
                        if i4==f[ii][3] and i4==1:
                          count[ii]=count[ii]+1   
                        if i5==f[ii][4] and i5==1:
                          count[ii]=count[ii]+1
                        if i6==f[ii][5] and i6==1:
                          count[ii]=count[ii]+1
                        if i7==f[ii][6] and i7==1:
                          count[ii]=count[ii]+1
                        if i8==f[ii][7] and i8==1:
                          count[ii]=count[ii]+1
                        if i9==f[ii][8] and i9==1:
                          count[ii]=count[ii]+1   
                        if i10==f[ii][9] and i10==1:
                          count[ii]=count[ii]+1                          
                    
                    if sumi>0:
                      ans_0=0
                      #print(count)
                      for i in range(n):
                         ans_0=ans_0+p[i][count[i]]
                      ans=max(ans,ans_0)
                          
                                                                            
print(ans)                     
                      
                      
                      
                      
                      
                      
                      
                      
                      

Fixed submission:
n=int(input())

ans=-10**9
f=[[0 for i in range(10)] for j in range(n)]
p=[[0 for i in range(11)] for j in range(n)]

for i in range(n):
  f[i]=[int(i) for i in input().split()]
for i in range(n):
  p[i]=[int(i) for i in input().split()]


for i1 in range(2):
  for i2 in range(2):
    for i3 in range(2):
      for i4 in range(2):
        for i5 in range(2):
          for i6 in range(2):
            for i7 in range(2):
              for i8 in range(2):
                for i9 in range(2):
                  for i10 in range(2):
                    sumi=i1+i2+i3+i4+i5+i6+i7+i8+i9+i10
                    count=[0 for i in range(n)]
                    for ii in range(n):
                        if i1==f[ii][0] and i1==1:
                          count[ii]=count[ii]+1
                        if i2==f[ii][1] and i2==1:
                          count[ii]=count[ii]+1
                        if i3==f[ii][2] and i3==1:
                          count[ii]=count[ii]+1
                        if i4==f[ii][3] and i4==1:
                          count[ii]=count[ii]+1   
                        if i5==f[ii][4] and i5==1:
                          count[ii]=count[ii]+1
                        if i6==f[ii][5] and i6==1:
                          count[ii]=count[ii]+1
                        if i7==f[ii][6] and i7==1:
                          count[ii]=count[ii]+1
                        if i8==f[ii][7] and i8==1:
                          count[ii]=count[ii]+1
                        if i9==f[ii][8] and i9==1:
                          count[ii]=count[ii]+1   
                        if i10==f[ii][9] and i10==1:
                          count[ii]=count[ii]+1                          
                    
                    if sumi>0:
                      ans_0=0
                      #print(count)
                      for i in range(n):
                         ans_0=ans_0+p[i][count[i]]
                      ans=max(ans,ans_0)
                          
                                                                            
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())

ans=-10**9
f=[[0 for i in range(10)] for j in range(n)]
p=[[0 for i in range(10)] for j in range(n)]

for i in range(n):
  f[i]=[int(i) for i in input().split()]
for i in range(n):
  p[i]=[int(i) for i in input().split()]



for i1 in range(2):
  for i2 in range(2):
    for i3 in range(2):
      for i4 in range(2):
        for i5 in range(2):
          for i6 in range(2):
            for i7 in range(2):
              for i8 in range(2):
                for i9 in range(2):
                  for i10 in range(2):
                    sumi=i1+i2+i3+i4+i5+i6+i7+i8+i9+i10
                    count=[0 for i in range(10)]
                    for ii in range(n):
                        if i1==f[ii][0] and i1==1:
                          count[ii]=count[ii]+1
                        if i2==f[ii][1] and i2==1:
                          count[ii]=count[ii]+1
                        if i3==f[ii][2] and i3==1:
                          count[ii]=count[ii]+1
                        if i4==f[ii][3] and i4==1:
                          count[ii]=count[ii]+1   
                        if i5==f[ii][4] and i5==1:
                          count[ii]=count[ii]+1
                        if i6==f[ii][5] and i6==1:
                          count[ii]=count[ii]+1
                        if i7==f[ii][6] and i7==1:
                          count[ii]=count[ii]+1
                        if i8==f[ii][7] and i8==1:
                          count[ii]=count[ii]+1
                        if i9==f[ii][8] and i9==1:
                          count[ii]=count[ii]+1   
                        if i10==f[ii][9] and i10==1:
                          count[ii]=count[ii]+1                          
                    
                    if sumi>0:
                      ans_0=0
                      #print(count)
                      for i in range(n):
                        if count[i]!=0:
                          ans_0=ans_0+p[i][count[i]]
                        
                      ans=max(ans,ans_0)
                          
                                                                            
print(ans)                     
                      
                      
                      
                      
                      
                      
                      
                      
                      

Fixed submission:
n=int(input())

ans=-10**9
f=[[0 for i in range(10)] for j in range(n)]
p=[[0 for i in range(11)] for j in range(n)]

for i in range(n):
  f[i]=[int(i) for i in input().split()]
for i in range(n):
  p[i]=[int(i) for i in input().split()]


for i1 in range(2):
  for i2 in range(2):
    for i3 in range(2):
      for i4 in range(2):
        for i5 in range(2):
          for i6 in range(2):
            for i7 in range(2):
              for i8 in range(2):
                for i9 in range(2):
                  for i10 in range(2):
                    sumi=i1+i2+i3+i4+i5+i6+i7+i8+i9+i10
                    count=[0 for i in range(n)]
                    for ii in range(n):
                        if i1==f[ii][0] and i1==1:
                          count[ii]=count[ii]+1
                        if i2==f[ii][1] and i2==1:
                          count[ii]=count[ii]+1
                        if i3==f[ii][2] and i3==1:
                          count[ii]=count[ii]+1
                        if i4==f[ii][3] and i4==1:
                          count[ii]=count[ii]+1   
                        if i5==f[ii][4] and i5==1:
                          count[ii]=count[ii]+1
                        if i6==f[ii][5] and i6==1:
                          count[ii]=count[ii]+1
                        if i7==f[ii][6] and i7==1:
                          count[ii]=count[ii]+1
                        if i8==f[ii][7] and i8==1:
                          count[ii]=count[ii]+1
                        if i9==f[ii][8] and i9==1:
                          count[ii]=count[ii]+1   
                        if i10==f[ii][9] and i10==1:
                          count[ii]=count[ii]+1                          
                    
                    if sumi>0:
                      ans_0=0
                      #print(count)
                      for i in range(n):
                         ans_0=ans_0+p[i][count[i]]
                      ans=max(ans,ans_0)
                          
                                                                            
print(ans)