Phineas and Ferb
Practice
3 (2 votes)
Mathematics
Easy
Game theory
Problem
70% Success 2355 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Phineas and Ferb are playing an interesting game. They have N piles of stones numbered from 1 to N in front of them. The \(i^{th}\) pile contains \(A_{i}\) stones. Both of them play turn wise and optimally with Phineas starting first.

In each turn, a player can remove any number of stones from any of the pile which has positive amount of stones left in it. A player loses when he cannot remove any stone and all piles are already empty.

You are given Q queries. Each query contains two integers integer l and r. For each query, your task is to tell winner of the game if it was only played on the piles from range l to r (both inclusive).

Note that, each query is independent from other queries and does not affect them in any way.

Input:
The first line of the input contains a single integer N denoting the number of piles.
The second line contains N space-separated integers where \(i^{th}\) integer denotes the amount of stones in \(i^{th}\) pile.
The third line contains an integer Q denoting the number of queries.
Next Q lines contains two single space separated integers l and r as described in the problem statement.

Output:
Print winner of each query in a separate line. Output "Phineas" if Phineas wins or "Ferb" if Ferb wins.

Constraints:

  • \(1 ≤ N ≤ 5 * 10^{5}\)
  • \(1 ≤ A_{i} ≤ 10^{9}\)
  • \(1 ≤ Q ≤ 2 * 10^{5}\)
  • \(1 ≤ l \le r ≤ N\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
2 votes
Tags:
Easy