id stringlengths 24 27 | content stringlengths 37 384k | max_stars_repo_path stringlengths 51 51 |
|---|---|---|
condefects-python_data_2301 | MOD = 998244353
N, M = map(int, input().split())
ans = 0
for i in range(60):
if (M >> i) & 1:
ans += M // (1 << (i + 1)) * (1 << i) + max(0, (M % (1 << (i + 1))) - (1 << i) + 1)
ans %= MOD
print(ans)
MOD = 998244353
N, M = map(int, input().split())
ans = 0
for i in range(60):
if (M >> i) & 1:
... | ConDefects/ConDefects/Code/abc356_d/Python/55124661 |
condefects-python_data_2302 | N,M = map(int,input().split())
MOD = 998244353
ret = 0
for i in range(60):
if(M and 2**i):
tmp = N // ((2**i)*2)
ret = ret + tmp*(2**i)
tmp = N % ((2**i)*2)
if(tmp >= (2**i)):
ret = ret + tmp - (2**i) + 1
ret = ret % MOD
print(ret)
N,M = map(int,input().split())
... | ConDefects/ConDefects/Code/abc356_d/Python/55026737 |
condefects-python_data_2303 | import sys
import time
import collections
import itertools
import bisect
import copy
import math
import heapq
import random
from collections import deque, Counter, defaultdict
from itertools import accumulate, combinations, permutations, product
from functools import lru_cache
from heapq import heapify, heappush, heapp... | ConDefects/ConDefects/Code/abc356_d/Python/54727857 |
condefects-python_data_2304 | #再起回数を増やす
import sys
sys.setrecursionlimit(10 ** 8)
from collections import defaultdict
#こんな感じで使う
#Dict = defaultdict(list)
def I():
"""
複数列、複数行の入力を縦方向にまとめint型のリストで返却する
入力例 :
A1 B1
A2 B2 -> A = [1,2] B = [B1,B2]
"""
return int(input())
def MI():
"""
スペース区切りで入力を受け取り、mapで返却する
入力... | ConDefects/ConDefects/Code/agc063_b/Python/44136745 |
condefects-python_data_2305 | n = int(input())
A = list(map(int,input().split()))
count1 = 0
count2 = 0
for i in range(n):
a = A[i]
if (a == i+1):
count1 += 1
elif (A[a-1] == i+1):
count2 += 1
if (count1 >= 2):
print(count1 * (count1-1) // 2 + count2//2)
else:
print(count2)
n = int(input())
A = list(map(int,inpu... | ConDefects/ConDefects/Code/abc262_c/Python/44821687 |
condefects-python_data_2306 | n=int(input())
a=list(map(int,input().split()))
s=[list(map(str,input())) for i in range(n)]
q=int(input())
ans=[[[10**9,10**20] for i in range(n)] for i in range(n)]
for i in range(n):
ans[i][i]=[0,a[i]]
for i in range(n):
for j in range(n):
if s[i][j]=="Y":
ans[i][j]=[1,a[i]+a[j]]
for k in range(n):
f... | ConDefects/ConDefects/Code/abc286_e/Python/45479724 |
condefects-python_data_2307 | import collections
N = int(input())
A = list(map(int,input().split()))
S = [list(input()) for _ in range(N)]
max_value = [ [[0,0] for _ in range(N) ] for _ in range(N) ]
for start in range(N):
que = collections.deque([[start,A[start]]])
seen = [-1]*N
seen[start] = 0
while que:
from_i,value... | ConDefects/ConDefects/Code/abc286_e/Python/45217169 |
condefects-python_data_2308 | from collections import deque
n=int(input())
A=list(map(int,input().split()))
S=[input() for i in range(n)]
graph=[[] for i in range(n)]
for i in range(n):
for j in range(n):
if i==j:
continue
if S[i][j]=="Y":
graph[i].append(j)
ans=[[[10**12,-1] for i in range(n)] for j in range(n)]
for i in rang... | ConDefects/ConDefects/Code/abc286_e/Python/46169747 |
condefects-python_data_2309 | T = int(input())
for _ in range(T):
N,M,K = map(int,input().split())
S = input()
cnt = 0
lst = [1]
for i in range(1,len(S)):
if S[i] == S[i-1]:
lst[-1] += 1
else:
lst.append(1)
ans = 0
flag = False
for i in range(len(lst)-1):
if not flag:
... | ConDefects/ConDefects/Code/agc060_b/Python/37547592 |
condefects-python_data_2310 | t = int(input())
for _ in range(t):
n,m,k=map(int,input().split(' '))
s=input()
i=0
l=len(s)
ans=0
while(i<l-1):
if(i+3<=l and (s[i:i+3]=='RDR' or s[i:i+3]=='DRD')):
ans+=1
i+=2
elif(s[i:i+2]=='RD' or s[i:i+2]=='DR'):
ans+=1
i+=1
else:
i+=1
print(ans)
t = in... | ConDefects/ConDefects/Code/agc060_b/Python/41598368 |
condefects-python_data_2311 | def check(aaa):
""" A0とA1に対する操作回数の差分 d を求める """
bbb = aaa.copy()
bbb.append(aaa[0])
for i in range(2, n):
tmp = bbb[i - 1]
bbb[i - 1] -= tmp
bbb[i] += tmp * 2
bbb[i + 1] -= tmp
if bbb[-2] + bbb[-1] != 0:
return None
d, m = divmod(bbb[-2], len(aaa))
... | ConDefects/ConDefects/Code/arc129_d/Python/27435812 |
condefects-python_data_2312 | N = int(input())
A = list(map(int,input().split()))
if sum(A) != 0:
print(-1)
exit()
B = [0]
for a in A:
B.append(B[-1] + a)
sb = sum(B)
if sb%N != 0:
print(-1)
exit()
ans = abs(sb)//N
if sb > 0:
for i in range(1,N):
B[i] -= sb//N
B[N-1] -= sb//N
if sb < 0:
for i in range(1,N... | ConDefects/ConDefects/Code/arc129_d/Python/27941784 |
condefects-python_data_2313 | import sys
input = sys.stdin.readline
N=int(input())
A=list(map(int,input().split()))
if sum(A)!=0:
print(-1)
exit()
S=[0]
for a in A:
S.append(S[-1]+a)
x=sum(S)
if x%N!=0:
print(-1)
exit()
#print(x,S)
if x<0:
ANS=-x//N
A[0]+=ANS*2
A[1]-=ANS
A[-1]-=ANS
elif x>0:
ANS=x//N
... | ConDefects/ConDefects/Code/arc129_d/Python/27452332 |
condefects-python_data_2314 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
def solve():
INF = 10**18
#INF = 10**2
N, M = map(int, input().split())
Ass = [[0]*(N+2)] + [[0]+list(map(int, input().split())) for _ in range(N)]
accss = [[0]*(N+1) for _ in range(N+1)]
for x in range(1, N+1):
for y ... | ConDefects/ConDefects/Code/abc347_f/Python/52760025 |
condefects-python_data_2315 | #ABC347F
#二次元累積和 Grid[Sh:Gh)[Sw:Gw)の矩形和を求める(半開区間なので注意)
class Csum2D:
def __init__(self,H=1,W=1):
self._H=H; self._W=W; self._G=[[0]*W for _ in range(H)]; self._made=0
def add(self,h,w,x):
if -H<=h<H and -W<=w<W and not self._made: self._G[h][w]+=x; return 1
else: return 0
def build... | ConDefects/ConDefects/Code/abc347_f/Python/51970859 |
condefects-python_data_2316 | S=input()
T=input()
A=["R G B","B R G","G B R"]
if S in A == T in A:
print("Yes")
else:
print("No")
S=input()
T=input()
A=["R G B","B R G","G B R"]
if (S in A) == (T in A):
print("Yes")
else:
print("No") | ConDefects/ConDefects/Code/abc244_d/Python/45311340 |
condefects-python_data_2317 | S=list(input().split())
T=list(input().split())
count=0
for i in range(3):
if S[i]==T[i]:
count+=1
print("Yes") if count!=2 else print("No")
S=list(input().split())
T=list(input().split())
count=0
for i in range(3):
if S[i]!=T[i]:
count+=1
print("Yes") if count!=2 else print("No") | ConDefects/ConDefects/Code/abc244_d/Python/46208474 |
condefects-python_data_2318 | s = input()
t = input()
cnt = 0
for i in range(3):
if s[i] != t[i]:
cnt += 1
if cnt == 0:
print("Yes")
elif cnt == 3:
if t in s + s:
print("Yes")
else:
print("No")
s = input()
t = input()
s = s.replace(' ', '')
t = t.replace(' ', '')
cnt = 0
for i in range(3):
if s[i] != t[i]:
... | ConDefects/ConDefects/Code/abc244_d/Python/45792017 |
condefects-python_data_2319 | S = list(map(str, input().split()))
T = list(map(str, input().split()))
diff = 0
for i in range(3):
if S[i] != T[i]:
diff += 1
if diff % 2 == 0:
print('Yes')
else:
print('No')
S = list(map(str, input().split()))
T = list(map(str, input().split()))
diff = 0
for i in range(3):
if S[i] != T[i]:
... | ConDefects/ConDefects/Code/abc244_d/Python/44600103 |
condefects-python_data_2320 | S = [a for a in input().split()]
T = [a for a in input().split()]
cnt = 0
for i in range(3):
if S[i] == T[i]:
cnt += 1
if cnt%2 == 1:
print("Yes")
else:
print("No")
S = [a for a in input().split()]
T = [a for a in input().split()]
cnt = 0
for i in range(3):
if S[i] == T[i]:
cnt += 1
... | ConDefects/ConDefects/Code/abc244_d/Python/45666207 |
condefects-python_data_2321 | S1,S2,S3 = input().split()
T1,T2,T3 = input().split()
cnt = 0
if S1 != T1:
cnt += 1
if S2 != T2:
cnt += 1
if S3 != T3:
cnt += 1
print("Yes" if cnt%2==0 else "No")
S1,S2,S3 = input().split()
T1,T2,T3 = input().split()
cnt = 0
if S1 != T1:
cnt += 1
if S2 != T2:
cnt += 1
if S3 != T3:
cnt += 1
pri... | ConDefects/ConDefects/Code/abc244_d/Python/46207866 |
condefects-python_data_2322 | 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, choices
from string import ascii_lowercase, ascii_uppercase
from os import envir... | ConDefects/ConDefects/Code/abc244_d/Python/44593613 |
condefects-python_data_2323 | A = ["RGB","GBR","BRG"]
S = input()
T = input()
print('Yes' if (S in A) == (T in A) else 'No')
A = ["R G B","G B R","B R G"]
S = input()
T = input()
print('Yes' if (S in A) == (T in A) else 'No')
| ConDefects/ConDefects/Code/abc244_d/Python/45508442 |
condefects-python_data_2324 | n,l,r = map(int,input().split())
n_l = [0]*(n.bit_length())
for i in range(n.bit_length()):
if n >> i & 1:
n_l[i] = 1
l_d = l.bit_length()
r_d = r.bit_length()
l_l = [0]*(l_d)
r_l = [0]*(r_d)
for i in range(l_d):
if l >> i & 1:
l_l[i] = 1
for i in range(r_d):
if r >> i & 1:
r_l[i] = ... | ConDefects/ConDefects/Code/arc129_a/Python/38752586 |
condefects-python_data_2325 | import sys
input = sys.stdin.readline
n, l, r = map(int, input().split())
out = 0
for i in range(60):
lo = max(l, 1 << i)
hi = min(r + 1, 2 * lo)
if hi >= lo and n & (1 << i):
out += hi - lo
print(out)
import sys
input = sys.stdin.readline
n, l, r = map(int, input().split())
out = 0... | ConDefects/ConDefects/Code/arc129_a/Python/43963825 |
condefects-python_data_2326 | N, L, R = map(int, input().split())
ans = 0
for k in range(100):
if N&(1<<k):
rr = (1 << (k+1)) -1
ll = 1 << k
nums = rr - ll + 1
if R < rr:
nums -= (rr-R)
if ll < L:
nums -= (L-ll)
ans += nums
print(ans)
N, L, R = map(int, input().split())... | ConDefects/ConDefects/Code/arc129_a/Python/37037100 |
condefects-python_data_2327 | n,l,r=map(int,input().split())
ans=0
for i in range(60):
if (n>>i)&1:
ans+=min(r+1,(1<<(i+1)))-max(l,1<<i)
print(ans)
n,l,r=map(int,input().split())
ans=0
for i in range(60):
if (n>>i)&1:
ans+=max(0,min(r+1,(1<<(i+1)))-max(l,1<<i))
print(ans) | ConDefects/ConDefects/Code/arc129_a/Python/37413709 |
condefects-python_data_2328 | n,l,r = map(int,input().split())
z=format(n,'b')
z=int(z)
s=list(str(z))
m=len(s)
ans=0
for i in range(m):
if n>>i&1 == 1:
if 2**i<=l<r<2**(i+1):
ans+=r-l+1
elif 2**i<l<2**(i+1):
ans+=2**(i+1)-l
elif 2**i<=r<2**(i+1):
ans+=r-2**i+1
else:
... | ConDefects/ConDefects/Code/arc129_a/Python/38833629 |
condefects-python_data_2329 | n, l, r = map(int, input().split())
bin_n = bin(n)[2:]
rev = reversed(bin_n)
wari = []
for i, c in enumerate(rev):
if c == '1':
wari.append(2 ** i)
ans = 0
for num in wari:
s = num
e = s * 2 - 1
cnt = min(r, e) - max(l, s) + 1
ans += cnt
print(ans)
n, l, r = map(int, input().split())
b... | ConDefects/ConDefects/Code/arc129_a/Python/44795955 |
condefects-python_data_2330 | N, L, R = map(int, input().split())
n = format(N, 'b')
ans = 0
l = len(n)
x = 2 ** l
for i in range(len(n)):
x = x // 2
if n[i] == '1':
ans += min(R, 2 * x - 1) - max(L, x) + 1
print(ans)
N, L, R = map(int, input().split())
n = format(N, 'b')
ans = 0
l = len(n)
x = 2 ** l
for i in range(len(n)):
x ... | ConDefects/ConDefects/Code/arc129_a/Python/38487358 |
condefects-python_data_2331 | import sys, math
from collections import deque
sys.setrecursionlimit(10 ** 9)
N, L, R = map(int,input().split())
p = N.bit_length()
ans = 0
for i in range(p):
if not (N >> i) & 1:
continue
ups = min(R, (1 << (i + 1)) - 1)
los = max(L, (1 << i))
ans += ups - los + 1
print(ans)
import sys, m... | ConDefects/ConDefects/Code/arc129_a/Python/39058948 |
condefects-python_data_2332 | import sys
from collections import *
from functools import lru_cache, partial
from itertools import *
from pprint import pprint
def debug(*args, end='\n'): print(*args, end=end, file=sys.stderr)
dpprint = partial(pprint, stream=sys.stderr)
sys.setrecursionlimit(10 ** 6)
MOD=998244353
N = int(input())
# p x q^3 <= q... | ConDefects/ConDefects/Code/abc250_d/Python/45811839 |
condefects-python_data_2333 | n = int(input())
prl = [0] *(10**6)
def pr_jg(p):
pr = int(p ** (1/2)) + 1
m = 2
while m <= pr:
if p % m == 0:
return(False)
m += 1
return True
k = int((n//2) ** (1/3))
prl[0] = 2
cur = 1
for i in range(3,k+1):
if pr_jg(i):
prl[cur] = i
cur += 1
maxv = cu... | ConDefects/ConDefects/Code/abc250_d/Python/44996552 |
condefects-python_data_2334 | def enum_primes(n):
prime_flag = [1] * (n + 1)
prime_flag[0] = 0
prime_flag[1] = 0
i = 2
while i * i <= n:
if prime_flag[i]:
for j in range(2 * i, n + 1, i):
prime_flag[j] = 0
i += 1
return [i for i in range(n + 1) if prime_flag[i]]
N=int(input())
n=i... | ConDefects/ConDefects/Code/abc250_d/Python/45025075 |
condefects-python_data_2335 | # エラトステネスの篩
def Eratosthenes(N):
# 素数であるかの判定リスト
IsPrime=[True]*(N+1)
# i=2,3,4,...
i=2
# i≤√Nまで⇔i^2≤Nまで
while i**2<=N:
# iが素数でなければ
if IsPrime[i]==False:
# 次のiへ
i+=1
continue
# k=2,3,4,...
k=2
while i*k<=N:
... | ConDefects/ConDefects/Code/abc250_d/Python/45700046 |
condefects-python_data_2336 | import heapq
n,m,k,l=map(int,input().split())
a=list(map(int,input().split()))
a=[0]+a
b=list(map(int,input().split()))
g=[[] for _ in range(n+1)]
for _ in range(m):
u,v,c=map(int,input().split())
g[u].append([v,c])
g[v].append([u,c])
ans=[[[10**18,-1] for _ in range(2)] for _ in range(n+1)]
hq=[]
for i in r... | ConDefects/ConDefects/Code/abc245_g/Python/51453180 |
condefects-python_data_2337 |
from heapq import heappop, heappush
from typing import List, Tuple
INF = int(4e18)
def abc245g(
n: int, edges: List[Tuple[int, int, int]], colors: List[int], criticals: List[int]
) -> List[int]:
adjList = [[] for _ in range(n)]
for u, v, w in edges:
adjList[u].append((v, w))
adjList[v]... | ConDefects/ConDefects/Code/abc245_g/Python/49870441 |
condefects-python_data_2338 | # import io
# import sys
# _INPUT = """\
# 5 998244353
# """
# sys.stdin = io.StringIO(_INPUT)
n, mod = map(int, input().split())
dp = [[0]*(n+2) for _ in range(n+2)]
dp[0][0] = 1
dp[1][0] = -1
ans = 0
for i in range(n+1):
for j in range(n+1):
if i!=0:
dp[i][j] += dp[i-1][j]
dp[i][j] %= mod
... | ConDefects/ConDefects/Code/abc249_e/Python/51504381 |
condefects-python_data_2339 | n,M=map(int,input().split())
q=[[0]*(n+1) for i in range(n+1)]
q[0][0]=1
q[1][0]=-1
for i in range(n+1):
for j in range(n+1):
q[i][j]+=q[i-1][j]
q[i][j]%=M
for k in range(1,5):
if i+10**(k-1)<=n and j+1+k<=n:
q[i+10**(k-1)][j+1+k]+=q[i][j]*(25+(i==0))
if i+10**k<=n:
q[i+10*... | ConDefects/ConDefects/Code/abc249_e/Python/47998431 |
condefects-python_data_2340 | import sys
input = sys.stdin.readline
from collections import deque,Counter
N,K=map(int,input().split())
A=sorted(map(int,input().split()))
C=Counter(A)
mod=998244353
FACT=[1]
for i in range(1,N+10):
FACT.append(FACT[-1]*i%mod)
now=1
Q=deque(A)
ANS=1
while Q:
if Q[-1]+Q[0]>=K:
Q.pop()
ANS=A... | ConDefects/ConDefects/Code/arc148_e/Python/35986831 |
condefects-python_data_2341 | from collections import Counter
P = 998244353
N, K = map(int, input().split())
nn = N + 10
fa = [1] * (nn+1)
fainv = [1] * (nn+1)
for i in range(nn):
fa[i+1] = fa[i] * (i+1) % P
fainv[-1] = pow(fa[-1], P-2, P)
for i in range(nn)[::-1]:
fainv[i] = fainv[i+1] * (i+1) % P
C = lambda a, b: fa[a] * fainv[b] % P * fa... | ConDefects/ConDefects/Code/arc148_e/Python/35713028 |
condefects-python_data_2342 | N,K=map(int,input().split())
A=sorted([int(x) for x in input().split()])
mod=998244353
d=1
from collections import Counter
C=Counter(A)
for c in C:
for i in range(C[c]):
d*=i+1
d%=mod
x=pow(d,mod-2,mod)
t=1
j=N-1
for i in range(N):
while j>i:
if A[j]+A[i]>=K:
t+=1
else:
break
j-=... | ConDefects/ConDefects/Code/arc148_e/Python/34804387 |
condefects-python_data_2343 | N,K=map(int,input().split())
A=[int(x) for x in input().split()]
mod=998244353
A.sort()
d=1
from collections import Counter
C=Counter(A)
for c in C:
for i in range(C[c]):
d*=i+1
d%=mod
dp=[1,0]
t=0
j=N-1
for i in range(N):
while j>=i:
if A[j]+A[i]>=K:
t+=1
else:
break
j-=1
if... | ConDefects/ConDefects/Code/arc148_e/Python/34801295 |
condefects-python_data_2344 | from collections import Counter
M = 998244353
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
res = 1
j = n-1
fact = [1] * (n+1)
for i in range(1, n+1):
fact[i] = fact[i-1] * i % M
for i, x in enumerate(a):
if x >= (k+1) // 2:
break
while a[j] + x >= k:
res = res * m... | ConDefects/ConDefects/Code/arc148_e/Python/39108367 |
condefects-python_data_2345 | n = int(input())
ans = ""
for i in range(n + 1):
judge = False
for j in range(1,9):
if n % j == 0:
if i % (n / j) == 0:
judge = True
ans += str(j)
break
if judge:
pass
else:
ans += "-"
print(ans)
n = int(input())
ans... | ConDefects/ConDefects/Code/abc319_b/Python/46199988 |
condefects-python_data_2346 | N = int(input())
D=[]
for i in range(1,9):
if N % i ==0:
D.append(i)
S =[1]+["-"]*(N)
for i in range(1,N+1):
for d in D:
if i % (N/d) == 0:
S[i] = d
break
print(*S,sep="")
N = int(input())
D=[]
for i in range(1,10):
if N % i ==0:
D.append(i)
S =[1]+["-"]*(N)
for i in range(1,N+1):... | ConDefects/ConDefects/Code/abc319_b/Python/45808237 |
condefects-python_data_2347 | N = int(input())
def judge_num(num):
for j in range(1,11):
if N % j == 0:
if num % (N / j) == 0:
return str(j)
break
return "-"
ans = str()
for i in range(0, N+1):
ans = ans + judge_num(i)
print(ans)
N = int(input())
def judge_num(num):
for j in range(1,10):
if N % j == 0:
... | ConDefects/ConDefects/Code/abc319_b/Python/45999150 |
condefects-python_data_2348 |
import sympy as sp
def solver():
N = int(input())
divisors = sp.divisors(N)
# divisros のうち1から9までの約数を取り出す
divisors = [i for i in divisors if 1 <= i <= 9]
for i in range(N + 2):
flag = False
for j in divisors:
tmp = N // j
if i % tmp == 0:
p... | ConDefects/ConDefects/Code/abc319_b/Python/45811398 |
condefects-python_data_2349 | n = int(input())
s = ["-"] * (n+1)
for i in range(n+1):
for j in range(1, 9):
if n % j == 0 and i % (n/j) == 0:
s[i] = str(j)
break
result = ''.join(s)
print(result)
n = int(input())
s = ["-"] * (n+1)
for i in range(n+1):
for j in range(1, 10):
if n % j == 0 and i % (n/j) == 0:
s[i] =... | ConDefects/ConDefects/Code/abc319_b/Python/45813638 |
condefects-python_data_2350 | def get_divisors_list(num):
divisors = []
for i in range(1, num+1 if num < 9 else 9):
if num % i == 0:
divisors.append(i)
return divisors
def main():
n = int(input())
divisors = get_divisors_list(n)
answer = ""
for i in range(n+1):
is_found = False
f... | ConDefects/ConDefects/Code/abc319_b/Python/45969465 |
condefects-python_data_2351 | def getInt():
return int(input())
def main():
n = getInt()
a = [j for j in range(1, 9) if n % j == 0]
r = ''
for i in range(n + 1):
x = [b for b in a if i % (n / b) == 0]
if len(x) == 0:
r += '-'
else:
r += str(min(x))
print(r)
if __name__ == "_... | ConDefects/ConDefects/Code/abc319_b/Python/46206496 |
condefects-python_data_2352 | class Centroid_decomposition:
def __init__(self, N, graph):
self._N = N
self._C = C = [dict() for _ in range(N)]
self._B = B = [list() for _ in range(N)]
Q = [(0, -1)]
S = [1] * N
for now,back in Q:
for nxt in G[now]:
if nxt != back: Q.appe... | ConDefects/ConDefects/Code/abc291_h/Python/50116430 |
condefects-python_data_2353 | def Make_Centroid_Tree():
parent = [0] * N
size = [0] * N
used = [0] * N
def dfs(root):
que = [N * N]
order = []
while que:
x = que.pop()
v, u = x % N, x // N
order.append([v, u])
for w in g[v]:
if w == u or used[w]... | ConDefects/ConDefects/Code/abc291_h/Python/51212589 |
condefects-python_data_2354 | N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
def is_ok(mid):
if sum(map(lambda x: x <= mid, A)) >= sum(map(lambda x: x >= mid, B)):
return True
else:
return False
def binary_search(ok, ng):
while ng - ok > 1:
mid = (ok ... | ConDefects/ConDefects/Code/abc312_c/Python/45722260 |
condefects-python_data_2355 | from bisect import bisect_left
def check(k):
x = bisect_left(a, k)
y = m - bisect_left(b, k)
return x >= y
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
ng = -1
ok = 10**10
while abs(ok - ng) > 1:
mid = ok + ng >> 1
if... | ConDefects/ConDefects/Code/abc312_c/Python/45722066 |
condefects-python_data_2356 | N,M=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
from bisect import bisect_right
from bisect import bisect_left
A.sort()
B.sort()
l=0
r=10**9
while l<r:
m=(l+r)//2
a=bisect_right(A,m)
b=M-bisect_left(B,m)
if a>=b:
r=m
else:
l=m+1
print(l... | ConDefects/ConDefects/Code/abc312_c/Python/45923293 |
condefects-python_data_2357 | N,M = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.sort()
B.sort()
amax = A[-1]
bmax = B[-1]
#ok = 10**9
ok = max(amax,bmax)
ng = 0
while abs(ok-ng)>1:
mid = (ok+ng)//2
sell = 0
for a in A:
if a <= mid:
sell += 1
buy = 0
for b... | ConDefects/ConDefects/Code/abc312_c/Python/46004421 |
condefects-python_data_2358 | N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())), reverse=True)
def bisect(ok, ng, solve):
while abs(ok - ng) > 1:
mid = (ng + ok) // 2
if solve(mid):
ok = mid
else:
ng = mid
return ok
def so... | ConDefects/ConDefects/Code/abc312_c/Python/46056572 |
condefects-python_data_2359 | #! /usr/bin/env python3
import numpy as np
import sys
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N, M = map(int, input().rstrip().split())
A = list(map(int, input().rstrip().split()))
B = list(map(int, input().rstrip().split()))
A.sort()
B.sort()
ans = 10**9... | ConDefects/ConDefects/Code/abc312_c/Python/46017936 |
condefects-python_data_2360 | N,M = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
#A,B の判定
def check(x):
#売っても良い人数
anum = 0
for i in A:
if i<= x:
anum += 1
#買ってもいい人数
bnum = 0
for i in B:
if i >= x:
bnum += 1
return True if... | ConDefects/ConDefects/Code/abc312_c/Python/45783776 |
condefects-python_data_2361 | N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort()
B.sort()
mx = max(A[-1],B[-1])
def is_ok(x):
sell = len([a for a in A if a<=x])
buy = len([b for b in B if b>=x])
return sell>=buy
def binary_search(ng, ok):
"""
初期値のng,okを受け取り,is_okを... | ConDefects/ConDefects/Code/abc312_c/Python/46028780 |
condefects-python_data_2362 | N,M = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.sort()
B.sort()
def count_seller(mid):
cnt = 0
for i in range(len(A)):
if A[i] <= mid:
cnt += 1
return cnt
def count_buyer(mid):
cnt = 0
for i in range(len(B)):
if B[... | ConDefects/ConDefects/Code/abc312_c/Python/46019234 |
condefects-python_data_2363 | N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
#A,Bの判定
def check(x):
#売ってもいい人数
anum = 0
for i in A:
if i <= x:
anum += 1
#買ってもいい人数
bnum = 0
for i in B:
if i >= x:
bnum += 1
return ... | ConDefects/ConDefects/Code/abc312_c/Python/45814496 |
condefects-python_data_2364 | # abc312c_InvisibleHand.py
from bisect import bisect_left,bisect_right
N,M = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.sort()
B.sort()
low = 0
high = 10**9
while low +1 < high:
m = (high+low)//2
fx = bisect_right(A,m)
gx = M - bisect_left(B,m)
i... | ConDefects/ConDefects/Code/abc312_c/Python/46161992 |
condefects-python_data_2365 | N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
def check(X):
a = 0
b = 0
for i in range(N):
if A[i] <= X:
a += 1
for i in range(M):
if B[i] >= X:
b += 1
if a >= b:
flag = True
... | ConDefects/ConDefects/Code/abc312_c/Python/45783787 |
condefects-python_data_2366 | r=range
K=int(input().split()[1])
N=int(K**.5)
S=(K-N*N)//2
f=lambda a,b:[print(x,y,a-x-y)for x in r(b)for y in r(b)if x+y<=a and x+y+b>=a]
f(S-2,N)
f(S+N-1,N+1)
f(S+N+N-1,N)
if(K+N*N)%2:print(N,N,N)
r=range
K=int(input().split()[1])
N=int(K**.5)
S=(K-N*N)//2
f=lambda a,b:[print(x,y,a-x-y)for x in r(b)for y in r(b)if ... | ConDefects/ConDefects/Code/arc175_e/Python/51661723 |
condefects-python_data_2367 | a,b=map(int,input().split())
if abs(a-b)== 1 or 9:
print("Yes")
else:
print("No")
a,b=map(int,input().split())
if b - a == 1 or b - a == 9:
print("Yes")
else:
print("No")
| ConDefects/ConDefects/Code/abc240_a/Python/45813906 |
condefects-python_data_2368 | a,b=map(int,input().split())
if abs(a%10-b%10)==1:
print('Yes')
else:print('No')
a,b=map(int,input().split())
if b-a==1 or (a==1 and b==10):
print('Yes')
else:print('No') | ConDefects/ConDefects/Code/abc240_a/Python/45299721 |
condefects-python_data_2369 | a,b=map(int,input().split())
print(['YNeos'[a!=1::2],'YNeos'[b-1!=a::2]][b<10])
a,b=map(int,input().split())
print(['YNeos'[1<a<9::2],'YNeos'[b-1!=a::2]][b<10]) | ConDefects/ConDefects/Code/abc240_a/Python/45200852 |
condefects-python_data_2370 | a,b = map(int,input().split())
if abs(a % 10 - b % 10) == 1:
print("Yes")
else:
print("No")
a,b = map(int,input().split())
if abs(a % 10 - b % 10) in [1,9]:
print("Yes")
else:
print("No") | ConDefects/ConDefects/Code/abc240_a/Python/45439093 |
condefects-python_data_2371 | A,B = map(int,input().split())
if B-A == 1 or A-B == 9:
print("Yes")
else:
print("No")
A,B = map(int,input().split())
if B-A == 1 or B-A == 9:
print("Yes")
else:
print("No") | ConDefects/ConDefects/Code/abc240_a/Python/45456899 |
condefects-python_data_2372 | a, b = map(int, input().split())
if b - a or b - a == 9:
print('Yes')
else:
print('No')
a, b = map(int, input().split())
if b - a == 1 or b - a == 9:
print('Yes')
else:
print('No') | ConDefects/ConDefects/Code/abc240_a/Python/45439558 |
condefects-python_data_2373 | a,b = map(int,input().split())
ok = [(i,i+1) for i in range(9)]
ok.append((1,10))
if (a,b) in ok:
print("Yes")
else:
print("No")
a,b = map(int,input().split())
ok = [(i,i+1) for i in range(1,10)]
ok.append((1,10))
if (a,b) in ok:
print("Yes")
else:
print("No") | ConDefects/ConDefects/Code/abc240_a/Python/46212840 |
condefects-python_data_2374 | 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
fro... | ConDefects/ConDefects/Code/abc281_f/Python/45038482 |
condefects-python_data_2375 | def dfs(digit,A,res):
S = []
T = []
for a in A:
if (a >> digit) & 1:
S.append(a)
else:
T.append(a)
if digit == 0:
global ans
if len(S) == 0:
ans = min(ans,res)
elif len(T) == 0:
ans = min(ans,res)
else:
ans = min(ans,res+1)
return
if len(S) == 0:
d... | ConDefects/ConDefects/Code/abc281_f/Python/45472060 |
condefects-python_data_2376 | import sys
sys.setrecursionlimit(10**6)
# sys.set_int_max_str_digits(10**6)
# mod = 998244353
# ds = [(-1,0),(0,1),(1,0),(0,-1)]
# inf = float('inf')
# ni,nj=i+di,j+dj
# 0<=ni<H and 0<=nj<W
# alph = 'abcdefghijklmnopqrstuvwxyz'
def rint(offset=0,base=10): return list(map(lambda x: int(x, base)+offset, input().split())... | ConDefects/ConDefects/Code/abc320_c/Python/55010802 |
condefects-python_data_2377 | """
cf. https://atcoder.jp/contests/abc288/editorial/5659
"""
INF = 10**12
def solve(n, m, a, c, x):
x = [_-1 for _ in x]
# i番目の商品までで、j個の商品を買ったときに、必要なコスト
cost = [[INF] * n for i in range(n)]
for i in range(n):
cost[i][0] = c[i]
for j in range(1, i+1):
cost[i][j] = min(cost[i]... | ConDefects/ConDefects/Code/abc288_e/Python/41523056 |
condefects-python_data_2378 | from bisect import *
N = int(input())
A = list(map(int, input().split()))
at = [[] for _ in range(N)]
for i, x in enumerate(A):
at[x - 1].append(i)
Q = int(input())
for it in range(Q):
L, R, X = map(int, input().split())
L -= 1
have = bisect_right(at[X - 1], R) - bisect_left(at[X - 1], L)
print(have)
fro... | ConDefects/ConDefects/Code/abc248_d/Python/45763368 |
condefects-python_data_2379 | import sys
from collections import deque,defaultdict
import heapq
import math
import collections
import itertools
import bisect
#sys.setrecursionlimit(10 ** 9)
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
lli = lambda n: [li() fo... | ConDefects/ConDefects/Code/abc248_d/Python/45983434 |
condefects-python_data_2380 | from collections import defaultdict as dd
import bisect
N = int(input())
A =list(map(int, input().split()))
Q = int(input())
idx = [ [] for _ in range(N+1) ]
for i in range(N):
idx[A[i]].append(i+1)
for _ in range(Q):
L,R,X =map(int, input().split())
l = bisect.bisect_left(idx[X], L)
r = bisect.bisect_... | ConDefects/ConDefects/Code/abc248_d/Python/45297242 |
condefects-python_data_2381 | import bisect
N,T = input().split()
N = int(N)
k = len(T)
left = []
right = []
for i in range(N):
s = input()
c = 0
for j in s:
if j == T[c]: c += 1
if c == k: break
left.append(c)
c = 0
for j in s[::-1]:
if j == T[k-1-c]: c += 1
if c == k: break
right.append... | ConDefects/ConDefects/Code/abc324_e/Python/52742757 |
condefects-python_data_2382 | from sortedcontainers import SortedList
n=int(input())
s=[*input()]
cnts=[]
i=0
while i<n:
if s[i]=="R":
for j in range(1,n+5):
if i-j<0 or s[i-j]!='A':
cnta=j-1
break
for j in range(1,n+5):
if i+j>=n or s[i+j]!='C':
cntc=j-1
... | ConDefects/ConDefects/Code/arc140_b/Python/45660608 |
condefects-python_data_2383 | # https://github.com/tatyam-prime/SortedSet/blob/main/SortedMultiset.py
import math
from bisect import bisect_left, bisect_right, insort
from typing import Generic, Iterable, Iterator, TypeVar, Optional, List
T = TypeVar('T')
class SortedMultiset(Generic[T]):
BUCKET_RATIO = 50
REBUILD_RATIO = 170
def _b... | ConDefects/ConDefects/Code/arc140_b/Python/44778158 |
condefects-python_data_2384 | from collections import deque
N=int(input())
S=input()
def solve(N,S):
rs=[]
As,Cs=0,0
st=False
for s in S:
if s=='C':
Cs+=1
else:
if st:
st=False
rs[-1]=min(rs[-1],Cs)
Cs=0
if s=='R':
st=True
... | ConDefects/ConDefects/Code/arc140_b/Python/40407040 |
condefects-python_data_2385 | n=int(input())
s=list(map(str,input()))
R=[]
for i in range(1,n-1):
if s[i]=="R":
R.append(i)
ARCnum=0
ARClen=[]
for k in R:
le=0
nu=0
for i in range(1,min(k+1,n-k)):
if s[k-i]=="A" and s[k+i]=="C":
le+=1
nu=1
else:
ARCnum+=nu
if le>0:
ARClen.append(le-2)
break
... | ConDefects/ConDefects/Code/arc140_b/Python/43246102 |
condefects-python_data_2386 | import heapq
from collections import defaultdict
class MultiSet_Max():
"""
Multi Setクラス
Attributes
--------------------
add_heap : list
追加する要素を集めたヒープキュー
del_heap : list
削除する要素をヒープキュー
"""
def __init__(self):
self.add_heapq = []
self.del_heapq = []
... | ConDefects/ConDefects/Code/arc140_b/Python/45256391 |
condefects-python_data_2387 | from collections import Counter
n=int(input())
A=sorted(list(map(int,input().split())))
M=10**6
acount=[0]*(M+1)
for i in range(n):
acount[A[i]]+=1
for i in range(M):
acount[i+1]+=acount[i]
ans=0
for num,ct in Counter(A).items():
ans+=ct*(ct-1)//2
for j in range(1,M//num):
c=acount[min(M,(j+1)*num-1)]-aco... | ConDefects/ConDefects/Code/abc356_e/Python/54960213 |
condefects-python_data_2388 | #!/usr/bin/env python3
import math
import sys
from bisect import ( # type: ignore
bisect,
bisect_left,
bisect_right,
insort,
insort_left,
insort_right,
)
from collections import Counter, defaultdict, deque # type: ignore
from heapq import ( # type: ignore
heapify,
heappop,
heappus... | ConDefects/ConDefects/Code/abc356_e/Python/54889247 |
condefects-python_data_2389 | from itertools import permutations
N, H, W = map(int, input().split())
A, B = [None]*N, [None]*N
for i in range(N):
A[i], B[i] = map(int, input().split())
def check(p, s):
cnt = 0
S = [[False for _ in range(W)] for _ in range(H)]
for i in range(H):
for j in range(W):
if S[i][j] == ... | ConDefects/ConDefects/Code/abc345_d/Python/54472552 |
condefects-python_data_2390 | from itertools import product
import copy
import sys
sys.setrecursionlimit(1 << 20)
N,H,W = map(int, input().split())
AB = list()
for _ in range(N):
a,b = map(int, input().split())
AB.append([a,b])
global ans
ans = False
C = [ [True for _ in range(W)] for i in range(H)]
check = [0,1,0,1,1]
def dfs(x,y,rem,ma... | ConDefects/ConDefects/Code/abc345_d/Python/54461819 |
condefects-python_data_2391 | def find_first_empty_pos():
for i in range(H):
for j in range(W):
if not G[i][j]:
return i,j
return -1,-1
def is_place(h,w,a,b):
if h+a > H or w+b > W:
return False
for i in range(h,h+a):
for j in range(w,w+b):
if G[i][j] != 0:
... | ConDefects/ConDefects/Code/abc345_d/Python/53727420 |
condefects-python_data_2392 | N = int(input())
grid = [[0 for _ in range(N)] for j in range(N)]
grid[(N+1)//2-1][(N+1)//2-1] = "T"
dir=[[0,1],[1,0],[0,-1],[-1,0]]
dirPath = 0
x=y=0
grid[x][y] = 1
for i in range(2,N**2):
while x+dir[dirPath][0] < 0 or x+dir[dirPath][0] > N-1 or y+dir[dirPath][1] < 0 or y+dir[dirPath][1] > N-1 or grid[x+dir[dir... | ConDefects/ConDefects/Code/abc335_d/Python/53021579 |
condefects-python_data_2393 | import sys
input=sys.stdin.readline
import heapq
N,M,L=map(int,input().split())
A=list(map(int,input().split()))
b=list(map(int,input().split()))
ban=set()
for i in range(L):
p,q=map(int,input().split())
ban.add(p*1000000+q)
B=[[b[i],i+1] for i in range(M)]
#A.sort(reverse=True)
B.sort(reverse=True)
cur=[0]*N... | ConDefects/ConDefects/Code/abc331_e/Python/54003123 |
condefects-python_data_2394 | from collections import defaultdict
def main():
N, M, L = mapint()
A = lint()
B = lint()
unCombSet = defaultdict(set)
is_reverse = False
if N > M:
N, M = M, N
A, B = B, A
is_reverse = True
for i in range(L):
x, y = mapint0()
if is_reverse:
... | ConDefects/ConDefects/Code/abc331_e/Python/52779261 |
condefects-python_data_2395 | N, M, L = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
pat = [list(map(lambda x:int(x)-1, input().split())) for _ in range(L)]
ng_set = set()
for i, j in pat:
ng_set.add((i, j))
#P:Bを価格の大きい順にソートしたものでindexも同時に保持している
P = sorted([(b, j) for j, b in enumerate(B)], ... | ConDefects/ConDefects/Code/abc331_e/Python/53576352 |
condefects-python_data_2396 | # √(L+1)の範囲で全探索
N, M, L = map(int, input().split())
l_a = min(int(L**0.5)+1, N)
l_b = min(int(L**0.5)+1, M)
A = list(map(int, input().split()))
A_s = list([A[i], i] for i in range(N))
A.sort(reverse=True)
A_s.sort(reverse=True)
D_A = {A_s[i][1]:i for i in range(N)}
B = list(map(int, input().split()))
B_s = list([B[i], ... | ConDefects/ConDefects/Code/abc331_e/Python/54388604 |
condefects-python_data_2397 | import sys, bisect, math
sys.setrecursionlimit(10**8)
sys.set_int_max_str_digits(0)
inf = 1<<60
# inf = float('INF')
from collections import deque, defaultdict, Counter
from itertools import product, combinations, permutations, accumulate
from heapq import heapify, heappop, heappush
from sortedcontainers import SortedL... | ConDefects/ConDefects/Code/abc331_e/Python/52731476 |
condefects-python_data_2398 | from heapq import heappush, heappop, heapify
from collections import defaultdict, deque,Counter
from math import ceil, floor, sqrt, factorial,gcd,cos,sin,pi
from itertools import permutations, combinations,product
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import Fraction
from... | ConDefects/ConDefects/Code/abc331_e/Python/54054504 |
condefects-python_data_2399 | import bisect
import collections
import functools
import heapq
import itertools
import math
import operator
import string
import sys
from atcoder.lazysegtree import LazySegTree
readline = sys.stdin.readline
LS = lambda: readline().strip()
LI = lambda: int(readline().strip())
LLS = lambda: readline().strip().split()
L... | ConDefects/ConDefects/Code/abc347_e/Python/55155569 |
condefects-python_data_2400 | # INF = 1<<60 # 1152921504606846976 ~ 10^18
# def meguru_bisect(ng, ok):
# while ok - ng > 1:
# mid = (ng + ok) // 2
# if is_ok(mid): # 小さくできる
# ok = mid
# else:
# ng = mid # 大きくしないといけない
# return ok
import sys
def input():
return sys.stdin.readline()[:-1... | ConDefects/ConDefects/Code/abc347_e/Python/53797654 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.