P29008 [洛谷] Order Spell
提高+
题目描述

Problem Description

Modern wizards Little L and Little K are studying spells.

"Do you know how to use spells?"

"Of course, it's the most basic skill for a modern wizard."

"How much do you know about the history of spells?"

"I remember some from the lecture. It was a long, long time ago. Back then, no one knew how to use spells, and chaos magic was the mainstream in the magical world. It was an evil art that required no skill or rules; the darker one's heart, the stronger the power. As a result, evil wizards turned against each other, causing chaos and bloodshed. Among them, a group of wizards led by a self-proclaimed 'Chaos Demon' controlled almost the entire magical world through dirty means, making it difficult for wizards who sought order and peace to survive. At this critical moment, two wizards named Lehmuella and Kenmiedoka bravely stood up. With just their strength, they fought the Chaos Demon group in a decisive battle but were ultimately outnumbered and cornered. As the final attack from the Chaos Demon hit them, Lehmuella and Kenmiedoka used the immense magical power of this attack to elevate the remaining magic and will of both into a concept, creating the Order Spell system, which turned the world theory around, forever sealing chaos magic. The Chaos Demon also perished in this intense distortion. Since then, the magical world has transitioned from the Chaos Era to the Order Era, following the legacy of the two saints Lehmuella and Kenmiedoka, using spells under the Order Spell system, until now."

"That's how it is. We need to follow a series of principles to use spells because of this."

"Yes, these are the efforts of the two saints to prevent the world from regressing to the Chaos Era. By the way, you just attended your first magic class last week. Do you remember some of the principles for using spells?"

"Let me think. First, it must appear in the order sequence. The system left by the two saints, through the unremitting efforts of later wizards, has been translated into what is known as the order sequence. For the convenience of modern wizards, the order sequence consists only of lowercase English letters. Due to the immense power of the system, the legacy of the two saints has been transferred into two order sequences. Spells must be constrained by the order sequence. Specifically, they must appear in the order sequence (be a substring of the order sequence). Since the legacy of the two saints cannot be divided, the spell must appear in both order sequences. Second, to make the spell stable and precise, the order system specifies the form of the spell. Specifically, the first character of the spell must be the same as the last character, the second character must be the same as the second to last character, and so on. This ensures that the spell is symmetrical and orderly. What else...?"

"That's enough, the most important points are these. Also, you might not know, but the longer the spell, the more powerful it is."

"Is that so? No wonder the spell demonstrated by the teacher that day was so much more powerful than mine."

"Exactly. Haven't you noticed that there is a maximum limit to the power of spells?"

"Ah, that's right. But the teacher said that day, the user of the strongest spell hasn't appeared yet?"

"Yes. The user must have the same level of ability as the spell to use it smoothly. We beginners don't know when we'll reach that level..."

"Ah... Why don't we count the length of the most powerful spells and how many there are?"

"Sure, since we have nothing else to do, let's do something we can manage."

So, Little L and Little K started counting the length and number of the most powerful spells. But soon, they couldn't continue because the order sequences were too long.

Now, as an experienced wizard, you need to inform them of this basic knowledge. You already know the forms of the two order sequences, please help Little L and Little K calculate the length and number of the most powerful spells.

Input Format

The first line contains two integers \( n, m \), representing the lengths of the two order sequences.

The second and third lines are two strings, representing the two order sequences, with lengths \( n \) and \( m \) respectively.

Output Format

One line with two integers separated by a single space, representing the length and number of the most powerful spells.

Sample Input and Output

Sample Input #1

6 7
aaabab
ababaaa

Sample Output #1

3 3

Sample Input #2

10 10
bbaabaaaac
bbaabaaaac

Sample Output #2

5 1

Notes/Hints

Sample Explanation

Sample 1: The valid spells are \( a, b, aa, aaa, aba, bab \), among which the strongest are \( aaa, aba, bab \), with a length of \( 3 \), totaling \( 3 \).

Sample 2: The valid spells are \( a, b, aa, aaa, aaaa, bb, baab, aba, aabaa, c \), among which the strongest is \( aabaa \), with a length of \( 5 \), totaling \( 1 \).

Data Range

Due to certain reasons, this problem requires the use of subtasks. To obtain the score for a subtask, you need to pass all data points in that subtask.

Score Range of \( n, m \) Special Properties
Subtask 1 0 \( 1 \le n, m \le 260817 \) Example
Subtask 2 5 \( 1 \le n, m \le 260817 \) Both order sequences consist of the same character
Subtask 3 5 \( 1 \le n, m \le 10 \) None
Subtask 4 10 \( 1 \le n, m \le 300 \) None
Subtask 5 10 \( 1 \le n, m \le 2000 \) None
Subtask 6 30 \( 1 \le n, m \le 260817 \) Both order sequences are identical
Subtask 7 40 \( 1 \le n, m \le 260817 \) None

Clearly, the same spell is counted only once. It is guaranteed that there is at least one valid spell with a length of at least \( 1 \).

Note that the time limit is \( 3 \) seconds.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
6 7 aaabab ababaaa
样例输出
3 3