A Martian boy is named s — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets happy. For example, if s=«aba», then strings «baobab», «aabbaa», «helloabahello» make him very happy and strings «aab», «baaa» and «helloabhello» do not.

However rather than being happy once, he loves twice as much being happy twice! So, when he got string t as a present, he wanted to cut it in two parts (the left part and the right part) so that each part made him happy.

Help s determine the number of distinct ways to cut the given string t into two parts in the required manner.

Input

The first line contains string s, consisting of lowercase English letters. The length of string s is from 1 to 1000 letters.

The second line contains string t, that also consists of lowercase English letters. The length of string t is from 1 to 106 letters.

Output

Print the sought number of ways to cut string t in two so that each part made s happy. 

Examples

Input

aba
baobababbah


Output

2


Input

mars
sunvenusearthmarsjupitersaturnuranusneptune


Output

0
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    static MyScanner in;
    static PrintWriter out;
    //static Timer t = new Timer();
    
    public static void main(String[] args) throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out, true);
        
        char[] pat = in.next().toCharArray();
        char[] str = in.next().toCharArray();
        
        int i1 = -1, i2 = -1;
        
        //count front
        int index = 0;
        for(int i = 0; i < str.length; i++) {
            if(str[i] == pat[index]) {
                index++;
                if(index == pat.length) {
                    i1 = i;
                    break;
                }
            }
        }
        
        //count back
        index = pat.length - 1;
        for(int i = str.length - 1; i >= 0; i--) {
            if(str[i] == pat[index]) {
                index--;
                if(index == -1) {
                    i2 = i;
                    break;
                }
            }
        }
        
        if(i1 == -1 || i2 == -1 || i2 < i1)
            out.println(0);
        else
            out.println(i2 - i1);
    }
}

//<editor-fold defaultstate="collapsed" desc="MyScanner">
class MyScanner {
    private final BufferedReader br;
    private StringTokenizer st;

    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    
    public MyScanner(File r) throws FileNotFoundException {
        br = new BufferedReader(new FileReader(r));
    }
    
    public MyScanner(String path) throws FileNotFoundException {
        br = new BufferedReader(new FileReader(new File(path)));
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }
    
    boolean hasNext()  {
        if(st != null && st.hasMoreElements())
            return true;
        
        try {
            while (st == null || !st.hasMoreElements())
                st = new StringTokenizer(br.readLine());
        }
        catch(Exception e) {
            return false;
        }
        
        return true;
    }
    
    String nextLine() throws IOException {
        return br.readLine();
    }
    
    String[] nextStrings(int n) throws IOException {
        String[] arr = new String[n];
        for(int i = 0; i < n; i++)
            arr[i] = next();
        return arr;
    }
    
    String[] nextLines(int n) throws IOException {
        String[] arr = new String[n];
        for(int i = 0; i < n; i++)
            arr[i] = nextLine();
        return arr;
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    
    int[] nextInts(int n) throws IOException {
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }
    
    int[][] next2Ints(int n, int m) throws IOException {
        int[][] arr = new int[n][m];
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                arr[i][j] = nextInt();
        return arr;
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }
    
    long[] nextLongs(int n) throws IOException {
        long[] arr = new long[n];
        for(int i = 0; i < n; i++)
            arr[i] = nextLong();
        return arr;
    }
    
    long[][] next2Longs(int n, int m) throws IOException {
        long[][] arr = new long[n][m];
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                arr[i][j] = nextLong();
        return arr;
    }

    double nextDouble(boolean replace) throws IOException {
        if(replace)
            return Double.parseDouble(next().replace(',', '.'));
        else
            return Double.parseDouble(next());
    }
    
    boolean nextBool() throws IOException {
        String l = next();
        if(l.equalsIgnoreCase("true") || l.equals("1"))
            return true;
        
        if(l.equalsIgnoreCase("false") || l.equals("0"))
            return false;
        
        throw new IOException("Boolean expected, String found!");
    }
}
//</editor-fold>