Chang's new maths teacher is very enthusiastic about making sure that students understand the concept rather than remembering it. On her first day at teaching, she gives an assignment to all the students to test their potential. Chang wants to demonstrate that he understands the concept rather than rote learning. Help Chang in doing this by solving the hardest problem in the assignment. The problem is written as follows. 

A perfect function is defined in the following manner.

- F(x, y) = x2 + y for 1 ≤ x ≤ A, 1 ≤ y ≤ B
- F(x, y) = 2 otherwise

Find the number of integral pairs (x, y) such that F(x, y) is a perfect square.

-----Input-----
First and the only line of the input contains two single space separated integers A and B.

-----Output-----
Output a single integer indicating the output to the only test case.

-----Constraints-----
- 1 ≤ A, B ≤ 106

-----Example-----
Input:
4 4

Output:
1

-----Explanation-----
Example case 1.
(1, 3) is the only pair such that x = 1, y = 3 satisfying x <= 4 and y <= 4. 1^2 + 3 = 4 which is a perfect square.

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
from math import sqrt
(a, b) = map(int, input().split())
pairs = 0
for i in range(1, a + 1):
	for j in range(1, b + 1):
		root = sqrt(i ** 2 + j)
		if not root - int(root):
			pairs += 1
print(pairs)


import math

def isPerfectSquare(x):
	sr = math.sqrt(x)
	return sr - math.floor(sr) == 0
(a, b) = list(map(int, input().split()))
c = 0
for i in range(1, a + 1):
	for j in range(1, b + 1):
		s = i * i + j
		if isPerfectSquare(s):
			c += 1
print(c)


import math
(a, b) = list(map(int, input().split()))
l = []
for x in range(1, a + 1):
	for y in range(1, b + 1):
		f = x ** 2 + y
		r = math.sqrt(f)
		if int(r + 0.5) ** 2 == f:
			l.append(1)
		else:
			l.append(0)
print(sum(l))


(A, B) = [int(i) for i in input().split()]
counter = 0
for x in range(1, A + 1):
	num = x ** 2 + B
	counter += int(num ** 0.5) - x
print(counter)


(x, y) = list(map(int, input().split()))
pair = 0
for i in range(1, x + 1):
	pair += int((i ** 2 + y) ** 0.5) - i
print(pair)


import math
(a, b) = map(int, input().split())
ct = 0
for i in range(1, a + 1):
	for j in range(1, b + 1):
		x = math.sqrt(i * i + j)
		if x - int(x) == 0:
			ct = ct + 1
print(ct)


import math
(a, b) = list(map(int, input().split()))
c = 0
for i in range(1, a + 1):
	for j in range(1, b + 1):
		n = i ** 2 + j
		sr = math.sqrt(n)
		if sr - math.floor(sr) == 0:
			c += 1
print(c)


(a, b) = map(int, input().split())
f = 0
for i in range(1, a + 1):
	for j in range(1, b + 1):
		c = i * i + j
		d = c ** 0.5
		e = int(d)
		if d == e:
			f += 1
print(f)


(a, b) = map(int, input().split())
c = 0
for i in range(1, a + 1):
	for j in range(1, b + 1):
		a1 = i * i + j
		a2 = a1 ** 0.5
		a3 = int(a2)
		if a3 == a2:
			c += 1
print(c)


(a, b) = map(int, input().strip().split(' '))
count = 0
import math
r = int(math.sqrt(b))
for i in range(1, a + 1):
	for j in range(1, b + 1):
		r = i * i + j
		x = math.sqrt(r)
		if int(x) == x:
			count += 1
print(count)


(a, b) = str(input()).split(' ')
a = int(a)
b = int(b)
count = 0
for i in range(1, a + 1):
	for j in range(1, b + 1):
		a1 = i * i + j
		a2 = a1 ** 0.5
		a3 = int(a2)
		if a3 == a2:
			count += 1
print(count)


import math
(a, b) = map(int, input().split())
c = 0
for i in range(2, int(math.sqrt(a * a + b)) + 1):
	for x in range(1, i):
		if x > a:
			break
		c += int(i * i - x * x <= b)
print(c)


import math
(a, b) = map(int, input().split())
c = 0
for x in range(1, a + 1):
	for y in range(1, b + 1):
		if math.modf(math.sqrt(float(x * x) + float(y)))[0] == 0.0:
			c += 1
print(c)


import math
p = [int(i) for i in input().split()]
count = 0
for i in range(1, p[0] + 1):
	k = i + 1
	while True:
		y = k * k - i * i
		if y >= 1 and y <= p[1]:
			count += 1
		else:
			break
		k = k + 1
print(count)


import math
p = [int(i) for i in input().split()]
count = 0
for i in range(1, p[0] + 1):
	for j in range(1, p[1] + 1):
		k = i * i + j
		k1 = int(math.sqrt(k))
		if k1 * k1 == k:
			count += 1
print(count)


(a, b) = map(int, input().split())
ans = 0
for x in range(1, a + 1):
	m = 1
	y = 0
	while y < b:
		y = m * (2 * x + m)
		if y > b:
			break
		ans += 1
		m += 1
print(ans)


import math
(a, b) = map(int, input().split())
x = 1
y = 1
res = 0
for i in range(1, a + 1):
	for j in range(1, b + 1):
		temp = i * i + j
		sr = math.sqrt(temp)
		if sr - math.floor(sr) == 0:
			res += 1
print(res)


import math
(a, b) = list(map(int, input().split()))
l = []
m = []
cnt = 0
for i in range(1, a + 1):
	for j in range(1, b + 1):
		y = i ** 2 + j
		m = math.sqrt(y)
		if m == math.floor(m):
			cnt += 1
print(cnt)