Professional Documents
Culture Documents
Contest Question
Contest Question
Task Description :
Shishir has sat for a violin test. He was very busy for programming contests in past few days, so
he isn't well prepared today.
It's a beginner level test and he doesn't even need to play his violin. Only thing he needs to do is
to identify whether the given piece is a correct
or not.
A piece is a collection of notes maintaining rythm. Rhythm is simply the timing of the musical
sounds and silences.Violin has only seven natural, 5 sharp and 5 flat notes.
Flats are out of his syllabus, so we don't need to consider them. So, Let's talk about the other 12
notes(both natural and sharps).
A piece can also contain rest (rest means silence) which will be denoted as R.
| A A E E | F F E R | D D C# C# | B B A R |
If every note in the above example has a value ( which is called 'beat' in music theory,so let's call
it beat instead of value) of 1, then any pair of bar lines ( | | ) contain exactly four beats . If this
piece misses one or two beats, it'll be incorrect.
This is the main characteristic of a correct piece that the sum of beats inside any pair of bars
must be same throughout the whole peice. In the above example, the sums are 4 4 4 4.
As Shishir is a beginner level student, no pair of bar line will contain more than 8 beats inside
them, and each pair of the bar line will contain at least a single note that's for sure.
Your task is to help Shishir to answer the question : is this piece correct?
You'll be given the number of notes and you need to identify whether a correct piece could be
formed using those notes.
Input format :
First line will contain the number N(2<=N<=100), the number of notes in the piece.
Then N line containing a note and it's duration in beat B(1/8<=B<=4)separated by a space.
output format:
One line, containing the string "YES" if it's a correct piece or "NO", if it's not.
INPUT :
16
A1
A1
E1
E1
F1
F1
E1
R1
D1
D1
C# 1
C# 1
B1
B1
A1
R1
OUTPUT:
YES
INPUT :
6
A2
B2
C# 2
C# 2
A1
A2
OUTPUT:
NO