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

typedef struct {
    const char *object;
    const char *last_seen;
    const char *instruction;
} Ticket;

static const Ticket tickets[] = {
    {"A paperclip with an important expression", "inside the manual nobody opened", "Do not promise it a promotion."},
    {"One good intention, flattened", "under a receipt from last Tuesday", "Return without polishing."},
    {"The other glove's biography", "between the radiator and its alibi", "Read before pairing."},
    {"A spare button", "in the pocket of a coat that forgave winter", "Keep as evidence of future seams."}
};

static void print_rule(void) {
    puts("+--------------------------------------------------------+");
}

static void print_ticket(const Ticket *ticket, size_t number) {
    print_rule();
    puts("| LOST & FOUND / RECEIPT FOR AN ABSENCE                 |");
    print_rule();
    printf("| Ticket: %02zu                                              |\n", number + 1);
    printf("| Object: %-47s |\n", ticket->object);
    printf("| Last seen: %-44s |\n", ticket->last_seen);
    print_rule();
    printf("| Clerk's note: %-40s |\n", ticket->instruction);
    puts("| Status: NOT MISSING TO ITSELF                            |");
    print_rule();
}

int main(int argc, char **argv) {
    size_t index = 0;
    size_t count = sizeof tickets / sizeof tickets[0];

    if (argc == 3 && argv[1][0] == '-' && argv[1][1] == 'n' && argv[1][2] == '\0') {
        long requested = strtol(argv[2], NULL, 10);
        if (requested < 1 || (size_t)requested > count) {
            fprintf(stderr, "Ticket number must be between 1 and %zu.\n", count);
            return 1;
        }
        index = (size_t)requested - 1;
    } else if (argc != 1) {
        fprintf(stderr, "Usage: %s [-n 1..%zu]\n", argv[0], count);
        return 1;
    }

    print_ticket(&tickets[index], index);
    return 0;
}
