p01441 Full Text Search_28800
Mr. Don is an administrator of a famous quiz website named QMACloneClone. The users there can submit their own questions to the system as well as search for question texts with arbitrary queries. This search system employs bi-gram search method.

The bi-gram search method introduces two phases, namely preprocessing and search:

Preprocessing Precompute the set of all the substrings of one or two characters long for each question text.

Search Compute the set for the query string in the same way. Then nd the question texts whose precomputed sets completely contain the set constructed from the query.

Everything looked fine for a while after the feature was released. However, one of the users found an issue: the search results occasionally contained questions that did not include the query string as-is. Those questions are not likely what the users want. So Mr. Don has started to dig into the issue and asked you for help. For each given search query, your task is to find the length of the shortest question text picked up by the bi-gram method but not containing the query text as its substring.

Note

Let's consider the situation that one question text is "CloneQMAC". In this situation, the set computed in the preprocessing phase is {"C", "Cl", "l", "lo", "o", "on", "n", "ne", "e", "eQ", "Q", "QM", "M", "MA", "A", "AC"}.

In the testcase 2, our input text (search query) is "QMAClone". Thus the set computed by the program in the search phase is {"Q", "QM", "M", "MA", "A", "AC", "C", "Cl", "l", "lo", "o", "on", "n", "ne", "e"}.

Since the first set contains all the elements in the second set, the question text "CloneQMAC" is picked up by the program when the search query is "QMAClone" although the text "CloneQ-MAC" itself does not contain the question text "QMAClone". In addition, we can prove that there's no such text of the length less than 9, thus, the expected output for this search query is 9.



Input

The input consists of multiple datasets. A dataset is given as a search query on each line. The input ends with a line containing only a hash sign ("#"), which should not be processed.

A search query consists of no more than 1,000 and non-empty lowercase and/or uppercase letters. The question texts and queries are case-sensitive.

Output

For each search query, print the minimum possible length of a question text causing the issue. If there is no such question text, print "No Results" in one line (quotes only to clarify).

Examples

Input

a
QMAClone
acmicpc
abcdefgha
abcdefgdhbi
abcbcd
#


Output

No Results
9
7
9
12
6


Input

a
QMAClone
acmicpc
abcdefgha
abcdefgdhbi
abcbcd


Output

