/* * copyright (c) 2004 Michael Niedermayer * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef BITSTREAM_H #define BITSTREAM_H #include #include //#include #include #include #include "ffmpeg_bswap.h" /* The following 2 defines are taken from libavutil/intreadwrite.h */ #define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \ (((const uint8_t*)(x))[1] << 16) | \ (((const uint8_t*)(x))[2] << 8) | \ ((const uint8_t*)(x))[3]) #define AV_WB32(p, d) do { \ ((uint8_t*)(p))[3] = (d); \ ((uint8_t*)(p))[2] = (d)>>8; \ ((uint8_t*)(p))[1] = (d)>>16; \ ((uint8_t*)(p))[0] = (d)>>24; } while(0) #if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER) # define ALT_BITSTREAM_READER #endif //#define ALT_BITSTREAM_WRITER //#define ALIGNED_BITSTREAM_WRITER #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) # if defined(ARCH_ARM) # define A32_BITSTREAM_READER # else # define ALT_BITSTREAM_READER //#define LIBMPEG2_BITSTREAM_READER //#define A32_BITSTREAM_READER # endif #endif extern const uint8_t ff_reverse[256]; #if defined(ARCH_X86) // avoid +32 for shift optimization (gcc should do that ...) static inline int32_t NEG_SSR32( int32_t a, int8_t s){ __asm__ ("sarl %1, %0\n\t" : "+r" (a) : "ic" ((uint8_t)(-s)) ); return a; } static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ __asm__ ("shrl %1, %0\n\t" : "+r" (a) : "ic" ((uint8_t)(-s)) ); return a; } #else # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) #endif /* bit output */ /* buf and buf_end must be present and used by every alternative writer. */ typedef struct PutBitContext { #ifdef ALT_BITSTREAM_WRITER uint8_t *buf, *buf_end; int index; #else uint32_t bit_buf; int bit_left; uint8_t *buf, *buf_ptr, *buf_end; #endif int size_in_bits; } PutBitContext; static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size) { if(buffer_size < 0) { buffer_size = 0; buffer = NULL; } s->size_in_bits= 8*buffer_size; s->buf = buffer; s->buf_end = s->buf + buffer_size; #ifdef ALT_BITSTREAM_WRITER s->index=0; ((uint32_t*)(s->buf))[0]=0; // memset(buffer, 0, buffer_size); #else s->buf_ptr = s->buf; s->bit_left=32; s->bit_buf=0; #endif } /* return the number of bits output */ static inline int put_bits_count(PutBitContext *s) { #ifdef ALT_BITSTREAM_WRITER return s->index; #else return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left; #endif } /* pad the end of the output stream with zeros */ static inline void flush_put_bits(PutBitContext *s) { #ifdef ALT_BITSTREAM_WRITER align_put_bits(s); #else #ifndef BITSTREAM_WRITER_LE s->bit_buf<<= s->bit_left; #endif while (s->bit_left < 32) { /* XXX: should test end of buffer */ #ifdef BITSTREAM_WRITER_LE *s->buf_ptr++=s->bit_buf; s->bit_buf>>=8; #else *s->buf_ptr++=s->bit_buf >> 24; s->bit_buf<<=8; #endif s->bit_left+=8; } s->bit_left=32; s->bit_buf=0; #endif } void align_put_bits(PutBitContext *s); void ff_put_string(PutBitContext * pbc, const char *s, int put_zero); void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length); /* bit input */ /* buffer, buffer_end and size_in_bits must be present and used by every reader */ typedef struct GetBitContext { const uint8_t *buffer, *buffer_end; #ifdef ALT_BITSTREAM_READER int index; #elif defined LIBMPEG2_BITSTREAM_READER uint8_t *buffer_ptr; uint32_t cache; int bit_count; #elif defined A32_BITSTREAM_READER uint32_t *buffer_ptr; uint32_t cache0; uint32_t cache1; int bit_count; #endif int size_in_bits; } GetBitContext; #define VLC_TYPE int16_t typedef struct VLC { int bits; VLC_TYPE (*table)[2]; ///< code, bits int table_size, table_allocated; } VLC; typedef struct RL_VLC_ELEM { int16_t level; int8_t len; uint8_t run; } RL_VLC_ELEM; #ifndef ALT_BITSTREAM_WRITER static inline void put_bits(PutBitContext *s, int n, unsigned int value) { unsigned int bit_buf; int bit_left; // printf("put_bits=%d %x\n", n, value); //assert(n == 32 || value < (1U << n)); bit_buf = s->bit_buf; bit_left = s->bit_left; // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf); /* XXX: optimize */ #ifdef BITSTREAM_WRITER_LE bit_buf |= value << (32 - bit_left); if (n >= bit_left) { #if !HAVE_FAST_UNALIGNED if (3 & (intptr_t) s->buf_ptr) { AV_WL32(s->buf_ptr, bit_buf); } else #endif *(uint32_t *)s->buf_ptr = le2me_32(bit_buf); s->buf_ptr+=4; bit_buf = (bit_left==32)?0:value >> bit_left; bit_left+=32; } bit_left-=n; #else if (n < bit_left) { bit_buf = (bit_buf<> (n - bit_left); #if !defined(HAVE_FAST_UNALIGNED) if (3 & (intptr_t) s->buf_ptr) { AV_WB32(s->buf_ptr, bit_buf); } else #endif *(uint32_t *)s->buf_ptr = be2me_32(bit_buf); //printf("bitbuf = %08x\n", bit_buf); s->buf_ptr+=4; bit_left+=32 - n; bit_buf = value; } #endif s->bit_buf = bit_buf; s->bit_left = bit_left; } #endif #ifdef ALT_BITSTREAM_WRITER static inline void put_bits(PutBitContext *s, int n, unsigned int value) { # ifdef ALIGNED_BITSTREAM_WRITER # if ARCH_X86 __asm__ volatile( "movl %0, %%ecx \n\t" "xorl %%eax, %%eax \n\t" "shrdl %%cl, %1, %%eax \n\t" "shrl %%cl, %1 \n\t" "movl %0, %%ecx \n\t" "shrl $3, %%ecx \n\t" "andl $0xFFFFFFFC, %%ecx \n\t" "bswapl %1 \n\t" "orl %1, (%2, %%ecx) \n\t" "bswapl %%eax \n\t" "addl %3, %0 \n\t" "movl %%eax, 4(%2, %%ecx) \n\t" : "=&r" (s->index), "=&r" (value) : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n)) : "%eax", "%ecx" ); # else int index= s->index; uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5); value<<= 32-n; ptr[0] |= be2me_32(value>>(index&31)); ptr[1] = be2me_32(value<<(32-(index&31))); //if(n>24) printf("%d %d\n", n, value); index+= n; s->index= index; # endif # else //ALIGNED_BITSTREAM_WRITER # if ARCH_X86 __asm__ volatile( "movl $7, %%ecx \n\t" "andl %0, %%ecx \n\t" "addl %3, %%ecx \n\t" "negl %%ecx \n\t" "shll %%cl, %1 \n\t" "bswapl %1 \n\t" "movl %0, %%ecx \n\t" "shrl $3, %%ecx \n\t" "orl %1, (%%ecx, %2) \n\t" "addl %3, %0 \n\t" "movl $0, 4(%%ecx, %2) \n\t" : "=&r" (s->index), "=&r" (value) : "r" (s->buf), "r" (n), "0" (s->index), "1" (value) : "%ecx" ); # else int index= s->index; uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3)); ptr[0] |= be2me_32(value<<(32-n-(index&7) )); ptr[1] = 0; //if(n>24) printf("%d %d\n", n, value); index+= n; s->index= index; # endif # endif //!ALIGNED_BITSTREAM_WRITER } #endif static inline void put_sbits(PutBitContext *pb, int bits, int32_t val) { //assert(bits >= 0 && bits <= 31); put_bits(pb, bits, val & ((1<buf + (s->index>>3); #else return s->buf_ptr; #endif } /** * * PutBitContext must be flushed & aligned to a byte boundary before calling this. */ static inline void skip_put_bytes(PutBitContext *s, int n){ //assert((put_bits_count(s)&7)==0); #ifdef ALT_BITSTREAM_WRITER FIXME may need some cleaning of the buffer s->index += n<<3; #else //assert(s->bit_left==32); s->buf_ptr += n; #endif } /** * Skips the given number of bits. * Must only be used if the actual values in the bitstream do not matter. */ static inline void skip_put_bits(PutBitContext *s, int n){ #ifdef ALT_BITSTREAM_WRITER s->index += n; #else s->bit_left -= n; s->buf_ptr-= s->bit_left>>5; s->bit_left &= 31; #endif } /** * Changes the end of the buffer. */ static inline void set_put_bits_buffer_size(PutBitContext *s, int size){ s->buf_end= s->buf + size; } /* Bitstream reader API docs: name arbitrary name which is used as prefix for the internal variables gb getbitcontext OPEN_READER(name, gb) loads gb into local variables CLOSE_READER(name, gb) stores local vars in gb UPDATE_CACHE(name, gb) refills the internal cache from the bitstream after this call at least MIN_CACHE_BITS will be available, GET_CACHE(name, gb) will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit) SHOW_UBITS(name, gb, num) will return the next num bits SHOW_SBITS(name, gb, num) will return the next num bits and do sign extension SKIP_BITS(name, gb, num) will skip over the next num bits note, this is equivalent to SKIP_CACHE; SKIP_COUNTER SKIP_CACHE(name, gb, num) will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER) SKIP_COUNTER(name, gb, num) will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS) LAST_SKIP_CACHE(name, gb, num) will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing LAST_SKIP_BITS(name, gb, num) is equivalent to SKIP_LAST_CACHE; SKIP_COUNTER for examples see get_bits, show_bits, skip_bits, get_vlc */ #ifdef ALT_BITSTREAM_READER # define MIN_CACHE_BITS 25 # define OPEN_READER(name, gb)\ int name##_index= (gb)->index;\ int name##_cache= 0;\ # define CLOSE_READER(name, gb)\ (gb)->index= name##_index;\ # ifdef ALT_BITSTREAM_READER_LE # define UPDATE_CACHE(name, gb)\ name##_cache= AV_RL32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\ # define SKIP_CACHE(name, gb, num)\ name##_cache >>= (num); # else # define UPDATE_CACHE(name, gb)\ name##_cache= AV_RB32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\ # define SKIP_CACHE(name, gb, num)\ name##_cache <<= (num); # endif // FIXME name? # define SKIP_COUNTER(name, gb, num)\ name##_index += (num);\ # define SKIP_BITS(name, gb, num)\ {\ SKIP_CACHE(name, gb, num)\ SKIP_COUNTER(name, gb, num)\ }\ # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) # define LAST_SKIP_CACHE(name, gb, num) ; # ifdef ALT_BITSTREAM_READER_LE # define SHOW_UBITS(name, gb, num)\ ((name##_cache) & (NEG_USR32(0xffffffff,num))) # define SHOW_SBITS(name, gb, num)\ NEG_SSR32((name##_cache)<<(32-(num)), num) # else # define SHOW_UBITS(name, gb, num)\ NEG_USR32(name##_cache, num) # define SHOW_SBITS(name, gb, num)\ NEG_SSR32(name##_cache, num) # endif # define GET_CACHE(name, gb)\ ((uint32_t)name##_cache) static inline int get_bits_count(GetBitContext *s){ return s->index; } static inline void skip_bits_long(GetBitContext *s, int n){ s->index += n; } #elif defined LIBMPEG2_BITSTREAM_READER //libmpeg2 like reader # define MIN_CACHE_BITS 17 # define OPEN_READER(name, gb)\ int name##_bit_count=(gb)->bit_count;\ int name##_cache= (gb)->cache;\ uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\ # define CLOSE_READER(name, gb)\ (gb)->bit_count= name##_bit_count;\ (gb)->cache= name##_cache;\ (gb)->buffer_ptr= name##_buffer_ptr;\ # define UPDATE_CACHE(name, gb)\ if(name##_bit_count >= 0){\ name##_cache+= AV_RB16(name##_buffer_ptr) << name##_bit_count; \ name##_buffer_ptr+=2;\ name##_bit_count-= 16;\ }\ # define SKIP_CACHE(name, gb, num)\ name##_cache <<= (num);\ # define SKIP_COUNTER(name, gb, num)\ name##_bit_count += (num);\ # define SKIP_BITS(name, gb, num)\ {\ SKIP_CACHE(name, gb, num)\ SKIP_COUNTER(name, gb, num)\ }\ # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num) # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num) # define SHOW_UBITS(name, gb, num)\ NEG_USR32(name##_cache, num) # define SHOW_SBITS(name, gb, num)\ NEG_SSR32(name##_cache, num) # define GET_CACHE(name, gb)\ ((uint32_t)name##_cache) static inline int get_bits_count(GetBitContext *s){ return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count; } static inline void skip_bits_long(GetBitContext *s, int n){ OPEN_READER(re, s) re_bit_count += n; re_buffer_ptr += 2*(re_bit_count>>4); re_bit_count &= 15; re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count); UPDATE_CACHE(re, s) CLOSE_READER(re, s) } #elif defined A32_BITSTREAM_READER # define MIN_CACHE_BITS 32 # define OPEN_READER(name, gb)\ int name##_bit_count=(gb)->bit_count;\ uint32_t name##_cache0= (gb)->cache0;\ uint32_t name##_cache1= (gb)->cache1;\ uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\ # define CLOSE_READER(name, gb)\ (gb)->bit_count= name##_bit_count;\ (gb)->cache0= name##_cache0;\ (gb)->cache1= name##_cache1;\ (gb)->buffer_ptr= name##_buffer_ptr;\ # define UPDATE_CACHE(name, gb)\ if(name##_bit_count > 0){\ const uint32_t next= be2me_32( *name##_buffer_ptr );\ name##_cache0 |= NEG_USR32(next,name##_bit_count);\ name##_cache1 |= next<buffer_ptr - s->buffer)*8 - 32 + s->bit_count; } static inline void skip_bits_long(GetBitContext *s, int n){ OPEN_READER(re, s) re_bit_count += n; re_buffer_ptr += re_bit_count>>5; re_bit_count &= 31; re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count; re_cache1 = 0; UPDATE_CACHE(re, s) CLOSE_READER(re, s) } #endif /** * read mpeg1 dc style vlc (sign bit + mantisse with no MSB). * if MSB not set it is negative * @param n length in bits * @author BERO */ static inline int get_xbits(GetBitContext *s, int n){ register int sign; register int32_t cache; OPEN_READER(re, s) UPDATE_CACHE(re, s) cache = GET_CACHE(re,s); sign=(~cache)>>31; LAST_SKIP_BITS(re, s, n) CLOSE_READER(re, s) return (NEG_USR32(sign ^ cache, n) ^ sign) - sign; } static inline int get_sbits(GetBitContext *s, int n){ register int tmp; OPEN_READER(re, s) UPDATE_CACHE(re, s) tmp= SHOW_SBITS(re, s, n); LAST_SKIP_BITS(re, s, n) CLOSE_READER(re, s) return tmp; } /** * reads 1-17 bits. * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't */ static inline unsigned int get_bits(GetBitContext *s, int n){ register int tmp; OPEN_READER(re, s) UPDATE_CACHE(re, s) tmp= SHOW_UBITS(re, s, n); LAST_SKIP_BITS(re, s, n) CLOSE_READER(re, s) return tmp; } /** * shows 1-17 bits. * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't */ static inline unsigned int show_bits(GetBitContext *s, int n){ register int tmp; OPEN_READER(re, s) UPDATE_CACHE(re, s) tmp= SHOW_UBITS(re, s, n); // CLOSE_READER(re, s) return tmp; } static inline void skip_bits(GetBitContext *s, int n){ //Note gcc seems to optimize this to s->index+=n for the ALT_READER :)) OPEN_READER(re, s) UPDATE_CACHE(re, s) LAST_SKIP_BITS(re, s, n) CLOSE_READER(re, s) } static inline unsigned int get_bits1(GetBitContext *s){ #ifdef ALT_BITSTREAM_READER int index= s->index; uint8_t result= s->buffer[ index>>3 ]; #ifdef ALT_BITSTREAM_READER_LE result>>= (index&0x07); result&= 1; #else result<<= (index&0x07); result>>= 8 - 1; #endif index++; s->index= index; return result; #else return get_bits(s, 1); #endif } static inline unsigned int show_bits1(GetBitContext *s){ return show_bits(s, 1); } static inline void skip_bits1(GetBitContext *s){ skip_bits(s, 1); } /** * reads 0-32 bits. */ static inline unsigned int get_bits_long(GetBitContext *s, int n){ if(n<=17) return get_bits(s, n); else{ #ifdef ALT_BITSTREAM_READER_LE int ret= get_bits(s, 16); return ret | (get_bits(s, n-16) << 16); #else int ret= get_bits(s, 16) << (n-16); return ret | get_bits(s, n-16); #endif } } #if 0 /** * reads 0-32 bits as a signed integer. */ static inline int get_sbits_long(GetBitContext *s, int n) { return sign_extend(get_bits_long(s, n), n); } #endif /** * shows 0-32 bits. */ static inline unsigned int show_bits_long(GetBitContext *s, int n){ if(n<=17) return show_bits(s, n); else{ GetBitContext gb= *s; return get_bits_long(&gb, n); } } #if 0 static inline int check_marker(GetBitContext *s, const char *msg) { int bit= get_bits1(s); if(!bit) printf("Marker bit missing %s\n", msg); return bit; } #endif /** * init GetBitContext. * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end * @param bit_size the size of the buffer in bits */ static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size) { int buffer_size= (bit_size+7)>>3; if(buffer_size < 0 || bit_size < 0) { buffer_size = bit_size = 0; buffer = NULL; } s->buffer= buffer; s->size_in_bits= bit_size; s->buffer_end= buffer + buffer_size; #ifdef ALT_BITSTREAM_READER s->index=0; #elif defined LIBMPEG2_BITSTREAM_READER s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1)); s->bit_count = 16 + 8*((intptr_t)buffer&1); skip_bits_long(s, 0); #elif defined A32_BITSTREAM_READER s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3)); s->bit_count = 32 + 8*((intptr_t)buffer&3); skip_bits_long(s, 0); #endif } static inline void align_get_bits(GetBitContext *s) { int n= (-get_bits_count(s)) & 7; if(n) skip_bits(s, n); } #define init_vlc(vlc, nb_bits, nb_codes,\ bits, bits_wrap, bits_size,\ codes, codes_wrap, codes_size,\ flags)\ init_vlc_sparse(vlc, nb_bits, nb_codes,\ bits, bits_wrap, bits_size,\ codes, codes_wrap, codes_size,\ NULL, 0, 0, flags) int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags); #define INIT_VLC_USE_STATIC 1 ///< VERY strongly deprecated and forbidden #define INIT_VLC_LE 2 #define INIT_VLC_USE_NEW_STATIC 4 void free_vlc(VLC *vlc); #define INIT_VLC_STATIC(vlc, bits, a,b,c,d,e,f,g, static_size)\ {\ static VLC_TYPE table[static_size][2];\ (vlc)->table= table;\ (vlc)->table_allocated= static_size;\ init_vlc(vlc, bits, a,b,c,d,e,f,g, INIT_VLC_USE_NEW_STATIC);\ } /** * * if the vlc code is invalid and max_depth=1 than no bits will be removed * if the vlc code is invalid and max_depth>1 than the number of bits removed * is undefined */ #define GET_VLC(code, name, gb, table, bits, max_depth)\ {\ int n, index, nb_bits;\ \ index= SHOW_UBITS(name, gb, bits);\ code = table[index][0];\ n = table[index][1];\ \ if(max_depth > 1 && n < 0){\ LAST_SKIP_BITS(name, gb, bits)\ UPDATE_CACHE(name, gb)\ \ nb_bits = -n;\ \ index= SHOW_UBITS(name, gb, nb_bits) + code;\ code = table[index][0];\ n = table[index][1];\ if(max_depth > 2 && n < 0){\ LAST_SKIP_BITS(name, gb, nb_bits)\ UPDATE_CACHE(name, gb)\ \ nb_bits = -n;\ \ index= SHOW_UBITS(name, gb, nb_bits) + code;\ code = table[index][0];\ n = table[index][1];\ }\ }\ SKIP_BITS(name, gb, n)\ } #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\ {\ int n, index, nb_bits;\ \ index= SHOW_UBITS(name, gb, bits);\ level = table[index].level;\ n = table[index].len;\ \ if(max_depth > 1 && n < 0){\ SKIP_BITS(name, gb, bits)\ if(need_update){\ UPDATE_CACHE(name, gb)\ }\ \ nb_bits = -n;\ \ index= SHOW_UBITS(name, gb, nb_bits) + level;\ level = table[index].level;\ n = table[index].len;\ }\ run= table[index].run;\ SKIP_BITS(name, gb, n)\ } /** * parses a vlc code, faster then get_vlc() * @param bits is the number of bits which will be read at once, must be * identical to nb_bits in init_vlc() * @param max_depth is the number of times bits bits must be read to completely * read the longest vlc code * = (max_vlc_length + bits - 1) / bits */ static inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth) { int code; OPEN_READER(re, s) UPDATE_CACHE(re, s) GET_VLC(code, re, s, table, bits, max_depth) CLOSE_READER(re, s) return code; } //#define TRACE #ifdef TRACE static inline void print_bin(int bits, int n){ int i; for(i=n-1; i>=0; i--){ printf("%d", (bits>>i)&1); } for(i=n; i<24; i++) printf(" "); } static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ int r= get_bits(s, n); print_bin(r, n); printf("%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line); return r; } static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){ int show= show_bits(s, 24); int pos= get_bits_count(s); int r= get_vlc2(s, table, bits, max_depth); int len= get_bits_count(s) - pos; int bits2= show>>(24-len); print_bin(bits2, len); printf("%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); return r; } static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ int show= show_bits(s, n); int r= get_xbits(s, n); print_bin(show, n); printf("%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line); return r; } #define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define tprintf(p, ...) printf #else //TRACE #define tprintf(p, ...) {} #endif static inline int decode012(GetBitContext *gb){ int n; n = get_bits1(gb); if (n == 0) return 0; else return get_bits1(gb) + 1; } static inline int decode210(GetBitContext *gb){ if (get_bits1(gb)) return 0; else return 2 - get_bits1(gb); } #endif /* BITSTREAM_H */ a> 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580
/***************************************************************************
*             __________               __   ___.
*   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
*   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
*   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
*   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
*                     \/            \/     \/    \/            \/
* $Id$
*
* Copyright (C) 2005 Adam Boot
*
* Color graphics from Frozen Bubble (http://www.frozen-bubble.org/)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/

#include "plugin.h"

#include "lib/xlcd.h"
#include "lib/pluginlib_actions.h"
#include "lib/fixedpoint.h"
#include "lib/playback_control.h"
#include "lib/highscore.h"

/* files */
#define SCORE_FILE PLUGIN_GAMES_DATA_DIR "/bubbles.score"
#define SAVE_FILE  PLUGIN_GAMES_DATA_DIR "/bubbles.save"
#define DATA_FILE  PLUGIN_GAMES_DATA_DIR "/bubbles.data"

