import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    static class Reader {
        private BufferedReader br;
        private StringTokenizer token;

        protected Reader(InputStream obj) {
            br = new BufferedReader(new InputStreamReader(obj));
            token = null;
        }
        protected String next() {
            while (token == null || !token.hasMoreElements()) {
                try {
                    token = new StringTokenizer(br.readLine());
                } catch (IOException e) {e.printStackTrace();}
            }
            return token.nextToken();
        }
        protected int[] nextIntArr(int n) {
            int[] arr = new int[n];
            for (int i=0; i<n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }
        protected int nextInt() {return Integer.parseInt(next());}
    }

    public static void main(String[] args) throws IOException {
        Reader in = new Reader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a = in.nextInt(), b = in.nextInt();
        if (((a*b)&1) == 0) out.printf("%s\n", "Even");
        else out.printf("%s\n", "Odd");
        out.close();
    }
}


import java.util.Scanner;

/**
 * http://abc086.contest.atcoder.jp/tasks/abc086_a
 */
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		System.out.println(a*b%2==1 ? "Odd" : "Even");

	}

}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 100 points

Problem Statement

AtCoDeer the deer found two positive integers, a and b.
Determine whether the product of a and b is even or odd.

Constraints

1 ≤ a,b ≤ 10000

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

If the product is odd, print Odd; if it is even, print Even.

Sample Input 1

3 4

Sample Output 1

Even

As 3 × 4 = 12 is even, print Even.

Sample Input 2

1 21

Sample Output 2

Odd

As 1 × 21 = 21 is odd, print Odd.

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int y=sc.nextInt();
		for(int i=0; i<=n; i++) {
			for(int j=0; j<=n; j++) {
				if(i+j>n) continue;
				for(int k=0; k<=n; k++) {
					if(i+j+k>n) continue;
					if(10000*i + 5000*j + 1000*k == y) {
						System.out.println(i+" "+j+" "+k);
						sc.close();
						return;
					}
				}
			}
		}
		System.out.println("-1 -1 -1");
		sc.close();
	}
}

Score : 300 points

Problem Statement

The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.

According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.

Constraints

1 ≤ N ≤ 2000

1000 ≤ Y ≤ 2 × 10^7

N is an integer.

Y is a multiple of 1000.

Input

Input is given from Standard Input in the following format:

N Y

Output

If the total value of N bills cannot be Y yen, print -1 -1 -1.

If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed.

Sample Input 1

9 45000

Sample Output 1

4 0 5

If the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9 bills and 45000 yen in total. It is also possible that the envelope contained 9 5000-yen bills, so the output 0 9 0 is also correct.

Sample Input 2

20 196000

Sample Output 2

-1 -1 -1

When the envelope contained 20 bills in total, the total value would be 200000 yen if all the bills were 10000-yen bills, and would be at most 195000 yen otherwise, so it would never be 196000 yen.

Sample Input 3

1000 1234000

Sample Output 3

14 27 959

There are also many other possibilities.

Sample Input 4

2000 20000000

Sample Output 4

2000 0 0


import java.io.*;
import java.math.*;
import java.util.*;
public class Main { //CASH MONEY

	public static void main(String[] args) { //Ball out dawg
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long N = I.nextLong();
		long Y = I.nextLong();
		long x = -1;
		long y = -1;
		long z = -1;
		boolean good=false;
		for (long a = 0; a<=2000; a++) {
			for (long b = 0; b <= 2000; b++) {
				long cur = a*1000+b*5000;
				if (Y-cur>=0) {
					long diff = Y-cur;
					if ((N-a-b)*10000==diff) {
						x=a;
						y=b;
						z=N-a-b;
						good=true;
						break;
					}
				}
			}
			if (good) break;
		}
		O.p(z+" "+y+" "+x);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0)
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}


import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int Y = sc.nextInt();
    for (int i =0; i<=N; i++) {
      for (int j =0; j<=N-i; j++) {
        int k = N - i - j;
        if (i * 10000 + j * 5000 + k * 1000 == Y) {
          System.out.println(i + " " + j + " " + k);
          return;
        }
      }
    }
    System.out.println("-1 -1 -1");
  }
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int y = sc.nextInt();

        for (int i = 0; i <= n; i++) {
            for (int j = 0; j + i <= n; j++) {

                int k = n - i - j;
                int total = 10000 *i + 5000*j + 1000*k;
                if (total == y) {
                    System.out.println(i+" "+j+" "+k);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");

    }
}


import java.util.*;
import static java.lang.System.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int y = sc.nextInt();
		int[] ans = {-1, -1, -1};
		for(int i = 0; i <= n; i++) {
			for(int j = 0; j <= n; j++) {
				int ten = i;
				int five = j;
				int one = n - (ten + five);
				if (one < 0)  break;
				int value = ten * 10000 + five * 5000 + one * 1000;
				if (value == y) {
					ans[0] = ten;
					ans[1] = five;
					ans[2] = one;
				}
			}
		}

		for(int i: ans)
			out.print(i + " ");

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int y = sc.nextInt();

        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n - i; j++) {
                int k = n - j - i;
                if (10000 * i + 5000 * j + 1000 * k == y) {
                    System.out.println(i + " " + j + " " + k);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }

}


import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number, one, five, ten, value;
    boolean flag = true;
    number = Integer.parseInt(sc.next());
    value = Integer.parseInt(sc.next());
    for(ten = 0; ten <= number; ten++) {
      for(five = 0; five <= number - ten; five++) {
        one = number - ten - five;
        if(one * 1000 + five * 5000 + ten * 10000 == value) {
          flag = false;
          System.out.println(ten + " " + five + " " + one);
          return;
        }
      }
    }
    if(flag) System.out.println("-1 -1 -1");
  }
}


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int y = sc.nextInt();
		for(int im=0;n+1>im;im++) {
			int x=0;
			x=(10000*im);
			if(x==y&&im==n) {
				System.out.println(String.valueOf(im)+" "+"0"+" "+"0");
				System.exit(0);
			}
			for(int gs=0;n+1>gs;gs++) {
				x=0;
				x=(10000*im)+(5000*gs);
				if(x==y&&im+gs==n) {
					System.out.println(String.valueOf(im)+" "+String.valueOf(gs)+" "+"0");
					System.exit(0);
				}

				for(int s=0;n+1>s;s++) {
					x=0;
					x=(10000*im)+(5000*gs)+(1000*s);
					if(x==y&&im+gs+s==n) {
						System.out.println(String.valueOf(im)+" "+String.valueOf(gs)+" "+String.valueOf(s));
						System.exit(0);
					}

				}
			}
		}
		System.out.println("-1 -1 -1");
		//List<Integer> list=new ArrayList<Integer>();

	}

}


import java.util.*;

class Main {

  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int Y = sc.nextInt();
    for (int a = 0; a <= N; a++) {
      for (int b = 0; a + b <= N; b++) {
        int c = N - (a + b);
        if (10000 * a + 5000 * b + 1000 * c == Y) {
          System.out.println(a + " " + b + " " + c);
          return;
        }
      }
    }
    System.out.println("-1 -1 -1");
  }
}


import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int y = sc.nextInt();

        int a = -1;
        int b = -1;
        int c = -1;

        for(int i=0; i<=n; i++){
        	for(int j=0; j<=n-i; j++){
                if(10000*i+5000*j+1000*(n-i-j) == y){
                    a = i;
                    b = j;
                    c = n-i-j;
                    break;
                }
            }
        }
        System.out.print(a+" "+b+" "+c);
    }
}


import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int Y = sc.nextInt() / 1000;
    for (int i = 0; i <= Y / 10; i++) {
      for (int j = 0; j <= Y / 5; j++) {
        if (i * 10 + j * 5 > Y || i + j > N) {
          break;
        }
        for (int k = 0; k <= Y; k++) {
          if (i * 10 + j * 5 + k > Y || i + j + k > N) {
            break;
          }
          if (i * 10 + j * 5 + k == Y && i + j + k == N) {
            System.out.println(String.format("%d %d %d", i, j, k));
            return;
          }
        }
      }
    }
    System.out.println("-1 -1 -1");
  }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);

		int N = sc.nextInt();
		int Y = sc.nextInt();

		Y /= 1000;

		for (int x = 0; x <= N; x++) {
			for (int y = 0; x + y <= N; y++) {
				for (int z = 0; x + y + z <= N; z++) {
					if (Y == 10*x + 5 * y + z) {
						System.out.println(x + " " + y + " " + z);
						return;
					}
				}
			}
		}

		System.out.println("-1 -1 -1");

	}

	static class FastScanner {

		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;

	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }

	}

}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n, y;
		n = sc.nextInt();
		y = sc.nextInt();

		sc.close();

		y /= 1000;

		int x = -1, z = -1, ans = -1;

		for(int i = 0; i <= n; ++i) {
			for(int j = 0; j + i <= n; ++j) {
				int tmp = y - 5 * i - 10 * j;
				if(tmp + i + j == n && tmp >= 0) {
					x = i;
					z = j;
				}
			}
		}
		if(x != -1)ans = y - 5 * x - 10 * z;
		System.out.println(z + " " + x + " " + ans);
	}

}


