Input Format
A single line containing the string  and integer value  separated by a space.
Constraints

The string contains only UPPERCASE characters.
Output Format
Print the combinations with their replacements of string  on separate lines.

hackerrank itertools combinations with replacement problem solution in python

Problem solution in Python 3 programming language.

from itertools import combinations_with_replacement
S,k = input().split()
for i in combinations_with_replacement(sorted(S),int(k)):
 print("".join(i))

Second solution

# Enter your code here. Read input from STDIN. Print output to STDOUT
from itertools import combinations_with_replacement
s, n = input().split()
print(*[''.join(i) for i in combinations_with_replacement(
sorted(s), int(n))], sep="\n")

Problem solution in Python 2 programming language.

from itertools import combinations_with_replacement
S,k = raw_input().split()
for i in combinations_with_replacement(sorted(S),int(k)):
 print "".join(i)