Jul 1,2026
Component Library
The underlying headless component library..
competitive-programming
game-of-codes
INSEA
FST-Settat
teamwork
algorithms
problem-solving
Published February 8, 2026
Breakdown and solution for Problem C of Game of Codes 4 at INSEA: determining if a carpet tile sequence is harmonious.
Game of Codes 4 · INSEA, Rabat, Morocco · February 08, 2026
This is one of the problems our team Hmama Miyта tackled during the contest. It turns out to be an elegant little problem hiding behind a beautiful cultural setting — Jihad, a master carpet weaver from the medina of Fes.
Jihad creates Moroccan carpets represented as a sequence of colored tiles. A carpet pattern is called harmonious if it can be split into exactly two parts where both parts contain the same number of each color tile.
Given a carpet pattern, determine if it's harmonious.
Print YES if the pattern is harmonious, NO otherwise.
The problem note gives it away: a pattern is harmonious if and only if every color appears an even number of times.
If every color count is even, we can always split each color's tiles equally between the two parts — regardless of tile order.
This simplifies the problem dramatically. We don't need to think about how to partition — only whether the counts allow it.
Suppose every color appears times. For a valid split into two equal parts, each part must contain exactly tiles of color . This is only an integer when is even. Conversely, if all are even, such a split is always constructible:
Count frequencies — for each color, count how many times it appears.
Check parity — if any color has an odd frequency, output NO. Otherwise
output YES.
from collections import Counter
n = int(input())
tiles = list(map(int, input().split()))
freq = Counter(tiles)
if all(count % 2 == 0 for count in freq.values()):
print("YES")
else:
print("NO")
Don't overthink it. This problem might tempt you to simulate actual splits or use dynamic programming. The note in the problem statement reveals the clean equivalence — always read the notes!
This was a quick solve for us during the contest — a clean, satisfying problem that rewards reading carefully. The cultural framing around Moroccan carpet weaving gave it a lovely flavor that matched the INSEA setting perfectly.
Problems like this are a good reminder: the most elegant solutions often come from reformulating the question, not from implementing the naive approach.
Part of our Game of Codes 4 series — see the main article for the full contest recap.
Jul 1,2026
The underlying headless component library..
competitive-programming
game-of-codes
INSEA
FST-Settat
teamwork
algorithms
problem-solving
Feb 1,2026
How our team "Hmama Miyта" competed at the 4th edition of the Game of Codes Competitive Programming Contest at INSEA.
competitive-programming
game-of-codes
INSEA
FST-Settat
teamwork
algorithms
problem-solving