← Back to Problems
Minimum Variance
Easy standard Portfolio Optimization
Time limit: 1 s per test  ·  Memory: 256 MB

A desk can trade n assets whose returns have covariance matrix Sigma (symmetric, positive definite). Find the fully invested portfolio with the smallest variance: weights w_1, ..., w_n minimizing w' Sigma w subject to w_1 + ... + w_n = 1. Shorting is allowed: weights may be negative.

Input

The first line contains n. The next n lines each contain n numbers: the covariance matrix.

Output

n real numbers on one line: the optimal weights, each with absolute or relative error at most 1e-9.

Constraints

2 <= n <= 400

The covariance matrix is symmetric positive definite with entries given to 8 decimal places

Scoring

This is a standard problem: a submission scores full points if it produces the correct output for every test case, and zero otherwise.

Numeric answers are accepted if they are within an absolute tolerance of 1e-09 or a relative tolerance of 1e-09 of the expected value.

Examples

input
2
0.01733436 -0.00241317
-0.00241317 0.28196566
output
9.350680092314e-01 6.493199076857e-02
input
4
0.08564242 0.00000000 0.00000000 -0.00935349
0.00000000 0.08564242 0.00000000 0.00000000
0.00000000 0.00000000 0.08564242 -0.01038007
-0.00935349 0.00000000 -0.01038007 0.08564242
output
2.498295476748e-01 2.195231386197e-01 2.531557877635e-01 2.774915259420e-01
Python 3.13 i Execution environment Isolated microVM · 1 vCPU · no internet access Time and memory limits are set per problem Available packages numpy 2.5.0scipy 1.18.0pandas 3.0.0scikit-learn 1.9.0statsmodels 0.15.0cvxpy 1.9.2