greedy solution
a[3] denote frequency of remainder of 3\nAlice start with either stone a[1] or a[2]\nif a[0] is even then it doesn\'t effect anythink as they both take equal no
a[3] denote frequency of remainder of 3\nAlice start with either stone a[1] or a[2]\nif a[0] is even then it doesn\'t effect anythink as they both take equal no. of stone from a[0].\nif a[0] is odd it will change turn.\n```\neg. [1,1,3,1..] \nalice pick 1\nif bob pick 3\nagain alice has to pick.\n\neg.[1,1,3,3....]\nalice pick 1\nif bob pick 3 then alice will also pick 3\nso bob has to pick now with same remainder\n```\nwhen a[0] is odd then game is in alice hand if the diff of stone in a[1] and a[2] is more than 2. \nas she will start with a[1] if this is more\nelse start with a[2]\nif diff is less then she loss because of no stone left to play.\n\nwhen a[0] is even \nshe will start a[1] if it is less\nelse she will start with a[2]\nbut if any of them is zero she will loss.\n\n```\nclass Solution {\npublic:\n    bool stoneGameIX(vector<int>& s) {\n        int n = s.size();\n        if(n == 1) return 0;\n        int a[3] = {0};\n        for(int& x : s){\n            a[x%3]++;\n        }\n        if(a[0] & 1) {\n            if(abs(a[1]-a[2]) > 2) return 1;\n            else return 0;\n        }\n        else {\n            if(a[1] == 0 || a[2] == 0) return 0;\n            else return 1;\n        }\n    }\n};\n```\nupvote if this helps
[]