This page is still under construction.

Parts of this page are still being built. What you see may change.

Acperience

Time limit1sMemory limit64 MB

Summary
Given a weight vector, choose signs and a nonnegative scale to minimize the squared Euclidean distance, and report the minimum as a reduced fraction.
Level

Medium5 of 10

Topics
Math, Greedy, Number theory
Solved
No attempts yet

Problem

Deep neural networks (DNN) have shown significant improvements in several application domains, including computer vision and speech recognition. In computer vision, a particular type of DNN known as Convolutional Neural Networks (CNN) has achieved state-of-the-art results in object recognition and detection.

Convolutional neural networks give reliable results on object recognition and detection that are useful in real world applications. Alongside the recent progress in recognition, interesting advancements have been happening in virtual reality (VR by Oculus), augmented reality (AR by HoloLens), and smart wearable devices. Putting these two pieces together, we argue that it is the right time to equip smart portable devices with the power of state-of-the-art recognition systems. However, CNN-based recognition systems need large amounts of memory and computational power. While they perform well on expensive, GPU-based machines, they are often unsuitable for smaller devices like cell phones and embedded electronics.

In order to simplify the networks, Professor Zhang tries to introduce simple, efficient, and accurate approximations to CNNs by binarizing the weights. Professor Zhang needs your help.

More specifically, you are given a weight vector W=(w1,w2,…,wn)W = (w_1, w_2, \ldots, w_n). Professor Zhang would like to find a binary vector B=(b1,b2,…,bn)B = (b_1, b_2, \ldots, b_n) (bi∈{−1,+1}b_i \in \{-1, +1\}) and a real scaling factor α≥0\alpha \ge 0 in such a manner that ∥W−αB∥2\left\|W - \alpha B\right\|^{2} will be minimum possible.

Note that ∥⋅∥\left\|\cdot\right\| denotes the Euclidean norm, that is, ∥X∥=x12+⋯+xn2\left\|X\right\| = \sqrt{x_{1}^{2} + \cdots + x_{n}^{2}}, where X=(x1,x2,…,xn)X = (x_1, x_2, \ldots, x_n).

Input

There are multiple test cases. The first line of input contains an integer TT indicating the number of test cases. For each test case:

The first line contains an integer nn (1≤n≤100 0001 \le n \le 100\,000): the length of the given weight vector. The next line contains nn integers: w1,w2,…,wnw_1, w_2, \ldots, w_n (−10 000≤wi≤10 000-10\,000 \le w_i \le 10\,000).

There are no more than 400400 test cases. The total size of the input is at most 77 mebibytes.

Output

For each test case, output the minimum value of ∥W−αB∥2\left\|W - \alpha B\right\|^2 as an irreducible fraction pp/qq where pp and qq are integers, and q>0q > 0.

Examples1

  1. Example 1

    Input
    3
    4
    1 2 3 4
    4
    2 2 2 2
    5
    5 6 2 3 4
    
    Expected output
    5/1
    0/1
    10/1