



from collections import deque
from math import floor
from random import random
from time import time

class       snake_case__:

					"""simple docstring"""






					def __init__(							self					:	Dict     ):
									lowercase__     :    List[str]													=     {}







					def  snake_case     (							self					:	str      ,   SCREAMING_SNAKE_CASE					:	Any      ,   SCREAMING_SNAKE_CASE					:	List[str]      ,   SCREAMING_SNAKE_CASE					:	int=1     ):
									if self.graph.get(__lowercase     ):
													if self.graph[u].count([w, v]     ) == 0:
																	self.graph[u].append([w, v]     )
									else:
													lowercase__     :    Union[str, Any]													=     [[w, v]]
									if not self.graph.get(__lowercase     ):
													lowercase__     :    Optional[int]													=     []







					def  snake_case     (							self					:	Optional[int]     ):
									return list(self.graph     )







					def  snake_case     (							self					:	Optional[Any]      ,   SCREAMING_SNAKE_CASE					:	Tuple      ,   SCREAMING_SNAKE_CASE					:	Any     ):
									if self.graph.get(__lowercase     ):
													for _ in self.graph[u]:
																	if _[1] == v:
																					self.graph[u].remove(__lowercase     )







					def  snake_case     (							self					:	Dict      ,   SCREAMING_SNAKE_CASE					:	Union[str, Any]=-2      ,   SCREAMING_SNAKE_CASE					:	Union[str, Any]=-1     ):
									if s == d:
													return []
									lowercase__     :    List[Any]													=     []
									lowercase__     :    str													=     []
									if s == -2:
													lowercase__     :    str													=     list(self.graph     )[0]
									stack.append(__lowercase     )
									visited.append(__lowercase     )
									lowercase__     :    Optional[Any]													=     s

									while True:
													# check if there is any non isolated nodes
													if len(self.graph[s]     ) != 0:
																	lowercase__     :    List[Any]													=     s
																	for node in self.graph[s]:
																					if visited.count(node[1]     ) < 1:
																									if node[1] == d:
																													visited.append(__lowercase     )
																													return visited
																									else:
																													stack.append(node[1]     )
																													visited.append(node[1]     )
																													lowercase__     :    List[Any]													=     node[1]
																													break

            # check if all the children are visited
													if s == ss:
																	stack.pop()
																	if len(__lowercase     ) != 0:
																					lowercase__     :    Union[str, Any]													=     stack[len(__lowercase     ) - 1]
													else:
																	lowercase__     :    int													=     ss

													# check if se have reached the starting point
													if len(__lowercase     ) == 0:
																	return visited







					def  snake_case     (							self					:	Union[str, Any]      ,   SCREAMING_SNAKE_CASE					:	Optional[int]=-1     ):
									if c == -1:
													lowercase__     :    Optional[int]													=     floor(random() * 10_000     ) + 10
									for i in range(__lowercase     ):
													# every vertex has max 100 edges
													for _ in range(floor(random() * 102     ) + 1     ):
																	lowercase__     :    List[str]													=     floor(random() * c     ) + 1
																	if n != i:
																					self.add_pair(__lowercase      ,   __lowercase      ,   1     )







					def  snake_case     (							self					:	str      ,   SCREAMING_SNAKE_CASE					:	Optional[Any]=-2     ):
									lowercase__     :    Optional[int]													=     deque()
									lowercase__     :    Dict													=     []
									if s == -2:
													lowercase__     :    int													=     list(self.graph     )[0]
									d.append(__lowercase     )
									visited.append(__lowercase     )
									while d:
													lowercase__     :    Tuple													=     d.popleft()
													if len(self.graph[s]     ) != 0:
																	for node in self.graph[s]:
																					if visited.count(node[1]     ) < 1:
																									d.append(node[1]     )
																									visited.append(node[1]     )
									return visited







					def  snake_case     (							self					:	str      ,   SCREAMING_SNAKE_CASE					:	Union[str, Any]     ):
									lowercase__     :    Tuple													=     0
									for x in self.graph:
													for y in self.graph[x]:
																	if y[1] == u:
																					count += 1
									return count







					def  snake_case     (							self					:	str      ,   SCREAMING_SNAKE_CASE					:	int     ):
									return len(self.graph[u]     )







					def  snake_case     (							self					:	List[str]      ,   SCREAMING_SNAKE_CASE					:	Optional[int]=-2     ):
									lowercase__     :    Dict													=     []
									lowercase__     :    int													=     []
									if s == -2:
													lowercase__     :    Optional[Any]													=     list(self.graph     )[0]
									stack.append(__lowercase     )
									visited.append(__lowercase     )
									lowercase__     :    int													=     s
									lowercase__     :    Dict													=     []

									while True:
													# check if there is any non isolated nodes
													if len(self.graph[s]     ) != 0:
																	lowercase__     :    Optional[int]													=     s
																	for node in self.graph[s]:
																					if visited.count(node[1]     ) < 1:
																									stack.append(node[1]     )
																									visited.append(node[1]     )
																									lowercase__     :    Optional[Any]													=     node[1]
																									break

            # check if all the children are visited
													if s == ss:
																	sorted_nodes.append(stack.pop()     )
																	if len(__lowercase     ) != 0:
																					lowercase__     :    Any													=     stack[len(__lowercase     ) - 1]
													else:
																	lowercase__     :    List[Any]													=     ss

													# check if se have reached the starting point
													if len(__lowercase     ) == 0:
																	return sorted_nodes







					def  snake_case     (							self					:	Any     ):
									lowercase__     :    int													=     []
									lowercase__     :    Dict													=     []
									lowercase__     :    Tuple													=     list(self.graph     )[0]
									stack.append(__lowercase     )
									visited.append(__lowercase     )
									lowercase__     :    Any													=     -2
									lowercase__     :    Any													=     []
									lowercase__     :    List[str]													=     s
									lowercase__     :    int													=     False
									lowercase__     :    Optional[int]													=     set()

									while True:
													# check if there is any non isolated nodes
													if len(self.graph[s]     ) != 0:
																	lowercase__     :    Tuple													=     s
																	for node in self.graph[s]:
																					if (
																					    visited.count(node[1]     ) > 0
																					    and node[1] != parent
																					    and indirect_parents.count(node[1]     ) > 0
																					    and not on_the_way_back
																					):
																									lowercase__     :    List[str]													=     len(__lowercase     ) - 1
																									while len_stack >= 0:
																													if stack[len_stack] == node[1]:
																																	anticipating_nodes.add(node[1]     )
																																	break
																													else:
																																	anticipating_nodes.add(stack[len_stack]     )
																																	len_stack -= 1
																					if visited.count(node[1]     ) < 1:
																									stack.append(node[1]     )
																									visited.append(node[1]     )
																									lowercase__     :    Any													=     node[1]
																									break

            # check if all the children are visited
													if s == ss:
																	stack.pop()
																	lowercase__     :    List[Any]													=     True
																	if len(__lowercase     ) != 0:
																					lowercase__     :    Any													=     stack[len(__lowercase     ) - 1]
													else:
																	lowercase__     :    List[str]													=     False
																	indirect_parents.append(__lowercase     )
																	lowercase__     :    Optional[int]													=     s
																	lowercase__     :    Dict													=     ss

													# check if se have reached the starting point
													if len(__lowercase     ) == 0:
																	return list(__lowercase     )







					def  snake_case     (							self					:	Optional[int]     ):
									lowercase__     :    Tuple													=     []
									lowercase__     :    List[str]													=     []
									lowercase__     :    Dict													=     list(self.graph     )[0]
									stack.append(__lowercase     )
									visited.append(__lowercase     )
									lowercase__     :    List[str]													=     -2
									lowercase__     :    str													=     []
									lowercase__     :    Optional[Any]													=     s
									lowercase__     :    int													=     False
									lowercase__     :    Optional[int]													=     set()

									while True:
													# check if there is any non isolated nodes
													if len(self.graph[s]     ) != 0:
																	lowercase__     :    List[str]													=     s
																	for node in self.graph[s]:
																					if (
																					    visited.count(node[1]     ) > 0
																					    and node[1] != parent
																					    and indirect_parents.count(node[1]     ) > 0
																					    and not on_the_way_back
																					):
																									lowercase__     :    Dict													=     len(__lowercase     ) - 1
																									while len_stack_minus_one >= 0:
																													if stack[len_stack_minus_one] == node[1]:
																																	anticipating_nodes.add(node[1]     )
																																	break
																													else:
																																	return True
																					if visited.count(node[1]     ) < 1:
																									stack.append(node[1]     )
																									visited.append(node[1]     )
																									lowercase__     :    List[Any]													=     node[1]
																									break

            # check if all the children are visited
													if s == ss:
																	stack.pop()
																	lowercase__     :    List[Any]													=     True
																	if len(__lowercase     ) != 0:
																					lowercase__     :    int													=     stack[len(__lowercase     ) - 1]
													else:
																	lowercase__     :    Union[str, Any]													=     False
																	indirect_parents.append(__lowercase     )
																	lowercase__     :    List[Any]													=     s
																	lowercase__     :    Optional[Any]													=     ss

													# check if se have reached the starting point
													if len(__lowercase     ) == 0:
																	return False







					def  snake_case     (							self					:	int      ,   SCREAMING_SNAKE_CASE					:	Optional[Any]=-2      ,   SCREAMING_SNAKE_CASE					:	List[Any]=-1     ):
									lowercase__     :    int													=     time()
									self.dfs(__lowercase      ,   __lowercase     )
									lowercase__     :    int													=     time()
									return end - begin







					def  snake_case     (							self					:	Union[str, Any]      ,   SCREAMING_SNAKE_CASE					:	str=-2     ):
									lowercase__     :    Optional[int]													=     time()
									self.bfs(__lowercase     )
									lowercase__     :    List[Any]													=     time()
									return end - begin






