Problem:
Score : 900 points

Problem Statement

Takahashi has an N \times M grid, with N horizontal rows and M vertical columns.
Determine if we can place A 1 \times 2 tiles (1 vertical, 2 horizontal) and B 2 \times 1 tiles (2 vertical, 1 horizontal) satisfying the following conditions, and construct one arrangement of the tiles if it is possible:

All the tiles must be placed on the grid.

Tiles must not stick out of the grid, and no two different tiles may intersect.

Neither the grid nor the tiles may be rotated.

Every tile completely covers exactly two squares.

Constraints

1 \leq N,M \leq 1000

0 \leq A,B \leq 500000

N, M, A and B are integers.

Input

Input is given from Standard Input in the following format:

N M A B

Output

If it is impossible to place all the tiles, print NO.
Otherwise, print the following:

YES
c_{11}...c_{1M}
:
c_{N1}...c_{NM}

Here, c_{ij} must be one of the following characters: ., <, >, ^ and v. Represent an arrangement by using each of these characters as follows:

When c_{ij} is ., it indicates that the square at the i-th row and j-th column is empty;

When c_{ij} is <, it indicates that the square at the i-th row and j-th column is covered by the left half of a 1 \times 2 tile;

When c_{ij} is >, it indicates that the square at the i-th row and j-th column is covered by the right half of a 1 \times 2 tile;

When c_{ij} is ^, it indicates that the square at the i-th row and j-th column is covered by the top half of a 2 \times 1 tile;

When c_{ij} is v, it indicates that the square at the i-th row and j-th column is covered by the bottom half of a 2 \times 1 tile.

Sample Input 1

3 4 4 2

Sample Output 1

YES
<><>
^<>^
v<>v

This is one example of a way to place four 1 \times 2 tiles and three 2 \times 1 tiles on a 3 \times 4 grid.

Sample Input 2

4 5 5 3

Sample Output 2

YES
<>..^
^.<>v
v<>.^
<><>v

Sample Input 3

7 9 20 20

Sample Output 3

NO

Solution in C++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include <bits/stdc++.h>

using namespace std;

int n,m,a,b;

char board[1000][1000];

bool is_confined(int i, int j)
{
  return 0 <= i && i < n && 0 <= j && j < m;
}

bool fill_h(int i, int j)
{
  if (!is_confined(i,j) || j >= m-1 || board[i][j] != '.' || board[i][j+1] != '.')
    return false;

  board[i][j] = '<';
  board[i][j+1] = '>';

  return true;
}

bool clear_h(int i, int j)
{
  if (!is_confined(i,j) || j >= m-1)
    return false;

  board[i][j] = '.';
  board[i][j+1] = '.';

  return true;
}

bool fill_2h(int i, int j)
{
  if (!fill_h(i,j)) return false;

  if (!fill_h(i+1,j)) {
    clear_h(i,j);
    return false;
  }

  return true;
}

bool fill_v(int i, int j)
{
  if (!is_confined(i, j) || i >= n-1 || board[i][j] != '.' || board[i+1][j] != '.')
    return false;

  board[i][j] = '^';
  board[i+1][j] = 'v';

  return true;
}

bool clear_v(int i, int j)
{
  if (!is_confined(i, j) || i >= n-1)
    return false;

  board[i][j] = '.';
  board[i+1][j] = '.';

  return true;
}

bool fill_2v(int i, int j)
{
  if (!fill_v(i,j)) return false;

  if (!fill_v(i,j+1)) {
    clear_v(i,j);
    return false;
  }

  return true;
}

int main()
{
  cin >> n >> m >> a >> b;
  if (2*(a+b) <= n*m && a <= n * m/2 && b <= m * n/2) {
    cout << "YES" << endl;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        board[i][j] = '.';

    int ka = a, kb = b;

    if (n % 2 == 1 && m % 2 == 1) {
      if (n*m-1 == 2*(a+b) && b % 2 != m * n/2 % 2) {
        fill_v(n - 3, m - 3);
        fill_h(n - 3, m - 2);
        fill_v(n - 2, m - 1);
        fill_h(n - 1, m - 3);
        ka -= 2;
        kb -= 2;
      }
    }

    if (n % 2 == 1) {
      for (int i = 0; i < m; i+=2) {
        if (fill_h(n-1, i)) ka--;
      }
    }

    if (m % 2 == 1) {
      for (int i = 0; i < n; i+=2) {
        if (fill_v(i, m-1)) kb--;
      }
    }

    int i = 0, j = 0;
    while (ka > 0) {
      while (!fill_2h(i,j)) {
        // printf("ka=%d i=%d j=%d\n", ka, i, j);
        if (j >= m) { i++; j = 0; }
        else j++;
      }
      ka -= 2;
    }

    while (kb > 0) {
      while (!fill_2v(i,j)) {
        // printf("kb=%d i=%d j=%d\n", kb, i, j);
        if (j >= m) { i++; j = 0; }
        else j++;
      }
      kb -= 2;
    }

    // cleaning and printing
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (board[i][j] == '<') {
          if (a == 0) clear_h(i,j);
          else a--;
        } else if (board[i][j] == '^') {
          if (b == 0) clear_v(i,j);
          else b--;
        }
        cout << board[i][j];
      }
      cout << endl;
    }

  } else {
    cout << "NO" << endl;
  }
  return 0;
}