ll@n,@x,@q,z=0; rep(q){ ll@m,@f[m],a[n]{}; z+=sum[i,0,m](f[i]==x)?2:!!sum[i,0,m](a[f[i]-1]++); } wt(z*.5);