Logo
(追記) (追記ここまで)

26046번 - Earthquake 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 1024 MB69312340.351%

문제

Cimrman has quite a number of collaborators. Tomorrow morning, he is planning to make phone calls to many of them and his assistant had prepared a list of phone numbers on a sheet of paper. Regrettably, an earthquake struck yesterday. The coffee and juice stored close to the list had spilled out and made stains on the list. Upon close examination of the affected list, the following turned out:

  • No digit affected by a stain is readable.
  • Each coffee stain covers exactly one digit in any of the numbers.
  • There are at most two coffee stains on any of the numbers.
  • Each juice stain covers one or more consecutive digits in any of the numbers.
  • There is at most one juice stain on any of the numbers.
  • No stain affects more than one number.
  • No number has been affected by coffee and juice simultaneously.

Fortunately, Cimrman has an older list of his collaborators phone numbers. This older list was stored in the drawer and it survived the earthquake undamaged. Now, it will help to restore the damaged list. First, the assistant needs to know, to how many items on the old list may correspond each of the items on the damaged list.

입력

The first input line contains one integer N (1 ≤ N ≤ 104), the number of phone numbers in the older undamaged list. Each of the next N lines contains one phone number consisting of exactly 9 digits, leading zeros are allowed. All numbers are mutually different. Next, there is a line with one integer Q (1 ≤ Q ≤ 3 · 105), the number of phone numbers on the damaged list. Each of the next Q lines contains one, possibly stained, phone number from the damaged list. A coffee stain is represented by a question mark (“?”), a juice stain is represented by an asterisk (“*”). There are no spaces in any numbers. The phone numbers are given in no specific order.

출력

Output Q lines, the i-th line should contain the number of items in the undamaged list which may correspond to the i-th item on the damaged list.

제한

예제 입력 1

2
728147956
606327482
2
72814?956
622629145

예제 출력 1

1
0

예제 입력 2

4
606200400
606200500
606300500
706200400
3
?06200400
6*00
606?00?00

예제 출력 2

2
3
3

힌트

출처

ICPC > Regionals > Europe > Central European Regional Contest > CTU Open Contest > CTU Open Contest 2022 E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /