public class 回文日期 {
public static void main(String[] args) {
// 先判断是不是回文串在判断是不是日期
get();
}
public static void get(){
Scanner sr = new Scanner(System.in);
String s = sr.nextLine();
int date = Integer.parseInt(s);
int next = 0;
int nextAB = 0;
int times = 0;
int firstNext = 0;
for (date++;date <=89991231; date++){
if (huiwen(date) && isDate(date)) {
next = date;
times++;
if (isABhuiwen(date)) {
nextAB = date;
break;
}
if (times == 1)
firstNext = date;
}
}
System.out.println(Integer.toString(firstNext));
System.out.println(Integer.toString(nextAB));
}
private static boolean isABhuiwen(int date) {
//首先一定是回文了,只需要判断第一位是否和第三位相等,第二位是否和第四问相等即可。
String s = Integer.toString(date);
if(s.charAt(0) == s.charAt(2) && s.charAt(1) == s.charAt(3))
return true;
return false;
}
private static boolean isDate(int date) {
int year = date/10000;
int month = (date/100) %100;
int day = date % 100;
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){
if (day <= 31) return true;
}
else if (month == 2 || month == 4 || month == 6 || month == 9 || month == 11){
if ((year % 4 == 0 && year % 100 != 0) || year % 4 == 0){
if (day <= 29) {
return true;
} else {
if (day <= 28)
return true;
}
}
}
return false;
}
private static boolean huiwen(int date) {
String s = Integer.toString(date);
int i = 0;
int j = s.length()-1;
while (i <= j ){
if (s.charAt(i) != s.charAt(j))
return false;
i++;
j--;
}
return true;
}
}