Broken Piano | 프로그래밍의 벗 PivotOJ
PivotOJ

Broken Piano

시간 제한: 500ms메모리 제한: 1024MB출처: EIO 2021-22 openBOJ 29848

문제

MIDI (Musical Instrument Digital Interface) is a technical standard for describing musical pieces, where each note is represented by an integer from the range 010230 \ldots 1\,023. You have a piano with 10241\,024 keys and you want to play a piece given in the MIDI format. The leftmost key on the piano corresponds to MIDI code 00, the second key from the left to MIDI code 11, etc.

Unfortunately, the piano is very old and some keys are broken. You are familiar with the piano, and know, which keys work and which don't. You can assume that no working key will break during the palying of this one piece, and also no broken key will suddenly start working.

Write a program to find

  • the number of notes in the piece that cannot be played on the piano; and
  • the minimal transposition needed to play the piece on the piano.

Transposition means shifting all the notes in a piece up or down by the same amount. When transposing the piece up by a half-tone, instead of any key designated by the original piece, its right-hand neighbor will be played on the piano. Similarly, when transposing down by a half-tone, the left-hand neighbor of the original key will be played. When transposing by two half-tones, the next but one key will be played, etc. Note that when a piece is transposed up by a half-tone, the note with the MIDI code 10231\,023 cannot be played, because there is no corresponding key on the piano.

입력

The first line contains NN, the number of broken keys on the piano (1N10241 \le N \le 1\,024). The second line contains NN distinct integers AiA_i (0Ai10230 \le A_i \le 1\,023): the MIDI codes of the broken keys. The third line contains MM, the number of notes in the piece (1M1061 \le M \le 10^6). The fourth line contains MM integers BiB_i (0Bi10230 \le B_i \le 1\,023): the MIDI codes of the notes in the piece.

출력

Output two lines. The first line should contain a single integer, the number of notes in the piece that cannot be played on the piano. The second line should contain the number of half-tones by which the piece must be transposed so that it can be played on the piano. If the piece could be transposed in several ways, output the transposition with the minimal absolute value. If the piece cannot be played with any transposition, the second line should contain 'X'. If your solution does not find the transpostion amount, output 'E' on the second line.

예제

예제 1

입력
2
7 8
6
4 5 6 7 8 7
출력
3
-2

예제 2

입력
2
0 1023
4
0 1023 1023 1023
출력
4
X
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.