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

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

Spaceman Spoof's Functions

시간 제한2초메모리 제한512 MB

요약
숨은 x에 대해 아빌라시와 브라이언이 번갈아 YES/NO로 답할 때 각자가 아는 정보를 추적하고, 남은 x의 값들을 출력하거나 모순이면 -1을 출력한다.
난이도

보통10점 중 6점

유형
구현, 시뮬레이션, 해시맵
정답자
아직 제출이 없습니다

문제

Oh no! Our intrepid heroes, Abhilash, Brian, and you, Spaceman Spoof, have been trapped by the evil Zargons! The leader of the Zargons, Zarg One, has decided to have mercy on you and give you a single chance to escape.

He decides on two functions, ff and gg, which take as inputs integers between 11 and nn inclusive, and output some integer. He publicly announces these functions to Abhilash, Brian, and you. 

He then secretly decides on x∈\[1,2,…,n]x\in \[1, 2,\dots, n], and tells Abhilash the value of f(x)f(x), and tells Brian g(x)g(x). Then, Abhilash and Brian alternate giving one-word statements about whether they know the value of xx: each says YES if they know the value or NO otherwise. Abhilash goes first. They were injected with the Zargonian Truth Serum, and so can't lie. 

As the arch-nemesis of Zarg One, you, Spaceman Spoof, have to figure out the secret value of xx, using only your knowledge of ff, gg, and the words that you hear from Abhilash and Brian. There is a chance that you will not be able to determine uniquely the value of xx. In this case, you must provide the whole set of possible values, in increasing order.

Note that Zarg One is temperamental, and might end his little game at any time, whether anybody has figured out the value of xx or not. That is, you are not guaranteed to hear a YES in the conversation, and the conversation  is not guaranteed to end when or if both Abhilash and Brian say YES.

In your predicament, you'll have to assume that Abhilash and Brian are perfectly logical and will at each point correctly deduce whether they know the value or xx or not based on the information available to them. However, it is possible for Abhilash and Brian to make a mistake, given the high-stress environment they are in. If you can prove a logical contradiction in the answers either hero has provided, you'll have no choice but to give up and grovel for mercy; print −1-1 instead of the value(s) of xx. You should keep paying attention and checking for possible contradictions even after you're confident that you've pinpointed the value of xx.

입력

The first line of the input contains a single integer nn (1≤n≤1051 \leq n \leq 10^5).

Then follows a line of nn space-separated integers that describes ff: the iith integer on this line (starting from i=1i=1) is the value of f(i)f(i) (0≤f(i)≤1050 \leq f(i) \leq 10^5). Next is a line of nn space-separated integers that describes gg, in identical manner: the iith integer in this line is g(i)g(i) (0≤g(i)≤1050 \leq g(i) \leq 10^5).

Then follows a line with a single integer qq (1≤q≤1051\leq q \leq 10^5), the number of words in the conversation, followed by a line containing qq space-separated words. Each word is either YES or NO.

출력

Print a single line of space-separated integers: the possible values of xx consistent with the information you've heard from Abhilash and Brian, listed in ascending order. In case you discover a logical contradiction, print a single −1-1 instead.

예제2

  1. 예제 1

    입력
    2
    0 1
    0 0
    2
    NO YES
    
    예상 출력
    -1
    
  2. 예제 2

    입력
    3
    0 1 1
    0 0 1
    2
    NO YES
    
    예상 출력
    2 3