AtCoder Beginner Contest 170 - Crane and Turtle

There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.
Takahashi says: "there are X animals in total in the garden, and they have Y legs in total." Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.

-----Constraints-----
 - 1 \leq X \leq 100
 - 1 \leq Y \leq 100
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
X Y

-----Output-----
If there is a combination of numbers of cranes and turtles in which the statement is correct, print Yes; otherwise, print No.

-----Sample Input-----
3 8

-----Sample Output-----
Yes

The statement "there are 3 animals in total in the garden, and they have 8 legs in total" is correct if there are two cranes and one turtle. Thus, there is a combination of numbers of cranes and turtles in which the statement is correct.

Source: atcoder | Difficulty: EASY


Solutions:
(b, a) = map(int, input().split())
if a % 2 == 0 and a >= 2 * b and (a <= 4 * b):
	print('Yes')
else:
	print('No')


(x, y) = map(int, input().split())
if y % 2 == 0 and 0 <= y // 2 - x <= x:
	print('Yes')
else:
	print('No')


(x, y) = map(int, input().split())
if y > 4 * x or y < 2 * x or y % 2 != 0:
	print('No')
else:
	print('Yes')


(X, Y) = map(int, input().split())
print('NYoe s'[2 <= Y / X <= 4 & ~Y * 4::2])


(X, Y) = map(int, input().split())
flg = 0
for i in range(X + 1):
	if i * 2 + (X - i) * 4 == Y:
		flg = 1
if flg == 1:
	print('Yes')
else:
	print('No')


(X, Y) = map(int, input().split())
print('Yes' if Y % 2 == 0 and 2 * X <= Y <= 4 * X else 'No')


(x, y) = map(int, input().split())
print('YNeos'[y % 2 == 1 or x * 4 < y or x * 2 > y::2])


(x, y) = list(map(int, input().split()))
if y % 2 != 0:
	print('No')
	return
if x * 2 <= y <= x * 4:
	print('Yes')
else:
	print('No')


(x, y) = map(int, input().split())
print('Yes' if y <= 4 * x and y >= 2 * x and (y & 1 != 1) else 'No')


(x, y) = list(map(int, input().split()))
for i in range(x + 1):
	if 2 * i + 4 * (x - i) == y:
		print('Yes')
		return
print('No')


(x, y) = map(int, input().split())
cnt = 0
for b in range(x + 1):
	for t in range(x + 1):
		if x == b + t and y == 2 * b + 4 * t:
			print('Yes')
			return
		else:
			continue
print('No')


(x, y) = map(int, input().split())
bool = False
for i in range(x + 1):
	if 2 * i + 4 * (x - i) == y:
		print('Yes')
		break
else:
	print('No')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, bisect
