We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Game Theory
  4. Poker Nim

Poker Nim

Problem
Submissions
Leaderboard
Discussions
Editorial

Poker Nim is another -player game that's a simple variation on a Nim game. The rules of the games are as follows:

  • The game starts with piles of chips indexed from to . Each pile (where ) has chips.
  • The players move in alternating turns. During each move, the current player must perform either of the following actions:

    • Remove one or more chips from a single pile.
    • Add one or more chips to a single pile.

    At least chip must be added or removed during each turn.

  • To ensure that the game ends in finite time, a player cannot add chips to any pile more than times.
  • The player who removes the last chip wins the game.

Given the values of , , and the numbers of chips in each of the piles, determine whether the person who wins the game is the first or second person to move. Assume both players move optimally.

Input Format

The first line contains an integer, , denoting the number of test cases.
Each of the subsequent lines defines a test case. Each test case is described over the following two lines:

  1. Two space-separated integers, (the number of piles) and (the maximum number of times an individual player can add chips to some pile ), respectively.
  2. space-separated integers, , where each describes the number of chips at pile .

Constraints

Output Format

For each test case, print the name of the winner on a new line (i.e., either or ).

Sample Input

2
2 5
1 2
3 5
2 1 3

Sample Output

First
Second

Author

Shafaet

Difficulty

Easy

Max Score

20

Submitted By

7065

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website

Join us

Create a HackerRank account

Be part of a 26 million-strong community of developers

Please signup or login in order to view this challenge

or
Already have an account?Log in