1481: LYS 拿 HF 的U盘

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:25 Solved:1

Description

Input

Output

Sample Input Copy

5
10011
1 5 4 3 2

Sample Output Copy

8

HINT

1≤N≤1×10$^6$;1≤G≤1×10$^9$。