import sys
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
stdin = sys.stdin
ni = lambda : int(ns())
nf = lambda : float(ns())
na = lambda : list(map(int, stdin.readline().split()))
nb = lambda : list(map(float, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
(X, Y) = na()
ans = 'No'
for turu in range(X + 1):
	kame = X - turu
	if turu * 2 + kame * 4 == Y:
		ans = 'Yes'
		break
print(ans)


X = list(map(int, input().split()))
legs = 0
flag = 0
for crane in range(X[0] + 1):
	turtle = X[0] - crane
	legs = crane * 2 + turtle * 4
	if X[1] == legs:
		flag = 1
		break
if flag == 1:
	print('Yes')
else:
	print('No')


(x, y) = map(int, input().split())
ans = 'No'
for i in range(x + 1):
	tmp = 2 * i + 4 * (x - i)
	if tmp == y:
		ans = 'Yes'
print(ans)


(X, Y) = map(int, input().split())
ans = 'No'
for i in range(0, X + 1):
	if i * 2 + (X - i) * 4 == Y:
		ans = 'Yes'
		break
print(ans)


(x, y) = list(map(int, input().split()))
haveAns = False
for i in range(1, x + 1):
	if i * 2 + (x - i) * 4 == y or i * 4 + (x - i) * 2 == y:
		print('Yes')
		haveAns = True
		break
if not haveAns:
	print('No')


(N, M) = map(int, input().split())
if M % 2 != 0 or M > 4 * N or M < 2 * N:
	print('No')
else:
	print('Yes')


(x, y) = map(int, input().split())
print('Yes' if sum((2 * c + 4 * (x - c) == y for c in range(x + 1))) else 'No')


(X, Y) = [int(i) for i in input().split()]
print('Yes' if 2 * X <= Y <= 4 * X and Y % 2 == 0 else 'No')


(x, y) = map(int, input().split())
print('YNeos'[y % 2 or x * 2 < y // 2 or y // 2 < x::2])


(a, b) = input().split(' ')
ans = 0
for i in range(int(a) + 1):
	turu = int(i)
	turt = int(a) - int(i)
	if turu * 2 + turt * 4 == int(b):
		ans = 1
		break
if ans == 1:
	print('Yes')
else:
	print('No')


import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
(x, y) = [int(i) for i in input().split()]
tmp = 0
res = 'No'
for i in range(x + 1):
	j = x - i
	if 2 * i + 4 * j == y:
		res = 'Yes'
print(res)


(x, y) = map(int, input().split())
if y in range(x * 2, x * 4 + 1, 2):
	print('Yes')
else:
	print('No')


(x, y) = map(int, input().split())
output = 'No'
if x * 2 <= y <= x * 4:
	if y % 2 == 0:
		output = 'Yes'
print(output)


(X, Y) = map(int, input().split())
for i in range(1, X + 1):
	a = i * 2
	b = Y - a
	c = b // 2
	d = b // 4
	if c + i == X or d + i == X:
		if b % 2 == 0 or b % 4 == 0:
			print('Yes')
			return
print('No')


(a, l) = map(int, input().split())
if not 2 * a <= l <= 4 * a or l % 2 == 1:
	print('No')
else:
	print('Yes')


(x, y) = map(int, input().split())
if y % 2 == 1 or 2 * x < y / 2 or y / 2 < x:
	print('No')
else:
	print('Yes')


numline = input().split(' ')
a = int(numline[0])
b = int(numline[1])
if 2 * a <= b and b <= 4 * a and (b % 2 == 0):
	print('Yes')
else:
	print('No')


def main():
	(X, Y) = map(int, input().split())
	for x in range(101):
		for y in range(101):
			if x + y == X and 2 * x + 4 * y == Y:
				return True
	return False

def __starting_point():
	print('Yes' if main() else 'No')
__starting_point()


(x, y) = input().split()
x = int(x)
y = int(y)
if y % 2 == 1 or x * 2 > y or x * 4 < y:
	a = 'No'
else:
	a = 'Yes'
print(a)


(x, y) = list(map(int, input().split()))
cnt = 0
for a in range(x + 1):
	b = x - a
	if b >= 0 and 2 * a + 4 * b == y:
		ans = 'Yes'
		break
else:
	ans = 'No'
print(ans)


(X, Y) = map(int, input().split())
print('YNeos'[X * 2 > Y or Y > X * 4 or Y % 2::2])


(x, y) = map(int, input().split())
print(('No', 'Yes')[2 * x <= ~y % 2 * y <= 4 * x])


(x, y) = list(map(int, input().split()))
flag = True
for animal in range(1, x + 1):
	if y == animal * 4 + (x - animal) * 2 or y == animal * 2 + (x - animal) * 4:
		print('Yes')
		flag = False
		break
if flag:
	print('No')


(X, Y) = map(int, input().split())
if Y % 2 == 1 or 4 * X < Y or 2 * X > Y:
	print('No')
else:
	print('Yes')


(n, k) = map(int, input().split())
if 2 * n <= k <= 4 * n and k % 2 == 0:
	print('Yes')
else:
	print('No')


(X, Y) = list(map(int, input().split()))
K = 0
if Y % 2 == 0:
	K = Y // 2 - X
	if K >= 0:
		if X - K >= 0:
			print('Yes')
			return
print('No')


(x, y) = map(int, input().split())
counter = 0
for i in range(0, x + 1):
	j = x - i
	if 2 * i + 4 * j == y:
		counter += 1
		break
if counter >= 1:
	print('Yes')
else:
	print('No')


(X, Y) = list(map(int, input().split()))
for i in range(100):
	for j in range(100):
		if i + j == X and 2 * i + 4 * j == Y:
			print('Yes')
			break
	else:
		continue
	break
else:
	print('No')


(x, y) = [int(_) for _ in input().split()]
ans = 'No'
if y % 2 == 0 and x * 2 <= y <= x * 4:
	ans = 'Yes'
print(ans)


def answer(x: int, y: int) -> str:
	if x * 2 <= y <= x * 4 and y % 2 == 0:
		return 'Yes'
	return 'No'

def main():
	(x, y) = map(int, input().split())
	print(answer(x, y))

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
if m % 2 == 1 or m // 2 < n or m // 2 - n > n:
	print('No')
	exit()
print('Yes')


(x, y) = map(int, input().split())
if 2 * x > y or 4 * x < y or y % 2:
	print('No')
	exit()
print('Yes')


(x, y) = map(int, input().split())
print('Yes' if any((x * 2 + i * 2 == y for i in range(x + 1))) else 'No')


(X, Y) = list(map(int, input().split()))
for x in range(X + 1):
	if x * 2 + (X - x) * 4 == Y:
		print('Yes')
		break
else:
	print('No')


(X, Y) = map(int, input().split())
flag = False
for i in range(100):
	for j in range(100):
		if i + j == X and 2 * i + 4 * j == Y:
			flag = True
if flag:
	print('Yes')
else:
	print('No')


(x, y) = map(int, input().split())
if any([y / 2 - x < 0, 2 * x - y / 2 < 0, y % 2 == 1]):
	print('No')
else:
	print('Yes')


(x, y) = [int(x) for x in input().split()]
if y % 2 == 0 and y >= 2 * x and (y <= 4 * x):
	print('Yes')
else:
	print('No')


(x, y) = map(int, input().split())
print('NYoe s'[(2 * x <= y <= 4 * x) > y % 2::2])


(X, Y) = map(int, input().split())
for i in range(X + 1):
	if 2 * i + 4 * (X - i) == Y:
		print('Yes')
		return
print('No')


(X, Y) = map(int, input().split())
num = 0
for a in range(X + 1):
	if 2 * a + 4 * (X - a) == Y:
		num = num + 1
if num >= 1:
	print('Yes')
else:
	print('No')


(X, Y) = (int(x) for x in input().split())
a = 4 * X - Y
b = Y - 2 * X
if a >= 0 and b >= 0 and (a % 2 == 0) and (b % 2 == 0):
	print('Yes')
else:
	print('No')


(x, y) = list(map(int, input().split()))
ans = 'No'
for i in range(x + 1):
	j = x - i
	if 2 * i + 4 * j == y:
		ans = 'Yes'
		break
print(ans)


(x, y) = map(int, input().split())
if y % 2 == 0:
	print('NYoe s'[2 * x <= y <= 4 * x::2])
else:
	print('No')


(x, y) = map(int, input().split())
f = 0
for i in range(x + 1):
	j = x - i
	f |= i * 2 + j * 4 == y
print('NYoe s'[f::2])


(X, Y) = (int(x) for x in input().split())
Flag = False
for A in range(0, X + 1):
	B = X - A
	if 2 * A + 4 * B == Y:
		Flag = True
		break
print(['No', 'Yes'][Flag])


def i_input():
	return int(input())

def i_map():
	return map(int, input().split())

def i_list():
	return list(map(int, input().split()))

def i_row(N):
	return [int(input()) for _ in range(N)]

def i_row_list(N):
	return [list(map(int, input().split())) for _ in range(N)]
(x, y) = i_map()
ans = 'No'
for i in range(x + 1):
	if 2 * i + 4 * (x - i) == y:
		ans = 'Yes'
		break
print(ans)


animals_and_legs = input()
list = animals_and_legs.split()
animals = int(list[0])
legs = int(list[1])
j = animals
i = 0
something = True
while i <= animals:
	if i * 4 + j * 2 == legs:
		print('Yes')
		something = False
		break
	i = i + 1
	j = j - 1
if something is True:
	print('No')


(x, y) = map(int, input().split())
(a, b) = (x * 2 - y // 2, y // 2 - x)
print('YNeos'[y % 2 or a < 0 or b < 0::2])


(x, y) = map(int, input().split())
i = 0
while i <= x:
	if y == 2 * i + 4 * (x - i):
		print('Yes')
		return
	i += 1
print('No')


(x, y) = map(int, input().split())
if y % 2 == 0 and 4 * x >= y and (2 * x <= y):
	print('Yes')
	exit()
print('No')


def main():
	(x, y) = map(int, input().split())
	b = (y - x * 2) // 2
	a = x - b
	if a >= 0 and b >= 0 and (2 * a + 4 * b == y):
		print('Yes')
	else:
		print('No')

def __starting_point():
	main()
__starting_point()


(a, b) = list(map(int, input().split()))
leg = 0
for i in range(0, a + 1):
	if 2 * i + 4 * (a - i) == b:
		print('Yes')
		return
print('No')


(x, y) = list(map(int, input().split()))
ans = 'No'
for a in range(x + 1):
	b = x - a
	if 2 * a + 4 * b == y:
		ans = 'Yes'
print(ans)


(x, y) = map(int, input().split())
l = []
flag = False
for i in range(x + 1):
	l.append((i, x - i))
for (xx, yy) in l:
	if y == xx * 2 + yy * 4:
		flag = True
		break
if flag:
	print('Yes')
else:
	print('No')


(x, y) = map(int, input().split())
n = 'No'
for i in range(51):
	for j in range(26):
		if 2 * i + 4 * j == y:
			if i + j == x and i + j != 0:
				n = 'Yes'
print(n)


(x, y) = list(map(int, input().split()))
ans = 'No'
if y % 2 == 0 and y >= x * 2 and (y <= x * 4):
	ans = 'Yes'
print(ans)


(x, y) = list(map(int, input().split()))
flag = 0
for i in range(x + 1):
	if i * 2 + (x - i) * 4 == y:
		print('Yes')
		flag = 1
		break
if flag == 0:
	print('No')


(n, leg) = map(int, input().split())
print(['No', 'Yes'][not leg % 2 and 2 * n <= leg <= 4 * n])


(x, y) = map(int, input().split())
msg = 'No'
for a in range(1, x + 1):
	if 2 * a + 4 * (x - a) == y or 4 * a + 2 * (x - a) == y:
		msg = 'Yes'
print(msg)


(x, y) = map(int, input().split())
a = any((i * 2 + (x - i) * 4 == y for i in range(x + 1)))
print(['No', 'Yes'][a])


(X, Y) = map(int, input().split())
result = 'No'
for a in range(X + 1):
	b = X - a
	if 2 * a + 4 * b == Y:
		result = 'Yes'
print(result)


y = [int(i) for i in input().split()]
N = y[0]
Q = y[1]
if Q & 1:
	print('No')
elif Q >= N * 2 and Q <= N * 4:
	print('Yes')
else:
	print('No')


(s, t) = map(int, input().split())
print('Yes' if s * 2 <= t <= s * 4 and t % 2 == 0 else 'No')


(X, Y) = map(int, input().split())
ans = False
for i in range(X + 1):
	if 2 * i + 4 * (X - i) == Y:
		ans = True
if ans:
	print('Yes')
else:
	print('No')


(x, y) = map(int, input().split())
print(['No', 'Yes'][y in [2 * x + 2 * t for t in range(x + 1)]])


(x, y) = map(int, input().split())
print('NYoe s'[y % 2 == 0 and 2 * x <= y <= 4 * x::2])


import sys
(vol, foot) = map(int, input().split())
for i in range(vol + 1):
	if 2 * i + 4 * (vol - i) == foot:
		print('Yes')
		return
print('No')


(X, Y) = map(int, input().split())
print('YNeos'[not any((i * 2 + (X - i) * 4 == Y for i in range(X + 1)))::2])


(X, Y) = list(map(int, input().split()))
flag = True
for kame in range(X + 1):
	tsuru = X - kame
	if 4 * kame + 2 * tsuru == Y:
		print('Yes')
		flag = False
		break
if flag:
	print('No')


(x, y) = map(int, input().split())
ans = 'Yes'
if y & 1 or 2 * x > y or y > 4 * x:
	ans = 'No'
print(ans)


(X, Y) = list(map(int, input().split()))
ans = 'No'
for a in range(X + 1):
	b = X - a
	if Y == 2 * a + 4 * b:
		ans = 'Yes'
		break
print(ans)


(X, Y) = map(int, input().split())
if Y % 2 == 1:
	print('No')
else:
	for num_turu in range(X + 1):
		num_kame = X - num_turu
		if Y == 4 * num_kame + 2 * num_turu:
			print('Yes')
			break
	else:
		print('No')


(n, m) = map(int, input().split())
if n * 2 <= m and m <= n * 4 and (m % 2 == 0):
	print('Yes')
	exit()
print('No')


(x, y) = list(map(int, input().split()))
if y % 2 == 1:
	print('No')
	return
q2 = y // 2
q4 = y // 4
n = 0
for i in range(q4 + 1):
	n = q2 - i
	if n == x:
		print('Yes')
		return
print('No')


(X, Y) = list(map(int, input().split()))
T = 0
K = 0
for i in range(X + 1):
	j = X - i
	if 2 * i + 4 * j == Y:
		print('Yes')
		return
print('No')


(x, y) = map(int, input().split())
print('YNeos'[1 - (x * 2 <= y <= x * 4 and y % 2 == 0)::2])


(x, y) = map(int, input().split())
b = y / 2 - x
a = x - b
if y % 2 != 0:
	print('No')
elif b < 0:
	print('No')
elif a >= 0:
	print('Yes')
else:
	print('No')


(X, Y) = map(int, input().split())
result = 'No'
for i in range(0, 100):
	for j in range(0, 100):
		if i + j == X and i * 2 + j * 4 == Y:
			result = 'Yes'
print(result)


(x, y) = map(int, input().split())
flg = False
for i in range(x + 1):
	j = x - i
	if i * 2 + j * 4 == y:
		flg = True
		break
print('Yes' if flg else 'No')