import java.io.File;
import java.io.IOException;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		File file = new File("input.txt");
		Scanner sc = new Scanner(file);

		//Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int Y = sc.nextInt();

		for(int x = 0; x <= N; x++){
			if(10000 * x > Y) continue;
			for(int y = 0; y <= N - x; y++){
				int z = N - x - y;
				int xx = 10000 * x;
				int yy = 5000 * y;
				int zz = 1000 * z;
				if(xx + yy + zz == Y){
					System.out.println(x + " " + y + " " + z);
					//System.out.println(xx + " " + yy + " " + zz);
					return;
				}
			}
		}

		System.out.println("-1 -1 -1");
	}
}


import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int y = scan.nextInt();
    boolean flag = false;

    outside:for(int i = 0; i <= n; i++){
      for(int j = 0; j <=n-i; j++){
        if(10000*i + 5000*j + 1000*(n-i-j) == y){
          System.out.println(i + " " + j + " " + (n-i-j));
          flag = true;
          break outside;
        }
      }
    }
    if(flag == false){System.out.println((-1) + " " + (-1) + " " + (-1));}
  }
}


import java.util.*;

public class Main {

	public static void main(
			String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int y = sc.nextInt();
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				if (i + j > n) {
					break;
				}
				if ((n - i - j) * 10000 + j * 5000 + i * 1000 == y) {
					System.out.println((n - i - j) + " " + j + " " + i);
					return;
				}
			}
		}
		System.out.println("-1 -1 -1");
	}
}


import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Y = sc.nextInt() / 1000;
		for (int x=0; x<=2000; x++) {
			for (int y=0; y<=4000; y++) {
				int z = N - x - y;
				if (z >= 0 && 10*x + 5*y + z == Y) {
					System.out.println(String.format("%d %d %d", x, y, z));
					return;
				}
			}
		}
		System.out.println("-1 -1 -1");
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = ni();

		long h = ni();

		long a[] = new long[n];
		long b[] = new long[n];
		long count = 0;

		for (int i = 0; i < n; i++) {
			a[i] = nl();
			b[i] = nl();
		}
		a = sort(a);
		b = sort(b);

		for (int i = n - 1; i >= 0; i--) {
			if (b[i] < a[n - 1]) {
				break;
			}
			h -= b[i];
			count++;
			if (h <= 0) {
				out(count);
				return;
			}
		}

		count += h / a[n - 1];
		if (h % a[n - 1] != 0) {
			count++;
		}
		out(count);
		//		for (;;) {
		//			h -= a[n - 1];
		//			count++;
		//			if (h <= 0) {
		//				out(count);
		//				return;
		//			}
		//		}
	}

	/*
	 * 以下メソッド集
	 */
	static int[] sort(int[] n) {
		Arrays.sort(n);
		return n;
	}

	static void debug() {
		out("---");
	}

	static void debug(long a) {
		out("-------");
		out(a);
		out("-------");
	}

	static void debug(String a) {
		out("-------");
		out(a);
		out("-------");
	}

	static long[] sort(long[] n) {
		Arrays.sort(n);
		return n;
	}

	static int ketasuu(int n) {
		String str = "" + n;
		return str.length();
	}

	static int account(String str) {
		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static double nd() {
		return sc.nextDouble();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void out(Object obj) {
		System.out.println(obj.toString());
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static double max(double d, double e) {
		return Math.max(d, e);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static long min(long d, long e) {
		return Math.min(d, e);
	}

	static int min(int a, int b) {
		return (int) Math.min(a, b);
	}
}

class XY {
	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}

Score : 400 points

Problem Statement

You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:

Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times.

Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.

The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?

Constraints

1 ≤ N ≤ 10^5

1 ≤ H ≤ 10^9

1 ≤ a_i ≤ b_i ≤ 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N H
a_1 b_1
:
a_N b_N

Output

Print the minimum total number of attacks required to vanish the monster.

Sample Input 1

1 10
3 5

Sample Output 1

3

You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3 + 3 + 5 = 11 points of damage in a total of three attacks, vanishing the monster.

Sample Input 2

2 10
3 5
2 6

Sample Output 2

2

In addition to the katana above, you also have another katana. Wielding it deals 2 points of damage, and throwing it deals 6 points of damage. By throwing both katana, you will deal 5 + 6 = 11 points of damage in two attacks, vanishing the monster.

Sample Input 3

4 1000000000
1 1
1 10000000
1 30000000
1 99999999

Sample Output 3

860000004

Sample Input 4

5 500
35 44
28 83
46 62
31 79
40 43

Sample Output 4

9


/**
 * Created at 12:27 on 2019-08-29
 */

import java.io.*;
import java.util.*;
import java.util.function.Predicate;

public class Main {

  static FastScanner sc = new FastScanner();
  static Output out = new Output(System.out);

  static final int[] dx = {0, 1, 0, -1};
  static final int[] dy = {-1, 0, 1, 0};

  static final long MOD = (long) (1e9 + 7);
  static final long INF = Long.MAX_VALUE / 2;

  public static class Solver {
    public Solver() {

      int N = sc.nextInt();
      long H = sc.nextLong();

      Katana[] katana = new Katana[N];
      for (int i=0; i<N; i++) {
        katana[i] = new Katana(sc.nextInt(), sc.nextInt());
      }

      Arrays.sort(katana, (o1, o2) -> Compare.L(o2.b, o1.b));

      long[] sumB = new long[N+1];
      for (int i=1; i<=N; i++) {
        sumB[i] = sumB[i-1] + katana[i-1].b;
      }

      long ans = INF;
      for (int i=0; i<N; i++) {
        long a = katana[i].a;
        int index = BinarySearch.binarySearch(j -> katana[j].b >= a, 0, N, false);
        long h = H - sumB[index+1];
        ans = Math.min(ans, (index+1) + ceil(h, a) );
      }

      out.println(ans);

    }

    /*
     * n >= a/b なる最小の整数nを返す
     */
    public long ceil(long a, long b) {
      if (b < 0) {
        a *= -1;
        b *= -1;
      }

      if (a > 0) {
        //よくある切り上げのテクニック
        return (a+b-1)/b;
      } else {
        //絶対値の小さい方に丸められる(負なら正の方向)
        return a/b;
      }
    }

    public static class BinarySearch {

      /*
       * [l, r)の区間でchecker.test()を実行する
       * rightOK ... 右側OK左側NGならtrue, 右側NG左側OKならfalse
       */
      public static long binarySearchLong(Predicate<Long> checker, long l, long r, boolean rightOK) {
        long ng, ok;

        if (rightOK) {
          ok = r-1;
          ng = l;
          if (!checker.test(ok)) {
            return r;
          }
          if (checker.test(ng)) {
            return l;
          }
        } else {
          ok = l;
          ng = r-1;
          if (!checker.test(ok)) {
            return l-1;
          }
          if (checker.test(ng)) {
            return r-1;
          }
        }

        /* ok と ng のどちらが大きいかわからないことを考慮 */
        while (Math.abs(ok - ng) > 1) {
          long mid = (ok + ng) / 2;

          if (checker.test(mid)) ok = mid;
          else ng = mid;
        }

        return ok;
      }

      /*
       * [l, r)の区間でchecker.test()を実行する
       */
      public static int binarySearch(Predicate<Integer> checker, int l, int r, boolean rightOK) {

        int ng, ok;

        if (rightOK) {
          ok = r-1;
          ng = l;
          if (!checker.test(ok)) {
            return r;
          }
          if (checker.test(ng)) {
            return l;
          }
        } else {
          ok = l;
          ng = r-1;
          if (!checker.test(ok)) {
            return l-1;
          }
          if (checker.test(ng)) {
            return r-1;
          }
        }

        while (Math.abs(ok - ng) > 1) {
          int mid = (ok + ng) / 2;

          if (checker.test(mid)) ok = mid;
          else ng = mid;
        }

        return ok;
      }

      public static int lowerBound(long[] a, long v) {

        if (a[0] >= v) return 0;

        int l = 0, r = a.length;
        int mid = (r + l) / 2;

        while (r - l > 1) {

          if (a[mid] >= v) r = mid;
          else l = mid;

          mid = (r + l) / 2;
        }

        return r;

      }

      public static int upperBound(long[] a, long v) {

        if (a[0] > v) return 0;

        int l = 0, r = a.length;
        int mid = (r + l) / 2;

        while (r - l > 1) {

          if (a[mid] > v) r = mid;
          else l = mid;

          mid = (r + l) / 2;
        }

        return r;

      }

      public static int count(long[] a, long v) {
        int lower = lowerBound(a, v);
        int upper = upperBound(a, v);
        return upper - lower;
      }

    }

    class Katana {
      long a, b;
      Katana(long A, long B) {
        a = A;
        b = B;
      }
    }

    public static class Compare {
      public static int L(long l1, long l2) {
        if (l1 == l2) return 0;
        else if (l1 < l2) return -1;
        else return 1;
      }
    }

  }

  public static void main(String[] args) {
    new Solver();
    out.flush();
  }

  static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
      if (ptr < buflen) {
        return true;
      } else {
        ptr = 0;
        try {
          buflen = in.read(buffer);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (buflen <= 0) {
          return false;
        }
      }
      return true;
    }

    private int readByte() {
      if (hasNextByte()) return buffer[ptr++];
      else return -1;
    }

    private static boolean isPrintableChar(int c) {
      return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    }

    public boolean hasNext() {
      skipUnprintable();
      return hasNextByte();
    }

    public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while (isPrintableChar(b)) {
        sb.appendCodePoint(b);
        b = readByte();
      }
      return sb.toString();
    }

    public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
        minus = true;
        b = readByte();
      }
      if (b < '0' || '9' < b) {
        throw new NumberFormatException();
      }
      while (true) {
        if ('0' <= b && b <= '9') {
          n *= 10;
          n += b - '0';
        } else if (b == -1 || !isPrintableChar(b)) {
          return minus ? -n : n;
        } else {
          throw new NumberFormatException();
        }
        b = readByte();
      }
    }

    public int nextInt() {
      return (int) nextLong();
    }

    public int[] nextIntArray(int N, boolean oneBased) {
      if (oneBased) {
        int[] array = new int[N + 1];
        for (int i = 1; i <= N; i++) {
          array[i] = sc.nextInt();
        }
        return array;
      } else {
        int[] array = new int[N];
        for (int i = 0; i < N; i++) {
          array[i] = sc.nextInt();
        }
        return array;
      }
    }

    public long[] nextLongArray(int N, boolean oneBased) {
      if (oneBased) {
        long[] array = new long[N + 1];
        for (int i = 1; i <= N; i++) {
          array[i] = sc.nextLong();
        }
        return array;
      } else {
        long[] array = new long[N];
        for (int i = 0; i < N; i++) {
          array[i] = sc.nextLong();
        }
        return array;
      }
    }
  }

  static class Output extends PrintWriter {

    public Output(PrintStream ps) {
      super(ps);
    }

    public void print(int[] a, String separator) {
      for (int i = 0; i < a.length; i++) {
        if (i == 0) print(a[i]);
        else print(separator + a[i]);
      }
      println();
    }

    public void print(long[] a, String separator) {
      for (int i = 0; i < a.length; i++) {
        if (i == 0) print(a[i]);
        else print(separator + a[i]);
      }
      println();
    }

    public void print(String[] a, String separator) {
      for (int i = 0; i < a.length; i++) {
        if (i == 0) print(a[i]);
        else print(separator + a[i]);
      }
      println();
    }

    public void print(ArrayList a, String separator) {
      for (int i = 0; i < a.size(); i++) {
        if (i == 0) print(a.get(i));
        else print(separator + a.get(i));
      }
      println();
    }
  }

}


