CF884F.Anti-Palindromize

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A string aa of length mm is called antipalindromic iff mm is even, and for each ii ( 1<=i<=m1<=i<=m ) aiami+1a_{i}≠a_{m-i+1} .

Ivan has a string ss consisting of nn lowercase Latin letters; nn is even. He wants to form some string tt that will be an antipalindromic permutation of ss . Also Ivan has denoted the beauty of index ii as bib_{i} , and the beauty of tt as the sum of bib_{i} among all indices ii such that si=tis_{i}=t_{i} .

Help Ivan to determine maximum possible beauty of tt he can get.

输入格式

The first line contains one integer nn ( 2<=n<=1002<=n<=100 , nn is even) — the number of characters in ss .

The second line contains the string ss itself. It consists of only lowercase Latin letters, and it is guaranteed that its letters can be reordered to form an antipalindromic string.

The third line contains nn integer numbers b1b_{1} , b2b_{2} , ..., bnb_{n} ( 1<=bi<=1001<=b_{i}<=100 ), where bib_{i} is the beauty of index ii .

输出格式

Print one number — the maximum possible beauty of tt .

输入输出样例

  • 输入#1

    8
    abacabac
    1 1 1 1 1 1 1 1
    

    输出#1

    8
    
  • 输入#2

    8
    abaccaba
    1 2 3 4 5 6 7 8
    

    输出#2

    26
    
  • 输入#3

    8
    abacabca
    1 2 3 4 4 3 2 1
    

    输出#3

    17
    
首页