/* final game return status */
enum {
    BB_LOSE,
    BB_QUIT_WITHOUT_SAVING,
    BB_QUIT,
    BB_USB,
    BB_END,
    BB_WIN,
    BB_NONE,
};

/* play board dimension */
#define BB_HEIGHT 12
#define BB_WIDTH  8
#define BB_LEVEL_HEIGHT 10

/* various amounts */
#define NUM_SCORES   5
#define NUM_LEVELS   100
#define NUM_QUEUE    2
#define NUM_BUBBLES  8
#define MIN_ANGLE    -76
#define MAX_ANGLE    76
#define NUM_COMPRESS 9
#define MAX_SHOTTIME 1000

/* keyboard layouts */

#ifdef HAVE_SCROLLWHEEL
/* sansas use the wheel instead of left/right if available */
#define BUBBLES_LEFT        PLA_SCROLL_BACK
#define BUBBLES_LEFT_REP    PLA_SCROLL_BACK_REPEAT
#define BUBBLES_RIGHT       PLA_SCROLL_FWD
#define BUBBLES_RIGHT_REP   PLA_SCROLL_FWD_REPEAT
#else
#define BUBBLES_LEFT        PLA_LEFT
#define BUBBLES_LEFT_REP    PLA_LEFT_REPEAT
#define BUBBLES_RIGHT       PLA_RIGHT
#define BUBBLES_RIGHT_REP   PLA_RIGHT_REPEAT
#endif

