Array Game

All submissions for this problem are available.
Problem description.
2 players A and B are playing a game taking turns alternatively.They are given an array of 'N' numbers : X[1],X[2].....X[N] ..
During each turn , the player selects an index 'i' <= (N/2) such that X[i] > 0 ,
subtracts 1 from X[i] and adds 1 to either X[2*i],X[3*i] or X[5*i] ( Obviously the index to which the player is adding should be less than or equal to N ) .
Player A starts the game and makes the first move.The player who can't make a move loses the game.
Both the players are playing optimally. Determine the winner of this game.
Input
Input description.
 The first line of the input contains an integer N
 Next line contains N integers X[1],X[2], ..... X[N]
Output
Output description.
 Output a single line containing the winner : "A" or "B".
Constraints
 1 ≤ N ≤ 100000
 0 ≤ X[1],X[2].....X[N] ≤ 1000000000
Example 1
Input: 5
0 0 1 0 0
Output: B
Example 2
Input: 5
0 1 0 0 0
Output: A
Explanation
Example case 1 : Player A can't make a move because X[1] = 0 and X[2] = 0.
Example case 2 : Player A has only 1 possible move ( X[2] = X[2]  1 , X[4] = X[4]+1). After that the array becomes : 0 0 0 1 0
Now B can't make a move and hence B loses. Note that when A selected index i = 2 , both i*3,i*5 were greater than N and hence only 1 move was possible.
Author:  kshitijbathla 
Tags  kshitijbathla 
Date Added:  8032016 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions