Wrong Answer in Next Palindrome

Someone Please explain why am I getting Wrong Answer.Here is my code HNMn2G - Online C++ Compiler & Debugging Tool - Ideone.com
Sample Input:
38

123246

1234246

123659

9999

9

129999931

139999921

100

10000001

1000001

1

9

919

333999

33999

33399

9911

9991

911

199

1999

9876

987

1

9

0

8008

8007

1234

101

102

999

9999

998

948

1000

100

10001

Sample Output:

123321

1234321

124421

10001

11

139999931

139999931

101

10011001

1001001

2

11

929

334433

34943

33433

9999

9999

919

292

2992

9889

989

2

11

1

8118

8008

1331

111

111

1001

10001

999

949

1001

101

10101

your code gives wrong answer for this case , have a look

ideone link

129999931
ans is 130000031 i guess and not 139999931

1 Like