No Results
9
7
9
12
6
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		while (true) {
			char[] s = sc.next().toCharArray();
			if (s.length == 1 && s[0] == '#')
				break;
			solve(s);
		}
	}

	void solve(char[] s) {
		int[] v = new int[s.length];
		for (int i = 0; i < s.length; ++i) {
			v[i] = s[i] - 'A';
		}
		boolean[] valid = new boolean['z' - 'A' + 1];
		for (int i = 0; i < v.length; ++i) {
			valid[v[i]] = true;
		}
		@SuppressWarnings("unchecked")
		ArrayList<Integer>[] g = new ArrayList['z' - 'A' + 1];
		for (int i = 0; i < g.length; ++i) {
			g[i] = new ArrayList<>();
		}
		int e_sz = 0;
		for (int i = 0; i + 1 < v.length; ++i) {
			if (!g[v[i]].contains(v[i + 1])) {
				g[v[i]].add(v[i + 1]);
				++e_sz;
			}
		}

		if (v.length <= 2) {
			System.out.println("No Results");
			return;
		}
		int[] indegree = new int[g.length];
		int[] outdegree = new int[g.length];
		for (int i = 0; i < g.length; ++i) {
			if (!valid[i])
				continue;
			outdegree[i] = g[i].size();
			for (int dst : g[i]) {
				++indegree[dst];
			}
		}

		int d = 0;
		for (int i = 0; i < g.length; ++i) {
			if (!valid[i])
				continue;
			if (indegree[i] - outdegree[i] > 0)
				d += indegree[i] - outdegree[i];
		}

		if (d == 0) {
			System.out.println(e_sz + 1);
			return;
		}

		if (d == 1) {
			System.out.println(semi_Eulerian(g, v, valid, indegree, outdegree, e_sz));
			return;
		}

		if (d >= 2) {
			System.out.println(e_sz + d);
			return;
		}

	}

	int semi_Eulerian(ArrayList<Integer>[] g, int[] v, boolean[] valid, int[] indegree, int[] outdegree, int e_sz) {
		if (e_sz + 1 < v.length) {
			return e_sz + 1;
		}
		if (e_sz + 1 != v.length) {
			throw new AssertionError();
		}
		int src = -1;
		int dst = -1;
		for (int i = 0; i < g.length; ++i) {
			if (!valid[i])
				continue;
			if (indegree[i] - outdegree[i] > 0)
				dst = i;
			else if (indegree[i] - outdegree[i] < 0)
				src = i;
		}
		if (src == v[0] && dst == v[v.length - 1]) {
			if (dfs(g, new boolean[g.length][g.length], src, 0, e_sz) > 1)
				return v.length;
			return v.length + 1;
		} else {
			return v.length;
		}
	}

	int dfs(ArrayList<Integer>[] g, boolean[][] vis, int cur, int num, int e_sz) {
		if (e_sz == num)
			return 1;
		int sum = 0;
		for (int dst : g[cur]) {
			if (vis[cur][dst])
				continue;
			vis[cur][dst] = true;
			sum += dfs(g, vis, dst, num + 1, e_sz);
			if (sum >= 2)
				return sum;
			vis[cur][dst] = false;
		}
		return sum;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
a
QMAClone
acmicpc
abcdefgha
abcdefgdhbi
abcbcd a
QMAClone
acmicpc
abcdefgha
abcdefgdhbi
abcbcd
# `
QMAClone
acmicpc
abcdefgha
abcdefgdhbi
abcbcd `
QMAClone
acmicpc
abcdefgha
abcdefgdibi
abcbcd `
QMAClone
acmicpc
abcdefhha
abcdefgdibi
abbbcd a
RMAClone
mcaicpc
ahgfedcba
abcdefgdhbi
dbcbca
$ `
QLAClone
accimpb
abcdefhha
bbcdefgeibi
abcbcc `
enolACMR
cpaiccm
ahgfedcba
abbeefgdhbh
dbcbca
" _
enolACLR
cpaiccm
ahgfedcba
abbeefgdhbh
cbcbca
! _
enolCALQ
pbnicca
abcdeehha
bbcdefgeibi
abcbdc _
enolACLR
cpaiccm
bhgfedcba
abbeefgdhbh
cbcbca
! _
enolACLR
cpaiccm
bhgfedcba
abbeefgdhbh
ccbcba
! _
enolACLR
cpaiccm
bhgfedcba
abbeefgdhbh
ccbcba
  _
enolACLR
dpaiccm
bhgfedcba
hbhdgfeebba
ccbcba
  ^
QLAClone
pboicca
bbaedehga
bbcdefgeibi
abcbdc ]
dnomADMR
eoajemd
bhgeddcba
abbeegfbhdh
cbacba
  \
