  
function [prob]=wsurtcdf(W, n1, n)
% 
if  W < n1*(n1+1)/2  
    prob=0;
end
if W > n1 * (2*n - n1 + 1)/2
    prob = 1;
end
if W >= n1*(n1+1)/2 && W <= n1 * (2*n - n1 + 1)/2
    if n <= 40
%wsurtexact
  s=sum(combnk(1:n,n1),2); %there are n choose n1 rows, sum rows
  b = unique(s');
for i = 1:length(b)
fb(i) = sum(ismember(s,b(i)));
end
pro=fb/nchoosek(n, n1);
cp=cumsum(pro);
prob=cp(W - n1*(n1+1)/2 + 1);
    else
        prob=normcdf(W, n1*(n+1)/2, sqrt(n1*(n-n1)* (n+1)/12));
    end
end
end
