input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import bisect import copy import heapq import sys import itertools import math import queue from functools import lru_cache input = sys.stdin.readline sys.setrecursionlimit(1000000) mod = 10 ** 9 + 7 def read_values(): return list(map(int, input().split())) def read_index(): return [int(x) - 1 for x in i...
import bisect import copy import heapq import sys import itertools import math import queue from functools import lru_cache input = sys.stdin.readline sys.setrecursionlimit(1000000) mod = 10 ** 9 + 7 def read_values(): return list(map(int, input().split())) def read_index(): return [int(x) - 1 for x in i...
p02632
import sys import math import collections sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): K = int(eval(input())) S = input().strip() MOD = 10 ** 9 + 7 fact = [1, 1] factinv = [1, 1] inv = [0, 1] def cmb(n, k, p): if (k < 0) or (n < k):...
import sys import math import collections sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): K = int(eval(input())) S = input().strip() MOD = 10 ** 9 + 7 fact = [1, 1] factinv = [1, 1] inv = [0, 1] def cmb(n, k, p): if (k < 0) or (n < k):...
p02632
# coding: utf-8 import sys from math import factorial stdin = sys.stdin ns = lambda: stdin.readline().rstrip() # ignore trailing spaces ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) def nCr(n,r): return (factorial(n) // factorial(r) // factorial(n - r)) def main(): ...
# coding: utf-8 import sys stdin = sys.stdin ns = lambda: stdin.readline().rstrip() # ignore trailing spaces ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) def main(): k = ni() s = ns() n = len(s) mod = 1000000007 ans = 0 inv25 = pow(25, mod-2, mod...
p02632
MOD = 10**9+7 factorial = [1] inverse_factorial = [0] def modpow(a, p): ans = 1 while p: if p&1 == 1: ans = (ans*a)%MOD a = (a*a)%MOD p >>= 1 return ans def nCr(n, r): if r == 0 or r == n: return 1 return (((factorial[n]*inverse_f...
MOD = 10**9+7 factorial = [1] inverse_factorial = [0] def modpow(a, p): ans = 1 while p: if p&1 == 1: ans = (ans*a)%MOD a = (a*a)%MOD p >>= 1 return ans def nCr(n, r): if r == 0 or r == n: return 1 return (((factorial[n]*inverse_f...
p02632
import sys sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python import math from copy import copy, deepcopy from copy import deepcopy as dcp from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from co...
import sys sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python import math from copy import copy, deepcopy from copy import deepcopy as dcp from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from co...
p02632
#!/usr/bin/env python3 import sys from functools import lru_cache sys.setrecursionlimit(1_000_002) MOD = 1000000007 # type: int def solve(K: int, S: str): ''' >>> solve(1, 'a') 51 ''' N = len(S) mf = ModFactorial(MOD, N+K+1) ans = 0 for k in range(K+1): ans...
#!/usr/bin/env python3 import sys MOD = 1000000007 # type: int def solve(K: int, S: str): ''' >>> solve(1, 'a') 51 ''' N = len(S) mf = ModFactorial(MOD, N+K+1) ans = 0 for k in range(K+1): ans = (ans + mf.combination(k+N-1, k) * pow(25, k, MOD) % MOD * pow(26...
p02632
import sys, math input = sys.stdin.readline rs = lambda: input().strip() ri = lambda: int(eval(input())) rl = lambda: list(map(int, input().split())) mod = 10**9 + 7 K = ri() S = rs() class CombMod: def __init__(self, N): self.fact = [1] self.rfact = [1] for i in range(1, N+1...
import sys, math input = sys.stdin.readline rs = lambda: input().strip() ri = lambda: int(eval(input())) rl = lambda: list(map(int, input().split())) mod = 10**9 + 7 K = ri() S = rs() class CombMod: def __init__(self, N): self.fact = [1] self.rfact = [1] for i in range(1, N+1...
p02632
def main(): import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) class Combination: def __init__(self, n_max, mod=10**9+7): # O(n_max + log(mod)) self.mod = mo...
def main(): import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) class Combination: def __init__(self, n_max, mod=10**9+7): # O(n_max + log(mod)) self.mod = mo...
p02632
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = float('inf') MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()] NI = lambda : int(sys.st...
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): MOD = 10**9 + 7 NI = lambda : int(sys.stdin.readline()) SI = lambda : sys.stdin.readline().rstrip() K = NI() S = SI() LS = len(S) f = [1] * (K+LS) r = [1] * (K+LS) c = 1 for i in range(1, K...
p02632
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): MOD = 10**9 + 7 NI = lambda : int(sys.stdin.readline()) SI = lambda : sys.stdin.readline().rstrip() K = NI() S = SI() LS = len(S) f = [1] * (K+LS) r = [1] * (K+LS) c = 1 for i in range(1, K...
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): MOD = 10**9 + 7 NI = lambda : int(sys.stdin.readline()) SI = lambda : sys.stdin.readline().rstrip() K = NI() S = SI() LS = len(S) f = [0] * (K+LS) r = [0] * (K+LS) f[0] = 1 r[0] = 1 c ...
p02632
import sys K = int(sys.stdin.readline()) S = sys.stdin.readline().rstrip('\n') # ## COMBINATION (MOD) ### N_MAX = 2*10**6 # 問題サイズに合わせて変えておく MOD = 10**9 + 7 fac = [1, 1] # 元テーブル facinv = [1, 1] # 逆元テーブル inv = [0, 1] # 逆元テーブル計算用テーブル for i in range(2, N_MAX + 1): fac.append((fac[-1] * i) % MOD) ...
import sys K = int(sys.stdin.readline()) S = sys.stdin.readline().rstrip('\n') # ## COMBINATION (MOD) ### N_MAX = 10**6 # 問題サイズに合わせて変えておく MOD = 10**9 + 7 inv = [0, 1] # 逆元テーブル計算用テーブル for i in range(2, N_MAX + 2): inv.append((-inv[MOD % i] * (MOD // i)) % MOD) # K 文字追加 ans = 0 ln = len(S) ...
p02632
import sys readline = sys.stdin.readline P = 10 ** 9 + 7 def mod_prod(a,b): return (a % P) * (b % P) % P def mod_fact(a): ret = 1 for i in range(a): ret = ret * (i + 1) % P return ret def mod_pow(a, n): ret = 1 while n > 0: if n % 2 == 1: ret = ret...
import sys readline = sys.stdin.readline P = 10 ** 9 + 7 def mod_prod(a,b): return (a % P) * (b % P) % P def mod_fact(a): ret = 1 for i in range(a): ret = ret * (i + 1) % P return ret def mod_pow(a, n): ret = 1 while n > 0: if n % 2 == 1: ret = ret...
p02632
N,M,Q = list(map(int,input().split())) a = list(map(int,input().split())) q = list(map(int,input().split())) t = [ 1 for i in range(N) ] i = 0 for m in range(M): if a[m] % 2 == 1: s = -1 else: s = 1 aa = a[m] while aa > 0: i = (i + s) % N if t[i] == 1:...
N,M,Q = list(map(int,input().split())) a = list(map(int,input().split())) q = list(map(int,input().split())) t = [ i for i in range(N) ] n = N i = 0 for aa in a: if aa % 2 == 1: i = (i - aa) % n else: i = (i + aa) % n del t[i] n -= 1 for i in q: if i in t: ...
p00296
from bisect import bisect_left as bl n, m, q = list(map(int, input().split())) lst = [i for i in range(n)] alst = list(map(int, input().split())) ind = 0 for a in alst: if a % 2 == 0: ind += a else: ind -= a ind = ind % len(lst) lst.pop(ind) ind = ind % len(lst) qlst = list(map(int, i...
from bisect import bisect_left as bl n, m, q = list(map(int, input().split())) lst = [i for i in range(n)] alst = list(map(int, input().split())) ind = 0 for a in alst: if a % 2 == 0: ind += a else: ind -= a ind = ind % len(lst) lst.pop(ind) ind = ind % len(lst) qlst = list(map(int, i...
p00296
import sys f = sys.stdin def is_odd(num): return num % 2 n,_,_ = list(map(int,f.readline().split()))#_は読み飛ばし a = list(map(int, f.readline().split())) q = list(map(int, f.readline().split())) students = list(range(n)) pos = 0 for ai in a: pos += -ai if is_odd(ai) else ai pos %= len(student...
import sys f = sys.stdin def is_odd(num): return num % 2 n,_,_ = list(map(int,f.readline().split()))#_は読み飛ばし a = list(map(int, f.readline().split())) q = list(map(int, f.readline().split())) s = list(range(n)) pos = 0 for ai in a: pos += -ai if is_odd(ai) else ai pos %= len(s) s.pop(...
p00296
n, m, _ = list(map(int, input().split())) n0 = n exem = [1] * n0 i = 0 for a in map(int, input().split()): is_even = not a & 1 a %= n if is_even: a = n - a c = 0 while a: c += 1 if exem[i - c]: a -= 1 exem[i - c] = 0 i = (i - c + 1) % n0 n -= ...
n, m, _ = list(map(int, input().split())) exem = list(range(n)) i = 0 for a in map(int, input().split()): is_odd = a & 1 i += -a if a & 1 else a i %= n exem.pop(i) n -= 1 for q in map(int, input().split()): print((int(q in exem)))
p00296
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0301 WA """ import sys from sys import stdin from collections import deque input = stdin.readline def main(args): # members = deque(list(range(10))) # numbers = [2, 6, 5, 18, 3] # queries = [3, 0, 5] ...
# -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0301 """ import sys from sys import stdin from collections import deque input = stdin.readline def main(args): # members = deque(list(range(10))) # numbers = [2, 6, 5, 18, 3] # queries = [3, 0, 5] N,...
p00296
from heapq import * class MultisetBIT: """ 最大値が小さい数について、その重複を許した集合を管理する。 最大値 maxvalue を受け取り、[0, maxvalue] を管理する。 閉区間で管理する。 """ # __slots__ = ["n", "k", "data"] def __init__(self, maxvalue): "内部では [1, maxvalue + 1] でもつ。" self.n = maxvalue + 1 self.k ...
from heapq import * class MultisetBIT: """ 最大値が小さい数について、その重複を許した集合を管理する。 最大値 maxvalue を受け取り、[0, maxvalue] を管理する。 閉区間で管理する。 """ __slots__ = ["n", "k", "data"] def __init__(self, maxvalue): "内部では [1, maxvalue + 1] でもつ。" self.n = maxvalue + 1 self.k = ...
p02575
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) #import math #from itertools import product, accumulate, combinations, product #im...
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) #import math #from itertools import product, accumulate, combinations, product #im...
p02575
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) #import math #from itertools import product, accumulate, combinations, product #im...
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read #from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) #import math #from itertools import product, accumulate, combinations, product #im...
p02575
from sys import stdin input = stdin.readline class SegTreeFlag(): def segFunc(self, x, y): return x+y def searchIndexFunc(self, val): return val > 0 def __init__(self, ide, init_val): n = len(init_val) self.ide_ele = ide self.num = 2**(n-1).bit_length() ...
from sys import stdin input = stdin.readline class SegTreeFlag(): def segFunc(self, x, y): return x+y def searchIndexFunc(self, val): return val > 0 def __init__(self, ide, init_val): n = len(init_val) self.ide_ele = ide self.num = 2**(n-1).bit_length() ...
p02575
from sys import stdin input = stdin.readline class SegTreeFlag(): def segFunc(self, x, y): return x+y def searchIndexFunc(self, val): return val > 0 def __init__(self, ide, init_val): n = len(init_val) self.ide_ele = ide self.num = 2**(n-1).bit_length() ...
from sys import stdin input = stdin.readline class SegTreeFlag(): def segFunc(self, x, y): return x+y def searchIndexFunc(self, val): return val > 0 def __init__(self, ide, init_val): n = len(init_val) self.ide_ele = ide self.num = 2**(n-1).bit_length() ...
p02575
from sys import stdin input = stdin.readline class SegTreeFlag(): def segFunc(self, x, y): return x+y def searchIndexFunc(self, val): return val > 0 def __init__(self, ide, init_val): n = len(init_val) self.ide_ele = ide self.num = 2**(n-1).bit_length() ...
from sys import stdin input = stdin.readline class SegTreeFlag(): def segFunc(self, x, y): return x+y def searchIndexFunc(self, val): return val > 0 def __init__(self, ide, init_val): n = len(init_val) self.ide_ele = ide self.num = 2**(n-1).bit_length() ...
p02575
from sys import stdin input = stdin.readline class SegTreeFlag(): def segFunc(self, x, y): return x+y def searchIndexFunc(self, val): return val > 0 def __init__(self, ide, init_val): n = len(init_val) self.ide_ele = ide self.num = 2**(n-1).bit_length() ...
from sys import stdin input = stdin.readline class SegTreeFlag(): def segFunc(self, x, y): return x+y def searchIndexFunc(self, val): return val > 0 def __init__(self, ide, init_val): n = len(init_val) self.ide_ele = ide self.num = 2**(n-1).bit_length() ...
p02575
from sys import stdin input = stdin.readline class SegTreeFlag(): def segFunc(self, x, y): return x+y def searchIndexFunc(self, val): return val > 0 def __init__(self, ide, init_val): n = len(init_val) self.ide_ele = ide self.num = 2**(n-1).bit_length() ...
from sys import stdin input = stdin.readline class SegTreeFlag(): def segFunc(self, x, y): return x+y def searchIndexFunc(self, val): return val > 0 def __init__(self, ide, init_val): n = len(init_val) self.ide_ele = ide self.num = 2**(n-1).bit_length() ...
p02575
''' 自宅用PCでの解答 ''' import math #import numpy as np import itertools import queue import bisect from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecurs...
''' 自宅用PCでの解答 ''' import math #import numpy as np import itertools import queue import bisect from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecurs...
p02575
import sys,heapq input = sys.stdin.buffer.readline h,w = list(map(int,input().split())) #dp[i] : iの時の最小右移動回数 dp = [0]*(w+1) #解候補 res = [0]*w #解候補から消されるもの anti = [] #Ai = {1:dp[i]はvalid 0:invalid} #A1 ... AnのBIT(1-indexed) BIT = [0]*(w+100) #A1 ~ Aiまでの和 O(logN) def BIT_query(idx): r...
import sys,heapq input = sys.stdin.buffer.readline h,w = list(map(int,input().split())) #dp[i] : iの時の最小右移動回数 dp = [0]*(w+1) dp[0] = -1 #解候補 res = [0]*w #解候補から消されるもの anti = [] #Ai = {1:dp[i]はvalid 0:invalid} #A1 ... AnのBIT(1-indexed) BIT = [0]*(w+1) #A1 ~ Aiまでの和 O(logN) def BIT_query(id...
p02575
import sys,heapq input = sys.stdin.buffer.readline def main(): h,w = list(map(int,input().split())) #dp[i] : iの時の最小右移動回数 dp = [0]*(w+1) #解候補 res = [0]*w #解候補から消されるもの anti = [] #Ai = {1:dp[i]はvalid 0:invalid} #A1 ... AnのBIT(1-indexed) BIT = [0]*(w...
import sys,heapq input = sys.stdin.buffer.readline def main(): h,w = list(map(int,input().split())) #dp[i] : iの時の最小右移動回数 dp = [0]*(w+1) #解候補 res = [0]*w #解候補から消されるもの anti = [] #Ai = {1:dp[i]はvalid 0:invalid} #A1 ... AnのBIT(1-indexed) BIT = [0]*(w...
p02575
import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in ...
from heapq import * import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): r...
p02575
from heapq import * import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): r...
from heapq import * import sys int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_...
p02575
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math #from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ###...
import sys input = sys.stdin.readline from collections import defaultdict def DD(arg): return defaultdict(arg) def int_log(n, a): count = 0 while n>=a: n //= a count += 1 return count H,W = list(map(int,input().split())) data = [list(map(int, input().split())) for _ in range(H)] clas...
p02575
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline H,W=list(map(int,input().split())) D=[tuple(map(int,input().split())) for i in range(H)] # 範囲更新、最大値取得の遅延セグ木と、範囲更新、最小値取得の遅延セグ木 seg_el=1<<((W+3).bit_length()) # Segment treeの台の要素数 SEG=[1<<30]*(2*seg_el) # 1-indexedなので、要素数2*s...
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline H,W=list(map(int,input().split())) # 範囲更新、最大値取得の遅延セグ木と、範囲更新、最小値取得の遅延セグ木 seg_el=1<<((W+3).bit_length()) # Segment treeの台の要素数 SEG=[1<<30]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化 LAZY=[0]*(2*seg_el) # 1-ind...
p02575
class LazySegmentTree: __slots__ = ["n", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"] def __init__(self, monoid_data, monoid_identity, operator_identity, func_monoid_monoid, func_monoid_operator, func_operator_operator): self.me = monoid_identity self.oe = operator_identity ...
class LazySegmentTree: __slots__ = ["n", "data", "lazy", "me", "oe", "fmm", "fmo", "foo"] def __init__(self, monoid_data, monoid_identity, operator_identity, func_monoid_monoid, func_monoid_operator, func_operator_operator): self.me = monoid_identity self.oe = operator_identity ...
p02575
import sys input = lambda: sys.stdin.readline().rstrip() class SegmentTree(): def __init__(self, init, unitX, unitA, f, g, h): self.f = f # (X, X) -> X self.g = g # (X, A, size) -> X self.h = h # (A, A) -> A self.unitX = unitX self.unitA = unitA self.f = f ...
import sys input = lambda: sys.stdin.readline().rstrip() class SegmentTree1(): def __init__(self, init, unitX, unitA, f, g, h): self.f = f # (X, X) -> X self.g = g # (X, A, size) -> X self.h = h # (A, A) -> A self.unitX = unitX self.unitA = unitA self.f =...
p02575
import sys input = lambda: sys.stdin.readline().rstrip() class SegmentTree1(): def __init__(self, init, unitX, unitA, f, g, h): self.f = f # (X, X) -> X self.g = g # (X, A, size) -> X self.h = h # (A, A) -> A self.unitX = unitX self.unitA = unitA self.f =...
import sys input = lambda: sys.stdin.readline().rstrip() class SegmentTree1(): def __init__(self, init, unitX, unitA, f, g, h): self.f = f # (X, X) -> X self.g = g # (X, A, size) -> X self.h = h # (A, A) -> A self.unitX = unitX self.unitA = unitA self.f =...
p02575
import sys input = lambda: sys.stdin.readline().rstrip() class SegmentTree1(): def __init__(self, init, unitX, unitA, f, g, h): self.f = f # (X, X) -> X self.g = g # (X, A, size) -> X self.h = h # (A, A) -> A self.unitX = unitX self.unitA = unitA self.f =...
import sys input = lambda: sys.stdin.readline().rstrip() class SegmentTree1(): def __init__(self, init, unitX, unitA, f, g, h): self.f = f # (X, X) -> X self.g = g # (X, A, size) -> X self.h = h # (A, A) -> A self.unitX = unitX self.unitA = unitA self.f =...
p02575
import sys input = lambda: sys.stdin.readline().rstrip() class SegmentTreeDual(): def __init__(self, init, unitX, unitA, g, h): self.g = g # (X, A, size) -> X self.h = h # (A, A) -> A self.unitA = unitA if type(init) == int: self.n = init self.n = 1...
import sys input = lambda: sys.stdin.readline().rstrip() class SegmentTreeDual(): def __init__(self, init, unitX, unitA, g, h): self.g = g # (X, A, size) -> X self.h = h # (A, A) -> A self.unitA = unitA if type(init) == int: self.n = init self.n = 1...
p02575
def collatz(n): c = 0 while n > 1: if n%2: n = 3*n+1 else: n /= 2 c += 1 return c while True: n = int(input()) if n == 0: break print(collatz(n))
def f(n): c=0 while n>1: if n%2:n=3*n+1 else:n /= 2 c += 1 print(c) while 1: n=eval(input()) if n==0:break f(n)
p00158
import sys for line in sys.stdin: l = [int(i) for i in line.split(' ')] print(len(str(l[0] + l[1])))
import sys for s in sys.stdin: a,b = list(map(int,s.split())) print(len(str(a+b)))
p00002
import math while True: try: line = input().split(" ") a = int(line[0]) b = int(line[1]) print((int(math.log10(a+b))+1)) except: break
import math while True: try: line = input().split(" ") print((int(math.log10(int(line[0])+int(line[1])))+1)) except: break
p00002
while True: try: print((len(str(sum(map(int, input().split())))))) except EOFError: break
import sys [print(len(str(y[0] + y[1]))) for y in [[int(z) for z in x.split()] for x in sys.stdin]]
p00002
import sys from math import log10 for line in sys.stdin: a, b = list(map(int, line.split())) digitNumber = int(log10((a + b))) + 1 print(digitNumber)
import sys for line in sys.stdin: a, b = list(map(int, line.split())) digitNumber = len(str(a + b)) print(digitNumber)
p00002
import sys strs = sys.stdin.readlines() for s in strs: a, b = list(map(int, s.split())) print((len(str(a + b))))
import sys for line in sys.stdin: a, b = list(map(int, line.split())) print((len(str(a + b))))
p00002
import sys a=[map(int,i.split()) for i in sys.stdin] [print(len(str(b+c))) for b,c in a]
import sys for a in sys.stdin: b,c=list(map(int,a.split())) d=len(str(b+c)) print(d)
p00002
import sys for a in sys.stdin: b,c=list(map(int,a.split())) d=len(str(b+c)) print(d)
import sys a=[map(int,i.split())for i in sys.stdin] [print(len(str(b+c)))for b,c in a]
p00002
import sys for line in sys.stdin: x, y = list(map(int, line.split())) print((len(str(x+y))))
import sys [print(len(str(sum(map(int, line.split()))))) for line in sys.stdin]
p00002
import sys for s in sys.stdin: print(len(str(sum(map(int,s.split())))))
import sys for s in sys.stdin: x=len(str(sum(map(int,s.split())))) print(x)
p00002
while 1: try: a, b = list(map(int, input().split())) c = str(a + b) print((len(c))) except: break
import sys def solve(): while True: try: a, b = list(map(int, sys.stdin.readline().split())) c = a + b if c == 0: print((1)) else: ans = 0 while c > 0: ans += 1 ...
p00002
from collections import defaultdict N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] S = sum(A) DP = [defaultdict(int)] DP[0][0] = 2 DP[0][A[0]] = 1 DP2 = [defaultdict(int)] # R=G=S/2, B=0 DP2[0][0] = 1 DP2[0][A[0]] = 1 for i in range(1, N): curr = defaultdict(int) curr2 = defa...
from collections import defaultdict N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] S = sum(A) DP = [[0]*(S+1) for _ in range(2)] DP[0][0] = 2 DP[0][A[0]] = 1 # R=G=S/2, B=0 DP2 = [[0]*(S+1) for _ in range(2)] DP2[0][0] = 1 DP2[0][A[0]] = 1 max_A = A[0] for i in range(1, N): ...
p03064
from collections import defaultdict N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] S = sum(A) DP = [[0]*(S+1) for _ in range(2)] DP[0][0] = 2 DP[0][A[0]] = 1 # R=G=S/2, B=0 DP2 = [[0]*(S+1) for _ in range(2)] DP2[0][0] = 1 DP2[0][A[0]] = 1 max_A = A[0] for i in range(1, N): ...
from collections import defaultdict N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] S = sum(A) DP = [[0]*(S+1) for _ in range(2)] DP[0][0] = 2 DP[0][A[0]] = 1 # R=G=S/2, B=0 DP2 = [[0]*(S+1) for _ in range(2)] DP2[0][0] = 1 DP2[0][A[0]] = 1 max_A = A[0] for i in range(1, N): ...
p03064
from collections import defaultdict MOD = 998244353 def main(): N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] total = sum(A) half = -(-total//2) dp1 = [defaultdict(lambda: 0) for _ in range(N+1)] dp1[0][0] = 1 dp2 = [defaultdict(lambda: 0) for _ in range(N+...
from collections import defaultdict MOD = 998244353 def main(): N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] total = sum(A) half = -(-total//2) dp1 = [defaultdict(lambda: 0) for _ in range(2)] dp1[0][0] = 1 dp2 = [defaultdict(lambda: 0) for _ in range(2)] ...
p03064
N, *A = list(map(int, open(0).read().split())) MOD = 998244353 S = sum(A) dp0 = [0]*(S+1) dp0[0] = 1 dp1 = [0]*(S+1) dp1[0] = 1 for a in A: for i in range(S, a-1, -1): dp0[i] = (dp0[i] + dp0[i-a]*2) % MOD dp1[i] = (dp1[i] + dp1[i-a]) % MOD ans = pow(3, N, MOD) for L in range(0, S+1):...
N, *A = list(map(int, open(0).read().split())) MOD = 998244353 S = sum(A) dp0 = [0]*(S+1) dp0[0] = 1 for a in A: for i in range(S, a-1, -1): dp0[i] = (dp0[i] + dp0[i-a]*2) % MOD dp1 = [0]*(S+1) dp1[0] = 1 for a in A: for i in range(S, a-1, -1): dp1[i] = (dp1[i] + dp1[i-a]) % MOD ...
p03064
M=998244353 N,*A=open(0) d=[0]*90001 d[0]=1 e=[0]*90001 e[0]=1 z=1 s=0 for a in A: i=s;a=int(a);s+=a;z*=3 while~i:d[i+a]+=d[i]%M;d[i]*=2;e[i+a]+=e[i]%M;i-=1 i=s while i*2>=s:z=(z-d[i]*3)%M;i-=1 print(([(z+e[s//2]*3)%M,z][s%2]))
M=998244353 N,*A=open(0) d=[0]*90001 d[0]=1 e=[0]*90001 e[0]=1 z=1 s=0 for a in A: i=s;a=int(a);s+=a;z*=3 while~i:d[i+a]+=d[i]%M;d[i]*=2;e[i+a]+=e[i]%M;i-=1 i=s while i*2>=s:z=(z-d[i]*3)%M;i-=1 if~s%2:z+=e[s//2]*3 print((z%M))
p03064
M=998244353 N,*A=open(0) d=[0]*90301 d[0]=1 e=[0]*90301 e[0]=1 z=1 s=0 for a in A: a=int(a);s+=a;i=s;z*=3 while~i:d[i]=d[i]*2+d[i-a]%M;e[i]+=e[i-a]%M;i-=1 i=s while i*2>=s:z=(z-d[i]*3)%M;i-=1 z+=~s%2*e[s//2]*3 print((z%M))
M=998244353 N,*A=open(0) d=[0]*90301 d[0]=1 e=[0]*90301 e[0]=1 z=1 s=0 for a in A: a=int(a);s+=a;i=s;z*=3 while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1 i=s while i*2>=s:z=(z-d[i]*3)%M;i-=1 z+=~s%2*e[s//2]*3 print((z%M))
p03064
M=998244353 N,*A=open(0) d=[1]+[0]*7**6 e=[1]+[0]*7**6 z=1 s=0 for a in A: a=int(a);s+=a;i=s;z*=3 while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1 i=s while i*2>=s:z=(z-d[i]*3)%M;i-=1 z+=~s%2*e[s//2]*3 print((z%M))
M=998244353 N,*A=open(0) d=[1]+[0]*7**6 e=[1]+[0]*7**6 z=1 s=0 for a in A: a=int(a);s+=a;i=s;z*=3 while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1 i=s while i*2>=s:z=(z-d[i]*3)%M;i-=1 print(((z+~s%2*e[s//2]*3)%M))
p03064
M=998244353 N,*A=open(0) d=[1]+[0]*7**6 e=[1]+[0]*7**6 z=1 s=0 for a in A: a=int(a);s+=a;i=s;z*=3 while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1 i=s while i*2>=s:z=(z-d[i]*3)%M;i-=1 print(((z+~s%2*e[s//2]*3)%M))
M,z,s=998244353,1,0 d=[1]+[0]*7**6 e=[1]+[0]*7**6 for _ in'_'*eval(input()): a=eval(input());s+=a;i=s;z*=3 while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1 i=s while i*2>=s:z=(z-d[i]*3)%M;i-=1 print((z+~s%2*e[s//2]*3)%M)
p03064
import sys input = sys.stdin.readline n = int(eval(input())) a = [int(eval(input())) for i in range(n)] w = sum(a) mod =998244353 dp = [[0]*(w+1) for i in range(n)] cnt = a[0] dp[0][a[0]] = 1 dp[0][0] = 2 for i in range(1,n): cnt += a[i] for j in range(cnt+1): dp[i][j] = dp[i-1][j]*2 ...
import sys input = sys.stdin.readline n = int(eval(input())) a = [int(eval(input())) for i in range(n)] w = sum(a) mod =998244353 dp = [[0]*(w+1) for i in range(n)] cnt = a[0] dp[0][a[0]] = 1 dp[0][0] = 2 for i in range(1,n): cnt += a[i] for j in range(cnt+1): dp[i][j] = dp[i-1][j]*2 ...
p03064
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] sum_A = sum(A) MOD = 998244353 dp1 = [0] * (sum_A + 1) dp2 = [0] * (sum_A + 1) dp1[0] = dp2[0] = 1 for a in A: dp1_ = [0] * (sum_A + 1) dp2_ = [0] * (sum_A + 1) for i in range(sum_A + 1): if i - a >= 0: ...
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] sum_A = sum(A) MOD = 998244353 dp1 = [0] * (sum_A + 1) dp2 = [0] * (sum_A + 1) dp1[0] = dp2[0] = 1 for a in A: for i in reversed(list(range(sum_A + 1))): if i - a >= 0: # R に塗れる場合 dp1[i] = (dp1[i - a...
p03064
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] sum_A = sum(A) MOD = 998244353 dp1 = [0] * (sum_A + 1) dp2 = [0] * (sum_A + 1) dp1[0] = dp2[0] = 1 for a in A: for i in reversed(list(range(sum_A + 1))): if i - a >= 0: # R に塗れる場合 dp1[i] = (dp1[i - a...
N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] sum_A = sum(A) MOD = 998244353 dp1 = [0] * (sum_A + 1) dp2 = [0] * (sum_A + 1) dp1[0] = dp2[0] = 1 tmp_sum = 0 for a in A: tmp_sum += a for i in reversed(list(range(tmp_sum + 1))): if i - a >= 0: # R に塗れる場合 ...
p03064
MOD = 998244353 N = int(eval(input())) a = [int(eval(input())) for _ in range(N)] total = sum(a) sup = (total - 1) // 2 # total > 2 * max(R,G,B) # を満たすR,G,Bの場合の数 # (total - 1) // 2 >= max(R,G,B) dp = [[[0 for _ in range(total + 1)] for _ in range(total + 1)] for _ in range(N + 1)] dp[0][0][0] = 1 # dp...
# https://atcoder.jp/contests/tenka1-2019/submissions/5065329 import sys input = sys.stdin.readline N = int(eval(input())) a = [int(eval(input())) for _ in range(N)] total = sum(a) MOD = 998244353 '''(1)全体''' U = pow(3, N, MOD) # 三角形を構成できない場合を含むRGBの組み合わせ総数 '''(2)単円''' dp = [[0] * (total + 1) for _ ...
p03064
from math import ceil # 入力 N = int(eval(input())) A = [int(eval(input())) for i in range(N)] MOD = 998244353 class ModInt: def __init__(self, x): self.x = x % MOD def __str__(self): return str(self.x) __repr__ = __str__ def __add__(self, other): return (...
from math import ceil # 入力 N = int(eval(input())) A = [int(eval(input())) for i in range(N)] MOD = 998244353 S = sum(A) # 赤色の整数の和がiとなるような塗り方の個数 dp = [0 for _ in range(S + 1)] dp[0] = 1 # 赤色の整数の和がi, 他の整数がすべて青色となるような塗り方の個数 dp2 = [0 for _ in range(S // 2 + 1)] dp2[0] = 1 # 動的計画法により、dp, dp2を求める for a...
p03064
import sys input = sys.stdin.readline N=int(eval(input())) A=[int(eval(input())) for i in range(N)] SUM=sum(A) MAX=(SUM-1)//2 mod=998244353 from collections import Counter DPLIST=[[0]*301 for i in range(MAX+2)] DPLIST[0][0]=1 ANS=0 for a in A: for i in range(299,-1,-1): for j in range(M...
import sys input = sys.stdin.readline N=int(eval(input())) A=[int(eval(input())) for i in range(N)] SUM=sum(A) MAX=(SUM-1)//2 mod=998244353 DPLIST=[0]*(MAX+2) DPLIST[0]=1 for a in A: for i in range(MAX+1,-1,-1): if i==MAX+1: DPLIST[i]=DPLIST[i]*3%mod else: ...
p03064
N = int(eval(input())) A = [int(eval(input())) for i in range(N)] MOD = 998244353 S = sum(A) dp = [[0]*(S+1) for _ in range(N+1)] dp[0][0] = 1 dp2 = [[0]*(S+1) for _ in range(N+1)] dp2[0][0] = 1 for i in range(N): a = A[i] x = 0 while x <= S: if x + a <= S: dp[i+1][x...
N = int(eval(input())) A = [int(eval(input())) for i in range(N)] MOD = 998244353 S = sum(A) dp = [[0]*(S+1) for _ in range(N+1)] dp[0][0] = 1 dp2 = [[0]*(S+1) for _ in range(N+1)] dp2[0][0] = 1 for i in range(N): a = A[i] x = 0 while x <= S: if x + a <= S: dp[i+1][x...
p03064
MOD = 998244353 def pow(n,k,m):#n^k mod m ans = 1 while k>0: if(k & 1):ans = (ans*n) % m n = (n*n)%m k >>= 1 return ans n = int(eval(input())) a =[int(eval(input())) for i in range(n)] s = sum(a) dp1 = [0 for i in range(s+1)] #dp1[x]:Bの和=xとなるような塗り方の総数 dp1[0] = 1 fo...
MOD = 998244353 def pow(n,k,m):#n^k mod m ans = 1 while k>0: if(k & 1):ans = (ans*n) % m n = (n*n)%m k >>= 1 return ans n = int(eval(input())) a =[int(eval(input())) for i in range(n)] s = sum(a) dp1 = [0 for i in range(s+1)] #dp1[x]:Bの和=xとなるような塗り方の総数 dp1[0] = 1 fo...
p03064
M,z,s=998244353,1,0 N,*A=list(map(int,open(0))) d=[1]+[0]*7**6 e=[1]+[0]*7**6 for a in A: i=s;s+=a;z*=3 while~i:d[i+a]+=d[i]%M;d[i]*=2;e[i+a]+=e[i]%M;i-=1 i=s while i*2>=s:z=(z-d[i]*3)%M;i-=1 print(((z+~s%2*e[s//2]*3)%M))
M,z,s=998244353,1,0 d=[1]+[0]*7**6 e=[1]+[0]*7**6 for _ in'_'*eval(input()): a=eval(input());s+=a;i=s;z*=3 while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1 i=s while i*2>=s:z=(z-d[i]*3)%M;i-=1 print((z+~s%2*e[s//2]*3)%M)
p03064
M,z,s=998244353,1,0 d=[1]+[0]*7**6 e=[1]+[0]*7**6 for _ in'_'*eval(input()): a=eval(input());s+=a;i=s;z*=3 while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a];i-=1 i=s while i*2>=s:z-=d[i]*3;i-=1 print((z+~s%2*e[s//2]*3)%M)
M,z,s=998244353,1,0 d=[1]+[0]*7**6 e=[1]+[0]*7**6 for _ in'_'*eval(input()): a=eval(input());s+=a;i=s;z*=3 while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1 i=s while i*2>=s:z-=d[i]*3;i-=1 print((z+~s%2*e[s//2]*3)%M)
p03064
M,z,s=998244353,1,0 N,*A=open(0) d=[1]+[0]*7**6 e=[1]+[0]*7**6 for a in A: a=int(a);s+=a;i=s;z*=3 while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1 print(((z+~s%2*e[s//2]*3-3*sum(d[-~s//2:]))%M))
M,s=998244353,0 d=[1]+[0]*7**6 e=d[:] n=eval(input()) for _ in'_'*n: a=eval(input());s+=a;i=s while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1 print((3**n+~s%2*e[s//2]*3-3*sum(d[-~s//2:]))%M)
p03064
mod = 998244353 N = int(eval(input())) A = [int(eval(input())) for i in range(N)] A.sort() S = sum(A) PS = [0 for i in range(N+1)] for i in range(N): PS[i+1] = PS[i] + A[i] # D[i][r]: i個塗った時点でR=rとなる場合の数 D = [[0 for _ in range(PS[i]+1)] for i in range(N+1)] D[0][0] = 1 # D2[i][r]: i個塗った時点でR=r, B=0となる場...
mod = 998244353 N = int(eval(input())) A = [int(eval(input())) for i in range(N)] A.sort() S = sum(A) PS = [0 for i in range(N+1)] for i in range(N): PS[i+1] = PS[i] + A[i] # D[i][r]: i個塗った時点でR=rとなる場合の数 D = [[0 for _ in range(PS[i]+1)] for i in range(N+1)] D[0][0] = 1 # D2[i][r]: i個塗った時点でR=r, B=0となる場...
p03064
from collections import deque import sys def bfs(M, sy, sx, gy, gx): queue = deque([[sy, sx]]) M[sy][sx] = 0 while queue: # queueには訪れた地点が入っている。そこから、4方向に移動できるか考え、queueから消す。 y, x = queue.popleft() # queueに入っていたものを消す。 if [y, x] == [gy, gx]: # もしゴールについていたならば、そのときの手数を出す。 ...
from collections import deque import sys def bfs(M, sy, sx): queue = deque([[xs, ys]]) M[sy][sx] = 0 while queue: # queueには訪れた地点が入っている。そこから、4方向に移動できるか考え、queueから消す。 x1, y1 = queue.popleft() # queueに入っていたものを消す。 if [x1, y1] == [xg, yg]: # もしゴールについていたならば、そのときの手数を出す。 ...
p02644
from collections import deque import sys def bfs(xs, ys): queue = deque([[xs, ys]]) M[xs][ys] = 0 while queue: # queueには訪れた地点が入っている。そこから、4方向に移動できるか考え、queueから消す。 x1, y1 = queue.popleft() # queueに入っていたものを消す。 if [x1, y1] == [xg, yg]: # もしゴールについていたならば、そのときの手数を出す。 ...
from collections import deque import sys def bfs(xs, ys, d): queue = deque() queue.append((xs, ys, d)) M[xs][ys] = d while queue: # queueには訪れた地点が入っている。そこから、4方向に移動できるか考え、queueから消す。 x1, y1, d = queue.popleft() # queueに入っていたものを消す。 if [x1, y1] == [xg, yg]: # もしゴールについてい...
p02644
import sys from collections import deque def bfs(x1, y1, d): q = deque([]) q.append((d, x1, y1)) M[x1][y1] = d while q: d, x1, y1 = q.popleft() if [x1, y1] == [xg, yg]: print(d) return for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)): ...
import sys from collections import deque def bfs(x1, y1, d): q = deque([]) q.append((d, x1, y1)) M[x1][y1] = d while q: d, x1, y1 = q.popleft() if [x1, y1] == [xg, yg]: print(d) return for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)): ...
p02644
import sys from collections import deque def bfs(x1, y1, d): q = deque([]) q.append((d, x1, y1)) M[x1][y1] = d while q: d, x1, y1 = q.popleft() if [x1, y1] == [xg, yg]: print(d) return for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)): ...
import sys from collections import deque def bfs(x1, y1, d): q = deque([]) q.append((d, x1, y1)) M[x1][y1] = d while q: d, x1, y1 = q.popleft() M[x1][y1] = d if [x1, y1] == [xg, yg]: print(d) return for dx, dy in ((0, 1), (1, ...
p02644
import sys read = sys.stdin.read readline = sys.stdin.buffer.readline from collections import deque INF = float('inf') def main(): import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines from collections import deque H, W, K = list(map(int,...
import sys read = sys.stdin.read readline = sys.stdin.buffer.readline from collections import deque INF = float('inf') def main(): H, W, K = list(map(int, readline().split())) x1, y1, x2, y2 = list(map(int, readline().split())) x1 -= 1 y1 -= 1 x2 -= 1 y2 -= 1 C = read().split...
p02644
from functools import lru_cache from heapq import heappop, heappush import sys input = sys.stdin.readline H, W, K = list(map(int, input().split())) x1, y1, x2, y2 = [int(x)-1 for x in input().split()] S = [input()[:-1] for _ in [0]*H] dirs = [(-1, 0), (0, -1), (0, 1), (1, 0)] @lru_cache(None) def f(x, y): ...
from heapq import heappop, heappush import sys input = sys.stdin.readline H, W, K = list(map(int, input().split())) x1, y1, x2, y2 = [int(x)-1 for x in input().split()] S = [input()[:-1] for _ in [0]*H] def geth(x, y, z): return (x*W+y)*4+z def push(x, y, z, d): h = geth(x, y, z) if D[h] <= d:...
p02644
import sys input=sys.stdin.readline h,w,k=map(int,input().split()) si,sj,ti,tj=map(int,input().split()) si-=1 sj-=1 ti-=1 tj-=1 b=[input()for _ in range(h)] ans=[[-1]*w for _ in range(h)] ans[si][sj]=0 from collections import deque d=deque() d.append((si,sj)) while d: x,y=d.popleft() if x==ti and y=...
def main(): import sys input=sys.stdin.readline h,w,k=map(int,input().split()) sx,sy,tx,ty=map(int,input().split()) b=[[-1]*(w+2)] for i in range(h): s=input() bb=[-1] for j in s: if j==".":bb.append(0) else:bb.append(-1) bb.append(-1) b.append(bb) b.append([-...
p02644
from queue import Queue def main(): h, w, k = list(map(int, input().split())) sx, sy, gx, gy = [int(z) - 1 for z in input().split()] c = [list(input().replace('\n', '')) for _ in range(h)] c[sx][sy] = 0 q = Queue() q.put((sx, sy)) while not q.empty(): x, y = q.get() ...
from queue import Queue def main(): h, w, k = list(map(int, input().split())) sx, sy, gx, gy = [int(z) - 1 for z in input().split()] c = [list(input().replace('\n', '')) for _ in range(h)] c[sx][sy] = 0 q = Queue() q.put((sx, sy)) while not q.empty(): x, y = q.get() ...
p02644
# -*- coding: utf-8 -*- from collections import Counter, defaultdict, deque import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def rea...
# -*- coding: utf-8 -*- from collections import Counter, defaultdict, deque import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def rea...
p02644
from collections import deque import sys int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MI1(): return map(int1, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline...
from collections import deque import sys int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MI1(): return map(int1, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline...
p02644
#!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(...
#!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(...
p02644
#!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(...
#!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(...
p02644
import sys read = sys.stdin.buffer.read input = sys.stdin.readline #input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(eval(input())) def MI(): return list(map(int,input().split())) def MF(): return list(...
import sys read = sys.stdin.buffer.read input = sys.stdin.readline #input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(eval(input())) def MI(): return list(map(int,input().split())) def MF(): return list(...
p02644
import sys from collections import deque input = iter(sys.stdin.readlines()).__next__ R, C, K = [int(x) for x in input().split()] X1, Y1, X2, Y2 = [int(x) - 1 for x in input().split()] # 0 indexed grid = [input().rstrip() for r in range(R)] source = (X1, Y1) q = deque([source]) dist = {source: 0} ...
import sys from collections import deque input = iter(sys.stdin.readlines()).__next__ R, C, K = [int(x) for x in input().split()] X1, Y1, X2, Y2 = [int(x) - 1 for x in input().split()] # 0 indexed grid = [input().rstrip() for r in range(R)] source = (X1, Y1) q = deque([source]) dist = {source: 0} ...
p02644
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math #from math import gcd import bisect from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# ...
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math #from math import gcd import bisect from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# ...
p02644
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, ...
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, ...
p02644
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, ...
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, ...
p02644
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, ...
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, ...
p02644
#関数リスト import sys input = sys.stdin.readline from collections import defaultdict, deque def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): h, w, k = MI() x1, y1, x2, y2 = MI() x1 -= 1 y1 -= 1 ...
#関数リスト import sys input = sys.stdin.readline from collections import defaultdict, deque def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): h, w, k = MI() x1, y1, x2, y2 = MI() x1 -= 1 y1 -= 1 ...
p02644
def examA(): X = LI() for i in range(len(X)): if X[i]==0: ans = i+1 print(ans) return def examB(): X, Y = LI() ans = "No" for i in range(X+1): if i*2+(X-i)*4==Y: ans = "Yes" print(ans) return def examC(): X, N = LI() ...
def examA(): X = LI() for i in range(len(X)): if X[i]==0: ans = i+1 print(ans) return def examB(): X, Y = LI() ans = "No" for i in range(X+1): if i*2+(X-i)*4==Y: ans = "Yes" print(ans) return def examC(): X, N = LI() ...
p02644
import sys input = sys.stdin.readline from collections import deque H,W,K=list(map(int,input().split())) x1,y1,x2,y2=list(map(int,input().split())) MAP2=[list(input().strip()) for i in range(H)] MAP=[-1]*(H*W) for i in range(H): for j in range(W): if MAP2[i][j]==".": MAP[i*W+j]=1<<...
import sys input = sys.stdin.readline from collections import deque H,W,K=list(map(int,input().split())) x1,y1,x2,y2=list(map(int,input().split())) MAP=[list(input().strip()) for i in range(H)] for i in range(H): for j in range(W): if MAP[i][j]==".": MAP[i][j]=1<<30 else: ...
p02644
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = float('inf') MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()] NI = lambda : int(sys.st...
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = float('inf') MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()] NI = lambda : int(sys.st...
p02644
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = float('inf') MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()] NI = lambda : int(sys.st...
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = float('inf') MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()] NI = lambda : int(sys.st...
p02644
# -*- coding: utf-8 -*- import sys from collections import deque sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 H,W,K=...
# -*- coding: utf-8 -*- import sys from collections import deque sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 H,W,K=...
p02644
from collections import deque import sys N_MAX = 200000 + 5 H, W, K = list(map(int, input().split())) sth, stw, glh, glw = list(map(int, input().split())) INF = 10**6 * K dp = [[INF for _ in range(W+2)] for _ in range(H+2)] dp[0] = [-1]*(W+2) dp[H+1] = [-1]*(W+2) for h in range(1, H+1): s = sys....
from collections import deque import sys N_MAX = 200000 + 5 H, W, K = list(map(int, input().split())) sth, stw, glh, glw = list(map(int, input().split())) INF = 10**6 * K dp = [[INF for _ in range(W + 2)] for _ in range(H + 2)] dp[0] = [-1] * (W + 2) dp[H + 1] = [-1] * (W + 2) for h in range(1, H + 1...
p02644
h,a,*m=open(0) h,w,k,a,b,f,g=list(map(int,(h+a).split())) d=[I:=h*w]*I a=~w+a*w+b d[a]=1 q=[a] for s in q: for y,x in(1,0),(-1,0),(0,1),(0,-1): for z in range(k): i,j=s//w+y*~z,s%w+x*~z;t=i*w+j;p=d[s]+1 if(h>i>-1<j<w)-1or'.'<m[i][j]or d[t]<p:break if d[t]==I:q+=t,;d[t]=p print((d[~w+f*w+g]%I-1))
h,a,*m=open(0) h,w,k,a,b,f,g=list(map(int,(h+a).split())) I=h*w d=[I]*I a=~w+a*w+b d[a]=1 q=[a] for s in q: for y,x in(1,0),(-1,0),(0,1),(0,-1): for z in range(k): i,j=s//w+y*~z,s%w+x*~z;t=i*w+j;p=d[s]+1 if(h>i>-1<j<w)-1or'.'<m[i][j]or d[t]<p:break if d[t]>p:q+=t,;d[t]=p print((d[~w+f*w+g]%I-1)...
p02644
h,a,*m=open(0) h,w,k,a,b,f,g=list(map(int,(h+a).split())) d=[I:=h*w]*I m+=d, a=~w+a*w+b d[a]=1 q=[a] for s in q: for y,x in(1,0),(-1,0),(0,1),(0,-1): for z in range(k): i,j=s//w+y*~z,s%w+x*~z;t=i*w+j;p=d[s]+1 if'.'!=m[i][j]or d[t]<p:break if d[t]>p:q+=t,;d[t]=p print((d[~w+f*w+g]%I-1))
h,a,*m=open(0) h,w,k,a,b,f,g=list(map(int,(h+a).split())) I=h*w d=[I]*I m+=d, a=~w+a*w+b d[a]=1 q=[a] for s in q: for y,x in(1,0),(-1,0),(0,1),(0,-1): for z in range(k): i,j=s//w+y*~z,s%w+x*~z;t=i*w+j;p=d[s]+1 if'.'!=m[i][j]or d[t]<p:break if d[t]>p:q+=t,;d[t]=p print((d[~w+f*w+g]%I-1))
p02644
h,a,*m=open(0) h,w,k,a,b,f,g=list(map(int,(h+a).split())) I=h*w d=[I]*I m+=d, a=~w+a*w+b d[a]=1 q=[a] for s in q: for y,x in(1,0),(-1,0),(0,1),(0,-1): for z in range(k): i,j=s//w+y*~z,s%w+x*~z;t=i*w+j;p=d[s]+1 if'.'!=m[i][j]or d[t]<p:break q+=t,;d[t]=p print((d[~w+f*w+g]%I-1))
h,a,*m=open(0) h,w,k,a,b,f,g=list(map(int,(h+a).split())) d=[I:=h*w]*I m+=d, q=[a:=~w+a*w+b] d[a]=1 for s in q: for y,x in(1,0),(-1,0),(0,1),(0,-1): for z in range(k): if'.'!=m[(i:=s//w+y*~z)][(j:=s%w+x*~z)]or(p:=d[s]+1)>d[(t:=i*w+j)]:break if d[t]>p:q+=t,;d[t]=p print((d[~w+f*w+g]%I-1))
p02644
h,a,*m=open(0) h,w,k,a,b,f,g=list(map(int,(h+a).split())) d=[I:=h*w]*I m+=d, q=[a:=~w+a*w+b] d[a]=1 for s in q: for y,x in(1,0),(-1,0),(0,1),(0,-1): for z in range(k): if'.'!=m[(i:=s//w+y*~z)][(j:=s%w+x*~z)]or(p:=d[s]+1)>d[(t:=i*w+j)]:break if d[t]>p:q+=t,;d[t]=p print((d[~w+f*w+g]%I-1))
h,a,*m=open(0) h,w,k,a,b,f,g=list(map(int,(h+a).split())) d=[I:=h*w]*I m+=d, q=[a:=~w+a*w+b] d[a]=1 for s in q: for y,x in(1,0),(-1,0),(0,1),(0,-1): for z in range(k): if'.'!=m[(i:=s//w+y*~z)][(j:=s%w+x*~z)]or d[s]>=d[(t:=i*w+j)]:break if-~d[s]<d[t]:q+=t,;d[t]=d[s]+1 print((d[~w+f*w+g]%I-1))
p02644
y=1,0,-1,0,1 h,a,*m=open(0) h,w,k,a,b,f,g=list(map(int,(h+a).split())) d=[I:=h*w]*I m+=d, q=[a:=~w+a*w+b] d[a]=1 for s in q: for x in range(4): for z in range(k): if'.'!=m[(i:=s//w+y[x]*~z)][(j:=s%w+y[x+1]*~z)]or(p:=d[s]+1)>d[(t:=i*w+j)]:break if d[t]>p:q+=t,;d[t]=p print((d[~w+f*w+g]%I-1))
h,a,*m=open(0) h,w,k,a,b,f,g=list(map(int,(h+a).split())) I=h*w d=[I]*I m+=d, a=~w+a*w+b q=[a] d[a]=1 for s in q: for x in range(4): for z in range(k): y=~z,0,z+1,0,~z;i,j=s//w+y[x],s%w+y[x+1];t=i*w+j;p=d[s]+1 if'.'!=m[i][j]or d[t]<p:break if d[t]>p:q+=t,;d[t]=p print((d[~w+f*w+g]%I-1))
p02644
h,a,*m=open(0) h,w,k,a,b,f,g=list(map(int,(h+a).split())) d=[I:=h*w]*I m+=d, q=[a:=~w+a*w+b] d[a]=1 for s in q: for x in 0,1,2,3: for z in range(k): y=~z,0,z+1,0,~z;i,j=s//w+y[x],s%w+y[x+1];t=i*w+j;p=d[s]+1 if'.'!=m[i][j]or d[t]<p:break if d[t]>p:q+=t,;d[t]=p print((d[~w+f*w+g]%I-1))
h,a,*m=open(0) h,w,k,a,b,f,g=list(map(int,(h+a).split())) I=h*w d=[I]*I m+=d, a=~w+a*w+b q=[a] d[a]=1 for s in q: for x in 0,1,2,3: for z in range(k): y=~z,0,z+1,0;i,j=s//w+y[x],s%w+y[x^1];t=i*w+j;p=d[s]+1 if'.'!=m[i][j]or d[t]<p:break if d[t]>p:q+=t,;d[t]=p print((d[~w+f*w+g]%I-1))
p02644
h,a,*m=open(0) h,w,k,a,b,f,g=list(map(int,(h+a).split())) d=[I:=h*w]*I m+=d, q=[a:=~w+a*w+b] d[a]=1 for s in q: for x in range(4): for z in range(k): y=~z,0,z+1,0;i,j=s//w+y[x],s%w+y[x^1];t=i*w+j;p=d[s]+1 if'.'!=m[i][j]or d[t]<p:break if d[t]>p:q+=t,;d[t]=p print((d[~w+f*w+g]%I-1))
h,a,*m=open(0) h,w,k,a,b,f,g=list(map(int,(h+a).split())) I=h*w d=[I]*I m+=d, a=~w+a*w+b q=[a] d[a]=1 for s in q: for x in 0,1,2,3: for z in range(k): y=~z,0,z+1,0;i,j=s//w+y[x],s%w+y[~x];t=i*w+j;p=d[s]+1 if'.'!=m[i][j]or d[t]<p:break if d[t]>p:q+=t,;d[t]=p print((d[~w+f*w+g]%I-1))
p02644