import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int h = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        Pair[] pairs = new Pair[n];
         for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            Pair p = new Pair();
            p.a = a[i];
            p.b = b[i];
            pairs[i] = p;
        }

         Arrays.sort(a);

         int aMax = a[n - 1];

         Arrays.sort(pairs);

         int count = 0;
         for (int i = n - 1 ; i >= 0 ; i--) {
             if (h > 0 && pairs[i].b > aMax) {
                 count++;
                 h -= pairs[i].b;
             }
         }

         if (h <= 0) {
             System.out.println(count);
         } else {
             int mod = h / aMax;
             h -= aMax * mod;
             count += mod;
             if (h > 0) {
                 count++;
             }
             System.out.println(count);
         }

    }

}

class Pair implements Comparable {
    int a;
    int b;
    @Override
    public int compareTo(Object other) {
        Pair otherpair = (Pair) other;
        return b - otherpair.b;
    }
}


import java.util.*;

public class Main{
    private static void solve(int N, int H, int[][] ab){
        double count = 0;
        int result = 0;
        int countb = 0;
        int sum = 0;
        int sumb = 0;
        int maxa = ab[0][0];
        int[] b = new int[N];

        for(int i = 0; i < N; i ++){
            sumb += ab[i][1];
        }
        for(int i = 1; i < N; i ++){
            if(ab[i][0] > maxa) maxa = ab[i][0];
        }
        for(int i = 0; i < N; i ++){
            b[i] = ab[i][1];
        }
        Arrays.sort(b);
        if(b[0] >= maxa){
            if(sumb >= H){
                int i = N - 1;
                while(sum < H){
                    sum += b[i];
                    i --;
                    result ++;
                }
                System.out.print(result);
                return;
            }
            else{
                double cal = (double)(H - sumb) / maxa;
                count = N + Math.ceil(cal);
                result = (int)count;
                System.out.print(result);
                return;
            }
        }
        else{
            for(int i = N - 1; i > 0; -- i){
                if(b[i] > maxa){
                    sum += b[i];
                    countb ++;
                }
                else break;
            }
            double cala = (double)(H - sum) / maxa;
            count = countb + Math.ceil(cala);
            result = (int)count;
            System.out.print(result);
            return;
        }
    }
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int H = input.nextInt();
        int[][] ab = new int[N][2];
        for(int i = 0; i < N; i ++){
            for(int j = 0; j < 2; j ++){
                ab[i][j] = input.nextInt();
            }
        }
        input.close();
        solve(N, H, ab);
    }
}


import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double hp = sc.nextInt();
		double a = 0;
		Integer b[] = new Integer [n];
		for(int i = 0; i < n ; i++){
			int tmp = sc.nextInt();
			if( tmp > a){
				a = tmp;
			}
			b[i] = sc.nextInt();
		}
		/*for( int i = n; i > 0; i--){
			for( int j = 0; j < i - 1 ; j++ ){
				if(b[j] < b[j+1]){
					int tmp = b[j];
					b[j] = b[j+1];
					b[j+1] = tmp;
				}
			}
		}*/
		Arrays.sort(b,Collections.reverseOrder());
		int ans = 0;
		int index = 0;
		while( hp > 0){
			if( index < n && b[index] >= a ){
				hp -= b[index];
				ans++;
				index++;
			}else{
				break;
			}
		}
		if(hp%a == 0){
			ans += hp/a;
		}else{
			Double tmpA = hp/a;
			int tmpB = tmpA.intValue();
			if(tmpA - tmpB < 0){
				ans += tmpB;
			}else{
				ans += tmpB + 1;
			}
		}
		System.out.print(ans);
	}
}


import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int hp = sc.nextInt();
		int a = 0;
		int b[] = new int [n];
		for(int i = 0; i < n ; i++){
			int tmp = sc.nextInt();
			if( tmp > a){
				a = tmp;
			}
			b[i] = sc.nextInt();
		}
		for( int i = n; i > 0; i--){
			for( int j = 0; j < i - 1 ; j++ ){
				if(b[j] < b[j+1]){
					int tmp = b[j];
					b[j] = b[j+1];
					b[j+1] = tmp;
				}
			}
		}
		int ans = 0;
		int index = 0;
		while( hp > 0){
			if( index < n && b[index] >= a ){
				hp -= b[index];
				ans++;
				index++;

			}else{
				if(hp%a == 0){
					ans += hp/a;
				}else{
					ans += hp/a + 1;
				}
				break;
			}
		}
		System.out.print(ans);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String[] sl = r.readLine().split("[\\s]+");
    int N = Integer.parseInt(sl[0]);
    int H = Integer.parseInt(sl[1]);

    int[] a = new int[114514];
    int[] b = new int[114514];

    for(int i = 0; i < N; i++)
    {
      sl = r.readLine().split("[\\s]+");
      a[i] = Integer.parseInt(sl[0]);
      b[i] = Integer.parseInt(sl[1]);
    }

   int mainw = 0;
    for(int i = 0; i < N; i++)
    {
      if(mainw < a[i])
      {
        mainw = a[i];
      }
    }

    List<Integer> li = new ArrayList<Integer>();
    for(int i = 0; i < N; i++)
    {
      if(mainw < b[i])
      {
        li.add(b[i]);
      }
    }

    Collections.sort(li);

    int dam = 0;
    int count = 0;
    for(int i = li.size() - 1; 0 <= i; i--)
    {
      dam += li.get(i);
      count++;
      if(H <= dam)
      {
        break;
      }
    }

    if(dam < H)
    {
      count += (H - dam + mainw - 1) / mainw;
    }

    System.out.println(count);

  }

}


