The secret services need you !
Statement
Goal
Your government has found an important file encrypted with a password. The length of the password and the potential characters are known. It's up to you to generate the possible combinations that the government will use to try to open the file.A password of length 2 with characters A and B will produce the following combinations : (AA, BA, AB, BB)
The order of arrival of the characters must be respected. The characters must be swapped from the left before advancing like a conventional combination lock.
If the order of arrival is "1 2 3" and the length of the password is 2 then the valid result is
11
21
31
12
22
32
13
23
33
Input
Line 1 : An integer length for the password length.
Line 2 : An integer charCount for the number of different characters possible.
Line 3 : A string characters of charCount different characters separated by spaces.
Line 2 : An integer charCount for the number of different characters possible.
Line 3 : A string characters of charCount different characters separated by spaces.
Output
The different combinations of characters possible.
Constraints
1 ≤ size ≤ 5
All chars of characters are different
All chars of characters are different
Example
Input
2 3 1 2 3
Output
11 21 31 12 22 32 13 23 33
Game modes
Fastest, Shortest, Reverse
Test cases
Test 1 Test
Input
2
3
1 2 3
Output
11
21
31
12
22
32
13
23
33
Validator 1 Validator
Input
3
2
O I
Output
OOO
IOO
OIO
IIO
OOI
IOI
OII
III
Test 2 Test
Input
3
2
1 2
Output
111
211
121
221
112
212
122
222
Validator 2 Validator
Input
3
3
R S T
Output
RRR
SRR
TRR
RSR
SSR
TSR
RTR
STR
TTR
RRS
SRS
TRS
RSS
SSS
TSS
RTS
STS
TTS
RRT
SRT
TRT
RST
SST
TST
RTT
STT
TTT
Test 3 Test
Input
3
3
1 2 $
Output
111
211
$11
121
221
$21
1$1
2$1
$$1
112
212
$12
122
222
$22
1$2
2$2
$$2
11$
21$
$1$
12$
22$
$2$
1$$
2$$
$$$
Validator 3 Validator
Input
1
1
Z
Output
Z
Test 4 Test
Input
3
3
L O V
Output
LLL
OLL
VLL
LOL
OOL
VOL
LVL
OVL
VVL
LLO
OLO
VLO
LOO
OOO
VOO
LVO
OVO
VVO
LLV
OLV
VLV
LOV
OOV
VOV
LVV
OVV
VVV
Validator 4 Validator
Input
3
4
# & [ ]
Output
###
&##
[##
]##
#&#
&&#
[&#
]&#
#[#
&[#
[[#
][#
#]#
&]#
[]#
]]#
##&
&#&
[#&
]#&
#&&
&&&
[&&
]&&
#[&
&[&
[[&
][&
#]&
&]&
[]&
]]&
##[
&#[
[#[
]#[
#&[
&&[
[&[
]&[
#[[
&[[
[[[
][[
#][
&][
[][
]][
##]
&#]
[#]
]#]
#&]
&&]
[&]
]&]
#[]
&[]
[[]
][]
#]]
&]]
[]]
]]]
Test 5 Test
Input
3
3
{ [ (
Output
{{{
[{{
({{
{[{
[[{
([{
{({
[({
(({
{{[
[{[
({[
{[[
[[[
([[
{([
[([
(([
{{(
[{(
({(
{[(
[[(
([(
{((
[((
(((
Validator 5 Validator
Input
3
3
} ] )
Output
}}}
]}}
)}}
}]}
]]}
)]}
})}
])}
))}
}}]
]}]
)}]
}]]
]]]
)]]
})]
])]
))]
}})
]})
)})
}])
]])
)])
}))
]))
)))
Test 6 Test
Input
1
1
Z
Output
Z
Validator 6 Validator
Input
1
1
A
Output
A
Test 7 Test
Input
4
1
Z
Output
ZZZZ
Validator 7 Validator
Input
4
1
A
Output
AAAA
Test 8 Test
Input
4
2
A B
Output
AAAA
BAAA
ABAA
BBAA
AABA
BABA
ABBA
BBBA
AAAB
BAAB
ABAB
BBAB
AABB
BABB
ABBB
BBBB
Validator 8 Validator
Input
4
2
C D
Output
CCCC
DCCC
CDCC
DDCC
CCDC
DCDC
CDDC
DDDC
CCCD
DCCD
CDCD
DDCD
CCDD
DCDD
CDDD
DDDD
Solution language
Solution
Stub generator input