#define ANGLE_STEP          2
#define ANGLE_STEP_REP      4

#define BUBBLES_QUIT1       PLA_EXIT
#define BUBBLES_QUIT2       PLA_CANCEL

/* these are better off shooting with up */
#if (CONFIG_KEYPAD == SAMSUNG_YH_PAD) \
 || (CONFIG_KEYPAD == ONDIO_PAD) \
 || (CONFIG_KEYPAD == IRIVER_H10_PAD)
#define SHOOT_WITH_UP
#endif

#ifdef SHOOT_WITH_UP
#define BUBBLES_FIRE        PLA_UP
#define BUBBLES_FIRE_REPEAT PLA_UP_REPEAT
#define BUBBLES_PAUSE       PLA_SELECT
#else
#define BUBBLES_FIRE        PLA_SELECT
#define BUBBLES_FIRE_REPEAT PLA_SELECT_REPEAT
#define BUBBLES_PAUSE       PLA_UP
#endif

/* external bitmaps */
#ifdef HAVE_LCD_COLOR
#include "pluginbitmaps/bubbles_background.h"
#endif
#include "pluginbitmaps/bubbles_bubble.h"
#include "pluginbitmaps/bubbles_emblem.h"

#define BUBBLE_WIDTH  BMPWIDTH_bubbles_bubble
#define BUBBLE_HEIGHT BMPHEIGHT_bubbles_bubble
#define EMBLEM_WIDTH  BMPWIDTH_bubbles_emblem
#define EMBLEM_HEIGHT (BMPHEIGHT_bubbles_emblem/8)

/* bubbles will consume height of ROW_HEIGHT*(BB_HEIGHT-1)+BUBBLE_HEIGHT*3/2 */
/* 44x44 bubbles (m:robe 500) */
#if (LCD_WIDTH == 640) && (LCD_HEIGHT == 480)
#define XOFS          144
#define MAX_FPS       40

