PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000171. Xóa các bội nhỏ nhất (Removing Smallest Multiples)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

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 SS contains 1,2,…,n1,2,\ldots,n. You may repeatedly choose 1≤k≤n1\le k\le n if at least one multiple of kk remains in SS, and then delete the smallest multiple of kk still present in SS. This operation costs kk. The target subset TT is described by a binary string ss of length nn: si=s_i= 1 exactly when i∈Ti\in T. Find the minimum total cost of turning SS into TT. Every 1 must remain, and every 0 must be removed.

Input

The first line contains nn. The second line contains a binary string ss of exactly length nn.

Output

Print one nonnegative integer: the minimum total operation cost.

Subtasks

  • Subtask 1 (20 points): 1≤n≤1001 \le n \le 100.
  • Subtask 2 (30 points): 1≤n≤1041 \le n \le 10^4.
  • Subtask 3 (50 points): 1≤n≤1061 \le n \le 10^6.

Examples

Input

7
1101001

Output

11

Explanation

The target set is T={1,2,4,7}T=\{1,2,4,7\}. Choose k=3k=3 to delete 33 (cost 33), choose k=3k=3 again to delete 66 (cost 33), and choose k=5k=5 to delete 55 (cost 55). Total cost is 1111, which is optimal.