dnomAEMR
eoajemd
bhgeddcba
hhhbfdeebba
cbacba
  [
dmomAEMR
eoajemd
abcddeghb
hhhbfdaebbf
cbacba
  [
dmomAEMR
eoajemd
abcddeghb
hhhbfdaebbf
cbaabc
  [
dmomAEMR
eoajemd
abcddeghb
hhhbfdaebbf
dbaabc
  Z
dmolAEMR
eoajemd
abcddeghb
ihhbfdaebbf
bbaacd
  a
QMAClone
acmicpc
abcdefgh`
abcdefgdhbi
abcbcd `
QMAClone
acmicpc
abcdefhha
abcdefgdibi
acbbcd `
enolACMR
cpaiccm
abcdefgha
abbeefgdhbh
dbdbca
" ^
QLAClone
pboicca
bbaedehga
bbcdefgeibi
abcbdd _
Qn@CloLf
pbcioca
aghddeabb
bbcdefgeibi
dbbbbb ]
dnomADMR
eoajemd
bhgeddcba
abbeegfahdh
cbacba
  \
dnomAEMR
eoajemd
ahgeddcba
hhhbfdeebba
cbacba
  [
dmomAEMR
eoajemd
abcddeghb
hhhbfdfebba
cbabba
  a
RMAClone
acmicpc
abcdefgha
abccefgdhbi
bbcacd
# `
QMAClone
acmicpc
abcdefahh
bbcdefgeibi
aabbcc `
enolACMR
dpaiccm
ahgfedcba
hbhdgfeebba
dbcbca
" ^
enolCALQ
accimbp
abcdeehha
bbcdefgeibi
abcccc `
enolACLR
cpaiccm
ahgfedcba
bbbeefgdhbh
acbcbd
! [
dnomAEMR
eoajeme
abcddeghb
abbefdfbhhh
cbacba
  Z
RMEAlome
eoajfmd
abdddeghb
ihhbfdaebbf
bbaacd
  a
QMAClone
mdaicpc
abcdefgh`
abcdefgdhbi
abcbcd _
enolCAMR
mcaicpc
ahgfedcba
abbbefgdheh
dbcbca
# ^
enomACLR
doajdmd
bhgfedcba
hbidgfeebba
bcbcba
  ^
dnolACMR
eoajdmd
bhhfdddba
hbhdfgeebba
ccbcba
  ^
dnomAEMR
eoajemd
bhgfddcba
bbbeegfdhbh
dcacba
  `
QMAClone
admicpc
abcdefhha
abcdefgeibi
acbbcd _
enolCAMR
mcaicpc
ahgfedcba
abbbefgdheh
dccbba
# `
enolACLR
cpaiccm
ahgfedcba
bbbeeegehbh
acbcbd
! ^
enolBALQ
pboicca
abbedehga
eacdefgbibi
abccdc [
dmolAEMR
eoajemd
bhgeddcba
hhhbfdafbbf
acdacb
  _
enolCAMR
mcaicpc
ahgfedcb`
abbbefgdheh
dccbba
# `
enomACLR
cpaiccm
bhgfedcba
hbhdgfeebba
dbcbca
" _
eAolmBLR
cpaiccm
bhgfeecba
hbhdgfeebba
ccacba
  \
dnomADMR
eoajemd
abcdddghb
abbeegfahdh
caacba
  a
enolCAMR
cpciacm
ahdfegbca
abhdefgdcbi
dbcbda
$ `
QLAClone
cpmicca
ahgfedbba
iciegfedbbb
abcbcc _
enplADLR
cqaiccm
chgfedcba
bbbedfgdhbh
cbcbca
! ^
dnolACMR
moajdfd
bhhfdddba
hbhdfgeebbb
ccbcba
  \
dnomADMR
eoajemd
abcdddghb
abbeegfahdh
caacbb
  [
cmnlAEMS
emejaoe
abceddghb
hhhbfdaebbf
bbaacd
  Y
RMEAlome
eoajfmd
bhgededaa
ihhbfdaebbf
bbaacd
  `
eMAClooQ
adpicmc
abccefgha
ibjdgfedcba
abcbcd a
RMAClone
acmidqc
ahgfedcba
hbhdgfedcba
abcabd
" _
enplADLR
cqaiccm
chgfedcba
bbbedfgdhbh
cbbcca
! \
dmomAEMQ
eoajfmd
bbcddegib
hhhbfdaebbf
cbaabc
  [
cmnlAEMS
emejaoe
abbeddghb
hhhbfdaebbf
bbaacd
  `
QMAClone
acmicoc
ahbfcdega
abcdfegdhbi
accacd _
enolACLR
capiccm
abcdefghb
ecbaefgdhbh
bbbbbc
" a
RMAClone
acmicpc
abcdefgha
abcdefgdhbi
abcbcd
# a
RMAClone
acmicpc
ahgfedcba
abcdefgdhbi
abcbcd
# `
QMAClone
acmicpc
abcdefhha
abcdefgdibi
abcbcd a
RMAClone
mcaicpc
ahgfedcba
abcdefgdhbi
abcbcd
# a
RMAClone
mcaicpc
ahgfedcba
abcdefgdhbi
dbcbca
# `
QMAClone
acmicpc
abcdefhha
abcdefgdibi
abbbcc `
QMAClone
acmicpc
abcdefhha
bbcdefgdibi
abbbcc a
RMAClone
mcaicpc
ahgfedcba
abcdefgdhbh
dbcbca
# `
QMAClone
acmicpc
abcdefhha
bbcdefgeibi
abbbcc a
RMAClone
cpciacm
ahgfedcba
abcdefgdhbh
dbcbca
# `
QMAClone
accimpc
abcdefhha
bbcdefgeibi
abbbcc `
RMAClone
cpciacm
ahgfedcba
abcdefgdhbh
dbcbca
# `
QLAClone
accimpc
abcdefhha
bbcdefgeibi
abbbcc `
enolCAMR
cpciacm
ahgfedcba
abcdefgdhbh
dbcbca
# `
QLAClone
accimpc
abcdefhha
bbcdefgeibi
ccbbba `
enolCAMR
cpciacm
ahgfedcba
abbdefgdhbh
dbcbca
# `
QLAClone
accimpc
abcdefhha
bbcdefgeibi
ccbcba `
enolCAMR
cpciacm
ahgfedcba
abbeefgdhbh
dbcbca
# `
QLAClone
accimpc
abcdefhha
bbcdefgeibi
abcbcc `
enolACMR
cpciacm
ahgfedcba
abbeefgdhbh
dbcbca
# `
enolACMR
cpaiccm
ahgfedcba
abbeefgdhbh
dbcbca
# _
QLAClone
accimpb
abcdefhha
bbcdefgeibi
abcbcc _
QLAClone
accimbp
abcdefhha
bbcdefgeibi
abcbcc `
enolACMR
cpaiccm
abcdefgha
abbeefgdhbh
dbcbca
" _
enolCALQ
accimbp
abcdefhha
bbcdefgeibi
abcbcc `
enolACLR
cpaiccm
ahgfedcba
abbeefgdhbh
dbcbca
" _
enolCALQ
accimbp
abcdeehha
bbcdefgeibi
abcbcc `
enolACLR
cpaiccm
ahgfedcba
abbeefgdhbh
dbcbca
! _
enolCALQ
accinbp
abcdeehha
bbcdefgeibi
abcbcc _
enolACLR
cpaiccm
ahgfedcba
abbeefgdhbh
dbcbca
! _
enolCALQ
pbnicca
abcdeehha
bbcdefgeibi
abcbcc _
enolCALQ
pbnicca
abcdeehga
bbcdefgeibi
abcbdc _
enolACLR
cpaiccm
bhgfedcba
abbeefgdhbh
acbcbc
! _
enolCALQ
pbnicca
abbdeehga
bbcdefgeibi
abcbdc _
enolCALQ
pbnicca
abbedehga
bbcdefgeibi
abcbdc ^
enolCALQ
pbnicca
abbedehga
bbcdefgeibi
abcbdc _
enolACLR
cpaiccm
bhgfedcba
hbhdgfeebba
ccbcba
  ^
enolCALQ
pboicca
abbedehga
bbcdefgeibi
abcbdc
No Results
9
7
9
12
6 No Results
9
7
9
12
6 No Results
9
7
9
12
6
 No Results
9
7
9
11
6
 No Results
9
7
9
11
5
 No Results
9
7
9
12
6
No Results
 No Results
9
8
9
11
5
 No Results
9
7
9
11
6
No Results
 No Results
9
7
9
11
4
No Results
 No Results
9
8
9
11
6
 No Results
9
7
10
11
4
No Results
 No Results
9
7
10
11
5
No Results
 No Results
9
7
10
11
5
 No Results
9
8
10
11
5
 No Results
9
8
10
11
6
 No Results
9
8
10
11
4
 No Results
9
8
10
10
4
 No Results
9
8
10
9
4
 No Results
9
8
10
9
6
 No Results
9
8
10
9
7
 No Results
9
8
10
10
7
 No Results
9
7
10
12
6
 No Results
9
7
9
11
7
 No Results
9
7
9
11
5
No Results
 No Results
9
8
10
11
7
 No Results
9
8
10
11
3
 No Results
9
8
10
12
4
 No Results
9
8
9
10
4
 No Results
9
8
10
10
5
 No Results
9
7
9
12
7
 No Results
9
7
10
11
7
 No Results
9
8
9
11
6
No Results
 No Results
9
8
9
11
4
 No Results
9
7
9
10
6
No Results
 No Results
9
7
10
10
4
 No Results
9
8
8
10
7
 No Results
9
8
10
12
6
 No Results
9
7
9
10
6
 No Results
9
7
10
11
4
 No Results
9
8
8
11
5
 No Results
9
8
10
10
6
 No Results
9
8
9
11
7
 No Results
9
7
9
10
7
 No Results
9
7
9
9
6
No Results
 No Results
9
8
9
10
6
 No Results
9
8
10
9
5
 No Results
9
7
10
10
7
 No Results
9
7
10
11
6
No Results
 No Results
9
7
10
11
6
 No Results
9
8
8
12
6
 No Results
9
7
9
12
7
No Results
 No Results
9
7
9
10
5
 No Results
9
7
10
10
4
No Results
 No Results
9
8
8
10
5
 No Results
9
8
8
12
7
 No Results
9
7
10
9
7
 No Results
9
8
9
10
7
 No Results
9
8
9
12
6
 No Results
9
8
9
11
5
No Results
 No Results
9
7
10
10
6
No Results
 No Results
9
8
9
9
6
 No Results
9
7
9
9
7
 No Results
9
7
9
12
5
 No Results
9
7
10
11
3
No Results
 No Results
9
7
9
12
6
 No Results
9
7
9
12
6
 No Results
9
7
9
11
6
 No Results
9
7
9
12
6
 No Results
9
7
9
12
6
 No Results
9
7
9
11
5
 No Results
9
7
9
11
5
 No Results
9
7
9
11
6
 No Results
9
7
9
11
5
 No Results
9
7
9
11
6
 No Results
9
7
9
11
5
 No Results
9
7
9
11
6
 No Results
9
7
9
11
5
 No Results
9
7
9
11
6
 No Results
9
7
9
11
5
 No Results
9
7
9
11
6
 No Results
9
7
9
11
5
 No Results
9
7
9
11
6
 No Results
9
7
9
11
5
 No Results
9
7
9
11
6
 No Results
9
7
9
11
6
 No Results
9
8
9
11
5
 No Results
9
8
9
11
5
 No Results
9
7
9
11
6
No Results
 No Results
9
8
9
11
5
 No Results
9
7
9
11
6
No Results
 No Results
9
8
9
11
5
 No Results
9
7
9
11
6
No Results
 No Results
9
8
9
11
5
 No Results
9
7
9
11
6
No Results
 No Results
9
8
9
11
5
 No Results
9
8
9
11
6
 No Results
9
7
10
11
4
No Results
 No Results
9
8
9
11
6
 No Results
9
8
9
11
6
 No Results
9
8
9
11
6
 No Results
9
7
10
11
5
 No Results
9
8
9
11
6
