#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LOOP_COUNT 1000000
#define EXPECTED_CHECKSUM 4600001

typedef struct {
    int32_t len;
    const char **data;
} vec_string;

static int32_t configured_loop_count(void) {
    int32_t value = LOOP_COUNT;
    if (scanf("%d", &value) != 1 || value <= 0) {
        return LOOP_COUNT;
    }
    return value;
}

static const char *configured_target(int argc, char **argv) {
    return argc > 1 ? argv[1] : "omega";
}

static vec_string make_words(void) {
    vec_string values;
    values.len = 5;
    values.data = malloc(sizeof(char *) * (size_t)values.len);
    if (values.data == NULL) {
        fputs("allocation failed\n", stderr);
        exit(2);
    }

    values.data[0] = "alpha";
    values.data[1] = "omega";
    values.data[2] = "delta";
    values.data[3] = "omega";
    values.data[4] = "sigma";
    return values;
}

static int32_t vec_string_eq_loop(int32_t limit, const char *target) {
    vec_string words = make_words();
    int32_t i = 0;
    int32_t acc = 1;

    while (i < limit) {
        const char *current = words.data[i % words.len];
        acc = strcmp(current, target) == 0 ? acc + 7 : acc + 3;
        acc = acc > 1000000000 ? acc - 1000000000 : acc;
        i = i + 1;
    }

    free(words.data);
    return acc;
}

int main(int argc, char **argv) {
    int32_t result = vec_string_eq_loop(configured_loop_count(), configured_target(argc, argv));
    printf("%d\n", result);
    return result == EXPECTED_CHECKSUM ? 0 : 1;
}
