function [w a]=swdist(n, B)
if nargin < 2
    B= floor(25000000/n);
%
zmat = normrnd(0,1,[B n]);
sorted=sort(zmat,2);
clear zmat
m=mean(sorted)';
V=cov(sorted);
clear sorted
c= m' * V;
clear V
b1=c./sqrt(sum(c.^2));
b2=-fliplr(b1);
a= (b1 + b2)./2;
    Zs = sort(normrnd(0,1,[B n]),2);
    Sxx=(n-1)*var(Zs');
    num = a  * Zs';
    clear Zs
    w= num.^2./Sxx;
end