###Complete the Code Below###

from langchain import SerpAPIWrapper
from utils import QA_LLM
search = SerpAPIWrapper()

def Search(query:str,thought:str):
    """Search relevant information about query based on external Search Engine.
    Attributes:
		query: The question you want to search.
		thought: The reason why this query is need. 
    """
    if thought is not None:
        return search.run(query)
    else:
        return ("Please give your thought!")

def Get_Answer(query:str,info:str):
    """Get the answer of the query based on the information.
    Attributes:
    query: The question you want to search.
    info: The information relevant to the query.
    """
    ### Use the QA_LLM model to get the answer.
    return QA_LLM(query,info)

def Compare(Original_Query:str,Subquestions:list,Answers:list):
    """Compare the answer of the sub-questions and return the final answer of original query.
    Attributes:
    Original_Query: The original question.
    Subquestions: The list of sub-questions.
    Answers: The list of answers of the sub-questions.
    """
    query = Original_Query
    info = str()
    for i in range(len(Subquestions)):
        info += Subquestions[i] + ' : ' + Answers[i] + '\n'
    return QA_LLM(query,info)

def Intersection(Answer1:str,Answer2:str):
    """Find the intersection of two answer sets.
    Attributes:
    Answer1: The first answer set.
    Answer2: The second answer set.
    """
    List1 = Answer1.split(',')
    List2 = Answer2.split(',')
    return str(set(List1) & set(List2))

def Union(Answer1:str,Answer2:str):
    """Find the union of two answer sets.
    Attributes:
    Answer1: The first answer set.
    Answer2: The second answer set.
    """
    List1 = Answer1.split(',')
    List2 = Answer2.split(',')
    return str(set(List1) | set(List2))

def Finish_The_Plan(Answer:str):
    """Call this function to finish the plan and return the final answer.
    Attributes:
    Answer: The final answer of the original question.
    """
    return Answer

###################
# Example 0:
###################

Original_Question: str = "What is the ethnic group of Booker T. Jones?"
### Question Type: One Projection
### Decompose the original question into sub-questions.

Thought1: str = "An atomic question, no need to decompose. Search directly."
Sub_Question_1: str = "What is the ethnic group of Booker T. Jones?"
Info_1: str = Search(query = Sub_Question_1, thought = Thought1)
Ans_1: str = Get_Answer(query = Sub_Question_1, info = Info_1)

Final_Answer: str = Finish_The_Plan(Answer = Ans_1)

###################
# Example 1:
###################

Original_Question: str = "Who succeeded the first President of Namibia?"
### Question Type: Two Projection
### Decompose the original question into sub-questions.

Thought1: str = "If I want to know who succeeded the first President of Namibia, I need to first know who is the first President of Namibia."
Sub_Question_1: str = "Who is the first President of Namibia?"
Info_1: str = Search(query = Sub_Question_1, thought = Thought1)
Ans_1: str = Get_Answer(query = Sub_Question_1, info = Info_1)

Thought2: str = "After knowing who is the first President of Namibia, I need to know who succeeded him."
Sub_Question_2: str = f"Who succeeded {Ans_1}?"
Info_2: str = Search(query = Sub_Question_2, thought = Thought2)
Ans_2: str = Get_Answer(query = Sub_Question_2, info = Info_2)

Final_Answer: str = Finish_The_Plan(Answer = Ans_2)

###################
# Example 2:
###################

Original_Question: str = "What is the foundational text of Android developer's country?"
### Question Type: Three Projection
### Decompose the original question into sub-questions.

Thought1: str = "If I want to know what is the foundational text of Android developer's country, I need to first know what(who) is the developer of Android."
Sub_Question_1: str = "What(Who) is the developer of Android?"
Info_1: str = Search(query = Sub_Question_1, thought = Thought1)
Ans_1: str = Get_Answer(query = Sub_Question_1, info = Info_1)

Thought2: str = "After knowing what(who) is the developer of Android, I need to the know its country."
Sub_Question_2: str = f"What is the country of {Ans_1}?"
Info_2: str = Search(query = Sub_Question_2, thought = Thought2)
Ans_2: str = Get_Answer(query = Sub_Question_2, info = Info_2)

Thought3: str = "After knowing what is the country of Android developer, I need to know what is the foundational text of country Ans_2."
Sub_Question_3: str = f"What is the foundational text of {Ans_2}?"
Info_3: str = Search(query = Sub_Question_3, thought = Thought3)
Ans_3: str = Get_Answer(query = Sub_Question_3, info = Info_3)

Final_Answer: str = Finish_The_Plan(Answer = Ans_3)

###################
# Example 3:
###################

Original_Question: str = "When was the first establishment that McDonaldization is named after, open in the country Horndean is located?"
### Question Type: Entity Replacement
### Decompose the original question into sub-questions.

Thought1: str = "If I want to know when the first establishment that McDonaldization is named after, open in the country Horndean is located, I need to first know what is McDonaldization named after."
Sub_Question_1: str = "What is McDonaldization named after?"
Info_1: str = Search(query = Sub_Question_1, thought = Thought1)
Ans_1: str = Get_Answer(query = Sub_Question_1, info = Info_1)

