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

Bài tập thuộc lộ trình

1 lộ trình

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 ss 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 33. Delete as few digits as possible. Print any optimal result, or -1 if impossible.

Input

One line containing decimal string ss.

Output

Print any optimal valid result or -1.

Subtasks

  • Subtask 1 (20 points): 1≤length⁡(s)≤121 \le \operatorname{length}(s) \le 12; s[0]≠0s[0] \ne 0
  • Subtask 2 (30 points): 1≤length⁡(s)≤20001 \le \operatorname{length}(s) \le 2000; s[0]≠0s[0] \ne 0
  • Subtask 3 (50 points): 1≤length⁡(s)≤1000001 \le \operatorname{length}(s) \le 100000; s[0]≠0s[0] \ne 0

Examples

Input

1234

Output

123

Explanation

The original digit sum is 1010, not divisible by 33. Deleting 4 yields 123 with digit sum 66 and only one deletion.