import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {

	public static class Katana implements Comparable<Katana> {
		long a, b;

		public Katana(long a, long b){
			this.a = a;
			this.b = b;
		}

		@Override
		public int compareTo(Katana o) {
			return -Long.compare(this.b, o.b);
		}
	}

	public static void main(String[] args) throws IOException {
		try (Scanner sc = new Scanner(System.in)) {
			final int N = sc.nextInt();
			final long H = sc.nextLong();

			Katana[] ks = new Katana[N];

			long[] bs= new long[N];

			for(int i = 0; i < N; i++){
				final long a = sc.nextLong();
				final long b = sc.nextLong();

				ks[i] = new Katana(a, b);
				bs[i] = b;
			}

			Arrays.sort(bs);
			long[] b_post_sum = new long[bs.length + 1];
			for(int i = 1; i < b_post_sum.length; i++){
				b_post_sum[i] += b_post_sum[i - 1];
				b_post_sum[i] += bs[i - 1];
			}
			//System.out.println(Arrays.toString(bs));
			//System.out.println(Arrays.toString(b_post_sum));

			long min = Long.MAX_VALUE;
			for(final Katana katana : ks){
				final long curr_a = katana.a;

				int range_lower = -1, range_upper = N - 1;
				while(range_lower + 1 < range_upper){
					final int middle = (range_lower + range_upper) / 2;
					//System.out.println("> " + bs[middle] + " " + middle);

					if(bs[middle] < curr_a){
						range_lower = middle;
					}else{
						range_upper = middle;
					}
				}
				//System.out.println(range_lower + " " + range_upper);

				int p_sum_lower = range_lower, p_sum_upper = N;
				while(p_sum_lower + 1 < p_sum_upper){
					final int middle = (p_sum_lower + p_sum_upper) / 2;

					final long sum = b_post_sum[middle] - b_post_sum[range_upper];
					if(sum < H){
						p_sum_lower = middle;
					}else{
						p_sum_upper = middle;
					}
				}
				//System.out.println(p_sum_lower + " " + p_sum_upper);

				final int full_b_use_time = p_sum_upper - range_upper;
				final long full_b_use_sum = b_post_sum[p_sum_upper] - b_post_sum[range_upper];
				//System.out.println(full_b_use_time + " " + full_b_use_sum + " " + curr_a);

				if(full_b_use_sum < H){
					final long full_a_use_time = ((H - full_b_use_sum) + (curr_a - 1)) / (curr_a);
					//System.out.println(full_b_use_time + full_a_use_time);
					min = Math.min(min, full_b_use_time + full_a_use_time);
				}else{
					min = Math.min(min, full_b_use_time);
				}

			}

			System.out.println(min);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        int sum = 0;
        for (int i = 1; i <= n; ++i) {
            int digitSum = 0;
            int tmp = i;
            while (tmp > 0) {
                digitSum += tmp % 10;
                tmp /= 10;
            }
            if (a <= digitSum && digitSum <= b)
                sum += i;
        }

        System.out.println(sum);
    }
}

Score : 200 points

Problem Statement

Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Constraints

1 \leq N \leq 10^4

1 \leq A \leq B \leq 36

All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Sample Input 1

20 2 5

Sample Output 1

84

Among the integers not greater than 20, the ones whose sums of digits are between 2 and 5, are: 2,3,4,5,11,12,13,14 and 20. We should print the sum of these, 84.

Sample Input 2

10 1 2

Sample Output 2

13

Sample Input 3

100 4 16

Sample Output 3

4554


import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int end = sc.nextInt();
    int min = sc.nextInt();
    int max = sc.nextInt();
    sc.close();

    long sum = 0;

    for (int i = 1; i <= end; i++) {
      int x = getXxx(i);

      if (min <= x && x <= max) {
        sum += i;
      }
    }

    System.out.println(sum);

  }

  private static int getXxx(int num) {

    int result = 0;

    while(num > 0) {
      result += num % 10;
      num /= 10;
    }

    return result;

  }
}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        int result = 0;

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        for (int i=1; i<=n; i++){
            int sum = 0;
            String str = Integer.toString(i);
            String []resultArray = str.split("");

            for(int j = 0; j < resultArray.length; j++){
                int num=Integer.parseInt(resultArray[j]);
                sum += num;
            }

            if(a <= sum && sum <= b){
                result += i;
            }

        }

        System.out.println(result);
        sc.close();
    }
}


import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        int sumAll = 0;

        for(int i=1;i <= n; i++) {
            String t = String.valueOf(i);
            int sum = 0;
            for(int j = 0; j < t.length(); j++) {
                sum += Integer.parseInt(t.substring(j, j+1));
            }

            if(sum >=a && sum <=b) {
                sumAll += i;
            }

        }
        System.out.println(sumAll);
    }
}


import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int sum = 0;
		for(int i = 1; i <= n; i++) {
			int c = 0, d = i;
			for(int j = 1; j < 5; j++) {
				c += d % 10;
				d /= 10;
			}
			if(a <= c && c <= b) {
				sum += i;
			}
		}
		System.out.print(sum);
	}
}


import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int nlen = String.valueOf(n).length();
		int tmp1 = 0;
		int tmp2 = 0;
		int sum = 0;

		for (int i = 1; i <= nlen; i++) {
			for (int j = (int) Math.pow(10, i-1); j < Math.pow(10, i); j++) {
				if (j > n) {
					System.out.println(sum); return;
				} else if (i == 1) {
					tmp1 = j;
					if (tmp1 >= a && tmp1 <= b) {
						sum += j;
					}
				} else if (i == 2) {
					tmp1 = j/10;
					tmp2 = j%10;
					tmp1 += tmp2;
					if (tmp1 >= a && tmp1 <= b) {
						sum += j;
					}
				} else if (i == 3) {
					tmp1 = j/100;
					tmp2 = j%100;
					tmp1 += tmp2/10;
					tmp2 = tmp2%10;
					tmp1 += tmp2;
					if (tmp1 >= a && tmp1 <= b) {
						sum += j;
					}
				}else if (i == 4) {
					if (1 >= a && 1 <= b) {
						sum += j;
					}
				}
				tmp1 = 0;
				tmp2 = 0;
			}
		}
		System.out.println(sum);
	}
}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int result = 0;

        for (int i = 1; i <= N; i++) {
            String imput = String.valueOf(i);
            String[] strings;
            strings = imput.split("");

            int sum = 0;
            for (int j = 0; j <= imput.length() - 1; j++) {
                sum += Integer.valueOf(strings[j]);
            }

            if(A <= sum && sum <= B) {
                result += i;
            }
        }
        System.out.println(result);
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.skip("0").next();
        System.out.println(s.length());
    }
}

Score : 100 points

Problem Statement

Snuke has a grid consisting of three squares numbered 1, 2 and 3.
In each square, either 0 or 1 is written. The number written in Square i is s_i.

Snuke will place a marble on each square that says 1.
Find the number of squares on which Snuke will place a marble.

Constraints

Each of s_1, s_2 and s_3 is either 1 or 0.

Input

Input is given from Standard Input in the following format:

s_{1}s_{2}s_{3}

Output

Print the answer.

Sample Input 1

101

Sample Output 1

2

A marble will be placed on Square 1 and 3.

Sample Input 2

000

Sample Output 2

0

No marble will be placed on any square.


import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int che = 30;
    for(int i = 1 ; i <= n ; i++){
      int a = sc.nextInt();
      int zyo = 0;
      int cou = 0;
      while(zyo == 0){
        if(a % 2 == 1){
          zyo = 1;
        }else{
          cou = cou + 1;
          a = a / 2;
        }
      }
      if(cou < che){
         che = cou;
      }
    }
    System.out.println(che);
  }
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        s = s.replace("0", "");
        System.out.println(s.length());

    }
}


import java.util.ArrayList;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * すぬけ君は1,2,3の番号がついた3つのマスからなるマス目を持っています。
 * 各マスには 0 か 1 が書かれており、マスiにはs iが書かれています。
 *
 * すぬけ君は 1 が書かれたマスにビー玉を置きます。
 * ビー玉が置かれるマスがいくつあるか求めてください。
 *
 * # restrict
 * s1, s2, s3 は、'0', '1'
 *
 * # input
 * 入力は以下の形式で標準入力から与えられる。
 * s1s2s3
 *
 * #
 */
public class Main {
    public static void main(String[] args) {
        final Scanner s = new Scanner(System.in);

        String s1 = s.next();
        String s2 = s.next();
        String s3 = s.next();

        ArrayList<String> list = new ArrayList<String>();
        list.add(s1);
        list.add(s2);
        list.add(s3);

        int count = list.stream()
                .filter( str -> str.equals("1"))
                .collect(Collectors.toList())
                .size();

        System.out.print(count);
    }
}


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		//宣言文
		//標準入力オブジェクトを生成
		Scanner sc = new Scanner(System.in);
		//標準入力で以下の変数を初期化
		int[] numArray = new int[3];
		numArray[0] = sc.nextInt();
		numArray[1] = sc.nextInt();
		numArray[2] = sc.nextInt();
		//フラグ変数
		boolean numFlag = true;
		int countNum = 0;

		//処理文
		for (int i = 0; i < numArray.length; i++) {
			if (!(numArray[i] == 0 || numArray[i] == 1)) {
				//制約 配列の中身が０か１なのか判定
				numFlag = false;
				break;
			}else if(numArray[i] == 1){
				//1をカウントする。
				countNum++;
			}

		}

		if(numFlag) {
			//標準出力
			System.out.print(countNum);
		}
	}
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int count = 0;
		for(int i = 0;i < 3;i++) {
		    if(s[i] - '0' == 1) count++;
		}

		System.out.println(count);
    }

}


import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    s = s.replaceAll("0","");
    System.out.println(s.length());
  }
}


import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);

      String s = sc.next();

      System.out.println(s.replace("0","").length());

	}
}


import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
       	String s = sc.next();
        s = s.replaceAll("0","");
        System.out.println(s.length());
    }
}


import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int count = 0;
		String str = sc.next();

		for (int i = 0; i < str.length(); i++) {

			if (str.charAt(i) == '1') {
				count++;
			}
		}
		System.out.println(count);
	}
}


import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        s = s.replaceAll("0","");
        System.out.println(s.length());
    }

}


import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        String [] strArray = s.split("");
        int sum = 0;

        for (int i = 0; i < strArray.length; i++) {
            sum = sum + Integer.parseInt(strArray[i]);
        }

        System.out.println(sum);

    }
}


import java.util.*;

public class Main{

  public static void main (String[] args){

  	Scanner scanner = new Scanner (System.in);

 	String number = scanner.nextLine();

  	int count = 0;

  	for (int i=0; i<3; i++){
  		char temp = number.charAt(i);

      	if (temp == '1'){
          count++;
        }
    }
    System.out.println(count);
  }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int n = 0;

		for(int i = 0;i < 3; i++) {
			if(str.charAt(i) == '1') {
				n += 1;
			}else {
				n += 0;
			}
		}
		System.out.println(n);

	}

}


