PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000019. Xóa chữ số để chia hết cho ba (Divide by Three)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Xóa chữ số để chia hết cho ba (Divide by Three)
Divide by Three
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a decimal representation of a positive integer without leading zeros, delete any digits while preserving the order of those retained. The result must be a nonempty decimal integer without leading zeros (except 0) divisible by . Delete as few digits as possible. Print any optimal result, or -1 if impossible.
Input
One line containing decimal string .
Output
Print any optimal valid result or -1.
Subtasks
- Subtask 1 (20 points): ;
- Subtask 2 (30 points): ;
- Subtask 3 (50 points): ;
Examples
Input
1234
Output
123
Explanation
The original digit sum is , not divisible by . Deleting 4 yields 123 with digit sum and only one deletion.