아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Broken Piano

시간 제한0.5초메모리 제한1024 MB

요약
연주할 수 없는 음의 개수를 세고, 모든 음이 정상 건반에 놓이게 하는 최소 절댓값 이조 값을 구한다.
난이도

보통10점 중 4점

유형
완전 탐색, 배열, 비트 연산
정답자
아직 제출이 없습니다

문제

MIDI (Musical Instrument Digital Interface) is a technical standard for describing musical pieces, where each note is represented by an integer from the range 0…1,0230 \ldots 1\\,023. You have a piano with 1,0241\\,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 1,0231\\,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 (1≤N≤1,0241 \le N \le 1\\,024). The second line contains NN distinct integers A_iA\_i (0≤A_i≤1,0230 \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 (1≤M≤1061 \le M \le 10^6). The fourth line contains MM integers B_iB\_i (0≤B_i≤1,0230 \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.

예제2

  1. 예제 1

    입력
    2
    7 8
    6
    4 5 6 7 8 7
    
    예상 출력
    3
    -2
    
  2. 예제 2

    입력
    2
    0 1023
    4
    0 1023 1023 1023
    
    예상 출력
    4
    X