output_description: If the conditions cannot be satisfied by writing 0 or 1 in each of the
  squares, print -1.
  
  If the conditions can be satisfied, print one way to fill the squares so that
  the conditions are satisfied, in the following format:
  
      
      
      s_{11}s_{12}\cdots s_{1W}
      s_{21}s_{22}\cdots s_{2W}
      \vdots
      s_{H1}s_{H2}\cdots s_{HW}
      
  
  Here s_{ij} is the digit written in the square at the i-th row from the top
  and the j-th column from the left in the grid.
  
  If multiple solutions exist, printing any of them will be accepted.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      H W A B
attempt: import copy
  
  x, y, a, b = list(map(int, input().split()))
  
  base = [a, b, x, y]
  c1 = [0] * x
  c2 = copy.deepcopy(c1)
  
  c1[:a] = [1] * a
  c2[: (len(c1) - a)] = [1] * (len(c1) - a)
  
  d1 = [a, a, x, x]
  if base[3] > 1 and base[2] > 1:
      if x % a == 0:
          d2 = [1, 1, x, 2]
          small = d2[3]
          large = d1[3]
          ans_sum = False
          for i in range(base[3] // large + 1):
              tsum = (large) * i
              nokori = base[3] - tsum
              i2 = nokori // small
              if (
                  nokori % small == 0
                  and base[3] == tsum + (small * i2)
                  and base[1] == d1[1] * i + d2[1] * i2
              ):
                  ans_sum = True
                  break
  
          if ans_sum:
              ans_sum = []
  
              if i > 0:
                  for h in range(i):
                      ans = [c1]
                      cc1 = copy.deepcopy(c1)
                      for i in range(d1[3] - 1):
                          y1 = cc1[::-1].index(1)
                          y2 = d1[3] - y1
                          cc1 = [0] * x
                          for j in range(d1[1]):
                              y3 = y2 + j
                              if y3 >= d1[3]:
                                  y3 = abs(d1[3] - y3)
                              cc1[y3] = 1
                          ans.append(cc1)
                      ans_sum.append(ans)
              if i2 > 0:
                  for h in range(i2):
                      ans = [c1]
                      cc1 = copy.deepcopy(c1)
                      for i, name in enumerate(cc1):
                          if name == 1:
                              cc1[i] = 0
                          else:
                              cc1[i] = 1
                      ans.append(cc1)
                  ans_sum.append(ans)
  
          else:
              ans_sum = "No"
      else:
          if y // d1[3] == b // d1[1]:
              ans_sum = []
              for h in range(b // d1[1]):
                  ans = [c1]
                  cc1 = copy.deepcopy(c1)
                  for i in range(d1[3] - 1):
                      y1 = cc1[::-1].index(1)
                      y2 = d1[3] - y1
                      cc1 = [0] * x
                      for j in range(d1[1]):
                          y3 = y2 + j
                          if y3 >= d1[3]:
                              y3 = abs(d1[3] - y3)
                          cc1[y3] = 1
                      ans.append(cc1)
                  ans_sum.append(ans)
          else:
              ans_sum = "No"
  
  if base[2] == 1 and base[1] == 0:
      c1 = [0] * base[3]
      for i in range(base[0]):
          c1[i] = 1
      print("".join(map(str, c1)))
  elif base[3] == 1 and base[0] == 0:
      c1 = [0] * base[2]
      for i in range(base[1]):
          c1[i] = 1
      for i in c1:
          print(i)
  elif ans_sum == "No":
      print(ans_sum)
  else:
      for j in ans_sum:
          for i in j:
              y1 = list(map(str, i))
              print("".join(y1))
  
problem_description: Statement
  
  We have a square grid with H rows and W columns. Snuke wants to write 0 or 1
  in each of the squares. Here, all of the following conditions have to be
  satisfied:
  
    * For every row, the smaller of the following is A: the number of 0s contained in the row, and the number of 1s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
    * For every column, the smaller of the following is B: the number of 0s contained in the column, and the number of 1s contained in the column.
  
  Determine if these conditions can be satisfied by writing 0 or 1 in each of
  the squares. If the answer is yes, show one way to fill the squares so that
  the conditions are satisfied.
samples: [{"input": "3 3 1 1", "output": "100\n    010\n    001\n    \n\nEvery row contains two 0s and one 1, so the first condition is satisfied.\nAlso, every column contains two 0s and one 1, so the second condition is\nsatisfied.\n\n* * *"}, {"input": "1 5 2 0", "output": "01010"}]