id stringlengths 24 27 | content stringlengths 37 384k | max_stars_repo_path stringlengths 51 51 |
|---|---|---|
condefects-python_data_1 | import sys
def main():
input = sys.stdin.readline
N = int(input())
P = [int(p) for p in input().strip().split()]
ans = []
def calc1(i):
if i <= 2:
return True
if P[i-3] % 2 != (i-2) % 2:
return True
ans.append(('B', i-1))
P[i-3], P[i-1] = P[i... | ConDefects/ConDefects/Code/arc147_b/Python/42082334 |
condefects-python_data_2 | N = int(input())
P = list(map(int, input().split()))
A = list(range(1,N+1))
ans = []
B = [[] for _ in range(2)]
for i, p in enumerate(P):
if (p - i) % 2 == 0:
B[i % 2].append(i)
for i in range(len(B[0])):
b0, b1 = B[0][i], B[1][i]
if b0 > b1:
b0, b1 = b1, b0
while b0 + 1 < b1:
an... | ConDefects/ConDefects/Code/arc147_b/Python/45545981 |
condefects-python_data_3 | N = int(input())
A = list(map(int, input().split()))
st = ['o' if A[i]%2 == (i+1)%2 else 'x' for i in range(N)]
ng = st.count(0)
ans = []
for i in range(N):
flag = False
if st[i] == 'o':
q = [i]
for j in range(i+2, N, 2):
if st[j] == 'o':
q.append(j)
els... | ConDefects/ConDefects/Code/arc147_b/Python/39591338 |
condefects-python_data_4 | MOD, MAXN = 998244353, 2 * pow(10, 5)
N = int(input())
p, inv = [1] * (MAXN + 10), [1] * (MAXN + 10)
p[1] = 2
for i in range(2, MAXN + 1):
p[i] = p[i - 1] * 2 % MOD
inv[i] = -(MOD // i) * inv[MOD % i] % MOD
ans, res = 2, 1
for i in range(1, N + 1):
res = res * (p[N] - p[i - 1] + MOD) % MOD * inv[i] % MOD
... | ConDefects/ConDefects/Code/arc146_c/Python/34191586 |
condefects-python_data_5 | def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr... | ConDefects/ConDefects/Code/arc148_a/Python/44882552 |
condefects-python_data_6 | from math import gcd
n = int(input())
a = list(map(int,input().split()))
g = 0
for i in range (n-1):
g = gcd(g,abs(a[i]-a[i+1]))
if g >= 2:
ans = 1
else:
ans = 2
print(ans)
from math import gcd
n = int(input())
a = list(map(int,input().split()))
g = 0
for i in range (n-1):
g = gcd(g,abs(a[i]-a[... | ConDefects/ConDefects/Code/arc148_a/Python/42795362 |
condefects-python_data_7 | import math
n=int(input())
a=list(map(int,input().split()))
a=list(set(a))
a.sort()
l=len(a)
x=a[0]
for i in range(l):
a[i]-=x
x=a[-1]
for i in range(2,l):
x = math.gcd(a[i],x)
if x==1:
print(2)
else:
print(1)
import math
n=int(input())
a=list(map(int,input().split()))
a=list(set(a))
a.sor... | ConDefects/ConDefects/Code/arc148_a/Python/44660957 |
condefects-python_data_8 | from math import gcd
n = int(input())
a = list(map(int, input().split()))
for i in range(n - 1):
if a[i] == a[i + 1]:
exit(print(1))
g = abs(a[0] - a[1])
for i in range(1, n - 1):
g = gcd(g, abs(a[1] - a[2]))
print(2 if g == 1 else 1)
from math import gcd
n = int(input())
a = list(map(int, input().split()))
fo... | ConDefects/ConDefects/Code/arc148_a/Python/44544084 |
condefects-python_data_9 | from math import gcd
import os
import sys
import numpy as np
def solve(inp):
n = inp[0]
m = inp[1]
ddd = inp[2:]
MOD = 998244353
n2 = 1 << n
INF = 1 << 60
def pop_count_32(n):
c = (n & 0x55555555) + ((n >> 1) & 0x55555555)
c = (c & 0x33333333) + ((c >> 2) & 0x33333333)
... | ConDefects/ConDefects/Code/abc236_h/Python/28807713 |
condefects-python_data_10 | N,M=map(int,input().split())
L=list(map(int,input().split()))
def isok(n):
dist=-1
count=0
for i in range(N):
if L[i]>n:
return False
if dist+1+L[i]>n:
dist=-1
count+=1
dist+=(1+L[i])
if count+1<=M:
return True
return False
left,ri... | ConDefects/ConDefects/Code/abc319_d/Python/45752844 |
condefects-python_data_11 | import sys
input = lambda: sys.stdin.readline().rstrip()
INF = 10**18
N,M = map(int,input().split())
L = list(map(int,input().split()))
def is_ok(arg):
nrow = 1
x = 0
for i in range(N):
if x == 0:
if x + L[i] <= arg:
x += L[i]
else:
nrow += 1... | ConDefects/ConDefects/Code/abc319_d/Python/45778019 |
condefects-python_data_12 | n, m = map(int, input().split())
word_lengths = list(map(int, input().split()))
total_chars = sum(word_lengths) + (n - 1)
left, right = max(max(word_lengths), (total_chars + m - 1) // m), total_chars
while left < right:
mid = (left + right) // 2
lines_needed, current_line_length = 1, 0
for length in wor... | ConDefects/ConDefects/Code/abc319_d/Python/45943488 |
condefects-python_data_13 | import heapq
import itertools
from collections import deque
from sys import stdin
N, M = map(int, input().split())
L = list(map(int, input().split()))
for i in range(N):
L[i] += 1
ok = 10 ** 15
ng = -1
def check(num):
wordLen = -1
wordLines = 1
for i in range(N):
if wordLen+L[i] > num:
... | ConDefects/ConDefects/Code/abc319_d/Python/45753057 |
condefects-python_data_14 | n, m = map(int, input().split())
L = list(map(int, input().split()))
left, right = max(L), sum(L)
while left < right:
mid = (left + right) // 2
cur = 0
level = 0
# print("lr", left, right, mid)
flag = False
for i in range(n):
# print("lc", level, cur, L[i])
if L[i] > mid:
... | ConDefects/ConDefects/Code/abc319_d/Python/45926522 |
condefects-python_data_15 | n, m = map(int, input().split())
l = list(map(int, input().split()))
def search(width: int) -> bool:
length = 0
lines = 1
for e in l:
if length > 0:
length += 1
if length + e > width:
lines += 1
length = 0
count = 0
length += e
# p... | ConDefects/ConDefects/Code/abc319_d/Python/45764630 |
condefects-python_data_16 | condition = list(map(int, input().split()))
word_lengths = list(map(int, input().split()))
# # 単語数
# N = condition[0]
# 行数
M = condition[1]
# Wの最小値(単語の長さの最大値を取得)
lower = max(word_lengths)
# # すべての単語をすべての行に隙間なく埋めた場合の1行の長さ
# min_length = int(sum(word_lengths) / M)
# Wの最大値(すべて1行に並べたときの長さ)
upper = sum(word_lengths) + ... | ConDefects/ConDefects/Code/abc319_d/Python/45793373 |
condefects-python_data_17 | N,M=map(int,input().split())
L=list(map(int,input().split()))
def jadge(col_num):
row_num=1
count=-1
for i in range(N):
count+=L[i]+1
if count>col_num:
row_num+=1
count=L[i]
#print(L[i],count,row_num)
return row_num
def bs():
left=max(L)
right=su... | ConDefects/ConDefects/Code/abc319_d/Python/45968743 |
condefects-python_data_18 | # -------------------------------------------------
# 基本ライブラリ(PyPy3対応)
# -------------------------------------------------
import sys
import math
import bisect #二分探索
import itertools as itert
from queue import Queue
import heapq
from collections import deque
from decimal import Decimal, ROUND_HALF_UP
sys.setrecursionl... | ConDefects/ConDefects/Code/abc319_d/Python/46194473 |
condefects-python_data_19 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
L = list(map(int, input().split()))
ng, ok = max(L) - 1, sum(L) + n - 1
while ok - ng > 1:
mid = (ok + ng) // 2
res = 1
temp = 0
for i in range(n):
temp += L[i]
if temp > mid:
res += 1
temp =... | ConDefects/ConDefects/Code/abc319_d/Python/45944386 |
condefects-python_data_20 | N,M = map(int,input().split())
L = list(map(int,input().split()))
def f(w) -> bool:
# 0の場合を特別化する
n_row = 0
# 残り文字数を管理
rem = 0
for i in range(N):
# もし残り文字数が十分であるならば、それをremから引く
if rem >= L[i]+1:
rem -= L[i]+1
else:
n_row += 1
rem = w - L[i]
... | ConDefects/ConDefects/Code/abc319_d/Python/45948664 |
condefects-python_data_21 | import itertools # permutation
import heapq # queue
if __name__ == '__main__':
n, m = map(int, input().split())
lis = list(map(int, input().split()))
for i in range(n):
lis[i] += 1
# 二分探索
l = max(lis)
r = sum(lis)
while l+1 < r:
mid = (l+r)//2
row = 1
cn... | ConDefects/ConDefects/Code/abc319_d/Python/45774151 |
condefects-python_data_22 | def check_ans(W):
'''
ある値でOKか否かの判定関数。問題に合わせて変更する。
'''
line_cnt = 1
line_char_cnt = 0
if L[0] > W:
return False
else:
line_char_cnt = L[0]
for i in range(1,N):
if L[i] > W:
return False
else:
if line_char_cnt + 1 + L[i] <= W:
... | ConDefects/ConDefects/Code/abc319_d/Python/45993248 |
condefects-python_data_23 | n, m = list(map(int, input().split()))
l = list(map(int, input().split()))
def check(x):
cnt = 1
s = l[0]
for i in range(1, n):
if s + l[i] + 1 > x:
cnt += 1
s = l[i]
else:
s += l[i] + 1
if cnt > m:
return False
return True
min_x ... | ConDefects/ConDefects/Code/abc319_d/Python/45933392 |
condefects-python_data_24 | #!/usr/bin/env python3
import math
import sys
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right # type: ignore
from collections import Counter, defaultdict, deque # type: ignore
from heapq import heapify, heappop, heappush, heappushpop, heapreplace, merge # type: ignore
from ite... | ConDefects/ConDefects/Code/abc319_d/Python/46138292 |
condefects-python_data_25 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
N, M, *L = map(int, read().split())
left = max(L)
right = 10 ** 18
while right - left > 1:
mid = (left + right) // 2
cnt = 1
idx = 0
for i, l in enumerate(L):
if idx + l <= mid:
idx += ... | ConDefects/ConDefects/Code/abc319_d/Python/45768613 |
condefects-python_data_26 | N, M = map(int, input().split())
L = list(map(int, input().split()))
ng, ok = max(L), sum(L) + N - 1
while ng + 1 < ok:
chk = (ng + ok) // 2
m = 1
w = L[0]
for l in L[1:]:
if (w + 1 + l) > chk:
m += 1
w = l
else:
w += 1 + l
if m <= M:
... | ConDefects/ConDefects/Code/abc319_d/Python/46172725 |
condefects-python_data_27 | from collections import defaultdict
from collections import deque
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1]*n
self.rank = [0]*n
def find(self, x):
if(self.root[x] < 0):
return x
else:
self.root[x] = self.find(self.root[... | ConDefects/ConDefects/Code/abc233_f/Python/50214757 |
condefects-python_data_28 | t = int(input())
for iiiii in range(t):
n = int(input())
s =(input())
flag = True
b = False
for i in range(n):
if s[i] == "B":
b=True
if s[i] == "A" and b:
flag = False
if(flag):
print("B")
else :
print("A")
t = int(input())
for iiiii in range(t):
n = int(inpu... | ConDefects/ConDefects/Code/agc062_a/Python/43213602 |
condefects-python_data_29 | n=int(input())
for _ in range(n):
t=input()
s=input()
if('A' in s[1:]):
print('A')
else:
print('B')
n=int(input())
for _ in range(n):
t=input()
s=input()
if('A'==s[-1] or 'BA' in s):
print('A')
else:
print('B')
| ConDefects/ConDefects/Code/agc062_a/Python/44927989 |
condefects-python_data_30 | def solve(N, S):
if S[-1] == 'A':
return 'A'
else:
if S.count('AB') == 1:
return 'B'
else:
return 'A'
T = int(input())
for _ in range(T):
N = int(input())
S = input()
print(solve(N, S))
def solve(N, S):
if S[-1] == 'A':
return 'A'
el... | ConDefects/ConDefects/Code/agc062_a/Python/42875065 |
condefects-python_data_31 | t = int(input())
for _ in range(t):
n = int(input())
c = input()
i = 0
j = n - 1
while i < n and c[i] == 'A':
i += 1
while j > 0 and c[j] == 'B':
j -= 1
if i - j == 1 and c[-1] == 'B':
print('B')
else:
print('A')
t = int(input())
for _ in range(t):
n ... | ConDefects/ConDefects/Code/agc062_a/Python/44110722 |
condefects-python_data_32 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
T = int(readline())
for _ in range(T):
N = int(readline())
S = readline().rstrip()
if not 'B' in S:
print('A')
continue
index_ = S.index('B')
if S == 'A' * index_ and 'B' * (N - index... | ConDefects/ConDefects/Code/agc062_a/Python/43015792 |
condefects-python_data_33 | t = int(input())
ans = []
for _ in range(t):
n = int(input())
s = input()
if s[-1] == "A":
ans.append("A")
else:
if all(i == "B" for i in s):
ans.append("B")
if any(s[i] == "B" and s[i+1] == "A" for i in range(n-1)):
ans.append("A")
else:
ans.append("B")
print("\n".join(ans))
... | ConDefects/ConDefects/Code/agc062_a/Python/44358952 |
condefects-python_data_34 | t=int(input())
for i in range(t):
n=int(input())
s=list(map(str,input()))
cnt=0
for i in range(n-1):
if s[i]=="A" and s[i+1]=="B":
cnt+=1
if cnt==0 and s[0]=="B" and s[-1]=="B":
print("B")
elif cnt==1 and s[0]=="A":
print("B")
else:
print("A")
t=int(input())
for i in range(t):
n=i... | ConDefects/ConDefects/Code/agc062_a/Python/43035982 |
condefects-python_data_35 | from itertools import product
N,S,M,L=map(int,input().split())
ans=10**20
for i,j,k in product(range(N),repeat=3):
if 6*i+8*j+12*k<N:
continue
ans=min(ans,S*i+M*j+L*k)
print(ans)
from itertools import product
N,S,M,L=map(int,input().split())
ans=10**20
for i,j,k in product(range(N+1),repeat=3):
if 6*i+8*j+12*k<N:... | ConDefects/ConDefects/Code/abc331_b/Python/54148195 |
condefects-python_data_36 | n, s, m, l = map(int,input().split())
sum = 10000
for j in range(20):
for k in range(15):
for a in range(10):
if n <= 6*j + 8*k + 12* a <= n + 11:
if s*j + m*k + l*a < sum:
sum = s*j + m*k + l*a
print(sum)
n, s, m, l = map(int,input().split())
sum = 10**10
for j in range(20):... | ConDefects/ConDefects/Code/abc331_b/Python/54957730 |
condefects-python_data_37 | n,s,m,l = map(int,input().split())
ans = float('inf')
for i in range(101):
for j in range(101):
for k in range(101):
if i+j+l>=n:
ans=min(ans,i*s+j*m+l*k)
print(ans)
n,s,m,l = map(int,input().split())
ans = float('inf')
for i in range(101):
for j in range(101):
for k in range(101):
if 6... | ConDefects/ConDefects/Code/abc331_b/Python/54769953 |
condefects-python_data_38 | import sys
from collections import defaultdict
out = []
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
l = input().split()
d = {}
for v in l:
if v not in d:
d[v] = 1
else:
d[v] += 1
big2 = []
big = []
br = []
... | ConDefects/ConDefects/Code/agc059_b/Python/37027269 |
condefects-python_data_39 | from collections import Counter, deque
import sys
sys.setrecursionlimit(2*10**5)
def dfs(v):
for _ in range(D[v+1]-len(G[v])+1):
ans.append(v+1)
D[v+1]-=1
seen[v] = True
for nv in G[v]:
if seen[nv]:
continue
dfs(nv)
if D[v+1]>0:
ans.append(v+1... | ConDefects/ConDefects/Code/agc059_b/Python/37047746 |
condefects-python_data_40 | from collections import defaultdict
T = int(input())
for _ in range(T):
N = int(input())
C = list(map(int,input().split()))
dc = {}
for c in C:
if c not in dc:
dc[c] = 0
dc[c] += 1
lst = []
cnt = 0
for k in dc:
lst.append((dc[k],k))
cnt += 1
... | ConDefects/ConDefects/Code/agc059_b/Python/37028649 |
condefects-python_data_41 | g=lambda:map(int,input().split());N,M=g();P=list(g());D=998244353;f=lambda i:i*i+i;dp=[0,0,1];h=lambda x:pow(max(1,x),-1,D);A=0
for m in range(M):a,b,c=dp;X=(N-2)*(N-3)//2+1;dp=[(a*(X+4*N-11)+b*(N-3))%D,(a*4+b*(X+N-2)+c*(2*N-4))%D,(b+c*X)%D]
for i,j in zip(P,P[1:]):s=f(i-1)+f(j-1)+f(N-i)+f(N-j);t=abs(i-j);A=(A+dp[2]*t+... | ConDefects/ConDefects/Code/arc176_d/Python/52672133 |
condefects-python_data_42 | import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush... | ConDefects/ConDefects/Code/arc176_d/Python/52671232 |
condefects-python_data_43 | import sys
input = sys.stdin.readline
mod=998244353
# 行列の計算(numpyを使えないとき,modを使用)
def prod(A,B,k,l,m):# A:k*l,B:l*m
C=[[None for i in range(m)] for j in range(k)]
for i in range(k):
for j in range(m):
ANS=0
for pl in range(l):
ANS=(ANS+A[i][pl]*B[pl][j])%mod
... | ConDefects/ConDefects/Code/arc176_d/Python/52897913 |
condefects-python_data_44 | import sys
import heapq
def main():
N = int(input())
tl = []
for _ in range(N):
T, D = map(int, input().split())
tl.append([T, T+D])
tl.sort()
q = []
time = tl[0][0]
ind = 0
heapq.heapify(q)
ans = 0
while ind < N or q:
if ind < N and time < tl[ind][0]:... | ConDefects/ConDefects/Code/abc325_d/Python/52936269 |
condefects-python_data_45 | N = int(input())
inout = [tuple(map(int, input().split())) for _ in range(N)]
inout.sort()
import heapq
from collections import defaultdict
D = defaultdict(list)
for t, d in inout:
D[t].append(t + d)
INF = 10 ** 18 + 1
event = sorted(D.keys())
event.append(INF)
ans = 0
now = 1
cnt = 0
hq = []
while now < INF:
... | ConDefects/ConDefects/Code/abc325_d/Python/53574782 |
condefects-python_data_46 | from heapq import heappush, heappop
n = int(input())
arr = [list(map(int, input().split())) for _ in range(n)]
arr = sorted(arr)
heap = []
i, cnt, t = 0, 0, 1
while i < len(arr):
if t < arr[i][0]: t = arr[i][0]
while i < len(arr) and arr[i][0] <= t:
heappush(heap, (arr[i][0] + arr[i][1]))
i += 1
while len(heap)... | ConDefects/ConDefects/Code/abc325_d/Python/53458224 |
condefects-python_data_47 | import sys
input = lambda: sys.stdin.readline().strip()
from collections import defaultdict
d = defaultdict(int)
n=int(input())
a=list(map(int,input().split()))
m=200005
for i in range(n):
d[a[i]]+=1
ans=0
for i in range(1,m):
for j in range((m-1)//i):
k=i*j
ans+=d[k]*d[i]*d[j]
print(ans)
... | ConDefects/ConDefects/Code/abc249_d/Python/44452633 |
condefects-python_data_48 | n = 10**12
def primes(n):
ass = []
is_prime = [True] * (n+1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5)+1):
if not is_prime[i]:
continue
for j in range(i*2, n+1, i):
is_prime[j] = False
for i in range(len(is_prime)):
if ... | ConDefects/ConDefects/Code/abc300_d/Python/45256387 |
condefects-python_data_49 | def extgcd(a, b):
if b:
d, y, x = extgcd(b, a % b)
y -= (a // b) * x
return d, x, y
return a, 1, 0
# V = [(X_i, Y_i), ...]: X_i (mod Y_i)
def remainder(V):
x = 0; d = 1
for X, Y in V:
g, a, b = extgcd(d, Y)
x, d = (Y*b*x + d*a*X) // g, d*(Y // g)
x %= d
... | ConDefects/ConDefects/Code/abc256_f/Python/41932099 |
condefects-python_data_50 | #!/usr/bin/env python3
import sys
from bisect import bisect_left, bisect_right, insort_left, insort_right # type: ignore
from collections import Counter, defaultdict, deque # type: ignore
from math import gcd, sqrt # type: ignore
from heapq import heapify, heappop, heappush, heappushpop, heapreplace, merge # type: ... | ConDefects/ConDefects/Code/abc256_f/Python/42749759 |
condefects-python_data_51 | if __name__ == '__main__':
s = str(input())
n = int(input())
m = len(s)
res = 0
for i in range(m):
if s[i] == "1":
res += (1 << (m - 1 - i))
if res > n:
res = -1
else:
for i in range(m - 1, -1, -1):
if s[i] == "?" and res + (1 << (m - 1 - i)) <... | ConDefects/ConDefects/Code/abc301_d/Python/45723653 |
condefects-python_data_52 |
def solve():
s = input()
n = int(input())
ans = int(s.replace('?', '0'), 2)
print(ans)
if ans > n:
print(-1)
return
m = len(s)
for i, c in enumerate(s):
if c == '?' and ans + (1 << (m - 1 - i)) <= n:
ans += (1 << (m - 1 - i))
return
solve()
def ... | ConDefects/ConDefects/Code/abc301_d/Python/45732372 |
condefects-python_data_53 | import sys
from functools import lru_cache, cmp_to_key
from itertools import accumulate
from collections import defaultdict, Counter, deque
from math import inf, sqrt, isqrt, ceil, comb
from bisect import bisect_left, bisect_right
from sortedcontainers import SortedSet, SortedList
# mod = 998244353
def main():
#... | ConDefects/ConDefects/Code/abc301_d/Python/45725346 |
condefects-python_data_54 | import sys
from collections import deque, defaultdict
from math import *
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
def get(s1, s2):
global n
i = 0
while i < len(s1) and (s1[i] == '?' or s1[i] == s2[i]):
i += 1
if i == len(s1): return n
else:
if s1[i] <... | ConDefects/ConDefects/Code/abc301_d/Python/45747617 |
condefects-python_data_55 | def get_min(s):
mask = 1
val = 0
for ch in s[::-1]:
if ch == '1':
val += mask
mask <<= 1
return val
def I():
return input()
def II():
return int(input())
def solve():
s = I()
n = II()
min_val = get_min(s)
mask = 1 << (len(s) - 1)
if min_val > n:... | ConDefects/ConDefects/Code/abc301_d/Python/45718315 |
condefects-python_data_56 | n,m = map(int,input().split())
d = [[0] * (n+2) for _ in range(n+2)]
c = [0] * (n+1)
d[0][0] = c[0] = 1
M = 998244353
for i in range(1,n+1):
for s in range(i,n+1):
d[i][s] += d[i][s-i] + c[s-i]
for s in range(n+1):
c[s] += d[i][s] - d[i-m][s]
c[s] %= M
print(d[i][n])
... | ConDefects/ConDefects/Code/abc221_h/Python/40746464 |
condefects-python_data_57 | N,M = map(int,input().split())
MOD = 998244353
dp = [[0]*(N+1) for _ in range(N+1)] #dp[i][j]: i個使ってその和がj
dp[0][0] = 1
S = [[0,0] for _ in range(N+1)]
S[0][1] = 1
for i in range(1,N+1):
for j in range(N+1):
nj = j-i
if nj < 0:
S[j].append(S[j][-1])
continue
k_max = m... | ConDefects/ConDefects/Code/abc221_h/Python/26325908 |
condefects-python_data_58 | import sys
readline = sys.stdin.readline
n,m = map(int,readline().split())
dp = [[0]*(n+1) for _ in range(n+1)]
acc = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
acc[0] = [1]*(n+1)
MOD = 9998244353
for x in range(1,n+1):
dpx = dp[x]
for y in range(1,n+1):
dpx[y] = (acc[x-y][y] - (0 if y-m-1 < 0 else ... | ConDefects/ConDefects/Code/abc221_h/Python/30564189 |
condefects-python_data_59 | #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def IR(n):
return [I() fo... | ConDefects/ConDefects/Code/abc221_h/Python/26320903 |
condefects-python_data_60 | import sys
input = sys.stdin.readline
N,M=map(int,input().split())
mod=998244353
# ヤング図形を用いて考えるのが重要
# ヤング図形に置き換えた後はDP
DP=[[0]*(N+5) for i in range(N+5)]
# DP[i][j]で、今までの総和がi、今まで使った段差がj個。
# DP[i+j][j]+=DP[i][j] : 今までの段差全てに+1
# DP[i+k+j][j+k] += DP[i][j] : 今までの段差全てに+1し、さらにk<=M個一段のものを加える。
DP[1][1]=1
DP[1+M+1][1+M+1... | ConDefects/ConDefects/Code/abc221_h/Python/26785022 |
condefects-python_data_61 | import math
from heapq import heapify, heappop, heappush
# import bisect
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
def ipt(num=0):
if num==1:return int(input())
elif num==2:return map(int, input().split())
elif num==3:return input().rstrip()
return list(map(int, input().split())... | ConDefects/ConDefects/Code/abc283_f/Python/46910621 |
condefects-python_data_62 | from collections import deque
from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)
s=input()
t=[]
for i in s:
t.append(i)
k=0
for i in range(len(t)):
if t[i]=="(":
k+=1
elif t[i]==")":
k-=1
else:
if k%2==1:
if ord(t[i])-ord("A")<26:
... | ConDefects/ConDefects/Code/abc350_f/Python/54219104 |
condefects-python_data_63 | from collections import deque
def swap_char(x, swap):
if swap == 0:
return x
else:
xu = x.upper()
if x == xu:
return x.lower()
else:
return xu
S = list(input())
left_to_right = dict()
d = deque()
for i, s in enumerate(S):
if s == "(":
d.ap... | ConDefects/ConDefects/Code/abc350_f/Python/53750325 |
condefects-python_data_64 | N, X = map(int, input().split())
A = list(map(int,input().split()))
Aset = set(A)
ok = False
for a in A:
if X-a in Aset:
ok = True
break
if ok:
print('Yes')
else:
print('No')
N, X = map(int, input().split())
A = list(map(int,input().split()))
Aset = set(A)
ok = False
for a in A:
if... | ConDefects/ConDefects/Code/abc296_c/Python/46012599 |
condefects-python_data_65 | import heapq
import math
def dijkstra(graph,start):
N = len(graph)
dist = [float('inf')] * len(graph)
dist[start] = 0
q = [(0,start)]
while q:
cost,current = heapq.heappop(q)
if dist[current] < cost: continue
if math.isfinite(dist[goal]):
print(dist[goal])
exit()
for i, weight in graph[current]:
... | ConDefects/ConDefects/Code/abc232_g/Python/28970603 |
condefects-python_data_66 | from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heapify, heappush as hpush, heappop as hpop
def dijkstra(n, E, i0=0):
kk = 18
mm = (1 << kk) - 1
h = [i0]
D = [-1] * n
done = [0] * n
D[i0] = 0
while h:
x = hpop(h)
d, i = x >> kk, x ... | ConDefects/ConDefects/Code/abc232_g/Python/28189928 |
condefects-python_data_67 | N,M=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list()
for i in range(N):
C.append([B[i]-M,i])
C.sort()
for i in range(N):
if C[i][1]==0:
st=i
if C[i][1]==N-1:
fin=i
G=[list() for i in range(N)]
for i in range(N):
if C[i][1]==0:
G[i].append([(i+2)%N,(... | ConDefects/ConDefects/Code/abc232_g/Python/28190550 |
condefects-python_data_68 | n,m = map(int, input().split())
xl = list(map(int, input().split()))
cyl = [list(map(int, input().split())) for _ in range(m)]
yl = [0] * n
for c,y in cyl:
yl[c-1] = y
dp = [[0] * (n) for i in range(n)]
for i in range(n):
if i == 0:
dp[i][0] = xl[0] + yl[0]
else:
for j in range(1,i+1):
... | ConDefects/ConDefects/Code/abc261_d/Python/45285878 |
condefects-python_data_69 | # ref: https://qiita.com/Kota-Y/items/396ab3c57830dad65cfb
import sys
import re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combi... | ConDefects/ConDefects/Code/abc261_d/Python/45506869 |
condefects-python_data_70 | n,m=map(int,input().split())
x=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(m)]
ans=0
d=[0]*(n+1)
for i in range(m):
d[s[i][0]]=s[i][1]
dp=[[0]*(n+1) for i in range(n+1)]
for i in range(n):
for j in range(1,n+1):
dp[i+1][j]=dp[i][j-1]+x[i]+d[j]
dp[i+1][0]=max(dp[i])
print(ma... | ConDefects/ConDefects/Code/abc261_d/Python/46044177 |
condefects-python_data_71 | n = int(input())
adict = dict(zip(list(range(1,n+1)), list(map(int, input().split()))))
iset = set(adict.keys())
aset = set(adict.values())
last = (iset - aset).pop()
acc = []
while last != -1:
acc.append(last)
last = adict[last]
acc.reverse()
print(acc)
n = int(input())
adict = dict(zip(list(range(1,n+1)), li... | ConDefects/ConDefects/Code/abc337_c/Python/54271526 |
condefects-python_data_72 | N = int(input())
A = list(map(int, input().split()))
s = [i for i in range(1,N+1)]
d = dict(zip(A, s))
next = d[-1]
while next!=N:
print(next, end = ' ')
next = d[next]
print(next)
N = int(input())
A = list(map(int, input().split()))
s = [i for i in range(1,N+1)]
d = dict(zip(A, s))
next = d[-1]
for _ in r... | ConDefects/ConDefects/Code/abc337_c/Python/54225038 |
condefects-python_data_73 | def solve():
H, W, N = map(int, input().split())
Grid = [[1] * (W + 1) for _ in range(H + 1)]
for i in range(N):
a, b = map(int, input().split())
Grid[a][b] = 0
ans = 0
ODP = [0] * (W + 1)
DP = [0] * (W + 1)
for i in range(1, H + 1):
ODP, DP = DP, ODP
Grid_... | ConDefects/ConDefects/Code/abc311_e/Python/45970897 |
condefects-python_data_74 | import sys, math, itertools, heapq, copy, collections, bisect, random, time
from collections import deque, defaultdict, Counter
from decimal import Decimal
from functools import lru_cache
def MI(): return map(int, sys.stdin.buffer.readline().split())
def MI1(): return map(lambda x:int(x)-1, sys.stdin.buffer.readline(... | ConDefects/ConDefects/Code/arc135_a/Python/43694743 |
condefects-python_data_75 | from collections import deque
N, M = map(int, input().split())
A = deque(map(int, input().split()))
C = deque(map(int, input().split()))
answer = []
while A[0] == 0:
A.popleft()
A = list(A)
# 多項式を筆算で割り算する動きをシミュレーションする
while len(C) >= len(A):
c = C.popleft()
answer.append(c // A[0])
for i, a in enu... | ConDefects/ConDefects/Code/abc245_d/Python/52210355 |
condefects-python_data_76 | # B
n = int(input())
a = list(map(int, input().split()))
#n = 5
#a = [3, 1, 4, 5, 4]
#print(a)
call = set()
for i in range(n):
#print(i)
#print(a[i])
if i+1 in call:
pass
else:
call.add(a[i])
print(sorted(call))
no_call =[]
for i in range(1, n+1):
if i not in call:
#print(i)
... | ConDefects/ConDefects/Code/abc293_b/Python/46050349 |
condefects-python_data_77 |
import bisect, heapq, sys, math, copy, itertools, decimal
from collections import defaultdict, deque
sys.setrecursionlimit(10**7)
def INT(): return int(input())
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return list(map(int, input().split()))
def LS(): return list(m... | ConDefects/ConDefects/Code/abc223_f/Python/46212630 |
condefects-python_data_78 | from atcoder import lazysegtree
n,q=map(int,input().split())
s=list(input())
st=lazysegtree.LazySegTree(
lambda x,y:min(x,y),
n,
lambda dd,d:dd+d,
lambda ddd,dd:ddd+dd,
0,
[0]*n
)
for i in range(n):
st.apply(i,n,2*(s[i]=="(")-1)
for i in range(q):
t,l,r=map(int,input().split())
t-=1
l-=1
r-=1
if... | ConDefects/ConDefects/Code/abc223_f/Python/45728797 |
condefects-python_data_79 | import sys
sys.setrecursionlimit(10**6)
# import resource
# resource.setrlimit(resource.RLIMIT_STACK, (1073741824//4, 1073741824//4))
from collections import deque, Counter, defaultdict
from itertools import accumulate, permutations, combinations
from bisect import bisect_left, bisect_right
from heapq import heapify, h... | ConDefects/ConDefects/Code/abc313_d/Python/45777524 |
condefects-python_data_80 | N,K = map(int,input().split())
A = [0] * N
S = []
def request(i):
if i <= K:
X = [(k+i)%(K+1)+1 for k in range(K)]
else:
X = [k+1 for k in range(K-1)] + [i+1]
print("?",*X)
s = int(input())
S.append(s)
for i in range(N):
request(i)
T = sum(S[:K+1]) % 2
for i in range(K+1):
... | ConDefects/ConDefects/Code/abc313_d/Python/45654990 |
condefects-python_data_81 | n,q = map(int,input().split())
s = str(input())
cnt = 0
for i in range(q):
t,x = map(int,input().split())
if t == 1:
cnt += 1
cnt = cnt % n
if t == 2:
print(s[(n - cnt + (x-1))%n])
n,q = map(int,input().split())
s = str(input())
cnt = 0
for i in range(q):
t,x = map(int,input().split())
if t == ... | ConDefects/ConDefects/Code/abc258_c/Python/44704874 |
condefects-python_data_82 | N = int(input())
H = list(map(int, input().split()))
ans = 0
for i in range(1, N):
if H[i] > H[i-1]:
ans = H[i]
else:
break
print(ans)
N = int(input())
H = list(map(int, input().split()))
ans = H[0]
for i in range(1, N):
if H[i] > H[i-1]:
ans = H[i]
else:
break
print(a... | ConDefects/ConDefects/Code/abc235_b/Python/44832943 |
condefects-python_data_83 | N = int(input())
H = list(map(int, input().split()))
ans = 0
for i in range(N -1):
if H[i] < H[i + 1] :
ans = H[i + 1]
if H[0] >= H[1]:
ans = H[0]
else: break
print(ans)
N = int(input())
H = list(map(int, input().split()))
ans = 0
for i in range(N -1):
if H[i] < H[i + 1] :
ans =... | ConDefects/ConDefects/Code/abc235_b/Python/45931351 |
condefects-python_data_84 | n = int(input())
H = list(map(int, input().split()))
count = 0
for i in range(n-1):
if H[i] < H[i+1]:
count += 1
print(H[count])
n = int(input())
H = list(map(int, input().split()))
count = 0
for i in range(n-1):
if H[i] < H[i+1]:
count += 1
else:
break
print(H[count])
| ConDefects/ConDefects/Code/abc235_b/Python/45498250 |
condefects-python_data_85 | N = int(input())
H = list(map(int,input().split()))
ans=0
for n in range(N-1):
if H[n+1]>H[n]:
ans=H[n+1]
else:
break
print(ans)
N = int(input())
H = list(map(int,input().split()))
ans=H[0]
for n in range(N-1):
if H[n+1]>H[n]:
ans=H[n+1]
else:
break
print(ans)
| ConDefects/ConDefects/Code/abc235_b/Python/44433073 |
condefects-python_data_86 | import sys
input = sys.stdin.readline
mod=998244353
N,S=map(int,input().split())
A=sorted(map(int,input().split()))
if 1 in A:
DP=[1,0]
else:
DP=[1,1]
DP=[DP]
# 行列の計算(numpyを使えないとき,modを使用)
def prod(A,B,k,l,m):# A:k*l,B:l*m
C=[[None for i in range(m)] for j in range(k)]
for i in range(k):
for j ... | ConDefects/ConDefects/Code/abc258_h/Python/33045301 |
condefects-python_data_87 | import sys
def mul(A, v, mod):
m = len(A)
n = len(v)
w = [0]*m
for i in range(m):
s = 0
for k in range(n):
s += A[i][k] * v[k]
w[i] = s % mod
return w
def p2(A, mod):
n = len(A)
C = [[0]*n for _ in range(n)]
for i in range(n):
for j in range... | ConDefects/ConDefects/Code/abc258_h/Python/32929696 |
condefects-python_data_88 | M=998244353
n,s=map(int,input().split())
f=lambda a,b,c,d:[(a*c+b*d*5)%M,(a*d+b*c)%M]
CD=[cd:=[M//2+1]*2]+[cd:=f(*cd,*cd)for i in range(60)]
g=1
k=0
a=[0,*map(int,input().split()),s]
for i in range(1,n+2):
x,y=0,598946612
r=a[i]-a[i-1]-1
for j in range(60):
if r&1:x,y=f(x,y,*CD[j])
r>>=1
... | ConDefects/ConDefects/Code/abc258_h/Python/50522493 |
condefects-python_data_89 | def ip():return int(input())
def mp():return map(int, input().split())
def lmp():return list(map(int, input().split()))
# 20230610 ABC305 E 1158 - Art Gallery on Graph PyPyで提出
N, M, K = mp()
edge = [[] for _ in range(N)]
for _ in range(M):
a, b = mp()
a -= 1
b -= 1
edge[a].append(b)
edge[b].append(a... | ConDefects/ConDefects/Code/abc305_e/Python/46045921 |
condefects-python_data_90 | N=int(input())
S=[input() for _ in range(N)]
#i行目のl列目からr列目までに"#"は含まれるか
pre_h = [0]*N**3
for i in range(N):
for l in range(N):
for r in range(N):
for k in range(l,r+1):
if S[i][k]=="#":
pre_h[i*N**2+l*N+r]=1
#i列目のl行目からr行目までに"#"は含まれるか
pre_w... | ConDefects/ConDefects/Code/abc233_g/Python/38349532 |
condefects-python_data_91 | def f(n):
return n**2+2*n+3
n=int(input())
print(f(f(f(n)+n))+f(f(n)))
def f(n):
return n**2+2*n+3
n=int(input())
print(f(f(f(n)+n)+f(f(n)))) | ConDefects/ConDefects/Code/abc234_a/Python/45030219 |
condefects-python_data_92 | def f(x):
return x**2+2*x+3
t = int(input())
print((f(f(t)+t)+f(f(t))))
def f(x):
return x**2+2*x+3
t = int(input())
print(f(f(f(t)+t)+f(f(t)))) | ConDefects/ConDefects/Code/abc234_a/Python/44890153 |
condefects-python_data_93 | S = input()
def inverse(n, d):
return n * pow(d, -1, MOD) % MOD
MOD = 998244353
comb = [[0]*len(S) for _ in range(len(S))]
for i in range(len(S)):
for j in range((i+1)//2+1):
if j == 0:
comb[i][j] = i+1
else:
comb[i][j] = comb[i][j-1]
comb[i][j] *= inverse(i... | ConDefects/ConDefects/Code/abc234_f/Python/53824155 |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 11