f=file("stdin","r");m=c() repeat{m=cbind(m,a<-scan(f,nlines=1)) any(a)&&next if(a<-ncol(m))m=write(c(m[0:-a,]%*%m[1:a,],""),1,a)}