B. Absorption Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Example
Input
5
7 6 3 2 5
7
? 1 3
? 2 5
! 2 4 A
? 1 3
! 1 2 A
! 2 5 D
? 1 3
Output
223
503
47
39