Line-wrap into proper columns
GolfScript, 73 characters
n%(' '-:C;~:T,,1&gt;{T/zip{.,1&gt;*.&amp;.,1=*}%''*C&amp;C=},.{0=T/n*}{'no solution'}if

Breaks at the first position which is possible. The input must be given on STDIN in the format specified in the question.
Example (online):
X Y
abcdeXfYghijklmnXoYpqrstuvwXxYyzXYZ

abcdeXfYghi
jklmnXoYpqr
stuvwXxYyzX
YZ

Annotated code:
n%               # Split the input at newlines
(' '-:C;         # Extract the first line, remove all spaces
                 # and assign the resulting string to variable C
~:T              # Take the second line and assign this string
                 # to variable T
,,1&gt;             # Makes an array [1 2 3 ... L-1] where L is the 
                 # length of T
{                # A filter block {...}, selects all possible 
                 # line wrap positions from this array
  T/             #   Test the current length by splitting T (input)
                 #   in pieces
  zip            #   Transpose the result (i.e. we now have a array
                 #   of strings representing the columns)
  {              #   For each column
    .,1&gt;*        #     Is the length greater than one, then keep the column
                 #     else transforms it to the empty string (string * 0)
    .&amp;           #     &quot;and&quot;s the string with itself, i.e. the result
                 #     is a string of the distinct characters in the column
    .,1=*        #     If the length is 1 (i.e. only one character) keep
                 #     the column, otherwise reduce it to the empty string
  }%
  ''*            #   Combine the resulting characters into a string again
  C&amp;C=           #   Check if this string contails all characters from C
},
.{               # If the filter returns at least one possible wrap position
  0=             #   Take the first one
  T/n*           #   Split the string and join again with newlines
}{               # Else
  'no solution'  #   Return 'no solution'
}if              # Endif