public static void main(String args[] ) throws Exception {
        /*
         * Read input from stdin and provide input before running
*/

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        char[] palindrom = line.toCharArray();
        boolean isPalindrom = true;

        BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
        String line1 = br1.readLine();
        int aCost = Integer.parseInt(line1);
        
        BufferedReader br2 = new BufferedReader(new InputStreamReader(System.in));
        String line2 = br2.readLine();
        int bCost = Integer.parseInt(line2);

        int sum = 0;
        
        for (int i = 0; i < palindrom.length/2; i++) {
        	
        	if(palindrom[i]==SLASH){
        		if(palindrom[palindrom.length-1-i]==A){
        			sum = sum + aCost;
        		} else {
        			sum = sum + bCost;
        		}
        		palindrom[i]=palindrom[palindrom.length-1-i];
        	} else if(palindrom[palindrom.length-1-i]==SLASH){
        		if(palindrom[i]==A){
        			sum = sum + aCost;
        		} else {
        			sum = sum + bCost;
        		}
        		palindrom[palindrom.length-1-i]=palindrom[i];
        	} else if(palindrom[i]==SLASH && palindrom[palindrom.length-1-i]==SLASH){
        		sum = sum + Math.min(aCost,bCost);
        	}

        	if(palindrom[i]!=palindrom[palindrom.length-1-i]){
            	isPalindrom = false;
            	break;
            } 
            
        }

        if(isPalindrom)
        	System.out.println(sum);
        else 
        	System.out.println("-1");
    }