int *a = (int*)malloc(1000*1000*sizeof(int));

val1 = a[i*1000+j];

a[i*1000+j] = val2;