#include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>
#include <cmath>
using namespace std;
/*****************************************************************************************
// DevDraft 2014 Brian Ackermann Submission 2.0
// TreeNode class represents a single node in the decision tree
// Contains the current hand of the player's turn
// left child, right child and possible middle child if this is the root of our tree
// two static methods used to construct the decision tree
// and to decide if player one can force a win (if not player 2 automatically wins)
******************************************************************************************/
class TreeNode{
public:
//public fields used to represent decision tree node
std::vector<double> hand;
TreeNode* left;
TreeNode* middle;
TreeNode* right;
//Basic constructor to fill the player's hand
TreeNode(std::vector<double> arr)
{
this->hand = arr;
}
/********************************************
// constructTree static method
// Input: TreeNode pointer, boolean
// Output: nothing
// Side-effects: Constructs decision tree
*********************************************/
static void constructTree(TreeNode* root, bool isRoot)
{
std::vector<double> leftHand, middleHand, rightHand;
std::vector<double> currHand = root->hand;
//we've encountered a leaf node simply return
if(currHand[0] == currHand[1] && currHand[0] == currHand[2])
{
return;
}
//we've encountered a parent of a leaf node
else if(currHand[0] == currHand[1])
{
rightHand.push_back(currHand[0]);
rightHand.push_back(currHand[0]);
rightHand.push_back(currHand[0]);
root->right = new TreeNode(rightHand);
constructTree(root->right, false);
}
else if(currHand[1] == currHand[2])
{
leftHand.push_back(currHand[1]);
leftHand.push_back(currHand[1]);
leftHand.push_back(currHand[1]);
root->left = new TreeNode(leftHand);
constructTree(root->left, false);
}
//We're at the root of our tree, three branches must be made
else
{
if(isRoot)
{
if(currHand[0] != std::floor((currHand[1]+currHand[2])/2))
{
leftHand.push_back(currHand[1]);
leftHand.push_back(std::floor((currHand[1]+currHand[2])/2));
leftHand.push_back(currHand[2]);
root->left = new TreeNode(leftHand);
constructTree(root->left, false);
}
else
return;
if(currHand[1] != std::floor((currHand[0]+currHand[2])/2))
{
middleHand.push_back(currHand[0]);
middleHand.push_back(std::floor((currHand[0]+currHand[2])/2));
middleHand.push_back(currHand[2]);
root->middle = new TreeNode(middleHand);
constructTree(root->middle, false);
}
else
return;
if(currHand[2] != std::floor((currHand[0]+currHand[1])/2))
{
rightHand.push_back(currHand[0]);
rightHand.push_back(std::floor((currHand[0]+currHand[1])/2));
rightHand.push_back(currHand[1]);
root->right = new TreeNode(rightHand);
constructTree(root->right, false);
}
else
return;
}
//we're at an interior node create two branches and recurse
else
{
if(currHand[0] != std::floor((currHand[1]+currHand[2])/2))
{
leftHand.push_back(currHand[1]);
leftHand.push_back(std::floor((currHand[1]+currHand[2])/2));
leftHand.push_back(currHand[2]);
root->left = new TreeNode(leftHand);
constructTree(root->left, false);
}
else
return;
if(currHand[2] != std::floor((currHand[0]+currHand[1])/2))
{
rightHand.push_back(currHand[0]);
rightHand.push_back(std::floor((currHand[0]+currHand[1])/2));
rightHand.push_back(currHand[1]);
root->right = new TreeNode(rightHand);
constructTree(root->right, false);
}
else
return;
}
}
}
/***************************************************************
// playerOneCanForceWin static method determines if player one
// can force a win if not player two must be able to
//
// Input: TreNode pointer, integer depth, bool
// Output: Boolean
// Side-effects: none
***************************************************************/
static bool playerOneCanForceWin(TreeNode* root, int depth, bool isRoot)
{
//reached leaf node, if player one's turn return false
if(!root->left && !root->right)
{
if(depth%2 == 0)
return false;
return true;
}
if(isRoot)
{
bool leftTurn = false;
bool rightTurn = false;
bool middleTurn = false;
if(root->left)
{
leftTurn = playerOneCanForceWin(root->left, depth+1, false);
}
else
{
leftTurn = true;
}
if(root->right)
{
rightTurn = playerOneCanForceWin(root->right, depth+1, false);
}
else
{
rightTurn = true;
}
if(root->middle)
{
middleTurn = playerOneCanForceWin(root->middle, depth+1, false);
}
else
{
middleTurn = true;
}
if(leftTurn || rightTurn || middleTurn)
return true;
else
return false;
}
//we're at an interior player 1 node, check if either route returns true
else if(depth%2 == 0)
{
bool leftTurn = false;
bool rightTurn = false;
if(root->left)
{
leftTurn = playerOneCanForceWin(root->left, depth+1, false);
}
else
{
leftTurn = true;
}
if(root->right)
{
rightTurn = playerOneCanForceWin(root->right, depth+1, false);
}
else
{
rightTurn = true;
}
if(leftTurn || rightTurn)
return true;
else
return false;
}
//we're at an interior player 2 node, check if both routes return true (both must or else player two can force a win)
else
{
bool leftTurn = false;
bool rightTurn = false;
if(root->left)
{
leftTurn = playerOneCanForceWin(root->left, depth+1, false);
}
else
{
leftTurn = true;
}
if(root->right)
{
rightTurn = playerOneCanForceWin(root->right, depth+1, false);
}
else
{
rightTurn = true;
}
if(leftTurn && rightTurn)
return true;
else
return false;
}
}
~TreeNode()
{
delete left;
delete middle;
delete right;
}
};
int main() {
//read in standard input parse into hand and call premade functions
std::string tmp;
while(std::getline(std::cin, tmp)){
std::vector<double> nums;
std::stringstream ss(tmp);
int ti;
while(ss >> ti)
nums.push_back(ti);
if(nums.size() != 1)
{
TreeNode* root = new TreeNode(nums);
TreeNode::constructTree(root, true);
if(TreeNode::playerOneCanForceWin(root, 0, true))
cout << "First\n";
else
cout << "Second\n";
}
}
return 0;
}