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.math.*;
import java.util.*;
import java.util.concurrent.*;

@SuppressWarnings("unchecked")
public class P523C {
  
  int scan(String s, String t, boolean front) {
    int sidx = front ? 0 : s.length() - 1;
    int tidx = front ? 0 : t.length() - 1;
    int dir = front ? 1 : -1;

    while ((tidx >= 0) && (tidx < t.length())) {
      if (s.charAt(sidx) == t.charAt(tidx)) {
        sidx += dir;
      }

      if ((sidx < 0) || (sidx >= s.length())) {
        break;
      }

      tidx += dir;
    }

    return tidx;
  }

  public void run() throws Exception {
    String s = next();
    String t = next();

    int idxf = scan(s, t, true);
    int idxr = scan(s, t, false);

    println((idxf < idxr) ? (idxr - idxf) : 0);
  }

  // ---------------------------------------------------------------------------------------------
  public static void main(String... args) {
    try {
      new P523C().run();
    } catch (Exception e) {
      System.err.println(e);
    } finally {
      pw.close();
    }
  }

  final static String  inFile = null;
  final static String outFile = null;
  static InputStream  is = null;
  static OutputStream os = null;
  static {
    try {
      is = (( inFile == null) ? System.in  : new FileInputStream(  inFile));
      os = ((outFile == null) ? System.out : new FileOutputStream(outFile));
    } catch (Exception e) {
      System.err.println(e);
    }
  }
  final static BufferedReader br = new BufferedReader(new InputStreamReader(is));
  final static PrintWriter    pw = new PrintWriter(   new BufferedOutputStream(os));


  static StringTokenizer strTok = null;
  static String token() throws IOException {
    while ((strTok == null) || (!strTok.hasMoreTokens())) {
      strTok = new StringTokenizer(br.readLine());
    }
    return (strTok.nextToken());
  }

  void print(  char c) { print(c + ""); }
  void print(  long l) { print(l + ""); }
  void print(double d) { print(d + ""); }
  void print(Object o) { print(o + ""); }

  void printsp(  char c) { print(c + " "); }
  void printsp(  long l) { print(l + " "); }
  void printsp(double d) { print(d + " "); }
  void printsp(Object o) { print(o + " "); }
  void printsp(String s) { print(s + " "); }

  void println(  char c) { print(c + "\n"); }
  void println(  long l) { print(l + "\n"); }
  void println(double d) { print(d + "\n"); }
  void println(Object o) { print(o + "\n"); }
  void println(String s) { print(s + "\n"); }

  void println() { pw.println(); }
  void print(String s) { pw.print(s); }

  int    nextInt()    throws Exception { return Integer.valueOf(token()); }
  long   nextLong()   throws Exception { return Long.valueOf(token());    }
  double nextDouble() throws Exception { return Double.valueOf(token());  }
  String next()       throws Exception { return token();                  }
  String nextLine()   throws Exception { return br.readLine();            }

  int [] nextInt(int size) throws Exception {
    int [] arr = new int [size]; for (int i = 0; i < size; i++) arr[i] = nextInt(); return arr;
  }
  long [] nextLong(int size) throws Exception {
    long [] arr = new long [size]; for (int i = 0; i < size; i++) arr[i] = nextLong(); return arr;
  }
  double [] nextDouble(int size) throws Exception {
    double [] arr = new double [size]; for (int i = 0; i < size; i++) arr[i] = nextDouble(); return arr;
  }
  String [] next(int size) throws Exception {
    String [] arr = new String [size]; for (int i = 0; i < size; i++) arr[i] = next(); return arr;
  }
  String [] nextLines(int size) throws Exception {
    String [] arr = new String [size]; for (int i = 0; i < size; i++) arr[i] = nextLine(); return arr;
  }
}