id
stringlengths
24
27
content
stringlengths
37
384k
max_stars_repo_path
stringlengths
51
51
condefects-python_data_2201
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 import copy, deepcopy from heapq import heapify, heappush, heappop, heappushpop, heapreplace from functools import cmp_to_key as cmpk al = "abcdefghijklmnopqrstuvwxyz" au = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" # io # begin fastio import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin = IOWrapper(sys.stdin) # sys.stdout = IOWrapper(sys.stdout) _log = True # if False, perr() do notiong import sys import itertools def input(): return sys.stdin.readline().rstrip() def ii(): return int(sys.stdin.readline().rstrip()) def gl(): return list(map(int, sys.stdin.readline().split())) def gs(): return list(input().split()) def gr(l): res = itertools.groupby(l) return list([(key, len(list(v))) for key, v in res]) def glm(h,w): a = [] for i in range(h): a.append(gl()) return a def gsm(h): a = [] for i in range(h): a.append(input().split()) return a def perr(*l): if _log: print('\033[33m', end = '', file = sys.stderr) print(*l, '\033[0m', file=sys.stderr) def pex(con): pyn(con) exit() def pyn(con, yes = 'Yes', no = 'No'): if con: print(yes) else: print(no) def py(yes = 'Yes'): print(yes) def pn(no = 'No'): print(no) def putedges(g, idx = 0): n = len(g) e = [] cnt2 = 0 for i in range(n): for j in g[i]: cnt2 += 1 e.append((i, j)) m = len(g) print(n, cnt2) for i in e: if idx == 0: print(*[i[0], i[1]]) else: print(*[i[0] + 1, i[1] + 1]) # end io class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) # return group_members return dict(group_members) def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) # begin util/util def rev(a): a = a[:] return list(reversed(a)) def drev(d): newd = {} for k in rev(list(d.keys())): newd[k] = d[k] return newd def dvsort(d): return dict(sorted(d.items(), key = lambda x: x[1])) def dksort(d): return dict(sorted(d.items())) def yn(con, yes = 'Yes', no = 'No'): if con: return yes else: return no def kiriage(n, r): if n % r == 0: return n // r else: return (n // r) + 1 def ketawa(n): ans = 0 s = str(n) for i in s: ans += int(i) return ans def sinhen(n, l): if n < l: return [n] else: return sinhen(n // l, l) + [n % l] import re def search(q, b): return re.search(b, q) def cut_yoko(a, y): a_copy = deepcopy(a) res = [] for x in range(len(a[0])): res.append(a_copy[y][x]) return res def cut_tate(a, x): a_copy = deepcopy(a) res = [] for y in range(len(a)): res.append(a_copy[y][x]) return res def rmwh(a): s = set([len(e) for e in a]) assert len(s) == 1 while not '#' in a[0]: a = a[1:] while not '#' in a[-1]: a = a[:-1] ok = True while True: for y in range(len(a)): if a[y][0] == '#': ok = False if ok: for y in range(len(a)): a[y] = a[y][1:] else: break ok = True while True: for y in range(len(a)): if a[y][-1] == '#': ok = False if ok: for y in range(len(a)): a[y] = a[y][:-1] else: break return a def cntsep(a, b, k): r = a % k m = a - r ans = (b - m) // (k+1) if r > 0: ans -= 1 return ans def compress(a, base = 1): s = set() for e in a: s.add(e) s = list(sorted(s)) d = {} for i in range(len(s)): d[s[i]] = i b = [] for e in a: b.append(d[e] + base) return b # from decimal import * def myround(x, k): if k < 0: return float(Decimal(str(x)).quantize(Decimal('1E' + str(k+1)), rounding = ROUND_HALF_UP)) else: return int(Decimal(str(x)).quantize(Decimal('1E' + str(k+1)), rounding = ROUND_HALF_UP)) def rp(s, d): return s.translate(str.maketrans(d)) def tr(s, a, b): assert len(a) == len(b) res = [] d = {} for i in len(a): d[a] = b[b] return ''.join([d[e] for e in s])# ned # end util/util # begin permutation # https://strangerxxx.hateblo.jp/entry/20220201/1643705539 def next_permutation(a, l = 0, r = None): if r is None: r = len(a) for i in range(r - 2, l - 1, -1): if a[i] < a[i + 1]: for j in range(r - 1, i, -1): if a[i] < a[j]: a[i], a[j] = a[j], a[i] p, q = i + 1, r - 1 while p < q: a[p], a[q] = a[q], a[p] p += 1 q -= 1 return True return False def prev_permutation(a, l = 0, r = None): if r is None: r = len(a) for i in range(r - 2, l - 1, -1): if a[i] > a[i + 1]: for j in range(r - 1, i, -1): if a[i] > a[j]: a[i], a[j] = a[j], a[i] p, q = i + 1, r - 1 while p < q: a[p], a[q] = a[q], a[p] p += 1 q -= 1 return True return False # end permutation # begin math/gcd def lcm2(x, y): return (x * y) // math.gcd(x, y) def lcm3(*ints): return functools.reduce(lcm2, ints) def gcd(*ints): return math.gcd(*ints) # end math/gcd # 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, List, Tuple, TypeVar, Optional T = TypeVar('T') class SortedSet(Generic[T]): BUCKET_RATIO = 16 SPLIT_RATIO = 24 def __init__(self, a: Iterable[T] = []) -> None: "Make a new SortedSet from iterable. / O(N) if sorted and unique / O(N log N)" a = list(a) n = len(a) if any(a[i] > a[i + 1] for i in range(n - 1)): a.sort() if any(a[i] >= a[i + 1] for i in range(n - 1)): a, b = [], a for x in b: if not a or a[-1] != x: a.append(x) n = self.size = len(a) num_bucket = int(math.ceil(math.sqrt(n / self.BUCKET_RATIO))) self.a = [a[n * i // num_bucket : n * (i + 1) // num_bucket] for i in range(num_bucket)] def __iter__(self) -> Iterator[T]: for i in self.a: for j in i: yield j def __reversed__(self) -> Iterator[T]: for i in reversed(self.a): for j in reversed(i): yield j def __eq__(self, other) -> bool: return list(self) == list(other) def __len__(self) -> int: return self.size def __repr__(self) -> str: return "SortedSet" + str(self.a) def __str__(self) -> str: s = str(list(self)) return "{" + s[1 : len(s) - 1] + "}" def _position(self, x: T) -> Tuple[List[T], int, int]: "return the bucket, index of the bucket and position in which x should be. self must not be empty." for i, a in enumerate(self.a): if x <= a[-1]: break return (a, i, bisect_left(a, x)) def __contains__(self, x: T) -> bool: if self.size == 0: return False a, _, i = self._position(x) return i != len(a) and a[i] == x def add(self, x: T) -> bool: "Add an element and return True if added. / O(√N)" if self.size == 0: self.a = [[x]] self.size = 1 return True a, b, i = self._position(x) if i != len(a) and a[i] == x: return False a.insert(i, x) self.size += 1 if len(a) > len(self.a) * self.SPLIT_RATIO: mid = len(a) >> 1 self.a[b:b+1] = [a[:mid], a[mid:]] return True def _pop(self, a: List[T], b: int, i: int) -> T: ans = a.pop(i) self.size -= 1 if not a: del self.a[b] return ans def discard(self, x: T) -> bool: "Remove an element and return True if removed. / O(√N)" if self.size == 0: return False a, b, i = self._position(x) if i == len(a) or a[i] != x: return False self._pop(a, b, i) return True def lt(self, x: T) -> Optional[T]: "Find the largest element < x, or None if it doesn't exist." for a in reversed(self.a): if a[0] < x: return a[bisect_left(a, x) - 1] def le(self, x: T) -> Optional[T]: "Find the largest element <= x, or None if it doesn't exist." for a in reversed(self.a): if a[0] <= x: return a[bisect_right(a, x) - 1] def gt(self, x: T) -> Optional[T]: "Find the smallest element > x, or None if it doesn't exist." for a in self.a: if a[-1] > x: return a[bisect_right(a, x)] def ge(self, x: T) -> Optional[T]: "Find the smallest element >= x, or None if it doesn't exist." for a in self.a: if a[-1] >= x: return a[bisect_left(a, x)] def __getitem__(self, i: int) -> T: "Return the i-th element." if i < 0: for a in reversed(self.a): i += len(a) if i >= 0: return a[i] else: for a in self.a: if i < len(a): return a[i] i -= len(a) raise IndexError def pop(self, i: int = -1) -> T: "Pop and return the i-th element." if i < 0: for b, a in enumerate(reversed(self.a)): i += len(a) if i >= 0: return self._pop(a, ~b, i) else: for b, a in enumerate(self.a): if i < len(a): return self._pop(a, b, i) i -= len(a) raise IndexError def index(self, x: T) -> int: "Count the number of elements < x." ans = 0 for a in self.a: if a[-1] >= x: return ans + bisect_left(a, x) ans += len(a) return ans def index_right(self, x: T) -> int: "Count the number of elements <= x." ans = 0 for a in self.a: if a[-1] > x: return ans + bisect_right(a, x) ans += len(a) return ans # https://github.com/tatyam-prime/SortedSet/blob/main/SortedMultiset.py import math from bisect import bisect_left, bisect_right from typing import Generic, Iterable, Iterator, List, Tuple, TypeVar, Optional T = TypeVar('T') class SortedMultiset(Generic[T]): BUCKET_RATIO = 16 SPLIT_RATIO = 24 def __init__(self, a: Iterable[T] = []) -> None: "Make a new SortedMultiset from iterable. / O(N) if sorted / O(N log N)" a = list(a) n = self.size = len(a) if any(a[i] > a[i + 1] for i in range(n - 1)): a.sort() num_bucket = int(math.ceil(math.sqrt(n / self.BUCKET_RATIO))) self.a = [a[n * i // num_bucket : n * (i + 1) // num_bucket] for i in range(num_bucket)] def __iter__(self) -> Iterator[T]: for i in self.a: for j in i: yield j def __reversed__(self) -> Iterator[T]: for i in reversed(self.a): for j in reversed(i): yield j def __eq__(self, other) -> bool: return list(self) == list(other) def __len__(self) -> int: return self.size def __repr__(self) -> str: return "SortedMultiset" + str(self.a) def __str__(self) -> str: s = str(list(self)) return "{" + s[1 : len(s) - 1] + "}" def _position(self, x: T) -> Tuple[List[T], int, int]: "return the bucket, index of the bucket and position in which x should be. self must not be empty." for i, a in enumerate(self.a): if x <= a[-1]: break return (a, i, bisect_left(a, x)) def __contains__(self, x: T) -> bool: if self.size == 0: return False a, _, i = self._position(x) return i != len(a) and a[i] == x def count(self, x: T) -> int: "Count the number of x." return self.index_right(x) - self.index(x) def add(self, x: T) -> None: "Add an element. / O(√N)" if self.size == 0: self.a = [[x]] self.size = 1 return a, b, i = self._position(x) a.insert(i, x) self.size += 1 if len(a) > len(self.a) * self.SPLIT_RATIO: mid = len(a) >> 1 self.a[b:b+1] = [a[:mid], a[mid:]] def _pop(self, a: List[T], b: int, i: int) -> T: ans = a.pop(i) self.size -= 1 if not a: del self.a[b] return ans def discard(self, x: T) -> bool: "Remove an element and return True if removed. / O(√N)" if self.size == 0: return False a, b, i = self._position(x) if i == len(a) or a[i] != x: return False self._pop(a, b, i) return True def lt(self, x: T) -> Optional[T]: "Find the largest element < x, or None if it doesn't exist." for a in reversed(self.a): if a[0] < x: return a[bisect_left(a, x) - 1] def le(self, x: T) -> Optional[T]: "Find the largest element <= x, or None if it doesn't exist." for a in reversed(self.a): if a[0] <= x: return a[bisect_right(a, x) - 1] def gt(self, x: T) -> Optional[T]: "Find the smallest element > x, or None if it doesn't exist." for a in self.a: if a[-1] > x: return a[bisect_right(a, x)] def ge(self, x: T) -> Optional[T]: "Find the smallest element >= x, or None if it doesn't exist." for a in self.a: if a[-1] >= x: return a[bisect_left(a, x)] def __getitem__(self, i: int) -> T: "Return the i-th element." if i < 0: for a in reversed(self.a): i += len(a) if i >= 0: return a[i] else: for a in self.a: if i < len(a): return a[i] i -= len(a) raise IndexError def pop(self, i: int = -1) -> T: "Pop and return the i-th element." if i < 0: for b, a in enumerate(reversed(self.a)): i += len(a) if i >= 0: return self._pop(a, ~b, i) else: for b, a in enumerate(self.a): if i < len(a): return self._pop(a, b, i) i -= len(a) raise IndexError def index(self, x: T) -> int: "count the number of elements < x." ans = 0 for a in self.a: if a[-1] >= x: return ans + bisect_left(a, x) ans += len(a) return ans def index_right(self, x: T) -> int: "count the number of elements <= x." ans = 0 for a in self.a: if a[-1] > x: return ans + bisect_right(a, x) ans += len(a) return ans # https://stackoverflow.com/questions/2501457/what-do-i-use-for-a-max-heap-implementation-in-python#answer-40455775 class Heapq(): # def __init__(self, arr = []): # self.hq = arr # heapify(self.hq) def __init__(self, arr = None): if arr == None: arr = [] self.hq = arr heapify(self.hq) def pop(self): return heappop(self.hq) def append(self, a): heappush(self.hq, a) def __len__(self): return len(self.hq) def __getitem__(self, idx): return self.hq[idx] def __repr__(self): return str(self.hq) class _MaxHeapObj(object): def __init__(self, val): self.val = val def __lt__(self, other): return self.val > other.val def __eq__(self, other): return self.val == other.val def __str__(self): return str(self.val) class Maxheapq(): def __init__(self, arr = []): self.hq = [_MaxHeapObj(e) for e in arr] heapify(self.hq) def pop(self): return heappop(self.hq).val def append(self, a): heappush(self.hq, _MaxHeapObj(a)) def __len__(self): return len(self.hq) def __getitem__(self, idx): return self.hq[idx].val def __repr__(self): return str([e.val for e in self.hq]) def dijkstra(g, st): h = Heapq() h.append((0, st)) vi = set() res = [inf for i in range(len(g))] while len(vi) != n and len(h) != 0: d, now = h.pop() if now in vi: continue vi.add(now) res[now] = d for to in g[now]: if not to in vi: h.append((d + g[now][to], to)) return res def tarjan(g): n = len(g) scc, s, p = [], [], [] q = [i for i in range(n)] state = [0] * n while q: node = q.pop() if node < 0: d = state[~node] - 1 if p[-1] > d: scc.append(s[d:]) del s[d:] p.pop() for v in scc[-1]: state[v] = -1 elif state[node] > 0: while p[-1] > state[node]: p.pop() elif state[node] == 0: s.append(node) p.append(len(s)) state[node] = len(s) q.append(~node) q.extend(g[node]) return scc def top_sort(g): res = [] vi = set() q = deque() din = [0 for i in range(len(g))] for i in range(len(g)): for e in g[i]: din[e] += 1 for i in range(len(din)): if din[i] == 0: q.append(i) while len(q) != 0: st = q.popleft() res.append(st) for to in g[st]: din[to] -= 1 if din[to] == 0: q.append(to) return res # begin combination # https://rin204.github.io/Library-Python/expansion/math/Combination.py import math class Combination: def __init__(self, n, MOD=998244353): n = min(n, MOD - 1) self.fact = [1] * (n + 1) self.invfact = [1] * (n + 1) self.MOD = MOD for i in range(1, n + 1): self.fact[i] = self.fact[i - 1] * i % MOD self.invfact[n] = pow(self.fact[n], MOD - 2, MOD) for i in range(n - 1, -1, -1): self.invfact[i] = self.invfact[i + 1] * (i + 1) % MOD def extend(self, n): le = len(self.fact) if n < le: return self.fact.extend([1] * (n - le + 1)) self.invfact.extend([1] * (n - le + 1)) for i in range(le, n + 1): self.fact[i] = self.fact[i - 1] * i % self.MOD self.invfact[n] = pow(self.fact[n], self.MOD - 2, self.MOD) for i in range(n - 1, le - 1, -1): self.invfact[i] = self.invfact[i + 1] * (i + 1) % self.MOD def nPk(self, n, k): if k < 0 or n < k: return 0 if n >= len(self.fact): self.extend(n) return self.fact[n] * self.invfact[n - k] % self.MOD def nCk(self, n, k): if k < 0 or n < k: return 0 if n >= len(self.fact): self.extend(n) return (self.fact[n] * self.invfact[n - k] % self.MOD) * self.invfact[k] % self.MOD def nHk(self, n, k): if n == 0 and k == 0: return 1 return self.nCk(n + k - 1, k) def Catalan(self, n): return (self.nCk(2 * n, n) - self.nCk(2 * n, n - 1)) % self.MOD def nCk(n, k): return math.comb(n, k) def nCk_mod(n, k, mod = 998244353): if k < 0 or n < k: return 0 res = 1 for i in range(k): res *= (n - i) res %= mod res *= pow((k - i), -1, mod) res %= mod return res # end combination def mbs(a, key): ng = -1 ok = len(a) while abs(ok - ng) > 1: mid = (ok + ng) // 2 if a[mid] >= key: ok = mid else: ng = mid return ok def satlow(f, lower = 0, upper = 10**9): ng = lower ok = upper while abs(ok - ng) > 1: mid = (ok + ng) // 2 if f(mid): ok = mid else: ng = mid return ok def listsatlow(a, f): ng = -1 ok = len(a) while abs(ok - ng) > 1: mid = (ok + ng) // 2 if f(a[mid]): ok = mid else: ng = mid return ok _log=True def pex(con): pyn(con) exit() def yn(con, yes = 'Yes', no = 'No'): if con: return yes else: return no def pp(con, yes = 'Yes', no = 'No'): if con: print(yes) else: print(no) def pyn(con, yes = 'Yes', no = 'No'): if con: print(yes) else: print(no) def py(yes = 'Yes'): print(yes) def pn(no = 'No'): print(no) yes='Yes' no='No' v4 = [[-1, 0], [0, -1], [0, 1], [1, 0]] inf = float('inf') ans = inf cnt=0 #main n = ii() a = glm(n, 2) d = {} def p(now): if now in d.keys(): return d[now] win = False for i in range(n - 1): if win: break if now & (1 << i) != 0: continue for j in range(i + 1, n): if win: break if now & (1 << j) != 0: continue if a[i][0] != a[j][0] and a[i][0] != a[j][1] and a[i][1] != a[j][0] and a[i][1] and a[j][1]: continue new = now new |= (1 << i) new |= (1 << j) res = p(new) if not res: win = True if win: d[now] = True else: d[now] = False return d[now] if p(0): print('Takahashi') else: print('Aoki') 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 import copy, deepcopy from heapq import heapify, heappush, heappop, heappushpop, heapreplace from functools import cmp_to_key as cmpk al = "abcdefghijklmnopqrstuvwxyz" au = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" # io # begin fastio import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin = IOWrapper(sys.stdin) # sys.stdout = IOWrapper(sys.stdout) _log = True # if False, perr() do notiong import sys import itertools def input(): return sys.stdin.readline().rstrip() def ii(): return int(sys.stdin.readline().rstrip()) def gl(): return list(map(int, sys.stdin.readline().split())) def gs(): return list(input().split()) def gr(l): res = itertools.groupby(l) return list([(key, len(list(v))) for key, v in res]) def glm(h,w): a = [] for i in range(h): a.append(gl()) return a def gsm(h): a = [] for i in range(h): a.append(input().split()) return a def perr(*l): if _log: print('\033[33m', end = '', file = sys.stderr) print(*l, '\033[0m', file=sys.stderr) def pex(con): pyn(con) exit() def pyn(con, yes = 'Yes', no = 'No'): if con: print(yes) else: print(no) def py(yes = 'Yes'): print(yes) def pn(no = 'No'): print(no) def putedges(g, idx = 0): n = len(g) e = [] cnt2 = 0 for i in range(n): for j in g[i]: cnt2 += 1 e.append((i, j)) m = len(g) print(n, cnt2) for i in e: if idx == 0: print(*[i[0], i[1]]) else: print(*[i[0] + 1, i[1] + 1]) # end io class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) # return group_members return dict(group_members) def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) # begin util/util def rev(a): a = a[:] return list(reversed(a)) def drev(d): newd = {} for k in rev(list(d.keys())): newd[k] = d[k] return newd def dvsort(d): return dict(sorted(d.items(), key = lambda x: x[1])) def dksort(d): return dict(sorted(d.items())) def yn(con, yes = 'Yes', no = 'No'): if con: return yes else: return no def kiriage(n, r): if n % r == 0: return n // r else: return (n // r) + 1 def ketawa(n): ans = 0 s = str(n) for i in s: ans += int(i) return ans def sinhen(n, l): if n < l: return [n] else: return sinhen(n // l, l) + [n % l] import re def search(q, b): return re.search(b, q) def cut_yoko(a, y): a_copy = deepcopy(a) res = [] for x in range(len(a[0])): res.append(a_copy[y][x]) return res def cut_tate(a, x): a_copy = deepcopy(a) res = [] for y in range(len(a)): res.append(a_copy[y][x]) return res def rmwh(a): s = set([len(e) for e in a]) assert len(s) == 1 while not '#' in a[0]: a = a[1:] while not '#' in a[-1]: a = a[:-1] ok = True while True: for y in range(len(a)): if a[y][0] == '#': ok = False if ok: for y in range(len(a)): a[y] = a[y][1:] else: break ok = True while True: for y in range(len(a)): if a[y][-1] == '#': ok = False if ok: for y in range(len(a)): a[y] = a[y][:-1] else: break return a def cntsep(a, b, k): r = a % k m = a - r ans = (b - m) // (k+1) if r > 0: ans -= 1 return ans def compress(a, base = 1): s = set() for e in a: s.add(e) s = list(sorted(s)) d = {} for i in range(len(s)): d[s[i]] = i b = [] for e in a: b.append(d[e] + base) return b # from decimal import * def myround(x, k): if k < 0: return float(Decimal(str(x)).quantize(Decimal('1E' + str(k+1)), rounding = ROUND_HALF_UP)) else: return int(Decimal(str(x)).quantize(Decimal('1E' + str(k+1)), rounding = ROUND_HALF_UP)) def rp(s, d): return s.translate(str.maketrans(d)) def tr(s, a, b): assert len(a) == len(b) res = [] d = {} for i in len(a): d[a] = b[b] return ''.join([d[e] for e in s])# ned # end util/util # begin permutation # https://strangerxxx.hateblo.jp/entry/20220201/1643705539 def next_permutation(a, l = 0, r = None): if r is None: r = len(a) for i in range(r - 2, l - 1, -1): if a[i] < a[i + 1]: for j in range(r - 1, i, -1): if a[i] < a[j]: a[i], a[j] = a[j], a[i] p, q = i + 1, r - 1 while p < q: a[p], a[q] = a[q], a[p] p += 1 q -= 1 return True return False def prev_permutation(a, l = 0, r = None): if r is None: r = len(a) for i in range(r - 2, l - 1, -1): if a[i] > a[i + 1]: for j in range(r - 1, i, -1): if a[i] > a[j]: a[i], a[j] = a[j], a[i] p, q = i + 1, r - 1 while p < q: a[p], a[q] = a[q], a[p] p += 1 q -= 1 return True return False # end permutation # begin math/gcd def lcm2(x, y): return (x * y) // math.gcd(x, y) def lcm3(*ints): return functools.reduce(lcm2, ints) def gcd(*ints): return math.gcd(*ints) # end math/gcd # 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, List, Tuple, TypeVar, Optional T = TypeVar('T') class SortedSet(Generic[T]): BUCKET_RATIO = 16 SPLIT_RATIO = 24 def __init__(self, a: Iterable[T] = []) -> None: "Make a new SortedSet from iterable. / O(N) if sorted and unique / O(N log N)" a = list(a) n = len(a) if any(a[i] > a[i + 1] for i in range(n - 1)): a.sort() if any(a[i] >= a[i + 1] for i in range(n - 1)): a, b = [], a for x in b: if not a or a[-1] != x: a.append(x) n = self.size = len(a) num_bucket = int(math.ceil(math.sqrt(n / self.BUCKET_RATIO))) self.a = [a[n * i // num_bucket : n * (i + 1) // num_bucket] for i in range(num_bucket)] def __iter__(self) -> Iterator[T]: for i in self.a: for j in i: yield j def __reversed__(self) -> Iterator[T]: for i in reversed(self.a): for j in reversed(i): yield j def __eq__(self, other) -> bool: return list(self) == list(other) def __len__(self) -> int: return self.size def __repr__(self) -> str: return "SortedSet" + str(self.a) def __str__(self) -> str: s = str(list(self)) return "{" + s[1 : len(s) - 1] + "}" def _position(self, x: T) -> Tuple[List[T], int, int]: "return the bucket, index of the bucket and position in which x should be. self must not be empty." for i, a in enumerate(self.a): if x <= a[-1]: break return (a, i, bisect_left(a, x)) def __contains__(self, x: T) -> bool: if self.size == 0: return False a, _, i = self._position(x) return i != len(a) and a[i] == x def add(self, x: T) -> bool: "Add an element and return True if added. / O(√N)" if self.size == 0: self.a = [[x]] self.size = 1 return True a, b, i = self._position(x) if i != len(a) and a[i] == x: return False a.insert(i, x) self.size += 1 if len(a) > len(self.a) * self.SPLIT_RATIO: mid = len(a) >> 1 self.a[b:b+1] = [a[:mid], a[mid:]] return True def _pop(self, a: List[T], b: int, i: int) -> T: ans = a.pop(i) self.size -= 1 if not a: del self.a[b] return ans def discard(self, x: T) -> bool: "Remove an element and return True if removed. / O(√N)" if self.size == 0: return False a, b, i = self._position(x) if i == len(a) or a[i] != x: return False self._pop(a, b, i) return True def lt(self, x: T) -> Optional[T]: "Find the largest element < x, or None if it doesn't exist." for a in reversed(self.a): if a[0] < x: return a[bisect_left(a, x) - 1] def le(self, x: T) -> Optional[T]: "Find the largest element <= x, or None if it doesn't exist." for a in reversed(self.a): if a[0] <= x: return a[bisect_right(a, x) - 1] def gt(self, x: T) -> Optional[T]: "Find the smallest element > x, or None if it doesn't exist." for a in self.a: if a[-1] > x: return a[bisect_right(a, x)] def ge(self, x: T) -> Optional[T]: "Find the smallest element >= x, or None if it doesn't exist." for a in self.a: if a[-1] >= x: return a[bisect_left(a, x)] def __getitem__(self, i: int) -> T: "Return the i-th element." if i < 0: for a in reversed(self.a): i += len(a) if i >= 0: return a[i] else: for a in self.a: if i < len(a): return a[i] i -= len(a) raise IndexError def pop(self, i: int = -1) -> T: "Pop and return the i-th element." if i < 0: for b, a in enumerate(reversed(self.a)): i += len(a) if i >= 0: return self._pop(a, ~b, i) else: for b, a in enumerate(self.a): if i < len(a): return self._pop(a, b, i) i -= len(a) raise IndexError def index(self, x: T) -> int: "Count the number of elements < x." ans = 0 for a in self.a: if a[-1] >= x: return ans + bisect_left(a, x) ans += len(a) return ans def index_right(self, x: T) -> int: "Count the number of elements <= x." ans = 0 for a in self.a: if a[-1] > x: return ans + bisect_right(a, x) ans += len(a) return ans # https://github.com/tatyam-prime/SortedSet/blob/main/SortedMultiset.py import math from bisect import bisect_left, bisect_right from typing import Generic, Iterable, Iterator, List, Tuple, TypeVar, Optional T = TypeVar('T') class SortedMultiset(Generic[T]): BUCKET_RATIO = 16 SPLIT_RATIO = 24 def __init__(self, a: Iterable[T] = []) -> None: "Make a new SortedMultiset from iterable. / O(N) if sorted / O(N log N)" a = list(a) n = self.size = len(a) if any(a[i] > a[i + 1] for i in range(n - 1)): a.sort() num_bucket = int(math.ceil(math.sqrt(n / self.BUCKET_RATIO))) self.a = [a[n * i // num_bucket : n * (i + 1) // num_bucket] for i in range(num_bucket)] def __iter__(self) -> Iterator[T]: for i in self.a: for j in i: yield j def __reversed__(self) -> Iterator[T]: for i in reversed(self.a): for j in reversed(i): yield j def __eq__(self, other) -> bool: return list(self) == list(other) def __len__(self) -> int: return self.size def __repr__(self) -> str: return "SortedMultiset" + str(self.a) def __str__(self) -> str: s = str(list(self)) return "{" + s[1 : len(s) - 1] + "}" def _position(self, x: T) -> Tuple[List[T], int, int]: "return the bucket, index of the bucket and position in which x should be. self must not be empty." for i, a in enumerate(self.a): if x <= a[-1]: break return (a, i, bisect_left(a, x)) def __contains__(self, x: T) -> bool: if self.size == 0: return False a, _, i = self._position(x) return i != len(a) and a[i] == x def count(self, x: T) -> int: "Count the number of x." return self.index_right(x) - self.index(x) def add(self, x: T) -> None: "Add an element. / O(√N)" if self.size == 0: self.a = [[x]] self.size = 1 return a, b, i = self._position(x) a.insert(i, x) self.size += 1 if len(a) > len(self.a) * self.SPLIT_RATIO: mid = len(a) >> 1 self.a[b:b+1] = [a[:mid], a[mid:]] def _pop(self, a: List[T], b: int, i: int) -> T: ans = a.pop(i) self.size -= 1 if not a: del self.a[b] return ans def discard(self, x: T) -> bool: "Remove an element and return True if removed. / O(√N)" if self.size == 0: return False a, b, i = self._position(x) if i == len(a) or a[i] != x: return False self._pop(a, b, i) return True def lt(self, x: T) -> Optional[T]: "Find the largest element < x, or None if it doesn't exist." for a in reversed(self.a): if a[0] < x: return a[bisect_left(a, x) - 1] def le(self, x: T) -> Optional[T]: "Find the largest element <= x, or None if it doesn't exist." for a in reversed(self.a): if a[0] <= x: return a[bisect_right(a, x) - 1] def gt(self, x: T) -> Optional[T]: "Find the smallest element > x, or None if it doesn't exist." for a in self.a: if a[-1] > x: return a[bisect_right(a, x)] def ge(self, x: T) -> Optional[T]: "Find the smallest element >= x, or None if it doesn't exist." for a in self.a: if a[-1] >= x: return a[bisect_left(a, x)] def __getitem__(self, i: int) -> T: "Return the i-th element." if i < 0: for a in reversed(self.a): i += len(a) if i >= 0: return a[i] else: for a in self.a: if i < len(a): return a[i] i -= len(a) raise IndexError def pop(self, i: int = -1) -> T: "Pop and return the i-th element." if i < 0: for b, a in enumerate(reversed(self.a)): i += len(a) if i >= 0: return self._pop(a, ~b, i) else: for b, a in enumerate(self.a): if i < len(a): return self._pop(a, b, i) i -= len(a) raise IndexError def index(self, x: T) -> int: "count the number of elements < x." ans = 0 for a in self.a: if a[-1] >= x: return ans + bisect_left(a, x) ans += len(a) return ans def index_right(self, x: T) -> int: "count the number of elements <= x." ans = 0 for a in self.a: if a[-1] > x: return ans + bisect_right(a, x) ans += len(a) return ans # https://stackoverflow.com/questions/2501457/what-do-i-use-for-a-max-heap-implementation-in-python#answer-40455775 class Heapq(): # def __init__(self, arr = []): # self.hq = arr # heapify(self.hq) def __init__(self, arr = None): if arr == None: arr = [] self.hq = arr heapify(self.hq) def pop(self): return heappop(self.hq) def append(self, a): heappush(self.hq, a) def __len__(self): return len(self.hq) def __getitem__(self, idx): return self.hq[idx] def __repr__(self): return str(self.hq) class _MaxHeapObj(object): def __init__(self, val): self.val = val def __lt__(self, other): return self.val > other.val def __eq__(self, other): return self.val == other.val def __str__(self): return str(self.val) class Maxheapq(): def __init__(self, arr = []): self.hq = [_MaxHeapObj(e) for e in arr] heapify(self.hq) def pop(self): return heappop(self.hq).val def append(self, a): heappush(self.hq, _MaxHeapObj(a)) def __len__(self): return len(self.hq) def __getitem__(self, idx): return self.hq[idx].val def __repr__(self): return str([e.val for e in self.hq]) def dijkstra(g, st): h = Heapq() h.append((0, st)) vi = set() res = [inf for i in range(len(g))] while len(vi) != n and len(h) != 0: d, now = h.pop() if now in vi: continue vi.add(now) res[now] = d for to in g[now]: if not to in vi: h.append((d + g[now][to], to)) return res def tarjan(g): n = len(g) scc, s, p = [], [], [] q = [i for i in range(n)] state = [0] * n while q: node = q.pop() if node < 0: d = state[~node] - 1 if p[-1] > d: scc.append(s[d:]) del s[d:] p.pop() for v in scc[-1]: state[v] = -1 elif state[node] > 0: while p[-1] > state[node]: p.pop() elif state[node] == 0: s.append(node) p.append(len(s)) state[node] = len(s) q.append(~node) q.extend(g[node]) return scc def top_sort(g): res = [] vi = set() q = deque() din = [0 for i in range(len(g))] for i in range(len(g)): for e in g[i]: din[e] += 1 for i in range(len(din)): if din[i] == 0: q.append(i) while len(q) != 0: st = q.popleft() res.append(st) for to in g[st]: din[to] -= 1 if din[to] == 0: q.append(to) return res # begin combination # https://rin204.github.io/Library-Python/expansion/math/Combination.py import math class Combination: def __init__(self, n, MOD=998244353): n = min(n, MOD - 1) self.fact = [1] * (n + 1) self.invfact = [1] * (n + 1) self.MOD = MOD for i in range(1, n + 1): self.fact[i] = self.fact[i - 1] * i % MOD self.invfact[n] = pow(self.fact[n], MOD - 2, MOD) for i in range(n - 1, -1, -1): self.invfact[i] = self.invfact[i + 1] * (i + 1) % MOD def extend(self, n): le = len(self.fact) if n < le: return self.fact.extend([1] * (n - le + 1)) self.invfact.extend([1] * (n - le + 1)) for i in range(le, n + 1): self.fact[i] = self.fact[i - 1] * i % self.MOD self.invfact[n] = pow(self.fact[n], self.MOD - 2, self.MOD) for i in range(n - 1, le - 1, -1): self.invfact[i] = self.invfact[i + 1] * (i + 1) % self.MOD def nPk(self, n, k): if k < 0 or n < k: return 0 if n >= len(self.fact): self.extend(n) return self.fact[n] * self.invfact[n - k] % self.MOD def nCk(self, n, k): if k < 0 or n < k: return 0 if n >= len(self.fact): self.extend(n) return (self.fact[n] * self.invfact[n - k] % self.MOD) * self.invfact[k] % self.MOD def nHk(self, n, k): if n == 0 and k == 0: return 1 return self.nCk(n + k - 1, k) def Catalan(self, n): return (self.nCk(2 * n, n) - self.nCk(2 * n, n - 1)) % self.MOD def nCk(n, k): return math.comb(n, k) def nCk_mod(n, k, mod = 998244353): if k < 0 or n < k: return 0 res = 1 for i in range(k): res *= (n - i) res %= mod res *= pow((k - i), -1, mod) res %= mod return res # end combination def mbs(a, key): ng = -1 ok = len(a) while abs(ok - ng) > 1: mid = (ok + ng) // 2 if a[mid] >= key: ok = mid else: ng = mid return ok def satlow(f, lower = 0, upper = 10**9): ng = lower ok = upper while abs(ok - ng) > 1: mid = (ok + ng) // 2 if f(mid): ok = mid else: ng = mid return ok def listsatlow(a, f): ng = -1 ok = len(a) while abs(ok - ng) > 1: mid = (ok + ng) // 2 if f(a[mid]): ok = mid else: ng = mid return ok _log=True def pex(con): pyn(con) exit() def yn(con, yes = 'Yes', no = 'No'): if con: return yes else: return no def pp(con, yes = 'Yes', no = 'No'): if con: print(yes) else: print(no) def pyn(con, yes = 'Yes', no = 'No'): if con: print(yes) else: print(no) def py(yes = 'Yes'): print(yes) def pn(no = 'No'): print(no) yes='Yes' no='No' v4 = [[-1, 0], [0, -1], [0, 1], [1, 0]] inf = float('inf') ans = inf cnt=0 #main n = ii() a = glm(n, 2) d = {} def p(now): if now in d.keys(): return d[now] win = False for i in range(n - 1): if win: break if now & (1 << i) != 0: continue for j in range(i + 1, n): if win: break if now & (1 << j) != 0: continue if a[i][0] != a[j][0] and a[i][1] != a[j][1]: continue new = now new |= (1 << i) new |= (1 << j) res = p(new) if not res: win = True if win: d[now] = True else: d[now] = False return d[now] if p(0): print('Takahashi') else: print('Aoki')
ConDefects/ConDefects/Code/abc354_e/Python/54730171
condefects-python_data_2202
from functools import lru_cache N = int(input()) A, B = [None]*N, [None]*N for i in range(N): A[i], B[i] = map(int, input().split()) @lru_cache(maxsize = None) def DFS(M, turn): res = False for i in range(N-1): for j in range(i+1, N): if M & 1<<i and M & 1<<j: if A[i] == A[j] or B[i] == B[j]: res = res or turn == DFS(M ^ 1<<i ^ 1<<j, not turn) if res: return turn else: return not turn print('Takahashi' if DFS((1<<N) - 1, True) else 'No') from functools import lru_cache N = int(input()) A, B = [None]*N, [None]*N for i in range(N): A[i], B[i] = map(int, input().split()) @lru_cache(maxsize = None) def DFS(M, turn): res = False for i in range(N-1): for j in range(i+1, N): if M & 1<<i and M & 1<<j: if A[i] == A[j] or B[i] == B[j]: res = res or turn == DFS(M ^ 1<<i ^ 1<<j, not turn) if res: return turn else: return not turn print('Takahashi' if DFS((1<<N) - 1, True) else 'Aoki')
ConDefects/ConDefects/Code/abc354_e/Python/54930119
condefects-python_data_2203
N = int(input()) A = list(map(lambda x:int(x)-1,input().split())) mod = 998244353 mv = 2*10**5+10 count = [0]*(mv) for i in A: count[i] += 1 ans = 0 dp = dict() dp[0] = 1 for i in range(mv): change = dict() value = [] for j in dp.keys(): cur = (count[i] + j) // 2 if cur not in change.keys(): change[cur] = dp[j] value.append(cur) else: change[cur] += dp[j] change[cur] %= mod nextdp = dict() maxv = max(value) now = 0 for j in range(maxv,-1,-1): if j in change.keys(): now += change[j] now %= mod nextdp[j] = now dp = nextdp print(dp[0]) N = int(input()) A = list(map(lambda x:int(x)-1,input().split())) mod = 998244353 mv = 2*10**5+65 count = [0]*(mv) for i in A: count[i] += 1 ans = 0 dp = dict() dp[0] = 1 for i in range(mv): change = dict() value = [] for j in dp.keys(): cur = (count[i] + j) // 2 if cur not in change.keys(): change[cur] = dp[j] value.append(cur) else: change[cur] += dp[j] change[cur] %= mod nextdp = dict() maxv = max(value) now = 0 for j in range(maxv,-1,-1): if j in change.keys(): now += change[j] now %= mod nextdp[j] = now dp = nextdp print(dp[0])
ConDefects/ConDefects/Code/arc160_c/Python/41479555
condefects-python_data_2204
# 2023-05-20 12:43:31 n = int(input()) A = list(map(int, input().split())) s = 4 * 10**5 + 10 B = [0] * s mod = 998244353 for a in A: B[a] += 1 dp = [1] for i in range(s): b = B[i] nl = b + (len(dp) - 1) // 2 + 1 + 1 ndp = [0] * nl for j in range(len(dp)): ndp[b] += dp[j] ndp[b + j // 2 + 1] -= dp[j] for j in range(1, nl): ndp[j] += ndp[j - 1] ndp[j] %= mod dp = ndp[:-1] print(dp[0]) # 2023-05-20 12:43:31 n = int(input()) A = list(map(int, input().split())) s = 4 * 10**5 + 10 B = [0] * s mod = 998244353 for a in A: B[a] += 1 dp = [1] for i in range(s): b = B[i] nl = b + (len(dp) - 1) // 2 + 1 + 1 ndp = [0] * nl for j in range(len(dp)): ndp[b] += dp[j] ndp[b] %= mod ndp[b + j // 2 + 1] -= dp[j] ndp[b + j // 2 + 1] %= mod for j in range(1, nl): ndp[j] += ndp[j - 1] ndp[j] %= mod dp = ndp[:-1] print(dp[0])
ConDefects/ConDefects/Code/arc160_c/Python/41526904
condefects-python_data_2205
MOD = 998244353 N = int(input()) A = list(map(int,input().split())) NX = 2 * 10 ** 5 + 100 X = [0] * NX for a in A: X[a] += 1 dp =[1] inc = 0 for i in range(1,NX): x = X[i] dp2 = [0] * ((x+inc)//2+1) tmp = 0 for j in reversed(range((x+inc)//2+1)): if j <= x // 2: tmp += dp[0] else: tmp += dp[j*2-x] dp2[j] = tmp dp = dp2 inc = (x + inc) //2 #print(i,dp) print(dp[0]) MOD = 998244353 N = int(input()) A = list(map(int,input().split())) NX = 2 * 10 ** 5 + 100 X = [0] * NX for a in A: X[a] += 1 dp =[1] inc = 0 for i in range(1,NX): x = X[i] dp2 = [0] * ((x+inc)//2+1) tmp = 0 for j in reversed(range((x+inc)//2+1)): if j <= x // 2: tmp += dp[0] tmp %= MOD else: tmp += dp[j*2-x] tmp %= MOD dp2[j] = tmp dp = dp2 inc = (x + inc) //2 #print(i,dp) print(dp[0])
ConDefects/ConDefects/Code/arc160_c/Python/41518740
condefects-python_data_2206
MOD = 998244353 M = 2*10**5+2 N = int(input()) A = list(map(int,input().split())) B = [0]*M for a in A: B[a] += 1 dp = [1] for i in range(1,M): b = B[i] S = [0]*((len(dp)-1+b)//2+2) for i in range(len(dp)): S[0] += dp[i] S[(b+i)//2+1] += -dp[i] #print(S) S[0] %= MOD for i in range(len(S)-1): S[i+1] += S[i] S[i+1] %= MOD dp = S[:-1] #print(b,dp) print(sum(dp)%MOD) MOD = 998244353 M = 2*10**5+30 N = int(input()) A = list(map(int,input().split())) B = [0]*M for a in A: B[a] += 1 dp = [1] for i in range(1,M): b = B[i] S = [0]*((len(dp)-1+b)//2+2) for i in range(len(dp)): S[0] += dp[i] S[(b+i)//2+1] += -dp[i] #print(S) S[0] %= MOD for i in range(len(S)-1): S[i+1] += S[i] S[i+1] %= MOD dp = S[:-1] #print(b,dp) print(sum(dp)%MOD)
ConDefects/ConDefects/Code/arc160_c/Python/41463787
condefects-python_data_2207
from math import log2 from collections import Counter import sys n, *alists = map(int, sys.stdin.read().split()) MOD = 998244353 if n == 1: print(1) exit() maxlen = max(alists) + int(log2(n)) li = [0] * (maxlen + 1) co = Counter(list(alists)) for k,v in co.items(): li[k] += v dp = [1] for i in range(1,maxlen): newdp = [0] * ((li[i] + len(dp))//2+2 ) for j, dpi in enumerate(dp): newdp[0] += dpi newdp[(li[i]+j)//2+1] -= dpi # print(i,j,newdp) newdp[0] %= MOD for k in range(len(newdp)-1): newdp[k+1] += newdp[k] newdp[k+1] %= MOD # print(newdp) dp = newdp print(sum(dp)) from math import log2 from collections import Counter import sys n, *alists = map(int, sys.stdin.read().split()) MOD = 998244353 if n == 1: print(1) exit() maxlen = max(alists) + int(log2(n)) li = [0] * (maxlen + 1) co = Counter(list(alists)) for k,v in co.items(): li[k] += v dp = [1] for i in range(1,maxlen): newdp = [0] * ((li[i] + len(dp))//2+2 ) for j, dpi in enumerate(dp): newdp[0] += dpi newdp[(li[i]+j)//2+1] -= dpi # print(i,j,newdp) newdp[0] %= MOD for k in range(len(newdp)-1): newdp[k+1] += newdp[k] newdp[k+1] %= MOD # print(newdp) dp = newdp print(sum(dp) % MOD)
ConDefects/ConDefects/Code/arc160_c/Python/42877627
condefects-python_data_2208
from collections import Counter MOD=998244353 N=int(input()) A=list(map(int, input().split())) M=max(A) C=Counter(A) dp=[1] for a in range(1,M+1): c=C[a] dp=[0]*c+dp ndp=[0]*(len(dp)//2+2) for i in range(len(dp)): ndp[i//2+1]-=dp[i] ndp[0]+=dp[i] ndp[i//2+1]%=MOD ndp[0]%=MOD for i in range(len(ndp)-1): ndp[i+1]+=ndp[i] ndp[i+1]%=MOD dp=ndp print(sum(dp)%MOD) from collections import Counter MOD=998244353 N=int(input()) A=list(map(int, input().split())) M=max(A)*2 C=Counter(A) dp=[1] for a in range(1,M+1): c=C[a] dp=[0]*c+dp ndp=[0]*(len(dp)//2+2) for i in range(len(dp)): ndp[i//2+1]-=dp[i] ndp[0]+=dp[i] ndp[i//2+1]%=MOD ndp[0]%=MOD for i in range(len(ndp)-1): ndp[i+1]+=ndp[i] ndp[i+1]%=MOD dp=ndp print(sum(dp)%MOD)
ConDefects/ConDefects/Code/arc160_c/Python/44003371
condefects-python_data_2209
import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd n = int(input()) a = list(map(int,input().split())) mod = 998244353 d = defaultdict(int) for i in range(n): d[a[i]] += 1 last = [1] tot = 1 for i in range(1, 2*10**5+10): cnt = len(last) - 1 new = [] di = d[i] mx = (cnt + di)//2 for j in range(mx+1): need = max(0,2*j-di) new.append(last[need]) for i in range(len(new)-1)[::-1]: new[i] += new[i+1] new[i] %= mod last = new print(last[0] % mod) import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd n = int(input()) a = list(map(int,input().split())) mod = 998244353 d = defaultdict(int) for i in range(n): d[a[i]] += 1 last = [1] tot = 1 for i in range(1, 3*10**5+10): cnt = len(last) - 1 new = [] di = d[i] mx = (cnt + di)//2 for j in range(mx+1): need = max(0,2*j-di) new.append(last[need]) for i in range(len(new)-1)[::-1]: new[i] += new[i+1] new[i] %= mod last = new print(last[0] % mod)
ConDefects/ConDefects/Code/arc160_c/Python/42565675
condefects-python_data_2210
import sys, random input = lambda : sys.stdin.readline().rstrip() write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x)) debug = lambda x: sys.stderr.write(x+"\n") YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18 LI = lambda v=0: list(map(lambda i: int(i)-v, input().split())); II=lambda : int(input()); SI=lambda : [ord(c)-ord("a") for c in input()] def debug(_l_): for s in _l_.split(): print(f"{s}={eval(s)}", end=" ") print() def dlist(*l, fill=0): if len(l)==1: return [fill]*l[0] ll = l[1:] return [dlist(*ll, fill=fill) for _ in range(l[0])] n = int(input()) p = LI(1) s = input() M = 998244353 v0 = p[0] def sub(v0): ans = 1 done = [0]*n # p[0] の v0 はとる if v0=="L": done[p[0]] = 1 else: done[(p[0]+1)%n] = 1 for i in range(1,n): if v0=="L": if s[p[i]]=="R" and not done[(p[i]+1)%n]: return 0 assert not done[p[i]] done[p[i]] = 1 if s[p[i]]=="?" and done[(p[i]+1)%n]: ans *= 2 ans %= M else: if s[p[i]]=="L" and not done[p[i]]: return 0 assert not done[(p[i]+1)%n] done[(p[i]+1)%n] = 1 if s[p[i]]=="?" and done[p[i]]: ans *= 2 ans %= M return ans if s[p[0]]=="?": ans = sub("L") + sub("R") else: ans = sub(s[p[0]]) print(ans) import sys, random input = lambda : sys.stdin.readline().rstrip() write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x)) debug = lambda x: sys.stderr.write(x+"\n") YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18 LI = lambda v=0: list(map(lambda i: int(i)-v, input().split())); II=lambda : int(input()); SI=lambda : [ord(c)-ord("a") for c in input()] def debug(_l_): for s in _l_.split(): print(f"{s}={eval(s)}", end=" ") print() def dlist(*l, fill=0): if len(l)==1: return [fill]*l[0] ll = l[1:] return [dlist(*ll, fill=fill) for _ in range(l[0])] n = int(input()) p = LI(1) s = input() M = 998244353 v0 = p[0] def sub(v0): ans = 1 done = [0]*n # p[0] の v0 はとる if v0=="L": done[p[0]] = 1 else: done[(p[0]+1)%n] = 1 for i in range(1,n): if v0=="L": if s[p[i]]=="R" and not done[(p[i]+1)%n]: return 0 assert not done[p[i]] done[p[i]] = 1 if s[p[i]]=="?" and done[(p[i]+1)%n]: ans *= 2 ans %= M else: if s[p[i]]=="L" and not done[p[i]]: return 0 assert not done[(p[i]+1)%n] done[(p[i]+1)%n] = 1 if s[p[i]]=="?" and done[p[i]]: ans *= 2 ans %= M return ans if s[p[0]]=="?": ans = sub("L") + sub("R") else: ans = sub(s[p[0]]) print(ans%M)
ConDefects/ConDefects/Code/arc175_a/Python/52999116
condefects-python_data_2211
N = int(input()) P = list(map(int, input().split())) S = input() ans_l = 1 ans_r = 1 visited = [False]*N for p in P: visited[p-1] = True if visited[p%(N)]: if S[p-1] == "?": ans_l *= 2 else: if S[p-1] == "R": ans_l *= 0 if visited[p-2]: if S[p-1] == "?": ans_r *= 2 else: if S[p-1] == "L": ans_r *= 0 ans_l %= 998244353 ans_r %= 998244353 #print(ans_l, ans_r, p, S[p-1]) print(ans_l+ans_r) N = int(input()) P = list(map(int, input().split())) S = input() ans_l = 1 ans_r = 1 visited = [False]*N for p in P: visited[p-1] = True if visited[p%(N)]: if S[p-1] == "?": ans_l *= 2 else: if S[p-1] == "R": ans_l *= 0 if visited[p-2]: if S[p-1] == "?": ans_r *= 2 else: if S[p-1] == "L": ans_r *= 0 ans_l %= 998244353 ans_r %= 998244353 #print(ans_l, ans_r, p, S[p-1]) print((ans_l+ans_r)%998244353)
ConDefects/ConDefects/Code/arc175_a/Python/53404790
condefects-python_data_2212
n = int(input()) oder = list(map(lambda x: int(x)-1, input().split())) lr = input() def calc(d): ret = 1 taken = [0] * n taken[oder[0]] = 1 for i in range(1, n): if taken[((oder[i] + (1 if d=='L' else (-1))) + n) % n] == 1: if lr[i] == "?": ret *= 2 ret %= 998244353 else: if lr[oder[i]] != d and lr[oder[i]] != "?": return 0 taken[oder[i]] = 1 return ret ans = 0 if lr[oder[0]] == "L": ans += calc('L') elif lr[oder[0]] == "R": ans += calc("R") else: ans += calc("L") ans += calc("R") print(ans % 998244353) n = int(input()) oder = list(map(lambda x: int(x)-1, input().split())) lr = input() def calc(d): ret = 1 taken = [0] * n taken[oder[0]] = 1 for i in range(1, n): if taken[((oder[i] + (1 if d=='L' else (-1))) + n) % n] == 1: if lr[oder[i]] == "?": ret *= 2 ret %= 998244353 else: if lr[oder[i]] != d and lr[oder[i]] != "?": return 0 taken[oder[i]] = 1 return ret ans = 0 if lr[oder[0]] == "L": ans += calc('L') elif lr[oder[0]] == "R": ans += calc("R") else: ans += calc("L") ans += calc("R") print(ans % 998244353)
ConDefects/ConDefects/Code/arc175_a/Python/51898575
condefects-python_data_2213
MOD = 998244353 N = int(input()) P = list(map(lambda x: int(x)-1, input().split())) S = input() def pow(a, b): if b==0: return 1 ret = pow((a**2)%MOD, b//2) if b%2: ret = ret*a%MOD return ret def countL(): cnt = 0 spoon = [False]*N for p in P: match S[p]: case "L": spoon[p] = True case "R": if not spoon[(p+1)%N]: return 0 spoon[p] = True case "?": if spoon[(p+1)%N]: cnt += 1 spoon[p] = True return pow(2,cnt) def countR(): cnt = 0 spoon = [False]*N for p in P: match S[p]: case "R": spoon[(p+1)%N] = True case "L": if not spoon[p]: return 0 spoon[(p+1)%N] = True case "?": if spoon[p]: cnt += 1 spoon[(p+1)%N] = True return pow(2,cnt) ans = 0 match S[P[0]]: case "L": ans = countL() case "R": ans = countR() case "?": ans = countL() + countR() print(ans) MOD = 998244353 N = int(input()) P = list(map(lambda x: int(x)-1, input().split())) S = input() def pow(a, b): if b==0: return 1 ret = pow((a**2)%MOD, b//2) if b%2: ret = ret*a%MOD return ret def countL(): cnt = 0 spoon = [False]*N for p in P: match S[p]: case "L": spoon[p] = True case "R": if not spoon[(p+1)%N]: return 0 spoon[p] = True case "?": if spoon[(p+1)%N]: cnt += 1 spoon[p] = True return pow(2,cnt) def countR(): cnt = 0 spoon = [False]*N for p in P: match S[p]: case "R": spoon[(p+1)%N] = True case "L": if not spoon[p]: return 0 spoon[(p+1)%N] = True case "?": if spoon[p]: cnt += 1 spoon[(p+1)%N] = True return pow(2,cnt) ans = 0 match S[P[0]]: case "L": ans = countL() case "R": ans = countR() case "?": ans = (countL() + countR())%MOD print(ans)
ConDefects/ConDefects/Code/arc175_a/Python/52650326
condefects-python_data_2214
MOD = 998244353 n = int(input()) p = list(map(lambda x: int(x) - 1, input().split())) s = list(input()) sp = [True for i in range(n)] ans1 = 1 for i in p: sp[i] = False if sp[(i + 1) % n]: if s[i] == "R": ans1 = 0 break else: if s[i] == "?": ans1 *= 2 ans1 %= MOD sp = [True for i in range(n)] ans2 = 1 for i in p: sp[(i + 1) % n] = False if sp[i]: if s[i] == "L": ans2 = 0 break else: if s[i] == "?": ans2 *= 2 ans2 %= MOD print(ans1 + ans2) MOD = 998244353 n = int(input()) p = list(map(lambda x: int(x) - 1, input().split())) s = list(input()) sp = [True for i in range(n)] ans1 = 1 for i in p: sp[i] = False if sp[(i + 1) % n]: if s[i] == "R": ans1 = 0 break else: if s[i] == "?": ans1 *= 2 ans1 %= MOD sp = [True for i in range(n)] ans2 = 1 for i in p: sp[(i + 1) % n] = False if sp[i]: if s[i] == "L": ans2 = 0 break else: if s[i] == "?": ans2 *= 2 ans2 %= MOD print((ans1 + ans2) % MOD)
ConDefects/ConDefects/Code/arc175_a/Python/52661518
condefects-python_data_2215
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random class segtree(): n=1 size=1 log=2 d=[0] op=None e=10**15 def __init__(self,V,OP,E): self.n=len(V) self.op=OP self.e=E self.log=(self.n-1).bit_length() self.size=1<<self.log self.d=[E for i in range(2*self.size)] for i in range(self.n): self.d[self.size+i]=V[i] for i in range(self.size-1,0,-1): self.update(i) def set(self,p,x): assert 0<=p and p<self.n p+=self.size self.d[p]=x for i in range(1,self.log+1): self.update(p>>i) def get(self,p): assert 0<=p and p<self.n return self.d[p+self.size] def prod(self,l,r): assert 0<=l and l<=r and r<=self.n sml=self.e smr=self.e l+=self.size r+=self.size while(l<r): if (l&1): sml=self.op(sml,self.d[l]) l+=1 if (r&1): smr=self.op(self.d[r-1],smr) r-=1 l>>=1 r>>=1 return self.op(sml,smr) def all_prod(self): return self.d[1] def max_right(self,l,f): assert 0<=l and l<=self.n assert f(self.e) if l==self.n: return self.n l+=self.size sm=self.e while(1): while(l%2==0): l>>=1 if not(f(self.op(sm,self.d[l]))): while(l<self.size): l=2*l if f(self.op(sm,self.d[l])): sm=self.op(sm,self.d[l]) l+=1 return l-self.size sm=self.op(sm,self.d[l]) l+=1 if (l&-l)==l: break return self.n def min_left(self,r,f): assert 0<=r and r<=self.n assert f(self.e) if r==0: return 0 r+=self.size sm=self.e while(1): r-=1 while(r>1 and (r%2)): r>>=1 if not(f(self.op(self.d[r],sm))): while(r<self.size): r=(2*r+1) if f(self.op(self.d[r],sm)): sm=self.op(self.d[r],sm) r-=1 return r+1-self.size sm=self.op(self.d[r],sm) if (r& -r)==r: break return 0 def update(self,k): self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def __str__(self): return str([self.get(i) for i in range(self.n)]) #sys.setrecursionlimit(10**9) #sys.set_int_max_str_digits(0) input = sys.stdin.readline #n = int(input()) #alist = list(map(int,input().split())) #alist = [] #s = input() n,m = map(int,input().split()) edge = [[] for i in range(n)] for i in range(m): u,v,w = map(int,input().split()) u-=1 v-=1 edge[u].append((v,w)) edge[v].append((u,w)) #for i in range(n): # alist.append(list(map(int,input().split()))) k = int(input()) a = list(map(int,input().split())) ans = [-1 for i in range(n)] for i in range(k): a[i] -= 1 ans[a[i]] = 0 day = int(input()) x = list(map(int,input().split())) st = segtree(x,max,-10**18) d = [] dist = [(10**18,10**18) for i in range(n)] for i in a: heapq.heappush(d,(-1,10**18,i)) dist[i] = (-1,10**18) while d: hiduke,kyori,now = heapq.heappop(d) if (hiduke,kyori) > dist[now]: continue if hiduke >= day-1: continue for to,cost in edge[now]: if dist[now][1] + cost <= x[dist[now][0] + 1]: new_day = dist[now][0] new_cost = dist[now][1] + cost else: def f(z): if z >= cost: return 0 else: return 1 if st.prod(dist[now][0]+1,day) < cost: new_day = 10**18 new_cost = 10**18 else: x_p = st.max_right(dist[now][0]+1,f) new_day = x_p new_cost = cost if dist[to] > (new_day,new_cost): dist[to] = (new_day,new_cost) heapq.heappush(d,(dist[to][0],dist[to][1],to)) for i in range(n): print(dist[i][0]+1 if dist[i][0] != 10**18 else -1) import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random class segtree(): n=1 size=1 log=2 d=[0] op=None e=10**15 def __init__(self,V,OP,E): self.n=len(V) self.op=OP self.e=E self.log=(self.n-1).bit_length() self.size=1<<self.log self.d=[E for i in range(2*self.size)] for i in range(self.n): self.d[self.size+i]=V[i] for i in range(self.size-1,0,-1): self.update(i) def set(self,p,x): assert 0<=p and p<self.n p+=self.size self.d[p]=x for i in range(1,self.log+1): self.update(p>>i) def get(self,p): assert 0<=p and p<self.n return self.d[p+self.size] def prod(self,l,r): assert 0<=l and l<=r and r<=self.n sml=self.e smr=self.e l+=self.size r+=self.size while(l<r): if (l&1): sml=self.op(sml,self.d[l]) l+=1 if (r&1): smr=self.op(self.d[r-1],smr) r-=1 l>>=1 r>>=1 return self.op(sml,smr) def all_prod(self): return self.d[1] def max_right(self,l,f): assert 0<=l and l<=self.n assert f(self.e) if l==self.n: return self.n l+=self.size sm=self.e while(1): while(l%2==0): l>>=1 if not(f(self.op(sm,self.d[l]))): while(l<self.size): l=2*l if f(self.op(sm,self.d[l])): sm=self.op(sm,self.d[l]) l+=1 return l-self.size sm=self.op(sm,self.d[l]) l+=1 if (l&-l)==l: break return self.n def min_left(self,r,f): assert 0<=r and r<=self.n assert f(self.e) if r==0: return 0 r+=self.size sm=self.e while(1): r-=1 while(r>1 and (r%2)): r>>=1 if not(f(self.op(self.d[r],sm))): while(r<self.size): r=(2*r+1) if f(self.op(self.d[r],sm)): sm=self.op(self.d[r],sm) r-=1 return r+1-self.size sm=self.op(self.d[r],sm) if (r& -r)==r: break return 0 def update(self,k): self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def __str__(self): return str([self.get(i) for i in range(self.n)]) #sys.setrecursionlimit(10**9) #sys.set_int_max_str_digits(0) input = sys.stdin.readline #n = int(input()) #alist = list(map(int,input().split())) #alist = [] #s = input() n,m = map(int,input().split()) edge = [[] for i in range(n)] for i in range(m): u,v,w = map(int,input().split()) u-=1 v-=1 edge[u].append((v,w)) edge[v].append((u,w)) #for i in range(n): # alist.append(list(map(int,input().split()))) k = int(input()) a = list(map(int,input().split())) ans = [-1 for i in range(n)] for i in range(k): a[i] -= 1 ans[a[i]] = 0 day = int(input()) x = list(map(int,input().split())) st = segtree(x,max,-10**18) d = [] dist = [(10**18,10**18) for i in range(n)] for i in a: heapq.heappush(d,(-1,10**18,i)) dist[i] = (-1,10**18) while d: hiduke,kyori,now = heapq.heappop(d) if (hiduke,kyori) > dist[now]: continue if hiduke >= day-1: continue for to,cost in edge[now]: if dist[now][1] + cost <= x[dist[now][0]]: new_day = dist[now][0] new_cost = dist[now][1] + cost else: def f(z): if z >= cost: return 0 else: return 1 if st.prod(dist[now][0]+1,day) < cost: new_day = 10**18 new_cost = 10**18 else: x_p = st.max_right(dist[now][0]+1,f) new_day = x_p new_cost = cost if dist[to] > (new_day,new_cost): dist[to] = (new_day,new_cost) heapq.heappush(d,(dist[to][0],dist[to][1],to)) for i in range(n): print(dist[i][0]+1 if dist[i][0] != 10**18 else -1)
ConDefects/ConDefects/Code/abc307_f/Python/51485146
condefects-python_data_2216
N,M=map(int, input().split()) E=[[] for _ in range(N+1)] V=[-1]*(N+1) V[0]=0;cost=[10**2]*(N+1);DD=[10**2]*(N+1) import heapq for i in range(M): a,b,t=map(int,input().split()) E[a].append((t,b));E[b].append((t,a)) K=int(input()) A=list(map(int, input().split())) L=int(input()) B=list(map(int, input().split())) hq=[] for a in A: E[0].append((0,a)) E[a].append((0,0)) cost[0]=0;DD[0]=0 T=[] for i in range(L+1): H=[] if i==0: heapq.heappush(hq,(0,0)) H.append(0) ky=0 else: ky=B[i-1] while T: c,now=heapq.heappop(T) if DD[now]!=c: continue if c<=ky: heapq.heappush(hq,(c,now)) H.append(now) cost[now]=c else: heapq.heappush(T,(c,now)) break #print(i,DD,cost,hq) while hq: c,now=heapq.heappop(hq) if cost[now]!=c: continue for d,nex in E[now]: if c+d>ky: if DD[nex]>d: DD[nex]=d heapq.heappush(T,(d,nex)) else: if cost[nex]>c+d: cost[nex]=c+d heapq.heappush(hq,(c+d,nex)) H.append(nex) for h in H: cost[h]=0 DD[h]=0 V[h]=i for v in V[1:]: print(v) N,M=map(int, input().split()) E=[[] for _ in range(N+1)] V=[-1]*(N+1) V[0]=0;cost=[10**15]*(N+1);DD=[10**15]*(N+1) import heapq for i in range(M): a,b,t=map(int,input().split()) E[a].append((t,b));E[b].append((t,a)) K=int(input()) A=list(map(int, input().split())) L=int(input()) B=list(map(int, input().split())) hq=[] for a in A: E[0].append((0,a)) E[a].append((0,0)) cost[0]=0;DD[0]=0 T=[] for i in range(L+1): H=[] if i==0: heapq.heappush(hq,(0,0)) H.append(0) ky=0 else: ky=B[i-1] while T: c,now=heapq.heappop(T) if DD[now]!=c: continue if c<=ky: heapq.heappush(hq,(c,now)) H.append(now) cost[now]=c else: heapq.heappush(T,(c,now)) break #print(i,DD,cost,hq) while hq: c,now=heapq.heappop(hq) if cost[now]!=c: continue for d,nex in E[now]: if c+d>ky: if DD[nex]>d: DD[nex]=d heapq.heappush(T,(d,nex)) else: if cost[nex]>c+d: cost[nex]=c+d heapq.heappush(hq,(c+d,nex)) H.append(nex) for h in H: cost[h]=0 DD[h]=0 V[h]=i for v in V[1:]: print(v)
ConDefects/ConDefects/Code/abc307_f/Python/48677305
condefects-python_data_2217
import heapq n,m=map(int,input().split()) g=[[] for _ in range(n+1)] for _ in range(m): u,v,w=map(int,input().split()) g[u].append([v,w]) g[v].append([u,w]) k=int(input()) a=list(map(int,input().split())) ans=[-1]*(n+1) d=[10**18]*(n+1) hq=[] new=[] for i in range(k): ans[a[i]]=0 d[a[i]]=0 new.append(a[i]) k=int(input()) a=list(map(int,input().split())) for i in range(k): while new: v=new.pop() for j,w in g[v]: if d[j]>w: d[j]=w heapq.heappush(hq,(w,j)) hq2=[] new=[] s=set() while hq: w,j=hq[0] if w!=d[j]: heapq.heappop(hq) continue if w<=a[i]: heapq.heappush(hq2,(w,j)) heapq.heappop(hq) d[j]=w else: break while hq2: w,j=heapq.heappop(hq2) if d[j]<w: continue s.add(j) d[j]=0 for q,ww in g[j]: if ww+w<=a[i] and ww+w<d[q]: heapq.heappush(hq2,(ww+w,q)) d[q]=ww+w for j in s: if ans[j]==-1: ans[j]=i+1 new.append(j) for i in range(1,n): print(ans[i]) import heapq n,m=map(int,input().split()) g=[[] for _ in range(n+1)] for _ in range(m): u,v,w=map(int,input().split()) g[u].append([v,w]) g[v].append([u,w]) k=int(input()) a=list(map(int,input().split())) ans=[-1]*(n+1) d=[10**18]*(n+1) hq=[] new=[] for i in range(k): ans[a[i]]=0 d[a[i]]=0 new.append(a[i]) k=int(input()) a=list(map(int,input().split())) for i in range(k): while new: v=new.pop() for j,w in g[v]: if d[j]>w: d[j]=w heapq.heappush(hq,(w,j)) hq2=[] new=[] s=set() while hq: w,j=hq[0] if w!=d[j]: heapq.heappop(hq) continue if w<=a[i]: heapq.heappush(hq2,(w,j)) heapq.heappop(hq) d[j]=w else: break while hq2: w,j=heapq.heappop(hq2) if d[j]<w: continue s.add(j) d[j]=0 for q,ww in g[j]: if ww+w<=a[i] and ww+w<d[q]: heapq.heappush(hq2,(ww+w,q)) d[q]=ww+w for j in s: if ans[j]==-1: ans[j]=i+1 new.append(j) for i in range(1,n+1): print(ans[i])
ConDefects/ConDefects/Code/abc307_f/Python/53719250
condefects-python_data_2218
n, m = map(int, input().split()) c = input().split() d = input().split() p = list(map(int, input().split())) ds = {d[i]: p[1 + i] for i in range(m)} s = 0 for i in c: if i not in ds: print(p[0]) else: s += ds[i] print(s) n, m = map(int, input().split()) c = input().split() d = input().split() p = list(map(int, input().split())) ds = {d[i]: p[1 + i] for i in range(m)} s = 0 for i in c: if i not in ds: s += p[0] else: s += ds[i] print(s)
ConDefects/ConDefects/Code/abc308_b/Python/45960039
condefects-python_data_2219
h, w = map(int, input().split()) r, c = map(int, input().split()) ans = 4 if r == 1: ans -= 1 if r == h: ans -= 1 if w == 1: ans -= 1 if w == c: ans -= 1 print(ans) h, w = map(int, input().split()) r, c = map(int, input().split()) ans = 4 if r == 1: ans -= 1 if r == h: ans -= 1 if c == 1: ans -= 1 if w == c: ans -= 1 print(ans)
ConDefects/ConDefects/Code/abc250_a/Python/54768832
condefects-python_data_2220
t=int(input()) for _ in range(t): A = list(map(int, input().split())) P = list(map(int, input().split())) s=sum(A)*3 ans=0 for i,j in enumerate(A): s-=(i+1)*j if s<=0: print(0) break if P[3]*2<=P[4]: print(s*P[3]) else: if s%2==0: print((s//2)*P[4]) else: print((s//2)*P[4]+min(P[3],P[4])) t=int(input()) for _ in range(t): A = list(map(int, input().split())) P = list(map(int, input().split())) s=sum(A)*3 ans=0 for i,j in enumerate(A): s-=(i+1)*j if s<=0: print(0) continue if P[3]*2<=P[4]: print(s*P[3]) else: if s%2==0: print((s//2)*P[4]) else: print((s//2)*P[4]+min(P[3],P[4]))
ConDefects/ConDefects/Code/arc174_b/Python/51697010
condefects-python_data_2221
N = int(input()) An = [] Pn = [] for _ in range(N): An.append(list(map(int, input().split()))) Pn.append(list(map(int, input().split()))) for A, P in zip(An, Pn): po = 0 for i, a in enumerate(A, 1): po -= (i-3) * a if po <= 0: print(0) continue q, r = divmod(po, 2) money = min(P[3]*2, P[4]) print(money * q + money * r) N = int(input()) An = [] Pn = [] for _ in range(N): An.append(list(map(int, input().split()))) Pn.append(list(map(int, input().split()))) for A, P in zip(An, Pn): po = 0 for i, a in enumerate(A, 1): po -= (i-3) * a if po <= 0: print(0) continue q, r = divmod(po, 2) money = min(P[3]*2, P[4]) print(money * q + min(P[3], P[4]) * r)
ConDefects/ConDefects/Code/arc174_b/Python/51471469
condefects-python_data_2222
# -*- coding: utf-8 -*- T=int(input()) for i in range(T): A=list(map(int,input().split())) P=list(map(int,input().split())) K=A[0]*-2+A[1]*-1+A[3]+A[4]*2 ans=0 if K<0: if P[3]<P[4]/2: ans=P[3]*abs(K) else: ans=P[4]*abs(K)//2 if K%2!=0: ans+=min(P[3],P[4]) print(ans) # -*- coding: utf-8 -*- T=int(input()) for i in range(T): A=list(map(int,input().split())) P=list(map(int,input().split())) K=A[0]*-2+A[1]*-1+A[3]+A[4]*2 ans=0 if K<0: if P[3]<P[4]/2: ans=P[3]*abs(K) else: ans=P[4]*(abs(K)//2) if K%2!=0: ans+=min(P[3],P[4]) print(ans)
ConDefects/ConDefects/Code/arc174_b/Python/51473065
condefects-python_data_2223
t = int(input()) for _ in range(t): A = list(map(int, input().split())) _, _, _, p4, p5 = map(int, input().split()) target = 2 * A[0] + A[1] - A[3] - 2 * A[4] if target <= 0: ans = 0 else: ans = min(target // 2 * p5, target * p4) if target % 2 != 0: ans += min(p5, p4) print(ans) t = int(input()) for _ in range(t): A = list(map(int, input().split())) _, _, _, p4, p5 = map(int, input().split()) target = 2 * A[0] + A[1] - A[3] - 2 * A[4] if target <= 0: ans = 0 else: ans = min(target // 2 * p5, target // 2 * p4 * 2) if target % 2 != 0: ans += min(p5, p4) print(ans)
ConDefects/ConDefects/Code/arc174_b/Python/52291293
condefects-python_data_2224
T = int(input()) for _ in range(T): A = list(map(int, input().split())) P = list(map(int, input().split())) num_reviews = sum(A) original_score = sum([A[i] * (i + 1) for i in range(5)]) # print(original_score) rhs = 3 * num_reviews - original_score if original_score >= 3 * num_reviews: print(0) continue def test(x): return 2 * x >= rhs ok = 10**18 ng = 0 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if test(mid): ok = mid else: ng = mid k5 = ok ans = k5 * P[4] def test2(x): return x >= rhs ok = 10**18 ng = 0 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if test2(mid): ok = mid else: ng = mid k4 = ok ans = min(ans, k4 * P[3]) def test3(x): return 2 * x >= rhs - 1 ok = 10**18 ng = 0 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if test2(mid): ok = mid else: ng = mid ans = min(ok * P[4] + P[3], ans) print(ans) T = int(input()) for _ in range(T): A = list(map(int, input().split())) P = list(map(int, input().split())) num_reviews = sum(A) original_score = sum([A[i] * (i + 1) for i in range(5)]) # print(original_score) rhs = 3 * num_reviews - original_score if original_score >= 3 * num_reviews: print(0) continue def test(x): return 2 * x >= rhs ok = 10**18 ng = 0 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if test(mid): ok = mid else: ng = mid k5 = ok ans = k5 * P[4] def test2(x): return x >= rhs ok = 10**18 ng = 0 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if test2(mid): ok = mid else: ng = mid k4 = ok ans = min(ans, k4 * P[3]) def test3(x): return 2 * x >= rhs - 1 ok = 10**18 ng = 0 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if test3(mid): ok = mid else: ng = mid ans = min(ok * P[4] + P[3], ans) print(ans)
ConDefects/ConDefects/Code/arc174_b/Python/53660002
condefects-python_data_2225
n = int(input()) for _ in range(n): arr = list(map(int, input().split())) brr = list(map(int, input().split())) avg = 0 sm = sum(arr) for i in range(5): avg += arr[i] * (i+1) #print(avg / sm) best_cost = 10**99 best = 10**99 l,r = 0, 10**20 for j in range(100): mid = (l+r) // 2 sav = avg + mid * 4 sam = sm + mid if sav / sam >= 3: l,r = l, mid best = min(best, mid) else: l,r = mid+1, r best_cost = min(best_cost, best * brr[3]) #print(best_cost, "BEST") best = 10**99 l,r = 0, 10**20 for j in range(100): mid = (l+r) // 2 sav = avg + mid * 5 sam = sm + mid if sav / sam >= 3: l,r = l, mid best = min(best, mid) else: l,r = mid+1, r best_cost = min(best_cost, best * brr[4]) #print(best_cost, "BEST") best = 10**99 l,r = 0, 10**20 for j in range(100): mid = (l+r) // 2 sav = avg + mid * 5 + 4 sam = sm + mid + 1 if sav / sam >= 3: l,r = l, mid best = min(best, mid) else: l,r = mid+1, r best_cost = min(best_cost, best * brr[4] + brr[3]) print(best_cost, "BEST") n = int(input()) for _ in range(n): arr = list(map(int, input().split())) brr = list(map(int, input().split())) avg = 0 sm = sum(arr) for i in range(5): avg += arr[i] * (i+1) #print(avg / sm) best_cost = 10**99 best = 10**99 l,r = 0, 10**20 for j in range(100): mid = (l+r) // 2 sav = avg + mid * 4 sam = sm + mid if sav / sam >= 3: l,r = l, mid best = min(best, mid) else: l,r = mid+1, r best_cost = min(best_cost, best * brr[3]) #print(best_cost, "BEST") best = 10**99 l,r = 0, 10**20 for j in range(100): mid = (l+r) // 2 sav = avg + mid * 5 sam = sm + mid if sav / sam >= 3: l,r = l, mid best = min(best, mid) else: l,r = mid+1, r best_cost = min(best_cost, best * brr[4]) #print(best_cost, "BEST") best = 10**99 l,r = 0, 10**20 for j in range(100): mid = (l+r) // 2 sav = avg + mid * 5 + 4 sam = sm + mid + 1 if sav / sam >= 3: l,r = l, mid best = min(best, mid) else: l,r = mid+1, r best_cost = min(best_cost, best * brr[4] + brr[3]) print(best_cost)#, "BEST")
ConDefects/ConDefects/Code/arc174_b/Python/51500083
condefects-python_data_2226
T = int(input()) for i in range(T): A = list(map(int, input().split())) P = list(map(int, input().split())) tmp = 0 for i in range(1, 6): tmp += (i-3)*A[i-1] if tmp >= 0: print(0) break x = (-tmp+1)//2 ans = -tmp*P[3] if 2*P[3]-P[4] >= 0: ans = min(ans, x*(2*P[3]-P[4])-tmp*(P[4]-P[3])) ans = min(ans, -tmp*P[4]) ans = min(ans, x*P[4]) print(ans) T = int(input()) for i in range(T): A = list(map(int, input().split())) P = list(map(int, input().split())) tmp = 0 for i in range(1, 6): tmp += (i-3)*A[i-1] if tmp >= 0: print(0) continue x = (-tmp+1)//2 ans = -tmp*P[3] if 2*P[3]-P[4] >= 0: ans = min(ans, x*(2*P[3]-P[4])-tmp*(P[4]-P[3])) ans = min(ans, -tmp*P[4]) ans = min(ans, x*P[4]) print(ans)
ConDefects/ConDefects/Code/arc174_b/Python/52256842
condefects-python_data_2227
N, M, P = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) B.sort() S = [B[0]] for j in range(1, M) : S.append(B[j] + S[j - 1]) res = 0 for i in range(N) : l, r = -1, M while l + 1 < r : m = (l + r) // 2 if A[i] + B[m] <= P : l = m else : r = m res += (S[l] + A[i] if l >= 0 else 0) + P * (M - r) print(res) N, M, P = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) B.sort() S = [B[0]] for j in range(1, M) : S.append(B[j] + S[j - 1]) res = 0 for i in range(N) : l, r = -1, M while l + 1 < r : m = (l + r) // 2 if A[i] + B[m] <= P : l = m else : r = m res += (S[l] + r * A[i] if l >= 0 else 0) + P * (M - r) print(res)
ConDefects/ConDefects/Code/abc321_d/Python/54470617
condefects-python_data_2228
n = int(input()) s: list[str] = [input().rstrip() for _ in range(n)] a = list(map(int, input().split())) ng = [[s[i].find(s[j]) != -1 or s[j].find(s[i]) != -1 for j in range(n)] for i in range(n)] import sys import ortools.linear_solver.pywraplp as lp solver = lp.Solver('SolveIntegerProblem', lp.Solver.CBC_MIXED_INTEGER_PROGRAMMING) x = [solver.IntVar(0, 1, 'x[%i]' % i) for i in range(n)] for i in range(n): for j in range(i+1, n): if ng[i][j]: solver.Add(x[i] + x[j] <= 1) solver.Maximize(solver.Sum([a[i] * x[i] for i in range(n)])) solver.set_time_limit(1200) status = solver.Solve() print(int(solver.Objective().Value())) if status == lp.Solver.OPTIMAL: print("Optimal", file=sys.stderr) else: print("Not optimal", file=sys.stderr) n = int(input()) s: list[str] = [input().rstrip() for _ in range(n)] a = list(map(int, input().split())) ng = [[s[i].find(s[j]) != -1 or s[j].find(s[i]) != -1 for j in range(n)] for i in range(n)] import sys import ortools.linear_solver.pywraplp as lp solver = lp.Solver('SolveIntegerProblem', lp.Solver.BOP_INTEGER_PROGRAMMING) x = [solver.IntVar(0, 1, 'x[%i]' % i) for i in range(n)] for i in range(n): for j in range(i+1, n): if ng[i][j]: solver.Add(x[i] + x[j] <= 1) solver.Maximize(solver.Sum([a[i] * x[i] for i in range(n)])) solver.set_time_limit(1200) status = solver.Solve() print(int(solver.Objective().Value())) if status == lp.Solver.OPTIMAL: print("Optimal", file=sys.stderr) else: print("Not optimal", file=sys.stderr)
ConDefects/ConDefects/Code/abc354_g/Python/53647241
condefects-python_data_2229
n, q = map(int,input().split()) T = list(map(int,input().split())) hanuke = [0] * (n + 1) for t in T: hanuke[t] ^= 1 print(n - hanuke.count(1)) print(hanuke) n, q = map(int,input().split()) T = list(map(int,input().split())) hanuke = [0] * (n + 1) for t in T: hanuke[t] ^= 1 print(n - hanuke.count(1)) #print(hanuke)
ConDefects/ConDefects/Code/abc350_b/Python/54727667
condefects-python_data_2230
s=[] for i in range(9): s.append(input()) ans=0 for k in range(8): for i in range(8-k): for j in range(8-k): if s[i][j]=="#" and s[i+k+1][j]=="#" and s[i][j+k+1]=="#" and s[i+k+1][j+k+1]=="#": ans+=1 for k in range(4): for i in range(7-2*k): for j in range(7-2*k): if s[i+k+1][j]=="#" and s[i][j+k+1]=="#" and s[i+1][j+2*(k+1)]=="#" and s[i+2*(k+1)][j+k+1]=="#": ans+=1 for i in range(6): for j in range(6): if s[i+1][j]=="#" and s[i][j+2]=="#" and s[i+2][j+3]=="#" and s[i+3][j+1]=="#": ans+=1 if s[i][j+1]=="#" and s[i+2][j]=="#" and s[i+1][j+3]=="#" and s[i+3][j+2]=="#": ans+=1 for i in range(3): for j in range(3): if s[i+4][j]=="#" and s[i][j+2]=="#" and s[i+6][j+4]=="#" and s[i+2][j+6]=="#": ans+=1 if s[i+2][j]=="#" and s[i][j+4]=="#" and s[i+6][j+2]=="#" and s[i+4][j+6]=="#": ans+=1 for i in range(5): for j in range(5): if s[i][j+1]=="#" and s[i+1][j+4]=="#" and s[i+3][j]=="#" and s[i+4][j+3]=="#": ans+=1 if s[i+1][j]=="#" and s[i+4][j+1]=="#" and s[i][j+3]=="#" and s[i+3][j+4]=="#": ans+=1 if s[0][2]=="#" and s[2][8]=="#" and s[6][0]=="#" and s[8][6]=="#": ans+=1 if s[2][0]=="#" and s[8][2]=="#" and s[0][6]=="#" and s[6][8]=="#": ans+=1 for k in range(4): for i in range(4-k): for j in range(4-k): if s[i][j+1]=="#" and s[i+1][j+5+k]=="#" and s[i+4+k][j]=="#" and s[i+5+k][j+4+k]=="#": ans+=1 if s[i+1][j]=="#" and s[i+5+k][j+1]=="#" and s[i][j+4+k]=="#" and s[i+4+k][j+5+k]=="#": ans+=1 for k in [3,5]: for i in range(9-2-k): for j in range(9-2-k): if s[i][j+2]=="#" and s[i+2][j+2+k]=="#" and s[i+k][j]=="#" and s[i+2+k][j+k]=="#": ans+=1 if s[i+2][j]=="#" and s[i+2+k][j+2]=="#" and s[i][j+k]=="#" and s[i+k][j+2+k]=="#": ans+=1 for k in [4,5]: for i in range(9-3-k): for j in range(9-3-k): if s[i][j+3]=="#" and s[i+3][j+3+k]=="#" and s[i+k][j]=="#" and s[i+3+k][j+k]=="#": ans+=1 if s[i+3][j]=="#" and s[i+3+k][j+3]=="#" and s[i][j+k]=="#" and s[i+k][j+3+k]=="#": ans+=1 print(ans) s=[] for i in range(9): s.append(input()) ans=0 for k in range(8): for i in range(8-k): for j in range(8-k): if s[i][j]=="#" and s[i+k+1][j]=="#" and s[i][j+k+1]=="#" and s[i+k+1][j+k+1]=="#": ans+=1 for k in range(4): for i in range(7-2*k): for j in range(7-2*k): if s[i+k+1][j]=="#" and s[i][j+k+1]=="#" and s[i+k+1][j+2*(k+1)]=="#" and s[i+2*(k+1)][j+k+1]=="#": ans+=1 for i in range(6): for j in range(6): if s[i+1][j]=="#" and s[i][j+2]=="#" and s[i+2][j+3]=="#" and s[i+3][j+1]=="#": ans+=1 if s[i][j+1]=="#" and s[i+2][j]=="#" and s[i+1][j+3]=="#" and s[i+3][j+2]=="#": ans+=1 for i in range(3): for j in range(3): if s[i+4][j]=="#" and s[i][j+2]=="#" and s[i+6][j+4]=="#" and s[i+2][j+6]=="#": ans+=1 if s[i+2][j]=="#" and s[i][j+4]=="#" and s[i+6][j+2]=="#" and s[i+4][j+6]=="#": ans+=1 for i in range(5): for j in range(5): if s[i][j+1]=="#" and s[i+1][j+4]=="#" and s[i+3][j]=="#" and s[i+4][j+3]=="#": ans+=1 if s[i+1][j]=="#" and s[i+4][j+1]=="#" and s[i][j+3]=="#" and s[i+3][j+4]=="#": ans+=1 if s[0][2]=="#" and s[2][8]=="#" and s[6][0]=="#" and s[8][6]=="#": ans+=1 if s[2][0]=="#" and s[8][2]=="#" and s[0][6]=="#" and s[6][8]=="#": ans+=1 for k in range(4): for i in range(4-k): for j in range(4-k): if s[i][j+1]=="#" and s[i+1][j+5+k]=="#" and s[i+4+k][j]=="#" and s[i+5+k][j+4+k]=="#": ans+=1 if s[i+1][j]=="#" and s[i+5+k][j+1]=="#" and s[i][j+4+k]=="#" and s[i+4+k][j+5+k]=="#": ans+=1 for k in [3,5]: for i in range(9-2-k): for j in range(9-2-k): if s[i][j+2]=="#" and s[i+2][j+2+k]=="#" and s[i+k][j]=="#" and s[i+2+k][j+k]=="#": ans+=1 if s[i+2][j]=="#" and s[i+2+k][j+2]=="#" and s[i][j+k]=="#" and s[i+k][j+2+k]=="#": ans+=1 for k in [4,5]: for i in range(9-3-k): for j in range(9-3-k): if s[i][j+3]=="#" and s[i+3][j+3+k]=="#" and s[i+k][j]=="#" and s[i+3+k][j+k]=="#": ans+=1 if s[i+3][j]=="#" and s[i+3+k][j+3]=="#" and s[i][j+k]=="#" and s[i+k][j+3+k]=="#": ans+=1 print(ans)
ConDefects/ConDefects/Code/abc275_c/Python/44917428
condefects-python_data_2231
N = int(input()) for n in range(N, 920) : s = str(n) a = int(s[0]) b = int(s[1]) c = int(s[2]) if a * b == b * c : print(n) break N = int(input()) for n in range(N, 920) : s = str(n) a = int(s[0]) b = int(s[1]) c = int(s[2]) if a * b == c : print(n) break
ConDefects/ConDefects/Code/abc326_b/Python/54408960
condefects-python_data_2232
N = int(input()) def like326_Number(i): i_hundred = int(i/100) i_ten = int((i%100)/10) i_one = int(i%10) if i_hundred*i_ten == i_one: return True else: return False for i in range(N,919): if like326_Number(i): print(i) exit() N = int(input()) def like326_Number(i): i_hundred = int(i/100) i_ten = int((i%100)/10) i_one = int(i%10) if i_hundred*i_ten == i_one: return True else: return False for i in range(N,920): if like326_Number(i): print(i) exit()
ConDefects/ConDefects/Code/abc326_b/Python/54706855
condefects-python_data_2233
N = int(input()) for i in range(N, 919): N_str = str(i) if int(N_str[0]) * int(N_str[1]) == int(N_str[2]): print(i) exit() N = int(input()) for i in range(N, 920): N_str = str(i) if int(N_str[0]) * int(N_str[1]) == int(N_str[2]): print(i) exit()
ConDefects/ConDefects/Code/abc326_b/Python/54769546
condefects-python_data_2234
n = int(input()) for i in range(919): if i <= 99: continue elif i < n: continue else: if int(str(i)[0]) * int(str(i)[1]) == int(str(i)[2]): print(i) exit() n = int(input()) for i in range(920): if i <= 99: continue elif i < n: continue else: if int(str(i)[0]) * int(str(i)[1]) == int(str(i)[2]): print(i) exit()
ConDefects/ConDefects/Code/abc326_b/Python/55009435
condefects-python_data_2235
n = int(input()) for i in range(n,919): c = str(i) if int(c[0])*int(c[1])==int(c[2]): print(i) exit() n = int(input()) for i in range(n,920): c = str(i) if int(c[0])*int(c[1])==int(c[2]): print(i) exit()
ConDefects/ConDefects/Code/abc326_b/Python/55135461
condefects-python_data_2236
N = int(input()) for i in range(N,917): s = str(i) if int(s[0]) * int(s[1]) == int(s[2]): print(i) exit() N = int(input()) for i in range(N,920): s = str(i) if int(s[0]) * int(s[1]) == int(s[2]): print(i) exit()
ConDefects/ConDefects/Code/abc326_b/Python/54935249
condefects-python_data_2237
n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) ans1 = 0 ans2 = 0 for i in range(n): if a[i] == b[i]: ans1 += 1 for i in range(n): for j in range(n): if a[i] == b[j]: ans2 += 1 print(ans1) print(ans2) n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) ans1 = 0 ans2 = 0 for i in range(n): if a[i] == b[i]: ans1 += 1 for i in range(n): for j in range(n): if i!=j and a[i] == b[j]: ans2 += 1 print(ans1) print(ans2)
ConDefects/ConDefects/Code/abc243_b/Python/44827583
condefects-python_data_2238
n = int(input()) A = [input() for _ in range(n)] D = [(1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1),(0,1),(1,1)] ans = [] for r in range(n): for c in range(n): for dr,dc in D: tmp = [] for i in range(n): tmp.append(A[(r+dr*i)%n][(c+dc*i)%n]) ans.append("".join(tmp)) ans.sort() print(ans[-1]) n = int(input()) A = [input() for _ in range(n)] D = [(1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1),(0,1),(1,1)] ans = [] for r in range(n): for c in range(n): for dr,dc in D: tmp = [] for i in range(n): tmp.append(A[(r+dr*i)%n][(c+dc*i)%n]) ans.append("".join(tmp)) ans.sort() print(ans[-1])
ConDefects/ConDefects/Code/abc258_b/Python/44828873
condefects-python_data_2239
n = int(input()) a = [list(input()) for _ in range(n)] l, m = [], "0" for i in range(n): for j in range(n): if a[i][j]>m: m = a[i][j] l = [[i, j]] elif a[i][j]==m: l.append([i, j]) ans = set() for i in l: for x in range(-1, 2, 1): for y in range(-1, 2, 1): if x==y==0: break b = "" for j in range(n): b = b + a[(i[0] + x*j)%n][(i[1] + y*j)%n] ans.add(int(b)) ans = list(ans) ans.sort() print(ans[-1]) n = int(input()) a = [list(input()) for _ in range(n)] l, m = [], "0" for i in range(n): for j in range(n): if a[i][j]>m: m = a[i][j] l = [[i, j]] elif a[i][j]==m: l.append([i, j]) ans = set() for i in l: for x in range(-1, 2, 1): for y in range(-1, 2, 1): if x==y==0: continue b = "" for j in range(n): b = b + a[(i[0] + x*j)%n][(i[1] + y*j)%n] ans.add(int(b)) ans = list(ans) ans.sort() print(ans[-1])
ConDefects/ConDefects/Code/abc258_b/Python/45801553
condefects-python_data_2240
import sys import pypyjit pypyjit.set_param('max_unroll_recursion=-1') from itertools import combinations, permutations, product, accumulate, groupby from collections import defaultdict, deque, Counter from functools import reduce from operator import add, mul import heapq as hq import bisect sys.setrecursionlimit(10**7) input = sys.stdin.readline N,S,T,A,B = map(int,input().split()) if T == 1: if S == 1: print(0) else: print(N*B) exit() ok = 1 ng = T def f(l): return (N*B + A*l*(l+1)//2)/(l+1) while ng - ok > 1: x = (ng+ok)//2 L = f(x) if x*A <= L: ok = x else: ng = x l = ok L = f(l) if T < S: print(L) elif (T-S) <= l: print((T-S)*A) else: print(L) import sys import pypyjit pypyjit.set_param('max_unroll_recursion=-1') from itertools import combinations, permutations, product, accumulate, groupby from collections import defaultdict, deque, Counter from functools import reduce from operator import add, mul import heapq as hq import bisect sys.setrecursionlimit(10**7) input = sys.stdin.readline N,S,T,A,B = map(int,input().split()) if T == 1: if S == 1: print(0) else: print(N*B) exit() ok = 0 ng = T def f(l): return (N*B + A*l*(l+1)//2)/(l+1) while ng - ok > 1: x = (ng+ok)//2 L = f(x) if x*A <= L: ok = x else: ng = x l = ok L = f(l) if T < S: print(L) elif (T-S) <= l: print((T-S)*A) else: print(L)
ConDefects/ConDefects/Code/abc224_g/Python/32872217
condefects-python_data_2241
n,s,t,a,b=map(int,input().split()) def f(l:int)->float: if l<=s<=t:return (t-s)*a sm=t*(t-l+1)-(t+l)*(t-l+1)/2 w=t-l+1 return a*sm/w+b+(n-w)*b/w l=1 r=t while r-l>2: n1=(2*l+r)//3 n2=(l+2*r)//3 if f(n1)>f(n2):l=n1 else:r=n2 ans=10**50 for i in range(l-5,r+5): if 1<=i<=t: ans=min(ans,f(i)) print("{:.50f}".format(ans)) n,s,t,a,b=map(int,input().split()) def f(l:int)->float: if l<=s<=t:return (t-s)*a sm=t*(t-l+1)-(t+l)*(t-l+1)/2 w=t-l+1 return a*sm/w+b+(n-w)*b/w l=1 r=t while r-l>2: n1=(2*l+r)//3 n2=(l+2*r)//3 if f(n1)>=f(n2):l=n1 else:r=n2 ans=10**50 for i in range(l-5,r+5): if 1<=i<=t: ans=min(ans,f(i)) print("{:.50f}".format(ans))
ConDefects/ConDefects/Code/abc224_g/Python/52137623
condefects-python_data_2242
N,S,T,A,B=map(int,input().split()) ans=N*B for i in range(1000000): cost=B*N cost+=(N-T)*ans line=min(T-1,ans//A) cost+=(T-line-1)*ans cost+=(line*(line+1)//2)*A cost/=N ans=cost if T-S<0: print('{:f}'.format(ans)) else: print('{:f}'.format(ans)) N,S,T,A,B=map(int,input().split()) ans=N*B for i in range(1000000): cost=B*N cost+=(N-T)*ans line=min(T-1,ans//A) cost+=(T-line-1)*ans cost+=(line*(line+1)//2)*A cost/=N ans=cost if T-S<0: print('{:f}'.format(ans)) else: print('{:f}'.format(min((T-S)*A,ans)))
ConDefects/ConDefects/Code/abc224_g/Python/46503439
condefects-python_data_2243
def expect(k): """expect""" global n, s, t, a, b p = t - k + 1 return b * (n / p) + a * (p - 1) / 2 n, s, t, a, b = [int(x) for x in input().split()] l = 1 r = t while r - l >= 3: d = (r - l) // 3 p1 = l + d * 1 p2 = l + d * 2 e1 = expect(p1) e2 = expect(p2) if e1 >= p2: l = p1 else: r = p2 # 0 <= r-l <=2 mn = l for i in range(l + 1, r + 1): if expect(i) < expect(mn): mn = i ans = expect(mn) if s <= t: ans = min(ans, (t - s) * a) print(ans) def expect(k): """expect""" global n, s, t, a, b p = t - k + 1 return b * (n / p) + a * (p - 1) / 2 n, s, t, a, b = [int(x) for x in input().split()] l = 1 r = t while r - l >= 3: d = (r - l) // 3 p1 = l + d * 1 p2 = l + d * 2 e1 = expect(p1) e2 = expect(p2) if e1 >= e2: l = p1 else: r = p2 # 0 <= r-l <=2 mn = l for i in range(l + 1, r + 1): if expect(i) < expect(mn): mn = i ans = expect(mn) if s <= t: ans = min(ans, (t - s) * a) print(ans)
ConDefects/ConDefects/Code/abc224_g/Python/27132818
condefects-python_data_2244
N, S, T, A, B = map(int, input().split()) def value(k): if k < S <= T: return A*(T-S)/2 elif k >= T: return float('inf') else: return B*N/(T-k)+A*(T-k-1)/2 l, r = 0, T if r-l == 1: print(min(value(0), value(1))) exit() if r-l == 2: print(min(value(0), value(1), value(2))) exit() while r-l > 2: m1 = l+(r-l)//3 m2 = r-(r-l)//3 if value(m1) >= value(m2): l = m1 else: r = m2 print(min(value(l), value(l+1), value(r))) N, S, T, A, B = map(int, input().split()) def value(k): if k < S <= T: return A*(T-S) elif k >= T: return float('inf') else: return B*N/(T-k)+A*(T-k-1)/2 l, r = 0, T if r-l == 1: print(min(value(0), value(1))) exit() if r-l == 2: print(min(value(0), value(1), value(2))) exit() while r-l > 2: m1 = l+(r-l)//3 m2 = r-(r-l)//3 if value(m1) >= value(m2): l = m1 else: r = m2 print(min(value(l), value(l+1), value(r)))
ConDefects/ConDefects/Code/abc224_g/Python/28236524
condefects-python_data_2245
N=int(input()) A=list(map(int,input().split())) for i in range(1,N,2): A[i]^=1 if A==[0]*N: print("Yes") ; exit() for i in range(N): if A[i]==1: break S=[j%2 for j in range(N)] idx=0 for k in range(i,N): if idx>=N: break if A[k]!=S[idx]: idx+=2 else: idx+=1 if idx>=N: print("No") else: print("Yes") N=int(input()) A=list(map(int,input().split())) for i in range(1,N,2): A[i]^=1 if A==[0]*N: print("Yes") ; exit() for i in range(N): if A[i]==1: break S=[j%2 for j in range(N)] idx=0 for k in range(i,N): if idx>=N: break if A[k]==S[idx]: idx+=2 else: idx+=1 if idx>=N: print("No") else: print("Yes")
ConDefects/ConDefects/Code/arc138_b/Python/39937104
condefects-python_data_2246
n=int(input()) a=list(map(int,input().split())) l=0 while l<n: if a[l]^(l&1): l+=1 else: break r=0 a+=[0] for i in range(l,n): r+=a[i]^a[i+1] print ("Yes" if l>=r else "No") n=int(input()) a=list(map(int,input().split())) l=0 while l<n: if a[l]==(l&1): l+=1 else: break r=0 a+=[0] for i in range(l,n): r+=a[i]^a[i+1] print ("Yes" if l>=r else "No")
ConDefects/ConDefects/Code/arc138_b/Python/45602873
condefects-python_data_2247
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() if a[0]: print("No") elif max(a) == 0: print("Yes") else: if a[0] == a[1] == 0: print("No") return j = 1 while j < n and a[j] != a[j-1]: j += 1 if j == n: print("Yes") return k = j while a[j+1] == a[k]: j += 1 from itertools import groupby c = len(list(groupby(a[j+1:]))) print("No" if c > k else "Yes") for _ in range(t): solve() 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() if a[0]: print("No") elif max(a) == 0: print("Yes") else: if a[0] == a[1] == 0: print("No") return j = 1 while j < n and a[j] != a[j-1]: j += 1 if j == n: print("Yes") return k = j while a[j+1] == a[k]: j += 1 from itertools import groupby c = len(list(groupby(a[j+1:]))) print("No" if c >= k else "Yes") for _ in range(t): solve()
ConDefects/ConDefects/Code/arc138_b/Python/39687485
condefects-python_data_2248
N = int(input()) A = list(map(int, input().split())) odd = [x for x in A if x%2==1] even = [x for x in A if x%2==0 and x != 0] odd.sort(reverse=True) even.sort(reverse=True) if len(odd) < 2 and len(even) < 2: print(-1) elif len(odd) < 2: print(even[0]+even[1]) elif len(even) < 2: print(odd[0]+odd[1]) else: print(max(even[0]+even[1], odd[0]+odd[1])) N = int(input()) A = list(map(int, input().split())) odd = [x for x in A if x%2==1] even = [x for x in A if x%2==0] odd.sort(reverse=True) even.sort(reverse=True) if len(odd) < 2 and len(even) < 2: print(-1) elif len(odd) < 2: print(even[0]+even[1]) elif len(even) < 2: print(odd[0]+odd[1]) else: print(max(even[0]+even[1], odd[0]+odd[1]))
ConDefects/ConDefects/Code/abc272_c/Python/45929207
condefects-python_data_2249
N = int(input()) A = list(map(int, input().split())) o = [] e = [] for a in A: if a % 2: o.append(a) else: e.append(a) if len(o) < 2 and len(e) < 2: print(-1) exit() co = o[-1] + o[-2] if len(o) >= 2 else -1 ce = e[-1] + e[-2] if len(e) >= 2 else -1 print(max(co,ce)) N = int(input()) A = list(map(int, input().split())) o = [] e = [] for a in A: if a % 2: o.append(a) else: e.append(a) if len(o) < 2 and len(e) < 2: print(-1) exit() o.sort() e.sort() co = o[-1] + o[-2] if len(o) >= 2 else -1 ce = e[-1] + e[-2] if len(e) >= 2 else -1 print(max(co,ce))
ConDefects/ConDefects/Code/abc272_c/Python/46144815
condefects-python_data_2250
N = int(input()) A = [int(x) for x in input().split()] odd = [-10000000000, -10000000000] even = [-10000000000, -10000000000] for ai in A: if ai % 2 == 0: even.append(ai) else: odd.append(ai) odd.sort() even.sort() print(max(odd[-1] + even[-1], odd[-1] + odd[-2], even[-1] + even[-2], -1)) N = int(input()) A = [int(x) for x in input().split()] odd = [-10000000000, -10000000000] even = [-10000000000, -10000000000] for ai in A: if ai % 2 == 0: even.append(ai) else: odd.append(ai) odd.sort() even.sort() print(max(odd[-1] + odd[-2], even[-1] + even[-2], -1))
ConDefects/ConDefects/Code/abc272_c/Python/45973568
condefects-python_data_2251
n = int(input()) a = list(map(int,input().split())) odd = [] even = [] for i in range(n): if a[i] % 2 == 0: even.append(a[i]) else: odd.append(a[i]) if len(odd) <= 1 and len(even) <= 1: print(-1) elif len(odd) <= 1: print(even[-1] + even[-2]) elif len(even) <= 1: print(odd[-1] + odd[-2]) else: print(max(even[-1] + even[-2], odd[-1] + odd[-2])) n = int(input()) a = list(map(int,input().split())) odd = [] even = [] for i in range(n): if a[i] % 2 == 0: even.append(a[i]) else: odd.append(a[i]) even.sort() odd.sort() if len(odd) <= 1 and len(even) <= 1: print(-1) elif len(odd) <= 1: print(even[-1] + even[-2]) elif len(even) <= 1: print(odd[-1] + odd[-2]) else: print(max(even[-1] + even[-2], odd[-1] + odd[-2]))
ConDefects/ConDefects/Code/abc272_c/Python/45985100
condefects-python_data_2252
N = int(input()) A = list(map(int, input().split())) even = [] #偶数 odd = [] #奇数 for i in range(N): #A[i]が偶数ならば if A[i]%2==0: even.append(A[i]) #A[i]が奇数ならば else: odd.append(A[i]) even.sort(reverse=True) odd.sort(reverse=True) ans = -1 if len(even)>=2: ans = max(ans, even[0]+even[1]) elif len(odd)>=2: ans = max(ans, odd[0]+odd[1]) print(ans) N = int(input()) A = list(map(int, input().split())) even = [] #偶数 odd = [] #奇数 for i in range(N): #A[i]が偶数ならば if A[i]%2==0: even.append(A[i]) #A[i]が奇数ならば else: odd.append(A[i]) even.sort(reverse=True) odd.sort(reverse=True) ans = -1 if len(even)>=2: ans = max(ans, even[0]+even[1]) if len(odd)>=2: ans = max(ans, odd[0]+odd[1]) print(ans)
ConDefects/ConDefects/Code/abc272_c/Python/45282989
condefects-python_data_2253
def resolve(): B = int(input()) for x in range(B+1): tmp = x**x if tmp==B: return x elif tmp>B: return -1 print(resolve()) def resolve(): B = int(input()) for x in range(1, B+1): tmp = x**x if tmp==B: return x elif tmp>B: return -1 print(resolve())
ConDefects/ConDefects/Code/abc327_b/Python/54757356
condefects-python_data_2254
B=int(input()) for i in range(20): if i**i==B: print(i) break if i**i>=10**18: print(-1) break B=int(input()) for i in range(1,20): if i**i==B: print(i) break if i**i>=10**18: print(-1) break
ConDefects/ConDefects/Code/abc327_b/Python/55103874
condefects-python_data_2255
n = int(input()) for i in range(n+1): if i**i > n: break if i**i == n: print(i) exit() print(-1) n = int(input()) for i in range(1,n+1): if i**i > n: break if i**i == n: print(i) exit() print(-1)
ConDefects/ConDefects/Code/abc327_b/Python/55112756
condefects-python_data_2256
B = int(input()) for x in range(18): if x**x == B: print(x) exit() print(-1) B = int(input()) for x in range(1,18): if x**x == B: print(x) exit() print(-1)
ConDefects/ConDefects/Code/abc327_b/Python/54706960
condefects-python_data_2257
B=int(input()) a=-1 for i in range(1,B): if i**i==B: a=i break print(a) B=int(input()) a=-1 for i in range(1,17): if i**i==B: a=i break print(a)
ConDefects/ConDefects/Code/abc327_b/Python/54789222
condefects-python_data_2258
B = int(input()) for A in range(1,15) : pow = 1 for j in range(A) : pow *= A if pow == B : print(A) exit() print(-1) B = int(input()) for A in range(1,16) : pow = 1 for j in range(A) : pow *= A if pow == B : print(A) exit() print(-1)
ConDefects/ConDefects/Code/abc327_b/Python/54881267
condefects-python_data_2259
B = int(input()) for i in range(19): if i ** i == B: print(i) exit() if i ** i > B: break print(-1) B = int(input()) for i in range(1, 19): if i ** i == B: print(i) exit() if i ** i > B: break print(-1)
ConDefects/ConDefects/Code/abc327_b/Python/55166023
condefects-python_data_2260
b = int(input()) for i in range(1, 15): if i**i == b: print(i) exit() print(-1) b = int(input()) for i in range(1, 16): if i**i == b: print(i) exit() print(-1)
ConDefects/ConDefects/Code/abc327_b/Python/55040351
condefects-python_data_2261
B=int(input()) Frag=-1 for i in range(200): X=i**i if B<X: break elif B==X: Frag=i break print(Frag) B=int(input()) Frag=-1 for i in range(1,200): X=i**i if B<X: break elif B==X: Frag=i break print(Frag)
ConDefects/ConDefects/Code/abc327_b/Python/54671379
condefects-python_data_2262
B = int(input()) i = 0 while pow(i,i) < B: i += 1 if pow(i,i) == B: print(i) else: print(-1) B = int(input()) i = 1 while pow(i,i) < B: i += 1 if pow(i,i) == B: print(i) else: print(-1)
ConDefects/ConDefects/Code/abc327_b/Python/54666596
condefects-python_data_2263
B = int(input()) for i in range(20): if i ** i == B: print(i) exit() print(-1) B = int(input()) for i in range(1, 20): if i ** i == B: print(i) exit() print(-1)
ConDefects/ConDefects/Code/abc327_b/Python/54721670
condefects-python_data_2264
# import sys # sys.setrecursionlimit(10**6) # import pypyjit # pypyjit.set_param("max_unroll_recursion=-1") # sys.set_int_max_str_digits(10**6) # mod = 998244353 # ds = [(-1,0),(0,1),(1,0),(0,-1)] # inf = float('inf') # ni,nj=i+di,j+dj # 0<=ni<H and 0<=nj<W # alph = 'abcdefghijklmnopqrstuvwxyz' def rint(offset=0,base=10): return list(map(lambda x: int(x, base)+offset, input().split())) def full(s, f=int, *args): return [full(s[1:], f) if len(s) > 1 else f(*args) for _ in range(s[0])] def shift(*args,offset=-1): return (a+offset for a in args) B, = rint() ans =-1 for A in range(16): if A**A == B : ans = A break print(ans) # import sys # sys.setrecursionlimit(10**6) # import pypyjit # pypyjit.set_param("max_unroll_recursion=-1") # sys.set_int_max_str_digits(10**6) # mod = 998244353 # ds = [(-1,0),(0,1),(1,0),(0,-1)] # inf = float('inf') # ni,nj=i+di,j+dj # 0<=ni<H and 0<=nj<W # alph = 'abcdefghijklmnopqrstuvwxyz' def rint(offset=0,base=10): return list(map(lambda x: int(x, base)+offset, input().split())) def full(s, f=int, *args): return [full(s[1:], f) if len(s) > 1 else f(*args) for _ in range(s[0])] def shift(*args,offset=-1): return (a+offset for a in args) B, = rint() ans =-1 for A in range(1,20): if A**A == B : ans = A break print(ans)
ConDefects/ConDefects/Code/abc327_b/Python/55112773
condefects-python_data_2265
b = int(input()) flag = False for i in range(17): if i**i == b: flag = True break print(i if flag else -1) b = int(input()) flag = False for i in range(1, 17): if i**i == b: flag = True break print(i if flag else -1)
ConDefects/ConDefects/Code/abc327_b/Python/55043539
condefects-python_data_2266
b = int(input()) ans = -1 for a in range(16): if a**a == b: ans = a break print(ans) b = int(input()) ans = -1 for a in range(1, 17): if a**a == b: ans = a break print(ans)
ConDefects/ConDefects/Code/abc327_b/Python/54902111
condefects-python_data_2267
b = int(input()) answer = -1 for i in range(1,15): if i**i == b: answer = i else: pass print(answer) b = int(input()) answer = -1 for i in range(1,16): if i**i == b: answer = i else: pass print(answer)
ConDefects/ConDefects/Code/abc327_b/Python/54929751
condefects-python_data_2268
MOD = 998244353 n, x, y, z = map(int, input().split()) x = abs(x) y = abs(y) z = abs(z) def factorial(n): fact = [1] * (n + 1) ifact = [0] * (n + 1) for i in range(1, n + 1): fact[i] = fact[i-1] * i % MOD ifact[n] = pow(fact[n], MOD - 2, MOD) for i in range(n, 0, -1): ifact[i-1] = ifact[i] * i % MOD return fact, ifact fact, ifact = factorial(n) def comb(n, r): if r < 0 or r > n: return 0 return fact[n] * ifact[r] % MOD * ifact[n-r] % MOD def f(a, b): b = abs(b) if a < b or (a - b) % 2: return 0 return comb(a, (a - b) // 2) ans = 0 for i in range(x, n, 2): t = comb(n, i) * f(i, x) % MOD t = t * f(n - i, y + z) % MOD t = t * f(n - i, y - z) % MOD ans = (ans + t) % MOD print(ans) MOD = 998244353 n, x, y, z = map(int, input().split()) x = abs(x) y = abs(y) z = abs(z) def factorial(n): fact = [1] * (n + 1) ifact = [0] * (n + 1) for i in range(1, n + 1): fact[i] = fact[i-1] * i % MOD ifact[n] = pow(fact[n], MOD - 2, MOD) for i in range(n, 0, -1): ifact[i-1] = ifact[i] * i % MOD return fact, ifact fact, ifact = factorial(n) def comb(n, r): if r < 0 or r > n: return 0 return fact[n] * ifact[r] % MOD * ifact[n-r] % MOD def f(a, b): b = abs(b) if a < b or (a - b) % 2: return 0 return comb(a, (a - b) // 2) ans = 0 for i in range(x, n + 1, 2): t = comb(n, i) * f(i, x) % MOD t = t * f(n - i, y + z) % MOD t = t * f(n - i, y - z) % MOD ans = (ans + t) % MOD print(ans)
ConDefects/ConDefects/Code/abc240_g/Python/35075785
condefects-python_data_2269
from math import gcd def distance(x1, y1, x2, y2, m): xa = x1 - x2 ya = y1 - y2 xb = x2 - x1 yb = y2 - y1 if xa == 0: ya //= abs(ya) yb //= abs(yb) elif ya == 0: xa //= abs(xa) xb //= abs(xb) else: g = gcd(xa, xb) xa //= g ya //= g xb //= g yb //= g m.add((xa, ya)) m.add((xb, yb)) def main(): n = int(input()) m = set() p = [] for _ in range(n): x, y = map(int, input().split()) p.append((x, y)) for i in range(n): for j in range(i + 1, n): distance(p[i][0], p[i][1], p[j][0], p[j][1], m) print(len(m)) if __name__ == '__main__': main() from math import gcd def distance(x1, y1, x2, y2, m): xa = x1 - x2 ya = y1 - y2 xb = x2 - x1 yb = y2 - y1 if xa == 0: ya //= abs(ya) yb //= abs(yb) elif ya == 0: xa //= abs(xa) xb //= abs(xb) else: g = gcd(xa, ya) xa //= g ya //= g xb //= g yb //= g m.add((xa, ya)) m.add((xb, yb)) def main(): n = int(input()) m = set() p = [] for _ in range(n): x, y = map(int, input().split()) p.append((x, y)) for i in range(n): for j in range(i + 1, n): distance(p[i][0], p[i][1], p[j][0], p[j][1], m) print(len(m)) if __name__ == '__main__': main()
ConDefects/ConDefects/Code/abc226_d/Python/53188054
condefects-python_data_2270
import sys from math import * from bisect import * def solve(): N = int(input()) A = list(map(int, input().split())) dp = [] Len = [0 for i in range(N)] for i in range(N): j = bisect_left(dp, A[i]) Len[i] = j + 1 if j < len(dp): dp[j] = A[i] else: dp.append(A[i]) O = max(Len) Max = [-1 for i in range(N + 2)] Max[O + 1] = 10000000000 ans = [] for i in range(N - 1, -1, -1): if Max[Len[i] + 1] > A[i]: ans.append(i + 1) Max[Len[i]] = max(Max[Len[i]], A[i]) print(len(ans)) ans = ans[::-1] print(*ans) for test in range(int(input())): solve() import sys from math import * from bisect import * def solve(): N = int(input()) A = list(map(int, input().split())) dp = [] Len = [0 for i in range(N)] for i in range(N): j = bisect_left(dp, A[i]) Len[i] = j + 1 if j < len(dp): dp[j] = A[i] else: dp.append(A[i]) O = max(Len) Max = [-1 for i in range(N + 2)] Max[O + 1] = 10000000000 ans = [] for i in range(N - 1, -1, -1): if Max[Len[i] + 1] > A[i]: ans.append(i + 1) Max[Len[i]] = max(Max[Len[i]], A[i]) print(len(ans)) ans = ans[::-1] print(*ans) for test in range(int(input())): solve()
ConDefects/ConDefects/Code/abc354_f/Python/54029773
condefects-python_data_2271
ImportType = 1 InputType = 1 ConstType = 1 if ImportType: import os, sys, random, threading from random import randint, choice, shuffle from copy import deepcopy from io import BytesIO, IOBase from types import GeneratorType from functools import lru_cache, reduce from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from itertools import accumulate, combinations, permutations from heapq import heapify, heappop, heappush, heappushpop from typing import Generic, Iterable, Iterator, TypeVar, Union, List from string import ascii_lowercase, ascii_uppercase, digits from math import ceil, comb, floor, sqrt, pi, factorial, gcd, log, log10, log2, inf from decimal import Decimal, getcontext from sys import stdin, stdout, setrecursionlimit if InputType: input = lambda: sys.stdin.readline().rstrip("\r\n") I = lambda: input() II = lambda: int(input()) MII = lambda: map(int, input().split()) LI = lambda: list(input().split()) LII = lambda: list(map(int, input().split())) GMI = lambda: map(lambda x: int(x) - 1, input().split()) LGMI = lambda: list(map(lambda x: int(x) - 1, input().split())) if ConstType: RD = random.randint(10 ** 9, 2 * 10 ** 9) MOD = 998244353 Y = "Yes" N = "No" def abc354_f(): for _ in range(II()): n = II() a = LII() pre = [0] * n suf = [0] * n g = [] for i, x in enumerate(a): idx = bisect_left(g, x) if idx < len(g): g[idx] = x else: g.append(x) pre[i] = idx + 1 g = [] for i in range(n - 1, -1, -1): v = -a[i] idx = bisect_left(g, v) if idx < len(g): g[idx] = v else: g.append(v) suf[i] = idx + 1 ans = [] for i in range(n): if pre[i] + suf[i] - 1 == len(g): ans.append(i + 1) print(*ans) def cf_486E(): n = II() a = LII() pre = [0] * n suf = [0] * n ans = ['1'] * n g = [] for i, x in enumerate(a): idx = bisect_left(g, x) if idx < len(g): g[idx] = x else: g.append(x) pre[i] = idx + 1 g = [] for i in range(n - 1, -1, -1): v = -a[i] idx = bisect_left(g, v) if idx < len(g): g[idx] = v else: g.append(v) suf[i] = idx + 1 cnt = [0] * (n + 1) for i in range(n): if pre[i] + suf[i] - 1 == len(g): ans[i] = '3' cnt[pre[i]] += 1 for i in range(n): if ans[i] == '3' and cnt[pre[i]] > 1: ans[i] = '2' print(len(ans)) print(''.join(ans)) return def main(): # cf_486E() abc354_f() return if __name__ == '__main__': main() ImportType = 1 InputType = 1 ConstType = 1 if ImportType: import os, sys, random, threading from random import randint, choice, shuffle from copy import deepcopy from io import BytesIO, IOBase from types import GeneratorType from functools import lru_cache, reduce from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from itertools import accumulate, combinations, permutations from heapq import heapify, heappop, heappush, heappushpop from typing import Generic, Iterable, Iterator, TypeVar, Union, List from string import ascii_lowercase, ascii_uppercase, digits from math import ceil, comb, floor, sqrt, pi, factorial, gcd, log, log10, log2, inf from decimal import Decimal, getcontext from sys import stdin, stdout, setrecursionlimit if InputType: input = lambda: sys.stdin.readline().rstrip("\r\n") I = lambda: input() II = lambda: int(input()) MII = lambda: map(int, input().split()) LI = lambda: list(input().split()) LII = lambda: list(map(int, input().split())) GMI = lambda: map(lambda x: int(x) - 1, input().split()) LGMI = lambda: list(map(lambda x: int(x) - 1, input().split())) if ConstType: RD = random.randint(10 ** 9, 2 * 10 ** 9) MOD = 998244353 Y = "Yes" N = "No" def abc354_f(): for _ in range(II()): n = II() a = LII() pre = [0] * n suf = [0] * n g = [] for i, x in enumerate(a): idx = bisect_left(g, x) if idx < len(g): g[idx] = x else: g.append(x) pre[i] = idx + 1 g = [] for i in range(n - 1, -1, -1): v = -a[i] idx = bisect_left(g, v) if idx < len(g): g[idx] = v else: g.append(v) suf[i] = idx + 1 ans = [] for i in range(n): if pre[i] + suf[i] - 1 == len(g): ans.append(i + 1) print(len(ans)) print(*ans) def cf_486E(): n = II() a = LII() pre = [0] * n suf = [0] * n ans = ['1'] * n g = [] for i, x in enumerate(a): idx = bisect_left(g, x) if idx < len(g): g[idx] = x else: g.append(x) pre[i] = idx + 1 g = [] for i in range(n - 1, -1, -1): v = -a[i] idx = bisect_left(g, v) if idx < len(g): g[idx] = v else: g.append(v) suf[i] = idx + 1 cnt = [0] * (n + 1) for i in range(n): if pre[i] + suf[i] - 1 == len(g): ans[i] = '3' cnt[pre[i]] += 1 for i in range(n): if ans[i] == '3' and cnt[pre[i]] > 1: ans[i] = '2' print(''.join(ans)) return def main(): # cf_486E() abc354_f() return if __name__ == '__main__': main()
ConDefects/ConDefects/Code/abc354_f/Python/54039651
condefects-python_data_2272
N,M,K = map(int,input().split()) C = list(map(int,input().split())) if K == 1: for i in range(N): print(M) exit() C += C m = 0 d = [0 for i in range(N)] for i in range(N): d[C[i]-1] += 1 CC = [0 for i in range(N)] use = [0 for i in range(N)] ans = 0 for r in range(N): c = C[r] - 1 CC[c] += 1 if CC[c] % K == 1: m += 1 use[c] += 1 ans += min(d[c],use[c]*K) if m == M: break print(ans) for l in range(1,N): c = C[l-1] - 1 CC[c] -= 1 if CC[c] % K == 0: use[c] -= 1 ans -= min(K,d[c] - use[c]*K) m -= 1 for i in range(1,N+1): if m == M: break r += 1 cc = C[r] - 1 CC[cc] += 1 if CC[cc] % K == 1: m += 1 ans += min(K,d[cc] - K*use[cc]) use[cc] += 1 if m == M: break if r == l + N - 1: break print(ans) N,M,K = map(int,input().split()) C = list(map(int,input().split())) if K == 1: for i in range(N): print(M) exit() C += C m = 0 d = [0 for i in range(N)] for i in range(N): d[C[i]-1] += 1 CC = [0 for i in range(N)] use = [0 for i in range(N)] ans = 0 for r in range(N): c = C[r] - 1 CC[c] += 1 if CC[c] % K == 1: m += 1 ans += min(d[c] - use[c]*K,K) use[c] += 1 if m == M: break print(ans) for l in range(1,N): c = C[l-1] - 1 CC[c] -= 1 if CC[c] % K == 0: use[c] -= 1 ans -= min(K,d[c] - use[c]*K) m -= 1 for i in range(1,N+1): if m == M: break r += 1 cc = C[r] - 1 CC[cc] += 1 if CC[cc] % K == 1: m += 1 ans += min(K,d[cc] - K*use[cc]) use[cc] += 1 if m == M: break if r == l + N - 1: break print(ans)
ConDefects/ConDefects/Code/abc337_f/Python/50099741
condefects-python_data_2273
from collections import defaultdict def solution(): N, M, K = map(int, input().split()) c_lst = list(map(lambda s: int(s) - 1, input().split())) cnt = defaultdict(int) for c in c_lst: cnt[c] += 1 c_lst *= 2 res = 0 # number of total balls in boxes within range [i,i+N-1] box = 0 # number of boxes currently being used within range [i,i+N-1] dp = [0] * N # dp[c] = number of color c balls in boxes within range [i,j] j = 0 for i in range(N): if i > 0: # print("remove at i={}".format(i)) dp[c_lst[i - 1]] -= 1 if dp[c_lst[i - 1]] % K == 0: box -= 1 res -= min(K, 1 + (cnt[c_lst[i - 1]] - dp[c_lst[i - 1]] - 1)) # print("remove more at i={} for {}".format(i, min(K, 1+(cnt[c_lst[i-1]]-dp[c_lst[i-1]]-1)))) while j < i + N and box < M: # print("scan i,j={}".format((i,j))) dp[c_lst[j]] += 1 if dp[c_lst[j]] % K == 1: box += 1 res += min(K, cnt[c_lst[j]] - dp[c_lst[j]] + 1) # print("include at i,j={} for {}".format((i,j), min(K, cnt[c_lst[j]]-dp[c_lst[j]]+1))) j += 1 print(res) return solution() from collections import defaultdict def solution(): N, M, K = map(int, input().split()) c_lst = list(map(lambda s: int(s) - 1, input().split())) cnt = defaultdict(int) for c in c_lst: cnt[c] += 1 c_lst *= 2 res = 0 # number of total balls in boxes within range [i,i+N-1] box = 0 # number of boxes currently being used within range [i,i+N-1] dp = [0] * N # dp[c] = number of color c balls in boxes within range [i,j] j = 0 for i in range(N): if i > 0: # print("remove at i={}".format(i)) dp[c_lst[i - 1]] -= 1 if dp[c_lst[i - 1]] % K == 0: box -= 1 res -= min(K, 1 + (cnt[c_lst[i - 1]] - dp[c_lst[i - 1]] - 1)) # print("remove more at i={} for {}".format(i, min(K, 1+(cnt[c_lst[i-1]]-dp[c_lst[i-1]]-1)))) while j < i + N and box < M: # print("scan i,j={}".format((i,j))) dp[c_lst[j]] += 1 if (dp[c_lst[j]] - 1) % K + 1 == 1: box += 1 res += min(K, cnt[c_lst[j]] - dp[c_lst[j]] + 1) # print("include at i,j={} for {}".format((i,j), min(K, cnt[c_lst[j]]-dp[c_lst[j]]+1))) j += 1 print(res) return solution()
ConDefects/ConDefects/Code/abc337_f/Python/49855272
condefects-python_data_2274
import bisect n, k = map(int, input().split()) a = list( map(int, input().split()) ) for i in range(k): a[i] -= 1 p = [] for _ in range(n): p.append(list(map(int, input().split()))) ans = 0 for i in range(n): minr = float("inf") for j in a: if i==j: continue dis0 = ( (p[i][0] - p[j][0])**2 + (p[i][1] - p[j][1])**2 ) minr = min(minr, dis0) ans = max(ans, minr) print(ans**0.5) import bisect n, k = map(int, input().split()) a = list( map(int, input().split()) ) for i in range(k): a[i] -= 1 p = [] for _ in range(n): p.append(list(map(int, input().split()))) ans = 0 for i in range(n): minr = float("inf") for j in a: dis0 = ( (p[i][0] - p[j][0])**2 + (p[i][1] - p[j][1])**2 ) minr = min(minr, dis0) ans = max(ans, minr) print(ans**0.5)
ConDefects/ConDefects/Code/abc255_b/Python/46036276
condefects-python_data_2275
import sys import os from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def I(): return input() def II(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(input().split()) def LII(): return list(map(int, input().split())) def GMI(): return map(lambda x: int(x) - 1, input().split()) #------------------------------FastIO--------------------------------- from bisect import * from heapq import * from collections import * from functools import * from itertools import * #dfs - stack# #check top!# def solve(): n = II() A = LII() B = LII() if A[0] != B[0]: print('NO') return ans = [] for i in range(n - 1, -1, -1): #print('A', i, A) #print('B', i, B) if A[i] == B[i]: continue else: bases = [] ind = [] for j in range(i): b = B[j] for x in bases: b = min(b, b ^ x) if b != 0: bases.append(b) ind.append(j) #print('bases', bases) x = A[i] ^ B[i] for b in bases: x = min(x, x ^ b) if x: print('No') return prod = 0 for b in B[:i]: prod ^= b prod ^= A[i] ^ B[i] sz = len(bases) j = sz - 1 while j >= 0 and prod > 0: x = prod for k in range(j + 1): x = min(x, x ^ bases[k]) if x == 0: ind_ = k break ans.append(ind[ind_] + 1) p = 0 nbases = [] for k in range(ind[ind_] + 1): B[k + 1] ^= B[k] prod ^= B[k] if k == ind[p]: b = B[k] for x in nbases: b = min(b, b ^ x) nbases.append(b) p += 1 nbases.pop() bases = nbases j = ind_ - 1 ans.append(i) for j in range(i): B[j + 1] ^= B[j] print('Yes') print(len(ans)) print(*[a + 1 for a in ans[::-1]]) for _ in range(1):solve() import sys import os from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def I(): return input() def II(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(input().split()) def LII(): return list(map(int, input().split())) def GMI(): return map(lambda x: int(x) - 1, input().split()) #------------------------------FastIO--------------------------------- from bisect import * from heapq import * from collections import * from functools import * from itertools import * #dfs - stack# #check top!# def solve(): n = II() A = LII() B = LII() if A[0] != B[0]: print('No') return ans = [] for i in range(n - 1, -1, -1): #print('A', i, A) #print('B', i, B) if A[i] == B[i]: continue else: bases = [] ind = [] for j in range(i): b = B[j] for x in bases: b = min(b, b ^ x) if b != 0: bases.append(b) ind.append(j) #print('bases', bases) x = A[i] ^ B[i] for b in bases: x = min(x, x ^ b) if x: print('No') return prod = 0 for b in B[:i]: prod ^= b prod ^= A[i] ^ B[i] sz = len(bases) j = sz - 1 while j >= 0 and prod > 0: x = prod for k in range(j + 1): x = min(x, x ^ bases[k]) if x == 0: ind_ = k break ans.append(ind[ind_] + 1) p = 0 nbases = [] for k in range(ind[ind_] + 1): B[k + 1] ^= B[k] prod ^= B[k] if k == ind[p]: b = B[k] for x in nbases: b = min(b, b ^ x) nbases.append(b) p += 1 nbases.pop() bases = nbases j = ind_ - 1 ans.append(i) for j in range(i): B[j + 1] ^= B[j] print('Yes') print(len(ans)) print(*[a + 1 for a in ans[::-1]]) for _ in range(1):solve()
ConDefects/ConDefects/Code/arc145_e/Python/33700944
condefects-python_data_2276
import sys import os from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def I(): return input() def II(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(input().split()) def LII(): return list(map(int, input().split())) def GMI(): return map(lambda x: int(x) - 1, input().split()) #------------------------------FastIO--------------------------------- from bisect import * from heapq import * from collections import * from functools import * from itertools import * #dfs - stack# #check top!# def solve(): n = II() A = LII() B = LII() ans = [] for i in range(n - 1, -1, -1): if A[i] == B[i]: continue else: bases = [] ind = [] for j in range(i): b = B[j] for x in bases: b = min(b, b ^ x) if b != 0: bases.append(b) ind.append(j) x = A[i] ^ B[i] for b in bases: x = min(x, x ^ b) if x: print('NO') return prod = 0 for b in B[:i]: prod ^= b prod ^= A[i] ^ B[i] sz = len(bases) j = sz - 1 while j >= 0 and prod > 0: x = prod for k in range(j + 1): x = min(x, x ^ bases[k]) if x == 0: ind_ = k break ans.append(ind[ind_] + 1) p = 0 nbases = [] for k in range(ind[ind_] + 1): B[k + 1] ^= B[k] prod ^= B[k] if k == ind[p]: b = B[k] for x in nbases: b = min(b, b ^ x) nbases.append(b) p += 1 nbases.pop() bases = nbases j = ind_ - 1 ans.append(i) for j in range(i): B[j + 1] ^= B[j] print('Yes') print(len(ans)) print(*[a + 1 for a in ans[::-1]]) for _ in range(1):solve() import sys import os from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def I(): return input() def II(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(input().split()) def LII(): return list(map(int, input().split())) def GMI(): return map(lambda x: int(x) - 1, input().split()) #------------------------------FastIO--------------------------------- from bisect import * from heapq import * from collections import * from functools import * from itertools import * #dfs - stack# #check top!# def solve(): n = II() A = LII() B = LII() ans = [] for i in range(n - 1, -1, -1): if A[i] == B[i]: continue else: bases = [] ind = [] for j in range(i): b = B[j] for x in bases: b = min(b, b ^ x) if b != 0: bases.append(b) ind.append(j) x = A[i] ^ B[i] for b in bases: x = min(x, x ^ b) if x: print('No') return prod = 0 for b in B[:i]: prod ^= b prod ^= A[i] ^ B[i] sz = len(bases) j = sz - 1 while j >= 0 and prod > 0: x = prod for k in range(j + 1): x = min(x, x ^ bases[k]) if x == 0: ind_ = k break ans.append(ind[ind_] + 1) p = 0 nbases = [] for k in range(ind[ind_] + 1): B[k + 1] ^= B[k] prod ^= B[k] if k == ind[p]: b = B[k] for x in nbases: b = min(b, b ^ x) nbases.append(b) p += 1 nbases.pop() bases = nbases j = ind_ - 1 ans.append(i) for j in range(i): B[j + 1] ^= B[j] print('Yes') print(len(ans)) print(*[a + 1 for a in ans[::-1]]) for _ in range(1):solve()
ConDefects/ConDefects/Code/arc145_e/Python/33700497
condefects-python_data_2277
s = input() ok = True for i in range(2, 16, 2): ok = s[i] == '0' and ok print('Yes' if ok else 'No') s = input() ok = True for i in range(1, 16, 2): ok = s[i] == '0' and ok print('Yes' if ok else 'No')
ConDefects/ConDefects/Code/abc323_a/Python/54475716
condefects-python_data_2278
s = input() ans = "Yes" for i in range(3,16): if i %2 == 1 and s[i] != "0": ans = "No" break print(ans) s = input() ans = "Yes" for i in range(16): if i %2 == 1 and s[i] != "0": ans = "No" break print(ans)
ConDefects/ConDefects/Code/abc323_a/Python/54490439
condefects-python_data_2279
S = input() count=0 for i in range(1, 16, 2): if S[i] == '0': break else: count+=1 if count==0: print("Yes") else: print("No") S = input() count=0 for i in range(1, 16, 2): if S[i] == '0': continue else: count+=1 if count==0: print("Yes") else: print("No")
ConDefects/ConDefects/Code/abc323_a/Python/54486886
condefects-python_data_2280
S = input().strip() for i in range(1, 9): if S[2 * i - 1] != 0: print("No") exit() print("Yes") S = input().strip() for i in range(1, 9): if S[2 * i - 1] != "0": print("No") exit() print("Yes")
ConDefects/ConDefects/Code/abc323_a/Python/54934224
condefects-python_data_2281
S = input() ans = True for i in range(1, 17, 2): if S[i-1]!='0': ans = False if ans: print("Yes") else: print("No") S = input() ans = True for i in range(1, 17, 2): if S[i]!='0': ans = False if ans: print("Yes") else: print("No")
ConDefects/ConDefects/Code/abc323_a/Python/54970529
condefects-python_data_2282
s = input() for i in range(2,2,16): if s[i] != "0": print("No") break else: print("Yes") s = input() for i in range(1,17,2): if s[i] != "0": print("No") break else: print("Yes")
ConDefects/ConDefects/Code/abc323_a/Python/54767961
condefects-python_data_2283
#https://atcoder.jp/contests/abc323/tasks/abc323_a S = input() flag = True for i, s in enumerate(S): if (i + 1) % 2 == 0: print((i + 1), s) if s == "0": continue else: flag = False break if flag: print("Yes") else: print("No") #https://atcoder.jp/contests/abc323/tasks/abc323_a S = input() flag = True for i, s in enumerate(S): if (i + 1) % 2 == 0: # print((i + 1), s) if s == "0": continue else: flag = False break if flag: print("Yes") else: print("No")
ConDefects/ConDefects/Code/abc323_a/Python/54513324
condefects-python_data_2284
from sys import stdin from sys import setrecursionlimit from heapq import * setrecursionlimit(10**8) input = lambda : stdin.readline().strip() N = int(input()) A = list(map(int, input().split())) thp = [[(0, -1)] for i in range(4 * N)] delt = set() def add(i, x, y, l, r, info): if l >= y or r <= x: return if l >= x and r <= y: # print(i, l, r) heappush(thp[i], info) return mid = l + r >> 1 add(i << 1, x, y, l, mid, info) add(i << 1 | 1, x, y, mid + 1, r, info) def query(i, x, l, r): while thp[i][0][1] in delt: heappop(thp[i]) res = -thp[i][0][0] if r - l == 1: return res mid = l + r >> 1 if mid > x: res = max(res, query(i << 1, x, l, mid)) else: res = max(res, query(i << 1 | 1, x, mid ,r)) return res q = int(input()) for i in range(q): op = list(map(int, input().split())) if op[0] == 1: l, r, x = op[1:] l -= 1 # print('add:') add(1, l, r, 0, N, (-x, i)) elif op[0] == 2: delt.add(op[1] - 1) else: x = op[1] - 1 # print('query:') print(max(A[x], query(1, x, 0, N))) from sys import stdin from sys import setrecursionlimit from heapq import * setrecursionlimit(10**8) input = lambda : stdin.readline().strip() N = int(input()) A = list(map(int, input().split())) thp = [[(0, -1)] for i in range(4 * N)] delt = set() def add(i, x, y, l, r, info): if l >= y or r <= x: return if l >= x and r <= y: # print(i, l, r) heappush(thp[i], info) return mid = l + r >> 1 add(i << 1, x, y, l, mid, info) add(i << 1 | 1, x, y, mid, r, info) def query(i, x, l, r): while thp[i][0][1] in delt: heappop(thp[i]) res = -thp[i][0][0] if r - l == 1: return res mid = l + r >> 1 if mid > x: res = max(res, query(i << 1, x, l, mid)) else: res = max(res, query(i << 1 | 1, x, mid ,r)) return res q = int(input()) for i in range(q): op = list(map(int, input().split())) if op[0] == 1: l, r, x = op[1:] l -= 1 # print('add:') add(1, l, r, 0, N, (-x, i)) elif op[0] == 2: delt.add(op[1] - 1) else: x = op[1] - 1 # print('query:') print(max(A[x], query(1, x, 0, N)))
ConDefects/ConDefects/Code/abc342_g/Python/50740919
condefects-python_data_2285
#ABC342G Retroactive Range Chmax_禊 import heapq import sys input = sys.stdin.readline #入力受取 N = int(input()) A = list(map(int,input().split())) #node[i]: 現在の最小値(正負反転して扱う点に注意) #delete[i]: ノードiのうち、削除待ちキュー logN = (N - 1).bit_length() size = 1 << logN node = [[] for _ in range(2 * size)] for i in range(N): node[i + size].append(-A[i]) delete = [[] for _ in range(2 * size)] #クエリに回答 Q = int(input()) query = [None] * Q for q in range(Q): t, *L = map(int, input().split()) if t == 1: Lt, Rt, x = L Lt -= 1 x = -x #正負を反転 query[q] = (Lt, Rt, x) #区間に加算 Lt, Rt = Lt + size, Rt + size while Lt < Rt: if Lt & 1: heapq.heappush(node[Lt], x) Lt += 1 if Rt & 1: Rt -= 1 heapq.heappush(node[Rt], x) Lt >>= 1 Rt >>= 1 if t == 2: i = L[0] - 1 Lt, Rt, x = query[i] #区間から削除 削除キューに入れる Lt, Rt = Lt + size, Rt + size while Lt < Rt: if Lt & 1: heapq.heappush(delete[Lt], x) Lt += 1 if Rt & 1: Rt -= 1 heapq.heappush(delete[Lt], x) Lt >>= 1 Rt >>= 1 if t == 3: i = L[0] - 1 #fold i += size ans = 0 while i > 0: #削除待ちキューを相殺 while node[i] and delete[i] and node[i][0] == delete[i][0]: heapq.heappop(node[i]) heapq.heappop(delete[i]) #答えに反映 if node[i]: ans = min(ans, node[i][0]) i >>= 1 print(- ans) #ABC342G Retroactive Range Chmax_禊 import heapq import sys input = sys.stdin.readline #入力受取 N = int(input()) A = list(map(int,input().split())) #node[i]: 現在の最小値(正負反転して扱う点に注意) #delete[i]: ノードiのうち、削除待ちキュー logN = (N - 1).bit_length() size = 1 << logN node = [[] for _ in range(2 * size)] for i in range(N): node[i + size].append(-A[i]) delete = [[] for _ in range(2 * size)] #クエリに回答 Q = int(input()) query = [None] * Q for q in range(Q): t, *L = map(int, input().split()) if t == 1: Lt, Rt, x = L Lt -= 1 x = -x #正負を反転 query[q] = (Lt, Rt, x) #区間に加算 Lt, Rt = Lt + size, Rt + size while Lt < Rt: if Lt & 1: heapq.heappush(node[Lt], x) Lt += 1 if Rt & 1: Rt -= 1 heapq.heappush(node[Rt], x) Lt >>= 1 Rt >>= 1 if t == 2: i = L[0] - 1 Lt, Rt, x = query[i] #区間から削除 削除キューに入れる Lt, Rt = Lt + size, Rt + size while Lt < Rt: if Lt & 1: heapq.heappush(delete[Lt], x) Lt += 1 if Rt & 1: Rt -= 1 heapq.heappush(delete[Rt], x) Lt >>= 1 Rt >>= 1 if t == 3: i = L[0] - 1 #fold i += size ans = 0 while i > 0: #削除待ちキューを相殺 while node[i] and delete[i] and node[i][0] == delete[i][0]: heapq.heappop(node[i]) heapq.heappop(delete[i]) #答えに反映 if node[i]: ans = min(ans, node[i][0]) i >>= 1 print(- ans)
ConDefects/ConDefects/Code/abc342_g/Python/50668241
condefects-python_data_2286
H, W = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(H)] Flag = True for a in range(H-1): for b in range(a+1, H): for c in range(W-1): for d in range(b+1, W): if A[a][c] + A[b][d] > A[b][c] + A[a][d]: Flag = False if Flag: print('Yes') else: print('No') H, W = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(H)] Flag = True for a in range(H-1): for b in range(a+1, H): for c in range(W-1): for d in range(c+1, W): if A[a][c] + A[b][d] > A[b][c] + A[a][d]: Flag = False if Flag: print('Yes') else: print('No')
ConDefects/ConDefects/Code/abc224_b/Python/46150770
condefects-python_data_2287
info = list(map(int, input().split())) n_rows = info[0] n_columns = info[1] matrix = [] for i in range(n_rows): matrix.append(list(map(int, input().split()))) does_satisfy = True for i in range(n_rows): for j in range(n_rows): if i < j: for l in range(n_columns): for k in range(n_columns): if l < k: if matrix[i][l] + matrix[j][k] > matrix[j][l] + matrix[i][k]: does_satisfy = False # print(matrix[i][l], matrix[j][k]) # print(matrix[j][l], matrix[i][k]) if does_satisfy: print('Yes') else: print('False') info = list(map(int, input().split())) n_rows = info[0] n_columns = info[1] matrix = [] for i in range(n_rows): matrix.append(list(map(int, input().split()))) does_satisfy = True for i in range(n_rows): for j in range(n_rows): if i < j: for l in range(n_columns): for k in range(n_columns): if l < k: if matrix[i][l] + matrix[j][k] > matrix[j][l] + matrix[i][k]: does_satisfy = False # print(matrix[i][l], matrix[j][k]) # print(matrix[j][l], matrix[i][k]) if does_satisfy: print('Yes') else: print('No')
ConDefects/ConDefects/Code/abc224_b/Python/44610651
condefects-python_data_2288
H, W = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(H)] flag = True for h in range(H): for w in range(W): for i in range(h+1, H): for j in range(w+1, W): if A[h][w] + A[i][j] < A[i][w] + A[h][j] : flag = False if flag : print("Yes") else : print("No") H, W = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(H)] flag = True for h in range(H): for w in range(W): for i in range(h+1, H): for j in range(w+1, W): if A[h][w] + A[i][j] > A[i][w] + A[h][j] : flag = False if flag : print("Yes") else : print("No")
ConDefects/ConDefects/Code/abc224_b/Python/45096470
condefects-python_data_2289
N = int(input()) A = list(map(int, input().split())) C = sorted(A) B = [] ans = 0 for i in range(int(N/2),N): ans += C[i] for i in range(N): if A[i] < C[int(N/2)]: B.append(1) else : B.append(-1) sum = 0 minimum = 0 minkey = -1 for i in range(N): sum += B[i] if sum < minimum: minimum = sum minkey = i print(minkey + 1) print(ans) N = int(input()) A = list(map(int, input().split())) C = sorted(A) B = [] ans = 0 for i in range(int(N/2),N): ans += C[i] for i in range(N): if A[i] < C[int(N/2)]: B.append(1) else : B.append(-1) sum = 0 minimum = 0 minkey = -1 for i in range(N): sum += B[i] if sum < minimum: minimum = sum minkey = i if minkey + 1 == N: minkey = 0 print(minkey + 1) print(ans)
ConDefects/ConDefects/Code/arc138_c/Python/31560360
condefects-python_data_2290
import sys n=int(input()) a=list(map(int,input().split())) sa=sorted(a) ans=0 for i in range(n//2,n): ans+=sa[i] med,s,id,mins,c=sa[n//2-1],0,0,n,0 for i,x in enumerate(a): if x<=med and c*2<n: s+=1 c+=1 else: s-=1 if s<mins: id,mins=i,s print(id+1,ans) import sys n=int(input()) a=list(map(int,input().split())) sa=sorted(a) ans=0 for i in range(n//2,n): ans+=sa[i] med,s,id,mins,c=sa[n//2-1],0,0,n,0 for i,x in enumerate(a): if x<=med and c*2<n: s+=1 c+=1 else: s-=1 if s<mins: id,mins=i,s print((id+1)%n,ans)
ConDefects/ConDefects/Code/arc138_c/Python/31278965
condefects-python_data_2291
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): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = (1 << 63)-1 inf = (1 << 31)-1 md = 10**9+7 # md = 998244353 n = II() aa = LI() ia = sorted(enumerate(aa), key=lambda x: x[1]) # pDB(ia) vv = [0]*n ans = 0 for i, a in ia[:n//2]: vv[i] = -1 for i, a in ia[n//2:]: vv[i] = 1 ans += a # pDB(vv) mx = 0 k = 0 s = 0 for i, v in enumerate(vv): s += v if s > mx: mx, k = s, (n-i-1)%n print(k, ans) 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): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = (1 << 63)-1 inf = (1 << 31)-1 md = 10**9+7 # md = 998244353 n = II() aa = LI() ia = sorted(enumerate(aa), key=lambda x: x[1]) # pDB(ia) vv = [0]*n ans = 0 for i, a in ia[:n//2]: vv[i] = -1 for i, a in ia[n//2:]: vv[i] = 1 ans += a # pDB(vv) mx = 0 k = 0 s = 0 for i, v in enumerate(vv): s += v if s > mx: mx, k = s, (i+1)%n print(k, ans)
ConDefects/ConDefects/Code/arc138_c/Python/30923012
condefects-python_data_2292
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 collections import deque, Counter as counter, defaultdict as ddict from bisect import bisect_left, bisect_right from heapq import heappush, heappop, heapify, heappushpop, heapreplace as heappoppush, nlargest, nsmallest from functools import lru_cache, reduce from itertools import count, cycle, accumulate, chain, groupby, islice, product, permutations, combinations, combinations_with_replacement inf = 3074457345618258602 sys.setrecursionlimit(2147483647) readline = sys.stdin.buffer.readline cache = lru_cache(None) def input(): return readline().rstrip().decode() def S(): return readline().rstrip().decode() def Ss(): return readline().rstrip().decode().split(' ') def I(): return int(readline()) def I1(): return int(readline()) - 1 def Is(): return [int(i) for i in readline().rstrip().split(b' ')] def I1s(): return [int(i) - 1 for i in readline().rstrip().split(b' ')] def F(): return float(readline()) def Fs(): return [float(i) for i in readline().rstrip().split(b' ')] n = I() a = Is() large = nlargest(n // 2, a) m = large[-1] s = sum(large) p = [None] * n cnt = 0 for i in range(n): cnt += a[i] >= m p[i] = (cnt - i, i) print((max(p)[1] + 1) % n, s) if __name__ == '__main__': main() 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 collections import deque, Counter as counter, defaultdict as ddict from bisect import bisect_left, bisect_right from heapq import heappush, heappop, heapify, heappushpop, heapreplace as heappoppush, nlargest, nsmallest from functools import lru_cache, reduce from itertools import count, cycle, accumulate, chain, groupby, islice, product, permutations, combinations, combinations_with_replacement inf = 3074457345618258602 sys.setrecursionlimit(2147483647) readline = sys.stdin.buffer.readline cache = lru_cache(None) def input(): return readline().rstrip().decode() def S(): return readline().rstrip().decode() def Ss(): return readline().rstrip().decode().split(' ') def I(): return int(readline()) def I1(): return int(readline()) - 1 def Is(): return [int(i) for i in readline().rstrip().split(b' ')] def I1s(): return [int(i) - 1 for i in readline().rstrip().split(b' ')] def F(): return float(readline()) def Fs(): return [float(i) for i in readline().rstrip().split(b' ')] n = I() a = Is() large = nlargest(n // 2, a) m = large[-1] s = sum(large) p = [None] * n cnt = 0 for i in range(n): cnt += a[i] >= m p[i] = (cnt - i // 2, i) print((max(p)[1] + 1) % n, s) if __name__ == '__main__': main()
ConDefects/ConDefects/Code/arc138_c/Python/31643804
condefects-python_data_2293
import itertools N,W = list(map(int,input().split())) A = list(map(int,input().split())) ans = set() for n in range(1,4): for ss in itertools.combinations(A,n): m = sum(ss) if(m < W): ans.add(m) print(len(ans)) import itertools N,W = list(map(int,input().split())) A = list(map(int,input().split())) ans = set() for n in range(1,4): for ss in itertools.combinations(A,n): m = sum(ss) if(m <= W): ans.add(m) print(len(ans))
ConDefects/ConDefects/Code/abc251_b/Python/46014786
condefects-python_data_2294
n, w = map(int, input().split()) an = list(map(int, input().split())) an.append(0) an.append(0) an.append(0) ans = set() n += 3 for i in range(n): for j in range(n): for k in range(n): total = an[i] + an[j] + an[k] if total != 0 and total < w and i != j and i != k and j != k: ans.add(total) print(len(ans)) n, w = map(int, input().split()) an = list(map(int, input().split())) an.append(0) an.append(0) an.append(0) ans = set() n += 3 for i in range(n): for j in range(n): for k in range(n): total = an[i] + an[j] + an[k] if total != 0 and total <= w and i != j and i != k and j != k: ans.add(total) print(len(ans))
ConDefects/ConDefects/Code/abc251_b/Python/45950112
condefects-python_data_2295
from itertools import combinations def ans_count(num_list, num, W, ans): result = 0 combinations_list = list(combinations(num_list, num)) for combination in combinations_list: # print(combination) if sum(combination) < W: ans.append(sum(combination)) return ans N,W = map(int,input().split()) num_map = map(int,input().split()) num_list = list(num_map) ans = [] if len(num_list) >= 1: ans = ans_count(num_list,1,W,ans) # print(str(1) + str(ans)) if len(num_list) >= 2: ans = ans_count(num_list,2,W,ans) # print(str(2) + str(ans)) if len(num_list) >= 3: ans = ans_count(num_list,3,W,ans) # print(str(3) + str(ans)) num_set = set(ans) print(len(num_set)) from itertools import combinations def ans_count(num_list, num, W, ans): result = 0 combinations_list = list(combinations(num_list, num)) for combination in combinations_list: # print(combination) if sum(combination) <= W: ans.append(sum(combination)) return ans N,W = map(int,input().split()) num_map = map(int,input().split()) num_list = list(num_map) ans = [] if len(num_list) >= 1: ans = ans_count(num_list,1,W,ans) # print(str(1) + str(ans)) if len(num_list) >= 2: ans = ans_count(num_list,2,W,ans) # print(str(2) + str(ans)) if len(num_list) >= 3: ans = ans_count(num_list,3,W,ans) # print(str(3) + str(ans)) num_set = set(ans) print(len(num_set))
ConDefects/ConDefects/Code/abc251_b/Python/45515530
condefects-python_data_2296
n, w = map(int, input().split()) a = list(map(int, input().split())) sum_set = set(a) #2個の和 for i in range(0, n-1): for j in range(i+1, n): s = a[i] + a[j] if s<=w: sum_set.add(s) #3個の和 for i in range(0, n-2): for j in range(i+1, n-1): for k in range(j+1, n): s = a[i] + a[j] + a[k] if s<=w: sum_set.add(s) cnt = 0 for i in range(w): if i in sum_set: cnt+=1 print(cnt) n, w = map(int, input().split()) a = list(map(int, input().split())) sum_set = set(a) #2個の和 for i in range(0, n-1): for j in range(i+1, n): s = a[i] + a[j] if s<=w: sum_set.add(s) #3個の和 for i in range(0, n-2): for j in range(i+1, n-1): for k in range(j+1, n): s = a[i] + a[j] + a[k] if s<=w: sum_set.add(s) cnt = 0 for i in range(w): if i+1 in sum_set: cnt+=1 print(cnt)
ConDefects/ConDefects/Code/abc251_b/Python/44443990
condefects-python_data_2297
from itertools import combinations def getIntMap(): return map(int, input().split()) def getIntList(): return list(map(int, input().split())) def main(): N, W = getIntMap() A = getIntList() res = set() for i in range(1, 4): for elem in combinations(A, i): if sum(elem) < W: res.add(sum(elem)) print(len(res)) if __name__ == "__main__": main() from itertools import combinations def getIntMap(): return map(int, input().split()) def getIntList(): return list(map(int, input().split())) def main(): N, W = getIntMap() A = getIntList() res = set() for i in range(1, 4): for elem in combinations(A, i): if sum(elem) <= W: res.add(sum(elem)) print(len(res)) if __name__ == "__main__": main()
ConDefects/ConDefects/Code/abc251_b/Python/44546670
condefects-python_data_2298
n = int(input()) a = "" for i in range(2*n): a += "1" if i%2 ==0 else "0" print(a) n = int(input()) a = "" for i in range(2*n+1): a += "1" if i%2 ==0 else "0" print(a)
ConDefects/ConDefects/Code/abc341_a/Python/54737422
condefects-python_data_2299
N, M = map(int, input().split()) MOD = 998244353 if N == 0 or M == 0: print(0) exit() A = [] n = 1 while n <= N: A.append(n) n *= 2 #print(A) B = [] NN = N + 1 for a in A: b = NN // a b1 = b // 2 b2 = b % 2 c = NN % a d = b1 * a + b2 * c d %= MOD B.append(d) B = B + [0] * 60 #print("B =", B) MM = bin(M) L = len(MM) - 2 ans = 0 #print("MM =", MM) #print("L =", L) for i in range(L): b = MM[-i-1] if b: ans += B[i] ans %= MOD print(ans) N, M = map(int, input().split()) MOD = 998244353 if N == 0 or M == 0: print(0) exit() A = [] n = 1 while n <= N: A.append(n) n *= 2 #print(A) B = [] NN = N + 1 for a in A: b = NN // a b1 = b // 2 b2 = b % 2 c = NN % a d = b1 * a + b2 * c d %= MOD B.append(d) B = B + [0] * 60 #print("B =", B) MM = bin(M) L = len(MM) - 2 ans = 0 #print("MM =", MM) #print("L =", L) for i in range(L): b = int(MM[-i-1]) if b: ans += B[i] ans %= MOD print(ans)
ConDefects/ConDefects/Code/abc356_d/Python/54865160
condefects-python_data_2300
N,M = map(int, input().split()) ans=0 for i in range(60): if (M>>i&1)==1: p=2**(i+1) r=N%p ans+=(N-r)/2 if (r>=2**i): ans+=(r-(2**i)+1) print(int(ans%998244353)) N,M = map(int, input().split()) ans=0 for i in range(60): if (M>>i&1)==1: p=2**(i+1) r=N%p ans+=N//p*2**i if (r>=2**i): ans+=(r-(2**i)+1) print(int(ans%998244353))
ConDefects/ConDefects/Code/abc356_d/Python/54706203