1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| from collections.abc import Generator import sys
def chunk_reader(func=int, chunk_size=1 << 15) -> Generator[int, None, None]: inp_cache = "" while True: chunk = sys.stdin.read(chunk_size) if not chunk: if inp_cache: yield func(inp_cache) del inp_cache break
for c in chunk: if c.isspace(): if inp_cache: yield func(inp_cache) del inp_cache inp_cache = "" else: inp_cache += c del c del chunk
inp = chunk_reader(chunk_size=1 << 18) n, m = next(inp), next(inp) a = [next(inp) for _ in range(n)]
|