#B3948. Misaligned Multiple-Choice Scoring

    ID: 11605 Type: Default 1000ms 256MiB

Misaligned Multiple-Choice Scoring

Misaligned Multiple-Choice Scoring

In an exam, there are ( n ) multiple-choice questions numbered from (0) to (n-1). Each question has 4 options; for each question, an option is either correct or wrong. The scoring rule for a question is as follows:

  1. If at least one wrong option is selected or no option is selected at all, the score is 0.
  2. If all the correct options are selected and no wrong option is selected, the score is 6.
  3. If a non-empty proper subset of correct options is selected (and no wrong option), the score is 3.

The correctness of each option for every question is given by an ( n \times 4 ) binary matrix ( a ) where ( a_{i,j} = 1 ) means that the ( j )th option for question ( i ) (0-indexed) is correct, and 0 otherwise.

Due to a mistake, the answer sheet has been misaligned. The examinee's answers are recorded in an ( n \times 4 ) binary matrix ( b ) where the ( i )th row corresponds to the answers filled in for the ( i )th answered question (in order) and ( b_{i,j} = 1 ) means the ( j )th option was selected. However, if the first answered question is actually question number ( x ) (where ( x ) is in ( [0, n-1] )), then the examinee answers the questions in the order ( x, (x+1)\bmod n, (x+2)\bmod n, \ldots, (x+n-1)\bmod n ).

Your task is to compute, for each ( i ) from ( 0 ) to ( n-1 ), the total score the examinee would get if his first answered question were question ( i ).

inputFormat

The input begins with an integer ( n ) representing the number of questions. This is followed by ( n ) lines, each containing 4 space-separated integers (either 0 or 1) representing the matrix ( a ) (the correct answers for each question). After that, there are ( n ) lines, each containing 4 space-separated integers (either 0 or 1) representing the matrix ( b ) (the answers filled by the examinee in order).

outputFormat

Output a single line containing ( n ) space-separated integers. The ( i )th integer denotes the total score the examinee would earn if the first answered question is question number ( i ).

sample

2
1 0 0 1
0 1 0 0
1 0 0 0
0 1 0 0
9 0