← Practice problem bank

Jan 13, 2026

The Enchanted Modulo Pathways

Daily Challenge Archive · Open

mediumdynamic programming

150 pts · 10000 ms · 128 MB · Practice only

Problem

Welcome to Modulosia, an enchanted realm where every path is woven with magical numbers. Your quest as a daring explorer is to traverse an array of integers, seeking the path that yields the highest value using special modulo rules. Begin your journey from any position in the array, which represents a magical waypoint. Your goal is to leap from one waypoint to another, but you can only jump if the number at your current position, when taken modulo the target index, results in a value greater than zero. This ensures that each step is not only strategic but also magical. To complete the challenge, identify the sequence of steps that maximizes the cumulative value of the journey. For example, consider an array [3, 6, 9, 2]. Starting from any position, calculate the modulo with potential target indices and decide the optimal path. Edge cases include arrays with negative numbers or zeros, which might affect the modulo operation.

Hints
  • Start by thinking about how you can evaluate each potential jump using modulo arithmetic.
  • Consider using dynamic programming to store intermediate results and improve efficiency.
  • A hash map might be useful to keep track of visited indices and their associated values.
  • Pay attention to edge cases such as when the array contains zero or negative numbers, as these can affect your modulo calculations.
  • Look for patterns that emerge from the modulo operations, as they might guide you to the optimal path.

Input format

The first line contains a single integer n (1 <= n <= 1000), the length of the array. The second line contains n integers, the elements of the array a_i (-1000 <= a_i <= 1000).

Output format

Output a single integer, the maximum value you can reach by traversing the enchanted pathways.

Constraints

1 <= n <= 1000, -1000 <= a_i <= 1000

Sample input

5
6 -7 14 -2 3

Sample output

14

Sign in to submit solutions

Run your code against all test cases and get instant feedback.

Sign in