E - Text Editor Gym - 101466E 二分+KMP查找子串的个数

E - Text Editor

 Gym - 101466E 

One of the most useful tools nowadays are text editors, their use is so important that the Unique Natural Advanced Language (UNAL) organization has studied many of the benefits working with them.

They are interested specifically in the feature "find", that option looks when a pattern occurs in a text, furthermore, it counts the number of times the pattern occurs in a text. The tool is so well designed that while writing each character of the pattern it updates the number of times that the corresponding prefix of the total pattern appears on the text.

Now the UNAL is working with the editor, finding patterns in some texts, however, they realize that many of the patterns appear just very few times in the corresponding texts, as they really want to see more number of appearances of the patterns in the texts, they put a lower bound on the minimum number of times the pattern should be found in the text and use only prefixes of the original pattern. On the other hand, the UNAL is very picky about language, so they will just use the largest non-empty prefix of the original pattern that fit into the bound.

Input

The first line contains the text A (1 ≤ |A| ≤  105) The second line contains the original pattern B (1 ≤ |B| ≤  |A|) The third line contains an integer n (1 ≤ n ≤  |A|) - the minimum number of times a pattern should be found on the text.

Output

A single line, with the prefix of the original pattern used by the UNAL, if there is no such prefix then print "IMPOSSIBLE" (without the quotes)

Examples

Input

aaaaa
aaa
4

Output

aa

Input

programming
unal
1

Output

IMPOSSIBLE

Input

abracadabra
abra
1

Output

abra

Input

Hello World!
H W
5

Output

IMPOSSIBLE

 

 

#include
using namespace std;
string s1,s2;
int n,flag,Next[100015];
void next_get(string b)//获取next数组 
{
	Next[0]=0;
	Next[1]=0;
	int j=0;
	int m=b.length();
	for(int i=1; i>n;
	int q=s2.length();
	int l=0,r=q,ans=0;
	string ss="",sq="IMPOSSIBLE";
	while(l<=r)//二分 
	{
		int mid=(l+r)/2;
		ss=s2.substr(0,mid);//获取子串
		if(mid==0) break;
		if(kmp(s1,ss)>=n)
		{
			sq=ss;
			l=mid+1;
		}
		else r=mid-1;
	}
	cout<

 

你可能感兴趣的:(模板,KMP)