Alice and Bob are playing the following game:
a word is written on paper in front of the players
in one move, a player can erase one letter, or two identical letters, or, all letters of the same type
players take turns
Alice is the first to start
it is the player, who erases the last letter, that wins.
Write a program that will determine the winner of the described above game for a given word (given that the players play optimally (successfully).
Input
The input contains a single line — the starting word. The word consists of capital Latin letters, and its length does not exceed 40 characters.
Output
Type “Alice” (without quotes) if Alice wins, or “Bob” (without quotes) if Bob wins.
Examples
Input
ZADACHA
Output
Alice
Input
WORD
Output
Bob
Note
For example, in the word “ZADACHA”, Alice erases all the letters “A” by her first move. The word “Z.D.CH.” remains, and she wins because, in subsequent moves, the players are forced to erase only one letter at a time.
#include <bits/stdc++.h>
using namespace std;
int dp[50];
int a[26];
set<int> s;
string ch;
int main()
{
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= 40; i++)
{
s.clear();
s.insert(0);
if (i > 1) s.insert(dp[i - 1]);
if (i > 2) s.insert(dp[i - 2]);
int k = 0;
for (; s.find(k) != s.end(); k++);
dp[i] = k;
}
cin >> ch;
int n = ch.length();
for (int i = 0; i < n; i++)
{
a[ch[i] - 'A']++;
}
int flag = 0;
for (int i = 0; i < 26; i++)
{
flag ^= dp[a[i]];
}
if (flag)
puts("Alice");
else
puts("Bob");
}