input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
from functools import reduce INF = int(1e9 + 7) def modmulti(a, b): # aとbを掛けた値をmodする(a * b mod p) return a * b % INF def factorial(x): FCT = 1 FCT = reduce(modmulti, list(range(2, x + 1)), FCT) return FCT def main(): N, M = list(map(int, input().split())) MIN_NM = fact...
INF = int(1e9 + 7) def modmulti(a, b): # aとbを掛けた値をmodする(a * b mod p) return a * b % INF def factorial(x): FCT = 1 for i in range(2, x + 1): FCT = modmulti(i, FCT) return FCT def main(): N, M = list(map(int, input().split())) MIN_NM = factorial(min(N, M)) i...
p03681
INF = int(1e9 + 7) def modmulti(a, b): # aとbを掛けた値をmodする(a * b mod p) return a * b % INF def factorial(x): FCT = 1 for i in range(2, x + 1): FCT = modmulti(i, FCT) return FCT def main(): N, M = list(map(int, input().split())) MIN_NM = factorial(min(N, M)) i...
INF = int(1e9 + 7) def modmulti(a, b): # aとbを掛けた値をmodする(a * b mod p) return a * b % INF def factorial(x): FCT = 1 for i in range(2, x + 1): FCT = modmulti(i, FCT) return FCT def main(): N, M = list(map(int, input().split())) MIN_NM = factorial(min(N, M)) i...
p03681
INF = int(1e9 + 7) def modmulti(a, b): # aとbを掛けた値をmodする(a * b mod p) return a * b % INF def factorial(x): FCT = 1 for i in range(2, x + 1): FCT = modmulti(i, FCT) return FCT def main(): N, M = list(map(int, input().split())) MIN_NM = factorial(min(N, M)) i...
INF = int(1e9 + 7) def factorial(x): FCT = 1 for i in range(2, x + 1): FCT = i * FCT % INF return FCT def main(): N, M = list(map(int, input().split())) MIN_NM = factorial(min(N, M)) if N == M: print((2 * MIN_NM * MIN_NM % INF)) elif abs(N - M) <= 1: ...
p03681
def f(x): k = 1 for i in range(1,x+1): k *= i return k % (10**9 + 7) a,b = list(map(int,input().split())) if abs(a-b) <= 1: print(((f(a)*f(b)) % (10**9 + 7) if abs(a-b) == 1 else (2*f(a)*f(b)) % (10**9 + 7))) else: print((0))
import math def f(x): return math.factorial(x) % (10**9 + 7) a,b = list(map(int,input().split())) if abs(a-b) <= 1: print(((f(a)*f(b)) % (10**9 + 7) if abs(a-b) == 1 else (2*f(a)*f(b)) % (10**9 + 7))) else: print((0))
p03681
n, m = list(map(int, input().split())) mod = 10**9 + 7 def fact(n): i = n ret = 1 while i > 1: ret *= i i -= 1 return ret if n == m: print((fact(n) ** 2 * 2 % mod)) # elif n+1 == m or n-1 == m: # print(fact(n) * fact(m)) elif n == m+1: n_f = fact(n) print((n_f * (n_f//n) % mod)) ...
n, m = list(map(int, input().split())) mod = 10**9 + 7 def fact(x): ret = 1 for i in range(1, x+1): ret = ret * i % mod return ret if n == m: print((fact(n)**2 * 2 % mod)) elif n+1 == m or n-1 == m: print((fact(n) * fact(m) % mod)) else: print((0))
p03681
import math a,b=list(map(int, input().split())) if abs(a-b) == 1: print((math.factorial(a)*math.factorial(b))) if abs(a-b) == 0: print((math.factorial(a)*math.factorial(b)*2)) if abs(a-b) >= 2: print((0))
import math a,b=list(map(int, input().split())) if abs(a-b) == 1: c = math.factorial(a)%(10**9+7) d = math.factorial(b)%(10**9+7) print((c*d%(10**9+7))) if abs(a-b) == 0: c = math.factorial(a)%(10**9+7) d = math.factorial(b)%(10**9+7) print((c*d*2%(10**9+7))) if abs(a-b) >= 2: p...
p03681
import math mod = 10**9+7 n,m = list(map(int,input().split())) if abs(n-m) > 1: print(0) quit() if max(n,m) > min(n,m): print(math.factorial(max(n,m)) % mod * math.factorial(min(n,m)) % mod) else : print((((math.factorial(n))%mod)**2 * 2)%mod)
mod = 10**9+7 n,m = list(map(int,input().split())) def factorial(x): retval = 1 for i in range(2,x+1): retval = (retval * i)% mod return retval if abs(n-m) > 1: print(0) quit() if max(n,m) > min(n,m): print((factorial(max(n,m)) * factorial(min(n,m))) % mod) else : print(((factorial(n)**2)%...
p03681
n, m = list(map(int, input().split())) MOD = 1000000007 a, b = n, m count_n = n count_m =m count = 0 if abs(n-m) == 1: for _ in range(n-1): n -= 1 count_n *= (n % MOD) for _ in range(m-1): m -= 1 count_m *= (m % MOD) count = (count_m % MOD) * (count_n % MOD) elif abs(n-m) == 0: fo...
import math n, m = list(map(int, input().split())) MOD = 1000000007 count_n = 0 count_m = 0 count = 0 if abs(n-m) == 1: count_n = math.factorial(n) % MOD count_m = math.factorial(m) % MOD count = count_m * count_n % MOD elif abs(n-m) == 0: count_n = math.factorial(n) % MOD count_m = math.factorial...
p03681
import math n, m = list(map(int, input().split())) MOD = 1000000007 count_n = 0 count_m = 0 count = 0 if abs(n-m) == 1: count_n = math.factorial(n) % MOD count_m = math.factorial(m) % MOD count = count_m * count_n % MOD elif abs(n-m) == 0: count_n = math.factorial(n) % MOD count_m = math.factorial...
import math N, M = list(map(int, input().split())) mod = 10**9+7 if abs(N-M) > 1: print((0)) exit() if N < M: N, M = M, N if N == M: ans = math.factorial(N) ans %= mod ans *= math.factorial(M) ans %= mod ans *= 2 ans %= mod else: ans = math.factorial(M) ans %= mod ans *= ...
p03681
n, m = list(map(int, input().split())) ans = 1 if n==m: for i in range(1, n+1): ans *= i ans %= 10**9+7 print(((ans**2*2)%(10**9+7))) elif abs(n-m)==1: for i in range(1, n+1): ans *= i ans %= 10**9+7 for i in range(1, m+1): ans *= i ans %= 10*...
n, m = list(map(int, input().split())) ans = 1 mod = 10**9+7 if n==m: for i in range(1, n+1): ans *= i ans %= mod print(((ans**2*2)%mod)) elif abs(n-m)==1: for i in range(1, n+1): ans *= i ans %= mod for i in range(1, m+1): ans *= i ans %= mo...
p03681
n, m = list(map(int, input().split())) ans = 1 mod = 10**9+7 a = lambda x, y: x*y % mod if n==m: for i in range(1, n+1): ans = a(ans, i) print(((ans**2*2)%(mod))) elif abs(n-m)==1: for i in range(1, n+1): ans = a(ans, i) for i in range(1, m+1): ans = a(ans, i) pr...
n, m = list(map(int, input().split())) ans = 1 mod = 10**9+7 def a(x, y): return x*y%mod if n==m: for i in range(1, n+1): ans = a(ans, i) print(((ans**2*2)%(mod))) elif abs(n-m)==1: for i in range(1, n+1): ans = a(ans, i) for i in range(1, m+1): ans = a(ans, i)...
p03681
def frac(n): sum = 1 for i in range(1,n+1): sum*=i return sum import sys,fractions N,M=list(map(int,input().split(' '))) # abs(N-M) > 1なら無理 if (abs(N-M) > 1): print((0)) sys.exit() # それぞれの階乗を求める frac_n = frac(N) frac_m = frac(M) if N == M: ans = frac_m * frac_n * 2 else: ans = f...
divisor = 10**9 + 7 def frac(n): sum = 1 for i in range(1,n+1): sum = sum * i % divisor return sum import sys,fractions N,M=list(map(int,input().split(' '))) # abs(N-M) > 1なら無理 if (abs(N-M) > 1): print((0)) sys.exit() # それぞれの階乗を求める frac_n = frac(N) frac_m = frac(M) if N == M: ans...
p03681
def 解(): iN,iM = [int(_) for _ in input().split()] iD = 10**9+7 if abs(iN - iM) <= 1: if iN < iM: iN,iM = iM,iN iFacM = 1 for i in range(1,iM+1): iFacM *= i iFacM %=iD if iN == iM: print(( iFacM * iFacM % iD * 2 % i...
def 解(): iN,iM = [int(_) for _ in input().split()] iD = 10**9+7 if abs(iN - iM) <= 1: if iN < iM: iN,iM = iM,iN iFacM = 1 for i in range(1,iM+1): iFacM *= i iFacM %=iD if iN == iM: print(( iFacM ** 2 % iD * 2 % iD )...
p03681
# -*- coding: utf-8 -*- from math import factorial n, m = list(map(int, input().split())) def solve(m, n): if m > n: m, n = n, m if n - m > 1: return 0 fct = factorial(m) if n - m == 1: return fct ** 2 * n else: # n - m == 0 return fct ** 2 * 2 ...
# -*- coding: utf-8 -*- n, m = list(map(int, input().split())) mod = 10 ** 9 + 7 def factorial(x): ret = 1 for i in range(1, x + 1): ret *= i ret %= mod return ret def solve(m, n): if m > n: m, n = n, m if n - m > 1: return 0 fct = fact...
p03681
N, M = list(map(int, input().split())) a = 1 b = 1 if N == M: for i in range(1,N+1): a *= i % 1000000007 b = a elif N - M == 1: for i in range(1,M+1): b *= i % 1000000007 a = b * N elif M - N == 1: for i in range(1,N+1): a *= i % 1000000007 b = a * M ...
import math import time N, M = list(map(int, input().split())) st = time.time() a = math.factorial(N) % 1000000007 b = math.factorial(M) % 1000000007 """ if N == M: for i in range(1,N+1): a *= i % 1000000007 b = a elif N - M == 1: for i in range(1,M+1): b *= i % 10000000...
p03681
n,m=list(map(int,input().split())) div=10**9+7 if abs(n-m)>1: print((0)) else: ans=1 for i in range(1,n+1): ans=ans*i%div for i in range(1,m+1): ans=ans*i%div if n==m: ans*=2 print((ans%div))
n,m=list(map(int,input().split())) div=10**9+7 if abs(n-m)>1: print((0)) else: ans=1 for i in range(1,min(m,n)+1): ans=ans*i%div ans*=ans if n!=m: ans*=max(m,n) if n==m: ans*=2 print((ans%div))
p03681
import math n,m=list(map(int,input().split())) ans=math.factorial(m)*math.factorial(n) if n==m: ans*=2 elif abs(n-m)>1: ans=0 print(ans)
import math n,m=list(map(int,input().split())) ans=math.factorial(m)*math.factorial(n)%(10**9+7) if n==m: ans*=2 ans%=(10**9+7) elif abs(n-m)>1: ans=0 print(ans)
p03681
import sys readline = sys.stdin.readline from math import factorial MOD = 10 ** 9 + 7 def main(): N, M = list(map(int, readline().rstrip().split())) if abs(N-M) > 1: ans = 0 elif N == M: ans = (factorial(N) % MOD) * (factorial(M) % MOD) * 2 else: ans = (factorial(N) ...
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 def factorial(N, mod=MOD): res = 1 for i in range(2, N+1): res *= i res %= mod return res def main(): N, M = list(map(int, readline().rstrip().split())) if abs(N-M) > 1: ans = 0 elif N == M: ...
p03681
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 def factorial(N, mod=MOD): res = 1 for i in range(2, N+1): res *= i res %= mod return res def main(): N, M = list(map(int, readline().rstrip().split())) if abs(N-M) > 1: ans = 0 elif N == M: ...
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 def factorial(N, mod=MOD): res = 1 for i in range(2, N+1): res *= i res %= mod return res def main(): N, M = list(map(int, readline().rstrip().split())) if abs(N-M) > 1: ans = 0 elif N == M: ...
p03681
n,m = list(map(int,input().split())) lst = [0] for i in range(n - 1): lst.append(lst[-1] + int(eval(input()))) ans = 0 num = 0 for i in range(m): a = int(eval(input())) ans += abs(lst[num] - lst[num + a]) ans %= 100000 num += a print(ans)
def solve(): n,m = list(map(int,input().split())) lst = [0] for i in range(n - 1): lst.append(lst[-1] + int(eval(input()))) ans = 0 num = 0 for i in range(m): a = int(eval(input())) ans += abs(lst[num] - lst[num + a]) num += a print((ans % 100000)) solve()
p00472
def solve(n): ans=0 for a in range(int(n/4)+1): for b in range(a,int(n/3)+1): if b>1000: break for c in range(b,int(n/2)+1): if c>1000: break d=n-(a+b+c) if d>=c: if a==b==c==d: ans+=1#4!/4! elif a==b==c or b==c==d: ans+=4#4!/3! elif a==b and c==d...
M = 1000 DM = M * 2 + 1 def count(n): global M res = n + 1 if n > M: res -= (n-M) * 2 return res def solve(n): cnt = 0 for a in range(min(DM, n), -1, -1): b = n - a if b > DM: break cnt += count(a) * count(b) return cnt whi...
p00096
b=[0]*2001 for i in range(1001): for j in range(1001): b[i+j]+=1 while 1: try:n=int(eval(input())) except:break c=0;a=[1000,n][n<1000] for i in range(2*a+1): for j in range(2*a+1): if i+j==n:c+=b[i]*b[j] print(c)
s=[0]*4001 for i in range(2001): a=a+2*(i-999)*(i-1000) if i>1000 else 0 s[i]=(i+3)*(i+2)*-~i//6-a s[4000-i]=s[i] while 1: try:print((s[int(eval(input()))])) except:break
p00096
import sys a=[0]*4001 for i in range(1999):a[i]=a[4000-i]=(i+3)*(i+2)*(i+1)//6-a[i-1001]*4*(i>999) for e in sys.stdin:print((a[int(e)]))
import sys a=[0]*4001 for i in range(2001):a[i]=a[4000-i]=(i+3)*(i+2)*(i+1)//6-a[i-1001]*4*(i>999) for e in sys.stdin:print((a[int(e)]))
p00096
from collections import Counter two_dict = Counter() for i in range(1001): for j in range(1001): two_dict[i + j] += 1 while True: try: n = int(eval(input())) ans = 0 for i in range(n + 1): ans += two_dict[i] * two_dict[n - i] print(ans) except EOFError: break
from collections import Counter pair_dict = Counter() for i in range(2001): pair_dict[i] = min(i, 2000 - i) + 1 while True: try: n = int(eval(input())) ans = 0 for i in range(n + 1): ans += pair_dict[i] * pair_dict[n - i] print(ans) except EOFError: break
p00096
# -*- coding: utf-8 -*- import sys import os for s in sys.stdin: n = int(s) T = [0] * 2001 for a in range(1001): for b in range(1001): T[a+b] += 1 sum_n_num = 0 for a_b_sum in range(0, n+1): c_d_sum = n - a_b_sum if a_b_sum <= 2000 and c_d_sum ...
# -*- coding: utf-8 -*- import sys import os import math T = [0] * 2001 for a in range(1001): for b in range(1001): T[a + b] += 1 for s in sys.stdin: n = int(s) sum_n_num = 0 for a_b_sum in range(0, n+1): c_d_sum = n - a_b_sum if a_b_sum <= 2000 and c_d_sum <...
p00096
while True: try: n = int(input()) count = 0 for a in range(1000,-1,-1): if 0 <= n - a <= 3000: for b in range(1000,-1,-1): if n - a - b > 2000: break elif 0 <= n - a - b <= 1000: ...
while True: try: n = int(input()) count = 0 for a in range(1000,-1,-1): na = n - a if 3000 < na: break elif 0 <= na <= 3000: for b in range(1000,-1,-1): nab = n - a - b if n...
p00096
T = 1000 memo = [[0] * (2 * T + 1) for _ in range(3)] #Java: int[][] memo = new int[3][2*T+1]; memo[0][0] = 1 for i in range(1,3): for j in range(i*T+1): memo[i][j] = sum([memo[i-1][k] for k in range(max(0,j-T),j+1)]) while True: try: n = eval(input()) except EOFError: ...
T = 1000 N = 4000 dp = [[0] * (N + 1) for _ in range(5)] #Java: int[][] dp = new int[5][N]; dp[0][0] = 1 for i in range(1,5): for j in range(i*T+1): dp[i][j] = sum([dp[i-1][k] for k in range(max(0,j-T),j+1)]) while True: try: n = eval(input()) except EOFError: break ...
p00096
T = 1000 N = 4000 dp = [[0] * (N + 1) for _ in range(5)] #Java: int[][] dp = new int[5][N]; dp[0][0] = 1 for i in range(1,5): for j in range(i*T+1): dp[i][j] = sum([dp[i-1][k] for k in range(max(0,j-T),j+1)]) while True: try: n = eval(input()) except EOFError: break ...
T = 1000 def f(x): return max(0, T + 1 - abs(T - x)) while True: try: n = eval(input()) except EOFError: break cnt = 0 for i in range(n+1): cnt += f(i) * f(n-i) print(cnt) #O(n),
p00096
# -*- coding: utf-8 -*- """ Sum of 4 Integers II http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0096 """ import sys from sys import stdin from collections import defaultdict input = stdin.readline def main(args): lut = defaultdict(list) for a in range(1001): for b in range(10...
# -*- coding: utf-8 -*- """ Sum of 4 Integers II http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0096 """ import sys from sys import stdin from collections import defaultdict input = stdin.readline def main(args): lut = defaultdict(int) for a in range(1001): for b in range(100...
p00096
import sys a=[0]*2001 b=[0]*4001 n=1001 for i in range(n): for j in range(n): a[i+j]+=1 n=2001 for i in range(n): for j in range(n): b[i+j]+=a[i]*a[j] for i in sys.stdin: print(b[int(i)])
import sys n=1001 a=[0]*2001 for i in range(n): for j in range(n): a[i+j]+=1 for n in map(int,sys.stdin): x=0 for i in range(max(0,n-2000),min(n,2000)+1): x+=a[i]*a[n-i] print(x)
p00096
import sys n=1001 a=[0]*2001 for i in range(n): for j in range(n): a[i+j]+=1 for n in map(int,sys.stdin): x=0 for i in range(max(0,n-2000),min(n,2000)+1): x+=a[i]*a[n-i] print(x)
import sys n=1001 a=list(range(1,n)) a+=[n]+a[::-1] for n in map(int,sys.stdin): x=0 for i in range(max(0,n-2000),min(n,2000)+1): x+=a[i]*a[n-i] print(x)
p00096
import sys def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし s = LS2() a = ''.join(s[0:5]) b = ''.join(s[6:13]) c = ''.join(s[14:19]) print(('{} {} {}'.format(a,b,c)))
import sys def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし s = LS2() s[5] = ' ' s[13] = ' ' print((''.join(s)))
p03834
s = list( map( str, input().split(",") ) ) print(( s[0] + " " + s[1] + " " + s[2] ))
print(( input().replace( ",", " " ) ))
p03834
print((input().replace(',', ' ')))
*S, = input() S[5] = S[13] = ' ' print(*S, sep='')
p03834
s = input().split(",") s = " ".join(s) print(s)
S = input().strip() x = S[:5]+" "+S[6:13]+" "+S[14:] print(x)
p03834
s1, s2, s3 = input().split(',') print((s1 + ' ' + s2 + ' ' + s3))
s = list(input().split(',')) print((' '.join(s)))
p03834
L,R = list(map(int,input().split())) mod = 10**9+7 m = 64 +1 fac = [1]*m ninv = [1]*m finv = [1]*m for i in range(2,m): fac[i] = fac[i-1]*i%mod ninv[i] = (-(mod//i)*ninv[mod%i])%mod finv[i] = finv[i-1]*ninv[i]%mod def comb(n,k): return (fac[n]*finv[k]%mod)*finv[n-k]%mod def f(L,R): ...
L,R = list(map(int,input().split())) mod = 10**9+7 def f(L,R): if L>R : return 0 R = bin(R)[2:] N = len(R) ret = f(L,int("0"+"1"*(N-1),2)) L = bin(L)[2:] if len(L) != N : L = "1"+"0"*(N-1) for i in range(N): if R[i] == "0" : continue R2 = R[:i] + "0" + "?"*(N-i...
p02938
L,R = list(map(int,input().split())) mod = 10**9+7 def f(L,R): if L>R : return 0 R = bin(R)[2:] N = len(R) ret = f(L,int("0"+"1"*(N-1),2)) L = bin(L)[2:] if len(L) != N : L = "1"+"0"*(N-1) for i in range(N): if R[i] == "0" : continue R2 = R[:i] + "0" + "?"*(N-i...
L,R = list(map(int,input().split())) mod = 10**9+7 def f(L,R): if L>R : return 0 R = bin(R)[2:] N = len(R) ret = f(L,int("0"+"1"*(N-1),2)) L = bin(L)[2:] if len(L) != N : L = "1"+"0"*(N-1) for i in range(N): if R[i] == "0" : continue R2 = R[:i] + "0" + "?"*(N-i...
p02938
import sys sys.setrecursionlimit(2147483647) INF=float("inf") input=lambda :sys.stdin.buffer.readline().rstrip() class ModInt(object): __MOD=10**9+7 def __init__(self,x): self.__x=x%self.__MOD def __repr__(self): return str(self.__x) def __add__(self,other): retu...
import sys sys.setrecursionlimit(2147483647) INF=float("inf") input=lambda :sys.stdin.buffer.readline().rstrip() class ModInt(object): __MOD=10**9+7 def __init__(self,x): self.__x=x%self.__MOD def __repr__(self): return str(self.__x) def __add__(self,other): retu...
p02938
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] dp = [[a[i] if i==j else max(a[i],a[(i+1)%n]) if (i+1)%n==j else 0 for j in range(n)] for i in range(n)] for i in range(3 if n%2==0 else 2,n,2): for l in range(n): r = (l+i)%n pat = [] for x,nextl,nextr in [(l,(l+1)...
n = int(eval(input())) a = [int(eval(input())) for _ in range(n)] dp = [0 for _ in range(n)] for i in range(n): if i%2 == n%2: dp = [ dp[(l+1)%n] if a[l]>a[(l+i)%n] else dp[l] for l in range(n)] else: dp = [ max( a[l]+dp[(l+1)%n], a[(l+i)%n]+dp[l] ) for l in range(n)] print((max(dp...
p00538
n, q, s, t = list(map(int, input().split())) a = [int(eval(input())) for _ in range(n + 1)] for _ in range(q): l, r, x = list(map(int, input().split())) for i in range(l, r + 1): a[i] += x temp = 0 for i in range(1, n + 1): temp += (a[i - 1] - a[i]) * s if a[i] > a[i - 1] else (a...
n, q, s, t = list(map(int, input().split())) a = [int(eval(input())) for _ in range(n + 1)] for i in range(1, n + 1)[::-1]: a[i] -= a[i - 1] count = 0 for i in range(n + 1): count -= a[i] * s if a[i] > 0 else a[i] * t for _ in range(q): l, r, x = list(map(int, input().split())) count += a[l] * ...
p00559
# -*- coding: utf-8 -*- n=int(eval(input())) m=int(eval(input())) ans=c=m for i in range(n): a,b=[int(a) for a in input().split()] if c<0: continue c+=a-b if ans<c: ans=c if c<0: ans=0 print(ans)
n=int(eval(input())) ans=c=m=int(eval(input())) for i in[0]*n: a,b=list(map(int,input().split())) if c<0:ans=0;break c+=a-b ans=max(ans,c) print(ans)
p00510
from collections import deque n, m = int(eval(input())), int(eval(input())) B, S = 0, m d = deque([0]*m) for _ in range(n): cars = list(map(int, input().split())) for _ in range(cars[0]): d.append(0) try: for _ in range(cars[1]): d.pop() except IndexError: B = 1 S = max(S,...
n, m = int(eval(input())), int(eval(input())) B, S = 0, m d = [0]*m for _ in range(n): cars = list(map(int, input().split())) for _ in range(cars[0]): d.append(0) try: for _ in range(cars[1]): d.pop() except IndexError: B = 1 S = max(S, len(d)) print((0 if B else S))
p00510
n = int(eval(input())) m = int(eval(input())) S_max = m for i in range(n): a, b = list(map(int, input().split())) m += a - b if m < 0: print((0)) break S_max = max(S_max, m) else: print(S_max)
n = int(eval(input())) m = int(eval(input())) S_max = m for i in range(n): a, b = list(map(int, input().split())) m += a - b if m < 0: S_max = 0 break S_max = max(S_max, m) print(S_max)
p00510
n = eval(input()) lis = [] for i in range(n): com = input() try: com, x = com.split() if com == 'insert': lis.append(x) elif com == 'delete': l = len(lis) - 1 while (lis[l] != x) and l >= 0: l -= 1 if lis[l] ==...
n = eval(input()) lis = [] bot = 0 for i in range(n): com = input() if com[0] == 'i': lis.append(com[7:]) elif com[6] == ' ': try: lis.pop(~lis[::-1].index(com[7:])) except: pass elif com[6] == 'F': lis.pop() else: bot ...
p02265
#coding:utf-8 from collections import deque n = int(eval(input())) day = deque() for i in range(n): order = list(input().split()) if order[0] == "insert": day.appendleft(order[1]) if order[0] == "delete": try: day.remove(order[1]) except: continu...
#coding:utf-8 from collections import deque n = int(eval(input())) day = deque() for i in range(n): order = list(input().split()) if order[0] == "insert": day.appendleft(order[1]) elif order[0] == "delete": try: day.remove(order[1]) except: conti...
p02265
class Node: def __init__(self, key, prev, next): self.key = key self.prev = prev self.next = next class LinkedList: def __init__(self): self.nil = Node(None, None, None) self.nil.prev = self.nil self.nil.next = self.nil def insert(self, key): ...
import sys class Node: def __init__(self, key, prev, next): self.key = key self.prev = prev self.next = next class LinkedList: def __init__(self): self.nil = Node(None, None, None) self.nil.prev = self.nil self.nil.next = self.nil def inse...
p02265
import sys class Node: def __init__(self, key, prev, next): self.key = key self.prev = prev self.next = next class LinkedList: def __init__(self): self.nil = Node(None, None, None) self.nil.prev = self.nil self.nil.next = self.nil def inse...
import sys class Node: def __init__(self, key, prev, next): self.key = key self.prev = prev self.next = next class LinkedList: def __init__(self): self.nil = Node(None, None, None) self.nil.prev = self.nil self.nil.next = self.nil def insert...
p02265
from collections import deque arr = [] for i in range(int(eval(input()))): command_line = input().split(" ") command = command_line[0] arg = "" if len(command_line) > 1: arg = command_line[1] if command == "insert": arr.insert(0, arg) if command == "delete": try: arr.remove(ar...
from collections import deque q = deque() for i in range(int(eval(input()))): command_line = input().split(" ") command = command_line[0] arg = "" if len(command_line) > 1: arg = command_line[1] if command == "insert": q.appendleft(arg) elif command == "delete": try: q.remove(...
p02265
# -*- coding: utf-8 -*- """ Created on Wed Jun 21 08:50:28 2017 @author: syaga """ COMMAND = ["insert", "delete", "deleteFirst", "deleteLast"] if __name__ == "__main__": n = int(eval(input())) com = [] for i in range(n): com.append(input().split()) ans = [] for i in com: ...
# -*- coding: utf-8 -*- """ Created on Wed Jun 21 09:13:28 2017 @author: syaga """ COMMAND = ["insert", "delete", "deleteFirst", "deleteLast"] if __name__ == "__main__": n = int(eval(input())) com = [] for i in range(n): com.append(input().split()) ans = [] for i in com: ...
p02265
# -*- coding: utf-8 -*- from collections import deque COMMAND = ("insert", "delete", "deleteFirst", "deleteLast") if __name__ == "__main__": n = int(eval(input())) ans = deque() for i in range(n): com = input().split() if com[0] == COMMAND[0]: ans.appendleft(com[1]...
# -*- coding: utf-8 -*- from collections import deque import sys COMMAND = ("insert", "delete", "deleteFirst", "deleteLast") if __name__ == "__main__": n = int(sys.stdin.readline()) ans = deque() inp = sys.stdin.readlines() for i in range(n): com = inp[i].split() if com[0...
p02265
n = int(eval(input())) dlist = [] for i in range(n): arr = input().split() cmd = '' key = 0 cmd = arr[0] if len(arr) > 1: key = int(arr[1]) if cmd == 'insert': dlist.insert(0, key) elif cmd == 'delete': if dlist.count(key) > 0: idx = dlist...
n = int(eval(input())) dlist = [] for i in range(n): arr = input().split() cmd = '' key = 0 cmd = arr[0] if len(arr) > 1: key = arr[1] if cmd == 'insert': dlist.insert(0, key) elif cmd == 'delete': if dlist.count(key) > 0: idx = dlist.inde...
p02265
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ???????????£???????????? ??\?????????????????????????????????????????£???????????????????£?????????????????????? insert x: ??£?????????????????????????????? x ?????????????´?????¶?????¶??????? delete x: ?????? x ??????????????????????´??????£????????????????????...
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ???????????£???????????? ??\?????????????????????????????????????????£???????????????????£?????????????????????? insert x: ??£?????????????????????????????? x ?????????????´?????¶?????¶??????? delete x: ?????? x ??????????????????????´??????£????????????????????...
p02265
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ???????????£???????????? ??\?????????????????????????????????????????£???????????????????£?????????????????????? insert x: ??£?????????????????????????????? x ?????????????´?????¶?????¶??????? delete x: ?????? x ??????????????????????´??????£????????????????????...
#!/usr/bin/env python # -*- coding: utf-8 -*- """ ???????????£???????????? ??\?????????????????????????????????????????£???????????????????£?????????????????????? insert x: ??£?????????????????????????????? x ?????????????´?????¶?????¶??????? delete x: ?????? x ??????????????????????´??????£????????????????????...
p02265
class Node(): key = 0 def __init__( self, key ): self.key = key self.next = -1 self.pre = -1 def insert( self, othernode ): # othernodeにはinsert前の先頭のノードを入れる self.next = othernode othernode.pre = self return self def delete( self, x ): #先頭ノードで...
class Node(): key = 0 def __init__( self, key ): self.key = key self.next = -1 self.pre = -1 def insert( self, othernode ): # othernodeにはinsert前の先頭のノードを入れる self.next = othernode othernode.pre = self return self def delete( self, x ): #先頭ノードで...
p02265
from collections import deque queue = deque([]) n = int(input()) for i in range(n): commands = input().split(" ") command = commands[0] if command == "insert": queue.appendleft(commands[1]) elif command == "delete": try: queue.remove(commands[1]) exce...
from collections import deque queue = deque([]) for _ in range(int(eval(input()))): commands = input().split(" ") command = commands[0] if command == "insert": queue.appendleft(commands[1]) elif command == "delete": try: queue.remove(commands[1]) except ...
p02265
from collections import deque queue = deque([]) for _ in range(int(eval(input()))): commands = input().split(" ") command = commands[0] if command == "insert": queue.appendleft(commands[1]) elif command == "delete": try: queue.remove(commands[1]) except ...
from collections import deque queue = deque() for _ in range(int(eval(input()))): commands = input().split(" ") if commands[0] == "insert": queue.appendleft(commands[1]) elif commands[0] == "delete": try: queue.remove(commands[1]) except ValueError: ...
p02265
from collections import deque def main(): queue = deque() for _ in range(int(eval(input()))): commands = input().split(" ") if commands[0] == "insert": queue.appendleft(commands[1]) elif commands[0] == "delete": try: queue.remove(com...
import sys from collections import deque queue = deque() for _ in range(int(sys.stdin.readline())): commands = sys.stdin.readline()[:-1].split(" ") if commands[0] == "insert": queue.appendleft(commands[1]) elif commands[0] == "delete": try: queue.remove(commands[1]) ...
p02265
# coding: utf-8 import sys from collections import deque output_str = deque() data_cnt = int(eval(input())) for i in range(data_cnt): line = input().rstrip() if line.find(" ") > 0: in_command, in_str = line.split(" ") else: in_command = line if in_command == "inse...
# coding: utf-8 import sys from collections import deque output_str = deque() data_cnt = int(eval(input())) for i in range(data_cnt): in_command = input().rstrip().split(" ") if in_command[0] == "insert": output_str.appendleft(in_command[1]) elif in_command[0] == "delete": ...
p02265
n = int(input()) xlist = [] for i in range(n): command = list(map(str,input().split())) if (command[0] == 'insert'): x = command[1] if (len(xlist) == 0): xlist.append(int(x)) else: xlist.append(int(x)) for i in range(1,len(xlist)): ...
n = int(input()) xlist = [] for i in range(n): command = list(map(str,input().split())) if (command[0] == 'insert'): x = command[1] if (len(xlist) == 0): xlist.append(int(x)) else: xlist = [int(x)] + xlist #print(xlist) elif (command[0] == '...
p02265
from sys import stdin class DList: class Cell: def __init__(self, k): self.key = k self.prev = None self.next = None def __init__(self): self.head = DList.Cell(None) self.last = DList.Cell(None) self.head.next = self.last ...
from sys import stdin class DList: class Cell: def __init__(self, k): self.key = k self.prev = None self.next = None def __init__(self): self.head = DList.Cell(None) self.last = DList.Cell(None) self.head.next = self.last ...
p02265
from collections import deque n = int(eval(input())) q = deque() for i in range(n): cmd = input().strip().split() try: if cmd[0][0] == 'i': q.appendleft(cmd[1]) elif cmd[0][-1] == 'e': q.remove(cmd[1]) elif cmd[0][6] == 'F': q.popleft() ...
from collections import deque n = int(eval(input())) q = deque() for i in range(n): cmd = input().strip().split() if cmd[0] == 'insert': q.appendleft(cmd[1]) continue if cmd[0] == 'delete': try: q.remove(cmd[1]) except: pass co...
p02265
n = int(eval(input())) L = [] i = 0 while i < n: s = list(map(str, input().split(' '))) if s[0] == 'insert': L.insert(0, int(s[1])) elif s[0] == 'delete': if int(s[1]) in L: L.remove(int(s[1])) elif s[0] == 'deleteFirst': del L[0] elif s[0] == 'deleteL...
n = int(eval(input())) L = [] i = 0 while i < n: s = list(map(str, input().split(' '))) if s[0] == 'insert': L.insert(0, int(s[1])) elif s[0] == 'delete': try: L.remove(int(s[1])) except: pass elif s[0] == 'deleteFirst': del L[0] ...
p02265
from collections import deque def pr(A,n): for i in range(n): if i!=n-1: print(A[i],end=" ") else: print(A[i]) n=int(input()) que_r=deque() c=0 for i in range(n): s=input().split() if s[0]=="insert": que_r.appendleft(int(s[1])) elif s...
from collections import deque def pr(A,n): for i in range(n): if i!=n-1: print(A[i],end=" ") else: print(A[i]) n=int(input()) que_r=deque() for i in range(n): s=input().split() if s[0]=="insert": que_r.appendleft(int(s[1])) elif s[0]==...
p02265
class DLList: class Cell: def __init__(self, data, pre, nex): self.data = data self.pre = pre self.nex = nex def __init__(self): self.top = DLList.Cell(None, None, None) def insert(self, x): if self.top.nex == None: w ...
class DLList: class Cell: def __init__(self, data, pre, nex): self.data = data self.pre = pre self.nex = nex def __init__(self): self.top = DLList.Cell(None,None,None) self.top.nex = self.top def insert(self, x): w = DLLis...
p02265
from collections import deque n = int( eval(input( )) ) que = deque( ) for i in range( n ): op = input( ).split( " " ) if "insert" == op[0]: que.appendleft( op[1] ) elif "delete" == op[0]: if op[1] in que: que.remove( op[1] ) elif "deleteFirst" == op[0] : que.popleft( ) elif "deleteLast" == ...
import sys from collections import deque n = int( sys.stdin.readline( ) ) que = deque( ) lines = sys.stdin.readlines() for line in lines: op = line.rstrip().split( " " ) if "insert" == op[0]: que.appendleft( op[1] ) elif "delete" == op[0]: if op[1] in que: que.remove( op[1] ) elif "deleteFirst"...
p02265
n = int(input()) commands = [] for a in range(n): raw = input().split() try: commands.append([raw[0], int(raw[1])]) except: commands.append([raw[0], 'none']) result = [] for a in commands: command, x = a[0], a[1] if command == 'insert': result.append(x) eli...
n = int(input()) result = [] for a in range(n): c = input().split() if c[0] == 'insert': result.append(int(c[1])) elif c[0] == 'delete': c[1] = int(c[1]) if c[1] in result: if result.count(c[1]) == 1: result.remove(c[1]) else: ...
p02265
#! /usr/bin/env python # -*- coding: utf-8 -*- ''' ???????????£???????????? ''' from collections import deque functions = {"insert": lambda obj, x: obj.insert(x), "delete": lambda obj, x: obj.delete(x), "deleteFirst": lambda obj: obj.deleteFirst(), "deleteLast": lambd...
#! /usr/bin/env python # -*- coding: utf-8 -*- ''' ???????????£???????????? ''' from collections import deque functions = {"insert": lambda obj, x: obj.insert(x), "delete": lambda obj, x: obj.delete(x), "deleteFirst": lambda obj: obj.deleteFirst(), "deleteLast": lambd...
p02265
class Node: def __init__(self, key, prevNode, nextNode): self.key = key self.prevNode = prevNode self.nextNode = nextNode def deleteNode(node): if node == fNode: return node.prevNode.nextNode = node.nextNode node.nextNode.prevNode = node.prevNode def searchN...
class Node: def __init__(self, key, prevNode, nextNode): self.key = key self.prevNode = prevNode self.nextNode = nextNode def deleteNode(node): if node == fNode: return node.prevNode.nextNode = node.nextNode node.nextNode.prevNode = node.prevNode def searchN...
p02265
import sys res = dict() dll = [None] * 2000000 left = 0 right = 0 n = int(eval(input())) for inpt in sys.stdin.read().splitlines(): i = inpt.split() if i[0] == "insert": x = int(i[1]) dll[left] = x if(x in res): res[x].append(left) else: res[...
import sys res = dict() dll = [None] * 2000000 left = 0 right = 0 n = int(eval(input())) for inpt in sys.stdin.read().splitlines(): i = inpt.split() if i[0] == "insert": x = int(i[1]) dll[left] = x if(x in res): res[x].add(left) else: res[x] ...
p02265
import sys class Node: def __init__(self, value): self.value = value self.prev = None self.next = None class DoublyLinkedList: def __init__(self): self.head = None self.tail = None self.size = 0 def get_size(self): return self.size def is_empty(self): return self.size == 0 ...
import sys class Node: def __init__(self, value): self.value = value self.prev = None self.next = None class DoublyLinkedList: def __init__(self): self.head = None self.tail = None self.size = 0 def get_size(self): return self.size def is_empty(self): return self.size == 0 ...
p02265
import sys class Node: def __init__(self, value): self.value = value self.prev = None self.next = None class DoublyLinkedList: def __init__(self): self.head = None self.tail = None self.size = 0 def get_size(self): return self.size def is_empty(self): return self.size == 0 ...
class Node(object): def __init__(self, num, prv = None, nxt = None): self.num = num self.prv = prv self.nxt = nxt class DoublyLinkedList(object): def __init__(self): self.start = self.last = None def insert(self, num): new_elem = Node(num) ...
p02265
class LinkedListNode: def __init__(self, key, prev_node, next_node): self.key = key self.prev_node = prev_node self.next_node = next_node class LinkedList: def __init__(self): self.front_node = None self.last_node = None self.size = 0 def insert(...
import sys class LinkedListNode: def __init__(self, key, prev_node, next_node): self.key = key self.prev_node = prev_node self.next_node = next_node class LinkedList: def __init__(self): self.front_node = None self.last_node = None self.size = 0 ...
p02265
# -*- coding: utf-8 -*- from collections import deque n = int(input()) key = deque() for i in range(n): command = list(input().split()) if command[0] == 'insert': key.insert(0, command[1]) elif command[0] == 'delete' and command[1] in key: key.remove(command[1]) elif comm...
# -*- coding: utf-8 -*- from collections import deque n = int(input()) key = deque() for i in range(n): command = list(input().split()) if command[0] == 'insert': key.insert(0, command[1]) elif command[0] == 'delete' and command[1] in key: key.remove(command[1]) elif comm...
p02265
# -*- coding: utf-8 -*- from collections import deque n = int(input()) key = deque() for i in range(n): command = list(input().split()) if command[0] == 'insert': key.insert(0, command[1]) elif command[0] == 'delete' and command[1] in key: key.remove(command[1]) elif comm...
# -*- coding: utf-8 -*- from collections import deque n = int(input()) key = deque() for i in range(n): command = list(input().split()) if command[0] == 'insert': key.appendleft(command[1]) elif command[0] == 'delete': try: key.remove(command[1]) except: ...
p02265
class Node(object): def __init__(self, num, prev = None, nxt = None): self.num = num; self.prev = prev; self.nxt = nxt; class Double_Linked_List(object): def __init__(self): self.first = self.last = None; def insert(self, num): node = Node(num); ...
class Node(object): def __init__(self, num, prv = None, nxt = None): self.num = num self.prv = prv self.nxt = nxt class DoublyLinkedList(object): def __init__(self): self.start = self.last = None def insert(self, num): new_elem = Node(num) ...
p02265
n = int(eval(input())) A = [list(map(str,input().split())) for _ in range(n)] B = [] for i in range(n): if A[i][0] == 'insert': B.insert(0,int(A[i][1])) elif A[i][0] == 'delete': if int(A[i][1]) in B: B.remove(int(A[i][1])) elif A[i][0] == 'deleteFirst': del B...
n = int(eval(input())) B = [] for i in range(n): A = list(map(str,input().split())) if A[0] == 'insert': B.insert(0,int(A[1])) elif A[0] == 'delete': if int(A[1]) in B: B.remove(int(A[1])) elif A[0] == 'deleteFirst': del B[0] elif A[0] == 'deleteLast'...
p02265
from collections import deque def insert(): a.appendleft(command[1]) def delete(): try: a.remove(command[1]) except ValueError: pass def deleteFirst(): a.popleft() def deleteLast(): a.pop() n = int(input()) a = deque([]) for i in range(n): command = input()...
from collections import deque a = deque([]) for i in range(int(input())): c = input().split() if c[0] == "insert": a.appendleft(c[1]) elif c[0] == "delete": try: a.remove(c[1]) except ValueError: pass elif c[0] == "deleteFirst": a.pople...
p02265
from collections import deque class MyList(list): def __init__(self): self.__init__ = list self.d = {'deleteFirst':self.delF, 'deleteLast':self.delL, 'insert':self.insX, 'delete':self.delX} def cmd(self,command): if ' ' in command: ope, num = command.split() ...
from collections import deque class MyList(deque): def __init__(self): self.__init__ = deque self.d = {'deleteFirst':self.delF, 'deleteLast':self.delL, 'insert':self.insX, 'delete':self.delX} def cmd(self,command): if ' ' in command: ope, num = command.split() ...
p02265
import sys class mydeque: class cell: def __init__(self,x,y = None,z = None): self.data = x self.next = y self.prev = z def __init__(self): head = mydeque.cell(None) head.next = head head.prev = head self.size = 0 ...
import sys class mydeque: class cell: def __init__(self,x,y = None,z = None): self.data = x self.next = y self.prev = z def __init__(self): head = mydeque.cell(None) head.next = head head.prev = head self.size = 0 ...
p02265
class Node: def __init__(self, key, prev, next): self.key = key self.prev = prev self.next = next class MyDLL: def __init__(self): self.linkedlist = [] self.length = 0 def insert(self, x): # 連結リストの先頭にキー x を持つ要素を継ぎ足す。 if self.le...
class Node: def __init__(self, key): self.key = key self.prev = None self.next = None class MyDLL: def __init__(self): # 番兵:仮想的な先頭 self.sentinel = Node(None) self.sentinel.prev = self.sentinel self.sentinel.next = self.sentinel ...
p02265
class DLL: class Node: def __init__(self, x, y, z): self.v = x self.prv = y self.nxt = z def __init__(self): init = DLL.Node(None, None, None) init.prv = init init.nxt = init self.size = 0 self.init = init de...
#16D8104025G 佐藤智裕 mist75__ Python3 class DLL: class Node: def __init__(self, x, y, z): self.v = x self.prv = y self.nxt = z def __init__(self): init = DLL.Node(None, None, None) init.prv = init init.nxt = init self.size =...
p02265
import sys class Node: def __init__(self, num): self.prev = None self.next_node = None self.num = num def delete(self): if self.prev is not None: self.prev.next_node = self.next_node if self.next_node is not None: self.next_node.prev = ...
class Node(object): def __init__(self, num, prv = None, nxt = None): self.num = num self.prv = prv self.nxt = nxt class DoublyLinkedList(object): def __init__(self): self.start = self.last = None def insert(self, num): new_elem = Node(num) ...
p02265
from sys import stdin class Node: def __init__(self, num): self.prev = None self.next_node = None self.num = num def delete(self): if self.prev is not None: self.prev.next_node = self.next_node if self.next_node is not None: self.next_n...
class Node(object): def __init__(self, num, prv = None, nxt = None): self.num = num self.prv = prv self.nxt = nxt class DoublyLinkedList(object): def __init__(self): self.start = self.last = None def insert(self, num): new_elem = Node(num) ...
p02265
from collections import deque n = int(input()) d = deque() for _i in range(n): line = input().split() order = line[0] if order in ('insert', 'delete'): key = int(line[1]) if order == 'insert': d.appendleft(key) elif order == 'delete': try: d.remove(k...
from collections import deque n = int(eval(input())) d = deque() for _i in range(n): line = input().split() order = line[0] if order in ('insert', 'delete'): key = line[1] if order == 'insert': d.appendleft(key) elif order == 'delete': try: d.remove(...
p02265
from collections import deque n = int(eval(input())) d = deque() for _i in range(n): line = input().split() order = line[0] if order in ('insert', 'delete'): key = line[1] if order == 'insert': d.appendleft(key) elif order == 'delete': try: d.remove(...
from collections import deque n = int(eval(input())) d = deque() for _i in range(n): line = input().split() order = line[0] if order == 'deleteFirst': d.popleft() elif order == 'deleteLast': d.pop() else: key = line[1] if order == 'insert': ...
p02265
def pr(data,next,head,tail): i = head while(1): if i == -1: print("") break print(data[i],end = "") i = next[i] if i != -1 : print(" ",end = "") def ins_f(data,next,prev,x,head,tail): size = len(data) if head != -1 : ...
def pr(data,next,head,tail): i = head while(1): if i == -1: print("") break print(data[i],end = "") i = next[i] if i != -1 : print(" ",end = "") def ins_f(data,next,prev,x,head,tail): size = len(data) if head != -1 : ...
p02265
from collections import deque n = int(eval(input())) output = deque() for i in range(n): li = input().split(' ') if(li[0] == 'insert'): output.appendleft(int(li[1])) elif(li[0] == 'delete'): try: output.remove(int(li[1])) except: pass elif(li...
from collections import deque n = int(eval(input())) output = deque() for i in range(n): li = input().split(' ') if(li[0] == 'insert'): output.appendleft(li[1]) elif(li[0] == 'deleteFirst'): output.popleft() elif(li[0] == 'deleteLast'): output.pop() elif(li[0] == '...
p02265
from collections import deque def doubly_lined_list(n, A): Q = deque() for i in range(n): if A[i][0] == 'insert': Q.appendleft(A[i][1]) elif A[i][0] == 'delete': try: Q.remove(A[i][1]) except: pass elif A[i][0] == 'deleteFirst': Q.popleft() elif A[i][0] == 'deleteLast': ...
import sys from collections import deque def doubly_lined_list(): n = int(eval(input())) Q = deque() for i in range(n): line = sys.stdin.readline() command = line.split()[0] if command == 'insert': Q.appendleft(line.split()[1]) elif command == 'delete': try: Q.remove(line.split()[...
p02265
#coding:utf-8 #1_3_C from collections import deque n = int(eval(input())) ary = deque() for i in range(n): cmd = input().split() if cmd[0] == "insert": ary.appendleft(cmd[1]) elif cmd[0] == "delete": try: ary.remove(cmd[1]) except ValueError: pass...
#coding:utf-8 #1_3_C from collections import deque n = int(eval(input())) q = deque() for i in range(n): cmd = input().split() if cmd[0] == "insert": q.appendleft(cmd[1]) elif cmd[0] == "delete": try: q.remove(cmd[1]) except ValueError: pass ...
p02265
class LinkedList(object): def __init__(self): self.nodes = [] self.first = None self.last = None def insert(self, key): node = {'key':key, 'next':None, 'prev':None} if not self.nodes: self.first = self.last = node self.nodes.append(node)...
class LinkedList(object): def __init__(self): self.first = None self.last = None def insert(self, key): node = {'key':key, 'next':None, 'prev':None} if not self.first: self.first = self.last = node else: node['next'] = self.first ...
p02265
class LinkedList(object): def __init__(self): self.first = None self.last = None def insert(self, key): node = {'key':key, 'next':None, 'prev':None} if not self.first: self.first = self.last = node else: node['next'] = self.first ...
class LinkedList(object): def __init__(self): self.first = None self.last = None def insert(self, key): node = {'key':key, 'next':None, 'prev':None} if not self.first: self.first = self.last = node else: node['next'] = self.first ...
p02265
# 2019-11-23 01:28:44(JST) import sys from string import ascii_lowercase as alphabet def main(): n, s, k = sys.stdin.read().split() n, k = list(map(int, [n, k])) c = s[k-1] for l in alphabet: if l != c: s = s.replace(l, '*') print(s) if __name__ == ...
# 2019-11-23 01:28:44(JST) import sys def main(): n, s, k = sys.stdin.read().split() n, k = list(map(int, [n, k])) c = s[k-1] letters = set(s) - set(c) for l in letters: s = s.replace(l, '*') print(s) if __name__ == '__main__': main()
p03068
from operator import itemgetter n,q=list(map(int,input().split())) c=list(map(int,input().split())) l=[list(map(int,input().split())) for i in range(q)] for i in range(q): l[i].append(i) l2=sorted(l,key=itemgetter(1)) L=[-1]*(5*10**5+1) class Bit: def __init__(self,n): self.size=n self.tree=[...
n,q=list(map(int,input().split())) c=list(map(int,input().split())) l=[list(map(int,input().split())) for i in range(q)] for i in range(q): l[i].append(i) l2=sorted(l,key=lambda x:x[1]) L=[-1]*(5*10**5+1) class Bit: def __init__(self,n): self.size=n self.tree=[0]*(n + 1) self.depth=n.bit_...
p02599
n,q=list(map(int,input().split())) c=list(map(int,input().split())) l=[list(map(int,input().split())) for i in range(q)] for i in range(q): l[i].append(i) l2=sorted(l,key=lambda x:x[1]) L=[-1]*(5*10**5+1) class Bit: def __init__(self,n): self.size=n self.tree=[0]*(n + 1) self.depth=n.bit_...
n,q=list(map(int,input().split())) c=list(map(int,input().split())) l=[list(map(int,input().split())) for i in range(q)] for i in range(q): l[i].append(i) l.sort(key=lambda x:x[1]) L=[-1]*(5*10**5+1) class Bit: def __init__(self,n): self.size=n self.tree=[0]*(n + 1) self.depth=n.bit_lengt...
p02599
import sys input=sys.stdin.readline from operator import itemgetter n,q=list(map(int,input().split())) c=list(map(int,input().split())) l=[list(map(int,input().split())) for i in range(q)] for i in range(q): l[i].append(i) l.sort(key=lambda x:x[1]) L=[-1]*(5*10**5+1) class Bit: def __init__(self,n): ...
import sys input=sys.stdin.readline n,q=list(map(int,input().split())) c=list(map(int,input().split())) l=[] for i in range(q): L,R=list(map(int,input().split())) l.append([L,R,i]) l.sort(key=lambda x:x[1]) L=[-1]*(5*10**5+1) class Bit: def __init__(self,n): self.size=n self.tree=[0]*(n +...
p02599
import sys input=sys.stdin.readline n,q=list(map(int,input().split())) c=list(map(int,input().split())) l=[] for i in range(q): L,R=list(map(int,input().split())) l.append([L,R,i]) l.sort(key=lambda x:x[1]) L=[-1]*(5*10**5+1) class Bit: def __init__(self,n): self.size=n self.tree=[0]*(n +...
import sys input=sys.stdin.readline n,q=list(map(int,input().split())) c=list(map(int,input().split())) l=[] for i in range(q): L,R=list(map(int,input().split())) l.append([L,R,i]) l.sort(key=lambda x:x[1]) L=[-1]*(5*10**5+1) class Bit: def __init__(self,n): self.size=n self.tree=[0]*(n +...
p02599
from dataclasses import dataclass class BIT: ''' All methods use 0-based index while the implementation use 1-based index ''' def __init__(self, N, val=0): self.data = [val] * (N + 1) self.N = N def add_at(self, idx, val): i = idx + 1 while i <= self.N: ...
class BIT: ''' All methods use 0-based index while the implementation use 1-based index ''' def __init__(self, N, val=0): self.data = [val] * (N + 1) self.N = N def add_at(self, idx, val): i = idx + 1 while i <= self.N: self.data[i] += va...
p02599
import sys input = sys.stdin.readline class BIT: def __init__(self, n): self.n = n self.bit = [0]*(n+1) self.value = [0]*(n+1) def summarize(self, i): s = 0 while i > 0: s += self.bit[i] i -= i & -i return s ...
import sys input = sys.stdin.readline class BIT: def __init__(self, n): self.n = n self.bit = [0]*(n+1) self.value = [0]*(n+1) def summarize(self, i): s = 0 while i > 0: s += self.bit[i] i -= i & -i return s ...
p02599
from collections import Counter from operator import add class SegmentTree(): def __init__(self, iterable, func, e): self.func = func self.e = e ls = list(iterable) self.n = 1 << len(ls).bit_length() ls.extend( [self.e] * (self.n - len(ls)) ) self.data = ...
from operator import add class BIT(): def __init__(self, length_or_list, func, e): self.func = func self.e = e if isinstance(length_or_list, int): self.n = length_or_list + 1 self.data = [self.e] * self.n else: self.n = len(length_or_l...
p02599