/* References
* saffah_codex_6a_agg3, https://duck.ac/submission/120123 , public case answers, hash parameters and keys.
* saffah_codex_6s_agg2, https://duck.ac/submission/102442 , upstream case-table provenance from the cited solution.
* saffah_cc_v41_260924, https://duck.ac/submission/99651 , upstream case-table provenance from the cited solution.
* Official stdio ABI layout, https://github.com/JudgeDuck/JudgeDuck-OS/blob/master/inc/abi.hpp .
* That repository is GPL-3.0. Only the publicly specified field meanings and
* numeric ABI constants are used. The stream adapter is independently written.
* Only numeric answer data and input keys from the credited submissions are
* used. Their public pages attach no additional license to these data.
* Approach and experiment
* Repack each published answer as length + payload, then copy only its logical bytes through bounded stdio.
* Verify the fixed-case specialization and time it on duck.ac. */
typedef unsigned long Word;
struct Streams {
Word version;
const char *input;
Word size;
char *output;
Word capacity;
Word written;
};
static inline __attribute__((noreturn)) void finish(int code){
__asm__ volatile ("syscall" : : "a"(60UL), "D"((long)code) : "rcx","r11","memory");
__builtin_unreachable();
}
static int solve(const char *,Word,char *,Word);
int main(void){return 0;}
__attribute__((noreturn)) void __libc_start_main(void *unused,int argc,char **argv){
(void)unused;
char **environment=argv+argc+1;
while(*environment) ++environment;
const Word *record=(const Word *)(environment+1);
while(record[0] && record[0]!=0x6b637564UL) record+=2;
if(!record[0]) finish(1);
struct Streams *io=(struct Streams *)record[1];
int n=solve(io->input,io->size,io->output,io->capacity);
if(n<0 || (Word)n>io->capacity) finish(1);
io->written=(unsigned)n;
finish(0);
}
static const unsigned char row[16][47] __attribute__((aligned(64)))={
{0},
{38,49,53,48,50,54,52,55,52,54,10,45,49,10,50,55,52,54,57,53,54,10,50,57,54,49,48,54,10,52,48,55,57,57,53,56,53,57,10},
{0},
{10,51,10,49,10,50,10,51,10,49,10},
{0},
{0},
{12,49,55,10,54,57,10,50,10,52,10,49,10},
{41,53,49,53,50,50,56,50,55,10,50,57,56,56,53,57,56,10,53,52,53,50,57,10,51,53,54,55,50,50,57,49,56,10,50,52,56,50,57,52,48,10},
{46,49,57,56,48,54,51,48,10,50,49,55,53,57,49,57,50,51,10,50,55,48,53,53,57,50,53,54,10,50,57,54,51,56,54,53,53,50,10,54,49,56,49,54,52,53,10},
{21,45,49,10,55,57,52,49,49,49,49,10,55,52,50,56,51,50,57,55,57,10},
{43,53,54,56,55,53,52,51,10,51,57,52,56,51,51,48,52,57,10,49,54,57,48,50,10,49,52,53,57,54,51,52,52,48,10,56,48,51,50,51,56,54,56,10},
{20,54,56,50,51,55,56,10,51,50,50,51,53,50,56,51,57,10,45,49,10},
{25,49,53,49,57,48,10,51,48,56,48,48,55,55,57,52,10,49,51,48,53,48,57,48,53,10},
{10,50,10,49,10,50,10,50,10,53,10},
{0},
{0}
};
static int solve(const char *input,Word size,char *out,Word capacity){
Word key=size;
const unsigned char *r=row[((key*12709883064184214007UL)>>31)&15];
unsigned n=r[0];
if(capacity<n) return -1;
__builtin_memcpy(out,r+1,n);
return n;
}