id
stringlengths
24
27
content
stringlengths
37
384k
max_stars_repo_path
stringlengths
51
51
condefects-python_data_601
t = int(input()) for i in range(t): n, k = map(int, input().split()) if n % 2 != k % 2 or n < k: print("No") else: pre = n count = 0 while True: count = pre % 3 pre = pre // 3 if pre < 3: count += pre ...
ConDefects/ConDefects/Code/arc164_a/Python/45658155
condefects-python_data_602
# 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/arc164_a/Python/45556032
condefects-python_data_603
def dt(n): if n == 0: return 0 ternary = 0 while n > 0: remainder = n % 3 ternary+=remainder n //= 3 return ternary tc = int(input()) for _ in range(tc): n,k = map(int, input().split()) print("Yes" if dt(n) <= k and k<=n else "No") def dt(n): if n == 0: return 0 ternary...
ConDefects/ConDefects/Code/arc164_a/Python/45492377
condefects-python_data_604
T = int(input()) for _ in range(T): N, K = map(int, input().split()) while N > 0: K -= N % 3 N //= 3 if K >=0: print("Yes") else: print("No") T = int(input()) for _ in range(T): N, K = map(int, input().split()) while N > 0: K -= N % 3 N //= 3 ...
ConDefects/ConDefects/Code/arc164_a/Python/45000515
condefects-python_data_605
def recur(n): x=0 for i in range(28,-1,-1): p=pow(3,i) x += n // p n-=p*(n//p) return x def solve(): n,k=map(int,input().split()) x=recur(n) if x>k or k%2!=n%2: print("No") else: print("Yes") for i in range(int(input())): solve() def re...
ConDefects/ConDefects/Code/arc164_a/Python/45705547
condefects-python_data_606
T=int(input()) for i in range(T): ternary=[] N,K=map(int,input().split()) N2=N while N2>0: ternary.append(N2%3) N2//=3 print(ternary) print(sum(ternary)) if N%2!=K%2: print("No") else: if K<sum(ternary): print("No") else: pr...
ConDefects/ConDefects/Code/arc164_a/Python/45247627
condefects-python_data_607
#ARC164A def I(): return int(input()) def LI(): return list(map(int,input().split())) def RI(): return map(int,input().split()) def DI(): return list(input()) def change(N,shinsu): keta=0 for i in range(10**9): if N<shinsu**i: keta+=i break ans=[0]*keta check=0 fo...
ConDefects/ConDefects/Code/arc164_a/Python/45533632
condefects-python_data_608
t = int(input()) for i in range(t): n, k = map(int, input().split()) l = 0 for i in range(12): l += (n // 3**i) % 3 if k >= l and (k - l) % 2 == 0: print("Yes") else: print("No") t = int(input()) for i in range(t): n, k = map(int, input().split()) l = 0 for i in...
ConDefects/ConDefects/Code/arc164_a/Python/46191198
condefects-python_data_609
# 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 # from datetime import * # from decimal import * # PyPyだと遅い # from string import ascii_lowercase,ascii...
ConDefects/ConDefects/Code/arc164_a/Python/45517397
condefects-python_data_610
N = int(input()) S = input() Q = int(input()) TXC = [[i for i in input().split()] for _ in range(Q)] isupper = -1 islower = -1 lastmodified = [-1]*N li = [c for c in S] for i, (t,x,c) in enumerate(TXC): t = int(t) if t == 1: x = int(x) li[x-1] = c lastmodified[x-1] = i elif t == 2: ...
ConDefects/ConDefects/Code/abc314_d/Python/46143343
condefects-python_data_611
if __name__ == '__main__': N = int(input()) S = input() Q = int(input()) flg = 1 d = dict() query = [] last = 0 for i in range(Q): t, x, c = input().split() query.append([t, x, c]) if t == '2': flg = 2 last = i elif t == '3': ...
ConDefects/ConDefects/Code/abc314_d/Python/46146276
condefects-python_data_612
N = int(input()) T = [list(map(int,input().split())) for _ in range(N)] L = [t[0] for t in T] R = [t[1] for t in T] L.sort(reverse=True) R.sort() ans = 0 for i in range(N): if L[i] > R[i]: ans += (L[i]-R[i])*(N-1) print(ans) N = int(input()) T = [list(map(int,input().split())) for _ in range(N)] L = [t...
ConDefects/ConDefects/Code/arc147_c/Python/43399411
condefects-python_data_613
n = int(input()) l,r = zip(*[list(map(int,input().split())) for i in range(n)]) l = list(l) r = list(r) l.sort(reverse=True) r.sort() ans = 0 for i in range(n): ans += max(0,l[i]-r[i])*(n-i-1) print(ans) n = int(input()) l,r = zip(*[list(map(int,input().split())) for i in range(n)]) l = list(l) r = list(r) l.sort(re...
ConDefects/ConDefects/Code/arc147_c/Python/41820301
condefects-python_data_614
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 import random n = ii() a = li() def solve(n, a, p): ans = [] for i in range(random.randint(0, p)): p = list(range(1, n + 1)) ...
ConDefects/ConDefects/Code/arc159_c/Python/40556226
condefects-python_data_615
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 SegTree: def __init__(self, n, o...
ConDefects/ConDefects/Code/abc353_g/Python/53993648
condefects-python_data_616
#2 3 3 4 #素数列挙 def prime(N): primes = [] for i in range(2, N + 1): primes.append(i) for p in range(2, i): if i % p == 0: primes.remove(i) break return primes setx=set(prime(100)) A,B,C,D=map(int,input().split()) for i in range(A,B+1): q=True ...
ConDefects/ConDefects/Code/abc239_d/Python/52953499
condefects-python_data_617
primes=[] for i in range(2,101): for j in range(2,i): if i%j==0: break else: primes.append(i) a,b,c,d=map(int,input().split()) for i in range(a,b+1): for j in range(c,d+1): if i+j in primes: break if j==d: print('Takahashi') e...
ConDefects/ConDefects/Code/abc239_d/Python/54197752
condefects-python_data_618
from more_itertools import* a,b,c,d=map(int,input().split()) s={*sieve(205)} ans=0 for i in range(a,b+1): t=1 for j in range(c,d+1): if i+j in s: t=0 ans|=t if t: print('Takahashi') else: print('Aoki') from more_itertools import* a,b,c,d=map(int,input().split()) s={*sieve(205)} ans=0 for i in range...
ConDefects/ConDefects/Code/abc239_d/Python/54694563
condefects-python_data_619
from atcoder.modint import ModContext, Modint MOD = 998244353 ModContext.context.append(MOD) Modint.__repr__ = lambda x: repr(x._v) A, B = map(int, input().split()) def factorization(N): from collections import defaultdict res = defaultdict(int) x = N y = 2 while y*y <= x: while x%y == 0: ...
ConDefects/ConDefects/Code/arc167_b/Python/49611980
condefects-python_data_620
def prime_factorize(N): # 答えを表す可変長配列 res = {} # √N まで試し割っていく for p in range(2, N): # p * p <= N の範囲でよい if p * p > N: break # N が p で割り切れないならばスキップ if N % p != 0: continue # N の素因数 p に対する指数を求める e = 0 while N % p == 0: ...
ConDefects/ConDefects/Code/arc167_b/Python/51380686
condefects-python_data_621
A, B = map(int, input().split()) degrees = [] at = 2 while at * at <= A: if A % at == 0: cnt = 0 while A % at == 0: cnt += 1 A //= at degrees.append(cnt) at += 1 if A != 1: degrees.append(1) # print(*degrees) new_degrees = [] for el in degrees: new_degrees...
ConDefects/ConDefects/Code/arc167_b/Python/50502972
condefects-python_data_622
a, b = map(int, input().split()) md = 998244353 def inv(num): mo=998244353 return pow(num, mo-2, mo) def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i...
ConDefects/ConDefects/Code/arc167_b/Python/55110212
condefects-python_data_623
a, b = map(int, input().split()) i = 2 c = [] while i * i <= a: if a % i == 0: t = 0 while a % i == 0: t += 1 a //= i c.append(t) i += 1 if a > 1: c.append(1) M = 998244353 res = 1 for i in c: res = res * (i * b + 1) % M res = res * b % M res = res * (M...
ConDefects/ConDefects/Code/arc167_b/Python/52183821
condefects-python_data_624
def ip():return int(input()) def mp():return map(int, input().split()) def lmp():return list(map(int, input().split())) # ABC251 D 1463 - At Most 3 (Contestant ver.) # 整数 W が与えられます。 # あなたは以下の条件をすべて満たすようにいくつかのおもりを用意することにしました。 # ・おもりの個数は 1 個以上 300 個以下である。 # ・おもりの重さは 10^6 以下の正整数である。 # ・1 以上 W 以下のすべての正整数は 良い整数 である。ここで、以下の条...
ConDefects/ConDefects/Code/abc251_d/Python/46009389
condefects-python_data_625
w=int(input()) print(299) A=[i for i in range(1,100)]+[100*i for i in range(1,100)]+[10000*i for i in range(1,101)] print(*A) w=int(input()) print(298) A=[i for i in range(1,100)]+[100*i for i in range(1,100)]+[10000*i for i in range(1,101)] print(*A)
ConDefects/ConDefects/Code/abc251_d/Python/44691668
condefects-python_data_626
import sys import copy from collections import deque,defaultdict import math import heapq from itertools import accumulate import itertools from functools import reduce #import pypyjit #pypyjit.set_param('max_unroll_recursion=-1') sys.setrecursionlimit(10**8) mod = 10**9 + 7 INF = math.inf input = lambda: sys.stdin.re...
ConDefects/ConDefects/Code/abc251_d/Python/45210558
condefects-python_data_627
import sys input = sys.stdin.readline def ip():return int(input()) def mp():return map(int, input().split()) def lmp():return list(map(int, input().split())) # ABC251 D 1463 - At Most 3 (Contestant ver.) W = ip() A = [] for i in range(1, 101): A.append(1 + i) A.append(100 * i) A.append(10000 * i) print(300)...
ConDefects/ConDefects/Code/abc251_d/Python/44700899
condefects-python_data_628
H, W, N = map(int,input().split()) grid = [] for i in range(H): grid.append(["."] * W) i = 0 j = 0 p = 0 h = [[0,-1],[1,0],[0,1],[-1,0]] for k in range(N): if grid[i][j] == ".": grid[i][j] = "#" # 時計まわり p = (p+1) % 4 elif grid[i][j] == "#": grid[i][j] = "." # 半時計...
ConDefects/ConDefects/Code/abc339_b/Python/54311169
condefects-python_data_629
import sys;sys.setrecursionlimit(100000000) H,W,N=map(int,sys.stdin.readline().split()) grid=[["."]*W for i in range(H)] directions=((-1,0),(0,1),(1,0),(0,-1)) dirNum=0 x=0 y=0 for i in range(N): if grid[y][x]==".": grid[y][x]="#" dirNum+=1 y+=directions[dirNum%4][0] x+=directions[di...
ConDefects/ConDefects/Code/abc339_b/Python/54672032
condefects-python_data_630
import cProfile import math import sys import io import os import traceback from bisect import bisect_left, bisect_right from collections import deque from functools import lru_cache from itertools import accumulate # region IO BUFSIZE = 8192 class FastIO(io.IOBase): newlines = 0 def __init__(self, file): ...
ConDefects/ConDefects/Code/abc237_f/Python/35962547
condefects-python_data_631
def rint(): return list(map(int, input().split())) H, W = rint() S = [[a for a in rint()] for _ in range(H)] G = [[i*W+j+1 for j in range(W)] for i in range(H)] # print(G) def op(A, x,y): for i in range(H-1): for j in range(W-1): if i*W+j > (H-1)*(W-1)//2: return ...
ConDefects/ConDefects/Code/abc336_f/Python/54952831
condefects-python_data_632
N = int(input()) if N < 10: print("AGC00" + str(N)) elif N >= 42 : A = N + 1 print("AGC0" + str(A)) N = int(input()) if N < 10: print("AGC00" + str(N)) elif 10 <= N < 42: print("AGC0" + str(N)) elif N >= 42 : A = N + 1 print("AGC0" + str(A))
ConDefects/ConDefects/Code/abc230_a/Python/44422973
condefects-python_data_633
N = int(input()) if N >= 43: print(f"AGC{N+1:03}") else : print(f"AGC{N:03}") N = int(input()) if N >= 42: print(f"AGC{N+1:03}") else : print(f"AGC{N:03}")
ConDefects/ConDefects/Code/abc230_a/Python/45743291
condefects-python_data_634
N = int(input()) if N > 42: N += 1 if N < 10: z = 2 else: z = 1 print('AGC'+ '0' * z + str(N)) N = int(input()) if N >= 42: N += 1 if N < 10: z = 2 else: z = 1 print('AGC'+ '0' * z + str(N))
ConDefects/ConDefects/Code/abc230_a/Python/44349986
condefects-python_data_635
N = int(input()) print(f"AGC{N+1}" if N > 41 else f"AGC{N}") N = int(input()) print(f"AGC{str(N+1).zfill(3)}" if N > 41 else f"AGC{str(N).zfill(3)}")
ConDefects/ConDefects/Code/abc230_a/Python/45572645
condefects-python_data_636
N = int(input()) if N >= 42: print(f"AGC{N + 1:03}") else: print('AGC' + '0' + str(N)) N = int(input()) if N >= 42: print(f"AGC{N + 1:03}") else: print(f"AGC{N:03}")
ConDefects/ConDefects/Code/abc230_a/Python/44828138
condefects-python_data_637
N=input() if int(N) >=42: Z =(int(N)+1) print("AGC0"+ str(Z)) elif int(N) <10: print("AGC00"+ N) else: print("AGC00"+ N) N=input() if int(N) >=42: Z =(int(N)+1) print("AGC0"+ str(Z)) elif int(N) <10: print("AGC00"+ N) else: print("AGC0"+ N)
ConDefects/ConDefects/Code/abc230_a/Python/45437543
condefects-python_data_638
n = int(input()) x = n if n >= 42: x += 1 print(f"AGC0{x}") n = int(input()) x = n if n >= 42: x += 1 print(f"AGC{x:03}")
ConDefects/ConDefects/Code/abc230_a/Python/45690200
condefects-python_data_639
from collections import Counter from functools import reduce N = int(input()) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: ...
ConDefects/ConDefects/Code/abc292_c/Python/45536157
condefects-python_data_640
# https://qiita.com/LorseKudos/items/9eb560494862c8b4eb56 # https://note.com/kai1023/n/naf4e2ef6f88d # https://techmath-project.com/2023/03/05/abc292/#C_%E2%80%93_Four_Variables N = int(input()) def make_divisors(i): cnt = 0 for range_num in range(1,int(i **0.5)+1): if i % range_num == 0: ...
ConDefects/ConDefects/Code/abc292_c/Python/45291809
condefects-python_data_641
import sys from collections import defaultdict from typing import TypeVar, Generic, Callable, List T = TypeVar('T') U = TypeVar('U') class LazySegmentTreeInjectable(Generic[T, U]): def __init__(self, n: int, identity_data: Callable[[], T], identity_lazy: Callabl...
ConDefects/ConDefects/Code/abc360_f/Python/55104098
condefects-python_data_642
n=int(input()) z=[0,1] q=[] for i in range(n): l,r=map(int,input().split()) z+=[l,l-1,l+1,r,r-1,r+1] q+=[(l+1,0,l-1,-1),(r,0,l-1,1),(r+1,l+1,r-1,-1)] z=sorted(set(z)) d={v:i for i,v in enumerate(z)} from atcoder import lazysegtree st=lazysegtree.LazySegTree(min,(0,10**10),lambda f,x:(x[0]+f,x[1]),lambda g,f:g+f,0...
ConDefects/ConDefects/Code/abc360_f/Python/55104262
condefects-python_data_643
def main(): # write code here. N = II() LR = LL(N) """ 座圧すべき値は l+1,r,r+1,10**9 """ CAP = 10**9+5 inv = [CAP] for l,r in LR: inv+=[l+1,r,r+1] inv = sorted(set(inv)) D = {e:i for i,e in enumerate(inv)} # x軸で処理内容をソート. event = [] for l,r in LR: ...
ConDefects/ConDefects/Code/abc360_f/Python/55118906
condefects-python_data_644
from atcoder.lazysegtree import LazySegTree from collections import deque N = int(input()) LR = [list(map(int, input().split())) for _ in range(N)] sousa = deque() s = set() s.add(10 ** 9 + 1) s.add(0) for l, r in LR: if r < 10 ** 9: sousa.append([l + 1, r + 1, 10 ** 9 + 1, 1]) s.add(l + 1) s.add(r + 1)...
ConDefects/ConDefects/Code/abc360_f/Python/55105382
condefects-python_data_645
from operator import add import typing import sys input = sys.stdin.readline def main(): N = int(input()) LR = [] Z = {-1, 0, 1} for _ in range(N): l, r = map(int, input().split()) LR.append((l, r)) for d in range(-1, 2): Z.add(l + d) Z.add(r + d) Z = ...
ConDefects/ConDefects/Code/abc360_f/Python/55163164
condefects-python_data_646
A,B=map(int,input().split()) now=min(A,B) x=abs(A-B) ans=0 if A==B: print(A) exit() def make_divisors(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)...
ConDefects/ConDefects/Code/arc159_b/Python/43997330
condefects-python_data_647
import math a, b = map(int, input().split()) if a < b: a, b = b, a ans = 0 while b > 0: g = math.gcd(a, b) a //= g b //= g diff = a - b if diff == 1: ans += b break else: m = float("inf") for i in range(1, int(diff**0.5) + 1): if diff % i == 0: ...
ConDefects/ConDefects/Code/arc159_b/Python/45431609
condefects-python_data_648
S, T = map(str, input().split()) if S == "AtCoder" and T == "Land": print("Yes") else: print("N") S, T = map(str, input().split()) if S == "AtCoder" and T == "Land": print("Yes") else: print("No")
ConDefects/ConDefects/Code/abc358_a/Python/55126932
condefects-python_data_649
s,t=input().split() if s=="Atcoder" and t=="Land": print("Yes") else: print("No") s,t=input().split() if s=="AtCoder" and t=="Land": print("Yes") else: print("No")
ConDefects/ConDefects/Code/abc358_a/Python/55110270
condefects-python_data_650
S,T = list(input().split()) if S == "Atcoder" and T == "Land": print('Yes') else: print('No') S,T = list(input().split()) if S == "AtCoder" and T == "Land": print('Yes') else: print('No')
ConDefects/ConDefects/Code/abc358_a/Python/55031522
condefects-python_data_651
S,T = input().split() if S == "AtCorder" and T == "Land": print("Yes") else: print("No") S,T = input().split() if S == "AtCoder" and T == "Land": print("Yes") else: print("No")
ConDefects/ConDefects/Code/abc358_a/Python/55146983
condefects-python_data_652
s, t = input().split() if s == 'AtCoder ' and t == 'Land': print('Yes') else: print('No') s, t = input().split() if s == 'AtCoder' and t == 'Land': print('Yes') else: print('No')
ConDefects/ConDefects/Code/abc358_a/Python/55148090
condefects-python_data_653
print("yes" if input() == "AtCoder Land" else "No") print("Yes" if input() == "AtCoder Land" else "No")
ConDefects/ConDefects/Code/abc358_a/Python/55029700
condefects-python_data_654
n = int(input()) mod = 998244353 dp = [[0]*10 for _ in range(n)] for i in range(1, 10): dp[0][i] = 1 for i in range(n): for j in range(1, 10): dp[i][j] += dp[i-1][j] dp[i][j] %= mod if j-1 >= 1: dp[i][j] += dp[i-1][j-1] dp[i][j] %= mod if j+1 <= 9: ...
ConDefects/ConDefects/Code/abc242_c/Python/44896564
condefects-python_data_655
N = int(input()) mod = 998244353 dp = [[0]*11 for _ in range(N)] for i in range(1,10): dp[0][i] = 1 for i in range(N-1): for j in range(1,10): dp[i+1][j] = (dp[i][j-1] + dp[i][j] + dp[i][j+1])%mod for d in dp: print(d) print(sum(dp[-1])%mod) N = int(input()) mod = 998244353 dp = [[0]*11 for _ ...
ConDefects/ConDefects/Code/abc242_c/Python/45475697
condefects-python_data_656
N,M = map(int, input().split()) T0 = [] T1 = [] T2 = [] for i in range(N): t,x = map(int, input().split()) if t==0: T0.append(x) elif t==1: T1.append(x) elif t==2: T2.append(x) T0.sort(reverse=True) T1.sort() T2.sort(reverse=True) import heapq ans = 0 que = T0[:min(len(T1),M)] an...
ConDefects/ConDefects/Code/abc312_f/Python/46140996
condefects-python_data_657
N,M=map(int,input().split()) open_cans=[] closed_cans=[] openers=[] for _ in range(N): T,X=map(int,input().split()) if T==0: open_cans.append(X) elif T==1: closed_cans.append(X) else: openers.append(X) open_cans.sort() closed_cans.sort(reverse=True) openers.sort(reverse=True) l...
ConDefects/ConDefects/Code/abc312_f/Python/46206445
condefects-python_data_658
class Node: def __init__(self, value=""): self.nex = None self.pre = None self.value = value #N = 5 #S = "LRRLR" N = int(input()) S = input() nil = Node() nil.nex = nil nil.pre = nil recent_node = Node(0) recent_node.nex = nil recent_node.pre = nil for i in range(1, N+1): new_node = Node(i) if S[i...
ConDefects/ConDefects/Code/abc237_d/Python/54010383
condefects-python_data_659
from itertools import permutations from collections import defaultdict as dd N,M = map(int,input().split()) S = [input().rstrip() for n in range(N)] T = dd(set) for m in range(M): t = list(input().rstrip()) if t[0]=="_" or t[-1]=="_" : continue key = [] val = [] temp = [t[0]] for i in range(1,le...
ConDefects/ConDefects/Code/abc268_d/Python/45999253
condefects-python_data_660
def ip():return int(input()) def mp():return map(int, input().split()) def lmp():return list(map(int, input().split())) # ABC268 D 1309 - Unique Username # 高橋君はあるサービスで使うユーザー名を決めるのに困っています。彼を助けるプログラムを書いてください。 # 以下の条件をすべて満たす文字列 X を 1 つ求めてください。 # ・X は次の手順で得られる文字列である。 # N 個の文字列 S1,S2,…,SN を好きな順番で並べたものを S1′,S2′,…,SN′ とする。 # ...
ConDefects/ConDefects/Code/abc268_d/Python/46151794
condefects-python_data_661
N,M = map(int, input().split()) l = [input() for i in range(N)] s = set([]) for i in range(M): s.add(input()) pt = [] free = 16 for i in l: free -= len(i) free-=N-1 #print(free) from itertools import permutations per_all = list(permutations(range(N))) per = [] def solve(now,free,le): # print(now,le) le...
ConDefects/ConDefects/Code/abc268_d/Python/46188576
condefects-python_data_662
# 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 impo...
ConDefects/ConDefects/Code/abc268_d/Python/45037018
condefects-python_data_663
from itertools import permutations N, M = map(int, input().split()) S = [input() for _ in range(N)] T = {input() for _ in range(M)} stack = [] def rec(i, rest): if i == N - 1: for p in permutations(list(range(N)), N): res = [] for j in range(N): res.append(S[p[j]]) ...
ConDefects/ConDefects/Code/abc268_d/Python/46033322
condefects-python_data_664
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 import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 ...
ConDefects/ConDefects/Code/abc268_d/Python/45791112
condefects-python_data_665
n,m=map(int,input().split()) s=[input() for _ in range(n)] t={input() for _ in range(m)} all=0 for i in range(n): all+=len(s[i]) und=16-all-(n-1) add=[] def dfs1(i,L): if i==n: global add add+=[L[:]] else: for j in range(n): if L[j]==-1: L[j]=i ...
ConDefects/ConDefects/Code/abc268_d/Python/45092436
condefects-python_data_666
from itertools import permutations N,M = map(int,input().split()) S = [input().rstrip() for n in range(N)] T = set([input().rstrip() for m in range(M)]) def recc(surp): for i in range(surp+1): temp.append(i) if len(temp)<N-1 : recc(surp-i) else : ans = "" ...
ConDefects/ConDefects/Code/abc268_d/Python/45999403
condefects-python_data_667
import numpy as np N,X,Y=map(int,input().split()) C=input() Mod=998244353 def ABmodC(A,B,C): b=bin(B)[2:] a=[A] for i in range(len(b)-1): a.append((a[-1]**2)%C) d=1 for i in range(len(b)): if b[-i-1]=='1': d=(d*a[i])%C return d Xa=(X*ABmodC(100,Mod-2,Mod))%Mod Ya=(Y*...
ConDefects/ConDefects/Code/abc271_g/Python/37700812
condefects-python_data_668
#from collections import defaultdict #d = defaultdict(int) #from collections import deque #import math #import heapq #from queue import Queue import numpy as np #Mo=998244353 #s=input() n=int(input()) #l,r = list(input().split()) a=list(map(int, input().split())) #a= [int(input()) for _ in range(n)] c=0 for i in rang...
ConDefects/ConDefects/Code/arc132_b/Python/44219174
condefects-python_data_669
import sys input = sys.stdin.readline inf = float('inf') def getInt(): return int(input()) def getStr(): return input().strip() def getList(dtype=int, split=True): s = getStr() if split: s = s.split() return list(map(dtype, s)) t = 1 def solve(): n = getInt() a = getList() ...
ConDefects/ConDefects/Code/arc132_b/Python/40304207
condefects-python_data_670
N = int(input()) P = list(map(int, input().split())) if P[0] == 1: if P[1] == 2: print(0) else: print(2) elif P[-1] == 1: if P[-2] == 2: print(1) else: print(3) else: idx = P.index(1) if P[idx+1] == 2: print(min(idx, N-idx+2)) # 1を先頭に持ってくる else: ...
ConDefects/ConDefects/Code/arc132_b/Python/41870393
condefects-python_data_671
N = int(input()) P = list(map(int, input().split())) if P[0] == 1 and P[1] == 2: print(0) exit() if P[-1] == 1 and P[-2] == 2: print(1) exit() if P[0] == 1 and P[1] != 2: print(2) exit() if P[-1] == 1 and P[-2] != 2: print(3) exit() a = P.index(1) #print(*[i for i in range(N)]) #print(*...
ConDefects/ConDefects/Code/arc132_b/Python/40278857
condefects-python_data_672
n = int(input()) a = list(map(int, input().split())) b = [a[0]] for i in range(n-1): if abs(a[i+1]-a[i]) != 1: break b.append(a[i+1]) if b == [1]: print(2) elif b[1] > b[0]: if len(b) == n: print(0) else: print(min(len(b),n-len(b)+2)) else: if len(b) == n: print(1) else: print(min(len(b)+1,n-len(b)...
ConDefects/ConDefects/Code/arc132_b/Python/38109909
condefects-python_data_673
N = int(input()) P = list(map(int, input().split())) if P[0] == 1 and P[-1] == N: print(0) exit() for i, (l, r) in enumerate(zip(P, P[1:])): if abs(l - r) == N - 1: break ans = 0 if l < r: ans = min(i + 1 + 1, 1 + N - i) else: ans = min(i + 1, 2 + N - i - 1) print(ans) N = int(input())...
ConDefects/ConDefects/Code/arc132_b/Python/37384305
condefects-python_data_674
n=int(input()) p=list(map(int,input().split())) if p[0]==1: ans=0 elif p[0]<p[1]: ans=min(n-p[0]+1,2+p[0]-1) else: ans=min(p[0]+1,n-p[0]+1) print(ans) n=int(input()) p=list(map(int,input().split())) if p[0]==1 and p[1]==2: ans=0 elif p[0]<p[1]: ans=min(n-p[0]+1,2+p[0]-1) else: ans=min(p[0]+1,n-p[0]+1) pr...
ConDefects/ConDefects/Code/arc132_b/Python/40788624
condefects-python_data_675
n = int(input()) p = list(map(int,input().split())) def isAscending(l): return l == sorted(l) ans = [] # pattern1: S,S,... i = p.index(1) p2 = p[i:] + p[:i] if isAscending(p2): ans.append(i) # patter2: R,S,S... p2 = p[::-1] i = p2.index(1) p2 = p[i:] + p[:i] if isAscending(p2): ans.append(i+1) # patter...
ConDefects/ConDefects/Code/arc132_b/Python/40631011
condefects-python_data_676
S=input() N=len(S) if set(S)=={'a'}: print('Yes') exit() left=0 right=N-1 while left<N and S[left]=='a': left+=1 while 0<=right and S[right]=='a': right-=1 if left>=N-1-right: print('No') exit() S=S[left:right+1] def palindrome(string): length=len(string) for i in range(length//2)...
ConDefects/ConDefects/Code/abc237_c/Python/46026874
condefects-python_data_677
import sys sys.setrecursionlimit(10**6) # import resource # resource.setrlimit(resource.RLIMIT_STACK, (1073741824//4, 1073741824//4)) from collections import deque, Counter, defaultdict from itertools import accumulate, permutations, combinations from bisect import bisect_left, bisect_right from heapq import heapify, h...
ConDefects/ConDefects/Code/abc237_c/Python/45967024
condefects-python_data_678
S=input() N=len(S) if S=="a"*N: print("Yes") exit() a=0 b=0 s=-1 t=-1 for i in range(N-1,-1,-1): if S[i]=="a": a+=1 else: s=i break for i in range(N): if S[i]=="a": b+=1 else: t=i break if a<b: print("No") exit() ...
ConDefects/ConDefects/Code/abc237_c/Python/45711395
condefects-python_data_679
s = input() n = len(s) i, j = 0, n-1 while j >= 0: if s[j] == 'a': j -= 1 else: break if j < 0: print('Yes') exit(0) while i < j: if s[i] == 'a': i += 1 else: break if i == j: print('Yes') exit(0) st, ed = i, n-j t = s[i : j+1] if t != t[::-1]: print('No') exit(0) if st <= ed: print('Yes') else: p...
ConDefects/ConDefects/Code/abc237_c/Python/45275344
condefects-python_data_680
s = input() count_r = 0 count_l = 0 while s[len(s)-1 - count_r] == "a": count_r += 1 if count_r == len(s): break while s[count_l] == "a": count_l += 1 if count_l == len(s): break sub = count_r - count_l if sub < 0: print("No") exit(0) l = 0 r = len(s) - 1 - sub while s[l] == ...
ConDefects/ConDefects/Code/abc237_c/Python/45542474
condefects-python_data_681
S = input() N = len(S) x,y = 0,0 for i in range(N): if S[i] != "a": break x += 1 for i in reversed(range(N)): if S[-i] != "a": break y += 1 S = "a"*(y-x) + S if S == S[::-1]: print('Yes') else: print('No') S = input() N = len(S) x,y = 0,0 for i in range(N): if S[i] ...
ConDefects/ConDefects/Code/abc237_c/Python/45277332
condefects-python_data_682
s = input() t = s.rstrip('a') suffix = len(s) - len(t) u = t.lstrip('a') prefix = len(t) - len(u) if prefix <= suffix: print('Yes') else: print('No') s = input() t = s.rstrip('a') suffix = len(s) - len(t) u = t.lstrip('a') prefix = len(t) - len(u) if prefix <= suffix and u==u[::-1]: print(...
ConDefects/ConDefects/Code/abc237_c/Python/45766102
condefects-python_data_683
s = input() tmp1 = s.rstrip("a") back_a = len(s)-len(tmp1) tmp2 = tmp1.lstrip("a") front_a = len(s)-len(tmp2) if tmp2==tmp2[::-1] and front_a<=back_a: print("Yes") else: print("No") s = input() tmp1 = s.rstrip("a") back_a = len(s)-len(tmp1) tmp2 = tmp1.lstrip("a") front_a = len(tmp1)-len(tmp2) if tmp2==tmp2[::-1] ...
ConDefects/ConDefects/Code/abc237_c/Python/45766174
condefects-python_data_684
# 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/abc343_c/Python/54882998
condefects-python_data_685
N = int(input()) n = 10**6 for i in range(n, 1, -1): k = i **3 k_str = str(k) if (k < N) and (k_str == k_str[::-1]): print(k) exit() print(1) N = int(input()) n = 10**6 for i in range(n, 1, -1): k = i **3 k_str = str(k) if (k <= N) and (k_str == k_str[::-1]): print(k) exit() print(1)
ConDefects/ConDefects/Code/abc343_c/Python/55124093
condefects-python_data_686
def isok(x): x = str(x) for i in range(len(x)//2): if x[i] != x[-i-1]: return False return True n = int(input()) ans = 0 for i in range(n): if i**3 <= n and isok(i**3): ans = i**3 elif i**3 > n: break print(ans) def isok(x): x = str(x) for i in range(len...
ConDefects/ConDefects/Code/abc343_c/Python/54879224
condefects-python_data_687
n = int(input()) x = 1 ans = x while x**3 < n: s = str(x**3) l = len(s) kai = True for i in range(l//2): # print(s, i, s[i], s[l-1]) if s[i] != s[l-i-1]: kai = False break if kai: ans = s x += 1 print(ans) n = int(input()) x = 1 ans = x while x**3 <= n: s = str(x**3) l = len...
ConDefects/ConDefects/Code/abc343_c/Python/54626929
condefects-python_data_688
N = int(input()) ans = 0 for x in range(N): if x**3 > N: print(ans) exit() else: s = str(x**3) str(s) S = list(s) P = S.copy() P.reverse() if S == P: if ans < x**3: ans = x**3 N = int(input()) ans = 0 for x in range(10000000000000): if x*...
ConDefects/ConDefects/Code/abc343_c/Python/54944365
condefects-python_data_689
#1603 N = int(input()) A = [] for i in range(0, 10**6+1): B = i**3 if B >= N: break elif str(B) == str(B)[::-1]: A.append(B) print(max(A)) #1603 N = int(input()) A = [] for i in range(0, 10**6+1): B = i**3 if B > N: break elif str(B) == str(B)[::-1]: A.app...
ConDefects/ConDefects/Code/abc343_c/Python/54781891
condefects-python_data_690
N=int(input()) index=1 s = set() l=[] while (True): flg=0 three=index*index*index if(three>N): break l.append(three) index+=1 #print(l) flg=0 for i in reversed(l): flg=0 strthree=str(i) if(len(strthree)==1): #print(i) break for j in range(len(strthree)//2): #print(j) #print(strthr...
ConDefects/ConDefects/Code/abc343_c/Python/54978258
condefects-python_data_691
N = int(input()) import math n = [i**3 for i in range(math.floor(N**(1/3))+1)] for i in range(len(n)-1, -1, -1): x = True for j in range(len(str(n[i]))//2 + 1): if str(n[i])[j] != str(n[i])[-j-1]: x = False if x: print(n[i]) exit() N = int(input()) import math n = [i**3 for i in range(ma...
ConDefects/ConDefects/Code/abc343_c/Python/54772219
condefects-python_data_692
N = int(input()) least_number = 0 for number in range(1000000): if number**3 <= N: for_number = str(number**3) rev_number = str(number**3)[::-1] for keta in range(int(len(for_number))): if for_number[keta] != rev_number[keta]: break elif keta == int(le...
ConDefects/ConDefects/Code/abc343_c/Python/54740731
condefects-python_data_693
N = int(input()) x_max = int(pow(N+1, 1/3)) if pow(x_max, 3) > N: x_max -= 1 for x in range(x_max, 0, -1): x_str = str(pow(x,3)) x_half_n = len(x_str)//2 if x_str[:x_half_n] == x_str[::-1][:x_half_n]: print(pow(x,3)) break N = int(input()) x_max = round(pow(N+1, 1/3)) if pow(x_max, 3) >...
ConDefects/ConDefects/Code/abc343_c/Python/55032181
condefects-python_data_694
s, a, b, m = input(), 0, 1, 998244353 for c in input()[::-1]: a += b * (ord(c) - ord('0')) b = (b * 10 + a) % m print(a) s, a, b, m = input(), 0, 1, 998244353 for c in input()[::-1]: a += b * (ord(c) - ord('0')) b = (b * 10 + a) % m print(a % m)
ConDefects/ConDefects/Code/abc288_f/Python/44220093
condefects-python_data_695
n=int(input()) x=input() mod=998255353 dp=0 s=1 for i in range(n): k=int(x[i]) dp=(dp*10+s*k)%mod s+=dp s%=mod print(dp) n=int(input()) x=input() mod=998244353 dp=0 s=1 for i in range(n): k=int(x[i]) dp=(dp*10+s*k)%mod s+=dp s%=mod print(dp)
ConDefects/ConDefects/Code/abc288_f/Python/54492440
condefects-python_data_696
import sys input = lambda: sys.stdin.readline().strip() MOD = 998244353 def solve(): n = int(input()) s = input() sum_f = 1 f = 0 for c in s: x = int(c) f = (f * 10 + x) % MOD sum_f += f print(f) solve() import sys input = lambda: sys.stdin.readline().strip() MOD = 99...
ConDefects/ConDefects/Code/abc288_f/Python/44222318
condefects-python_data_697
s, a, b, m = input(), 0, 1, 998244353 for c in input(): a = (a * 10 + b * (ord(c) - ord('0'))) % m b += a print(a) s, a, b, m = input(), 0, 1, 998244353 for c in input(): a = (a * 10 + b * (ord(c) - ord('0'))) % m b += a print(a)
ConDefects/ConDefects/Code/abc288_f/Python/44219980
condefects-python_data_698
N,T=map(int,input().split()) result=0 L=[] for i in range(N): w,x,v=map(int,input().split()) L.append((w,x,v)) from collections import defaultdict for q in range(N): R=set() score=0 w,x,v=L[q][:] score+=w P=defaultdict(int) for i in range(N): if i==q: continue w2,x2,v2=L[i][:] if x<=x2...
ConDefects/ConDefects/Code/abc274_f/Python/50475104
condefects-python_data_699
def floor_sum(n, m, a, b): res = 0 if n == 0: return 0 if a >= m: res += n*(n-1)//2*(a//m) a %= m if b >= m: res += n*(b//m) b %= m if a == 0: return res q = (a*n+b)//m r = (a*n+b)%m res += floor_sum(q, a, m, r) return r...
ConDefects/ConDefects/Code/abc283_h/Python/37533124
condefects-python_data_700
from collections import defaultdict import sys import os sys.setrecursionlimit(int(1e9)) input = lambda: sys.stdin.readline().rstrip("\r\n") def main() -> None: def check(mid: int) -> bool: def dfs(cur: int, pre: int) -> int: """(对方最优操作下)子树中权值>=mid的点的个数""" subtree = 0 ...
ConDefects/ConDefects/Code/abc246_g/Python/33284569