code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
a,b,c,d=map(int,input().split())
print("No" if (a-1)//d<(c-1)//b else"Yes") | a, b, c, d = map(int, input().split())
def kaisuu(atk, hp):
if (hp/atk) > (hp//atk):
return hp//atk + 1
else:
return hp//atk
if kaisuu(b,c) <= kaisuu(d,a):
print("Yes")
else:
print("No") | 1 | 29,772,362,168,788 | null | 164 | 164 |
A,B,C,K=map(int,input().split())
ans=1*min(A,K)
K=max(0,K-A-B)
print(ans-(1*K))
| #! python3
# triangle.py
import math
a, b, C = [int(x) for x in input().split(' ')]
S = a * b * math.sin(math.radians(C)) / 2.0
L = a + b + math.sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * math.cos(math.radians(C)))
h = b * math.sin(math.radians(C))
print('%.5f'%S)
print('%.5f'%L)
print('%.5f'%h)
| 0 | null | 10,997,475,228,170 | 148 | 30 |
import sys
input = sys.stdin.readline
#n = int(input())
#l = list(map(int, input().split()))
'''
a=[]
b=[]
for i in range():
A, B = map(int, input().split())
a.append(A)
b.append(B)'''
def cal(n,li):
lis=[True]*(n+1)
for item in li:
if lis[item]:
for i in range(item*2,n+1,item):
lis[i]=False
return lis
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
a.sort()
l=cal(a[-1],a)
ll=Counter(a)
#print(l,ll)
ans=0
for i in range(n):
if ll[a[i]]==1:
if l[a[i]]:
ans+=1
print(ans)
| n = int(input())
A = sorted(list(map(int, input().split())))
from collections import Counter
c = Counter(A)
MAX = 10 ** 6 + 1000
dp = [True] * MAX
for k, v in c.items():
if dp[k] == False: continue
if v > 1: dp[k] = False
for x in range(k + k, MAX, k):
dp[x] = False
res = 0
for x in range(n):
if dp[A[x]]: res += 1
print(res) | 1 | 14,456,664,495,420 | null | 129 | 129 |
a = list(map(int,input().split()))
T = a.index(0)
print(T+1)
# | N, M = map(int,input().split())
ans = [["",0] for i in range(N)]
for i in range(M):
p,S = map(str,input().split())
p = int(p)-1
if ans[p][0] != "AC":
if S == "AC":
ans[p][0] = "AC"
elif S == "WA":
ans[p][1] += 1
AC = 0
WA = 0
for i in ans:
if i[0] == "AC":
AC += 1
WA += i[1]
print(AC,WA) | 0 | null | 53,338,181,686,390 | 126 | 240 |
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
N, K = read_ints()
H = read_ints()
if K >= N:
return 0
H.sort(reverse=True)
return sum(H[K:])
if __name__ == '__main__':
print(solve())
| n,k = map(int,input().split())
H = sorted(list(map(int,input().split())))
if n <= k:
print(0)
exit()
if k == 0:
print(sum(H))
exit()
print(sum(H[:-k]))
| 1 | 79,265,290,306,972 | null | 227 | 227 |
N, *XL = map(int, open(0).read().split())
XL = sorted((x + l, x - l) for x, l in zip(*[iter(XL)] * 2))
curr = -float("inf")
ans = 0
for right, left in XL:
if left >= curr:
curr = right
ans += 1
print(ans)
| N=int(input())
robot=[]
for _ in range(N):
x,l=map(int,input().split())
robot.append((x+l,x-l))
robot.sort()
tmp=-10**10
ans=0
for i in range(N):
end,start=robot[i]
if tmp<=start:
tmp=end
ans+=1
print(ans)
| 1 | 89,769,344,910,404 | null | 237 | 237 |
import sys
input = sys.stdin.readline
n = int(input())
print(8 - int((n - 400) / 200))
| x=int(input())
if(x>=400 and x<=599):
print('8')
elif(x>=600 and x<=799):
print('7')
elif(x>=800 and x<=999):
print('6')
elif(x>=1000 and x<=1199):
print('5')
elif(x>=1200 and x<=1399):
print('4')
elif(x>=1400 and x<=1599):
print('3')
elif(x>=1600 and x<=1799):
print('2')
elif(x>=1800 and x<=1999):
print('1')
| 1 | 6,712,279,529,240 | null | 100 | 100 |
m=[0]*50
f=[0]*50
r=[0]*50
result=[""]*50
num=0
while True:
a,b,c=map(int,input().split())
if a == b == c ==-1:
break
else:
m[num],f[num],r[num]=a,b,c
num+=1
for i in range(num):
if m[i] == -1 or f[i]==-1:
result[i]="F"
elif m[i]+f[i]>=80:
result[i]="A"
elif m[i]+f[i]>=65:
result[i]="B"
elif m[i]+f[i]>=50:
result[i]="C"
elif m[i]+f[i]>=30:
if r[i] >=50:
result[i]="C"
else:
result[i]="D"
else:
result[i]="F"
for i in range(num):
print(result[i])
| while True:
m, t, f = map( int, raw_input().split())
if m == -1 and t == -1 and f == -1:
break
if m == -1 or t == -1:
r = "F"
elif (m + t) >= 80:
r = "A"
elif (m + t) >= 65:
r = "B"
elif (m + t) >= 50:
r = "C"
elif (m + t) >= 30:
if f >= 50:
r = "C"
else:
r = "D"
else:
r = "F"
print r | 1 | 1,226,201,226,620 | null | 57 | 57 |
n=int(input())
d,m=divmod(n,500)
print(d*1000+m//5*5) | h,w,k = map(int, input().split())
item = [[0 for _ in range(w)] for _ in range(h)]
for i in range(k):
y,x,v = list(map(int,input().split()))
item[y-1][x-1]=v
dp = [[[0 for _ in range(w)] for _ in range(h)] for _ in range(4)]
for y in range(h):
for x in range(w):
for i in range(4):
if y<h-1:
dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x])
if x<w-1:
dp[i][y][x+1]=max(dp[i][y][x+1],dp[i][y][x])
if item[y][x]>0:
for i in range(3):
if y<h-1:
dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x] + item[y][x])
if x<w-1:
dp[i+1][y][x+1]=max(dp[i+1][y][x+1],dp[i][y][x] + item[y][x])
ans=[dp[0][-1][-1] + item[-1][-1],
dp[1][-1][-1] + item[-1][-1],
dp[2][-1][-1] + item[-1][-1],
dp[3][-1][-1]]
print(max(ans)) | 0 | null | 24,240,769,811,046 | 185 | 94 |
import sys
dic = {}
for i in xrange(97, 123):
dic.setdefault(chr(i), 0)
line = ""
while True:
try:
temp = raw_input()
# print "temp = " + temp
if temp != "":
line += temp
else:
break
except:
break
# print line
for i in xrange(len(line)):
try:
if line[i].lower() in dic:
dic[line[i].lower()] += 1
except TypeError:
continue
# print dic
for i in xrange(97, 123):
print chr(i) + " : " + str(dic[chr(i)]) | import time
start = time.time()
n = int(input())
a = list(map(int,input().split()))
b = []
m = 0
for i in range(1,n):
m = m ^ a[i]
b.append(m)
for j in range(1,n):
m = m ^ a[j-1]
m = m ^ a[j]
b.append(m)
b = map(str,b)
print(' '.join(b)) | 0 | null | 7,041,203,293,878 | 63 | 123 |
import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
n = int(readline().rstrip())
S = [readline().rstrip() for _ in range(n)]
c = collections.Counter(S)
keys = sorted(c.keys())
maxS = c.most_common()[0][1]
for key in keys:
if c[key] == maxS:
print(key)
if __name__ == '__main__':
main()
| import collections
N = int(input())
S = [input() for i in range(N)]
C = collections.Counter(S)
L = C.most_common()
ans = []
flag = 0
for n in range(len(C)):
if L[n][1] < flag:
break
else:
ans.append(L[n][0])
flag = (L[n][1])
ans.sort()
for i in range(len(ans)):
print(ans[i]) | 1 | 70,198,157,372,992 | null | 218 | 218 |
from bisect import bisect_left
import numpy
def main():
def isOK(score):
count = 0
for a in reversed(A):
border_score = score - a
index = bleft(A, border_score)
count += N - index
if count >= M:
return True
return False
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
ans = 0
ng = A[-1] + A[-1] + 1
ok = A[0] + A[0]
bleft = bisect_left
while(abs(ok-ng) > 1):
#print(ok, ng)
mid = (ok+ng) // 2
f = isOK(mid)
if f:
ok = mid
else:
ng = mid
#print(f)
#print(ok, ng)
C = [0,] + A
C = numpy.cumsum(C[::-1])
#print(C)
min_score = float('inf')
count = 0
for a in reversed(A):
index = bleft(A, ok-a)
if index < N:
min_score = min(a+A[index], min_score)
ans += C[N-index-1] + (N-index) * a
count += N-index
ans -= min_score * (count-M)
print(ans)
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
from bisect import bisect, bisect_left
from itertools import accumulate
def main():
def check(x):
count = 0
for a in aaa:
if x <= a:
count += n
else:
count += n - bisect_left(aaa, x - a)
return count >= m
n, m = map(int, input().split())
aaa = list(map(int, input().split()))
aaa.sort()
acc = [0] + list(accumulate(aaa))
sum_a = acc[-1]
l, r = 0, 200001
while l + 1 < r:
mid = (l + r) // 2
if check(mid):
l = mid
else:
r = mid
# 合計がlより大きい組み合わせの和と組数を求める→Mに足りない分だけ合計がlの組を採用
ans = 0
count = 0
for a in aaa:
if l <= a:
ans += sum_a + a * n
count += n
else:
omit = bisect(aaa, l - a)
if omit < n:
ans += sum_a - acc[omit] + a * (n - omit)
count += n - omit
ans += l * (m - count)
print(ans)
if __name__ == '__main__':
main() | 1 | 107,733,368,541,262 | null | 252 | 252 |
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
from math import gcd
def main(given=sys.stdin.readline):
input = lambda: given().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
XLMIIS = lambda x: [LMIIS() for _ in range(x)]
YN = lambda c : print('Yes') if c else print('No')
MOD = 10**9+7
A,B = LMIIS()
print(A*B//gcd(A,B))
if __name__ == '__main__':
main() | import fractions
from functools import reduce
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
A,B=list(map(int,input().split()))
print(lcm_list([A,B])) | 1 | 113,255,063,961,820 | null | 256 | 256 |
k=map(int, raw_input().split())
a=k[0]
b=k[1]
c=k[2]
count=0
for i in range(a,b+1):
if c%i==0:
count=count+1
print count | def table_composition(N):
table = []
i = 1
while i <= N/2:
if N%i == 0:
table.append(i)
i += 1
table.append(N)
return table
a, b, c = map(int, input().split())
table = table_composition(c)
count = 0
for ele in table:
if ele >= a and ele <= b:
count += 1
print(count) | 1 | 554,521,160,088 | null | 44 | 44 |
#!/usr/bin/env python3
T = list(input())
cnt = 0
for i in range(len(T)):
if T[i] == '?':
T[i] = 'D'
print(''.join(T))
| n = int(input())
y = 1
while y <= n :
if(y % 3 == 0):
print(' %d'%y,end='')
else:
p = y
while(p != 0):
if(p % 10 == 3):
print(' %d'%y,end='')
break
p //= 10
y+=1
print()
| 0 | null | 9,629,422,780,516 | 140 | 52 |
import math
base = 100000
r = 0.05
n = int(raw_input())
if n <= 100:
for i in range(1, n+1):
base = base + (base * r)
now = int(math.ceil(base / 1000))
base = now * 1000
print "{}".format(base) | a=raw_input()
debt = 100000
for i in range(int(a)):
debt += debt/20
b=debt%1000
if b > 0:
debt += 1000-b
print debt | 1 | 1,302,956,050 | null | 6 | 6 |
n,m = map(int,input().split())
C = sorted(map(int,input().split()))
T = [float("inf")]*(n+1)
T[0]= 0
for i in range(m):
for j in range(C[i],n+1):
T[j] = min(T[j],T[j-C[i]]+1)
print(T[n]) | n, k = map(int,input().split())
lst = list(map(int,input().split()))
ans = 0
for i in range(n):
if (lst[i] >= k):
ans = ans + 1
print(ans) | 0 | null | 89,445,382,959,200 | 28 | 298 |
x,y = map(int, input().split())
ans = 0
dic = {1:300000, 2:200000, 3:100000}
if x in dic:
ans = dic[x]
if y in dic:
ans += dic[y]
if x==1 and y==1:
ans += 400000
print(ans) | # import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math
import sys
# import numpy as np
ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
x, y = list(map(int,ipti().split()))
prize = [300000, 200000, 100000, 0]
if x == y == 1:
print(1000000)
else:
x = 4 if x > 3 else x
y = 4 if y > 3 else y
print(prize[x-1]+prize[y-1])
if __name__ == '__main__':
main() | 1 | 140,634,518,311,300 | null | 275 | 275 |
n=int(input())
suit = ["S","H","C","D"]
card = {i:[] for i in suit}
for i in range(n):
tmp = ([c for c in input().split()])
card[tmp[0]].append(tmp[1])
for i in suit:
for j in range(1,14):
if not (str(j) in card[i]):
print("%s %s" % (i,j)) | n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(1,len(a)):
height_step = a[i] - a[i-1]
if height_step < 0:
ans -= height_step
a[i] = a[i-1]
print(ans) | 0 | null | 2,775,014,147,428 | 54 | 88 |
A,B=input().split()
A=int(A)
B=int(100*float(B)+0.5)
print(A*B//100)
| num_lis = list(map(int,input().split()))
amount = sum(num_lis)
if amount >= 22:
print("bust")
else:
print("win") | 0 | null | 67,606,976,174,192 | 135 | 260 |
import sys
for l in sys.stdin:
x,y=map(int, l.split())
m=x*y
while x%y:x,y=y,x%y
print "%d %d"%(y,m/y) | x=int(input())
yo=100
n=0
while x>yo:
yo+=yo//100
n+=1
print(n) | 0 | null | 13,645,448,308,934 | 5 | 159 |
import numpy as np
N = int(input())
def divisor(N):
x = np.arange(1, int(N**(1/2))+1, dtype=np.int64)
div = set(x[N % x == 0])
return div | set(N // x for x in div)
cand = divisor(N) | divisor(N - 1)
def test(N, K):
if K == 1:
return False
while N % K == 0:
N //= K
return N % K == 1
answer = sum(test(N, d) for d in cand)
print(answer) | #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from functools import reduce, lru_cache
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy
sys.setrecursionlimit(1000000)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
def divisors(N):
divs = set([1, N])
i = 2
while i ** 2 <= N:
if N % i == 0:
divs.add(i)
divs.add(N//i)
i += 1
return sorted(list(divs))
def is_ok(N, K):
if K <= 1:
return False
while N % K == 0:
N //= K
return N % K == 1
def main():
N = I()
ans = 0
for divisor in divisors(N-1):
if is_ok(N, divisor):
ans += 1
for divisor in divisors(N):
if is_ok(N, divisor):
ans += 1
print(ans)
if __name__ == '__main__':
main() | 1 | 41,421,975,135,180 | null | 183 | 183 |
h,n = map(int,input().split())
arr=list(map(int,input().split()))
print("No" if h>sum(arr) else "Yes") | h,n= map(int, input().split())
a = list(map(int,input().split()))
for i in range(n):
h -= a[i]
print("Yes" if h <=0 else "No") | 1 | 77,837,536,741,004 | null | 226 | 226 |
H,W,M=map(int,input().split())
HSum=[0 for _ in range(H)]
WSum=[0 for _ in range(W)]
bombs = set()
for _ in range(M):
hi,wi = map(lambda x:int(x)-1,input().split())
HSum[hi] += 1
WSum[wi] += 1
bombs.add( (hi,wi) )
# print(HSum)
# print(WSum)
curMax = 0
## 計算量多すぎ。。
# for h in range(H):
# for w in range(W):
# tmp = HSum[h] + WSum[w]
# if curMax <= tmp:
# if (h,w) in bombs:
# tmp -= 1
# curMax = max( curMax, tmp )
hMax = max(HSum)
wMax = max(WSum)
tmpMax = hMax + wMax
ans = 0
hSumMaxOnly = [h for h, x in enumerate(HSum) if x == hMax]
wSumMaxOnly = [w for w, y in enumerate(WSum) if y == wMax]
for h in hSumMaxOnly:
if ans == tmpMax:
break
for w in wSumMaxOnly:
if (h,w) in bombs:
ans = tmpMax - 1
else:
ans = tmpMax
break
print(ans)
| from collections import defaultdict
h, w, m = map(int, input().split())
target = []
point = defaultdict(int)
count_target_of_y = defaultdict(int)
count_target_of_x = defaultdict(int)
for i in range(m):
x, y = map(int, input().split())
count_target_of_y[y] += 1
count_target_of_x[x] += 1
point[(x,y)] += 1
max_x_count = max(list(count_target_of_x.items()), key=lambda x:x[1])[1]
max_y_count = max(list(count_target_of_y.items()), key=lambda x:x[1])[1]
max_x_count_list = [i for i in count_target_of_x.items() if i[1] == max_x_count]
max_y_count_list = [i for i in count_target_of_y.items() if i[1] == max_y_count]
for x in max_x_count_list:
for y in max_y_count_list:
if point[(x[0], y[0])] == 0:
print(max_x_count + max_y_count)
exit()
print(max_x_count + max_y_count - 1)
| 1 | 4,714,686,883,688 | null | 89 | 89 |
S = list(input())
NS = [s for s in S]
K = int(input())
L = len(S)
if "".join(S) == S[0] * L:
print(L * K // 2)
exit()
ans = 0
for i in range(L-1):
f_s = S[i]
s_s = S[i+1]
if f_s == s_s:
S[i+1] = '-'
ans += 1
# 先頭と末尾が異なる
if S[0] != S[-1]:
ans *= K
# 一緒
else:
a = 0
for i in range(L):
if NS[i] == NS[0]:
a += 1
else:
break
b = 0
for i in range(L)[::-1]:
if NS[i] == NS[-1]:
b += 1
else:
break
ans *= K
#t = (- (-a // 2)) + (- (-b // 2)) - (- (-a-b) // 2)
#t = -(-a // 2) - (-b // 2) + (-(a+b) // 2)
t = a // 2 + b // 2 - (a+b) // 2
ans -= t * (K-1)
print(ans)
| S = input()
K = int(input())
if len(set(S)) == 1:
print(len(S)*K//2)
else:
i, count1 = 1, 0
while i < len(S):
if S[i] == S[i-1]:
count1 += 1
i += 2
else:
i += 1
ss = S*2
i, count2 = 1, 0
while i < len(ss):
if ss[i] == ss[i-1]:
count2 += 1
i += 2
else:
i += 1
print(count1+(count2-count1)*(K-1))
| 1 | 175,808,932,619,804 | null | 296 | 296 |
a, b = map(int, input().split())
print("{} {} {:.12f}".format(a // b, a % b, a * 1.0 / b)) | from math import sqrt
N = int(input())
X = []
Y = []
for i in range(N):
x, y = map(int, input().split())
X.append(x)
Y.append(y)
ans = 0
for i in range(0, N-1):
for j in range(i+1, N):
ans += sqrt((X[i] - X[j]) ** 2 + (Y[i] - Y[j]) ** 2)
print(ans * 2.0 / N) | 0 | null | 74,139,241,204,710 | 45 | 280 |
if __name__ == "__main__":
while True:
a,op,b = map(str,input().split())
if op is "+":
print("%d"%(int(a)+int(b)))
elif op is "-":
print("%d"%(int(a)-int(b)))
elif op is "*":
print("%d"%(int(a)*int(b)))
elif op is "/":
print("%d"%(int(a)/int(b)))
else:
break | s = str(input())
n = len(s)
dp = [[0]*2 for _ in range(n+1)]
dp[0][1] = 1
for i in range(n):
p = int(s[i])
dp[i+1][0] = min(dp[i][1]+10-p,dp[i][0]+p)
dp[i+1][1] = min(dp[i][1]+10-p-1,dp[i][0]+p+1)
print(dp[-1][0]) | 0 | null | 35,778,938,198,990 | 47 | 219 |
import sys
def main():
input = sys.stdin.readline
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
a.sort(reverse=True)
f.sort()
l, r = -1, pow(10, 12)+1
while r-l > 1:
judge = (r+l)//2
sub = 0
for i in range(n):
if a[i]*f[i] <= judge:
continue
sub += a[i]-judge//f[i]
if sub <= k:
r = judge
else:
l = judge
print(r)
if __name__ == "__main__":
main() | m = 2000003
def MyHash(k,i):
return (k%m+i*(1+(k%m)))%m
def main():
n = input()
T = ['']*2000003
O = []
for i in range(n):
c, k = raw_input().split()
i = 0
if c == 'insert':
k_hashed = hash(k)
while True:
j = MyHash(k_hashed,i)
if T[j] == '':
T[j] = k
break
else:
i += 1
else:
O.append(search(T,k))
for item in O:
print item
return 0
def search(T,k):
k_hashed = hash(k)
i = 0
while True:
j = MyHash(k_hashed,i)
if T[j] == k:
o = 'yes'
break
elif T[j] == '':
o = 'no'
break
else:
i += 1
return o
if __name__ == "__main__":
main() | 0 | null | 82,305,334,757,050 | 290 | 23 |
nums = [int(e) for e in input().split()]
if nums[0]<nums[1]:
print("a < b")
elif nums[0]>nums[1]:
print("a > b")
else:
print("a == b")
| input_line = input()
a,b = input_line.strip().split(' ')
a = int(a)
b = int(b)
if a < b:
print("a < b")
elif a > b:
print("a > b")
elif a == b:
print("a == b") | 1 | 351,241,721,600 | null | 38 | 38 |
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())
r =[0]*100001
s=[0]*100001
p=[0]*100001
for i in range(N):
if T[i]=='r':
r[i]=1
if i>=K:
if r[i-K]==1:
r[i]=0
elif T[i] =='s':
s[i]=1
if i>=K:
if s[i-K]==1:
s[i]=0
elif T[i]=='p':
p[i]=1
if i>=K:
if p[i-K]==1:
p[i]=0
count=0
for i in range(N):
if r[i]==1:
count+=P
elif s[i]==1:
count+=R
elif p[i]==1:
count+=S
print(count)
| n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = input()
last = ["" for _ in range(k)]
move = {"r": "p", "p": "s", "s": "r"}
pts = {"r": r, "p": p, "s": s}
score = 0
for i in range(n):
if move[t[i]] != last[i%k]:
score += pts[move[t[i]]]
last[i%k] = move[t[i]]
else:
last[i%k] = ""
print(score) | 1 | 106,782,026,482,310 | null | 251 | 251 |
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
answer = (N+1) // 2
print(answer)
| n= int(input())
if n%2==0:
print(int(n*0.5))
else:
print(int(0.5*n)+1) | 1 | 58,972,898,248,860 | null | 206 | 206 |
class DP:
def __init__(self, value, variety, coins):
self.value = value
self.variety = variety
self.coins = coins
self.DP = [[0 for _ in range(value + 1)] for _ in range(variety)]
self.DPinit()
def monitor(self):
for (i, row) in enumerate(self.DP):
print(coins[i], row)
def DPinit(self):
for row in self.DP:
row[1] = 1
self.DP[0] = [i for i in range(self.value + 1)]
def DPcomp(self):
for m in range(self.variety):
if m == 0:
continue
for n in range(self.value + 1):
self.DP[m][n] = self.numberOfCoin(m, n)
def numberOfCoin(self, m, n):
if n >= self.coins[m]:
return min(self.DP[m - 1][n], self.DP[m][n - self.coins[m]] + 1)
else:
return self.DP[m - 1][n]
def answer(self):
self.DPcomp()
return self.DP[self.variety - 1][self.value]
if __name__ == "__main__":
status = list(map(int,input().split()))
coins = list(map(int,input().split()))
dp = DP(status[0],status[1],coins)
print(dp.answer()) |
def main():
n,x,m = map(int,input().split())
a = [0] * m
b = [x]
ans = x
i = 1
while i < n:
x = (x*x) % m
if x == 0:
print(ans)
exit()
if a[x] == 0:
a[x] = i
b.append(x)
ans += x
i += 1
else :
q = len(b) - a[x]
qq = (n-len(b)) // q
qqq = (n-len(b)) % q
ans += sum(b[a[x]:]) * qq
ans += sum(b[a[x]:a[x]+qqq])
#print(b + b[a:] * qq + b[a:a+qqq])
print(ans)
exit()
print(ans)
if __name__ == '__main__':
main() | 0 | null | 1,463,240,211,072 | 28 | 75 |
def main():
N, P = (int(i) for i in input().split())
L = [int(s) for s in input()][::-1]
ans = 0
if P == 2 or P == 5:
for i, e in enumerate(L):
if e % P == 0:
ans += N-i
else:
A = [0]*N
d = 1
for i, e in enumerate(L):
A[i] = (e*d) % P
d *= 10
d %= P
S = [0]*(N+1)
for i in range(N):
S[i+1] = S[i] + A[i]
S[i+1] %= P
from collections import Counter
c = Counter(S)
for v in c.values():
ans += v*(v-1)//2
print(ans)
if __name__ == '__main__':
main()
| import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
if debugmode:
print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 998244353
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True
n2 = [1 for _ in range(3010)]
for i in range(1, 3010):
n2[i] = n2[i - 1] * 2 % mod
n, s = MAP()
a = LIST()
dp = [[0 for _ in range(s + 1)] for _ in range(n)]
if s >= a[0]:
dp[0][a[0]] = 1
for i in range(1, n):
for j in range(1, min(s + 1, a[i])):
dp[i][j] = dp[i - 1][j] * 2
dp[i][j] %= mod
if a[i] <= s:
dp[i][a[i]] = dp[i - 1][a[i]] * 2 + n2[i]
dp[i][a[i]] %= mod
for j in range(a[i] + 1, s + 1):
dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i]]
dp[i][j] %= mod
print(dp[n - 1][s])
| 0 | null | 37,876,593,901,222 | 205 | 138 |
# B 1%
import math
X = int(input())
Y = 100
cnt = 0
while Y < X:
cnt += 1
# Y = math.floor(Y*1.01)
Y = Y + Y//100
print(cnt) | x = int(input())
taka = 100
count = 0
while taka < x:
taka = taka * 101 // 100
count += 1
print(count)
| 1 | 27,136,270,560,718 | null | 159 | 159 |
N = int(input())
if N%2==1:
ans = 0
else:
n = N//10
ans = n
k = 1
while 5**k<=n:
ans += n//(5**k)
k += 1
print(ans) | import sys
input = sys.stdin.readline
n = int(input())
a = 0
if n % 2 == 1:
a == 0
else:
n = n // 2
k = 5
while k <= n:
a += n // k
k *= 5
print(a) | 1 | 116,065,127,627,680 | null | 258 | 258 |
if __name__ == "__main__":
n, m = map(int, raw_input().split())
b = [0] * m
A = [0] * m * n
for i in xrange(n):
A[i*m:i*m+m] = map( int, raw_input().split())
for i in xrange(m):
b[i] = int(raw_input())
c = [0] * n
for i in xrange(n):
for j in xrange(m):
c[i] += A[i*m + j] * b[j]
for i in xrange(n):
print c[i] | s = input()
print(int(s)*int(s)) | 0 | null | 72,826,707,308,400 | 56 | 278 |
l=raw_input()
k=l.split()
a=0.0
b=0.0
a=int(k[0])
b=int(k[1])
#
print int((a-(a%b))/b),
print int(a%b),
a*=1.0
b*=1.0
if b==1:
print a*1.0
else:
if a/b>0.0000002:
print a/b
else: print "0.00000001.99999982" | a, b = map(int, input().split())
# a/bだとeやらEやら(名称忘れた)も出力されてしまうので小数点以下をフォーマットした
print(a//b, a % b, format(a/b, '.10f'))
| 1 | 608,150,223,408 | null | 45 | 45 |
D = list(input())
ans = 0
cnt = 0
for i in D:
if i == 'R':
cnt += 1
else:
cnt = 0
if ans < cnt:
ans = cnt
print(ans) | N=int(input())
w =0
x =0
y =0
z =0
for i in range(N):
s =input()
if s =='AC':
w +=1
elif s == 'WA':
x +=1
elif s == 'TLE':
y +=1
elif s == 'RE':
z +=1
print ('AC x '+str(w))
print ('WA x '+str(x))
print ('TLE x '+str(y))
print ('RE x '+str(z)) | 0 | null | 6,741,068,838,628 | 90 | 109 |
s = input()
k = int(input())
if len(set(s)) == 1:
print(len(s)*k//2)
exit()
l = head = 0
now = s[0]
for i in range(len(s)):
if s[i] == now:
head += 1
else:
l = i
break
r = tail = 0
now = s[-1]
for i in range(len(s))[::-1]:
if s[i] == now:
tail += 1
else:
r = i+1
break
ans = 0
cnt = 0
now = s[l]
for i in range(l,r):
if s[i] == now:
cnt += 1
else:
ans += cnt//2
cnt = 1
now = s[i]
ans += cnt//2
ans *= k
if s[0] == s[-1]:
ans += (head+tail)//2*(k-1)
ans += head//2+tail//2
else:
ans += (head//2+tail//2)*k
print(ans) | class UnionFind:
def __init__(self, num):
self.parent = [-1] * num
def find(self, node):
if self.parent[node] < 0:
return node
self.parent[node] = self.find(self.parent[node])
return self.parent[node]
def union(self, node1, node2):
node1 = self.find(node1)
node2 = self.find(node2)
if node1 == node2:
return
if self.parent[node1] > self.parent[node2]:
node1, node2 = node2, node1
self.parent[node1] += self.parent[node2]
self.parent[node2] = node1
return
def same(self, node1, node2):
return self.find(node1) == self.find(node2)
def size(self, x):
return -self.parent[self.find(x)]
def roots(self):
return [i for i, x in enumerate(self.parent) if x < 0]
def group_count(self):
return len(self.roots())
n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
uf.union(a, b)
print(uf.group_count() - 1)
| 0 | null | 89,223,768,199,260 | 296 | 70 |
import math
def main():
n, x, t = map(int, input().split())
print(math.ceil(n / x) * t)
if __name__ == '__main__':
main() | a,b,c=map(int, input().split())
#たこ焼きが余るかの場合分け
if a%b==0:
Q=a//b
#ちょうど焼ききる
else:
Q=a//b+1
#余る
print(Q*c)#回数×時間
#完了
| 1 | 4,276,496,132,740 | null | 86 | 86 |
a1, a2, a3 = [int(n) for n in input().split()]
print('bust' if a1+a2+a3 >= 22 else 'win') | s = input()
q = int(input())
for _ in range(q):
line = input().split()
if line[0] == 'print':
print(s[int(line[1]):int(line[2]) + 1])
elif line[0] == 'reverse':
s1 = s[:int(line[1])]
s2 = s[int(line[1]):int(line[2]) + 1]
s2 = s2[::-1]
s3 = s[int(line[2]) + 1::]
s = s1 + s2 + s3
elif line[0] == 'replace':
s1 = s[:int(line[1])]
s2 = s[int(line[2]) + 1:]
s = s1 + line[3] + s2
| 0 | null | 60,161,330,479,940 | 260 | 68 |
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
n, k = map(int, input().split())
P = list(map(lambda x : int(x) - 1, input().split()))
C = list(map(int, input().split()))
# doubling table
nexts = [P]
vals = [C]
totals = [C]
for _ in range(60):
next, val, total = nexts[-1], vals[-1], totals[-1]
nnext, nval, ntotal = [0] * n, [0] * n, [0] * n
for i in range(n):
nnext[i] = next[next[i]]
nval[i] = val[i] + val[next[i]]
ntotal[i] = max(total[i], val[i] + total[next[i]])
nexts.append(nnext)
vals.append(nval)
totals.append(ntotal)
# answer
ans = -INF
for now in range(n):
score = 0
for d in range(59, -1, -1):
if k >> d & 1:
ans = max(ans, score + totals[d][now])
score += vals[d][now]
now = nexts[d][now]
print(ans)
resolve() | n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=[]
for i in range(n):
ct=0
score=0
s=[]
pos=i
while ct<k:
ct+=1
pos=p[pos]-1
score+=c[pos]
s.append(score)
if pos==i:
break
if s[-1]<0:
ans.append(max(s))
elif pos!=i:
ans.append(max(s))
elif k%len(s)==0:
ans.append(s[-1]*(k//len(s)-1)+max(s))
else:
ans.append(max(s[-1]*(k//len(s)-1)+max(s),s[-1]*(k//len(s))+max(s[0:k%len(s)])))
print(max(ans)) | 1 | 5,380,518,197,472 | null | 93 | 93 |
text = input()
q = int(input())
for _ in range(q):
ops = input().split()
if len(ops) == 3:
op, a, b = ops
else:
op, a, b, p = ops
a = int(a)
b = int(b)
if op == 'print':
print(text[a:b+1])
elif op == 'reverse':
text = text[:a] + ''.join(reversed(text[a:b+1])) + text[b + 1:]
else:
text = text[:a] + p + text[b + 1:] |
s = str(input())
q = int(input())
for i in range(q):
arr = list(map(str, input().split()))
c = arr[0]
n1 = int(arr[1])
n2 = int(arr[2])
if c == 'print':
print(s[n1:n2 + 1])
if c == 'replace':
s = s[0:n1] + arr[3] + s[n2 + 1:len(s)]
if c == 'reverse':
l = n2 - n1 + 1
reverse = ''
for i in range(l):
reverse += s[n2 - i]
s = s[0:n1] + reverse + s[n2 + 1:len(s)]
| 1 | 2,105,647,377,468 | null | 68 | 68 |
r, c= map(int, input().split())
list = [list(map(int,input().split())) for i in range(r)]
for i in range(r):
list[i].append(sum(list[i]))
for i in range(r):
for j in range(c):
print(list[i][j], end = ' ')
print(list[i][c])
for i in range(c):
a = 0
for j in range(r):
a += list[j][i]
print(a, end = ' ')
a = 0
for j in range(r):
a += list[j][c]
print(a)
| def main():
r, c = map(int, input().split())
table = []
for _ in range(r):
table.append(list(map(int, input().split())))
table.append([0] * (c+1))
for index, line in enumerate(table[:-1]):
table[index].append(sum(line))
for index1, value in enumerate(table[index]):
table[-1][index1] += value
for line in [map(str, line) for line in table]:
print(' '.join(line))
return
if __name__ == '__main__':
main()
| 1 | 1,369,531,730,112 | null | 59 | 59 |
class MinMaxAndSum:
def output(self, a):
print "%d %d %d" % (min(a), max(a), sum(a))
if __name__ == "__main__":
mms = MinMaxAndSum()
raw_input()
a = map(int, raw_input().split())
mms.output(a) | # -*- coding:utf-8 -*-
import math
def insertion_sort(num_list, length, interval):
cnt = 0
for i in range(interval, length):
v = num_list[i]
j = i - interval
while j >= 0 and num_list[j] > v:
num_list[j+interval] = num_list[j]
j = j - interval
cnt = cnt + 1
num_list[j+interval] = v
return cnt
def shell_sort(num_list, length):
cnt = 0
h = 4
intervals = [1,]
while length > h:
intervals.append(h)
h = 3 * h + 1
for i in reversed(range(len(intervals))):
cnt = cnt + insertion_sort(num_list, length, intervals[i])
print(len(intervals))
print(*reversed(intervals))
print(cnt)
input_num = int(input())
input_list = list()
for i in range(input_num):
input_list.append(int(input()))
shell_sort(input_list, input_num)
for num in input_list:
print(num) | 0 | null | 374,710,547,498 | 48 | 17 |
x='123'
for _ in range(2):
x=x.replace(input(),'')
print(x)
| a=int(input())
b=int(input())
v=[1,2,3]
for i in v:
if a!=i and b!=i:
print(i)
break | 1 | 110,922,163,703,728 | null | 254 | 254 |
while True:
a, op, b = raw_input().split()
if op == '?': break
a, b = int(a), int(b)
if op == '+': print a+b
if op == '-': print a-b
if op == '*': print a*b
if op == '/': print a/b | N = str(input())
K = int(input())
dp = [[[0]*2 for _ in range(K+1)] for _ in range(len(N)+1)]
dp[0][0][0] = 1
for i in range(len(N)):
n = int(N[i])
for j in range(K+1):
for k in range(2): # smaller(未満なら1)
for l in range(10):
nj, nk = j, 0
if k == 0 and l == n:
nk = 0
elif k == 0 and l < n:
nk = 1
elif k == 0 and l > n:
continue
if k == 1:
nk = 1
if l != 0:
if j < K:
nj += 1
else:
continue
dp[i+1][nj][nk] += dp[i][j][k]
print(dp[-1][K][0] + dp[-1][K][1])
| 0 | null | 38,433,422,686,058 | 47 | 224 |
rate = int(input())
print(10 - rate//200) | n = int(input())
dp = [0]*(n+1)
for i in range(1,n+1):
x = n//i
for j in range(1,x+1):
dp[i*j]+=1
sum_div = 0
for i in range(1,n+1):
sum_div += i*dp[i]
print(sum_div) | 0 | null | 8,925,635,913,220 | 100 | 118 |
n = int(input())
for _ in range(n):
edges = sorted([int(i) for i in input().split()])
if edges[0] ** 2 + edges[1] ** 2 == edges[2] ** 2:
print("YES")
else:
print("NO")
| def main():
s = input()
arr = [0]*(len(s)+1)
for i in range(len(s)):
c = s[i]
if c == "<":
arr[i+1] = arr[i]+1
for i in reversed(range(len(s))):
c = s[i]
if c == ">":
arr[i] = max(arr[i], arr[i+1]+1)
print(sum(arr))
if __name__ == "__main__":
main()
| 0 | null | 78,260,096,724,880 | 4 | 285 |
# -*-coding:utf-8
import fileinput
import math
def main():
for line in fileinput.input():
a, b, c = map(int, line.strip().split())
count = 0
for i in range(a, b+1):
if(c % i == 0):
count += 1
print(count)
if __name__ == '__main__':
main() | num = [int(x) for x in input().split() if x.isdigit()]
count = 0
for i in range(num[0], num[1]+1):
if num[2] % i == 0:
count += 1
print(count) | 1 | 558,146,251,712 | null | 44 | 44 |
N, X, M = map(int, input().split())
flag = [False for _ in range(M)]
record = list()
record.append(X)
flag[X] = 1
An = X
for i in range(M + 1):
An = pow(An, 2, M)
if flag[An]:
start = flag[An]
cnt = i + 2 - start
cost = record[-1] - record[start - 2] if start > 1 else record[-1]
break
else:
record.append(An + record[-1])
flag[An] = i + 2
if start >= N:
print(record[N - 1])
else:
print(((N - start) // cnt) * cost
+ record[(N - start) % cnt + start - 1])
| def f(a):
return a * a % m
n, x, m = map(int, input().split())
a = x
i = 1
li = [a]
num2index = {a: 1}
while f(a) not in num2index and i + 1 <= n:
i += 1
a = f(a)
li.append(a)
num2index[a] = i
if i == n:
ans = sum(li)
else:
before_loop = num2index[f(a)]
loop, left = divmod(n - i, i - before_loop + 1)
loop_sm = loop * sum(li[before_loop-1:])
left_sm = sum(li[before_loop-1:before_loop-1+left])
ans = sum(li) + loop_sm + left_sm
print(ans)
| 1 | 2,815,594,190,410 | null | 75 | 75 |
icase=0
if icase==0:
k,x=map(int,input().split())
if 500*k>=x:
print("Yes")
else:
print("No")
| a,b=map(int,input().split())
print("Yes" if (a*500>=b) else "No") | 1 | 98,233,205,688,928 | null | 244 | 244 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
def divide_choco(bit):
divrow_num = bin(bit).count("1") + 1 # 割った回数+1
choco_current = [[0] * w for _ in range(divrow_num)]
row_divided_cur = 0
for col, piece in enumerate(choco[0]):
choco_current[0][col] = piece
for row in range(h - 1):
if bit >> row & 1:
row_divided_cur += 1
for col, piece in enumerate(choco[row + 1]):
choco_current[row_divided_cur][col] += piece
return choco_current, divrow_num
h, w, k = list(map(int, readline().split()))
choco = []
for i in range(h):
choco_in = input()
choco_add = [int(c) for c in choco_in]
choco.append(choco_add)
ans = INF
for bit in range(1 << (h - 1)):
choco_current, divrow_num = divide_choco(bit)
choco_cursum = [0] * divrow_num
is_exceed = False # 超えてる場合True
ans_temp = bin(bit).count("1")
if divrow_num > 1:
for col in range(w):
choco_currow = [choco_current[dr][col] for dr in range(divrow_num)]
for drow, pieces in enumerate(choco_currow):
if pieces > k:
ans_temp += INF
elif choco_cursum[drow] + pieces > k:
is_exceed = True
if is_exceed:
choco_cursum = [cc for cc in choco_currow]
ans_temp += 1
is_exceed = False
else:
choco_cursum = [cc + cs for cc, cs in zip(choco_currow, choco_cursum)]
else:
choco_cursum = 0
for pieces in choco_current[0]:
if pieces > k:
ans_temp += INF
elif choco_cursum + pieces > k:
choco_cursum = pieces
ans_temp += 1
else:
choco_cursum = choco_cursum + pieces
ans = min(ans, ans_temp)
print(ans)
if __name__ == '__main__':
main() | import sys
input = sys.stdin.readline
N = int(input())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
a = make_divisors(N)
b = make_divisors(N - 1)
s = set(a + b)
res = 0
for x in s:
if x == 1: continue
t = N + 0
while t % x == 0: t //= x
res += (t % x == 1)
print(res) | 0 | null | 44,998,941,873,388 | 193 | 183 |
s,t = input().split()
a,b = map(int,input().split())
A = input()
if A == s:print(a-1,b)
else:print(a,b-1) | n = int(input())
j_list = [input() for x in range(n)]
print("AC x",j_list.count("AC"))
print("WA x",j_list.count("WA"))
print("TLE x",j_list.count("TLE"))
print("RE x",j_list.count("RE")) | 0 | null | 40,296,044,572,880 | 220 | 109 |
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
@njit((i8, i8, i8, i8[:,:]), cache=True)
def solve(R,C,K,item):
dp = np.zeros((C+1,5), dtype=np.int64)
for i in range(1,R+1):
new_dp = np.zeros((C+1,5), dtype=np.int64)
#上からアイテムを取らずに移動
new_dp[:,0] = dp[:,-1]
#上からアイテムを取って移動
new_dp[1:,1] = np.maximum(new_dp[1:,1],dp[1:,-1]+item[i-1])
for j in range(1,C+1):
#横からアイテムを取らずに移動
new_dp[j] = np.maximum(new_dp[j],new_dp[j-1])
#横からアイテムを取って移動
for k in range(1,4):
new_dp[j,k] = max(new_dp[j,k],new_dp[j-1,k-1]+item[i-1,j-1])
for k in range(4):
new_dp[:,-1] = np.maximum(new_dp[:,-1],new_dp[:,k])
dp = new_dp
ans = dp[-1,-1]
return ans
R, C, K = map(int, input().split())
item = np.zeros((R,C), dtype=np.int64)
for i in range(K):
r,c,v = map(int, input().split())
item[r-1,c-1] = v
print(solve(R,C,K,item)) |
r, c, k = map(int, input().split())
v = [[0 for _ in range(c)] for _ in range(r)]
for _ in range(k):
ri, ci, vi = map(int, input().split())
v[ri - 1][ci - 1] = vi
dp = [[0, 0, 0, 0] for _ in range(c)]
for i in range(r):
for j in range(c):
dpj = dp[j][:]
if j == 0:
dp[j] = [max(dpj), max(dpj) + v[i][j], 0, 0]
else:
dp[j][0] = max(max(dpj), dp[j - 1][0])
dp[j][1] = dp[j - 1][1]
dp[j][2] = dp[j - 1][2]
dp[j][3] = dp[j - 1][3]
if v[i][j] > 0:
dp[j][1] = max(dp[j][1], dp[j - 1][0] + v[i][j], max(dpj) + v[i][j])
dp[j][2] = max(dp[j][2], dp[j - 1][1] + v[i][j])
dp[j][3] = max(dp[j][3], dp[j - 1][2] + v[i][j])
print(max(dp[c - 1]))
| 1 | 5,531,688,523,218 | null | 94 | 94 |
N = int(input())
D = N % 10
if D in [2, 4, 5, 7, 9]:
print("hon")
if D in [0, 1, 6, 8]:
print("pon")
if D == 3:
print("bon") | # -*- coding: utf-8 -*-
"""
Created on Fri Aug 7 01:24:25 2020
@author: saito
"""
# %% import phase
# %% define phase
# %% input phase
N = int(input())
# %% process phase
answer = 1000-((N-1)%1000+1)
# %%output phase
print(answer) | 0 | null | 13,898,520,979,710 | 142 | 108 |
def cin(): return list(map(int,input().split()))
a, b, c = cin()
res1 = 4 * a * b
res2 = (c - a - b) ** 2
if c - a - b <= 0: print("No")
else:
if res1 < res2: print("Yes")
else: print("No") | a,b,c= map(int,input().split())
if c>a+b and 4*a*b<(c-a-b)*(c-a-b):
print('Yes')
else:
print('No') | 1 | 51,457,356,696,630 | null | 197 | 197 |
x=int(input())
for i in range(int(x**.5),0,-1):
if x%i==0: break
print(i+x//i-2) | int = int(input())
print(int*int) | 0 | null | 153,445,727,916,778 | 288 | 278 |
n = int(input())
a = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(int)
ans=1
for num in a:
if num==0:
last_cnt=3
tmp = last_cnt - d[num]
else:
last_cnt=d[num-1]
tmp = last_cnt - d[num]
if tmp == 0:
# tmp=1
ans=0
ans*=tmp
ans%=1000000007
d[num]+=1
print(ans) | p = 1000000007
n = int(input())
A = list(map(int, input().split()))
ans = 1
cnt = [3 if i == 0 else 0 for i in range(n+1)]
for a in A:
ans *= cnt[a]
ans %= p
cnt[a] -= 1
cnt[a+1] += 1
print(ans) | 1 | 130,002,417,127,710 | null | 268 | 268 |
#! python3
a, b = [int(x) for x in input().strip().split(' ')]
if a > b:
print('a > b')
elif a < b:
print('a < b')
else:
print('a == b') | inArray = str(input()).split(" ")
if int(inArray[0]) < int(inArray[-1]):
print("a < b")
elif int(inArray[0]) > int(inArray[-1]):
print("a > b")
else:
print("a == b")
| 1 | 363,712,839,858 | null | 38 | 38 |
N = int(input())
A = list(map(int,input().split()))
#A.reverse()
ans = [0 for _ in range(N)]
for i in reversed(range(N-1)):
#今i番目(0index)の社員
boss = A[i]-1 #0index
ans[boss] += 1
#print(ans,i,boss)
for x in ans:
print(x) | while 1:
x, y = map(int, raw_input().split())
if x == 0 and y == 0:
break
print min(x, y),
print max(x, y) | 0 | null | 16,542,401,236,360 | 169 | 43 |
import sys
from math import sqrt
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int
nl = lambda: list(map(int, readline().split())) # input multiple int to list
a, b, c = nm()
if 4*a*b < (c-a-b)**2 and c-a-b>0:
print('Yes')
else:
print('No') | import math
r = float(input())
m = r ** 2 * math.pi
l = r * 2 * math.pi
print('{:.6f} {:.6f}'.format(m, l)) | 0 | null | 25,972,296,453,760 | 197 | 46 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce
n,k = list(map(int, input().split()))
a = n*(n+k+1)*(n-k+2)//2
b = n-k+2
c = -((n+2)*(n+1)*n - k*(k-1)*(k-2))//3
print((a+b+c) % (10**9+7)) | N,K = list(map(int, input().split()))
mod = int(1e9+7)
# N+1からK個をとる手法
# だけどmin - maxまで一飛ばしで作れるはずなので引き算でもとめてよい
ans = 0
for i in range(K,N+2):
ans = (ans + i * (N+1-i) + 1) % mod
print(ans) | 1 | 33,132,194,064,160 | null | 170 | 170 |
#6回目、2020-0612
#2重ループ +O(1)
#場合分けを近道と通常のみ(絶対値を使う)
#初期入力
N, x, y = map(int, input().split())
normal =0
short =0
ans ={i:0 for i in range(1,N)}
for i in range(1,N):
for j in range(i+1,N+1):
normal =j -i
short =abs(x-i) +1 +abs(j-y)
dist =min(normal,short)
ans[dist] +=1
#答え出力
for i in range(1,N):
print(ans[i]) | 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,151,787,334,620 | null | 187 | 187 |
n, m = map(int, input().split())
A = [[int(e) for e in input().split()] for i in range(n)]
b = []
for i in range(m):
e = int(input())
b.append(e)
for i in range(n):
p = 0
for j in range(m):
p += A[i][j] * b[j]
print(p) | from math import floor, ceil
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
l = 0
r = max(a)
while r - l > 1:
c = (l+r)//2
cnt = 0
for i in a:
cnt += max(ceil(i/c) - 1, 0)
if cnt <= k:
r = c
else:
l = c
print(r) | 0 | null | 3,831,785,694,820 | 56 | 99 |
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
sum = 0
for i in range(M):
sum = sum + A[i]
if N > sum:
print(N - sum)
elif N == sum:
print(0)
else:
print(-1) | n,m = map(int,input().split())
A = list(map(int,input().split()))
if (sum(A) <= n):
print(n - sum(A))
else:
print("-1") | 1 | 31,933,742,688,770 | null | 168 | 168 |
n, m = map(int, input().split())
s = list(str(input()))
s = list(reversed(s))
#print(s)
ds = []
d = 1
for i in range(1, n+1):
if s[i] == '0':
ds.append(d)
d = 1
else:
d += 1
#print(ds)
temp0 = 0
ans = []
for i in range(len(ds)):
if ds[i] > m:
print(-1)
exit()
temp1 = temp0 + ds[i]
#print(temp1)
if temp1 > m:
ans.append(temp0)
temp0 = ds[i]
elif temp1 == m:
ans.append(temp1)
temp0 = 0
else:
temp0 = temp1
else:
if temp0 != 0:
ans.append(temp0)
ans = list(reversed(ans))
print(*ans) | #!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations_with_replacement, compress
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
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 LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
def main():
N, M, Q = LI()
abcd = [LI() for _ in range(Q)]
ans = 0
for A in combinations_with_replacement(range(1, M + 1), N):
tmp = 0
for (a, b, c, d) in abcd:
tmp += d if (A[b-1] - A[a-1] == c) else 0
ans = max(ans, tmp)
print(ans)
main() | 0 | null | 83,577,970,494,240 | 274 | 160 |
N = int(input())
S = input()
ris = [i for i, s in enumerate(S) if s == "R"]
gis = [i for i, s in enumerate(S) if s == "G"]
bis = [i for i, s in enumerate(S) if s == "B"]
all = len(ris) * len(gis) * len(bis)
cnt = 0
for i in range(N):
for j in range(i+1, N):
k = 2*j - i
if 0 <= k < N:
if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
cnt += 1
ans = all - cnt
print(ans)
| s, t = map(str, input().split())
x = t + s
print(x) | 0 | null | 69,181,887,652,680 | 175 | 248 |
def main():
print(input().swapcase())
if __name__ == '__main__':
main()
| n = input()
print(n.swapcase())
| 1 | 1,501,132,827,650 | null | 61 | 61 |
n = int(input())
s = list(input())
s = [ord(i)-97 for i in s]
dic = {}
for i in range(26):
dic[i] = []
for i in range(n):
dic[s[i]].append(i)
for i in range(26):
dic[i].append(float('inf'))
from bisect import bisect_left
q = int(input())
for i in range(q):
x, y, z = input().split()
if x == '1':
y, z = int(y) - 1, ord(z) - 97
p = bisect_left(dic[s[y]], y)
dic[s[y]].pop(p)
dic[z].insert(bisect_left(dic[z], y), y)
s[y] = z
else:
res = 0
y, z = int(y) - 1, int(z) - 1
for i in range(26):
p = dic[i][bisect_left(dic[i], y)]
if p <= z:
res += 1
print(res) | N = int(input())
S = list(input())
Q = int(input())
class Bit:
"""1-indexed"""
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
en2asc = lambda s: ord(s) - 97
Bits = [Bit(N) for _ in range(26)]
for i, s in enumerate(S):
Bits[en2asc(s)].add(i + 1, 1)
for _ in range(Q):
q = input().split()
if q[0] == '1':
i, c = int(q[1]), q[2]
old = S[i - 1]
Bits[en2asc(old)].add(i, -1)
Bits[en2asc(c)].add(i, 1)
S[i - 1] = c
else:
l, r = int(q[1]), int(q[2])
ans = 0
for b in Bits:
ans += bool(b.sum(r) - b.sum(l - 1))
print(ans)
| 1 | 62,377,893,151,830 | null | 210 | 210 |
H, W, K = map(int, input().split())
m = []
for h in range(H):
m.append(list(map(int, list(input()))))
ans = float('inf')
for hb in range(2**(H-1)):
hl = []
for i in range(H-1):
if hb & (1 << i) > 0:
hl.append(i+1)
t = len(hl)
hl = [0]+hl+[H]
w, pw = 0, 0
wl = [0]*len(hl)
while w < W:
ok = True
for i in range(len(hl)-1):
sh, eh = hl[i], hl[i+1]
for h in range(sh, eh):
wl[i] += m[h][w]
if wl[i] > K:
ok = False
break
if not ok:
break
if not ok:
if pw == w:
t = float('inf')
break
pw, w = w, w
t += 1
wl = [0]*len(hl)
else:
w += 1
ans = min(t, ans)
print(ans)
| s = input()
prev = s[0]
for i in range(1, 3):
if s[i] != prev:
print('Yes')
break
else:
print('No')
| 0 | null | 51,806,011,593,700 | 193 | 201 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
N=I()
L=[]
R=[]
for i in range(N):
a,b=MI()
L.append(a)
R.append(b)
L.sort()
R.sort()
#中央値の最小値は,Lの中央値.中央値の最大値はRの中央値
#間は全部埋められそう?
if N%2==0:
Lm=(L[N//2]+L[N//2-1])
Rm=(R[N//2]+R[N//2-1])
else:
Lm=L[N//2]
Rm=R[N//2]
ans=Rm-Lm+1
print(ans)
main()
| i = 0
while True :
x = int(input())
if(x == 0) :
break
else :
i += 1
print("Case ", i, ": ", x, sep = "")
| 0 | null | 8,974,212,291,850 | 137 | 42 |
N = int(input())
ans = set()
def check(N, k):
if k<2:
return False
N //= k
while N:
if (N-1)%k==0:
return True
if N%k:
return False
N //= k
for k in range(1, int(N**0.5)+1):
if (N-1)%k==0:
ans.add(k)
ans.add((N-1)//k)
if N%k==0:
if check(N, k):
ans.add(k)
if check(N, N//k):
ans.add(N//k)
ans.remove(1)
print(len(ans)) | a, b, c = map(int, input().split())
k = int(input())
cnt = 0
while a >= b:
cnt += 1
b *= 2
while b >= c:
cnt += 1
c *= 2
if cnt <= k: print("Yes")
else: print("No") | 0 | null | 23,989,912,700,270 | 183 | 101 |
n,k,s = map(int, input().split())
if s < 10**9:
ans = [s+1] * n
else:
ans = [1]*n
ans[:k] = [s]*k
print(" ".join(map(str,ans))) | S,W=map(int,input().split(" "))
if S>W:
print("safe")
else:
print("unsafe") | 0 | null | 59,872,825,661,638 | 238 | 163 |
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
ans = 0
for i in range(60):
cou = 0
bit = 1 << i
for j in a:
if j & bit:
cou += 1
num1 = cou
num0 = n - num1
ans += ((num1*num0) * bit )%mod
print(ans%mod) | def readinput():
n=int(input())
l=list(map(int,input().split()))
return n,l
def main(n,a):
MOD=10**9+7
hist=[0]*61
bs=[]
for i in range(n):
# s=list(reversed(bin(a[i])[2:]))
# for j in range(len(s)):
# if s[j]=='1':
# hist[j]+=1
# bs.append(s)
s=bin(a[i])[2:]
bs.append(s)
for j in range(len(s)):
if s[j]=='1':
hist[len(s)-j-1]+=1
# j=0
# ai=a[i]
# while ai>0:
# if ai&1==1:
# hist[j]+=1
# ai = ai >> 1
# j+=1
#print(bs)
#print(hist)
sum=0
for i in range(n-1):
s=bs[i]
b=1
for j in range(len(s)):
if s[len(s)-1-j]=='0':
sum=(sum+hist[j]*b)%MOD
else:
sum=(sum+( n-i-hist[j] )*b)%MOD
hist[j]-=1
b*=2
for j in range(len(s),61):
sum=(sum+hist[j]*b)%MOD
b*=2
# b=1
# for j in range(61):
# sum=(sum+( hist[j]*(n-hist[j])*b )%MOD )%MOD
# b*=2
return sum
if __name__=='__main__':
n,l=readinput()
ans=main(n,l)
print(ans)
| 1 | 123,409,634,828,448 | null | 263 | 263 |
t = input('')
tlist = list(t)
for i in range(len(tlist)):
if tlist[i] == '?':
if i==0:
tlist[i] = 'D'
elif i==len(tlist)-1:
tlist[i] = 'D'
else:
if tlist[i-1] == 'P':
if tlist[i+1] == 'P':
tlist[i] = 'D'
elif tlist[i+1] == 'D':
tlist[i] = 'D'
elif tlist[i+1] == '?':
tlist[i] = 'D'
else:
# 1つ前が'D'
if tlist[i+1] == 'P':
tlist[i] = 'D'
elif tlist[i+1] == 'D':
tlist[i] = 'P'
elif tlist[i+1] == '?':
tlist[i] = 'P'
print("".join(tlist)) | import math
def div(x, y): #x>y
A = 1
for i in range(1, int(math.sqrt(x))+1):
if x % i == 0 and y % i == 0:
A = max(A, i)
j = int(x/i)
if x % j == 0 and y % j == 0:
A = max(A, j)
return A
x, y = map(int, input().split(" "))
print(div(x,y))
| 0 | null | 9,245,940,163,584 | 140 | 11 |
# -*- coding: utf-8 -*-
# E
import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline
# 再起回数上限変更
# sys.setrecursionlimit(1000000)
n = int(input())
d1 = [] * n
d2 = [] * n
for i in range(n):
x, y = map(int, input().split())
d1.append(x+y)
d2.append(x-y)
print(max(max(d1) - min(d1), max(d2)-min(d2)))
| n=int(input())
zl,wl=[],[]
for i in range(n):
x,y=map(int,input().split())
z=x+y
w=x-y
zl.append(z)
wl.append(w)
zl.sort()
wl.sort()
print(max(zl[-1]-zl[0],wl[-1]-wl[0])) | 1 | 3,427,753,117,062 | null | 80 | 80 |
a = list(map(int,input().split()))
print(a[0]*a[1] if a[0] <= 9 and a[1] <= 9 else -1) | a,b = input().split()
x = int(a) * b
y = int(b) * a
l = []
l.append(x)
l.append(y)
l = sorted(l)
print(min(l)) | 0 | null | 121,038,102,493,418 | 286 | 232 |
l = int(input())
print(l**3 / 27)
| n = int(input())
a = n//3
b = n%3
if b == 1:
print((a+1/3)**3)
elif b==2:
print((a+2/3)**3)
else:
print(a**3) | 1 | 47,023,387,554,880 | null | 191 | 191 |
import fractions
def c2(a):
ans = 0
while True:
q,r = divmod(a,2)
if r==0:
ans+=1
a = q
else:break
return ans
gcd = fractions.gcd
n,m= map(int,input().split())
A = list(map(lambda x:int(x)//2,input().split()))
A.sort()
ma = 0
cp = c2(A[0])
for i in range(n):
if cp!=c2(A[i]):
print(0)
exit()
lcm = A[0]
for i in range(1,n):
lcm = A[i]*lcm//gcd(A[i],lcm)
print((m//lcm +1)//2)
| from fractions import gcd
from functools import reduce
def l(a,b):return a*b//gcd(a,b)
def L(N):return reduce(l,N)
n,m=map(int,input().split())
A=list(map(lambda x:int(x)//2,input().split()))
a=A[0]
c=0
while(a%2==0):
a//=2
c+=1
if any([(a%(2**c)==0 and a//(2**c))%2==0 for a in A]):
print(0)
exit()
a=L(A)
print((m+a)//(2*a))
| 1 | 101,355,364,006,108 | null | 247 | 247 |
num = int(input())
if 400 <= num and num <= 599:
print("8")
elif num <= 799:
print("7")
elif num <= 999:
print("6")
elif num <= 1199:
print("5")
elif num <= 1399:
print("4")
elif num <= 1599:
print("3")
elif num <= 1799:
print("2")
elif num <= 1999:
print("1") | def ma():
return map(int,input().split())
k,x=ma()
if k*500>=x:
print('Yes')
else:
print('No') | 0 | null | 52,694,809,717,510 | 100 | 244 |
A, B = map(int, input().split())
ans = A*B if max(A,B)<=9 else -1
print(ans) | A,B = map(int,input().split())
if A<=9 and B<=9:print(A*B)
else : print(-1) | 1 | 157,471,436,410,618 | null | 286 | 286 |
"""
入力例 1
11 3 2
ooxxxoxxxoo
->6
入力例 2
5 2 3
ooxoo
->1
->5
入力例 3
5 1 0
ooooo
->
入力例 4
16 4 3
ooxxoxoxxxoxoxxo
->11
->16
"""
n,k,c = map(int,input().split())
s = input()
r=[0]*n
l=[0]*n
ki=0
ci=100000
for i in range(n):
ci += 1
if s[i]=='x':
continue
if ci > c:
ci = 0
ki+=1
l[i]=ki
if ki == k:
break
ki=k
ci=100000
for i in range(n):
ci += 1
if s[n-1-i]=='x':
continue
if ci > c:
ci = 0
r[n-1-i]=ki
ki-=1
if ki == 0:
break
ret=[]
for i in range(n):
if r[i]==l[i] and r[i]!=0:
ret.append(i+1)
# print(l)
# print(r)
for i in range(len(ret)):
print(ret[i])
| H, W = map(int, input().split())
if H == 1 or W == 1:
ans = 1
else:
if H % 2:
if W % 2:
ans = ((H // 2 + 1) * (W // 2 + 1)) + ((H // 2) * (W // 2))
else:
ans = ((H // 2 + 1) + (H // 2)) * (W // 2)
else:
ans = H / 2 * W
print(int(ans))
| 0 | null | 45,470,904,516,420 | 182 | 196 |
import numpy as np
from numba import *
N = int(input())
length = np.array(input().split(), np.int64)
length = np.sort(length)
def calc(length):
cnt = 0
for i in range(N):
for j in range(i + 1, N):
for k in range(j + 1, N):
l1, l2, l3 = length[i], length[j], length[k]
if (l1 != l2 and l1 != l3 and l2 != l3):
if (l1 + l2 > l3):
cnt += 1
return (cnt)
ans = calc(length)
print(ans)
| a = int(input())
if a % 2 is 0:
print(a // 2 - 1)
else:
print(a // 2) | 0 | null | 79,075,523,719,072 | 91 | 283 |
N, K, C = map(int, input().split())
S = input()
def get_positions():
res = []
i = 0
while i < N and len(res) < K:
if S[i] == "o":
res.append(i)
i = i + C + 1
else:
i += 1
return res
l = get_positions()
S = S[::-1]
r = get_positions()
for i in range(K):
r[i] = N - 1 - r[i]
S = S[::-1]
lastl = [-1] * (N + 1)
for i in range(K):
lastl[l[i] + 1] = i
for i in range(N):
if lastl[i + 1] == -1:
lastl[i + 1] = lastl[i]
lastr = [-1] * (N + 1)
for i in range(K):
lastr[r[i]] = i
for i in range(N-1, -1, -1):
if lastr[i] == -1:
lastr[i] = lastr[i + 1]
for i in range(N):
if S[i] == "x":
continue
li = lastl[i]
ri = lastr[i + 1]
cnt = 0
if li != -1:
cnt += (li + 1)
if ri != -1:
cnt += (ri + 1)
if li != -1 and ri != -1 and r[ri] - l[li] <= C:
cnt -= 1
if cnt >= K:
continue
print(i + 1) | n, k, c = [int(i) for i in input().split()]
s = input()
work1 = [0] * k
work2 = [0] * k
cnt = 0
day = 0
while cnt < k:
if s[day] == 'o':
work1[cnt] = day
cnt += 1
day += (c+1)
else:
day += 1
cnt = k-1
day = n-1
while cnt >= 0:
if s[day] == 'o':
work2[cnt] = day
cnt -= 1
day -= (c + 1)
else:
day -= 1
for i in range(k):
if work1[i] == work2[i]:
print(work1[i]+1)
| 1 | 40,431,804,334,350 | null | 182 | 182 |
import itertools, math
N = int(input())
ls, L = [], 0
for i in range(N):
x, y = map(int, input().split(' '))
ls.append([x, y])
perms = itertools.permutations(range(N))
for perm in perms:
for i in range(N - 1):
L += math.sqrt((ls[perm[i + 1]][0] - ls[perm[i]][0]) ** 2 + (ls[perm[i + 1]][1] - ls[perm[i]][1]) ** 2)
print(L / math.factorial(N)) | # coding: utf-8
from math import sqrt
from itertools import permutations
def main():
N = int(input())
ans = 0.0
P = [i for i in range(N)]
C = [list(map(int, input().split())) for _ in range(N)]
for p in permutations(P):
for i in range(N - 1):
ans += sqrt(((C[p[i + 1]][0] - C[p[i]][0]) ** 2) + ((C[p[i + 1]][1] - C[p[i]][1]) ** 2))
for i in range(2, N + 1):
ans /= i
print(ans)
if __name__ == "__main__":
main()
| 1 | 147,890,428,092,642 | null | 280 | 280 |
x,y,z = map(int,input().split())
a,b,c = x,y,z
a,b = b,a
a,c = c,a
print(a,b,c)
| n, k = map(int, input().split())
A = list(map(int, input().split()))
for i in range(k, n):
if A[i-k] < A[i]: print('Yes')
else: print('No') | 0 | null | 22,717,728,782,750 | 178 | 102 |
S = list(input())
countA = 0
countB = 0
for i in range(0, len(S)):
if S[i] == "A":
countA += 1
elif S[i] == "B":
countB += 1
if countA == 3 or countB == 3:
print("No")
else:
print("Yes") | s = input()
print('No' if s.count('A') > 2 or s.count('B') > 2 else 'Yes') | 1 | 54,849,532,661,132 | null | 201 | 201 |
import collections
zzz = 1
nn = int(input())
ans = 0
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
for i in range(1,nn):
zzz = 1
cc = collections.Counter(prime_factorize(i))
hoge = cc.values()
for aaa in hoge:
zzz *= aaa + 1
ans += zzz
print(ans) | from math import sqrt
# Function to return count of Ordered pairs
# whose product are less than N
def countOrderedPairs(N):
# Initialize count to 0
count_pairs = int(0)
# count total pairs
p = int(sqrt(N - 1)) + 1
q = N
# q = int(sqrt(N)) + 2
for i in range(1, p, 1):
for j in range(i, q, 1):
if i * j > N-1:
break
# print(i,j)
count_pairs += 1
#print(count_pairs)
# multiply by 2 to get ordered_pairs
count_pairs *= 2
#print(count_pairs)
# subtract redundant pairs (a, b) where a==b.
count_pairs -= int(sqrt(N - 1))
# return answer
return count_pairs
# Driver code
N = int(input())
print(countOrderedPairs(N))
# ans=prime_factorize(N)
# print(ans) | 1 | 2,580,906,405,180 | null | 73 | 73 |
n = input()
print("No" if n.count("A") == 3 or n.count("B") == 3 else "Yes") | N = input()
K = int(input())
# K = 1の時の組み合わせを求める関数
def func_1(N):
Nm = int(N[0])
return Nm + 9 * (len(N) - 1)
# K = 2の時の組み合わせを求める関数
def func_2(N):
#NはStringなので
#print(N[0])
Nm = int(N[0])
m = len(N)
#if m == 1:
# print("0")
#print((Nm-1)*(m-1)*9)
#print((m - 1) * (m - 2) * 9 * 9 / 2)
x = int(N) - Nm * pow(10, m-1)
#print(x)
#print(1)
#print(func_1(str(x)))
return int((Nm-1)*(m-1)*9+(m-1)*(m-2)*9*9/2+func_1(str(x)))
def func_3(N):
#print("OK")
Nm = int(N[0])
m = len(N)
# if m == 1 or m == 2:
# print("0")
return int(pow(9,3)*(m-1)*(m-2)*(m-3)/6+(Nm-1)*(m-1)*(m-2)*9*9/2+func_2(str(int(N)-Nm*(10**(m-1)))))
if K == 1:
print(func_1(N))
elif K == 2:
print(func_2(N))
elif K == 3:
print(func_3(N)) | 0 | null | 65,466,714,470,808 | 201 | 224 |
while 1:
h,w=map(int,raw_input().split())
if (h,w)==(0,0):
break
print ("#"*w+"\n")*h | while(1):
h,w = [int(i) for i in input().split()]
if h == 0 and w == 0:
break
for i in range(h):
print("#"*w)
print("")
| 1 | 766,656,928,192 | null | 49 | 49 |
N = int(input())
A = list(map(int, input().split()))
mod = int(1e9) + 7
cA = [A[0]]
ans = 0
for i in range(1, N):
cA.append(cA[-1] + A[i])
for i in range(N-1):
ans += A[i] * ((cA[-1] - cA[i])%mod)
ans %= mod
print(ans) | taro = 0
hanako = 0
n = int(input())
for _ in range(n):
taro_card, hanako_card = input().split()
if taro_card > hanako_card:
taro += 3
elif taro_card < hanako_card:
hanako += 3
else:
taro += 1
hanako += 1
print(taro, hanako) | 0 | null | 2,864,091,659,076 | 83 | 67 |
import sys
def main():
orders = sys.stdin.readlines()[1:]
dna_set = set()
for order in orders:
command, dna = order.split(" ")
if command == "insert":
dna_set.add(dna)
elif command == "find":
if dna in dna_set:
print("yes")
else:
print("no")
if __name__ == "__main__":
main() | # -*- coding: utf-8 -*-
def main():
dictionary = {}
input_num = int(raw_input())
counter = 0
while counter < input_num:
command, key = raw_input().split(' ')
if command == 'insert':
dictionary[key] = True
else:
if key in dictionary:
print 'yes'
else:
print 'no'
counter += 1
if __name__ == '__main__':
main() | 1 | 76,103,432,238 | null | 23 | 23 |
n = int(input())
num_list = list(map(int, input().split()))
ans_list = [0]*n
for i, j in enumerate(num_list):
ans_list[j-1] = str(i+1)
ans = ' '.join(ans_list)
print(ans) | def gotoS(org, n):
res = [0] * n
for i in range(1, n+1):
res[org[i-1]-1] = i
return res
n = int(input())
org = list(map(int, input().split()))
print(*gotoS(org, n)) | 1 | 181,189,144,727,950 | null | 299 | 299 |
A, B, C, K = map(int, input().split())
sum = 0
if A > K:
print(K)
elif A + B > K:
print(A)
else:
print(A-(K-A-B)) # =(A+B-(K-(A+B))) |
# 公式解説を見てからやった
# 複数サイクルでき、1-K回移動可能
# N < 5000?多分、O(N * 2N)くらいで行けそうに見えるが。。。
def main(N,K,P,C):
# 一度計算したサイクル情報を一応キャッシュしておく。。。
# あんまり意味なさそう
cycleIDs = [ -1 for _ in range(N) ]
cycleInfs = []
# print(P)
ans = -1e10
cycleID = 0
for n in range(N):
v = n
currentCycleItemCnt = 0
currentCycleTotal = 0
if cycleIDs[v] != -1:
currentCycleItemCnt, currentCycleTotal = cycleInfs[ cycleIDs[v] ]
# print(currentCycleItemCnt, currentCycleTotal)
else:
while True:
# 全頂点について、属するサイクルを計算する
currentCycleItemCnt += 1
currentCycleTotal += C[v]
v = P[v]
if v == n:
# サイクル発見
cycleInfs.append( (currentCycleItemCnt, currentCycleTotal) )
cycleID += 1
break
# 一応、一度サイクルを計算した頂点については、
# その頂点の属するサイクルの情報をメモっておく。。。
cycleIDs[v] = cycleID
procCnt = 0
currentCycleSumTmp = 0
while True:
# 頂点vにコマが置かれた時の最高スコアを計算し、
# これまでの最高スコアを上回ったら、これまでの最高スコアを更新する
procCnt += 1
currentCycleSumTmp += C[v]
if K < procCnt:
break
cycleLoopCnt = 0
if procCnt < K and 0 < currentCycleTotal:
cycleLoopCnt = ( K - procCnt ) // currentCycleItemCnt
# print("v=", v, "currentCycleSumTmp=", currentCycleSumTmp, procCnt)
tmp = currentCycleSumTmp + cycleLoopCnt * currentCycleTotal
ans = max( ans, tmp )
v = P[v]
if v == n:
# サイクル終了
break
return ans
# print(ans)
if __name__ == "__main__":
N,K = map(int,input().split())
P = [ int(p)-1 for p in input().split() ]
C = list(map(int,input().split()))
ans=main(N,K,P,C)
print(ans)
| 0 | null | 13,688,509,060,160 | 148 | 93 |
import sys
input = sys.stdin.buffer.readline
import numpy as np
def main():
N,K = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse=True)
if sum(a) <= K:
print(0)
else:
a = np.array(a)
f = np.array(f)
left,right = 0,max(a)*max(f)
while right-left > 1:
mid = (left+right)//2
pra = a-mid//f
pra[pra<0] = 0
if np.sum(pra) > K:
left = mid
else:
right = mid
print(right)
if __name__ == "__main__":
main()
| import collections
s = list(input())
n = len(s)
mod = [0]*(n+1)
pow10 = 1
for i in range(n):
mod[i+1] = (mod[i] + int(s[-1-i])*pow10)%2019
pow10 = pow10*10%2019
d = collections.Counter(mod)
ans = 0
for i in d.values():
ans += i*(i-1)//2
print(ans)
| 0 | null | 97,926,651,621,762 | 290 | 166 |
#! /usr/bin/env python3
import itertools
import sys
sys.setrecursionlimit(10**9)
INF=10**20
def solve(N: int, P: "List[int]", Q: "List[int]"):
X = list(range(1,N+1))
R = []
for r in itertools.permutations(X,N):
R.append(int("".join(list(map(str,r)))))
R.sort()
P = int("".join(P))
Q = int("".join(Q))
a,b = 0,0
for i,r in enumerate(R):
if r == P:
a = i
if r == Q:
b = i
print(abs(a-b))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
P = [str(next(tokens)) for _ in range(N)] # type: "List[int]"
Q = [str(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, P, Q)
if __name__ == "__main__":
main()
| S = input()
week = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
if S == week[0]:
print(7)
elif S == week[1]:
print(6)
elif S == week[2]:
print(5)
elif S == week[3]:
print(4)
elif S == week[4]:
print(3)
elif S == week[5]:
print(2)
else:
print(1) | 0 | null | 117,209,770,010,398 | 246 | 270 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
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 LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
class UnionFind:
def __init__(self, n):
# 負 : 根であることを示す。絶対値はランクを示す
# 非負: 根でないことを示す。値は親を示す
self.table = [-1] * n
self.size = [1] * n
# self.group_num = n
def root(self, x):
if self.table[x] < 0:
return x
else:
self.table[x] = self.root(self.table[x])
return self.table[x]
def get_size(self, x):
r = self.root(x)
return self.size[r]
def is_same(self, x, y):
return self.root(x) == self.root(y)
def union(self, x, y):
r1 = self.root(x)
r2 = self.root(y)
if r1 == r2:
return
# ランクの取得
d1 = self.table[r1]
d2 = self.table[r2]
if d1 <= d2:
self.table[r2] = r1
self.size[r1] += self.size[r2]
if d1 == d2:
self.table[r1] -= 1
else:
self.table[r1] = r2
self.size[r2] += self.size[r1]
# self.group_num -= 1
n, k = LI()
P = LI()
C = LI()
U = UnionFind(n)
for i in range(n):
U.union(P[i] - 1, i)
D = defaultdict(int)
for i in range(n):
D[U.root(i)] += C[i]
ans = -INF
k -= 1
for j in range(n):
now = P[j] - 1
r = D[U.root(now)]
m = U.get_size(now)
ret = C[now]
ans = max(ans, ret)
if k // m and r >= 0:
ret += k // m * r
ans = max(ans, ret)
for l in range(k % m):
now = P[now] - 1
ret += C[now]
ans = max(ans, ret)
ret = C[now]
for l in range(min(m, k)):
now = P[now] - 1
ret += C[now]
ans = max(ans, ret)
print(ans)
| import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
SI = lambda : sys.stdin.readline().rstrip()
T = LI()
A = LI()
B = LI()
p1 = (A[0] - B[0]) * T[0]
p2 = p1 + (A[1] - B[1]) * T[1]
if p1 * p2 > 0:
print(0)
return
elif p2 == 0:
print('infinity')
return
ans = 1
if p2 + p1 == 0:
print(2)
return
p2 = abs(p2)
p1 = abs(p1)
if p2 > p1:
print(1)
return
if p1 % p2 == 0:
ans -= 1
ans += (p1 // p2) * 2
print(ans)
if __name__ == '__main__':
main() | 0 | null | 68,814,517,344,510 | 93 | 269 |
n = int(input())
ans = set()
#n-1の約数は確定でOK
for i in range(1,int(pow(n-1,0.5)) + 1):
if (n-1) % i == 0:
ans.add((n-1)//i)
ans.add(i)
#n = (1 + pk) * k^q の形になるkを探す。q ≠ 0のとき、kはnの約数
for i in range(2,int(pow(n,0.5)) + 1):
if n % i == 0:
tmp = n
while tmp % i == 0:
tmp = tmp // i
if (tmp - 1) % i == 0:
ans.add(i)
print(len(ans))
| """
一回以上わるとき、KはNの約数なので、Nの約数を全通り試して1に持っていけるかどうかを検証する。
Nを一回も割らずに1まで持っていけるようなKは、N-1の約数の数だけ存在する。
それぞれカウントすればよい
"""
N = int(input())
ans = 0
if N == 2:
print(1)
exit()
divisers = [N]
d = 2
while d*d < N:
if N % d == 0:
divisers.append(d)
divisers.append(N//d)
d += 1
if d**2 == N:
divisers.append(d)
for d in divisers:
dummyN = N
while dummyN%d == 0:
dummyN //= d
if dummyN % d == 1:
ans += 1
N -= 1
divisers = [N]
d = 2
while d*d < N:
if N % d == 0:
divisers.append(d)
divisers.append(N//d)
d += 1
if d**2 == N:
divisers.append(d)
ans += len(divisers)
print(ans) | 1 | 41,338,103,653,168 | null | 183 | 183 |
N,K = list(map(int,input().split()))
P = list(map(int,input().split()))
import numpy as np
Q = np.cumsum(P)
R = np.pad(Q,K,'constant', constant_values=0)[:N]
a = np.argmax(Q-R)
ans = 0
for i in range(K):
ans += (1.00+P[a-i])/2.00
print(ans) | n, k = map(int, input().split())
p = list(map(int, input().split()))
q = [0]
m = 0
for i in p:
m += (1+i)/2
q.append(m)
ans = 0
for i in range(k, n+1):
ans = max(q[i]-q[i-k], ans)
#あまり深く事を考えずに
print(ans) | 1 | 74,784,239,048,448 | null | 223 | 223 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.