import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// // 整数の入力
		// int a = sc.nextInt();
		// // スペース区切りの整数の入力
		// int b = sc.nextInt();
		// int c = sc.nextInt();
		// // 文字列の入力
		// String s = sc.next();
		// // 出力
    // System.out.println((a+b+c) + " " + s);
    String s = sc.next();
    int ans = 0;
    for (char c : s.toCharArray()) {
      if (c == '1') ans++;
    }
    System.out.println(ans);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {

	public static void main(String[] args)throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		int count=0;
		for(int i=0;i<line.length();i++){
			char ch = line.charAt(i);
			if(ch=='1'){
				count++;
			}
		}
		System.out.println(count);
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {

		for(int i=0;i<1;i++) {

			slover();
			out.flush();
		}
	}
	static FastScanner sc = new FastScanner();
	static PrintWriter out = new PrintWriter(System.out);
	//StringBuffer S = new StringBuffer(sc.next());
		//String hoge2 = str.reverse().toString();
		//map.containsKey(A)
		//Map<Integer, Integer> map = new HashMap<Integer, Integer>(N);
		/*for ( キーのデータ型 key : マップの名前.keySet() ) {
			データのデータ型 data = マップの名前.get( key );

			// keyやdataを使った処理;
		}*/
		//int i = Integer.parseInt(s);
		//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek BFSは前から実行される
		//Deque<String> dd=new ArrayDeque<>();//push後ろに入れる,poll(pop)後ろからとる,peek addは先頭に入るからバグ注意
		//stackdfsは後ろから実行される
		//ArrayList<Integer> cc = new ArrayList<>(N);
		//cc.contains(tmp)
		//Arrays.asList(c).contains("a")
		//list.set(1,"walk");//1 1 2 3 5
		//PriorityQueue<Integer> r=new PriorityQueue<Integer>();//add poll

		private static int INF =1000000007;

		private static class D{

			ArrayList<Integer> X=new ArrayList<>();
			ArrayList<Integer> Y=new ArrayList<>();
			int t=0;
			int index=0;
			D(ArrayList<Integer> X,ArrayList<Integer> Y,int t,int index){
				this.X=X;;
				this.Y=Y;
				this.t=t;
				this.index=index;
			}

		}

	//Set<Long> a=new HashSet<Long>();

	//Integer.toBinaryString(i);
	//Integer.toString(i, 2);
//	//Integer.parseInt(bin, 2);
	//bitset
	private static int mod=1000000007;
	private static int slover()   {
		StringBuffer S = new StringBuffer(sc.next());
		StringBuffer T = new StringBuffer(sc.next());

		int v=S.length()-1;

		a:for(int i=v;i>=T.length()-1;i--) {

			for(int t=0;t<T.length();t++) {

				if(S.charAt(i-t)!=T.charAt(T.length()-t-1)&&S.charAt(i-t)!='?') {
					continue a;
				}

			}

			for(int t=0;t<T.length();t++) {
				S.setCharAt(i-t, T.charAt(T.length()-t-1));
			}
			p(S.toString().replace('?', 'a'));
			return 0;
		}
		p("UNRESTORABLE");
		return 0;
	}
	//速度が足りないときは、前計算を1回だけにしたり、longをintに変えたりするといい
	private static long modNcR2(int n,int r) {
		long x_b=1;

		for(int i=0;i<r;i++) {
			x_b*=(n-i);
			x_b%=mod;
		}

		long y=1;
		for(int i=1;i<=r;i++) {
			y*=i;
			y%=mod;
			//nPrにr!%modの逆元を掛ける
		}
		return  (x_b*modPow((int) y,mod-2,mod)%mod);

	}
	private static int modPow2(String S,int mod) {
		//iのt乗をO(log t)で返す
		int a=2;
		int res=1;
		int N=S.length()-1;
		for(int i=0;i<S.length();i++) {
			if(S.charAt(N-i)=='1') {
				res=res*a%mod;
			}
			a=a*a%mod;
		}
		return res;
	}

	private static ArrayList<Long> divisors2(long t) {
		ArrayList<Long> c=new ArrayList<>();
		for(long i=2;i*i<=t;i++) {

			if(t%i==0) {
				p(t+" "+i);
				c.add((long)i);
				t/=i;
				i--;
			}
		}
		if(t!=1)c.add(t);
		Collections.sort(c);

		return c;
	}

	private static long modPow(int i,int t,long mod) {
		//iのt乗をO(log t)で返す
		long a=i;
		long res=1;
		while(t!=0) {
			//p(t);
			if((1&t)==1) {
				res=res*a%mod;
			}
			a=a*a%mod;
			t=t>>1;
		}
		return res;
	}

	public static long gcd(long num1,long num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }
	public static long lcm(long num1,long num2) {
		return num1*num2/gcd(num1,num2);
	}
	//O(N^0.5)
	private static boolean isPrime(long t) {
		if(t<2)return false;
		for(int i=2;i*i<=t;i++) {
			if(t%i==0)return false;
		}
		return true;
	}
	private static ArrayList<Long> divisors(long t) {
		ArrayList<Long> c=new ArrayList<>();
		for(int i=1;i*i<=t;i++) {
			if(t%i==0) {
				if(i*i!=t) {
					c.add(t/i);
				}
				c.add((long)i);
			}
		}
		return c;
	}
	private static void bubunwa() {
		int N=sc.nextInt();
		int K=sc.nextInt();
		int a[]=sc.nextIntArray(N, false);

		boolean dp[] =new boolean[K+1];

		Arrays.fill(dp, false);
		dp[0]=true;
		for(int i=0;i<N;i++) {
			for(int x=K-a[i];x>=0;x--) {
				if(dp[x])dp[x+a[i]]=true;
			}
		}

		p(dp[K] ? "Yes":"No");
	}

	private static String bitToString(int i) {

			String T="";
			for(int j=0;j<2;j++) {
				//if(i>>j==0)break;
				if((1&i>>j)==1) {
					T+="1";
				}else T+="0";
			}
			return (i+" "+T);

	}
/*********************************************************************/
	//target以下までの値のindexを返す
	//target以上が欲しいときは返り値+1すればいい
	//0-indexで個数を求めるときはさらにindex+1する必要あり
	private static int lower_bound(long a[],long target) {
	//p(target+ " "+Arrays.toString(a));
	if(a[0]>target)return -1;
	//最後の値がtarget以下であるときは最後のindexを返す。
	//target以上が欲しいときは注意する必要あり
	if(a[a.length-1]<=target) return a.length-1;

	int S=-1;
	int E=a.length;

	while(S<E) {

		int G=(S+E)/2;
		if(G+1==a.length) {
			G--;
		}
		//未満にしたいときは=の場所を変える
		if(a[G]<=target&&a[G+1]>target) {
			return G;

		}else if(a[G]<=target){
			S=G;
		}else if(a[G]>target) {
			E=G;
		}

	}

	return -1;
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;

		int minPos=-1;
		char min =Character.MAX_VALUE;

		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}

		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));

		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
private static long[][] com;
private static void nCr() {
	int MAX = 3001;
	com= new long[MAX][MAX];
	for(int i = 0; i < MAX; i++)
	    com[i][0] = 1;
	for(int i = 1; i < MAX; i++) {
	    for(int j = 1; j <= i; j++) {
	        com[i][j] = com[i-1][j-1] + com[i-1][j];
	        com[i][j] %= mod;
	    }
	}
}

	static void p(String ans) {out.println(ans);};
	static void p(int ans) {out.println(ans);};
	static void p() {out.println();};
	static void p(long ans) {out.println(ans);};
	static void p(double ans) {out.println(ans);};

	static void pn(String ans) {out.print(ans);};
	static void pn(int ans) {out.print(ans);};
	static void pn() {out.print("");};
	static void pn(long ans) {out.print(ans);};
	static void pn(double ans) {out.print(ans);};

	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;

	    private boolean hasNextByte() {
	      if (ptr < buflen) {
	        return true;
	      } else {
	        ptr = 0;
	        try {
	          buflen = in.read(buffer);
	        } catch (IOException e) {
	          e.printStackTrace();
	        }
	        if (buflen <= 0) {
	          return false;
	        }
	      }
	      return true;
	    }

	    private int readByte() {
	      if (hasNextByte()) return buffer[ptr++];
	      else return -1;
	    }

	    private static boolean isPrintableChar(int c) {
	      return 33 <= c && c <= 126;
	    }

	    private void skipUnprintable() {
	      while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
	    }

	    public boolean hasNext() {
	      skipUnprintable();
	      return hasNextByte();
	    }

	    public String next() {
	      if (!hasNext()) throw new NoSuchElementException();
	      StringBuilder sb = new StringBuilder();
	      int b = readByte();
	      while (isPrintableChar(b)) {
	        sb.appendCodePoint(b);
	        b = readByte();
	      }
	      return sb.toString();
	    }

	    public long nextLong() {
	      if (!hasNext()) throw new NoSuchElementException();
	      long n = 0;
	      boolean minus = false;
	      int b = readByte();
	      if (b == '-') {
	        minus = true;
	        b = readByte();
	      }
	      if (b < '0' || '9' < b) {
	        throw new NumberFormatException();
	      }
	      while (true) {
	        if ('0' <= b && b <= '9') {
	          n *= 10;
	          n += b - '0';
	        } else if (b == -1 || !isPrintableChar(b)) {
	          return minus ? -n : n;
	        } else {
	          throw new NumberFormatException();
	        }
	        b = readByte();
	      }
	    }

	    public int nextInt() {
	      return (int) nextLong();
	    }

	    public double nextDouble(){
	    	return Double.parseDouble(next());
	    }

	    public int[] nextIntArray(int N, boolean oneBased) {
	      if (oneBased) {
	        int[] array = new int[N + 1];
	        for (int i = 1; i <= N; i++) {
	          array[i] = sc.nextInt();
	        }
	        return array;
	      } else {
	        int[] array = new int[N];
	        for (int i = 0; i < N; i++) {
	          array[i] = sc.nextInt();
	        }
	        return array;
	      }
	    }

	    public long[] nextLongArray(int N, boolean oneBased) {
	      if (oneBased) {
	        long[] array = new long[N + 1];
	        for (int i = 1; i <= N; i++) {
	          array[i] = sc.nextLong();
	        }
	        return array;
	      } else {
	        long[] array = new long[N];
	        for (int i = 0; i < N; i++) {
	          array[i] = sc.nextLong();
	        }
	        return array;
	      }
	    }
	  }
}

Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.

