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.util.*;
import java.io.*;
// MAMA / MAMA / MAMA
// mama / mamamama
// mamama / mamama
// mamamama / mama
//
public class Main {
    public static void main(String[] args) {
       // System.out.println(happyFirst("aba", "baobab"));
        /*System.out.println(happy("aba", "aabbaa"));
        System.out.println(happy("aba", "helloabahello"));
        System.out.println(happy("aba", "aab"));
        System.out.println(happy("aba", "baaa"));
        System.out.println(happy("aba", "helloabhello"));*/
        Scanner in = new Scanner(System.in);
        String c_s = in.nextLine();
        String c_t = in.nextLine();
        int a = happyFirst(c_s, c_t);
        int b = happyLast(c_s, c_t);
        if (b-a < 0) System.out.println(0);
        else System.out.println(b-a);
        //b -= c_s.length() - 1;
        //System.out.println(a  + " (" + c_t.charAt(a) + "), " + b + " (" + c_t.charAt(b) + ")");
        /*int a = happyFirst(c_s, c_t) - 1;
        int b = -1;
        for (int i = c_t.length() - 1; i > 0; i --) {
            int x = happyFirst(c_s, c_t.substring(i));
            if (x != -1) {
                b = x + i - 1 - c_s.length();
                break;
            }
        }
        System.out.println(a + " " + b);
        if (a == b || (a == -1) || (b == -1)) System.out.println( 0 );
        else {
            System.out.println(b - a);
        }*/
        /*int b = -1;
        for (int i = c_t.length() - 1; i > 0; i --) {
            int x = happyFirst(c_s, c_t.substring(i));
            if (x != -1) {
                b = x + i - 1 - c_s.length();
                break;
            }
        }
        System.out.println(b + " " + a);
        if (a == (b + c_s.length()) || (a == -1) || (b == -1)) System.out.println(0);
        else {
            System.out.println(b - a + 1);
        }*/
    }

     public static int happyFirst(String s, String t) {
        int j = 0, i = 0;
        for ( ; i < s.length(); i ++) {
            if (j >= t.length()) break;
            while (s.charAt( i ) != t.charAt( j )) {
                j ++;
                if (j >= t.length()) break;
            }
            j ++;
        }

        if (i == s.length() && j <= t.length() && s.charAt(i - 1) == t.charAt(j - 1)) {
            //System.out.println(s.charAt(i - 1) + " " + t.charAt(j));
            return j - 1;
        }
        else return -1;
    }

    public static int happyLast(String s, String t) {
        int ind = t.length() - 1;
        for (int i = s.length() - 1; i >= 0; i--)
        {
            int j;
            for (j = ind; j >= 0; j--)
            {
                if (s.charAt(i) == t.charAt(j))
                    break;
            }
            ind = j - 1;
        }
        return ind + 1;
    }

    /*public static int happyLast(String s, String t) {
        int j = t.length() - 1, i = s.length() - 1;
        for ( ; i > 0; i --) {
            if (j < 0) break;
            while (s.charAt( i ) != t.charAt( j )) {
                j --;
                if (j < 0) break;
            }
            j --;
        }
        if (i == 0 && j >= 0) return j;
        else return -1;
    }*/

}

// MA MA  / MA / MA / MA / MA MA

// RASSERASSER

//