P1200 [USACO1.1] Your Ride Is Here

Description

As everyone knows, there is a UFO behind every comet. These UFOs often come to gather loyal supporters on Earth. Unfortunately, their saucer can take only one group of supporters on each trip. Therefore, they use a clever scheme to let the groups know in advance who will be taken by a comet. They give each comet a name and use these names to decide whether a particular group is the one to be taken (who do you think names these comets?). The details of how to match are given below; your task is to write a program that, given a group name and a comet name, decides whether the group will be taken by the UFO behind that comet. Both the group name and the comet name are converted into a number as follows: the final number is the product of the values of all letters in the name, where $\texttt A$ is $1$ and $\texttt Z$ is $26$. For example, the group $\texttt{USACO}$ yields $21 \times 19 \times 1 \times 3 \times 15 = 17955$. If the group’s number $\bmod 47$ equals the comet’s number $\bmod 47$, you should tell the group to get ready to go! (Remember that "$a \bmod b$" is the remainder when $a$ is divided by $b$; for example, $34 \bmod 10$ equals $4$.) Write a program that reads the comet name and the group name and determines whether the two names match under the scheme above. If they match, output `GO`; otherwise, output `STAY`. Both the group name and the comet name are strings of uppercase letters with no spaces or punctuation (at most $6$ letters).

Input Format

Line 1: An uppercase string of length $1$ to $6$, the comet’s name. Line 2: An uppercase string of length $1$ to $6$, the group’s name.

Output Format

N/A

Explanation/Hint

Problem translation from NOCOW. USACO Training Section 1.1. Translated by ChatGPT 5