id
stringlengths
24
27
content
stringlengths
37
384k
max_stars_repo_path
stringlengths
51
51
condefects-python_data_2001
from functools import* def ask(i,j,k): print('?',i+1,j+1,k+1) return input() == "No" n = int(input()) p = 0 for i in range(1,n): if ask(i,i,p): p = i P = [0]*n def cmp(i,j): return ask(p,i,j) for p,i in enumerate(sorted(range(n),key=cmp_to_key(cmp)),1): P[i] = p print('!',*P) from functools import* def a...
ConDefects/ConDefects/Code/arc154_d/Python/38556628
condefects-python_data_2002
from random import shuffle def judge(i, j, k): # print("i, j, k =", i, j, k) if X[i] + X[j] + 1 > X[k]: # print(">> Yes") return 1 # print(">> No") return 0 def ask(i, j, k): if 1 or not DEBUG: print("?", i + 1, j + 1, k + 1) if DEBUG: return judge(i, j, k) r...
ConDefects/ConDefects/Code/arc154_d/Python/38271304
condefects-python_data_2003
from functools import cmp_to_key def ask(i,j,k): print("?",i,j,k) return input() == "Yes" class box(): def __init__(self,i): self.i = i def __lt__(self,other): return ask(other.i,now,self.i) N = int(input()) for i in range(3703): ask(1,1,1) now = 1 for i in range(2,N+1): if ask(now,now,i...
ConDefects/ConDefects/Code/arc154_d/Python/43287084
condefects-python_data_2004
import sys def resolve(): input = sys.stdin.readline memo = {} def q(i, j, k): if i > j: i, j = j, i t = (i, j, k) if t in memo: return memo[t] if i == k or j == k: return True print("?", i, j, k, flush=True) memo[t] = in...
ConDefects/ConDefects/Code/arc154_d/Python/38487427
condefects-python_data_2005
n=int(input()) mn=0 for q in range(1,n): print("?",mn+1,mn+1,q+1) s=input() if s=="Yes": mn=q Ans=[0] for q in range(1,n): ansa=0 ansb=len(Ans) while ansa!=ansb: vid=ansa+(ansb-ansa)//2 print("?",vid+1,mn+1,q+1) s=input() if s=="Yes": ansb=vid ...
ConDefects/ConDefects/Code/arc154_d/Python/38265701
condefects-python_data_2006
def func(): # 入力を取得 S = input() print(sorted(S)) if __name__ == '__main__': func() def func(): # 入力を取得 S = input() print(*sorted(S), sep='') if __name__ == '__main__': func()
ConDefects/ConDefects/Code/abc242_b/Python/45803292
condefects-python_data_2007
n = int(input()) q = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) from ortools.sat.python import cp_model import sys model = cp_model.CpModel() ub = 10**6 + 10 x = model.NewIntVar(0, ub, 'x') y = model.NewIntVar(0, ub, 'y') for i in range(n): model.Add...
ConDefects/ConDefects/Code/abc338_c/Python/54431526
condefects-python_data_2008
n=int(input()) q=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) am=10**6 for i in range(n): if a[i]==0: continue if am>q[i]//a[i]: am=q[i]//a[i] bm=10**6 for i in range(n): if b[i]==0: continue if bm>q[i]//b[i]: bm=q[i]//...
ConDefects/ConDefects/Code/abc338_c/Python/54514586
condefects-python_data_2009
N = int(input()) Q,A,B = list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split())) ans = 0 Acnt,Bcnt = 0,0 while all(x >= 0 for x in Q): Q = [x - y for x, y in zip(Q, A)] Acnt += 1 Q = [x + y for x, y in zip(Q, A)] Acnt -=1 ans = max(ans,Acnt) print("A :",Acnt) while Acnt>=0: ...
ConDefects/ConDefects/Code/abc338_c/Python/54294909
condefects-python_data_2010
N = int(input()) material = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) def canmake(K): #K人分の料理を作れるか判定 judge = False for i in range(K): local_judge = True for j in range(N): if A[j]*i + B[j]*(K-i) > material[j]: local_judge = False ...
ConDefects/ConDefects/Code/abc338_c/Python/54397398
condefects-python_data_2011
n = int(input()) q = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) def solve(p): #ans = False for j in range(p+1): flag = True for i in range(n): if j*a[i]+(p-j)*b[i]>q[i]: flag = False break if flag ==True: return Tr...
ConDefects/ConDefects/Code/abc338_c/Python/54499412
condefects-python_data_2012
n=int(input()) q=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) ans=0 inf=float("inf") for x in range(max(q)+1): y=inf for i in range(n): if q[i]<x*a[i]: y=-inf break elif b[i]>0: y=min((q[i]-x*a[i])//b[i],x) ...
ConDefects/ConDefects/Code/abc338_c/Python/54491236
condefects-python_data_2013
n = int(input()) q_s = list(map(int, input().split())) a_s = list(map(int, input().split())) b_s = list(map(int, input().split())) max_num = 0 flag = False for i in range(10**6): number_of_a = i for j in range(n): if b_s[j] == 0: continue number_of_b = (q_s[j] - a_s[j] * number_of_...
ConDefects/ConDefects/Code/abc338_c/Python/54924810
condefects-python_data_2014
n=int(input()) q=tuple(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) amax=10**7 bmax=10**7 for k,i in enumerate(a): if i!=0: x=q[k]//i if x <amax: amax=x x=0 for k,i in enumerate(b): if i!=0: x=q[k]//i if x <bmax: ...
ConDefects/ConDefects/Code/abc338_c/Python/54437216
condefects-python_data_2015
n=int(input()) count=0 for i in range (n): s=input() if s=="for": count= count+1 if count > n/2: print("Yes") else: print("No") n=int(input()) count=0 for i in range (n): s=input() if s=="For": count= count+1 if count > n/2: print("Yes") else: print("No")
ConDefects/ConDefects/Code/abc287_a/Python/45997845
condefects-python_data_2016
n=int(input()) count=0 for i in range (n): s=input() if s=="For": count=count+1 print(s,count) print(count) if count >n/2: print("Yes") else: print("No") n=int(input()) count=0 for i in range (n): s=input() if s=="For": count=count+1 if count >n/2: print("Yes") else: ...
ConDefects/ConDefects/Code/abc287_a/Python/45997981
condefects-python_data_2017
n = int(input()) result = 0 for _ in range(n): if "For" == input(): result += 1 if result >= n // 2: print("Yes") else: print("No") n = int(input()) result = 0 for _ in range(n): if "For" == input(): result += 1 if result > n // 2: print("Yes") else: print("No")
ConDefects/ConDefects/Code/abc287_a/Python/45662090
condefects-python_data_2018
n = int(input()) count = 0 for i in range(n): a = input() if a == 'for': count= count + 1 else : count=count if count > n/2 : print('Yes') else: print('No') n = int(input()) count = 0 for i in range(n): a = input() if a == 'For': count= count + 1 else : c...
ConDefects/ConDefects/Code/abc287_a/Python/45997889
condefects-python_data_2019
n=int(input()) count=0 for i in range(n): s=input() if s=="For": count=count+1 print(s,count) print(count) if count>n/2: print("Yes") else: print("No") n=int(input()) count=0 for i in range(n): s=input() if s=="For": count=count+1 if count>n/2: print("Yes") else: ...
ConDefects/ConDefects/Code/abc287_a/Python/45997875
condefects-python_data_2020
h,w=list(map(int,input().split())) a=[input() for _ in range(h)] n=int(input()) rce=[list(map(int,input().split())) for _ in range(n)] rc={(rce[i][0]-1,rce[i][1]-1):rce[i][2] for i in range(n)} for i in range(h): for j in range(w): if a[i][j]=="S": s=(i,j) if a[i][j]=="T": t...
ConDefects/ConDefects/Code/abc348_d/Python/54754604
condefects-python_data_2021
s,t,m=map(int,input().split()) dp=[[-1]*t for i in range(t)] g=[[] for i in range(s)] for i in range(m): a,b=map(int,input().split()) g[a-1].append(b-s-1) for i in range(s): if not g[i]: continue for x in g[i]: for y in g[i]: if x==y: continue if dp[x][y]!=-1: exit(print(x+t,...
ConDefects/ConDefects/Code/abc260_f/Python/46046400
condefects-python_data_2022
n,m = map(int,input().split()) hunaka = [[1] * n for _ in range(n)] for _ in range(m): a = list(map(int,input().split())) for i in range (n-1): x,y = a[i],a[i+1] hunaka[x-1][y-1]=0 hunaka[y-1][x-1]=0 ans = sum(sum(row) for row in hunaka) - n print(ans/2) n,m = map(int,input().split()) h...
ConDefects/ConDefects/Code/abc303_b/Python/45560009
condefects-python_data_2023
n=int(input()) tx=[list(map(int,input().split())) for _ in range(n)] K_max,k=0,0 ans=[] cnt=[0]*(n+1) for t,x in tx[::-1]: if t==1: if cnt[x]<0: cnt[x]+=1 ans.append(1) else: ans.append(0) k-=1 else: cnt[x]-=1 k+=1 K_max=max(K_max,k) if min(cnt)==0: print(K_max)...
ConDefects/ConDefects/Code/abc333_e/Python/52477249
condefects-python_data_2024
from collections import deque n = int(input()) a = [list(map(int,input().split())) for i in range(n)] d = {} s = [0] * n b = [] ans = 0 for i in range(n): if a[i][0] == 1: x = a[i][1] if x in d: d[x].append(i) else: d[x] = deque([i]) for i in range(n): if a...
ConDefects/ConDefects/Code/abc333_e/Python/53773546
condefects-python_data_2025
from collections import deque n=int(input()) A=[] for i in range(n+1): A.append(deque()) Q=[] for i in range(n): t,x=map(int,input().split()) Q.append([t,x]) S=set() for i in range(n-1,-1,-1): t,x=Q[i][0],Q[i][1] if t==1: if len(A[x])>0: A[x].pop() S.add(i) ...
ConDefects/ConDefects/Code/abc333_e/Python/52260050
condefects-python_data_2026
from collections import defaultdict def main(): N = ini() orders = [] essential = defaultdict(list) for i in range(N): t, x = mapint() orders.append((t, x)) if t == 1: essential[x].append(i) essential_list = [] for i in range(N-1, -1, -1): ...
ConDefects/ConDefects/Code/abc333_e/Python/52758263
condefects-python_data_2027
import sys readline = sys.stdin.readline #n = int(readline()) #*a, = map(int,readline().split()) # b = [list(map(int,readline().split())) for _ in range()] n,k = map(int,readline().split()) s = readline().strip() y = s.count("Y") x = n-y if x <= k: # x を全部 y に変える # y のうち k 個を x に変える k -= x s = ["X" ...
ConDefects/ConDefects/Code/arc157_b/Python/42828291
condefects-python_data_2028
N,K = map(int,input().split()) S = input() X = S.count("X") if X < K: K = N-K T = [] for s in S: if s == "X": T.append("Y") else: T.append("X") S = T if all(s == "X" for s in S): print(K-1) exit() C = [10**6] state = 0 cnt = 0 ans = 0 for i in range(1,...
ConDefects/ConDefects/Code/arc157_b/Python/43416351
condefects-python_data_2029
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readli...
ConDefects/ConDefects/Code/arc157_b/Python/44930646
condefects-python_data_2030
import sys N, K = map(int,input().split()) S = list(input()) x_cnt = 0 for i in range(N): if S[i] == "X": x_cnt += 1 if N == 1: print(0) sys.exit() if x_cnt < K: for i in range(N): if S[i] == "X": S[i] = "Y" elif S[i] == "Y": S[i] = "X" K = N-K...
ConDefects/ConDefects/Code/arc157_b/Python/43913220
condefects-python_data_2031
N,K=map(int,input().split()) S=list(input())+["Z"] xcount=0 for i in range(N): if S[i]=="X": xcount+=1 if K>xcount: for i in range(N): if S[i]=="X": S[i]="Y" elif S[i]=="Y": S[i]="X" K=K-xcount hq=[] from heapq import * heapify(hq) for i in range(N+1): if...
ConDefects/ConDefects/Code/arc157_b/Python/43050544
condefects-python_data_2032
def solve(k, s): res = 0 lst = [] for s_i in s: if lst and lst[-1][0] == s_i:lst[-1][1] += 1 else:lst.append([s_i, 1]) x, edge_x = [], 0 for i in range(len(lst)): l_i, cnt = lst[i] if i in [0, len(lst) - 1] and l_i == "X":edge_x += cnt elif l_i == "X":x.append...
ConDefects/ConDefects/Code/arc157_b/Python/45276579
condefects-python_data_2033
H = int(input()) now = 0 day = 0 while now <= H: now = 2**day day += 1 print(day) H = int(input()) now = 0 day = 0 while now <= H: now+= 1<<day day += 1 print(day)
ConDefects/ConDefects/Code/abc354_a/Python/54993286
condefects-python_data_2034
from math import log2, ceil def strict_ceil(number): if number == ceil(number): return number + 1 return ceil(number) H = int(input()) print(strict_ceil(log2(H + 1))) from math import log2, ceil def strict_ceil(number): if number == ceil(number): return int(number + 1) return ceil(nu...
ConDefects/ConDefects/Code/abc354_a/Python/54934155
condefects-python_data_2035
N = int(input()) P = 0 i = 0 while (N > P): P += 2 ** i i += 1 print(i) N = int(input()) P = 0 i = 0 while (N >= P): P += 2 ** i i += 1 print(i)
ConDefects/ConDefects/Code/abc354_a/Python/54982154
condefects-python_data_2036
H = int(input()) a = 0 i = 1 while True: a = a + 2 ** i i += 1 if a > H: print(i) break H = int(input()) a = 0 i = 1 while True: a = a + 2 ** i i += 1 if a >= H: print(i) break
ConDefects/ConDefects/Code/abc354_a/Python/55041411
condefects-python_data_2037
H = int(input()) for i in range(H): n = (2 ** i) - 1 if H < n: print(i) break H = int(input()) for i in range(10 ** 9): n = (2 ** i) - 1 if H < n: print(i) break
ConDefects/ConDefects/Code/abc354_a/Python/54981924
condefects-python_data_2038
h = int(input()) cnt = 0 plant = 0 while plant < h: plant = plant + 2**cnt cnt += 1 print(cnt) h = int(input()) cnt = 1 plant = 0 while plant < h: plant = plant + 2**cnt cnt += 1 print(cnt)
ConDefects/ConDefects/Code/abc354_a/Python/55104399
condefects-python_data_2039
H = int(input()) P = 0 for i in range(H): P += pow(2, i) if P > H: print(i + 1) break H = int(input()) P = 0 for i in range(H + 1): P += pow(2, i) if P > H: print(i + 1) break
ConDefects/ConDefects/Code/abc354_a/Python/54981846
condefects-python_data_2040
H = int(input()) height = 0 days = 1 while height <= H: height += 2 ** days days += 1 print(days) H = int(input()) height = 0 days = 0 while height <= H: height += 2 ** days days += 1 print(days)
ConDefects/ConDefects/Code/abc354_a/Python/54935160
condefects-python_data_2041
(n,x,y),a,b=[[*map(int,s.split())]for s in open(0)] INF=1<<60 dp=[INF]*(1<<n) dp[0]=0 for s in range(1<<n): c=s.bit_count() for i in range(n): if s>>i&1: continue d=str(bin(s)[i+2:]).count('1') dp[s|(1<<i)]=min(dp[s|(1<<i)],dp[s]+(i+d-c)*y+abs(a[i]-b[c])*x) print(dp[-1]) (n,x,y),a,b=[[*map(int,s....
ConDefects/ConDefects/Code/abc232_f/Python/54006538
condefects-python_data_2042
N,A,B,P,Q=map(int,input().split()) mod=998244353 def sugoroku(X,start): dp=[[0 for _ in range(N+1)] for _ in range(N+1)] dp[0][start]=1 for i in range(N): for j in range(N+1): for k in range(1,X+1): denominator=pow(X,-1,mod) if j+k>=N: ...
ConDefects/ConDefects/Code/abc298_e/Python/46008577
condefects-python_data_2043
A = list(map(int, input().split())) ans = 0 for i in range(64): ans += A[i] * 2 ** A[i] print(ans) A = list(map(int, input().split())) ans = 0 for i in range(64): ans += A[i] * (2 ** i) print(ans)
ConDefects/ConDefects/Code/abc306_b/Python/45767909
condefects-python_data_2044
A = list(map(int,input().split())) S = 0 import math for i in range(63): S = S + A[i]*(pow(2,i)) print(S) A = list(map(int,input().split())) S = 0 import math for i in range(64): S = S + A[i]*(pow(2,i)) print(S)
ConDefects/ConDefects/Code/abc306_b/Python/45442211
condefects-python_data_2045
import sys input = lambda: sys.stdin.readline().strip() a = list(map(int, input().split())) ans = 0 for i in range(63): if a[i] == 0: continue else: ans += (2 ** i) print(ans) import sys input = lambda: sys.stdin.readline().strip() a = list(map(int, input().split())) ans = 0 for i in range(...
ConDefects/ConDefects/Code/abc306_b/Python/45523037
condefects-python_data_2046
# https://atcoder.jp/contests/arc173/tasks/arc173_b import sys; input: lambda _: sys.stdin.readline().rstrip() # import pypyjit; pypyjit.set_param('max_unroll_recursion=-1') sys.setrecursionlimit(10001000) int1=lambda x: int(x) - 1 def isonline(u, v, w): dw0, dw1 = w[0] - u[0], w[1] - u[1] dv0, dv1 = v[0] - u[...
ConDefects/ConDefects/Code/arc173_b/Python/52906431
condefects-python_data_2047
from math import floor line_dict = {} n = int(input()) points = [] for i in range(n): x, y = map(int, input().split()) points.append((x, y)) for i in range(n): for j in range(i + 1, n): if points[i][0] - points[j][0] == 0: key = f"slope:inf, intercept:{points[i][0]}" if line...
ConDefects/ConDefects/Code/arc173_b/Python/51178140
condefects-python_data_2048
N=int(input()) P=[list(map(int,input().split())) for i in range(N)] lin={} for i in range(N-1): a,b=P[i] for j in range(i+1,N): c,d=P[j] lin=[b-d,c-a,a*b-b*c] count=0 for k in range(N): x,y=P[k] if lin[0]*x+lin[1]*y+lin[2]==0: count+=1 ...
ConDefects/ConDefects/Code/arc173_b/Python/51168394
condefects-python_data_2049
n = int(input()) import sys input = sys.stdin.readline mp = map(int, sys.stdin.read().split()) xy = list(zip(mp,mp)) stack = [] cnt = 0 ans = 0 for i in range(n): if cnt < 2: stack.append(i) cnt += 1 continue xi,yi = xy[i] flag = False for ji in range(cnt): if flag...
ConDefects/ConDefects/Code/arc173_b/Python/51157170
condefects-python_data_2050
M = int(input()) D = list(map(int, input().split())) middleD = (sum(D)+1)/2 sumD = 0 for i in range(M): sumD += D[i] if sumD >= middleD: print(i+1, middleD - sumD + D[i]) break M = int(input()) D = list(map(int, input().split())) middleD = int((sum(D)+1)/2) sumD = 0 for i in range(M): sumD += D[i] if...
ConDefects/ConDefects/Code/abc315_b/Python/46054320
condefects-python_data_2051
M=int(input()) D=list(map(int,input().split())) half=(sum(D)+1)/2 for i in range(M): if half-D[i]<=0: print(i+1,half) break else: half-=D[i] M=int(input()) D=list(map(int,input().split())) half=int((sum(D)+1)/2) for i in range(M): if half-D[i]<=0: print(i+1,half) break else: half-=D[...
ConDefects/ConDefects/Code/abc315_b/Python/46027434
condefects-python_data_2052
m = int(input()) d = list(map(int, input().split())) mid = (sum(d) + 1) // 2 i = 0 while True: if mid - d[i] >=0 and m != 1: mid -= d[i] i += 1 else: print(i+1, mid) break m = int(input()) d = list(map(int, input().split())) mid = (sum(d) + 1) // 2 i = 0 while True: if mid - d[i] > 0 and m !=...
ConDefects/ConDefects/Code/abc315_b/Python/45969003
condefects-python_data_2053
M = int(input()) D = list(map(int, input().split())) X = (sum(D)+1)//2 S = 0 print(X) for i in range(M): S = S + D[i] if S >= X: exit(print(i+1, X-S+D[i])) M = int(input()) D = list(map(int, input().split())) X = (sum(D)+1)//2 S = 0 for i in range(M): S = S + D[i] if S >= X: exit(pri...
ConDefects/ConDefects/Code/abc315_b/Python/45937526
condefects-python_data_2054
M = int(input()) D = list(map(int, input().split())) mid = (sum(D) + 1) // 2 for i in range(M): mid -= D[i] if mid < 0: print(i+1, mid+D[i]) break elif mid == 0: print(i+1, D[i-1]) break M = int(input()) D = list(map(int, input().split())) mid = (sum(D) + 1) // 2 for i i...
ConDefects/ConDefects/Code/abc315_b/Python/46021749
condefects-python_data_2055
N = int(input()) S = input() print(max([S.rfind('A'), S.rfind('B'), S.rfind('C')])+1) N = int(input()) S = input() print(max([S.find('A'), S.find('B'), S.find('C')])+1)
ConDefects/ConDefects/Code/abc311_a/Python/46012329
condefects-python_data_2056
n = int(input()) result = [char for char in input()] flag_a = 0 flag_b = 0 flag_c = 0 for i in range(n): if result[i] == 'A': flag_a = 1 elif result[i] == 'B': flag_b = 1 elif result[i] == 'C': flag_c = 1 if flag_a + flag_b + flag_c == 3: print(i) break n = in...
ConDefects/ConDefects/Code/abc311_a/Python/45962858
condefects-python_data_2057
n = int(input()) s = input() a,b,c = 0,0,0 for i in range(n): if s[i] == 'A': a = 1 if s[i] == 'B': b = 1 if s[i] == 'C': c = 1 if a*b*c == 1: print(i) exit() n = int(input()) s = input() a,b,c = 0,0,0 for i in range(n): if s[i] == 'A': a = 1 if s[i] == 'B': b = 1 if s[i] == '...
ConDefects/ConDefects/Code/abc311_a/Python/45791225
condefects-python_data_2058
N = int(input()) S = input() a = S.find("A") b = S.find("B") c = S.find("C") print(max(a,b,c)) N = int(input()) S = input() a = S.find("A") b = S.find("B") c = S.find("C") print(max(a,b,c)+1)
ConDefects/ConDefects/Code/abc311_a/Python/45775601
condefects-python_data_2059
import sys N=int(input()) S=str(input()) a=0 b=0 c=0 n=0 S=list(S) for i in range(N): if a>=1 and b>=1 and c>=1: print(n) sys.exit() elif S[i]=='A': n+=1 a+=1 elif S[i]=='B': n+=1 b+=1 elif S[i]=='C': n+=1 c+=1 else: n+=1 impor...
ConDefects/ConDefects/Code/abc311_a/Python/46036400
condefects-python_data_2060
from collections import defaultdict mod = 998244353 kaijou = [1] kaijou_ = [1] for i in range(1,2*10**5+1): k = kaijou[-1]*i k %= mod kaijou.append(k) k = pow(k,mod-2,mod) kaijou_.append(k) def comb(n,r): if n < r: return 0 res = kaijou[n] res *= kaijou_[r] res %= mod res *= kaijou_[n-r] r...
ConDefects/ConDefects/Code/abc262_e/Python/44831745
condefects-python_data_2061
n = int(input()) s = input() result = set() ch = s[0] length = 1 result.add((ch, length)) for i in range(1, n): if s[i-1] == s[i]: length += 1 result.add((ch, length)) else: ch = s[i] length = 1 result.add((ch, length)) result = len(result) n = int(input()) s = input() r...
ConDefects/ConDefects/Code/abc329_c/Python/54204891
condefects-python_data_2062
from collections import defaultdict N = int(input()) S = list(input()) d = defaultdict(int) a = 1 for i in range(N-1): if S[i]==S[i+1]: a += 1 else: a = 1 d[S[i]] = max(d[S[i]], a) ans = 0 for i in d.values(): ans += i print(ans) from collections import defaultdict N = int(input()) if N==1: exit(print...
ConDefects/ConDefects/Code/abc329_c/Python/54527271
condefects-python_data_2063
n = int(input()) lsts = list(input()) ords = [ord(x) - ord("a") for x in lsts] apb = [0] * 26 apb[ords[0]] = 1 cnt = 1 for i in range(1,n): if i == n-1: apb[ords[i]] = max(cnt, apb[ords[i]]) continue if ords[i] == ords[i+1]: cnt += 1 continue elif ords[i] != ords[i+1]: ...
ConDefects/ConDefects/Code/abc329_c/Python/54412437
condefects-python_data_2064
def calc1(a, m, t): if t == -1: return len(a) // 2 if len(a) < 2: return 0 bit = 1 << t b = [] c = [] for i in a: if i & bit: c.append(i) else: b.append(i) if m & bit: return calc2(b, c, m, t - 1) else: if len(b) > len(c): b, c = c, b res = len(b) + min((len(c) - len(b)) // 2, ca...
ConDefects/ConDefects/Code/abc304_g/Python/41991921
condefects-python_data_2065
N=int(input()) A=list(map(int,input().split())) limit=(N+1)//2 def f1(d,C,x): if len(C)<=1: return 0 if d==-1: return len(C)//2 c0=[] c1=[] for i in C: if (i>>d)&1==0: c0.append(i) else: c1.append(i) if len(c0)>len(c1): c0,c1=c1,c0...
ConDefects/ConDefects/Code/abc304_g/Python/41999726
condefects-python_data_2066
p=998244353;f=[1,1];e=[1];N=1<<21;R=range for i in R(N):f+=(f[-1]+f[-2])%p, for i in R(2,N,2):e+=e[-1]*f[i]**2%p, for i in[*open(0)][1:]:h,w=map(int,sorted(i.split()));print(e[h]*pow(f[h*2+1],w-h,p)%p) p=998244353;f=[1,1];e=[1];N=1<<21;R=range for i in R(N):f+=(f[-1]+f[-2])%p, for i in R(2,N,2):e+=e[-1]*f[i]**2%p, for...
ConDefects/ConDefects/Code/arc166_c/Python/49538058
condefects-python_data_2067
import sys sys.setrecursionlimit(10**8) from sys import stdin #import numba as nb #from numba import b1, i4, i8, f8 from collections import defaultdict from collections import Counter from collections import deque import heapq #import networkx as nx from itertools import combinations,permutations from functools import ...
ConDefects/ConDefects/Code/arc171_c/Python/50019081
condefects-python_data_2068
P = 998244353 p, g, ig = 998244353, 3, 332748118 W = [pow(g, (p - 1) >> i, p) for i in range(24)] iW = [pow(ig, (p - 1) >> i, p) for i in range(24)] def convolve(a, b): def fft(f): for l in range(k, 0, -1): d = 1 << l - 1 U = [1] for i in range(d): U.appe...
ConDefects/ConDefects/Code/arc171_c/Python/50011378
condefects-python_data_2069
import itertools import copy N=int(input()) R=input() C=input() def solve5(): ite=set(itertools.permutations("ABC..")) ite=tuple(ite) fl=[] for i in range(len(ite)): for j in range(len(ite[i])): if ite[i][j]!=".": fl.append(ite[i][j]) break leng=len(ite) # ans=0 def isOkCol(boar...
ConDefects/ConDefects/Code/abc326_d/Python/52796362
condefects-python_data_2070
from itertools import product from more_itertools import distinct_permutations N = int(input()) R = list(input()) C = list(input()) di = {'A': [], 'B': [], 'C': []} for p in distinct_permutations('ABC' + '.'*(N-3)): for x in p: if x != '.': di[x].append(p) break ok_list = ['.'] * ...
ConDefects/ConDefects/Code/abc326_d/Python/52271253
condefects-python_data_2071
N = int(input()) R,C = input(),input() def dfs(y, x, a): if(y == N): print(a) if(all("".join(sorted([ai[j] for ai in a])).strip('.').strip('.') == "ABC" and "".join([ai[j] for ai in a]).strip('.').strip('.')[0] == C[j] for j in range(N))): print("Yes") print("\n".join("".jo...
ConDefects/ConDefects/Code/abc326_d/Python/54027090
condefects-python_data_2072
import itertools def isok(n,c,a): for j in range(n): cnt=[0,0,0] for i in range(n): if a[i][j]!=".": if cnt==0 and a[i][j]!=c[j]: return False cnt[ord(a[i][j])-ord('A')]+=1 if cnt!=[1,1,1]: return False return Tr...
ConDefects/ConDefects/Code/abc326_d/Python/52906322
condefects-python_data_2073
import sys def ii():return int(sys.stdin.readline().rstrip("\r\n")) def mi():return map(int, sys.stdin.readline().rstrip("\r\n").split()) def lmi():return list(map(int, sys.stdin.readline().rstrip("\r\n").split())) def line_list(n): return [sys.stdin.readline().rstrip("\r\n") for _ in range(n)] def ii_list(n): return [...
ConDefects/ConDefects/Code/abc326_d/Python/53923236
condefects-python_data_2074
n = int(input()) rowLeft, colUp = input(), input() grid = [['.' for _ in range(n)] for _ in range(n)] alphabet = ('A', 'B', 'C', '.') rows = [{'A': False, 'B': False, 'C': False} for _ in range(n)] cols = [{'A': False, 'B': False, 'C': False} for _ in range(n)] rLeftPos = [n] * n cUpPos = [n] * n def valid(r: int, c: ...
ConDefects/ConDefects/Code/abc326_d/Python/54403865
condefects-python_data_2075
import sys input = sys.stdin.readline from itertools import * def check(S): ss = list(zip(*S)) for i, s in enumerate(ss): if s.count('.') != 2: return False if s.count('A') != 1: return False if s.count('B') != 1: return False if s.count('C') != 1: return False for ns in...
ConDefects/ConDefects/Code/abc326_d/Python/53955700
condefects-python_data_2076
N = int(input()) Q = int(input()) query = [list(map(int,input().split())) for _ in range(Q)] box = [[] for _ in range(2*(10**5))] i_in_box =[[] for _ in range(2*(10**5))] for q in query: #print(q) if q[0] == 1: box[q[2]-1].append(q[1]) i_in_box[q[1]-1].append(q[2]) elif q[0] == 2: ...
ConDefects/ConDefects/Code/abc298_c/Python/45807883
condefects-python_data_2077
import sys from collections import defaultdict MOD = 998_244_353 INF = 10**18 N, Q = map(int, sys.stdin.readline().rstrip().split()) A = list(map(int, sys.stdin.readline().rstrip().split())) D = defaultdict(list) for i in range(N): D[A[i]].append(i + 1) print(D) for q in range(Q): x, k = list(map(int, sys.st...
ConDefects/ConDefects/Code/abc235_c/Python/46176667
condefects-python_data_2078
N = int(input()) A = list(map(int, input().split())) # Aに0が入っている場合は、0の個数(n_0)*n - (n_0 + 1)*n_0/2 n_0 = A.count(0) import math import collections # 素因数分解する A = [a for a in A if a != 0] # 0を除外 B = [] # Aの各要素を平方数で割った残りを入れる for i in range(len(A)): a = A[i] for j in range(2,int(math.sqrt(a))+1): if a%(j**...
ConDefects/ConDefects/Code/abc342_d/Python/55039384
condefects-python_data_2079
#!/usr/bin/env python3 from collections import Counter from math import comb from sys import stdin _tokens = (y for x in stdin for y in x.split()) def read(): return next(_tokens) def iread(): return int(next(_tokens)) def prime_factorize(n): if n == 0: return [0] a = [] while n % 2 == 0: ...
ConDefects/ConDefects/Code/abc342_d/Python/54693725
condefects-python_data_2080
N,X = map(int,input().split()) A = list(map(int,input().split())) # A.sort(reverse=True) # if sum(A)-A[0] >= X*(N-1): # print(0) # else: # del A[-1] # print(X - sum(A) + A[0]) # print(X,sum(A),A[0]) # print(A) def check(): for i in range(0,100): A.append(i) A.sort(reverse=True) x = sum(A) - A...
ConDefects/ConDefects/Code/abc321_b/Python/55168667
condefects-python_data_2081
n,x = map(int, input().split()) alist = list(map(int, input().split())) s = sum(alist) mx = max(alist) mn = min(alist) for i in range(100): if s + i - min(mn, i) - max(mx, i) >= x: print(i) exit() print(-1) n,x = map(int, input().split()) alist = list(map(int, input().split())) s = sum(alist) mx = ...
ConDefects/ConDefects/Code/abc321_b/Python/54748415
condefects-python_data_2082
n, x = map(int, input().split()) A = list(map(int, input().split())) A.sort() ans = float("inf") for i in range(101): A.append(i) A.sort() a = sum(A[1:-1]) if a == x: ans = i break A.remove(i) print(ans if ans!=float("inf") else -1) n, x = map(int, input().split()) A = list(map(int, input().split()...
ConDefects/ConDefects/Code/abc321_b/Python/54705590
condefects-python_data_2083
import math x,y = map(int,input().split()) print(math.ceil((y-x)/10)) import math x,y = map(int,input().split()) print(math.ceil(max((y-x),0)/10))
ConDefects/ConDefects/Code/abc233_a/Python/45939689
condefects-python_data_2084
X,Y = map(int, input().split()) if X >= Y: print(0) exit() else: print((Y-X)//10+1) X,Y = map(int, input().split()) if X >= Y: print(0) exit() elif((Y-X)%10==0): print((Y-X)//10) else: print((Y-X)//10+1)
ConDefects/ConDefects/Code/abc233_a/Python/45723931
condefects-python_data_2085
A,B,D = map(int, input().split()) X=[] while A<=B: X.append(A) A+=D print(X) A,B,D = map(int, input().split()) X=[] while A<=B: X.append(A) A+=D print(*X)
ConDefects/ConDefects/Code/abc340_a/Python/54645367
condefects-python_data_2086
A,B,D=map(int,input().split()) for i in range(A,B,2): print(i,end=" ") print(B) A,B,D=map(int,input().split()) for i in range(A,B,D): print(i,end=" ") print(B)
ConDefects/ConDefects/Code/abc340_a/Python/54976696
condefects-python_data_2087
A,B,D=map(int,input().split()) ans=[A] while A<=B: ans.append(A+D) A+=D print(*ans) A,B,D=map(int,input().split()) ans=[A] while A+D<=B: ans.append(A+D) A+=D print(*ans)
ConDefects/ConDefects/Code/abc340_a/Python/54522310
condefects-python_data_2088
#!/usr/bin/env python3 import sys import math import bisect from heapq import heapify, heappop, heappush from collections import deque, defaultdict, Counter from functools import cache from fractions import Fraction from itertools import accumulate, combinations, permutations, product from sortedcontainers import Sorte...
ConDefects/ConDefects/Code/abc329_b/Python/54730859
condefects-python_data_2089
#頂点は1-index,下段は0-index class LazySegTree: #単位元と結合と作用をここで定義 Xunit = (0,1) Aunit = 0 def Xf(self,x,y): return (x[0] + y[0],x[1] + y[1]) #Xf = max def Af(self,a,b): return a + b #AのXへの作用 def operate(self,x,a): return (x[0] + a * x[1],x[1]) def __in...
ConDefects/ConDefects/Code/abc342_f/Python/50665510
condefects-python_data_2090
N,L,D = map(int,input().split()) M = max(N+10,L+D+10) #ディーラがiを通る確率 & 累積ver dpd = [0]*(M) dpdr = [0]*(M) dpd[0] = 1 dpdr[0] = 1 for i in range(1,L+D): l = max(0,i-D) r = min(i-1,L-1) if l != 0: dpd[i] = (dpdr[r]-dpdr[l-1])/D else: dpd[i] = (dpdr[r])/D dpdr[i] = dpdr[i-1]+dpd[i] #ディーラが最終的にiにいる確率 dp...
ConDefects/ConDefects/Code/abc342_f/Python/50697688
condefects-python_data_2091
class Dual_Fenwick_Tree: def __init__(self, n): self._n = n + 1 self.data = [0] * (n + 1) 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): assert 0 <= l <=...
ConDefects/ConDefects/Code/abc342_f/Python/54509689
condefects-python_data_2092
# -*- coding: utf-8 -*- H, W = [int(s) for s in input().split(' ')] A = [] ans = [] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for i in range(H): A = [int(s) for s in input().split(' ')] preAns = [] for a in A: if 0 == a: preAns.append('.') else: preAns.append(alphabet[a...
ConDefects/ConDefects/Code/abc294_b/Python/46049020
condefects-python_data_2093
H,W = map(int,input().split()) A = [[int(i) for i in input().split()]for j in range(H)] ans = [["." for h in range(W)] for w in range(H)] for i in range(H): for j in range(W): if A[i][j] == 0: continue ans[i][j] = chr(64 + A[i][j]) for i in range(H): for j in range(W): if W...
ConDefects/ConDefects/Code/abc294_b/Python/46002739
condefects-python_data_2094
H, W = map(int, input().split()) A = [] for _ in range(H): A.append(list(map(int, input().split()))) strings = [] for i in range(H): s = "" for j in range(W): if A[i][j] == 0: s += "." else: s += chr(ord('A') + A[i][j] + 1) strings.append(s) for s in strings: ...
ConDefects/ConDefects/Code/abc294_b/Python/46001863
condefects-python_data_2095
import sys readline=sys.stdin.readline def SCC(N,edges): start = [0] * (N + 1) elist = [0] * len(edges) for e in edges: start[e[0] + 1] += 1 for i in range(1, N + 1): start[i] += start[i - 1] counter = start[:] for e in edges: elist[counter[e[0]]] = e[1] counter[...
ConDefects/ConDefects/Code/abc277_h/Python/41713007
condefects-python_data_2096
from random import randint, shuffle from math import gcd, log2, log, sqrt, hypot, pi, degrees from fractions import Fraction from bisect import bisect_left, bisect_right from itertools import accumulate, permutations, combinations, product, chain, groupby from sortedcontainers import SortedList from collections import ...
ConDefects/ConDefects/Code/abc349_b/Python/54749110
condefects-python_data_2097
S = input() cnt = [] for s in set(S): cnt.append(S.count(s)) ans = "Yes" for i in range(1,max(cnt)+1): if cnt.count(i) != 2: ans = "No" break print(ans) S = input() cnt = [] for s in set(S): cnt.append(S.count(s)) ans = "Yes" for i in range(1,max(cnt)+1): if (cnt.count(i) != 2) and (c...
ConDefects/ConDefects/Code/abc349_b/Python/54719195
condefects-python_data_2098
import string s = input() alphabets = {i: 0 for i in string.ascii_lowercase} for i in s: if i in alphabets: alphabets[i] += 1 f = True c = 0 for i in range(1,len(s)): for j in alphabets.values(): if i == j: c += 1 if not(c == 0 or c == 2): print("No") exit() ...
ConDefects/ConDefects/Code/abc349_b/Python/54938253
condefects-python_data_2099
S=input() ans="Yes" word_list=[0]*26 for s in S: word_list[ord(s)-ord("a")]+=1 # wordlistの1とか2とかを数えるリストを考える word_count_list=[0]*101 for i in range(1,len(word_list)+1): word_count_list[i]=word_list.count(i) for i in range(1,len(word_count_list)): if word_count_list[i] == 0 or word_count_list[i]== 2: ...
ConDefects/ConDefects/Code/abc349_b/Python/54895344
condefects-python_data_2100
S = input() strgs = list(set(S)) strgs_count = [] results = [] for strg in strgs: strgs_count.append(S.count(strg)) for unique in list(set(strgs_count)): if strgs_count.count(unique) % 2 == 0: result = True results.append(result) else: result = False results.append(result) ...
ConDefects/ConDefects/Code/abc349_b/Python/54765901