Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/yonalishlar-orasidagi-burchak

Angle between directions

Medium 1000 ms 64 MB 46%
Share

A compass has eight directions: s (north), sq (north-east), q (east), jq (south-east), j (south), jg (south-west), g (west), sg (north-west); the angle between neighbouring directions is $45^\circ$. Two directions are given. Find the smaller angle between them in degrees (from $0$ to $180$).

A compass: eight directions, the two given ones shown by arrows, the smaller angle between them marked with an arc

Input

One line with two words — the directions.

Output

One integer — the angle in degrees.

Note

Each direction is one of the eight above.

Examples

Input #1
sq j
Output #1
135
Input #2
g sg
Output #2
45

Sign in to submit a solution

Signing up is free and takes a minute.