#P1200. [USACO1.1] 你的飞碟在这儿 Your Ride Is Here

[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 A\texttt A is 11 and Z\texttt Z is 2626. For example, the group USACO\texttt{USACO} yields 21×19×1×3×15=1795521 \times 19 \times 1 \times 3 \times 15 = 17955. If the group’s number mod47\bmod 47 equals the comet’s number mod47\bmod 47, you should tell the group to get ready to go! (Remember that "amodba \bmod b" is the remainder when aa is divided by bb; for example, 34mod1034 \bmod 10 equals 44.)

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 66 letters).

Input Format

Line 1: An uppercase string of length 11 to 66, the comet's name.

Line 2: An uppercase string of length 11 to 66, the group's name.

COMETQ
HVNGAT
GO
ABSTAR
USACO
STAY

Hint

Problem translation from NOCOW.

USACO Training Section 1.1.

Translated by ChatGPT 5