id stringlengths 24 27 | content stringlengths 37 384k | max_stars_repo_path stringlengths 51 51 |
|---|---|---|
condefects-python_data_801 | def solve():
n,x,k = list(map(int, input().split(' ')))
# print(n,x,k)
n += 1
k = min(100,k)
ans = 0
depth = k
prev = -1
while x and depth >= 0:
# print(f'{x=} {depth=} {prev=}')
if prev == -1:
L = x*(1<<depth)
R = L + (1<<depth)
else:
... | ConDefects/ConDefects/Code/abc321_e/Python/54658110 |
condefects-python_data_802 | import sys
input = sys.stdin.readline
n = int(input())
dp = [0] * (n + 1)
for i in range(1, n + 1):
tmp = 0
for j in range(1, 7):
if j < dp[i - 1]:
tmp += dp[i - 1] / 6
else:
tmp += j / 6
dp[i] = tmp
print(dp)
import sys
input = sys.stdin.readline
n = int(input... | ConDefects/ConDefects/Code/abc266_e/Python/44641284 |
condefects-python_data_803 | n,a,b,c = map(int, input().split())
al = list(map(int, input().split()))
def gcm(a,b):
if b == 0:
return a
else:
return gcm(b,a%b)
def calc(x,y):
if x%y == 0:
return x
else:
return y * (x//y + 1)
ab_gcm = gcm(a,b)
ab = a*b//ab_gcm
ac_gcm = gcm(a,c)
ac = a*c//ac_gcm... | ConDefects/ConDefects/Code/arc166_b/Python/49426497 |
condefects-python_data_804 | ## https://atcoder.jp/contests/arc166/tasks/arc166_b
def calc_gcd(A, B):
"""
正の整数A, Bの最大公約数を計算する
"""
a = max(A, B)
b = min(A, B)
while a % b > 0:
c = a % b
a = b
b = c
return b
def main():
N, a, b, c = map(int, input().split())
A = list(map(int, input().spli... | ConDefects/ConDefects/Code/arc166_b/Python/51949905 |
condefects-python_data_805 | n,m = map(int,input().split())
q = True
if n > m:
n,m = m,n
q = False
t = m - n
ans = []
for i in range(2 + t):
ans.append([1,i + 1])
if t == 0:
for i in range(2):
ans.append([2,2 + t - i])
else:
for i in range(3):
ans.append([2,2 + t - i])
for i in range(n - 2):
ans.append([2 + ... | ConDefects/ConDefects/Code/arc139_c/Python/31247940 |
condefects-python_data_806 | n,m=map(int,input().split())
ans=set()
use=set()
use2=set()
for i in range(10**5):
for dx in range(1,4):
for dy in range(1,4):
x=2*i+dx
y=2*i+dy
if 1<=x<=n and 1<=y<=m:
ans.add((x,y))
use.add(3*x+y)
use2.add(x+3*y)
if m<=n:
for y in range(1,m+1):
x=n
if 3*x+y ... | ConDefects/ConDefects/Code/arc139_c/Python/31248584 |
condefects-python_data_807 | import functools
import math
import decimal
import collections
import itertools
import sys
import random
import bisect
import typing
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
# Union-Find
class UnionFind():
def __init__(self, n: int) -> None:
self.n = n
self.par = list(range(self.n))
self.rank... | ConDefects/ConDefects/Code/arc139_c/Python/31269738 |
condefects-python_data_808 | n, m = map(int, input().split())
ab = []
nexts = list(range(8))
for a in range(n + 3 * m):
br = (3 * a) % 8
b = nexts[br]
mn = max((a + 2) // 3, 3 * a - 8 * m + 1)
mx = min(3 * a, (a + 8 * n - 1) // 3)
if mn > mx:
continue
if b < mn:
b += (mn - br + 7) // 8 * 8
if b <= mx:
... | ConDefects/ConDefects/Code/arc139_c/Python/31249723 |
condefects-python_data_809 | n,m=map(int,input().split())
hi=False
if n<m:
hi=True
n,m=m,n
l1=[2,4,-2,0,2,-4,-2,0]
canr=(m-1)//2
ll=[[4,4]]
nows=4
for i in range(canr):
for j in l1:
nows+=1
ll.append([nows,nows+j])
if m%2==1:
nowt=nows
for i in range(n-m):
nows+=1
nowt+=3
ll.append([nows,nowt])
else:
nowt=now... | ConDefects/ConDefects/Code/arc139_c/Python/31246555 |
condefects-python_data_810 | N, M = map(int, input().split())
if N > M:
r = N
N = M
M = r
swap = 1
else:
swap = 0
ans = [(1, 1)]
for i in range(1, N - 1, 2):
for j in range(3):
for k in range(3):
if j + k == 0:
continue
ans.append((i + j, i + k))
if N & 1:
for i in range(N... | ConDefects/ConDefects/Code/arc139_c/Python/31456138 |
condefects-python_data_811 | import bisect
import collections
import functools
import heapq
import itertools
import math
import operator
import string
import sys
from atcoder.dsu import DSU
readline = sys.stdin.readline
LS = lambda: readline().strip()
LI = lambda: int(readline().strip())
LLS = lambda: readline().strip().split()
LL = lambda: list... | ConDefects/ConDefects/Code/abc350_c/Python/54963583 |
condefects-python_data_812 | N = int(input())
A = list(map(int, input().split()))
ans = []
num = 0
i = 0
while i < N:
if A[i] == i + 1:
i += 1
continue
else:
j = A[i] - 1
num += 1
ans.append([A[j], A[i]])
A[i], A[j] = A[j], A[i]
print(num)
for i in range(num):
print(' '.join(map(str, ans... | ConDefects/ConDefects/Code/abc350_c/Python/54896149 |
condefects-python_data_813 | n = int(input())
a = list(map(int,input().split()))
for i in range(n):
a[i] -= 1
ans = []
for i in range(n):
while a[i] != i:
now = a[i]
ans.append([now+1,a[now]+1])
a[i], a[now] = a[now], a[i]
print(len(ans))
for x in ans:
print(*sorted(x))
n = int(input())
a = list(map(int,input().split()))
f... | ConDefects/ConDefects/Code/abc350_c/Python/55151814 |
condefects-python_data_814 | import sys
input = sys.stdin.readline
H,W=map(int,input().split())
MAP=[input().strip() for i in range(H)]
mod=998244353
E=[[] for i in range(H*W)]
for i in range(H):
for j in range(W):
if i+1<H and MAP[i][j]=="#" and MAP[i+1][j]=="#":
E[i*W+j].append((i+1)*W+j)
E[(i+1)*W+j].appe... | ConDefects/ConDefects/Code/abc334_g/Python/50711635 |
condefects-python_data_815 | N = int(input())
l=0; r=N
while r-l>1:
m = (l+r)//2
print('?', m)
a = input()
if a=='0': l = m
else : r = m
print(l)
N = int(input())
l=0; r=N
while r-l>1:
m = (l+r)//2
print('?', m)
a = input()
if a=='0': l = m
else : r = m
print('!', l)
| ConDefects/ConDefects/Code/abc299_d/Python/45261350 |
condefects-python_data_816 | import io
import sys
import math
import collections
import itertools
from operator import mul
from functools import reduce, wraps
from collections import defaultdict, deque
import bisect
import time
import heapq
from copy import deepcopy
import sys
sys.setrecursionlimit(1000000000)
# input
# -------------------------... | ConDefects/ConDefects/Code/abc299_d/Python/46179112 |
condefects-python_data_817 | n = int(input())
high = n
low = -1
while low + 1 < high:
mid = (low + high) // 2
print(f'? {mid}')
s = input()
if s == "0":
low = mid
else:
high = mid
print(f"! {low + 1}")
n = int(input())
high = n
low = -1
while low + 1 < high:
mid = (low + high) // 2
print(f'? {mid +... | ConDefects/ConDefects/Code/abc299_d/Python/45452741 |
condefects-python_data_818 | n = int(input())
max = n
min = 0
past = -1
cnt = 0
ans = -1
while cnt <= 20 and max-min > 1:
mid = (max+min)//2
print("? " + str(mid) + '\n')
s = int(input())
if s == 1:
max = mid
else:
min = mid
cnt += 1
print("! " + str(min))
exit()
n = int(input())
max = n
min = 0
past = -... | ConDefects/ConDefects/Code/abc299_d/Python/45471725 |
condefects-python_data_819 | def main():
N = int(input())
l = [0,0]
r = [N-1,1]
for i in range(20):
m = (r[0]+l[0])//2
print(f"? {m+1}")
N = int(input())
if N == l[1]:
l[0] = m
elif N == r[1]:
r[0] = m
if abs(r[0]-l[0]) <= 1:
break
prin... | ConDefects/ConDefects/Code/abc299_d/Python/45280139 |
condefects-python_data_820 | N,M,K = map(int,input().split())
UVA = [list(map(int,input().split())) for _ in range(M)]
S = set(map(int,input().split()))
E = [[] for _ in range(N+1)]
INF = 10 ** 6
for i,(u,v,a) in enumerate(UVA,start = 1):
E[u].append((v,a,i))
E[v].append((u,a,i))
C = [[INF,INF] for _ in range(N+1)]
C[1][1] = 0
q = [(1,1)]
... | ConDefects/ConDefects/Code/abc277_e/Python/46166743 |
condefects-python_data_821 | from collections import deque
n, m, k = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
u, v, a = map(int, input().split())
u -= 1
v -= 1
g[u].append((v, a))
g[v].append((u, a))
sw = set(map(lambda x: int(x) - 1, input().split()))
INF = float("INF")
dist = [[INF, INF] for ... | ConDefects/ConDefects/Code/abc277_e/Python/45112675 |
condefects-python_data_822 | S = input()
K = int(input())
N = len(S)
X = [0]*N
if N==1:
if (S[0]=='.' and K==1) or (S[0]=='X' and K==0):
print(1)
exit()
if K==0:
ans = 0
for i in range(N):
if S[i]=='X':
if i!=N-1:
for j in range(i+1,N):
if S[j]!='X':
break
ans = max(ans,j-i+1)
e... | ConDefects/ConDefects/Code/abc229_d/Python/45424479 |
condefects-python_data_823 | s=input()
k=int(input())
s=s.split(".")
l=[0]
ans=0
for i in s:
l.append(l[-1]+len(i))
if len(s)-1>k:
for i in range(len(s)-k-1):
ans=max(ans,l[i+k+1]-l[i]+k)
else:
ans=l[-1]+len(s)-1
print(ans)
s=input()
k=int(input())
s=s.split(".")
l=[0]
ans=0
for i in s:
l.append(l[-1]+len(i))
if len(s)-1>k:
for i in... | ConDefects/ConDefects/Code/abc229_d/Python/44842027 |
condefects-python_data_824 | from collections import deque
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(int, input().split())
a -= 1
b -= 1
G[a].append(b)
G[b].append(a)
dist = [-1 for i in range(N)]
que = deque()
for i in range(N):
if G[i] == 1:
dist[i] = 0
que.append(i)
... | ConDefects/ConDefects/Code/abc303_e/Python/53920661 |
condefects-python_data_825 | T=int(input())
for t in range(T):
B,K,Sx,Sy,Gx,Gy=map(int,input().split())
ans=(abs(Sx-Gx)+abs(Sy-Gy))*K
for a,b in ((Sx,Sy//B*B),(Sx,(Sy+B-1)//B*B),(Sx//B*B,Sy),((Sx+B-1)//B*B,Sy)):
for c,d in ((Gx,Gy//B*B),(Gx,(Gy+B-1)//B*B),(Gx//B*B,Gy),((Gx+B-1)//B*B,Gy)):
if a==c or b==d:
... | ConDefects/ConDefects/Code/abc258_f/Python/53486241 |
condefects-python_data_826 | import sys
input = sys.stdin.readline
def dist(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
def push(x, y, B, K):
if x % B == 0 or y % B == 0:
return [(x, y, 0)]
dx, ux = x//B*B, (x+B-1)//B*B
L = []
L.append((dx, y, K * abs(x - dx)))
L.append((ux, y, K * abs(x - ux)))
dy, uy... | ConDefects/ConDefects/Code/abc258_f/Python/54437029 |
condefects-python_data_827 | # 大通りだけを通って (sx, sy) -> (gx, gy) にいく最短距離
def path(sx, sy, gx, gy, b):
if sx == gx or sy == gy:
return abs(sx - gx) + abs(sy - gy)
if (sx - sy) % b and (gx - gy) % b:
if sy % b:
sx, sy = sy, sx
gx, gy = gy, gx
rem = sx % b
return min(
path(sx - ... | ConDefects/ConDefects/Code/abc258_f/Python/46362422 |
condefects-python_data_828 | from math import gcd
N, K = map(int, input().split())
if N % 2 == 0:
exit(print(-1))
g = gcd(N, K)
a = N // g
x = K // g
ans = []
if g == 1:
for i in range((a - 1) // 2):
ans.append((2 * i, 2 * i + 1))
else:
for i in range((a - 1) // 2):
base = 2 * g * i
for j in range(g // 2):
... | ConDefects/ConDefects/Code/arc152_d/Python/36680742 |
condefects-python_data_829 | import sys
input = sys.stdin.readline
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
#sys.setrecursionlimit(10000000)
from collections import defaultdict,deque
import bisect
inf=10**20
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):... | ConDefects/ConDefects/Code/arc152_d/Python/36684114 |
condefects-python_data_830 | H,W = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
maze = [[1]*4 for _ in range(H)]
for i in range(H):
for j in range(W):
F = True
if j >= 1:
if A[i][j] == A[i][j-1]:
F = False
if j <= W-2:
if A[i][j] == A[i][j+1]:
... | ConDefects/ConDefects/Code/abc283_e/Python/45759088 |
condefects-python_data_831 | # import pypyjit;pypyjit.set_param("max_unroll_recursion=-1")
# from bisect import *
# from collections import *
# from heapq import *
# from itertools import *
# from math import *
# from datetime import *
# from decimal import * # PyPyだと遅い
# from string import ascii_lowercase,ascii_uppercase
# import numpy as np
imp... | ConDefects/ConDefects/Code/arc141_a/Python/43463915 |
condefects-python_data_832 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
T = int(readline())
for _ in range(T):
N = readline().rstrip()
LEN = len(N)
if LEN % 2:
LEN += 1
ans = int('9' * (LEN - 1))
for i in range(1, LEN // 2 + 1):
num1 = N[:i]
num2 ... | ConDefects/ConDefects/Code/arc141_a/Python/42776036 |
condefects-python_data_833 | T = int(input())
for _ in range(T):
s = list(input())
m = len(s)
ans = -1
for k in range(1,m//2+1):
if m%k!=0:
continue
mini = s[:k]
temp = mini*(m//k)
if temp>s:
mini = list(str(int("".join(mini))-1))
temp = mini*(m//k)
ans = max(ans,int("".join(temp)))
print(ans)
T = ... | ConDefects/ConDefects/Code/arc141_a/Python/44827544 |
condefects-python_data_834 | T=int(input())
for _ in range(T):
N=input()
ans=0
for i in range(1,len(N)):
if len(N)%i==0:
if int(N[:i]*(len(N)//i))<=int(N):
ans=max(ans,int(N[:i]*(len(N)//i)))
else:
ans=max(ans,int(str(int(N[:i])-1)*(len(N)//i)))
print(ans)
T=int(input())
for _ in range(T):
N=input()
ans... | ConDefects/ConDefects/Code/arc141_a/Python/44321950 |
condefects-python_data_835 | t = int(input())
for _ in range(t):
s = input()
ints = int(s)
ans = 1
lens = len(s)
for length in range(1, len(s)):
if lens % length != 0:
continue
base = s[:length]
num = int(base * (lens // length))
while ints < num:
base = str(int(base) - 1)
num = int(base * (lens // lengt... | ConDefects/ConDefects/Code/arc141_a/Python/44207258 |
condefects-python_data_836 | T = int(input())
for _ in range(T):
case = input()
length = len(case)
max_val = 0
for i in range(1, length):
if length % i == 0:
tmp = case[:i]
tmp = "".join(tmp)
val1 = int(tmp*(length//i))
val2 = int(str(int(t... | ConDefects/ConDefects/Code/arc141_a/Python/41469868 |
condefects-python_data_837 | def make_div(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
T = int(input())
for _ in range... | ConDefects/ConDefects/Code/arc141_a/Python/43307420 |
condefects-python_data_838 | import sys
# sys.setrecursionlimit(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().split()))
def LLI(rows_number): retu... | ConDefects/ConDefects/Code/arc138_d/Python/38710598 |
condefects-python_data_839 | n,k = map(int,input().split())
if k == n or k%2 == 0:
print("No")
exit()
graycode = [i^(i>>1) for i in range(1<<n)]
basis = []
cand = []
for i in range(1<<n):
if bin(i).count("1") != k:
continue
now = i
for b in basis:
now = min(now,now^b)
if now:
basis.append(now)
... | ConDefects/ConDefects/Code/arc138_d/Python/31152215 |
condefects-python_data_840 | #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
def main():
n, k = map(int,input().split())
if n == 1 and k == 1:
print("Yes")
print("0")
return
if k >= n:
print("No")
return
if k % 2 == 0:
print("No")
else:
if k == ... | ConDefects/ConDefects/Code/arc138_d/Python/30827068 |
condefects-python_data_841 | def gray_code(n):
g=[0]*(2**n)
for k in range(2 ** n):
g[k]=format(bin(k^(k>>1))[2:],"0>"+str(n))
return(g)
import array
n,k=map(int,input().split())
if k%2==0 or n==k:
print("No");exit()
print("Yes")
xornum=[]
s={0}
for i in range(2**n):
if bin(i).count("1")==k and i not in s:
news=set()
for j i... | ConDefects/ConDefects/Code/arc138_d/Python/33049315 |
condefects-python_data_842 | N,K=map(int, input().split())
if K%2==0 or N==K:
print("No")
exit()
print("Yes")
def calc(bit,n,rets):
if n==-1:
rets.append(bit)
return bit
bit=calc(bit,n-1,rets)
bit^=1<<n
return calc(bit,n-1,rets)
gray=[]
calc(0,N-1,gray)
norm=[(1<<K)-1]
for i in range(K-1):
norm.append((1... | ConDefects/ConDefects/Code/arc138_d/Python/31059522 |
condefects-python_data_843 | import math
def map_int(s):
try:
return list(map(int, s.split()))
except ValueError:
return s.strip().split()
def main():
(n,k), = [map_int(s) for s in open(0)]
s = set()
for i in range(2 ** n):
j = i
t = 0
while i:
t += i % 2
i >>= 1... | ConDefects/ConDefects/Code/arc138_d/Python/30830027 |
condefects-python_data_844 | import sys
from collections import deque,defaultdict
def input():
return sys.stdin.readline()[:-1]
def popcount(n):
#O(logn)
answer=0
while n>0:
answer+=n&0b1
n>>=1
return answer
def popcount_fast(n):
assert n.bit_length()<=64
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x ... | ConDefects/ConDefects/Code/arc138_d/Python/30842365 |
condefects-python_data_845 | n,k=map(int,input().split())
if n==1:
print('Yes')
print(1,1)
exit()
if (not k&1) or k==n:
print('No')
exit()
gray = [0]
for i in range(n):
nxt = []
flip = False
for ai in gray:
if flip:
nxt.append(ai|(1<<i))
nxt.append(ai)
else:
nxt... | ConDefects/ConDefects/Code/arc138_d/Python/30833301 |
condefects-python_data_846 | def popcount(n):
cnt = 0
while n:
cnt += n & 1
n //= 2
return cnt
def basis01(N, K):
lst = []
lst2 = []
for i in range(1 << N):
if popcount(i) != K:
continue
temp = i
for e in lst:
temp = min(temp, e^temp)
if temp != 0:
... | ConDefects/ConDefects/Code/arc138_d/Python/34316813 |
condefects-python_data_847 | import sys
input = sys.stdin.readline
import random
N,K=map(int,input().split())
if N==K or K%2==0:
print("No")
exit()
A=0
B=1
check=[0]*(1<<N)
ANS=[]
check[A]=1
check[B]=1
def route(x,i,j):#xから始まるルート,bit iは固定.j 残りbitの個数
NOW=x
ANS.append(NOW)
check[NOW]=1
for k in range(1<<j):
for... | ConDefects/ConDefects/Code/arc138_d/Python/30896644 |
condefects-python_data_848 | N, K = map(int, input().split())
if K % 2 == 0 or K == N:
print("No")
else:
print("Yes")
z = [(1 << K) - 1]
for i in range(K - 1):
z.append((1 << K + 1) - 1 - (1 << i))
for i in range(K, N):
z.append((1 << K - 1) - 1 + (1 << i))
ans = [0]
a = 0
for i in range(1, 1 << N)... | ConDefects/ConDefects/Code/arc138_d/Python/31052535 |
condefects-python_data_849 | n, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(list(set(a)))
p, ans = 0, 0
for i in range(min(len(a), k)):
if p==i:
ans+=1
p+=1
else:
break
print(ans)
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(list(set(a)))
p, ans = 0, 0
for i in ra... | ConDefects/ConDefects/Code/abc290_c/Python/46128954 |
condefects-python_data_850 | N, K = map(int, input().split())
A = list(map(int, input().split()))
d = {}
for i in range(10):
d[i] = 0
A.sort()
if A[0] != 0:
print(0)
else:
i = 1
while i < N:
if (A[i] >= K):
print(A[i-1]+1)
break
if (A[i]-A[i-1] > 1):
print(A[i-1]+1)
... | ConDefects/ConDefects/Code/abc290_c/Python/45270856 |
condefects-python_data_851 | n,k=map(int,input().split())
a=sorted(list(set(map(int,input().split()))))
for i in range(min(len(a),k)):
if i!=a[i]:
exit(print(i))
print(k)
n,k=map(int,input().split())
a=sorted(list(set(map(int,input().split()))))
for i in range(min(len(a),k)):
if i!=a[i]:
exit(print(i))
print(min(len(a),k)) | ConDefects/ConDefects/Code/abc290_c/Python/45296084 |
condefects-python_data_852 | n,k=(int(x) for x in input().split())
a=set([])
A=input().split()
for i in range(n):
if not A[i] in a:
a.add(int(A[i]))
if k>=10:
k=10
ans=0
for i in range(k):
if i in a:
ans+=1
else:
break
print(ans)
n,k=(int(x) for x in input().split())
a=set([])
A=input().split()
for i in range(n):
if not A[i... | ConDefects/ConDefects/Code/abc290_c/Python/45228128 |
condefects-python_data_853 | N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
A_lim = list(set(A))
for i in range(len(A)-len(A_lim)):
A_lim.append(A_lim[-1])
check = 0
ans = 0
flag = True
for i in range(K):
if A_lim[i] == check:
check += 1
else:
ans = i
Flag = False
break
if flag == True:
prin... | ConDefects/ConDefects/Code/abc290_c/Python/46162962 |
condefects-python_data_854 | N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
mex = 0
count = 0
for a in A:
if mex == a and count < K:
mex += 1
count += 1
else:
break
print(mex)
N, K = map(int, input().split())
A = sorted(list(set(map(int, input().split()))))
mex = 0
count = 0
for a ... | ConDefects/ConDefects/Code/abc290_c/Python/46194587 |
condefects-python_data_855 |
def solve():
n=int(input())
r=list(map(int,input().split()))
c=list(map(int,input().split()))
q=int(input())
for i in range(q):
x,y=map(int,input().split())
x-=1
y-=1
if r[x]+c[y]>5:
print("#",end="")
else:
print(".",end="")
for te... | ConDefects/ConDefects/Code/arc132_a/Python/38864069 |
condefects-python_data_856 | 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/arc132_a/Python/43293149 |
condefects-python_data_857 | n = int(input())
r = list(map(int, input().split()))
c = list(map(int, input().split()))
q = int(input())
ans = ""
for i in range(q):
a, b = map(int, input().split())
a-=1
b-=1
if(r[a] > 5-c[b]):ans += "#"
else:ans += "."
print(ans)
n = int(input())
r = list(map(int, input().split()))
c = list(... | ConDefects/ConDefects/Code/arc132_a/Python/44360542 |
condefects-python_data_858 | # 長さnのリストRと長さnのリストCが与えられます。
# また、q個のクエリが与えられます。
# 各クエリは、2つの整数aとbが与えられ、Rのa番目の要素とCのb番目の要素を足した値がnより大きい場合は'#'を、そうでない場合は'.'を出力してください。
# という問題と同義。
def solve(n,R,C,Q,queries):
ans = []
for r,c in queries:
if R[r-1]+C[c-1] > n:
ans.append("#")
else:
ans.append(".")
return an... | ConDefects/ConDefects/Code/arc132_a/Python/39808227 |
condefects-python_data_859 | n=int(input())
r=list(map(int,input().split()))
c=list(map(int,input().split()))
q=int(input())
ans=""
for i in range(q):
y,x=map(int,input().split())
ans+="#" if r[y-1]+c[y-1]>n else "."
print (ans)
n=int(input())
r=list(map(int,input().split()))
c=list(map(int,input().split()))
q=int(input())
ans=""
for i in ran... | ConDefects/ConDefects/Code/arc132_a/Python/45439715 |
condefects-python_data_860 | n=int(input())
R=list(map(int,input().split()))
C=list(map(int,input().split()))
q=int(input())
ans=""
for i in range(q):
r,c=map(int,input().split())
if R[r-1]+C[c-1]>5:
ans+="#"
else:
ans+="."
print(ans)
n=int(input())
R=list(map(int,input().split()))
C=list(map(int,input().split()))
q=in... | ConDefects/ConDefects/Code/arc132_a/Python/37932148 |
condefects-python_data_861 | N=int(input())
P=list(map(int,input().split()))
flg=[[False]*N for i in range(N)]
for i in range(1,N):
for j in range(i):
flg[j][i]=True
Q=int(input())
for i in range(Q):
A,B=map(int,input().split())
if flg[A-1][B-1]:
print(A)
else:
print(B)
N=int(input())
P=list(map(int,input().split()))
flg=[[False]*N for ... | ConDefects/ConDefects/Code/abc342_b/Python/54862037 |
condefects-python_data_862 | import heapq
def prev(l,d,k,c,t):
if l+d*(k-1)+c<=t: a=l+d*(k-1)
elif t<l+c: a=-1
else: a=l+d*((t-l)//d)
return a
def dijkstra(P,T,v,s):
H,T[v]=[],s
heapq.heappush(H,(-s,v))
while H:
t,v=heapq.heappop(H)
if T[v]>-t: continue
for l,d,k,c,a in P[v]:
s=prev(l,d,k,c,-t)
if T[a]<s:
... | ConDefects/ConDefects/Code/abc342_e/Python/52012139 |
condefects-python_data_863 | #!/usr/bin/env python3
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush
from math import gcd
from sys import setrecursionlimit
dpos4 = ((1, 0), (0, 1), (-1, 0), (0, -1))
dpos8 = ((0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1), (-1,... | ConDefects/ConDefects/Code/abc342_e/Python/52271105 |
condefects-python_data_864 | import heapq
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_max(heap,item):
heap.append(item)
heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
i... | ConDefects/ConDefects/Code/abc342_e/Python/55130298 |
condefects-python_data_865 | import heapq
N,M=map(int,input().split())
edge=[[] for i in range(N)]
for i in range(M):
l,d,k,c,A,B=map(int,input().split())
A-=1;B-=1
edge[B].append((l,d,k,c,A))
P=[(-10**20,N-1)]
heapq.heapify(P)
ans=[-1]*N
while P:
time,pos=heapq.heappop(P)
time*=-1
if ans[pos]>0:
continue
ans[pos]=time
for l,d,k,c,A in e... | ConDefects/ConDefects/Code/abc342_e/Python/54872777 |
condefects-python_data_866 | # import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
# import sys
# sys.setrecursionlimit(10**7)
import re
# import more_itertools
import functools
import sys
import bisect
import math
import itertools
from collections import deque
from collections import defaultdict
from collections import Counter
from copy... | ConDefects/ConDefects/Code/abc342_e/Python/53929087 |
condefects-python_data_867 | from heapq import*;f=lambda:map(int,input().split());N,M=f();G=[[]for x in" "*N*2];I=1e18;T=[-I]*N+[I];Q=[(-I,N)]
for m in " "*M:*t,b=f();G[b]+=[t]
while Q:
s,x=heappop(Q)
for l,d,k,c,y in G[x]:
t=min((a:=-s-c-l)//d*d,(k-1)*d)+l
if T[y]<t and a>=0:T[y]=t;heappush(Q,(-t,y))
for t in T[1:N]:print([t,"Unreachable"][... | ConDefects/ConDefects/Code/abc342_e/Python/55130748 |
condefects-python_data_868 | n,s=map(int, input().split())
c=[0]*n
d=[]
for i in range(n):
a,b=map(int, input().split())
if a<=b:
d.append(b-a)
s-=a
else:
c[i]=1
d.append(a-b)
s-=b
if s<=0:
print("No")
exit()
dp=[[0]*(s+1) for _ in range(n+1)]
dp[0][0]=1
for i in range(n):
D=d[i]
for j in range(s+1):
if dp[i... | ConDefects/ConDefects/Code/abc271_d/Python/46008428 |
condefects-python_data_869 | M=998244353
n,m,k=map(int,input().split())
c=[0]*(m+1)
for a in list(map(int,input().split())):
c[a]+=1
z=c[0]
c[0]=0
fa=[1]
fb=[1]
for i in range(1,z+1):
fa.append((fa[-1]*i)%M)
fb.append((fb[-1]*pow(i,M-2,M))%M)
for i in range(m):
c[i+1]+=c[i]
f=0
for i in range(1,m+1):
if c[i-1]>k-1:
break
g=0
fo... | ConDefects/ConDefects/Code/abc295_e/Python/42176175 |
condefects-python_data_870 | import sys
input = sys.stdin.readline
ii = lambda: int(input())
mi = lambda: map(int, input().split())
N, M, K = mi()
A = list(mi())
# N, M, K = 10,20,7
# A = [6, 5, 0, 2, 0, 0, 0, 15, 0, 0]
# N,M,K = [3, 5, 2]
# A = [2, 0, 4]
###############
MAX = N+1
MOD = 998244353
fac = [0 for i in range(0,MAX)]
finv = [0 for... | ConDefects/ConDefects/Code/abc295_e/Python/42264948 |
condefects-python_data_871 | n,m,k=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
cnt=[0]*(m+1)
for i in a:
cnt[i]+=1
q=pow(m,-cnt[0],mod)
p=[1]
pr=[1]
for i in range(1,n+1):
p.append(p[-1]*i%mod)
pr.append(pow(p[-1],-1,mod))
now=0
ans=0
for i in range(1,m+1):
if now>=k:
break
for j in range(k-no... | ConDefects/ConDefects/Code/abc295_e/Python/54729841 |
condefects-python_data_872 | h,w,k=map(int,input().split())
sy,sx=map(lambda x: int(x)-1,input().split())
A=[list(map(int,input().split())) for _ in range(h)]
dp=[[0]*w for _ in range(h)]
ans=0
dp=[[[-1]*w for _ in range(h)]for _ in range(h*w+10)]
dp[0][sy][sx]=0
for t in range(min(h*w,k)+1):
for i in range(h):
for j in range(w):
ans=... | ConDefects/ConDefects/Code/abc358_g/Python/54747596 |
condefects-python_data_873 | H, W, K = map(int,input().split())
sh, sw = map(int,input().split())
sh, sw = sh-1, sw-1
A = []
for _ in range(H):
A.append(list(map(int,input().split())))
trial = min(H*W-1,K)
# dp[i][h][w]:i回目に(h,w)にいるときの「楽しさ」の最大
dp = [[[-1 for _ in range(W)] for _ in range(H)] for _ in range(trial+1)]
dp[0][sh][sw] = 0
mv ... | ConDefects/ConDefects/Code/abc358_g/Python/54855434 |
condefects-python_data_874 | import bisect
import collections
import functools
import heapq
import itertools
import math
import operator
import string
import sys
import typing
# sys.setrecursionlimit(1000000)
readline = sys.stdin.readline
LS = lambda: readline()
LI = lambda: int(readline())
LLS = lambda: readline().split()
LL = lambda: list(map(i... | ConDefects/ConDefects/Code/abc358_g/Python/54786782 |
condefects-python_data_875 | import sys
readline = sys.stdin.readline
LS = lambda: readline()
LI = lambda: int(readline())
LLS = lambda: readline().split()
LL = lambda: list(map(int, readline().split()))
h, w, k = LL()
sx, sy = LL()
sx -= 1
sy -= 1
A = [LL() for _ in range(h)]
moves = [(0, 1), (1, 0), (0, -1), (-1, 0)]
INF = 10**18
f = [[[INF] ... | ConDefects/ConDefects/Code/abc358_g/Python/54786893 |
condefects-python_data_876 | from random import randint, shuffle
from math import gcd, log2, log, sqrt, hypot, pi, degrees
from fractions import Fraction
from bisect import bisect_left, bisect_right
from itertools import accumulate, permutations, combinations, product, chain, groupby
from sortedcontainers import SortedList
from collections import ... | ConDefects/ConDefects/Code/abc358_g/Python/54886527 |
condefects-python_data_877 | #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
from random import random, randint
def main():
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
fixed = [[a[i][j] != 0 for j in range(n)] for i in range(n)]
minAns = float("inf")
p2 = []
for _ in... | ConDefects/ConDefects/Code/abc347_g/Python/51866544 |
condefects-python_data_878 | def calc_area(y, x):
ret = score[N][N] * (x//N) * (y//N)
ret += score[N][x%N] * (y//N)
ret += score[y%N][N] * (x//N)
ret += score[y%N][x%N]
return ret
N, Q = map(int, input().split())
P = [list(input()) for i in range(N)]
score = [[0] * (N+1) for i in range(N+1)]
ABCD = [list(map(int, input().split... | ConDefects/ConDefects/Code/abc331_d/Python/53655797 |
condefects-python_data_879 | #!/usr/bin/env python3
#import sys
#sys.setrecursionlimit(10**8)
#import math
#from itertools import product,permutations,combinations,combinations_with_replacement
#from sortedcontainers import SortedDict,SortedSet,SortedKeyList
#from collections import deque
#from heapq import heapify,heappop,heappush
#from bisect i... | ConDefects/ConDefects/Code/abc331_d/Python/53468592 |
condefects-python_data_880 | import sys
from collections import deque, defaultdict
from itertools import (
accumulate,
product,
permutations,
combinations,
combinations_with_replacement,
)
import math
from bisect import bisect_left, insort_left, bisect_right, insort_right
# product : bit全探索 product(range(2),repeat=n)
# permuta... | ConDefects/ConDefects/Code/abc331_d/Python/52719206 |
condefects-python_data_881 | n,m=map(int,input().split())
S=[]
for i in range(2,2*n+1,2):
s,tmp=0,1
for j in range(15):
if i>>j&1:
s+=tmp
tmp*=3
S.append(s)
x=(m-sum(S))%n
for i in range(x):
S[i]+=1
diff=(sum(S)-m)
print(*[s-diff for s in S])
n,m=map(int,input().split())
S=[]
for i in range(2,2*n+1,2):
... | ConDefects/ConDefects/Code/arc145_d/Python/39783538 |
condefects-python_data_882 | from random import randrange
N, M = map(int, input().split())
S = [0]
for k in range(15):
for a in S[:]:
S.append(a + 3 ** k)
T = S[:N]
s = sum(T)
while (s - M) % N:
j = randrange(N)
s += S[-1] - T[j]
T[j] = S.pop()
print(*[a - (s - M) // N for a in T])
from random import randrange
N, M = map... | ConDefects/ConDefects/Code/arc145_d/Python/33637469 |
condefects-python_data_883 | from functools import lru_cache
@lru_cache(maxsize=None)
def a(x):
if x==0:return 1
if x&1:return 3*a(x//2)-1
return 3*a(x//2)-2
n,m=map(int,input().split())
if n==1:
print(m)
exit(0)
ANS=[a(x) for x in range(n-1)]
s=sum(ANS)
# print(ANS,s)
target=abs(m)+2*10**6
plus=(target-s)//(n-1)+1
ANS=[num... | ConDefects/ConDefects/Code/arc145_d/Python/34667900 |
condefects-python_data_884 | N, M = map(int, input().split())
ans = []
SUM = 0
count = 0
for i in range(10**7)[::-1]:
OK = True
cur = i
while cur > 0:
if cur % 3 == 2:
OK = False
break
else:
cur //= 3
if OK:
ans.append(i)
SUM += i
count += 1
if count ... | ConDefects/ConDefects/Code/arc145_d/Python/33635092 |
condefects-python_data_885 | import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
import math
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict
#from collections import deque
#import copy #DeepCopy: hoge = ... | ConDefects/ConDefects/Code/arc145_d/Python/34720181 |
condefects-python_data_886 | def main():
import sys, operator, math
if sys.implementation.name == 'pypy':
import pypyjit
pypyjit.set_param('max_unroll_recursion=1')
from math import gcd, floor, ceil, sqrt, isclose, pi, sin, cos, tan, asin, acos, atan, atan2, hypot, degrees, radians, log, log2, log10
from array import array
from c... | ConDefects/ConDefects/Code/arc145_d/Python/33636883 |
condefects-python_data_887 | n, m = map(int, input().split())
d = [1]
while len(d) < n:
d = d + [sum(d)] + d
d = d[:n - 1]
d += [sum(d) + 1]
for i in range(1, n):
d[i] += d[i - 1]
sub = (sum(d) - m) // n + 1
for i in range(n):
d[i] -= sub
d[-1] -= sum(d) - m
print(*d)
n, m = map(int, input().split())
d = [1]
while len(d) < n:
d = d + [sum... | ConDefects/ConDefects/Code/arc145_d/Python/35361966 |
condefects-python_data_888 | 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()
n,m,q = map(int,input().split())
#for i in range(n):
# alist.append(list(map(int,input().split())))
query =... | ConDefects/ConDefects/Code/abc253_f/Python/45527428 |
condefects-python_data_889 | from collections import Counter
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, m = mi()
N = 1
while N <= n:
N *= 2
a = li()
class andconvolution():
def __init__(self):
... | ConDefects/ConDefects/Code/arc137_d/Python/36174552 |
condefects-python_data_890 | 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 _heappus... | ConDefects/ConDefects/Code/arc137_d/Python/30239419 |
condefects-python_data_891 | from random import randrange
from time import time
def calc(t):
X.sort(key = lambda x: -x[0] * t - x[1])
su1, su0 = 0, 0
for i in range(K):
su1 += X[i][0]
su0 += X[i][1]
return (1 if su1 > t else -1, su1 ** 2 + su0)
sTime = time()
N, K = map(int, input().split())
C = [int(a) * 36 for a ... | ConDefects/ConDefects/Code/abc257_h/Python/32762821 |
condefects-python_data_892 | S = input()
if S[0].isupper() and S[-1].isupper():
T = S[1:-1]
if T.isdigit():
if 100000 <= int(T) <= 999999:
print('Yes')
else:
print('No')
else:
print('No')
else:
print('No')
S = input()
if S[0].isupper() and S[-1].isupper():
T = S[1:-1]
if T.... | ConDefects/ConDefects/Code/abc281_b/Python/45944374 |
condefects-python_data_893 | S = list(input())
x = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
if len(S) != 8:
print("No")
exit()
elif not(S[0] in x) and not(S[-1] in x) and S[1] != "0":
for i in range(6):
if not(S[i + 1] in x):
print("No")
exit()
else:
print("No")
exit()
print("Yes")
S = list... | ConDefects/ConDefects/Code/abc281_b/Python/45344289 |
condefects-python_data_894 | def solve(s: str) :
""" You are given a string S consisting of uppercase English letters and digits. Determine whether
S satisfies the following condition.
S is a concatenation of the following characters and string in the order listed.
1 - An uppercase English letter
2 - A string of length 6 that ... | ConDefects/ConDefects/Code/abc281_b/Python/45430441 |
condefects-python_data_895 | s = input()
s_list = []
for i in range(len(s)):
if s[i] in [chr(i) for i in range(65, 91)]:
s_list.append(s[i])
if len(s_list) == 2 and s[0] in [chr(i) for i in range(65, 91)] and s[len(s) - 1] in [chr(i) for i in range(65, 91)]:
if (s[0] in [chr(i) for i in range(65, 91)]) and (s[len(s) - 1] in [chr(i)... | ConDefects/ConDefects/Code/abc281_b/Python/46135181 |
condefects-python_data_896 | # import pypyjit;pypyjit.set_param("max_unroll_recursion=-1")
# from bisect import *
# from collections import *
# from heapq import *
# from itertools import *
# from sortedcontainers import *
# from math import gcd, lcm
# from datetime import *
# from decimal import * # PyPyだと遅い
from string import ascii_lowercase, a... | ConDefects/ConDefects/Code/abc281_b/Python/45944008 |
condefects-python_data_897 | s=input()
t=s[1:-1]
ans='No'
if s[0].isupper() and s[-1].isupper():
if t.isdigit() and 100000<=int(t)<=999999:
ans='Yes'
print(ans)
s=input()
t=s[1:-1]
ans='No'
if s[0].isupper() and s[-1].isupper():
if len(s)==8 and t.isdigit() and 100000<=int(t)<=999999:
ans='Yes'
print(ans) | ConDefects/ConDefects/Code/abc281_b/Python/45943845 |
condefects-python_data_898 | s = input()
n = len(s)
keyA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
key0 = "0123456789"
turn = 0
idx = 0
i = 0
while i < n:
if turn == 0:
if s[i] in keyA:
turn = 1
else:
break
elif turn == 1:
if s[i] == "0":
break
else:
turn = 2
... | ConDefects/ConDefects/Code/abc281_b/Python/45699589 |
condefects-python_data_899 | def prefix_sum(A) :
N = len(A)
res = [0 for i in range(N)]
res[0] = A[0]
for i in range(1, N) : res[i] = A[i] + res[i - 1]
return res
N = int(input())
A = list(map(int, input().split()))
S = list(reversed(prefix_sum(list(reversed(A)))))
dit = [10 ** len(str(A[i])) for i in range(N)]
ditsum = list(reversed(p... | ConDefects/ConDefects/Code/abc353_d/Python/54729259 |
condefects-python_data_900 | N = int(input())
S = []
for i in range(N):
s = input()
S.append(s)
flag = False
for i in range(N):
for j in range(N):
if i == j:
break
a = S[i] + S[j]
if a == a[::-1]:
flag = True
print('Yes' if flag else 'No')
N = int(input())
S = []
for i in range(N):
s = input(... | ConDefects/ConDefects/Code/abc307_b/Python/45983540 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.