#elif (LCD_WIDTH == 480) && (LCD_HEIGHT == 640)
#define XOFS          128
#define MAX_FPS       40

/* 22x22 bubbles (iPod Video) */
#elif (LCD_HEIGHT == 240) && (LCD_WIDTH == 320)
#define XOFS          72
#define MAX_FPS       40

/* 22x22 bubbles (Gigabeat, Onda VX747) */
#elif ((LCD_HEIGHT == 320) || (LCD_HEIGHT == 400)) && (LCD_WIDTH == 240)
#define XOFS          64
#define MAX_FPS       30

/* 16x16 bubbles (H300, iPod Color, HDD6330) */
#elif (LCD_HEIGHT == 176) && (LCD_WIDTH == 220)
#define XOFS          46
#define MAX_FPS       30

/* 16x16 bubbles (Sansa E200) */
#elif (LCD_HEIGHT == 220) && (LCD_WIDTH == 176)
#define XOFS            24
#define MAX_FPS         30
#define YOFS            45

/* custom text positioning */
#define LEVEL_TXT_X     24
#define LEVEL_TXT_WIDTH 31
#define LEVEL_TXT_Y      5
#define SCORE_TXT_X     58
#define SCORE_TXT_WIDTH 31
#define SCORE_TXT_Y      5
#define NEXT_BB_X      112
#define NEXT_BB_WIDTH   31
#define NEXT_BB_Y        3

/* 12x12 bubbles (iPod Nano) */
#elif (LCD_HEIGHT == 132) && (LCD_WIDTH == 176)
#define XOFS          40
#define MAX_FPS       40

/* 12x12 bubbles (H100, H10, iAudio X5, HDD1630, iPod 3G, iPod 4G grayscale) */
#elif (LCD_HEIGHT == 128) && ((LCD_WIDTH == 160) || (LCD_WIDTH == 128))
#define XOFS          33
#define MAX_FPS       30

/* 12x12 bubbles (GoGear SA9200) */
#elif (LCD_HEIGHT == 160) && (LCD_WIDTH == 128)
#define XOFS          16
#define YOFS          32
#define ROW_HEIGHT    10
#define ROW_INDENT     6
#define MAX_FPS       30

/* custom text positioning */
#define LEVEL_TXT_X      2
#define LEVEL_TXT_WIDTH 31
#define LEVEL_TXT_Y      3
#define SCORE_TXT_X     34
#define SCORE_TXT_WIDTH 31
#define SCORE_TXT_Y      3
#define NEXT_BB_X       81
#define NEXT_BB_WIDTH   31
#define NEXT_BB_Y        2

/* 10x10 bubbles (iPod Mini) */
#elif (LCD_HEIGHT == 110) && (LCD_WIDTH == 138)
#define XOFS          33
#define MAX_FPS       30

/* 9x9 bubbles (iAudio M3) */
#elif (LCD_HEIGHT == 96) && (LCD_WIDTH == 128)
#define XOFS          45
#define MAX_FPS       30

/* 8x8 bubbles (Sansa C200) */
#elif ((LCD_HEIGHT == 80) && (LCD_WIDTH == 132))
#define XOFS          45
#define ROW_HEIGHT     6
#define MAX_FPS       30

/* 7x7 bubbles (Sansa Clip/m200) */
#elif (LCD_HEIGHT == 64 && LCD_WIDTH == 128)
#define XOFS          33
#define ROW_HEIGHT     5
#define MAX_FPS       30

/* 8x7 bubbles (Archos recorder, Ondio) */
#elif (LCD_HEIGHT == 64) && (LCD_WIDTH == 112)
#define XOFS          33
#define ROW_HEIGHT     5
#define MAX_FPS       20

#else
    #error BUBBLES: Unsupported LCD type
#endif

#if !defined(ROW_HEIGHT)
#define ROW_HEIGHT    (BUBBLE_WIDTH-(BUBBLE_WIDTH-EMBLEM_WIDTH)/2)
#endif

#if !defined(ROW_INDENT)
#define ROW_INDENT    (BUBBLE_WIDTH/2)
#endif

#define TEXT_LINES (LCD_HEIGHT/8)

#ifndef YOFS
#define YOFS 0
#endif

/* shot position */
#define SHOTX XOFS+ROW_INDENT+BUBBLE_WIDTH*3
#define SHOTY (YOFS+ROW_HEIGHT*(BB_HEIGHT-1)+BUBBLE_HEIGHT/2)

/* collision distance squared */
#define MIN_DISTANCE ((BUBBLE_WIDTH*8)/10)*((BUBBLE_HEIGHT*8)/10)

