App=int(input()) app=App-1 saba=0 sum=0 into=1 pop=0 Q,A,Z,W,S,X,E,D,C,R,F,V,T,G,B,Y,H,N,U,J,M,I,K,O,L,P=map(int,input().split()) QQ,AA,ZZ,WW,SS,XX,EE,DD,CC,RR,FF,VV,TT,GG,BB,YY,HH,NN,UU,JJ,MM,II,KK,OO,LL,PP=map(int,input().split()) q,a,z,w,s,x,e,d,c,r,f,v,t,g,b,y,h,n,u,j,m,i,k,o,l,p=map(int,input().split()) qq,aa,zz,ww,ss,xx,ee,dd,cc,rr,ff,vv,tt,gg,bb,yy,hh,nn,uu,jj,mm,ii,kk,oo,ll,pp=map(int,input().split()) iti=Q+A+Z+W+S+X+E+D+C+R+F+V+T+G+B+Y+H+N+U+J+M+I+K+O+L+P ni=QQ+AA+ZZ+WW+SS+XX+EE+DD+CC+RR+FF+VV+TT+GG+BB+YY+HH+NN+UU+JJ+MM+II+KK+OO+LL+PP san=q+a+z+w+s+x+e+d+c+r+f+v+t+g+b+y+h+n+u+j+m+i+k+o+l+p yon=qq+aa+zz+ww+ss+xx+ee+dd+cc+rr+ff+vv+tt+gg+bb+yy+hh+nn+uu+jj+mm+ii+kk+oo+ll+pp for _ in range(100): wow=iti+ni+san+yon+into if wow%App == 0: pop=pop+1 i=i+1 print(pop)