He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.

One more thing he found is a sheet of paper with the following facts written on it:

Condition 1: The string S contains a string T as a contiguous substring.

Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string S.

If such a string does not exist, print UNRESTORABLE.

Constraints

1 \leq |S'|, |T| \leq 50

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

If such a string does not exist, print UNRESTORABLE instead.

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say S = atcoder.

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

There is no string that satisfies Condition 1, so the string S does not exist.


import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] base = sc.next().toCharArray();
		char[] test = sc.next().toCharArray();
		for (int i = base.length - test.length; i >= 0; i--) {
		    boolean flag = true;
		    for (int j = 0; j < test.length; j++) {
		        if (base[i + j] != test[j] && base[i + j] != '?') {
		            flag = false;
		            break;
		        }
		    }
		    if (flag) {
		        for (int j = 0; j < test.length; j++) {
		            base[i + j] = test[j];
		        }
    		    for (int j = 0; j < base.length; j++) {
    		        if (base[j] == '?') {
    		            base[j] = 'a';
    		        }
    		    }
    		    System.out.println(base);
    		    return;
		    }
		}
		System.out.println("UNRESTORABLE");
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    private void solve() throws IOException {
        try {
//            solveA();
//            solveB();
//            solveC();
            solveD();
//            solveE();
//            solveF();
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.flush();
                out.close();
            }
        }

    }

    // mods
    long MOD = (long) Math.pow(10, 9) + 7;

    private void solveA() {
        long a = nextLong();
        long b = nextLong();
        int k = nextInt();
        for (int i = 0; i < k; i++) {
            if (i % 2 == 0) {
                if (a % 2 == 1) {
                    a -= 1;
                }
                b += (a / 2);
                a /= 2;
            } else {
                if (b % 2 == 1) {
                    b -= 1;
                }
                a += (b / 2);
                b /= 2;
            }
        }
        out.println(a + " " + b);
    }

    private void solveB() {
        String s = next();
        if (s.length() == 2) {
            out.println(0);
            return;
        }
        s = s.substring(0, s.length() - 1);
        int res = 0;
        int length = s.length() / 2;
        for (int i = 0; i < length; i++) {
            int m = i + 1;
            String fr = s.substring(0, m);
            String bk = s.substring(m, m + m);
            if (fr.equals(bk)) {
                res = Math.max(res, fr.length() + bk.length());
            }
        }
        out.println(res);
    }

    private void solveC() {
        int n = nextInt();
        Integer[] a = IntStream.range(0, n).mapToObj(i -> nextInt()).sorted().toArray(Integer[]::new);
        Map<Integer, Long> am = Arrays.stream(a).collect(Collectors.groupingBy(i -> i, Collectors.counting()));
        long h = 0;
        long w = 0;
        for (int i = a.length - 1; i >= 0; i--) {
            int val = a[i];
            if (am.getOrDefault(val, 0L) < 2)
                continue;

            if (h == 0) {
                h = val;
            } else if (w == 0) {
                w = val;
            }
            am.put(val, am.get(val) - 2);
        }
        out.print(h * w);
    }

    private void solveD() {
        String s = next();
        String t = next();
        if (s.length() < t.length()) {
            out.println("UNRESTORABLE");
            return;
        }
        List<String> res = new ArrayList<String>();
        for (int i = 0; i < s.length(); i++) {

            boolean isMatch = true;
            for (int j = 0, idx = i; j < t.length() && idx < s.length(); j++, idx++) {
                if (s.charAt(idx) != '?' && s.charAt(idx) != t.charAt(j)) {
                    isMatch = false;
                    break;
                }
            }
            if (isMatch) {
                StringBuilder builder = new StringBuilder();

                for (int j = 0; j < s.length(); j++) {
                    if (j >= i && j < i + t.length()) {
                        builder.append(t.charAt(j - i));
                    } else {
                        builder.append(s.charAt(j) == '?' ? "a" : s.charAt(j));
                    }
                }
                res.add(builder.toString());
            }
        }
        Collections.sort(res);
        if (res.size() == 0)
            out.println("UNRESTORABLE");
        else
            out.println(res.get(0));
    }

    private void solveE() {
        int n = nextInt();
        int m = nextInt();
        int[] p = IntStream.range(0, n).map(i -> nextInt()).toArray();

        int[][] xy = Stream.generate(() -> new int[]{nextInt(), nextInt()}).limit(m).toArray(int[][]::new);
        UnionFind unionFind = new UnionFind(n);
        for (int[] l : xy) {
            unionFind.unite(p[l[0] - 1], p[l[1] - 1]);
        }
        int res = 0;
        for (int i = 1; i <= n; i++) {
            if (unionFind.isSame(i, p[i - 1]))
                res++;
        }
        out.println(res);
    }

    private void solveF() {

    }

    private static class GraphNode {
        private int n;
        private List<Integer> childs;

        public GraphNode(int n) {
            this.n = n;
            childs = new ArrayList<Integer>();
        }

        public void addChild(int child) {
            this.childs.add(child);
        }
    }

    private static class Graph {

        private Map<Integer, GraphNode> graph;

        public Graph(int[][] list) {
            graph = new HashMap<Integer, GraphNode>();
            Arrays.stream(list).forEach(l -> {
                int a = l[0];
                int b = l[1];
                graph.put(a, graph.getOrDefault(a, new GraphNode(a)));
                graph.get(a).addChild(b);
                graph.put(b, graph.getOrDefault(b, new GraphNode(b)));
                graph.get(b).addChild(a);
            });
        }

    }

    private static class SegTree {
        long e = 0;

        long calcFunc(long a, long b) {
            return a + b;
        }

        int n;
        long nodes[];

        public SegTree(long[] a) {
            init(a);
        }

        public SegTree(int len, long x) {
            long a[] = new long[len];
            Arrays.fill(a, x);
            init(a);
        }

        public SegTree(int len) {
            init(len);
        }

        void init(long[] a) {
            init(a.length);
            for (int i = 0; i < a.length; i++) {
                nodes[i + n - 1] = a[i];
            }
            for (int i = n - 2; i >= 0; i--) {
                nodes[i] = calcFunc(nodes[i * 2 + 1], nodes[i * 2 + 2]);
            }
        }

        void init(int len) {
            n = 1;
            while (n < len) {
                n *= 2;
            }
            nodes = new long[n * 2 - 1];
            Arrays.fill(nodes, e);
            for (int i = n - 2; i >= 0; i--) {
                nodes[i] = calcFunc(nodes[i * 2 + 1], nodes[i * 2 + 2]);
            }
        }

        void set(final int i, long val) {
            int wkI = i + n - 1;
            nodes[wkI] = val;
            while (wkI > 0) {
                wkI = (wkI - 1) / 2;
                nodes[wkI] = calcFunc(nodes[wkI * 2 + 1], nodes[wkI * 2 + 2]);
            }
        }

        long get(int i) {
            return find(i, i + 1);
        }

        /*
       要求区間 [a, b) 中の要素の最小値を答える
       k := 自分がいるノードのインデックス
       対象区間は [l, r) にあたる
        */
        long find(int a, int b) {
            return find(a, b, 0, 0, n);
        }

        long find(int a, int b, int k, int l, int r) {
            if (r < 0)
                r = n;

            if (b <= l || r <= a)
                return e;

            if (a <= l && r <= b)
                return nodes[k];

            long val1 = find(a, b, k * 2 + 1, l, (l + r) / 2);
            long val2 = find(a, b, k * 2 + 2, (l + r) / 2, r);
            //Math.min()
            //今回は区間内の個数なのでSUM
            return val1 + val2;
        }
    }

    private static class UnionFind {
        int[] pars;

        public UnionFind(int n) {
            pars = new int[n + 1];
            Arrays.fill(pars, -1);
        }

        public int getChilds(int n) {
            int wk = getRoot(n);
            return pars[wk];
        }

        public int getRoot(int n) {
            if (pars[n] < 0)
                return n;
            return pars[n] = getRoot(pars[n]);
        }

        public boolean isSame(int a, int b) {
            return getRoot(a) == getRoot(b);
        }

        private int getSize(int a) {
            return -pars[getRoot(a)];
        }

        public void unite(int a, int b) {
            int wkA = getRoot(a);
            int wkB = getRoot(b);
            if (wkA == wkB)
                return;

            if (getSize(wkA) < getSize(wkB)) {
                int tmp = wkA;
                wkA = wkB;
                wkB = tmp;
            }
            pars[wkA] = pars[wkA] + pars[wkB];
            pars[wkB] = wkA;
        }
    }

    public long calcSimpleCombination(long n, long m, long CONST_MOD) {
        long mole = 1;
        for (long i = 1; i <= n + m; i++) {
            mole *= i;
            mole %= CONST_MOD;
        }
        long deno = 1;
        for (long i = 1; i <= n; i++) {
            deno *= i;
            deno %= CONST_MOD;
        }
        for (int i = 1; i <= m; i++) {
            deno *= i;
            deno %= CONST_MOD;
        }
        deno = modInverse(deno, CONST_MOD);
        return (mole * deno) % CONST_MOD;
    }

    long abs(double x) {
        return (long) Math.abs(x);
    }

    long round(double x) {
        return Math.round(x);
    }

    long floor(double x) {
        return (long) Math.floor(x);
    }

    long ceil(double x) {
        return (long) Math.ceil(x);
    }

    double sqrt(double x) {
        return Math.sqrt(x);
    }

    double pow(double x, double y) {
        return Math.pow(x, y);
    }

    long pow(long x, long y) {
        return (long) Math.pow(x, y);
    }

    int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    int upperToInt(char a) {
        return a - 'A';
    }

    int lowerToInt(char a) {
        return a - 'a';
    }

    int numToInt(char a) {
        return a - '0';
    }

    int charToInt(char a) {
        return a >= 'a' ? lowerToInt(a) : a >= 'A' ? upperToInt(a) : numToInt(a);
    }

    char intToUpper(int a) {
        return (char) (a + 'A');
    }

    char intToLower(int a) {
        return (char) (a + 'a');
    }

    char intToNum(int a) {
        return (char) (a + '0');
    }

    void reverse(String array[]) {
        String reversed[] = new String[array.length];
        for (int i = 0; i < array.length; i++) {
            reversed[array.length - i - 1] = array[i];
        }
        for (int i = 0; i < array.length; i++) {
            array[i] = reversed[i];
        }
    }

    void reverse(int array[]) {
        int reversed[] = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            reversed[array.length - i - 1] = array[i];
        }
        for (int i = 0; i < array.length; i++) {
            array[i] = reversed[i];
        }
    }

    void reverse(long array[]) {
        long reversed[] = new long[array.length];
        for (int i = 0; i < array.length; i++) {
            reversed[array.length - i - 1] = array[i];
        }
        for (int i = 0; i < array.length; i++) {
            array[i] = reversed[i];
        }
    }

    void reverse(double array[]) {
        double reversed[] = new double[array.length];
        for (int i = 0; i < array.length; i++) {
            reversed[array.length - i - 1] = array[i];
        }
        for (int i = 0; i < array.length; i++) {
            array[i] = reversed[i];
        }
    }

    void reverse(boolean array[]) {
        boolean reversed[] = new boolean[array.length];
        for (int i = 0; i < array.length; i++) {
            reversed[array.length - i - 1] = array[i];
        }
        for (int i = 0; i < array.length; i++) {
            array[i] = reversed[i];
        }
    }

    void fill(int array[], int x) {
        Arrays.fill(array, x);
    }

    void fill(long array[], long x) {
        Arrays.fill(array, x);
    }

    void fill(double array[], double x) {
        Arrays.fill(array, x);
    }

    void fill(boolean array[], boolean x) {
        Arrays.fill(array, x);
    }

    void fill(int array[][], int x) {
        for (int a[] : array) {
            fill(a, x);
        }
    }

    void fill(long array[][], long x) {
        for (long a[] : array) {
            fill(a, x);
        }
    }

    void fill(double array[][], double x) {
        for (double a[] : array) {
            fill(a, x);
        }
    }

    void fill(boolean array[][], boolean x) {
        for (boolean a[] : array) {
            fill(a, x);
        }
    }

    void fill(int array[][][], int x) {
        for (int a[][] : array) {
            fill(a, x);
        }
    }

    void fill(long array[][][], long x) {
        for (long a[][] : array) {
            fill(a, x);
        }
    }

    void fill(double array[][][], double x) {
        for (double a[][] : array) {
            fill(a, x);
        }
    }

    void fill(boolean array[][][], boolean x) {
        for (boolean a[][] : array) {
            fill(a, x);
        }
    }

    long INF = (long) 1e18 + 7;

    boolean isINF(long a) {
        return abs(a) > INF / 1000;
    }

    boolean isPlusINF(long a) {
        return a > 0 && isINF(a);
    }

    boolean isMinusINF(long a) {
        return isPlusINF(-a);
    }

    int I_INF = (int) 1e9 + 7;

    boolean isINF(int a) {
        return abs(a) > I_INF / 1000;
    }

    boolean isPlusINF(int a) {
        return a > 0 && isINF(a);
    }

    boolean isMinusINF(int a) {
        return isPlusINF(-a);
    }

    public long mod(long i) {
        return i % MOD + ((i % MOD) < 0 ? MOD : 0);
    }

    long powMod(long x, long y) {
        if (y == 0) {
            return 1;
        } else {
            long tmp = powMod(x, y / 2);
            return mod(mod(tmp * tmp) * (y % 2 == 0 ? 1 : x));
        }
    }

    long[] powsMod(long x, int max) {
        long pow[] = new long[max + 1];
        pow[0] = 1;
        for (int i = 0; i < max; i++) {
            pow[i + 1] = mod(pow[i] * x);
        }
        return pow;
    }

    long inv(long x) {
        return powMod(x, MOD - 2);
    }

    int MAX_FACT = 5_000_100;
    long fact[];
    long invFact[];

    /**
     * Combination簡易版
     * 5 C 2
     * 異なる n個のものから r個を選ぶ組み合わせの総数 nCr を求めます。
     * 5!(5*4*3*2*1)
     * /
     * 2!(2*1) *  (5-2)!(3*2*1)
     *
     * @param n
     * @param r
     * @return
     */
    private long getComb(int n, int r) {
        long tmp = 1;
        for (int i = 1; i <= r; i++) {
            tmp *= n - i + 1;
            tmp = mod(tmp);
            tmp *= inv(i);
            tmp = mod(tmp);
        }
        return tmp;
    }

    /**
     * 階乗計算の事前累積和
     * [1, 1, 2, 3, 4, 5, … FACTORIAL_NUM]
     * mod済
     */
    void prepareFact() {
        fact = new long[MAX_FACT];
        Arrays.fill(fact, 0);
        invFact = new long[MAX_FACT];
        Arrays.fill(invFact, 0);
        fact[0] = 1;
        int maxIndex = (int) min(MAX_FACT, (int) MOD);
        for (int i = 1; i < maxIndex; i++) {
            fact[i] = mod(fact[i - 1] * i);
        }
        invFact[maxIndex - 1] = inv(fact[maxIndex - 1]);
        for (int i = maxIndex - 1; i > 0; i--) {
            invFact[i - 1] = mod(invFact[i] * i);
        }
    }

    /**
     * 順列
     * nPk -> n! / (n-k)!
     *
     * @param n
     * @param r
     * @return
     */
    long permutation(int n, int r) {
        if (n < 0 || r < 0 || n < r) {
            return 0;
        }
        return mod(fact[n] * invFact[n - r]);
    }

    /**
     * 組み合わせ
     * nCk -> n! / k!・(n-k)!
     *
     * @param n
     * @param r
     * @return
     */
    long combination(int n, int r) {
        if (n < 0 || r < 0 || n < r) {
            return 0;
        }
        return mod(permutation(n, r) * invFact[r]);
    }

    /**
     * 重複組合せ nHr （同次積）
     * nHr = (n+r-1)Cr
     * 異なるn個のものから重複を許してr個取る組合せの総数
     * 例：
     * リンゴ，ミカン，牛肉の3種類の果物があります．これらの中から6個の食材を買って帰ります．
     * このとき，何通りの買い方がありますか？ただし，含まれない食材があってもよいものとします
     *
     * @param n
     * @param r
     * @return
     */
    long homogeneousProduct(int n, int r) {
        return combination((n - 1) + r, r);
    }

    /**
     * 多項係数
     * 文字aをp個,bをq個,cをr個, dをs個 あわせてn個を1列に並べるときの並べ方
     * n! / p!・q!・r!・s!
     *
     * @param n
     * @param strNum
     * @param mod
     * @return
     */

    /**
     * フェルマーの小定理を用いて逆元を求める。
     * ある数xのmod p（pは素数）の逆数x'はx' = x^(p-2)
     * 繰り返し二乗法を用いて計算する。
     * http://satanic0258.hatenablog.com/entry/2016/04/29/004730
     * {@link BigInteger#modInverse(BigInteger)}とどちらが速いか？
     *
     * @param x
     * @return
     */
    private long modInverse(long x, long mod) {
        long res = 1L;
        long k = mod - 2L;
        long y = x;
        while (k != 0) {
            if (k % 2 != 0) {
                res = (res * y) % mod;
            }
            y = (y * y) % mod;
            k /= 2;
        }
        return res;
    }

    private final PrintWriter out = new PrintWriter(System.out);
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
    }

    public boolean hasNext() {
        skipUnprintable();
        return hasNextByte();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public long min(long... v) {
        long min = Long.MAX_VALUE;
        for (long i : v) min = Math.min(min, i);
        return min;
    }

    public long max(long... v) {
        long max = Long.MIN_VALUE;
        for (long i : v) max = Math.max(max, i);
        return max;
    }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		char []s = sc.next().toCharArray();
		String t = sc.next();

		int n = s.length;
		int m = t.length();

		if(n < m) {
			System.out.println("UNRESTORABLE");
			return;
		}

		int cnt = m-1;
		int num = -1;

		for(int i = n-1 ;i >= 0 ;i--) {
			if(s[i] =='?' || s[i] == t.charAt(cnt)) {
				cnt--;
			}
			else {
				cnt = m-1;
			}
			if(cnt == -1) {
				num = i;
				break;
			}

		}

		cnt = 0;

		for(int i = 0 ;i < n ;i++) {
			if(num > i || cnt == m) {
				if(s[i] == '?') {
					s[i] = 'a';
				}
			}
			else {
				s[i] = t.charAt(cnt);
				cnt++;
			}
		}

		String ans = String.valueOf(s);
		if(cnt != -1) {
			System.out.println("UNRESTORABLE");
			return;
		}
		System.out.println(ans);
	}
}


