This page is still under construction.

Parts of this page are still being built. What you see may change.

Counting substrings

Interview

Time limit1sMemory limit1024 MB

Summary
Count the distinct strings that can be built from some subset of the distinct letters of S and that contain P as a contiguous substring.
Level

Medium6 of 10

Topics
Backtracking, Combinatorics, String, Brute force
Solved
No attempts yet

Problem

Strings SS and PP consisting of lowercase Latin letters are given.

Write a program substrings that determines the number of distinct words made from the letters of SS that contain PP as a substring.

Input

The first line of the standard input contains the string SS, and the second line contains the string PP.

Output

On a single line of the standard output, the program must print a single integer: the number of distinct words.

Constraints

  • 1≤1 \le number of characters in the strings ≤16\le 16
  • All characters in the string SS are distinct.

Hint

Explanation of example 1: The substrings are bc, abc, bca, dbc, bcd, adbc, dabc, abcd, dbca, bcad, bcda.

Examples2

  1. Example 1

    Input
    dcba
    bc
    
    Expected output
    11
    
  2. Example 2

    Input
    xyz
    xx
    
    Expected output
    0