```
public static int getNextGrayCode(int num, boolean direction) {
    if (direction) {
        return num ^ (num >> 1);
    } else {
        int mask = num;
        while ((mask & 1) == 0) {
            mask >>= 1;
        }
        return num ^ mask | (mask >> 1);
    }
}
```
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence