FGH. TV

Bertie is visiting his remote relatives in a far away country. Initially he has a lot of trouble getting along with people in this country, but he figures capturing the local TV broadcast will help him overcome some of the social difficulties. Unfortunately the country developed it's own standards that are incompatible with the built-in TV set of Bertie's motorcycle.

Your task is to decode the stream and use the resulting video as input for solving different subtasks for Bertie.

Signal

There is a continuous stream of 8 bit, signed integers delivering frames. Frames are broken up into approx. NROWS rows, each row having about NCOLS pixels. Each pixel is described by a single intensity value found in the next 8 bit integer - intensities are positive, between 0 (black) and +127 (white).

   vintage television set
source: http://www.nowpublic.com/vintage_televison_set

Because of the inaccuracy of transmission, NROWS and NCOLS pixels can not be counted in number of samples; instead sync signals separate rows and frames. A sync signal is a continuous series of samples with value less than STHRS. Values between 0 and STHRS should be considered black pixels.

Each new row starts after the last sample of a horizontal-sync (hsync) signal not shorter than HSYNC_MIN and no longer than HSYNC_MAX. A new frame starts at the end of a vertical sync (vsync) signal which is longer than VSYNC_MIN and shorter than VSYNC_MAX. A vsync signal also functions as a hsync for the first row.

Constants:
name value description
NROWS 100 nominal number of rows
NCOLS 160 nominal number of columns
STHRS -32 sync signal threshold
HSYNC_MIN 2 minimal length of a hsync signal in number of samples
HSYNC_MAX 8 maximum length of a hsync signal in number of samples
VSYNC_MIN 9 minimal length of a vsync signal in number of samples
VSYNC_MAX 16 maximum length of a vsync signal in number of samples

F. TV - Maze (500 points)

The city Bertie needs to go through is a maze - quite literally. GPS is made impossible to use by local authorities. The only alternative is a special video stream service that (after registration) shows the map of the city with your current position marked. Your task is to find the way out, the path between the marked location and the border of the map and direct Bertie through the maze of narrow streets.

Input

A tv stream showing the map. White pixels are streets, black pixels are walls and a little grey area marks Bertie's current position.

Output

A series of single-character directions in one long line, each causing Bertie to move to the adjacent cell.
direction
character
meaning
n go north (up)
e go east (right)
s go south
w go west

Example

Input 0 can be decoded into
###########
#         #
### ##### #
# # #S  # #
# # ### # #
#       # G
###########
	
and one of the solutions is
eesswwwwnnnneeeeeesssse
	

G. TV - Count (500 points)

One of the TV channels broadcasted a strange program after the evening news. It showed the faces of all the politicians recently elected, being happy or sad. Bertie is interested in the general mood in the local parliament, because it is rumored that some new laws regarding motorbike traffic regulations are forthcoming - and he thinks happy politicians result in lenient laws.

Your task is count smiling and sad faces in recordings of the program.

Input

A tv stream showing faces.

Output

The output should contain two numbers separated by whitespace: first the number of happy faces then the number of sad faces.

H. TV - air defense stream (3000 points)

Bertie only got the visa necessary for this far away country by agreeing to a number of ridiculous demands. Some of these pertained to personal hygiene and other inconsequential trifles, but one has given him a bit of pause before he signed the necessary forms. It is apparently the custom of this country that for the duration of one day, he would be asked to participate in the defense efforts against the hated and villainous neighboring country.

As it turns out, the neighboring country has mounted a ferocious attack by air. Friendly airspace is swarming with enemy aircraft. The local ground-to-air defense arsenal may be adequate, but friend-or-foe identification is a problem.

The country has a number of TV cameras pointed towards the skies. An army of volunteers watches the screens, keeping their eyes peeled to sort friend from adversary. Their input data controls flak cannons and other assorted surprises.

Enemy aircraft look pretty similar to friendly ones - they even have the same sort of identification codes - but luckily, they prefer sleek, angled wings.

All aircraft are identified by a sort of barcode painted on their bodies. The barcode is read from nose to tail. A wide bar encodes a 1 bit, a narrow bar a 0 bit. The last bar (nearest to the tail) is a parity bit. If the count of 1 bits before it is even, it is narrow (0); if it's odd, it is wide (1) - thus, the number of wide bars in such a barcode is always even.

Bertie receives his live TV stream via UDP broadcast on UDP port 30002. He is requested to report his findings by TCP connection to server.ch24.org port 31000.

For every aircraft he sees and identifies, he should send via TCP (on a single line terminated by LF):

These commands will only work when the given aircraft is still visible - otherwise it's too late for air defense to do anything!

For every correctly identified plane, Bertie is rewarded 10 Cents of Courage - he is however penalized 1 Cent of Courage for every misidentified plane (which is a very good deal; people before have received harsher punishment for needlessly sending civilians to their deaths). One plane may be identified only once (correctly or incorrectly).

This task uses scaled scoring. Your team will receive a score given by comparing the number of Cents of Courage collected against other teams, the score scaled accordingly. The team who collects the most receives maximum score, which is XYZ. All teams receive the same TV stream, and see the same planes; but more than one team may identify a single plane (and all teams will get the proper score accordingly).

Note that this task may contain secrets, which may lead its finders to more Coins or other rewards.