#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"I=input;n=int(I());f=[int(I()[::2],2)for _ in[0]*n];p=[I().split()for _ in[0]*n];print(max(sum(int(q[bin(i&g).count('1')])for g,q in zip(f,p))for i in range(1,1024)))\n"
"\"";
  system(s);
  return 0;
}            