class       snake_case__:

					"""simple docstring"""






					def __init__(							self					:	str     ):
									lowercase__     :    Union[str, Any]													=     {}







					def  snake_case     (							self					:	Union[str, Any]      ,   SCREAMING_SNAKE_CASE					:	List[Any]      ,   SCREAMING_SNAKE_CASE					:	Optional[Any]      ,   SCREAMING_SNAKE_CASE					:	List[Any]=1     ):
									# check if the u exists
									if self.graph.get(__lowercase     ):
													# if there already is a edge
													if self.graph[u].count([w, v]     ) == 0:
																	self.graph[u].append([w, v]     )
									else:
													# if u does not exist
													lowercase__     :    Union[str, Any]													=     [[w, v]]
									# add the other way
									if self.graph.get(__lowercase     ):
													# if there already is a edge
													if self.graph[v].count([w, u]     ) == 0:
																	self.graph[v].append([w, u]     )
									else:
													# if u does not exist
													lowercase__     :    Tuple													=     [[w, u]]







					def  snake_case     (							self					:	List[str]      ,   SCREAMING_SNAKE_CASE					:	Optional[Any]      ,   SCREAMING_SNAKE_CASE					:	Tuple     ):
									if self.graph.get(__lowercase     ):
													for _ in self.graph[u]:
																	if _[1] == v:
																					self.graph[u].remove(__lowercase     )
        # the other way round
									if self.graph.get(__lowercase     ):
													for _ in self.graph[v]:
																	if _[1] == u:
																					self.graph[v].remove(__lowercase     )







					def  snake_case     (							self					:	int      ,   SCREAMING_SNAKE_CASE					:	Optional[int]=-2      ,   SCREAMING_SNAKE_CASE					:	Optional[int]=-1     ):
									if s == d:
													return []
									lowercase__     :    Dict													=     []
									lowercase__     :    Any													=     []
									if s == -2:
													lowercase__     :    Tuple													=     list(self.graph     )[0]
									stack.append(__lowercase     )
									visited.append(__lowercase     )
									lowercase__     :    int													=     s

									while True:
													# check if there is any non isolated nodes
													if len(self.graph[s]     ) != 0:
																	lowercase__     :    Optional[Any]													=     s
																	for node in self.graph[s]:
																					if visited.count(node[1]     ) < 1:
																									if node[1] == d:
																													visited.append(__lowercase     )
																													return visited
																									else:
																													stack.append(node[1]     )
																													visited.append(node[1]     )
																													lowercase__     :    int													=     node[1]
																													break

            # check if all the children are visited
													if s == ss:
																	stack.pop()
																	if len(__lowercase     ) != 0:
																					lowercase__     :    List[Any]													=     stack[len(__lowercase     ) - 1]
													else:
																	lowercase__     :    int													=     ss

													# check if se have reached the starting point
													if len(__lowercase     ) == 0:
																	return visited







					def  snake_case     (							self					:	str      ,   SCREAMING_SNAKE_CASE					:	Optional[int]=-1     ):
									if c == -1:
													lowercase__     :    Optional[int]													=     floor(random() * 10_000     ) + 10
									for i in range(__lowercase     ):
													# every vertex has max 100 edges
													for _ in range(floor(random() * 102     ) + 1     ):
																	lowercase__     :    List[Any]													=     floor(random() * c     ) + 1
																	if n != i:
																					self.add_pair(__lowercase      ,   __lowercase      ,   1     )







					def  snake_case     (							self					:	Union[str, Any]      ,   SCREAMING_SNAKE_CASE					:	Union[str, Any]=-2     ):
									lowercase__     :    Dict													=     deque()
									lowercase__     :    Any													=     []
									if s == -2:
													lowercase__     :    Optional[Any]													=     list(self.graph     )[0]
									d.append(__lowercase     )
									visited.append(__lowercase     )
									while d:
													lowercase__     :    Optional[int]													=     d.popleft()
													if len(self.graph[s]     ) != 0:
																	for node in self.graph[s]:
																					if visited.count(node[1]     ) < 1:
																									d.append(node[1]     )
																									visited.append(node[1]     )
									return visited







					def  snake_case     (							self					:	Union[str, Any]      ,   SCREAMING_SNAKE_CASE					:	str     ):
									return len(self.graph[u]     )







					def  snake_case     (							self					:	Dict     ):
									lowercase__     :    int													=     []
									lowercase__     :    Dict													=     []
									lowercase__     :    Dict													=     list(self.graph     )[0]
									stack.append(__lowercase     )
									visited.append(__lowercase     )
									lowercase__     :    Union[str, Any]													=     -2
									lowercase__     :    str													=     []
									lowercase__     :    Optional[int]													=     s
									lowercase__     :    Union[str, Any]													=     False
									lowercase__     :    Tuple													=     set()

									while True:
													# check if there is any non isolated nodes
													if len(self.graph[s]     ) != 0:
																	lowercase__     :    Optional[int]													=     s
																	for node in self.graph[s]:
																					if (
																					    visited.count(node[1]     ) > 0
																					    and node[1] != parent
																					    and indirect_parents.count(node[1]     ) > 0
																					    and not on_the_way_back
																					):
																									lowercase__     :    List[str]													=     len(__lowercase     ) - 1
																									while len_stack >= 0:
																													if stack[len_stack] == node[1]:
																																	anticipating_nodes.add(node[1]     )
																																	break
																													else:
																																	anticipating_nodes.add(stack[len_stack]     )
																																	len_stack -= 1
																					if visited.count(node[1]     ) < 1:
																									stack.append(node[1]     )
																									visited.append(node[1]     )
																									lowercase__     :    Dict													=     node[1]
																									break

            # check if all the children are visited
													if s == ss:
																	stack.pop()
																	lowercase__     :    Optional[Any]													=     True
																	if len(__lowercase     ) != 0:
																					lowercase__     :    Tuple													=     stack[len(__lowercase     ) - 1]
													else:
																	lowercase__     :    Optional[int]													=     False
																	indirect_parents.append(__lowercase     )
																	lowercase__     :    List[str]													=     s
																	lowercase__     :    str													=     ss

													# check if se have reached the starting point
													if len(__lowercase     ) == 0:
																	return list(__lowercase     )







					def  snake_case     (							self					:	List[Any]     ):
									lowercase__     :    Optional[Any]													=     []
									lowercase__     :    Any													=     []
									lowercase__     :    int													=     list(self.graph     )[0]
									stack.append(__lowercase     )
									visited.append(__lowercase     )
									lowercase__     :    Any													=     -2
									lowercase__     :    List[str]													=     []
									lowercase__     :    Dict													=     s
									lowercase__     :    int													=     False
									lowercase__     :    str													=     set()

									while True:
													# check if there is any non isolated nodes
													if len(self.graph[s]     ) != 0:
																	lowercase__     :    List[str]													=     s
																	for node in self.graph[s]:
																					if (
																					    visited.count(node[1]     ) > 0
																					    and node[1] != parent
																					    and indirect_parents.count(node[1]     ) > 0
																					    and not on_the_way_back
																					):
																									lowercase__     :    Optional[Any]													=     len(__lowercase     ) - 1
																									while len_stack_minus_one >= 0:
																													if stack[len_stack_minus_one] == node[1]:
																																	anticipating_nodes.add(node[1]     )
																																	break
																													else:
																																	return True
																					if visited.count(node[1]     ) < 1:
																									stack.append(node[1]     )
																									visited.append(node[1]     )
																									lowercase__     :    int													=     node[1]
																									break

            # check if all the children are visited
													if s == ss:
																	stack.pop()
																	lowercase__     :    Any													=     True
																	if len(__lowercase     ) != 0:
																					lowercase__     :    Optional[Any]													=     stack[len(__lowercase     ) - 1]
													else:
																	lowercase__     :    List[Any]													=     False
																	indirect_parents.append(__lowercase     )
																	lowercase__     :    Tuple													=     s
																	lowercase__     :    List[str]													=     ss

													# check if se have reached the starting point
													if len(__lowercase     ) == 0:
																	return False







					def  snake_case     (							self					:	Tuple     ):
									return list(self.graph     )







					def  snake_case     (							self					:	str      ,   SCREAMING_SNAKE_CASE					:	int=-2      ,   SCREAMING_SNAKE_CASE					:	Optional[int]=-1     ):
									lowercase__     :    Optional[Any]													=     time()
									self.dfs(__lowercase      ,   __lowercase     )
									lowercase__     :    List[str]													=     time()
									return end - begin







					def  snake_case     (							self					:	str      ,   SCREAMING_SNAKE_CASE					:	Tuple=-2     ):
									lowercase__     :    Optional[int]													=     time()
									self.bfs(__lowercase     )
									lowercase__     :    Any													=     time()
									return end - begin





