n=40;
parfor i=1:n
    M = magic(n);
    R = rand(n);
    
    A(i) = sum(M(i,:) * R(n+1-i, :))
end
