Algorithm


A. Palindromic Times
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.

On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome.

In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment.

However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him.

Input

The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits.

Output

Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.

Examples
input
Copy
12:21
output
Copy
13:31
input
Copy
23:59
output
Copy
00:00



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

string s, h, m;

bool not_palindrome() {
  return h[0] == m[1] && h[1] == m[0];
}

string add(string s) {
  if(s[1] == '9') {
    ++s[0];
    s[1] = '0';
  } else {
    ++s[1];
  }
  return s;
}

int main() {
  cin >> s;

  h = s.substr(0, 2);
  m = s.substr(3, 2);

  do {
    m = add(m);
    if(m == "60") {
      m = "00";
      h = add(h);
    }
    if(h == "24")
      h = "00";
  } while(!not_palindrome());

  cout << h << ':' << m << endl;

  return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
12:21

Output

x
+
cmd
13:31
Advertisements

Demonstration


Codeforcess Solution Palindromic Times, A. Palindromic Times C,C++, Java, Js and Python , A. Palindromic Times,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+