import argparse
import json

from tqdm import tqdm



def lowerCamelCase  (   ):
    '''simple docstring'''







    __UpperCamelCase     :Tuple			  =		argparse.ArgumentParser()

    # Required parameters
    parser.add_argument(
        '''--src_path'''  ,			type=SCREAMING_SNAKE_CASE  ,			default='''biencoder-nq-dev.json'''  ,			help='''Path to raw DPR training data'''  ,			)
    parser.add_argument(
        '''--evaluation_set'''  ,			type=SCREAMING_SNAKE_CASE  ,			help='''where to store parsed evaluation_set file'''  ,			)
    parser.add_argument(
        '''--gold_data_path'''  ,			type=SCREAMING_SNAKE_CASE  ,			help='''where to store parsed gold_data_path file'''  ,			)
    __UpperCamelCase     :str			  =		parser.parse_args()

    with open(args.src_path  ,			'''r'''	) as src_file, open(args.evaluation_set  ,			'''w'''	) as eval_file, open(
        args.gold_data_path  ,			'''w'''	) as gold_file:
        __UpperCamelCase     :List[str]			  =		json.load(SCREAMING_SNAKE_CASE	)
        for dpr_record in tqdm(SCREAMING_SNAKE_CASE	):
            __UpperCamelCase     :List[str]			  =		dpr_record['''question''']
            __UpperCamelCase     :Tuple			  =		[context['''title'''] for context in dpr_record['''positive_ctxs''']]
            eval_file.write(question + '''\n'''	)
            gold_file.write('''\t'''.join(SCREAMING_SNAKE_CASE	) + '''\n'''	)


if __name__ == "__main__":
    main()





