Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin x times, then Petya tosses a coin y times. If the tossing player gets head, he scores one point. If he gets tail, nobody gets any points. The winner is the player with most points by the end of the game. If boys have the same number of points, the game finishes with a draw.

At some point, Valera lost his count, and so he can not say exactly what the score is at the end of the game. But there are things he remembers for sure. He remembers that the entire game Vasya got heads at least a times, and Petya got heads at least b times. Moreover, he knows that the winner of the game was Vasya. Valera wants to use this information to know every possible outcome of the game, which do not contradict his memories.


-----Input-----

The single line contains four integers x, y, a, b (1 ≤ a ≤ x ≤ 100, 1 ≤ b ≤ y ≤ 100). The numbers on the line are separated by a space.


-----Output-----

In the first line print integer n — the number of possible outcomes of the game. Then on n lines print the outcomes. On the i-th line print a space-separated pair of integers c_{i}, d_{i} — the number of heads Vasya and Petya got in the i-th outcome of the game, correspondingly. Print pairs of integers (c_{i}, d_{i}) in the strictly increasing order.

Let us remind you that the pair of numbers (p_1, q_1) is less than the pair of numbers (p_2, q_2), if p_1 < p_2, or p_1 = p_2 and also q_1 < q_2.


-----Examples-----
Input
3 2 1 1

Output
3
2 1
3 1
3 2

Input
2 4 2 2

Output
0

Difficulty: interview

Starter code:

Solutions:
import sys
f = sys.stdin
#f = open("input.txt", "r")
x, y, a, b = map(int, f.readline().strip().split())
a1, a2 = [], []
if a+(x-a) <= b:
    print(0)
else:
    for i in range(a, x+1):
        for k in range(b, y+1):
            if i > k:
                a1.append(i)
                a2.append(k)
    print(len(a1))
    for i in range(len(a1)):
        print(a1[i], a2[i])

#149 Heads or Tails

data = input().split(" ")
x = int(data[0])
y = int(data[1])
a = int(data[2])
b = int(data[3])
counter = 0
for i in range(a, x+1):
	for j in range(b, y+1):
		if j < i:
			counter += 1
if counter == 0:
	print(0)
else:
	print(counter)
	for i in range(a, x+1):
		for j in range(b, y+1):
			if j < i:
				print("%s %s" %(i, j))
				noAnswer = False

def g(n):
    k = (n - a + 1)
    return ((n + a) * k) // 2 - b * k
    
x, y, a, b = list(map(int, input().split()))
a = max(a, b + 1)

if x <= b: print(0)
else:
    if y > x - 2: print(g(x))
    elif y >= a - 1: print((x - y - 1) * (y - b + 1) + g(y + 1))
    else: print((x - a + 1) * (y - b + 1))
    
for i in range(a, x + 1):
    for j in range(b, min(i, y + 1)):
        print(i, j)


x,y,a,b=list(map(int,input().split()))
Results=[]
for i in range(a,x+1):
    for j in range(b,y+1):
        if(j>=i):
            continue
        Results.append((i,j))
print(len(Results))

Results.sort()

for item in Results:
    print(item[0],item[1])



def all_outcome(x, y, a, b):
    s = x + y
    outcomes = []

    # first player's outcomes
    for c in range(a, x+1):
        for d in range(b, y+1):
            if d >= b and d <= y and c > d:
                outcomes.append([c, d])
        
    # if
    print(len(outcomes))
    for o in outcomes:
        print(o[0], o[1])

l = input().split()
x = int(l[0])
y = int(l[1])
a = int(l[2])
b = int(l[3])

all_outcome(x,y, a, b)


x, y, a, b = map(int, input().split())
ans = []

for i in range(a, x + 1):
	for j in range(b, y + 1):
		if i > j:
			ans.append((i, j))

print(len(ans))
[print(x[0], x[1]) for x in ans]

x, y, a, b = (int(x) for x in input().split())
val = []
for i in range(max(a, b + 1), x + 1):
    for j in range(b, min(i - 1, y) + 1):
        val.append((i, j))
print(len(val))
for o in val:
    print(o[0], o[1])

x, y, a, b = [int(x) for x in input().split()]
l = []
for i in range(a, x + 1):
	for j in range(b, y + 1):
		if j < i:
			l.append(str(i) + ' ' + str(j))
print(len(l))
print('\n'.join(l))


def main():
    x, y, a, b = map(int, input().split())
    res = [None]
    for i in range(a, x + 1):
        si = str(i)
        for j in range(b, min(y + 1, i)):
            res.append(' '.join((si, str(j))))
    res[0] = str(len(res) - 1)
    print('\n'.join(res))


def __starting_point():
    main()
__starting_point()

a, b, c, d = list(map(int, input().split(' ')))

ct = 0
ct2 = 0
badtoed= [] 

for i in range(1, a+1):
    for j in range(1, b+1):
        if i > j and i >= c and j >= d:
            badtoed.append(str(i) + ' ' + str(j))
            ct += 1

print(ct)
for i in badtoed:
    print(i)


f=input().split()

a=int(f[0])
b=int(f[1])

