#include <bits/stdc++.h>
using namespace std;
#define inf 99999999999999
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,i;
cin>>n;
int cost[n];
string a[n],b[n];
for(i=0;i<n;i++)cin>>cost[i];
for(i=0;i<n;i++){
cin>>a[i];
b[i]=a[i];
reverse(b[i].begin(),b[i].end());
}
int ans=0;
for(i=0;i<n-1;i++){
if(a[i+1]<a[i]){
long long c1=-99,c2=-99,c3=-99;
if(b[i]<a[i+1])c1=cost[i];else c1=inf;
if(b[i+1]>a[i])c2=cost[i+1];else c2=inf;
if(b[i]<b[i+1])c3=cost[i]+cost[i+1];else c3=inf;
if(c1 <= c2 && c1 <=c3 && c1!=inf){ans+=c1;if(c1==c2)a[i+1]=min(a[i+1],b[i+1]);}
else if(c2<=c1 && c2 <=c3 && c2!=inf){ans+=c2;a[i+1]=min(a[i+1],b[i+1]);}
else if(c3<=c1 && c3 <=c2 && c3!=inf){ans+=c3;a[i+1]=min(b[i+1],a[i+1]);}
else {cout<<-1;return 0;}
}
}
cout<<ans;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgaW5mIDk5OTk5OTk5OTk5OTk5CmludCBtYWluKCkgewoJaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CgljaW4udGllKE5VTEwpOwoJaW50IG4saTsKCWNpbj4+bjsKCWludCBjb3N0W25dOwoJc3RyaW5nIGFbbl0sYltuXTsKCWZvcihpPTA7aTxuO2krKyljaW4+PmNvc3RbaV07Cglmb3IoaT0wO2k8bjtpKyspewoJCWNpbj4+YVtpXTsKCQliW2ldPWFbaV07CgkJcmV2ZXJzZShiW2ldLmJlZ2luKCksYltpXS5lbmQoKSk7Cgl9CglpbnQgYW5zPTA7Cglmb3IoaT0wO2k8bi0xO2krKyl7CgkJaWYoYVtpKzFdPGFbaV0pewoJCQlsb25nIGxvbmcgYzE9LTk5LGMyP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