typedef uint8_t card_t;


unsigned int rand_n(unsigned int n) {
    unsigned int out, mask = 1;
    
    while (mask < n) mask = mask<<1 | 1;
    
    do {
        out = rand() & mask;
    } while (out >= n);
    return out;
}


card_t rand_card() {
    return rand_n(52);
}


void print_card(card_t card) {
    static char *suits = ; 
    static char *cards[] = {,,,,,,,,,,,,};
    printf(, cards[card>>2], suits[card&3]);
}


void shuffle(card_t *pack) {
    int card;
    card_t temp, randpos;
    for (card=0; card<52; card++) {
        randpos = rand_card();
        temp = pack[card];
        pack[card] = pack[randpos];
        pack[randpos] = temp;
    }
}


int trick() {
    card_t pack[52];
    card_t blacks[52/4], reds[52/4];
    card_t top, x, card;
    int blackn=0, redn=0, blacksw=0, redsw=0, result;

    
    for (card=0; card<52; card++) pack[card] = card;
    shuffle(pack);

    

    printf(); 

    for (card=0; card<52; card += 2) {
        top = pack[card]; 
        if (top & 1) { 
            blacks[blackn++] = pack[card+1];
        } else {
            reds[redn++] = pack[card+1];
        }

        print_card(top); 

    }

    printf();


    
    x = rand_n(min(blackn, redn));
    for (card=0; card<x; card++) {
        
        blacksw = rand_n(blackn);
        redsw = rand_n(redn); 
        
        top = blacks[blacksw];
        blacks[blacksw] = reds[redsw];
        reds[redsw] = top;
    }

    
    result = 0;
    for (card=0; card<blackn; card++)
        result += (blacks[card] & 1) == 1;
    for (card=0; card<redn; card++)
        result -= (reds[card] & 1) == 0;
    result = !result;

    printf(
           ,
           result?  : );
    return result;
}

int main() {
    unsigned int seed, i, successes = 0;
    FILE *r;

    
    if ((r = fopen(, )) == NULL) {
        fprintf(stderr, );
        return 255;
    }
    if (fread(&seed, sizeof(unsigned int), 1, r) != 1) {
        fprintf(stderr, );
        return 255;
    }
    fclose(r);
    srand(seed);

    
    for (i=1; i<=SIM_N; i++) {
        printf(, i);
        successes += trick();
        printf();
    }

    printf(,
        successes, SIM_N);

    return 0;
}