cswork / OAOpen practice workspace

AmazonOA #346

Split Prefix Suffix

Estimated MediumJudge-ready

Topics (AI-labelled)HashingPrefix & Ranges

Split the whole string into two non-empty contiguous parts; the number of distinct letters that appear in both parts must be strictly greater than k. Find the number of valid split positions; this does not count repeated occurrences of shared characters.

Input

The string and k are given, separated by whitespace. Original bounds: a lowercase string of length 1..100000, and 0≤k≤26.

Output

Output a single integer, the answer.

Example 1

Input:

abbcac
1

Output:

2

Example 2

Input:

a
0

Output:

0

Example 3

Input:

aaaa
1

Output:

0

Example notes

The outputs of the three public examples are 2; 0; and 0, checked by independent enumeration or direct simulation.

Editorial

Loading solution…