#include #include #include using namespace std; const int MAX_LENGTH = 1000000; int length; int stomp[2][3]; int field[2][MAX_LENGTH+1]; void stomper(int col) { field[0][col] = field[0][col] ^ stomp[0][0]; field[1][col] = field[1][col] ^ stomp[1][0]; field[0][col+1] = field[0][col+1] ^ stomp[0][1]; field[1][col+1] = field[1][col+1] ^ stomp[1][1]; field[0][col+2] = field[0][col+2] ^ stomp[0][2]; field[1][col+2] = field[1][col+2] ^ stomp[1][2]; } int sumField(int col) { int temp = 0; temp = temp + field[0][col] + field[0][col+1] + field[0][col+2]; temp = temp + field[1][col] + field[1][col+1] + field[1][col+2]; return temp; } int sumStomped(int col) { int temp = 0; temp += (field[0][col+0] ^ stomp[0][0]); temp += (field[0][col+1] ^ stomp[0][1]); temp += (field[0][col+2] ^ stomp[0][2]); temp += (field[1][col+0] ^ stomp[1][0]); temp += (field[1][col+1] ^ stomp[1][1]); temp += (field[1][col+2] ^ stomp[1][2]); return temp; } int main() { ifstream fin("input.txt"); assert( fin ); fin >> length; fin >> stomp[0][0] >> stomp[0][1] >> stomp[0][2]; fin >> stomp[1][0] >> stomp[1][1] >> stomp[1][2]; //popolo il campo for(int i = 0; i < length; i++) fin >> field[0][i]; for(int i = 0; i < length; i++) fin >> field[1][i]; int ones = 0; if (length > 2) { int temp = 0; for(int i = 0; i < length-2; i++) { if (sumField(i) > sumStomped(i)) stomper(i); ones += (field[0][i] + field[1][i]); } ones = ones + field[0][length-2] + field[0][length-1] + field[1][length-2] + field[1][length-1]; } else for(int i = 0; i < length; i++) ones += (field[0][i]+field[1][i]); ofstream fout("output.txt"); assert( fout ); fout << ones << endl; fout.close(); return 0; }