FINGP - Fingerprints

no tags 

Professor Emad Eldin one of the best people in pattern recognition, he asked his students to create a program to check if a special pattern belongs to fingerprints of someone or not.

He said that we can consider that a computer reads the special pattern and the fingerprints as strings, and we can say that the special pattern belongs to the fingerprint if the last substring of the fingerprint string is the same as the special pattern string.

Your task is to help professor Emad students.

Input

The first line of the input contains special pattern string S (1 ≤ |S| ≤ 50). Second line will be a single integer N, the number of fingerprints (1 ≤ N ≤ 10). N lines follow, each line contains fingerprint string F (1 ≤ |F| ≤ 50).

Output

For each test case, print an integer K, the number of fingerprints strings that special pattern string belongs to it. Followed by K lines, each contains the fingerprint string that the special pattern string belongs to it. You should print the fingerprint strings in a lexicographical order. If there is no fingerprint belongs to the special pattern, print "Wrong fingerprints!" instead.

Examples

Input:
On
5
Pattern recognatiOn
CommOn patterN
game
organizatiOn
lion

Output:
2
Pattern recognatiOn
organizatiOn
Input:
Ze
2
Fingerprint
pattern design

Output:
Wrong fingerprints!

Notes

  • String S contains uppercase English letters ('A' - 'Z') and lowercase English letters ('a' - 'z') only.
  • All other strings in the input contains uppercase English letters ('A' - 'Z'), lowercase English letters ('a' - 'z') and spaces (' ') only.
  • All strings are case sensitive ('A' is not equal to 'a').
  • Lexicographical order is defined in following way. When we compare s and t, first we find the leftmost position with differing characters: si ≠ ti. If there is no such position (i.e. s is a prefix of t or vice versa) the shortest string is less. Otherwise, we compare characters si and ti according to their order in alphabet.

hide comments
RR: 2022-12-27 09:29:16

Completely agree with nadstratosfer. Idiotic problem which shouldn't be in classical problemset. The only reason for this problem's existence is to annoy users with random programming language restrictions (e.g. why tf is Pypy 3 not allowed when Python 3 is allowed??) and dumb whitespaces in input just to annoy users who use some languages.

lumaks_69: 2022-01-06 22:36:27

SPACEEEEEEEESSS

rkjandu: 2018-08-03 14:29:46

@Atif, My solution is correct and I have taken care of space also. But still getting WA. My solution id 22089909.

Last edit: 2018-08-03 14:30:10
nadstratosfer: 2017-10-12 13:38:56

Idiotic problem that can be solved with a builtin if you have the patience to guess which whitespaces are supposed to be left there. All the frustration with string problems that you know all too well from wrong judge settings or incompetently designed testfiles is cooked up on purpose here. Mean and useless.

Karen: 2016-04-29 17:30:35

Very easy
Just be careful because in the end of the string can be SPACE

Rishav Goyal: 2015-11-19 11:11:45

RIP PROBLEM.

anuraagbaishya: 2015-10-17 22:26:24

Getting WA. I have taken care of spaces as well. Please check. @atef

hodobox: 2015-09-09 14:07:29

You should mention that when comparing strings, we take into consideration their ASCII values (or atleast capital < lowercase) instead of alphabet order, because my code outputs ZZZZ before aaaa, because in ASCII a>Z, but a definitely isn't after Z in the alphabet.

Shivaraj Lakka: 2015-09-02 20:15:53

Hi Atef,
Can you check my solution.? getting WA, I have taken care of space as well... plz check and let me know.
my solution ID: 15050538

atef: 2015-06-20 11:16:01

@Nick
try this test case man

a
8
abc aa
za za
az aza a
ab ba
ba
a
abfk
aa

it should output 7 :)


Added by:atef
Date:2015-04-24
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: MAWK BC C-CLANG NCSHARP CPP14-CLANG COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH JULIA KTLN NIM OBJC OBJC-CLANG OCT PICO PROLOG PYPY3 R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA