ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

## 1299. Psylonians

Time limit: 1.0 second
Memory limit: 64 MB
The Psylonian race is known to wield by far the most advanced military battle-robots. During the fight for Terra, it took four of these battle-robots only three hours to completely wipe out one of the ancient cities with adjacent territories. You’d better watch your back with them. The Earth Defense Forces command is utterly preoccupied. Personnel is being trained for military operations against Psylonians in case the armed conflict bursts out again. But working out good tactics requires modeling of the battle-robot’s artificial intelligence unit. And you are to help us!
The robot’s behavior turned out to be rather simple. He can use just four basic patterns: “Defense”, “Attack”, “Guard” and “Patrol”. Moreover, the behavior control unit you have to model implements a rather simple scheme: it takes some parameters as input and outputs one of the following commands for the robot to execute:
LEFT X – spend X energy units for turning left;
RIGHT X – spend X energy units for turning right;
FRONT X – spend X energy units for moving forward;
BACKWARD X – spend X energy units for moving backward;
FIRE P – spend P fire units for attacking the enemy;
STOP – nothing to do.
In all these cases X is calculated as follows: If the robot’s power supply has more than 100 energy units available, then X = 100; otherwise, X is the amount of power units remaining. Similarly, P is calculated as the smallest of two values: 20 and the actual amount of ammunition units remaining.
The most simple behavioral pattern is “Guard”. When it’s active, robot does not walk, it can only turn. It picks the most dangerous target, and determines angle between robot’s current line of sight and direction to the target. If the angle is less than 5 degrees (by absolute value), robot shoots. Otherwise, if the angle is greater than or equals to 5, the robot turns left; if the angle is less than or equals to -5, the command is to turn right. If there are no targets around, robot does nothing.
According to the “Defense” pattern, robot’s actions are defined as follows: calculate the number of enemies and multiply it by 20. If the result is not less than the amount of ammunition units left, the robot will “Retreat and Return Fire”. Otherwise, it will act as if following the “Guard” pattern.
The “Attack” pattern works as follows: If N*NP > M*MP*3, then the robot will “Advance and Return Fire”; else it will “Retreat and Return Fire”. Here: N is the total number of allied battle-robots; NP is the average amount of energy units they have remaining; M is the total number of enemy robots; MP is the average amount of energy units the enemy robots have remaining.
When the battle-robot “Retreats and Returns Fire”, it checks the angle to the most dangerous enemy. If the angle is 5 degrees or more, or there are no enemies, the robot just moves backward. Otherwise, it fires its guns.
Similarly, when the battle-robot “Advances and Returns Fire”, it checks the angle to the most dangerous enemy. If the angle is 10 degrees or more, or there are no enemies, the robot just moves forward or shoots otherwise.
When “Patrolling”, the robot follows its waypoint route, if there are no enemies. If the robot encounters enemy when patrolling, then it acts as if the “Defense” pattern was active. When following a route, robot uses this algorithm to move to the next waypoint:
If the angle to the next waypoint exceeds 20 degrees by absolute value, the robot turns into direction to waypoint. Note that it does not matter whether the robot is moving forward or backward while following the route. You should consider this when calculating the turn direction - the turn angle should be minimal.
Otherwise, if the angle to the next waypoint does not exceed 20, then the robot just moves towards the next waypoint.

### Input

The first line contains two integers separated by space; the first integer is the amount of energy units available, the second one is the amount of ammunition available. The second line contains a single character, which determines the operating pattern: G stands for “Guard”, D for “Defense”, A for “Attack”, and P for “Patrol”. On the third line there are three integers: amount of enemies, average amount of energy units enemy bots possess, and angle to the most dangerous enemy target.
If the robot follows the “Attack” pattern, then the fourth line contains two integers: amount of allied bots and average amount of power units remaining in their power supplies, respectively. If the robot follows the “Patrol” pattern, then the fourth line contains only one integer: angle to the next waypoint.
Angle values range from -179 to 180 inclusive, all other integers are non-negative and none of them exceeds 1000.

### Output

The command for the robot using the format described above.

### Samples

inputoutput
```100 100
P
0 0 0
-100
```
```LEFT 100
```
```10 1000
A
1 10 30
100 1000
```
```FRONT 10
```
```10 1000
G
1 10 4
```
```FIRE 20
```
Problem Author: Pavel Egorov
Problem Source: IX Open Collegiate Programming Contest of the High School Pupils (13.03.2004)
Tags: none