fork(1) download
  1. def nine(s,l):
  2. for i in range(0,l):
  3. if s[i]!='9':
  4. return 0
  5. return 1
  6. t=int(input())
  7. while t!=0:
  8. n=int(input())
  9. s=str(n)
  10. l=len(s)
  11. if (nine(s,l)):
  12. print(n+2)
  13. else:
  14. if l%2==0:
  15. s1=s[:l//2-1]
  16. if int(s1+s[l//2-1]+s[l//2-1]+s1[::-1])>n:
  17. print(s1+s[l//2-1]+s[l//2-1]+s1[::-1])
  18. else:
  19. print(s1+str(int(s[l//2-1])+1)+str(int(s[l//2-1])+1)+s1[::-1])
  20. else:
  21. s1=s[:l//2]
  22. if int(s1+s[l//2]+s1[::-1])>n:
  23. print(s1+s[l//2]+s1[::-1])
  24. else:
  25. print(s1+str(int(s[l//2])+1)+s1[::-1])
  26. t-=1
  27.  
Runtime error #stdin #stdout #stderr 0.03s 27656KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 6, in <module>
EOFError: EOF when reading a line