#P3856. Common Substrings in Three Strings
Common Substrings in Three Strings
Common Substrings in Three Strings
You are given three strings. A substring of a string is defined as a contiguous sequence of characters that can be obtained by removing zero or more characters from the beginning and/or the end of the string. For example, for the string aabbcc, substrings such as abc, aa, and abbc are valid, while aba is not.
Your task is to determine how many distinct (non-empty) substrings are common to all three given strings. Note that even if the same substring occurs at different positions, it should be counted only once.
The mathematical formulation can be expressed as:
\( Answer = |\{ x \mid x \text{ is a non-empty substring of } s_1 \text{ and } x \text{ is a substring of } s_2 \text{ and } x \text{ is a substring of } s_3 \}| \)
inputFormat
The input consists of three lines. Each line contains one string.
outputFormat
Output a single integer representing the number of distinct non-empty substrings that appear in all three strings.
sample
a
a
a
1