# Alchemy

Since the days of yore, alchemy has been studied and practiced. The practice makes alchemists able to transmute materials into other forms. Transmuting materials requires drawing a transmutation circle on the ground. A little known fact about transmutation circles is they can be drawn inside or outside other transmutation circles. By activating certain configurations in the correct order, more powerful transmutations can be produced. Activating circles incorrectly can have drastic effects on the alchemist’s body.

A young alchemist named Nicholas Flamel would like to learn the ways of alchemy. He is going to draw several configurations of transmutation circles on the ground. When a circle is drawn it burns bright red representing the element of fire. The drawing of the circle itself produces no energy, but it has an effect on any and all circles that are already drawn inside! All of the circles inside the newly drawn circle quickly change to their complement elements. Fire changes to a cool blue representing water. Circles that were blue for water will burn fiery red once again. This transformation can either create or drain energy. Interestingly, it is the transformation, and not the drawing, that emanates energy. Beware, energy can go negative at any time draining the alchemist’s life force.

Nicholas wants to get as much out of his transmutations as possible. To do so requires him to draw his circles in an order that releases the most energy. Determine the maximum amount of energy that can be released, and the order in which he should draw the circles.

## Input

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. Each test case will start with a line with a single integer $n$ ($1 \le n \le 2\, 000$) indicating the number of circles. The next $n$ lines will describe the circles, in order, from circle $1$ to circle $n$. Each line will describe its circle with $5$ integers, with a single space between integers:

x y r a b


Where $(x,y)$ is the center of the circle ($-20\, 000 \le x,y \le 20\, 000$), $r$ is the radius of the circle ($1 \le r \le 20\, 000$), $a$ is the energy released in the transition from fire to water, and $b$ is the energy released in the transition from water to fire ($-500 \le a,b \le 500$). It is guaranteed that no two circles’ edges will intersect.

## Output

Output exactly two lines. On the first line output a single integer representing the maximum energy that can be produced by activating the circles. On the second line output the order of drawing the circles that can produce that energy. If more than one order will work, output the one that comes first lexicographically.

Sample Input 1 Sample Output 1
8
0 0 100 -100 -100
0 0 50 -10 -10
0 0 10 -100 500
0 0 1 100 100
1000 1000 100 -1 1
1000 1000 50 -1 1
1000 1000 10 -1 1
1000 1000 1 -1 1

700
4 3 1 2 5 6 7 8
{"ft_lang_label":"__label__en","ft_lang_prob":0.9011928,"math_prob":0.9826537,"size":2899,"snap":"2021-43-2021-49","text_gpt3_token_len":715,"char_repetition_ratio":0.14749569,"word_repetition_ratio":0.015473888,"special_character_ratio":0.264574,"punctuation_ratio":0.090277776,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96833456,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-01T09:00:31Z\",\"WARC-Record-ID\":\"<urn:uuid:1a05096c-9d85-4f44-8243-56d0e2575cf8>\",\"Content-Length\":\"19276\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5c882829-8a15-4fb7-878d-f317c21f0e3d>\",\"WARC-Concurrent-To\":\"<urn:uuid:d0082714-e825-4f81-affb-de8e4b3a1314>\",\"WARC-IP-Address\":\"172.66.40.199\",\"WARC-Target-URI\":\"https://kth.kattis.com/problems/alchemy\",\"WARC-Payload-Digest\":\"sha1:5XWSL3ZMIJZKUP6AWGHA7BOQTER5W6NP\",\"WARC-Block-Digest\":\"sha1:NEVHOC23GOPPHWNBNGS44KIIZIXMWSYW\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964359976.94_warc_CC-MAIN-20211201083001-20211201113001-00387.warc.gz\"}"}