A. Chord

Codeforces
IDCF88A
Time2000ms
Memory256MB
Difficulty
brute forceimplementation
English · Original
Chinese · Translation
Formal · Original
Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: _C_, _C#_, _D_, _D#_, _E_, _F_, _F#_, _G_, _G#_, _A_, _B_, _H_. He also knows that the notes are repeated cyclically: after _H_ goes _C_ again, and before _C_ stands _H_. We will consider the _C_ note in the row's beginning and the _C_ note after the _H_ similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between _C_ and _E_ is 4 semitones and between _E_ and _C_ is 8 semitones Vasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor. Let's define a major triad. Let the triad consist of notes _X_, _Y_ and _Z_. If we can order the notes so as the distance along the musical scale between _X_ and _Y_ equals 4 semitones and the distance between _Y_ and _Z_ is 3 semitones, then the triad is major. The distance between _X_ and _Z_, accordingly, equals 7 semitones. A minor triad is different in that the distance between _X_ and _Y_ should be 3 semitones and between _Y_ and _Z_ — 4 semitones. For example, the triad "_C E G_" is major: between _C_ and _E_ are 4 semitones, and between _E_ and _G_ are 3 semitones. And the triplet "_C# B F_" is minor, because if we order the notes as "_B C# F_", than between _B_ and _C#_ will be 3 semitones, and between _C#_ and _F_ — 4 semitones. Help Vasya classify the triad the teacher has given to him. ## Input The only line contains 3 space-separated notes in the above-given notation. ## Output Print "_major_" if the chord is major, "_minor_" if it is minor, and "_strange_" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously. [samples]
Vasya 正在学习音乐。 他已经学到了许多有趣的知识。例如,他知道共有 12 个音符:_C_、_C#_、_D_、_D#_、_E_、_F_、_F#_、_G_、_G#_、_A_、_B_、_H_。他还知道这些音符是循环重复的:_H_ 之后是 _C_,_C_ 之前是 _H_。我们将乐谱开头的 _C_ 和 _H_ 之后的 _C_ 视为相同,并将它们等同看待。音符之间的距离以全音为单位度量:相邻两个音符之间恰好是一个半音,即 0.5 全音。距离从最低音到最高音计算,即 _C_ 到 _E_ 的距离是 4 个半音,而 _E_ 到 _C_ 的距离是 8 个半音。 Vasya 也知道和弦是什么。和弦是不少于三个音符的无序集合。但目前 Vasya 只处理三和弦,即恰好由三个音符组成的和弦。他已能区分两种三和弦——大三和弦与小三和弦。 定义大三和弦:设该和弦由音符 #cf_span[X]、#cf_span[Y] 和 #cf_span[Z] 组成。如果能将这些音符排序,使得 #cf_span[X] 与 #cf_span[Y] 之间的距离为 4 个半音,且 #cf_span[Y] 与 #cf_span[Z] 之间的距离为 3 个半音,则该和弦为大三和弦。此时,#cf_span[X] 与 #cf_span[Z] 之间的距离为 7 个半音。 小三和弦的区别在于:#cf_span[X] 与 #cf_span[Y] 之间的距离应为 3 个半音,而 #cf_span[Y] 与 #cf_span[Z] 之间的距离为 4 个半音。 例如,和弦 "_C E G_" 是大三和弦:_C_ 与 _E_ 之间是 4 个半音,_E_ 与 _G_ 之间是 3 个半音。而三音组 "_C# B F_" 是小三和弦,因为若将音符排序为 "_B C# F_",则 _B_ 与 _C#_ 之间是 3 个半音,_C#_ 与 _F_ 之间是 4 个半音。 帮助 Vasya 判断老师给他的三和弦类型。 仅一行,包含三个用空格分隔的音符,使用上述记号。 如果和弦是大三和弦,输出 "_major_";如果是小三和弦,输出 "_minor_";如果老师给的和弦既不是大三也不是小三,则输出 "_strange_"。Vasya 向你保证答案总是明确的,即不存在同时是大三和弦和小三和弦的和弦。 ## Input 仅一行,包含三个用空格分隔的音符,使用上述记号。 ## Output 如果和弦是大三和弦,输出 "_major_";如果是小三和弦,输出 "_minor_";如果老师给的和弦既不是大三也不是小三,则输出 "_strange_"。Vasya 向你保证答案总是明确的,即不存在同时是大三和弦和小三和弦的和弦。 [samples]
Let the 12 musical notes be represented as elements of $\mathbb{Z}_{12}$, where: $$ \begin{aligned} &\text{C} \mapsto 0, \quad \text{C\#} \mapsto 1, \quad \text{D} \mapsto 2, \quad \text{D\#} \mapsto 3, \quad \text{E} \mapsto 4, \quad \text{F} \mapsto 5, \\ &\text{F\#} \mapsto 6, \quad \text{G} \mapsto 7, \quad \text{G\#} \mapsto 8, \quad \text{A} \mapsto 9, \quad \text{B} \mapsto 10, \quad \text{H} \mapsto 11. \end{aligned} $$ Given three notes $a, b, c \in \mathbb{Z}_{12}$, define the set $S = \{a, b, c\}$. Let $x_0 < x_1 < x_2$ be the sorted representatives of $S$ in the cyclic order modulo 12, considering the circular nature: the distances are computed as the minimal clockwise steps. Define the three pairwise clockwise distances between consecutive notes (in sorted cyclic order): $$ d_1 = (x_1 - x_0) \mod 12, \quad d_2 = (x_2 - x_1) \mod 12, \quad d_3 = (x_0 + 12 - x_2) \mod 12. $$ Since the chord is a triad, exactly one of the three cyclic orderings yields a valid sequence of two adjacent intervals summing to 7 semitones (the third interval being 5 semitones, completing the circle). But for triads, we only consider the two intervals forming the stack (i.e., skip the wrap-around). Actually, since the chord is unordered and we are to find *any* permutation of the three notes such that the two consecutive intervals are (4,3) for major or (3,4) for minor, we can do the following: Let $T = \{a, b, c\}$. For each of the 6 permutations $(p_1, p_2, p_3)$ of $T$, compute: $$ d_1 = (p_2 - p_1) \mod 12, \quad d_2 = (p_3 - p_2) \mod 12. $$ If $d_1 = 4$ and $d_2 = 3$, then it is a **major** triad. If $d_1 = 3$ and $d_2 = 4$, then it is a **minor** triad. If no permutation satisfies either, output **strange**. Note: The third interval $d_3 = (p_1 - p_3) \mod 12$ is always $12 - d_1 - d_2$, and we do not need to check it. **Formal Statement:** Let $S \subset \mathbb{Z}_{12}$ with $|S| = 3$. Let $\mathcal{P}$ be the set of all ordered triples $(x, y, z)$ formed by permuting the elements of $S$. Define: $$ \text{major} \iff \exists (x, y, z) \in \mathcal{P} \text{ such that } (y - x) \mod 12 = 4 \text{ and } (z - y) \mod 12 = 3 \\ \text{minor} \iff \exists (x, y, z) \in \mathcal{P} \text{ such that } (y - x) \mod 12 = 3 \text{ and } (z - y) \mod 12 = 4 $$ Output: - "major" if major condition holds, - "minor" if minor condition holds, - "strange" otherwise.
Samples
Input #1
C E G
Output #1
major
Input #2
C# B F
Output #2
minor
Input #3
A B H
Output #3
strange
API Response (JSON)
{
  "problem": {
    "name": "A. Chord",
    "description": {
      "content": "Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: _C_, _C#_, _D_, _D#_, _E_, _F_, _F#_, _G_, _G#_, _A_, _B_, _H_. He also knows that the no",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF88A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Vasya studies music.\n\nHe has learned lots of interesting stuff. For example, he knows that there are 12 notes: _C_, _C#_, _D_, _D#_, _E_, _F_, _F#_, _G_, _G#_, _A_, _B_, _H_. He also knows that the no...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Vasya 正在学习音乐。\n\n他已经学到了许多有趣的知识。例如,他知道共有 12 个音符:_C_、_C#_、_D_、_D#_、_E_、_F_、_F#_、_G_、_G#_、_A_、_B_、_H_。他还知道这些音符是循环重复的:_H_ 之后是 _C_,_C_ 之前是 _H_。我们将乐谱开头的 _C_ 和 _H_ 之后的 _C_ 视为相同,并将它们等同看待。音符之间的距离以全音为单位度量:相邻两个音符之...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "Let the 12 musical notes be represented as elements of $\\mathbb{Z}_{12}$, where:\n\n$$\n\\begin{aligned}\n&\\text{C} \\mapsto 0, \\quad \\text{C\\#} \\mapsto 1, \\quad \\text{D} \\mapsto 2, \\quad \\text{D\\#} \\mapsto...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments