Skip to main content
Back to problems
Codeforces
Easy
Math
Strings
Ilya and Bank Account

Given a bank account balance, remove at most one digit from its decimal representation to make the resulting number as large as possible.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Problem

Ilya has a bank account balance that may be negative. He is allowed to delete at most one digit from the decimal representation of the number in order to maximize the final value.

If the number is negative, removing a digit can change the magnitude and therefore the value. The goal is to choose the best possible digit to delete, or delete nothing if that is already optimal.

Return the maximum possible value after this operation.

Key idea

You are working with the number as a string of digits (with an optional leading -). The task is to try the best single deletion and keep the numerically largest outcome.

Input Format

The input contains a single integer xx.

  • xx may be positive or negative.
  • You may delete at most one digit from the decimal representation of xx.
  • If you delete a digit, the remaining digits stay in their original order.

Output Format

Print one integer — the maximum value that can be obtained after deleting at most one digit.

Constraints

  • xx fits in a 32-bit signed integer.
  • The absolute value of xx has no leading zeros in the input.
  • You may choose not to delete any digit.
Examples
Sample cases returned by the problem API.

Example 1

Input

512

Output

52

Explanation

Deleting 1 gives 52, which is larger than deleting any other digit or keeping the number unchanged.

Example 2

Input

-7605

Output

-605

Explanation

Since the number is negative, we want the value closest to zero. Deleting 7 gives -605, which is better than deleting any other digit.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.