int***mat = (int ***)malloc(M *sizeof(int**));

mat[i]= (int **)malloc(N *sizeof(int*));

mat[i][j]= (int *)malloc(3*sizeof(int));