id
stringlengths
24
27
content
stringlengths
37
384k
max_stars_repo_path
stringlengths
51
51
condefects-python_data_1901
#!/usr/bin/env python3 # from typing import * from math import sqrt # def solve(N: int) -> int: def solve(N): # 片方を決め打てばよさそう? ans = 10**20 if N == 0: return 0 for n in range(400000): m = (-20 * n**3 + 3 * sqrt(3) * sqrt(16 * n**6 - 40 * n**3 * N + 27 * N**2) + 27 * N)**(1/3)/(3 * 2*...
ConDefects/ConDefects/Code/abc246_d/Python/45780372
condefects-python_data_1902
import bisect from itertools import accumulate, permutations, combinations from collections import deque, Counter, defaultdict import heapq from string import ascii_lowercase # 'abcdefghijklmnopqrstuvwxyz' from string import ascii_uppercase # 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' # import pypyjit # pypyjit.set_param('max_unro...
ConDefects/ConDefects/Code/abc353_c/Python/55158545
condefects-python_data_1903
N = int(input()) print('N'*N) N = int(input()) print((10**N-1)//9*N)
ConDefects/ConDefects/Code/abc333_a/Python/54873390
condefects-python_data_1904
N, K = map(int,input().split()) ct = list(map(int,input().split())) import sys S = sum(ct) to_go = sum(ct) ans = [-1]*to_go block_idx = -(-to_go // K) #print(block_idx, to_go) dead = 0 while to_go > 0: steps = to_go % K if steps == 0: steps = K criticals = set() for n in range(N): if ct[n] > blo...
ConDefects/ConDefects/Code/arc128_e/Python/27510550
condefects-python_data_1905
import sys sys.setrecursionlimit(10**6) def f(x): if x // 2 not in dp: dp[x // 2] = f(x // 2) if x // 3 not in dp: dp[x // 3] = f(x // 3) return dp[x // 2] + dp[x // 3] N = int(input()) dp = {0: 1} print(f(N)) import sys sys.setrecursionlimit(10**6) def f(x): if x in dp: retu...
ConDefects/ConDefects/Code/abc275_d/Python/45982640
condefects-python_data_1906
# 275d import math def rec(n, memo={}): if math.floor(n) == 0: return 1 if n in memo: return memo[n] memo[n] = rec(n/2, memo) + rec(n/3, memo) return memo[n] n = int(input()) rec(n) # 275d import math def rec(n, memo={}): if math.floor(n) == 0: return 1 if n in me...
ConDefects/ConDefects/Code/abc275_d/Python/45717410
condefects-python_data_1907
n,m=list(map(int,input().split())) l=[int(x) for x in input().split()] d=dict() for i in l: if i in d: d[i]+=1 else : d[i]=1 yes=True nl=[int(x) for x in input().split()] for i in nl: if i not in d or d[i]==0: yes=False break print("Yes"if yes else "No") n,m=list(map(int,in...
ConDefects/ConDefects/Code/abc241_b/Python/45708346
condefects-python_data_1908
class Lazy_Evaluation_Tree(): def __init__(self, L, op, unit, act, comp, id): """ op を演算, act を作用とするリスト L の Segment Tree を作成 op: 演算 unit: Monoid op の単位元 ( xe=ex=x を満たす e ) act: 作用素 comp: 作用素の合成 id: 恒等写像 [条件] M: Monoid, F={f: F x M→ M: 作用素} に対して, 以下が成立する. ...
ConDefects/ConDefects/Code/abc346_g/Python/51628683
condefects-python_data_1909
import sys input = sys.stdin.readline N=int(input()) A=list(map(int,input().split())) LIST=[[] for i in range(N+100)] for i in range(N): LIST[A[i]].append(i) # 非再帰遅延伝搬セグ木 # 高々N点を更新 seg_el=1<<(N.bit_length()) # Segment treeの台の要素数 SEG=[[0,1] for i in range(2*seg_el)] # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初...
ConDefects/ConDefects/Code/abc346_g/Python/51994914
condefects-python_data_1910
def job(): s = input() a_set = set() stack_kakko = [] stack_i = [] for i in range(len(s)): stack_i.append(i) c = s[i] if c == '(': stack_kakko.append(i) elif c == ')': peak = stack_kakko[-1] while stack_i[-1] > peak: ...
ConDefects/ConDefects/Code/abc283_d/Python/45517172
condefects-python_data_1911
S = input() level = 0 LV = [set()]*len(S) ST = set() for ss in S: if ss == ")": ST = ST - LV[level] LV[level] =set() level -= 1 elif ss == "(": level += 1 else: if ss in ST: print("No") exit() else: ST.add(ss) LV[level].add(ss) print("Yes") S = input() ...
ConDefects/ConDefects/Code/abc283_d/Python/44825137
condefects-python_data_1912
S = input() t = set([]) a=[[]] for i in S: if i.isalpha() == True: if i in t: print("No") exit() else: t.add(i) a[-1].append(i) elif i==")": # print(a) for j in a[-1]: print(t) t.remove(j) a.pop(-1) ...
ConDefects/ConDefects/Code/abc283_d/Python/45462979
condefects-python_data_1913
import bisect H,W,rs,cs=map(int,input().split()) N=int(input()) r_dic={} c_dic={} for _ in range(N): r,c=map(int,input().split()) if r not in r_dic: r_dic[r]=set() r_dic[r].add(c) else: r_dic[r].add(c) if c not in c_dic: c_dic[c]=set() c_dic[c].add(r) else: ...
ConDefects/ConDefects/Code/abc273_d/Python/45461646
condefects-python_data_1914
from typing import Generic, Iterable, Iterator, List, Tuple, TypeVar, Optional from collections import deque, defaultdict from decimal import Decimal from bisect import bisect_left, bisect_right from heapq import heapify, heappush, heappop from itertools import permutations, combinations from random import randrange, c...
ConDefects/ConDefects/Code/abc273_d/Python/45053294
condefects-python_data_1915
import re import functools import copy import bisect import math from collections import deque from collections import defaultdict from collections import Counter from heapq import heapify, heappush, heappop, heappushpop, heapreplace al = "abcdefghijklmnopqrstuvwxyz" au = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" def ii(): re...
ConDefects/ConDefects/Code/abc273_d/Python/44934690
condefects-python_data_1916
n=int(input()) ans=format(n,'x').zfill(2) #zfillで2桁となるよう0埋め print(ans) n=int(input()) ans=f'{n:02X}' print(ans)
ConDefects/ConDefects/Code/abc271_a/Python/45782471
condefects-python_data_1917
n = int(input()) num = 'abcdef' a = str(hex(n)) #print(a) a = a[2:] #print(a) if len(a) < 2: if a in num: a = a.upper() a = '0'+a print(a) exit() else: print(a) exit() else: b = [] for i in range(len(a)): if a[i] in num: c = a[i]...
ConDefects/ConDefects/Code/abc271_a/Python/45793366
condefects-python_data_1918
N = int(input()) print(hex(N)[2:].upper()) N = int(input()) print(hex(N)[2:].upper().zfill(2))
ConDefects/ConDefects/Code/abc271_a/Python/45555284
condefects-python_data_1919
a = int(input()) b = format(a,"x") b = str(b) if a < 16: b = "0"+ b print(b) a = int(input()) b = format(a,"x") b = str(b) if a < 16: b = "0"+ b print(b.upper())
ConDefects/ConDefects/Code/abc271_a/Python/46000119
condefects-python_data_1920
n = int(input()) print(hex(n)[2:].upper()) n = int(input()) print(hex(n)[2:].upper().zfill(2))
ConDefects/ConDefects/Code/abc271_a/Python/44974304
condefects-python_data_1921
n,a,b,c,d = map(int, input().split()) print("No" if abs(b - c) > 1 or (b == c == 0 and (a != 0 and b != 0)) else "Yes") n,a,b,c,d = map(int, input().split()) print("No" if abs(b - c) > 1 or (b == c == 0 and (a != 0 and d != 0)) else "Yes")
ConDefects/ConDefects/Code/arc157_a/Python/42091625
condefects-python_data_1922
N, A, B, C, D = map(int, input().split()) if abs(B - C) > 1: print("No") exit() elif B == C: if B == 0: if A > 0 and D == 0: if N == A + 1: print("Yes") else: print("No") elif A == 0 and D > 0: if N == D + 1: ...
ConDefects/ConDefects/Code/arc157_a/Python/45521757
condefects-python_data_1923
import sys readline = sys.stdin.readline #n = int(readline()) #*a, = map(int,readline().split()) # b = [list(map(int,readline().split())) for _ in range()] n,a,b,c,d = map(int,readline().split()) def check(a,b,c,d): #XY if b-c==1: return 1 #YY,XX if b == c: if b==0: if a==0 or d==...
ConDefects/ConDefects/Code/arc157_a/Python/42827862
condefects-python_data_1924
from collections import defaultdict class UnionFind(): #「uf = UnionFind(頂点の数)」で初期化 def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): #uf.find(x) #要素xが属するグループの根を返す if self.parents[x] < 0: return x else: self.parent...
ConDefects/ConDefects/Code/arc157_a/Python/43019650
condefects-python_data_1925
''' ・XX, XY, YX, YYは必ず 重なる ①XY, YXについて 数の差が2以上になると実現不可能 XY1 YX2 = YXYX に、もうひとつ「YX」をつけようとすると ・後ろにつけようとする YXYXYX → XYが発生 ・前につけようとする YXYXYX → XYが発生 ②XX, YYどちらもあって、YX, XYどちらもないは実現不可能 ・XXYY → XYが発生 ・YYXX → YXが発生 ''' n, xx, xy, yx, yy = map(int, input().split()) flg = 1 if abs(xy - yx) >= 2: flg = 0...
ConDefects/ConDefects/Code/arc157_a/Python/43792391
condefects-python_data_1926
N, A, B, C, D = map(int, input().split()) # XX, XYは(start)X, XX, YXの後にのみ続く # YX, YYは(start)Y, XY, YYの後にのみ続く # A, Bの個数はA, Cの個数とほぼ同じ -> Bの個数はCの個数とほぼ同じ # C, Dの個数はB, Dの個数とほぼ同じ -> Cの個数はBの個数とほぼ同じ if abs(B-C) == 1: print("Yes") elif B==C and B!=0: print("Yes") elif A==0 or D==0: # B=C=0 print("Yes") else: p...
ConDefects/ConDefects/Code/arc157_a/Python/43268490
condefects-python_data_1927
n,a,b,c,d=map(int,input().split()) if abs(b-c)<=1: if b==c==0 and (a<n-1 or d<n-1): print("No") else: print("Yes") else: print("No") n,a,b,c,d=map(int,input().split()) if abs(b-c)<=1: if b==c==0 and a<n-1 and d<n-1: print("No") else: print("Yes") else: print("No")
ConDefects/ConDefects/Code/arc157_a/Python/44812026
condefects-python_data_1928
N, A, B, C, D = map(int, input().split()) if abs(B - C) > 1: print("No") else: print("Yes") N, A, B, C, D = map(int, input().split()) if abs(B - C) > 1: print("No") elif B == 0 and C == 0 and A > 0 and D > 0: print("No") else: print("Yes")
ConDefects/ConDefects/Code/arc157_a/Python/44691106
condefects-python_data_1929
import math N,A,B,C,D=(int(x) for x in input().split()) n=math.floor(N/2) if abs(B-C)<=1 and B<=n and C<=n and B+C>0: print("Yes") else: print("No") import math N,A,B,C,D=(int(x) for x in input().split()) n=math.floor(N/2) if (abs(B-C)<=1 and B<=n and C<=n and B+C!=0) or A==N-1 or D==N-1: print("Yes") else: pr...
ConDefects/ConDefects/Code/arc157_a/Python/44416887
condefects-python_data_1930
n, a, b, c, d = map(int, input().split()) if abs(b-c) >= 2: print("No") elif b + c == 0 and a*b != 0: print("No") else: print("Yes") n, a, b, c, d = map(int, input().split()) if abs(b-c) >= 2: print("No") elif b + c == 0 and a*d != 0: print("No") else: print("Yes")
ConDefects/ConDefects/Code/arc157_a/Python/42873423
condefects-python_data_1931
from collections import deque import sys import math import heapq import random import itertools from functools import cmp_to_key from fractions import Fraction def gs(): return sys.stdin.readline().split()[0] def gd(): return float(sys.stdin.readline()) def gi(): return int(sys.stdin.readline()) def gi...
ConDefects/ConDefects/Code/arc157_a/Python/42886459
condefects-python_data_1932
INF = 1 << 64 mod = 10**9 + 7 dir = [(1, 0), (0, 1), (-1, 0), (0, -1)] import sys from collections import defaultdict, deque #from functools import lru_cache #@lru_cache input = sys.stdin.readline sys.setrecursionlimit(10**9) def ni(): return int(input()) def na(): return map(int, input().split()) def nl(): return list...
ConDefects/ConDefects/Code/arc141_b/Python/36162097
condefects-python_data_1933
n,m=map(int,input().split()) binm=bin(m)[2:] if n>len(binm): print(0) exit() num=[0]*len(binm) num[-1]=m-(1<<(len(binm)-1))+1 for i in range(len(binm)-1): num[i]=1<<i dp=[[0]*len(binm) for i in range(n)] dp[0]=num for i in range(n-1): for j in range(len(binm)): for k in range(j+1,len(binm)): ...
ConDefects/ConDefects/Code/arc141_b/Python/40574832
condefects-python_data_1934
import math N,M=map(int,input().split()) mod=998244353 l=(int(math.log2(M))+1) if N<l or N==1: dp=[[0]*l for _ in range(N)] X=[] for i in range(l): if 2**(i+1)-1<M: X.append((2**i)%mod) dp[0][i]=X[-1] else: X.append((M-2**i+1)%mod) dp[0][i]=X[-1] if i>0: dp[0][i]+=dp[0][i...
ConDefects/ConDefects/Code/arc141_b/Python/39358112
condefects-python_data_1935
import math N, M = map(int, input().split()) Mod = 998244353 if math.floor(math.log2(M)) < N: print(0) exit() #dp[i] = 最上位ビットがiになる場合の数 a = [0] * 70 for i in range(70): if 2 * 2 ** i <= M: a[i] = 2 ** i else: a[i] = max(0, M - 2 ** i + 1) a = [0] + a dp = a[:] for i in range(N - 1): ...
ConDefects/ConDefects/Code/arc141_b/Python/38039113
condefects-python_data_1936
p = 998244353 N, M = map(int, input().split()) K = 60 if N > 60: print(0) exit() dp = [[0] * (K + 1) for _ in range(N + 1)] dp[0][0] = 1 for i in range(N): for j in range(K + 1): for jj in range(1, K + 1): jn = j + jj if jn > K: continue "jn桁となるのは ...
ConDefects/ConDefects/Code/arc141_b/Python/44178563
condefects-python_data_1937
N, A, B = map(int, input().split()) S = list(input()) ans = 0 sa = [0 for _ in range(2 * N)] wa = [0 for _ in range(2 * N + 1)] for s in range(2 * N): if S[s] == ")": sa[s] = -1 else: sa[s] = 1 W = sum(sa) if W != 0: i = 0 while W != 0: if W < 0: if S[i] == ")": ...
ConDefects/ConDefects/Code/arc175_b/Python/52710253
condefects-python_data_1938
DEBUG = False testcase = r""" 1 2 3 test """[1:] from typing import * from collections import Counter, deque, defaultdict import bisect import heapq import copy import itertools from pprint import pprint import math import sys _input = input input = lambda: sys.stdin.readline().rstrip() mi = lambda: map(int, input(...
ConDefects/ConDefects/Code/arc175_b/Python/51933297
condefects-python_data_1939
def job(): n, a, b = map(int, input().split()) s = input() a_sum = 0 a_min = 0 a = min(a, 2 * b) left = s.count(')') right = s.count('(') s = list(s) ans = 0 diff = abs(right - left) cnt = diff // 2 ans += b * cnt tot = 0 if left > right: for i in range(2 ...
ConDefects/ConDefects/Code/arc175_b/Python/51749871
condefects-python_data_1940
N, A, B = map(int, input().split()) S = list(input()) res = 0 right = S.count('(') - S.count(')') # print(right) left = 0 for i in range(2*N): # print(i, 'L', left) if S[i] == '(': if left + 1 > 2 * N - i - 1: left -= 1 res += 1 else: left += 1 else: ...
ConDefects/ConDefects/Code/arc175_b/Python/52484583
condefects-python_data_1941
n, a, b = map(int, input().split()) s=list(input()) stnum=s.count("(") ans=0 pos=0 while stnum < n: while s[pos]=="(": pos=pos+1 s[pos]="(" stnum+=1 ans+=b pos=n*2-1 while stnum > n: while s[pos]==")": pos=pos-1 s[pos]=")" stnum-=1 ans+=b cnts=0 for i in range(2*n): if s[i]=="(": cnts+=1 ...
ConDefects/ConDefects/Code/arc175_b/Python/53758611
condefects-python_data_1942
def main(): N, A, B = map(int, input().split()) str = list(input()) open_cnt = str.count('(') closed_cnt = str.count(')') # Calculate lower bound of minimum cost result = B * (abs(open_cnt - closed_cnt)) // 2 tmp = 0 if closed_cnt > open_cnt: for i in range(len(str)): ...
ConDefects/ConDefects/Code/arc175_b/Python/51713549
condefects-python_data_1943
# -*- coding: utf-8 -*- N,A,B=map(int,input().split()) S=input() ans=0 X=[0]*(N*2+1) for i in range(N*2): if S[i]=="(": X[i+1]=1 if S[i]==")": X[i+1]=-1 K=sum(X) #print(X) #print(K) ans+=B*abs(K)//2 if K>0: for i in range(N*2): if X[N*2-i]==1: X[N*2-i]=-1 K...
ConDefects/ConDefects/Code/arc175_b/Python/51792735
condefects-python_data_1944
import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) def cmb(n, r, mod): if ( r<0 or r>n ): ...
ConDefects/ConDefects/Code/arc140_d/Python/31726462
condefects-python_data_1945
n=int(input()) a=[0]+list(map(int,input().split())) ################################################# import sys sys.setrecursionlimit(10 ** 9) # 再帰の上限をあげる ######### uni_num=n+1 ######### union_root = [-1 for i in range(uni_num + 1)] # 自分が親ならグループの人数のマイナス倍を、そうでないなら(元)親の番号を示す union_depth = [0] * (uni_num + 1) ...
ConDefects/ConDefects/Code/arc140_d/Python/31731857
condefects-python_data_1946
mod = 998244353 from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return sel...
ConDefects/ConDefects/Code/arc140_d/Python/31743854
condefects-python_data_1947
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor, co...
ConDefects/ConDefects/Code/arc140_d/Python/31727307
condefects-python_data_1948
import sys input = sys.stdin.readline for _ in range(int(input())): N = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) sa = set(a) sb = set(b) if sa | sb != sa: print("No") continue la = [a[0]] lb = [b[0]] for i in range(1, N): if la[-1] != a[i]: la...
ConDefects/ConDefects/Code/arc154_c/Python/38909905
condefects-python_data_1949
import sys input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) INF = 2**63-1 mod = 998244353 def solve(): n = ii() a = li() b = li() if a == b: return 'Yes' c = [] for i in range(n): if not c ...
ConDefects/ConDefects/Code/arc154_c/Python/39123866
condefects-python_data_1950
import bisect import copy import decimal import fractions import heapq import itertools import math import random import sys import time from collections import Counter,deque,defaultdict from functools import lru_cache,reduce from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max def _heappush...
ConDefects/ConDefects/Code/arc147_e/Python/34616740
condefects-python_data_1951
import heapq import collections N = int(input()) AB = [list(map(int, input().split())) for _ in range(N)] OK = [] NG = [] for a,b in AB: if a>=b: OK.append([a,b]) else: NG.append([a,b]) OK = sorted(OK, reverse=True, key=lambda x: x[0]) OK_D = collections.deque(OK) NG_A = [] NG_B = [] for a,b in ...
ConDefects/ConDefects/Code/arc147_e/Python/40546012
condefects-python_data_1952
import sys input = sys.stdin.readline def scc_decomposition(G): n = len(G) G_rev = [[] for _ in range(n)] for u in range(n): for v in G[u]: G_rev[v].append(u) # dfs vs = [] visited = [False] * n used = [False] * n for u in range(n): if visited[u]: ...
ConDefects/ConDefects/Code/arc165_d/Python/45683063
condefects-python_data_1953
import sys input = sys.stdin.readline class SCC: def __init__(self,n): self.n = n self.edges = [] def csr(self): self.start = [0]*(self.n+1) self.elist = [0]*len(self.edges) for e in self.edges: self.start[e[0]+1] += 1 for i in range(1,self.n+1): ...
ConDefects/ConDefects/Code/arc165_d/Python/45791883
condefects-python_data_1954
class UnionFind: def __init__(self, n): self.n = n self.par = [-1] * n self.group_ = n def find(self, x): if self.par[x] < 0: return x lst = [] while self.par[x] >= 0: lst.append(x) x = self.par[x] for y in lst: ...
ConDefects/ConDefects/Code/arc165_d/Python/45675161
condefects-python_data_1955
n=int(input()) from collections import defaultdict as df d=df(list) exist=set() num=[[] for i in range(n)] for i in range(n): m=int(input()) for __ in range(m): a,b=map(int,input().split()) num[i].append([a,b]) d[a].append([i,b]) if a not in exist: exist.add(a) for k in exist: d[k].sort(key=...
ConDefects/ConDefects/Code/abc259_e/Python/45515452
condefects-python_data_1956
N=int(input()) A=list(map(int,input().split())) v=[0]*30 for i in range(N): x=A[i] for k in range(30): if (x>>k)&1: v[k]+=1 result=sum(A) y=result for i in range(N): w=0 x=A[i] for k in range(k): if (x>>k)&1: w-=v[k]*2**k w+=(N-v[k])*2**k result=max(result,y+w) print(result) N=int...
ConDefects/ConDefects/Code/arc135_c/Python/41836593
condefects-python_data_1957
import heapq import sys from collections import defaultdict, deque from math import inf sys.setrecursionlimit(10**6) MOD = 10**9 + 7 stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces # count the ones in ever...
ConDefects/ConDefects/Code/arc135_c/Python/33027382
condefects-python_data_1958
s = float(input()) print(round(s)) s = float(input()) print(round(s+0.0005))
ConDefects/ConDefects/Code/abc226_a/Python/45900046
condefects-python_data_1959
X = float(input()) print(round(X)) X = float(input()) print(round(X + 0.00005))
ConDefects/ConDefects/Code/abc226_a/Python/46153240
condefects-python_data_1960
x = float(input()) print(int(round(x, 0))) x = float(input()) print(int(round(x+0.0005, 0)))
ConDefects/ConDefects/Code/abc226_a/Python/44824039
condefects-python_data_1961
X = input() print(int(float(X)+1)) X = input() print(int(float(X)+0.5))
ConDefects/ConDefects/Code/abc226_a/Python/45214057
condefects-python_data_1962
n, l, r = map(int, input().split()) a = list(map(int, input().split())) base = [] for i in a: for j in base: i = min(i, i ^ j) if i: base.append(i) base.sort() for i in range(len(base) - 1, -1, -1): for j in range(i - 1, -1, -1): base[i] = min(base[i], base[i] ^ base[j]) for i in...
ConDefects/ConDefects/Code/abc283_g/Python/42794591
condefects-python_data_1963
N,L,R = map(int,input().split()) L -= 1 R -= 1 A = list(map(int,input().split())) A.sort() base = [] for i in range(N): a = A[i] for e in base: a = min(a,a^e) for i in range(len(base)): base[i] = min(base[i],a ^ base[i]) if a > 0: base.append(a) base.sort() ans = [] for x in range(L,R+1): res = 1...
ConDefects/ConDefects/Code/abc283_g/Python/50031003
condefects-python_data_1964
from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): way=[] while True: if self.parents[x] < 0: break else: way.append(x) x=se...
ConDefects/ConDefects/Code/abc283_g/Python/51990912
condefects-python_data_1965
n,l,r = map(int,input().split()) a = list(map(int,input().split())) v = [] for i in range(n): w = a[i] for e in v: w = min(w, e^w) if w > 0: for j in range(len(v)): v[j] = min(v[j], v[j] ^ w) v.append(w) v.sort() #print(v) ans = [] l-=1 r-=1 for i in range(l, r+1): tmp = 0 for j in range(30): if (i >>...
ConDefects/ConDefects/Code/abc283_g/Python/38648014
condefects-python_data_1966
n,l,r=map(int,input().split()) a=list(map(int,input().split())) e=[] for i in a: now=i for j in e: now=min(now,now^j) if now: e.append(now) e.sort(reverse=True) for i in range(len(e)): now=1<<(e[i].bit_length()-1) for j in range(len(e)): if i==j: continue if e[j]&now: e...
ConDefects/ConDefects/Code/abc283_g/Python/54268895
condefects-python_data_1967
string = input() point_list = [] for x in string: point_list.append(ord(x)) code_point = point_list[0] for x in point_list: if x == code_point: continue elif x-1 == code_point and x == code_point + 1: code_point = x else: print('No') exit() print('Yes') st...
ConDefects/ConDefects/Code/abc337_b/Python/54960837
condefects-python_data_1968
S = input() state = 0 for i in S: if state == 0 and i == 'B': state += 1 elif state == 1 and i == 'C': state += 1 if state == 0 and i != 'A': print("No") exit() elif state == 1 and i != 'B': print("No") exit() elif state == 2 and i != 'C': ...
ConDefects/ConDefects/Code/abc337_b/Python/54984614
condefects-python_data_1969
s = list(input()) ex_list = [s[0]] for i in range(len(s)-1): if s[i] != s[i+1]: ex_list.append(s[i+1]) word = ''.join(ex_list) if word in ['ABC', 'A', 'B', 'C', 'AC', 'BC']: print('Yes') else: print('No') s = list(input()) ex_list = [s[0]] for i in range(len(s)-1): if s[i] != s[i+1]: ...
ConDefects/ConDefects/Code/abc337_b/Python/54959734
condefects-python_data_1970
# ref: https://qiita.com/Kota-Y/items/396ab3c57830dad65cfb import sys import re from math import ceil, floor, sqrt, pi, factorial, gcd from copy import deepcopy from collections import Counter, deque, defaultdict from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combi...
ConDefects/ConDefects/Code/abc270_d/Python/45974029
condefects-python_data_1971
# import sys # sys.setrecursionlimit(10**6) import re import copy import bisect import math import itertools from collections import deque from collections import defaultdict from collections import Counter from heapq import heapify, heappush, heappop, heappushpop, heapreplace from functools import cmp_to_key as cmpk i...
ConDefects/ConDefects/Code/abc270_d/Python/45126109
condefects-python_data_1972
N,Q=map(int,input().split()) S=input() #Segment Tree def operator(x,y): #行う計算 return x+y identity=0 #単位元 def stcreate(N:int): #セグメント木の生成,N=要素数 nl=(N-1).bit_length() ST=[identity]*(2**(nl+1)) return ST def stupdate(ST:list,i:int,x): #値の更新 ci=(len(ST)>>1)+i ST[ci]=x ci>>=1 while ci>0: ...
ConDefects/ConDefects/Code/agc059_a/Python/38137266
condefects-python_data_1973
import sys def input(): return sys.stdin.readline().strip() def mapint(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) N, Q = mapint() S = list(input()) LR = [mapint() for _ in range(Q)] last = "-" diffs = [0]*N for i in range(N): s = S[i] if s!=last: diffs[i] = 1 last = s ...
ConDefects/ConDefects/Code/agc059_a/Python/37052492
condefects-python_data_1974
import sys,os from math import gcd,log from bisect import bisect as bi from collections import defaultdict,Counter input=sys.stdin.readline I = lambda : list(map(int,input().split())) from heapq import heappush,heappop import random as rd tree = [0]*(10**6) def merge(xx,yy): if xx[0]=="": return yy if yy[0]=='':...
ConDefects/ConDefects/Code/agc059_a/Python/37117986
condefects-python_data_1975
def solve(k): if k <= 2: return k if k % 2 == 0: return (k - 2) // 2 + 2 return (k - 1) // 2 + 1 class LazySegTree: "X × G --> X" "Fill in the brackets." X_e = 0 G_e = X_e @classmethod def X_op(cls, x, y): return x + y @classmethod def G_op(cls, a,...
ConDefects/ConDefects/Code/agc059_a/Python/37116120
condefects-python_data_1976
n, q = map(int, input().split()) s = input() pre = [0] * n for i in range(1, n): pre[i] = pre[i-1] + (s[i] != s[i-1]) for i in range(q): l, r = map(int, input().split()) l -= 1 r -= 1 ans = pre[r] - pre[l] ans += s[r] != s[l] print(ans) n, q = map(int, input().split()) s = input() pre = [0...
ConDefects/ConDefects/Code/agc059_a/Python/37644565
condefects-python_data_1977
from itertools import accumulate N, Q = map(int, input().split()) S = input() A = [0]*N for i in range(N-1): if S[i] != S[i+1]: A[i+1] = 1 B = list(accumulate(A)) for _ in range(Q): l, r = map(int, input().split()) l -= 1 r -= 1 x = B[r]-B[l] print(-(-x//2)) from itertools import a...
ConDefects/ConDefects/Code/agc059_a/Python/38508739
condefects-python_data_1978
from collections import defaultdict T = int(input()) def solve2(x: str, y:str) -> bool: cnt_x: defaultdict[str, int] = defaultdict(int) cnt_y: defaultdict[str, int] = defaultdict(int) for c in x: cnt_x[c] += 1 for c in y: cnt_y[c] += 1 if (cnt_x["A"] > cnt_y["A"] or cnt_x["B"] > cn...
ConDefects/ConDefects/Code/arc166_a/Python/50268055
condefects-python_data_1979
T=int(input()) for i in range(T): N,X,Y=map(str,input().split()) flag = True for j in range(int(N)): if Y[j]=="C" and X[j]!="C": flag = False sx="" sy="" for j in range(int(N)): if Y[j]!="C": sx+=X[j] sy+=Y[j] else: ...
ConDefects/ConDefects/Code/arc166_a/Python/48970771
condefects-python_data_1980
S = input() ans = [0] * len(S) for i in range(len(S)): ans[i] = S[i] print(ans) S = input() ans = [0] * len(S) for i in range(len(S)): ans[i] = S[i] print(*ans)
ConDefects/ConDefects/Code/abc329_a/Python/55135985
condefects-python_data_1981
A=list(input()) print("".join(A)) A=list(input()) print(*A)
ConDefects/ConDefects/Code/abc329_a/Python/54463372
condefects-python_data_1982
A = list(input()) print(A) A = list(input()) print(*A)
ConDefects/ConDefects/Code/abc329_a/Python/54918661
condefects-python_data_1983
print([*input()]) print(*[*input()])
ConDefects/ConDefects/Code/abc329_a/Python/54889625
condefects-python_data_1984
from numpy import* P=9998244353 A=array([[216256883,0,410860701,0,415332064,0,11143596,0,841696407,0,0,0],[422024809,216256883,526844238,410860701,940403245,415332064,910241205,11143596,955071971,841696407,0,0],[341556236,0,774017054,0,242578546,0,446580657,0,42392189,0,0,0],[246691192,341556236,837742309,774017054,582...
ConDefects/ConDefects/Code/abc299_h/Python/40885357
condefects-python_data_1985
T = int(input()) a, s = zip(*[map(int, input().split(' ')) for _ in range(T)]) for i in range(T): A = bin(a[i])[2:] S = bin(s[i])[2:] n = len(A) m = len(S) x = a[i] y = a[i] if s[i] < 2*x: print("No") continue elif s[i] == 2*x: print("Yes") continue ...
ConDefects/ConDefects/Code/abc238_d/Python/45717530
condefects-python_data_1986
import sys, re from math import ceil, floor, sqrt, pi, factorial, gcd,sin,cos,tan,asin,acos,atan2,exp,log,log10 from collections import deque, Counter, defaultdict from itertools import product, accumulate from functools import reduce,lru_cache from bisect import bisect from heapq import heapify, heappop, heappush sys....
ConDefects/ConDefects/Code/abc238_d/Python/45053944
condefects-python_data_1987
from collections import * import heapq import bisect INF = float("inf") MOD = 998244353 mod = 998244353 T = int(input()) for _ in range(T): a, s = map(int, input().split()) if 2 * a <= s: print("Yes") else: print("No") from collections import * import heapq import bisect INF = float("in...
ConDefects/ConDefects/Code/abc238_d/Python/45261628
condefects-python_data_1988
T=int(input()) for _ in range(T): a,s=map(int,input().split()) b=s-2*a if b>0 and a&b==0: print('Yes') else: print('No') T=int(input()) for _ in range(T): a,s=map(int,input().split()) b=s-2*a if b>=0 and a&b==0: print('Yes') else: print('No')
ConDefects/ConDefects/Code/abc238_d/Python/45321864
condefects-python_data_1989
inf = 10**12 def calc_1(x,y): if y == 0 and x >= 0: return x return inf def calc_2(x,y): if x == y and x >= 0: return x return inf def calc_12(x,y): if y >= 0 and x >= y: return x return inf def calc_13(x,y): if x >= 0 and y >= 0: return x+y return inf...
ConDefects/ConDefects/Code/abc271_h/Python/35401620
condefects-python_data_1990
T=int(input()) for t in range(T): A,B,S=input().split() A=int(A) B=int(B) S=list(map(int,S)) inf=1<<60 dx=[1,1,0,-1,-1,-1,0,1] dy=[0,1,1,1,0,-1,-1,-1] def solve(A,B,S): S=S[:] if A<0: A=-A S=[S[4],S[3],S[2],S[1],S[0],S[7],S[6],S[5]] if B<0:...
ConDefects/ConDefects/Code/abc271_h/Python/54716396
condefects-python_data_1991
n = int(input()) ans = 0 for i in range(1, int(n**0.5)+1): ans += n//i ans = ans*2 - n print(ans) n = int(input()) ans = 0 for i in range(1, int(n**0.5)+1): ans += n//i ans = ans*2 - (int(n**0.5))**2 print(ans)
ConDefects/ConDefects/Code/abc230_e/Python/45074707
condefects-python_data_1992
n = int(input()) li = list(map(int,input().split())) cnt = 0 per = n-2 for i in range(n-1): li[i] -= 1 while(True): if(li[per] == 0): cnt += 1 print(cnt) break else: cnt += 1 per = li[per-1] n = int(input()) li = list(map(int,input().split())) cnt = 0 per = n-2 for i in range(n-1): ...
ConDefects/ConDefects/Code/abc263_b/Python/45056655
condefects-python_data_1993
n=int(input()) p=list(map(int, input().split())) h=p[-1] ans=0 while h!=1: h=p[h-2] ans+=1 if p[-1]==1: print(1) else: print(ans) n=int(input()) p=list(map(int, input().split())) h=p[-1] ans=0 while h!=1: h=p[h-2] ans+=1 if p[-1]==1: print(1) else: print(ans+1)
ConDefects/ConDefects/Code/abc263_b/Python/44792447
condefects-python_data_1994
N, M = map(int, input().split()) G = [[0]*N for _ in range(N)] for _ in range(M): A, B, C = map(int, input().split()) G[A-1][B-1] = C G[B-1][A-1] = C from itertools import permutations T = [i for i in range(N)] ans = 0 for t in permutations(T): total = 0 for i in range(len(t)-1): if G[t[i]][t[i+1]] != 0: tota...
ConDefects/ConDefects/Code/abc317_c/Python/54762197
condefects-python_data_1995
from itertools import permutations n, m = map(int, input().split()) graph = [[0]*(n+1) for i in range(n+1)] for i in range(m): a,b,c = map(int, input().split()) graph[a][b] = c graph[b][a] = c # for i in range(1,n+1): # print(*graph[i]) P = permutations(range(1,n+1)) ans = 0 for p in P: s = 0 for j in ra...
ConDefects/ConDefects/Code/abc317_c/Python/54776081
condefects-python_data_1996
N, M = map(int, input().split()) G = [[0]*N for _ in range(N)] for _ in range(M): A, B, C = map(int, input().split()) G[A-1][B-1] = C G[B-1][A-1] = C dist = 0 visited = [-1]*N def rec(v, cost): visited[v] = 0 global dist if cost > dist: dist = cost for v2 in range(N): if visited[v2] == -1: rec(v2, cost+G[...
ConDefects/ConDefects/Code/abc317_c/Python/54762079
condefects-python_data_1997
from collections import deque import heapq m=int(input()) v=[tuple(map(int,input().split())) for i in range(m)] p=list(map(int,input().split())) p=list(set(p)^set(range(1,10)))+p p=[i-1 for i in p] p=tuple([p.index(i) for i in range(9)]) g={i:[] for i in range(9)} for i in range(m): a,b=v[i] g[a-1]+=[b-1] g...
ConDefects/ConDefects/Code/abc224_d/Python/44885115
condefects-python_data_1998
import sys, random input = lambda : sys.stdin.readline().rstrip() write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x)) debug = lambda x: sys.stderr.write(x+"\n") YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18 LI = lambda : list(map(int, input().split()));...
ConDefects/ConDefects/Code/arc154_d/Python/38323187
condefects-python_data_1999
def out(a, b, c): print('?', a, b, c, flush=True) def inp(): return S.index(input()) N = int(input()) S = ['No', 'Yes'] pos1 = 1 for i in range(2, N+1): out(i, i, pos1) if not inp(): pos1 = i P = [[i] for i in range(1, N+1)] while len(P) > 1: nP = [] for i in range(0, len(P), 2): ...
ConDefects/ConDefects/Code/arc154_d/Python/38323705
condefects-python_data_2000
from sys import stdin input=lambda :stdin.readline()[:-1] def ask(i,j,k): print('?',i+1,j+1,k+1,flush=True) res=input() return res=='Yes' n=int(input()) if n==1: print('!',1) exit() one=0 for i in range(1,n): if ask(i,i,one): one=i now=[one] for i in range(n): if i==one: continue ng,ok=-1,l...
ConDefects/ConDefects/Code/arc154_d/Python/38267983