code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
# ??????????????????????????
# ケース12と13、完全にバグとしか思えないのですが?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
# もしかして:頂点1は必ず0?
n = int(input())
a = list(map(int, input().split()))
if a[0] != 0:
print(0)
exit()
a = sorted(a)
d = {}
for av in a:
if av not in d:
d[av] = 1
else:
d[av] += 1
if d[0] != 1:
print(0)
exit()
MOD = 998244353
ans = 1
for i in range(1, a[-1] + 1):
if i not in d:
ans = 0
break
ans *= pow(d[i - 1], d[i], MOD)
print(ans % MOD) | n = int(input())
y = 1000 - (n % 1000)
if y == 1000:
y = 0
print(y) | 0 | null | 81,859,662,784,788 | 284 | 108 |
N=int(input())
S={}
for n in range(N):
s=input()
S[s]=S.get(s,0)+1
S=sorted(S.items(), key=lambda x:(-x[1],x[0]))
maxS=S[0][1]
for s, cnt in S:
if cnt!=maxS:
break
print(s) | import sys
import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict
# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846
def read_str(): return sys.stdin.readline().strip()
def read_int(): return int(sys.stdin.readline().strip())
def read_ints(): return map(int, sys.stdin.readline().strip().split())
def read_ints2(x): return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)
def Main():
n, m = read_ints()
a = read_int_list()
a = [x // 2 for x in a]
lcm = 1
for x in a:
lcm *= x // math.gcd(lcm, x)
for x in a:
if lcm // x % 2 == 0:
print(0)
exit()
print(math.ceil((m // lcm) / 2))
if __name__ == '__main__':
Main() | 0 | null | 85,875,470,253,382 | 218 | 247 |
N = int(input())
Count = 0
for T in range(1,N+1):
if not (T%3==0 or T%5==0):
Count = Count+T
print(Count) | import math
n = int(input())
x = n * (n + 1) / 2
f = math.floor(n / 3)
fizzsum = f * (f + 1) / 2 * 3
b = math.floor(n / 5)
buzzsum = b * (b + 1) / 2 * 5
fb = math.floor(n / 15)
fizzbuzzsum = fb * (fb + 1) / 2 * 15
print(int(x - fizzsum - buzzsum + fizzbuzzsum)) | 1 | 34,792,409,515,068 | null | 173 | 173 |
def main():
s = input()
p = input()
if p in s*2:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| s = str(raw_input())
p = str(raw_input())
i = 0
while(1):
if i == len(s):
print "No"
break
if i+len(p) >= len(s):
str = s[i:len(s)] + s[0:len(p)-len(s[i:len(s)])]
else:
str = s[i:i+len(p)]
if str == p:
print "Yes"
break
else:
i += 1 | 1 | 1,759,547,106,048 | null | 64 | 64 |
S=input()
if S[-1]=='s':
Ans=S+'es'
else:
Ans=S+'s'
print(Ans) | import bisect
N = int(input())
L = list(map(int,input().split()))
ans = 0
L = sorted(L)
for i in range(N):
for j in range(N):
if i >= j:
continue
a = L[i]
b = L[j]
c = bisect.bisect_left(L,a+b)
ans += c - j - 1
print(ans) | 0 | null | 86,817,230,046,258 | 71 | 294 |
N = input().strip()
INFTY = 10**8
dp = [[INFTY for _ in range(2)] for _ in range(len(N)+1)]
a = int(N[-1])
for i in range(10):
if i<a:
dp[1][1] = min(dp[1][1],i+10-a)
else:
dp[1][0] = min(dp[1][0],i+i-a)
for k in range(2,len(N)+1):
a = int(N[-k])
for i in range(10):
if i>=a:
dp[k][0] = min(dp[k][0],dp[k-1][0]+i+i-a)
if i-1>=a:
dp[k][0] = min(dp[k][0],dp[k-1][1]+i+i-1-a)
if i<a:
dp[k][1] = min(dp[k][1],dp[k-1][0]+i+10-a)
if i==0:
dp[k][1] = min(dp[k][1],dp[k-1][1]+9-a)
if 0<=i-1<a:
dp[k][1] = min(dp[k][1],dp[k-1][1]+i+10-a+i-1)
print(min(dp[len(N)][0],dp[len(N)][1]+1)) | ri = lambda S: [int(v) for v in S.split()]
def rii(): return ri(input())
H, N = rii()
A = rii()
print("Yes" if H - sum(A) <= 0 else "No") | 0 | null | 74,273,523,891,068 | 219 | 226 |
a = input()
b = a[::-1]
c = 0
for i in range(int(len(a)/2)):
if a[i] != b[i]:
c += 1
print(c)
| s, t = [input() for i in range(2)]
c = []
for i in range(len(s) - len(t) + 1):
d = len(t)
for a, b in zip(s[i:], t):
if a == b:
d -= 1
c.append(d)
print(min(c)) | 0 | null | 62,131,735,828,722 | 261 | 82 |
while True:
L = map(int,raw_input().split())
H = (L[0])
W = (L[1])
if H == 0 and W == 0:break
for x in range(0,H):print "#" * W
print "" | # coding: utf-8
# Your code here!
# ITP1_5_A
while(True):
x,y=map(int,input().split())
if x==0 and y==0:
break
else:
for r in range(0,x):
print("#"*y)
print("")
| 1 | 788,681,118,562 | null | 49 | 49 |
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
def inp():
'''
一つの整数
'''
return int(input())
def inpl():
'''
一行に複数の整数
'''
return list(map(int, input().split()))
s, t = input().split()
a, b = inpl()
u = input()[:-1]
if u == s:
print(a - 1, b)
else:
print(a, b - 1)
| MOD = 10**9 + 7
k = int(input())
s = input()
n = len(s)
MAX = 2 * 10**6 + 5
fact = [1] * (MAX + 1) # i!
finv = [1] * (MAX + 1) # (i!)^{-1}
iinv = [1] * (MAX + 1) # i^{-1}
for i in range(2, MAX + 1):
fact[i] = fact[i - 1] * i % MOD
iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * iinv[i] % MOD
def comb(n: int, k: int) -> int:
if n < k or n < 0 or k < 0:
return 0
return (fact[n] * finv[k] % MOD) * finv[n - k] % MOD
ans = 0
for i in range(k + 1):
ans += comb(n + k - i - 1, k - i) * pow(25, k - i, MOD) % MOD * pow(
26, i, MOD) % MOD
ans %= MOD
print(ans)
| 0 | null | 42,224,897,580,448 | 220 | 124 |
X,N = map(int,input().split())
P = list(map(int,input().split()))
if N == 0:
print(X)
else:
for i in range(X,-2,-1):
if i not in P:
a = abs(X - i)
break
for j in range(X+1,102):
if j not in P:
b = abs(j - X)
break
if a <= b:
print(i)
else:
print(j) | import sys
import itertools
N, K = map(int, input().split())
a = 0
h = 0
l = 0
for j in range(0,K-1):
h += j
for j in range(N+2-K,N+1):
l += j
for i in range(K,N+2):
h += i-1
l += N+1-i
a += l - h + 1
a %= 10 ** 9 + 7
print(a)
| 0 | null | 23,530,278,139,334 | 128 | 170 |
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
check = [0]*N
ima = 0
for i in range(K):
if check[A[ima]-1] != 0:
loopen = ima
check[ima] = i+1
looplen = check[ima] - check[A[ima]-1] + 1
loopend = i
break
if i == K-1:
print(A[ima])
exit()
check[ima] = i+1
ima = A[ima]-1
offset = (K-(i-looplen)-1)%looplen
ima = 0
for i in range(loopend-looplen+offset+1):
ima = A[ima]-1
print(ima+1)
| def main():
n, k = map(int, input().split())
# ダブリング
d = 60
to = [[0 for _ in range(n)]
for _ in range(d)] # to[i][j] : 町jから2**i回ワープした町
to[0] = list(map(int, input().split()))
for i in range(1, d):
for j in range(n):
to[i][j] = to[i - 1][to[i - 1][j] - 1]
v = 1
for i in range(d, -1, -1):
l = 2 ** i # 2**i回ワープする
if l <= k:
v = to[i][v - 1]
k -= l
if k == 0:
break
print(v)
if __name__ == "__main__":
main()
| 1 | 22,851,227,769,092 | null | 150 | 150 |
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
a = LI()
s = sum(a)
if s >= 22:
print('bust')
else:
print('win') | print(['bust', 'win'][sum(map(int, input().split()))<=21]) | 1 | 119,012,561,678,138 | null | 260 | 260 |
inp1 = int(input())
x=(inp1 - (inp1 // 2)) / inp1
print(float(x)) | N = int(input())
O = [i for i in range(1, N+1) if i % 2 == 1]
print(len(O) / N) | 1 | 177,165,109,648,340 | null | 297 | 297 |
def main():
s = input()
t = input()
t = t[0:len(t)-1]
# print(s,t)
ans = 'Yes' if s == t else 'No'
print(ans)
if __name__ == '__main__':
main()
| #!/usr/bin/python3
# -*- coding:utf-8 -*-
def main():
h, w = map(int, input().split())
grid = []
for _ in range(h):
grid.append(list(input().strip()))
dp = [[0]*(w) for _ in range(h)]
def cals_score(i, j):
score = 10**9 + 7
if i >= 1:
score = dp[i-1][j] + (1 if grid[i-1][j]!=grid[i][j] else 0)
if j >= 1:
score = min(score, dp[i][j-1] + (1 if grid[i][j-1]!=grid[i][j] else 0))
return score
dp[0][0] = 1
for i in range(1, w):
dp[0][i] = cals_score(0, i)
for i in range(1, h):
dp[i][0] = cals_score(i, 0)
for i in range(1, h):
for j in range(1, w):
dp[i][j] = cals_score(i, j)
print(dp[-1][-1]//2 + dp[-1][-1]%2 * (grid[0][0]=='#'))
if __name__=='__main__':
main()
| 0 | null | 35,493,449,113,600 | 147 | 194 |
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
k,n = mi()
a = li()
max_l = 0
for i in range(n-1):
max_l = max(max_l,a[i+1]-a[i])
max_l = max(max_l,k-a[-1]+a[0])
print(k-max_l) | k,n = map(int, input().split())
a = list(map(int, input().split()))
l = [a[n-1]-a[0]]
for i in range(n-1):
l.append(k-a[i+1]+a[i])
print(min(l)) | 1 | 43,355,966,246,590 | null | 186 | 186 |
import sys
def m():
d={};input()
for e in sys.stdin:
if'f'==e[0]:print('yes'if e[5:]in d else'no')
else:d[e[7:]]=0
if'__main__'==__name__:m()
| import sys
n = int(input())
command = sys.stdin.readlines()
Q = {}
for i in range(n):
a,b = command[i].split()
if a == "insert":
Q[b] = 0
else:
if b in Q.keys():
print("yes")
else:
print("no") | 1 | 77,855,151,888 | null | 23 | 23 |
import math
n=int(input())
def koch(d,p1,p2):
if d==0:
return
s=[0,0]
t=[0,0]
u=[0,0]
s[0]=2/3*p1[0]+1/3*p2[0]
s[1]=2/3*p1[1]+1/3*p2[1]
t[0]=1/3*p1[0]+2/3*p2[0]
t[1]=1/3*p1[1]+2/3*p2[1]
u[0]=s[0]+(t[0]-s[0])*math.cos(math.pi/3)-(t[1]-s[1])*math.sin(math.pi/3)
u[1]=s[1]+(t[0]-s[0])*math.sin(math.pi/3)+(t[1]-s[1])*math.cos(math.pi/3)
koch(d-1,p1,s)
print(*s)
koch(d-1,s,u)
print(*u)
koch(d-1,u,t)
print(*t)
koch(d-1,t,p2)
print(0,0)
koch(n,[0,0],[100,0])
print(100,0)
| n = int(input())
P = [(0.0,0.0), (100.0, 0)]
import copy
import math
sin60 = math.sin(math.radians(60))
cos60 = math.cos(math.radians(60))
for _ in range(n):
next_p = []
for p1, p2 in zip(P[:-1], P[1:]):
l = (p1[0]*2/3+p2[0]*1/3, p1[1]*2/3+p2[1]*1/3)
r = (p1[0]*1/3+p2[0]*2/3, p1[1]*1/3+p2[1]*2/3)
x = cos60*(r[0]-l[0])-sin60*(r[1]-l[1])+l[0]
y = sin60*(r[0]-l[0])+cos60*(r[1]-l[1])+l[1]
next_p.append(p1)
next_p.append(l)
next_p.append((x, y))
next_p.append(r)
next_p.append(P[-1])
P = copy.copy(next_p)
for p in P:
print(p[0], p[1])
| 1 | 128,144,788,282 | null | 27 | 27 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
n = max(A).bit_length()
cnt = [0]*n
for x in A:
for i, y in enumerate("{:b}".format(x).zfill(n)[::-1]):
if y == "1":
cnt[i] += 1
ans = 0
for i, c in enumerate(cnt):
bit_sum = (c*(N-c)%mod) * pow(2, i, mod) % mod
ans = (ans+bit_sum)%mod
print(ans)
| l = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = list(int(input()) for _ in range(n))
for i in range(3) :
for j in range(3) :
for k in range(n) :
if l[i][j] == b[k] :
l[i][j] = 0
for i in range(3) :
if l[i][0] + l[i][1] + l[i][2] == 0 :
print('Yes')
exit()
if l[0][i] + l[1][i] + l[2][i] == 0 :
print('Yes')
exit()
if l[0][0] + l[1][1] + l[2][2] == 0 :
print('Yes')
exit()
if l[0][2] + l[1][1] + l[2][0] == 0 :
print('Yes')
exit()
print('No') | 0 | null | 91,052,040,807,620 | 263 | 207 |
A,B = map(int,input().split())
if A<=9 and B<=9:print(A*B)
else : print(-1) | n, k = map(int, input().split())
i = 1
while True:
if k ** i > n:
print(i)
break
i += 1 | 0 | null | 110,992,945,892,860 | 286 | 212 |
import math
H, N = map(int, input().split())
dp = [[0 for _ in range(H + 1)] for _ in range(N)]
A, B = map(int, input().split())
for i in range(H + 1):
cnt = math.ceil(i / A)
dp[0][i] = B * cnt
for i in range(1, N):
A, B = map(int, input().split())
for j in range(H + 1):
dp[i][j] = min(dp[i - 1][j], dp[i][max(j - A, 0)] + B)
# print(*dp, sep='\n')
print(dp[-1][-1]) | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
N = int(readline())
dp = [[0] * 10 for _ in range(10)]
ans = 0
for i in range(1, N + 1):
s = str(i)
first = int(s[0])
second = int(s[-1])
ans += 2 * dp[second][first]
if first == second:
ans += 1
dp[first][second] += 1
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 83,617,102,272,672 | 229 | 234 |
import sys
input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
#####segfunc#####
def segfunc(x, y):
return x*y
#################
#####ide_ele#####
ide_ele = 1
#################
class SegTree:
"""
init(init_val, ide_ele): 配列init_valで初期化 O(N)
update(k, x): k番目の値をxに更新 O(logN)
query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
"""
def __init__(self, init_val, segfunc, ide_ele):
"""
init_val: 配列の初期値
segfunc: 区間にしたい操作
ide_ele: 単位元
n: 要素数
num: n以上の最小の2のべき乗
tree: セグメント木(1-index)
"""
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.tree = [ide_ele] * 2 * self.num
# 配列の値を葉にセット
for i in range(n):
self.tree[self.num + i] = init_val[i]
# 構築していく
for i in range(self.num - 1, 0, -1):
self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, k, x):
"""
k番目の値をxに更新
k: index(0-index)
x: update value
"""
k += self.num
self.tree[k] = x
while k > 1:
self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
k >>= 1
def query(self, l, r):
"""
[l, r)のsegfuncしたものを得る
l: index(0-index)
r: index(0-index)
"""
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.tree[l])
l += 1
if r & 1:
res = self.segfunc(res, self.tree[r - 1])
l >>= 1
r >>= 1
return res
def main():
n=II()
s=input().rstrip().decode()
S=[]
for i in s:
S.append(ord(i)-ord("a"))
seg=[SegTree([1]*n,segfunc,ide_ele) for _ in range(26)]
#print(S)
#print(seg)
for i in range(n):
seg[S[i]].update(i,0)
q=II()
for _ in range(q):
a,b,c=input().split()
if int(a)==1:
b=int(b)-1
seg[S[b]].update(b,1)
t=ord(c)-ord("a")
seg[t].update(b,0)
S[b]=t
else:
#print(S)
b=int(b)-1
c=int(c)
cnt=0
for se in seg:
if se.query(b,c)==0:
cnt+=1
print(cnt)
if __name__=="__main__":
main()
| inp=input().split()
s = inp[0]
t = inp[1]
print(t+s) | 0 | null | 82,749,064,646,160 | 210 | 248 |
N = int(input())
if N % 2 ==1:
print(0)
exit()
else:
count =0
N = N//2
while N //5:
N = N//5
count +=N
print(count) | N, A, B = map(int, input().split())
if A == 0:
print(0)
elif N >= A+B:
if N%(A+B) >= A:
blue = A * (N // (A+B)) + A
else:
blue = A * (N // (A+B)) + N%(A+B)
print(blue)
elif N < A+B:
if N < A:
print(N)
else:
print(A) | 0 | null | 85,727,096,001,340 | 258 | 202 |
n = int(input())
a_line = []
b_line = []
for i in range(n):
a, b = map(int, input().split())
a_line.append(a)
b_line.append(b)
a_line.sort()
b_line.sort()
if n % 2 == 0:
left = a_line[n // 2 - 1] + a_line[n // 2]
right = b_line[n // 2 - 1] + b_line[n // 2]
print(right - left + 1)
else:
print(b_line[n // 2] - a_line[n // 2] + 1) | n=int(input())
import bisect as bi
A=[] ; B=[]
for i in range(n):
a,b=map(int,input().split())
A.append(a)
B.append(b)
A.sort() ; B.sort()
if n%2==1:
a=A[(n-1)//2] ; b=B[(n-1)//2]
print(b-a+1)
else:
a=(A[n//2-1]+A[n//2])/2 ; b=(B[n//2-1]+B[n//2])/2
print(int((b-a)/0.5)+1)
| 1 | 17,283,256,910,698 | null | 137 | 137 |
N,A,B = map(int,input().split())
if (B-A)%2 == 0:
ans = [N-A,(B-A)//2,B-1]
print(min(ans))
else:
ans = [N-A,B-1,((B-A-1)//2)+(N-B+1),((B-A-1)//2)+A]
print(min(ans)) | n,a,b=map(int,input().split())
if (b-a)%2==0:
print((b-a)//2);exit()
a-=1;b-=1
# print(min(b,n-1-a))
ans1=0; ans2=0
ans1+= a
aa=0 ; bb=b-a
ans1+= (bb//2+1)
ans2=n-1-b
b=n-1
a+=ans2
ans2+= (b-a)//2+1
print(min(ans1,ans2)) | 1 | 109,913,076,362,192 | null | 253 | 253 |
def main():
import sys
input=sys.stdin.buffer.readline
n=int(input())
d=[0]*n+[1<<c-97for c in input()[:n]]
for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i]
r=[]
for _ in range(int(input())):
q,a,b=input().split()
i,s=int(a)+n-1,0
if q<b'2':
d[i]=1<<b[0]-97
while i:
i//=2
d[i]=d[i+i]|d[i-~i]
continue
j=int(b)+n
while i<j:
if i&1:
s|=d[i]
i+=1
if j&1:
j-=1
s|=d[j]
i//=2
j//=2
r+=bin(s).count('1'),
print(' '.join(map(str,r)))
main() | n = int(input())
a = 0
w = 0
t = 0
r = 0
for i in range(n):
s = input()
if s == 'AC':
a+=1
elif s =='WA':
w +=1
elif s =='TLE':
t +=1
else:
r+=1
print('AC x '+str(a))
print('WA x '+str(w))
print('TLE x '+str(t))
print('RE x '+str(r)) | 0 | null | 35,578,703,132,362 | 210 | 109 |
n = int(input())
playList = []
sumTerm = 0
for i in range(n) :
song = input().split()
song[1] = int(song[1])
playList.append(song)
sumTerm += song[1]
x = input()
tmpSumTerm = 0
for i in range(n) :
tmpSumTerm += playList[i][1]
if playList[i][0] == x :
print(sumTerm - tmpSumTerm)
break
| # Aizu Problem ALDS_1_1_A: Insertion Sort
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input2.txt", "rt")
def printA(A):
print(' '.join([str(a) for a in A]))
def insertion_sort(A):
for i in range(1, len(A)):
key = A[i]
# insert A[i] into the sorted sequence A[0,...,j-1]
j = i - 1
while j >= 0 and A[j] > key:
A[j+1] = A[j]
j -= 1
A[j+1] = key
printA(A)
N = int(input())
A = [int(_) for _ in input().split()]
printA(A)
insertion_sort(A) | 0 | null | 48,706,484,578,880 | 243 | 10 |
# SelectionSort(A)
#1 for i = 0 to A.length-1
#2 mini = i
#3 for j = i to A.length-1
#4 if A[j] < A[mini]
#5 mini = j
#6 swap A[i] and A[mini]
# リストの宣言
A = []
# 入力の最初の行に、数列の長さを表す整数 N が与えられます。
# 2 行目に、N 個の整数が空白区切りで与えられます。
LENGTH =int(input())
A = input().split()
# 変数
i = 0
CHANGE_COUNT = 0
while i <= LENGTH -1:
j = i + 1
mini = i
while j <= LENGTH -1:
if int(A[j]) < int(A[mini]) :
mini = j
j += 1
if mini != i:
tmp = A[i]
A[i] = A[mini]
A[mini] = tmp
CHANGE_COUNT += 1
i += 1
print(" ".join(map(str,A)))
print (CHANGE_COUNT)
| import sys
input = sys.stdin.readline
N, M, L = map(int, input().split())
INF = float('inf')
VD = [[INF] * N for _ in range(N)]
for _ in range(M):
a, b, c = map(int, input().split())
a -= 1
b -= 1
VD[a][b] = c
VD[b][a] = c
for i in range(N):
VD[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
if VD[i][j] > VD[i][k] + VD[k][j]:
VD[i][j] = VD[i][k] + VD[k][j]
WD = [[INF] * N for _ in range(N)]
for i in range(N):
WD[i][i] = 0
for j in range(i+1,N):
d = VD[i][j]
if d <= L:
WD[i][j] = 1
WD[j][i] = 1
for k in range(N):
for i in range(N):
for j in range(N):
if WD[i][j] > WD[i][k] + WD[k][j]:
WD[i][j] = WD[i][k] + WD[k][j]
Q = int(input())
for _ in range(Q):
s, t = map(int, input().split())
print(WD[s-1][t-1]-1 if WD[s-1][t-1] < INF else -1) | 0 | null | 86,607,456,658,360 | 15 | 295 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n, m = map(int, readline().split())
if m % 2 == 0:
rem = m
for i in range(m // 2):
print(i + 1, m + 1 - i)
rem -= 1
if rem == 0:
return
for i in range(n):
print(m + 2 + i, 2 * m + 1 - i)
rem -= 1
if rem == 0:
return
else:
rem = m
for i in range((m - 1) // 2):
print(i + 1, m - i)
rem -= 1
if rem == 0:
return
for i in range(n):
print(m + 1 + i, 2 * m + 1 - i)
rem -= 1
if rem == 0:
return
if __name__ == '__main__':
main()
| import math
a = float(input())
print(2*a*math.pi) | 0 | null | 29,853,231,654,036 | 162 | 167 |
A, B = map(int, input().split())
print(A * B) if len(str(A)) == 1 and len(str(B)) == 1 else print(-1) | (A,B)=input().split()
(A,B)=(int(A),int(B))
if 1<=A<=9 and 1<=B<=9:
print(A*B)
else:
print(-1) | 1 | 157,934,809,076,290 | null | 286 | 286 |
class SegmentTree(object):
"""
セグメントツリー (0-indexed)
1. 値の更新 O(logN)
2. 区間クエリ O(logN)
"""
def __BinOp(self, x, y):
""" セグ木で使用する二項演算 """
return x | y
def __init__(self, init_ele, N:int):
"""
セグ木を構築する
init_ele: 単位元
N: 要素数
"""
self.__init_ele = init_ele
self.__n = 1
while self.__n < N:
self.__n <<= 1
self.__dat = [init_ele] * (2 * self.__n)
def update(self, k:int, x):
""" k番目の値をxに変更する """
k += self.__n - 1
self.__dat[k] = x
while k:
k = (k - 1) // 2
self.__dat[k] = self.__BinOp(
self.__dat[k * 2 + 1], self.__dat[k * 2 + 2]
)
def query(self, p:int, q:int):
""" 区間クエリ [p,q) """
if q <= p: return self.__init_ele
p += self.__n - 1
q += self.__n - 2
res = self.__init_ele
while q - p > 1:
if not (p & 1):
res = self.__BinOp(res, self.__dat[p])
if q & 1:
res = self.__BinOp(res, self.__dat[q])
q -= 1
p = p // 2
q = (q - 1) // 2
res = self.__BinOp(res, self.__dat[p])
if p != q: res = self.__BinOp(res, self.__dat[q])
return res
def get_num(self, k:int):
""" k番目の値を取得する """
k += self.__n - 1
return self.__dat[k]
############################################################
N = int(input())
ST = SegmentTree(0, N)
for i, s in enumerate(list(input())):
ST.update(i, 1 << (ord(s) - ord('a')))
Q = int(input())
for _ in range(Q):
x,y,z = map(str,input().split())
x = int(x); y = int(y)
if x == 1:
ST.update(y - 1, 1 << (ord(z) - ord('a')))
else:
z = int(z)
print(bin(ST.query(y - 1, z)).count("1")) | import sys
def input(): return sys.stdin.readline().rstrip()
def ctoi(c):
return ord(c)-97
class BIT:
def __init__(self, n):
self.unit_sum=0 # to be set
self.n=n
self.dat=[0]*(n+1)#[1,n]
def add(self,a,x): #a(1-)
i=a
while i<=self.n:
self.dat[i]+=x
i+=i&-i
def sum(self,a,b=None):
if b!=None:
return self.sum(b-1)-self.sum(a-1) #[a,b) a(1-),b(1-)
res=self.unit_sum
i=a
while i>0:
res+=self.dat[i]
i-=i&-i
return res #Σ[1,a] a(1-)
def __str__(self):
self.ans=[]
for i in range(1,self.n):
self.ans.append(self.sum(i,i+1))
return ' '.join(map(str,self.ans))
def main():
n=int(input())
S=list(input())
q=int(input())
BIT_tree=[]
for i in range(26):
obj=BIT(n+1)
BIT_tree.append(obj)
for i in range(n):
BIT_tree[ctoi(S[i])].add(i+1,1)
for _ in range(q):
query=input().split()
if query[0]=="1":
index,x=int(query[1])-1,query[2]
BIT_tree[ctoi(S[index])].add(index+1,-1)
BIT_tree[ctoi(x)].add(index+1,1)
S[index]=x
else:
l,r=int(query[1])-1,int(query[2])-1
ans=0
for c in range(26):
if BIT_tree[c].sum(l+1,r+2):
ans+=1
print(ans)
if __name__=='__main__':
main() | 1 | 62,506,645,146,062 | null | 210 | 210 |
from operator import itemgetter
n = int(input())
s = []
for i in range(n):
l = list(map(int, input().split()))
rang = [l[0] - l[1], l[0] + l[1]]
s.append(rang)
s_sort = sorted(s, key=itemgetter(1))
ans = 0
last = -float("inf")
for i in range(n):
if last <= s_sort[i][0]:
ans += 1
last = s_sort[i][1]
print(ans)
| def main():
a, b, c = map(int,input().split())
_set = set()
if a <= c and b >= c: _set.add(c)
if c // 2 < b:
b = c // 2
if c % 2 == 0:
_set = _set | set(range(a, b+1))
else:
if a % 2 == 0:
_set = _set | set(range(a+1, b+1, 2))
else:
_set = _set | set(range(a, b+1, 2))
print(sum(map(lambda x: c % x == 0, _set)))
main() | 0 | null | 45,196,851,245,572 | 237 | 44 |
s = int(input())
c = s // 500
d = s % 500
e = d //5
h = c*1000 + e*5
print(h) | import math
a, b, c, d = map(int, input().split())
takahashi_attacks = math.ceil(c / b)
aoki_attacks = math.ceil(a / d)
if takahashi_attacks <= aoki_attacks:
print('Yes')
else:
print('No') | 0 | null | 36,368,669,043,168 | 185 | 164 |
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
cnt_list = Counter(A)
total = sum([cnt*(cnt-1)//2 if cnt > 1 else 0 for cnt in cnt_list.values()])
print(*[total-cnt_list[a]+1 for a in A], sep='\n') | import sys
sys.setrecursionlimit(10 ** 8)
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]
def main():
N, K = ZZ()
A = sorted(ZZ(), reverse=True)
F = sorted(ZZ())
if sum(A) <= K:
print(0)
return
cost = list()
for a, f in zip(A, F): cost.append(a*f)
ok = 10 ** 12
ng = -1
while ok - ng > 1:
mid = (ok+ng)//2
cc = 0
for i in range(N): cc += max(0, (cost[i]-mid+F[i]-1)//F[i])
if cc <= K: ok = mid
else: ng = mid
print(ok)
return
if __name__ == '__main__':
main()
| 0 | null | 106,515,407,738,110 | 192 | 290 |
l = input()
l = l.split()
a = int(l[0])
b = int(l[1])
print(a*b,end=" ")
print(2*a + 2*b) | (a,b) = map(int,raw_input().split())
print '%d %d' %(a*b,(a+b)*2) | 1 | 311,450,018,440 | null | 36 | 36 |
while True:
h,w = map(int,input().split())
if h == w == 0:
break
for y in range(h):
for x in range(w):
if (y+x)%2 == 0:
print('#',end="")
if (y+x)%2 == 1:
print('.',end="")
print()
print() | from collections import defaultdict
it = lambda: list(map(int, input().strip().split()))
def solve():
N, X, M = it()
if N == 1: return X % M
cur = 0
cnt = 0
value = defaultdict(int)
history = defaultdict(int)
for i in range(N):
if X in history: break
value[X] = cur
history[X] = i
cnt += 1
cur += X
X = X * X % M
loop = cur - value[X]
period = i - history[X]
freq, rem = divmod(N - cnt, period)
cur += freq * loop
for i in range(rem):
cur += X
X = X * X % M
return cur
if __name__ == '__main__':
print(solve()) | 0 | null | 1,826,455,583,654 | 51 | 75 |
#!/usr/bin/env python3
h,w,k = map(int,input().split())
b =[]
for i in range(h):
s = input()
b.append(s)
# 縦の切り方を固定すれば、左から見て貪欲に考えることができる。
# どれかの切り方でK+1 以上1 のマスがあれば、そこで切る
if h == 1:
print(math.ceil(s//k))
exit()
# リストで現在のそれぞれのブロックの1の数を持つ
# 列の切断が入ったときに全て0に初期化
# bit 全探索は 2 ** h-1 存在する
ans = h*w #INF
for i in range(2**(h-1)):
cnt_white = [0]
# ループの中で宣言する
ans_i = 0
#前処理として、どこに切れ込みがあるかを見て、リストの構成
for bit in range(h-1):
if i >> bit & 1:
cnt_white.append(0)
ans_i += 1
#print("i = ",i,cnt_white)
c = 0
last_div = 0
while c < w:# 左から貪欲
r_idx = 0
for r in range(h):
if b[r][c] == "1":#対応するブロックのcnt+=1
cnt_white[r_idx] += 1
#print("col = ",c,cnt_white,r_idx,ans_i)
if i >> r & 1:#次にブロックが変わるのでidxを増やす
r_idx += 1
# 1行だけでmax(cnt_white) >= k+1になるときはその切り方では不可能
if max(cnt_white) >= k+1:
# 戻らないといけない
ans_i += 1
if c == last_div:
ans_i = h*w #INF
break
last_div = c
c -= 1
cnt_white = [0]*len(cnt_white)#初期化
#print("initialize",last_div)
c += 1
ans = min(ans,ans_i)
print(ans) | import itertools
h, w, k = map(int, input().split())
a = []
for i in range(h):
s = input()
a.append(s)
s = [[0 for i in range(w)] for i in range(h)]
ans = h+w
for grid in itertools.product([0,1], repeat=h-1):
ary = [[0]]
for i in range(h-1):
if grid[i] == 1:
ary.append([i+1])
else:
ary[-1].append(i+1)
# print (grid, ary)
wk = 0
for i in grid:
if i == 1:
wk += 1
# print (wk)
cnt = [0] * len(ary)
for j in range(w):
for ii, g in enumerate(ary):
for b in g:
if a[b][j] == '1':
cnt[ii] += 1
if any(W > k for W in cnt):
wk += 1
cnt = [0] * len(ary)
for ii, g in enumerate(ary):
for jj in g:
if a[jj][j] == '1':
cnt[ii] += 1
if any(W > k for W in cnt):
wk = h+w
break
ans = min(ans, wk)
print (ans) | 1 | 48,433,170,117,592 | null | 193 | 193 |
N = int(input())
a = [int(x) for x in input().split()]
def selectionSort(A, N):
count = 0
for i in range(0,N):
minj = i
for j in range(i,N):
if A[minj] > A[j]:
minj = j
if i != minj:
tmp = A[minj]
A[minj] = A[i]
A[i] = tmp
count += 1
return A,count
ans,c = selectionSort(a,N)
print(*ans)
print(c) | N, M = map(int, input().split())
AB = [list(map(lambda x : int(x) - 1, input().split())) for _ in range(M)]
class UnionFind():
def __init__(self, n):
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
uf = UnionFind(N)
for a, b in AB:
uf.union(a, b)
ans = min(uf.parents)
print(-ans)
| 0 | null | 2,019,788,504,792 | 15 | 84 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N = getN()
A = getList()
# N // 2個の整数をどの2箇所も連続しないように選ぶ
# 和の最大値を求めよ
# 通りの数は? まあまあ多い
# 偶数の場合
# 始点がA[1]なら1通りに定まる
# 始点がA[0]なら?
# 次に3個先を取ると1通りに定まる
# 次に2個先を取り、その次に3個先を取ると1通りに定まる
# dp[i][j]: i回目までに3つ飛ばしをj回使った
# 長さが偶数なら1回まで使える
if N % 2 == 0:
dp = [[-float('inf')] * 2 for i in range(N)]
dp[0][0] = A[0]
dp[1][0] = A[1]
for i in range(2, N):
for j in range(1, -1, -1):
if j == 0:
dp[i][j] = max(dp[i][j], dp[i - 2][j] + A[i])
elif j == 1 and i - 3 >= 0:
dp[i][j] = max(dp[i][j], dp[i - 2][j] + A[i])
if i - 3 >= 0 and j - 1 >= 0:
dp[i][j] = max(dp[i][j], dp[i - 3][j - 1] + A[i])
# 0個飛ばしdp[-2]:奇数個目だけ 0個飛ばしdp[-1]:偶数個目だけ 1個飛ばしdp[-1]
print(max(dp[-2][0], dp[-1][0], dp[-1][1]))
# 長さが奇数なら2回まで使える
else:
dp = [[-float('inf')] * 3 for i in range(N)]
dp[0][0] = A[0]
dp[1][0] = A[1]
for i in range(2, N):
for j in range(2, -1, -1):
if j == 0:
dp[i][j] = max(dp[i][j], dp[i - 2][j] + A[i])
elif j >= 1 and i - 3 >= 0:
dp[i][j] = max(dp[i][j], dp[i - 2][j] + A[i])
if i - 3 >= 0 and j - 1 >= 0:
dp[i][j] = max(dp[i][j], dp[i - 3][j - 1] + A[i])
opt_1 = [A[i] for i in range(N) if i % 2 == 0]
opt_2 = [A[i] for i in range(N) if i % 2 == 1]
# 2個飛ばしならdp[-1]のが該当
# 1個飛ばしならdp[-1], dp[-2]のが該当
# 0個飛ばしは奇数個目だけ - その中の最小値、偶数個目だけ
print(max(dp[-1][2], dp[-1][1], dp[-2][1], sum(opt_1) - min(opt_1), sum(opt_2))) | A, B, N = map(int, input().split())
x = N if B-1 > N else B-1
print(A*x//B-A*(x//B)) | 0 | null | 32,854,176,740,892 | 177 | 161 |
# -*- coding: utf-8 -*-
def main():
from math import ceil
n = int(input())
count = 0
for i in range(1, ceil(n / 2)):
j = n - i
if i != j:
count += 1
print(count)
if __name__ == '__main__':
main()
| H,W=map(int,input().split())
w1=0--W//2
w2=W//2
if H==1 or W==1:
print(1)
else:
print(w1*(0--H//2)+w2*(H//2)) | 0 | null | 102,277,770,784,950 | 283 | 196 |
# -*- coding: utf-8 -*-
'import sys'
input()
a=[int(i) for i in input().split()]
a.reverse()
f=0
for i in range(len(a)):
if f: print(" ",end="")
print("{}".format(a[i]),end="")
f=1
print("") | all_N = []
while True:
N = list(map(int, input().split(' ')))
if N[0] == 0 and N[0] == 0:
break
all_N.append(N)
for i in range(len(all_N)):
print('#' * all_N[i][1])
for j in range(all_N[i][0]-2):
print('#%s#' % ((all_N[i][1]-2) * '.'))
print('#' * all_N[i][1])
print('') | 0 | null | 917,165,922,190 | 53 | 50 |
s,t,a,b,u=open(0).read().split()
if s==u:
print(int(a)-1,b)
elif t==u:
print(a,int(b)-1) | def resolve():
a = int(input())
ans = a * (1 + a * (1 + a))
print(ans)
if __name__ == "__main__":
resolve() | 0 | null | 41,021,742,714,520 | 220 | 115 |
n = int(input())
al = list(map(int, input().split()))
s = sum(al)
acc = 0
res = 10**18
for a in al:
acc += a
res = min(res, abs((s-acc)-acc))
print(res) | b=input().split(' ')
b[0]=int(b[0])
b[1]=int(b[1])
k=1
m=0
while k==1:
if b[0]<=0:
k=k+1
b[0]=b[0]-b[1]
m=m+1
print(m-1) | 0 | null | 109,907,027,965,020 | 276 | 225 |
n,d=list(map(int,input().split()))
s=list(map(int,input().split()))
v=0
for i in s:
v+=int(i)
if v>=n:
print("Yes")
else:
print("No")
| print(*set([input(),input()])^set([*'123'])) | 0 | null | 94,390,548,388,592 | 226 | 254 |
N,M,L = (int(i) for i in input().split())
A = [[int(i) for i in input().split()] for i in range(N)]
B = [[int(i)for i in input().split()] for i in range(M)]
C = []
for i in range(N):
for i2 in range(L):
ans = 0
for i3 in range(M):
ans += A[i][i3]*B[i3][i2]
if i2 == L-1:
print(ans)
else:
print(ans,end=" ") | n=int(input())
def dfs(s,mx):
if len(s)==n:
print(s)
return
for c in range(ord('a'),mx+2):
t=s
t+=chr(c)
dfs(t,max(mx,c))
dfs("",ord('a')-1) | 0 | null | 26,737,393,546,720 | 60 | 198 |
def cmb(n, r, mod):
if (r < 0) or (n < r):
return 0
r = min(r, n-r)
return fact[n]*factinv[r]*factinv[n-r]%mod
mod = 10**9+7
N = 10**6 # N は必要分だけ用意する
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N+1):
fact.append((fact[-1]*i)%mod)
inv.append((-inv[mod%i]*(mod//i))%mod)
factinv.append((factinv[-1]*inv[-1])%mod)
n, k = map(int,input().split())
ans = 0
for i in range(0, min(n, k+1)):
#0がi個
ans = (ans + cmb(n, i, mod) * cmb(n-1, i, mod)) % mod
print(ans) | #import numpy as np
N = int(input())
a = list(map(int, input().split()))
all_xor = 0
for _a in a:
all_xor = all_xor ^ _a
for _a in a:
print(all_xor ^ _a)
| 0 | null | 39,911,275,257,220 | 215 | 123 |
n = int(input())
aas = list(map(int, input().split()))
if n == 1 and aas == [1]:
print(0)
exit()
t = 0
for i in aas:
if i == t + 1:
t += 1
print(n-t if t > 0 else -1) | import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
n = I()
lst = LI()
cnt = 1
ans = 0
for brock in lst:
if brock == cnt:
cnt += 1
else:
ans += 1
if cnt != 1:
print(ans)
else:
print(-1)
main()
| 1 | 115,114,416,468,480 | null | 257 | 257 |
import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)[0:x]
q = sorted(list(map(int, input().split())), reverse=True)[0:y]
r = sorted(list(map(int, input().split())), reverse=True)
pq = sorted((p + q))
for i in range(min(c, (x + y))):
if pq[i] > r[i]:
break
pq[i] = r[i]
print(sum(pq))
if __name__ == '__main__':
main()
| while True:
h, w = map(int, input().split())
if(w == h == 0): break
for i in range(h):
for j in range(w):
if (i + j) % 2:
print('.', end = '')
else:
print('#', end = '')
print('')
print('')
| 0 | null | 23,014,822,987,392 | 188 | 51 |
n = int(input())
order = [''] * n
st = [''] * n
for i in range(n):
order[i], st[i] = map(str, input().split())
dic = {}
for i in range(n):
if order[i] == 'insert':
dic.setdefault(st[i], 0)
else:
if st[i] in dic:
print('yes')
else:
print('no')
| import sys
d={}
input()
for e in sys.stdin:
c,g=e.split()
if'i'==c[0]:d[g]=0
else:print(['no','yes'][g in d])
| 1 | 79,458,191,968 | null | 23 | 23 |
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
inf=float("inf")
DP=[[-inf]*4 for _ in range(n+1)]
DP[0][2]=0
for i,a in enumerate(A):
if (i+1)%2==0:
DP[i+1][0]=DP[i][3]+a
if i>=1:
DP[i+1][0]=max(DP[i+1][0],DP[i-1][2]+a)
DP[i+1][2]=DP[i][0]
DP[i+1][3]=max(DP[i][1],DP[i][3])
if i>=1:
DP[i+1][3]=max(DP[i+1][3],DP[i-1][2])
else:
DP[i+1][0]=DP[i][2]+a
DP[i+1][1]=DP[i][3]+a
DP[i+1][3]=max(DP[i][0],DP[i][2])
if n%2==0:
print(max(DP[n][0],DP[n][2]))
else:
print(max(DP[n][1],DP[n][3]))
| N = int(input())
A_list = [int(i) for i in input().split()]
monney = 1000
stock = 0
def max_day(index):
if index == N-1 or (A_list[index] > A_list[index+1]):
return index
return max_day(index+1)
def min_day(index):
if index == N-1:
return -1
if A_list[index] < A_list[index+1]:
return index
return min_day(index+1)
def main(day=0, flag="buy"):
global monney, stock
if flag == "buy":
buy_day = min_day(day)
if buy_day == -1:
return monney
stock, monney = divmod(monney, A_list[buy_day])
return main(buy_day+1, "sell")
elif flag == "sell":
sell_day = max_day(day)
monney += stock * A_list[sell_day]
stock = 0
if sell_day == N-1:
return monney
return main(sell_day+1, "buy")
print(main())
| 0 | null | 22,466,221,828,998 | 177 | 103 |
def main():
n, k = [int(x) for x in input().split()]
scores = [int(x) for x in input().split()]
# zip にすると2つのリストを作るのか,これよりも少し時間とメモリ増。
{
print('Yes' if scores[index] < new else 'No')
for index, new in enumerate(scores[k:])}
if __name__ == '__main__':
main()
| N, K = map(int, input().split())
A = list(map(int, input().split()))
result = []
for i in range(K, N):
if A[i] > A[i - K]:
result.append('Yes')
else:
result.append('No')
print(*result, sep='\n') | 1 | 7,140,725,516,576 | null | 102 | 102 |
from collections import deque
def solve(A, K):
a = deque() # 繰り返し部分
seen = [False for _ in range(len(A))] # 一度見たかどうか
cur = 0
while True:
# 一度通った頂点を見つけたときの処理
if seen[cur]:
while a[0] != cur:
# 最初の余計な数手分を除去する
K -= 1
a.popleft()
# K が限界になったらリターン
if K == 0:
return a[0] + 1
break
# 最初は愚直にシミュレーションしつつ、履歴をメモしていく
a.append(cur)
seen[cur] = True
cur = A[cur]
return a[K % len(a)] + 1
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [v - 1 for v in A]
print(solve(A, K)) | N, K = map(int,input().split())
As = list(map(int,input().split()))
visited = [0] * N
path = []
now_town = 1
while(True):
visited[now_town-1] = 1
path.append(now_town)
now_town = As[now_town-1]
if visited[now_town-1] == 1:
break
index = path.index(now_town)
loop = path[index:len(path)]
loop_len = len(loop)
if index < K:
k = K - index
r = k % loop_len
print(loop[r])
else:
print(path[K])
| 1 | 22,770,800,274,430 | null | 150 | 150 |
n = int(input())
hon = [2,4,5,7,9]
pon = [0,1,6,8]
num = n % 10
if num in hon:
print("hon")
elif num in pon:
print("pon")
elif num == 3:
print("bon") | N = int(input())
max = 10**6
sum = 0
for i in range(1,N+1):
if i % 3 != 0 and i % 5 != 0:
sum = sum + i
print(sum)
| 0 | null | 27,040,074,399,470 | 142 | 173 |
n = int(input())
lr_cnt = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, n + 1):
str_i = str(i)
start = int(str_i[0])
end = int(str_i[-1])
lr_cnt[start][end] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += lr_cnt[i][j] * lr_cnt[j][i]
print(ans)
| import math
from collections import Counter
N = int(input())
c = Counter()
ans = 0
for n in range(1, N + 1):
left = n // (10 ** int(math.log10(n)))
right = n % 10
c[(left, right)] += 1
for left, right in c.keys():
ans += c[(left, right)] * c[(right, left)]
print(ans)
| 1 | 86,775,942,449,742 | null | 234 | 234 |
# -*- coding: utf-8 -*-
input_list = input().split(" ")
print(int(input_list[0]) * int(input_list[1])) | X, Y = map(int, input().split())
ans = "No"
for i in range(101) :
for j in range(101) :
if(i + j != X) :
continue
if(2*i + 4*j != Y) :
continue
ans = "Yes"
break
print(ans) | 0 | null | 14,661,021,797,968 | 133 | 127 |
n,k = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
s = [0]
for i in range(len(a)):
s.append(s[-1]+a[i])
for i in range(len(s)):
s[i] = (s[i] - i) % k
# print(s)
d = {0:1}
ans = 0
for j in range(1,n+1):
if s[j] in d:
d[s[j]] += 1
else:
d[s[j]] = 1
if j >= k:
d[s[j-k]] -= 1
ans += d[s[j]] - 1
# print(d)
# print(ans)
print(ans) | import sys
import itertools
import collections
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n, k = list(map(int, input().rstrip('\n').split()))
ls = [0] + list(map(lambda x: int(x) - 1, input().rstrip('\n').split()))
ls = [i % k for i in list(itertools.accumulate(ls))]
d = collections.defaultdict(int)
t = 0
for i, x in enumerate(ls):
t += d[x]
d[x] += 1
if i >= k - 1:
d[ls[i - k + 1]] -= 1
print(t)
if __name__ == '__main__':
solve()
| 1 | 137,620,229,337,472 | null | 273 | 273 |
import math
def is_prime(x):
if x == 2:
return True
if (x % 2 == 0):
return False
m = math.ceil(math.sqrt(x))
for i in range(3, m + 1):
if x % i == 0:
return False
return True
n = int(input())
prime = 0
for i in range(n):
x = int(input())
if is_prime(x):
prime += 1
print(prime) | c = 0
while True:
try:
n = int(input())
except EOFError:
break
c += 1
for i in range(2, int(n ** 0.5 + 1)):
if n % i == 0:
c -= 1
break
print(c) | 1 | 10,223,512,910 | null | 12 | 12 |
if __name__ == '__main__':
nm = input()
nm = nm.split()
n = int(nm[0])
m = int(nm[1])
if n%2==1:
for i in range(1,m+1):
print(i,n+1-i)
if n%2==0:
t = n
f = 0
for i in range(1,m+1):
p = i-1+t-n
if p>=n-i-1 and f==0:
f = 1
n -= 1
print(i,n)
n -= 1
| s = input()
t = input()
max = 0
for i in range(len(s) -len(t) + 1):
target = s[i:i+len(t)]
matched = 0
for j in range(len(target)):
if target[j] == t[j]:
matched += 1
if matched > max:
max = matched
print(len(t) - max)
| 0 | null | 16,154,069,501,010 | 162 | 82 |
h,w,p=map(int,input().split())
A=[]
ans=0
for i in range(h):
A.append(list(input()))
for i in range(2**h):
hs=[False]*h
for j in range(h):
if ((i>>j)&1):
hs[j]=True
for k in range(2**w):
ws=[False]*w
for l in range(w):
if ((k>>l)&1):
ws[l]=True
cnt=0
for a in range(h):
if hs[a]==True:
for b in range(w):
if ws[b]==True:
if A[a][b]=='#':
cnt+=1
if cnt==p:
ans+=1
print(ans) | while True:
n, x = map(int, input().split())
if (n == x == 0):
break
count = 0
for a in range(1, x // 3):
for b in range(a + 1, x // 2):
for c in range(b + 1, n + 1):
Sum = a + b + c
if (Sum == x):
count += 1
print(count) | 0 | null | 5,183,051,547,002 | 110 | 58 |
a,b,c,k=map(int,input().split())
ai=0
bi=0
ci=0
if a >= k:
ai=k
else:
ai=a
if b>= k-ai:
bi=k-ai
else:
bi=b
ci= k - ai - bi
print(ai-ci)
| import sys
ans=0
A, B, C, K = (int(x) for x in input().split())
if A>K:
print(K)
sys.exit(0)
else:
K-=A
ans+=A
if B>K:
print(ans)
sys.exit(0)
else:K-=B
if C>K:
print(ans-K)
sys.exit()
else:
ans-=C
print(ans) | 1 | 21,895,441,692,942 | null | 148 | 148 |
from collections import deque
N,U,V = map(int, input().split())
U,V = U-1, V-1
E = [[] for _ in range(N)]
for _ in range(N-1):
a,b = map(int, input().split())
a,b = a-1, b-1
E[a].append(b)
E[b].append(a)
def BFS(root):
D = [ 0 for _ in range(N) ]
visited = [False for _ in range(N)]
willSearch = [ False for _ in range(N)]
Q = deque()
Q.append(root)
willSearch[root] = True
while len(Q) > 0:
now = Q.pop()
visited[now] = True
for nx in E[now]:
if visited[nx] or willSearch[nx]:
continue
willSearch[nx] = True
D[nx] = D[now] + 1
Q.append(nx)
return D
UD = BFS(U)
VD = BFS(V)
#print(UD)
#print(VD)
#初手で青木くんのPOINTにしか行けないケース
if E[U] == [V]:
print(0)
exit(0)
ans=0
for i in range(N):
if UD[i]<=VD[i]:
ans=max(ans,VD[i]-1)
print(ans) | import sys
sys.setrecursionlimit(10**9)
f=lambda:map(int,input().split())
n,st,sa=f()
st-=1
sa-=1
g=[[] for _ in range(n)]
for _ in range(n-1):
a,b=f()
g[a-1].append(b-1)
g[b-1].append(a-1)
def dfs(v,p=-1,d=0):
l[v]=d
for c in g[v]:
if c==p: continue
dfs(c,v,d+1)
def dist(s):
global l
l=[0]*n
dfs(s)
return l
lt=dist(st)
la=dist(sa)
m=0
for i in range(n):
if lt[i]<la[i]: m=max(m,la[i])
print(m-1) | 1 | 117,170,385,776,468 | null | 259 | 259 |
import sys
def selection_sort(x):
count = 0
for i in range(0,len(l)-1):
mini = i
for j in range(i+1,len(l)):
if(x[j] < x[mini]):
mini = j
if(mini != i):
count += 1
temp = x[i]
x[i] = x[mini]
x[mini] = temp
for data in x:
print data,
print
print count
l = []
for input in sys.stdin:
l.append(input)
l = l[1:]
l = l[0].split()
for i in range(0,len(l)):
l[i] = int(l[i])
selection_sort(l)
| # coding: utf-8
# Here your code !
S = int(input())
N = list(map(int,input().split(" ")))
def seleSort(n,s):
c =0
for i in range(s):
minj = i
for j in range(i+1,s):
if n[j]<n[minj]:
minj = j
n[i],n[minj]=n[minj],n[i]
if i!= minj:
c+=1
print(" ".join(list(map(str,n))))
print(c)
seleSort(N,S) | 1 | 19,978,407,130 | null | 15 | 15 |
n = int(raw_input())
S = map(int, raw_input().split())
q = int(raw_input())
T = map(int, raw_input().split())
ans = 0
for i in T:
if i in S:
ans += 1
print ans | x = int(input())
if x == 0: print(1)
elif x == 1: print(0) | 0 | null | 1,480,881,050,698 | 22 | 76 |
#! python3
# shuffle.py
def shuffle(text, n):
return text[n:] + text[:n]
while True:
sent = input()
if sent == '-': break
m = int(input())
h = 0
for i in range(m):
h += int(input())
h = h % len(sent)
sent = shuffle(sent, h)
print(sent)
| A = input()
while(A != '-'):
m = int(input())
for i in range(m):
h = int(input())
A = A[h:]+A[:h]
print(A)
A = input()
| 1 | 1,916,027,792,340 | null | 66 | 66 |
N,M=map(int, input().split())
peaks=list(map(int, input().split()))
flag=[1]*N
a=0
b=0
for i in range(M):
a,b=map(int,input().split())
a-=1
b-=1
if peaks[a]<=peaks[b]:
flag[a]=0
if peaks[a]>=peaks[b]:
flag[b]=0
ans=0
for i in flag:
ans+=i
print(ans) | a = lambda x: x+(x**2)+(x**3)
n = int(input())
print(a(n)) | 0 | null | 17,783,012,495,776 | 155 | 115 |
X = int(input())
ans=0
if X < 500:
print((X // 5) * 5)
else:
ans += (X // 500)*1000
X -= (X//500)*500
ans += (X//5)*5
print(ans)
| x = int(input())
n_500 = x//500
n_5 = (x%500)//5
print(n_500*1000 + n_5*5) | 1 | 42,681,115,626,100 | null | 185 | 185 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n, k, c = map(int, input().split())
S = [1 if a == "o" else 0 for a in input()]
count = 0
X = [0] * n
Y = [0] * n
i = 0
while i < n:
if S[i]:
count += 1
X[i] = 1
i += c + 1
else:
i += 1
if count > k:
exit()
i = n - 1
while i >= 0:
if S[i]:
Y[i] = 1
i -= c + 1
else:
i -= 1
for i in range(0, n):
if X[i] and Y[i]:
print(i + 1) | #ライブラリインポート
from collections import defaultdict
con = 10 ** 9 + 7
#入力受け取り
def getlist():
return list(map(int, input().split()))
#処理内容
def main():
N, K, C = getlist()
S = list(input())
D1 = defaultdict(int)
D2 = defaultdict(int)
var = - float("inf")
cnt = 0
for i in range(N):
if S[i] == "o":
if i - var >= C + 1:
cnt += 1
var = i
D1[i] += 1
if cnt >= K + 1:
return
#詰める
var = float("inf")
cnt = 0
for i in range(N):
if S[N - 1 - i] == "o":
if var - (N - 1 - i) >= C + 1:
cnt += 1
var = N - 1 - i
D2[N - 1 - i] += 1
# print(D1)
# print(D2)
ans = []
for i in D1:
if D2[i] == 1:
ans.append(i)
ans = sorted(ans)
for i in ans:
print(i + 1)
if __name__ == '__main__':
main() | 1 | 40,742,180,828,390 | null | 182 | 182 |
from math import gcd
from collections import defaultdict
n = int(input())
AB = [list(map(int, input().split())) for _ in range(n)]
MOD = 1000000007
box = defaultdict(int)
zeros = 0
for a, b in AB:
if a == b == 0:
zeros += 1
else:
if a != 0 and b == 0:
box[(-1, 1, 0)] += 1
elif a == 0 and b != 0:
box[(1, 0, 1)] += 1
else:
g = gcd(a, b)
ga = a // g
gb = b // g
if (a // b) < 0:
s = -1
else:
s = 1
box[(s, abs(ga), abs(gb))] += 1
nakawaru = dict()
others = 0
for (s, i, j), v in box.items():
if (-s, j, i) in box.keys():
if (s, i, j) not in nakawaru.keys() and (-s, j, i) not in nakawaru.keys():
nakawaru[(s, i, j)] = (box[(s, i, j)], box[(-s, j, i)])
else:
others += v
seed = 1
for i, j in nakawaru.values():
seed *= (pow(2, i, MOD) + pow(2, j, MOD) - 1)
seed %= MOD
ans = zeros + pow(2, others, MOD) * seed - 1
ans %= MOD
print(ans)
| N = int(input())
*A, = map(int, input().split())
ans = 0
for i, a in enumerate(A):
if (i + 1) & 1 and a & 1:
ans += 1
print(ans)
| 0 | null | 14,221,374,491,520 | 146 | 105 |
def resolve():
N, K = map(int, input().split())
candy_counter = [0] * N
for _ in range(K):
d = int(input())
A = list(map(int, input().split()))
for i in A:
candy_counter[i-1] += 1
ans = 0
for i in candy_counter:
if i == 0:
ans += 1
print(ans)
if __name__ == "__main__":
resolve() | import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
return int(input())
def inpl():
return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------
N, K = inpl()
dp = [False] * N
for i in range(K):
d = inp()
A = inpl()
for a in A:
dp[a-1] = True
cnt = 0
for bl in dp:
if not bl:
cnt += 1
print(cnt)
# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr) | 1 | 24,691,330,646,928 | null | 154 | 154 |
n,m=input().split()
print(m+n) | b,a = input().split()
print(a + b) | 1 | 102,704,784,090,532 | null | 248 | 248 |
while True:
H, W = map(int, input().split())
if (H, W) == (0, 0):
break
[print("#"*W+"\n") if i == H-1 else print("#"*W) for i in range(H)] | n = int(input())
S = input()
r = S.count('R')
w = 0
ans = r
for i in range(n):
if S[i] == "W":
w += 1
elif S[i] == "R":
r -= 1
ans = min(ans,max(r,w))
print(ans) | 0 | null | 3,527,923,059,760 | 49 | 98 |
target = input()
now_height = []
now_area = [0]
answer = []
continued = 0
depth = 0
depth_list = []
for t in target:
# print(now_height,depth_list,now_area,answer,continued)
if t == '\\':
now_height.append(continued)
depth_list.append(depth)
now_area.append(0)
depth -= 1
elif t == '_':
pass
elif t == '/' and len(now_height) > 0:
depth += 1
started = now_height.pop()
temp_area = continued - started
# print(depth_list[-1],depth)
now_area[-1] += temp_area
if depth > depth_list[-1]:
while depth > depth_list[-1]:
temp = now_area.pop()
now_area[-1] += temp
depth_list.pop()
continued += 1
now_area = list(filter(lambda x:x != 0,now_area))
answer.extend(now_area)
print(sum(answer))
print(len(answer),*answer) | def main():
N, K, C = map(int, input().split())
S = input()
# greedy
head, tail = [-C - 1] * (K + 1), [N + C + 1] * (K + 1)
idx = 0
for i in range(N):
if S[i] == 'o' and i - head[idx] > C:
idx += 1
head[idx] = i
if idx == K:
break
idx = K
for i in range(N - 1, -1, -1):
if S[i] == 'o' and tail[idx] - i > C:
idx -= 1
tail[idx] = i
if idx == 0:
break
# ans
for i in range(K):
if head[i + 1] == tail[i]:
print(tail[i] + 1)
if __name__ == '__main__':
main()
| 0 | null | 20,444,319,421,100 | 21 | 182 |
score = int(input())
levelList = [600,800,1000,1200,1400,1600,1800]
level = 8
for i in range(7):
if score < levelList[i]:
break
else :
level = level - 1
print(level) | from sys import stdin, stdout
s = input()
n = len(s)
P = 2019
# suffix_rems is a list of remainders obtained by dividing the suffix starting at i with P. suffix[i] = s[i:]%P.
suffix_rems = [-1]*n
suffix_rems[-1] = int(s[-1])%P
# Stores the frequency of remainders obtained. We just want number of (i, j) pairs.
rems_d = dict()
rems_d[0] = 1
rems_d[int(s[-1])] = 1
# Those remainders which occur more than once. To pick (i, j) pairs from N, we need N > 1.
special_keys = set()
for i in range(n-1)[::-1]:
rem = (pow(10, n-i-1, P) * int(s[i]) + suffix_rems[i + 1])%P
if rem in rems_d:
rems_d[rem] += 1
special_keys.add(rem)
else:
rems_d[rem] = 1
suffix_rems[i] = rem
ans = 0
for key in special_keys:
t = rems_d[key]
# pick any two of those same remainder indices.
ans += (t*(t-1))//2
print(ans) | 0 | null | 18,788,132,442,752 | 100 | 166 |
x = input()
x = int(x)
num = 1
while x:
print("Case {0}: {1}".format(num, x))
x = input()
x = int(x)
num += 1 | import sys
i=1
while True:
x=sys.stdin.readline().strip()
if x=="0":
break;
print("Case %d: %s"%(i,x))
i+=1 | 1 | 473,551,829,000 | null | 42 | 42 |
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
def main():
N, D, A = map(int, input().split())
XH = [None] * N
X = [None] * N
for i in range(N):
XH[i] = tuple(map(int, input().split()))
X[i] = XH[i][0]
XH.sort()
X.sort()
ans = 0
S = [0] * (N+1)# 与えたダメージ
for i in range(N):
if S[i] < XH[i][1]:
# あと何回攻撃する?
need = (XH[i][1]-S[i]+A-1)//A
# 爆弾が届く範囲
j = bisect_right(X,X[i]+2*D)
# imos法
S[i] += need*A
S[j] -= need*A
ans += need
S[i+1] += S[i]
print(ans)
if __name__ == "__main__":
main()
| from sys import stdin, setrecursionlimit
def main():
input = stdin.buffer.readline
a, b = map(int, input().split())
ans = a - 2 * b
if ans >= 0:
print(ans)
else:
print(0)
if __name__ == "__main__":
setrecursionlimit(10000)
main()
| 0 | null | 124,186,902,109,552 | 230 | 291 |
import math
import collections
def prime_diviation(n):
factors = []
i = 2
while i <= math.floor(math.sqrt(n)):
if n%i == 0:
factors.append(int(i))
n //= i
else:
i += 1
if n > 1:
factors.append(n)
return factors
N = int(input())
if N == 1:
print(0)
exit()
#pr:素因数分解 prs:集合にしたやつ prcnt:counter
pr = prime_diviation(N)
prs = set(pr)
prcnt = collections.Counter(pr)
#print(pr, prs, prcnt)
ans = 0
for a in prs:
i = 1
cnt = 2*prcnt[a]
#2*prcnt >= n(n+1)となる最大のnを探すのが楽そう
# print(cnt)
while cnt >= i*(i+1):
i += 1
ans += i - 1
print(ans) | m = 100000
for i in range(int(raw_input())):
m*=1.05
m=(int((m+999)/1000))*1000
print m | 0 | null | 8,390,773,736,850 | 136 | 6 |
# M-SOLUTIONS プロコンオープン 2020: B – Magic 2
A, B, C = [int(i) for i in input().split()]
K = int(input())
is_success = 'No'
for i in range(K + 1):
for j in range(K + 1):
for k in range(K + 1):
if i + j + k <= K and A * 2 ** i < B * 2 ** j < C * 2 ** k:
is_success = 'Yes'
print(is_success) | # -*- coding: utf-8 -*-
from sys import stdin
input = stdin.readline
MOD = 10**9+7
def main():
D, T, S = list(map(int,input().split()))
print('Yes' if D/S <= T else 'No')
if __name__ == "__main__":
main()
| 0 | null | 5,226,883,721,560 | 101 | 81 |
# -*- coding: utf-8 -*-
A, B=map(int,input().split())
if(A<=B):
print("unsafe")
else:
print("safe") | a, b = input().split()
a, b = int(a), int(b)
print('%d %d' % (a * b, 2 * (a + b)))
| 0 | null | 14,838,863,525,060 | 163 | 36 |
import math
N = int(input())
ans = [0] * N
n = int(math.sqrt(N))
for x in range(1, n+1):
for y in range(1, x+1):
for z in range(1, y+1):
i = x**2 + y**2 + z**2 + x*y + y*z + z*x
if i <= N:
if x == y == z:
ans[i-1] += 1
elif x == y or y == z:
ans[i-1] += 3
else:
ans[i-1] += 6
for j in range(N):
print(ans[j]) | N = int(input())
S = input()
if N % 2 == 1:
print("No")
else:
if S[:N // 2] == S[N // 2:]:
print("Yes")
else:
print("No")
| 0 | null | 77,373,940,546,490 | 106 | 279 |
def aizu006():
while True:
xs = map(int,raw_input().split())
if xs[0] == 0 and xs[1] == 0: break
else:
xs.sort()
for i in range(0,2):
print xs[i],
print
aizu006() | # coding: utf-8
import sys
i = sys.stdin
for line in i:
a,b = map(int,line.split())
if a == 0 and b == 0: break
if a < b:
print(a,b)
else:
print(b,a) | 1 | 523,534,105,226 | null | 43 | 43 |
n = int(input())
a = sorted([(i, int(ai)) for i, ai in zip(range(1, n + 1), input().split())], key=lambda x: x[1])
for i in range(n):
print(a[i][0], end=' ') | import sys
input = sys.stdin.readline
if __name__ == '__main__':
n=int(input())
D=[0]*n
A=[]
def h1(x):
return x%n
def h2(x):
return 1+x%(n-1)
def h(x,i):
return h1(x)+i*h2(x)
def insert(x):
i=0
k=0
while True:
k=h(x,i)%n
if D[k]==0:
D[k]=x
return k
elif D[k]==x:
return k
i+=1
def find(x):
i=0
k=0
while i<n:
k=h(x,i)%n
if D[k]==x:
return True
elif D[k]==0:
return False
i+=1
return False
def getKey(X):
res=''
for x in X:
if x=='A':
res+='1'
elif x=='C':
res+='2'
elif x=='G':
res+='3'
elif x=='T':
res+='4'
return int(res)
for _ in range(n):
c,x=input().strip("\n").split()
#x=x.replace('A','1').replace('C','2').replace('G','3').replace('T','4')
#x=int(x)
x=getKey(x)
if c=='insert':
insert(x)
else:
A.append(find(x))
for ans in A:
print('yes' if ans else 'no')
| 0 | null | 90,176,732,588,580 | 299 | 23 |
N=int(input())
S=input()
ans=0
for i in range(1000):
one=str(i//100)
two=str((i%100)//10)
three=str(i%10)
f1,f2,f3=False,False,False
ptr=0
for j in range(ptr,N-2):
if S[j]==one:
f1=True
ptr=j+1
break
if f1:
for j in range(ptr,N-1):
if S[j]==two:
f2=True
ptr=j+1
break
if f2:
for j in range(ptr,N):
if S[j]==three:
f3=True
ans+=1
break
print(ans) | a, b = (int(i) for i in input().split())
while a != 0 or b != 0:
count = 0
for i in range(1, a-1):
for j in range(i+1 , a):
for k in range(i+2, a+1):
if i + j + k == b and i < j < k:
count += 1
print("{0}".format(count))
a, b = (int(i) for i in input().split()) | 0 | null | 64,721,327,403,968 | 267 | 58 |
n, m = map(int, input().split())
print(int(n*m) if (n<=9 and m<=9) else -1) | a, b = map(int, input().split())
print((a <= 9 and b <= 9) and a * b or -1) | 1 | 158,255,281,926,660 | null | 286 | 286 |
A=int(input())
B=int(input())
if 1 not in [A,B]:
print(1)
if 2 not in [A,B]:
print(2)
if 3 not in [A,B]:
print(3) | A = int(input())
B = int(input())
if A == 1:
if B == 2:
print(3)
else:
print(2)
elif A == 2:
if B == 1:
print(3)
else:
print(1)
else:
if B == 1:
print(2)
else:
print(1)
| 1 | 110,835,183,804,618 | null | 254 | 254 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
def solve(S: str, T: str, A: int, B: int, U: str):
return f"{A-(S==U)} {B-(T==U)}"
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
T = next(tokens) # type: str
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
U = next(tokens) # type: str
print(f'{solve(S, T, A, B, U)}')
if __name__ == '__main__':
main()
| def m():
MOD = 998244353
N = int(input())
D = [0] + list(map(int, input().split()))
if D[1] != 0:
return 0
tree = {1:1}
for i in range(2, N + 1):
if D[i] == 0: return 0
tree[D[i] + 1] = tree[D[i] + 1] + 1 if tree.get(D[i] + 1, False) else 1
height = len(tree.keys())+1
cnt = 1
for i in range(2, height):
if not tree.get(i, 0):
return 0
cnt = cnt * pow(tree[i-1], tree[i]) % MOD
return cnt
print(m())
| 0 | null | 113,278,318,674,042 | 220 | 284 |
n = int(input())
plus_bracket = []
minus_bracket = []
for _ in range(n):
mini = 0
cur = 0
for bracket in input():
if bracket == '(':
cur += 1
else:
cur -= 1
if cur < mini:
mini = cur
if cur > 0:
plus_bracket.append([-mini, cur])
else:
minus_bracket.append([cur - mini, -cur])
success = True
cur = 0
plus_bracket.sort()
minus_bracket.sort()
for bracket in plus_bracket:
if cur < bracket[0]:
success = False
break
cur += bracket[1]
back_cur = 0
for bracket in minus_bracket:
if back_cur < bracket[0]:
success = False
break
back_cur += bracket[1]
if cur != back_cur:
success = False
if success:
print('Yes')
else:
print('No') | import sys
import itertools
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# n = map(int, readline().split())
n = int(readline())
ls = []
rs = []
total = 0
S = list(map(lambda x: x.strip().decode(), readlines()))
for i in range(n):
s = S[i]
b = 0
h = 0
for c in s:
if c == '(':
h += 1
else:
h -= 1
b = min(b, h)
if h >= 0:
ls.append((b, h))
else:
rs.append((b - h, -h))
total += h
if total != 0:
print("No")
exit()
ls = sorted(ls, reverse=True)
rs = sorted(rs, reverse=True)
h = 0
OK = True
for p in ls:
b = h + p[0]
h += p[1]
if b < 0:
OK = False
h = 0
for p in rs:
b = h + p[0]
h += p[1]
if b < 0 or h < 0:
OK = False
if not OK:
print("No")
else:
print("Yes")
| 1 | 23,536,861,315,008 | null | 152 | 152 |
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions import gcd
#input=sys.stdin.readline
import bisect
s=input()
t=input()
n=len(s)
ans=0
for i in range(n):
if s[i]!=t[i]:
ans+=1
print(ans) | import math
H, W = map(int, raw_input().split())
while H > 0 or W > 0 :
print "#" * W
for i in xrange(H-2) :
print "#" + "." * (W-2) + "#"
print "#" * W
print
H, W = map(int, raw_input().split()) | 0 | null | 5,598,584,481,260 | 116 | 50 |
import math
def main():
n=int(input())
print(math.ceil(n/2)/n)
if __name__ == '__main__':
main() | n = int(input())
cnt = 0
for i in range(n):
if (i + 1) % 2 == 1:
cnt += 1
print(cnt/n)
| 1 | 177,159,910,182,138 | null | 297 | 297 |
s=set(input())
if len(s)==2:print('Yes')
else:print('No') | S = len(set(input()))
if S == 2:
print('Yes')
else:
print('No') | 1 | 55,076,360,000,172 | null | 201 | 201 |
A = []
b = []
row = 0
col = 0
row, col = map(int, raw_input().split())
A = [[0 for i in range(col)] for j in range(row)]
for i in range(row):
r = map(int, raw_input().split())
for index, j in enumerate(r):
A[i][index] = j
for i in range(col):
b.append(int(raw_input()))
for i in A:
ret = 0
for j,k in zip(i,b):
ret += j*k
print ret | import sys
#fin = open("test.txt", "r")
fin = sys.stdin
n, m = map(int, fin.readline().split())
A = [[] for i in range(n)]
for i in range(n):
A[i] = list(map(int, fin.readline().split()))
b = [0 for i in range(m)]
for i in range(m):
b[i] = int(fin.readline())
c = [0 for i in range(n)]
for i in range(n):
for j in range(m):
c[i] += A[i][j] * b[j]
for i in range(n):
print(c[i]) | 1 | 1,169,186,872,700 | null | 56 | 56 |
import sys
from io import StringIO
import unittest
import os
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
# DPの対象配列の先頭に0を追加(先頭を0桁目、でなく1桁目、として可読性を上げる)
# さらに、入力を1文字ずつ分けて、数値型でリストに格納する。
def get_dp_target(string: str) -> []:
return [0] + list(map(int, list(string)))
# 実装を行う関数
def resolve(test_def_name=""):
try:
# ※DP対象は以下の関数で取得※
n = get_dp_target(input())
target = int(input())
# ---------------------------------
# DP準備
# ---------------------------------
# DP配列作成※問題ごとに変える※
dp = [[[0 for _ in range(101)] for _ in range(2)] for _ in range(len(n) + 1)]
# DP準備(1桁目の設定)※0も処理するので1桁目の値+1回ループ
for i in range(n[1] + 1):
# 未満フラグ設定
is_smaller = True if i < n[1] else False
# ※問題ごとに変える※
# dp[1][is_smaller][?] = ? というイメージは同じ。
not_zero_count = 0 if i == 0 else 1
dp[1][is_smaller][not_zero_count] += 1
# ---------------------------------
# DP(2桁目以降を処理する) ※ポイント:各ループの回数はDP配列の要素数と同じ。
for place in range(2, len(n)):
# 未満フラグの全パターンループ(2種類しかないが・・)
for is_smaller in range(2):
# 0以外の出現回数ループ(DPの兼ね合い上、範囲は0~100でOK)
for not_zero_count in range(100):
# 値ループ
val_range = 10 if is_smaller else n[place] + 1
for val in range(val_range):
# 値によるフラグ変動
work_is_smaller = is_smaller or val < n[place]
work_not_zero_count = not_zero_count if val == 0 else not_zero_count + 1
dp[place][work_is_smaller][work_not_zero_count] += dp[place - 1][is_smaller][not_zero_count]
print(dp[len(n) - 1][0][target] + dp[len(n) - 1][1][target])
except IndexError as err:
print("インデックスエラー:", err.args[0])
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve(sys._getframe().f_back.f_code.co_name)
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """100
1"""
output = """19"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """25
2"""
output = """14"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """314159
2"""
output = """937"""
self.assertIO(test_input, output)
def test_input_4(self):
test_input = """9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3"""
output = """117879300"""
self.assertIO(test_input, output)
# 自作テストパターン
def test_original(self):
pass
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| import math
import itertools
n=int(input())
k=int(input())
def comb(n,k):
return len(list(itertools.combinations(range(n), k)))
x=str(n)
m=len(x)
ans=0
for i in range(1,m):
ans+=(comb(i-1,k-1)*(9**k))
if k==1:
for i in range(1,10):
if i*(10**(m-1))<=n:
ans+=1
elif k==2:
for i in range(1,10):
if i*(10**(m-1))<=n:
for j in range(m-1):
for a in range(1,10):
if i*(10**(m-1))+a*(10**(j))<=n:
ans+=1
else:
break
else:
break
else:
po=[10**i for i in range(m)]
for i in range(1,10):
if i*po[m-1]<=n:
for j in range(m-1):
for a in range(1,10):
if i*po[m-1]+a*po[j]<=n:
for b in range(j):
for c in range(1,10):
ans+=(i*po[m-1]+a*po[j]+c*po[b]<=n)
else:
break
else:
break
print(ans)
| 1 | 75,812,060,858,560 | null | 224 | 224 |
time = int(input())
s = time % 60
h = time // 3600
m = (time - h * 3600) // 60
print(str(h) + ":" + str(m) + ":" + str(s))
| n=int(input())
A=tuple(map(int, input().split()))
cnt=0
def merge_sort(A,cnt):
m=len(A)
if m == 1:
return A,cnt
else:
mid=(m+1)//2
A1=tuple(A[:mid])
A2=tuple(A[mid:])
A1,cnt=merge_sort(A1,cnt)
A2,cnt=merge_sort(A2,cnt)
n1=len(A1)
n2=len(A2)
i1=0
i2=0
ans=[0]*(n1+n2)
j=0
while j < n1+n2:
if i1 == n1:
ans[j]=A2[i2]
i2+=1
cnt+=1
elif i2 == n2:
ans[j]=A1[i1]
i1+=1
cnt+=1
elif A1[i1] < A2[i2]:
ans[j]=A1[i1]
i1+=1
cnt+=1
else:
ans[j]=A2[i2]
i2+=1
cnt+=1
j += 1
return ans,cnt
sorted_A,cnt=merge_sort(A,0)
print(*sorted_A)
print(cnt)
| 0 | null | 219,037,608,230 | 37 | 26 |
from collections import defaultdict
from itertools import groupby, accumulate, product, permutations, combinations
from math import gcd
def reduction(x,y):
g = gcd(x,y)
return abs(x)//g,abs(y)//g
def solve():
mod = 10**9+7
dplus = defaultdict(lambda: 0)
dminus = defaultdict(lambda: 0)
N = int(input())
x0,y0,xy0 = 0,0,0
for i in range(N):
x,y = map(int, input().split())
if x==0 and y==0:
xy0 += 1
elif x==0 and y!=0:
x0 += 1
elif y==0:
y0 += 1
elif x*y>0:
dplus[reduction(x,y)] += 1
else:
dminus[reduction(-y,x)] += 1
ans = pow(2,x0,mod)+pow(2,y0,mod)-1
other = N-x0-y0-xy0
for k,v in dplus.items():
ans *= pow(2,dminus[k],mod)+pow(2,v,mod)-1
other -= dminus[k]+v
ans *= pow(2,other,mod)
ans += xy0-1
ans %= mod
return ans
print(solve())
| n,k=list(map(int,input().split()))
alst=list(map(int,input().split()))
ok=max(alst)
ng=0
while abs(ok-ng)>1:
cen=(ok+ng)//2
cnt=0
for a in alst:
cnt+=(a+cen-1)//cen-1
if cnt<=k:
ok=cen
else:
ng=cen
print(ok) | 0 | null | 13,806,089,796,688 | 146 | 99 |
for i in range(1, 10):
for j in range(1, 10):
print '%sx%s=%s' % (i, j, i * j) | a,b,c,d=map(int,input().split())
def ret(a,b,c,d):
return max(b*d,a*c,0 if (a*b<=0 or c*d<=0) else -1e64,a*d,b*c)
print(ret(a,b,c,d)) | 0 | null | 1,545,205,373,712 | 1 | 77 |
import random
S = input()
rand = random.randrange(0, len(S) - 2)
print(S[rand] + S[rand + 1] + S[rand + 2])
| S = str(input())
print(S[0:3]) | 1 | 14,811,834,044,128 | null | 130 | 130 |
N = input()
if len(N) == 1:
if N == '3':
print('bon')
elif N == '0' or N == '1' or N == '6' or N == '8':
print('pon')
else:
print('hon')
elif len(N) == 2:
if N[1] == '3':
print('bon')
elif N[1] == '0' or N[1] == '1' or N[1] == '6' or N[1] == '8':
print('pon')
else:
print('hon')
elif len(N) == 3:
if N[2] == '3':
print('bon')
elif N[2] == '0' or N[2] == '1' or N[2] == '6' or N[2] == '8':
print('pon')
else:
print('hon') | # Reference: https://qiita.com/dn6049949/items/afa12d5d079f518de368
# self.data: 1-indexed
# __1__
# _2_ _3_
# 4 5 6 7
# f(f(a, b), c) == f(a, f(b, c))
class SegmentTree:
# a = [default] * n
# O(n)
def __init__(self, n, f=max, default=-2**30):
self.num_leaf = 2 ** (n-1).bit_length()
self.data = [default] * (2*self.num_leaf)
self.f = f
# a[i] = x
# O(log(n))
def update(self, i, x):
i += self.num_leaf
self.data[i] = x
i >>= 1
while i > 0:
self.data[i] = self.f(self.data[2*i], self.data[2*i+1])
i >>= 1
# return f(a[l:r])
# O(log(n))
def query(self, l, r):
l += self.num_leaf
r += self.num_leaf - 1
lres, rres = self.data[0], self.data[0] # self.data[0] == default
while l < r:
if l & 1:
lres = self.f(lres, self.data[l])
l += 1
if not r & 1:
rres = self.f(self.data[r], rres)
r -= 1
l >>= 1
r >>= 1
if l == r:
res = self.f(self.f(lres, self.data[l]), rres)
else:
res = self.f(lres, rres)
return res
# You can use min_index only if f == max.
# return min({i | x <= i and v <= a[i]}, self.num_leaf)
# O(log(n))
def min_index(self, x, v):
x += self.num_leaf
while self.data[x] < v:
if x & 1:
if x.bit_length() == (x+1).bit_length():
x += 1
else:
return self.num_leaf
else:
x >>= 1
while x < self.num_leaf:
if self.data[2*x] >= v:
x = 2*x
else:
x = 2*x + 1
return x - self.num_leaf
from sys import stdin
def input():
return stdin.readline().strip()
def main():
n = int(input())
s = list(input())
forest = [SegmentTree(n, f=max, default=0) for _ in range(26)]
for ind, si in enumerate(s):
forest[ord(si) - 97].update(ind, 1)
q = int(input())
ans = []
for _ in range(q):
typ, l, r = input().split()
l = int(l) - 1
if typ == '1':
forest[ord(s[l]) - 97].update(l, 0)
s[l] = r
forest[ord(r) - 97].update(l, 1)
else:
cnt = 0
for tree in forest:
if tree.min_index(l, 1) < int(r):
cnt += 1
ans.append(cnt)
for i in ans:
print(i)
main() | 0 | null | 40,958,339,611,200 | 142 | 210 |
n,k,c=map(int,input().split())
s=input()
def greedy_work(days,rest,plan):
day_count=0
go=[0]*n
while day_count < days:
if plan[day_count]=='o':
go[day_count]=1
day_count += rest+1
else:
day_count += 1
return(go)
front = greedy_work(n,c,s)
back = greedy_work(n,c,s[::-1])
back = back[::-1]
if front.count(1)==k:
for i in range(n):
if front[i]==1 and back[i]==1:
print(i+1) | #ABC157E
n = int(input())
s = list(input())
q = int(input())
bits = [[0 for _ in range(n+1)] for _ in range(26)]
sl = []
for alp in s:
alpord = ord(alp) - 97
sl.append(alpord)
#print(bits) #test
#print(sl) #test
#print('クエリ開始') #test
def query(pos):
ret = [0] * 26
p = pos
while p > 0:
for i in range(26):
ret[i] += bits[i][p]
p -= p&(-p)
return ret
def update(pos, a, x):
r = pos
while r <= n:
bits[a][r] += x
r += r&(-r)
for i in range(n):
update(i+1, sl[i], 1)
#print(bits) #test
for _ in range(q):
quer, xx, yy = map(str, input().split())
if quer == '1':
x = int(xx)
y = ord(yy) - 97
if sl[x-1] == y:
continue
else:
update(x, sl[x-1], -1)
update(x, y, 1)
sl[x-1] = y
#print('クエリ1でした') #test
#print(bits) #test
#print(sl) #test
else:
x = int(xx)
y = int(yy)
cnt1 = query(y)
cnt2 = query(x-1)
#print('クエリ2です') #test
#print(cnt1) #test
#print(cnt2) #test
ans = 0
for i in range(26):
if cnt1[i] - cnt2[i] > 0:
ans += 1
print(ans) | 0 | null | 51,634,656,875,780 | 182 | 210 |
import math
r = input()
print "%0.6f %0.6f"%(r*r*math.pi,r*2*math.pi) | num = list(map(int,input().split()))
max_num = 0
max_num = num[0] * num[2]
max_num = max(max_num, num[0] * num[3])
max_num = max(max_num, num[1] * num[2])
max_num = max(max_num, num[1] * num[3])
print(max_num) | 0 | null | 1,855,385,926,966 | 46 | 77 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys
INF = float('inf')
def solve(A: int, B: int):
return max(A-2*B, 0)
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
print(f'{solve(A, B)}')
if __name__ == '__main__':
main()
| import sys
from math import gcd
from collections import Counter
MOD = 10**9 + 7
def main():
input = sys.stdin.readline
N = int(input())
V = []
z = 0
for _ in range(N):
A, B = map(int, input().split())
g = gcd(A, B)
if g == 0:
z += 1
continue
A, B = A // g, B // g
if A == 0: V.append((0, 1))
elif A < 0: V.append((-A, -B))
else: V.append((A, B))
C = Counter(V)
ans = Mint(1)
used = set()
for k, V in C.items():
if k in used: continue
a, b = k
v = (0, 1) if b == 0 else (b, -a) if b > 0 else (-b, a)
t = Mint(1)
t += pow(2, V, MOD) - 1
t += pow(2, C[v], MOD) - 1
ans *= t
used.add(v)
print(ans - 1 + z)
class Mint:
def __init__(self, value=0):
self.value = value % MOD
if self.value < 0: self.value += MOD
@staticmethod
def get_value(x): return x.value if isinstance(x, Mint) else x
def inverse(self):
a, b = self.value, MOD
u, v = 1, 0
while b:
t = a // b
b, a = a - t * b, b
v, u = u - t * v, v
if u < 0: u += MOD
return u
def __repr__(self): return str(self.value)
def __eq__(self, other): return self.value == other.value
def __neg__(self): return Mint(-self.value)
def __hash__(self): return hash(self.value)
def __bool__(self): return self.value != 0
def __iadd__(self, other):
self.value = (self.value + Mint.get_value(other)) % MOD
return self
def __add__(self, other):
new_obj = Mint(self.value)
new_obj += other
return new_obj
__radd__ = __add__
def __isub__(self, other):
self.value = (self.value - Mint.get_value(other)) % MOD
if self.value < 0: self.value += MOD
return self
def __sub__(self, other):
new_obj = Mint(self.value)
new_obj -= other
return new_obj
def __rsub__(self, other):
new_obj = Mint(Mint.get_value(other))
new_obj -= self
return new_obj
def __imul__(self, other):
self.value = self.value * Mint.get_value(other) % MOD
return self
def __mul__(self, other):
new_obj = Mint(self.value)
new_obj *= other
return new_obj
__rmul__ = __mul__
def __ifloordiv__(self, other):
other = other if isinstance(other, Mint) else Mint(other)
self *= other.inverse()
return self
def __floordiv__(self, other):
new_obj = Mint(self.value)
new_obj //= other
return new_obj
def __rfloordiv__(self, other):
new_obj = Mint(Mint.get_value(other))
new_obj //= self
return new_obj
if __name__ == '__main__':
main()
| 0 | null | 93,743,487,087,852 | 291 | 146 |
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np # cumsum
# from bisect import bisect_left, bisect_right
def solve():
K = II()
A, B = MI()
for i in range(A, B+1):
if i % K == 0:
print('OK')
return
print('NG')
if __name__ == '__main__':
solve()
| K = int(input())
A,B = map(int,input().split())
li = []
for i in range(A,B+1):
li.append(i)
ans = False
for j in li:
if j%K == 0:
ans = True
break
else:
ans = False
if ans == True:print("OK")
else:print("NG") | 1 | 26,539,973,352,350 | null | 158 | 158 |
a, b, m = list(map(int, input().split()))
refrigerator_list = list(map(int, input().split()))
microwave_list = list(map(int, input().split()))
coupon_list = list()
for _ in range(m):
coupon_list.append(list(map(int, input().split())))
ans = min(refrigerator_list) + min(microwave_list)
for coupon in coupon_list:
ans = min(refrigerator_list[coupon[0] - 1] + microwave_list[coupon[1] - 1] - coupon[2], ans)
print(ans)
| N=int(input())
if(N%1000==0):
print(0)
else:
print(-(-N//1000)*1000-N) | 0 | null | 31,152,081,481,472 | 200 | 108 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.