#C7700. Reverse Integer

    ID: 51601 Type: Default 1000ms 256MiB

Reverse Integer

Reverse Integer

Given an integer x, your task is to reverse its digits.

The reversed integer must lie within the 32-bit signed integer range \(\left[-2^{31}, 2^{31}-1\right]\). If the reversed integer overflows this range, output 0.

Note: If x is negative, the reversed number should also be negative.

For example:

  • If x = 123, the output should be 321.
  • If x = -123, the output should be -321.
  • If x = 120, the output should be 21.

The problem requires careful handling to avoid integer overflow.

inputFormat

The input consists of a single integer x provided via standard input.

outputFormat

Output a single integer which is the reversed form of x. If the reversed integer is not within the 32-bit signed integer range, output 0.

## sample
123
321