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

#define LOOP_COUNT 1000000
#define EXPECTED_CHECKSUM 3500013

typedef struct {
    int32_t digits[8];
} Packet;

typedef enum {
    PACKET_MISSING = 0,
    PACKET_LIVE = 1,
    PACKET_CACHED = 2,
} PacketTag;

typedef struct {
    PacketTag tag;
    Packet payload;
} PacketState;

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 PacketState live_state(void) {
    PacketState state = {PACKET_LIVE, {{2, 7, 1, 8, 2, 8, 1, 8}}};
    return state;
}

static PacketState cached_state(void) {
    PacketState state = {PACKET_CACHED, {{1, 6, 1, 8, 0, 3, 4, 5}}};
    return state;
}

static PacketState select_state(int32_t i, PacketState live, PacketState cached) {
    return i % 2 == 0 ? live : cached;
}

static int32_t state_digit(PacketState state, int32_t index) {
    switch (state.tag) {
    case PACKET_LIVE:
    case PACKET_CACHED:
        return state.payload.digits[index];
    case PACKET_MISSING:
    default:
        return 0;
    }
}

static int32_t enum_struct_payload_loop(int32_t limit) {
    PacketState live = live_state();
    PacketState cached = cached_state();
    int32_t i = 0;
    int32_t acc = 13;

    while (i < limit) {
        PacketState state = select_state(i, live, cached);
        acc = acc + state_digit(state, i % 8);
        acc = acc > 1000000000 ? acc - 1000000000 : acc;
        i = i + 1;
    }

    return acc;
}

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