/* levels */
char level[NUM_LEVELS][BB_LEVEL_HEIGHT][BB_WIDTH] = {
    {{ 6,  6,  4,  4,  2,  2,  3,  3},
     { 6,  6,  4,  4,  2,  2,  3, -1},
     { 2,  2,  3,  3,  6,  6,  4,  4},
     { 2,  3,  3,  6,  6,  4,  4, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  7,  7,  7,  7,  7,  7, -1},
     {-1,  1,  1,  1,  1,  1, -1, -1},
     {-1, -1,  2,  2,  2,  2, -1, -1},
     {-1, -1, -1,  2, -1, -1, -1, -1},
     {-1, -1, -1,  2,  2, -1, -1, -1},
     {-1, -1, -1,  5, -1, -1, -1, -1},
     {-1, -1, -1,  5,  5, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1,  7, -1, -1,  7, -1, -1},
     {-1, -1,  7,  1,  7, -1, -1, -1},
     {-1, -1, -1,  1,  2, -1, -1, -1},
     {-1, -1,  1,  2,  1, -1, -1, -1},
     {-1, -1, -1,  2,  5, -1, -1, -1},
     {-1, -1,  3,  5,  3, -1, -1, -1},
     {-1, -1, -1,  5,  3, -1, -1, -1},
     {-1, -1, -1,  3, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  0,  0, -1, -1, -1},
     {-1, -1,  5,  0,  1, -1, -1, -1},
     {-1, -1,  3,  5,  1,  6, -1, -1},
     {-1,  4,  3, -1,  6,  7, -1, -1},
     {-1,  7,  4, -1, -1,  7,  4, -1},
     { 6,  7, -1, -1, -1,  4,  3, -1},
     { 1,  6, -1, -1, -1, -1,  3,  5},
     { 1, -1, -1, -1, -1, -1,  5, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1,  0,  0,  0,  0, -1, -1},
     {-1,  0,  1,  1,  1,  0, -1, -1},
     {-1,  0,  1,  0,  0,  1,  0, -1},
     {-1,  0,  1,  1,  1,  0, -1, -1},
     {-1, -1,  0,  0,  0,  0, -1, -1},
     {-1, -1,  7, -1,  7, -1, -1, -1},
     {-1, -1,  7,  7,  7,  7, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  4,  4,  4,  6,  6,  6, -1},
     { 4, -1, -1, -1, -1, -1,  6, -1},
     {-1,  4, -1, -1, -1, -1,  6, -1},
     { 4,  2,  3,  1,  2,  3,  6, -1},
     {-1,  3,  1,  2,  3,  1,  2, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  4,  4,  4,  6,  6,  6, -1},
     { 4, -1, -1, -1, -1, -1,  6, -1},
     {-1,  4, -1, -1, -1, -1,  6, -1},
     { 4,  2,  3,  1,  2,  3,  6, -1},
     {-1,  3,  1,  2,  3,  1,  2, -1},
     {-1,  2,  3,  1,  2,  3, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  0,  0, -1, -1,  2,  2, -1},
     {-1,  5, -1, -1, -1,  3, -1, -1},
     {-1,  0, -1, -1, -1,  6, -1, -1},
     {-1,  3, -1, -1, -1,  0, -1, -1},
     {-1,  4, -1, -1, -1,  5, -1, -1},
     {-1,  2, -1, -1, -1,  3, -1, -1},
     {-1,  2, -1, -1, -1,  1, -1, -1},
     {-1,  3, -1, -1, -1,  4, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 3, -1, -1, -1, -1, -1, -1,  3},
     { 6,  3,  2,  4,  6,  3,  2, -1},
     { 4, -1, -1, -1, -1, -1, -1,  4},
     { 2,  4,  6,  3,  2,  4,  6, -1},
     {-1, -1, -1,  6, -1, -1, -1, -1},
     {-1, -1, -1,  3, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  2, -1,  1, -1,  1, -1,  2},
     { 1,  2, -1,  2,  1, -1,  1, -1},
     { 1, -1,  1, -1,  2, -1,  2, -1},
     { 2,  1, -1,  1,  2, -1,  2, -1},
     {-1,  2, -1,  2, -1,  2, -1,  2},
     { 1,  2, -1,  2,  1, -1,  1, -1},
     { 1, -1,  1, -1,  2, -1,  1, -1},
     { 2,  2, -1,  1,  1, -1,  2, -1},
     {-1,  2, -1,  1, -1,  1, -1,  1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  7,  7, -1, -1,  5,  5, -1},
     { 1, -1, -1, -1, -1, -1,  4, -1},
     { 2,  1, -1, -1, -1, -1,  4,  3},
     { 2, -1, -1, -1, -1, -1,  3, -1},
     { 1,  2, -1, -1, -1, -1,  3,  4},
     { 1, -1, -1, -1, -1, -1,  4, -1},
     { 7,  1, -1, -1, -1, -1,  4,  5},
     { 7,  7, -1, -1, -1,  5,  5, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 7,  7, -1, -1, -1, -1,  5,  5},
     { 1,  5, -1, -1, -1,  7,  4, -1},
     { 2,  1, -1, -1, -1, -1,  4,  3},
     { 2, -1, -1, -1, -1, -1,  3, -1},
     { 1,  5, -1, -1, -1, -1,  7,  4},
     { 1, -1, -1, -1, -1, -1,  4, -1},
     { 7,  1, -1, -1, -1, -1,  4,  5},
     { 7,  5, -1, -1, -1,  7,  5, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  0,  0, -1, -1, -1},
     {-1, -1,  5,  0,  1, -1, -1, -1},
     {-1, -1,  3,  5,  1,  6, -1, -1},
     {-1,  4,  3,  2,  6,  2, -1, -1},
     {-1,  7,  4,  7,  2,  2,  4, -1},
     { 6,  7,  7,  3,  3,  4,  3, -1},
     { 1,  6,  1,  1,  1,  3,  3,  5},
     { 1,  1, -1, -1, -1, -1,  5, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1,  0, -1, -1,  0, -1, -1},
     {-1,  3,  3, -1,  3,  3, -1, -1},
     {-1,  0,  2,  0,  0,  2,  0, -1},
     {-1,  3,  3, -1,  3,  3, -1, -1},
     {-1, -1,  0, -1, -1,  0, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  1,  1, -1, -1, -1},
     {-1, -1,  2,  2,  2, -1, -1, -1},
     {-1, -1,  3,  3,  3,  3, -1, -1},
     {-1,  4,  4,  4,  4,  4, -1, -1},
     {-1,  5,  5,  5,  5,  5,  5, -1},
     {-1, -1, -1,  6, -1, -1, -1, -1},
     {-1, -1, -1,  7,  7, -1, -1, -1},
     {-1, -1, -1,  0, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  2,  5, -1, -1, -1},
     {-1,  4,  3, -1, -1, -1, -1, -1},
     { 6,  7, -1,  5,  2, -1, -1, -1},
     {-1, -1, -1, -1,  3,  4, -1, -1},
     {-1, -1, -1,  2,  5, -1,  7,  6},
     {-1,  4,  3, -1, -1, -1, -1, -1},
     { 6,  7, -1,  5,  2, -1, -1, -1},
     {-1, -1, -1, -1,  3,  4, -1, -1},
     {-1, -1, -1, -1, -1, -1,  7,  6},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  5,  5, -1, -1, -1},
     {-1, -1, -1,  3, -1, -1, -1, -1},
     {-1, -1, -1,  1, -1, -1, -1, -1},
     {-1, -1, -1,  7, -1, -1, -1, -1},
     {-1, -1, -1,  2, -1, -1, -1, -1},
     {-1, -1, -1,  4, -1, -1, -1, -1},
     {-1, -1, -1,  5, -1, -1, -1, -1},
     {-1, -1, -1,  3, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  0,  1, -1, -1, -1},
     {-1, -1,  0,  2,  7,  7, -1, -1},
     {-1, -1, -1,  0,  1,  7, -1, -1},
     {-1,  0,  0,  0,  0, -1, -1, -1},
     {-1,  0,  0,  0,  1,  1, -1, -1},
     { 0,  0,  0,  1,  1,  1, -1, -1},
     {-1,  0,  0,  1,  1,  1, -1, -1},
     {-1,  0,  0,  0,  7,  7, -1, -1},
     {-1, -1,  7,  7, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  1, -1, -1, -1, -1, -1, -1},
     { 1, -1, -1, -1, -1, -1, -1, -1},
     {-1,  2,  3,  4,  7,  6,  5, -1},
     {-1, -1, -1, -1, -1, -1,  1, -1},
     {-1, -1, -1, -1, -1, -1,  1, -1},
     {-1,  2,  3,  4,  7,  6, -1, -1},
     {-1,  1, -1, -1, -1, -1, -1, -1},
     { 1, -1, -1, -1, -1, -1, -1, -1},
     {-1,  2,  3,  4,  7,  6,  5, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  6, -1, -1, -1, -1, -1, -1},
     { 5, -1, -1, -1, -1, -1, -1, -1},
     { 2,  3,  4,  7,  6,  5,  2,  3},
     {-1, -1, -1, -1, -1, -1,  4, -1},
     {-1, -1, -1, -1, -1, -1,  7, -1},
     {-1,  4,  3,  2,  5,  6, -1, -1},
     {-1,  7, -1, -1, -1, -1, -1, -1},
     { 6, -1, -1, -1, -1, -1, -1, -1},
     { 5,  2,  3,  4,  7,  6,  5, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 3,  2,  1,  0,  0,  1,  2,  3},
     { 3,  2,  1,  0,  1,  2,  3, -1},
     { 4,  3,  2,  1,  1,  2,  3,  4},
     { 4,  3,  2,  1,  2,  3,  4, -1},
     { 5,  4,  3,  2,  2,  3,  4,  5},
     { 5,  4,  3,  2,  3,  4,  5, -1},
     { 6,  5,  4,  3,  3,  4,  5,  6},
     { 6,  5,  4,  3,  4,  5,  6, -1},
     { 7,  6,  5,  4,  4,  5,  6,  7},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  5,  5, -1, -1, -1},
     {-1, -1, -1,  3, -1, -1, -1, -1},
     {-1, -1, -1,  2,  4, -1, -1, -1},
     {-1, -1, -1,  6, -1, -1, -1, -1},
     {-1, -1, -1,  2,  4, -1, -1, -1},
     {-1,  2, -1,  5, -1,  4, -1, -1},
     { 1,  0,  1,  0,  1,  0,  1,  0},
     { 3, -1,  3, -1,  2, -1,  6, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1, -1,  1, -1, -1, -1},
     { 7,  4,  3,  5, -1, -1, -1, -1},
     { 6, -1, -1,  1, -1, -1, -1, -1},
     {-1, -1, -1,  5,  3,  4,  7, -1},
     { 6, -1, -1, -1,  1, -1, -1,  6},
     { 7,  4,  3,  5, -1, -1, -1, -1},
     {-1, -1, -1,  1, -1, -1, -1,  6},
     {-1, -1, -1,  5,  3,  4,  7, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1, -1,  7,  3,  6, -1},
     {-1, -1,  3,  7,  3,  6,  3, -1},
     {-1, -1,  5,  7,  3,  6,  3, -1},
     {-1,  6,  7,  3,  6,  7, -1, -1},
     {-1,  7,  7,  3,  6,  1, -1, -1},
     { 3,  7,  3,  6,  3, -1, -1, -1},
     { 5,  6,  2,  7,  1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 5, -1, -1, -1, -1, -1, -1,  5},
     { 5, -1,  6,  6,  6, -1,  5, -1},
     {-1,  5,  4, -1, -1,  4,  5, -1},
     {-1,  3, -1, -1, -1,  3, -1, -1},
     {-1,  6,  0, -1, -1,  0,  6, -1},
     {-1,  3, -1, -1, -1,  3, -1, -1},
     {-1, -1,  4, -1, -1,  4, -1, -1},
     {-1, -1,  6,  6,  6, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  7,  0, -1, -1,  0,  7, -1},
     { 7, -1,  0, -1,  0, -1,  7, -1},
     { 7,  1, -1,  0,  0, -1,  1,  7},
     { 7,  1,  2,  0,  2,  1,  7, -1},
     { 7,  6,  3,  2,  2,  3,  6,  7},
     { 7, -1,  3,  2,  3, -1,  7, -1},
     {-1,  7,  7,  3,  3,  7,  7, -1},
     {-1, -1, -1,  3, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  3, -1,  1, -1,  7, -1,  6},
     { 5, -1,  7, -1,  7, -1,  6, -1},
     { 6, -1,  0, -1,  5, -1,  3, -1},
     {-1,  2, -1,  1, -1,  5, -1, -1},
     {-1,  4, -1,  3, -1,  4, -1, -1},
     { 2, -1,  3, -1,  2, -1, -1, -1},
     {-1, -1,  4, -1,  6, -1, -1, -1},
     {-1, -1, -1,  5, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1, -1,  1, -1, -1, -1},
     {-1, -1, -1, -1,  3, -1, -1, -1},
     { 6,  1,  3,  1,  2,  1,  4,  1},
     {-1, -1, -1, -1,  6, -1, -1, -1},
     {-1, -1, -1,  4,  1, -1, -1, -1},
     {-1, -1,  1, -1,  3, -1, -1, -1},
     {-1, -1, -1,  2,  1, -1, -1, -1},
     {-1, -1, -1, -1,  4, -1, -1, -1},
     {-1, -1, -1,  6,  1, -1, -1, -1},
     {-1, -1, -1,  6, -1, -1, -1, -1}},
    {{-1, -1, -1,  5,  4, -1, -1, -1},
     {-1, -1,  4,  1,  0, -1, -1, -1},
     {-1, -1, -1,  2,  3, -1, -1, -1},
     {-1,  1,  4, -1,  2,  2, -1, -1},
     {-1,  3,  1,  2,  5,  1,  4, -1},
     {-1,  4,  2, -1,  0,  4, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1, -1,  1, -1, -1, -1},
     {-1, -1, -1,  1, -1, -1, -1, -1},
     {-1,  2, -1, -1,  1, -1,  5, -1},
     { 5, -1, -1,  1, -1, -1,  0, -1},
     {-1,  6, -1, -1,  1, -1,  4, -1},
     {-1,  0, -1,  1, -1,  5, -1, -1},
     {-1, -1,  5,  5,  0,  1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  6,  3, -1, -1, -1},
     {-1, -1,  3,  2,  6, -1, -1, -1},
     {-1, -1,  2,  6,  3,  2, -1, -1},
     {-1,  6,  3,  2,  6,  3, -1, -1},
     {-1,  3,  2,  6,  3,  2,  6, -1},
     { 2,  6,  3,  2,  6,  3,  2, -1},
     { 6,  3,  2,  6,  3,  2,  6,  3},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 6,  6,  6,  6,  6,  6,  6,  6},
     { 4, -1, -1, -1, -1, -1, -1, -1},
     {-1,  3,  2,  5,  7,  6,  4,  3},
     {-1,  5, -1, -1, -1, -1, -1, -1},
     {-1, -1,  7,  6,  4,  3,  2,  5},
     {-1, -1,  4, -1, -1, -1, -1, -1},
     {-1, -1, -1,  3,  2,  5,  7,  6},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 1, -1,  7, -1, -1,  6, -1,  2},
     { 6, -1,  1, -1,  6,  1,  3, -1},
     {-1,  4, -1,  7,  2, -1,  7, -1},
     { 2,  7, -1, -1, -1,  4, -1, -1},
     { 6, -1,  3,  5,  0,  2, -1,  7},
     { 1, -1, -1, -1, -1, -1,  1, -1},
     {-1,  1,  4,  5,  7,  5,  1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 6,  6,  6, -1, -1,  6,  6,  6},
     {-1, -1,  6, -1,  6, -1, -1, -1},
     {-1, -1,  2,  3,  3,  2, -1, -1},
     {-1,  3, -1,  5, -1,  3, -1, -1},
     {-1, -1,  5,  3,  3,  5, -1, -1},
     {-1, -1,  6,  1,  6, -1, -1, -1},
     {-1,  4,  2, -1, -1,  2,  4, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  5,  5, -1, -1, -1},
     {-1, -1,  5, -1, -1, -1, -1, -1},
     {-1,  3,  4,  6,  6, -1, -1,  5},
     { 3,  3,  4,  6,  5, -1,  5, -1},
     { 3,  2,  3,  6,  6,  5,  5, -1},
     { 3,  3,  4,  6,  5, -1,  5, -1},
     {-1,  3,  4,  6,  6, -1, -1,  5},
     {-1, -1,  5, -1, -1, -1, -1, -1},
     {-1, -1, -1,  5,  5, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 1, -1, -1, -1, -1, -1, -1,  1},
     { 1, -1,  2,  2,  2, -1,  1, -1},
     {-1,  1,  2,  3,  3,  2,  1, -1},
     { 6,  2,  3, -1,  3,  2,  6, -1},
     { 6,  2,  3, -1, -1,  3,  2,  6},
     { 6,  2,  3, -1,  3,  2,  6, -1},
     { 3,  3,  3,  7,  7,  3,  3,  3},
     { 0,  5,  0,  2,  0,  5,  0, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1,  7,  7,  7, -1, -1, -1},
     {-1,  7,  2,  2,  7, -1, -1, -1},
     {-1,  7,  5,  5,  5,  7, -1, -1},
     { 7,  7,  7,  7,  7,  7, -1, -1},
     {-1, -1,  6, -1,  6, -1, -1, -1},
     {-1,  6, -1, -1,  6, -1, -1, -1},
     {-1,  6,  4,  4, -1,  6,  4,  4},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  3,  3, -1,  3,  3,  3, -1},
     { 3,  7,  5,  4,  6,  5,  3, -1},
     { 1,  3,  3,  3, -1,  3,  3,  1},
     { 2,  1,  2,  1,  2,  1,  2, -1},
     { 1,  3,  3, -1,  3,  3,  3,  1},
     { 3,  5,  6,  4,  5,  7,  3, -1},
     { 2,  3,  3,  3, -1,  3,  3,  2},
     { 1,  1,  2,  2,  2,  1,  1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  6,  5, -1, -1, -1, -1, -1},
     { 3,  1,  3, -1, -1, -1, -1, -1},
     {-1,  5,  6, -1, -1, -1, -1, -1},
     {-1, -1,  5,  3, -1, -1, -1, -1},
     {-1, -1,  6,  1,  6, -1, -1, -1},
     {-1, -1,  3,  5, -1, -1, -1, -1},
     {-1, -1, -1, -1,  3,  6, -1, -1},
     {-1, -1, -1,  5,  6,  5, -1, -1},
     {-1, -1, -1, -1,  6,  3, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 6,  3,  7,  4,  5,  1,  6,  3},
     { 5,  1,  6,  3,  7,  4,  5, -1},
     { 6,  3,  7,  4,  5,  1,  6,  3},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1, -1, -1, -1,  4,  4},
     {-1, -1,  7,  7,  7,  4,  4, -1},
     {-1, -1, -1, -1, -1, -1,  4,  4},
     {-1,  1, -1, -1, -1,  7, -1, -1},
     {-1,  1,  1, -1, -1,  7, -1, -1},
     { 3,  3,  3, -1,  7, -1, -1, -1},
     { 3, -1,  2,  3,  3,  3, -1,  3},
     {-1,  2, -1,  3, -1,  3,  3, -1},
     {-1,  2, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1,  4, -1, -1, -1, -1, -1},
     {-1,  7,  4, -1, -1, -1, -1, -1},
     {-1, -1,  7,  4, -1, -1, -1, -1},
     {-1,  4,  7,  4, -1, -1, -1, -1},
     { 1,  1,  1,  1,  1,  1,  1, -1},
     { 1,  2,  1,  2,  1,  1, -1, -1},
     { 2,  2,  2,  2,  2,  2,  2,  2},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 0, -1, -1, -1, -1, -1, -1,  6},
     { 6,  1,  4,  3,  7,  5,  0, -1},
     { 0, -1, -1, -1, -1, -1, -1,  6},
     { 6,  1,  4,  3,  7,  5,  0, -1},
     { 0, -1, -1, -1, -1, -1, -1,  6},
     { 6,  1,  4,  3,  7,  5,  0, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 3,  3,  4,  6,  6,  4,  3,  3},
     { 0,  3,  4,  6,  4,  3,  1, -1},
     { 5,  1,  3,  4,  4,  3,  0,  1},
     { 0,  1,  3,  4,  3,  1,  0, -1},
     { 2,  1,  6,  3,  3,  0,  0,  1},
     { 0,  3,  4,  3,  6,  1,  5, -1},
     { 6,  1,  2,  6,  4,  0,  0,  2},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 6,  6, -1, -1, -1, -1,  4,  4},
     { 4,  0, -1, -1, -1,  3,  6, -1},
     { 0,  6, -1, -1, -1, -1,  4,  2},
     { 7, -1, -1, -1, -1, -1,  7, -1},
     { 4,  4, -1, -1, -1, -1,  5,  6},
     { 6,  4,  7,  7,  5,  6,  4, -1},
     {-1,  7,  6,  4,  6,  4,  7, -1},
     {-1,  0, -1,  7, -1,  7, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  5, -1, -1, -1, -1,  4, -1},
     {-1,  5, -1, -1, -1,  4, -1, -1},
     {-1, -1,  5,  6,  6,  4, -1, -1},
     {-1, -1,  2, -1,  2, -1, -1, -1},
     { 0,  0,  6, -1, -1,  6,  1,  1},
     {-1, -1,  2, -1,  2, -1, -1, -1},
     {-1, -1,  7,  6,  6,  3, -1, -1},
     {-1,  7, -1, -1, -1,  3, -1, -1},
     {-1,  7, -1, -1, -1, -1,  3, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  6, -1, -1, -1, -1,  2, -1},
     { 1,  7,  1,  1,  1,  3,  1, -1},
     {-1, -1,  4,  1,  1,  4, -1, -1},
     {-1,  1,  3,  1,  7,  1, -1, -1},
     {-1, -1, -1,  2,  6, -1, -1, -1},
     {-1, -1,  1,  5,  1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 7,  7,  7,  7,  7,  7,  7,  7},
     { 7, -1, -1, -1, -1, -1,  7, -1},
     { 7, -1, -1,  2,  0,  5,  2,  2},
     { 7, -1, -1, -1,  0,  3,  6, -1},
     { 7, -1, -1, -1, -1, -1,  4,  0},
     { 5,  5, -1, -1, -1, -1, -1, -1},
     { 4,  3,  6,  2, -1, -1, -1, -1},
     { 0,  2,  0,  4, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1,  1, -1, -1,  1, -1, -1},
     {-1,  4, -1, -1,  5, -1, -1, -1},
     {-1,  7, -1, -1,  1,  1,  1, -1},
     { 6, -1, -1, -1, -1,  7, -1, -1},
     { 1,  1,  1,  1, -1,  4, -1, -1},
     {-1, -1,  5, -1, -1, -1, -1, -1},
     {-1, -1,  0, -1, -1, -1, -1, -1},
     {-1,  3, -1, -1, -1, -1, -1, -1},
     {-1,  1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  7,  7, -1, -1,  7,  7, -1},
     { 6, -1,  4, -1,  4, -1,  6, -1},
     { 5, -1, -1,  3,  3, -1, -1,  5},
     { 6, -1, -1, -1, -1, -1,  6, -1},
     {-1,  7, -1, -1, -1, -1,  7, -1},
     {-1,  4, -1, -1, -1,  4, -1, -1},
     {-1, -1,  3, -1, -1,  3, -1, -1},
     {-1, -1,  2, -1,  2, -1, -1, -1},
     {-1, -1, -1,  5,  5, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  0,  0, -1, -1,  0,  0, -1},
     { 7,  4,  6,  6,  6,  4,  3, -1},
     { 5,  6,  6,  6,  2,  6,  6,  3},
     { 7,  4,  6,  6,  6,  4,  3, -1},
     {-1,  0,  0, -1, -1,  0,  0, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1, -1, -1,  7,  7,  7},
     {-1, -1, -1, -1,  2,  7,  7, -1},
     {-1,  0,  7,  7,  7, -1,  7,  7},
     { 6,  7,  7,  7, -1, -1, -1, -1},
     { 6, -1, -1, -1,  7,  7,  7,  7},
     { 6, -1, -1, -1, -1, -1, -1, -1},
     { 4,  2,  2,  2,  4, -1,  3, -1},
     { 4,  4,  4,  4,  3,  3,  3, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 4, -1, -1,  7, -1,  6, -1,  7},
     { 7,  6,  7, -1, -1,  7,  4, -1},
     {-1, -1,  7, -1, -1,  7, -1, -1},
     {-1,  0,  0,  0,  0,  0,  3, -1},
     {-1, -1,  0,  2,  2,  0,  6,  4},
     {-1, -1,  0,  0,  0,  1,  3, -1},
     {-1, -1, -1,  0,  0, -1,  3,  4},
     {-1, -1, -1,  6, -1,  5,  6, -1},
     {-1, -1, -1, -1, -1, -1,  1,  0},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  5, -1, -1, -1, -1,  5, -1},
     { 0, -1, -1,  0, -1, -1,  0, -1},
     { 0,  0,  0,  2,  2,  0,  0,  0},
     { 0, -1, -1,  0, -1, -1,  0, -1},
     {-1,  7, -1,  3, -1, -1,  7, -1},
     {-1, -1,  3,  6, -1, -1, -1, -1},
     {-1, -1, -1,  6, -1, -1, -1, -1},
     {-1,  3,  6, -1, -1, -1, -1, -1},
     {-1,  3, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  6,  5, -1, -1, -1},
     {-1, -1,  2,  6,  3, -1, -1, -1},
     {-1, -1,  5,  4,  7,  1, -1, -1},
     {-1,  6,  2,  2,  3,  4, -1, -1},
     {-1, -1,  3,  7,  3,  6, -1, -1},
     {-1, -1,  1,  3,  2, -1, -1, -1},
     {-1, -1, -1,  4,  5, -1, -1, -1},
     {-1, -1, -1,  4, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 7,  7, -1,  2,  2, -1,  6,  6},
     { 6, -1, -1,  6, -1, -1,  3, -1},
     { 2, -1, -1,  1, -1, -1,  2, -1},
     { 5, -1, -1,  3, -1, -1,  2, -1},
     { 1, -1, -1,  2, -1, -1,  1, -1},
     { 5, -1, -1,  2, -1, -1,  2, -1},
     { 6, -1, -1,  1, -1, -1,  7, -1},
     { 5, -1, -1,  5, -1, -1,  4, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  6,  6, -1, -1, -1},
     {-1,  0,  4,  4,  4,  0, -1, -1},
     {-1, -1, -1,  6,  6, -1, -1, -1},
     {-1, -1,  2,  7,  2, -1, -1, -1},
     {-1, -1, -1,  6,  6, -1, -1, -1},
     {-1,  0,  5,  5,  5,  0, -1, -1},
     {-1, -1, -1,  3,  3, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1,  4,  1,  3, -1, -1, -1},
     {-1,  1, -1, -1,  1, -1, -1, -1},
     {-1, -1,  4,  1,  3,  4,  1, -1},
     {-1,  1,  3,  4, -1, -1,  4, -1},
     {-1,  3, -1, -1,  3,  4,  1, -1},
     {-1,  1,  3,  4,  1,  3, -1, -1},
     {-1, -1,  4,  1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  6,  4, -1,  3,  2,  5, -1},
     { 0, -1, -1, -1, -1, -1,  1, -1},
     {-1,  2,  3,  5, -1,  4,  6, -1},
     { 0, -1, -1, -1, -1, -1,  1, -1},
     {-1,  4,  6, -1,  2,  5,  3, -1},
     { 0, -1, -1, -1, -1, -1,  1, -1},
     {-1,  5,  2,  3, -1,  4,  6, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  6,  6, -1, -1, -1},
     {-1, -1,  7,  6,  4, -1, -1, -1},
     {-1,  2,  1,  7,  4,  1,  3, -1},
     { 2,  1,  1,  1,  1,  1,  3, -1},
     {-1,  2,  2,  2,  3,  3,  3, -1},
     {-1, -1, -1,  5, -1, -1, -1, -1},
     {-1, -1, -1,  2,  3, -1, -1, -1},
     {-1, -1, -1,  5, -1, -1, -1, -1},
     {-1, -1,  2,  2,  3,  3, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 4, -1,  5, -1, -1,  3, -1,  6},
     { 2, -1,  3, -1,  2, -1,  4, -1},
     { 4, -1, -1,  1,  0, -1, -1,  6},
     { 6, -1,  2,  3,  5, -1,  4, -1},
     { 4, -1, -1,  0,  1, -1, -1,  6},
     { 2, -1,  5, -1,  3, -1,  4, -1},
     { 4, -1,  3, -1, -1,  2, -1,  6},
     { 6, -1, -1, -1, -1, -1,  4, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 2,  6,  0,  5,  5,  1,  3,  4},
     { 1, -1, -1,  2, -1, -1,  0, -1},
     { 4, -1, -1,  3,  6, -1, -1,  2},
     {-1, -1, -1,  0, -1, -1, -1, -1},
     {-1, -1, -1,  1,  4, -1, -1, -1},
     {-1, -1, -1,  2, -1, -1, -1, -1},
     {-1, -1, -1,  6,  3, -1, -1, -1},
     {-1, -1, -1,  5, -1, -1, -1, -1},
     {-1, -1, -1,  4,  1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1, -1,  5,  1,  1,  3},
     { 0,  5,  1,  0,  5,  3,  3, -1},
     { 5,  1,  0,  5,  1,  0,  5,  1},
     { 0,  5,  1,  0,  5,  1,  6, -1},
     {-1, -1, -1, -1,  1,  6,  5,  1},
     {-1, -1, -1, -1,  5,  1,  6, -1},
     {-1, -1, -1, -1,  1,  0,  5,  1},
     {-1, -1, -1, -1,  5,  1,  0, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  0,  7,  3, -1, -1,  2,  2},
     {-1,  0,  7,  3, -1, -1,  2, -1},
     {-1,  0,  7,  3, -1, -1,  2,  2},
     {-1,  0,  7,  3, -1,  3,  1, -1},
     {-1,  0,  7,  3, -1,  6,  4,  5},
     {-1,  0,  7,  3, -1,  7,  0, -1},
     {-1,  0,  7,  3, -1,  2,  3,  4},
     {-1,  0,  7,  3, -1,  5,  6, -1},
     {-1, -1, -1, -1, -1,  7,  0,  1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  7,  7,  7,  7, -1},
     { 3,  4,  5, -1, -1, -1,  7, -1},
     { 2, -1, -1, -1, -1, -1, -1,  3},
     { 7, -1, -1, -1, -1, -1,  4, -1},
     { 7, -1, -1, -1,  3,  4,  5,  6},
     { 7, -1, -1,  2,  0,  1,  2, -1},
     { 6, -1, -1, -1,  3,  4,  5,  6},
     { 0,  1, -1, -1, -1, -1, -1, -1},
     { 2,  3,  4, -1, -1, -1, -1, -1},
     { 5,  6,  0, -1, -1, -1, -1, -1}},
    {{-1,  7, -1, -1, -1, -1,  2, -1},
     { 1,  1, -1, -1, -1,  3,  3, -1},
     {-1,  2, -1, -1, -1, -1,  4, -1},
     { 3,  3, -1, -1, -1,  5,  5, -1},
     {-1,  4, -1, -1, -1, -1,  6, -1},
     { 5,  5, -1, -1, -1,  1,  1, -1},
     {-1,  6, -1, -1, -1, -1,  7, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  4, -1, -1, -1, -1,  4, -1},
     { 2, -1, -1,  1, -1, -1,  2, -1},
     { 5, -1, -1,  0,  0, -1, -1,  5},
     { 5, -1, -1,  1, -1, -1,  6, -1},
     {-1,  4,  2,  7,  7,  5,  4, -1},
     {-1, -1, -1,  6, -1, -1, -1, -1},
     {-1, -1, -1,  3,  3, -1, -1, -1},
     {-1, -1, -1,  7, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  1, -1, -1,  2,  3,  4, -1},
     { 2, -1, -1,  3,  0,  4, -1, -1},
     { 4, -1, -1,  2,  3,  1, -1, -1},
     { 3, -1,  4,  3,  0, -1, -1, -1},
     { 4, -1, -1,  2,  5,  1, -1, -1},
     { 3, -1,  4,  5,  0,  4, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 2, -1, -1,  1,  1, -1, -1,  2},
     { 2, -1,  3,  3,  3, -1,  2, -1},
     {-1,  2, -1,  4,  4, -1,  2, -1},
     {-1,  7,  7,  0,  7,  7, -1, -1},
     {-1, -1, -1,  4,  4, -1, -1, -1},
     {-1, -1,  5,  7,  5, -1, -1, -1},
     { 6,  3,  2,  6,  4,  2,  3,  6},
     { 5, -1, -1, -1, -1, -1,  1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 4,  2,  3,  5,  7,  1,  3,  6},
     { 1, -1, -1,  1, -1, -1,  1, -1},
     { 3,  0,  1,  3,  2,  4,  3,  5},
     { 4, -1, -1,  4, -1, -1,  4, -1},
     {-1,  5, -1, -1,  5, -1, -1,  5},
     { 0,  3,  2,  0,  4,  5,  0, -1},
     {-1,  6, -1, -1,  6, -1, -1,  6},
     { 7, -1, -1,  7, -1, -1,  7, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1,  5,  4, -1,  1,  1, -1, -1},
     { 5, -1,  4,  1, -1,  1, -1, -1},
     { 0, -1, -1, -1, -1, -1,  0, -1},
     { 0,  6,  4, -1, -1,  4,  2, -1},
     {-1,  4,  3,  5,  2,  6,  3,  6},
     {-1,  2,  6, -1, -1,  5,  4, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  6,  6, -1, -1, -1},
     {-1, -1,  5,  5,  4, -1, -1, -1},
     {-1, -1,  1,  6,  6,  4, -1, -1},
     {-1,  1,  7,  2,  5,  3, -1, -1},
     {-1,  2,  7,  2,  1,  5,  3, -1},
     { 2,  1,  3,  1,  4,  2,  7, -1},
     {-1,  3,  1,  3,  4,  2,  7, -1},
     {-1,  3,  5,  5,  6,  6, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1,  7,  3, -1, -1, -1, -1},
     {-1,  1,  7,  6, -1, -1, -1, -1},
     {-1,  3,  7,  5,  1,  5, -1, -1},
     { 7,  7,  0,  2,  4,  0,  4, -1},
     { 7,  1,  4,  6,  5,  6,  5,  7},
     { 1,  7,  7,  1,  7,  7,  1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1,  1, -1, -1,  1, -1, -1},
     {-1,  5,  6,  1,  5,  6, -1, -1},
     {-1,  1,  1,  2,  2,  1,  1, -1},
     { 4,  7,  1,  0,  1,  7,  4, -1},
     {-1,  3,  7,  5,  7,  5,  3, -1},
     {-1,  1,  1,  1,  1,  1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 4, -1, -1, -1,  5, -1, -1,  4},
     { 6,  6,  7,  6, -1,  4,  5, -1},
     { 4,  2,  7,  5,  2,  2,  6,  4},
     {-1, -1,  4,  1, -1,  5,  2, -1},
     {-1,  5,  2,  7,  7, -1,  7,  4},
     { 4,  6,  5,  4, -1,  4,  2, -1},
     {-1, -1, -1,  4, -1,  4,  1, -1},
     { 0,  0,  0,  5, -1, -1, -1, -1},
     {-1, -1, -1, -1,  0,  0,  0,  0},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 1, -1, -1, -1,  0,  0, -1, -1},
     { 2, -1, -1,  0,  1,  0, -1, -1},
     { 3, -1, -1,  0,  2,  2,  0, -1},
     { 4, -1,  0,  1,  1,  1,  0, -1},
     { 5, -1, -1,  0,  4,  4,  0, -1},
     { 6, -1, -1,  4,  4,  4, -1, -1},
     { 7, -1, -1, -1,  4,  4, -1, -1},
     {-1, -1, -1,  0,  1,  0, -1, -1},
     {-1, -1, -1,  0,  1,  1,  0, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1,  3, -1, -1,  1,  7, -1},
     {-1,  7,  4, -1, -1,  4,  3, -1},
     { 1, -1, -1,  0,  2,  0, -1, -1},
     { 5,  4, -1,  3, -1, -1, -1, -1},
     { 4, -1,  3,  6,  1,  1,  6, -1},
     {-1,  1, -1, -1,  4, -1,  1, -1},
     {-1,  7,  5, -1, -1, -1,  3, -1},
     {-1, -1,  3, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 1, -1, -1, -1,  1, -1, -1, -1},
     { 2, -1, -1, -1,  2, -1, -1, -1},
     {-1,  3, -1, -1,  3,  3, -1, -1},
     {-1,  4, -1,  4, -1,  4, -1, -1},
     {-1,  5, -1, -1,  5,  5, -1, -1},
     { 6, -1, -1,  7,  1,  7, -1, -1},
     { 7, -1, -1, -1,  6,  6, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 2, -1, -1,  6, -1,  2,  5,  1},
     { 5, -1,  4, -1,  4, -1,  4, -1},
     { 6, -1, -1,  3, -1, -1, -1,  3},
     { 4,  2,  0, -1, -1, -1,  5, -1},
     {-1, -1, -1,  6, -1,  3,  6, -1},
     {-1, -1,  5, -1,  5, -1, -1, -1},
     {-1, -1, -1,  3, -1,  4,  2,  5},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 6, -1, -1, -1,  4, -1, -1,  3},
     { 0,  3, -1, -1,  6, -1,  0, -1},
     {-1, -1,  7, -1,  1, -1,  3, -1},
     { 7, -1,  4,  7, -1,  2, -1, -1},
     { 5,  2,  3,  2,  1,  6, -1,  3},
     {-1, -1,  0,  4,  3,  5,  4, -1},
     {-1,  7,  6, -1, -1,  0, -1, -1},
     { 4,  3, -1, -1, -1,  4,  2, -1},
     { 0, -1, -1, -1, -1, -1,  6, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{ 6,  1,  2,  5,  1,  6,  3,  0},
     {-1, -1, -1, -1, -1, -1,  4, -1},
     { 0,  5,  2,  7,  1,  6,  2, -1},
     { 3, -1, -1, -1, -1, -1, -1, -1},
     { 6,  7,  6,  4,  0,  5,  2,  6},
     {-1, -1, -1, -1, -1, -1,  1, -1},
     { 6,  1,  4,  0,  6,  2,  3, -1},
     { 0, -1, -1, -1, -1, -1, -1, -1},
     {-1,  0,  4,  5,  3,  7,  6,  0},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  0,  1, -1, -1, -1},
     {-1, -1,  0,  7,  0, -1, -1, -1},
     {-1, -1,  1,  2,  2,  0, -1, -1},
     {-1,  0,  7,  0,  7,  0, -1, -1},
     {-1,  6, -1,  7,  7, -1,  6, -1},
     { 4,  1,  6,  6,  6,  4,  1, -1},
     {-1,  5, -1,  7,  7, -1,  5, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1},
     {-1, -1, -1, -1, -1, -1, -1, -1}},
    {{-1, -1, -1,  5,  6, -1, -1, -1},
     {-1, -1,  3,  3,  3, -1, -1, -1},
     {-1, -1,  7,  5,  3,  7, -1, -1},
     {-1,  3, -1,  6, -1,  3, -1, -1},