import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		String s = sc.next();
		String t = sc.next();

		// 計算
		String result = "UNRESTORABLE";
		for(int i = s.length()-t.length(); i >= 0; i--){
		    boolean flg = true;
		    for(int j = 0; j < t.length(); j++){
		        if(i+j >= s.length()){
		            flg = false;
		            break;
		        }
		        if(s.charAt(i+j) != t.charAt(j) && s.charAt(i+j) != '?'){
		            flg = false;
		        }
		    }
		    if(flg){
		        String newS = s.replace('?', 'a');
		        result = newS.substring(0, i) + t + newS.substring(i+t.length());
		        break;
		    }
		}

		// 出力
		System.out.println(result);
	}
}


import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        String T = sc.nextLine();
        PriorityQueue<String> q = new PriorityQueue<String>();

        for (int i = S.length() - T.length(); i >= 0; i--) {
            String sub = S.substring(i, i + T.length());
            int k;
            int cnt = 0;
            for (k = 0; k < T.length(); k++) {
                if (sub.charAt(k) == '?') {
                    cnt++;
                    continue;
                }
                if (sub.charAt(k) != T.charAt(k))
                    break;
            }
            if (k == T.length()) {
                String ans = S.substring(0, i).replace('?', 'a');
                ans += T;
                ans += S.substring(i + T.length()).replace('?', 'a');;
                q.add(ans);
            }
        }
        if (q.peek() != null) {
            System.out.println(q.peek());
        } else {
            System.out.println("UNRESTORABLE");
        }
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        char[] S = s.toCharArray();
        char[] T = t.toCharArray();
        int slen = S.length;
        int tlen = T.length;
        char[] ans = null;
        boolean flg = false;
        if(s.indexOf(t)>=0) flg = true;
        for(int i=slen-tlen;i>=0;i--){
            if(diffCheck(S, T, i)){
                char[] tans = S.clone();
                for(int j=i;j<i+tlen;j++){
                    tans[j] = T[j-i];
                }
                if(ans == null || diff(ans,tans)>0){
                    ans = tans;
                }
            }
        }
        for(int i=0;i<ans.length;i++) ans[i]=ans[i]=='?'?'a':ans[i];
        System.out.println(String.valueOf(ans));
    }
    private static int diff(char[] a, char[] b){
        for(int i=0,e=a.length;i<e;i++){
            char c1 = a[i]=='?'?'a':a[i];
            char c2 = b[i]=='?'?'a':b[i];
            if(c1<c2) return -1;
            if(c1>c2) return 1;
        }
        return 0;
    }
    private static boolean diffCheck(char[] a, char[] b, int as){
        for(int i=0;i<b.length;i++){
            if(a[i+as] != b[i]){
                if(a[i+as] != '?'){
                    return false;
                }
            }
        }
        return true;
    }
}


