ARRANGE - runtime error


the same code below works fine and outputs what is expected at
however, it gives “runtime error” on both ideone, and codechef. dont know what is the problem :expressionless:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
   int a[65536][16], flag;
   for(int i=0; i<16; i++) a[0][i]=0;
   for(int i=1; i<65536; i++) {
       for(int j=15; j>=0; j--) {
           if(a[i-1][j]==0 && flag==0) {
           else if(a[i-1][j]==1 && flag==0) {
           else if(flag==1) {
   int t, k, b[65536][16], cnt, d;
   char s[65536], c[65536];
   scanf("%d", &t);
   while(t--) {
       scanf("%d%s", &k, s);
       d=pow(2, k);
       for(int i=0; i<d; i++) {
           for(int j=15, m=0; m<k; m++, j--) {
       for(int i=0; i<d; i++) {
           for(int j=0; j<d; j++) {
               for(int m=0; m<k; m++) {
                   if(b[i][m]==a[j][16-k+m]) cnt++;
               if(cnt==k) {
       printf("%s\n", c);
   return 0;

googling, i came up with: [][1]

however, i dont know whether that applies to 2 or more dimensional array. if yes, next obstacle: i dont know how to call that function in my above code. in the code above array assignments are from char string s[] to c[] and from int array a[][] to b[][].

a[][] is binary representation of numbers, b[][] is inversed version of a[][].

by the way, i peeked AC codes, saw there many bitwise operations, any help on how to carry out bitwise oper in this specific prob would be appreciated.(im familiar with XOR >> << etc)