Greedy logical approach with detailed explanation
\n/*\n\n    the first player will always chose the number which gives a remainder > 0\n    now whenever a player is playing, he should pick up some number such 
```\n/*\n\n    the first player will always chose the number which gives a remainder > 0\n    now whenever a player is playing, he should pick up some number such that the resultant sum is not divisible by 3\n    there are a couple of cases\n    1) the remainder of the sum of values picked up till now is 1\n    2) the remainder of the sum of values picked up till now is 2\n    \n    it cannot be zero, because when it becomes zero the game ends\n    \n    in case 1 : the currrent player can only pick up some number which gives a remainder 1 or remainder 0\n    in case 2 : the current player  can only pick up some number which gives a remainder 2 or 0\n    \n    see that 0 is useful in both cases, no we will avoid using 0 as much as possible\n    means in case1, we will try to pick up guy with remainder 1, if it is not availble, we go for 0\n    if both are not available the current player loses\n    \n    similarly in case2 we will try to pick up the one with remainder 2, if not availble, we are forced to look for 0\n    if both are not available, the current player loses\n    \n*/\nclass Solution {\npublic:\n    \n    int f(int rem, vector<int> remCnt) {\n        int turn = 1;\n        \n        while(remCnt[0] + remCnt[1] + remCnt[2] > 0) {\n            \n            if(rem == 1) {\n                if(remCnt[1]) {\n                    remCnt[1]--;\n                    rem = 2;\n                }\n                else if(remCnt[0]) {\n                    remCnt[0]--;\n                    rem = 1;\n                }\n                else return turn != 0;\n            } else {\n                // when rem == 2;\n                if(remCnt[2]) {\n                    remCnt[2]--;\n                    rem = 1;\n                } else if(remCnt[0]) {\n                    remCnt[0]--;\n                    rem = 2;\n                } else return turn != 0;\n            }\n            \n            turn = 1 - turn;\n        }\n        \n        return false;\n    }\n    \n    bool stoneGameIX(vector<int>& a) {\n        int n = a.size();\n        int turn = 1;\n        \n        \n        vector<int> remCnt(3, 0);\n        for(int x : a) remCnt[x%3]++;\n        \n        bool ans = false;\n        if(remCnt[1] == 0  && remCnt[2] == 0) return false;\n        if(remCnt[1]) {\n            // player 0 starting off with 1\n            remCnt[1]--;\n            ans = ans  or f(1, remCnt);\n            remCnt[1]++;\n        }\n        if(remCnt[2]) {\n            // player 0 starting off with 2\n            remCnt[2]--;\n            ans = ans or f(2, remCnt);\n            remCnt[2]++;\n        }\n        \n        \n        return ans;\n    }\n};\n\n```
['Greedy']