id stringlengths 24 27 | content stringlengths 37 384k | max_stars_repo_path stringlengths 51 51 |
|---|---|---|
condefects-python_data_1401 | N, M = map(int, input().split())
p = [int(i) for i in input().split()]
memo = [-1] * (N + 1)
for i in range(M):
x, y = map(int, input().split())
memo[x] = y
for j in range(2, N + 1):
memo[j] = max(memo[j], memo[p[j - 2]] - 1)
ans = 0
for i in range(N + 1):
ans += memo[i] >= 0
print(ans)
N, M = map... | ConDefects/ConDefects/Code/abc309_e/Python/46044734 |
condefects-python_data_1402 | import sys
input = sys.stdin.buffer.readline
sr = lambda: input().rstrip().decode('ascii') # 文字列の読み込み
ir = lambda: int(input()) # 数字の読み込み
lr = lambda: list(map(int, input().split())) # 数字の配列の読み込み
N, M = lr()
p = lr()
tree = [set() for _ in range(N)]
for i in range(1, N):
tree[p[i-1]-1].add(i)
ins = [-1]*N
for i in... | ConDefects/ConDefects/Code/abc309_e/Python/46214263 |
condefects-python_data_1403 | class Input_kyopro:
def II(self): return int(input())
def MI(self): return map( int,input().split())
def MS(self): return map(str,input().split())
def LMI(self): return list(self.MI())
def LMS(self): return list(self.MS())
def LLI(self,N): return [self.LMI() for _ in range(N)]
def LLS(self,N... | ConDefects/ConDefects/Code/abc309_e/Python/45971969 |
condefects-python_data_1404 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import Counter, defaultdict, deque
from typing import DefaultDict, List
N, M = map(int, input().split())
P = list(map(int, input().split()))
G: DefaultDict[int, List[int]] = defaultdict(list)
for i, p in enumerate(P, 2):
G[p].append(i)
... | ConDefects/ConDefects/Code/abc309_e/Python/45761344 |
condefects-python_data_1405 | from collections import deque
N = int(input())
G = [[] for _ in range(N)]
dist = [0 for _ in range(N)]
for _ in range(N):
u, v = map(int, input().split())
u -= 1
v -= 1
G[u].append(v)
G[v].append(u)
dist[u] += 1
dist[v] += 1
que = deque([])
for i in range(N):
if dist[i] == 1:
qu... | ConDefects/ConDefects/Code/abc266_f/Python/50709042 |
condefects-python_data_1406 | n=int(input())
a=list(map(int,input().split()))
st=set()
for i in a:
st.add(i)
ans=0
while n>=0:
if ans+1 in st:
n-=1
ans+=1
else:
if n>1:
n-=2
ans+=1
else:
print(ans)
exit()
print(ans)
n=int(input())
a=list(map(int,input... | ConDefects/ConDefects/Code/abc271_c/Python/45062381 |
condefects-python_data_1407 | from collections import deque
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
deq = deque()
se = set()
non_need = deque()
for a in A:
if a not in se:
se.add(a)
deq.append(a)
else:
non_need.append(a)
deq = deq + non_need
for i in range(N):
ni = i + 1
if deq a... | ConDefects/ConDefects/Code/abc271_c/Python/45004566 |
condefects-python_data_1408 | N = int(input())
a = list(map(int, input().split()))
st = set()
for i in range(N):
st.add(a[i])
ans = 0
s = 0
for i in range(1, N):
if i in st:
s += 1
else:
s += 2
if s > N:
break
ans = i
print(ans)
N = int(input())
a = list(map(int, input().split()))
st = set()
for i in ran... | ConDefects/ConDefects/Code/abc271_c/Python/45808178 |
condefects-python_data_1409 | A,B = map(int,input().split())
print(A//B+1)
A,B = map(int,input().split())
print((A-1)//B+1) | ConDefects/ConDefects/Code/abc302_a/Python/46001200 |
condefects-python_data_1410 | A, B = map(int, input().split())
print(1 + A // B)
A, B = map(int, input().split())
print((A + B - 1) // B) | ConDefects/ConDefects/Code/abc302_a/Python/45467003 |
condefects-python_data_1411 | x, y = map(int, input().split())
print(int(x/y)+1)
x, y = map(int, input().split())
print((x+y-1)//y) | ConDefects/ConDefects/Code/abc302_a/Python/45902614 |
condefects-python_data_1412 | A,B = map(int,input().split())
if A%B == 0:
print(int(A/B))
else:
print(int(A//B)+1)
A,B = map(int,input().split())
if A%B == 0:
print(int((A+B-1)//B))
else:
print(int(A//B)+1) | ConDefects/ConDefects/Code/abc302_a/Python/45783782 |
condefects-python_data_1413 | a=int(input())
x=0
y=0
lot=[]
deli=[]
for i in range(a):
x,y=map(int,input().split())
lot.append(x)
deli.append(y)
x=lot[deli.index(max(deli))]
y=deli.index(max(deli))
maxx=max(deli)
lot.pop(y)
deli.pop(y)
num=[]
for i in range(len(deli)):
if lot[i]==x:
num.append(deli[i]/2)
else:
nu... | ConDefects/ConDefects/Code/abc315_c/Python/46161967 |
condefects-python_data_1414 | result="Yse"
N=int(input())
lis=list(map(int,input().split(' ')))
for i in range(len(lis)-1):
if lis[i]!=lis[i+1]:
result="No"
print(result)
result="Yes"
N=int(input())
lis=list(map(int,input().split(' ')))
for i in range(len(lis)-1):
if lis[i]!=lis[i+1]:
result="No"
print(result) | ConDefects/ConDefects/Code/abc324_a/Python/54513764 |
condefects-python_data_1415 | N=int(input())
A = set(map(int, input().split()))
print('Yes' if len(A) else 'No')
N=int(input())
A = set(map(int, input().split()))
print('Yes' if len(A)==1 else 'No') | ConDefects/ConDefects/Code/abc324_a/Python/54455002 |
condefects-python_data_1416 | G = [[1, 2], [2, 3], [4, 5], [5, 6], [7, 8], [8, 9], [1, 4], [4, 7], [2, 5], [5, 8], [3, 6], [6, 9]]
R = list(map(int, input().split()))
flag = False
for g in G:
if R[0] == g[0] and R[1] == g[1]:
flag = True
if flag:
print("Yes")
else:
print("No")
G = [[1, 2], [2, 3], [4, 5], [5, 6], [7, 8], [... | ConDefects/ConDefects/Code/abc309_a/Python/45974546 |
condefects-python_data_1417 | a, b = map(int, input().split())
if b-a != 1:
print("No")
cnt = 0
def judge(s):
if s in (1,3,4,6,7,9):
return 1
else:
return 2
if judge(a) + judge(b) == 2:
print("No")
else:
print("Yes")
a, b = map(int, input().split())
if b-a != 1:
print("No")
exit()
def judge(s):
if s in (1,3,... | ConDefects/ConDefects/Code/abc309_a/Python/45963671 |
condefects-python_data_1418 | A,B = map(int,input().split())
if (A,B) ==(1,2):
print("Yes")
elif (A,B) ==(2,3):
print("Yes")
elif (A,B) ==(4,5):
print("Yes")
elif (A,B) == (5,6):
print("Yes")
elif (A,B) ==(7,8):
print("Yes")
elif (A,B) ==(8,9):
print("Yes")
A,B = map(int,input().split())
if (A,B) ==(1,2):
print("Yes")
elif (A,B) ==(2... | ConDefects/ConDefects/Code/abc309_a/Python/45775765 |
condefects-python_data_1419 | A,B=map(int, input().split())
if A%3==0 and B==A+1:
print('No')
elif A==B-1 or A==B-3:
print('Yes')
else:
print('No')
A,B=map(int, input().split())
if A%3==0 and B==A+1:
print('No')
elif A==B-1:
print('Yes')
else:
print('No') | ConDefects/ConDefects/Code/abc309_a/Python/46161633 |
condefects-python_data_1420 | a,b=map(int,input().split())
if set([a,b]) not in [{3,4},{6,7}] and abs(a-b) in [1,3]:
print("Yes")
else:
print("No")
a,b=map(int,input().split())
if set([a,b]) not in [{3,4},{6,7}] and abs(a-b)==1:
print("Yes")
else:
print("No") | ConDefects/ConDefects/Code/abc309_a/Python/45763717 |
condefects-python_data_1421 | import sys
import string
import numpy as np
from collections import defaultdict, deque
from math import dist
import itertools
import operator
INF = -1000000000000000000
A, B = map(int, input().split())
ax = (A - 1) // 3
ay = (A - 1) % 3
bx = (B - 1) // 3
by = (B - 1) % 3
print("Yes" if ax == ay and by - ay == 1 else... | ConDefects/ConDefects/Code/abc309_a/Python/46003315 |
condefects-python_data_1422 | #a = int(input());
list_A_B = list(map(int, input().split()));
A = list_A_B[0]
B = list_A_B[1]
#x = int(input());
if A%3 == 1 and B == A+1:
print('Yes')
elif A%3 == 2 and B == A+1:
print('YES')
else:
print('No')
#a = int(input());
list_A_B = list(map(int, input().split()));
A = list_A_B[0]
B = list_A_B[1]... | ConDefects/ConDefects/Code/abc309_a/Python/46005581 |
condefects-python_data_1423 |
p = {1:(2, 4), 2:(1, 5, 3), 3:(2, 6), 4:(1, 5, 7), 5:(2, 4, 6, 8), 6:(3, 5, 9), 7:(4, 8), 8:(5, 7, 9), 9:(6, 8)}
A, B = map(int, input().split())
if B in p[A]:
print("Yes")
else:
print("No")
p = {1:(2,), 2:(1, 3), 3:(2,), 4:(5,), 5:(6, 8), 6:(5,), 7:(8,), 8:(7, 9), 9:(8,)}
A, B = map(int, input().split())... | ConDefects/ConDefects/Code/abc309_a/Python/45782370 |
condefects-python_data_1424 | a,b=map(int,input().split())
if b==a+1:
if a%3!=0:
print('Yes')
else:
print('No')
a,b=map(int,input().split())
if b==a+1:
if a%3!=0:
print('Yes')
else:
print('No')
else:
print('No') | ConDefects/ConDefects/Code/abc309_a/Python/45740476 |
condefects-python_data_1425 | grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
a = list(map(int, input().split()))
for i in range(3):
for j in range(2):
for k in range(2):
if (a[k%2] == grid[i][j] and a[(k+1)%2] == grid[i][j+1]) or (a[k%2] == grid[j][i] and a[(k+1)%2] == grid[j+1][i]):
exit(print("Yes"))
print("No")
grid = [[1, 2, 3], ... | ConDefects/ConDefects/Code/abc309_a/Python/45980846 |
condefects-python_data_1426 | from collections import defaultdict
from string import ascii_letters, ascii_lowercase, ascii_uppercase
from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
INF = 10**18
numChar = 26
numChar2 = numChar*numChar
N = int(input())
scores = defaultdict(int)
for _ in range(N):
... | ConDefects/ConDefects/Code/abc264_g/Python/42294250 |
condefects-python_data_1427 | def SPFA(g, start):#g: グラフ, start: 始点
from collections import deque
n = len(g)
relax_max = [n]*n #緩和回数
is_inQ = [False]*n #キューに入っているか
dist = [float("inf")]*n
dist[start] = 0
q = deque([start])
while q:
v = q.popleft()
is_inQ[v] = False
for to,cost in g[v]:
... | ConDefects/ConDefects/Code/abc264_g/Python/34022331 |
condefects-python_data_1428 | from functools import lru_cache
@lru_cache(maxsize=1000)
def f(a):
return chr(a+97)
Q=int(input())
C=dict()
for _ in range(Q):
T,P=input().split()
P=int(P)
C[T]=P
d=dict()
G=list()
M=26**3+26**2+1
L=[0]*M
N=26**3
for i in range(26):
for j in range(26):
for s in range(26):
S=f(i)+f(j)+f(s)
L[6... | ConDefects/ConDefects/Code/abc264_g/Python/34040426 |
condefects-python_data_1429 | import copy
h1,w1=map(int,input().split())
A=[list(input()) for i in range(h1)]
h2,w2=map(int,input().split())
B=[list(input()) for i in range(h2)]
h3,w3=map(int,input().split())
X=[list(input()) for i in range(h3)]
def left_up(A,L,h,w):
h1,h2,w1,w2=L[0],L[1],L[2],L[3]
B=[["." for i in range(w)] for j in range(h)]
... | ConDefects/ConDefects/Code/abc307_c/Python/46162555 |
condefects-python_data_1430 | N, M = map(int, input().split())
raw_path = [list(map(lambda i: int(i) - 1, input().split())) for _ in range(M)]
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self... | ConDefects/ConDefects/Code/abc287_c/Python/46180932 |
condefects-python_data_1431 | def ip():return int(input())
def mp():return map(int, input().split())
def lmp():return list(map(int, input().split()))
# ABC287 C 466 - Path Graph?
# N 頂点 M 辺の単純無向グラフが与えられます。
# 頂点には 1,2,…,N の番号が、辺には 1,2,…,M の番号が付けられています。
# 辺 i(i=1,2,…,M) は頂点 ui, vi を結んでいます。
# このグラフがパスグラフであるか判定してください。
# 頂点に 1,2,…,N の番号が付けられた N 頂点のグラフがパ... | ConDefects/ConDefects/Code/abc287_c/Python/45520506 |
condefects-python_data_1432 | import numpy as np
import sys
from functools import lru_cache
import math
sys.setrecursionlimit(int(1e7))
from collections import *
from fractions import Fraction
import heapq
import bisect
import itertools
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(... | ConDefects/ConDefects/Code/abc258_e/Python/45738993 |
condefects-python_data_1433 | import itertools
import bisect
N, Q, X = map(int, input().split())
W = list(map(int, input().split()))
u = sum(W)
R = list(itertools.accumulate([0] + W + W))
B = []
n = X // u
b = (X // u) * u
need = X - b
X = []
for i in range(1, N+1):
add = n
ok = R[i-1] + need
idx = bisect.bisect_left(R, ok)
add ... | ConDefects/ConDefects/Code/abc258_e/Python/45310559 |
condefects-python_data_1434 | from collections import deque
N, Q, X = map(int, input().split())
W = list(map(int, input().split()))
right = [0] * N
SUM = sum(W)
A = X // SUM
B = X % SUM
count = [N * A] * N
deq = deque([])
r = 0
tmp = 0
# while tmp < B:
# deq.append(W[r])
# tmp += W[r]
# r += 1
# r %= N
# right[0] = r
# count[0] +=... | ConDefects/ConDefects/Code/abc258_e/Python/44667415 |
condefects-python_data_1435 | def ip():return int(input())
def mp():return map(int, input().split())
def lmp():return list(map(int, input().split()))
# ABC258 E 1545 - Packing Potatoes PyPyで提出
# ベルトコンベアに載って 10^100 個のじゃがいもが 1 個ずつ流れてきます。
# 流れてくるじゃがいもの重さは長さ N の数列 W = (W0,…,W_{N-1}) で表され、i (1≤i≤10^100) 番目に流れてくるじゃがいもの重さは W_{(i-1) mod N} です。
# 高橋君は、まず空の箱... | ConDefects/ConDefects/Code/abc258_e/Python/46182612 |
condefects-python_data_1436 | h1,w1=map(int,input().split())
a=[]
for i in range(h1):
tmp=list(map(int,input().split()))
a.append(tmp)
h2,w2=map(int,input().split())
b=[]
for i in range(h2):
tmp=list(map(int,input().split()))
b.append(tmp)
for bit_r in range(1<<h1):
for bit_c in range(1<<w1):
after=[]
for shift_r... | ConDefects/ConDefects/Code/abc264_c/Python/44997229 |
condefects-python_data_1437 | h1,w1=map(int,input().split())
a=[]
for i in range(h1):
tmp=list(map(int,input().split()))
a.append(tmp)
h2,w2=map(int,input().split())
b=[]
for i in range(h2):
tmp=list(map(int,input().split()))
b.append(tmp)
for bit_r in range(1<<h1):
for bit_c in range(1<<w1):
after=[]
for shift_r... | ConDefects/ConDefects/Code/abc264_c/Python/45221303 |
condefects-python_data_1438 | ctypedef long long ll
from libcpp.vector cimport vector
cdef:
ll N,D,S,i,j,k,w,b,now
double mean
vector[double] pre
vector[ll] bi
vector[vector[double]] dp
N,D=map(int,input().split())
W=list(map(int,input().split()))
mean=sum(W)/D
#print(mean)
for S in range(1<<N):
w=0
j=0
for i in r... | ConDefects/ConDefects/Code/abc332_e/Python/52500433 |
condefects-python_data_1439 | mod = 998244353
g = 3
ginv = 332748118
W = [pow(g, (mod-1)>>i, mod) for i in range(24)]
Winv = [pow(ginv, (mod-1)>>i, mod) for i in range(24)]
def fft(k,f):
for l in range(k,0,-1):
d = 1 << l - 1
U = [1]
for i in range(d):
U.append(U[-1]*W[l]%mod)
for i in range(1<<k - l... | ConDefects/ConDefects/Code/abc307_h/Python/43030329 |
condefects-python_data_1440 | mod=998244353
mod_syou=119
mod_log=23
mod_kon=3
root=pow(mod_kon,mod_syou,mod)
rootinv=pow(root,mod-2,mod)
bbeki=[0]*(mod_log+1)
bbeki2=[0]*(mod_log+1)
beki_dic=dict()
this=1
for i in range(mod_log+1):
beki_dic[this]=i
this*=2
def beki_mae():
x=root
beki=1
for i in range(mod_log,-1,-1):
bbeki[i]=x
x=x... | ConDefects/ConDefects/Code/abc247_h/Python/30891102 |
condefects-python_data_1441 | SIZE=10**4+1; MOD=998244353 #ここを変更する
inv = [0]*SIZE # inv[j] = j^{-1} mod MOD
fac = [0]*SIZE # fac[j] = j! mod MOD
finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE):
fac[i] = fac[i-1]*i%MOD
finv[-1] = pow(fac[-1],MOD-2,MOD)
for i in range(SIZE-1,0,-1):... | ConDefects/ConDefects/Code/arc162_e/Python/43020372 |
condefects-python_data_1442 | s=input()
n=int(input())
ts=[input() for i in range(n)]
e1=[[-1]*26]
p=[0]
v=1
d=[""]
for i in range(n):
t=ts[i]
y=0
for j in range(len(t)):
u=ord(t[j])-ord("a")
if e1[y][u]==-1:
e1+=[[-1]*26]
e1[y][u]=v
p+=[y]
d+=[t[j]]
v+=1
y=e1[y][u]
x=[0]*v
for i in range(n):
t=ts... | ConDefects/ConDefects/Code/abc268_h/Python/49647495 |
condefects-python_data_1443 | from collections import deque
class Trie_with_Aho_Corasick():
def __init__(self, keywords, sigma = 26):
self.keywords = keywords
self.sigma = sigma
self.tree = [[-1] * (sigma + 2) for _ in range(sum(len(_str) for _str in keywords) + 1)]
self.depth = [0] * len(self.tree)
self... | ConDefects/ConDefects/Code/abc268_h/Python/49241806 |
condefects-python_data_1444 | import bisect
import sys
readline=sys.stdin.readline
def Compress(lst):
decomp=sorted(list(set(lst)))
comp={x:i for i,x in enumerate(decomp)}
return comp,decomp
def SA_IS(lst,compressed=False):
N=len(lst)
if not compressed:
decomp=sorted(list(set(lst)))
comp={x:i for i,x in enumera... | ConDefects/ConDefects/Code/abc268_h/Python/44447952 |
condefects-python_data_1445 | # Accepted. From the official editorial.
K = int(input())
Sx, Sy = [int(x) for x in input().split()]
Tx, Ty = [int(x) for x in input().split()]
# Kずつ右上にずらしておく。
Sx += K
Sy += K
Tx += K
Ty += K
# 上界を入れておく。
dist = max(Tx, Sx) - min(Tx, Sx) + max(Ty, Sy) - min(Ty, Sy)
# 1 < Kのとき、大タイルを経由する移動を考える。
if 1 < K:
large_start =... | ConDefects/ConDefects/Code/abc353_f/Python/54723688 |
condefects-python_data_1446 | K = int(input())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
def dist_big(S, T):
global K
if K <= 2:
D = [abs(S[i] - T[i]) for i in range(2)]
ret = min(D) * 2
ret += (max(D) - min(D)) * (K + 1)
return ret
else:
return abs((S[0] + S[1]) - (... | ConDefects/ConDefects/Code/abc353_f/Python/53483883 |
condefects-python_data_1447 | import sys
# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline(... | ConDefects/ConDefects/Code/abc353_f/Python/53517874 |
condefects-python_data_1448 | K=int(input())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
S[0]+=2*K
S[1]+=2*K
T[0]+=2*K
T[1]+=2*K
distX = T[0] - S[0]
distY = T[1] - S[1]
bigM = max(distX,-distX) + max(distY,-distY)
if K == 1:
print(bigM)
exit()
if (S[0]//K + S[1]//K) %2 == 0:
tileS = "small"
else:
tileS ... | ConDefects/ConDefects/Code/abc353_f/Python/53505050 |
condefects-python_data_1449 | from sys import stdin, setrecursionlimit
from collections import deque, defaultdict, Counter
setrecursionlimit(10 ** 9 + 7)
input = stdin.readline
INF = 1 << 61
# DX = (0, 1, 0, -1)
# DY = (-1, 0, 1, 0)
# DX = (0, 1, 1, 1, 0, -1, -1, -1)
# DY = (-1, -1, 0, 1, 1, 1, 0, -1)
class P:
def __init__(self, x, y):
... | ConDefects/ConDefects/Code/abc353_f/Python/53655550 |
condefects-python_data_1450 | import sys
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
INF = 2 ** 63 - 1
mod = 998244353
n = ii()
a = li()
a1 = a[:n]
a2 = a[n:]
p = min(a1)
t =[]
ind = -1
for i in range(n):
if a1[i] == p:
t.append((a1[i], a2[i])... | ConDefects/ConDefects/Code/arc134_d/Python/33208299 |
condefects-python_data_1451 | N = int(input())
A = list(map(int, input().split()))
mna1 = min(A[:N])
B = [(a, i) for i, a in enumerate(A[:N])]
B.sort()
x = 10**10
li = 0
for i in range(N):
if A[i] == mna1:
x = min(A[i+N], x)
li = i
if x < mna1:
print(mna1, x)
exit()
ans1 = []
ans2 = []
f = True
f2 = False
for i in rang... | ConDefects/ConDefects/Code/arc134_d/Python/39521763 |
condefects-python_data_1452 | from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
mae = a[:n]
koho = defaultdict(list)
num = sorted(list(set(mae)))
for i in range(n):
koho[a[i]].append(i)
mn = float("inf")
for k in koho[num[0]]:
pair = a[k+n]
mn = min(pair, mn)
if mn <= num[0]:
print(num[0], pair)
exi... | ConDefects/ConDefects/Code/arc134_d/Python/36030496 |
condefects-python_data_1453 | import sys
input = sys.stdin.readline
def ii(): return int(input())
def fi(): return float(input())
def si(): return input().rstrip()
def mii(): return map(int, input().split())
def fii(): return map(float, input().split())
def mii1(): return map(lambda x: int(x)-1, input().split())
def lii(): return list(map(int, inp... | ConDefects/ConDefects/Code/arc134_d/Python/32125806 |
condefects-python_data_1454 | import sys
from math import ceil, floor
from fractions import Fraction
from itertools import permutations
input = sys.stdin.readline
inf = 10**18
def read(dtype=int):
return list(map(dtype, input().split()))
r, = read(float)
x, = read()
# ceil
ans = (Fraction(r) - Fraction("1e-100")
).limit_denominator(... | ConDefects/ConDefects/Code/abc333_g/Python/49970736 |
condefects-python_data_1455 | from math import gcd
def cfraction(a, b):
ans = [b//a]
while a != 1:
a,b=b%a,a
ans.append(b//a)
return ans
def fromfrac(frac):
num = frac[-1]
den = 1
for i in range(len(frac)-2, -1,-1):
num,den=den,num
num += den * frac[i]
return den,num
def closer(a,b, n1,d1, n2,d2):
na = abs(a*d1 - n1*b)
da = b*d1... | ConDefects/ConDefects/Code/abc333_g/Python/50750395 |
condefects-python_data_1456 | def solve(n, l, r):
"""
2^i*jと2^i*(j+1)に辺を張ったグラフ問題として考える
BFSで頂点r+1から頂点lへの最短経路を割り出す
頂点が増える方向なら加算、減る方向なら減算として、最終的な解を求める
"""
ub = 1<<n
# 2^i*jと2^i*(j+1)に対して辺を張る
E = [[] for _ in range(ub+1)]
for i in range(n):
j = 0
while (2**i) * (j+1) <= ub:
x = (2**i) * j... | ConDefects/ConDefects/Code/abc355_e/Python/54238089 |
condefects-python_data_1457 | from sys import stdout
import sys
input = sys.stdin.readline
inf = 10**18
def read(dtype=int):
return list(map(dtype, input().split()))
n, l, r = read()
def cout(*args, **kwargs):
print(*args, **kwargs)
stdout.flush()
def ask(x, y):
cout("?", x, y)
return read()[0]
N = 1 << n
p = [-1] * (N... | ConDefects/ConDefects/Code/abc355_e/Python/54789032 |
condefects-python_data_1458 | import math
import re
import functools
import random
import sys
import os
import typing
from math import gcd, comb, sqrt,isqrt,lcm
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from itertools import accumulate, combinations, permutations
from heapq import nsmallest, nlarges... | ConDefects/ConDefects/Code/abc355_e/Python/54311444 |
condefects-python_data_1459 | from collections import defaultdict
import sys
#input = sys.stdin.readline
sys.setrecursionlimit(10**9)
INF = 10**9
N, L000, R000 = map(int, input().split())
R000 += 1
numss = [defaultdict(lambda: INF) for d in range(N+2)]
numss[0][(L000, R000)] = 0
prevss = [defaultdict(lambda: (-1, -1)) for d in range(N+2)]
for d... | ConDefects/ConDefects/Code/abc355_e/Python/54431130 |
condefects-python_data_1460 | import sys
from collections import deque
INF = 1 << 19
N, L, R = map(int, sys.stdin.readline().rstrip().split())
R += 1
E = [[] for _ in range(2**N + 1)]
# 質問できる組み合わせに辺を張る
for i in range(N + 1):
for j in range(2**N):
if pow(2, i) * (j + 1) > 2**N:
break
l = pow(2, i) * j
r = p... | ConDefects/ConDefects/Code/abc355_e/Python/54059945 |
condefects-python_data_1461 | def calc(d: int) -> int:
if d == 0:
return 1
arr = [2, 4, 8, 6]
return arr[d % 4 - 1]
t = int(input())
ans = []
for _ in range(t):
n, m, k = map(int, input().split())
if n < k:
ans.append(calc(n))
else:
d1 = (n - k) % (m - k)
ans.append(calc(d1 + k))
for ansi i... | ConDefects/ConDefects/Code/arc176_b/Python/54752998 |
condefects-python_data_1462 | import sys
readline = sys.stdin.readline
def calc(N, M, K):
if K > N:
return pow(2, N, 10)
if K == N:
if M == K+1:
return 0
else:
return pow(2, N, 10)
if K > 0:
a = calc(N-K, M-K, 0)
return a*pow(2, K, 10)%10
# K == 0
if N < M:
... | ConDefects/ConDefects/Code/arc176_b/Python/53411571 |
condefects-python_data_1463 | mods = {0: 6, 1: 2, 2: 4, 3: 8}
t = int(input())
for i in range(t):
n, m, k = map(int, input().split())
if n < k:
ans = mods[n % 4]
else:
ans = mods[(k + (n - k) % (m - k)) % 4]
print(ans)
mods = {0: 6, 1: 2, 2: 4, 3: 8}
t = int(input())
for i in range(t):
n, m, k = map(int, input... | ConDefects/ConDefects/Code/arc176_b/Python/53249661 |
condefects-python_data_1464 | import sys
input = lambda: sys.stdin.readline().strip()
for _ in range(int(input())):
n, m, k = map(int, input().split())
if m == k + 1:
print(0)
elif n < m:
print((6, 2, 4, 8)[n % 4])
else:
print(((6, 2, 4, 8)[(n - k) % (m - k) % 4] if (n - k) % (m - k) else 1) * (6, 2, 4, 8)... | ConDefects/ConDefects/Code/arc176_b/Python/53269328 |
condefects-python_data_1465 | n=int(input())
for _ in range(n):
n, m,k = map(int, input().split())
if n==m-1==k:
print(0)
continue
if n >= m:
sa=n-m
num=sa//(m-k)+1
n=n-num*(m-k)
print(pow(2,n,10))
n=int(input())
for _ in range(n):
n, m,k = map(int, input().split())
if m-1==k and n>=m-1:
print(0)
continue
... | ConDefects/ConDefects/Code/arc176_b/Python/53761488 |
condefects-python_data_1466 | # based on https://atcoder.jp/contests/arc176/submissions/53409900
T = int(input())
table = [2,4,8,6]
def solve(N, M, K):
if M-K == 1:
return 0 if N >= K-1 else pow(2, N, 10)
if N >= M:
# N<MになるまでNからM-Kを引く操作を高速に行う。
# NからN-Mより大きいM-Kの倍数で引く
N -= ((N-M+M-K)//(M-K))*(M-K)
return table[(N+3)... | ConDefects/ConDefects/Code/arc176_b/Python/53698323 |
condefects-python_data_1467 | from scipy.spatial import KDTree
N, K = map(int, input().split())
points = []
for _ in range(N):
x, y = map(int, input().split())
points.append((x, y))
if K <= 1000:
ans = []
for i in range(N):
for j in range(N):
if i < j and (points[i][0]-points[j][0])**2 + (points[i][1]-points[j][1])**2 <= K**2:
ans.a... | ConDefects/ConDefects/Code/abc234_h/Python/49361492 |
condefects-python_data_1468 | n=int(input())
a=list(map(int,input().split()))
from collections import Counter
c=list(Counter(a).items())
l=[]
for num,cnt in c:
l.append(num*cnt)
from itertools import accumulate
l=list(accumulate(l))
a_set=sorted(set(a))
d=dict(zip(a_set,l))
total=sum(a)
ans=[]
for i in range(n):
ans.append(total-d[a[i]])
pr... | ConDefects/ConDefects/Code/abc331_c/Python/54472770 |
condefects-python_data_1469 | # || ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄||
# 早速解いていくよ
#
# || \ (゚ー゚*) キホン。
# ||________________ ⊂⊂ |
# ∧ ∧ ∧ ∧ ∧ ∧ | ̄ ̄ ̄ ̄|
# ( ∧ ∧ ( ∧ ∧ ( ∧ ∧ | |
# ~(_( ∧ ∧ __( ∧ ∧__( ∧ ∧ ̄ ̄ ̄
# ~(_( ∧ ∧_( ∧ ∧_( ∧ ∧ は~い、先生。
# ~(_( ,,)~(_( ,,)~(_( ,,)
# ~(__... | ConDefects/ConDefects/Code/abc232_e/Python/45459245 |
condefects-python_data_1470 | H,W,K=map(int, input().split())
x1,y1,x2,y2=map(int, input().split())
dp = [[0]*4 for i in range(K+1)]
mod=998244353
if x1==x2 and y1==y2:
dp[0][3]=1
elif x1==x2:
dp[0][1]=1
elif y1==y2:
dp[0][2]=1
else:
dp[0][0]=1
for i in range(K):
dp[i+1][0]+=dp[i][1]*(W-1)%mod
dp[i+1][0]%=mod
dp[i+1][0... | ConDefects/ConDefects/Code/abc232_e/Python/44929490 |
condefects-python_data_1471 | import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log,sqrt
from atcoder.modint import ModContext, Modint
from atcoder.dsu import DSU
ModContext(1).context.append(998244353)
sys.setrecursionlimit(1000000)... | ConDefects/ConDefects/Code/abc232_e/Python/45574605 |
condefects-python_data_1472 | h,w,k = map(int, input().split())
x1,y1,x2,y2 = map(int, input().split())
MOD = 998244353
dp = [0 for _ in range(4)]
dp[0] = 1
for _ in range(1):
dp = [
dp[1]*(w-1) + dp[2]*(h-1),
dp[1]*(w-2) + dp[0] + dp[3]*(h-1),
dp[2]*(h-2) + dp[0] + dp[3]*(w-1),
dp[1] + dp[2] + dp[3]*(h+w-... | ConDefects/ConDefects/Code/abc232_e/Python/46187377 |
condefects-python_data_1473 | n, m = map(int, input().split())
aaa = list(map(int, input().split()))
MOD = 998244353
pos = [-1] * n
for i, a in enumerate(aaa):
pos[a] = i
min_aaa = min(aaa)
leftmost = [0] * n
rightmost = [0] * n
l = pos[min_aaa]
r = l + 1
for a in range(min_aaa + 1, n):
if pos[a] == -1:
leftmost[a] = l
rig... | ConDefects/ConDefects/Code/arc178_d/Python/53680716 |
condefects-python_data_1474 | A = list(map(int, input().split()))
N = int(input())
X = list(map(int, input().split()))
prices = [1, 5, 10, 50, 100, 500]
valid = True
for i in range(1, 6):
n = 0
for x in X:
n += x % prices[i]
if n > A[i - 1]:
valid = False
break
A[i] += (A[i - 1] - n) // prices[i]
X = ... | ConDefects/ConDefects/Code/arc177_a/Python/53803564 |
condefects-python_data_1475 | A, B, C, D, E, F = map(int, input().split())
N = int(input())
X = list(map(int, input().split()))
out = "Yes"
for i in range(N):
while(X[i] >= 500 and F > 0):
X[i] = X[i] - 500
F = F - 1
while(X[i] >= 100 and E > 0):
X[i] = X[i] - 100
E = E - 1
while(X[i] >= 50 and D > 0):
X[i] = X[i] - 50
... | ConDefects/ConDefects/Code/arc177_a/Python/53706270 |
condefects-python_data_1476 | h, w = map(int, input().split())
s = []
o = []
for _ in range(h):
s.append(input())
for row in range(h):
for col in range(w):
if s[row][col] == "o":
o.append([row,col])
hirai = abs(o[0][0]- o[1][0]) + abs(o[1][0]-o[1][1])
print(hirai)
h, w = map(int, input().split())
s = []
o = []
for _ in ... | ConDefects/ConDefects/Code/abc253_b/Python/45785764 |
condefects-python_data_1477 | N = int(input())
list = []
T = 0
for i in range(N):
S, C = input().split()
list.append([S, int(C)])
T += int(C)
name = []
for j in range(N):
name.append(list[j])
name.sort()
m = T % N
print(list[m][0])
N = int(input())
list = []
T = 0
for i in range(N):
S, C = input().split()
list.append([S, in... | ConDefects/ConDefects/Code/abc354_b/Python/54729742 |
condefects-python_data_1478 | N=int(input())
S, C = [""]*N, [0]*N
for i in range(N):
S[i],C[i] = input().split()
C[i] = int(C[i])
S.sort()
print(S[sum(C) % N])
N=int(input())
S, C = [""]*N, [0]*N
for i in range(N):
S[i],C[i] = input().split()
C[i] = int(C[i])
S.sort()
print(S[sum(C) % N]) | ConDefects/ConDefects/Code/abc354_b/Python/54929590 |
condefects-python_data_1479 | S = input()
N = len(S)
from collections import defaultdict
s_dict = defaultdict(list)
for i in range(N-1,-1,-1):
s_dict[S[i]].append(i)
def my_check(i,j):
for k in range((j-i+1)//2):
if S[i+k] != S[j-k]:
return False
return True
text_set = set()
for i in range(N):
for j in s_dict... | ConDefects/ConDefects/Code/abc237_h/Python/29196395 |
condefects-python_data_1480 | """
3 2
1 2 2 1
1 3 -1 -2
"""
N,M=map(int,input().split())
G=[[]for i in range(N+1)]
for i in range(M):
a,b,x,y=map(int,input().split())
G[a].append([b,x,y])
G[b].append([a,x,y])
visited=[False]*(N+1)
visited[1]=True
listx=[[0]*2 for i in range(N+1)]
set1={1}
while len(set1)>0:
set2=set()
for i in ... | ConDefects/ConDefects/Code/abc320_d/Python/54919763 |
condefects-python_data_1481 | user_n, q = map(int, input().split(" "))
dic = {}
for i in range(q):
ope, user1, user2 = map(int, input().split(" "))
if user1 not in dic:
dic[user1] = set()
if user2 not in dic:
dic[user2] = set()
if ope == 1:
dic[user1].add(user2)
elif ope == 2:
if user1 in dic[use... | ConDefects/ConDefects/Code/abc278_c/Python/44900806 |
condefects-python_data_1482 | from collections import defaultdict
N, Q = map(int, input().split())
follow = defaultdict(bool)
for i in range(Q):
t, a, b = map(int, input().split())
if t==1:
follow[(a, b)] = True
elif t==2:
follow[(b, a)] = False
elif t==3:
if follow[(a, b)] and follow[(b, a)]:
... | ConDefects/ConDefects/Code/abc278_c/Python/45320717 |
condefects-python_data_1483 | M = 998244353
N, D = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
size = (D+1)*(D+1)
def idx(i, j):
return i + j * (D+1)
dp = [0]*size
px, qx = P[0], Q[0]
boaders = [px-D, px+D, qx-D, qx+D]
boaders.sort()
for rx in range(boaders[1], boaders[2]+1):
dp[idx(abs(... | ConDefects/ConDefects/Code/abc265_f/Python/43487741 |
condefects-python_data_1484 | K, G, M = map(int, input().split())
Gi, Mi = 0, 0
for _ in range(K):
if Gi == G:
Gi = 0
elif Mi == 0:
Mi = M
else:
if Gi + Mi > G:
Gi = G
Mi = Mi - (G - Gi)
else:
Gi = Gi + Mi
Mi = 0
print(Gi, Mi)
K, G, M = map(int, input().spl... | ConDefects/ConDefects/Code/abc332_b/Python/54879479 |
condefects-python_data_1485 | N = int(input())
S = input()
se = set()
se.add((0, 0))
now = (0, 0)
for i in range(N):
if S[i] == "L":
now = (now[0] - 1, now[1])
if S[i] == "R":
now = (now[0] + 1, now[1])
if S[i] == "U":
now = (now[0], now[1] + 1)
if S[i] == "D":
now = (now[0], now[1] - 1)
se.add(now)
if len(se) == N + 1:
... | ConDefects/ConDefects/Code/abc291_c/Python/45227759 |
condefects-python_data_1486 | N = int(input())
S = input()
def Move(s, x, y):
if s=="R":
x += 1
elif s=="L":
x -= 1
elif s=="U":
y += 1
elif s=="D":
y += 1
return x, y
X, Y = 0, 0
visited = set()
visited.add((X, Y))
for i in range(N):
X, Y = Move(S[i], X, Y)
if (X, Y) in visited:
... | ConDefects/ConDefects/Code/abc291_c/Python/45313651 |
condefects-python_data_1487 | n=int(input())
S=input()
s=set((0,0))
x=0
y=0
for c in S:
if c=='U':
y+=1
if c=='D':
y-=1
if c=='R':
x+=1
if c=='L':
x-=1
s.add((x,y))
if len(s)==n+1:
print('No')
else:
print('Yes')
n=int(input())
S=input()
s={(0,0)}
x=0
y=0
for c in S:
if c=='U':
... | ConDefects/ConDefects/Code/abc291_c/Python/45751656 |
condefects-python_data_1488 | from enum import Enum
from typing import SupportsFloat
import numpy as np
from scipy.optimize import linprog # type: ignore
class LPVariableType(Enum):
CONTINUOUS = 1
INTEGER = 2
class LPBase:
def __add__(self, other: "AffineExpressionLike") -> "AffineExpression":
return AffineExpression.build... | ConDefects/ConDefects/Code/abc326_g/Python/49041438 |
condefects-python_data_1489 | import sys
input = sys.stdin.readline
from math import ceil, sqrt
class Mo():
def __init__(self, A):
self.M = 202020
self.M2 = self.M**2
self.A = A
self.N = len(A)
self.B = ceil(sqrt(self.N))
self.K = self.N // self.B + 1
self.Query = [[] for i in range(self.... | ConDefects/ConDefects/Code/abc242_g/Python/52939949 |
condefects-python_data_1490 | from itertools import permutations
N = int(input())
A = sorted([i for i in input().split()])
ans = 0
for a in permutations(A[-3:],3):
tmp = int("".join(map(str, a)))
if ans < tmp:
ans = tmp
print(ans)
from itertools import permutations
N = int(input())
A = sorted([int(i) for i in input().split()])
ans ... | ConDefects/ConDefects/Code/arc146_a/Python/40409761 |
condefects-python_data_1491 | from itertools import permutations
N = int(input())
A = list(map(int, input().split()))
res = [[] for _ in range(10)]
for i in range(N):
res[len(str(A[i]))].append(A[i])
for i in range(10):
res[i].sort(reverse=True)
res2 = []
for i in range(10):
for j in range(min(3, len(res[i]))):
res2.append(r... | ConDefects/ConDefects/Code/arc146_a/Python/44240762 |
condefects-python_data_1492 | import heapq
import sys
from collections import Counter, defaultdict, deque
from itertools import accumulate, combinations, permutations
from heapq import heappop, heappush
from math import inf
sys.setrecursionlimit(10**6)
MOD = 10**9 + 7
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readl... | ConDefects/ConDefects/Code/abc359_f/Python/54954031 |
condefects-python_data_1493 | import sys
import math
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
MOD = 998_244_353
INF = 10**9
sys.setrecursionlimit(10**6) # ネスト数制限
N, A1, A2, A3 = map(int, sys.stdin.readline().rstrip().split())
dp = [[[[[0 for _ in range(A3)] for _ in range(A2)] for _ in range(A1)] for _ in range(8)] for _ ... | ConDefects/ConDefects/Code/abc317_f/Python/45104583 |
condefects-python_data_1494 | from math import gcd
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 998244353
DDD = 64
#DDD = 10
def lcm(a, b):
return a // gcd(a, b) * b
N, A1, A2, A3 = map(int, input().split())
binNs = bin(N)[2:].zfill(DDD)[::-1]
#print('# binNs:', binNs)
dp = [[[[[[0]*(A3) for m in range(A2)] for ... | ConDefects/ConDefects/Code/abc317_f/Python/46240679 |
condefects-python_data_1495 | from collections import deque
MOD = 998244353
h, w = map(int, input().split())
S = [["."] * (w + 2)] + [list("." + input() + ".") for _ in range(h)] + [["."] * (w + 2)]
h += 2
w += 2
for i in range(h):
for j in range(w):
if S[i][j] == "S":
si, sj = i, j
elif S[i][j] == "G":
... | ConDefects/ConDefects/Code/abc243_h/Python/30771376 |
condefects-python_data_1496 | mod = 998244353
h,w = map(int,input().split())
grid = [[0] * w for _ in range(h)]
sx,sy = 0,0
gx,gy = 0,0
for i in range(h):
ci = input()
for j in range(w):
if ci[j] == '.':
grid[i][j] = 1
elif ci[j] == 'S':
sx,sy = i,j
elif ci[j] == 'G':
gx,gy = i,j
... | ConDefects/ConDefects/Code/abc243_h/Python/30174663 |
condefects-python_data_1497 | N = int(input())
info = []
for _ in range(N):
a, b = map(int,input().split())
info.append([a / b, 1 / b])
info.sort(reverse = True)
#print(info)
task = []
section = []
for a, b in info:
while task:
p, q = task.pop()
x, y = section.pop()
if p == a: continue
x_new = (b - q) / (p - a)
if x >=... | ConDefects/ConDefects/Code/abc356_g/Python/54232515 |
condefects-python_data_1498 | import sys
input = sys.stdin.readline
from collections import defaultdict
n=int(input())
dic=defaultdict(int)
for _ in range(n):
a,b=map(int,input().split())
dic[a]=max(dic[a],b)
ab=[]
for i in dic:
ab.append((i,dic[i]))
def ConvexHull(point_list):
pos2idx = {point_list[i]: i for i in range(len(point_list))}
... | ConDefects/ConDefects/Code/abc356_g/Python/54133842 |
condefects-python_data_1499 | n = int(input())
a = [0]+list(map(int, input().split()))
e = [0]*(n+2)
rui = [0]*(n+2)
mod = 998244353
#e[n]=0
for i in reversed(range(1,n)):
A = a[i]
e[i]=rui[i+1]-rui[i+A+1]+(A+1)*pow(A,mod-2,mod)
e[i]%=mod
rui[i]=e[i]+rui[i+1]
rui[i]%=mod
print(e[1])
n = int(input())
a = [0]+list(map(int, input().split())... | ConDefects/ConDefects/Code/abc263_e/Python/44902374 |
condefects-python_data_1500 | from sortedcontainers import SortedList,SortedSet,SortedDict
n,k = map(int,input().split())
p = list(map(int,input().split()))
s = SortedList()
idx = [0]*(n+1)
for i in range(n):
idx[p[i]] = i
ans = float('inf')
for i in range(1,n+1):
s.add(idx[i])
if len(s) > k:
s.discard(idx[i-k])
ans = m... | ConDefects/ConDefects/Code/abc352_d/Python/54879664 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.