Skip to main content
Back to problems
Codeforces
Easy
Arrays
Math
Inna and Alarm Clock

Find the earliest acceptable alarm time after shifting the clock by a fixed number of minutes.

Acceptance 0%
Problem Statement

Problem

Inna has an alarm clock that is set to ring at some time during the day. She wants to know how long she should wait until the clock shows a time whose minute component is divisible by a given number.

You are given the current time of the alarm clock in 24-hour format as hh:mm and a positive integer k. Each minute, the clock moves forward by one minute, wrapping from 23:59 to 00:00.

Your task is to determine the smallest non-negative number of minutes to add to the current time so that the resulting time has a minute value divisible by k.

This is a straightforward time simulation / arithmetic problem: check the current minute value, then move forward until the condition is satisfied.

Input Format

  • The first line contains a time in the format hh:mm.
  • The second line contains an integer k.

The time is given in 24-hour format with leading zeros.

Output Format

Print one integer — the minimum number of minutes that must be added to the given time so that the minute part of the new time is divisible by k.

Constraints

  • 00 <= hh <= 23
  • 00 <= mm <= 59
  • 1 <= k <= 60
  • The answer is always well-defined.
Examples
Sample cases returned by the problem API.

Example 1

Input

05:17
5

Output

3

Explanation

After 3 minutes, the time becomes 05:20 and the minute part 20 is divisible by 5.

Example 2

Input

23:59
60

Output

1

Explanation

One minute later the time becomes 00:00, and 0 is divisible by 60.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.