Top Spinning

Time limit1sMemory limit128 MB

Problem

Spinning tops are among the most popular and traditional toys, and making one's own is a favorite pastime. One of the easiest ways to make a top is to cut a shape out of cardboard and pierce an axis through its center of mass. Professionally made tops usually have three-dimensional shapes, but in this problem we consider only two-dimensional ones.

Tops usually have rotationally symmetric shapes, such as a circle, a rectangle (with 2-fold rotational symmetry), or a regular triangle (with 3-fold symmetry). Although such symmetries are useful in determining the center of mass, they are not strictly required: an asymmetric top also spins well if its axis is pierced exactly at the center of mass.

Given the shape of a top as a path used to cut it out of cardboard of uniform thickness, find its center of mass so that it spins well. You must also determine whether the center of mass lies on the piece of cardboard that was cut out; if it does not, the axis cannot be pierced.

Java note: submitted Java programs may not use classes implementing the interface java.awt.Shape (you may use them for debugging purposes).

Input

The input consists of multiple datasets, each describing a counterclockwise path used to cut out a top. A path is given as a sequence of command lines, each specifying a line segment or an arc.

In the command descriptions below, the current position is the position from which the next cut starts. After the cut of a command is executed, the current position moves to the end of that cut. Each command name starts in the first column of a line, and the command and its arguments are separated by spaces. All arguments are integers.

  • start x y — Sets the start of a path. This command performs no cut; it only sets the current position to $(x, y)$.
  • line x y — Cuts a straight line from the current position to $(x, y)$, which is different from the current position.
  • arc x y r — Cuts a circular arc from the current position to $(x, y)$, which is different from the current position. The arc has radius $|r|$. When $r$ is negative, the center of the circle is on the left side of the direction of the cut; when $r$ is positive, it is on the right side. The value $|r|$ is greater than half the distance between the two ends of the arc. Of the two arcs of that radius connecting the start and end positions, the one specified is the arc whose central angle is less than $180$ degrees.
  • close — Closes the path with a straight cut back to the initial start position and ends the dataset. If the current position is already the start position, this command simply marks the end of the dataset.

A dataset begins with a start command and ends with a close command. The end of the input is a line containing the single command end.

There are at most $100$ commands in a dataset and at most $100$ datasets in the input. The absolute values of all coordinates and radii are at most $100$. You may assume that the path neither crosses nor touches itself, and that the path never extends beyond the edges of the cardboard (in other words, the cardboard is effectively infinitely large).

Output

For each dataset, output one line containing the $x$- and $y$-coordinates of the center of mass of the top cut out by the given path, followed by a character '+' or '-' indicating whether this center is on the top or not, respectively. Print each of the two coordinates rounded to exactly $5$ digits after the decimal point, with a single space between the two coordinates and between the $y$-coordinate and the '+'/'-' character. Print no other characters. The center of mass is computed exactly; the test data guarantee that the center of mass is at least $10^{-3}$ away from the path (so the '+'/'-' decision is unambiguous) and that neither printed coordinate lies on a $5$-decimal rounding boundary. If a coordinate rounds to zero, print it as 0.00000 with no minus sign.

Hint

A useful property of centers of mass: when an object $O$ can be decomposed into parts $O_1, \ldots, O_n$ with masses $M_1, \ldots, M_n$, the center of mass of $O$ is

$$G = \frac{\sum_{i=1}^{n} M_i \cdot G_i}{\sum_{i=1}^{n} M_i},$$

where $G_i$ is the position vector of the center of mass of $O_i$.

A circular segment (the region bounded by a chord and its arc) with radius $r$ and central angle $\theta$ (in radians) has arc length $s = r\theta$ and chord length $c = r\sqrt{2 - 2\cos\theta}$. Its area is $A = r^2(\theta - \sin\theta)/2$, and its center of mass is at distance $\frac{2 r^3 \sin^3(\theta/2)}{3A}$ from the center of the circle.