P8716 [Lanqiao Cup 2020 NOI Qualifier AB2] Palindrome Date
Description
During the 2020 Spring Festival, a special date caught everyone’s attention: February 2, 2020. Because if we write this date in the `yyyymmdd` format as an $8$-digit number, it is `20200202`, which happens to be a palindrome. We call such dates palindrome dates.
Some people said that `20200202` is a “once in a thousand years” special day. Xiao Ming does not agree, because less than 2 years later, there is the next palindrome date: `20211202`, which is December 2, 2021.
Others said that `20200202` is not only a palindrome date, but also an `ABABBABA`-type palindrome date. Xiao Ming also does not agree, because after about $100$ years, you can meet the next `ABABBABA`-type palindrome date: `21211212`, which is December 12, 2121. It is not “once in a thousand years”, at most “twice in a thousand years”.
Given an $8$-digit date, please compute what day is the next palindrome date after this date, and what day is the next `ABABBABA`-type palindrome date after this date.
Input Format
The input contains an eight-digit integer $N$, representing a date.
Output Format
Output two lines, each with one eight-digit number. The first line is the next palindrome date. The second line is the next `ABABBABA`-type palindrome date.
Explanation/Hint
For all test cases, $10000101 \le N \le 92200229$, and it is guaranteed that $N$ is an $8$-digit number representing a valid date.
Lanqiao Cup 2020 Second Round Provincial Contest, Group A Problem G (Group B Problem G).
Translated by ChatGPT 5