Thought2: str = "At the same time, I need to know where the country Horndean is located."
Sub_Question_2: str = "Where is the country Horndean located?"
Info_2: str = Search(query = Sub_Question_2, thought = Thought2)
Ans_2: str = Get_Answer(query = Sub_Question_2, info = Info_2)

Thought3: str = "After knowing what is McDonaldization named after (i.e., Ans_1) and where the country Horndean is located (i.e., Ans_2), I need to know when the first Ans_1 open in the Ans_2."
Sub_Question_3: str = f"When did the first {Ans_1}\'s open in {Ans_2}?"
Info_3: str = Search(query = Sub_Question_3, thought = Thought3)
Ans_3: str = Get_Answer(query = Sub_Question_3, info = Info_3)

Final_Answer: str = Finish_The_Plan(Answer = Ans_3)

###################
# Example 4:
###################

Original_Question: str = "Which magazine was started first Arthur's Magazine or First for Women?"
### Question Type: Compare
### Decompose the original question into sub-questions.

Thought1: str = "If I want to know which magazine was started first, I need to first know when Arthur's Magazine was started."
Sub_Question_1: str = "When was Arthur's Magazine started?"
Info_1: str = Search(query = Sub_Question_1, thought = Thought1)
Ans_1: str = Get_Answer(query = Sub_Question_1, info = Info_1)

Thought2: str = "At the same time, I need to know when First for Women was started."
Sub_Question_2: str = "When was First for Women started?"
Info_2: str = Search(query = Sub_Question_2, thought = Thought2)
Ans_2: str = Get_Answer(query = Sub_Question_2, info = Info_2)

Thought3: str = "After knowing when Arthur's Magazine was started (i.e., Ans_1) and when First for Women was started, I need to compare the two dates."
Ans_3: str = Compare(Original_Query = Original_Question, Subquestions = [Sub_Question_1,Sub_Question_2], Answers = [Ans_1,Ans_2])

Final_Answer: str = Finish_The_Plan(Answer = Ans_3)

###################
# Example 5:
###################

Original_Question: str = "Which areas border with Burlington County and Trumbull County at the same time?"
### Question Type: Two Intersection
### Decompose the original question into sub-questions.

Thought1: str = "If I want to know which areas border with Burlington County and Trumbull County at the same time, I need to first know which areas border with Burlington County."
Sub_Question_1: str = "Which areas border with Burlington County?"
Info_1: str = Search(query = Sub_Question_1, thought = Thought1)
Ans_1: str = Get_Answer(query = Sub_Question_1, info = Info_1)

Thought2: str = "At the same time, I need to know which areas border with Trumbull County."
Sub_Question_2: str = "Which areas border with Trumbull County?"
Info_2: str = Search(query = Sub_Question_2, thought = Thought2)
Ans_2: str = Get_Answer(query = Sub_Question_2, info = Info_2)

Thought3: str = "After knowing which areas border with Burlington County (i.e., Ans_1) and which areas border with Trumbull County (i.e., Ans_2), I need to find the intersection of the two answer sets."
Inter_Results1: str = Intersection(Answer1 = Ans_1, Answer2 = Ans_2)

Final_Answer: str = Finish_The_Plan(Answer = Inter_Results1)


###################
# Example 6:
###################

Original_Question: str = "What are the same genre shared between Alice in Wonderland, Blues Brothers 2000 and Pinocchio?"
### Question Type: Three Intersection
### Decompose the original question into sub-questions.

Thought1: str = "If I want to know what are the same genre shared between Alice in Wonderland, Blues Brothers 2000 and Pinocchio, I need to first know what is the genre of Alice in Wonderland."
Sub_Question_1: str = "What is the genre of Alice in Wonderland?"
Info_1: str = Search(query = Sub_Question_1, thought = Thought1)
Ans_1: str = Get_Answer(query = Sub_Question_1, info = Info_1)

Thought2: str = "At the same time, I need to know what is the genre of Blues Brothers 2000."
Sub_Question_2: str = "What is the genre of Blues Brothers 2000?"
Info_2: str = Search(query = Sub_Question_2, thought = Thought2)
Ans_2: str = Get_Answer(query = Sub_Question_2, info = Info_2)

Thought3: str = "At the same time, I need to know what is the genre of Pinocchio."
Sub_Question_3: str = "What is the genre of Pinocchio?"
Info_3: str = Search(query = Sub_Question_3, thought = Thought3)
Ans_3: str = Get_Answer(query = Sub_Question_3, info = Info_3)

Thought4: str = "After knowing what is the genre of Alice in Wonderland (i.e., Ans_1), what is the genre of Blues Brothers 2000 (i.e., Ans_2) and what is the genre of Pinocchio (i.e., Ans_3), I need to find the intersection of the three answer sets."
Inter_Results1: str = Intersection(Answer1 = Ans_1, Answer2 = Ans_2)
Inter_Results2: str = Intersection(Answer1 = Inter_Results1, Answer2 = Ans_3)

