← Practice problem bank

Jan 3, 2026

The Modulo Maze Explorer

Daily Challenge Archive · Open

easymath

100 pts · 10000 ms · 128 MB · Practice only

Problem

Welcome to the Modulo Maze Explorer! Imagine embarking on an adventure through a maze where each twist and turn is dictated by numbers. Your task is to determine your final destination using the power of modulo operations. Here's how to tackle this challenge: you are provided with a list of integers, each representing steps within the maze. The objective is to calculate the total sum of these steps and then apply the modulo operation with a specified divisor to pinpoint your final position within the maze. For instance, if your steps result in a sum of 17 and your divisor is 5, applying the modulo operation gives you 17 % 5 = 2, meaning you land at position 2. Consider edge cases like negative numbers or when the divisor is larger than the sum.

Hints
  • Approach suggestions: Think about how addition and modulo operations work together, and remember that negative numbers behave differently in modulo arithmetic.
  • Algorithm/data structure hints: Using a loop to iterate through the list and a variable to accumulate the sum can be effective.
  • Edge cases to consider: What happens if all numbers are negative? What if the list is empty?
  • Optimization tips: Try to minimize the number of operations by combining steps logically and remember that the modulo operation is computationally inexpensive.

Input format

The first line contains two integers, n and m, where n is the number of elements in the list and m is the modulo value. The second line contains n integers, representing the elements of the maze.

Output format

Output a single integer, the final position in the modulo sequence after summing and applying the modulo operation.

Constraints

1 <= n <= 1000, 1 <= m <= 1000, 0 <= element <= 1000

Sample input

5 3
1 2 3 4 5

Sample output

0

Sign in to submit solutions

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

Sign in