← All problemsSign in

Counting Is Fun

CodeChefRating 2787Open on judge ↗

Suppose $f(X, Y, Z)$ denotes the number of arrays $A$ of length $X$ such that: - $1 \leq A_i \leq Y$, for all $(1 \leq i \leq X)$; - There are **at most** $Z$ values of $i$ $(2 \leq i \leq X)$ such that $A_i=A_{i-1}$. In other words, for at most $Z$ indices, the element at a given index is equal to the previous element. You are given an integer $M$ and $Q$ queries. The $i^{th}$ query is of the f

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start