import java.util.*; import java.util.regex.*; import java.io.*; /** * Solution to Runes * * @author vanb */ public class runes_vanb { Scanner sc; PrintStream ps; public static final char digits[] = "0123456789".toCharArray(); public void doit() throws Exception { sc = new Scanner( System.in ); ps = System.out; String expression = sc.nextLine(); char e[] = expression.toCharArray(); // Find operator, = int oppos=0; // Operator position int eqpos=0; // Equals position for( int i=1; i1 ) okzero = false; else if( t2.charAt( 0 )=='?' && t2.length()>1 ) okzero = false; else if( t3.charAt( 0 )=='?' && t3.length()>1 ) okzero = false; else if( t2.startsWith( "-?" ) || t3.startsWith( "-?" ) ) okzero = false; // Go through all of the digits for( int d=okzero?0:1; d<10 && !itworks; d++ ) { digit = digits[d]; // If this digit appears anywhere in the expression, // then ? can't be this digit. Keep looking. if( expression.indexOf( digit )>=0 ) continue; try { long term1 = Long.parseLong( t1.replace( '?', digit ) ); long term2 = Long.parseLong( t2.replace( '?', digit ) ); long term3 = Long.parseLong( t3.replace( '?', digit ) ); long result=0; switch( op ) { case '+' : result = term1+term2; break; case '-' : result = term1-term2; break; case '*' : result = term1*term2; break; default: System.err.println( "PANIC!! op is " + op ); } itworks = (result==term3); } catch( NumberFormatException nfe ){} } ps.println( itworks ? (""+digit) : "-1" ); } public static void main( String[] args ) throws Exception { new runes_vanb().doit(); } }