Stroop Effect
Time limit2sMemory limit512 MB
Given sequences of two-digit word-ink codes, check whether each sequence satisfies the counts and the no-three-in-a-row rule for a valid Stroop test.
- Level
Easy3 of 10
- Topics
- Implementation, Simulation, Array, Brute force
- Solved
- No attempts yet
Problem

The Stroop effect is a phenomenon that occurs when you must say the color of a word but not the name of the word. When the name of a color (e.g., "blue", "green", or "red") is printed in a color that is not denoted by the name (e.g., the word "red" printed in blue ink instead of red ink), naming the color of the word takes longer and is more prone to errors than when the color of the ink matches the name of the color. The effect is named after John Ridley Stroop, who first published the effect in English in 1935. The original paper has been one of the most cited papers in the history of experimental psychology, leading to more than 700 replications. The effect has been used to create a psychological test (Stroop test) that is widely used in clinical practice and investigation.
Stimuli in Stroop paradigms can be divided into 2 groups: congruent and incongruent. Congruent stimuli are those in which the ink color and the word refer to the same color (for example the word "red" written in red ink). Incongruent stimuli are those in which ink color and word differ (for example the word "blue" written in red ink). There are four primary colors in the Stroop test: blue, yellow, red, and green. In the Stroop test, stimuli from both groups are displayed one by one in random order. Each time one is displayed, the patient must respond with the correct color, not the word.
A sequence is a valid Stroop test stimulus if and only if it satisfies all of the following conditions.
- The number of congruent stimuli equals the number of incongruent stimuli, and there is at least one stimulus.
- In the congruent group, each of the four colors appears the same number of times. That is, the counts of 11, 22, 33, and 44 are all equal.
- In the incongruent group, each of the 12 word-ink combinations appears the same number of times.
- No three consecutive stimuli share the same word, and no three consecutive stimuli share the same ink color. Up to two in a row are allowed.
Each stimulus is given as a two-digit number. The first digit represents the word color and the second digit represents the ink color, and the digits 1 through 4 correspond to the four colors.
For example, a valid frequency table for 24 stimuli is as follows.
Out of 24 stimuli, 12 are congruent and 12 are incongruent, and each incongruent word-color combination appears once.
Given a sequence of two-digit numbers, determine whether it satisfies all of the conditions above.
Input
The first line of input gives the number of test cases, (), followed by test cases. Each test case is a sequence of two-digit integers whose digits are 1, 2, 3, or 4. Each sequence ends with the number 00, which is not part of the stimuli. The number of stimuli in each test case is not more than 500.
Output
For each test case, print one line in the format Case #x: result, where x is the case number starting from 1. The result is Stroop if the sequence satisfies all of the conditions, and Not Stroop otherwise.