Mock CCC '26 J5 - Crow Clash
View as PDFMock Canadian Computing Competition: 2026 Junior #5
Researcher Seagull Man is determined to prove, once and for all, that crows are not as intelligent as people claim to be. As part of his highly questionable research, he looks up into the sky and imagines it as a massive 2D grid.
On this grid, Seagull Man observes crows, where the
crow is initially at the integer coordinates
. The
crow is flying in one of four directions
, and it continues forever in that direction at a constant speed of
unit per second. The possible directions are:
N: North, where in one second the crow moves to the positionS: South, where in one second the crow moves to the positionE: East, where in one second the crow moves to the positionW: West, where in one second the crow moves to the position
Seagull Man defines a clash as the moment when a pair of crows occupy the exact same grid coordinate at the exact same time. The crows, being blissfully unaware of Seagull Man's research, do not change direction or behavior after a clash and simply continue flying as if nothing happened.
To strengthen his paper, Seagull Man wants to know: how many total clashes will occur among all the crows?
Given the number of crows, their starting positions, and their directions of movement, determine the total number of clashes that occur over all time.
Input Specification
The first line contains a single integer , the number of crows.
The next line lines will contain the character
, and integers
and
, representing the direction of movement and coordinates of the
crow. It is guaranteed that every crow occupies a distinct position initially.
The following table shows how the available 15 marks are distributed.
| Marks Awarded | Bounds on |
Bounds on |
Additional Constraints |
|---|---|---|---|
E or W (All crows are flying either east or west) | |||
E or W (All crows are flying either east or west) | |||
| None | |||
| None |
Output Specification
Output the number of clashes that will occur.
Please note that the answer is not guaranteed to fit in a -bit integer.
Sample Input 1
2
W 1 1
E -2 1
Output for Sample Input 1
1
Explanation of Output for Sample Input 1
Given that the first crow is red and the second crow is green, here is what the initial setup looks like:

At time equals seconds, the two crows will clash at
, thus resulting in a total of
clash. The following diagrams shows the clashes:

Sample Input 2
3
E -3 1
N 0 -2
S 0 3
Output for Sample Input 2
2
Explanation of Output for Sample Input 2
Given that the first crow is red, the second crow is green, and the third crow is blue, here is what the initial setup looks like:

When time equals seconds, crow
and crow
clash at
. When time equals
seconds, crow
and crow
clash at
. Therefore there will be
clashes in total. The following diagrams shows the clashes:

Sample Input 3
3
E -1 0
N 0 -1
S 0 1
Output for Sample Input 3
3
Explanation of Output for Sample Input 2
All three crows collide at . That means there are
clashes (pairs of crows colliding). The clashes are between crow
& crow
, crow
& crow
, and crow
& crow
.
Comments