input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
H,W=list(map(int,input().split())) h,w=list(map(int,input().split())) print((H*W-H*w-h*W+h*w))
H,W=list(map(int,input().split())) h,w=list(map(int,input().split())) print((H*W-h*W-H*w+h*w))
p03101
H, W = list(map(int, input().split())) h, w = list(map(int, input().split())) HM = H * W hW = W * h h1 = H - h h2 = h1 * w h3 = HM - hW - h2 print(h3)
H, W = list(map(int, input().split())) h, w = list(map(int, input().split())) s = H * W s1 = h * W s2 = H * w s3 = s1 + s2 - h * w print((s - s3))
p03101
H, W = list(map(int, input().split())) h, w = list(map(int, input().split())) print((H * W - h * W - H * w + h * w))
H, W = list(map(int, input().split())) h, w = list(map(int, input().split())) print(((H - h) * (W - w)))
p03101
H,W = list(map(int,input().split())) h,w = list(map(int,input().split())) print(((H-h)*(W-w)))
# Python3 (3.4.3) import sys input = sys.stdin.readline # ------------------------------------------------------------- # function # ------------------------------------------------------------- # ------------------------------------------------------------- # main # ------------------------------------------------------------- H,W = list(map(int,input().split())) h,w = list(map(int,input().split())) print(((H-h)*(W-w)))
p03101
H, W = (int(i) for i in input().split()) h, w = (int(i) for i in input().split()) ans = H * W sel = h * W + w * (H - h) ans -= sel print(ans)
def main(): H, W = (int(i) for i in input().split()) h, w = (int(i) for i in input().split()) ans = H*W - W*h - H*w + h*w print(ans) if __name__ == '__main__': main()
p03101
# AtCoder Beginner Contest 121 # https://atcoder.jp/contests/abc121 import sys s2nn = lambda s: list(map(int, s.split(' '))) ss2nn = lambda ss: list(map(int, ss)) ss2nnn = lambda ss: [s2nn(s) for s in ss] i2s = lambda: sys.stdin.readline().rstrip() i2n = lambda: int(i2s()) i2nn = lambda: s2nn(i2s()) ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)] ii2nn = lambda n: ss2nn(ii2ss(n)) ii2nnn = lambda n: ss2nnn(ii2ss(n)) def main(): H, W = i2nn() h, w = i2nn() n = (H - h) * (W - w) print(n) main()
# AtCoder Beginner Contest 121 # https://atcoder.jp/contests/abc121 import sys #import numpy as np s2nn = lambda s: list(map(int, s.split(' '))) ss2nn = lambda ss: list(map(int, ss)) ss2nnn = lambda ss: [s2nn(s) for s in ss] i2s = lambda: sys.stdin.readline().rstrip() i2n = lambda: int(i2s()) i2nn = lambda: s2nn(i2s()) ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)] ii2nn = lambda n: ss2nn(ii2ss(n)) ii2nnn = lambda n: ss2nnn(ii2ss(n)) def main(): H, W = i2nn() h, w = i2nn() n = (H - h) * (W - w) print(n) main()
p03101
a,b=[list(map(int,input().split())) for i in range(2)] print(((a[0]-b[0])*(a[1]-b[1])))
H,W=list(map(int,input().split())) h,w=list(map(int,input().split())) print(((H-h)*(W-w)))
p03101
H,W = list(map(int,input().split())) h,w = list(map(int,input().split())) ans = (H-h)*(W-w) print(ans)
H, W = list(map(int,input().split())) h, w = list(map(int,input().split())) ans = H*W -(h*W+w*H) + h*w print(ans)
p03101
[print(f.reduce(o.mul,f.reduce(lambda x,y:[x[0]-y[0],x[1]-y[1]],[[int(i)for i in input().split()],[int(i)for i in input().split()]])))for f,o in[[__import__('functools'),__import__('operator')]]]
[print((H-h)*(W-w))for H,W,h,w in[map(int,open(0).read().split())]]
p03101
H,W = list(map(int,input().split())) h,w = list(map(int,input().split())) print(((H-h) * (W-w)))
def main(): H, W = list(map(int, input().split())) h, w = list(map(int, input().split())) print(((H-h)*(W-w))) main()
p03101
H, W = list(map(int, input().split())) h, w = list(map(int, input().split())) ans = 0 masu = [[0] * W for i in range(H)] for i in range(h): for j in range(W): masu[i][j] = 1 for i in range(H): for j in range(w): masu[i][j] = 1 for i in range(H): for j in range(W): if masu[i][j] == 0: ans += 1 print(ans)
H, W = list(map(int, input().split())) h, w = list(map(int, input().split())) print(((H - h) * (W - w)))
p03101
uh, uw = list(map(int, input().split())) h, w = list(map(int, input().split())) print((int((uh*uw) - (uh*w) - (uw*h) + (h*w))))
uh,uw = list(map(int, input().split())) h, w = list(map(int, input().split())) print(((uh-h)*(uw-w)))
p03101
h,w = list(map(int,input().split())) p, q = list(map(int,input().split())) print((h * w - p * w - q * h + p * q))
H,W = list(map(int,input().split())) h,w = list(map(int,input().split())) print(((H - h) * (W - w)))
p03101
H,W=list(map(int,input().split())) h,w=list(map(int,input().split())) lw=H*W-(h*W+H*w-h*w) print(lw)
H,W=list(map(int,input().split())) h,w=list(map(int,input().split())) print(((H-h)*(W-w)))
p03101
H,W = list(map(int,input().split())) h,w = list(map(int,input().split())) print(((H-h)*(W-w)))
H,W=list(map(int,input().split())) h,w=list(map(int,input().split())) s=(H-h)*(W-w) print(s)
p03101
N=int(eval(input())) result = 0; for i in range(1,N+1): result += i print(result)
n=int(eval(input())) s=0 for i in range(1,n+1): s+=i print(s)
p04029
def resolve(): n=int(eval(input())) print(((1+n)*n//2)) resolve()
def resolve(): n=int(eval(input())) ans=0 for i in range(1,n+1): ans+=i print(ans) resolve()
p04029
val1=int(eval(input())) print((int(val1*(val1+1)/2)))
s=int(eval(input())) print((int(s*(s+1)/2)))
p04029
N = int(eval(input())) sum = 0 for i in range(1, N+1): sum += i print(sum)
print((sum(list(range(1, int(eval(input()))+1)))))
p04029
n = eval(input()) x = int(n) y = 0.5*x*(x+1) print((int(y)))
N=int(eval(input())) print((int(N*(N+1)/2)))
p04029
N= int(eval(input())) C=0 for i in range(N): C = C + i + 1 print(C)
N = int(eval(input())) print((N*(N+1)//2))
p04029
child_num = eval(input()) child_num = int(child_num) candy_num = int((child_num**2 + child_num) / 2) print(candy_num)
#子供の数を入力 child_num = int(eval(input())) candy_num = int((child_num**2 + child_num) / 2) print(candy_num)
p04029
n = int(eval(input())) ans = 0 for i in range(1,n+1): ans += i print(ans)
def main(): N = int(eval(input())) print((N*(N+1)//2)) if __name__ == '__main__': main()
p04029
print((sum(range(int(eval(input()))+1))))
n=int(eval(input()));print((n*(n+1)//2))
p04029
n=int(eval(input()));print((n*-~n//2))
print((sum(range(int(eval(input()))+1))))
p04029
N=int(eval(input())) print((N*(N+1)//2))
N=int(eval(input())) i=1 s=0 while i<=N: s+=i i+=1 print(s)
p04029
a = int(eval(input())) print((int((1+a)*a/2)))
a = int(eval(input())) print((int(a*(a+1)/2)))
p04029
n = int(eval(input())) answer = int((n + 1) * n / 2) print(answer)
n = int(eval(input())) print((int((n + 1) * n / 2)))
p04029
def main(): N = int(eval(input())) candys = N * (1 + N) // 2 print(candys) if __name__ == '__main__': main()
N = int(eval(input())) cnt = N *(1+N)//2 print(cnt)
p04029
N=int(eval(input())) print((N*(N+1)//2))
n=int(eval(input())) i=0 for m in range(n+1): i=i+m print(i)
p04029
N = int(eval(input())) print((int(N*(N+1)/2)))
N = int(eval(input())) print((N*(N+1)//2))
p04029
def acum(n): if n <= 1: return 1 return n + acum(n - 1) print((acum(int(eval(input())))))
n=int(eval(input()));print((n*-~n>>1))
p04029
N = int(eval(input())) ans = sum([i for i in range(N+1)]) print(ans)
def resolve(): N = int(eval(input())) print((int((1+N) * N * (1/2)))) resolve()
p04029
print((sum([i for i in range(1, int(eval(input()))+1)])))
n = int(eval(input())) print((n*(n+1)//2))
p04029
N = int(eval(input())) cnt = 0 for i in range(1,N+1): cnt += i print(cnt)
N = int(eval(input())) def dfs(n): ret = 0 for i in range(1,n+1): ret += i return ret print((dfs(N)))
p04029
N = int(eval(input())) num = 0 for i in range(1,N+1): num += i print(num)
N = int(eval(input())) print((sum([i for i in range(1, N+1)])))
p04029
#coding:utf-8 N = int(eval(input())) trees = [list(input().split()) for i in range(N)] class BinaryTree: def __init__(self,key,p=None,l=None,r=None): self.key = key self.p = p self.l = l self.r = r def Insert(root,z): y = None x = root while x != None: y = x if z.key < x.key: x = x.l else: x = x.r z.p = y if y == None: root = z elif z.key < y.key: y.l = z else: y.r = z return root def preOrder(x): if x == None: return global preList preList.append(x.key) preOrder(x.l) preOrder(x.r) def inOrder(x): if x == None: return inOrder(x.l) global inList inList.append(x.key) inOrder(x.r) def Find(x,target): if x == None: return if x.key == target: global yes yes = True return True Find(x.l,target) Find(x.r,target) root = None for data in trees: if data[0] == "insert": z = BinaryTree(int(data[1])) root = Insert(root,z) if data[0] == "find": yes = False a = Find(root, int(data[1])) if yes: print("yes") else: print("no") if data[0] == "print": inList = [] preList = [] inOrder(root) a = " " + " ".join([str(num) for num in inList]) print(a) preOrder(root) a = " " + " ".join([str(num) for num in preList]) print(a)
#coding:utf-8 N = int(eval(input())) trees = [list(input().split()) for i in range(N)] class BinaryTree: def __init__(self,key,p=None,l=None,r=None): self.key = key self.p = p self.l = l self.r = r def Insert(root,z): y = None x = root while x != None: y = x if z.key < x.key: x = x.l else: x = x.r z.p = y if y == None: root = z elif z.key < y.key: y.l = z else: y.r = z return root def preOrder(x): if x == None: return global preList preList.append(x.key) preOrder(x.l) preOrder(x.r) def inOrder(x): if x == None: return inOrder(x.l) global inList inList.append(x.key) inOrder(x.r) def Find(x,target): while x != None: y = x if target < x.key: x = x.l elif target > x.key: x = x.r else: print("yes") return print("no") root = None for data in trees: if data[0] == "insert": z = BinaryTree(int(data[1])) root = Insert(root,z) if data[0] == "find": Find(root, int(data[1])) if data[0] == "print": inList = [] preList = [] inOrder(root) a = " " + " ".join([str(num) for num in inList]) print(a) preOrder(root) a = " " + " ".join([str(num) for num in preList]) print(a)
p02284
class Node: def __init__(self, key=-1, parent=-1, left=-1, right=-1): self.key = key self.parent = parent self.left = left self.right = right def insert(t, z): x, y = t, -1 while x != -1: y = x if z.key < x.key: x = x.left else: x = x.right z.parent = y if y == -1: t = z elif z.key < y.key: y.left = z else: y.right = z return t def find(x, k): while x != -1 and k != x.key: if k < x.key: x = x.left else: x = x.right return x def print_tree(t): def in_order(z): if z == -1: return in_order(z.left) print(" {}".format(z.key), end="") in_order(z.right) def pre_order(z): if z == -1: return print(" {}".format(z.key), end="") pre_order(z.left) pre_order(z.right) in_order(t) print() pre_order(t) print() def main(): n = int(input()) bst = -1 for i in range(n): order = input().split() if order[0][0] == "i": bst = insert(bst, Node(int(order[1]))) elif order[0][0] == "f": if find(bst, int(order[1])) == -1: print("no") else: print("yes") else: print_tree(bst) if __name__ == '__main__': main()
class BinarySearchTree: class __Node: def __init__(self, key=-1, parent=-1, left=-1, right=-1): self.key = key self.parent = parent self.left = left self.right = right def __init__(self): self.root = -1 def insert(self, z): node = BinarySearchTree.__Node(key=z) x, y = self.root, -1 while x != -1: y = x if z < x.key: x = x.left else: x = x.right node.parent = y if y == -1: self.root = node elif z < y.key: y.left = node else: y.right = node def find(self, k): x = self.root while x != -1 and k != x.key: if k < x.key: x = x.left else: x = x.right return x def print_tree(self): def in_order(z): if z == -1: return in_order(z.left) print(" {}".format(z.key), end="") in_order(z.right) def pre_order(z): if z == -1: return print(" {}".format(z.key), end="") pre_order(z.left) pre_order(z.right) in_order(self.root) print() pre_order(self.root) print() def main(): n = int(input()) bst = BinarySearchTree() for i in range(n): order = input().split() if order[0][0] == "i": bst.insert(int(order[1])) elif order[0][0] == "f": if bst.find(int(order[1])) == -1: print("no") else: print("yes") else: bst.print_tree() if __name__ == '__main__': main()
p02284
import sys readline = sys.stdin.readline class Node: __slots__ = ['value', 'left', 'right'] def __init__(self, value = None, left = None, right = None): self.value = value self.left = left self.right = right class BinTree: __slots__ = ['_tree', '_node_list'] def __init__(self): self._tree = None self._node_list = set() def insert(self, value): self._node_list.add(value) p = None c = self._tree while c is not None: p = c if value < c.value: c = c.left else: c = c.right if p is None: self._tree = Node(value) elif value < p.value: p.left = Node(value) else: p.right = Node(value) def find(self, value): print(("yes" if value in self._node_list else "no")) def preoder_walk(self): def preoder(node): result = [] if node is not None: result.extend([node.value]) if node.left is not None: result.extend(preoder(node.left)) if node.right is not None: result.extend(preoder(node.right)) return result return preoder(self._tree) def inorder_walk(self): def inorder(node): result = [] if node is not None: result.extend(inorder(node.left)) result.append(node.value) result.extend(inorder(node.right)) return result return inorder(self._tree) n = int(eval(input())) tree = BinTree() for _ in range(n): com = readline().split() if com[0] == "insert": tree.insert(int(com[1])) elif com[0] == "find": tree.find(int(com[1])) else: print((" " + " ".join(map(str, tree.inorder_walk())))) print((" " + " ".join(map(str, tree.preoder_walk()))))
import sys readline = sys.stdin.readline class Node: __slots__ = ['value', 'left', 'right'] def __init__(self, value = None, left = None, right = None): self.value = value self.left = left self.right = right class BinTree: def __init__(self): self._tree = None def insert(self, value): p = None c = self._tree while c is not None: p = c if value < c.value: c = c.left else: c = c.right if p is None: self._tree = Node(value) elif value < p.value: p.left = Node(value) else: p.right = Node(value) def find(self, value): c = self._tree while c is not None: if value == c.value: return True elif value < c.value: c = c.left else: c = c.right return False def preoder_walk(self): self.result = [] def preoder(node): if node is not None: self.result.append(node.value) preoder(node.left) preoder(node.right) preoder(self._tree) print((" " + " ".join(map(str, self.result)))) def inorder_walk(self): self.result = [] def inorder(node): if node is not None: inorder(node.left) self.result.append(node.value) inorder(node.right) inorder(self._tree) print((" " + " ".join(map(str, self.result)))) n = int(eval(input())) tree = BinTree() for _ in range(n): com = readline().split() if com[0] == "insert": tree.insert(int(com[1])) elif com[0] == "find": print(("yes" if tree.find(int(com[1])) else "no")) else: tree.inorder_walk() tree.preoder_walk()
p02284
import sys import time class Node: def __init__(self, key = None): self.key = key self.left = None self.right = None def insert(key): global root z = Node(key) y = None x = root while x is not None: y = x if z.key < x.key: x = x.left else: x = x.right if y is None: root = z elif z.key < y.key: y.left = z else: y.right = z def find(node, key): if node is None: return False elif node.key == key: return True else: return find(node.left, key) or find(node.right, key) def inorderTreeWalk(node): if node: return inorderTreeWalk(node.left) + " " + str(node.key) + inorderTreeWalk(node.right) return "" def preorderTreeWalk(node): if node: return " " + str(node.key) + preorderTreeWalk(node.left) + preorderTreeWalk(node.right) return "" if __name__ == "__main__": lines = sys.stdin.readlines() del lines[0] root = None for line in lines: if line[0] == "p": print(inorderTreeWalk(root)) print(preorderTreeWalk(root)) else: com = line.split() if com[0][0] == "i": insert(int(com[1])) else: if find(root, int(com[1])): print("yes") else: print("no")
import sys import time class Node: def __init__(self, key): self.key = key self.parent = None self.left = None self.right = None def insert(z): global root y = None x = root while x is not None: y = x if z.key < x.key: x = x.left else: x = x.right z.parent = y if y is None: root = z elif z.key < y.key: y.left = z else: y.right = z def find(node, key): if node is None: return False elif node.key == key: return True elif node.key > key: return find(node.left, key) else: return find(node.right, key) def inorderTreeWalk(node): global In if node: inorderTreeWalk(node.left) In.append(str(node.key)) inorderTreeWalk(node.right) def preorderTreeWalk(node): global Pre if node: Pre.append(str(node.key)) preorderTreeWalk(node.left) preorderTreeWalk(node.right) if __name__ == "__main__": lines = sys.stdin.readlines() del lines[0] root = None for line in lines: if line[0] == "p": In = [] Pre = [] inorderTreeWalk(root) print(" " + " ".join(map(str, In))) preorderTreeWalk(root) print(" " + " ".join(map(str, Pre))) else: com = line.split() if com[0][0] == "i": insert(Node(int(com[1]))) else: if find(root, int(com[1])): print("yes") else: print("no")
p02284
from sys import stdin class Node: def __init__(self, id): self.id = id self.left = None self.right = None self.parent = None def preorder_tree_walk(root): print('', root.id, end='') if root.left != None: preorder_tree_walk(root.left) if root.right != None: preorder_tree_walk(root.right) def inorder_tree_walk(root): if root.left != None: inorder_tree_walk(root.left) print('', root.id, end='') if root.right != None: inorder_tree_walk(root.right) def insert(root, z): y = None x = root while isinstance(x, Node): y = x if z.id < x.id: x = x.left else: x = x.right z.parent = y if y == None: root = z elif z.id < y.id: y.left = z else: y.right = z return root def find(root, x): if root.id == x: return True if root.id > x: if root.left == None: return False else: return find(root.left, x) else: if root.right == None: return False else: return find(root.right, x) n = int(input()) root = None for i in range(n): cmd = stdin.readline() if cmd.startswith('i'): num = int(cmd[7:]) root = insert(root, Node(num)) elif cmd.startswith('p'): inorder_tree_walk(root) print() preorder_tree_walk(root) print() else: # find num = int(cmd[5:]) if find(root, num): print('yes') else: print('no')
from sys import stdin class Node: def __init__(self, id): self.id = id self.left = None self.right = None self.parent = None def preorder_tree_walk(root): print('', root.id, end='') if root.left != None: preorder_tree_walk(root.left) if root.right != None: preorder_tree_walk(root.right) def inorder_tree_walk(root): if root.left != None: inorder_tree_walk(root.left) print('', root.id, end='') if root.right != None: inorder_tree_walk(root.right) def insert(root, z): y = None x = root while isinstance(x, Node): y = x if z.id < x.id: x = x.left else: x = x.right z.parent = y if y == None: root = z elif z.id < y.id: y.left = z else: y.right = z return root def find(root, x): while root != None and x != root.id: if x < root.id: root = root.left else: root = root.right return root n = int(input()) root = None for i in range(n): cmd = stdin.readline() if cmd.startswith('i'): num = int(cmd[7:]) root = insert(root, Node(num)) elif cmd.startswith('p'): inorder_tree_walk(root) print() preorder_tree_walk(root) print() else: # find num = int(cmd[5:]) if find(root, num) != None: print('yes') else: print('no')
p02284
import sys class Node(): __slots__ = ['key', 'left', 'right'] def __init__(self, key): self.key = key self.left, self.right = None, None def __str__(self): return " " + str(self.key) def insert(z): global root x, y = root, None while x: y = x if z < x.key: x = x.left else: x = x.right if y == None: root = Node(z) elif z < y.key: y.left = Node(z) else: y.right = Node(z) def find(z): global root x, y = root, None while x: y = x if z < x.key: x = x.left elif z > x.key: x = x.right else: print("yes") return print("no") def preorder(x): return str(x) + preorder(x.left) + preorder(x.right) if x else "" def inorder(x): return inorder(x.left) + str(x) + inorder(x.right) if x else "" eval(input()) root = None for s in sys.stdin: if s[0] == "p": print((inorder(root))) print((preorder(root))) elif s[0] == "f": find(int(s[5:])) else: insert(int(s[7:]))
import sys class Node(): __slots__ = ['key', 'left', 'right'] def __init__(self, key): self.key = key self.left, self.right = None, None def insert(z): global root x, y = root, None while x: y = x if z < x.key: x = x.left else: x = x.right if y == None: root = Node(z) elif z < y.key: y.left = Node(z) else: y.right = Node(z) def find(z): global root x, y = root, None while x: y = x if z < x.key: x = x.left elif z > x.key: x = x.right else: print("yes") return print("no") def preorder(x): return f" {x.key}" + preorder(x.left) + preorder(x.right) if x else "" def inorder(x): return inorder(x.left) + f" {x.key}" + inorder(x.right) if x else "" eval(input()) root = None for s in sys.stdin: if s[0] == "p": print((inorder(root))) print((preorder(root))) elif s[0] == "f": find(int(s[5:])) else: insert(int(s[7:]))
p02284
#!/usr/bin/env python from sys import stdin class Node(object): def __init__(self, key=None): self.key = key self.parent = None self.left = None self.right = None def tree_insert(top, z): y = None x = top while isinstance(x, Node): y = x if z.key < x.key: x = x.left else: x = x.right z.parent = y if y is None: top = z elif z.key < y.key: y.left = z else: y.right = z return top def tree_find(node, key): if not node: return False if node.key == key: return True return tree_find(node.left, key) or tree_find(node.right, key) def inorder_walk(node): if node.left: inorder_walk(node.left) print('', node.key, end='') if node.right: inorder_walk(node.right) def preorder_walk(node): print('', node.key, end='') if node.left: preorder_walk(node.left) if node.right: preorder_walk(node.right) n = int(stdin.readline()) #assert n <= 500000 top = None for _ in range(n): cmd = stdin.readline() if cmd.startswith('i'): key = int(cmd[7:]) #assert -2000000000 <= key <= 2000000000 top = tree_insert(top, Node(key)) elif cmd.startswith('f'): key = int(cmd[5:]) r = tree_find(top, key) print('yes' if r else 'no') else: inorder_walk(top) print() preorder_walk(top) print()
#!/usr/bin/env python from sys import stdin class Node(object): def __init__(self, key=None): self.key = key self.parent = None self.left = None self.right = None def tree_insert(top, z): y = None x = top while isinstance(x, Node): y = x if z.key < x.key: x = x.left else: x = x.right z.parent = y if y is None: top = z elif z.key < y.key: y.left = z else: y.right = z return top def tree_find(node, key): if not node: return False if node.key == key: return True if key < node.key: return tree_find(node.left, key) return tree_find(node.right, key) def inorder_walk(node): if node.left: inorder_walk(node.left) print('', node.key, end='') if node.right: inorder_walk(node.right) def preorder_walk(node): print('', node.key, end='') if node.left: preorder_walk(node.left) if node.right: preorder_walk(node.right) n = int(stdin.readline()) #assert n <= 500000 top = None for _ in range(n): cmd = stdin.readline() if cmd.startswith('i'): key = int(cmd[7:]) #assert -2000000000 <= key <= 2000000000 top = tree_insert(top, Node(key)) elif cmd.startswith('f'): key = int(cmd[5:]) r = tree_find(top, key) print('yes' if r else 'no') else: inorder_walk(top) print() preorder_walk(top) print()
p02284
#!/usr/bin/env python # -*- coding: utf-8 -*- while True: x,y,s = list(map(int,input().split())) if (x,y,s) == (0,0,0): break ans = 0 for i in range(1,s-1): for j in range(1,s-i + 1): if i*(100+x)//100 + j*(100+x)//100== s: ans = max(ans,i*(100+y)//100 + j*(100+y)//100) print(ans)
#!/usr/bin/env python # -*- coding: utf-8 -*- while True: x,y,s = list(map(int,input().split())) if (x,y,s) == (0,0,0): break ans = 0 for i in range(1,s//2 + 1): for j in range(1,s-i + 1): if i*(100+x)//100 + j*(100+x)//100== s: ans = max(ans,i*(100+y)//100 + j*(100+y)//100) print(ans)
p00773
n,k=list(map(int,input().split())) d=set(input().split()) a=[] for i in range(n,10*n): if not set(str(i))&set(d): print(i) exit()
n,k=list(map(int,input().split())) d=set(input().split()) for i in range(n,10*n): if not set(str(i))&d: print(i) exit()
p04039
n, k = list(map(int, input().split())) d = set(range(10)) - set(map(int, input().split())) i = n while True: if (i >= n) and all(int(k) in d for k in str(i)): print(i) break i += 1
n, k = list(map(int, input().split())) d = set(range(10)) - set(map(int, input().split())) i = n while True: if (i >= n) and all(int(j) in d for j in str(i)): print(i) break i += 1
p04039
s=set(range(10)) n,k,*a=list(map(int,open(0).read().split())) a=s-set(a) #使っていい数字 for t in range(n,100000): if set(list(map(int,list(str(t)))))<=a: print(t) break
x=lambda:input().split() n,_=x();a=x();n=int(n) while any(s in set(a)for s in str(n)):n+=1 print(n)
p04039
N,K=list(map(int,input().split())) d=list(map(int,input().split())) dr=len(d) for i in range(N,100000): s=list(str(i)) num=0 for j in d: if(str(j) in s): break else: num+=1 if(num==dr): print(i) break
N,K=list(map(int,input().split())) D=list(input().split()) for i in range(N,100000): ans=True for j in str(i): if(str(j) in D): ans=False break if(ans): print(i) exit()
p04039
def slove(): import sys input = sys.stdin.readline n, k = list(map(int, input().rstrip('\n').split())) d = list(map(int, input().rstrip('\n').split())) for i in range(n, 10 ** 10): t = list(str(i)) b = True for j in range(len(t)): if int(t[j]) in d: b = False break if b: print(i) exit() if __name__ == '__main__': slove()
def slove(): import sys input = sys.stdin.readline n, k = list(map(int, input().rstrip('\n').split())) d = {str(i): 0 for i in list(map(int, input().rstrip('\n').split()))} for i in range(n, 10 ** 15): t = str(i) b = True for j in range(len(t)): if t[j] in d: b = False break if b: print(i) exit() if __name__ == '__main__': slove()
p04039
n, k = list(map(int, input().split())) d = list(input().split()) from itertools import count for i in count(n): s = str(i) for bit in s: if bit in d: break else: print(i) break
n,k = list(map(int, input().split())) d = list(map(int, input().split())) def v(n): for c in map(int, str(n)): if (c in d): return False return True while (v(n) == False): n += 1 print(n)
p04039
a,b = list(map(int,input().split(" "))) ar = list(map(int,input().split(" "))) while True: count = 0 br = list(str(a)) for r in br: if int(r) in ar: count += 1 if count == 0: print(a) break else: a += 1
a,b = list(map(int,input().split(" "))) ar = input().split(" ") while True: count = 0 for r in ar: if r in str(a): count += 1 break if count == 0: print(a) break a += 1
p04039
from collections import OrderedDict, deque import heapq import fileinput MAX_VELOCITY = 1000000000 MAX_N = 200000 MODULO = 1000000007 # class Takahashi(object): # __slots__ = ['position', 'velocity', 'block_start', 'block_end', 'seen'] # def __init__(self, position, velocity): # self.position = position # self.velocity = velocity # self.block_start = None # self.block_end = None # self.seen = False n = 0 takahashis = [] velocities = [] # maps a block index (0...N-1) to start (or end) of its corresponding block. block_starts = [] block_ends = [] seen = [] # all stops we take along the way block_starting_positions = OrderedDict() block_ending_positions = OrderedDict() # possibilities[i] indicates the number of possibilities # from block with indices 0 to i. possibilities = [] # HANDLE INPUT def file_iterator(file_name): with open(file_name) as f: for line in f: yield line def handle_input(file_name=None): if file_name: iterator = file_iterator(file_name) else: iterator = fileinput.input() global n n = int(next(iterator)) takahashis[:] = [None] * n for i in range(n): x, v = next(iterator).split() takahashis[i] = (int(x), int(v)) def preprocessing(): takahashis.sort() block_starts[:] = [None] * n block_ends[:] = [None] * n seen[:] = [False] * n possibilities[:] = [None] * (n + 1) velocities[:] = ((t[1], i) for i, t in enumerate(takahashis)) velocities.sort() def turn_input_into_blocks(): velocity_cursor = -1 rightmost_smaller_velocity_index = 0 for i in range(n): if seen[i]: continue # Determine end of block involving the smallest unseen velocity. # Also, get index of rightmost smaller velocity and mark as seen current_velocity = takahashis[i][1] first = True while velocity_cursor < n - 1 and current_velocity >= takahashis[velocities[velocity_cursor + 1][1]][1]: velocity_cursor += 1 upcoming_smaller_velocity_index = velocities[velocity_cursor][1] seen[upcoming_smaller_velocity_index] = True rightmost_smaller_velocity_index = max( rightmost_smaller_velocity_index, upcoming_smaller_velocity_index) if first: block_end = rightmost_smaller_velocity_index first = False block_starts[i] = i block_ends[i] = block_end # check if already have a longer block ending at same position previous_longer_block = block_ending_positions.get(block_end) if previous_longer_block is not None: del block_starting_positions[block_starts[previous_longer_block]] block_starting_positions[i] = i block_ending_positions[block_end] = i sentinel = [n - 1] if n - 1 not in block_ending_positions else [] return heapq.merge(block_starting_positions, block_ending_positions, sentinel) def build_stops_iterator(stops): current_position = None while True: next_position = next(stops, None) if next_position == current_position: next_position = next(stops, None) current_position = next_position if current_position is not None: yield current_position else: break def compute_possibilities(stops_iterator): possibilities[-1] = 1 active_blocks = deque() current_position = 0 alpha = 0 while current_position < n: # fast track check next_position = next(stops_iterator, None) indices_to_move = next_position - current_position if indices_to_move > 0: # fast track for `indices_to_move` rounds where no block starts or ends. k, p = indices_to_move, possibilities[current_position - 1] possibilities[current_position - 1 + k] = ( pow(2, k, MODULO) * p + (pow(2, k, MODULO) - 1) * alpha) % MODULO # move forward current_position += indices_to_move # update active blocks has_new_block = current_position in block_starting_positions if has_new_block: active_blocks.append(current_position) alpha += possibilities[current_position - 1] # compute result result = alpha + (2 * possibilities[current_position - 1] if not has_new_block else 0) possibilities[current_position] = result % MODULO # update active blocks if current_position in block_ending_positions: block_that_ended = active_blocks.popleft() alpha -= possibilities[block_starts[block_that_ended] - 1] current_position += 1 return possibilities[n - 1] def main(): handle_input() preprocessing() stops = turn_input_into_blocks() return compute_possibilities(build_stops_iterator(stops)) if __name__ == '__main__': print(main())
from bisect import bisect_left, bisect_right import fileinput MODULO = 1000000007 n = 0 # HANDLE INPUT def handle_input(): iterator = fileinput.input() global n n = int(next(iterator)) takahashis = [None] * n for i in range(n): x, v = next(iterator).split() takahashis[i] = (int(x), int(v)) return takahashis def build_blocks(takahashis): result = [-1] * (n + 1) max_velocities = [0] * n min_velocities = [MODULO] * (n + 1) for i in range(n): max_velocities[i] = max(max_velocities[i - 1], takahashis[i][1]) for i in range(n-1, -1, -1): min_velocities[i] = min(min_velocities[i + 1], takahashis[i][1]) for i in range(n): current_velocity = takahashis[i][1] block_start = bisect_left(max_velocities, current_velocity) block_end = bisect_right(min_velocities, current_velocity) - 1 result[block_end] = max(result[block_end], block_start) return result def compute_possibilities(blocks): possibilities = [1] * (n + 2) zeros_end_cursor = -2 for current_position in range(n): result = 2 * possibilities[current_position - 1] # Remove possibiltiies for (00..)1{.....} sequences. while zeros_end_cursor < blocks[current_position] - 1: result -= possibilities[zeros_end_cursor] zeros_end_cursor += 1 possibilities[current_position] = result % MODULO return possibilities[n - 1] def main(): takahashis = handle_input() takahashis.sort() blocks = build_blocks(takahashis) return compute_possibilities(blocks) if __name__ == '__main__': print(main())
p03709
code=""" #include <bits/stdc++.h> using namespace std; #define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl #define repi(i,a,b) for(int i=int(a);i<int(b);i++) #define peri(i,a,b) for(int i=int(b);i-->int(a);) #define rep(i,n) repi(i,0,n) #define per(i,n) peri(i,0,n) #define all(c) begin(c),end(c) #define mp make_pair #define mt make_tuple typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<string> vs; template<typename T1,typename T2> ostream& operator<<(ostream& os,const pair<T1,T2>& p){ return os<<'('<<p.first<<','<<p.second<<')'; } template<typename Tuple> void print_tuple(ostream&,const Tuple&){} template<typename Car,typename... Cdr,typename Tuple> void print_tuple(ostream& os,const Tuple& t){ print_tuple<Cdr...>(os,t); os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t); } template<typename... Args> ostream& operator<<(ostream& os,const tuple<Args...>& t){ print_tuple<Args...>(os<<'(',t); return os<<')'; } template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))> basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){ os<<'['; for(auto i=begin(c);i!=end(c);++i) os<<(i==begin(c)?"":" ")<<*i; return os<<']'; } constexpr int INF=1e9; constexpr int MOD=1e9+7; constexpr double EPS=1e-9; int dfs(const vvi& g,int u) { int res=1<<u; for(int v:g[u]) res|=dfs(g,v); return res; } int main() { for(int n,m;cin>>n>>m && n|m;){ array<int,20> cs; vvi g(n); rep(i,n){ cin>>cs[i]; int k; cin>>k; rep(j,k){ int r; cin>>r; g[i].push_back(r); } } array<int,20> bs; rep(i,n) bs[i]=dfs(g,i); static array<int,1<<20> sums; sums.fill(0); rep(i,n) sums[1<<i]=cs[i]; rep(i,1<<n) sums[i]=sums[i&-i]+sums[i-(i&-i)]; int res=INF; rep(i,1<<n) if(__builtin_popcount(i)<res){ int b=0; rep(j,n) b|=(i>>j&1)*bs[j]; if(sums[b]>=m) res=min(res,__builtin_popcount(b)); } cout<<res<<endl; } } """ import os,tempfile (_,filename)=tempfile.mkstemp(".cpp") f=open(filename,"w") f.write(code) f.close() os.system("g++ -std=c++0x {} -o ./a.out".format(filename)) os.system("./a.out")
code=""" #include <iostream> #include <algorithm> #include <array> #include <vector> using namespace std; #define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl #define repi(i,a,b) for(int i=int(a);i<int(b);i++) #define peri(i,a,b) for(int i=int(b);i-->int(a);) #define rep(i,n) repi(i,0,n) #define per(i,n) peri(i,0,n) #define all(c) begin(c),end(c) #define mp make_pair #define mt make_tuple typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<string> vs; constexpr int INF=1e9; constexpr int MOD=1e9+7; constexpr double EPS=1e-9; int dfs(const vvi& g,int u) { int res=1<<u; for(int v:g[u]) res|=dfs(g,v); return res; } int main() { for(int n,m;cin>>n>>m && n|m;){ array<int,20> cs; vvi g(n); rep(i,n){ cin>>cs[i]; int k; cin>>k; rep(j,k){ int r; cin>>r; g[i].push_back(r); } } array<int,20> bs; rep(i,n) bs[i]=dfs(g,i); static array<int,1<<20> sums; sums.fill(0); rep(i,n) sums[1<<i]=cs[i]; rep(i,1<<n) sums[i]=sums[i&-i]+sums[i-(i&-i)]; int res=INF; rep(i,1<<n) if(__builtin_popcount(i)<res){ int b=0; rep(j,n) b|=(i>>j&1)*bs[j]; if(sums[b]>=m) res=min(res,__builtin_popcount(b)); } cout<<res<<endl; } } """ import os,tempfile (_,filename)=tempfile.mkstemp(".cpp") f=open(filename,"w") f.write(code) f.close() os.system("g++ -std=c++0x {} -o ./a.out".format(filename)) os.system("./a.out")
p00618
#!/usr/bin/env python3 import sys YES = "Yes" # type: str NO = "No" # type: str def solve(N: int, A: int, B: int, C: int, D: int, S: str): ret = YES if '##' in S[A:C] or '##' in S[B:D]: ret = NO else: if D < C: #if S[B - 2:B] == '..' or S[B - 1:B + 1] == '..': if not '...' in S[B - 2:D + 1]: ret = NO print(ret) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int C = int(next(tokens)) # type: int D = int(next(tokens)) # type: int S = next(tokens) # type: str solve(N, A, B, C, D, S) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys YES = "Yes" # type: str NO = "No" # type: str def solve(N: int, A: int, B: int, C: int, D: int, S: str): ret = YES if '##' in S[A - 1:C] or '##' in S[B - 1:D]: ret = NO else: if D < C: #if S[B - 2:B] == '..' or S[B - 1:B + 1] == '..': if not '...' in S[B - 2:D + 1]: ret = NO print(ret) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int C = int(next(tokens)) # type: int D = int(next(tokens)) # type: int S = next(tokens) # type: str solve(N, A, B, C, D, S) if __name__ == '__main__': main()
p03017
# 2019-11-22 19:46:21(JST) import sys def main(): n, a, b, c, d = [int(x) for x in sys.stdin.readline().split()] s = '#' + sys.stdin.readline().rstrip() if '##' in s[a+1:c-1] or '##' in s[b+1:d-1]: ans = 'No' else: if c < d: ans = 'Yes' else: for i in range(b, d+1): if s[i-1] == s[i] == s[i+1] == '.': ans = 'Yes' break else: ans = 'No' print(ans) if __name__ == '__main__': main()
# 2019-11-22 19:46:21(JST) import sys def main(): n, a, b, c, d = [int(x) for x in sys.stdin.readline().split()] s = '#' + sys.stdin.readline().rstrip() if '##' in s[a+1:c-1] or '##' in s[b+1:d-1]: ans = 'No' else: if c < d: ans = 'Yes' else: # for i in range(b, d+1): # if s[i-1] == s[i] == s[i+1] == '.': # ans = 'Yes' # break if '...' in s[b-1:d+2]: ans = 'Yes' else: ans = 'No' print(ans) if __name__ == '__main__': main()
p03017
#!/usr/bin/env python3 import sys YES = "Yes" # type: str NO = "No" # type: str def solve(N: int, A: int, B: int, C: int, D: int, S: str): if(S[A-1] == '#' or S[B-1] == '#' or S[C-1] == '#' or S[D-1] == '#'): print(NO) sys.exit() if(S[A-1:C].count('##') == 0 and S[B-1:D].count('##') == 0): if(D < C): sf = (S[A-1:D+1].count('...')) if(sf == 0): print(NO) elif(sf == 1): tS = list(S) tS[B-1] = 'b' tS = ''.join(tS) if(tS[A-1:D+1].count('..b#') == 1): print(NO) else: print(YES) ######### あとはここだけ考える #### elif(sf >= 2): # print('Im here!') tS = list(S) tS[B-1] = 'b' tS = ''.join(tS) ptS = tS.rfind('..b#') if(ptS == -1): print(YES) else: if(tS[ptS+3:D+1].count('...') == 0): # print(tS[ptS:D]) print(NO) else: # print(tS[ptS:D]) print(YES) else: # D > Cの場合 print(YES) else: print(NO) return # Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int C = int(next(tokens)) # type: int D = int(next(tokens)) # type: int S = next(tokens) # type: str solve(N, A, B, C, D, S) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys YES = "Yes" # type: str NO = "No" # type: str def solve(N: int, A: int, B: int, C: int, D: int, S: str): if(S[A-1:C+1].count('##') > 0 or S[B-1:D+1].count('##')): # if(S[A:max(C,D)].count('##') > 1): print(NO) sys.exit() if(D < C): if(S[B-2:D+1].count('...') <= 0): print(NO) sys.exit() else: print(YES) else: print(YES) return # Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int C = int(next(tokens)) # type: int D = int(next(tokens)) # type: int S = next(tokens) # type: str solve(N, A, B, C, D, S) if __name__ == '__main__': main()
p03017
#!/usr/bin/env python import bisect from collections import defaultdict import math def judge(start, end, S): for i in range(start, end): s = S[i:i+2] if tuple(s) == ("#", "#"): return False return True def main(): N, A, B, C, D = list(map(int, input().split())) S = list(input().strip()) is_ok = judge(A-1, C-1, S) if not is_ok: print("No") return is_ok = judge(B-1, D-1, S) if not is_ok: print("No") return if C > D: for i in range(B-1, D): if S[i] != "#": new_S = list(S) new_S[i] = "#" is_ok = judge(A-1, C-1, new_S) if is_ok: print("Yes") return print("No") else: print("Yes") if __name__ == '__main__': main()
#!/usr/bin/env python import bisect from collections import defaultdict import math def judge(start, end, S): for i in range(start, end): s = S[i:i+2] if tuple(s) == ("#", "#"): return False return True def main(): N, A, B, C, D = list(map(int, input().split())) S = list(input().strip()) is_ok = judge(A-1, C-1, S) if not is_ok: print("No") return is_ok = judge(B-1, D-1, S) if not is_ok: print("No") return if C > D: for i in range(B-1, D): if S[i] != "#" and S[i-1] != "#" and S[i+1] != "#": print("Yes") return print("No") else: print("Yes") if __name__ == '__main__': main()
p03017
N,A,B,C,D = list(map(int,input().split())) S = input().strip() S = "."+S flag=0 if C<B: for i in range(A,C): if S[i:i+2]=="##": flag=1 break for i in range(B,D): if S[i:i+2]=="##": flag=1 break if flag==1: print("No") else: print("Yes") elif B<C<D: for i in range(A,D): if S[i:i+2]=="##": flag=1 break if flag==1: print("No") else: print("Yes") else: for i in range(A,C): if S[i:i+2]=="##": flag = 1 break if flag==1: print("No") else: flag = 1 for i in range(B+1,D): if S[i]=="#":continue if (S[i-1]=="#" and S[i+1]=="#") or (S[i-2:i]=="#." and S[i+1]=="#") or (S[i-1]=="#" and S[i+1:i+3]==".#"):continue else: flag=0 break if flag==1: if S[B+1]=="#" or (S[B-1]=="#" and S[B+1:B+3]==".#"): flag=1 else: flag=0 if flag==1: print("No") else: print("Yes")
N,A,B,C,D = list(map(int,input().split())) S = list(input().strip()) S.insert(0,0) if C<D: flag = 0 for i in range(A+1,C+1): if S[i-1]=="#" and S[i]=="#": flag = 1 break for i in range(B+1,D+1): if S[i-1]=="#" and S[i]=="#": flag = 1 break if flag==0: print("Yes") else: print("No") else: flag = 0 for i in range(A+1,C+1): if S[i]=="#" and S[i-1]=="#": flag = 1 break if flag == 0: flag1 = 1 for i in range(B,D+1): if i+1<=N and S[i-1]=="." and S[i]=="." and S[i+1]==".": flag1 = 0 break if flag1==1: flag = 1 if flag==0: print("Yes") else: print("No")
p03017
import sys input = sys.stdin.readline N,A,B,C,D=list(map(int,input().split())) S=input().strip() S+="#####" A-=1 B-=1 C-=1 D-=1 if C<D: while B!=D or A!=C: #print(A,B) if B!=D and S[B+1]==".": B+=1 elif B!=D and S[B+2]==".": B+=2 elif B!=D and S[B+1]=="#" and S[B+2]=="#": print("No") sys.exit() if A!=C and S[A+1]==".": A+=1 elif A!=C and S[A+2]==".": A+=2 elif A!=C and S[A+1]=="#" and S[A+2]=="#": print("No") sys.exit() print("Yes") else: while A<B: if S[A+1]=="." and A+1!=B: A+=1 elif S[A+2]=="." and A+2!=B: A+=2 elif S[A+1]=="#" and S[A+2]=="#": print("No") sys.exit() if A+1==B or (A+2==B and S[A+1]=="#"): break while True: if A+1==B and S[B+1]==".": A+=2 break if S[B+1]==".": B+=1 elif S[B+2]==".": B+=2 else: print("No") sys.exit() if S[A+1]==".": A+=1 elif S[A+2]==".": A+=2 if B>D: print("No") sys.exit() while B!=D or A!=C: if A!=C and S[A+1]==".": A+=1 elif A!=C and S[A+2]==".": A+=2 elif A!=C and S[A+1]=="#" and S[A+2]=="#": print("No") sys.exit() if B!=D and S[B+1]==".": B+=1 elif B!=D and S[B+2]==".": B+=2 elif B!=D and S[B+1]=="#" and S[B+2]=="#": print("No") sys.exit() print("Yes")
import sys input = sys.stdin.readline N,A,B,C,D=list(map(int,input().split())) S=input().strip() BLOCK=[0]*N OPEN=[0]*N for i in range(1,N): if S[i]=="#" and S[i-1]=="#": BLOCK[i]=1 for i in range(2,N): if S[i]==S[i-1]==S[i-2]==".": OPEN[i]=1 RIGHT_A=N-1 for i in range(A,N): if BLOCK[i]==1: RIGHT_A=i break RIGHT_B=N-1 for i in range(B,N): if BLOCK[i]==1: RIGHT_B=i break if C<=RIGHT_A+1 and D<=RIGHT_B+1: if C<D: print("Yes") sys.exit() if RIGHT_A==RIGHT_B: for j in range(B,D+1): if OPEN[j]==1: print("Yes") sys.exit() else: print("No") else: print("Yes") else: print("No")
p03017
import sys n, a, b, c, d = list(map(int, sys.stdin.readline().split())) s = sys.stdin.readline().rstrip() dp = [[False for _ in range(n)] for _ in range(n)] dp[a-1][b-1] = True for i in range(a-1, n): for j in range(b-1, n): if i == j: continue if not dp[i][j]: continue for x, y in ((1, 0), (2, 0), (0, 1), (0, 2)): if (i+x < n) and (j+y < n) and s[i+x] == '.' and s[j+y] == '.': dp[i+x][j+y] = True print(('Yes' if dp[c-1][d-1] else 'No'))
import sys n, a, b, c, d = list(map(int, sys.stdin.readline().split())) s = sys.stdin.readline().rstrip() def can_reach(start, end): for i in range(start-1, end-1): if s[i] == '#' and s[i+1] == '#': return False return True if can_reach(a, c) and can_reach(b, d): if c < d: print('Yes') else: flag = False for i in range(b-1, d): if s[i-1] == '.' and s[i] == '.' and s[i+1] == '.': flag = True print(('Yes' if flag else 'No')) else: print('No')
p03017
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): import operator class SegmentTree: def __init__(self, size, default, op = operator.add): self.size = 2**size.bit_length() self.dat = [default]*(self.size*2) self.op = op def update(self, i, x): i += self.size self.dat[i] = x while i > 0: i >>= 1 self.dat[i] = self.op(self.dat[i*2], self.dat[i*2+1]) def add(self, i, x): i += self.size self.dat[i] = self.op(self.dat[i], x) while i > 0: i >>= 1 self.dat[i] = self.op(self.dat[i], x) def get(self, a, b = None): if b is None: b = a + 1 l, r = a + self.size, b + self.size res = None while l < r: if l & 1: if res is None: res = self.dat[l] else: res = self.op(res, self.dat[l]) l += 1 if r & 1: r -= 1 if res is None: res = self.dat[r] else: res = self.op(res, self.dat[r]) l >>= 1 r >>= 1 return res def check(x,y): return (x == 0)|(x == w)|(y == 0)|(y == h) w,h,n = LI() p = [] lx = set() ly = set() for i in range(n): x,y,s,t = LI() if check(x,y)&check(s,t): p.append((x,y,s,t)) lx |= {x,s} ly |= {y,t} if len(p) < 2: print("YES") return lx = list(lx) ly = list(ly) lx.sort() ly.sort() px = {lx[i]: i for i in range(len(lx))} py = {ly[i]: i for i in range(len(ly))} w,h = max(px.values()),max(py.values()) fy0 = SegmentTree(w+1, 0) fyh = SegmentTree(w+1, 0) fx0 = SegmentTree(h+1, 0) fxw = SegmentTree(h+1, 0) for i in range(len(p)): b = 1<<i x,y,s,t = p[i] x,y,s,t = px[x],py[y],px[s],py[t] if x == 0: f1 = fx0.get(0,y+1) elif x == w: f1 = fxw.get(0,y+1) elif y == 0: f1 = fy0.get(0,x+1) else: f1 = fyh.get(0,x+1) if s == 0: f2 = fx0.get(0,t+1) elif s == w: f2 = fxw.get(0,t+1) elif t == 0: f2 = fy0.get(0,s+1) else: f2 = fyh.get(0,s+1) if f1^f2: print("NO") return if x == 0: if s == 0: y,t = min(y,t),max(y,t) fx0.add(y,b) fx0.add(t+1,-b) elif s == w: fx0.add(0,b) fx0.add(y+1,-b) fy0.add(0,b) fxw.add(0,b) fxw.add(t+1,-b) elif t == 0: fx0.add(0,b) fx0.add(y+1,-b) fy0.add(0,b) fy0.add(s+1,-b) else: fx0.add(y,b) fyh.add(0,b) fyh.add(s+1,-b) elif x == w: if s == 0: fx0.add(0,b) fx0.add(t+1,-b) fy0.add(0,b) fxw.add(0,b) fxw.add(y+1,-b) elif s == w: y,t = min(y,t),max(y,t) fxw.add(y,b) fxw.add(t+1,-b) elif t == 0: fy0.add(s,b) fxw.add(0,b) fxw.add(y+1,-b) else: fxw.add(y,b) fyh.add(s,b) elif y == 0: if s == 0: fy0.add(0,b) fy0.add(x+1,-b) fx0.add(0,b) fx0.add(t+1,-b) elif s == w: fy0.add(x,b) fxw.add(0,b) fxw.add(t+1,-b) elif t == 0: x,s = min(x,s),max(x,s) fy0.add(x,b) fy0.add(s,-b) else: fy0.add(x,b) fxw.add(0,b) fyh.add(s,b) else: if s == 0: fx0.add(t,b) fyh.add(0,b) fyh.add(x+1,-b) elif s == w: fxw.add(t,b) fyh.add(x,b) elif t == 0: fyh.add(x,b) fxw.add(0,b) fy0.add(s,b) else: x,s = min(x,s),max(x,s) fyh.add(x,b) fyh.add(s,-b) print("YES") return #Solve if __name__ == "__main__": solve()
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): def check(x,y): return (x == 0)|(x == w)|(y == 0)|(y == h) w,h,n = LI() px0 = [] pxw = [] py0 = [] pyh = [] for i in range(1,n+1): x,y,s,t = LI() if check(x,y)&check(s,t): if x == 0: px0.append((y,i)) elif x == w: pxw.append((-y,i)) elif y == 0: py0.append((-x,i)) else: pyh.append((x,i)) if s == 0: px0.append((t,i)) elif s == w: pxw.append((-t,i)) elif t == 0: py0.append((-s,i)) else: pyh.append((s,i)) px0.sort() pxw.sort() py0.sort() pyh.sort() p = px0+pyh+pxw+py0 q = deque() for x, i in p: if q: qi = q.pop() if qi != i: q.append(qi) q.append(i) else: q.append(i) if q: print("NO") else: print("YES") return #Solve if __name__ == "__main__": solve()
p03685
from collections import deque def f(x, y): if x == 0: return y if y == 0: return -x if x == r: return -(x + y) if y == c: return x + y r, c, n = list(map(int, input().split())) xy = [] lxy = 0 for i in range(n): x1, y1, x2, y2 = list(map(int, input().split())) d = [] if min(x1, y1) == 0 or x1 == r or y1 == c: d.append([f(x1, y1), i]) if min(x2, y2) == 0 or x2 == r or y2 == c: d.append([f(x2, y2), i]) if len(d) == 2: xy.append(d[0]) xy.append(d[1]) lxy += 2 xy.sort() q = deque() for i in range(lxy): if not q: q.append(xy[i][1]) else: if q[-1] == xy[i][1]: q.pop() else: q.append(xy[i][1]) print(("YES" if not q else "NO"))
from collections import deque def f(x, y): if x == 0: return y if y == 0: return -x if x == r: return -(x + y) if y == c: return x + y r, c, n = list(map(int, input().split())) xy = [] lxy = 0 for i in range(n): x1, y1, x2, y2 = list(map(int, input().split())) d = [] if min(x1, y1) == 0 or x1 == r or y1 == c: d.append([f(x1, y1), i]) if min(x2, y2) == 0 or x2 == r or y2 == c: d.append([f(x2, y2), i]) if len(d) == 2: xy.append(d[0]) xy.append(d[1]) lxy += 2 xy.sort() q = deque() lq = -1 for i in range(lxy): if not q: q.append(xy[i][1]) lq += 1 else: if q[lq] == xy[i][1]: q.pop() lq -= 1 else: q.append(xy[i][1]) lq += 1 print(("YES" if not q else "NO"))
p03685
import sys input = sys.stdin.readline r, c, n = list(map(int, input().split())) L = [] def trans(x, y): z = None if x == 0: z = y if y == c: z = c + x if x == r: z = c + r + c - y if y == 0: z = 2*r + 2*c - x return z for _ in range(n): x1, y1, x2, y2 = list(map(int, input().split())) z1 = trans(x1, y1) z2 = trans(x2, y2) if z1 is not None and z2 is not None: if z1 > z2: z1, z2 = z2, z1 L.append((z1, z2)) L.append((z2, z1)) L.sort() cnt = 0 D = dict() for z1, z2 in L: if z1 < z2: cnt += 1 D[z1] = cnt else: if D[z2] != cnt: print("NO") exit() cnt -= 1 print("YES")
import sys input = sys.stdin.readline def main(): r, c, n = list(map(int, input().split())) L = [] def trans(x, y): z = None if x == 0: z = y if y == c: z = c + x if x == r: z = c + r + c - y if y == 0: z = 2*r + 2*c - x return z for _ in range(n): x1, y1, x2, y2 = list(map(int, input().split())) z1 = trans(x1, y1) z2 = trans(x2, y2) if z1 is not None and z2 is not None: L.append((z1, z2)) L.append((z2, z1)) L.sort() cnt = 0 D = dict() for z1, z2 in L: if z1 < z2: cnt += 1 D[z1] = cnt else: if D[z2] != cnt: print("NO") exit() cnt -= 1 print("YES") if __name__ == "__main__": main()
p03685
w, h, n = list(map(int, input().split())) vec = [] l = [] b = [] r = [] t = [] for i in range(n): x, y, x1, y1 = list(map(int, input().split())) if x == 0: l.append([x, y, i]) elif y == 0: t.append([x, y, i]) elif x == w: r.append([x, y, i]) elif y == h: b.append([x, y, i]) if x1 == 0: l.append([x1, y1, i]) elif y1 == 0: t.append([x1, y1, i]) elif x1 == w: r.append([x1, y1, i]) elif y1 == h: b.append([x1, y1, i]) sorted_node = ( sorted(l, key=lambda x: x[1]) + sorted(b, key=lambda x: x[0]) + sorted(r, key=lambda x: x[1], reverse=True) + sorted(t, key=lambda x: x[0], reverse=True) ) colors = list([x[2] for x in sorted_node]) colors = list([x for x in set(colors) if colors.count(x) % 2 == 0]) stack = [] for node in sorted_node: if node[2] in colors: if not stack or stack[-1] != node[2]: stack.append(node[2]) else: stack.pop() print(("NO" if stack else "YES"))
w, h, n = list(map(int, input().split())) vec = [] l = [] b = [] r = [] t = [] for i in range(n): x, y, x1, y1 = list(map(int, input().split())) c = [x, y, x1, y1] if( ((c[0] == 0 or c[0] == w) or (c[1] == 0 or c[1] == h)) and ((c[2] == 0 or c[2] == w) or (c[3] == 0 or c[3] == h)) ): if x == 0: l.append([x, y, i]) elif y == 0: t.append([x, y, i]) elif x == w: r.append([x, y, i]) elif y == h: b.append([x, y, i]) if x1 == 0: l.append([x1, y1, i]) elif y1 == 0: t.append([x1, y1, i]) elif x1 == w: r.append([x1, y1, i]) elif y1 == h: b.append([x1, y1, i]) sorted_node = ( sorted(l, key=lambda x: x[1]) + sorted(b, key=lambda x: x[0]) + sorted(r, key=lambda x: x[1], reverse=True) + sorted(t, key=lambda x: x[0], reverse=True) ) stack = [] for node in sorted_node: if not stack or stack[-1] != node[2]: stack.append(node[2]) else: stack.pop() print(("NO" if stack else "YES"))
p03685
import sys input = lambda: sys.stdin.readline().rstrip() R, C, N = list(map(int, input().split())) X = {0, R} Y = {0, C} Z = [] for i in range(N): x1, y1, x2, y2 = list(map(int, input().split())) if (x1 == 0 or x1 == R or y1 == 0 or y1 == C) and (x2 == 0 or x2 == R or y2 == 0 or y2 == C): Z.append((x1, y1, x2, y2)) X.add(x1) X.add(x2) Y.add(y1) Y.add(y2) DX = {a: i for i, a in enumerate(sorted(list(X)))} DY = {a: i for i, a in enumerate(sorted(list(Y)))} R, C = DX[R], DY[C] def calc(a, b): if b == 0: return a if a == R: return b + R if b == C: return R + C + (R - a) if a == 0: return R + C + R + (C - b) A = [] for i, (x1, y1, x2, y2) in enumerate(Z): x3, y3, x4, y4 = DX[x1], DY[y1], DX[x2], DY[y2] A.append((calc(x3, y3), i)) A.append((calc(x4, y4), i)) A = [l[1] for l in sorted(A, key = lambda x: x[0])] B = [] while A: while len(B) and A[-1] == B[-1]: A.pop() B.pop() if A: B.append(A.pop()) print(("NO" if len(B) else "YES"))
import sys input = lambda: sys.stdin.readline().rstrip() def calc(a, b): if b == 0: return a if a == R: return b + R if b == C: return R + C + (R - a) if a == 0: return R + C + R + (C - b) R, C, N = list(map(int, input().split())) A = [] for i in range(N): x1, y1, x2, y2 = list(map(int, input().split())) if (x1 == 0 or x1 == R or y1 == 0 or y1 == C) and (x2 == 0 or x2 == R or y2 == 0 or y2 == C): A.append((calc(x1, y1), i)) A.append((calc(x2, y2), i)) A = [l[1] for l in sorted(A, key = lambda x: x[0])] B = [] while A: while len(B) and A[-1] == B[-1]: A.pop() B.pop() if A: B.append(A.pop()) print(("NO" if len(B) else "YES"))
p03685
r,c,n = list(map(int,input().split())) a = [list(map(int, input().split())) for _ in range(n)] iru = [] for i in range(n): if ((a[i][0] == 0 or a[i][0] == r or a[i][1] == 0 or a[i][1] == c) and (a[i][2] == 0 or a[i][2] == r or a[i][3] == 0 or a[i][3] == c)): iru.append(a[i]) if len(iru) <= 1: print("YES") else: for i in range(len(iru)): b = iru[i] b1 = [b[0],b[1]] b2 = [b[2],b[3]] if b1[0] == 0: b1 = b1[1] elif b1[1] == c: b1 = b1[0] + b1[1] elif b1[0] == r: b1 = c*2 +r-1 -b1[1] else: b1 = c*2 + r*2 -2 - b1[0] if b2[0] == 0: b2 = b2[1] elif b2[1] == c: b2 = b2[0] + b2[1] elif b2[0] == r: b2 = c*2 +r-1 -b2[1] else: b2 = c*2 + r*2 -2 - b2[0] if b1 > b2: tmp = b1 +0 b1 = b2 +0 b2 = tmp + 0 for j in range(i+1,len(iru)): d = iru[j] d1 = [d[0],d[1]] d2 = [d[2],d[3]] if d2[0] == 0: d2 = d2[1] elif d2[1] == c: d2 = d2[0] + d2[1] elif d2[0] == r: d2 = c*2 +r-1 -d2[1] else: d2 = c*2 + r*2 -2 - d2[0] if d1[0] == 0: d1 = d1[1] elif d1[1] == c: d1 = d1[0] + d1[1] elif d1[0] == r: d1 = c*2 +r-1 -d1[1] else: d1 = c*2 + r*2 -2 - d1[0] if d1 > d2: tmp = d1 +0 d1 = d2 +0 d2 = tmp + 0 if (b1 <= d1 and d1 <= b2 and b2 <= d2): print("NO") exit() elif (d1 <= b1 and b1 <= d2 and d2 <= b2): print("NO") exit() print("YES")
r,c,n = list(map(int,input().split())) a = [list(map(int, input().split())) for _ in range(n)] iru = [] for i in range(n): if ((a[i][0] == 0 or a[i][0] == r or a[i][1] == 0 or a[i][1] == c) and (a[i][2] == 0 or a[i][2] == r or a[i][3] == 0 or a[i][3] == c)): b = a[i] b1 = [b[0],b[1]] b2 = [b[2],b[3]] if b1[0] == 0: b1 = b1[1] elif b1[1] == c: b1 = b1[0] + b1[1] elif b1[0] == r: b1 = c +r+c -b1[1] else: b1 = c*2 + r*2 - b1[0] if b2[0] == 0: b2 = b2[1] elif b2[1] == c: b2 = b2[0] + b2[1] elif b2[0] == r: b2 = c*2 +r -b2[1] else: b2 = c*2 + r*2 - b2[0] if b1 > b2: tmp = b1 +0 b1 = b2 +0 b2 = tmp + 0 iru.append([b1,b2]) iru = sorted(iru) ato = 0 stack = [r+r+c+c] flag = 'YES' for a,b in iru: while a >= stack[-1]: stack.pop() if b > stack[-1]: flag = 'NO' break else: stack.append(b) print(flag)
p03685
def mx(mtrx): maxSum = -1000000 for colStart in range(n): partSum = [0]*n for colEnd in range(colStart,n): for row in range(n): partSum[row] += mtrx[row][colEnd] maxSum = max(maxPart(partSum), maxSum) return maxSum def maxPart(array): maxSum = -1000000 calcSum = 0 for i in range(n): calcSum += array[i] maxSum = max(calcSum,maxSum) if calcSum < 0: calcSum = 0 return maxSum n = int(input()) print(mx([list(map(int, input().split())) for i in range(n)]))
def x(a): m=-10**9 for c in N: p=[0]*n for e in range(c,n): for r in N: p[r]+=a[r][e] m=max(P(p),m) return m def P(a): m,c=-100000,0 for i in N: c+=a[i] m=max(c,m) if c<0:c=0 return m n = eval(input()) N = list(range(n)) print(x([list(map(int, input().split())) for i in N]))
p00098
from itertools import combinations_with_replacement n = eval(input()) sq = [list(map(int,input().split())) for u in range(n)] s_sq =[[0]*(n+1) for u in range(n+1)] ma = sq[0][0] for i in range(n): for ii in range(n): s_sq[i][ii] = sq[i][ii] + s_sq[i][ii-1] + s_sq[i-1][ii] - s_sq[i-1][ii-1] for tx,bx in combinations_with_replacement(list(range(n)),2): for ty,by in combinations_with_replacement(list(range(n)),2): #print "tx,ty=",tx,ty,"bx,by=",bx,by ma = max([ma,s_sq[by][bx]-s_sq[ty-1][bx]-s_sq[by][tx-1]+s_sq[ty-1][tx-1]]) print(ma)
n = eval(input()) sq = [list(map(int,input().split())) for u in range(n)] s_sq = [[[0]*n for u in range(n)] for uu in range(n)] #s_sq[lower_end][left_end][right_end] ma = -1000 * 100 * 100 for y in range(n): temp = [0] * (n+1) for x in range(n): #make sum of the sequence left_end == 0, right_end == n temp[x] = temp[x-1] + sq[y][x] for tx in range(n): for ex in range(tx,n): s_sq[y][tx][ex] = max([0,s_sq[y-1][tx][ex]]) + temp[ex] - temp[tx-1] ma = max([ma,s_sq[y][tx][ex]]) print(ma)
p00098
n=int(input()) N=list(range(n)) N1=N+[n] A=[[0]*(n+1)]+[[0]+list(map(int,input().split())) for i in N] B=[[0 for j in N1] for i in N1] N1=N1[1:] for i in N1: x=A[i] if i==0: y=[0]*n else: y=B[i-1][:] s=0 for j in N1: s+=x[j] y[j]+=s B[i]=y m=-1e6 for i1 in N1: for j1 in N1: for i2 in range(i1,n+1): for j2 in range(j1,n+1): m=max(m,B[i1-1][j1-1]+B[i2][j2]-B[i1-1][j2]-B[i2][j1-1]) print(m)
def f(i,j): B=[0]*n m=[] for x in range(i,n): a=0 for y in range(j,n): a+=A[y][x] B[y]+=a m.append(max(B[j:])) return max(m) n=int(input()) N=list(range(n)) A=[list(map(int,input().split())) for i in N] print(max([max([f(i,j) for i in N]) for j in N]))
p00098
def g(j,i): a=B[j-1][i-1] b1=B[j-1] m=[] for y in range(j,n+1): b=B[y] m.append(max([b[x]+a-b[i-1]-b1[x] for x in range(i,n+1)])) return max(m) n=int(input()) N=list(range(n)) B=[[0]*(n+1) for _ in range(n+1)] for j in N: A=list(map(int,input().split())) s=0 b=B[j] for i in N: s+=A[i] B[j+1][i+1]=b[i+1]+s N=N[1:]+[n] m=[max([g(j,i) for i in N]) for j in N] print(max(m))
m=-1e9 n=int(input()) B=[[0]*(n+1) for _ in range(n+1)] for _ in range(n): A=list(map(int,input().split())) for j in range(n): s=0 for k in range(j,n): s+=A[k] B[j][k]=max(B[j][k],0)+s m=max(B[j][k],m) print(m)
p00098
m=-1e9 n=int(input()) N=list(range(n)) B=[[0]*(n+1) for _ in range(n+1)] for _ in N: A=list(map(int,input().split())) for j in N: s=0 for k in N[j:]: s+=A[k] B[j][k]=max(B[j][k],0)+s m=max(B[j][k],m) print(m)
m=-1e9 n=int(input()) N=list(range(n)) B=[[0]*(n+1) for _ in range(n+1)] for _ in N: A=list(map(int,input().split())) for j in N: s=0 b=B[j] for k in N[j:]: s+=A[k] b[k]=max(b[k],0)+s m=max(b[k],m) print(m)
p00098
while True: N, M, s, g1, g2 = list(map(int, input().split())) if N == M == s == g1 == g2 == 0: break s, g1, g2 = s - 1, g1 - 1, g2 - 1 INF = 10 ** 5 D = [[INF] * N for _ in range(N)] for i in range(N): D[i][i] = 0 for _ in range(M): b1, b2, c = list(map(int, input().split())) b1, b2 = b1 - 1, b2 - 1 D[b1][b2] = c for k in range(N): for i in range(N): for j in range(N): D[i][j] = min(D[i][j], D[i][k] + D[k][j]) print((min(D[s][i] + D[i][g1] + D[i][g2] for i in range(N))))
while True: N, M, s, g1, g2 = list(map(int, input().split())) if N == M == s == g1 == g2 == 0: break s, g1, g2 = s - 1, g1 - 1, g2 - 1 INF = 10 ** 5 D = [[INF] * N for _ in range(N)] for i in range(N): D[i][i] = 0 for _ in range(M): b1, b2, c = list(map(int, input().split())) b1, b2 = b1 - 1, b2 - 1 D[b1][b2] = c for k in range(N): for i in range(N): for j in range(N): if D[i][j] > D[i][k] + D[k][j]: D[i][j] = D[i][k] + D[k][j] print((min(D[s][i] + D[i][g1] + D[i][g2] for i in range(N))))
p01130
r,g,b = input().split() rgb = r+g+b print(('YES' if int(rgb)%4==0 else 'NO'))
r,g,b=list(map(str,input().split())) print(('YES' if int(r+g+b)%4==0 else 'NO'))
p03693
r, g, b = list(map(int,input().split())) total = r*100 + g*10 + b if total % 4 == 0: print('YES') else: print('NO')
r,g,b = list(map(int,input().split())) if (100*r + 10*g + b)%4 == 0: print('YES') else: print('NO')
p03693
print(('YNEOS'[int(input().replace(' ',''))%4>0::2]))
print(('YNEOS'[int(input()[::2])%4>0::2]))
p03693
r,g,b = list(map(int,input().split())) if (r*100+g*10+b)%4 == 0: print("YES") else: print("NO")
r,g,b = input().split() l = int(r+g+b) print(("YES" if l%4 == 0 else "NO"))
p03693
a,b,c=list(map(int,input().split(' '))) d=(b*10+c)%4 if d==0: print('YES') else: print('NO')
# Problem https://atcoder.jp/contests/abc064/tasks/abc064_a # Python 1st Try rgbs = list(map(int,input().split(' '))) g = rgbs[1] b = rgbs[2] answer ='' checkgb=((g*10+b)%4) if checkgb == 0: answer = "YES" else: answer = "NO" print(answer)
p03693
import sys input = sys.stdin.readline rgb = int(''.join(input().split())) if rgb % 4 == 0: print("YES") else: print("NO")
import sys r, g, b = sys.stdin.readline().split() def main(): return 'NO' if int(g + b) % 4 else 'YES' if __name__ == '__main__': ans = main() print(ans)
p03693
a,b,c =list(map(int,input().split())) if (a*100+b*10+c)%4==0: print("YES") else: print("NO")
r,g,b =list(map(int,input().split())) C=r*100+g*10+b if C%4==0: print("YES") else: print("NO")
p03693
a, b, c = list(map(int, input().split())) A = 100*a + 10*b + c if A % 4 == 0: print('YES') else: print('NO')
r, g, b = list(map(int, input().split())) rgb = 100*r+10*g+b print(('YES' if rgb % 4 == 0 else 'NO'))
p03693
r, g ,b = (i for i in input().split()) num = int(r+g+b) print(("YES" if num%4 == 0 else "NO"))
def main(): A = [i for i in input().split()] S = "".join(A) N = int(S) print(("YES" if N % 4 == 0 else "NO")) if __name__ == '__main__': main()
p03693
r,g,b=list(map(int, input().split())) a = 100*r + 10*g + b if a%4 ==0: print('YES') else: print('NO')
r,g,b= list(map(int, input().split())) a = r*100+g*10+b print(('YES' if a %4==0 else 'NO'))
p03693
#!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def LI_(): return list([int(x)-1 for x in input().split()]) def II(): return int(eval(input())) def IF(): return float(eval(input())) def LS(): return list(map(list, input().split())) def S(): return list(input().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float('INF') #A def A(): n, m, R = LI() r = LI_() edg = [[inf] * n for i in range(n)] for _ in range(m): a, b, c = LI_() c += 1 edg[a][b] = c edg[b][a] = c for i in range(n): edg[i][i] = 0 for k in range(n): for i in range(n): for j in range(n): edg[i][j] = min(edg[i][j], edg[i][k] + edg[k][j]) fulls = itertools.permutations(list(range(R)), R) ans = inf for full in fulls: b = -1 tmp = 0 for f in full: if b == -1: b = r[f] continue tmp += edg[r[f]][b] b = r[f] ans = min(ans, tmp) print(ans) return #B def B(): n, m = LI() time = [[inf] * n for i in range(n)] for _ in range(m): a, b, t = LI_() t += 1 time[a][b] = t time[b][a] = t for i in range(n): time[i][i] = 0 for k in range(n): for i in range(n): for j in range(n): time[i][j] = min(time[i][j], time[i][k] + time[k][j]) for k in range(n): for i in range(n): if time[i][k] == inf: time[i][k] = 0 ans = inf for i in range(n): ans = min(ans, max(time[i])) print(ans) return #C def C(): h, w, t = LI() s = SR(h) for i in range(h): for k in range(w): if s[i][k] == "S": start = (i, k) if s[i][k] == "G": goal = (i, k) def f(X): dist = [[inf] * w for i in range(h)] dist[start[0]][start[1]] = 0 q = [[0, start]] while q: # print(q,1) time, a = heappop(q) y, x = a for yi, xi in [[0, -1], [0, 1], [1, 0], [-1, 0]]: yi += y xi += x # print(yi,xi) if 0 <= yi < h and 0 <= xi < w: if s[yi][xi] == "#": if dist[yi][xi] > time + X: heappush(q, [time + X, [yi, xi]]) dist[yi][xi] = time + X else: if dist[yi][xi] > time + 1: heappush(q, [time + 1, [yi, xi]]) dist[yi][xi] = time + 1 # print(dist) return dist[goal[0]][goal[1]] ok = 1 ng = t + 1 # print(goal) while abs(ok - ng) > 1: mid = (ng + ok) // 2 if f(mid) <= t: ok = mid else: ng = mid # print(mid) print(ok) return #D def D(): n = II() a, b = LI_() m = II() xy = [[] for i in range(n)] for _ in range(m): x, y = LI_() xy[x].append(y) xy[y].append(x) d = [inf] * n d[a] = 0 q = [[0, a]] while q: dist, now = heappop(q) for i in xy[now]: if d[i] > dist + 1: heappush(q, (dist + 1, i)) d[i] = dist + 1 ans = 1 q = [b] while q: qi = q[::1] q = [] tmp = 0 while qi: x = qi.pop() score = d[x] for xi in xy[x]: if d[xi] + 1 == score and not xi in q: q.append(xi) # print(tmp) tmp += 1 # print(tmp) ans *= tmp ans %= mod q = list(set(q)) # print(q) if q[0] == a: break print(ans) return #E def E(): x = S() f = True while f and x: f = False if len(x) >= 2: if x[-1] == "h" and x[-2] == "c": x = x[:-2] f = True continue if x[-1] == "o": x = x[:-1] f = True elif x[-1] == "k": x = x[:-1] f = True elif x[-1] == "u": x = x[:-1] f = True # print(x) if f: print("YES") else: print("NO") return #F def F(): s = S() n = II() for i in range(n): l, r = LI_() s[l: r + 1] = s[l: r + 1][::-1] print(("".join(s))) return #G def G(): s = S() ans = [] i = 0 while i < len(s): ans.append(s[i]) tmp = 0 x = s[i] while i != len(s): if x == s[i]: tmp += 1 i += 1 continue break ans.append(str(tmp)) print(("".join(ans))) return #H def H(): r, g, b = LI() if g & 1 and b % 4 == 2: print("YES") return if not (g & 1) and b % 4 == 0: print("YES") return print("NO") return #Solve if __name__ == '__main__': H()
print((["YES","NO"][int("".join(input().split()))%4!=0]))
p03693
S_list = list(map(int,input().split())) r, g, b = S_list[0], S_list[1], S_list[2] if (100 * r + 10 * g + b) % 4 == 0 : result = "YES" else: result = "NO" print(result)
S_list = list(map(int,input().split())) r, g, b = S_list[0], S_list[1], S_list[2] if (10 * g + b) % 4 == 0 : result = "YES" else: result = "NO" print(result)
p03693
from sys import stderr, setrecursionlimit from functools import reduce from operator import add setrecursionlimit(2147483647) def f(n=1): if n == 1: return [int(i) for i in input().split()] res = [] for i in range(n): res.append([int(j) for j in input().split()]) return res def debug(*x, sep=" ", end="\n"): for item in x: stderr.write(str(item)) stderr.write(sep) stderr.write(end) rgb = int("".join(input().split())) print(("NO" if rgb%4 else "YES"))
print((["NO","YES"][int("".join(input().split()))%4==0]))
p03693
# # abc064 a # import sys from io import StringIO import unittest def input(): return sys.stdin.readline().rstrip() class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """4 3 2""" output = """YES""" self.assertIO(input, output) def test_入力例_2(self): input = """2 3 4""" output = """NO""" self.assertIO(input, output) def resolve(): r, g, b = list(map(int, input().split())) x = 100*r + 10*g + b ans = "NO" if x % 4 == 0: ans = "YES" print(ans) if __name__ == "__main__": # unittest.main() resolve()
# # abc064 a # import sys from io import StringIO import unittest def input(): return sys.stdin.readline().rstrip() class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """4 3 2""" output = """YES""" self.assertIO(input, output) def test_入力例_2(self): input = """2 3 4""" output = """NO""" self.assertIO(input, output) def resolve(): r, g, b = list(map(int, input().split())) if (100*r + 10*g + b) % 4 == 0: print("YES") else: print("NO") if __name__ == "__main__": # unittest.main() resolve()
p03693
a = int(input().replace(" ","")) if a % 4 == 0: print("YES") else: print("NO")
a,b,c=input().split() x=a x+=b x+=c if int(x)%4==0: print('YES') else: print('NO')
p03693
r, g, b = input().split() num = int(r + g + b) print(("YES" if num%4==0 else 'NO'))
r,g,b = input().split() print(('YES' if int(r+g+b)%4==0 else 'NO'))
p03693
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): r,g,b = LI() s = r*100+g*10+b if s%4 == 0: print("YES") else: print("NO") return #Solve if __name__ == "__main__": solve()
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): r,g,b = LI() ans = ["YES","NO"] print((ans[((g<<1)+b)&3>0])) return #Solve if __name__ == "__main__": solve()
p03693
r, g, b = list(map(int, input().split())) print(('YES' if (10 * g + b) % 4 == 0 else 'NO'))
r, g, b = list(map(int, input().split())) number = 100 * r + 10 * g + b if number % 4 == 0: print('YES') else: print('NO')
p03693
r, g, b = input().split() string = r + g + b num = int(string) if num % 4 == 0: print("YES") else: print("NO")
r, g, b = input().split() if int(r + g + b) % 4 == 0: print("YES") else: print("NO")
p03693
r, g, b = list(map(int, input().split())) if (10 * g + b) % 4 == 0: print("YES") else: print("NO")
r, g, b = list(map(int, input().split())) print(("YES" if (10 * g + b) % 4 == 0 else "NO"))
p03693
r, g, b = list(map(int, input().split())) print(("YES" if (10 * g + b) % 4 == 0 else "NO"))
r, g, b = list(map(int, input().split(' '))) print(('YES' if (10 * g + b) % 4 == 0 else'NO'))
p03693
r,g,b=list(map(int,input().split())) result = (r*100+g*10+b)%4 if result==0: print('YES') else: print('NO')
r,g,b=list(map(int,input().split())) print(('YES' if (r*100+g*10+b)%4 == 0 else 'NO'))
p03693
r, g, b = input().split() x = int(r + g + b) if(x%4 == 0): print("YES") else: print("NO")
r, g, b = input().split() rgb = int(r + g + b) if(rgb%4 == 0): print('YES') else: print('NO')
p03693
r, g, b = list(map(int, input().split(" "))) n = r * 100 + g * 10 + b if n % 4 == 0: print("YES") else: print("NO")
n = int("".join(input().split())) if n % 4 == 0: print("YES") else: print("NO")
p03693
a,b,c=list(map(int,input().split())) print('YES') if (100*a+10*b+c)%4==0 else print('NO')
a,b,c=map(int,input().split()) print('YES') if (10*b+c)%4==0 else print('NO')
p03693
#ABC064 A - RGB Cards si = lambda: eval(input()) ni = lambda: int(eval(input())) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) r,g,b = list(map(str, input().split())) s = r+g+b if int(s)%4==0: print('YES') else: print('NO')
r,g,b=list(map(str,input().split())) ans=r+g+b s=int(ans) if s%4==0: print('YES') else: print('NO')
p03693
print(("YES" if int(input().replace(" ", "")) % 4 == 0 else "NO"))
print(("NO" if int("".join(input().split())) % 4 else "YES"))
p03693
r, g, b = list(map(int, input().split())) n = r*100 + g*10 + b if n%4 == 0: print("YES") else: print("NO")
n = "".join(input().split()) if int(n)%4 == 0: print("YES") else: print("NO")
p03693