id stringlengths 24 27 | content stringlengths 37 384k | max_stars_repo_path stringlengths 51 51 |
|---|---|---|
condefects-python_data_1501 |
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = [-1 for _ in range(N)]
for i, p in enumerate(P):
C[p-1] = i+1
ans = 100000000000
from sortedcontainers import SortedList
s = SortedList(sorted(C[:K]))
for i in range(N-K):
s.remove(C[i])
s.add(C[i+K])
ans = min(ans, s[-1]-s[... | ConDefects/ConDefects/Code/abc352_d/Python/54463118 |
condefects-python_data_1502 | N = int(input())
A = list(map(int, input().split()))
ex = []
for _ in range(N-1):
s,t = map(int, input().split())
ex.append([s,t])
# print(ex)
# ex_sorted = sorted(ex, key=lambda x:x[1], reverse=True)
# ex_sorted2 = sorted(ex_sorted, key = lambda x: x[0])
# print(ex_sorted2)
for i in range(N-1):
s = ex... | ConDefects/ConDefects/Code/abc341_b/Python/54459998 |
condefects-python_data_1503 | n = int(input())
a = list(map(int,input().split()))
for i in range(n-1):
s,t = map(int,input().split())
a[i+1] = t*(a[i]//s)
print(a[-1])
n = int(input())
a = list(map(int,input().split()))
for i in range(n-1):
s,t = map(int,input().split())
a[i+1] += t*(a[i]//s)
print(a[-1]) | ConDefects/ConDefects/Code/abc341_b/Python/54862743 |
condefects-python_data_1504 | import sys
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
from col... | ConDefects/ConDefects/Code/abc286_g/Python/38690639 |
condefects-python_data_1505 | class Unionfind:#根っこ参照で付け直し、デカイ木にちっさい木をつける
def __init__(self,n):
self.parent=[i for i in range(n)]#自分の親頂点の番号
self.num=[1]*n#自分を根とする部分木の頂点の個数
self.rank=[1]*n#自分を根とする部分木の高さ
def find(self,i):
if self.parent[i]==i:
return i
else:
self.parent[i]=self.fi... | ConDefects/ConDefects/Code/abc286_g/Python/41126621 |
condefects-python_data_1506 | import sys
def root(x):
if parents[x] < 0:
return x
else:
parents[x] = root(parents[x])
return parents[x]
def unite(x, y):
x = root(x)
y = root(y)
if x == y:
return
if parents[x] > parents[y]:
x, y = y, x
parents[x] += parents[y]
parents[y] = x
... | ConDefects/ConDefects/Code/abc286_g/Python/38302356 |
condefects-python_data_1507 | n=int(input())
i=1
L=[]
while i<n:
if i&n:
L+=[i]
i*=2
ans=[]
def f(i):
add=[i]
for k in ans:
add+=[i+k]
return add
for i in L:
ans+=f(i)
print(0,*ans,sep="\n")
n=int(input())
i=1
L=[]
while i<=n:
if i&n:
L+=[i]
i*=2
ans=[]
def f(i):
add=[i]
for k in ans:... | ConDefects/ConDefects/Code/abc269_c/Python/45092563 |
condefects-python_data_1508 | MOD=998244353
n,m=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(m):
u,v=map(lambda x:int(x)-1,input().split())
graph[u].append(v)
graph[v].append(u)
visited=[0]*n
from collections import deque
def dfs(s):
if visited[s]:
return []
visited[s]=1
q=deque([s])
link... | ConDefects/ConDefects/Code/abc226_e/Python/53676492 |
condefects-python_data_1509 | from collections import defaultdict
from sys import stdin
class FastIO:
def __init__(self):
self.random_seed = 0
self.flush = False
self.inf = 1 << 32
return
@staticmethod
def read_int():
return int(stdin.readline().rstrip())
@staticmethod
def read_float()... | ConDefects/ConDefects/Code/abc226_e/Python/53053125 |
condefects-python_data_1510 | # Idea: For each connected component, there need to be an equal number of edges and vertices.
# In this case, there are 2 ways to orient the edges per component. Otherwise the answer is 0.
from atcoder.dsu import DSU
from collections import defaultdict
n, m = map(int, input().split())
edges_in_comp = defaultdict(int... | ConDefects/ConDefects/Code/abc226_e/Python/52234913 |
condefects-python_data_1511 | import collections
from collections import defaultdict
class UnionFind():
def __init__(self):
'''
unionfind経路圧縮あり,要素にtupleや文字列可,始めに要素数指定なし
'''
self.parents = dict() # {子要素:親ID,}
self.members_set = collections.defaultdict(lambda : set()) # ... | ConDefects/ConDefects/Code/abc226_e/Python/53796243 |
condefects-python_data_1512 | n,d=map(int,input().split())
t=list(map(int,input().split()))
for i in range(n-1):
if t[i+1]-t[i]<=d:
print(t[i])
break
else:
print(-1)
n,d=map(int,input().split())
t=list(map(int,input().split()))
for i in range(n-1):
if t[i+1]-t[i]<=d:
print(t[i+1])
break
else:
print(-1) | ConDefects/ConDefects/Code/abc297_a/Python/45496094 |
condefects-python_data_1513 | n,d=map(int,input().split())
data=list(map(int,input().split()))
for i in range(n-1):
if data[i+1]-data[i]<=d:
print(data[i])
quit()
print(-1)
n,d=map(int,input().split())
data=list(map(int,input().split()))
for i in range(n-1):
if data[i+1]-data[i]<=d:
print(data[i+1])
quit()
p... | ConDefects/ConDefects/Code/abc297_a/Python/45500749 |
condefects-python_data_1514 | n,d = map(int,input().split())
t = list(map(int,input().split()))
ret = -1
p = -d-1
for i in t:
if i-p<d:
ret = i
break
p=i
print(ret)
n,d = map(int,input().split())
t = list(map(int,input().split()))
ret = -1
p = -d-1
for i in t:
if i-p<=d:
ret = i
break
p=i
print(ret) | ConDefects/ConDefects/Code/abc297_a/Python/46055159 |
condefects-python_data_1515 | n,d = map(int,input().split())
t = list(map(int,input().split()))
for i in range(n-1):
if t[i+1]-t[i]<=d:
print(t[i+1])
break
print(-1)
n,d = map(int,input().split())
t = list(map(int,input().split()))
for i in range(n-1):
if t[i+1]-t[i]<=d:
print(t[i+1])
exit()
print(-1) | ConDefects/ConDefects/Code/abc297_a/Python/45281375 |
condefects-python_data_1516 | n, d =map(int, input().split())
t = list(map(int, input().split()))
ans = -1
for i in range(1, len(t)):
if t[i] - t[i-1] < d:
ans = t[i]
break
print(ans)
n, d =map(int, input().split())
t = list(map(int, input().split()))
ans = -1
for i in range(1, len(t)):
if t[i] - t[i-1] <= d:
ans = t[i]
bre... | ConDefects/ConDefects/Code/abc297_a/Python/45477733 |
condefects-python_data_1517 | n,d = map(int,input().split())
l = []
l =list(map(int,input().split()))
s = 0
h = 0
for i in range(n-1):
s = l[i+1]-l[i]
if s < d:
print(l[i+1])
h += 1
break
if h == 0:
print("-1")
n,d = map(int,input().split())
l = []
l =list(map(int,input().split()))
s = 0
h = 0
for i in range(n-1):
s = l... | ConDefects/ConDefects/Code/abc297_a/Python/46009520 |
condefects-python_data_1518 |
N, D = map(int, input().split())
T = list(map(int, input().split()))
s = -10000
for t in T:
if t-s<=D:
print(t)
break
else:
s = t
else: print(-1)
N, D = map(int, input().split())
T = list(map(int, input().split()))
s = -1e10
for t in T:
if t-s<=D:
print(t)
break
else:
s = t
else: print(-1) | ConDefects/ConDefects/Code/abc297_a/Python/45577188 |
condefects-python_data_1519 | import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#n = int(input())
#alist = list(map(int,input().split()))
#alist = []
#s = input()
x,y,a,b,c = map(int,input().split())
def judge(x,y,a,b,c):
y -= (a // x) + (1 if a % x != 0 else 0)
if... | ConDefects/ConDefects/Code/abc223_e/Python/54247228 |
condefects-python_data_1520 | #長方形の設置の仕方は川か仁の2つ
import itertools
X,Y,A,B,C = map(int,input().split())
for i in range(2):
jls = list(itertools.permutations([A,B,C]))
#仁の字型チェック
for a,b,c in jls:
x1 = (a-1)//Y +1
if x1 < X:
y1 = (b-1)//(X-x1) +1
if y1 >= Y:
if (X-x1)*(Y-y1) >= c:
print("Yes")
ex... | ConDefects/ConDefects/Code/abc223_e/Python/49036505 |
condefects-python_data_1521 | from itertools import permutations
from sys import stdin
class FastIO:
def __init__(self):
self.random_seed = 0
self.flush = False
self.inf = 1 << 32
return
@staticmethod
def read_int():
return int(stdin.readline().rstrip())
@staticmethod
def read_float():... | ConDefects/ConDefects/Code/abc223_e/Python/53250614 |
condefects-python_data_1522 | x, y, a, b, c = map(int, input().split())
def solve_two(x, y, a, b):
if x==0 or y==0:
return False
res = ((a+x-1)//x+(b+x-1)//x <= y) or ((a+y-1)//y+(b+y-1)//y <= x)
return res
def solve_three(x, y, a, b, c):
case1 = solve_two(x, y-(a+x-1)//x, b, c)
case2 = solve_two(x-(a+y-1)//y, y, b, c)
... | ConDefects/ConDefects/Code/abc223_e/Python/54491597 |
condefects-python_data_1523 | from itertools import permutations
X, Y, A, B, C = map(int, input().split())
def func1(x, y):
cnt = 0
cnt += (A+x-1)//x
cnt += (B+x-1)//x
cnt += (C+x-1)//x
return cnt <= y
if func1(X, Y) or func1(Y, X):
exit(print("Yes"))
def func2(a, b, c, x, y):
y -= (a+x-1)//x
if y <= 0:
r... | ConDefects/ConDefects/Code/abc223_e/Python/53648866 |
condefects-python_data_1524 | def check_size(length, side, area):
other = 1 - side
need = (area + length[other] - 1) // length[other]
return length[side] - need
def rec(length, rem):
for i in range(3):
if not rem & 1 << i:
continue
n_rem = rem ^ 1 << i
for side in range(2):
nxt_length = check_s... | ConDefects/ConDefects/Code/abc223_e/Python/52933845 |
condefects-python_data_1525 | n=int(input())
s=list(map(int,input().split()))
mn=[0]*3
d=[0]*3
for i in range(n-1):
d[i%3]=s[i+1]-s[i]
mn[i%3]=min(mn[i%3],d[i%3])
# print(mn)
if -sum(mn)>s[0]:
print("No")
exit()
a=[-mn[0],-mn[1]]
for i in range(n):
a.append(s[i]-a[-1]-a[-2])
print("Yes")
print(*a)
n=int(input())
s=list(map(int,... | ConDefects/ConDefects/Code/arc135_b/Python/43508289 |
condefects-python_data_1526 | n = int(input())
s = list(map(int,input().split()))
m0 = []
m1 = []
m2 = []
for i in range(n-1):
if i%3 == 0:
m0.append(s[i+1]-s[i])
if i%3 == 1:
m1.append(s[i+1]-s[i])
if i%3 == 2:
m2.append(s[i+1]-s[i])
r0 = [0]
r1 = [0]
r2 = [0]
for i in m0:
r0.append(r0[-1]+i)
for i in m1:
r1.append(r1[-1]+i)
... | ConDefects/ConDefects/Code/arc135_b/Python/40764615 |
condefects-python_data_1527 |
def main():
from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
from copy import deepcopy
import copy
import random
from collections import deque,Counter,defaultd... | ConDefects/ConDefects/Code/arc135_b/Python/39932705 |
condefects-python_data_1528 | N=int(input())
S=list(map(int,input().split()))
a=[0]*(N+2)
mini=0
minj=0
mink=0
for i in range(3,N+2):
a[i]=a[i-3]+S[i-2]-S[i-3]
if i%3==0:
if mini>a[i]:
mini=a[i]
elif i%3==1:
if minj>a[i]:
minj=a[i]
else:
if mink>a[i]:
mink=a[i]
if -mini-minj-mink<=S[0]:
print("Yes")
mini=-m... | ConDefects/ConDefects/Code/arc135_b/Python/41266489 |
condefects-python_data_1529 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
N, *S = map(int, read().split())
L = [0, 0, 0]
mi = [0, 0, 0]
for i in range(N - 1):
d = S[i + 1] - S[i]
L.append(L[-3] + d)
mi[i % 3] = min(mi[i % 3], L[-1])
for i in range(N + 2):
L[i] -= mi[i % 3]
fo... | ConDefects/ConDefects/Code/arc135_b/Python/45786471 |
condefects-python_data_1530 | (h,w,C,q),*z=[[*map(int,t.split())]for t in open(0)]
a=[0]*C;s=u=set()
for t,n,c in z[::-1]:
if t==1 and n not in s:a[c-1]+=w;s|={n};h-=1
elif t==2 and n not in u:a[c-1]+=h;u|={n};w-=1
print(*a)
(h,w,C,q),*z=[[*map(int,t.split())]for t in open(0)]
a,s,u=[0]*C,set(),set()
for t,n,c in z[::-1]:
if t==1 and n not in s... | ConDefects/ConDefects/Code/arc130_b/Python/37079672 |
condefects-python_data_1531 | h, w, c, q = map(int, input().split())
dv = set()
db = set()
ans = [0] * c
queries = [list(map(lambda x: int(x)-1, input().split())) for _ in range(q)]
for t, n, c in reversed(queries):
if t == 2:
if n not in db:
ans[c] += w - len(dv)
db.add(n)
else:
if n not in dv:
ans[c] += h - len(db)
... | ConDefects/ConDefects/Code/arc130_b/Python/40982417 |
condefects-python_data_1532 | import os,sys,random,threading
from random import randint
from copy import deepcopy
from io import BytesIO, IOBase
from types import GeneratorType
from functools import lru_cache, reduce
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from itertools import accumulate, co... | ConDefects/ConDefects/Code/abc238_f/Python/48523335 |
condefects-python_data_1533 | n,k = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
mod = 998244353
a = [0]*(n)
for i in range(n):
a[p[i]-1] = q[i]-1
dp = [[0]*(n+1) for i in range(k+1)]
dp[0][n] = 1
for i in range(n):
ai = a[i]
new = [[0]*(n+1) for i in range(k+1)]
for j in range(k+1):
... | ConDefects/ConDefects/Code/abc238_f/Python/39396735 |
condefects-python_data_1534 | n,k = map(int, input().split())
pq = []
p = list(map(int, input().split()))
q = list(map(int, input().split()))
for i in range(n):
pq.append((p[i], q[i]))
pq.sort()
a = []
for i in range(n):
a.append(pq[i][1])
#dp[i][j][m] = 数列のi番目まで考えて、今後jより大の数字はNGとなるようなもので数字をm個選んでいるような選び方
dp = [[[0]*(n+1) for _ in range(n+2)] f... | ConDefects/ConDefects/Code/abc238_f/Python/41446414 |
condefects-python_data_1535 | ''' F - Two Exams
https://atcoder.jp/contests/abc238/tasks/abc238_f
'''
import io, os, sys
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # decode().strip() if str
output = sys.stdout.write
DEBUG = os.environ.get('debug') not in [None, '0']
if DEBUG:
from inspect import currentframe, getframeinfo
... | ConDefects/ConDefects/Code/abc238_f/Python/30171666 |
condefects-python_data_1536 | N = int(input())
starts = [0] * N
ends = [0] * N
for i in range(N):
start, end = map(int, input().split())
starts[i] = start
ends[i] = end
starts.sort(reverse = True)
ends.sort(reverse = True)
n_active_intervals = 0
n_overlaps = 0
while starts:
if starts[-1] <= ends[-1]:
# print(f"start at {s... | ConDefects/ConDefects/Code/abc355_d/Python/54769975 |
condefects-python_data_1537 | import bisect
N=int(input())
A=[]
left=[]
for i in range(N):
l,r=map(int,input().split())
A.append((l,r))
A.sort()
for l,r in A:
left.append(l)
res=0
for i in range(N):
j=bisect.bisect_right(left,A[i][1])
res+=j-1-1
print(res)
import bisect
N=int(input())
A=[]
left=[]
for i in range(N):
l,r=ma... | ConDefects/ConDefects/Code/abc355_d/Python/54962724 |
condefects-python_data_1538 | from collections import deque
import sys
import math
import heapq
import random
import itertools
from functools import cmp_to_key
from fractions import Fraction
def gs():
return sys.stdin.readline().split()[0]
def gd():
return float(sys.stdin.readline())
def gi():
return int(sys.stdin.readline())
def gi... | ConDefects/ConDefects/Code/arc150_a/Python/42959730 |
condefects-python_data_1539 | t=int(input())
for i in range(t):
n, k = map(int, input().split())
s=list(input())
b1 = s.count("1")
tz = [0]
tq=[0]
cz=0
cq=0
ac=0
for j in range(n):
cz+=int(s[j]=="0")
tz.append(cz)
cq+=int(s[j]=="?")
tq.append(cq)
for j in range(0,n-k):
... | ConDefects/ConDefects/Code/arc150_a/Python/46041187 |
condefects-python_data_1540 | import sys
from collections import Counter
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
T = int(readline())
for _ in range(T):
N, K = map(int, readline().split())
S = readline().rstrip()
S += '*'
cnt_one = S.count('1')
C = Counter(S[:K])
cnt = 0
fo... | ConDefects/ConDefects/Code/arc150_a/Python/42990587 |
condefects-python_data_1541 | T = int(input())
for t in range(T):
N,K = map(int,input().split())
S = "2" + input() + "2"
S = list(S)
C = S.count("1")
if C >= 2:
st = 0
ed = -1
ng = 0
for i in range(len(S)):
if S[i] == "1":
ed = i
if st == 0:
... | ConDefects/ConDefects/Code/arc150_a/Python/42081272 |
condefects-python_data_1542 | N = int(input())
A = [list(map(int, input().split())) for _ in range(2*N-1)]
lst = [True]*(2*N)
ans = 0
c = 0
def dfs(lst, score):
global ans
global c
key = -1
for i in range(2*N):
if lst[i]:
key = i
lst[key] = False
break
if key == -1:
ans = max(a... | ConDefects/ConDefects/Code/abc236_d/Python/54275288 |
condefects-python_data_1543 |
n,k,q=map(int,input().split())
a=list(map(int,input().split()))
l=list(map(int,input().split()))
masu=[ 0 for _ in range(n)]
for i in range(k):
masu[a[i] -1] = 1
print(masu)
for i in range(q):
c=0
for j in range(n):
if masu[j] == 1:
c+=1
if c==l[i]:
if j+1>=n:
... | ConDefects/ConDefects/Code/abc257_b/Python/45964870 |
condefects-python_data_1544 | n=int(input())
s=input()
a=[]
T=False
b=1
for i in range(n-1):
if s[i]=='>':
b+=1
else:
if b!=1:
a.append(b)
b=1
if b!=1:
a.append(b)
c=0
for i in a:
c+=(n*(n-1))//2
print(c)
n=int(input())
s=input()
a=[]
T=False
b=1
for i in range(n-1):
if s[i]=='>':
b+=1
else:
if b!=1:
a... | ConDefects/ConDefects/Code/arc168_a/Python/49215452 |
condefects-python_data_1545 | from functools import lru_cache
@lru_cache
def f(maxi, no):
if maxi < 10:
return maxi - (0 < no <= maxi)
q = maxi // 10
r = maxi % 10
ans = 0
for x in range(10):
if x == no:
continue
if x <= r:
ans += f(q, x) + (x != 0)
else:
ans +... | ConDefects/ConDefects/Code/arc173_a/Python/53255887 |
condefects-python_data_1546 | def neq(x):
n = len(x)
ans = 0
if n==1:
return int(x)
for i in range(n):
if i==0:
ans += (int(x[i])-1)*(9**(n-1))+neq('9'*(n-1))
elif i==n-1:
if int(x[i-1])<=int(x[i]):
return ans+int(x[i])
else:
return ans+int(x[i])+1
elif int(x[i-1])<int(x[i]):
ans += (i... | ConDefects/ConDefects/Code/arc173_a/Python/53665831 |
condefects-python_data_1547 | from itertools import accumulate
from bisect import bisect_left
def solve(N):
p = str(N)
M = len(str(N))
dp = [[[0] * 10 for _ in range(2)] for _ in range(M + 1)]
dp[0][0][0] = 1
for i in range(M):
di = int(p[i])
for smaller in range(2):
Lim = 10 if smaller else di + 1
... | ConDefects/ConDefects/Code/arc173_a/Python/51750768 |
condefects-python_data_1548 | n = int(input())
def calc(num):
moji = str(num)
keta = len(moji)
ret = 0
for i in range(keta):
p = int(moji[i])
if i == 0:
d = max(p - 1, 0)
ret = ret + d * 9 ** (keta - i - 1)
else:
d = p + 1
if d-1 > int(moji[i - 1]):
... | ConDefects/ConDefects/Code/arc173_a/Python/53784013 |
condefects-python_data_1549 | T = int(input())
for _ in range(T):
K = int(input())
left = 1
right = 10**18
while right - left > 1:
mid = (left+right)//2
ans = 0
mid_s = str(mid)
N = len(mid_s)
for i in range(N):
ans += pow(9,i)
ans += (int(mid_s[0])-1)*pow(9,N-1)
be... | ConDefects/ConDefects/Code/arc173_a/Python/54010856 |
condefects-python_data_1550 | import sys, random
input = lambda : sys.stdin.readline().rstrip()
write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18
LI = lambda : list(map(int, input().split()));... | ConDefects/ConDefects/Code/arc150_e/Python/37666166 |
condefects-python_data_1551 | mod=998244353
inv=pow(100,mod-2,mod)
N,P=map(int,input().split())
dp=[0,1]
for i in range(N-1):
dp.append(1+dp[-1]*(100-P)*inv+dp[-2]*P*inv)
dp[-1]%=mod
print(dp[-1])
print(dp)
mod=998244353
inv=pow(100,mod-2,mod)
N,P=map(int,input().split())
dp=[0,1]
for i in range(N-1):
dp.append(1+dp[-1]*(100-P)*inv+dp[... | ConDefects/ConDefects/Code/abc280_e/Python/45489025 |
condefects-python_data_1552 | from functools import lru_cache
S_x = lambda : input()
N_x = lambda : int(input())
N_more = lambda : map(int, input().split())
A_L = lambda : list(map(int, input().split()))
N = N_x()
@lru_cache
def n_split(x):
if x == 1:
return 1
else:
if x % 2 == 0:
return n_split(x//2) + n_split(x//2) + x
els... | ConDefects/ConDefects/Code/abc340_c/Python/54788831 |
condefects-python_data_1553 | import math
import functools
n = int(input())
@functools.cache
def calc(m):
if m < 2:
return 0
return m + calc(int(m / 2)) + calc(int((m + 1) / 2))
print(calc(n))
import math
import functools
n = int(input())
@functools.cache
def calc(m):
if m < 2:
return 0
return m + calc(m // 2) + calc((m + 1)... | ConDefects/ConDefects/Code/abc340_c/Python/54883033 |
condefects-python_data_1554 | import sys
input = sys.stdin.readline
from functools import lru_cache
@lru_cache(maxsize=None)
def grundy(N,L):
if N<L:
return 0
SET={grundy(N-L,L)}
x=N-L
for i in range(N-L):
SET.add(grundy(i,L)^grundy(x-i,L))
for i in range(10**9):
if i in SET:
pass... | ConDefects/ConDefects/Code/abc278_g/Python/36887453 |
condefects-python_data_1555 | def check(arg, case):
if case == 1:
# 平均値をargにできるか
B = [a - arg for a in A]
else:
if arg not in A:
return False
# 中央値をargにできるか
B = [1 if a >= arg else -1 for a in A]
# dp[i][j]:= i番目まで見て、i+1番目を 選ぶ / 選ばない(1 / 0)ときの総和の最大値
dp = [[0] * 2 for _ in range(n ... | ConDefects/ConDefects/Code/abc236_e/Python/45576293 |
condefects-python_data_1556 | from time import time
st_time = time()
N = int(input())
A = list(map(int,input().split()))
def calc_divs(n):
divs = set()
m = 1
while m*m <= n:
if n%m==0:
divs.add(m)
divs.add(n//m)
m += 1
return divs
from collections import Counter
end = set()
from random impo... | ConDefects/ConDefects/Code/abc272_g/Python/48246740 |
condefects-python_data_1557 | 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)
if temp!=1:
arr.append(temp)
if arr==[]:
arr.append(n)
... | ConDefects/ConDefects/Code/abc272_g/Python/48872899 |
condefects-python_data_1558 | 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 input().rstrip()
return list(map(int, input().split()))
mod = 998244353
# d = [[0]*s2 for t in range(s1)]
# for i in range():
n=ipt()[0]
a=... | ConDefects/ConDefects/Code/abc272_g/Python/47192828 |
condefects-python_data_1559 | def Divisors(N):
divisors=[]
for i in range(1,N+1):
if i**2>=N:
break
elif N%i==0:
divisors.append(i)
if i**2==N:
divisors+=[i]+[N//i for i in divisors[::-1]]
else:
divisors+=[N//i for i in divisors[::-1]]
return divisors
import random
N=int(i... | ConDefects/ConDefects/Code/abc272_g/Python/54704821 |
condefects-python_data_1560 | import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
def gcd(a, b):
while a:
a, b = b%a, a
return b
def is_prime(n):
if n == 2:
return 1
if n == 1 or n%2 == 0:
return 0
m = n - 1
lsb = m & -m
s = lsb.bit_length()-1
d ... | ConDefects/ConDefects/Code/abc272_g/Python/53473806 |
condefects-python_data_1561 | import math
import random
from collections import Counter
from sys import stdin
class FastIO:
def __init__(self):
self.random_seed = 0
self.flush = False
self.inf = 1 << 32
return
@staticmethod
def read_int():
return int(stdin.readline().rstrip())
@staticmetho... | ConDefects/ConDefects/Code/abc272_g/Python/52009362 |
condefects-python_data_1562 | P=[1]*10**6
for i in range(2,10**6):
if P[i]:
for j in range(i+i,10**6,i):
P[j]=0
P=[i for i in range(2,10**6) if P[i]]
n=int(input())
a=list(map(int,input().split()))
from random import randint
for _ in range(500):
i=randint(0,n-1)
j=randint(0,n-2)
j+=j<=i
A=abs(a[i]-a[j])
p=[]
for v in P:
... | ConDefects/ConDefects/Code/abc272_g/Python/48974864 |
condefects-python_data_1563 | from math import gcd
k = int(input())
for i in range(2, 1000001):
d = gcd(k, i)
if d > 1:
k //= d
if k == 1:
print(i)
exit()
print(k)
from math import gcd
k = int(input())
for i in range(2, 2000001):
d = gcd(k, i)
if d > 1:
k //= d
if k == 1:
print(i)
... | ConDefects/ConDefects/Code/abc280_d/Python/46198307 |
condefects-python_data_1564 | import math
k=int(input())
for i in range(2,10**6+2):
k//=math.gcd(k,i)
if k==1:
print(i)
exit()
print(k)
import math
k=int(input())
for i in range(2,5*10**6):
k//=math.gcd(k,i)
if k==1:
print(i)
exit()
print(k) | ConDefects/ConDefects/Code/abc280_d/Python/45204785 |
condefects-python_data_1565 | n=int(input())
f=[]
y=n
for i in range(2,int(y**0.5)+1):
while n%i==0:
f.append(i)
n//=i
if n!=1:
f.append(n)
if max(f)>int(y**0.5)+1:
print(y)
else:
import math
x=2
while True:
y//=math.gcd(y,x)
if y==1:
print(x)
exit()
else:
... | ConDefects/ConDefects/Code/abc280_d/Python/46193678 |
condefects-python_data_1566 | import math
K = int(input())
for i in range(2,10**6):
tmp=math.gcd(K,i)
if tmp!=1:
K//=tmp
if K==1:
print(i)
exit()
print(K)
import math
K = int(input())
for i in range(2,(10**6)*5):
tmp=math.gcd(K,i)
if tmp!=1:
K//=tmp
if K==1:
p... | ConDefects/ConDefects/Code/abc280_d/Python/46199363 |
condefects-python_data_1567 | n,m=map(int,input().split())
if not m:
if n&1:
print('Takahashi')
else:
print('Aoki')
exit()
xy = [tuple(map(int,input().split())) for _ in range(m)]
g = (xy[0][0]-1)^(n-xy[-1][0])
for i in range(m-1):
x1,y1 = xy[i]
x2,y2 = xy[i+1]
d = x2-x1-1
if d==0:
continue
... | ConDefects/ConDefects/Code/arc151_c/Python/43507594 |
condefects-python_data_1568 | N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(M)]
if M == 0:
print('Takahashi' if N % 2 else 'Aoki')
exit()
state = 0
for i in range(M-1):
a, b = A[i]
c, d = A[i+1]
state ^= ((c-a-1) % 2) ^ b ^ d
state ^= A[0][0]-1
state ^= N-A[-1][0]
print('Takahashi' if st... | ConDefects/ConDefects/Code/arc151_c/Python/38957887 |
condefects-python_data_1569 | n,m = map(int,input().split())
if m == 0:
print("Takahashi" if n % 2 else "Aoki")
exit()
li = [list(map(int,input().split())) for _ in range(m)]
sg = (n - li[-1][0])^(li[0][1] - 1)
for i in range(m - 1):
sg ^= int(li[i + 1][1] == li[i][1])
print('Takahashi' if sg else 'Aoki')
n,m = map(int,input().split())... | ConDefects/ConDefects/Code/arc151_c/Python/40405027 |
condefects-python_data_1570 | n, m = map(int, input().split())
before_x = -1
before_y = -1
grundy = 0
for _ in range(m):
x, y = map(int, input().split())
if before_x == -1:
grundy ^= x - 1
else:
grundy ^= (x - before_x + 1 - (before_y ^ y)) % 2
before_x, before_y = x, y
if before_x == -1:
grundy ^= n % 2
else:
... | ConDefects/ConDefects/Code/arc151_c/Python/36321896 |
condefects-python_data_1571 | import sys
read = sys.stdin.buffer.read
N,M,*XY = map(int,read().split())
if M==0 :
if N % 2 == 1:
g = 1
else:
g = 0
else:
it = iter(XY)
XY = [[xi,yi] for xi,yi in zip(it,it)]
g = 0
if XY[0][0] != 1:
g ^= XY[0][0] - 1
if XY[-1][0] != 1:
g ^= N - XY[-1][0]
... | ConDefects/ConDefects/Code/arc151_c/Python/41930310 |
condefects-python_data_1572 | import bisect, collections, copy, heapq, itertools, math, sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
# P = 10**9+7
P = 998244353
N, M = map(int, input().split())
S = list(list(map(int, input().split())) for _ in range(M))
ans = 0
if M == 0:
ans ^= N%2
if M > 0:
ans ^= S[0][0]-1
ans ^= N-S... | ConDefects/ConDefects/Code/arc151_c/Python/38433732 |
condefects-python_data_1573 | from sys import stdin
n,m = map(int,input().split())
l = []
for i in range(m):
x,y = map(int,stdin.readline().split())
l.append([x-1,y])
l.sort()
if m == 0:
ans = n % 2
else:
ans = l[0][0] ^ (n - l[-1][0] - 1)
for i in range(1,len(l) - 1):
if l[i][1] == l[i-1][1]:
ans ^= 1
if ans != 0:
print("Taka... | ConDefects/ConDefects/Code/arc151_c/Python/37458250 |
condefects-python_data_1574 | n,m = map(int,input().split())
xy = [list(map(int,input().split())) for i in range(m)]
g = 0
if m == 0:
if n%2:
print("Takahashi")
else:
print("Aoki")
exit()
for i in range(m+1):
if i == 0:
x,y = xy[i]
g ^= x-1
elif i == m:
x,y = xy[i-1]
g ^= n-x
else:
x,y = xy[i]
px,py = xy[... | ConDefects/ConDefects/Code/arc151_c/Python/36785462 |
condefects-python_data_1575 | def solve(N):
if N == 1:
return [1]
if N == 2:
return None
ans = [2]
used = set([3, 6])
for _ in range(N - 3):
for v in list(used):
if v + 1 not in used and v * (v + 1) not in used:
used.discard(v)
used.add(v + 1)
u... | ConDefects/ConDefects/Code/arc163_c/Python/45533123 |
condefects-python_data_1576 | from sys import stdin
from collections import deque
T = int(stdin.readline())
for tc in range(T):
n = int(stdin.readline())
if n == 1:
print('Yes')
print(1)
elif n == 2:
print('No')
st = {2,3,6}
a = deque([2,3,6])
fin = []
while len(a) + len(fin) < n:
cur = a.popleft()
if (cur+1 in st) or (cur*(cur... | ConDefects/ConDefects/Code/arc163_c/Python/43286713 |
condefects-python_data_1577 | # coding: utf-8
from random import randint
from functools import partial
import sys
try:
dummy = src
rl = partial(src.pop, 0)
except NameError:
rl = sys.stdin.readline
def ints():
return list(map(int, rl().rstrip().split(' ')))
def int1():
return int(rl().rstrip())
#@psecs
def main():
n, m = ... | ConDefects/ConDefects/Code/abc267_c/Python/45068144 |
condefects-python_data_1578 | # Python3/Pypy3テンプレート集
#ライブラリ-------------------------------------------------------------------
from bisect import *
import heapq
import collections
from collections import deque
from queue import Queue
from itertools import groupby
import itertools
import math
import array
import string
import copy
from decimal impo... | ConDefects/ConDefects/Code/abc267_c/Python/45118455 |
condefects-python_data_1579 | from collections import deque
N, M = map(int, input().split())
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
res = 0
que = deque()
A = A[::-1]
idx = 0
for l in range(N):
while A and len(que) < M:
n = A.pop()
que.append... | ConDefects/ConDefects/Code/abc267_c/Python/45076867 |
condefects-python_data_1580 | # -*- coding: utf-8 -*-
def match(sub: list[str]) -> bool:
if len(sub) != len(t):
return False
for e1, e2 in zip(sub, t):
if e1 != e2 and e1 != "#":
return False
return True
n, m = map(int, input().split())
s = list(input())
t = input()
que: list[int] = []
for i in range(n):... | ConDefects/ConDefects/Code/abc329_e/Python/51958155 |
condefects-python_data_1581 | n,m=map(int,input().split())
s=input()
t=input()
dp=[[False]*(m+1) for i in range(n+1)]
dp[0][0]=True
for i in range(n):
if dp[i][0]:
for k in range(m):
tl=t[k:]
if i-k<0 or i+(m-k)>n:
continue
for j in range(1,len(tl)+1):
if s[i:i+j]==tl... | ConDefects/ConDefects/Code/abc329_e/Python/54232904 |
condefects-python_data_1582 | # coding: utf-8
# Your code here!
n,m=map(int,input().split())
s=input()
t=input()
dp=[[[False]for _ in range(m+1)]for _ in range(n+1)]
dp[0][0]=True
for i in range(n):
if i+m<=n:
for j in range(m+1):
if dp[i][j]:
dp[i][0]=True
if dp[i][m]:
for j in range(m+1):
... | ConDefects/ConDefects/Code/abc329_e/Python/50998625 |
condefects-python_data_1583 | N, M = map(int,input().split())
S = list(input())
T = input()
from collections import deque
q = deque([])
for i in range(N-M+1) :
if "".join(S[i:i+M]) == T :
q.append(i)
def chk(s_,t) :
rtn = False
for i, ch in enumerate(t) :
if s_[i] == "#" : continue
if s_[i] != ch : return Fals... | ConDefects/ConDefects/Code/abc329_e/Python/52726801 |
condefects-python_data_1584 | N,M = map(int,input().split())
S = input()
T = input()
arr = [[0,0]]
for i in range(N-M+1):
if T == S[i:i+M]:
arr.append([i,i+M])
arr.append([N,N])
if not arr:
exit(print('No'))
for j,(l,r) in enumerate(arr):
if j==0 or j==len(arr)-1: continue
ll = arr[j-1][1]
rr = arr[j+1][0]
ok = {l... | ConDefects/ConDefects/Code/abc329_e/Python/52260983 |
condefects-python_data_1585 | from itertools import combinations
N, M, K = map(int, input().split())
edge = []
for _ in range(M):
u, v, w = map(int, input().split())
edge.append([u - 1, v - 1, w])
def find(x):
if R[x] < 0:
return x
else:
R[x] = find(R[x])
return R[x]
def unite(root_a, root_b):
i... | ConDefects/ConDefects/Code/abc328_e/Python/51767048 |
condefects-python_data_1586 | import sys
sys.setrecursionlimit(10**8)
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
def perm(n):
rt = []
def iter(s, acc):
if not s:
rt.append(acc[:])
for i in range(len(s)):
v = s[i]
... | ConDefects/ConDefects/Code/abc332_d/Python/53758957 |
condefects-python_data_1587 | from collections import defaultdict
H,W,N=map(int,input().split())
sx,sy=map(int,input().split())
gx,gy=map(int,input().split())
from collections import deque
import bisect
def bfs(s):
dq=deque()
dq.append([s,0])
high=defaultdict(lambda:-1)
high[s]=0
while len(dq)!=0:
p,h=dq.popleft()
... | ConDefects/ConDefects/Code/abc241_f/Python/41657280 |
condefects-python_data_1588 | # begin template
# begin import
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
# import sys
# sys.setrecursionlimit(10**7)
import sys
from collections import deque
from collections import defaultdict
from collections import Counter
from copy import copy, deepcopy
from functools import cmp_to_key as cmp... | ConDefects/ConDefects/Code/abc241_f/Python/51143333 |
condefects-python_data_1589 | n=int(input())
k=set([])
for i in range(n):
s=input()
S=[]
for i in range(len(s)):
S.append(s[i])
t=""
for i in range(len(s)):
t+=S[len(s)-1-i]
if not s in k:
if len(s)==1:
k.add(s)
k.add(s+str(1))
else:
k.add(s)
k.add(t)
print(int(len(k)/2))
n=int(input())
k=set... | ConDefects/ConDefects/Code/abc310_c/Python/45695385 |
condefects-python_data_1590 | N = int(input())
Z = set()
count = 0
for i in range(N):
S = input()
if S in Z:
count += 1
Z.add(S)
Z.add(S[::-1])
print(count)
N = int(input())
Z = set()
count = 0
for i in range(N):
S = input()
if S not in Z:
count += 1
Z.add(S)
Z.add(S[::-1])
print(count)
| ConDefects/ConDefects/Code/abc310_c/Python/45952581 |
condefects-python_data_1591 | from collections import defaultdict
class UnionFind():
"""
Union Find木クラス
Attributes
--------------------
n : int
要素数
root : list
木の要素数
0未満であればそのノードが根であり、添字の値が要素数
rank : list
木の深さ
"""
def __init__(self, n):
"""
Parameters
---... | ConDefects/ConDefects/Code/abc259_d/Python/53573512 |
condefects-python_data_1592 | class UnionFind:
def __init__(self, n:int) -> None:
self.parents = list(range(n))
self.rank = [0] * n
def find(self, x:int) -> int:
if self.parents[x] == x:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
d... | ConDefects/ConDefects/Code/abc259_d/Python/52382935 |
condefects-python_data_1593 | from collections import defaultdict
import sys
sys.setrecursionlimit(10**5)
N = int(input())
sx,sy,tx,ty = list(map(int,input().split()))
circles = []
for i in range(N):
x,y,r = list(map(int,input().split()))
circles.append((x,y,r))
s_maru = -1
t_maru = -1
for i in range(N):
x,y,r = circles[i]
if((sx-x... | ConDefects/ConDefects/Code/abc259_d/Python/54723545 |
condefects-python_data_1594 | import sys, itertools, functools, collections, bisect, math
from math import factorial as fact
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rmi = lambda: map(int, input().split())
ra = lambda: [int(x) for x in input().split()]
INF = 10**18
MOD = 10**9+7
def solve():
... | ConDefects/ConDefects/Code/abc289_c/Python/45332649 |
condefects-python_data_1595 | import itertools
n,m = map(int,input().split())
l = []
for i in range(m):
c = int(input())
a = list(map(int,input().split()))
l.append(a)
ans = 0
for i in range(1,n+1):
for j in itertools.combinations(l,i):
s = set([])
for k in j:
s = s | set(k)
if len(s) == n:
ans += 1
print(ans)
impo... | ConDefects/ConDefects/Code/abc289_c/Python/45901971 |
condefects-python_data_1596 | N = int(input())
A = list(map(int,input().split()))
check = [[] for _ in range(N+1)]
for i in range(N):
check[A[i]].append(i)
ans = 0
for i in check:
tmp = []
for j in range(len(i)-1):
tmp.append(i[j+1]-i[j]-1)
for j in range(len(tmp)):
ans += tmp[j]*(len(tmp)-j)
print(ans)
N = int(... | ConDefects/ConDefects/Code/abc318_e/Python/45971987 |
condefects-python_data_1597 | N=int(input())
A = list(map(int, input().split()))
l = [[] for i in range(3*10**5+1)]
for i,j in enumerate(A):
l[j].append(i)
#print(l[1])
ans=0
for i in range(1,300001):
now = l[i]
cnt = 0
M = len(now)-1
for j in range(len(now)-1):
space = now[j+1]-now[j]-1
cnt += M-j
ans... | ConDefects/ConDefects/Code/abc318_e/Python/45983420 |
condefects-python_data_1598 | import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
#input = sys.stdin.readline
mod = 998344353
n = int(input())
#https://qiita.com/Kiri8128/items/cbaa021dbcb07b5fdb92#非再帰-bfs
edge = [[] for i in range(n)]
for i in... | ConDefects/ConDefects/Code/abc287_f/Python/51238563 |
condefects-python_data_1599 | n, m = map(int, input().split())
p = []
c = []
f = []
for i in range(n):
l = list(map(int, input().split()))
p.append(l[0])
c.append(l[1])
f.append(set(l[2:]))
for i in range(n):
for j in range(n):
if p[i] >= p[j]:
if f[j].issuperset(f[i]):
print("Yes")
... | ConDefects/ConDefects/Code/abc310_b/Python/45545558 |
condefects-python_data_1600 | N, M = map(int, input().split())
product = [list(map(int, input().split())) for _ in range(N)]
product.sort(reverse=True)
answer = False
for i in range(N):
for j in range(i+1, N):
Pi = product[i][0]
Pj = product[j][0]
Fi = set(product[i][2:])
Fj = set(product[j][2:])
if Fi <... | ConDefects/ConDefects/Code/abc310_b/Python/46023032 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.