Final_Answer: str = Finish_The_Plan(Answer = Inter_Results2)

###################
# Example 7:
###################

Original_Question: str = "Who are all the cast members from 'Wuthering Heights' combined with the cast members from 'Traffic'?"
### Question Type: Two Union
### Decompose the original question into sub-questions.

Thought1: str = "If I want to know who are all the cast members from 'Wuthering Heights' combined with the cast members from 'Traffic', I need to first know who are the cast members from 'Wuthering Heights'."
Sub_Question_1: str = "Who are the cast members from 'Wuthering Heights'?"
Info_1: str = Search(query = Sub_Question_1, thought = Thought1)
Ans_1: str = Get_Answer(query = Sub_Question_1, info = Info_1)

Thought2: str = "At the same time, I need to know who are the cast members from 'Traffic'."
Sub_Question_2: str = "Who are the cast members from 'Traffic'?"
Info_2: str = Search(query = Sub_Question_2, thought = Thought2)
Ans_2: str = Get_Answer(query = Sub_Question_2, info = Info_2)

Thought3: str = "After knowing who are the cast members from 'Wuthering Heights' (i.e., Ans_1) and who are the cast members from 'Traffic' (i.e., Ans_2), I need to find the union of the two answer sets."
Union_Results1: str = Union(Answer1 = Ans_1, Answer2 = Ans_2)

Final_Answer: str = Finish_The_Plan(Answer = Union_Results1)

###################
# Example 8:
###################

Original_Question: str = "Which regions border Drake Bell's birthplace and Santa Ana at the same time?"
### Question Type: Projection then Two Intersection
### Decompose the original question into sub-questions.

Thought1: str = "If I want to know which regions border Drake Bell's birthplace and Santa Ana at the same time, I need to first know where is Drake Bell's birthplace."
Sub_Question_1: str = "Where is Drake Bell's birthplace?"
Info_1: str = Search(query = Sub_Question_1, thought = Thought1)
Ans_1: str = Get_Answer(query = Sub_Question_1, info = Info_1)

Thought2: str = "Then I need to know which regions border with Drake Bell's birthplace.(i.e., Ans_1)"
Sub_Question_2: str = f"Which regions border with {Ans_1}?"
Info_2: str = Search(query = Sub_Question_2, thought = Thought2)
Ans_2: str = Get_Answer(query = Sub_Question_2, info = Info_2)

Thought3: str = "At the same time, I need to know which regions border with Santa Ana."
Sub_Question_3: str = "Which regions border with Santa Ana?"
Info_3: str = Search(query = Sub_Question_3, thought = Thought3)
Ans_3: str = Get_Answer(query = Sub_Question_3, info = Info_3)

Thought4: str = "After knowing which regions border with Drake Bell's birthplace (i.e., Ans_2) and which regions border with Santa Ana (i.e., Ans_3), I need to find the intersection of the two answer sets."
Inter_Results1: str = Intersection(Answer1 = Ans_2, Answer2 = Ans_3)

Final_Answer: str = Finish_The_Plan(Answer = Inter_Results1)

###################
# Example 9:
###################

Original_Question: str = "What are the political party of people who are cast members of both The Blues Brothers and Going My Way?"
### Question Type: Two Intersection then Projection
### Decompose the original question into sub-questions.

Thought1: str = "If I want to know what are the political party of people who are cast members of both The Blues Brothers and Going My Way, I need to first know who are the cast members of The Blues Brothers."
Sub_Question_1: str = "Who are the cast members of The Blues Brothers?"
Info_1: str = Search(query = Sub_Question_1, thought = Thought1)
Ans_1: str = Get_Answer(query = Sub_Question_1, info = Info_1)

Thought2: str = "At the same time, I need to know who are the cast members of Going My Way."
Sub_Question_2: str = "Who are the cast members of Going My Way?"
Info_2: str = Search(query = Sub_Question_2, thought = Thought2)
Ans_2: str = Get_Answer(query = Sub_Question_2, info = Info_2)

Thought3: str = "After knowing who are the cast members of The Blues Brothers (i.e., Ans_1) and who are the cast members of Going My Way (i.e., Ans_2), I need to find the intersection of the two answer sets."
Inter_Results1: str = Intersection(Answer1 = Ans_1, Answer2 = Ans_2)

Thought4: str = "Then I need to know the political party of the people in Inter_Results1."
Sub_Question_3: str = f"What are the political party of people in {Inter_Results1}?"
Info_3: str = Search(query = Sub_Question_3, thought = Thought4)
Ans_3: str = Get_Answer(query = Sub_Question_3, info = Info_3)

Final_Answer: str = Finish_The_Plan(Answer = Ans_3)

###################
# Your turn! Just complete the code below and do not return other things.
###################

Original_Question: str = "What sport is associated with both John Madden and Ben Johnson?"