#K45367. Pedestrian Waiting Time Calculation

    ID: 27738 Type: Default 1000ms 256MiB

Pedestrian Waiting Time Calculation

Pedestrian Waiting Time Calculation

In this problem, you are given the current time in a traffic light cycle and a signal indicating whether a pedestrian has pressed the button to cross the street. The traffic light cycle lasts (T = 140) seconds and consists of three phases:

  • Red phase: (0 \le t < 60) seconds.
  • Green phase: (60 \le t < 135) seconds.
  • Yellow phase: (135 \le t < 140) seconds.

When the button is pressed (denoted by 1), if the current phase is the red phase, the pedestrian can cross immediately and the waiting time is 0 seconds. Otherwise, the pedestrian must wait until the end of the current cycle before they can cross, i.e. the waiting time is (140 - t), where (t = current_time \mod 140). If the button is not pressed (denoted by 0), the waiting time is 0 seconds regardless of the time.

Your task is to implement a program that reads the current time and the button status from standard input and outputs the corresponding waiting time to standard output.

inputFormat

The input consists of two space-separated values in one line:

  • An integer (current_time) representing the current time in seconds within the traffic light cycle ((0 \le current_time < \infty)).
  • An integer which is either 1 (button pressed) or 0 (button not pressed).

outputFormat

Output a single integer representing the number of seconds the pedestrian needs to wait.## sample

15 1
0