read n while read a b do((p|=1+a%2,s+=m[m>a]=a+=b*4)) done echo $[p<3?m*n-s>>1:-1]