#P8716. Next Palindrome Dates

    ID: 21880 Type: Default 1000ms 256MiB

Next Palindrome Dates

Next Palindrome Dates

Given an 8-digit date in the format \(yyyymmdd\), find the next palindromic date and the next \(ABABBABA\)-type palindromic date strictly after the given date.

A palindromic date is a date such that when written as an 8-digit number it reads the same forwards and backwards. For example, the date 20200202 is palindromic because \(20200202 = 20200202\) when reversed.

An \(ABABBABA\)-type palindromic date is a palindromic date that follows the pattern \(A\,B\,A\,B\,B\,A\,B\,A\), meaning that the digits at positions 0, 2, 5, and 7 (using 0-indexing) are identical and the digits at positions 1, 3, 4, and 6 are identical. For example, 21211212 is an \(ABABBABA\)-type palindromic date because its digits are 2,1,2,1,1,2,1,2.

inputFormat

The input consists of a single line containing an 8-digit date in the format \(yyyymmdd\).

outputFormat

Output two lines: the first line contains the next palindromic date, and the second line contains the next \(ABABBABA\)-type palindromic date, both in the format \(yyyymmdd\).

sample

20200202
20211202

21211212

</p>