N = int(raw_input())
lis = []
last = []
for num in xrange(N*2):
  lis.append( map(int,raw_input().split()) )
for a in xrange(2):
  for b in xrange(2):
    for c in xrange(2):
      for d in xrange(2):
        for e in xrange(2):
          for f in xrange(2):
            for g in xrange(2):
              for h in xrange(2):
                for i in xrange(2):
                  for j in xrange(2):
                    sumlis = []
                    for numb in xrange(N):
                      count = 0
                      for select in xrange(10):
                        check = [a,b,c,d,e,f,g,h,i,j]
                        if check == [0,0,0,0,0,0,0,0,0,0]:
                          continue
                        if check[select] == 1 and lis[numb][select] == 1:
                          count += 1
                      sumlis.append(lis[numb + N][count])
                    last.append(sum(sumlis))
print max(last)