id stringlengths 24 27 | content stringlengths 37 384k | max_stars_repo_path stringlengths 51 51 |
|---|---|---|
condefects-python_data_1701 | from itertools import combinations
N, M = list(map(int, input().split()))
flavors_of_stands = []
for _ in range(N):
s = int("".join(list(map(lambda x: '1' if x == 'o' else '0', input()))), base=2)
flavors_of_stands.append(s)
total = 2 ** M - 1
for i in range(1, N):
all_cases = combinations(range(N), i)
... | ConDefects/ConDefects/Code/abc358_c/Python/54954465 |
condefects-python_data_1702 | n, m = map(int, input().split())
grid = []
for _ in range(n):
row = input().strip()
grid.append(list(row))
ans = n
for bin in range(1 << n):
exist = [False] * m
cnt = 0
for i in range(n):
if (bin >> i) & 1:
cnt += 1
for j in range(m):
if grid[i][j] == "o":
exist[j] == True... | ConDefects/ConDefects/Code/abc358_c/Python/54942631 |
condefects-python_data_1703 | import sys
sys.setrecursionlimit(9999)
N,M=map(int,input().split())
con=[[] for _ in range(N)]
for i in range(M):
A,B,V=map(str,input().split())
A,B,V=int(A)-1,int(B)-1,1 if V=="(" else -1
con[A].append((B,V))#(終点、±)のタプル
inc,dec=False,False
go =[False for _ in range(N)]
back=[False for _ in range(N)]
pm ... | ConDefects/ConDefects/Code/arc173_d/Python/52512786 |
condefects-python_data_1704 | MOD = 998244353
def solve(h, w, s_list):
count_y = 0
for s in s_list:
count_y += s.count("Y")
if count_y % 2 == 1:
return 0
count_y //= 2
candidates = []
for i in range(1, 2002):
if i * i > count_y:
break
if count_y % i == 0:
candidates.a... | ConDefects/ConDefects/Code/arc157_d/Python/39202960 |
condefects-python_data_1705 | from itertools import groupby
MOD = 998244353
INF = MOD
H, W = map(int, input().split())
Ss = [input() for _ in range(H)]
if not any("Y" in S for S in Ss):
print(pow(2, H - 1, MOD) * pow(2, W - 1, MOD) % MOD)
exit()
lef_trim = 0
while "Y" not in Ss[lef_trim]:
lef_trim += 1
rig_trim = H
while "Y" not in ... | ConDefects/ConDefects/Code/arc157_d/Python/39194356 |
condefects-python_data_1706 |
def divisors(M):
d=[]
i=1
while M>=i**2:
if M%i==0:
d.append(i)
if i**2!=M:
d.append(M//i)
i=i+1
return d
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0f0f0f0f
... | ConDefects/ConDefects/Code/arc157_d/Python/39193714 |
condefects-python_data_1707 | H,W = map(int,input().split())
S = [list(input()) for i in range(H)]
cnth = []
cntw = []
for i in range(H):
cnt = 0
for j in range(W):
if S[i][j]=="Y":
cnt+=1
cnth.append(cnt)
for j in range(W):
cnt=0
for i in range(H):
if S[i][j]=="Y":
cnt+=1
cntw.append(... | ConDefects/ConDefects/Code/arc157_d/Python/39199908 |
condefects-python_data_1708 | def solve(n, A):
A.sort()
main, cur = 0, 0
if (A[0]%2) == 1:
cur = 1
if n == 1:
return "Yes"
for i in range(1, n):
if A[i] == A[i - 1]:
if (A[i] % 2) == 1:
cur += 1
else:
main += cur
cur = 0
if main < A[i] - 1:
return "Yes"
else:
if (A[i]%2) == 1:
cur = 1
return "No"
T = i... | ConDefects/ConDefects/Code/agc065_c/Python/49687962 |
condefects-python_data_1709 | def solve(n, A):
A.sort()
main, cur = 0, 0
A = [-1] + A
for i in range(n):
if A[i] == A[i - 1]:
if (A[i] % 2) == 1:
cur += 1
else:
main += cur
cur = 0
if main < A[i] - 1:
return "Yes"
else:
if (A[i]%2) == 1:
cur = 1
return "No"
T = int(input())
for _ in range(T):
n = int(input... | ConDefects/ConDefects/Code/agc065_c/Python/49687882 |
condefects-python_data_1710 | T = int(input())
for _ in range(T):
N = int(input())
A = sorted(list(map(int, input().split())))
Odd = 0
Test = 0
Em = 0
for i in A:
if i % 2 == 1:
Odd += 1
if Odd % 2 == 0 and i >= 2*Odd-1:
print("Yes")
Test = 1
bre... | ConDefects/ConDefects/Code/agc065_c/Python/48625236 |
condefects-python_data_1711 | 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 v=0: list(map(lambda i: int(i)-v, ... | ConDefects/ConDefects/Code/agc065_c/Python/48625380 |
condefects-python_data_1712 | N, M, X, T, D = map(int, input().split())
h = T
if M >= X:
print(T)
else:
print(T + (X - M) * D)
N, M, X, T, D = map(int, input().split())
h = T
if M >= X:
print(T)
else:
print(T - (X - M) * D) | ConDefects/ConDefects/Code/abc259_a/Python/46054994 |
condefects-python_data_1713 | # cf. https://atcoder.jp/contests/abc343/editorial/9435
def f(v):
return max(0, min(v)) + 7 - max(v)
def count2(a1, b1, c1, a2, b2, c2):
return f((a1, a2)) * f((b1, b2)) * f((c1, c2))
def count3(a1, b1, c1, a2, b2, c2, a3, b3, c3):
return f((a1, a2, a3)) * f((b1, b2, b3)) * f((c1, c2, c3))
def generate(... | ConDefects/ConDefects/Code/abc343_e/Python/54516497 |
condefects-python_data_1714 | N, K = map(int,input().split())
A = list(map(int,input().split()))
digit = 0
left = 1
right = N * (N+1) // 2
while digit < N:
small = [i for i in A[digit:] if i < A[digit]]
large = [i for i in A[digit:] if i > A[digit]]
x = False
if K - left < len(small):
small.sort()
x = small[K-left]
... | ConDefects/ConDefects/Code/arc160_a/Python/45909573 |
condefects-python_data_1715 | N, K = map(int, input().split())
A = list(map(int, input().split()))
ind = [0] * N
for i in range(N):
ind[A[i] - 1] = i
def re(l, r):
if r < N - 1:
return A[:l] + list(reversed(A[l:r + 1])) + A[r + 1:]
elif r == N - 1:
return A[:l] + list(reversed(A[l:r + 1]))
count = 0
flag = True
vi... | ConDefects/ConDefects/Code/arc160_a/Python/43403535 |
condefects-python_data_1716 | N, K = map(int, input().split())
A = list(map(int, input().split()))
K -= 1
inda = [-1]*(N+1)
for i, a in enumerate(A):
inda[a] = i
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
i += 1
s = 0
while i > 0:
s +... | ConDefects/ConDefects/Code/arc160_a/Python/43405529 |
condefects-python_data_1717 | N, K = map(int, input().split())
A = list(map(int, input().split()))
fixed1 = 1
fixed2 = N*(N+1)//2
for i, a in enumerate(A):
l = []
r = []
for j in range(i+1, N):
if A[j] < A[i]:
l.append(A[j])
if A[j] > A[i]:
r.append(A[j])
value = -1
if len(l)+fixed1 > K:
... | ConDefects/ConDefects/Code/arc160_a/Python/42065409 |
condefects-python_data_1718 | x,y,n = map(int,input().split())
yn = n//3
xn = n - yn*3
print(xn*x + yn*y)
x,y,n = map(int,input().split())
yn = n//3
xn = n - yn*3
print(min(xn*x + yn*y , n*x)) | ConDefects/ConDefects/Code/abc265_a/Python/45305147 |
condefects-python_data_1719 | x,y,n = map(int,input().split())
if x*3 > y:
print(n/3 * y + n%3 * x)
else:
print(x*n)
x,y,n = map(int,input().split())
if x*3 > y:
print(n//3 * y + n%3 * x)
else:
print(x*n) | ConDefects/ConDefects/Code/abc265_a/Python/45840285 |
condefects-python_data_1720 | N, A = map(int, input().split())
T = list(map(int, input().split()))
in_retu = 0
for i in range(N):
go = max(in_retu, T[i]) +A
print(go)
in_retu = go
N, A = map(int, input().split())
T = list(map(int, input().split()))
in_retu = 0
for i in range(N):
go = max(in_retu, T[i]) +A
print(go)
in_retu = go | ConDefects/ConDefects/Code/abc358_b/Python/54987803 |
condefects-python_data_1721 | n,a = list(map(int,input().split()))
T = list(map(int,input().split()))
time = 0
for i in T:
if (i>=time):
time=i+a-time
print(time)
else:
time+=a
print(time)
n,a = list(map(int,input().split()))
T = list(map(int,input().split()))
time = 0
for i in T:
if (i>=time):
time=i+a
print(time... | ConDefects/ConDefects/Code/abc358_b/Python/55111511 |
condefects-python_data_1722 | N,A =map(int,input().split())
T = list(map(int,input().split()))
time = 0
for i in range(N):
time = max(time, T[i]) + A
print(time, end = ' ')
N,A =map(int,input().split())
T = list(map(int,input().split()))
time = 0
for i in range(N):
time = max(time, T[i]) + A
print(time, end = ' ') | ConDefects/ConDefects/Code/abc358_b/Python/55163067 |
condefects-python_data_1723 | n,y,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
def calc(B):
next_x=[n+1]*len(B)
next_y=[n+1]*len(B)
for i in range(len(B)):
if B[i]==x:
next_x[i]=i
if B[i]==y:
next_y[i]=i
for i in range(len(B)-1,0,-1):
if next_y[i]!=n+1:
if next_y[i-1]==n+1:
next_y[i... | ConDefects/ConDefects/Code/abc247_e/Python/45003873 |
condefects-python_data_1724 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
N, X, Y, *A = map(int, read().split())
index_X = -1
index_Y = -1
index_ng = -1
ans = 0
for i in range(N):
if A[i] == X:
index_X = i
elif A[i] == Y:
index_Y = i
elif A[i] > X or A[i] < Y:
... | ConDefects/ConDefects/Code/abc247_e/Python/45540952 |
condefects-python_data_1725 | s1=input()
s2=input()
if (s1[0]=="#" and s2[0]=="#") or (s1[1]=="#" and s2[1]=="#"):
print("Yes")
else:
print("No")
s1=input()
s2=input()
if (s1[0]=="#" and s2[0]=="#") or (s1[1]=="#" and s2[1]=="#") or (s1[0]=="#" and s1[1]=="#") or (s2[0]=="#" and s2[1]=="#"):
print("Yes")
else:
print("No") | ConDefects/ConDefects/Code/abc229_a/Python/45784135 |
condefects-python_data_1726 | def solve() -> None:
if black >= 3:
print("Yes")
return
if (s1[0] == "#" and s2[1] == "#") or (s1[1] == "#" and s2[0] == "#"):
print("No")
return
s1 = input()
s2 = input()
black = s1.count("#")
black += s2.count("#")
solve()
def solve() -> None:
if black >= 3:
prin... | ConDefects/ConDefects/Code/abc229_a/Python/45690274 |
condefects-python_data_1727 | S1 = input()
S2 = input()
if S1==".#" and S2=="#.":
print("No")
else:
print("Yes")
S1 = input()
S2 = input()
if S1==".#" and S2=="#.":
print("No")
elif S1=="#." and S2==".#":
print("No")
else:
print("Yes") | ConDefects/ConDefects/Code/abc229_a/Python/45477841 |
condefects-python_data_1728 | S1 = input()
S2 = input()
if S1 == "##" or S2 == "##":
print("Yes")
elif S1 == ".#" and S2 == "#.":
print("No")
elif S1 == "#." and S2 == ".#":
print("No")
S1 = input()
S2 = input()
if S1 == "##" or S2 == "##":
print("Yes")
elif S1 == ".#" and S2 == "#.":
print("No")
elif S1 == "#." and S2 == ".#":... | ConDefects/ConDefects/Code/abc229_a/Python/45808992 |
condefects-python_data_1729 |
s1 = input()
s2 = input()
if [s1, s2]==["#.",".#"] or[".#","#."]:
print('No')
exit()
else:
print('Yes')
s1 = input()
s2 = input()
if [s1, s2]==["#.",".#"] or [s1, s2]==[".#","#."]:
print('No')
exit()
else:
print('Yes')
| ConDefects/ConDefects/Code/abc229_a/Python/46216070 |
condefects-python_data_1730 | S1 = input()
S2 = input()
k = []
s = []
k.append(S1[0])
k.append(S1[1])
s.append(k)
k = []
k.append(S2[0])
k.append(S2[1])
s.append(k)
o = 0
if s[0][0] == "#":
o +=1
if s[0][1] == "#":
o += 1
if s[1][0] == "#":
o += 1
if s[1][1] == "#":
o += 1
# answer
if o == 1 or o >= 3:
print("Yes")
else:
if (s[0][0] ... | ConDefects/ConDefects/Code/abc229_a/Python/44996770 |
condefects-python_data_1731 | S1 = input()
S2 = input()
if S1[0] == S2[0] or S1[1] == S2[1]:
print("Yes")
else:
print("No")
S1 = input()
S2 = input()
if S1[0] == S2[0] or S1[1] == S2[1] or S1[0] == S1[1] or S2[0] == S2[1]:
print("Yes")
else:
print("No") | ConDefects/ConDefects/Code/abc229_a/Python/46233112 |
condefects-python_data_1732 | S = input() + input()
if S == '.#.#' or S == '#.#.' :
print('No')
else:
print('Yes')
S = input() + input()
if S == '.##.' or S == '#..#' :
print('No')
else:
print('Yes') | ConDefects/ConDefects/Code/abc229_a/Python/44625287 |
condefects-python_data_1733 | N, M = map(int, input().split())
X=[]
for _ in range(M):
_, *x=map(int, input().split())
X.append(set(x))
flag=False
from itertools import combinations
for cmb in combinations(range(1,N+1), 2):
for i in X:
if cmb[0] in i and cmb[1] in i:
flag=True
break
else:
print("No")
exit()
pri... | ConDefects/ConDefects/Code/abc272_b/Python/53303936 |
condefects-python_data_1734 | N,K = map(int,input().split())
S = [input() for _ in range(N)]
import functools
S.sort(key=functools.cmp_to_key(lambda x,y:-1 if x+y>y+x else 1))
dp = ['|']*(K+1)
dp[0]= ''
for i in range(N):
for k in range(min(i,K),0,-1):
dp[k] = min(dp[k],S[i]+dp[k-1])
print(dp[K])
N,K = map(int,input().split())
S = [input() f... | ConDefects/ConDefects/Code/abc225_f/Python/29050129 |
condefects-python_data_1735 | import os, sys; sys.setrecursionlimit(10**7)
readline = sys.stdin.readline
if os.path.basename(__file__) == "Main.py":
import pypyjit; pypyjit.set_param('max_unroll_recursion=-1')
from functools import cmp_to_key
alphabet_to_int = lambda x:ord(x)-97
mod = 998244353
def f(S):
res = 0
for i in range(len(S)):
... | ConDefects/ConDefects/Code/abc225_f/Python/30550444 |
condefects-python_data_1736 | N, K = map(int, input().split())
S = [input() for _ in range(N)]
rule = []
for _ in range(N):
for i in range(N-1):
if S[i] + S[i+1] <= S[i+1] + S[i]:
pass
else:
S[i+1], S[i] = S[i], S[i+1]
dp = [[None]*N for _ in range(N)]
for i in range(N):
dp[i][0] = min(S[i:])
def... | ConDefects/ConDefects/Code/abc225_f/Python/31785117 |
condefects-python_data_1737 | n, l = map(int, input().split())
a_list = list(map(int, input().split()))
ans_half = float('inf')
i = 0
j = n-1
while i < j:
ai = a_list[i]
aj = a_list[j]
l_west = (aj-ai) + 2 * ai
l_east = (aj-ai) + 2 * (l-aj)
newans_half = max(l_west, l_east)
ans_half = min(ans_half, newans_half)
if l_e... | ConDefects/ConDefects/Code/arc152_b/Python/37047246 |
condefects-python_data_1738 | n,L=map(int,input().split())
a=list(map(int,input().split()))
a.append(10**18)
a=[-10**18]+a
ans=10**18
for i in range(n):
r=n
l=-1
while r-l>1:
v=(r+l)//2
if a[v]>=L-a[i+1]:
r=v
else:
l=v
ans=min(ans,2*L+min(L-a[i+1]-a[r-1],a[r]-L+a[i+1])*2)
print(ans)
n,L=map(int,input().spli... | ConDefects/ConDefects/Code/arc152_b/Python/46130280 |
condefects-python_data_1739 | from bisect import*
n,l,*a=map(int,open(0).read().split())
t=4*l
for c in a:x=l-c;i=bisect(a,x);t=min(t,min(x-a[i-1],a[min(i,n-1)]-x))
print(2*(t+l))
from bisect import*
n,l,*a=map(int,open(0).read().split())
t=4*l
for c in a:x=l-c;i=bisect(a,x);t=min(t,min(abs(x-a[min(max(j,0),n-1)])for j in[i,i-1]))
print(2*(t+l)) | ConDefects/ConDefects/Code/arc152_b/Python/36754688 |
condefects-python_data_1740 | N,L = map(int,input().split())
A = list(map(int,input().split()))
A = [0]+A+[L]
amin = 10**9
for i in range(1,N+1):
s = A[i]
high = N
low = 1
while high-low>1:
mid = (high+low)//2
t = A[mid]
dr = L-s+L-t
dl = s+t
if dr>=dl:
low = mid
else:
... | ConDefects/ConDefects/Code/arc152_b/Python/37067201 |
condefects-python_data_1741 | import bisect
n,l = map(int,input().split())
a = list(map(int,input().split()))
mi = l
for i in range(n):
aa = bisect.bisect_right(a,l-a[i])
if aa == n:
m = abs(a[i] - (l-a[aa-1]))
else:
m = min(abs(a[i] - (l-a[n-1])),abs(a[i] - (l-a[aa])))
mi = min(mi,m)
print(2 * (l + mi))
import bisect
n,l = map(int... | ConDefects/ConDefects/Code/arc152_b/Python/37447201 |
condefects-python_data_1742 | from bisect import *
N,L = map(int,input().split())
inf = L*4
A = list(map(int,input().split()))
ans = inf
for a in A:
b = L-a
p = bisect_left(A,b)
p1 = A[p] if p < N else inf
p2 = A[p-1]
ans_ = 2*L + min(abs(b-p1),abs(b-p2))
ans = min(ans,ans_)
print(ans)
from bisect import *
N,L = map(int,input().split()... | ConDefects/ConDefects/Code/arc152_b/Python/36775118 |
condefects-python_data_1743 | def main():
T = input()
N = int(input())
S = []
for _ in range(N):
tmp = input().split()
del(tmp[0])
S.append(tmp)
INF = 10**18
# dp[i] : i番目の袋から出した後
# dp[i][j] : j文字目まで完成しているときの最小スコア
dp = [([0] + [INF]*(len(T))) for _ in range(N+1)]
for i in range(1, ... | ConDefects/ConDefects/Code/abc344_d/Python/54876594 |
condefects-python_data_1744 | import sys
def main():
input = sys.stdin.readline
T = input().rstrip()
N = int(input())
l = len(T)
dp = [[10**9] * (l + 1) for _ in [0] * (N + 1)]
dp[0][0] = 0
for i in range(N):
a,*si = input().rstrip().split()
for j in range(l):
if dp[i][j] + 1:
... | ConDefects/ConDefects/Code/abc344_d/Python/54960181 |
condefects-python_data_1745 | n = int(input())
p = list(map(int, input().split()))
cnt = [0]
ans = []
def swap(i):
p[i], p[i+1] = p[i], p[i+1]
cnt[0] += 1
ans.append(i+1)
for i in range(0, 2*n, 2):
if i == 0:
if p[0] > p[1]:
swap(0)
continue
if p[i-1] > p[i]:
if p[i] > p[i+1]:
... | ConDefects/ConDefects/Code/agc058_a/Python/46230782 |
condefects-python_data_1746 | n=int(input())
a=list(map(int,input().split()))
q=[]
for i in range(n):
if i==0:
if a[0]>a[1]:
a[0],a[1]=a[1],a[0]
q.append(1)
else:
if a[i*2-1]<a[i*2] and a[i*2+1]>a[i*2]:
if a[i*2-1]<a[i*2+1]:
a[i*2-1],a[i*2]=a[i*2],a[i*2-1]
... | ConDefects/ConDefects/Code/agc058_a/Python/44643713 |
condefects-python_data_1747 | N = int(input())
p = list(map(int, input().split()))
ans = []
for i in range(1, 2 * N - 1, 2):
a, b, c = p[i-1], p[i], p[i+1]
if (max(a, b, c) == a):
ans.append(i)
p[i-1], p[i] = p[i], p[i-1]
elif (max(a, b, c) == c):
ans.append(i+2)
p[i], p[i+1] = p[i+1], p[i]
if p[2 * N - ... | ConDefects/ConDefects/Code/agc058_a/Python/43781605 |
condefects-python_data_1748 | N=int(input())
#HA,WA=map(int,input().split())
A=list(map(int,input().split()))
#S=[(input(),i) for i in range(N)]
def solve():
K=0
ans=[]
for i in range(2*N-1):
if i%2==1: #should be A[i]>A[i+1]
if A[i]<A[i+1]:
if A[i]>A[i+2]:
A[i],A[i+1]=A[i+1],A... | ConDefects/ConDefects/Code/agc058_a/Python/43275130 |
condefects-python_data_1749 |
def check(b,c):
#start at a and end at bth day, check if everyone is available
for i in range(N):
for j in range(b,c+1):
if(a[i][j] == 'x'):
return False
return True
a = []
temp = []
N,D = map(int,input().split()) #N = 3, D = 5
for i in range(N):
s = input()
a.append(s)
for i in range(N... | ConDefects/ConDefects/Code/abc311_b/Python/45980619 |
condefects-python_data_1750 | h,w=map(int,input().split())
c=[input() for _ in range(h)]
q=int(input())
rh=0
sh=1
rw=0
sw=1
for _ in range(q):
a,b=map(int,input().split())
a-=1
b-=1
if rh<=a:
rh=a-rh
else:
rh=h-(rh-a)
if sh<=a:
sh=a-sh
else:
sh=w-(sh-a)
if rw<=b:
rw=b-rw
else:
rw=w-(rw-b)
if sw<=b:
... | ConDefects/ConDefects/Code/arc153_b/Python/44454861 |
condefects-python_data_1751 | import sys
readline = sys.stdin.readline
H, W = map(int, readline().split())
A = [list(readline().strip()) for _ in range(H)]
x, y = 0, 0
Q = int(readline())
for q in range(Q):
a, b = map(int, readline().split())
if y < a:
y = a - 1 - y
else:
y = H - 1 - (y-a)
if x < b:
x = b -... | ConDefects/ConDefects/Code/arc153_b/Python/43165491 |
condefects-python_data_1752 | def main():
# write code here.
N = II()
A = LM()
A = [0] + A
#width[i]:=i連勤の時のその部分での生産量.
width = [0]*N
for i in range(1,N):
now = 0
for j in range(1,i+1):
now += A[min(j,i-j+1)]
width[i] = now
dp = [-INF]*(N+1)
dp[0] = 0
for i in range(1,N):
... | ConDefects/ConDefects/Code/abc285_e/Python/51473049 |
condefects-python_data_1753 | # i番目の重みws[i], 価値vs[i]
def solve(N, W, ws, vs):
dp = [0] * (W+1)
for i in range(N):
# 価値v, 重さw
v = vs[i]; w = ws[i]
for j in range(W, w-1, -1):
dp[j] = max(dp[j-w] + v, dp[j])
return max(dp)
N = int(input())
A = list(map(int,input().split()))
# 初日と翌週初日はお休み
# 開けた日数分の労働力を前... | ConDefects/ConDefects/Code/abc285_e/Python/53461443 |
condefects-python_data_1754 | # 初日を休日
# dp[i][j] := i日目を考える、j日平日が続いている
# 10
# 10 10
# 10 10 10
# 10 10 10 10
# 10 10 1 10 10
# 10 10 1 1 10 10
n = int(input())
base_productivity = list(map(int, input().split()))
productivity = [0]
for i in range(n):
productivity.append(productivity[-1] + base_productivity[i//2])
INF = float('inf')
dp = [[-IN... | ConDefects/ConDefects/Code/abc285_e/Python/48880084 |
condefects-python_data_1755 | import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log
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/abc336_g/Python/49317983 |
condefects-python_data_1756 | N, M = map(int, input().split())
dict = {}
for i in range(M):
a, b = map(int, input().split())
dict.setdefault(a, []).append(b)
dict.setdefault(b, []).append(a)
# キーで辞書をソート
sortDict = sorted(dict.items(), key=lambda x: x[0])
# キーの値(リスト)をソートして出力
for key, value in sortDict:
print(len(value), end=" ")
... | ConDefects/ConDefects/Code/abc276_b/Python/45457666 |
condefects-python_data_1757 | h,w=map(int,input().split())
grid=[['.' for _ in range(w+2)]]
for _ in range(h):
tmp=list(input())
grid.append(['.']+tmp+['.'])
grid.append(['.' for _ in range(w+2)])
if grid[1][1]!='s':
print('No')
else:
bool=[[False for _ in range(w+2)] for __ in range(h+2)]
bool[1][1]=True
box=[(1,1)]
di... | ConDefects/ConDefects/Code/abc308_d/Python/54718266 |
condefects-python_data_1758 | from sys import setrecursionlimit
H, W = map(int, input().split())
S = [input() for _ in [0]*H]
dir = [(-1, 0), (1, 0), (0, -1), (0, 1)]
setrecursionlimit(300000)
seen = [[False]*W for _ in [0]*H]
def func(y, x, p):
if y == H-1 and x == W-1:
print("Yes")
exit()
for ay, ax in dir:
ny, n... | ConDefects/ConDefects/Code/abc308_d/Python/54535139 |
condefects-python_data_1759 | #!/usr/bin/env python3
MOD = 998244353
def tri(n):
n %= MOD
return ((n + 1) * n // 2) % MOD
def solve():
a1, a2, a3 = map(int, input().split())
if a1 < a2:
a1, a2 = a2, a1
if not a1 <= a3 <= a1 + 1:
return 0
p1 = pow(10, a1 - 1, MOD)
p2 = pow(10, a2 - 1, MOD)
if a1... | ConDefects/ConDefects/Code/arc178_b/Python/54290534 |
condefects-python_data_1760 | import sys
input=sys.stdin.readline
T=int(input())
MOD=998244353
def f(p):
return 9*pow(10,p-1,MOD)
def g(p,q):
if p==q:
retval=(f(a)-pow(10,p-1,MOD))*\
(f(a)-pow(10,p-1,MOD)+1)//2
retval%=MOD
return retval
else:
h=f(a)
s=f(b)-pow(10,a-1,MOD)
... | ConDefects/ConDefects/Code/arc178_b/Python/54236460 |
condefects-python_data_1761 | t = int(input())
for _ in range(t):
n = int(input())
ans = 0
if n>=1: ans += 1
cnt = 2
while n>=10**cnt-2*10**(cnt//2):
ans += 1
ans += min(n, 10**cnt+10**(cnt//2)-1) - (10**cnt-10**(cnt//2)-1)
cnt += 2
print(ans)
t = int(input())
for _ in range(t):
n = int(input())
ans = 0
if n>=1: ... | ConDefects/ConDefects/Code/arc174_d/Python/51409995 |
condefects-python_data_1762 | t = int(input())
ins = [(1,1)]
for x in range(2,19,2):
v = pow(10,x)
h = pow(10,x//2)
ins.append((v-h*2,v-h*2))
ins.append((v-h,v+h-1))
print(ins)
for _ in range(t):
n = int(input())
ans = 0
for l,r in ins:
r = min(r,n)
if l <= r:
ans += r-l+1
print(ans)
t... | ConDefects/ConDefects/Code/arc174_d/Python/51974716 |
condefects-python_data_1763 | import copy
r, c = map(int, input().split())
b = []
for _ in range(r):
b.append(list(input()))
z = [0] * 10
zz = [0] * (c + 20)
ans = copy.copy(b)
for i in range(r):
for k in range(c):
if (b[i][k] == '1' or
b[i][k] == '2' or
b[i][k] == '3' or
b[i][k] == '4' or
b[i][k] == '5' or
b[i][k]... | ConDefects/ConDefects/Code/abc295_b/Python/45969944 |
condefects-python_data_1764 | R, C = map(int, input().split())
# 行列受け取り
B = []
for i in range(R):
row = input()
B.append(row)
# 新しく行列を作成
Q = [['1'] * C for r in range(R)]
for i in range(R):
for j in range(C):
# 数値に変換
# 変換出来たら数値のマンハッタン距離分のマスに"."を入れる
# 変換できなかった場合は、作成した行列が1の場合のみ、受け取った行列の値を入れる
b = B[i][j]
numberCheck = b.... | ConDefects/ConDefects/Code/abc295_b/Python/45457264 |
condefects-python_data_1765 | S = input()
T = input()
if T[-1] == 'X':
T = T[0:2]
T = T.lower()
j = 0
for i in range(len(T)):
while j < len(S):
if T[i] == S[j]:
j += 1
break
j += 1
if j == len(S):
print("No")
else:
print("Yes")
S = input()
T = input()
if T[-1] == 'X':
T = T[0:2]
T = T.lo... | ConDefects/ConDefects/Code/abc349_c/Python/54901128 |
condefects-python_data_1766 | def addstr(a,b,c):
return a+"\n"+str(b)+" "+str(c)
N=int(input())
P=list(map(lambda x: int(x)-1,input().split()))
Q=[-1]*N
for i in range(N):
Q[P[i]]=i
l=0
r=N-1
ans="Yes"
cnt=0
while l<r:
if l==Q[l]:
l+=1
continue
elif r==Q[r]:
r-=1
continue
elif l<Q[l]<=r-1:
... | ConDefects/ConDefects/Code/arc162_b/Python/43537557 |
condefects-python_data_1767 | N = int(input())
P_list = list(map(int, input().split()))
ans = []
for j in range(1, N):
i = P_list.index(j) + 1
if i == N:
ans.append((N-1, N-2))
P_list = P_list[:N-3] + [P_list[N-2], P_list[N-1], P_list[N-3]]
i = N-1
if P_list == list(range(1, N+1)):
break
#... | ConDefects/ConDefects/Code/arc162_b/Python/45211703 |
condefects-python_data_1768 | n = int(input())
p = list(map(lambda x:int(x)-1,input().split()))
ans = []
for i in range(n-2):
if p[i] == i:
continue
for j in range(i+1,n):
if p[j] == i:
break
if j != n-1:
ans.append([j+1,i])
p = p[:i]+p[j:j+2]+p[i:j]+p[j+2:]
else:
ans.append([n-1,n... | ConDefects/ConDefects/Code/arc162_b/Python/44215494 |
condefects-python_data_1769 | N = int(input())
P = list(map(int,input().split()))
res = []
for i in range(1, N):
pos = [-1 for _ in range(N)]
for ind, j in enumerate(P):
if j != i:
continue
if ind == N-1 and i == N-1:
print("No")
exit()
elif ind == N-1 and i != N-1:
P.p... | ConDefects/ConDefects/Code/arc162_b/Python/45772251 |
condefects-python_data_1770 | n = int(input())
p = list(map(int, input().split()))
ans = []
j = 0
while j < n:
if p[j] != j + 1 and j < n - 2:
ind = p.index(j + 1)
if ind == n - 1:
ans.append((n - 1, n - 3))
p = p[: n - 3] + [p[n - 1]] + p[n - 3 : n - 1]
else:
ans.append((ind + 1, j))
... | ConDefects/ConDefects/Code/arc162_b/Python/45429889 |
condefects-python_data_1771 | I=input;R=lambda:[*map(int,I().split())]
def f(a,sign=1,chk=False):
for i in range(1,n,2):
if a[i]*sign>a[i+1]*sign:
if i!=1 and a[i]*sign<a[i-2]*sign or a[i+1]*sign<a[i-1]*sign:
return 0
if chk and (s[a[i]]!='' or s[a[i+1]]!=''):return 0
s[a[i]]='(';s[a[i+1]]=')'
return 1
n=int(I())*2... | ConDefects/ConDefects/Code/arc141_c/Python/33055837 |
condefects-python_data_1772 | N=int(input())
p_array=list(map(lambda e: int(e)-1, input().split()))
q_array=list(map(lambda e: int(e)-1, input().split()))
rets=[0]*2*N
# pを先頭からチェック
done=[False]*2*N
now=0
for i in range(N*2):
if p_array[i]==now:
now+=1
for j in range(now,N*2):
if done[j]:
now=j+1
... | ConDefects/ConDefects/Code/arc141_c/Python/34662508 |
condefects-python_data_1773 | n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
n2 = n*2
ans = [''] * (n2+1)
left = 0
max_pi = 0
max_qi = 0
for i,pi,qi in zip(range(n2), p, q[::-1]):
max_pi = max(max_pi, pi)
max_qi = max(max_qi, qi)
# print(i, max_pi,max_qi)
if i % 2 == 0:
continue
... | ConDefects/ConDefects/Code/arc141_c/Python/40547162 |
condefects-python_data_1774 | N,P=map(int,input().split())
A=list(map(int,input().split()))
pr=set()
K=P-1
i=2
while i*i<=P-1:
while K%i==0:
if not(i in set()):
pr.add(i)
K//=i
if i==2:
i+=1
else:
i+=2
div=[]
div2=[]
i=1
while i*i<=P-1:
if (P-1)%i==0:
div.append(i)
div2.a... | ConDefects/ConDefects/Code/abc335_g/Python/49224063 |
condefects-python_data_1775 | def func():
# 入力を取得
N = int(input())
A = list(map(int, input().split()))
P = 0
for n in range(N):
if sum(A[n:]) > 4:
P += 1
print(P)
if __name__ == '__main__':
func()
def func():
# 入力を取得
N = int(input())
A = list(map(int, input().split()))
... | ConDefects/ConDefects/Code/abc256_b/Python/45645329 |
condefects-python_data_1776 | n=int(input())
a=list(map(int,input().split()))
for i in range(n):
for j in range(i):
a[j]+=a[i]
ans=0
for i in range(n):
ans+= a[i]>=5
print(ans)
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
for j in range(i):
a[j]+=a[i]
ans=0
for i in range(n):
ans+= a[i]>=4
print(ans) | ConDefects/ConDefects/Code/abc256_b/Python/44471761 |
condefects-python_data_1777 | N = int(input())
A = list(map(int, input().split()))
cum_sum = [0] * (N + 1)
for i in range(N):
cum_sum[i + 1] = cum_sum[i] + A[i]
ans = 0
for i in range(N):
if 4 < cum_sum[N] - cum_sum[i]:
ans += 1
else:
break
print(ans)
N = int(input())
A = list(map(int, input().split()))
cum_sum = [0] * ... | ConDefects/ConDefects/Code/abc256_b/Python/45997189 |
condefects-python_data_1778 | from collections import deque
N = int(input())
A = list(map(int, input().split()))
Q = deque()
ans = 0
for a in A:
ans += 1
if len(Q) == 0:
Q.append([a,1])
if Q[-1][0] != a:
Q.append([a,1])
else:
Q[-1][1] += 1
if Q[-1][1] == a:
Q.pop()
ans -= a
... | ConDefects/ConDefects/Code/abc240_d/Python/45435904 |
condefects-python_data_1779 | T=int(input())
for o in range(T):
N,K=map(int,input().split())
for i in range(70):
if 2**i+2>N:
k=i
break
result=K
x,y,z=[K-1,K-1],[K,K],[K+1,K+1]
Q=[x,y,z]
if x[0]%(2**k)==1 or x[0]%(2**k)==2**(k-1)+1 or x[0]==2**(k-1)+1:
x[1]+=1
elif x[0]%(2**k)==2 or x[0]%(2**k)==2**(k-1)+2 or x[0]=... | ConDefects/ConDefects/Code/agc061_a/Python/38853475 |
condefects-python_data_1780 | def ans(n,k,bit):
b=1<<bit
if n&b==0: return ans(n,k,bit-1)
if n==b:
if k%2==0: return k-1
else: return k+1
elif n==b+1:
if k==1: return 2
elif k==n-1: return n
elif k%2==1: return k-2
else: return k+2
else:
if k<=n-b: return ans(n-b,k,bit-1)
elif k>=b+1: return ans(n-b,k,bit-1... | ConDefects/ConDefects/Code/agc061_a/Python/38921956 |
condefects-python_data_1781 | T = int(input())
for _ in range(T):
N, K = map(int, input().split())
if N % 2 == 0:
N //= 2
i = K
if i % 2 == 1:
i += 1
i //= 2
if (N - 1) & (i - 1) == i - 1:
if K % 2 == 0:
print(K - 1)
else:
print(K + 1)
else:
print(K)
else:
if K == 1:
pr... | ConDefects/ConDefects/Code/agc061_a/Python/38852158 |
condefects-python_data_1782 | import math
import heapq
# import bisect
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
# n,x,y = map(int, input().split())
# a = list(map(int, input().split()))
n = int(input())
cld = [[] for i in range(n)]
s = [0]*n
g = [0]*n
md = []
inf = 1<<63
mx = 0
for i in range(n-1):
p,t,S,G = map(int, ... | ConDefects/ConDefects/Code/abc319_f/Python/45769357 |
condefects-python_data_1783 | ir = lambda: int(input()) # 数字の読み込み
lr = lambda: list(map(int, input().split())) # 数字の配列の読み込み
import heapq
N = ir()
P = [[] for _ in range(N)]
S = [0]
G = [0]
potionidx = []
for i in range(1, N):
p, t, s, g = lr()
# 木は親から子の方向だけ持つ
P[p-1].append(i)
S.append(s)
G.append(g)
if t == 2:
# 敵... | ConDefects/ConDefects/Code/abc319_f/Python/45777946 |
condefects-python_data_1784 | #D - Divide Interval
l, r = map(int, input().split())
#l = 3 の時、(3,4)のみ
#l = 4の時、 (4,5)(4,6)(4,8)があるので(4,8)←4 = 2**2 (2**)
#l = 8の時、(8,9)(8,12)(8,16)
#l = 16の時、(16,17)(16,18)(16,20)(16,24)(16,32)
#l + 0, l + 2**0, l + 2**1, l + 2**3, ...
#lが奇数の時、l + 2**0のみ
#lが偶数の時、
lis = []
if l % 2 == 1:
lis.append([l])
l = l + ... | ConDefects/ConDefects/Code/abc349_d/Python/54267102 |
condefects-python_data_1785 | from collections import deque
N,M = map(int,input().split())
G = []
for i in range(N):
G.append([-1]*N)
G[0][0] = 0
Q = deque()
Q.append((0,0))
dir = []
for i in range(M+1):
x,y = i,int((M-i)**0.5)
if x**2 + y**2 == M:
dir.append([x,y])
dir.append([-x,y])
dir.append([x,-y])
... | ConDefects/ConDefects/Code/abc272_d/Python/45114386 |
condefects-python_data_1786 | # import系 ---
from collections import deque
# 入力用 ---
INT = lambda: int(input())
MI = lambda: map(int, input().split())
MI_DEC = lambda: map(lambda x: int(x) - 1, input().split())
LI = lambda: list(map(int, input().split()))
LI_DEC = lambda: list(map(lambda x: int(x) - 1, input().split()))
LS = lambda: list(input())
L... | ConDefects/ConDefects/Code/abc272_d/Python/45575170 |
condefects-python_data_1787 | # import io
# import sys
# _INPUT = """\
# 3
# 1 2 1
# 1 1 2
# """
# sys.stdin = io.StringIO(_INPUT)
n = int(input())
A = list(map(lambda x:int(x)-1, input().split()))
B = list(map(lambda x:int(x)-1, input().split()))
A_ = [set() for _ in range(n)]
B_ = [set() for _ in range(n)]
for i in range(n):
a, b = A[i], B[i... | ConDefects/ConDefects/Code/abc296_f/Python/50949566 |
condefects-python_data_1788 | n = int(input())
a = list(int(c)-1 for c in input().split())
b = list(int(c)-1 for c in input().split())
if sorted(a) != sorted(b):
print('No')
exit()
if len(set(a)) < n:
print('Yes')
exit()
b2i = [0]*n
for i,v in enumerate(b):
b2i[v] = i
p = [0]*n
for i,j in enumerate(a):
p[i] = b2i[j]
visit... | ConDefects/ConDefects/Code/abc296_f/Python/43917096 |
condefects-python_data_1789 | import sys
def main():
input = sys.stdin.readline
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
if sorted(A) != sorted(B):
return False
G = [[] for _ in range(N + 1)]
for i, a in enumerate(A):
G[a].append(i)
for g in G:
s = set(B... | ConDefects/ConDefects/Code/abc296_f/Python/45331429 |
condefects-python_data_1790 | class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):#1インデックス
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
... | ConDefects/ConDefects/Code/abc296_f/Python/52941375 |
condefects-python_data_1791 | 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/abc296_f/Python/45226037 |
condefects-python_data_1792 | from itertools import takewhile
_ = input()
first, *others = map(int, input().split())
ans = sum(1 for x in takewhile(lambda x: x <= first, others))
print(-1 if ans==0 else ans+1)
from itertools import takewhile
_ = input()
first, *others = map(int, input().split())
ans = sum(1 for x in takewhile(lambda x: x <= firs... | ConDefects/ConDefects/Code/abc353_a/Python/54951286 |
condefects-python_data_1793 | x=int(input())
cont=0
cad=[int(x) for x in input().split()]
for i in range(1,len(cad)):
if cad[0]<cad[i]:
print(i+1)
break
elif cad[0]>cad[i]:
cont+=1
if len(cad)-1==cont:
print(-1)
x=int(input())
cont=0
cad=[int(x) for x in input().split()]
for i in range(1,len(cad)):
if cad[0]... | ConDefects/ConDefects/Code/abc353_a/Python/54934846 |
condefects-python_data_1794 | #int型で受け取るとき
N = int(input())
#list型で取得
l = list(map(int, input().split()))
height = l[0]
for i in range(N):
if height < l[i]:
print(i)
import sys
sys.exit()
print(-1)
#int型で受け取るとき
N = int(input())
#list型で取得
l = list(map(int, input().split()))
height = l[0]
for i in range(N):
... | ConDefects/ConDefects/Code/abc353_a/Python/55035442 |
condefects-python_data_1795 |
input = [list(map(int, input().split())) for i in range(2)]
BuildingNum = input[0]
HeightList = input[1]
print(HeightList)
Height_FirstBuld = HeightList[0]
found = 0
for i in range(len(HeightList)):
if HeightList[i] > Height_FirstBuld:
print(i+1)
found = 1
break
if(found == 0):
pr... | ConDefects/ConDefects/Code/abc353_a/Python/55010639 |
condefects-python_data_1796 | n=int(input())
A=0
B=10**12
for q in range(n):
a,b=map(int,input().split())
A=max(A,a)
B=min(B,b)
print(max(B-A+1,0))
n=int(input())
A=0
B=10**12
for q in range(n):
a,b=map(int,input().split())
A=max(A,a)
B=min(B,b)
print(max((A-B+1)//2,0)) | ConDefects/ConDefects/Code/arc129_b/Python/36921100 |
condefects-python_data_1797 |
def Main():
n=int(input())
maxl=-1000000000000000000
minr=1000000000000000000
for _ in range(n):
l,r=map(int,input().split())
maxl=max(maxl,l)
minr=min(minr,r)
if maxl<=minr:
print(0)
else:
print((maxl-minr)//2)
Main()
de... | ConDefects/ConDefects/Code/arc129_b/Python/38744633 |
condefects-python_data_1798 | n=int(input())
a=-10**10
b=10**10
for _ in range(n):
l,r=map(int,input().split())
a=max(a,l)
b=min(b,r)
if a<=b:
print(0)
else:
print((a-b)//2)
n=int(input())
a=-10**10
b=10**10
for _ in range(n):
l,r=map(int,input().split())
a=max(a,l)
b=min(b,r)
if a<=b:
pr... | ConDefects/ConDefects/Code/arc129_b/Python/44921969 |
condefects-python_data_1799 | 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/arc164_d/Python/43435953 |
condefects-python_data_1800 | #再帰はCpython,その他はpypy
import sys
sys.setrecursionlimit(1000000)
from collections import defaultdict
N, Q = map(int, input().split())
dic = defaultdict(set)
ans = N
for i in range(Q):
query = [*map(int, input().split())]
if query[0] == 2:
if len(dic[1]) == 0:
ans -= 1
for j in dic... | ConDefects/ConDefects/Code/abc302_e/Python/51480791 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.