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

#define LOOP_COUNT 1000000
#define EXPECTED_CHECKSUM 3875007

typedef struct {
    int32_t len;
    int32_t *data;
} vec_i32;

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 vec_i32 make_digits(void) {
    vec_i32 values;
    values.len = 8;
    values.data = malloc(sizeof(int32_t) * (size_t)values.len);
    if (values.data == NULL) {
        fputs("allocation failed\n", stderr);
        exit(2);
    }

    values.data[0] = 3;
    values.data[1] = 1;
    values.data[2] = 4;
    values.data[3] = 1;
    values.data[4] = 5;
    values.data[5] = 9;
    values.data[6] = 2;
    values.data[7] = 6;
    return values;
}

static int32_t vec_i32_index_loop(int32_t limit) {
    vec_i32 digits = make_digits();
    int32_t i = 0;
    int32_t acc = 7;

    while (i < limit) {
        acc = acc + digits.data[i % digits.len];
        acc = acc > 1000000000 ? acc - 1000000000 : acc;
        i = i + 1;
    }

    free(digits.data);
    return acc;
}

int main(void) {
    int32_t result = vec_i32_index_loop(configured_loop_count());
    printf("%d\n", result);
    return result == EXPECTED_CHECKSUM ? 0 : 1;
}
