Problem: 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

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.Vector;

/**
 * Created by Arthur on 3/14/2015.
 */
public class Main {

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

    Main() {
        initIO(false);
        solve();
        close();
    }

    FastScanner sc;
    PrintWriter pw;

    private void initIO(boolean files) {
        if (files) {
            sc = new FastScanner("input.txt");
            try {
                pw = new PrintWriter(new FileOutputStream("output.txt"), false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            sc = new FastScanner(System.in);
            pw = new PrintWriter(System.out);
        }
    }

    private void close() {
        sc.close();
        pw.close();
    }

    private void solve() {
        String s1 = sc.next();
        String s2 = sc.next();
        int n = s1.length();
        int m = s2.length();
        boolean a[] = new boolean[m];
        boolean b[] = new boolean[m];
        int p = 0;
        for (int i = 0; i < m; i++) {
            if (p == n) {
                a[i] = true;
                continue;
            }
            if (s1.charAt(p) == s2.charAt(i)) {
                p++;
            }
            a[i] = p == n;
        }
        p = 0;
        s1 = reverse(s1);
        for (int i = m-1; i >= 0; i--) {
            if (p == n) {
                b[i] = true;
                continue;
            }
            if (s1.charAt(p) == s2.charAt(i)) {
                p++;
            }
            b[i] = p == n;
        }
        int ans = 0;
        for (int i = 1; i < m; i++) {
            if (b[i] && a[i-1]) ans++;
        }
        pw.println(ans);
    }

    private String reverse(String s) {
        String res = "";
        for (int i = s.length() - 1; i >= 0; i--) {
            res += s.charAt(i);
        }
        return res;
    }
}

class FastScanner {

    BufferedReader br;
    StringTokenizer st;

    FastScanner(String file) {
        try {
            br = new BufferedReader(new FileReader(file));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        st = new StringTokenizer("");
    }

    FastScanner(InputStream is) {
        br = new BufferedReader(new InputStreamReader(is));
        st = new StringTokenizer("");
    }

    String next() {
        try {
            while (!st.hasMoreElements()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return st.nextToken();
    }

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

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

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

    public void close() {
        try {
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

class VectorInt {
    int capacity = 2;
    int data[] = new int[capacity];
    int size = 0;

    VectorInt() {
    }

    public VectorInt(int n) {
        this();
        setSize(n);
    }

    void add(int x) {
        if (size == capacity) grow();
        data[size++] = x;
    }

    void set(int x, int y) {
        data[x] = y;
    }

    int get(int x) {
        return data[x];
    }

    void remove() {
        if (size == 0) throw new IndexOutOfBoundsException();
        size--;
    }

    private void grow() {
        capacity = size + (size >> 1);
        data = Arrays.copyOf(data, capacity);
    }

    private void grow(int newSize) {
        capacity = newSize;
        data = Arrays.copyOf(data, capacity);
    }

    void setSize(int newSize) {
        if (newSize > capacity) {
            grow(newSize);
        }
        size = newSize;
    }

    public void readIn(FastScanner sc, int n) {
        int lastSize = size;
        setSize(size + n);
        for (int i = 0; i < n; i++) {
            data[lastSize + i] = sc.nextInt();
        }
    }

    public void print(PrintWriter pw) {
        for (int i = 0; i < size; i++) {
            pw.print(data[i] + " ");
        }
        pw.println();
    }
}