#GL0000171. Xóa các bội nhỏ nhất (Removing Smallest Multiples)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xóa các bội nhỏ nhất (Removing Smallest Multiples)
Removing Smallest Multiples
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Initially, the set contains . You may repeatedly choose if at least one multiple of remains in , and then delete the smallest multiple of still present in . This operation costs . The target subset is described by a binary string of length : 1 exactly when . Find the minimum total cost of turning into . Every 1 must remain, and every 0 must be removed.
Input
The first line contains . The second line contains a binary string of exactly length .
Output
Print one nonnegative integer: the minimum total operation cost.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
7
1101001
Output
11
Explanation
The target set is . Choose to delete (cost ), choose again to delete (cost ), and choose to delete (cost ). Total cost is , which is optimal.