#include<stdio.h>
#include<algorithm>
using namespace std;
const int N=10000;
int father[N];
int count1[N]={0}; //记录不同家庭人员数目
bool count2[N]={0}; //记录id是否有效
struct node{
int id;
int zm,za; //zm家庭总M,za家庭总Area
double av; //家庭平均Area
}Node[N];
bool cmp(node e,node f){
if(e.av!=f.av) return e.av>f.av;
else return e.id<f.id;
}
int findfather(int x){
int a=x;
while(x!=father[x]){
x=father[x];
}
while(a!=father[a]){
int z=a;
a=father[a];
father[z]=x;
}
return x;
}
void UNION(int a,int b){
int FA=findfather(a);
int FB=findfather(b);
if(FA!=FB){
if(FA<FB) swap(FA,FB); //编号小的作为father
father[FA]=FB;
}
}
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<N;i++){
father[i]=i;
}
int id,fa,ma,k,child,M,Area;
for(int i=0;i<n;i++){
scanf("%d%d%d%d",&id,&fa,&ma,&k);
count2[id]=true;
if(fa!=-1){
Node[fa].id=fa;
count2[fa]=true;
UNION(id,fa);
}
if(ma!=-1){
Node[ma].id=ma;
count2[ma]=true;
UNION(id,ma);
}
for(int j=0;j<k;j++){
scanf("%d",&child);
Node[child].id=child;
count2[child]=true;
UNION(id,child);
}
scanf("%d%d",&M,&Area);
Node[id].zm=M;
Node[id].za=Area;
Node[id].id=id;
}
for(int i=0;i<N;i++){ //求不同家庭za,zm
if(count2[i]==true){
count1[findfather(i)]++;
if(i!=findfather(i)){
Node[findfather(i)].za+=Node[i].za;
Node[findfather(i)].zm+=Node[i].zm;
Node[i].za=0;
Node[i].zm=0;
}
}
}
int ans=0;
for(int i=0;i<N;i++){
if(count1[i]!=0){
ans++; //不同家庭数目
}
}
for(int i=0;i<N;i++){
if(count1[i]!=0){
Node[i].av=Node[i].za*1.0/count1[i]; //不同家庭平均Area
}
}
sort(Node,Node+N,cmp);
printf("%d\n",ans);
for(int i=0;i<ans;i++){
printf("%04d %d %.3f %.3f\n",Node[i].id,count1[Node[i].id],Node[i].zm*1.0/count1[Node[i].id],Node[i].za*1.0/count1[Node[i].id]);
}
return 0;
}