input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, M = list(map(int, readline().split())) S = list(map(int, readline().split())) T = list(map(int, readline().split())) ...
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, M = list(map(int, readline().split())) S = list(map(int, readline().split())) T = list(map(int, readline().split())) ...
p03003
n,m = list(map(int, input().split())) s = list(map(int, input().split())) t = list(map(int, input().split())) PR = 1000000007 dp = [[0 for j in range(m+1)] for i in range(n+1)] for i in range(n+1): dp[i][0] = 1 for j in range(m+1): dp[0][j] = 1 for i in range(n): for j in range(m): #aa sumI ...
n,m = list(map(int, input().split())) s = list(map(int, input().split())) t = list(map(int, input().split())) PR = 1000000007 dp = [[0 for j in range(m+1)] for i in range(n+1)] for i in range(n+1): dp[i][0] = 1 for j in range(m+1): dp[0][j] = 1 for i in range(n): for j in range(m): #aa sumI ...
p03003
class BIT(): __slots__ = ["func", "e", "n", "data"] def __init__(self, length_or_list, func, e): self.func = func self.e = e if isinstance(length_or_list, int): self.n = length_or_list + 1 self.data = [self.e] * self.n else: self.n...
class BIT(): __slots__ = ["n", "data"] def __init__(self, length_or_list): if isinstance(length_or_list, int): self.n = length_or_list + 1 self.data = [0] * self.n else: self.n = len(length_or_list) + 1 self.data = [0] + length_or_list ...
p02559
class BIT(): __slots__ = ["n", "data"] def __init__(self, length_or_list): if isinstance(length_or_list, int): self.n = length_or_list + 1 self.data = [0] * self.n else: self.n = len(length_or_list) + 1 self.data = [0] + length_or_list ...
class BIT(): __slots__ = ["n", "data"] def __init__(self, length_or_list): if isinstance(length_or_list, int): self.n = length_or_list + 1 self.data = [0] * self.n else: self.n = len(length_or_list) + 1 self.data = [0] + length_or_list ...
p02559
class FenwickTree(): def __init__(self, n): self.n = n self.data = [0] * n def add(self, p, x): #assert 0 <= p < self.n p += 1 while p <= self.n: self.data[p - 1] += x p += p & -p def sum(self, r): s = 0 while r:...
class FenwickTree(): def __init__(self, n): self.n = n self.data = [0] * n def add(self, p, x): #assert 0 <= p < self.n p += 1 while p <= self.n: self.data[p - 1] += x p += p & -p def sum(self, r): s = 0 while r:...
p02559
class FenwickTree(): def __init__(self, n): self.n = n self.data = [0] * n def add(self, p, x): #assert 0 <= p < self.n p += 1 while p <= self.n: self.data[p - 1] += x p += p & -p def sum(self, r): s = 0 while r:...
class FenwickTree(): def __init__(self, n): self.n = n self.data = [0] * n def build(self, arr): #assert len(arr) <= n for i, a in enumerate(arr): self.data[i] = a for i in range(1, self.n + 1): if i + (i & -i) <= self.n: ...
p02559
import sys input = lambda: sys.stdin.readline().rstrip() class BIT: def __init__(self, n): self.bit = [0] * n def add(self, i, x): i += 1 while i <= len(self.bit): self.bit[i-1] += x i += i & -i def sum_sub(self, i): a = 0 i += 1 while i: a += self.bit...
import sys input = sys.stdin.readline class BIT(): def __init__(self, n, data=None): self.n = n self.bit = [0] * (self.n + 1) self.data = [0] * (self.n + 1) if data: self.build(data) def build(self, data): for i in range(self.n): s...
p02559
import sys input = sys.stdin.readline class BIT(): def __init__(self, n, data=None): self.n = n self.bit = [0] * (self.n + 1) self.data = [0] * (self.n + 1) if data: self.build(data) def build(self, data): for i in range(self.n): s...
from sys import stdin nii=lambda:list(map(int,stdin.readline().split())) lnii=lambda:list(map(int,stdin.readline().split())) class BIT(): def __init__(self, n, data=None): self.n = n self.bit = [0] * (self.n + 1) self.data = [0] * (self.n + 1) if data: self.bui...
p02559
#!/usr/bin python3 # -*- coding: utf-8 -*- # Binary Indexed Tree # 1-indexed # sum(r) :閉区間 [0,r] の合計を取得する # [8] a0 ・ a1 ・ a2 ・ a3 ・ a4 ・ a5 ・ a6 ・ a7 # [4] a0 ・ a1 ・ a2 ・ a3 # [2] a0 ・ a1 [6] a4 ・ a5 # [1] a0 [3] a2 [5] a4 [7] a6 # [1000] # ...
#!/usr/bin python3 # -*- coding: utf-8 -*- # Binary Indexed Tree # 1-indexed # sum(r) :閉区間 [0,r] の合計を取得する # [8] a0 ・ a1 ・ a2 ・ a3 ・ a4 ・ a5 ・ a6 ・ a7 # [4] a0 ・ a1 ・ a2 ・ a3 # [2] a0 ・ a1 [6] a4 ・ a5 # [1] a0 [3] a2 [5] a4 [7] a6 # [1000] # ...
p02559
n, q = list(map(int, input().split())) lst = [int(i) for i in input().split()] sum_list = [0] total = 0 for i in range(n): total += lst[i] sum_list.append(total) for _ in range(q): t, a, b = list(map(int, input().split())) if t == 0: for i in range(a + 1, n + 1): sum_list[i] += b else: ...
class bit: def __init__(self, n): self.size = n self.bit = [0] * (n + 1) def make(self, lst): self.bit = [0] + lst[:] for i in range(1, self.size + 1): if i + (i & -i) > self.size: continue self.bit[i + (i & -i)] += self.bit[i] def add(self, a, b): i = a ...
p02559
class BIT: def __init__(self, n): self.n = n self.data = [0] * n def sum(self, i): s = 0 while i > 0: s += self.data[i - 1] i &= i - 1 return s def update(self, i, x): while i < self.n: self.data[i] += x ...
import sys input = lambda: sys.stdin.readline() class BIT: def __init__(self, n): self.n = n self.data = [0] * n def sum(self, i): s = 0 while i > 0: s += self.data[i - 1] i &= i - 1 return s def update(self, i, x): w...
p02559
import sys input = lambda: sys.stdin.readline() class BIT: def __init__(self, n): self.n = n self.data = [0] * n def sum(self, i): s = 0 while i > 0: s += self.data[i - 1] i &= i - 1 return s def update(self, i, x): w...
import sys input = lambda: sys.stdin.readline() class BIT: def __init__(self, n): self.n = n self.data = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s def add(self, i, x): ...
p02559
import sys input = sys.stdin.readline class segtree: x_unit=0 # 単位元 x_func=sum # 関数 def __init__(self,n,seq): self.n=n self.x=[self.x_unit]*(2*n) for i,j in enumerate(seq, self.n): # n番目からseqをx配列に移していく self.x[i] = j for i in range(self.n-1, 0, -1): ...
import sys input = sys.stdin.readline class segtree: x_unit=0 # 単位元 x_func=lambda self,a:a[0]+a[1] # 関数 def __init__(self,n,seq): self.n=n self.x=[self.x_unit]*(2*n) for i,j in enumerate(seq, self.n): # n番目からseqをx配列に移していく self.x[i] = j for i in range...
p02559
import sys input=sys.stdin.readline n,q=list(map(int,input().split())) BIT=[0]*n def ADD(x,y):#A[x]+=y,1-origin while x<=n: BIT[x-1]+=y x+=x&(-x) def SUM(l):#1からlまでの和 if l==0: return 0 ret=0 while l>=1: ret+=BIT[l-1] l-=l&(-l) return ret IN=list(map(int,input().split())) for i in ran...
import sys input=sys.stdin.readline n,q=list(map(int,input().split())) BIT=[0]*n def ADD(x,y):#A[x]+=y,1-origin while x<=n: BIT[x-1]+=y x+=x&(-x) def SUM(l):#1からlまでの和 ret=0 while l>=1: ret+=BIT[l-1] l-=l&(-l) return ret IN=list(map(int,input().split())) for i in range(n): ADD(i+1,IN[i])...
p02559
class BIT: def __init__(self, n): self.size = n self.tree = [0]*(n+1) def sum(self, i): # [0, i) の要素の総和を返す s = 0 while i>0: s += self.tree[i] i -= i & -i return s # 0 index を 1 index に変更 転倒数を求めるなら1を足していく def add(self...
class BIT: def __init__(self, n): self.size = n self.tree = [0]*(n+1) def make(self, list): self.tree[1:] = list.copy() for i in range(self.size+1): j = i + (i & (-i)) if j < self.size+1: self.tree[j] += self.tree[i] ...
p02559
class BIT: def __init__(self, n): self.size = n self.tree = [0]*(n+1) def make(self, list): self.tree[1:] = list.copy() for i in range(self.size+1): j = i + (i & (-i)) if j < self.size+1: self.tree[j] += self.tree[i] ...
import sys input = sys.stdin.readline class BIT: def __init__(self, n): self.size = n self.tree = [0]*(n+1) def make(self, list): self.tree[1:] = list.copy() for i in range(self.size+1): j = i + (i & (-i)) if j < self.size+1: ...
p02559
ma = lambda :map(int,input().split()) lma = lambda :list(map(int,input().split())) tma = lambda :tuple(map(int,input().split())) ni = lambda:int(input()) yn = lambda fl:print("Yes") if fl else print("No") ips = lambda:input().split() import collections import math import itertools import heapq as hq class F...
ma = lambda :map(int,input().split()) lma = lambda :list(map(int,input().split())) tma = lambda :tuple(map(int,input().split())) ni = lambda:int(input()) yn = lambda fl:print("Yes") if fl else print("No") ips = lambda:input().split() import collections import math import itertools import heapq as hq import sy...
p02559
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools import math, fractions import sys, copy def L(): return sys.stdin.readline...
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools import math, fractions import sys, copy def L(): return sys.stdin.readline...
p02559
class fenwick_tree(): def __init__(self, n:int, mod:int = 0): self.__mod = mod self.__n = n self.__data = [0] * self.__n def add(self, p:int, x:int): assert (0 <= p) & (p < self.__n) if(self.__mod == 0): self.__add_mod0(p,x) else: ...
class fenwick_tree(): def __init__(self, n:int): self.__n = n self.__data = [0] * self.__n def add(self, p:int, x:int): assert (0 <= p) & (p < self.__n) p+=1 while( p<= self.__n): self.__data[p-1] += x p += p & -p def sum(self, l:...
p02559
n,q=list(map(int, input().split())) *a,=list(map(int, input().split())) bit=[0]*(2*n+1) def add(t,x): while t<=n: bit[t]+=x t+=t&(-t) def que(t): res=0 while t: res+=bit[t] t-=t&(-t) return res for i in range(n): add(i+1,a[i]) for _ in range(q...
import sys input=sys.stdin.readline n,q=list(map(int, input().split())) *a,=list(map(int, input().split())) bit=[0]*(n+1) def add(t,x): while t<=n: bit[t]+=x t+=t&(-t) def que(t): res=0 while t: res+=bit[t] t-=t&(-t) return res for i in range(n): ...
p02559
import sys class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def build(self, arr): #assert len(arr) <= n for i, a in enumerate(arr): self.add(i+1, a) def sum(self, i): s = 0 while i > 0: s += ...
import sys class Bit: def __init__(self, n, arr): self.size = n self.tree = [0] + arr for i in range(1, n+1): if i + (i & -i) < n + 1: self.tree[i + (i & -i)] += self.tree[i] def sum(self, i): s = 0 while i > 0: s +...
p02559
""" n,q = map(int,input().split()) a = list(map(int,input().split())) def segfunc(x,y): return x + y def init(init_val): #set_val for i in range(n): seg[i+num-1]=init_val[i] #built for i in range(num-2,-1,-1) : seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) def update(k,x): ...
class Bit: def __init__(self, n): """ :param n: 最大の要素数 """ self.n = n self.tree = [0]*(n+1) self.depth = n.bit_length() - 1 def sum(self, i): """ 区間[0,i) の総和を求める """ s = 0 i -= 1 while i >= 0: s += self.tr...
p02559
def segfunc(x,y):return x+y ide_ele=0 class segtree(): def __init__(self,init_val,segfunc=segfunc,ide_ele=ide_ele): n=len(init_val) self.segfunc=segfunc self.ide_ele=ide_ele self.num=1<<(n-1).bit_length() self.tree=[ide_ele]*2*self.num for i in range(n): self.tree[self.num+i]=i...
class binaryindexedtree(): def __init__(self,n): self.n=n self.tree=[0]*n def add(self,a,w): x=a while x<=self.n: self.tree[x-1]+=w x+=x&(-x) def sums(self,a): x=a S=0 while x!=0: S+=self.tree[x-1] x-=x&(-x) return S n,q=map(int,input().split...
p02559
class BIT(): __slots__ = ["n", "data"] def __init__(self, li): self.n = len(li) + 1 self.data = [0] + li for i in range(1, self.n): if i + (i & -i) < self.n: self.data[i + (i & -i)] += self.data[i] def add(self, i, a): i += 1 ...
class BIT(): __slots__ = ["n", "data"] def __init__(self, li): self.n = len(li) + 1 self.data = [0] + li for i in range(1, self.n): if i + (i & -i) < self.n: self.data[i + (i & -i)] += self.data[i] def add(self, i, a): i += 1 ...
p02559
class Binary_Indexed_Tree_Exception(Exception): pass class Binary_Indexed_Tree(): def __init__(self,N,L=[]): """calcを演算とするN項のBinary Indexed Treeを作成 N:要素数 """ self.calc=lambda x,y:x+y self.unit=0 N=max(N,len(L)) k=1 d=1 ...
class Binary_Indexed_Tree_Exception(Exception): pass class Binary_Indexed_Tree(): def __init__(self,L,calc,unit,inv): """calcを演算とするN項のBinary Indexed Treeを作成 calc:演算(2変数関数,群) unit:群calcの単位元(xe=ex=xを満たすe) inv:群calcの逆元(1変数関数) """ self.calc=calc ...
p02559
from copy import * import sys S=sys.stdin.readlines() def init(N,node,unit,func): n=1 while n<N: n<<=1 for i in range(n*2-1): if len(node)<=i: node.append(deepcopy(unit)) else: node[i]=deepcopy(unit) node.append(func) node.append(unit) node.append(n) def upd(node,x...
import sys S=sys.stdin.readlines() def Binit(B,siz): while len(B)<siz+1: B.append(0) while len(B)>siz+1: del B[-1] for i in range(siz+1): B[i]=0 B.append(siz) def Badd(B,a,x): z=a while z<=B[-1]: B[z]+=x z+=(z&(-z)) def Bsum(B,a): r=0 z=a while z>0: r+=B[...
p02559
import sys class Fenwick_Tree: def __init__(self, n): self._n = n self.data = [0] * n def add(self, p, x): assert 0 <= p < self._n p += 1 while p <= self._n: self.data[p - 1] += x p += p & -p def sum(self, l, r): ...
import sys class Fenwick_Tree: def __init__(self, n): self._n = n self.data = [0] * n def add(self, p, x): assert 0 <= p < self._n p += 1 while p <= self._n: self.data[p - 1] += x p += p & -p def sum(self, l, r): ...
p02559
class SegmentTree: ele = 0 def func(self, a, b): return a + b # SEG木は1-index # Aに関しては0-index def __init__(self, n): # Aは0-idx self.n = n self.num = 2 ** ((self.n - 1).bit_length()) self.SEG = [self.ele] * (2 * self.num) def search(self, idx): ...
import sys input = sys.stdin.buffer.readline class SegmentTree: ele = 0 def func(self, a, b): return a + b # SEG木は1-index # Aに関しては0-index def __init__(self, n): # Aは0-idx self.n = n self.num = 2 ** ((self.n - 1).bit_length()) self.SEG = [self.e...
p02559
import sys def input(): return sys.stdin.readline().strip() def resolve(): n=int(eval(input())) l=list(map(int,input().split())) c1=0 c2=0 c4=0 for i in l: if i%2==1: c1+=1 else: if i%4==0: c4+=1 else: ...
import sys def input(): return sys.stdin.readline().strip() def resolve(): n=int(eval(input())) l=list(map(int,input().split())) cnt1=0 cnt2=0 cnt4=0 for i in l: if i%2==1: cnt1+=1 elif i%4==0: cnt4+=1 else: cnt2+=1 ...
p03639
# def makelist(n, m): # return [[0 for i in range(m)] for j in range(n)] # n = int(input()) # a, b = map(int, input().split()) # s = input() yes = "Yes" no = "No" N = int(eval(input())) a = list(map(int, input().split())) four = 0 two = 0 none = 0 for e in a: if e % 4 == 0: four += 1 eli...
N = int(eval(input())) four = 0 two = 0 one = 0 for e in map(int, input().split()): if e % 4 == 0: four += 1 elif e % 2 != 0: one += 1 else: two += 1 if four >= one: print("Yes") else: if two == 0 and four == one - 1: print("Yes") else: pr...
p03639
import itertools N= int(eval(input())) A_list = list(map(int,input().split())) ans = '' for v in itertools.permutations(A_list): counter = 0 for i in range(len(v)-1): if (v[i]*v[i+1]) % 4 == 0: counter += 1 else: break if counter + 1 == len(v): ...
N = int(eval(input())) A_list = list(map(int, input().split())) dic = {4: 0, 2: 0, 1: 0} for i in A_list: if i % 4 == 0: dic[4] += 1 elif i % 2 == 0: dic[2] += 1 else: dic[1] += 1 dic[4] += dic[2] // 2 if len(A_list) // 2 <= dic[4]: print('Yes') else: print(...
p03639
N = int(eval(input())) A = list(map(int, input().split())) cnt = 0 for a in A: if a % 4 == 0: cnt += 1 elif a % 2 == 0: cnt += 0.5 print(("Yes" if cnt >= N // 2 else "No"))
n = int(eval(input())) A = list(map(int, input().split())) cnt = 0 for a in A: if a%4==0: cnt += 1 elif a%2==0: cnt += 0.5 cnt = int(cnt) print(("Yes" if n//2 <= cnt else "No"))
p03639
n = int(eval(input())) A = list(map(int, input().split())) checker = [] for a in A: cnt = 0 if a % 2 == 0: cnt = 1 if a % 4 == 0: cnt += 1 checker.append(cnt) count_2 = checker.count(2) count_1 = checker.count(1) count_0 = checker.count(0) if (count_0 <= count_2+1 and ...
n = int(eval(input())) A = list(map(int, input().split())) cnt4 = 0 cnt2 = 0 other = 0 for a in A: if a % 4 == 0: cnt4 += 1 continue if a % 2 == 0: cnt2 += 1 else: other += 1 if cnt4+1 >= cnt2 + other or cnt4 >= other: print('Yes') else: print('No')
p03639
import random N = int(eval(input())) num = list(map(int, input().split())) count = 0 for i in num: if i%4==0: N -= 2 elif i%2==0: count += 1 if count>1: N = N - count + 1 if N > 1: print('No') else: print('Yes')
N = int(eval(input())) num = list(map(int, input().split())) count = 0 for i in num: if i%4==0: N -= 2 elif i%2==0: count += 1 if count>1: N = N - count + 1 if N > 1: print('No') else: print('Yes')
p03639
import collections def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a n = int(ev...
n = int(eval(input())) A = list(map(int, input().split())) f2 = 0 f4 = 0 f_another = 0 for a in A: #c = collections.Counter(prime_factorize(a)) if a%4 == 0: f4 += 1 elif a%2 == 0: f2 += 1 else: f_another +=1 if n%2 == 0 and (n -f2//2 *2 -f4 *2 <= 0): print('Yes'...
p03639
n = int(eval(input())) cnt2 = 0 cnt4 = 0 A = list(map(int, input().split())) for a in A: if a % 4 == 0: cnt4 += 1 elif a % 2 == 0: cnt2 += 1 odd = n - cnt2 - cnt4 if cnt2 != 0: odd += 1 if odd - 1 > cnt4: print("No") else: print("Yes")
n = int(eval(input())) A = list(map(int, input().split())) div = 0 even = 0 for a in A: if a % 4 == 0: div += 1 elif a % 2 == 0: even += 1 odd = n - div - even if even: odd += 1 if div: div += 1 if div >= odd or even == n: print("Yes") else: print("No")
p03639
n = int(eval(input())) As = list(map(int, input().split())) four = sum([1 for a in As if a%4 == 0]) odd = sum([1 for a in As if a%2 == 1]) two = sum([1 for a in As if a%2 == 0 and a%4 != 0]) if four < two%2 + odd - 1: print("No") else: print("Yes")
n = int(eval(input())) As = list(map(int, input().split())) # four = sum([1 for a in As if a%4 == 0]) # odd = sum([1 for a in As if a%2 == 1]) # two = sum([1 for a in As if a%2 == 0 and a%4 != 0]) four = 0 odd = 0 two = 0 for a in As: if a % 2 == 1: odd += 1 elif a % 4 == 0: four +...
p03639
import sys n = int(sys.stdin.readline().strip()) ar = [int(x) for x in sys.stdin.readline().split()] stop = False def ok(x, y): if x == -1: return True return (x*y)%4 == 0 def find(ctr, prev, mask, app): global stop if ctr == n: stop = True if stop == True: return for i in range(n): if mask[i...
import sys n = int(sys.stdin.readline().strip()) ar = [int(x) for x in sys.stdin.readline().split()] f4, odd, even = 0, 0, 0 for num in ar: if num%4==0: f4 +=1 elif num%2==0: even+=1 else: odd+=1 if odd-f4 == 0: print("Yes") elif odd-f4 <= 1 and even == 0: print("Yes") else: print("No")
p03639
from collections import Counter N = int(eval(input())) A = [int(i) for i in input().split()] C = Counter(4 if a % 4 == 0 else 2 if a % 2 == 0 else 1 for a in A) if C[2] == 0: print(("Yes" if C[1] <= C[4] + 1 else "No")) else: print(("Yes" if C[1] <= C[4] else "No"))
N = int(eval(input())) A = [int(i) for i in input().split()] def solve(): f, t, o = 0, 0, 0 for a in A: if a % 4 == 0: f += 1 elif a % 2 == 0: t += 1 else: o += 1 if t == 0: return (o <= f + 1) else: return (o ...
p03639
N = int(eval(input())) A = [int(i) for i in input().split()] f, t = 0, 0 for a in A: if a % 4 == 0: f += 1 elif a % 2 == 0: t += 1 if N - f - t <= f + (t == 0): print("Yes") else: print("No")
N = int(eval(input())) A = [int(i) % 4 for i in input().split()] f, t = A.count(0), A.count(2) if N - f - t <= f + (t == 0): print("Yes") else: print("No")
p03639
N = int(eval(input())) A = list(map(int, input().split())) n1, n2, n4 = 0, 0, 0 for a in A: if not a % 4: n4 += 1 elif not a % 2: n2 += 1 else: n1 += 1 #print(n1, n2, n4) print((["Yes", "No"][not(n1 + (n2 % 2) <= n4 + 1)]))
N = int(eval(input())) A = list(map(int, input().split())) n1, n2, n4 = 0, 0, 0 for a in A: if not a % 4: n4 += 1 elif not a % 2: n2 = 1 else: n1 += 1 #print(n1, n2, n4) print((["Yes", "No"][not(n1 + n2 <= n4 + 1)]))
p03639
n = int(eval(input())) cou1 = 0 cou2 = 0 cou4 = 0 lis = list(map(int,input().split())) for i in range(n): if lis[i] % 2 == 0: if lis[i] % 4 == 0: cou4 += 1 else: cou2 += 1 else: cou1 += 1 if cou2 == 0: if cou1 <= cou4 + 1: print("Yes") ...
n = int(eval(input())) lis = list(map(int,input().split())) nu1 = 0 nu2 = 0 nu4 = 0 for nu in lis: if nu % 2 == 0: if nu % 4 == 0: nu4 += 1 else: nu2 = 1 else: nu1 += 1 if nu4 + 1 >= nu1 + nu2:print("Yes") else:print("No")
p03639
# AtCoder Regular Contest 080 # C - 4-adjacent N=int(eval(input())) alist=list(map(int,input().split())) oddcount=0 mod40=0 other=0 for a in alist: if a%2==1: oddcount+=1 elif a%4==0: mod40+=1 else: other+=1 if N==1: if mod40==N: print("Yes") ...
# AtCoder Regular Contest 080 # C - 4-adjacent N=int(eval(input())) alist=list(map(int,input().split())) oddcount=0 mod40=0 other=0 for a in alist: if a%2==1: oddcount+=1 elif a%4==0: mod40+=1 else: other+=1 if N==1: if mod40==N: print("Yes") ...
p03639
from collections import defaultdict N = int(input()) counter = defaultdict(int) for a in map(int, input().split()): if a % 4 == 0: counter[2] += 1 elif a % 2 == 0: counter[1] += 1 else: counter[0] += 1 if counter[1] == 0: print('Yes') if counter[0] <= counter[2] + ...
from collections import Counter N = int(input()) c = Counter(map(lambda x: int(x) % 4, input().split())) print('Yes') if sum([c[1], c[2] > 0, c[3]]) <= c[0] + 1 else print('No')
p03639
n=int(eval(input())) l=list(map(int,input().split())) c_4=0 even=0 odd=0 for i in l: if i%4==0: c_4+=1 elif i%2==0: even+=1 else: odd+=1 if even==0 and odd-1 <= c_4: ans="Yes" else: ans="No" if even>0 and odd <= c_4: ans="Yes" else: "No" print(ans)
n=int(eval(input())) l=list(map(int,input().split())) c_4=0 even=0 odd=0 for i in l: if i%4==0: c_4+=1 elif i%2==0: even+=1 else: odd+=1 if even==0 and odd-1 <= c_4: ans="Yes" else: ans="No" if even>0 and odd <= c_4: ans="Yes" elif even>0: ans="No" print(ans)
p03639
def reads(offset = 0): return [int(i) - offset for i in input().split(' ')] def Judge(vector): length = len(vector)-1 for i in range(length): if(vector[i] > vector[i+1]): return 0 return 1 (N, M) = reads() Q = int(input()) A = reads(1) pos = [-1] * M pat = [] freq = [0] * (M+1) freq[0] = N cou...
def reads(offset = 0): return [int(i) - offset for i in input().split(' ')] def Judge(vector): length = len(vector)-1 for i in range(length): if(vector[i] > vector[i+1]): return 0 return 1 (N, M) = reads() Q = int(input()) A = reads(1) pos = [-1] * M pat = [] freq = [0] * (M+1) freq[0] = N fou...
p03996
def reads(offset = 0): return [int(i) - offset for i in input().split(' ')] def Judge(vector): length = len(vector)-1 for i in range(length): if(vector[i] > vector[i+1]): return 0 return 1 (N, M) = reads() Q = int(input()) A = reads(1) pos = [-1] * M pat = [] freq = [0] * (M+1) freq[0] = N fou...
def reads(offset = 0): return [int(i) - offset for i in input().split(' ')] def Judge(vector): length = len(vector)-1 for i in range(length): if(vector[i] > vector[i+1]): return 0 return 1 (N, M) = reads() Q = int(input()) A = reads(1) pos = [-1] * M pat = [] freq = [0] * (M+1) freq[0] = N fou...
p03996
import sys import math def v(): pt=[5,0,1,2] N=100000 s=list(['0' if x=='g' else '1' for x in list(sys.stdin.readline().strip())]) n,x=len(s),int(''.join(s),2) s=list(format(x<<(N-n),'0100000b')) p=pt[n%4] for _ in range(n//4):p=(p<<4)+5 ss=list(format(p<<(N-n),'010000b')) ...
import sys def v(): pt=[5,0,1,2] s=list(['0' if x=='g' else '1' for x in list(sys.stdin.readline().strip())]) n=len(s) p=pt[n%4] for _ in range(n//4):p=(p<<4)+5 ss=list(format(p,'b').zfill(n)) res=0 for a,b in zip(s,ss): d=int(b)-int(a) res = res if d==0 else r...
p03965
#len(s)//2-s.count("p") iG = 0 iR = 0 for g in [int(_) for _ in list(input().rstrip().replace("g","1").replace("p","0"))]: if g : if 0 < iG: iR += 1 iG -= 1 else: iG += 1 else: if 0 < iG: iG -= 1 else: iR -...
#len(s)//2-s.count("p") iG = 0 iR = 0 for s in input().rstrip(): if s == "g" : if 0 < iG: iR += 1 iG -= 1 else: iG += 1 else: if 0 < iG: iG -= 1 else: iR -= 1 iG += 1 print(iR)
p03965
def d_AtCoDeer_and_RockPaper(S): # 解説どおり n = len(S) # ターン数 p = 0 # 相手がパーを出した回数 for c in S: if c == 'p': p += 1 return n // 2 - p S = input().strip() print((d_AtCoDeer_and_RockPaper(S)))
def d_atcodeer_and_rock_paper(S): return len(S) // 2 - S.count('p') S = input().strip() print((d_atcodeer_and_rock_paper(S)))
p03965
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): S = readline().strip() g, p = 0, 0 ans = 0 for c in S: if g > p: p += 1 if c == '...
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): S = readline().strip() ans = len(S) // 2 - S.count('p') print(ans) return if __name__ == '__main__': mai...
p03965
N = int(eval(input())) A = list(map(int, input().split())) T = [None] * N c = 0 from functools import reduce def check(): def f(a, b): return a * b global c r = reduce(f, T) # print(T, r) if r % 2 == 0: c += 1 def dfs(pos): if pos == N: chec...
N = int(eval(input())) A = list(map(int, input().split())) total = 3 ** N ng = 1 for ai in A: if ai % 2 == 0: ng *= 2 print((total-ng))
p03568
from itertools import product n = int(eval(input())) A = list(map(int, input().split())) count = 0 for C in product((-1, 0, 1), repeat=n): total = 1 for a, c in zip(A, C): total *= (a + c) if total % 2 == 0: count += 1 print(count)
n = int(eval(input())) A = list(map(int, input().split())) count = 1 for a in A: count *= 2 if a % 2 == 0 else 1 print((3 ** n - count))
p03568
import math import string def readints(): return list(map(int, input().split())) def nCr(n, r): return math.factorial(n)//(math.factorial(n-r)*math.factorial(r)) def has_duplicates2(seq): seen = [] for item in seq: if not(item in seen): seen.append(item) re...
import math import string def readints(): return list(map(int, input().split())) def nCr(n, r): return math.factorial(n)//(math.factorial(n-r)*math.factorial(r)) def has_duplicates2(seq): seen = [] for item in seq: if not(item in seen): seen.append(item) re...
p03568
def main(): N = int(input()) A = [int(i) for i in input().split()] if N == 1: return print(1 if A[0] % 2 == 0 else 2) ans = 0 d = (-1, 0, 1) from itertools import product for i in product(range(3), repeat=N): cur = 1 for j in range(N): cur *= (A...
def main(): N = int(eval(input())) A = [int(i) for i in input().split()] ans = 3**N cnt = len([a for a in A if a % 2 == 0]) ans -= 2**cnt print(ans) if __name__ == '__main__': main()
p03568
N = int(eval(input())) A = [int(x) for x in input().split()] ret = 0 for state in range(1 << N): flag = False ans = 1 for i in range(N): if (state >> i & 1): if A[i] % 2 == 1: flag = True ans *= 2 else: if A[i] % 2 == 0: ...
def main() -> None: N = int(eval(input())) ans = 3 ** N odd = 1 for a in map(int, input().split()): if a % 2 == 0: odd *= 2 print((ans - odd)) if __name__ == '__main__': main()
p03568
n = int(eval(input())) a = list(map(int,input().split())) amax = [] amin = [] for i in range(n): amax.append(a[i] + 1) amin.append(a[i] - 1) m = 3 ** n for z in range(3 ** n): asearch = [] amulti = 1 x = z for i in range(n): asearch.append(x % 3) x = x // 3 ...
n = int(eval(input())) a = list(map(int,input().split())) ans = 3 ** n o = 1 for i in range(n): if a[i] % 2 == 0: o *= 2 else: o *= 1 print((ans - o))
p03568
print((3**int(eval(input()))-2**sum(int(s)%2==0for s in input().split())))
print((3**int(eval(input()))-2**sum(~int(s)%2for s in input().split())))
p03568
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10000) INF = 1<<32 def solve(N: int, A: "List[int]"): ans = 1 t = 1 for i in range(N): # if A[i] == 1 or A[i] == 100: # t *= 2 # continue t *= 3 if A[i]%2 == 0: ans *= 2 ...
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10000) INF = 1<<32 def solve(N: int, A: "List[int]"): ans = 1 t = 1 for i in range(N): t *= 3 if A[i]%2 == 0: ans *= 2 print((t-ans)) return def main(): def iterate_tokens(): ...
p03568
N = int(eval(input())) A = list(map(int,input().split())) odd_count = 1 for a in A: if a%2 != 0: odd_count *= 1 else: odd_count *= 2 print((3**N - odd_count))
N = int(eval(input())) A = list(map(int,input().split())) odd_count = 1 for a in A: if a%2 == 0: odd_count *= 2 print((3**N - odd_count))
p03568
from functools import reduce from itertools import product N = int(eval(input())) *A, = list(map(int, input().split())) ans = 0 for t in product([-1, 0, 1], repeat=N): prod = reduce(lambda x, y: x*y, [a + t[i] for i, a in enumerate(A)]) if prod % 2 == 0: ans += 1 print(ans)
N = int(eval(input())) *A, = list(map(int, input().split())) evens = 0 for a in A: if a % 2 == 0: evens += 1 ans = 3**N - 2**evens print(ans)
p03568
n = int(eval(input())) a = sum(list([1-int(x)%2 for x in input().split()])) print((3**n-2**a))
print((3**int(eval(input()))-2**sum(list([1-int(x)%2 for x in input().split()]))))
p03568
N = int(eval(input())) As = list(map(int,input().split())) def dfs(A_s, index,Bss): if index == N: tmp = 1 for b in Bss: tmp *= b return 1 if tmp % 2 == 0 else 0 b_mi = Bss.copy() b_mi.append(A_s[index] - 1) b = Bss.copy() b.append(A_s[index]) ...
N = int(eval(input())) As = list(map(int,input().split())) tmp = 1 for i in range(N): if As[i] % 2 == 0: tmp *= 2 print((3 ** N - tmp))
p03568
n = int(eval(input())) print(('ABC' if n<1000 else 'ABD'))
print(('ABD' if int(eval(input()))>=1000 else 'ABC'))
p03327
n = int(eval(input())) if n < 1000: print("ABC") else: print("ABD")
n = int(eval(input())) if n > 999: print("ABD") else: print("ABC")
p03327
n = int(eval(input())) if n <= 999: print('ABC') else: print('ABD')
n = int(eval(input())) if n >= 1000: print('ABD') else: print('ABC')
p03327
print(('AB'+('C' if int(eval(input())) < 1000 else 'D')))
N = int(eval(input())) if N < 1000: ans = "ABC" N += 1000 N = str(N) N = N[1:] ans += N else: ans = "ABD" N -= 999 N += 1000 N = str(N) N = N[1:] ans += N print((ans[:3]))
p03327
print((('ABC','ABD')[len(input()[3:])]))
print((('ABD','ABC')[not input()[3:]]))
p03327
N=eval(input()) N=int(N) if N<1000: print('ABC') elif N>=1000: print('ABD')
N=eval(input()) N=int(N) if N<1000: print('ABC') else: print('ABD')
p03327
#S=input() N=int(eval(input())) #A,B=map(int,input().split()) if N<1000: print("ABC") else: print("ABD")
N=int(eval(input())) if N>999: print("ABD") else: print("ABC")
p03327
print(("ABC" if int(eval(input()))<1000 else "ABD"))
print((['ABC','ABD'][int(eval(input()))>999]))
p03327
print(('ABC' if int(eval(input())) < 1000 else 'ABD'))
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N = ir() answer = 'ABC' if N < 1000 else 'ABD' print(answer)
p03327
def main(): num = int(eval(input())) if num<1000: ans = 'ABC' elif num < 1999: ans = 'ABD' else: print("error") print(ans) if __name__ == "__main__": main()
N = int(eval(input())) if N < 1000: print("ABC") else: print("ABD")
p03327
a = int(eval(input())) if a > 999: print("ABD") else: print("ABC")
a=int(eval(input())) print(("ABC" if a<1000 else "ABD"))
p03327
print("ABC") if int(input())<=999 else print("ABD")
if int(eval(input()))<1000: print("ABC") else: print("ABD")
p03327
n=int(eval(input())) if n<=999: print("ABC") else: print("ABD")
if int(eval(input()))<=999: print("ABC") else: print("ABD")
p03327
n=int(eval(input())) if n<=999: print('ABC') else: print('ABD')
n=int(eval(input())) print(('ABC' if n<1000 else 'ABD'))
p03327
n = int(eval(input())) if n <= 999: print("ABC") else: print("ABD")
n = int(eval(input())) if n < 1000: ans = "ABC" else: ans = "ABD" print(ans)
p03327
# -*- coding: utf-8 -*- N = int(eval(input())) if N >= 1000: print("ABD") else: print("ABC")
N = int(eval(input())) if N >= 1000: print("ABD") else: print("ABC")
p03327
n = int(eval(input())) if n < 1000: print('ABC') else: print('ABD')
N = int(eval(input())) print(('ABC' if N < 1000 else 'ABD'))
p03327
from sys import stdin import fractions n = int(stdin.readline().rstrip()) if n <1000: print("ABC") else: print("ABD")
n = int(eval(input())) if n < 1000: print("ABC") else: print("ABD")
p03327
n=int(eval(input())) if n<=999: print("ABC") else: print("ABD")
n=int(eval(input())) x=n-999 if n>999 else n if n>999: print("ABD") else: print("ABC")
p03327
a, b, x = list(map(int, input().split())) if a%x == 0: print(((b//x+1) - (a//x))) else: print(((b//x+1) - (a//x+1)))
a, b, x = list(map(int, input().split())) def f(n): if n == -1: return 0 else: return n//x + 1 print((f(b) - f(a-1)))
p03861
from decimal import * a, b, x = list(map(int, input().split())) ax = int(Decimal(a) / Decimal(x)) bx = int(Decimal(b) / Decimal(x)) am = a % x bm = b % x if ax == bx and am != 0 and bm != 0: print((0)) elif am == 0: print((bx - ax + 1)) else: print((bx - ax))
a, b, x = list(map(int, input().split())) ans = b // x - a // x if a % x == 0: ans += 1 print(ans)
p03861
import sys def input(): return sys.stdin.readline().strip() def resolve(): a,b,x=list(map(int, input().split())) if a!=0: amade=(a-1)//x bmade=b//x print((bmade-amade)) else: print((b//x+1)) resolve()
import sys def input(): return sys.stdin.readline().strip() def resolve(): a,b,x=list(map(int, input().split())) amade=(a-1)//x bmade=b//x print((bmade-amade)) resolve()
p03861
a, b, x = list(map(int, input().split())) for i in range(x): fa = a+i if fa%x == 0: break if b < fa: print((0)) else: print((1+(b-fa)//x))
a, b, x = list(map(int, input().split())) i = 0 fa = x*i while x*i < a: i += 1 fa = x*i if b < fa: print((0)) else: print((1+(b-fa)//x))
p03861
from decimal import * #exp = Decimal(10**23) #rint((Decimal(11)*exp)/Decimal(10)) ## coding: UTF-8 s = input().split() t = [int(p) for p in s] #print(t) a = t[0] b = t[1] x = t[2] start = a goal = b while True: if(start % x == 0): break else: start += 1 #print(start) whil...
from decimal import * #exp = Decimal(10**23) #rint((Decimal(11)*exp)/Decimal(10)) ## coding: UTF-8 s = input().split() t = [int(p) for p in s] #print(t) a = t[0] b = t[1] x = t[2] ''' start = a goal = b while True: if(start % x == 0): break else: start += 1 #print(start) ...
p03861
from decimal import * #exp = Decimal(10**23) #rint((Decimal(11)*exp)/Decimal(10)) ## coding: UTF-8 s = input().split() t = [int(p) for p in s] #print(t) a = t[0] b = t[1] x = t[2] ''' start = a goal = b while True: if(start % x == 0): break else: start += 1 #print(start) ...
a, b, x = list(map(int,input().split())) if(a%x == 0): A = a//x else: A = a//x + 1 B = b//x print((B-A+1))
p03861
arr = input().split() arr = list(map(int,arr)) a = arr[0] b = arr[1] x = arr[2] c = a left = 0 while(True): if c % x == 0: left = c break else: c += 1 c = b while(True): if c % x == 0: right = c break else: c -= 1 print(((right - ...
arr = input().split() arr = list(map(int,arr)) a = arr[0] b = arr[1] x = arr[2] def f(n): if n == -1: return 0 else: return n // x + 1 print((f(b) - f(a-1)))
p03861
a, b, x = list(map(int, input().split())) c=a//x d=b//x e=a%x if(e == 0): print((d-c+1)) else: print((d-c))
a,b,x=list(map(int, input().split())) c=b//x-a//x if(a%x==0): print((c+1)) else: print(c)
p03861
a, b, x = list(map(int, input().split())) ans = 0 p = a while p <= b: if p%x == 0: break p += 1 t = b-p s = t//x ans = s + 1 print(ans)
a, b, x = list(map(int, input().split())) p = 0 y = int(b//x) + 1 i = 1 #for i in range(1,y): while x*i <= b: if a <= x*i: p = x*i break i += 1 if p != 0: t = b-p s = t//x ans = s + 1 if a == 0: ans += 1 print(ans) elif a == 0: print((1)) ...
p03861
# ABC48, B - between a and b import itertools a, b, x = [int(el) for el in input().split(' ')] for i in itertools.count(a): if i % x == 0: A = i break for i in itertools.count(b, -1): if i % x == 0: B = i break print((B // x - A // x +1))
# ABC48, B - between a and b def f(n, x): if n == -1: return(0) else: return(n // x + 1) a, b, x = [int(el) for el in input().split(' ')] print((f(b, x) - f(a-1, x)))
p03861
a,b,x = list(map(int, input().split())) s = b//x t = (a-1)//x print((s-t))
a,b,x = list(map(int, input().split())) print((b//x - (a-1)//x))
p03861
import sys a, b, x = list(map(int, input().split())) if a == b == 0: print((1)) sys.exit() if x > b: if a != 0: print((0)) sys.exit() else: print((1)) sys.exit() if x <= b: if a % x == 0: print((b // x - a //x + 1)) else: prin...
import sys a, b, x = list(map(int, input().split())) if a == b == 0: print((1)) sys.exit() if a % x == 0: print((b // x - a //x + 1)) else: print((b // x - a // x))
p03861
a, b, x = list(map(int, input().split())) print((b // x - (a - 1) // x))
a, b, x = list(map(int, input().split())) print((b // x - ~-a // x))
p03861
a, b, x = list(map(int, input().split())) def max_search(s, t): for i in range(s): if (s-i) % t == 0: return (s-i) // t return 0 a_max = max_search(a-1, x) b_max = max_search(b, x) if a == 0: b_max += 1 print((b_max-a_max))
a, b, x = list(map(int, input().split())) a_max = max(((a-1) // x, 0)) b_max = b // x if a == 0: b_max += 1 print((b_max-a_max))
p03861
a,b,x=list(map(int, input().split())) print((b//x-((a-1)//x+1)+1))
a,b,x=list(map(int, input().split())) print((b//x-(a-1)//x))
p03861
A,B,X = list(map(int,input().split())) print((B//X - (A-1)//X))
# python3 (3.4.3) import sys input = sys.stdin.readline # main A,B,X = list(map(int,input().split())) print((B//X - (A-1)//X))
p03861
start,end,devide = list(map(int,input().split())) num = 0 for i in range(start,end + 1): if i % devide == 0: num +=1 num += (end - i) // devide break print(num)
a, b, x = list(map(int, input().split())) if a != 0: print((b//x - (a-1)//x)) else: print((b//x + 1))
p03861
a, b, x = list(map(int, input().split())) key = 0 count = 0 if a == b: if a % x == 0: print((1)) exit() else: print((0)) exit() for i in range(a, b + 1, 1): if i % x == 0: key = i count += 1 ans = count + (b - key) // x print...
a, b, x = list(map(int, input().split())) big = b // x + 1 small = (a - 1) // x + 1 ans = big - small if ans < 0: ans = 0 print(ans)
p03861