import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        char[] s=sc.next().toCharArray();
        char[] t=sc.next().toCharArray();
        TreeSet<String> ts=new TreeSet<>();
        int sizeS=s.length;
        int sizeT=t.length;
        for (int i = 0; i <= sizeS-sizeT; i++) {
            int count=0,temp=0;
            for (int j = i; j < sizeT+i; j++) {
                if(s[j]=='?'||s[j]==t[j-i]){
                    count++;
                    temp=i;
                }
            }
            if(count==sizeT){
                String ans="";
                out.println("temp="+temp);
                for (int j = 0; j < sizeS; j++) {
                    out.println("j="+j);
                    out.println("ans="+ans);
                    if(j<temp){
                        if(s[j]=='?')ans+='a';
                        else ans+=s[j];
                    }else{
                        if(j-temp<sizeT)ans+=t[j-temp];
                        else if(s[j]=='?')ans+='a';
                        else ans+=s[j];
                    }
                }
                ts.add(ans);
            }
        }
        out.println(ts.size()==0?"UNRESTORABLE":ts.pollFirst());
    }
}


import java.io.*;
import java.util.*;

public class Main {

    private static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException exp) {
                    throw new RuntimeException(exp);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

    public static void main(String[] args) {    //throws FileNotFoundException {
        InputStream inputStream = System.in;    //new FileInputStream("input.txt");
        OutputStream outputStream = System.out; //new FileOutputStream("output.txt");
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task newTask = new Task();
        newTask.solve(in, out);

        out.close();
    }

    private static class Task {
        //.constant
        private final int INF = Integer.MAX_VALUE;
        private final int MOD = (int)1e9 + 7;

        //.data

        //.code
        public void solve(InputReader in, PrintWriter out) {
            String s = in.next();
            String t = in.next();

            for (int i = s.length() - t.length(); i >= 0; --i) {
                String sub = s.substring(i, i + t.length());
                boolean flag = true;
                for (int j = 0; j < t.length(); ++j) {
                    if (t.charAt(j) != sub.charAt(j) && sub.charAt(j) != '?') {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    StringBuilder ans = new StringBuilder();
                    for (int j = 0; j < i; ++j) {
                        ans.append((s.charAt(j) == '?') ? 'a' : s.charAt(j));
                    }
                    ans.append(t);
                    for (int j = i + t.length(); j < s.length(); ++j) {
                        ans.append((s.charAt(j) == '?') ? 'a' : s.charAt(j));
                    }
                    out.println(ans);
                    return;
                }
            }

            out.println("UNRESTORABLE");

        }//end

    }

}


import java.util.*;
public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String ss,t;
        ss = sc.next();
        t = sc.next();
        boolean f = true;
        int head = 0;
        for(int i=0;i<ss.length();i++){
            if(ss.charAt(i)==t.charAt(0) || ss.charAt(i)=='?'){
                head = i;
                for(int j=0;j<t.length();j++){
                    if(i+j>=ss.length()){
                        f = false;
                        break;
                    }
                    if(ss.charAt(i+j)==t.charAt(j) || ss.charAt(i+j)=='?'){

                        f = true;
                    } else {
                        f = false;
                        break;
                    }
                }
            if(f==true) break;
            }else{
                f = false;
            }

        }
        if(f==false){
            System.out.println("UNRESTORABLE");
        } else {
            String s = "";
            for(int i=0;i<head;i++){

                if(ss.charAt(i)!='?'){
                    s = s + ss.charAt(i);
                }else {
                    s = s+'a';
                }
            }
            s = s + t;
            for(int i= head + t.length();i<ss.length();i++){
                if(ss.charAt(i)!='?'){
                    s = s + ss.charAt(i);
                }else {
                    s = s+'a';
                }
            }
            System.out.println(s);
        }

    }

}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		char[] T = sc.nextLine().toCharArray();
		sc.close();
		String result = "UNRESTORABLE";
		StringBuilder sb = new StringBuilder();
		int indexS = 0;
		if (T.length <= S.length()) {
			boolean isTargetMain = false;
			for (int i = 0; i < T.length; i++) {
				indexS = S.indexOf(T[i]);
				if (S.length() - (indexS + 1) >= (T.length - (i + 1))
						&& indexS >= i) {
					boolean isTarget = true;
					int count = indexS;
					for (int j = i; j < T.length; j++) {
						if (S.charAt(count) != T[j] && S.charAt(count) != '?') {
							isTarget = false;
							break;
						}
						count++;
					}
					if (isTarget) {
						count = indexS - i;
						for (int j = 0; j < i; j++) {
							if (S.charAt(count) != T[j] && S.charAt(count) != '?') {
								isTarget = false;
								break;
							}
						}
						count++;
					} else {
						continue;
					}

					if (isTarget) {
						for (int k = 0; k < S.length(); k++) {
							if (k == indexS) {
								sb.append(T);
								k += T.length - 1;
							} else if (S.charAt(k) == '?') {
								sb.append('a');
							} else {
								sb.append(S.charAt(k));
							}
						}
						result = sb.toString();
						isTargetMain = true;
						break;
					}
				}
			}
			if (!isTargetMain) {
				StringBuilder sb1 = new StringBuilder();
				for (int i = 0; i < T.length; i++) {
					sb1.append('?');
				}
				indexS = S.indexOf(sb1.toString());
				if (indexS >= 0) {
					for (int k = 0; k < S.length(); k++) {
						if (k == indexS) {
							sb.append(T);
							k += T.length - 1;
						} else if (S.charAt(k) == '?') {
							sb.append('a');
						} else {
							sb.append(S.charAt(k));
						}
					}
					result = sb.toString();
				}
			}

		}
		System.out.println(result);
	}
}