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
|
---|---|---|---|---|---|---|
from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
def f(x):
cnt = 0
for a in A:
cnt += ceil(a / x) - 1
return True if cnt <= K else False
OK, NG = 10**9, 0
while OK - NG > 1:
mid = (OK + NG) // 2
if f(mid):
OK = mid
else:
NG = mid
print(OK)
| from collections import deque
n,m = map(int, input().split())
ikisaki=[[] for _ in range(n+1)]
for _ in range(m):
a,b = map(int, input().split())
ikisaki[a].append(b)
ikisaki[b].append(a)
ans=[0]+[1]+[0]*(n-1)
tansakuheya=deque([1])
tmp=deque()
for _ in range(1000009):
for bangou in tansakuheya:
for heya in ikisaki[bangou]:
if ans[heya]==0:
ans[heya]=bangou
tmp.append(heya)
tansakuheya=tmp.copy()
tmp=deque()
if not tansakuheya:
break
print("Yes")
for i in range(2,n+1):
print(ans[i]) | 0 | null | 13,618,506,799,288 | 99 | 145 |
def selection_sort(numbers, n):
"""selection sort method
Args:
numbers: a list of numbers to be sorted
n: len(numbers)
Returns:
sorted numberd, number of swapped times
"""
counter = 0
for i in range(0, n - 1):
min_j = i
for j in range(i + 1, n):
if numbers[j] < numbers[min_j]:
min_j = j
if min_j != i:
numbers[min_j], numbers[i] = numbers[i], numbers[min_j]
counter += 1
return numbers, counter
length = int(raw_input())
numbers = [int(x) for x in raw_input().split()]
numbers, number_of_swapped_times = selection_sort(numbers, length)
print(" ".join([str(x) for x in numbers]))
print(number_of_swapped_times) | # inputList = list(map(int, '''6
# 5 6 4 2 1 3'''.split()))
# N = inputList.pop(0)
def formatting(nums):
for i in range(len(nums)):
if i != len(nums) - 1:
print(nums[i], end=' ')
else:
print(nums[i])
def selectionSort(A, N):
count = 0
for i in range(N - 1):
minJ = i
for j in range(i, N):
if A[j] < A[minJ]:
minJ = j
if i != minJ:
A[i], A[minJ] = A[minJ], A[i]
count += 1
formatting(A)
print(count)
N = int(input())
inputList = list(map(int, input().split()))
selectionSort(inputList, N)
| 1 | 19,655,904,492 | null | 15 | 15 |
n=int(input())
P=[int(x) for x in input().split()]
Q=[int(x) for x in input().split()]
p=tuple(P)
q=tuple(Q)
l=list(range(1,n+1))
L=[]
import itertools
for v in itertools.permutations(l):
L.append(v)
a=L.index(p)
b=L.index(q)
print(abs(a-b)) | import itertools
n = int(input())
p_list = list(map(int, input().split()))
q_list = list(map(int, input().split()))
cnt = 0
p_cnt = 0
q_cnt = 0
for a in itertools.permutations(range(n)): #順列を生成して、それらに対して処理
cnt += 1
for i in range(len(a)):
if a[i]+1 != p_list[i]:
break
if i == len(a)-1:
p_cnt = cnt
for j in range(len(a)):
if a[j]+1 != q_list[j]:
break
if j == len(a)-1:
q_cnt = cnt
print(abs(p_cnt - q_cnt))
| 1 | 101,088,494,309,010 | null | 246 | 246 |
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def Main():
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = I()
print(a[k-1])
return
if __name__=='__main__':
Main() | # -*- coding: utf-8 -*-
import sys
index = int(input())
array = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(int(array[index-1]))
| 1 | 50,153,411,142,560 | null | 195 | 195 |
#! /usr/bin/env python
# -*- coding : utf-8 -*-
input()
seq = [int(x) for x in input().split()]
for i in range(0, len(seq)):
key = seq[i]
j = i - 1
assert isinstance(i, int)
while j >= 0 and seq[j] > key:
seq[j + 1] = seq[j]
j -= 1
seq[j + 1] = key
print(' '.join(map(str,seq))) | import sys
import fractions
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
H, W = lr()
dp = [[0 for _ in range(W)] for _ in range(H)]
masu = [sr() for _ in range(H)]
dp[0][0] = 1 if masu[0][0] == "#" else 0
for h, m in enumerate(masu):
for w, s in enumerate(m):
if w == 0 and h == 0:
continue
if w == 0:
if masu[h-1][w] != s and s == "#":
dp[h][w] += dp[h-1][w] + 1
else:
dp[h][w] += dp[h-1][w]
continue
if h == 0:
if masu[h][w-1] != s and s == "#":
dp[h][w] += dp[h][w-1] + 1
else:
dp[h][w] += dp[h][w-1]
continue
if masu[h-1][w] != s and s == "#":
cand1 = dp[h][w] + dp[h-1][w] + 1
else:
cand1 = dp[h][w] + dp[h-1][w]
if masu[h][w-1] != s and s == "#":
cand2 = dp[h][w] + dp[h][w-1] + 1
else:
cand2 = dp[h][w] + dp[h][w-1]
dp[h][w] = min(cand1, cand2)
print(dp[H-1][W-1])
| 0 | null | 24,513,089,955,190 | 10 | 194 |
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
As = [0] * (n + 1)
Bs = [0] * (m + 1)
for i in range(n):
As[i + 1] = A[i] + As[i]
for i in range(m):
Bs[i + 1] = B[i] + Bs[i]
l = 0
r = n + m + 1
while r - l > 1:
p = (l + r) // 2
best = min(
As[i] + Bs[p - i] for i in range(p + 1)
if min(i, n) + min(p - i, m) == p
)
if best <= k:
l = p
else:
r = p
print(l) | # -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
def solve():
X = Scanner.int()
X -= 400
print(8 - X // 200)
def main():
# sys.setrecursionlimit(1000000)
# sys.stdin = open("sample.txt")
solve()
if __name__ == "__main__":
main()
| 0 | null | 8,738,093,195,400 | 117 | 100 |
n,a,b = map(int,input().split())
modnum = 10**9+7
ans = pow(2,n,modnum)-1
def modinv(a, mod=10**9+7):
return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
r = min(r, n-r)
res = 1
for i in range(r):
res = res * (n - i) * modinv(i+1, mod) % mod
return res
ans -= combination(n, a, modnum)
ans -= combination(n, b, modnum)
ans %= modnum
print(ans) | def solve():
N = int(input())
A = list(map(int, input().split()))
ans = 0
p = 1
for a in A:
if a==p:
p += 1
else:
ans += 1
if p==1:
ans = -1
return ans
print(solve()) | 0 | null | 90,651,464,943,898 | 214 | 257 |
k = int(input())
a,b = map(int, input().split())
def judge(a,b):
for i in range(a,b+1):
if i%k == 0: return 'OK'
return 'NG'
print(judge(a,b)) | x,y=list(map(int, input().split()))
x,y=list(map(int, input().split()))
if y==1:
print(1)
else:
print(0) | 0 | null | 75,662,981,939,830 | 158 | 264 |
s = input()
if s[-1] == 's':
s += 'es'
else:
s += 's'
print(s)
| def main():
n = int(input())
a = list(map(int,input().split()))
b = [(0,0) for i in range(n)]
for i in range(n):
b[i] = (a[i],i + 1)
b.sort()
for i in range(n):
if i != n - 1:
print(b[i][1],end = " ")
else:
print(b[i][1])
main() | 0 | null | 91,179,020,602,040 | 71 | 299 |
def find_divisor(x):
Divisors = []
for i in range(1, int(x**0.5) + 1):
if x % i == 0:
Divisors.append(i)
if i != x // i:
Divisors.append(x // i)
return Divisors
n = int(input())
ways = len(find_divisor(n-1)) - 1
Div = find_divisor(n)
for i in range(1, len(Div)):
quo = n
while quo % Div[i] == 0:
quo = quo // Div[i]
if quo % Div[i] == 1:
ways += 1
print(ways) | def main(S, T):
if len(S)+1 == len(T) and S == T[:-1]:
return 'Yes'
else:
return 'No'
if __name__ == '__main__':
S = input()
T = input()
ans = main(S, T)
print(ans)
| 0 | null | 31,301,433,111,940 | 183 | 147 |
a = int(input())
print(a**3)
| n = input()
print(n ** 3) | 1 | 276,929,747,332 | null | 35 | 35 |
K = int(input())
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(K):
t = l[i] % 10
if t == 0:
l.append(l[i] * 10 + 0)
l.append(l[i] * 10 + 1)
elif t == 9:
l.append(l[i] * 10 + 8)
l.append(l[i] * 10 + 9)
else:
l.append(l[i] * 10 + t - 1)
l.append(l[i] * 10 + t)
l.append(l[i] * 10 + t + 1)
print(l[K-1]) | k = int(input())
cur = [[1]*10 for i in range(11)]
if k <= 9:
print(k)
exit()
c = 9
i = 0
while c < k:
i += 1
for j in range(10):
cur[i][j] = cur[i-1][j]
if j != 0:
cur[i][j] += cur[i-1][j-1]
if j != 9:
cur[i][j] += cur[i-1][j+1]
if c+sum(cur[i][1:]) >= k:
break
else:
c += sum(cur[i][1:])
ans = ''
for j in range(i,-1,-1):
for l in range(10):
if j == i and l == 0:
continue
if j != i and abs(l-int(ans[-1])) > 1:
continue
if c + cur[j][l] >= k:
ans += str(l)
break
else:
c += cur[j][l]
print(ans) | 1 | 39,743,386,880,588 | null | 181 | 181 |
X,Y = map(int,input().split())
money = [300000,200000,100000]
ans = 0
if X - 1 < 3:
ans += money[X - 1]
if Y - 1 < 3:
ans += money[Y - 1]
if X == 1 and Y == 1:
ans += 400000
print(ans) | import collections
import sys
sys.setrecursionlimit(10 ** 8)
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]
class edge:
def __init__(self, to, id): self.to, self.id = to, id
def main():
N = Z()
col = [0] * (N-1)
G = collections.defaultdict(list)
for i in range(N-1):
a, b = ZZ()
G[a].append(edge(b, i))
G[b].append(edge(a, i))
numCol = 0
for i in range(1, N+1): numCol = max(numCol, len(G[i]))
def dfs(v):
colSet = set()
for ed in G[v]:
if col[ed.id] != 0: colSet.add(col[ed.id])
c = 1
for ed in G[v]:
if col[ed.id] != 0: continue
while c in colSet: c += 1
col[ed.id] = c
c += 1
dfs(ed.to)
dfs(1)
print(numCol)
for i in range(N-1): print(col[i])
return
if __name__ == '__main__':
main()
| 0 | null | 138,252,373,785,116 | 275 | 272 |
n = input()
sum = 0
for i in range(len(n)):
sum += int(n[i])
if sum % 9 == 0:
print("Yes")
else:
print("No")
| N = int(input())
digits = list(map(int,str(N)))
if sum(digits) % 9 == 0:
print('Yes')
else:
print('No') | 1 | 4,357,638,168,352 | null | 87 | 87 |
import math
A, B, H, M = map(int, input().split())
h_rad = (H / 12 + M / 12 / 60)* 2 * math.pi
m_rad = M / 60 * 2 * math.pi
dif_rad = abs(h_rad - m_rad)
ans = math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(dif_rad))
print(ans) | import math
A,B,H,M = map(int,input().split())
t1 = (30*H+M/2)*math.pi/180
x1 = A*math.cos(t1)
y1 = A*math.sin(t1)
t2 = M*math.pi/30
x2 = B*math.cos(t2)
y2 = B*math.sin(t2)
d = ((x1-x2)**2+(y1-y2)**2)**0.5
print(d) | 1 | 19,983,721,408,230 | null | 144 | 144 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
def main():
n, k = map(int, input().split())
a = tuple(map(int, input().split()))
def kaisu(long):
return(sum([ceil(ae/long) - 1 for ae in a]))
def bs_meguru(key):
def isOK(index, key):
if kaisu(index) <= key:
return True
else:
return False
ng = 0
ok = max(a)
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if isOK(mid, key):
ok = mid
else:
ng = mid
return ok
print(bs_meguru(k))
if __name__ == '__main__':
main()
| import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
As = list(mapint())
ALL = 0
for a in As:
ALL ^= a
ans = [ALL^a for a in As]
print(*ans) | 0 | null | 9,559,501,727,790 | 99 | 123 |
a, b = map(int, input().split())
print("%d %d" % (int(a * b), int(a + a + b + b))) | a, b = map(int, input().split())
print(a*b,2*(a+b))
| 1 | 298,789,604,288 | null | 36 | 36 |
N = int(input())
S = [input() for i in range(N)]
S = set(S)
S = list(S)
print(len(S)) | N = int(input())
S = set([])
for i in range(N):
temp = str(input())
S.add(temp)
ans = len(S)
print(ans) | 1 | 30,149,482,509,958 | null | 165 | 165 |
n=int(input())
a=list(map(int,input().split()))
MOD= 10**9 + 7
toki = [0]*(n+1)
shigi=0
toki[0] = sum(a)-a[0]
for i in range(1, n-1):
toki[i] = toki[i-1]-a[i]
for i in range(n-1):
shigi += (a[i] * toki[i])
print(shigi%MOD) | n = int(input())
a = list(map(int, input().split()))
counter = 0
for i in range((len(a)+1)//2):
if a[i*2]%2 == 1:
counter += 1
print(counter) | 0 | null | 5,733,218,254,580 | 83 | 105 |
s=input()
rs=s[::-1]
ans=0
for i in range (len(s)):
if s[i] != rs[i]:
ans+=1
print(ans//2)
| if __name__ == '__main__':
def linearSearch(t):
S.append(t)
#print(S)
i=0
while S[i]!=t:
i+=1
del S[n]
return 1 if i!=n else 0
n=int(input())
S=list(map(int,input().split()))
q=int(input())
T=set(map(int,input().split()))
ans=0
for t in T:
ans+=linearSearch(t)
#print(t,ans)
print(ans)
| 0 | null | 60,389,798,704,804 | 261 | 22 |
s = input()
t = input()
count = 0
for i in range(len(s)):
if s[i] != t[i]:
count = count + 1
print(count) | #!/usr/bin/env python3
S = input()
T = input()
count = 0
for s, t in zip(S, T):
if s != t:
count += 1
ans = count
print(ans)
| 1 | 10,499,942,528,680 | null | 116 | 116 |
import heapq
X,Y,A,B,C = map(int,input().split())
qa = list(map(int,input().split()))
qb = list(map(int,input().split()))
r = list(map(int,input().split()))
qa.sort(reverse=True)
qb.sort(reverse=True)
r.sort(reverse=True)
qa_ans = qa[:X]
qb_ans = qb[:Y]
heapq.heapify(qa_ans)
heapq.heapify(qb_ans)
for i in range(C):
r_max = r[i]
qa_min = heapq.heappop(qa_ans)
qb_min = heapq.heappop(qb_ans)
if (r_max>qa_min) or (r_max>qb_min):
if qa_min >qb_min:
heapq.heappush(qa_ans,qa_min)
heapq.heappush(qb_ans,r_max)
else:
heapq.heappush(qa_ans,r_max)
heapq.heappush(qb_ans,qb_min)
else:
heapq.heappush(qa_ans, qa_min)
heapq.heappush(qb_ans, qb_min)
break
print(sum(qa_ans)+sum(qb_ans)) | import numpy as np
inp = input
#fin = open("case_21.txt")
#inp = fin.readline
X, Y, A, B, C = map(int, inp().split())
#red = np.array(list(map(int, inp().split())), np.int32)
#green = np.array(list(map(int, inp().split())), np.int32)
#white = np.array(list(map(int, inp().split())), np.int32)
red = list(map(int, inp().split()))
green = list(map(int, inp().split()))
white = list(map(int, inp().split()))
red.sort(reverse=True)
green.sort(reverse=True)
white.sort(reverse=True)
#fin.close()
#red[::-1].sort()
#green[::-1].sort()
#white[::-1].sort()
idr = 0
idg = 0
idw = 0
total = 0.0
countr = 0
countg = 0
countw = 0
while X > countr and Y > countg and (X+Y > countr+countg+countw):
if red[idr] >= green[idg]:
if idw >= C or red[idr] >= white[idw]:
#eat red
total += red[idr]
idr += 1
countr += 1
elif idw < C:
#eat white
total += white[idw]
idw += 1
countw += 1
else:
if idw >= C or green[idg] >= white[idw]:
# eat green
total += green[idg]
idg += 1
countg += 1
else:
#eat white
total += white[idw]
idw += 1
countw += 1
#eat remain
if Y <= countg:
while X > countr+countw:
# compare red 1st
if idw < C and red[idr] < white[idw]:
# eat white
total += white[idw]
idw += 1
else:
# eat red
total += red[idr]
idr += 1
countr += 1
if X <= countr:
while Y > countg+countw:
# compare green 1st
if idw < C and green[idg] < white[idw]:
# eat white
total += white[idw]
idw += 1
else:
# eat green
total += green[idg]
idg += 1
countg += 1
print(int(total))
| 1 | 44,646,828,875,900 | null | 188 | 188 |
import sys
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
N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
a, b = map(lambda x: int(x) - 1, sys.stdin.readline().split())
uf.union(a, b)
print(sum(p < 0 for p in uf.parents) - 1)
| N,X,M=map(int,input().split())
modlist=[0]*M
modset=set()
ans=0
for i in range(M):
if X in modset:
startloop=modlist.index(X)
sum_outofloop=sum(modlist[:startloop])
inloop=ans-sum_outofloop
numofloop=(N-startloop)//(i-startloop)
ans=sum_outofloop+numofloop*inloop+sum(modlist[startloop:startloop+((N-startloop)%(i-startloop))])
#print(inloop,i,startloop,sum_outofloop,numofloop,sum(modlist[startloop:startloop+((N-startloop)%(i-startloop))]))
break
else:
modset.add(X)
ans+=X
modlist[i]=X
X**=2
X%=M
if i==N-1:
break
print(ans)
#print(modlist) | 0 | null | 2,555,758,481,602 | 70 | 75 |
class UnionFind:
def __init__(self, n=0):
self.d = [-1]*n
def find(self, x):
if self.d[x] < 0:
return x
else:
self.d[x] = self.find(self.d[x])
return self.d[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.d[x] > self.d[y]:
x, y = y, x
self.d[x] += self.d[y]
self.d[y] = x
return True
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.d[self.find(x)]
n, m, k = map(int, input().split())
deg = [0]*100005
uf = UnionFind(n)
for _ in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
deg[a] += 1
deg[b] += 1
uf.unite(a, b)
for _ in range(k):
c, d = map(int, input().split())
c -= 1
d -= 1
if uf.same(c, d):
deg[c] += 1
deg[d] += 1
for i in range(n):
print(uf.size(i) - 1 - deg[i], end="")
if i == n-1:
print()
else:
print(" ", end="")
| h = int(input())
w = int(input())
n = int(input())
c = n // max(h,w)
if(n % max(h,w) != 0):c+=1
print(c) | 0 | null | 74,944,190,204,010 | 209 | 236 |
import re
i = str(input())
j = i.islower()
if j == 1:
o = 'a'
else:
o = 'A'
print(o) | a = input()
if a >= 'a':
print("a")
else:
print("A") | 1 | 11,357,742,917,418 | null | 119 | 119 |
n,k = map(int, input().split())
ans = 0
while n > 0:
n /= k
n = int(n)
ans += 1
print(ans)
| mod=998244353
N,K=map(int, input().split())
A=[list(map(int, input().split())) for _ in range(K)]
S=[0 for _ in range(N+1)]
S[1]=1
for i in range(1,N):
S[i+1]=S[i]
for l,r in A:
S[i+1]+=S[max(0,i-l+1)]-S[max(0,i-r)]
S[i+1]%=mod
print((S[N]-S[N-1])%mod) | 0 | null | 33,552,159,112,170 | 212 | 74 |
def func(x):
return x + x**2 + x**3
if __name__=="__main__":
input = input()
print(func(int(input)))
| import sys
h,w,m = map(int,input().split())
h_lst = [[0,i] for i in range(h)]
w_lst = [[0,i] for i in range(w)]
memo = []
for i in range(m):
x,y = map(int,input().split())
h_lst[x-1][0] += 1
w_lst[y-1][0] += 1
memo.append((x-1,y-1))
h_lst.sort(reverse = True)
w_lst.sort(reverse = True)
Max_h = h_lst[0][0]
Max_w = w_lst[0][0]
h_ans = [h_lst[0][1]]
w_ans = [w_lst[0][1]]
if h != 1:
s = 1
while s < h and h_lst[s][0] == Max_h:
h_ans.append(h_lst[s][1])
s+= 1
if w!= 1:
t=1
while t < w and w_lst[t][0] == Max_w:
w_ans.append(w_lst[t][1])
t += 1
memo = set(memo)
#探索するリストは、最大を取るものの集合でなければ計算量はO(m)にはならない!
for j in h_ans:
for k in w_ans:
if (j,k) not in memo:
print(Max_h+Max_w)
sys.exit()
print((Max_h+Max_w)-1)
| 0 | null | 7,462,227,824,700 | 115 | 89 |
s = list(input())
count = len(s)
for i in range(count):
s[i] = "x"
changed = "".join(s)
print(changed) | X = int(input())
i = 1
while (360 * i) % X != 0: i += 1
print((360 * i) // X) | 0 | null | 43,149,340,055,708 | 221 | 125 |
#!usr/bin/env python3
def string_two_numbers_spliter():
a, b, c = [int(i) for i in input().split()]
return a, b, c
def count_nums_of_divisors_of_c_in_a_and_b(a, b, c):
count = 0
for i in range(1, c+1):
if (c % i == 0):
if i >= a and i <= b:
count += 1
return count
def main():
a, b, c = string_two_numbers_spliter()
print(count_nums_of_divisors_of_c_in_a_and_b(a, b, c))
if __name__ == '__main__':
main() | def aizu007():
xs = map(int,raw_input().split())
a,b,c = xs[0],xs[1],xs[2]
cnt = 0
for i in range(a,b+1):
if c%i == 0:
cnt = cnt + 1
print cnt
aizu007() | 1 | 569,651,004,560 | null | 44 | 44 |
# coding: utf-8
class Dice(object):
def __init__(self, num_list):
self.num = num_list
def west(self):
num = list(self.num)
before = [5, 2, 0, 3]
after = [2, 0, 3, 5]
for i in range(4):
self.num[after[i]] = num[before[i]]
return self.num[5]
def east(self):
num = list(self.num)
before = [5, 2, 0, 3]
after = [3, 5, 2, 0]
for i in range(4):
self.num[after[i]] = num[before[i]]
return self.num[5]
def north(self):
num = list(self.num)
before = [0, 1, 5, 4]
after = [4, 0, 1, 5]
for i in range(4):
self.num[after[i]] = num[before[i]]
return self.num[5]
def south(self):
num = list(self.num)
before = [0, 1, 5, 4]
after = [1, 5, 4, 0]
for i in range(4):
self.num[after[i]] = num[before[i]]
return self.num[5]
if __name__ == "__main__":
num_list = [int(i) for i in raw_input().split()]
dice = Dice(num_list)
for order in raw_input():
if order == "E": dice.east()
elif order == "W": dice.west()
elif order == "S": dice.south()
elif order == "N": dice.north()
print dice.num[0] | #! python3
# distance.py
import math
x1, y1, x2, y2 = [float(x) for x in input().split(' ')]
print('%.5f'%math.sqrt(pow(x2-x1, 2) + pow(y2-y1, 2)))
| 0 | null | 195,658,232,900 | 33 | 29 |
sh,sm,eh,em,t=map(int,input().split())
print((eh-sh)*60+em-sm-t) | import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()
INF = float('inf')
def main():
n, x, y = LI()
x, y = x - 1, y - 1
d = [[INF] * n for _ in range(n)]
ans = [0] * n
for i in range(n - 1):
for j in range(i + 1, n):
d[i][j] = min([j - i,
abs(x - i) + 1 + abs(j - y),
abs(y - i) + 1 + abs(j - x)])
ans[int(d[i][j])] += 1
print(*ans[1:], sep='\n')
main()
| 0 | null | 30,937,233,750,400 | 139 | 187 |
x = input().split()
a,b,c=[int(x) for x in x]
ans=0
for x in range(a,b+1):
if c%x==0:ans+=1
print(ans)
| def i_miss_you():
# 入力
S = input()
# 初期処理
string = ''
# 処理
for _ in range(len(S)):
string += 'x'
return string
result = i_miss_you()
print(result) | 0 | null | 36,749,961,654,560 | 44 | 221 |
N = int(input())
D = []
count = 0
for i in range(N):
d = list(map(int,input().split()))
D.append(d)
for i in range(N-2):
if (D[i][0]==D[i][1]) and (D[i+1][0]==D[i+1][1]) and (D[i+2][0]==D[i+2][1]):
print("Yes")
break
else:
print("No")
| N,X,Y=map(int,input().split())
A=[0]*(N-1)
for i in range(1,N):
for j in range(i+1,N+1):
A[min(j-i,abs(X-i)+1+abs(j-Y),abs(Y-i)+1+abs(j-X))-1]+=1
for a in A:
print(a) | 0 | null | 23,456,240,607,590 | 72 | 187 |
n = int(input())
m=list(map(int,input().split()))
A=[0]*n
for i in range(n-1):
A[m[i]-1]+=1
print(*A, sep = "\n")
| import collections
N = int(input())
A = list(map(int,input().split()))
a = collections.Counter(A)
for i in range(1,len(A)+2):
print(a[i]) | 1 | 32,542,754,515,040 | null | 169 | 169 |
def f(x, m):
return x * x % m
def main():
N, X, M = map(int, input().split())
pre = set()
pre.add(X)
cnt = 1
while cnt < N:
X = f(X, M)
if X in pre: break
cnt += 1
pre.add(X)
if cnt == N:
return sum(pre)
ans = sum(pre)
N -= cnt
loop = set()
loop.add(X)
while cnt < N:
X = f(X, M)
if X in loop: break
loop.add(X)
left = N % len(loop)
ans += sum(loop) * (N // len(loop))
for i in range(left):
ans += X
X = f(X, M)
return ans
print(main())
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
d, t, s = map(int, input().split())
if t * s >= d:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| 0 | null | 3,218,770,453,980 | 75 | 81 |
# E - Dividing Chocolate
import numpy as np
H, W, K = map(int, input().split())
S = np.zeros((H, W), dtype=np.int64)
ans = H+W
for i in range(H):
S[i] = list(str(input()))
for m in range(1<<(H-1)):
cut = bin(m).count('1')
if cut >= ans:
continue
wp = np.zeros((cut+1, W), dtype=np.int64)
wp[0] = S[0]
c = 0
for n in range(H-1):
if m>>n&1:
c += 1
wp[c] += S[n+1]
if np.count_nonzero(wp > K):
continue
wq = np.zeros((cut+1, ), dtype=np.int64)
for j in range(W):
wq += wp[:,j]
if np.count_nonzero(wq > K):
cut += 1
wq = wp[:,j]
ans = min(ans, cut)
print(ans)
| import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
T1, T2 = mapint()
A1, A2 = mapint()
B1, B2 = mapint()
if not (A1-B1)*(A2-B2)<0:
print(0)
else:
if A1<B1:
A1, B1 = B1, A1
A2, B2 = B2, A2
if A1*T1+A2*T2==B1*T1+B2*T2:
print('infinity')
exit(0)
rest = (A1-B1)*T1
come = (B2-A2)*T2
if come<rest:
print(0)
else:
ans = come//(come-rest)
last = 1 if come%(come-rest)==0 else 0
print(ans*2-1-last) | 0 | null | 90,106,610,488,470 | 193 | 269 |
N = int(input())
a = list(map(int, input().split()))
left = []
for i in range(N):
if left:
if a[i] == left[-1] + 1:
left.append(a[i])
else:
if a[i] == 1:
left.append(a[i])
if left:
print(N - len(left))
else:
print(-1) | N = int(input())
a = list(map(int,input().split()))
ans = 0
c = 1
for i in range(N):
if a[i] == c:
c += 1
else:
ans += 1
if ans == N: print(-1)
else: print(ans) | 1 | 114,542,842,149,248 | null | 257 | 257 |
from collections import deque
def bfs(i, j):
dist = [[0] * w for _ in range(h)]
q = deque()
q.append((i, j))
dist[i][j] = 1
while q:
nx, ny = q.pop()
for dx, dy in D:
X, Y = nx + dx, ny + dy
if X < 0 or Y < 0 or X >= h or Y >= w:
continue
if m[X][Y] == "#":
continue
if dist[X][Y] != 0:
continue
q.appendleft((X, Y))
dist[X][Y] = 1 + dist[nx][ny]
mx = 0
for i in dist:
mx = max(mx, max(i))
return mx
h, w = map(int, input().split())
m = [input() for _ in range(h)]
D = [(-1, 0), (0, -1), (1, 0), (0, 1)]
ans = 0
for i in range(h):
for j in range(w):
if m[i][j] == ".":
ans = max(ans, bfs(i, j))
print(ans - 1) | N, K = list(map(int, input().split()))
ans = 0
all_sum = N*(N+1)/2
mod = 10**9+7
for i in range(K,N+2):
min_val = i*(i-1)/2
max_val = N*(N+1)/2 - (N-i+1)*(N-i)/2
ans += (int(max_val) - int(min_val) + 1) % mod
# print(i, min_val, max_val)
print(ans%mod)
| 0 | null | 63,903,367,657,930 | 241 | 170 |
import sys
read = sys.stdin.read
T1, T2, A1, A2, B1, B2 = map(int, read().split())
answer = 0
v1 = A1 - B1
v2 = A2 - B2
d = v1 * T1 + v2 * T2
if d == 0:
print('infinity')
exit()
elif v1 * d > 0:
print(0)
exit()
if v1 * T1 % -d == 0:
print(v1 * T1 // -d * 2)
else:
print(v1 * T1 // -d * 2 + 1) | T1, T2, A1, A2, B1, B2 = map(int, open(0).read().split())
P = (A1 - B1) * T1
Q = (A2 - B2) * T2
if P > 0:
P, Q = -P, -Q
if P + Q < 0:
print(0)
elif P + Q == 0:
print("infinity")
else:
S, T = divmod(-P, P + Q)
print(S * 2 + (T != 0))
| 1 | 131,800,403,731,392 | null | 269 | 269 |
n, m, k = map(int, input().split())
def bin(a, b, p):
res = 1
while b > 0:
if b & 1 > 0:
res = res * a % p
a = a * a % p
b >>= 1
return res
MOD = 998244353
N = 200000 + 50
f = [0 for i in range(N)]
invf = [0 for i in range(N)]
f[0] = invf[0] = 1
for i in range(1, N):
f[i] = f[i-1] * i % MOD
invf[n] = bin(f[n], MOD-2, MOD)
for ri in range(1, N-1):
i = n - ri
invf[i] = invf[i+1] * (i+1) % MOD
def binom(n, m):
if n < m or n < 0 or m < 0:
return 0
return f[n] * invf[m] % MOD * invf[n-m] % MOD
def g(n, m):
return m * bin(m-1, n-1, MOD)
ans = 0
for i in range(0, k+1):
# print(n-i, i, binom(n-1, i), bin(n-i, m, MOD), n-i, m)
ans = (ans + binom(n-1, i) * g(n-i, m)) % MOD
print(ans) | N,M,K=map(int,input().split())
MOD=998244353
ans=0
x,y=1,1
for k in range(K+1):
ans=ans+M*x*pow(y,MOD-2,MOD)*pow(M-1,N-1-k,MOD)
ans=ans%MOD
x=x*(N-k-1)
y=y*(k+1)
x=x%MOD
y=y%MOD
print(ans%MOD) | 1 | 23,104,972,291,360 | null | 151 | 151 |
N = int(input())
cnt = 0
for A in range(1, N + 1):
for B in range(1, N // A + 1):
C = N - A * B
if C >= 1 and A * B + C == N:
cnt += 1
print(cnt)
| import math
n = int(input())
x = n/1.08
t1 = math.ceil(x)
t2 = math.floor(x)
if math.floor(t1 * 1.08) == n:
print(t1)
elif math.floor(t2*1.08) == n:
print(t2)
else:
print(':(') | 0 | null | 64,352,528,609,280 | 73 | 265 |
S = list(input())
N = len(S)
if S == S[::-1] and S[:(N - 1) // 2] == S[:(N - 1) // 2][::-1] and S[(N - 1) // 2 + 1:] == S[(N - 1) // 2 + 1:][::-1]:
print("Yes")
else:
print("No")
| s = input()
n = len(s)
ans = "No"
cnt = 0
if s[::1] == s[::-1]:
cnt += 1
if s[:int((n-1)/2):1] == s[int((n-1)/2)-1::-1]:
cnt += 1
if s[int((n+1)/2)::1] == s[:int((n-1)/2):-1]:
cnt += 1
if cnt == 3:
ans = "Yes"
print(ans) | 1 | 46,408,139,328,810 | null | 190 | 190 |
N,K = map(int,input().split())
S = []
d = {}
A = list(map(int,input().split()))
ans = 0
sum =0
for i in range(1,N+1):
sum += A[i-1] % K
s = (sum - i) % K
if i > K:
x = S.pop(0)
d[x] -= 1
elif i < K:
if s == 0:
ans += 1
if s not in d:
d[s] = 0
ans += d[s]
d[s] += 1
S.append(s)
print(ans)
| import sys
input = sys.stdin.readline
from itertools import accumulate
N, K = map(int, input().split())
A = map(int, input().split())
B = accumulate(A)
C = [0]+[(b-i)%K for i, b in enumerate(B,start=1)]
cnt = dict()
cnt[C[0]] = 1
res = 0
for i in range(1, N+1):
if i >= K:
cnt[C[i-K]] = cnt.get(C[i-K],0) - 1
res += cnt.get(C[i], 0)
cnt[C[i]] = cnt.get(C[i],0) + 1
print(res)
| 1 | 137,076,963,656,152 | null | 273 | 273 |
H, W, M = map(int, input().split())
h_list = [0 for i in range(H)]
w_list = [0 for i in range(W)]
point = {}
for _ in range(M):
h, w = map(int, input().split())
h_list[h - 1] += 1
w_list[w - 1] += 1
point[(h - 1, w - 1)] = 1
hmax = 0
wmax = 0
hmap = {}
wmap = {}
for i, h in enumerate(h_list):
if hmax <= h:
hmax = h
hmap.setdefault(h, []).append(i)
for i, w in enumerate(w_list):
if wmax <= w:
wmax = w
wmap.setdefault(w, []).append(i)
# print(hmap)
# print(wmap)
# hmax = max(h_list)
# wmax = max(w_list)
h_index = h_list.index(hmax)
w_index = w_list.index(wmax)
for h in hmap[hmax]:
for w in wmap[wmax]:
if (h, w) not in point:
print(hmax + wmax)
exit(0)
print(hmax + wmax - 1) | import sys
h,w,m = map(int,input().split())
h_lst = [[0,i] for i in range(h)]
w_lst = [[0,i] for i in range(w)]
memo = []
for i in range(m):
x,y = map(int,input().split())
h_lst[x-1][0] += 1
w_lst[y-1][0] += 1
memo.append((x-1,y-1))
h_lst.sort(reverse = True)
w_lst.sort(reverse = True)
Max_h = h_lst[0][0]
Max_w = w_lst[0][0]
h_ans = [h_lst[0][1]]
w_ans = [w_lst[0][1]]
if h != 1:
s = 1
while s < h and h_lst[s][0] == Max_h:
h_ans.append(h_lst[s][1])
s+= 1
if w!= 1:
t=1
while t < w and w_lst[t][0] == Max_w:
w_ans.append(w_lst[t][1])
t += 1
memo = set(memo)
#探索するリストは、最大を取るものの集合でなければ計算量はO(m)にはならない!
for j in h_ans:
for k in w_ans:
if (j,k) not in memo:
print(Max_h+Max_w)
sys.exit()
print((Max_h+Max_w)-1)
| 1 | 4,688,869,700,792 | null | 89 | 89 |
while True:
n, x = map(int, input().split())
if n == 0 and x == 0:
break
else:
counter = 0
for a in range(1,(x // 3)):
for c in range ((x//3)+1,n+1):
b = x - a - c
if a < b < c:
counter += 1
print(counter) | import itertools
while True:
n,x = map(int,input().split(" "))
if n == 0 and x == 0:
break
#データリスト作成
data = [m for m in range(1,n+1)]
data_cmb = list(itertools.combinations(data,3))
#検証
res = [ret for ret in data_cmb if sum(ret) == x]
print(len(res))
| 1 | 1,287,893,429,020 | null | 58 | 58 |
N = int(input())
if N%1000 == 0:
print(0)
else:
print((int(N/1000)+1)*1000-N)
| n = int(input())
t = 1000
while n > t:
t += 1000
print(t - n) | 1 | 8,394,871,468,740 | null | 108 | 108 |
A = str(input())
B = str(input())
c = 0
lenA = len(A)
for i in range(lenA):
if A[i] != B[i]:
c += 1
print(c)
| a = input().split()
b = int(a[0])
c = int(a[1])
if b == 1 and c == 1:
print(0)
elif b>=2 and c>=2:
d = b-1
e = c-1
f = b*d/2
g = c*e/2
print(int(f+g))
elif b<=1 and c>=2:
d = c-1
f = c*d/2
print(int(f))
elif b>=2 and c<=1:
d = b-1
f = b*d/2
print(int(f)) | 0 | null | 28,000,736,223,200 | 116 | 189 |
N=int(input())
A=0
B=0
C=0
D=0
for i in range(N+1):
A+=i
for i in range(N+1):
if i % 3 == 0:
B+=i
for i in range(N+1):
if i % 5 == 0:
C+=i
for i in range(N+1):
if i % 15 == 0:
D+=i
print(A-B-C+D) | n = int(input())
ans = 0
for i in range(1,n+1):
if i % 3 == 0 and i % 5 == 0:
ans += 0
elif i % 3 == 0 or i % 5 == 0:
ans += 0
else:
ans += i
print(ans) | 1 | 34,915,259,429,180 | null | 173 | 173 |
a = list(map(int, input().split()))
x = 0
y = 0
for i in range(0,a[1]):
x = x + a[0]*(10**i)
for i in range(0,a[0]):
y = y + a[1]*(10**i)
if x<=y:
print(y)
else:
print(x) | s=input()
if s=="ABC":
print("ARC")
else:
print("ABC") | 0 | null | 54,083,831,937,332 | 232 | 153 |
n = list(input().split())
for i in range(len(n)):
if n[i] == "0":
print(int(i)+1)
| rooms = [0] * (4*3*10)
count = int(input())
for i in range(count):
b, f, r, v = [int(x) for x in input().split()]
rooms[30*(b-1) + 10*(f-1) + (r-1)] += v
for i, room in enumerate(rooms, start=1):
print('', room, end='')
if i%10 == 0:
print()
if i%30 == 0 and i%120 != 0:
print('#'*20) | 0 | null | 7,324,634,661,582 | 126 | 55 |
MAX = 10 ** 5 * 2
mod = 10 ** 9 + 7
frac = [1]
inv_frac=[1]
def pow(a, n):
if n == 0 : return 1
elif n == 1 : return a
tmp = pow(a, n//2)
tmp = (tmp * tmp) % mod
if n % 2 == 1 :
tmp = (tmp * a) % mod
return tmp
def inv(x):
return pow(x, mod - 2 )
for i in range(1,MAX + 1 ):
frac.append( (frac[-1] * i) % mod )
inv_frac.append(inv(frac[-1])%mod)
def comb(n, k):
if k >= n or k < 0 : return 1
return (frac[n]*inv_frac[n-k] * inv_frac[k]) %mod
n,k = map(int,input().split())
count=0
b=inv(n)
for i in range(min(n,k+1)):
a=comb(n,i)
count=(count+a*a*(n-i)*b)%mod
print(count) | MOD = 1000000007
n,k = map(int,input().split())
fac = [0]*(n+1)
finv = [0]*(n+1)
inv = [0]*(n+1)
answer = 0
# テーブルを作る前処理
def COMinit(n, MOD):
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, n+1):
fac[i] = fac[i - 1] * i % MOD
inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
# 二項係数計算
def COM(n, k):
if (n < k): return 0
if (n < 0 or k < 0): return 0
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
COMinit(n, MOD)
fac = tuple(fac)
finv = tuple(finv)
inv = tuple(inv)
a = n if n < k else k + 1
for i in range(a):
answer += COM(n,i) * COM(n-1, n-i-1)
# print(answer)
print(answer%MOD)
| 1 | 66,809,830,032,988 | null | 215 | 215 |
def sub(x):
global A; global F; global K
s = 0
for i in range(N):
s += max(A[i] - x // F[i], 0)
return s <= K
N, K = map(int,input().split())
A = list(map(int,input().split())); A.sort()
F = list(map(int,input().split())); F.sort(); F.reverse()
# print(A); print(F)
l = -1; r = max(A) * max(F)
while r - l > 1:
m = (l + r) // 2
if sub(m):
r = m
else:
l = m
print(r) | import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
return sys.stdin.readline().rstrip()
def main():
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
F=list(map(int,input().split()))
F.sort(reverse=True)
def nibutan(ok,ng):
while abs(ok-ng) > 1:
mid = (ok + ng) // 2
if solve(mid):
ok = mid
else:
ng = mid
return ok
def solve(mid):
k=0
for i in range(N):
k+=max(0,-(-(A[i]*F[i]-mid)//F[i]))
if k<=K:
return True
else:
return False
print(nibutan(10**18,-1))
if __name__ == '__main__':
main()
| 1 | 165,120,710,849,094 | null | 290 | 290 |
import sys
input = sys.stdin.buffer.readline
def main():
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())
l = (A1-B1)*T1 + (A2-B2)*T2
if l == 0:
print("infinity")
elif l > 0:
if A1 > B1:
print(0)
else:
d = (B1-A1)*T1
if d%l == 0:
ans = 2*(d//l)
else:
ans = 1+2*(d//l)
print(ans)
else:
l *= -1
if B1 > A1:
print(0)
else:
d = (A1-B1)*T1
if d%l == 0:
ans = 2*(d//l)
else:
ans = 1+2*(d//l)
print(ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
T = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p = (a[0] - b[0]) * T[0]
q = (a[1] - b[1]) * T[1]
if p > 0:
p *= -1
q *= -1
if p + q < 0:
print(0)
elif p + q > 0:
print(-p // (p + q) * 2 + ((-p % (p + q)) > 0))
else:
print("infinity") | 1 | 131,550,757,737,402 | null | 269 | 269 |
import math
r=float(input())
print("%.6f"%(r**2*math.pi),"%.6f"%(r*2*math.pi)) | h, w = map(int, input().split())
S = []
for _ in range(h):
s = str(input())
S.append(s)
DP = [[0 for _ in range(w)] for _ in range(h)]
if S[0][0] == '.':
DP[0][0] = 0
else:
DP[0][0] = 1
ren = False
if DP[0][0] == 1:
ren = True
for i in range(1,h):
if S[i][0] == '.':
DP[i][0] = DP[i-1][0]
ren = False
elif ren == False and S[i][0] == '#':
DP[i][0] = DP[i-1][0] + 1
ren = True
elif ren == True and S[i][0] == '#':
DP[i][0] = DP[i-1][0]
ren = True
ren = False
if DP[0][0] == 1:
ren = True
for j in range(1,w):
if S[0][j] == '.':
DP[0][j] = DP[0][j-1]
ren = False
elif ren == False and S[0][j] == '#':
DP[0][j] = DP[0][j-1] + 1
ren = True
elif ren == True and S[0][j] == '#':
DP[0][j] = DP[0][j-1]
ren = True
for i in range(1,h):
for j in range(1,w):
if S[i][j] == '.':
DP[i][j] = min(DP[i-1][j], DP[i][j-1])
elif S[i][j] == '#':
res_i = 0
res_j = 0
if S[i-1][j] == '.':
res_i = 1
if S[i][j-1] == '.':
res_j = 1
DP[i][j] = min(DP[i-1][j] + res_i, DP[i][j-1] + res_j)
print(DP[h-1][w-1]) | 0 | null | 25,089,831,615,258 | 46 | 194 |
N = int(input())
A = list(map(int, input().split()))
B = []
temp = 0
for i in range(N):
if A[i] != temp:
B.append(A[i])
temp = A[i]
N = len(B)
A = [float("inf")] + B + [0]
money, stock = 1000, 0
for i in range(1, N + 1):
if A[i - 1] > A[i] and A[i] < A[i + 1]:
x = money // A[i]
money -= A[i] * x; stock += x
if A[i - 1] < A[i] and A[i] > A[i + 1]:
x = stock
money += A[i] * x; stock -= x
print(money)
| n = int(input())
data = list(map(int, input().split()))
ans = 0
money = 1000
for idx in range(n-1):
today = data[idx]
tmr = data[idx+1]
if tmr > today:
money += (tmr-today) * (money//today)
print(money) | 1 | 7,321,829,915,368 | null | 103 | 103 |
x = int(input())
deposit = 100
year = 0
rate = 101
while(deposit < x):
deposit = deposit * rate // 100
year += 1
print(year) | #j-i=Ai+Aj(j>i)
#j-Aj=Ai+i
#Lj=Ri=X
from bisect import bisect_left
def main():
N=int(input())
A=list(map(int,input().split()))
L={}
R={}
res=0
for i in range(N):
l=(i+1)-A[i]
r=A[i]+i+1
if (l in R.keys()):
res+=len(R[l])
if (r in R.keys()):
R[r].append(i+1)
else:
R[r]=[i+1]
print(res)
if __name__=="__main__":
main()
| 0 | null | 26,607,950,672,160 | 159 | 157 |
from itertools import accumulate
n,m,k = map(int,input().split())
deskA = list(map(int,input().split()))
deskB = list(map(int,input().split()))
cumA = [0] + list(accumulate(deskA))
cumB = [0] + list(accumulate(deskB))
ans = 0
j = m
for i in range(n+1):
if cumA[i] > k:
continue
while cumA[i] + cumB[j] > k:
j -= 1
ans = max(i+j,ans)
print(ans) | import sys
li = []
for line in sys.stdin:
li.append(int(line))
if len(li) == 10:
break
li.sort(reverse=True)
li = li[0:3]
for i in li:
print(i) | 0 | null | 5,424,879,278,182 | 117 | 2 |
h, w = map(int, input().split())
import math
if h == 1 or w == 1:
print(1)
elif h%2 == 0 and w%2 == 0:
print(h * w // 2)
elif h%2 == 0 or w%2 == 0:
if h%2 == 0:
we = w//2
wo = math.ceil(w/2)
print(we * h//2 + wo * h//2)
else:
he = h//2
ho = math.ceil(h/2)
print(ho * w//2 + he * w//2)
else:
# odd
we = w//2
wo = math.ceil(w/2)
he = h//2
ho = math.ceil(h/2)
print(ho * wo + he * we)
| import sys
input=sys.stdin.readline
N=int(input())
S=input()
Q=int(input())
D={}
A=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(26):
D[A[i]]=i
n=1
while n<N:
n*=2
seg=[0 for i in range(n*2)]
#print(seg)
for i in range(N):
seg[n-1+i]=1<<D[S[i]]
k=n-1+i
while k>0:
k=(k-1)//2
seg[k]=(seg[k*2+1]|seg[k*2+2])
#print(list(bin(seg[0])).count("1"))
#0indexでa番目の値をbに変更
def update(a,b):
a+=n-1
seg[a]=1<<D[b]
while a>0:
a=(a-1)//2
seg[a]=(seg[a*2+1]|seg[a*2+2])
#print(seg)
#A~B-1(0-index)までの累積和を求める
#1~2までの累積和なら(1,3,0,0,n)
#Kは接点番号?L,Rはその接点が[L,R)に対応づいていることを表す?
#外部からはquery(A,B,0,0,n)として呼び出す
def query(A,B,K,L,R):
if K>=len(seg):
return 0
if R<=A or B<=L:
return 0
elif A<=L and R<=B:
return seg[K]
else:
vl=query(A,B,K*2+1,L,(L+R)//2)
vr=query(A,B,K*2+2,(L+R)//2,R)
#print(vl,vr)
return vl|vr
#print(n,len(seg))
#print("P",query(2,4,0,0,n),len(query(2,4,0,0,n)))
#update(3,"a")
#print(seg)
#print(query(2,4,0,0,n))
for i in range(Q):
x,y,z=list(input().split())
if x=="1":
update(int(y)-1,z)
else:
print(list(bin(query(int(y)-1,int(z),0,0,n))).count("1"))
| 0 | null | 56,621,930,227,510 | 196 | 210 |
from collections import deque
que = deque()
l = input()
S = 0
S2 = []
for j in range(len(l)):
i = l[j]
if i == '\\':
que.append(j)
continue
elif i == '/':
if len(que) == 0:
continue
k = que.pop()
pond_sum = j-k
S += pond_sum
while S2 and S2[-1][0] > k:
pond_sum += S2[-1][1]
S2.pop()
S2.append([k,pond_sum])
elif i == '_':
continue
data = [i for j,i in S2]
print(S)
print(len(S2),*data)
| MOD = 998244353
n, k = map(int, input().split())
l = [0] * k
r = [0] * k
for i in range(k):
l[i], r[i] = map(int, input().split())
s = [0] * (n + 2)
for i in range(k):
for j in range(l[i], r[i] + 1):
s[j] = 1
ans = [0] * (n + 1)
ans[0] = 1
for i in range(n - 1):
ans[i + 1] = ans[i]
for j in range(k):
ans[i + 1] += ans[max(-1, i + 1 - l[j])]
ans[i + 1] -= ans[max(-1, i + 1 - r[j] - 1)]
ans[i + 1] = ans[i + 1] % MOD
print((ans[n - 1] - ans[n - 2]) % MOD)
| 0 | null | 1,376,098,523,310 | 21 | 74 |
def resolve():
N, K = list(map(int, input().split()))
ans = 0
mini = sum(range(K))
maxi = sum(range(N, N-K, -1))
for i in range(K, N+2):
ans += maxi - mini + 1
ans %= 10**9+7
mini += i
maxi += N - i
print(ans)
if '__main__' == __name__:
resolve()
| #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(input())
import math
a,b,h,m = readInts()
h = h-12 if h>=12 else h
h_ = 30 * h + 30 * m/60
m_ = 360 * m / 60
kakudo = min(abs(m_ - h_), 360 - abs(m_ - h_))
c = pow(a**2 + b**2 - 2*a*b*math.cos(math.radians(kakudo)),.5)
print(c)
| 0 | null | 26,508,294,714,610 | 170 | 144 |
import math, cmath
def koch(p1, p2, n):
if n == 0:
return [p1, p2]
rad60 = math.pi/3
v1 = (p2 - p1)/3
v2 = cmath.rect(abs(v1), cmath.phase(v1)+rad60)
q1 = p1 + v1
q2 = q1 + v2
q3 = q1 + v1
if n == 1:
return [p1,q1,q2,q3,p2]
else:
x1 = koch(p1,q1,n-1)[1:-1]
x2 = koch(q1,q2,n-1)[1:-1]
x3 = koch(q2,q3,n-1)[1:-1]
x4 = koch(q3,p2,n-1)[1:-1]
x = [p1]+x1+[q1]+x2+[q2]+x3+[q3]+x4+[p2]
return x
n = int(raw_input())
p1 = complex(0,0)
p2 = complex(100,0)
for e in koch(p1,p2,n):
print e.real,e.imag | import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
n, m = map(int, readline().rstrip().split())
a = list(map(int, readline().rstrip().split()))
print(n - sum(a) if n - sum(a) >= 0 else -1)
if __name__ == '__main__':
main()
| 0 | null | 16,139,380,864,608 | 27 | 168 |
C =input()
L =[]
for i in range(97, 123):
L.append(chr(i))
print(L[ord(C)-96])
| r=float(input())
pi=3.141592653589793238
print(pi*r**2,2*pi*r)
| 0 | null | 46,602,778,497,538 | 239 | 46 |
s = input()
if s[-1] == s[-2]:
if s[-3] == s[-4]:
print("Yes")
exit()
print("No") | s=list(map(str,input()))
if s[2]==s[3] and s[4]==s[5]:
print('Yes')
else:
print('No')
| 1 | 42,232,369,561,840 | null | 184 | 184 |
s=input()
n=len(s)
from collections import Counter
c=Counter()
m=0
c[m]+=1
d=1
s=s[::-1]
for i in range(n):
m+=int(s[i])*d
m%=2019
d*=10
d%=2019
c[m]+=1
ans=0
for v in c.values():
ans+=v*(v-1)//2
print(ans)
| N = str(input())
n,mods = 0,[1]+[0]*2018
d = 1
for i in reversed(N):
n = (n+int(i)*d)%2019
mods[n] += 1
d = (d*10)%2019
print(sum([i*(i-1)//2 for i in mods])) | 1 | 30,973,421,739,260 | null | 166 | 166 |
from math import sqrt
from math import floor
n = int(input())
ans = 10 ** 12
m = floor(sqrt(n))
for i in range(1,m+1):
if n % i == 0:
j = n // i
ans = min(ans,i+j-2)
print(ans) | x=int(input())
if x<100:
print(0)
exit()
if x>=2000:
print(1)
exit()
else:
t=x//100
a=x%100
if 0<=a<=t*5:
print(1)
else:
print(0) | 0 | null | 144,931,196,530,862 | 288 | 266 |
N = int(input())
A = list(map(int, input().split()))
# ex. 24 11 8 3 16
A.sort()
# ex. 3 8 11 16 24
cnt = 0
# Aの最大値が24なら25個用意する感じ
# indexと考える値を一致させて分かりやすくしている
# Trueで初期化
# 最後のインデックスはA[-1]
dp = [True] * (A[-1] + 1)
# エラトステネスの篩っぽいやつ
for i in range(N):
if dp[A[i]] == True:
# dp[A[i]], dp[2*A[i]], dp[3*A[i]],...をFalseにする
for j in range(A[i], A[-1] + 1, A[i]):
dp[j] = False
if i < N - 1:
# 次も同じ数字が存在するなら数えない、なぜならお互いに割れてしまって題意を満たさないから
# 次以降に出てくる同じ数字は既にFalseになっているのでもう走査する事はない
if A[i] != A[i + 1]:
cnt += 1
# i=N-1の時は次がないので無条件でcntを増やす
# elseの方が良さそうだが明示的にするためにelifを使った
elif i == N - 1:
cnt += 1
print(cnt)
| N=int(input())
A=list(map(int,input().split()))
M=1000050
dp=[0 for i in range(M)]
ans=0
for x in A:
if dp[x]!=0:
dp[x]=2
continue
for i in range(x,M,x):
dp[i]+=1
for x in A:
if dp[x]==1:
ans+=1
print(ans)
| 1 | 14,481,204,114,788 | null | 129 | 129 |
from collections import deque
h,w=map(int,input().split())
maze=[list(input()) for i in range(h)]
ans=0
dx=[1,-1,0,0]
dy=[0,0,1,-1]
for i in range(h):
for j in range(w):
Q=deque()
Q.append((i,j,0))
if maze[i][j]=='#':
continue
dp=[[-1]*w for i in range(h)]
dp[i][j]=0
while Q:
p=Q.popleft()
ans=max(ans,p[2])
for k in range(4):
nx=p[0]+dx[k]
ny=p[1]+dy[k]
if 0<=nx<h and 0<=ny<w and maze[nx][ny]=='.' and dp[nx][ny]==-1:
Q.append((nx,ny,p[2]+1))
dp[nx][ny]=p[2]+1
print(ans)
| from collections import deque
import copy
H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]
# すべての.についてスタート地点と仮定してBFS
def bfs(i, j):
dq = deque()
maze_c = copy.deepcopy(maze)
maze_c[i][j] = 0
dq.appendleft([i, j])
res = 0
while len(dq) > 0:
ni, nj = dq.pop()
if maze_c[ni][nj] == "#":
continue
for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
if ni + di < 0 or nj + dj < 0 or ni + di >= H or nj + dj >= W:
continue
if maze_c[ni + di][nj + dj] == ".":
maze_c[ni + di][nj + dj] = maze_c[ni][nj] + 1
res = max(res, maze_c[ni + di][nj + dj])
dq.appendleft([ni + di, nj + dj])
return res
ans = 0
for i in range(H):
for j in range(W):
if maze[i][j] == ".":
ans = max(ans, bfs(i, j))
print(ans) | 1 | 94,514,842,496,800 | null | 241 | 241 |
# coding: utf-8
# Your code here!
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=a[k-1]
for i in range(n-k):
if a[i]<a[i+k]:
print('Yes')
else:
print('No')
| n, k = map(int, input().split())
li_a = list(map(int, input().split()))
for idx, v in enumerate(li_a):
if idx <= (k - 1):
pass
else:
if v > li_a[idx - k]:
print('Yes')
else:
print('No')
| 1 | 7,061,891,634,340 | null | 102 | 102 |
from collections import defaultdict
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
n = readInt()
a = readInts()
v = sum(a)/2
t = 0
for i in range(len(a)):
t+=a[i]
if t>v:
break
z1 = sum(a[:i])
k1 = sum(a[i:])
z2 = sum(a[:i+1])
k2 = sum(a[i+1:])
if abs(z1-k1)<abs(z2-k2):
z = z1
k = k1
else:
z = z2
k = k2
print(abs(z-k))
| N = int(input())
S = input()
ans = 1
for i in range(N-1):
if(S[i] != S[i+1]):
ans += 1
print(ans) | 0 | null | 156,196,033,426,640 | 276 | 293 |
from collections import deque
import sys
input = sys.stdin.readline
class DoublyLinkedList:
def __init__(self):
self.doubly_linked_list = deque()
def insert(self, item):
self.doubly_linked_list.appendleft(item)
def delete(self, item):
if item in self.doubly_linked_list:
self.doubly_linked_list.remove(item)
def delete_first(self):
if self.doubly_linked_list:
self.doubly_linked_list.popleft()
def delete_last(self):
if self.doubly_linked_list:
self.doubly_linked_list.pop()
doubly_linked_list = DoublyLinkedList()
def command_controller(command, n):
global doubly_linked_list
if command == 'insert':
doubly_linked_list.insert(n)
if command == 'deleteFirst':
doubly_linked_list.delete_first()
if command == 'deleteLast':
doubly_linked_list.delete_last()
if command == 'delete':
doubly_linked_list.delete(n)
n = int(input())
for _ in range(n):
command = list(input().split())
command_controller(command[0], command[-1])
print(*doubly_linked_list.doubly_linked_list)
| i = 1
a = input()
while a != 0:
print "Case %d: %d" % (i, a)
i = i + 1
a = input() | 0 | null | 259,692,677,120 | 20 | 42 |
import sys, math
import bisect
sys.setrecursionlimit(500000)
MOD = 10**9+7
def input():
return sys.stdin.readline()[:-1]
def mi():
return map(int, input().split())
def ii():
return int(input())
def i2(n):
tmp = [list(mi()) for i in range(n)]
return [list(i) for i in zip(*tmp)]
def isPrime(n):
if n < 2:
return False
i = 2
while i*i <= n:
if n%i==0:
return False
i += 1
return True
def main():
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = ii()
print(l[K-1])
if __name__ == '__main__':
main() | s=input()
p=input()
b=s
s+=s
ans=0
same_count=0
for i in range(len(b)):
for j in range(len(p)):
if s[i+j]==p[j]:
same_count+=1
if same_count==len(p):
ans=1
same_count=0
if ans==1:
print("Yes")
else:
print("No")
| 0 | null | 26,022,603,475,932 | 195 | 64 |
N = int(input())
A = list(map(int, input().split()))
A.sort()
MAX = 10**6+1
cnt = [0]*MAX
for x in A:
if cnt[x] != 0:
cnt[x] = 2
else:
for i in range(x, MAX, x):
cnt[i] += 1
ans = 0
for x in A:
# 2回以上通った数字 (cnt[x]>1) は,その数字より小さい約数が存在する (割り切れる他の数が存在する)。
if cnt[x] == 1:
ans += 1
print(ans) | from collections import Counter
N = int(input())
A = list(map(int, input().split()))
max_a = max(A)
A.sort()
count = Counter(A)
divisible = [False] * (max_a + 1)
ans = 0
for a in A:
if divisible[a]:
continue
for i in range(1, max_a // a + 1):
divisible[i * a] = True
if count[a] == 1:
ans += 1
print(ans)
| 1 | 14,441,907,441,628 | null | 129 | 129 |
import itertools
H,W,K=map(int,input().split())
C=[input() for i in range(H)]
ans=0
for i in range(H+1):
for j in range(W+1):
for n in itertools.combinations(list(range(H)),i):
for m in itertools.combinations(list(range(W)),j):
count = 0
for a in n:
for b in m:
if(C[a][b]=="#"):count+=1
if(count == K):
ans += 1
print(ans) | S,T = input().split()
N,M = list(map(int, input().split()))
U = input()
if U == S:
N = N - 1
if U == T:
M = M - 1
print(N, M)
| 0 | null | 40,476,645,684,020 | 110 | 220 |
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
T_split = [[] for i in range(K)]
for i in range(N):
T_split[i%K].append(T[i])
#print(T_split)
ans = 0
flag = 0
for i in range(len(T_split)):
for j in range(len(T_split[i])):
if flag == 1:
flag = 0
continue
if T_split[i][j] == 'r':
point = P
elif T_split[i][j] == 's':
point = R
elif T_split[i][j] == 'p':
point = S
ans += point
if j != len(T_split[i]) - 1:
if T_split[i][j] == T_split[i][j+1]:
flag = 1
print(ans)
| import collections
n, k = [int(w) for w in input().split()]
r, s, p = [int(w) for w in input().split()]
score = {"s": r, "p": s, "r": p}
t = input()
cnt = collections.Counter(t)
ans = 0
ans += cnt["s"] * r
ans += cnt["p"] * s
ans += cnt["r"]*p
for i in range(k):
sp_t = t[i:n: k]
is_prev_lose = False
for j in range(1, len(sp_t)):
if sp_t[j - 1] == sp_t[j]:
if is_prev_lose:
is_prev_lose = False
else:
is_prev_lose = True
ans -= score[sp_t[j]]
else:
is_prev_lose = False
print(ans)
| 1 | 106,654,505,899,280 | null | 251 | 251 |
import sys
n = int(input())
dic = {}
input_ = [x.split() for x in sys.stdin.readlines()]
for c, s in input_:
if c == 'insert':
dic[s] = 0
else:
if s in dic:
print('yes')
else:
print('no') | #!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
H,W = map(int, input().split())
s = [None for _ in range(H)]
for i in range(H):
s[i] = input()
dp = [[0]*(W+1) for _ in range(H+1)]
if s[0][0] == '#':
dp[1][1] += 1
for i in range(H):
for j in range(W):
if (i,j) == (0,0):
continue
tmp = []
if i > 0:
if s[i][j] == '#' and s[i-1][j] == '.':
tmp.append(dp[i][j+1]+1)
else:
tmp.append(dp[i][j+1])
if j > 0:
if s[i][j] == '#' and s[i][j-1] == '.':
tmp.append(dp[i+1][j]+1)
else:
tmp.append(dp[i+1][j])
dp[i+1][j+1] = min(tmp)
print(dp[H][W]) | 0 | null | 24,732,666,381,530 | 23 | 194 |
n = int(input())
s = str(input())
ans = n
for i in range(1,n):
if s[i-1] == s[i]:
ans -= 1
print(ans) | def abc143c_slimes():
n = int(input())
s = input()
cnt = 1
for i in range(n-1):
if s[i] != s[i+1]:
cnt += 1
print(cnt)
abc143c_slimes() | 1 | 170,461,072,784,272 | null | 293 | 293 |
n = int(input())
r = []
for i in range(n):
r.append(int(input()))
min = r[0]
max = -10 ** 12
for j in r[1:]:
if j - min > max:
max = j - min
if min > j:
min = j
print(max) | name = input()
str_name = str(name)
print(str_name[:3]) | 0 | null | 7,346,484,731,818 | 13 | 130 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
from math import gcd #for python3.8
def lcm(a,b):
G = gcd(a, b) #最大公約数
L = (a//G)*b #最小公倍数
return L
def main():
X = int(input())
print(lcm(X,360)//X)
if __name__ == '__main__':
main() | import numpy as np
import math
import collections
if __name__ == '__main__':
n = int(input())
print(int(np.lcm(360,n)/n)) | 1 | 13,201,539,736,180 | null | 125 | 125 |
def main():
N = int(input())
A = list(map(int,input().split()))
list_a = [0]*N
for i in range(len(A)):
list_a[A[i]-1] += 1
for i in range(N):
print(list_a[i])
main()
| import sys
def main():
N=int(sys.stdin.readline())
A=tuple(map(int,sys.stdin.readline().split()))
R=[0 for _ in range(N)]
for a in A:R[a-1]+=1
for r in R:print(r)
if __name__=='__main__':main() | 1 | 32,778,021,109,668 | null | 169 | 169 |
h = int(input())
counter = 0
while h > 0 :
h //= 2
counter += 1
print(pow(2, counter) - 1) | for i in range(1, 10):
for ii in range(1, 10):
print('{}x{}={}'.format(i, ii, i*ii)) | 0 | null | 39,836,995,722,820 | 228 | 1 |
import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N, M, L = inpl()
road = [[] for _ in range(N)]
ABC = []
for i in range(M):
A, B, C = inpl()
if C <= L:
road[A-1].append((B-1,C))
road[B-1].append((A-1,C))
ABC.append((A-1,B-1,C))
INF = 10**12
cur1 = [[INF]*N for _ in range(N)]
for a, b, c in ABC:
cur1[a][b] = cur1[b][a] = c
for k in range(N):
prev1 = cur1
cur1 = [[INF]*N for _ in range(N)]
for j in range(N):
for i in range(N):
cur1[j][i] = min(prev1[j][i], prev1[k][i]+prev1[j][k])
cur2 = [[INF]*N for j in range(N)]
for j in range(N):
for i in range(N):
if cur1[j][i] <= L:
cur2[j][i] = 1
for k in range(N):
prev2 = cur2
cur2 = [[INF]*N for _ in range(N)]
for j in range(N):
for i in range(N):
cur2[j][i] = min(prev2[j][i], prev2[k][i]+prev2[j][k])
Q = int(input())
ST = [inpl() for _ in range(Q)]
for s,t in ST:
if cur2[s-1][t-1] >= INF:
print(-1)
else:
print(cur2[s-1][t-1]-1) | n,m,l=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
q=int(input())
st=[list(map(int,input().split())) for _ in [0]*q]
inf=10**12
dist=[[inf]*n for _ in [0]*n]
for i in range(n):
dist[i][i]=0
for a,b,c in abc:
dist[a-1][b-1]=c
dist[b-1][a-1]=c
for k in range(n):
for i in range(n):
for j in range(n):
dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j])
inf=10**3
dist2=[[inf]*n for _ in [0]*n]
for i in range(n):
for j in range(n):
if dist[i][j]<=l:
dist2[i][j]=1
for k in range(n):
for i in range(n):
for j in range(n):
dist2[i][j]=min(dist2[i][j],dist2[i][k]+dist2[k][j])
for i in range(n):
for j in range(n):
if dist2[i][j]==inf:
dist2[i][j]=-1
else:
dist2[i][j]-=1
for s,t in st:
print(dist2[s-1][t-1]) | 1 | 173,865,128,864,062 | null | 295 | 295 |
import collections
n = int(input())
d = list(map(int,input().split()))
ma = max(d)
mod = 998244353
if d[0] != 0:
print(0)
exit()
p = [0 for i in range(ma+1)]
for i in range(n):
p[d[i]] += 1
if p[0] != 1:
print(0)
exit()
else:
ans = 1
for i in range(1,ma+1):
ans *= (p[i-1]**p[i])%mod
ans %= mod
print(ans) | n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
print(0)
exit()
d.sort()
import collections
c = collections.Counter(d)
if c[0] != 1:
print(0)
exit()
ans=1
for i in range(1,d[-1]+1):
if c[i] == 0:
print(0)
exit()
ans*=(c[i-1]**c[i])
ans%=998244353
print(ans) | 1 | 154,307,438,818,950 | null | 284 | 284 |
n,k=map(int, input().split())
a = list(map(int, input().split()))
mod=10**9+7
if n==k:
ans=1
for i in range(k):
ans*=a[i]
ans%=mod
print(ans)
exit()
minus=[i for i in a if i<0]
plus=[i for i in a if i>=0]
from collections import deque
minus=deque(sorted(minus))
plus=deque(sorted(plus,reverse=True))
n_minus=len(minus)
n_plus=len(plus)
if n_minus==n:
ans=1
if k%2==0:
for i in range(k):
ans*=minus.popleft()
ans+=mod
ans%=mod
print(ans)
exit()
else:
for i in range(k):
ans*=minus.pop()
ans+=mod
ans%=mod
print(ans)
exit()
cnt_minus=0
cand=deque([])
for i in range(k):
if not plus or ((plus and minus) and abs(minus[0])>abs(plus[0])):
cand.append(minus.popleft())
cnt_minus+=1
elif not minus or ((plus and minus) and abs(minus[0])<abs(plus[0])):
cand.append(plus.popleft())
else:
if cnt_minus%2==1:
cand.append(minus.popleft())
cnt_minus+=1
else:
cand.append(plus.popleft())
if cnt_minus%2==0:
ans=1
for i in range(k):
ans*=cand[i]
ans+=mod
ans%=mod
print(ans)
exit()
if 0 in cand:
print(0)
exit()
tmpm,tmpp=None,None
for i in range(k-1,-1,-1):
if cand[i]<0 and tmpm==None:
tmpm=cand[i]
elif cand[i]>=0 and tmpp==None:
tmpp=cand[i]
#print(tmpm,tmpp)
cand1,cand2=None,None
if tmpm!=None and plus:
cand1=plus[0]/abs(tmpm)
if tmpp!=None and minus:
if tmpp!=0:
cand2=abs(minus[0])/abs(tmpp)
else:
cand2=0
if tmpp==0:
if minus:
ans=1
flg=True
for i in range(k):
if flg and cand[i]==tmpp:
flg=False
continue
ans*=cand[i]
ans+=mod
ans%=mod
print((ans*minus[0])%mod)
exit()
elif (cand1!=None and cand2==None) or ((cand1!=None and cand2!=None) and plus[0]*abs(tmpp)>=abs(minus[0]*tmpm)):
ans=1
flg=True
for i in range(k):
if flg and cand[i]==tmpm:
flg=False
continue
ans*=cand[i]
ans+=mod
ans%=mod
print((ans*plus[0])%mod)
exit()
elif (cand1==None and cand2!=None) or ((cand1!=None and cand2!=None) and plus[0]*abs(tmpp)<abs(minus[0]*tmpm)):
ans=1
flg=True
for i in range(k):
if flg and cand[i]==tmpp:
flg=False
continue
ans*=cand[i]
ans+=mod
ans%=mod
print((ans*minus[0])%mod)
exit() | def grade(m, f, r):
if m == -1 or f == -1:
return 'F'
s = m + f
if s >= 80:
return 'A'
elif s >= 65:
return 'B'
elif s >= 50:
return 'C'
elif s < 30:
return 'F'
elif r >= 50:
return 'C'
else:
return 'D'
while True:
m, f, r = map(int, input().split())
if m == f == r == -1:
break
print(grade(m, f, r)) | 0 | null | 5,308,499,930,460 | 112 | 57 |
H1,M1,H2,M2,K=map(int,input().split())
t1=60*H1 + M1
t2=60*H2 + M2
t=t2 - K
ans=t-t1
print(max(0,ans)) | H1, M1, H2, M2, K = map(int, input().split())
T = (H2 - H1) * 60 + (M2 - M1)
print(T - K) | 1 | 17,988,792,568,682 | null | 139 | 139 |
def get_num(n, x):
ans = 0
for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1):
if n3 + min(n2 - 1, x - n3 - n2):
ans += 1
# for n1 in xrange(min(n2 - 1, x - n3 - n2), x - n3 - n2 - 1, -1):
# if n3 == x - n1 - n2:
# ans += 1
# break
return ans
data = []
while True:
[n, x] = [int(m) for m in raw_input().split()]
if [n, x] == [0, 0]:
break
if x < 3:
print(0)
else:
print(get_num(n, x)) | N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
import numpy as np
#0: g, R
#1: c, S
#2: p, P
ans = 0
L = [[] for _ in range(K)]
for i in range(K):
L[i] = T[i:N:K]
for l in L:
# print()
# print(l)
lenl = len(l)
Dp = np.zeros([lenl+1, 3], dtype=int)
Dp[:][:] = -1
Dp[0][:] = 0
# print(Dp)
ll = l[0]
if ll == 'r':
Dp[1][0] = 0
Dp[1][1] = 0
Dp[1][2] = P
elif ll == 's':
Dp[1][0] = R
Dp[1][1] = 0
Dp[1][2] = 0
elif ll == 'p':
Dp[1][0] = 0
Dp[1][1] = S
Dp[1][2] = 0
for i in range(1, lenl):
ll = l[i]
if ll == 'r':
Dp[i+1][0] = max(Dp[i][1], Dp[i][2])
Dp[i+1][1] = max(Dp[i][2], Dp[i][0])
Dp[i+1][2] = max(Dp[i][0], Dp[i][1]) + P
elif ll == 's':
Dp[i+1][0] = max(Dp[i][1], Dp[i][2]) + R
Dp[i+1][1] = max(Dp[i][2], Dp[i][0])
Dp[i+1][2] = max(Dp[i][0], Dp[i][1])
elif ll == 'p':
Dp[i+1][0] = max(Dp[i][1], Dp[i][2])
Dp[i+1][1] = max(Dp[i][2], Dp[i][0]) + S
Dp[i+1][2] = max(Dp[i][0], Dp[i][1])
# print(Dp)
ans += max(Dp[-1][:])
print(ans) | 0 | null | 54,041,334,578,842 | 58 | 251 |
N, M = map(int, input().split(" "))
a = list(set(map(int, input().split(" "))))
g = a.copy()
while not any(x%2 for x in g): g = [i //2 for i in g]
if not all(x%2 for x in g): print(0); exit(0)
def gcd(a, b):
while b:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
tot = 1
for x in a: tot = lcm(tot, x//2)
print((M//tot+1)//2) | k=int(input())
line="ACL"*k
print(line) | 0 | null | 51,880,106,376,602 | 247 | 69 |
from itertools import accumulate
N, K = map(int, input().split())
P = list(map(int, input().split()))
P = [((x+1) * x / 2) / x for x in P]
A = list(accumulate(P))
ans = A[K-1]
for i in range(K, N):
ans = max(ans, A[i] - A[i-K])
print(ans)
| import statistics
import math
N = int(input())
A_B = [[int(i) for i in input().split(' ')] for n in range(N)]
t = list(zip(*A_B))
A_sta = statistics.median(t[0])
B_sta = statistics.median(t[1])
if N % 2 == 0:
count = int(2 * (B_sta - A_sta) + 1)
else:
count = B_sta - A_sta + 1
print(count) | 0 | null | 45,894,847,384,328 | 223 | 137 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
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
#import numpy as np
#from decimal import *
N, X, Y = MAP()
graph = [[] for _ in range(N)]
for i in range(N-1):
graph[i].append(i+1)
graph[i+1].append(i)
graph[X-1].append(Y-1)
graph[Y-1].append(X-1)
dic = defaultdict(int)
for i in range(N):
q = deque([i])
dist = [-1]*N
dist[i] = 0
while q:
n = q.popleft()
for node in graph[n]:
if dist[node] == -1:
dist[node] = dist[n] + 1
q.append(node)
for i in range(N):
dic[dist[i]] += 1
for k in range(1, N):
print(dic[k]//2) | N,X,Y =map(int,input().split())
count = [0] * (N-1)
for i in range(1,N):
path = abs(X-i) +1
for j in range(i+1,N+1):
dist = min(j-i, path+abs(Y-j))
count[dist-1] +=1
print(*count, sep="\n") | 1 | 44,333,467,558,268 | null | 187 | 187 |
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') | A = list(map(int,input().split(" ")))
num = len(A)
for i in range(1,num):
v = A[i]
for j in range(i-1,-1,-1):
if A[j] > v:
#値移動
A[j+1] = A[j]
else:
#何もしない
A[j+1] = v
break
else:
A[0] = v
list2 = [str(k) for k in A]
print(" ".join(list2))
| 0 | null | 30,042,663,953,280 | 207 | 40 |
import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))
from math import ceil
h,w = readints()
s = [readstr() for i in range(h)]
dp = [[0]*w for i in range(h)]
if s[0][0] == '.':
dp[0][0] = 0
else:
dp[0][0] = 1
for i in range(1,h):
if s[i][0] != s[i-1][0]:
dp[i][0] = dp[i-1][0] + 1
else:
dp[i][0] = dp[i-1][0]
for i in range(1,w):
if s[0][i] != s[0][i-1]:
dp[0][i] = dp[0][i-1] + 1
else:
dp[0][i] = dp[0][i-1]
for i in range(1,h):
for j in range(1,w):
if s[i][j] != s[i-1][j]:
dp[i][j] = dp[i-1][j] + 1
else:
dp[i][j] = dp[i-1][j]
if s[i][j] != s[i][j-1]:
dp[i][j] = min(dp[i][j-1] + 1,dp[i][j])
else:
dp[i][j] = min(dp[i][j-1],dp[i][j])
print(ceil(dp[-1][-1]/2))
| i=0
while True:
a = input()
if a == 0:
break
else:
i=i+1
print "Case",str(i)+":", a | 0 | null | 24,804,521,793,870 | 194 | 42 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
N, M, K = map(int, input().split())
result = 0 # max
a_time = list(map(int, input().split()))
b_time = list(map(int, input().split()))
sum = 0
a_num = 0
for i in range(N):
sum += a_time[i]
a_num += 1
if sum > K:
sum -= a_time[i]
a_num -= 1
break
i = a_num
j = 0
while i >= 0:
while sum < K and j < M:
sum += b_time[j]
j += 1
if sum > K:
j -= 1
sum -= b_time[j]
if result < i + j:
result = i + j
i -= 1
sum -= a_time[i]
print(result)
|
def main():
N_satu, M_satu, K_fun = map(int, input().split())
A_fun = list(map(int, input().split()))
B_fun = list(map(int, input().split()))
SumOf_A = [0]
SumOf_B = [0]
for i in range(N_satu):
next_val = SumOf_A[i] + A_fun[i]
SumOf_A.append(next_val)
for i in range(M_satu):
next_val = SumOf_B[i] + B_fun[i]
SumOf_B.append(next_val)
index_b = M_satu
max_cnt = 0
for i in range(N_satu + 1):
if (SumOf_A[i] > K_fun):
break
while (SumOf_A[i] + SumOf_B[index_b] > K_fun):
index_b -= 1
max_cnt = max(max_cnt, i + index_b)
print(max_cnt)
if __name__ == '__main__':
main()
| 1 | 10,730,041,405,444 | null | 117 | 117 |
N,M = map(int,input().split())
if M % 2 == 1:
for i in range(M // 2):
print(1 + i, M - i)
for i in range(M - M // 2):
print(M + 1 + i, 2 * M + 1 - i)
else:
for i in range(M // 2):
print(1 + i, M + 1 - i)
print(M + 2 + i, 2 * M + 1 - i) | n,m=map(int,input().split())
for i in range(m):
print(i+1,2*m-i+(n%2==0 and 2*(m-i)-1>=n//2)) | 1 | 28,690,734,000,148 | null | 162 | 162 |
K, N = map(int,input().split())
A = [int(a) for a in input().split()]
dif = [A[i+1] - A[i] for i in range(N-1)]
dif.append(K + A[0] - A[N-1])
print(K - max(dif)) | import math
k,n= map(int,input().split())
a = list(map(int,input().split()))
ans = a[0]+k-a[n-1]
for i in range(1,len(a)):
s = a[i]-a[i-1]
ans =max(ans,s)
print(k-ans)
| 1 | 43,286,090,999,608 | null | 186 | 186 |
n = int(input())
num_list = input().split()
def bubbleSort(num_list, n):
flag = 1
count = 0
while flag:
flag = 0
for j in range(n-1, 0, -1):
if int(num_list[j]) < int(num_list[j-1]):
num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
flag = 1
count += 1
result = ' '.join(num_list)
print(result)
print(count)
bubbleSort(num_list, n) | def bubble_sort(A):
flag = 1
count = 0
while flag:
flag = 0
for i in range(len(A) - 1, 0, -1):
if A[i - 1] > A[i]:
A[i - 1], A[i] = A[i], A[i - 1]
flag = 1
count += 1
return count
def show(A):
for i in range(len(A) - 1):
print(A[i], end=" ")
print(A[len(A) - 1])
n = int(input())
line = input()
A = list(map(int, line.split()))
count = bubble_sort(A)
show(A)
print(count) | 1 | 16,800,677,520 | null | 14 | 14 |
a, b, m = map(int, input().split())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))
cost = []
for i in range(m):
x, y, c = map(int, input().split())
cost.append(arr_a[x - 1] + arr_b[y - 1] - c)
cost.append(min(arr_a) + min(arr_b))
ans = min(cost)
print(ans) | n = int(input())
S = [int(x) for x in input().split()]
q = int(input())
T = [int(x) for x in input().split()]
count = 0
for target in T:
if target in S:
count += 1
print(count) | 0 | null | 26,969,622,105,918 | 200 | 22 |
n = int(input())
a = [0 for _ in range(n)]
a = [int(s) for s in input().split()]
st_num = 0
mny = 1000
for i in range(n-1):
now_mn = a[i]
next_mn = a[i+1]
#print(st_num,mny)
if(next_mn > now_mn):
st_num += mny//now_mn
mny = mny%now_mn
else:
mny += st_num*now_mn
st_num = 0
if(a[n-1] > a[n-2] and st_num > 0):
mny += st_num*a[n-1]
st_num = 0
print(mny) | def resolve():
N,M = map(int,input().split())
if N % 2 == 1:
for i in range(M):
print(str(i+1) + " " + str(N-i))
else:
for i in range((M-1) // 2 + 1):
print(str(i+1) + " " + str(N-i))
for i in range((M-1) // 2 + 1 , M):
print(str(i+1) + " " + str(N-i-1))
resolve() | 0 | null | 18,092,501,920,572 | 103 | 162 |
k=int(input())
se=0
for i in range(k):
se=se*10
se+=7
i+=1
if se%k==0:
print(i)
exit()
se%=k
print('-1') | n = list(map(int,input()))
if sum(n)/9 == sum(n)//9:
print("Yes")
else:
print("No")
| 0 | null | 5,251,066,042,940 | 97 | 87 |
InputNum = input().split()
tate = int(InputNum[0])
yoko = int(InputNum[1])
square = tate * yoko
length = 2* (tate + yoko)
print(square,length) | s,n=map(int,input().split())
print("{} {}".format(s*n, (s+n)*2)) | 1 | 304,995,396,730 | null | 36 | 36 |
while True:
n = input()
if n == '0':
break
print(sum([int(x) for x in n])) | while True:
x = input()
if x == '0':
break
length = len(x)
tot = 0
for i in range(length):
tot += int(x[i:i + 1])
print(tot)
| 1 | 1,571,207,921,348 | null | 62 | 62 |
n=int(input())
a=list(map(int,input().split()))
num=["0"]*n
count="1"
for i in a:
num[i-1]=count
count=int(count)
count+=1
count=str(count)
print(" ".join(num)) | n=int(input())
s=list(map(int,input().split()))
p=["0"]*n
for i in range(n):
p[s[i]-1]=str(i+1)
p=' '.join(p)
print(p) | 1 | 181,328,159,001,440 | null | 299 | 299 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.