primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157,
163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239]
bukvi = ('a'..'z').to_a + ('A'..'Z').to_a
TABLICA = Hash[bukvi.zip(1..52)]
CHISLA = primes.take(bukvi.size)
class String
def hesh
self.split('').reduce(1) { |a,b| CHISLA[TABLICA[b]] * a }
end
end
veshi = gets.chomp.split
birki = gets.chomp
veshi.permutation.each do |x|
i = 0
if x.all? { |vesh| vesh.hesh == birki[i..((i += vesh.size) - 1)].hesh }
krasivie_birki = ''
birki = birki.split('')
x.each { |s| krasivie_birki << (birki.shift(s.size).join + ' ') }
puts krasivie_birki
puts x.join(' ')
break
end
end
cHJpbWVzID0gWzIsIDMsIDUsIDcsIDExLCAxMywgMTcsIDE5LCAyMywgMjksIDMxLCAzNywgNDEsIDQzLCA0NywgNTMsIDU5LCA2MSwgNjcsIDcxLAo3MywgNzksIDgzLCA4OSwgOTcsIDEwMSwgMTAzLCAxMDcsIDEwOSwgMTEzLCAxMjcsIDEzMSwgMTM3LCAxMzksIDE0OSwgMTUxLCAxNTcsCjE2MywgMTY3LCAxNzMsIDE3OSwgMTgxLCAxOTEsIDE5MywgMTk3LCAxOTksIDIxMSwgMjIzLCAyMjcsIDIyOSwgMjMzLCAyMzldCgpidWt2aSA9ICgnYScuLid6JykudG9fYSArICgnQScuLidaJykudG9fYQpUQUJMSUNBID0gSGFzaFtidWt2aS56aXAoMS4uNTIpXQpDSElTTEEgPSBwcmltZXMudGFrZShidWt2aS5zaXplKQoKY2xhc3MgU3RyaW5nCiAgZGVmIGhlc2gKICAgIHNlbGYuc3BsaXQoJycpLnJlZHVjZSgxKSB7IHxhLGJ8IENISVNMQVtUQUJMSUNBW2JdXSAqIGEgfQogIGVuZAplbmQKCnZlc2hpID0gZ2V0cy5jaG9tcC5zcGxpdApiaXJraSA9IGdldHMuY2hvbXAKCnZlc2hpLnBlcm11dGF0aW9uLmVhY2ggZG8gfHh8CiAgaSA9IDAKICBpZiB4LmFsbD8geyB8dmVzaHwgdmVzaC5oZXNoID09IGJpcmtpW2kuLigoaSArPSB2ZXNoLnNpemUpIC0gMSldLmhlc2ggfQogICAga3Jhc2l2aWVfYmlya2kgPSAnJwogICAgYmlya2kgPSBiaXJraS5zcGxpdCgnJykKICAgIHguZWFjaCB7IHxzfCBrcmFzaXZpZV9iaXJraSA8PCAoYmlya2kuc2hpZnQocy5zaXplKS5qb2luICsgJyAnKSB9CiAgICBwdXRzIGtyYXNpdmllX2JpcmtpCiAgCXB1dHMgeC5qb2luKCcgJykKICAJYnJlYWsKICBlbmQKZW5k