Under construction

Still being built. Things may change

Date Cycle Calculation

Interview

Time limit2sMemory limit4 MB

Summary
Find the smallest year whose Earth, Sun, and Moon cycle counters, each resetting at fixed limits, match a given triple of values.
Level

Easy3 of 10

Topics
Simulation, Math, Brute force
Solved
No attempts yet

Problem

In Jun-gyu's country, years are represented differently from the calendar we usually use. A year in this country is written as three numbers, E, S, and M, representing the cycles of Earth, Sun, and Moon.

Each number has its own range.

  • 1 <= E <= 15
  • 1 <= S <= 28
  • 1 <= M <= 19

Year 1 in our calendar is written as 1 1 1 in this system. Every year, all three numbers increase by 1. If a number passes the end of its range, it becomes 1 again.

So year 15 is written as 15 15 15, but the next year, year 16, is written as 1 16 16 because E cannot exceed 15.

Given E, S, and M, determine which year in our calendar is represented by those three numbers. Print the earliest possible year.

Input

The first line contains three integers E, S, and M, separated by spaces. The input always satisfies the ranges above.

Output

Print the earliest year represented by E S M. Since 1 1 1 is always year 1, the answer is always positive.

Examples4

  1. Example 1

    Input
    1 16 16
    
    Expected output
    16
    
  2. Example 2

    Input
    1 1 1
    
    Expected output
    1
    
  3. Example 3

    Input
    1 2 3
    
    Expected output
    5266
    
  4. Example 4

    Input
    15 28 19
    
    Expected output
    7980