id
stringlengths
24
27
content
stringlengths
37
384k
max_stars_repo_path
stringlengths
51
51
condefects-python_data_701
n = int(input()) a = list(map(int,input().split())) ikeru = [[] for i in range(n)] for i in range(n-1): u, v = map(int,input().split()) u-=1; v-=1 ikeru[u].append(v) ikeru[v].append(u) def canreach(x): #x以上に到達可能か? #部分木DP mada = [~0, 0] tansaku = [0] * n tansaku[0] = 1 dp = [0] * n while mada: i = mada.pop...
ConDefects/ConDefects/Code/abc246_g/Python/32131546
condefects-python_data_702
import sys import math import sys from collections import defaultdict N = int(input()) S = [0]+list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(N-1)] g = [[] for _ in range(N)] for a, b in AB: a -= 1 b -= 1 g[a].append(b) g[b].append(a) children = [[] for _ in range...
ConDefects/ConDefects/Code/abc246_g/Python/31385030
condefects-python_data_703
N = int(input()) A = [0]+list(map(int,input().split())) G = [[] for _ in range(N)] for _ in range(N-1): u,v = map(int,input().split()) u,v = u-1,v-1 G[u].append(v) G[v].append(u) order = [] par = [-1]*N from collections import deque dq = deque([0]) while dq: cur = dq.popleft() order.append(cur)...
ConDefects/ConDefects/Code/abc246_g/Python/41873287
condefects-python_data_704
N = int(input()) A = list(map(int,input().split())) A = [-1] + A G = [[] for i in range(N)] for _ in range(N-1): u,v = map(int,input().split()) u -= 1 v -= 1 G[u].append(v) G[v].append(u) dist = [-1 for i in range(N)] dist[0] = 0 todo = [0] RG = [[] for i in range(N)] H = [] while len(todo): u = todo.pop()...
ConDefects/ConDefects/Code/abc246_g/Python/49874325
condefects-python_data_705
class Tree: __slots__=("N", "index", "parent", "__mutable", "root", "children", "depth", "tower", "upper_list", "deg", "des_count", "preorder_number", "euler_vertex", "euler_edge", "in_time", "out_time") def __init__(self,N,index=0): """ N 頂点 (index, index+1, ..., N-1+index) の根付...
ConDefects/ConDefects/Code/abc246_g/Python/33722514
condefects-python_data_706
N = int(input()) S = [input() for _ in range(N)] dx = [1,0,1,-1] dy = [0,1,1,1] for h in range(N): for w in range(N): for i in range(4): cnt = 0 for j in range(6): nh = h + dy[i]*j nw = w + dx[i]*j if not (0 <= nh < N and 0 <= nw < N)...
ConDefects/ConDefects/Code/abc241_c/Python/45443856
condefects-python_data_707
from heapq import heappop, heappush N = int(input()) tree = [[] for _ in range(N)] for _ in range(N-1): u, v = map(int, input().split()) u -= 1; v -= 1 tree[u].append(v) tree[v].append(u) root = 0 parent = [-1] * N parent[root] = root num_children = [0] * N stack = [root] leaf = set(range(N)) while st...
ConDefects/ConDefects/Code/abc223_g/Python/45319303
condefects-python_data_708
from typing import NamedTuple, Optional, List, cast class MFGraph: class Edge(NamedTuple): src: int dst: int cap: int flow: int class _Edge: def __init__(self, dst: int, cap: int) -> None: self.dst = dst self.cap = cap self.rev: Optio...
ConDefects/ConDefects/Code/abc259_g/Python/41146837
condefects-python_data_709
from collections import deque from math import inf import sys import io import os # region IO BUFSIZE = 8192 class FastIO(io.IOBase): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.buffer = io.BytesIO() self.writable = "x" in file.mode ...
ConDefects/ConDefects/Code/abc259_g/Python/33161543
condefects-python_data_710
import sys from collections import deque,defaultdict import itertools import heapq import bisect import queue import math #sys.setrecursionlimit(10 ** 9) input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) li_st = lambda: list(map(str, ...
ConDefects/ConDefects/Code/abc226_b/Python/45483175
condefects-python_data_711
n = int(input()) l = set() for i in range(n): l.add(input().replace(" ", "")) print(len(l)) n = int(input()) l = set() for i in range(n): l.add(input()) print(len(l))
ConDefects/ConDefects/Code/abc226_b/Python/46010276
condefects-python_data_712
N=int(input()) for i in range(N): A=list(map(int,input().split())) ans=[] for j in range(N): if A[j]: ans.append(j+1) print(ans) N=int(input()) for i in range(N): A=list(map(int,input().split())) ans=[] for j in range(N): if A[j]: ans.append(j+1) print(*ans)
ConDefects/ConDefects/Code/abc343_b/Python/54873239
condefects-python_data_713
N = int(input()) matrix = [] for _ in range(N): row = list(map(int, input().strip().split())) matrix.append(row) for i in range(N): ans = [] for j in range(N): if matrix[i][j] == 1: ans.append(j) print(*ans) N = int(input()) matrix = [] for _ in range(N): row = list(map(int, input...
ConDefects/ConDefects/Code/abc343_b/Python/54300616
condefects-python_data_714
N = int(input()) A = [list(map(int, input().split())) for _ in range(N)] ans = [] for i in range(N): for j in range(N): if A[i][j] == 1: ans.append(j+1) print(*ans) N = int(input()) A = [list(map(int, input().split())) for _ in range(N)] for i in range(N): ans = [] for j in range(N)...
ConDefects/ConDefects/Code/abc343_b/Python/54540340
condefects-python_data_715
#!/usr/bin/env python3 import sys # https://github.com/tatyam-prime/SortedSet/blob/main/SortedSet.py import math from bisect import bisect_left, bisect_right from typing import Generic, Iterable, Iterator, TypeVar, Union, List T = TypeVar('T') class SortedSet(Generic[T]): BUCKET_RATIO = 50 REBUILD_RATIO = 170...
ConDefects/ConDefects/Code/arc155_b/Python/44148523
condefects-python_data_716
def main(): n = int(input()) s = list(input()) ok = False for i in range(n): if s[i] == "o": ok = True elif s[i] == "x": print("No") break if ok == True: print("Yes") else: print("No") if __name__ == "__main__": main...
ConDefects/ConDefects/Code/abc298_a/Python/45277640
condefects-python_data_717
N = int(input()) S = list(input()) if "○" in S and "x" not in S: print("Yes") else: print("No") N = int(input()) S = list(input()) if "o" in S and "x" not in S: print("Yes") else: print("No")
ConDefects/ConDefects/Code/abc298_a/Python/46129675
condefects-python_data_718
S = ["and", "not", "that", "the", "you"] N = int(input()) W = list(input().split()) for w in W: if w in S: exit(print("Yes")) print("NO") S = ["and", "not", "that", "the", "you"] N = int(input()) W = list(input().split()) for w in W: if w in S: exit(print("Yes")) print("No")
ConDefects/ConDefects/Code/abc295_a/Python/45025721
condefects-python_data_719
n=int(input()) x=list(input().split()) eng=["and","not","that","the","you"] for i in range(n): print(i) print(x[i]) if x[i] in eng: print("Yes") break elif i==n-1: print("No") n=int(input()) x=list(input().split()) eng=["and","not","that","the","you"] for i in range(n): if...
ConDefects/ConDefects/Code/abc295_a/Python/45272260
condefects-python_data_720
n=int(input()) L=list(map(str,input().split())) ans="No" for i in range(len(L)): if L[i]=="and" or L[i]=="not" and L[i]=="that" and L[i]=="the" and L[i]=="you": ans="Yes" break print(ans) n=int(input()) L=list(map(str,input().split())) ans="No" for i in range(len(L)): if L[i]=="and" or L[i]=="not" or L[i]=...
ConDefects/ConDefects/Code/abc295_a/Python/46045977
condefects-python_data_721
n = int(input()) s = list(input()) ary = set(s) keys = ["and", "not", "that", "the", "you"] for key in keys: if key in ary: print("Yes") break else: print("No") n = int(input()) s = input().split() ary = set(s) keys = ["and", "not", "that", "the", "you"] for key in keys: if key in ary: ...
ConDefects/ConDefects/Code/abc295_a/Python/45517657
condefects-python_data_722
N = int(input()) word_list = map(str,input().split()) keywords = ["and", "not", "that", "the", "you"] found = False for keyword in keywords: if keyword in word_list: found = True break if found: print("Yes") else: print("No") N = int(input()) word_list = list(map(str, input().split())) k...
ConDefects/ConDefects/Code/abc295_a/Python/44861660
condefects-python_data_723
n = int(input()) a = list(input().split()) ans = "No" for i in a: if i == "and" or i == "not" or i == "that" or i == "you": print("Yes") exit() print(ans) n = int(input()) a = list(input().split()) ans = "No" for i in a: if i == "and" or i == "not" or i == "that" or i == "you" or i == "the":...
ConDefects/ConDefects/Code/abc295_a/Python/45905401
condefects-python_data_724
S = input() for i in range(len(S)): if 'A' < S[i] < 'Z': print(i + 1) S = input() for i in range(len(S)): if 'A' <= S[i] <= 'Z': print(i + 1)
ConDefects/ConDefects/Code/abc291_a/Python/45508180
condefects-python_data_725
print(input().replace("0", "1").replace("1", "0")) print("".join(map(str, [(i+1)%2 for i in map(int, list(input()))])))
ConDefects/ConDefects/Code/abc289_a/Python/45965844
condefects-python_data_726
A,B,C,X = map(int,input().split()) if X <= A: print(1.000000000000) elif X < B: print(C/(B-A)) else: print(0.000000000000) A,B,C,X = map(int,input().split()) if X <= A: print(1.000000000000) elif X <= B: print(C/(B-A)) else: print(0.000000000000)
ConDefects/ConDefects/Code/abc242_a/Python/45438303
condefects-python_data_727
inp=input().split() A=inp[0] A=int(A) B=inp[1] B=int(B) C=inp[2] C=int(C) X=inp[3] X=int(X) D=B-A if A>=X: print(1) elif B<X: print(0) else: print(D/C) inp=input().split() A=inp[0] A=int(A) B=inp[1] B=int(B) C=inp[2] C=int(C) X=inp[3] X=int(X) D=B-A if A>=X: print(1) elif B<X: print(0) else: ...
ConDefects/ConDefects/Code/abc242_a/Python/44475619
condefects-python_data_728
from collections import Counter, defaultdict, deque from bisect import bisect_left, bisect_right from heapq import heapify, heappush, heappop def solve(): A, B, C, X = map(int, input().split()) if X >= 1 and X <= A: res = 1/1 elif X > A and X <= C: N = B - A res = C / N else: ...
ConDefects/ConDefects/Code/abc242_a/Python/45767519
condefects-python_data_729
a,b,c,x=list(map(int,input().split())) ans=1.0 if x>a+1 and x<=b: ans=c/(b-a) elif x>b: ans=0.0 print('%.10f'%ans) a,b,c,x=list(map(int,input().split())) ans=1.0 if x>=a+1 and x<=b: ans=c/(b-a) elif x>b: ans=0.0 print('%.10f'%ans)
ConDefects/ConDefects/Code/abc242_a/Python/45709103
condefects-python_data_730
a, b, c, x = map(int, input().split()) if x <= a: print(1) elif a < x <= b: print(c/(b-a+1)) else: print(0) a, b, c, x = map(int, input().split()) if x <= a: print(1) elif a < x <= b: print(c/(b-a)) else: print(0)
ConDefects/ConDefects/Code/abc242_a/Python/45690151
condefects-python_data_731
#!/usr/bin/env python3 import sys a, b, c, x = map(int, input().split()) res = 0.0 if x <= a: res = 100.0 elif x <= b: res = c / (b - a) print('%.9f' % (res)) #!/usr/bin/env python3 import sys a, b, c, x = map(int, input().split()) res = 0.0 if x <= a: res = 1.0 elif x <= b: res = c / (b - a) pri...
ConDefects/ConDefects/Code/abc242_a/Python/44877017
condefects-python_data_732
a,b,c,x=map(int,input().split()) if a>=x: print(1) elif b>=x>a: print(c/(b-a+1)) else: print(0) a,b,c,x=map(int,input().split()) if a>=x: print(1) elif b>=x>a: print(c/(b-a)) else: print(0)
ConDefects/ConDefects/Code/abc242_a/Python/45214716
condefects-python_data_733
A, B, C, X = map(int, input().split()) if X < A: print(1) elif X > B: print(0) else: answer = C / (B - A) print(answer) A, B, C, X = map(int, input().split()) if X <= A: print(1) elif X > B: print(0) else: answer = C / (B - A) print(answer)
ConDefects/ConDefects/Code/abc242_a/Python/45439791
condefects-python_data_734
M,D = map(int,input().split()) y,m,d = map(int,input().split()) if d+1 > D: d = 1 if m+1 > M: m = 1 y = y+1 else: m = m+1 else: d = d+1 print(f"y m d") M,D = map(int,input().split()) y,m,d = map(int,input().split()) if d+1 > D: d = 1 if m+1 > M: m = 1 y = y+1 else: m = m+1 else...
ConDefects/ConDefects/Code/abc331_a/Python/54744974
condefects-python_data_735
def resolve(): M, D = map(int, input().split()) y, m, d = map(int, input().split()) sm, sy = 0, 0 if d == D: d, sm = 1, 1 else: d+=1 if m+sm == M+1: m, sy = 1, 1 y += sy return (y, m, d) print(*resolve()) def resolve(): M, D = map(int, input().split()) y,...
ConDefects/ConDefects/Code/abc331_a/Python/54731952
condefects-python_data_736
M, D = map(int,input().split()) y, m, d = map(int,input().split()) if d==D and m==M: y += 1 m = 1 d = 1 elif m==M: m += 1 d = 1 else: d += 1 print(y,m,d) M, D = map(int,input().split()) y, m, d = map(int,input().split()) if d==D and m==M: y += 1 m = 1 d = 1 elif d==D: m += 1 ...
ConDefects/ConDefects/Code/abc331_a/Python/54773410
condefects-python_data_737
M,D = map(int,input().split()) y,m,d = map(int,input().split()) if d == D: # 最後の日 d = 1 if m == M: m = 1 y += 1 else: d += 1 print(y,m,d) M,D = map(int,input().split()) y,m,d = map(int,input().split()) if d == D: # 最後の日 d = 1 if m == M: m = 1 y += 1 else: ...
ConDefects/ConDefects/Code/abc331_a/Python/54933311
condefects-python_data_738
import bisect N = int(input()) P = list(map(int, input().split())) Q = list(map(int, input().split())) Qinv = {} for i, q in enumerate(Q): Qinv[q] = i S = [] for i, p in enumerate(P): A = [] for x in range(p, N + 1, p): j = Qinv[x] A.append(j) A.sort() A.reverse() S += A # prin...
ConDefects/ConDefects/Code/arc133_b/Python/41864112
condefects-python_data_739
from bisect import * n = int(input()) P = [int(x) for x in input().split()] Q = [int(x) for x in input().split()] Qpos = [-1]*(n+1) for i in range(n): Qpos[Q[i]] = i LIS = [10**9]*n for i in range(n): lst = [] for j in range(P[i],n+1,P[i]): lst.append(Qpos[j]) lst.sort(reverse=True) for j...
ConDefects/ConDefects/Code/arc133_b/Python/34093512
condefects-python_data_740
import numpy as np def dp(n,a): if n==1: print(a[1]-a[2],a[0]-a[1]+a[2],a[1]-a[0],end=' ') return [a[1]-a[2], a[1]-a[0],a[0]-a[1]+a[2]] else: x = 3**(n-1) a0 = a[:x] a1 = a[x:2*x] a2 = a[2*x:] print([a1-a2,a0-a1+a2,a1-a0]) return [dp(n-1,a1-a2),dp(n-1,a0-a1+a2),dp(n-1,a1-a0)] n = ...
ConDefects/ConDefects/Code/abc288_g/Python/38755910
condefects-python_data_741
import sys input = sys.stdin.readline # sys.setrecursionlimit(10**6) def main(): N = int(input()) l = [] for i in range(N): a, b = map(int, input().split()) l.append((-a * 10 ** 100 / (a + b), i + 1)) l.sort() for i in range(N): print(l[i][1], end=' ') print() if __nam...
ConDefects/ConDefects/Code/abc308_c/Python/46192638
condefects-python_data_742
if __name__ == '__main__': N = int(input()) X = [] for i in range(N): a, b = map(int, input().split()) X.append((-a*10**100 / (a+b), i)) X.sort() print(*[i+1 for x, i in X]) if __name__ == '__main__': N = int(input()) X = [] for i in range(N): a, b = map...
ConDefects/ConDefects/Code/abc308_c/Python/46192113
condefects-python_data_743
import sys n = int(input()) ans = [] for i in range(1, n + 1): a, b = map(int, sys.stdin.readline().strip().split()) sum = a + b res = a / (sum) ans.append([res, -i]) ans.sort(reverse = True) for i in range (0, len(ans)): print(-ans[i][1], end = " ") import sys n = int(input()) ans = [] for i in range(1, n + 1...
ConDefects/ConDefects/Code/abc308_c/Python/45936707
condefects-python_data_744
N = int(input()) L = [] for i in range(N): A, B = map(int, input().split()) L.append(((A*10**100)/(A+B), -i)) L.sort(reverse=True) for i, j in L: print(-j+1, end=' ') print() N = int(input()) L = [] for i in range(N): A, B = map(int, input().split()) L.append(((A*10**100)//(A+B), -i)) L.sort(revers...
ConDefects/ConDefects/Code/abc308_c/Python/45973622
condefects-python_data_745
n=int(input()) p=[] for i in range(n): a,b=map(int,input().split()) p.append(((a*(10**100))/(a+b),i+1)) p.sort(reverse=True) l=[] i=0 while i<n: if i<n-1 and p[i][0]==p[i+1][0]: same_n=2 same_p=p[i][0] j=2 while i+j<n and p[i+j][0]==same_p: same_n+=1 ...
ConDefects/ConDefects/Code/abc308_c/Python/45926524
condefects-python_data_746
MOD = 998244353 N, X = map(int, input().split()) dp = [[[0] * (1 << 2 * X - 1) for _ in range(N + 1)] for _ in range(N + 1)] dp[0][0][0] = 1 P = [1] for i in range(N): P.append(P[i] * (i + 1) % MOD) for i in range(1, N + 1): for j in range(i): for bit in range(1 << 2 * X - 1): # i項目を決める ...
ConDefects/ConDefects/Code/abc309_g/Python/43412855
condefects-python_data_747
s = input() if s <= "ABC349" and s != "ABC316": print("Yes") else : print("No") s = input() if "ABC001"<= s <= "ABC349" and s != "ABC316": print("Yes") else : print("No")
ConDefects/ConDefects/Code/abc350_a/Python/55133783
condefects-python_data_748
S=input() num=0 if "ABC316"==S: print("No") exit() for x in range(1,350): x=str(x) num=('ABC'+x) if num==S: print("Yes") break else: print("No") S=input() num=0 if "ABC316"==S: print("No") exit() for x in range(1,350): x=str(x).zfill(3) num=('ABC'+x) if num==...
ConDefects/ConDefects/Code/abc350_a/Python/54997297
condefects-python_data_749
print("YNeos"[(k:=int(input()[3:]))==316or k>349::2]) print("YNeos"[(k:=int(input()[3:]))==316or k>349or 1>k::2])
ConDefects/ConDefects/Code/abc350_a/Python/54957000
condefects-python_data_750
s = input() if len(s)== 6 and int(s[3:]) < 350 and int(s[3:]) != 316 : print("Yes") else : print("No") s = input() if int(s[3:]) > 0 and int(s[3:]) < 350 and int(s[3:]) != 316 : print("Yes") else : print("No")
ConDefects/ConDefects/Code/abc350_a/Python/54956876
condefects-python_data_751
S = input() K = 0 A = ["0", "1", "2", "3", "4"] if S == "ABC316" or "ABC000": K = 0 else: if S[3] == "3": for a in A: if S[4] == a: K = 1 break else: for a in A[:3]: if S[3] == a: K = 1 break print("Yes" if K == 1 else "No") S = input() K = 0 A = ["0", "1", "...
ConDefects/ConDefects/Code/abc350_a/Python/54976927
condefects-python_data_752
s = input() a = int(s[3:]) if a != 316 and 0 <= a < 350 : print('Yes') else : print('No') s = input() a = int(s[3:]) if a != 316 and 0 < a < 350 : print('Yes') else : print('No')
ConDefects/ConDefects/Code/abc350_a/Python/55028923
condefects-python_data_753
s = input() num = int(s[3:6]) if num > 349: print("No") elif num == 316: print("No") elif s[0:3] != "ABC": print("No") else: print("Yes") s = input() num = int(s[3:6]) if num > 349: print("No") elif num == 316: print("No") elif num < 1: print("No") else: print("Yes")
ConDefects/ConDefects/Code/abc350_a/Python/55141825
condefects-python_data_754
s = input() memo = int(s[3])*100+int(s[4])*10+int(s[5]) if memo>=0 and memo<=349 and memo!=316: print("Yes") else: print("No") s = input() memo = int(s[3])*100+int(s[4])*10+int(s[5]) if memo>0 and memo<=349 and memo!=316: print("Yes") else: print("No")
ConDefects/ConDefects/Code/abc350_a/Python/54950052
condefects-python_data_755
s=input() t=int(s[3:]) if t==316 or t>349: print("No") else: print("Yes") s=input() t=int(s[3:]) if t==316 or t>349 or t<=0: print("No") else: print("Yes")
ConDefects/ConDefects/Code/abc350_a/Python/54908916
condefects-python_data_756
c = int(input()[3:]) print("yes" if (c < 350 and c != 0 and c != 316) else "No") c = int(input()[3:]) print("Yes" if (0 < c < 350 and c != 316) else "No")
ConDefects/ConDefects/Code/abc350_a/Python/54959358
condefects-python_data_757
S = input() s = S[3:] n = int(s) if n > 349: print("No") elif n == 316: print("No") else: print("Yes") S = input() s = S[3:] n = int(s) if n > 349: print("No") elif n == 0: print("No") elif n == 316: print("No") else: print("Yes")
ConDefects/ConDefects/Code/abc350_a/Python/54895381
condefects-python_data_758
import sys S = sys.stdin.read().strip() if int(S[-3:]) <=349 and int(S[-3:]) != 316: print("Yes") else: print("No") import sys S = sys.stdin.read().strip() if 1 <= int(S[-3:]) <=349 and int(S[-3:]) != 316: print("Yes") else: print("No")
ConDefects/ConDefects/Code/abc350_a/Python/54996500
condefects-python_data_759
S = input() s = int(S[3:]) print('Yes' if 350 - s > 0 and s != 316 else 'No') S = input() s = int(S[3:]) print('Yes' if 350 > 350 - s > 0 and s != 316 else 'No')
ConDefects/ConDefects/Code/abc350_a/Python/55040537
condefects-python_data_760
S = int(input()[3:6]) if S != 316 and S < 350: print("Yes") else: print("No") S = int(input()[3:6]) if S != 316 and S!= 0 and S < 350: print("Yes") else: print("No")
ConDefects/ConDefects/Code/abc350_a/Python/55009759
condefects-python_data_761
s = input() s = s.replace("ABC","") if int(s) ==316: print("No") elif 000 <= int(s) <= 349: print("Yes") else: print("No") s = input() s = s.replace("ABC","") if int(s) ==316: print("No") elif 1 <= int(s) <= 349: print("Yes") else: print("No")
ConDefects/ConDefects/Code/abc350_a/Python/55042592
condefects-python_data_762
S = input() if int(S[3:]) == 316 or int(S[3:]) > 349: print("No") else: print("Yes") S = input() if int(S[3:]) == 316 or int(S[3:]) > 349 or int(S[3:]) == 0: print("No") else: print("Yes")
ConDefects/ConDefects/Code/abc350_a/Python/54971919
condefects-python_data_763
T = int(input()) LR = [list(input().split()) for _ in range(T)] def F(l, r): if len(l) == len(r): return int(r) - int(l) + 1 elif r[0] == "1": return int(r) - max(int(r[1:]), int(l), int(r)//10) else: return int(r) - 10**(len(r)-1) + 1 for l, r in LR: print(F(l, r)) T = int...
ConDefects/ConDefects/Code/agc057_a/Python/36403213
condefects-python_data_764
from sys import stdin T = int(input()) for i in range(T): L,R = [x for x in stdin.readline().rstrip().split()] x = len(L) y = len(R) if(x == y): print(int(R)-int(L)+1) elif(R[0]!="1"): print(int(R)-10**(y-1)+1) else: flag = True j = 0 while j+1 < y: ...
ConDefects/ConDefects/Code/agc057_a/Python/39108897
condefects-python_data_765
from collections import defaultdict, deque, Counter import copy from itertools import combinations, permutations, product, accumulate, groupby, chain from heapq import heapify, heappop, heappush import math import bisect from pprint import pprint from random import randint import sys # sys.setrecursionlimit(700000) inp...
ConDefects/ConDefects/Code/agc057_a/Python/43754109
condefects-python_data_766
#ABC057A Antichain of Integer Strings ''' 前哨戦。 いや、なんだこれ、難しすぎるだろ。 下の桁ほど不利っぽいな。L,R=1,100 のとき、A={3}を選んでしまうと3のつく整数全滅だし。 逆に上の桁は貪欲してよかったりする? どう考えても数字の大きいものから貪欲に決定するかんじ。 R = 32451 として考えると 10000 - 32451 は貪欲に採用できそう。 ああでも19999 を使っているから9999が採用できないか。それはかわいそうだ。 ・・・いや、いうて10000 - 19999 を全採用できるほうが嬉しいから、それでいいのか。 R = 12451 のときは? 100...
ConDefects/ConDefects/Code/agc057_a/Python/41587952
condefects-python_data_767
T = int(input()) for _ in range(T): l,r = input().split() l = int(l) if r=="1": print(0) else: if r[0]=="1": a = int(r[:-1]) b = int(r[1:]) r0 = max(a,b)+1 else: r0 = int("1"+"0"*(len(r)-1)) r = int(r) if l<=r0: ...
ConDefects/ConDefects/Code/agc057_a/Python/35335100
condefects-python_data_768
N = int(input()) A = list(map(int,input().split())) W = list(map(int,input().split())) flg = [-1]*(N) cost = 0 for i in range(N): if flg[A[i]-1] == -1: flg[A[i]-1] = W[i] continue cost += min(flg[A[i]-1],W[i]) flg[A[i]-1] = min(flg[A[i]-1],W[i]) print(cost) N = int(input()) A = list(map(int,input().split...
ConDefects/ConDefects/Code/abc360_c/Python/55149622
condefects-python_data_769
# [l, r)のうち値[x, y]のみを使って作れるLISの長さを返す def f(l, r, x, y): if (l, r, x, y) in memory: return memory[(l, r, x, y)] if l >= r: memory[(l, r, x, y)] = 0 return 0 if x > y: memory[(l, r, x, y)] = 0 return 0 ret = 0 #A[l]を使わない ret = max(ret, f(l + 1, r, x, y)) ...
ConDefects/ConDefects/Code/abc262_g/Python/33776994
condefects-python_data_770
import sys input = sys.stdin.readline N,M=map(int,input().split()) LR=[list(map(int,input().split())) for i in range(M)] S=[[0]*505 for i in range(505)] for l,r in LR: S[l][r]+=1 for i in range(1,505): for j in range(505): S[i][j]+=S[i-1][j] for i in range(505): for j in range(1,505): ...
ConDefects/ConDefects/Code/arc168_d/Python/47791112
condefects-python_data_771
a_s = [] while True: a = int(input()) if a == 0: break a_s.append(a) for a in reversed(a_s): print(a) a_s = [] while True: a = int(input()) a_s.append(a) if a == 0: break for a in reversed(a_s): print(a)
ConDefects/ConDefects/Code/abc344_b/Python/54708796
condefects-python_data_772
a = [] while True: i = int(input()) a.append(i) if i == 0: break a.sort() print(*a,sep='\n') a = [] while True: i = int(input()) a.append(i) if i == 0: break a.reverse() print(*a,sep='\n')
ConDefects/ConDefects/Code/abc344_b/Python/54684544
condefects-python_data_773
import sys array = [] for i in sys.stdin.readlines(): array.append(int(i.rstrip())) array.sort() for i in array: print(i) import sys array = [] for i in sys.stdin.readlines(): array.append(int(i.rstrip())) array.reverse() for i in array: print(i)
ConDefects/ConDefects/Code/abc344_b/Python/54781147
condefects-python_data_774
from atcoder.maxflow import MFGraph INF = 1 << 60 N, M = map(int, input().split()) g = MFGraph(N * 2) for _ in range(M): A, B = map(lambda x: int(x)-1, input().split()) g.add_edge(A+N, B, INF) # A_out -> B_in g.add_edge(B+N, A, INF) # B_out -> A_in C = list(map(int, input().split())) for i, c in enumera...
ConDefects/ConDefects/Code/abc239_g/Python/45950802
condefects-python_data_775
#ABC290-D import math T = int(input()) for _ in range(T): N, D, K = map(int, input().split()) K -= 1 #0-indexedに直す x = N//math.gcd(N, D) #何周期目か i = K//x #何番目か j = K%x print(((D+i)*j)%N) #ABC290-D import math T = int(input()) for _ in range(T): N, D, K = map(int, input().split()...
ConDefects/ConDefects/Code/abc290_d/Python/46020741
condefects-python_data_776
import math T=int(input()) for _ in range(T): N,D,K=map(int,input().split()) gcd=math.gcd(N,D) if gcd==1: answer=(D*(K-1))%N else: d=D//gcd n=N//gcd answer=((((K-1)%n)*d%N)*gcd+(K-1)//n)%n print(answer) import math T=int(input()) for _ in range(T): N,D,K=map(in...
ConDefects/ConDefects/Code/abc290_d/Python/45988606
condefects-python_data_777
from math import log10 n,m = map(int, input().split()) mketa = int(log10(m))+1 if m % 2 == 0: numli = [8] elif m % 5 == 0: numli = [5] else: numli = [9,7] xli = [] for num in numli: # resunit = num % m keta = mketa tempx = int(str(num) * keta) res = tempx % m resunit = (num * pow(...
ConDefects/ConDefects/Code/arc149_a/Python/42835406
condefects-python_data_778
def main(): from collections import deque,defaultdict import itertools from math import gcd import sys,heapq,bisect sys.setrecursionlimit(10**6) readline=sys.stdin.readline MOD=998244353 INF=10**15 N,M=list(map(int, readline().split())) #10^3未満の数->999,998, l=[0,0]#num,length ...
ConDefects/ConDefects/Code/arc149_a/Python/43012792
condefects-python_data_779
from collections import Counter import sys input = sys.stdin.readline sys.setrecursionlimit(10**9) def solve(): INF = 10**9 N, M = map(int, input().split()) ABs = [tuple(map(int, input().split())) for _ in range(N)] sumA = sum([A for A, B in ABs]) #print('# sumA:', sumA) diffs = [B-A for A, ...
ConDefects/ConDefects/Code/abc269_g/Python/35978955
condefects-python_data_780
n,m=map(int,input().split()) s=0 d={} for i in range(n): a,b=map(int,input().split()) s+=a if b-a not in d: d[b-a]=0 d[b-a]+=1 p=[] for dd in d: pp=1 while pp<=d[dd]: p.append((dd,pp)) d[dd]-=pp pp*=2 if d[dd]>0: p.append((dd,d[dd])) q=[n+1]*(m+1) q[s]=0 for dd,pp in p: nq=[n+1]*(m+1...
ConDefects/ConDefects/Code/abc269_g/Python/43509672
condefects-python_data_781
N = int(input()) P = list(map(int, input().split())) cur_cost = 0 cur_slope = 0 slope_diff = [0]*N for i in range(N): # 料理 P[i] は位置 P[i] にあってほしいが,現在位置 i にある cur_cost += min((P[i] - i) % N, (i - P[i]) % N) if N % 2 == 1: if 0 < (P[i] - i) % N <= N//2: cur_slope -= 1 elif (P[i] ...
ConDefects/ConDefects/Code/abc268_e/Python/46052240
condefects-python_data_782
N = int(input()) m = [0]*N p = [*map(int,input().split())] for n in range(N): m[(p[n]-n)%N]+=1 mid = N//2+N%2 fnsum,lnsum = sum(m[n] for n in range(mid)),sum(m[n] for n in range(mid,N)) fsum,lsum = sum(m[n]*n for n in range(mid)),sum(m[n]*(N-n) for n in range(mid,N)) ans = fsum+lsum for n in range(N-1): fsum = ...
ConDefects/ConDefects/Code/abc268_e/Python/46000676
condefects-python_data_783
from collections import defaultdict N = int(input()) p = list(map(int,input().split())) ans = [0] * N for i in range(N): ans[0] += min((p[i]-i)%N, (i-p[i])%N) diff = 0 change = defaultdict(int) if N & 1: for i in range(N): x = (p[i]-i) % N change[(N//2 - x - 1) % N] -= 1 change[(N//2 ...
ConDefects/ConDefects/Code/abc268_e/Python/45307852
condefects-python_data_784
def solve_sub(n, a, b, c, p_list): if n == 1: return "Yes" if c % 2 == 1: return "No" depth = [0] * n is_leaf = [1] * n parents = [0] * n children = [[] for _ in range(n)] for i, p in enumerate(p_list): depth[i + 1] = depth[p - 1] + 1 is_leaf[p - 1] = 0 ...
ConDefects/ConDefects/Code/arc157_e/Python/39201856
condefects-python_data_785
n=int(input()) print('YNeos'[n<-2**31 or n>2**31::2]) n=int(input()) print('YNeos'[n<-2**31 or n>=2**31::2])
ConDefects/ConDefects/Code/abc237_a/Python/45125955
condefects-python_data_786
N=int(input()) if -2**31<N<2**31: print("Yes") else: print("No") N=int(input()) if -2**31<=N<2**31: print("Yes") else: print("No")
ConDefects/ConDefects/Code/abc237_a/Python/45710805
condefects-python_data_787
print("Yes" if (a:=int(input()))<4294967296 and a>=-4294967296 else "No") print("Yes" if (a:=int(input()))<(1<<31) and a>=-(1<<31) else "No")
ConDefects/ConDefects/Code/abc237_a/Python/45267148
condefects-python_data_788
N=int(input()) print("Yes" if -2**31<=N<=2**31 else "No") N=int(input()) print("Yes" if -2**31<=N<2**31 else "No")
ConDefects/ConDefects/Code/abc237_a/Python/46166262
condefects-python_data_789
n, q = map(int, input().split()) record = [(i, 0) for i in reversed(range(1,n+1))] dict = {"R":(-1,0), "L":(1,0), "U":(0,1), "D":(0,-1)} for i in range(q): select, part = input().split() if select == "1": x,y = record[-1] dx, dy = dict[part] record.append((x+dx, y+dy)) else: ...
ConDefects/ConDefects/Code/abc335_c/Python/54505569
condefects-python_data_790
s=input().split() n=int(s[0]) a=[[n-i,0] for i in range(n)] q=int(s[1]) str="LURD" d=[1,0,-1,0] for _ in range(q): s=input().split() if s[0]=='1': a.append([a[-1][0]+d[str.index(s[1])],a[-1][1]+d[str.index(s[1])-1]]) else: print(a[-int(s[1])][0],a[-int(s[1])][1]) s=input().split() n=int(s[0]) a=[[n-i,0] ...
ConDefects/ConDefects/Code/abc335_c/Python/54761839
condefects-python_data_791
class SegmentTree: def __init__(self, a): self.padding = 0 self.n = len(a) self.N = 2 ** (self.n-1).bit_length() self.seg_data = [self.padding]*(self.N-1) + a + [self.padding]*(self.N-self.n) for i in range(2*self.N-2, 0, -2): self.seg_data[(i-1)//2] = self.seg_da...
ConDefects/ConDefects/Code/abc356_f/Python/54283471
condefects-python_data_792
import sys input = sys.stdin.readline # https://github.com/tatyam-prime/SortedSet/blob/main/SortedSet.py import math from bisect import bisect_left, bisect_right from typing import Generic, Iterable, Iterator, TypeVar, Union, List T = TypeVar('T') class SortedSet(Generic[T]): BUCKET_RATIO = 50 REBUILD_RATIO...
ConDefects/ConDefects/Code/abc356_f/Python/54486041
condefects-python_data_793
from functools import lru_cache from math import inf, ceil def read_ints(): return [int(x) for x in input().split(' ')] def slv(): s=input() K=int(input()) n=len(s) @lru_cache(None) def dfs(i,j): if j<i:return 0 if j==i:return 1 res=j-i+1 if s[i]=='o': ...
ConDefects/ConDefects/Code/abc325_g/Python/46914169
condefects-python_data_794
s = input() k = int(input()) n = len(s) dp = [[0] * (n + 1) for _ in range(n + 1)] for length in range(1, n + 1): for l in range(n - length + 1): r = l + length mi = length for mid in range(l + 1, r): mi = min(mi, dp[l][mid] + dp[mid][r]) if s[l] == 'o': for...
ConDefects/ConDefects/Code/abc325_g/Python/47132370
condefects-python_data_795
s=input() n=len(s) x=int(input()) q=[[0]*n for i in range(n)] for i in range(1,n+1): for j in range(n): l=j r=j+i-1 if not (0<=l<=r<n): break q[l][r]=r-l+1 for k in range(l,r): q[l][r]=min(q[l][r],q[l][k]+q[k+1][r]) if s[l]=="o": for k in range(l+1,r+1): if s[k]=="f" ...
ConDefects/ConDefects/Code/abc325_g/Python/46924310
condefects-python_data_796
t=int(input()) for i in range(t): a,b,c=map(int,input().split()) p=(a+b+c)/3 if p.is_integer(): d=(abs(a-p)+abs(b-p)+abs(c-p))//4 print(int(d)) else: print(-1) t=int(input()) for i in range(t): a,b,c=map(int,input().split()) p=(a+b+c)/3 if p.is_integer() and (a-b)%2==0 and (b-c)%2==0 and (c-a...
ConDefects/ConDefects/Code/arc158_a/Python/43732374
condefects-python_data_797
T = int(input()) for i in range(T): x1,x2,x3 = map(int,input().split()) #a > b > c a = max(x1,x2,x3) c = min(x1,x2,x3) b = x1+x2+x3-a-c if not(a % 6 == b % 6 == c % 6): print(-1) continue ans = 0 if a - b > b - c: ans = (b - c) // 2 else: ans = (a ...
ConDefects/ConDefects/Code/arc158_a/Python/45550808
condefects-python_data_798
T = int(input()) for i in range(T): x1, x2, x3 = map(int, input().split()) S = x1+x2+x3 if S % 3 == 0: D = abs(S//3-x1) + abs(S//3-x2) + abs(S//3-x3) print(D//4) else: print(-1) T = int(input()) for i in range(T): x1, x2, x3 = map(int, input().split()) S = x1+x2+x3 ...
ConDefects/ConDefects/Code/arc158_a/Python/43216127
condefects-python_data_799
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def solve(L): if sum(L) % 3: return -1 num = sum(L) // 3 tmp1 = 0 tmp2 = 0 for x in L: if x - num < 0: tmp1 += (num - x) // 2 else: tmp2 += (x - num...
ConDefects/ConDefects/Code/arc158_a/Python/42775332
condefects-python_data_800
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/54658079