#SP0000122. Xóa chữ số để tạo số nguyên tố (Prime Deletion)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xóa chữ số để tạo số nguyên tố (Prime Deletion)
Prime Deletion
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a sequence containing the nine digits through , each exactly once. You may delete digits from arbitrary positions, but may not delete when only two digits remain. The surviving digits must preserve their relative order.
Produce a remaining sequence representing a prime number. If multiple answers exist, any is accepted; print -1 if impossible.
Input
One line contains a length-nine string that is a permutation of digits 1 through 9.
Output
Print a subsequence of of length at least two, in original order, that represents a prime number; print -1 if impossible.
Subtasks
- Subtask 1 (100 points): ; is a permutation of exactly the digits .
Examples
Input
987654321
Output
31
Explanation
In 987654321, digit 3 occurs before 1. Delete the digits 9,8,7,6,5,4,2, keeping the ordered subsequence 31. The number is prime (it has no prime divisor at most ). Two digits remain, so the deletion rule is respected.