Input / output: | interactive | Time limit: | 1 sec | |
Memory limit: | 256 Mb |
This is an interactive problem. Your program will interact with a jury program by sending and receiving particular messages.
The jury has a two-dimensional matrix with N rows and M columns filled with numbers, where each number can be either 1 or 0. Rows are numbered from 1 to N from top to bottom, and columns are numbered from 1 to M from left to right.
Your program can make queries of the form "? Xi Yi Ai Bi
",
where i is the query number,
Xi, Yi represent the coordinates of the top-left corner of the rectangle, denoting the row and column numbers, respectively.
On the other hand, Ai, Bi indicate the dimensions of the rectangle, representing the number of rows and columns, respectively.
In response to the query, the jury's program will report the number of ones in the rectangle specified by the query.
Each rectangle must be entirely within the matrix, meaning the following inequalities must be satisfied:
1 ≤ Xi, Ai ≤ N and 1 ≤ Yi, Bi ≤ M
Xi + Ai − 1 ≤ N and Yi + Bi − 1 ≤ M
There are also constraints on the sizes of rectangles. The first rectangle must be smaller than the matrix on each side without considering orientation, and each subsequent rectangle must be smaller than the previous one on each side without considering orientation. More formally, the following inequalities must be satisfied:
min(A1, B1) < min(N, M) and max(A1, B1) < max(N, M)
min(Ai, Bi) < min(Ai − 1, Bi − 1) and max(Ai, Bi) < max(Ai − 1, Bi − 1) by i > 1
The goal is to determine the number of ones in the matrix by making any number of queries. It is guaranteed that the values in the matrix are predefined and do not depend on the queries.
The first line of input contains two integers N and M, the dimensions of the matrix.
To make the i-th query, your program should output "? Xi Yi Ai Bi
",
where Xi, Yi are integers, the coordinates of the top-left corner of the rectangle, row and column numbers respectively.
On the other hand Ai, Bi are integers, the dimensions of the rectangle, representing the number of rows and columns, respectively.
After the query, the jury's program responds to your program with an integer S, the number of ones in the specified rectangle.
When your program determines the answer to the task, it should output "! S
",
where S is an integer, the number of ones in the matrix.
After outputting the answer, the program should terminate.
If your program makes incorrect query, it will receive "Presentation error" verdict.
Every query and final output must be a single line ending with single end-of-line (\n
).
Output buffers must be flushed after every line:
Language | C++ | Pascal | Java | Python |
Code | cout.flush() |
flush(output) |
System.out.flush() |
stdout.flush() |
10 ≤ N, M ≤ 100
0 ≤ S ≤ 104
The matrices from the examples are represented in the picture.
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|