am=int(f[2])
bm=int(f[3])

l=[]


for i in range(bm+1,a+1):
    if i>bm and i>=am:
        for j in range(bm,i):
            if j<=b:
                p=[]
                p.append(i)
                p.append(j)
                l.append(p)
if(len(l)==0):
    print(0)
else:
    print(len(l))
    for i in range(len(l)):
        print(l[i][0],l[i][1])

import sys
import math
 
x, y, a, b = [int(x) for x in (sys.stdin.readline()).split()]

res = []
for j in range(x, a - 1, -1):
    for i in range(min(j - 1, y), b - 1, -1):
        res.append((j, i))

print(len(res))
for i in res[::-1]:
    print(i[0], i[1])

x, y, a, b = [int(x) for x in input().split(' ')]

r = []
for i in range(a,x+1):
   for j in range(b,y+1):
      if i > j:
         r.append([i,j])

l = len(r)
r.sort(key=lambda z:10*l*z[0]+z[1])
print(len(r))
list(map(lambda z:print('%s %s'%(z[0],z[1])),r))

x, y, a, b = map(int, input().split())
ans = []
for i in range(a, x + 1):
    for j in range(b, y + 1):
        if i > j:
            ans.append((i, j))

print(len(ans))
[print(x[0], x[1]) for x in ans]


# coding=utf-8

x, y, a, b = list(map(int, input().split(' ')))
ans = 0
result = ''
for i in range(a, x + 1):
    for j in range(b, y + 1):
        if i > j:
            ans += 1
            result += '%s %s\n' % (i, j)
print(ans)
if ans:
    print(result)


x, y, a, b = list(map(int, input().split()))

result = []
for i in range(a, x + 1):
    for j in range(b, min(i, y + 1)):
        result.append((i, j))
print(len(result))
for x, y in result:
    print(x, y)


x,y,a,b=input().split(' ')
x=int(x)
y=int(y)
a=int(a)
b=int(b)
n=0
for i in range(a,x+1):
    for j in range(b,min(i,y+1)):
        n+=1
print(n)
for i in range(a,x+1):
    for j in range(b,min(i,y+1)):
        print(i,' ',j)


x,y,a,b = list(map(int,input().split(' ')))

c = []

for p in range(a,x+1):
    for q in range(b,y+1):
        if(q<p):
            c.append((p,q))

print(len(c))
if c != []:
    for p in c :
        print(p[0],p[1])



l = input().split()
l = [int(x) for x in l]
x = l[0]
y = l[1]
a = l[2]
b = l[3]


r = []
for i in range(a, x+1):
    for j in range(b, y+1):
        if i>j:
            r.append((i, j))
        else:
            break

print(len(r))
for x in r:
    print(x[0], x[1])



x, y, a, b = map(int, input().split())
ans = []
for vasya in range(max(b + 1, a), x + 1):
  for petya in range(b, min(vasya, y + 1)):
    ans.append((petya, vasya))
print(len(ans))
print("\n".join(["%d %d" % (b, a) for a, b in ans]))

# your code goes here
arr = input().split()
p = int(arr[0])
q = int(arr[1])
a = int(arr[2])
b = int(arr[3])
flag = 0
if a <= b:
	a = b+1
x = b
y = a
while(a <= p):
	b = x
	while(b < a and b <= q):
		flag += 1
		#print(str(a) + ' ' + str(b))
		b += 1
	a += 1
print(str(flag))
a = y
b = x
while(a <= p):
	b = x
	while(b < a and b <= q):
		flag += 1
		print(str(a) + ' ' + str(b))
		b += 1
	a += 1




entrada = list([int(x) for x in input().split()])
qtdjogadasVencedor = entrada[0]#3
qtdjogadasPerdedor = entrada[1]#2
qtdminpontVencedor = entrada[2]#1
qtdminpontPerdedor = entrada[3]#1
listaPrincipal, laux = [], []
for i in range(qtdminpontVencedor,qtdjogadasVencedor+1):
    for j in range(qtdminpontPerdedor,qtdjogadasPerdedor+1):
        if j < i:
            laux.append((i,j))
print(len(laux))
for i in laux:
    print(i[0],i[1])
        
        


def main():
    (x, y, a, b) = list(map(int, input().split(' ')))
    l = []
    for c in range(a, x + 1):
        for d in range(b, y + 1):
            if c > d:
                l.append((c, d))
    print(len(l))
    for ll in l:
        print("{} {}".format(*ll))
main()



x, y, a, b = list(map(int, input().split()))
results = []
for i in range(a, x + 1):
	for j in range(b, y + 1):
		if i <= j:
			continue
		results.append((i, j))
print(len(results))
results.sort()
for a, b in results:
	print(a, b)


x,y,a,b=[ int(i) for i in input().split() ]

ans=[]
s_a=a
s_b=b
if a<=b:
  s_a=b+1
  s_b=b  

while s_a<=x:
  for i in range(s_b,min(s_a,y+1)):
    ans.append([s_a,i])
  s_a+=1
print(len(ans))
for i in ans:
  print(i[0],i[1])