#include <stdio.h>
#include <stdlib.h>
int **readGroup(FILE *fp, int rows){
int **gp, counter = 0;
gp=malloc(rows*sizeof(int*));
for(counter = 0; counter < rows ; ++counter){
int i,data,size;
fscanf(fp, " %d", &size);//size of trailing
gp[counter] = malloc((size+1)*sizeof(int));//+1 for size
gp[counter][0] = size;//store size to top
for(i=1;i<=size;++i){
fscanf(fp, " %d", &data);
gp[counter][i] = data;
}
}
return gp;
}
int main(void){
FILE *fp;
int L,C;
int **group[2];
fp = fopen("data.txt", "r");
fscanf(fp, " %d", &L);
fscanf(fp, " %d", &C);
group[0] = readGroup(fp, L);
group[1] = readGroup(fp, C);
fclose(fp);
{// check print
int gp,r,i,size;
int rows[] = {L, C};
for(gp=0;gp<2;++gp){
for(r=0;r<rows[gp];++r){
int size = group[gp][r][0];
for(i=1;i<=size;++i)
printf("%d ", group[gp][r][i]);
printf("\n");
}
printf("\n");
}
}
//deallocate
return 0;
}