#include <stdio.h>
typedef void (*Handler)(void);

// microcontroller commands
void BlueOn(void)  { printf ("Включаем синий. "); }
void BlueOff(void) { printf ("Выключаем синий. "); }
void RedOn(void)   { printf ("Включаем красный. "); }
void RedOff(void)  { printf ("Выключаем красный. "); }

// handlers for the signals
void BlueOnRedOn(void) { BlueOn(); RedOn(); }
void BlueOnRedNone(void) { BlueOn(); }
void BlueOnRedOff(void) { BlueOn(); RedOff(); }
void BlueNoneRedOn(void) { RedOn(); }
void BlueNoneRedOff(void) { RedOff(); }
void BlueOffRedOn(void) { BlueOff(); RedOn(); }
void BlueOffRedNone(void) { BlueOff(); }
void BlueOffRedOff(void) { BlueOff(); RedOff(); }

// jump table
Handler bothOff[4] = { 0, BlueOnRedNone, BlueNoneRedOn, BlueOnRedOn };
Handler blueOn[4] = { BlueOffRedNone, 0, BlueOffRedOn, BlueNoneRedOn };
Handler redOn[4] = { BlueNoneRedOff, BlueOnRedOff, 0, BlueOnRedNone };
Handler bothOn[4] = { BlueOffRedOff, BlueNoneRedOff, BlueOffRedNone, 0 };
Handler* handlers[4] = { bothOff, blueOn, redOn, bothOn };

int main(void) {
    Handler* current = bothOff;
    for(int n;;) {
        scanf("%d", &n); // signal from microcontroller
        if(n < 0 || n > 3) break;
        if(current[n]) {
            current[n]();
            current = handlers[n];
        }
        printf("Готово!\n");
    }
    return 0;
}
