LOOP_COUNT = 1_000_000
EXPECTED_CHECKSUM = 3_500_013

LIVE_STATE = {"tag": "live", "payload": {"digits": [2, 7, 1, 8, 2, 8, 1, 8]}}
CACHED_STATE = {"tag": "cached", "payload": {"digits": [1, 6, 1, 8, 0, 3, 4, 5]}}


def configured_loop_count() -> int:
    try:
        value = int(input().strip())
    except (EOFError, ValueError):
        return LOOP_COUNT

    return value if value > 0 else LOOP_COUNT


def select_state(i: int) -> dict[str, object]:
    return LIVE_STATE if i % 2 == 0 else CACHED_STATE


def state_digit(state: dict[str, object], index: int) -> int:
    if state["tag"] == "missing":
        return 0
    payload = state["payload"]
    assert isinstance(payload, dict)
    digits = payload["digits"]
    assert isinstance(digits, list)
    return digits[index]


def enum_struct_payload_loop(limit: int) -> int:
    i = 0
    acc = 13

    while i < limit:
        acc += state_digit(select_state(i), i % 8)
        acc = acc - 1_000_000_000 if acc > 1_000_000_000 else acc
        i += 1

    return acc


def main() -> int:
    result = enum_struct_payload_loop(configured_loop_count())
    print(result)
    return 0 if result == EXPECTED_CHECKSUM else 1


if __name__ == "__main__":
    raise SystemExit(main())
