My Accept Short Solution :D
#include<iostream>
#include<vector>
using namespace std;
#define forr(i,x,y) for(int i=(int)(x); i<=(int)(y); i++)
int p[24][6]={
{1,2,3,4,5,6},{1,2,6,5,3,4},{1,2,4,3,6,5},{1,2,5,6,4,3},{2,1,4,3,5,6},{2,1,6,5,4,3},{2,1,3,4,6,5},{2,1,5,6,3,4},
{3,4,2,1,5,6},{3,4,6,5,2,1},{3,4,1,2,6,5},{3,4,5,6,1,2},{4,3,6,5,1,2},{4,3,2,1,6,5},{4,3,5,6,2,1},{4,3,1,2,5,6},
{5,6,3,4,2,1},{5,6,1,2,3,4},{5,6,4,3,1,2},{5,6,2,1,4,3},{6,5,3,4,1,2},{6,5,2,1,3,4},{6,5,4,3,2,1},{6,5,1,2,4,3}};
int n,a[7],b[7],id[7][7][7][7][7][7],m=0,x=0;
vector< vector<int> > y(100100);
int main() {
scanf("%d",&n);
forr(i,1,n) {
scanf("%d %d %d %d %d %d",&a[3],&a[4],&a[2],&a[5],&a[1],&a[6]);
forr(q,0,23) if(x=id[a[p[q][0]]][a[p[q][1]]][a[p[q][2]]][a[p[q][3]]][a[p[q][4]]][a[p[q][5]]])break;
if(!x) { y[++m].push_back(i); id[a[1]][a[2]][a[3]][a[4]][a[5]][a[6]]=m; } else y[x].push_back(i);
}
printf("%d\n",m);
forr(i,1,m) { forr(j,0,y[i].size()-1) printf("%d ",y[i][j]); printf("\n"); }
}