一、内容

An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s1,s2,…,sn is beautiful if |si−si+1|=1 for all 1≤i≤n−1Trans has a
numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a+b+c+dnumbers.However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?

Input

The only input line contains four non-negative integers a, b, c and d (0<a+b+c+d≤105).

Output

If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.

Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a+b+c+d
integers, separated by spaces — a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3

If there are multiple answers, you can print any of them.

Input

2 2 2 1

Output

YES
0 1 0 1 2 3 2

二、思路

  • 大致分为3种情况就可以讨论完全。
  • 第一种:以0开头以0结尾 01010,这时候要求 n0 == n1 + 1且2和3的个数都为0
  • 第二种:以3开头以3结尾,32323,要求 n3 == n2 + 1且0和1的个数都为0
  • 第三种:可以0或1开头,可以2或3结尾。首先中间放0 1 或 2 1或 2 3。根据个数来判断要求。
    n1 - n0 代表剩下1的个数, n2 - n3代表剩下2的个数。
    若剩下1的个数 比剩下2的个数多1个, 那么就要以1为开头这样可以减少一个1
    若剩下1的个数比剩下2的个数少1个,那么必须要在最后添加一个2,这样打印2 1的时候才能保证刚好把 2和1用完。
    不合法的情况: 当剩下1的个数 - 剩下2的个数 如果 > 1, 那么代表我无论如何让前面多一个1或让最后面多一个2都无法让1 和 2用尽。

三、代码

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;
const int N = 1e5 + 5;
int a[N], n0, n1, n2, n3, cnt; 
int main() {
 	scanf("%d%d%d%d", &n0, &n1, &n2, &n3);	
	if (n0 > n1 + 1) {
		printf("NO");
	} else if (n3 > n2 + 1) {
		printf("NO"); 
	} else if (n3 == n2 + 1) {
		if (n0 > 0 || n1 > 0) {
			printf("NO");
			return 0;
		}
		printf("YES\n");
		for (int i = 1; i <= n2; i++) {
			printf("3 2 ");			
		}
		printf("3");
	} else if (n0 == n1 + 1) {
		if (n3 > 0 || n2 > 0) {
			printf("NO");
			return 0;
		}		
		printf("YES\n");
		for (int i = 1; i <= n1; i++) {
			printf("0 1 ");			
		}		
		printf("0");
	} else if (abs(n1 - n0 + n3 - n2) <= 1) {
		printf("YES\n");
		if (n1 - n0 == n2 - n3 + 1) printf("1 "), n1--;
		for (int i = 1; i <= n0; i++) printf("0 1 ");
		for (int i = 1; i <= n1 - n0; i++) printf("2 1 ");
		for (int i = 1; i <= n3; i++) printf("2 3 ");
		if (n1 - n0 + 1 == n2 - n3) printf("2 ");
	} else {
		printf("NO");
	}
	return 0;
}