This page is still under construction.

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

North North West

Interview

Time limit8sMemory limit512 MB

Summary
A direction string is built from copies of north and west; each prefix copy shifts the angle by 90/2^n, so compute the resulting angle as an integer or reduced fraction.
Level

Medium4 of 10

Topics
Math, String, Implementation, Simulation
Solved
No attempts yet

Problem

Repeating the names of directions describes a finer direction. For example, northwest is the direction halfway between north and west, and northnorthwest is the direction halfway between north and northwest.

This problem fixes the directions between north and west by the following rules.

  • "north" means 0 degrees.
  • "west" means 90 degrees.
  • If a direction string dir means aa degrees and the sum of the occurrences of "north" and "west" in dir is nn (n≥1n \ge 1), then "north"dir, the concatenation of "north" and dir, means a−902na - \frac{90}{2^n} degrees, and "west"dir means a+902na + \frac{90}{2^n} degrees.

Compute the angle in degrees that the given direction means.

Input

The input holds several datasets. The number of datasets does not exceed 100.

Each dataset is one line holding a string that denotes a direction. The string can be built by concatenating copies of "north" and "west", the sum of the occurrences of "north" and "west" in the string is between 1 and 20 inclusive, and the angle the string denotes is between 0 and 90 inclusive. A line holding only "#" follows the last dataset.

Output

For each dataset, print the angle that the direction means on its own line. Print an integer when the angle is an integer, and otherwise print the irreducible fraction p/q, where p and q are coprime positive integers and q is at least 2.

Examples1

  1. Example 1

    Input
    north
    west
    northwest
    northnorthwest
    westwestwestnorth
    #
    
    Expected output
    0
    90
    45
    45/2
    315/4