We need to determine winner of this impartial game? Actually it's a partizan game because moves available to players differ: first player can only remove odd-sum subsegments, second only even-sum subsegments. But because they alternate and each move reduces array size, it's a combinatorial game with two players having different move sets. So we need to analyze who wins given optimal play.
We have an array of numbers. Moves: remove a contiguous non-empty subarray whose sum has specified parity. After removal, the remaining parts are concatenated (order preserved). The game continues.
Goal: The player who cannot make a move loses. So typical game.
We need to determine winner for given array.
Constraints up to 1e6, so O(n) or O(n log n) needed.
Observation: The parity of sums depends on the parity of elements mod 2. Since we only care about parity, we can consider each element mod 2: 0 for even, 1 for odd. Because sum parity is determined by count of odd numbers modulo 2 (since even numbers contribute 0 mod 2). So we can replace each ai by bi = ai mod 2 (0 or 1). Then the array is a binary string.
Now the game: First player can remove any contiguous substring whose sum (i.e., number of 1s) is odd. That means the substring has an odd number of 1s (since each 1 contributes 1 mod 2, 0 contributes 0). So a subsegment with odd count of 1s.
Second player can remove any contiguous substring whose sum is even: i.e., even number of 1s.
Note: The subsegment can be of any length >0. Also it could be all zeros? Even sum: zeros are even sum (0) so yes, even-sum subsegments can be all zeros. Similarly, odd-sum subsegment must contain at least one odd (1) and the total count of 1s is odd.
Thus game reduces to binary string; players remove contiguous substrings with specified parity of 1-count.
Game ends when the array is such that the current player cannot find any subsegment with required parity.
We need to analyze.
First, note that the game is deterministic and perfect information. We can try to compute Grundy? But since moves differ, it's not impartial. We can treat as a game with positions and whose turn? The position consists of the binary string and a flag indicating whose turn. This is a two-player game with possible infinite moves? But array length decreases each move, so finite.
We could try to solve via DP with state being string and turn, but length up to 1e6, so need insight.
We can think about properties: The moves remove contiguous segments. The parity of total number of 1s in whole array may matter.
Let total number of 1s in current array be T (mod 2). Then what moves are available?
- First player (odd-sum) can move only if there exists a contiguous subsegment with odd number of 1s. That is equivalent to existence of at least one 1? Not exactly: if there is at least one 1, you can take a subsegment consisting of that single 1, which has odd sum (1). So first player can move if there is at least one 1 in the array. But careful: if there is a 1, that single element subsegment exists. So first player can always move as long as there is at least one odd element (1). If the array has only evens (all zeros), then there is no odd-sum subsegment because any subsegment sum is 0 (even). So first player loses if array contains no 1s. So condition: first player has move iff at least one 1 present.
Similarly, second player (even-sum) can move if there exists any contiguous subsegment with even sum. That includes subsegments of length 0? No, non-zero length. So even-sum subsegments exist if there is any subsegment with even number of 1s. That includes subsegments that contain only evens (0). If there is at least one 0, a single 0 subsegment has even sum (0). Also if there is a pair of 1s? Actually a subsegment with two 1s also has even sum. So second player can move if either there is at least one 0, OR the array has at least two 1s? But if the array consists solely of 1s (all ones), then any single element subsegment has sum 1 (odd), not even. A subsegment of length two has sum 2 (even). So if there are at least two consecutive 1s? Actually contiguous subsegment can be any contiguous part. If array is all 1s, you can take two adjacent 1s, so there is an even-sum subsegment. So as long as the array length >=2 (with all ones), there is an even subsegment (e.g., first two). More generally, if the total number of 1s is at least 2, there might be an even-sum subsegment but careful: if the 1s are isolated by zeros? Actually zeros allow single zero even. So condition: second player can move iff either there is a 0 or the number of 1s >=2? But even if there is exactly one 1 and the rest zeros? Then single zero gives even sum, so yes, because zeros exist. So second player cannot move only if the array consists solely of a single 1? Let's check: array = [1] (only one element, which is 1). Does second player have an even-sum subsegment? The only subsegment is that 1, sum odd. So no even-sum subsegment. So second player cannot move if the array is exactly [1] (single 1). Also array empty? Game ends when player cannot move; but if array empty, both cannot move, but the player whose turn it is loses because they have no moves. So if array is empty, the player to move loses.
Thus second player's move exists if the array has at least one 0, OR the array length >=2 and there are at least two 1s (since you can take two 1s maybe not adjacent? If two ones are separated by zeros? Then subsegment containing both ones and the zeros between them: sum = 2 (even) if zeros don't affect parity. So any subsegment that includes an even number of 1s works. If there are at least two 1s, you can take the whole array if it has even number of 1s; but if total number of 1s is odd and exactly two ones? Actually two ones give even number of ones, so total number of ones is even if exactly two ones. So you can take whole array if it has even total ones. But if total ones is odd (e.g., three ones) and no zeros, then whole array sum odd, but you can take a subsegment containing exactly two ones (maybe contiguous if they are adjacent? but if they are separated by one, you can take from first to second inclusive, which would include two ones? Actually if the ones are at positions 1,3,5, then taking subsegment from 1 to 3 includes two ones (positions 1 and 3) sum even. So yes, if there are at least two ones, you can always find a contiguous subsegment containing exactly two ones? Not always if ones are at ends and far apart? Let's think: suppose array = [1,1] -> both adjacent, subsegment both = even. [1,0,1] -> whole array = even? 1+0+1=2 even. So yes. If array = [1,0,0,1,0,1] (three ones). There exists subsegment with even ones: e.g., first two ones: positions 1 and 4, if you take from 1 to 4, includes two ones, zeros don't matter. So yes, as long as there are at least two ones, you can select a subsegment that starts at the first occurrence of a 1 and ends at the second occurrence (inclusive) to capture exactly two ones (the first and second). That gives even sum. So that works. So second player can move if either there is at least one zero, or there are at least two ones. The only case where second player cannot move is when the array consists of exactly one element which is 1 (single 1). Also what about array with only zeros? That is all evens; second player can take any zero, so yes can move. So second player's move exists unless the array is exactly [1].
Thus:
- First player move exists iff array has at least one 1.
- Second player move exists iff array is not exactly [1] (i.e., either length >1 or contains at least one 0). Actually also consider array empty: no moves.
But these are only about existence of any subsegment of required parity; but as game proceeds, array changes.
So the game essentially reduces to a token: we have a binary string, and players remove segments.
We can think in terms of parity of total ones and zeros, but also structure.
Maybe the outcome depends only on the parity of total number of 1s? Let's test small examples.
Example 1: [1,3,2,3] -> binary: 1,1,0,1? 3 mod2=1, 2 mod2=0, 3 mod2=1 -> [1,1,0,1]. Total ones = 3 (odd). First player wins according to sample. Example 2: [2,2] -> [0,0] total ones=0 (even). Second wins. That suggests that if total ones odd, first wins; if even, second wins? But need to verify more.
Test trivial cases:
-
n=1, a=[0] (even sum). First player's turn: can he move? He needs odd sum subsegment. The only subsegment is [0] sum even -> no move. So first loses. According to hypothesis (total ones even => second wins? But here total ones =0 even, so second would win? Actually second would win means first loses, correct. So fits.
-
n=1, a=[1] (odd sum). First player: can he move? Yes, subsegment [1] odd sum, he removes it, leaving empty array. Then second's turn on empty: no moves, second loses, so first wins. Total ones=1 odd => first wins. So fits.
-
n=2, a=[1,0] binary [1,0] total ones=1 odd. Who wins? Let's simulate optimally. First player's turn. Options: He can remove any odd-sum subsegment. Possibilities:
- Remove [1] (odd) -> remaining [0]. Then second's turn on [0]: second can remove [0] (even) -> empty, then first's turn empty -> first loses? Actually after second removes, it's first's turn on empty, first has no move, so first loses. So if first removes single 1, he loses (assuming optimal play from second).
- Remove [0]? That's even sum, not allowed.
- Remove [1,0] whole array sum =1 (odd) -> remove all, then second on empty loses, first wins. So first can win by removing whole array. So first wins. So total odd => first wins.
-
n=2, a=[1,1] binary [1,1] total ones=2 even. First player's turn: options: odd-sum subsegments. Which subsegments have odd sum? Single 1: either first or second element individually. Removing a single 1 leaves [1]. Then second's turn on [1]: can second move? [1] is exactly the array [1] which is not allowed for second (only even sum). So second has no move, loses, so first wins if he does that. Wait, is that correct? Let's simulate: array [1,1]. First player removes first element (odd). Remaining array: [1] (single 1). Second player's turn: needs even sum subsegment. Only subsegment is [1] sum odd, so no move. So second loses, first wins. That contradicts hypothesis that total even => second wins. But sample [2,2] gave second win. So not just total parity.
So we need more analysis.
Our example: [1,1] total ones even, but first can win by removing one 1, leaving single 1, then second stuck. So first wins. So hypothesis fails.
But sample [2,2] = [0,0] total ones=0 even, first cannot remove any odd subsegment? Check: any subsegment? single 0 even; whole [0,0] sum even. So first has no moves, loses. So difference: In [1,1], there is at least one 1, so first can move. In [0,0], no ones, so first cannot move. So first's ability to move depends on presence of 1s.
But in [1,1], first has move and wins. So maybe the game outcome is determined by whether the first player can force a win always when there is at least one 1? Not exactly: Consider [1,1,1] (three ones). Total odd. First should win? Let's test: [1,1,1]. First options: He could remove a single 1, leaving [1,1] (two ones). Then second's turn on [1,1]. Second can move? even sum subsegments: e.g., remove both (sum 2 even) leaving empty -> first's turn empty -> first loses. So if first removes single 1, second can win by removing both. Could second also do something else? But if second removes both, first loses. So maybe first should choose a different move? Could first remove two ones? That's even sum, not allowed. Could first remove three ones (whole) odd sum? That would win immediately (leaves empty, second loses). So first can win by removing whole array. So yes first wins.
Consider [1,1,1,1] (four ones). Total even. First options: Remove one 1 -> leaves [1,1,1] (three ones). Second's turn on [1,1,1]. Second can remove? Even sum subsegment: e.g., remove two ones? But careful: after first's move, the array is three ones. For second on [1,1,1], can he remove an even sum subsegment? Yes, any subsegment with even number of ones. For instance, remove the first two, leaving [1]. Then first's turn on [1]: first can remove that 1, leaving empty, then second loses? Let's simulate: start [1,1,1,1] first removes one 1 -> [1,1,1]. Second removes first two ones -> [1]. First removes that 1 -> empty. Now second's turn on empty, loses. So first wins? But is that optimal for second? Maybe second has a better response. After first leaves [1,1,1], second could remove all three? That's odd sum, not allowed. Could second remove a single 0? none. So second must remove an even-sum subsegment. Options: Remove a subsegment with exactly 2 ones (or whole array if even ones but whole has 3 ones odd). So any removal of two contiguous ones? But can he remove two ones that are not contiguous? They must be contiguous segment; in [1,1,1] all are contiguous. Removing the first two leaves [1]; removing last two leaves [1]; removing middle two? Actually any two consecutive leaves one remaining. Could also remove a segment that includes all three? Not allowed because sum odd. So any move by second leaves a single 1. Then first can remove it and win. So if first leaves three ones, second cannot avoid leaving one. So first wins from [1,1,1,1]? But sample with [2,2] (all zeros) gave second win. So maybe all-ones arrays always first wins regardless of parity? Check [1] first wins; [1,1] first wins; [1,1,1] first wins; [1,1,1,1] first wins? Let's simulate with optimal second: Could second ever force a win? For all-ones arrays, first can always remove the whole array? If total ones odd, whole array sum odd, first can win immediately by removing all. If total ones even, whole array sum even, not allowed for first. But first can consider other moves. For all-ones of even length, first cannot remove whole because even sum. Could first remove an odd-length segment? For all-ones, any segment of odd length has odd sum. So first can remove a subsegment of odd length. For example, in [1,1,1,1] (length 4 even), first could remove a segment of length 1 (odd sum) or length 3 (odd sum). Let's analyze if there is any move that leads to a losing position for second. After first moves, we get some array of ones (since all ones). If first removes a single 1, we get [1,1,1] (three ones). As argued, second then leaves [1] and first wins. If first removes three ones, we also get [1] (since remove three contiguous, leaving the other one). Then second's turn on [1] - second cannot move, loses immediately. So first wins by removing three ones. So indeed, for all-ones arrays, first always wins.
But we saw an example where first loses: [0,0] (no ones). Also maybe other combos.
Consider array [1,0,0] (binary 1,0,0). Total ones=1 odd. First can win? He can remove whole array (sum=1 odd) and win. So first wins.
Consider [0,1] binary 0,1. total ones=1 odd. First can remove whole? sum=1 odd -> win. So wins.
Consider [0,1,0] total ones=1 odd -> whole sum odd -> win.
Thus if whole array sum odd, first can win immediately by taking all. So only when total sum even does first need to think. If total sum even, first cannot win immediately. But still might win via other moves.
So key: The first player wins if total ones odd (since immediate win). But we already saw a counterexample? Actually [1,1] total even but first won. So total odd is sufficient but not necessary.
Let's test more arrays with total even but first wins: [1,1] we saw first wins; [1,1,1,1] first wins; [1,1,0]? Let's test [1,1,0] binary: ones=2 even. First's turn. Options: He can remove odd-sum subsegment. Possibilities:
- Remove a single 1 (position 1 or 2) -> left: if remove first 1, remaining [1,0]; if remove second 1, remaining [1,0] as well? Actually array [1,1,0], remove element1 -> [1,0]; remove element2 -> [1,0]; remove segment [1,1]? sum=2 even not allowed; remove segment [1,0]? That would be positions2-3? sum=1+0=1 odd allowed? Wait [1,0] sum=1 odd, but that subsegment is contiguous? positions 2 and 3: [1,0] sum=1 odd -> allowed. If first removes that, remaining [1] (first element). Then second's turn on [1] loses. So first can win. Also remove segment [1,1,0] whole sum=2 even not allowed. So first can win by removing two elements (2-3) leaving [1] and wins. So first wins.
What about [0,0,1,1]? ones=2 even. First: can he win? He can remove a segment that leaves second in losing position. Perhaps similar. Let's simulate: array [0,0,1,1]. First could remove a segment with odd sum. Options: single 1 (positions 3 or 4) leaves [0,0,1] or [0,0,1]? Actually if remove position3 (1), left [0,0,1] (since glue). Then second's turn on [0,0,1] (ones=1). Second can move? He needs even sum subsegment: there are zeros, so he can remove a zero. For example, remove a single 0, leaving [0,1] or [0,1]? Let's see: after first removal, array is [0,0,1] (three elements). Second could remove the first 0 -> remaining [0,1] (ones=1). Then first's turn on [0,1]: first can remove? need odd sum. He can remove the 1 (single) or whole [0,1] sum=1 odd, so wins? Let's see: first removes whole array -> empty, second loses. So if second removes a zero, first wins. Could second do something else? On [0,0,1], second could remove the 1? Not allowed because sum odd? 1 is odd, not even. Could remove two zeros? That would leave [1] -> first wins. Could remove [0,0] (both zeros) leaving [1] -> first wins. Could remove [0,1]? That's positions 2-3? sum=1 odd not allowed. So second's moves all lead to first winning? Possibly. But is there a move for second that leads to a position where first cannot move? For that, after second's move, the array must have no ones (since first needs a 1). So second would want to remove all ones? But second can only remove even-sum segments. Could he remove the 1 along with some zeros to make the segment even sum? He could remove [0,0,1] whole? sum=1 odd -> not allowed. Could remove [0,1]? sum=1 odd not allowed. So he cannot remove the 1 because any segment containing the 1 alone is odd; if he includes an even number of ones, but there is only one 1, so any segment containing that 1 has odd number of ones, sum odd. So second cannot remove the 1. So any move by second will leave the 1 present. So after second's move, the array will still contain at least that one 1, so first will have a move. Then can first always force win? Possibly. So first wins.
But there might be arrays where total even and first loses. Sample [0,0] is one such. Also consider [0] (single zero) total even, first loses. Consider [0,0,0] first loses. So seems if there are no ones, first loses.
What about arrays with ones and zeros but where first might lose? Let's attempt to find a counterexample.
Take [1] we know first wins.
[1,0] first wins.
[1,0,0] first wins.
[0,1] first wins.
[0,0,1] first wins (first can remove whole if odd? total ones=1 odd -> immediate win). Actually total odd => immediate win. So need total even.
So consider arrays with total even, at least one 1, and also zeros maybe. We've seen [1,1] (all ones) first wins; [1,1,0] first wins; [0,0,1,1] first wins. What about [1,0,1]? binary: 1,0,1 total ones=2 even. First's turn. Options: odd-sum segments:
- Remove a single 1 (position1) -> left [0,1]. Then second's turn on [0,1]. Second can move: even sum subsegments: remove 0 (leaves [1]) -> then first wins; remove [0,1]? sum=1 odd not allowed; remove whole? only two elements. So second's only move is to remove the 0, leaving [1]. First wins. So that move leads to win.
- Remove the other 1 (position3) -> symmetric, leaves [1,0] -> similar, first wins.
- Remove a segment of two? [1,0] position1-2 sum=1 odd? Actually 1+0=1 odd -> allowed. Remove that -> left [1]. Then second loses immediately. So first wins.
- Remove segment [0,1] positions2-3 sum=1 odd -> left [1] -> win.
- Remove whole array? sum=2 even not allowed.
So first wins.
What about [1,0,0,1]? ones=2 even. First can remove odd segment. Could there be a scenario where after first's move, second can force a win? Let's try to see if second could ever win when there is at least one 1. For second to win, after his move the first player must have no move (i.e., no ones). So second would like to eliminate all ones. But second can only remove even-sum segments. If there is at least one 1, can second remove a segment that contains that 1 and also maybe others such that the segment sum is even, thereby removing that 1? That requires the segment to contain an even number of ones. So if total number of ones in the array is even, second could potentially remove all ones by selecting a segment containing an even number of ones (maybe all). But after second's move, the remaining array may still have ones if not all removed. But second could aim to leave an array with no ones. For that, the segment he removes must contain all ones, and the segment must have even sum. That means the total number of ones must be even. So if at some point, it's second's turn and the total ones in the array is even, second could win by removing a segment that contains all ones (provided the segment is contiguous? But the ones might not be contiguous; the segment to remove must be contiguous and include all ones, but also may include zeros. However, to include all ones, the segment would stretch from the leftmost 1 to the rightmost 1. That segment will have exactly the total number of ones (even). So second can remove that whole segment (which may include zeros as well). After removal, the remaining parts (if any) are only zeros (since all ones removed). So the resulting array would contain no ones, meaning first cannot move on his next turn and loses. So second could win if at his turn the total number of ones is even and the segment from leftmost 1 to rightmost 1 is a valid subsegment (always contiguous) and he chooses to remove it. But is that move always legal? Yes, because the sum is even (since total ones even), so second can remove that entire segment (which has even sum). However, there might be zeros on the ends? The segment is contiguous and includes all ones. It will have even sum. So second can do that. But is it always optimal for second? Possibly.
Thus the game may revolve around parity of number of ones when it's second's turn. If second ever gets a turn with even total ones, he could remove the entire block containing all ones (the minimal covering segment) and win, provided that after removal, first has no moves (i.e., no ones). But wait: after second removes that segment, the remaining array (if any) consists only of zeros (if there were zeros outside the segment). Those zeros are even, but first needs odd sum, and with only zeros, no odd sum exists. So indeed first loses. So second wins if he can, on his turn, remove a contiguous segment that contains all ones and has even sum (i.e., even number of ones). That is possible if the current total number of ones is even. So if at second's turn, total ones is even, he can win immediately (by taking the segment from first 1 to last 1). However, we must check if there is any nuance: what if the segment from first to last 1 includes some ones but there are also zeros inside, but that's fine. So second's winning condition: if at his turn, the total number of ones is even, then he can win by removing the entire range covering all ones. Is that always legal? Yes, because the sum is even. But wait: what if the array has no ones at all? Then second cannot move? Actually second can move if there is a zero; but if there are no ones, second can still move (removing a zero). But in that case, first already lost because he had no move. So that's a different case. So for second to have a winning move from a position with ones, he needs even total ones.
Thus, if at the start (first player's turn) the total ones are even, first cannot win immediately by taking all, but if after his move he can force the total ones to be odd when second's turn, then second cannot win immediately. But second might still have other moves that could eventually lead to win.
Let's analyze more systematically.
Define the game state as (array, player to move). Since only parity of ones in segments matters, the distribution of zeros may affect possible moves. However, maybe we can reduce to a simpler impartial game based on number of ones and zeros? Let's attempt to characterize winning positions.
Given the high constraints, likely the answer depends simply on the parity of the number of ones? But we saw [1,1] (even ones) first wins, so not that simple.
Perhaps the outcome depends on whether the first player can force that after his move, the total number of ones becomes odd, preventing second's immediate win. But if first leaves an even number of ones, second can win immediately by taking the whole ones block. So first must avoid leaving an even number of ones. So first must make a move that results in an odd number of ones remaining. Is that always possible? If the current total ones is odd, first can take an odd-sum segment (any segment with odd number of ones). When he removes a segment with odd number of ones, the remaining total ones will be (original odd) minus (odd) = even. So after first's move, the total ones becomes even. Then second can win immediately by removing the block of all ones. So if initial total ones is odd, first can win immediately by taking whole array (since whole array sum odd) - that yields empty, second loses. But if first chooses any other move (removing an odd segment that is not the whole array), then remaining total ones becomes even, and second could then win by removing all ones. So in initial odd total, first's optimal move is to take whole array and win. So first wins if initial ones odd.
If initial total ones is even, then first cannot take whole array (sum even). He must make a move that removes some odd-sum segment. After his move, remaining total ones = even - odd = odd. So after his move, the total ones is odd. Then it's second's turn with odd total ones. Can second win immediately? As argued, if total ones is odd, second cannot remove a segment containing all ones because that sum would be odd (not allowed). But perhaps second can still win by other means? Let's analyze positions where it's second's turn and total ones is odd.
We need to analyze positions where current player (second) has to move, and the total number of ones is odd. Does second have a winning strategy? Or can first (next player) force a win? This is like a subgame.
Let's denote state by (S) where S is the array, but maybe only the number of ones and zeros and their arrangement? But arrangement might matter because moves must be contiguous. However, maybe we can compress the array into blocks of zeros and ones? Since the parity condition only depends on count of ones in selected segment, the positions relative to each other might matter for contiguity.
Let's consider representation: array is a sequence of bits. A move removes a contiguous segment. The remaining parts are glued. So effectively, the game is about removing a contiguous substring. This is reminiscent of a game on a string where players can delete substrings with certain parity constraints.
We can try to analyze via invariants or nimbers. But maybe there's a known result: The first player wins iff there is at least one odd number in the array? That would mean first wins unless all numbers even. But we have [0,0] (all evens) first loses; but [1,1] (all odds) first wins. However, what about arrays with both evens and odds? All examples with at least one odd gave first win. But is there a counterexample where first loses despite having an odd? Let's try to find.
Consider array [1,0,0,0]? ones=1 odd -> first wins by taking whole.
Consider array [1,0,0,0,0] also odd -> win.
So all simple.
Maybe a scenario where first cannot avoid leaving an even number of ones, but that's always the case after his move because even - odd = odd? Actually if initial ones even, after first removes odd segment, remaining ones = odd. So after his move, the total ones is odd. Then it's second's turn with odd ones. Could second, despite having odd total, still win? Possibly if he can make a move that results in a position where first has no move (i.e., no ones) or a losing position.
So we need to analyze positions where it's second's turn and total ones is odd.
Let's denote such a state as (odd number of ones, some zeros). Second can only remove even-sum segments. He can remove any contiguous segment with even number of ones. After removal, the remaining total ones = odd - even = odd (since odd minus even is odd). So after second's move, total ones remains odd (if he removes an even number of ones). Wait: odd - even = odd. So the parity of total ones does not change after second's move. So if it's second's turn with odd ones, after his move, the ones remain odd. Then it's first's turn with odd ones. First can then take whole array and win? Because if total ones is odd, first can take whole array (if the whole array has odd sum) and win immediately. But careful: after second's move, the array might not be whole? The whole array at that point is whatever is left. If total ones is odd, first can remove the entire remaining array (since its sum is odd) and win. So if after second's move, the array still has odd total ones, then first can win on his turn by taking everything. Therefore, second cannot allow the game to continue to first's turn with odd ones, because then first wins. So second must, if possible, make a move that results in total ones = 0 (i.e., remove all ones) on his turn, because that would leave no ones for first. But if total ones is odd, he cannot remove all ones in one move because that would be an odd-sum segment, not allowed. So second cannot remove all ones directly. Could he remove a segment such that after removal, the remaining array has no ones? That would require that the segment removed contains all ones and the sum is even (since removal must be even). But total ones is odd, so that sum would be odd, not allowed. So he cannot directly remove all ones. Could he remove a segment that leaves some ones, but then perhaps the resulting array's structure might make it impossible for first to take whole? But if the total ones in the resulting array is odd, first can still take the whole array. However, is it always true that first can take the whole array when total ones is odd? He can only take whole array if the whole array's sum is odd, which it is. But is that move always legal? Yes, because it's a subsegment of non-zero length (the whole array) with odd sum. So first can always win if at his turn the total ones is odd, by taking the whole array. Therefore, if at any point it's first's turn and total ones is odd, first wins immediately.
Thus, the game reduces to: If at start, total ones odd -> first wins. If total ones even -> first moves, and after his move, total ones becomes odd (since he removes an odd number of ones). Then it's second's turn with odd ones. But as argued, if second's turn with odd ones, first can win on next turn unless second can win immediately on his turn (i.e., make first have no move). But second cannot win immediately because to leave no ones, he would need to remove all ones, which is not allowed due to parity. However, could second make a move that results in the array having total ones = 0? That would require removing all ones. Not possible because sum odd. Could he make the array empty? That would also remove all ones, same issue. So second cannot directly end the game with a win. But could second make a move that results in a position where, despite total ones being odd, first cannot take the whole array? Wait, first can always take the whole array regardless of arrangement, as long as the total sum is odd. So that seems a sure win for first. Therefore, if second ever faces odd total ones, he loses because first will take all on his next turn.
But is there any nuance where first cannot take the whole array because the array might be empty? If second's move results in empty array, then first loses because it's his turn on empty. But can second, with odd total ones, make a move that results in empty array? That would require removing the whole array in one move. But removing whole array requires sum even for second (since he needs even sum). But total ones odd, whole array sum odd, so not allowed. So he cannot empty the array. So second cannot force a win in one move. Therefore, second loses if he faces odd total ones.
Thus, from initial even total ones, first moves and leaves odd total ones, then second loses. Wait, but that would imply that first always wins if there is at least one 1? Because if total ones even but >=2, first can move (since there is at least one 1) and after his move total ones becomes odd, then second loses. But we must check: Is it always possible for first to make a move when total ones even? He needs an odd-sum subsegment. As long as there is at least one 1, he can take a subsegment with odd number of ones. But does existence of at least one 1 guarantee existence of an odd-sum subsegment? Yes: a single 1 gives odd sum. So first can always move if there is at least one 1. So if there is at least one 1, first can always make a move. Therefore, according to this reasoning, if the array contains at least one 1, first wins. The only case first loses is when there are no 1s (all numbers even). But is that always true? Let's test [0,0] (no 1s) -> first loses, matches. [0] -> loses. [0,0,0] -> loses. So far consistent.
But wait, we earlier considered [1,1] (two ones) and found first wins, consistent. So all examples with at least one odd give first win.
But is there any scenario where first cannot force a win despite having at least one 1? Let's test a tricky case: suppose the array is [1,0,0,0,... many zeros]. First can take the 1, leaving all zeros, then second's turn on zeros: second can remove a zero, leaving still zeros, etc. Actually after first removes the 1, remaining array is all zeros. Then it's second's turn on array of zeros. Second can move (since zeros are even sum). He can remove any zero or segment of zeros. After his move, the array still consists of zeros (maybe fewer). Then it's first's turn on zeros: first has no odd sum, so he loses if the array is non-empty? Actually if it's first's turn and array consists only of zeros, he cannot move, so he loses. So in this line, after first removes the 1, second can move and then first loses. But is that the case? Let's simulate: start: [1,0,0] (for simplicity). First can remove the 1 (single element). Remaining array: [0,0]. Now second's turn: array has zeros only. Second can remove a segment with even sum. He can remove a single 0 (even sum). After removing one 0, array becomes [0]. Then first's turn on [0] -> no odd sum, cannot move, loses. So according to this, first loses if he removes the 1. But earlier we said first could also remove whole array [1,0,0] sum=1 odd, which would win. So first would choose that move instead. So indeed first can win by taking whole array. So that scenario doesn't defeat the hypothesis.
But what if the array is such that the whole array sum is even (so can't take all) and every odd-sum subsegment that first can remove results in a remaining array that contains only zeros? Then after his move, second gets an array of zeros and can move, leading to first eventually losing? But we argued that after first's move, total ones becomes odd (since he removed odd number from even total). That means the remaining array has odd number of ones. So it cannot be all zeros because zeros count as 0 ones, which is even, not odd. So the remaining array must have at least one 1. Because odd number of ones >=1. So the remaining array will contain at least one 1. So second's turn with odd total ones: we previously argued that first can then win on his next turn by taking whole. But careful: after first's move, second gets to move on an array with odd number of ones. As we argued, if second gets odd ones, he cannot prevent first from taking whole on next turn, because whatever move second makes, the total ones after his move will remain odd (since he removes even number of ones). So then first can take whole and win. So it seems first always wins if there is at least one 1.
But wait, we must examine: Could second, on his turn with odd total ones, make a move that results in an array that has odd total ones but where first cannot take the whole array because it's not a legal move? But why would taking whole not be legal? The whole array has odd sum, so it's a valid move for first. So first can always win on his turn by taking whole when total ones odd. That seems definitive.
Thus, the only way first loses is if he has no move at all at the beginning. That occurs when there are no 1s in the array. Because if there is at least one 1, he has a move, and after his move, the game state is such that second will eventually lose (since first can always win on his next turn if total odd). But we need to consider the possibility that first might be forced to make a move that leads to a state where second can win immediately, but we argued second cannot win immediately because total ones odd prevents him from removing all ones. However, could second have a move that makes the array empty? That would require removing whole array (even sum) but total odd, so not allowed. So second can't empty. So first always wins.
But is there any scenario where first, on his first move, cannot avoid leaving an odd number of ones? Actually from even total, any odd removal leads to odd remaining ones. That's inevitable. So indeed after first move, remaining ones is odd. So second's turn with odd ones.
Thus, seems the answer is simply: first wins if there is at least one odd number in the array; otherwise second wins.
But is it really that trivial? Let's test more complicated scenarios to be sure.
Consider array: [1,1,0,0]? ones=2 even. First must remove odd-sum segment. Options:
- Remove a single 1: then remaining array: if remove first 1 -> [1,0,0] (ones=1 odd). Then second's turn. Second can remove any even-sum segment. He could remove the whole array? sum=1 odd not allowed. He could remove a segment containing the 1? That would be odd sum, not allowed. So second's only even-sum segments are those consisting only of zeros. The array [1,0,0] has zeros. He could remove a zero (single or multiple zeros). If he removes a zero, the remaining array still contains the 1 and maybe other zeros. So after his move, total ones remains 1 (odd). Then first's turn: take whole array (odd) and win. So second loses. Could second instead remove a segment that includes the 1 and some zeros making even sum? Since only one 1, any segment containing that 1 has odd number of ones (1), so sum odd. So not allowed. So second's moves cannot remove the 1. So first wins.
- Remove two ones? Not allowed (even sum).
- Remove a segment like [1,0]? That would be odd sum? 1+0=1 odd. If first removes positions 1-2: [1,0] sum odd. That leaves [1,0]? Actually original [1,1,0,0]; removing first two elements (positions1-2) yields remaining [0,0] (two zeros). Wait, removing subsegment [1,1]? That's even sum not allowed. But [1,0] if we take positions1-2? Actually positions1-2 are [1,1] sum even. To get [1,0], we need positions1-2? No, [1,0] would be positions1-2 if the second element were 0, but it's 1. So maybe positions2-3: [1,0] sum=1 odd. Removing positions2-3 leaves [1,0]? Actually original indices: 1:1, 2:1, 3:0, 4:0. Remove subsegment from 2 to 3: elements [1,0]. Remaining: indices 1 and 4: [1,0] after gluing? Wait glue preserves order: left part is elements 1, right part is elements 4. So resulting array: [1,0]. That has ones=1 odd. Then second's turn on [1,0] similar to before: second cannot remove 1, can remove 0, leaving [1], then first wins. So first wins.
- Remove segment [1,0,0]? positions2-4: [1,0,0] sum=1 odd? Actually 1+0+0=1 odd. Removing leaves [1] (first element). Then second's turn on [1] -> second cannot move, loses immediately. So first wins.
Thus all good.
Now consider array with many ones and zeros. The reasoning appears solid.
But hold on: There's a subtlety: When second has odd total ones, after his move the total ones remains odd. However, could second make a move that results in the array having no contiguous subsegment of odd sum for first? But first only needs one odd-sum subsegment. If total ones is odd, there is at least one 1, so first can always take a subsegment with odd sum: either the whole array (which is odd), or a single 1. So first always has a move. So he won't be stuck. So the only way first loses on his turn is if there are no ones. So indeed.
Thus, the game outcome seems determined by whether there exists at least one odd element. If yes, first wins; otherwise second wins.
But wait, is there any possibility that first might be forced to make a move that leaves an even number of ones? No, because he removes an odd number of ones. Starting from even, odd minus odd = odd. So it's forced. So no choice.
What about starting with total ones even but zero? That's no ones, first loses. So consistent.
Thus answer: First wins iff there is at least one odd number in the array.
But before finalizing, let's double-check with some more random examples and edge cases.
Edge Cases:
- n=1, a=[0] -> no odd, first loses. Output Second. Good.
- n=1, a=[1] -> odd exists, first wins. Output First.
- n=2, a=[0,0] -> first loses.
- n=2, a=[1,0] -> first wins (has odd).
- n=2, a=[2,4] (both even) -> first loses.
- n=2, a=[1,2] -> first wins.
- n=2, a=[3,5] (both odd, sum even) -> ones=2 even, but first has odd numbers. According to hypothesis, first wins. Let's simulate: [1,1] (since 3,5 mod2 =1,1). First can remove one 1 leaving [1], second loses. So first wins.
- n=3, a=[0,0,0] -> first loses.
- n=3, a=[0,0,1] -> first wins (can remove whole? sum=1 odd -> win). Yes.
- n=3, a=[0,1,0] -> first wins.
- n=3, a=[1,1,1] -> first wins.
- n=4, a=[0,1,1,0] -> ones=2 even, first wins? Should be yes. Check: first can remove a segment with odd sum. Could remove single 1 at position2 leaving [0,1,0] (ones=1 odd). Then second's turn: array [0,1,0] has zeros, second can remove zero but leaves 1, first wins. So first wins.
- n=4, a=[1,1,1,1] -> first wins.
- n=4, a=[0,0,0,0] -> first loses.
All consistent.
Now consider array with only ones but even length: [1,1] we already did; [1,1,1,1] we did; works.
Consider array with mixed: [0,0,1,1,0] ones=2 even. First can remove [1] leaving [0,0,1,0]? Actually remove the first 1 (position3) leaves [0,0,1,0] (ones=1). Then second can remove a zero, leaving [0,1,0]? Actually after second removes a zero, still one 1 remains, first wins. So first wins.
What about an array where the only odd-sum subsegment is a single element that is a 1, but if first removes it, the remaining array has no ones? But then total ones after removal would be even? Wait if initial ones even, removing one odd (a single 1) leaves odd number of ones? Actually if initial ones = 2, removing one leaves 1 (odd). So remaining has one 1. So not zero. To have remaining zero ones, initial ones must be 1 (odd). But if initial ones odd, first can just take whole and win. So no problem.
Thus, the only losing case for first is all numbers even.
But let's think about a potential counterexample: Suppose the array is [1,1,0]. This has ones=2 even. According to our logic, first wins. We already checked. Could there be a scenario where first's only possible odd-sum subsegment is to take a single 1, and after that, second can remove a segment that includes the remaining 1 and some zeros such that the segment sum is even? But that would remove the 1, leaving zeros only. However, second can only remove even-sum segments. If the remaining array has exactly one 1, any segment containing that 1 has odd sum (since includes one 1). So second cannot remove that 1. So second cannot remove the last 1. So the 1 persists until first's turn, and then first can take it. So first wins.
What if after first's move, the remaining array has multiple ones but odd total, and second can remove a segment that removes exactly an even number of ones, leaving an odd number of ones (still odd). That's fine, then first takes all.
Thus seems robust.
But I recall some Codeforces problem "Leha and another game about arrays" maybe? Actually the problem statement resembles CF problem "Leha and another game about array"? Not sure. However, I think I've seen a problem where the answer is simply based on presence of odd numbers. But let's search memory: There is a known problem "Two players remove subsegments with odd/even sum" and the answer is: First wins if there is at least one odd number; otherwise Second wins. I think that's correct.
But we should be absolutely sure with a more complex scenario: Consider array: [1,0,1,0,1] (ones=3 odd). First can take whole and win. So fine.
Consider array: [1,0,1,0,1,0] (ones=3 odd? Actually 1+0+1+0+1+0 = 3 ones odd). First can take whole and win.
Consider array: [1,0,0,1,0,1]? ones=3 odd -> first wins.
Consider array: [2,4,6] all even -> first loses.
Now, could there be a scenario where first cannot make a move even though there is an odd number? That would require that no contiguous subsegment has odd sum. Is that possible? For a binary string with at least one 1, does there always exist a contiguous subsegment with odd sum? A subsegment with odd sum means odd number of 1s. If there is at least one 1, the subsegment consisting of that single 1 has odd sum. So yes. So first always has a move.
Thus, first's only losing condition is no 1s.
But wait, what about the scenario where first's move must be a subsegment of non-zero length with odd sum, but what if the array has a 1 but that 1 is not alone? It's still a subsegment. So fine.
Now, is there any possibility that first might be forced to lose even though he has a move, because after his move second can somehow force a win? Let's attempt to construct a scenario where after first's move (from even total ones), second can respond in a way that leaves first with no move on his next turn, despite total ones odd? That would require that after second's move, the array has no 1s. But as argued, second cannot remove the last 1 because that would require removing an odd number of ones (1) and he can only remove even number. But could second remove a segment that includes the last 1 along with other ones making the total removed even, but then there would be other ones left? Let's analyze: Suppose after first's move, the array has odd total ones, say 3 ones. Second could remove a segment containing exactly 2 ones (even), leaving 1 one. Then array has 1 one, still odd. So still at least one 1. To leave zero ones, second would need to remove an even number of ones that equals the total number of ones, which is odd, impossible. So second can never leave zero ones. So first will always have at least one 1 on his turn. So he always has a move.
Thus first always wins when he can make a first move.
But is there any possibility of infinite loops? No, length decreases each move.
So the conclusion stands: First wins iff there exists at least one odd number in the array. Otherwise Second wins.
But hold on: We must consider the possibility that the first player may choose not to win immediately when total ones odd, but he will. So optimal play: if total odd, take all and win. If total even, any move leads to a state where second loses. But we must verify that from even total, first can always make a move that doesn't inadvertently allow second to win? According to our reasoning, no matter what odd-sum segment first removes, the resulting state is second's turn with odd total ones, which is a losing state for second (i.e., winning for the player who will move after second, which is first). So first will win regardless of which odd-sum segment he picks. However, we should ensure that from the resulting state (second's turn, odd total ones), second cannot force a win. We argued that first can always win on his next turn by taking all. But is it always optimal for first to take all? Yes, because it's a winning move. So second cannot prevent that. Therefore, second loses. So first wins.
But is there a possibility that first might be forced to pick a move that results in second being able to win immediately because the array becomes something like [1]? Wait, if after first's move, the array is [1] (single 1), then second's turn, and we said second cannot move on [1] (since only subsegment sum odd). So second loses immediately. That's good for first. So even better. So no issue.
Therefore, the answer is indeed: First wins if there is at least one odd element; otherwise Second wins.
But wait, let's test a more complex scenario: Suppose the array is [1,1,1,1,1] (5 ones, odd). First takes all and wins.
If total even but contains at least one 1, first wins.
Now, is there any scenario where the first player cannot remove a subsegment with odd sum despite having ones? The only potential restriction is that the subsegment must be contiguous. If there is a 1, that's a contiguous segment of length 1. So yes.
Thus answer seems too trivial. But problem constraints up to 1e6 suggests they expect something non-trivial. However, sometimes Codeforces problems have simple solutions disguised. Let's search memory: I recall a problem "Leha and another game about array" maybe similar. Actually there is a Codeforces problem 841C? Not sure. Let's try to think if there might be a catch.
What about zeros? If all numbers are even, first loses. That's straightforward.
But what about the possibility that the array contains an odd number, but first cannot move because the array is such that the odd numbers are not accessible? No, they are always accessible.
Thus, the solution: check if any ai % 2 == 1. If yes, print "First", else "Second".
But before finalizing, let's test the sample:
Sample 1: 4 numbers: 1,3,2,3. All have mod? 1%2=1, 3%2=1, 2%2=0, 3%2=1 => has odd, output First. matches.
Sample 2: 2 numbers: 2,2 => both even, output Second. matches.
So it matches samples.
However, is there any nuance that the players play optimally? Could there be a scenario where first, despite having an odd, might choose a suboptimal move that lets second win, but since both play optimally, first will choose a winning move. According to our analysis, any move is winning when total even? Actually we said from even total, any odd-sum move leads to a state where second loses. So all moves are winning. So first can pick any.
But we must confirm that from even total, after first's move, second indeed cannot force a win. We argued second loses because after his move, first can take all. But is it always optimal for first to take all? If after second's move, the total ones is odd, first can take all and win. That seems correct.
But is there a scenario where second could make a move that results in the array being such that first cannot take all because the array might be empty? No, because if second's move results in empty, then first loses immediately. But can second achieve empty? That would require removing the whole array, which requires even sum. But total ones is odd, so whole array sum odd, not allowed. So second cannot empty the array.
Thus, the analysis stands.
But wait, could second make a move that results in an array that has odd total ones but where the whole array sum is odd, yet first cannot take it because it's not a legal move? It is legal. So yes.
Thus, it seems solved.
However, I want to double-check with a more intricate scenario: maybe the parity of zeros matters because after second's move, the array may contain zeros and ones, but first taking the whole array is allowed because whole array sum is odd (since total ones odd). Zeros do not affect parity. So yes.
Thus, answer is trivial.
But is there any scenario where first cannot move because the array has an odd number but it's isolated? No.
Given the problem constraints high, maybe they want to ensure O(n) but it's easy.
Nonetheless, I'm slightly uneasy because the problem statement seems to come from a contest (maybe Codeforces Round #) and typically such problems have more twist. However, I recall a problem "Leha and Another Game about Graph" but not this.
Maybe I missed a subtlety: The first player can remove odd-sum subsegments, second even-sum. But the subsegment must be of non-zero length, but that's fine. The removed subsegment can be any contiguous part. The players may remove subsegments that are not necessarily the whole array. Our reasoning used the fact that if total ones odd, first can take whole and win. That's correct. If total ones even, first must remove an odd-sum subsegment, leaving odd total ones for second. Then second's turn with odd total ones. Could second have a move that makes the first player unable to move on his next turn, even though total ones remain odd? First player's move requires existence of an odd-sum subsegment. If total ones is odd, there is at least one odd-sum subsegment: the whole array, or any single 1. So first always can move. So second can't make first stuck.
Thus second's only chance is to win immediately by making the array empty on his turn, but he can't because total ones odd prevents that.
Thus conclusion holds.
One more thought: Could second, on his turn with odd total ones, remove a subsegment such that the remaining array has no odd-sum subsegment despite having odd total ones? That would be contradictory because if total ones odd, there is at least one 1, and that 1 alone is an odd-sum subsegment. So impossible.
Thus answer stands.
Given that, solution is extremely simple.
But wait, what about the possibility that the first player might be forced to remove a subsegment that results in the array being such that the second player can now remove a subsegment that makes the array empty? We already argued cannot because total ones odd prevents second from removing whole array. However, could second remove a subsegment that results in the array being empty because the removed part is the whole array? That requires the whole array sum even. But whole array sum is odd, so cannot.
Thus, done.
I'll now write up the solution: Read n, read array, check if any number is odd. If yes, print "First", else "Second".
But we should also consider that n can be up to 1e6, reading with fast I/O.
Edge case: n=0? Not allowed; n>=1.
Now, just to be absolutely thorough, let's test some random arrays via mental simulation with small n exhaustive to see if any counterexample exists.
We can brute force small n with all binary strings (0/1) and simulate the game with optimal play to verify the condition. Let's do mental for n=1,2,3.
n=1:
- [0]: First cannot move => loses => Second wins. Condition: no odd => Second wins.
- [1]: First can move => wins => Condition: has odd => First wins.
n=2:
All possibilities (b0,b1):
[0,0]: no odd => Second wins.
[0,1]: has odd => First wins. Check: First can take whole (odd) => win.
[1,0]: has odd => First wins.
[1,1]: has odd? Both ones, so yes odd exists. But total ones even. According to condition, First wins. Sim: First can take one 1 leaving [1]; second loses. So wins.
All good.
n=3:
List all 8 binary strings:
000: no odd => Second wins.
001: has odd => First wins. (Can take whole? sum=1 odd => win)
010: has odd => First wins.
011: has odd => First wins. (total ones=2 even; first can remove one 1 leaving [0,1] or [1,0] etc; second loses)
100: has odd => First wins.
101: has odd => total ones=2 even? Actually 1+0+1=2 even, but odd numbers exist. Condition says First wins. Sim: first can remove first 1 -> [0,1] (ones=1) -> second can remove 0 -> [1] -> first wins. Or first can remove middle 0? Not allowed (even sum). So works.
110: has odd => first wins. (ones=2 even; first remove single 1 -> [1,0] -> second remove 0 -> [1] -> first wins)
111: has odd => first wins.
So all consistent.
Thus condition holds for n up to 3.
n=4: Let's test a tricky case: [0,0,0,0] no odd => second wins. [0,0,0,1] odd => first wins (can take whole? sum=1 odd => win). [0,0,1,1] odd => first wins (we already did). [0,1,0,1] odd => first wins. [0,1,1,0] odd => first wins. [1,0,0,0] odd => first wins. [1,0,0,1] odd => first wins. [1,0,1,0] odd => first wins. [1,1,0,0] odd => first wins. [1,1,1,1] odd => first wins. All good.
Thus seems correct.
One more nuance: Could the first player be forced to lose if there is at least one odd but the array is such that any odd-sum subsegment removal leads to a state where second can win? According to our parity argument, after first's move, second's turn has odd total ones. We claimed that from such state, the player whose turn it is (second) loses. But we must verify that claim by analyzing the state from second's perspective with odd total ones. Let's try to prove that the player to move on a state with odd total ones loses (assuming optimal play). We attempted to argue that the player to move (second) cannot win because the opponent (first) can always take all on next turn. But that is only if the current player cannot end the game immediately. But maybe the current player could have a move that results in the opponent having no move, i.e., leaving an array with no odd-sum subsegment for the opponent. That would require leaving an array with no 1s. As argued, to leave no 1s, the current player must remove all 1s, which requires removing a segment with even sum containing all 1s, but total ones is odd, so impossible. So cannot leave no 1s. Could the current player leave an array where there is at least one 1, but the opponent still cannot move? That would require that there is no odd-sum subsegment. But if there is at least one 1, a subsegment consisting of that 1 alone is odd-sum. So opponent can always move. So indeed, the opponent will always have a move. So the current player cannot force a win in one move. But could the current player force a win in more than one move? That would require that after his move, the opponent is in a losing position (i.e., a position from which, even with optimal play, the opponent loses). So we need to analyze whether a position with odd total ones is a losing position for the player to move. We argued it's losing because the opponent can immediately win by taking all. However, is it always optimal for the opponent to take all? If the opponent takes all, he wins. So that's a winning move. So the opponent has a winning move. Therefore the current player is in a losing position. So indeed, any state where it's your turn and total ones is odd is a losing position (since the opponent can take all and win). But wait, could the opponent have a better move than taking all? It doesn't matter; as long as there exists at least one winning move, the position is winning for the opponent. So from the perspective of the player to move, it's losing because no matter what he does, the opponent can force a win. But we need to confirm that from the odd total ones state, the player to move has no move that leads to a position that is losing for the opponent. But we already argued that all moves by the player lead to states where total ones remains odd (since odd - even = odd). Those states are also states where it's opponent's turn and total ones odd. If we can prove that any state with odd total ones is a losing position for the player to move, then by induction, after second's move, it's first's turn with odd total ones, which would be a losing position for first. That would contradict our claim that first can win by taking all. Wait, careful: We need to assign which player is which. The losing/winning status depends on the player to move. Let's define position P = (array, player), where player is either 1 (first) or 2 (second). But the moves available differ. So we cannot just say "odd total ones is losing for player to move" without considering which player. Because the moves differ. For example, consider a state where it's second's turn and total ones is odd. According to our earlier reasoning, second cannot win because first can then take all and win. So second is in a losing position. So from second's perspective, odd total ones is losing.
Now consider a state where it's first's turn and total ones is odd. First can take all and win, so it's winning for first. So odd total ones is winning for first, but losing for second. So the parity alone doesn't determine outcome; it also depends on whose turn.
Thus our earlier statement: after first's move (from even total), we have second's turn with odd total ones, which is losing for second. So first wins.
Now, we need to ensure that from even total, first's move always leads to second's turn with odd total ones. That is true because first removes an odd number of ones. So indeed.
Thus, the only potential pitfall is if first cannot remove an odd number of ones? But as long as there is at least one 1, he can remove a single 1, which removes exactly 1 (odd) one. So possible. Could there be a scenario where removing a single 1 is not allowed because the segment must be contiguous? It is contiguous. So yes.
But wait, what if the array contains 1s, but they are not isolated? Still fine.
Thus, answer stands.
But I recall a problem with similar description: "Leha and another game about array" maybe from Codeforces Round #429? Actually there is a problem "Leha and another game about array" where the answer is about parity of sum, but I'm not 100% sure. Let's search memory: I think there is a problem "Leha and Another Game About Graph" but not this.
Let's try to see if there is any hidden twist: The players remove subsegments, and after removal, the remaining parts are glued. This could create new subsegments that were not originally contiguous. But does that affect the parity of total ones? No, the total number of ones just reduces by the number of ones removed. The arrangement after gluing is just the concatenation of the left and right parts; it's still a sequence. The property of having at least one 1 is preserved if any left.
But there might be a subtlety: When a player removes a subsegment, they might affect the contiguity of the remaining ones. For the next player's move, they need to find a contiguous subsegment in the glued array. Could it be that even though total ones is odd, there might be no contiguous subsegment with odd sum? As argued, if there is at least one 1, that single 1 is a contiguous subsegment. However, after gluing, if the 1 is at the boundary, it's fine. But what if the array is such that there is a 1, but it's not alone; it's part of a block. Still, the subsegment consisting of that single element is contiguous. So always available.
Thus, no issue.
One more thought: What about the scenario where first removes a subsegment that is not a single 1, but something else, and the resulting array might have no 1s? That would require that he removed all ones. But since initial total ones even, to remove all ones he would need to remove an even number of ones, which would be an even sum removal. But he can only remove odd-sum. So cannot remove all ones. So after his move, at least one 1 remains.
Thus, first always wins when at least one odd exists.
Therefore, the solution is trivial.
Given the constraints, maybe the problem originally had a different twist, but as written, it's this.
I'll now produce final answer: If any ai is odd, print "First"; else "Second".
But wait, is there any scenario where the first player might have a move but still lose because the second player can force a win later? Let's try to construct a longer game tree to see if second could ever win from odd total ones turn. Suppose it's second's turn with odd total ones. Could second make a move that results in a position that is winning for him? That would require that after his move, it's first's turn with a losing position for first. So we need to find a state where it's first's turn and first loses (i.e., first cannot move). That state would have no 1s. So second would need to remove all 1s. But as argued, total ones odd, so cannot remove all because that would be odd sum. Could second remove a segment that leaves an array that still has 1s but first cannot move? That's impossible as argued. So second cannot force a win.
But could second force a draw? No draws; someone loses.
Thus, indeed.
Therefore, answer stands.
I'll now write solution in Python: read input, check any odd.
Implementation:
def solve():
import sys
data = sys.stdin.read().split()
if not data: return
n = int(data[0])
arr = list(map(int, data[1:1+n]))
for x in arr:
if x & 1:
print("First")
return
print("Second")
Complexity O(n).
Now, is there any scenario where n is large and we need to handle 1e6 quickly? Yes, but Python can handle.
Double-check: Input format: first line n, next line n integers. Could be multiple lines? Using sys.stdin.read() splits all.
Edge case: n=0? Not allowed.
Thus final.
But wait, there is also a possibility: The array might have an odd number but all odd numbers are in a configuration where any odd-sum subsegment removal results in an array that has no odd numbers? That would require that the removed subsegment contains all odd numbers, and after removal, only evens remain. But if total number of odd numbers is odd, then removing all of them would be an odd sum removal (since odd count of odds). That's allowed for first. So first could just remove all odds (the whole array if only odds, or a segment covering all odds). But is it always possible to remove all odds with a contiguous segment? The odds might not be contiguous; the segment from the leftmost odd to the rightmost odd will contain all odds (and possibly some evens in between). That segment will have sum equal to the number of odds (mod 2) which is odd if the count of odds is odd. So if total odds is odd, first can remove that segment, leaving only evens (if any outside). Then the remaining array (evens only) has no odds, so second's turn with no odds: second can move? Second can remove evens (even sum), so he can move. After his move, the array still evens, then first's turn with evens only, first cannot move and loses. So wait! This suggests that if total odds is odd, first might not necessarily win by taking whole array? Let's analyze carefully.
In our earlier reasoning, we said if total ones odd, first can take whole array and win. But taking whole array removes everything, leaving empty. That is a valid move because the whole array sum is odd. So after first takes whole array, there is no array left; second's turn on empty, second cannot move, so second loses. So that's a win for first. So first would always choose to take whole array rather than just the segment covering all odds leaving some evens behind. So first would not choose a move that leaves evens for second, because that could potentially allow second to move and maybe cause first to lose. Instead, first can win immediately by taking the entire array. So the optimal move is to take whole array. So first wins.
But what if the whole array sum is even? That's the case we already considered; then first cannot take whole. So the scenario where total odds odd but whole array sum even? Impossible: whole array sum parity is parity of total odds. So if total odds odd, whole array sum is odd. So first can always take whole and win. So fine.
Thus, the only case where first cannot take whole is when total odds even.
Now, from even total odds, after first's move, second's turn with odd total odds, and we argued second loses because first will take whole on next turn. But wait: after first's move, the remaining array has odd total odds. So on second's turn, can second take the whole remaining array? That would be an even-sum move? Whole remaining array sum is odd (since total odds odd). So second cannot take whole because he needs even sum. So second cannot win immediately. But could second make a move that results in a position where first cannot win? For first to win on his next turn, he would take whole (if it's odd). But could second remove a segment such that the remaining array still has odd total odds but the whole array is not a valid move for first? That doesn't make sense: if total odds odd, whole array sum odd, so it's a valid move for first. So first can always win by taking whole. So second cannot prevent that.
But what if after second's move, the array becomes empty? That would require second to take whole array, which is not allowed. So no.
Thus, second cannot avoid first's win.
Therefore, first always wins if there is at least one odd.
Wait, but what about the scenario where after first's move, the remaining array has odd total odds, and then second makes a move that does not change the odd parity, and then first takes whole. That's a win for first.
So the only losing case for first is when there are no odds at all.
Thus, solution stands.
However, there is one more nuance: The first player can only remove subsegments with odd sum. In the case where there is at least one odd, but the whole array sum is odd, he can remove the whole array and win. So that's straightforward.
Thus, the answer is indeed simple.
But is there any scenario where the whole array sum is odd, but the first player cannot remove the whole array because the whole array is not a "subsegment"? It is a subsegment (the entire array). So yes.
Thus, done.
I'll finalize.
But wait, I recall a problem "Leha and another game about array" from Codeforces Round #429 (Div. 2) problem C? Actually problem "Leha and Another Game about Graph" is different. There is also a problem "Leha and Function" etc. Let's search memory: I think there is a problem "Leha and another game about arrays" from Codeforces 794B? Not sure. But I'm slightly suspicious because the solution seems too trivial for a problem that expects up to 1e6 input. Usually they'd have a more interesting twist. But sometimes they do.
Let's consider if the players could also remove subsegments of length >0 with the required parity, but after removal, the remaining parts are glued. Could there be a situation where first's move is forced to be something that leads to second being able to remove an even-sum segment that includes all remaining ones? But as argued, second can only remove even number of ones. If after first's move, total ones is odd, second cannot remove all ones because that would be odd. So he cannot remove all ones.
But could second remove a segment that includes all ones except one, leaving exactly one 1, and then first can take that 1? That's a win for first anyway.
All good.
Let's also consider the possibility that the first player might be forced to make a move that results in the array having no odd-sum subsegments for the second player? That doesn't matter; second's move requires even sum. He could still have moves even if there are zeros.
But the only losing condition for second is when he has no move. That occurs only if the array is [1] (single 1) or empty? Actually for second, he needs an even-sum subsegment. Could there be a scenario where the array has odd total ones, but second still has no move? Let's analyze. Second needs a contiguous subsegment with even sum. Does an array with odd total ones always have an even-sum subsegment? Not necessarily. Consider array = [1] (odd total ones) -> no even-sum subsegment. So second loses immediately. That's a losing position for second. So if after first's move, the array is [1], second loses immediately, which is good for first.
What about array = [1,0]? total ones=1 odd. Does second have an even-sum subsegment? Yes: the single 0 is even sum. So he has moves.
What about array = [1,1,1]? total ones=3 odd. Even-sum subsegment exists: e.g., two adjacent 1s sum 2 even. So yes.
What about array = [1,0,0]? even-sum exists: single 0.
It seems the only case where second has no move with odd total ones is the single 1. Also maybe [1,0,0,0,...] always have a zero. So generally, after first's move, second will likely have a move unless the resulting array is exactly [1]. But that's fine because second loses immediately.
Thus, all good.
Therefore, final answer: First if any odd, else Second.
Now, I'll produce final solution in Python.
But wait, one more thought: Could the first player be forced to lose if there is an odd but the array is such that every odd-sum subsegment removal leads to a state where second can force a win? According to our analysis, from any state where it's second's turn with odd total ones, second loses. So no.
Thus, done.
Time to write final answer.
But perhaps the problem originally had the rule that the subsegment must have a sum of numbers (not parity) exactly odd or even, but that's what we used. Yes.
Thus, I'll answer.
But let me double-check the problem statement: "The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move."
Yes.
Thus, answer.
Now I'll craft final solution. ```python
import sys
def solve() -> None:
data = sys.stdin.buffer.read().split()
if not data:
return
n = int(data[0])
# Check if any number is odd
for i in range(1, n + 1):
if int(data[i]) & 1:
print("First")
return
print("Second")
if name == "main":
solve()