Account
GitHubFeedback
Drafts and results saved on this device
Submit on CSES.fi
CSES Problemset/Introductory Problems

Creating Strings

#1622
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

Time limit:1.00 s
Memory limit:512 MB
Unsolved
Download Tests (.zip)

Given a string, your task is to generate all different strings that can be created using its characters.

Input

The only input line has a string of length nn. Each character is between a–z.

Output

First print an integer kk: the number of strings. Then print kk lines: the strings in alphabetical order.

Constraints
  • 1≤n≤81 \le n \le 8
Sample Test Cases (1)
Example 1ID: sample-1
Input
aabac
Expected Output
20
aaabc
aaacb
aabac
aabca
aacab
aacba
abaac
abaca
abcaa
acaab
acaba
acbaa
baaac
baaca
bacaa
bcaaa
caaab
caaba
cabaa
cbaaa
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 chars
Test Bench
Download .zip
Input (stdin)
aabac
Expected Output
20
aaabc
aaacb
aabac
aabca
aacab
aacba
abaac
abaca
abcaa
acaab
acaba
acbaa
baaac
baaca
bacaa
bcaaa
caaab
caaba
cabaa
cbaaa