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
|
---|---|---|---|---|---|---|
from __future__ import (division, absolute_import, print_function,
unicode_literals)
import sys
from fractions import gcd
for line in sys.stdin:
small, large = sorted(int(n) for n in line .split())
G = gcd(large, small)
print(G, large // G * small) | n=int(input())
A=input().split()
def findProductSum(A,n):
product = 0
for i in range (n):
for j in range ( i+1,n):
product = product + int(A[i])*int(A[j])
return product
print(findProductSum(A,n)) | 0 | null | 84,529,668,914,432 | 5 | 292 |
number=list(map(int,input().split()))
n,m,q=number[0],number[1],number[2]
nums=[]
for i in range(q):
tmp=list(map(int,input().split()))
nums.append(tmp)
answer=0
mid=0
List1=[]
for i in range(m):
List1.append(i)
import itertools
for i in list(itertools.combinations_with_replacement(List1,n)):
mid=0
for j in range(q):
if i[nums[j][1]-1]-i[nums[j][0]-1]==nums[j][2]:
mid+=nums[j][3]
answer=max(mid,answer)
print(answer)
| n = int(input())
s = input()
if n % 2 == 1:
print('No')
else:
cnt = 0
for i in range(0, n // 2):
cnt += (s[i] == s[i + n // 2])
if(cnt == n // 2):
print('Yes')
else:
print('No')
| 0 | null | 87,080,240,563,188 | 160 | 279 |
while True:
a,op,b=input().split(" ")
a,b=[int(i) for i in (a,b)]
if op=="?":
break
print(a+b if op=="+" else a-b if op=="-" else a*b if op=="*" else int(a/b) if op=="/" else "") | n=int(input())
a=list(input().split())
l = [0 for _ in range(n+1)]
for i in a:
l[int(i)]+=1
for j in range(1,n+1):
print(l[j]) | 0 | null | 16,635,640,496,020 | 47 | 169 |
import sys
input = sys.stdin.buffer.readline
R,C,K = map(int,input().split())
goods = [[0]*(C+1) for _ in range(R+1)]
INF = 10**18
for i in range(K):
ri,ci,vi = map(int,input().split())
goods[ri][ci] = vi
DP = [[[-INF]*(C+1) for _ in range(R+1)] for _ in range(4)]
DP[0][1][1] = 0
if goods[1][1]:
DP[1][1][1] = goods[1][1]
for j in range(1,C):
DP[0][1][j+1] = 0
if goods[1][j+1]:
DP[1][1][j+1] = max(DP[1][1][j],DP[0][1][j]+goods[1][j+1])
DP[2][1][j+1] = max(DP[2][1][j],DP[1][1][j]+goods[1][j+1])
DP[3][1][j+1] = max(DP[3][1][j],DP[2][1][j]+goods[1][j+1])
else:
DP[1][1][j+1] = DP[1][1][j]
DP[2][1][j+1] = DP[2][1][j]
DP[3][1][j+1] = DP[3][1][j]
for i in range(1,R):
DP[0][i+1][1] = max(DP[0][i][1],DP[1][i][1],DP[2][i][1],DP[3][i][1])
if goods[i+1][1]:
DP[1][i+1][1] = DP[0][i+1][1] + goods[i+1][1]
for i in range(2,R+1):
for j in range(2,C+1):
DP[0][i][j] = max(DP[0][i-1][j],DP[1][i-1][j],DP[2][i-1][j],DP[3][i-1][j],DP[0][i][j-1])
if goods[i][j]:
DP[1][i][j] = max(DP[0][i][j]+goods[i][j],DP[1][i][j-1])
DP[2][i][j] = max(DP[2][i][j-1],DP[1][i][j-1]+goods[i][j])
DP[3][i][j] = max(DP[3][i][j-1],DP[2][i][j-1]+goods[i][j])
else:
DP[1][i][j] = DP[1][i][j-1]
DP[2][i][j] = DP[2][i][j-1]
DP[3][i][j] = DP[3][i][j-1]
print(max(DP[0][R][C],DP[1][R][C],DP[2][R][C],DP[3][R][C])) | moutain = [0 for i in range(10)]
for i in range(10):
moutain[i] = int(raw_input())
moutain.sort(reverse=True)
for i in range(3):
print moutain[i]
| 0 | null | 2,765,242,616,612 | 94 | 2 |
S = input()
N=len(S)+1
SS = '>'+S+'<'
a = [-1]*(N+2)
for i in range(N+1):
if SS[i] == '>' and SS[i+1]=='<':
a[i+1]=0
b = a[1:-1]
c = a[1:-1]
for i in range(N-1):
if S[i] == '<' and b[i]>=0 :
b[i+1] = b[i] +1
for i in range(N-2,-1,-1):
if S[i] == '>' and c[i+1]>=0:
c[i] = c[i+1] +1
ans = 0
for bb,cc in zip(b,c):
ans += max(bb,cc)
print(ans)
|
from collections import deque
n, q = map(int, input().split())
procs = deque([])
for i in range(n):
name, time = input().split()
time = int(time)
procs.append([name, time])
total = 0
while procs:
procs[0][1] -= q
if procs[0][1] > 0:
total += q
procs.append(procs.popleft())
else:
total += q + procs[0][1]
print(procs[0][0], total)
procs.popleft() | 0 | null | 78,578,073,433,978 | 285 | 19 |
def resolve():
N, K = list(map(int, input().split()))
snacks = [0 for _ in range(N)]
for i in range(K):
d = int(input())
A = list(map(int, input().split()))
for a in A:
snacks[a-1] += 1
cnt = 0
for s in snacks:
if s == 0:
cnt += 1
print(cnt)
if '__main__' == __name__:
resolve() | N,M=map(int,input().split())
A=input()
List_A=A.split()
day=0
for i in range(0,M):
day=day+int(List_A[i])
if N>=day:
print(N-day)
else:
print(-1) | 0 | null | 28,433,161,365,470 | 154 | 168 |
sum = 0
while 1:
x = raw_input()
sum = sum + 1
if x == '0':
break
print 'Case %s: %s' %(sum, x) | import sys
line = sys.stdin.readline()
n =[]
while line:
if int(line) == 0:
break;
else:
n.append(line)
line = sys.stdin.readline()
c = 1
for i in n:
print "Case",str(c)+":",str(i),
c+=1 | 1 | 490,063,721,620 | null | 42 | 42 |
n=int(input())
a=[int(x) for x in input().split()]
if len(a) == len(set(a)):
print("YES")
else:
print("NO") |
n = int(input())
s = [str(input()) for i in range(n)]
a = s.count(('AC'))
b = s.count(('WA'))
c = s.count(('TLE'))
d = s.count(('RE'))
print("AC x {}".format(a))
print("WA x {}".format(b))
print("TLE x {}".format(c))
print("RE x {}".format(d))
| 0 | null | 41,540,317,565,862 | 222 | 109 |
def resolve():
A = sum(map(int, input().split()))
print("bust" if A >= 22 else "win")
if '__main__' == __name__:
resolve() | d,t,s = map(int,input().split())
T = d/s
if(t>=T):
print("Yes")
else:
print("No") | 0 | null | 61,456,744,222,530 | 260 | 81 |
N,M = map(int,input().split())
print((str(N)*M,str(M)*N)[N > M]) | #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: B
# CreatedDate: 2020-06-28 21:02:34 +0900
# LastModified: 2020-06-28 22:01:44 +0900
#
import os
import sys
# import numpy as np
# import pandas as pd
def main():
d = int(input())
c = list(map(int, input().split()))
s = [] # 満足度
box = [-1]*26 # 各コンテストの実施日
for i in range(d):
s.append(list(map(int, input().split())))
total_satisfy = 0
for i in range(d):
t = int(input())
total_satisfy += s[i][t-1]
box[t-1] = i
for j in range(26):
if box[j] == -1:
total_satisfy -= c[j]*(i+1)
else:
total_satisfy -= c[j]*(i-box[j])
# print(box)
print(total_satisfy)
if __name__ == "__main__":
main()
| 0 | null | 47,307,094,687,258 | 232 | 114 |
tscore = hscore = 0
n = int( input( ) )
for i in range( n ):
tcard, hcard = input( ).split( " " )
if tcard < hcard:
hscore += 3
elif hcard < tcard:
tscore += 3
else:
hscore += 1
tscore += 1
print( "{:d} {:d}".format( tscore, hscore ) ) | n=int(raw_input())
p=[0,0]
for i in range(n):
c=[0 for i in range(100)]
c=map(list,raw_input().split())
m=0
while 1:
try:
if c[0]==c[1]:
p[0]+=1
p[1]+=1
break
elif c[0][m]<c[1][m]:
p[1]+=3
break
elif c[1][m]<c[0][m]:
p[0]+=3
break
m+=1
except IndexError:
if len(c[0])<len(c[1]):
p[1]+=3
break
if len(c[1])<len(c[0]):
p[0]+=3
break
print p[0], p[1] | 1 | 1,995,889,538,652 | null | 67 | 67 |
s = int(input())
MOD = 1000000007
kotae = [0 for _ in range(2001)]
kotae[0] = 0
kotae[1] = 0
kotae[2] = 0
kotae[3] = 1
kotae[4] = 1
kotae[5] = 1
kotae[6] = 2
for i in range(7,2001):
kotae[i] = kotae[i-1] + kotae[i-3]
kotae[i] = kotae[i] % MOD
print(kotae[s]) | import math
import itertools
def gcd(lst):
return math.gcd(math.gcd(lst[0],lst[1]), lst[2])
k = int(input())
lst = [i for i in range(1,k+1)]
itr = itertools.combinations_with_replacement(lst, 3)
ans = 0
for i in itr:
st = set(i)
num = len(st)
if num == 1:
ans += i[0]
elif num == 2:
a,b = st
ans += math.gcd(a,b) * 3
else:
ans += math.gcd(math.gcd(i[0],i[1]), i[2]) * 6
print(ans) | 0 | null | 19,481,293,153,100 | 79 | 174 |
def main():
S = input()
K = int(input())
A = []
last = S[0]
count = 1
for i in range(1, len(S)):
s = S[i]
if last == s:
count += 1
else:
A.append({'key': last, 'count': count})
count = 1
last = s
A.append({'key': last, 'count': count})
# print(A)
if len(A) == 1:
c = A[0]['count']
l = c*K
ans = l//2
print(ans)
return
ans = 0
if A[0]['key'] != A[-1]['key']:
for a in A:
c = a['count']
ans += (c//2) * K
print(ans)
return
for i in range(1, len(A) - 1):
a = A[i]
c = a['count']
ans += (c//2) * K
a0 = A[0]
a1 = A[-1]
c0 = a0['count']
c1 = a1['count']
ans += c0//2
ans += c1//2
ans += ((c0 + c1)//2) * (K - 1)
print(ans)
if __name__ == '__main__':
main()
| s = list(input())
k = int(input())
n = len(s)
if(len(set(s)) == 1):
print(n*k//2)
else:
t = 0
c = 1
for i in range(n-1):
if(s[i] == s[i+1]):
c += 1
else:
t += c // 2
c = 1
t += c // 2
if(s[0] != s[-1]):
print(t*k)
else:
a = 0
b = 0
for i in range(n):
if(s[i] == s[0]):a+=1
else:break
for i in range(n)[::-1]:
if(s[i] == s[-1]):b+=1
else:break
print(t*k - (a//2 + b//2 - (a+b)//2) * (k-1)) | 1 | 175,406,637,723,652 | null | 296 | 296 |
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction
# 10進数表記でnのk進数を求めてlength分0埋め
def ternary (n, k, length):
if n == 0:
nums = ['0' for i in range(length)]
nums = ''.join(nums)
return nums
nums = ''
while n:
n, r = divmod(n, k)
nums += str(r)
nums = nums[::-1]
nums = nums.zfill(length)
return nums
def main():
num = int(input())
data = list(map(int, input().split()))
mod = 10 ** 9 + 7
max_length = len(bin(max(data))) - 2
bit_count = [0 for i in range(max_length)]
for i in range(num):
now_bin = bin(data[i])[2:]
now_bin = now_bin.zfill(max_length)
for j in range(max_length):
if now_bin[j] == "1":
bit_count[j] += 1
flg_data = [0 for i in range(max_length)]
for i in range(max_length):
flg_data[i] += bit_count[i] * (num - bit_count[i])
ans = 0
for j in range(max_length):
pow_num = max_length - 1 - j
bbb = pow(2, pow_num, mod)
ans += bbb * flg_data[j]
ans %= mod
print(ans)
if __name__ == '__main__':
main()
| n, k = map(int, input().split())
scores = list(map(int, input().split()))
evals = []
cnt = 0
for i in range(k, n, 1):
edge = scores[cnt]
new_edge = scores[i]
if edge < new_edge:
print('Yes')
else:
print('No')
cnt += 1 | 0 | null | 64,838,718,287,002 | 263 | 102 |
from decimal import Decimal
a,b,c=[Decimal(int(i)) for i in input().split()]
l=a.sqrt()+b.sqrt()
r=c.sqrt()
print("Yes" if l < r else "No")
| # coding: utf-8
a = input()
print(int(a)*int(a)*int(a)) | 0 | null | 25,854,693,942,012 | 197 | 35 |
import sys
H = int(next(sys.stdin.buffer))
ans = 0
i = 1
while H > 0:
H //= 2
ans += i
i *= 2
print(ans) | while True:
try:
a=map(int,raw_input().split())
print len(str(a[0]+a[1]))
except:
break | 0 | null | 39,893,045,049,088 | 228 | 3 |
def solve():
N,R = [int(i) for i in input().split()]
if N >= 10:
print(R)
else:
print(R+100*(10-N))
if __name__ == "__main__":
solve() | n,r = input().split()
n = int(n)
r = int(r)
if n >= 10:
i = r
else:
i = r + 100 * (10 - n)
print(i) | 1 | 63,339,957,704,258 | null | 211 | 211 |
n = int(input())
*li, = map(int, input().split())
input()
*Q, = map(int, input().split())
bits = 1
for i in li:
# print(f"{i=}")
# print(f"{bin(bits)=}")
bits |= bits << i
# print(f"{bin(bits)=}")
# print()
# print()
for q in Q:
# print(f"{bin(bits)=}")
print("yes"*((bits >> q) & 1) or "no")
# print()
| #!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from itertools import combinations
def enum_sum_numbers(sets, s_range, r):
for cmb in combinations(sets, r):
yield sum(cmb)
if r <= s_range:
for s in enum_sum_numbers(sets, s_range, r+1):
yield s
stdin.readline()
a = [int(s) for s in stdin.readline().split()]
stdin.readline()
ms = [int(s) for s in stdin.readline().split()]
sets = {s for s in enum_sum_numbers(a, len(a), 1)}
for m in ms:
print('yes' if m in sets else 'no') | 1 | 99,971,278,340 | null | 25 | 25 |
l,r,d = map(int,input().split())
#print(l,r,d)
ans = 0
for i in range(101):
if d * i > r:
break
elif d * i >= l:
ans += 1
continue
else:
continue
print(ans) | import collections
n = int(input())
a = list(map(int, input().split()))
l = []
r = []
for i in range(n):
l.append(i+a[i])
r.append(i-a[i])
count_l = collections.Counter(l)
count_r = collections.Counter(r)
ans = 0
for i in count_l:
ans += count_r.get(i,0) * count_l[i]
print(ans) | 0 | null | 16,806,141,420,618 | 104 | 157 |
import bisect
N = int(input())
A = [int(x) for x in input().split()]
A=sorted(A)
index = 0
for i in range(1, N+1):
now = bisect.bisect_right(A, i)
print(now - index)
index = now
| print(2**int(input()).bit_length()-1)
| 0 | null | 56,470,271,706,462 | 169 | 228 |
fib = [1]*100
for i in range(2,100):
fib[i] = fib[i-1] + fib[i-2]
print(fib[int(input())])
| from sys import stdin
def main():
#入力
readline=stdin.readline
n=int(readline())
dp=[0]*(n+1)
for i in range(n+1):
if i==0 or i==1:
dp[i]=1
else:
dp[i]=dp[i-1]+dp[i-2]
print(dp[n])
if __name__=="__main__":
main()
| 1 | 1,880,398,682 | null | 7 | 7 |
s=input().split()
n=int(s[0])
m=int(s[1])
a=[[0 for j in range(m)]for i in range(n)]
b=[0 for j in range(m)]
for i in range(n):
t=input().split()
for j in range(m):
a[i][j]=int(t[j])
for j in range(m):
b[j]=int(input())
c=[0 for i in range(n)]
for i in range(n):
for j in range(m):
c[i]+=a[i][j]*b[j]
print("{0}".format(c[i])) | import sys
sys.setrecursionlimit(300000)
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')
K = I()
num = 7
for i in range(10 ** 6):
if num % K == 0:
print(i + 1)
exit()
num = (num * 10 + 7) % K
print(-1) | 0 | null | 3,594,367,589,732 | 56 | 97 |
import os
import sys
import numpy as np
def solve(inp):
def bitree_sum(bit, t, i):
s = 0
while i > 0:
s += bit[t, i]
i ^= i & -i
return s
def bitree_add(bit, n, t, i, x):
while i <= n:
bit[t, i] += x
i += i & -i
def bitree_lower_bound(bit, n, d, t, x):
sum_ = 0
pos = 0
for i in range(d, -1, -1):
k = pos + (1 << i)
if k <= n and sum_ + bit[t, k] < x:
sum_ += bit[t, k]
pos += 1 << i
return pos + 1
def initial_score(d, ccc, sss):
bit_n = d + 3
bit = np.zeros((26, bit_n), dtype=np.int64)
INF = 10 ** 18
for t in range(26):
bitree_add(bit, bit_n, t, bit_n - 1, INF)
ttt = np.zeros(d, dtype=np.int64)
last = np.full(26, -1, dtype=np.int64)
score = 0
for i in range(d):
best_t = 0
best_diff = -INF
costs = ccc * (i - last)
costs_sum = costs.sum()
for t in range(26):
tmp_diff = sss[i, t] - costs_sum + costs[t]
if best_diff < tmp_diff:
best_t = t
best_diff = tmp_diff
ttt[i] = best_t
last[best_t] = i
score += best_diff
bitree_add(bit, bit_n, best_t, i + 2, 1)
return bit, score, ttt
def calculate_score(d, ccc, sss, ttt):
last = np.full(26, -1, dtype=np.int64)
score = 0
for i in range(d):
t = ttt[i]
last[t] = i
score += sss[i, t] - (ccc * (i - last)).sum()
return score
def pinpoint_change(bit, bit_n, bit_d, d, ccc, sss, ttt, permissible):
cd = np.random.randint(0, d)
ct = np.random.randint(0, 26)
while ttt[cd] == ct:
ct = np.random.randint(0, 26)
diff = 0
t = ttt[cd]
k = bitree_sum(bit, t, cd + 2)
c = bitree_lower_bound(bit, bit_n, bit_d, t, k - 1) - 2
e = bitree_lower_bound(bit, bit_n, bit_d, t, k + 1) - 2
b = ccc[t]
diff -= b * (cd - c) * (e - cd)
diff -= sss[cd, t]
k = bitree_sum(bit, ct, cd + 2)
c = bitree_lower_bound(bit, bit_n, bit_d, ct, k) - 2
e = bitree_lower_bound(bit, bit_n, bit_d, ct, k + 1) - 2
b = ccc[ct]
diff += b * (cd - c) * (e - cd)
diff += sss[cd, ct]
if diff > permissible:
bitree_add(bit, bit_n, t, cd + 2, -1)
bitree_add(bit, bit_n, ct, cd + 2, 1)
ttt[cd] = ct
else:
diff = 0
return diff
def swap_change(bit, bit_n, bit_d, d, ccc, sss, ttt, permissible):
dd = np.random.randint(1, 14)
cd1 = np.random.randint(0, d - dd)
cd2 = cd1 + dd
ct1 = ttt[cd1]
ct2 = ttt[cd2]
if ct1 == ct2:
return 0
diff = 0
k = bitree_sum(bit, ct1, cd1 + 2)
c = bitree_lower_bound(bit, bit_n, bit_d, ct1, k - 1) - 2
e = bitree_lower_bound(bit, bit_n, bit_d, ct1, k + 1) - 2
diff += ccc[ct1] * (e + c - cd1 - cd2)
k = bitree_sum(bit, ct2, cd2 + 2)
c = bitree_lower_bound(bit, bit_n, bit_d, ct2, k - 1) - 2
e = bitree_lower_bound(bit, bit_n, bit_d, ct2, k + 1) - 2
diff -= ccc[ct2] * (e + c - cd1 - cd2)
diff -= sss[cd1, ct1] + sss[cd2, ct2]
diff += sss[cd1, ct2] + sss[cd2, ct1]
if diff > permissible:
bitree_add(bit, bit_n, ct1, cd1 + 2, -1)
bitree_add(bit, bit_n, ct1, cd2 + 2, 1)
bitree_add(bit, bit_n, ct2, cd1 + 2, 1)
bitree_add(bit, bit_n, ct2, cd2 + 2, -1)
ttt[cd1] = ct2
ttt[cd2] = ct1
else:
diff = 0
return diff
d = inp[0]
ccc = inp[1:27]
sss = np.zeros((d, 26), dtype=np.int64)
for r in range(d):
sss[r] = inp[27 + r * 26:27 + (r + 1) * 26]
bit, score, ttt = initial_score(d, ccc, sss)
bit_n = d + 3
bit_d = int(np.log2(bit_n))
loop = 5 * 10 ** 6
permissible_min = -2000.0
method_border = 0.8
best_score = score
best_ttt = ttt.copy()
for lp in range(loop):
permissible = (1 - lp / loop) * permissible_min
if np.random.random() < method_border:
diff = pinpoint_change(bit, bit_n, bit_d, d, ccc, sss, ttt, permissible)
else:
diff = swap_change(bit, bit_n, bit_d, d, ccc, sss, ttt, permissible)
score += diff
# print(lp, score, calculate_score(d, ccc, sss, ttt))
if score > best_score:
best_score = score
best_ttt = ttt.copy()
return best_ttt + 1
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('my_module')
cc.export('solve', '(i8[:],)')(solve)
cc.compile()
exit()
if os.name == 'posix':
# noinspection PyUnresolvedReferences
from my_module import solve
else:
from numba import njit
solve = njit('(i8[:],)', cache=True)(solve)
print('compiled', file=sys.stderr)
inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print('\n'.join(map(str, ans)))
| K = int(input())
A, B = map(int, input().split())
flag = 0
for n in range(A, B+1):
if n % K == 0:
flag = 1
break
if flag == 0:
print("NG")
else:
print("OK") | 0 | null | 18,183,885,221,780 | 113 | 158 |
def readinput():
n,k=map(int,input().split())
okashi=[]
for _ in range(k):
d=int(input())
l=list(map(int,input().split()))
okashi.append(l)
return n,k,okashi
def main(n,k,okashi):
sunuke=[0]*(n+1)
for l in okashi:
for su in l:
sunuke[su]+=1
count=0
for i in range(n):
if sunuke[i+1]==0:
count+=1
return count
if __name__=='__main__':
n,k,okashi=readinput()
ans=main(n,k,okashi)
print(ans)
| import sys
import string
s = sys.stdin.read().lower()
for c in string.ascii_lowercase:
print(c, ":", s.count(c)) | 0 | null | 13,013,997,437,288 | 154 | 63 |
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
#?????§??????
#??????????????????????????°???????????????????????¢?????´?????????????????????
def get_maximum_profit(value_list, n_list):
minv = pow(10,10) + 1
profit = -minv
for v in value_list:
profit = max(profit, v - minv)
minv = min(minv, v)
return profit
def main():
n_list = int(input())
target_list = [int(input()) for i in range(n_list)]
print(get_maximum_profit(target_list, n_list))
if __name__ == "__main__":
main() | from sys import stdin
n = int(input())
r=[int(input()) for i in range(n)]
rv = r[::-1][:-1]
m = None
p_r_j = None
for j,r_j in enumerate(rv):
if p_r_j == None or p_r_j < r_j:
p_r_j = r_j
if p_r_j > r_j:
continue
r_i = min(r[:-(j+1)])
t = r_j - r_i
if m == None or t > m:
m = t
print(m) | 1 | 13,838,991,008 | null | 13 | 13 |
import sys
N, K = map(int, sys.stdin.readline().rstrip().split())
H = [int(x) for x in sys.stdin.readline().rstrip().split()]
H.sort()
# print(H[:-K])
if K == 0:
print(sum(H))
else:
print(sum(H[:-K])) | n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n-1):
if a[i] <= a[i+1]:
pass
else:
ans += a[i] - a[i+1]
a[i+1] = a[i]
print(ans) | 0 | null | 41,741,370,629,188 | 227 | 88 |
A=[int(_) for _ in input().split()]
if A[0]<=A[1]*A[2]:
print("Yes")
else:
print("No") | # -*- coding: utf-8 -*-
import sys
def func2(x):
if not x.isalpha():
return x
else:
if x.isupper():
return x.lower()
else:
return x.upper()
print("".join(map(lambda x:func2(x),sys.stdin.readline().rstrip())))
| 0 | null | 2,500,151,517,770 | 81 | 61 |
import abc
class AdjacentGraph:
"""Implementation adjacency-list Graph.
Beware ids are between 1 and size.
"""
def __init__(self, size):
self.size = size
self._nodes = [[0] * (size+1) for _ in range(size+1)]
def set_adj_node(self, id_, adj_id):
self._nodes[id_][adj_id] = 1
def __iter__(self):
self._id = 0
return self
def __next__(self):
if self._id < self.size:
self._id += 1
return (self._id, self._nodes[self._id][1:])
raise StopIteration()
def dfs(self, handler=None):
def find_first():
try:
return visited.index(0) + 1
except ValueError:
return None
visited = [0] * self.size
first = 1
while first is not None:
stack = [(first, 0, 0)]
while len(stack) > 0:
i, depth, j = stack.pop()
if j == 0:
if handler:
handler.visit(i, depth)
visited[i-1] = 1
yield i
try:
j = self._nodes[i].index(1, j+1)
stack.append((i, depth, j))
if visited[j-1] == 0:
stack.append((j, depth+1, 0))
except ValueError:
if handler:
handler.leave(i)
first = find_first()
def bfs(self, handler=None):
def find_first():
try:
return visited.index(0) + 1
except ValueError:
return None
visited = [0] * self.size
first = 1
while first is not None:
queue = [(first, 0)]
while len(queue) > 0:
(i, depth), *queue = queue
if visited[i-1] == 0:
if handler:
handler.visit(i, depth)
visited[i-1] = 1
yield i
try:
j = 0
while j < self.size:
j = self._nodes[i].index(1, j+1)
if visited[j-1] == 0:
queue.append((j, depth+1))
except ValueError:
pass
if handler:
handler.leave(i)
first = find_first()
class EventHandler(abc.ABC):
@abc.abstractmethod
def visit(self, i, depth):
pass
@abc.abstractmethod
def leave(self, i):
pass
class Logger(EventHandler):
def __init__(self, n):
self.log = [(0, 0)] * n
self.step = 0
def visit(self, i, depth):
self.step += 1
self.log[i-1] = (self.step, depth, 0)
def leave(self, i):
self.step += 1
self.log[i-1] = (self.log[i-1][0], self.log[i-1][1], self.step)
def by_node(self):
i = 1
for discover, depth, finish in self.log:
yield (i, discover, depth, finish)
i += 1
def run():
n = int(input())
g = AdjacentGraph(n)
log = Logger(n)
for i in range(n):
id_, c, *links = [int(x) for x in input().split()]
for n in links:
g.set_adj_node(id_, n)
for i in g.bfs(log):
pass
reachable = None
for node in log.by_node():
id_, find, dep, exit = node
if id_ > 1 and dep == 0:
reachable = find - 1
if reachable is not None and find > reachable:
dep = -1
print("{} {}".format(id_, dep))
if __name__ == '__main__':
run()
| a,b,c = map(int, input().split())
X = c
Y = a
Z = b
print (X,Y,Z) | 0 | null | 18,974,065,269,600 | 9 | 178 |
def selection_sort(A):
count = 0
for i in range(len(A)):
min_value = A[i]
min_value_index = i
# print('- i:', i, 'A[i]', A[i], '-')
for j in range(i, len(A)):
# print('j:', j, 'A[j]:', A[j])
if A[j] < min_value:
min_value = A[j]
min_value_index = j
# print('min_value', min_value, 'min_value_index', min_value_index)
if i != min_value_index:
count += 1
A[i], A[min_value_index] = A[min_value_index], A[i]
# print('swap!', A)
return count
n = int(input())
A = list(map(int, input().split()))
count = selection_sort(A)
print(*A)
print(count)
| #!/usr/bin/env python3
import sys
import collections as cl
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
N = input()
print("No" if N[0] == N[1] == N[2] else "Yes")
main()
| 0 | null | 27,223,403,832,800 | 15 | 201 |
N,M = map(int,input().split())
array = list(map(int,input().split()))
total = sum(array)
count = 0
for i in range(N):
if array[i] < total / (4*M) :
continue
else:
count += 1
print('Yes' if count >= M else 'No') | n, m = map(int, input().split())
a = [int(x) for x in input().split()]
s = sum(a)
print('Yes' if len(list(filter(lambda x : x >= s * (1/(4*m)), a))) >= m else 'No') | 1 | 38,532,234,954,432 | null | 179 | 179 |
o = ['No','Yes']
f = 0
N = input()
s = str(N)
for c in s:
t = int(c)
if t == 7:
f = 1
print(o[f]) | N, M, Q = map(int, input().split())
res = 0
def dfs(L: list):
global res
A = L[::]
if len(A) == N + 1:
now = 0
for i in range(Q):
if A[b[i]] - A[a[i]] == c[i]:
now += d[i]
res = max(res, now)
# print(A, now)
return
A.append(A[-1])
while A[-1] <= M:
dfs(A)
A[-1] += 1
a, b, c, d = [], [], [], []
for _ in range(Q):
_a, _b, _c, _d = map(int, input().split())
a.append(_a)
b.append(_b)
c.append(_c)
d.append(_d)
dfs([1])
print(res)
| 0 | null | 30,930,382,600,620 | 172 | 160 |
S=list(str(input()))
for i in range(len(S)):
S[i]='x'
print(''.join(S)) | def main():
A,B,C = map(int,input().split())
K = int(input())
num = 0
while (B <= A):
num += 1
if num <= K:
B *= 2
else:
return ("No")
while (C <= B):
num += 1
if num <= K:
C *= 2
else:
return ('No')
return('Yes')
print(main())
| 0 | null | 39,915,055,255,218 | 221 | 101 |
t = input()
ans = ""
for i in range(len(t)):
if t[i] != '?':
ans += t[i]
else:
ans += 'D'
print(ans) | import sys
from collections import Counter
S = ""
for s in sys.stdin:
s = s.strip().lower()
if not s:
break
S += s
for i in 'abcdefghijklmnopqrstuvwxyz':
print(i, ":", S.count(i))
| 0 | null | 9,984,529,086,350 | 140 | 63 |
name=input()
l=len(name)
if (l>=3)and(l<=20):
print(name[:3]) | x,y = map(int,input().split())
A = y//2
B = (x-A)
while A>-1:
if y==2*A + 4*B:
print("Yes")
break
A = A-1
B = B+1
if A==-1:
print("No") | 0 | null | 14,414,570,930,404 | 130 | 127 |
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
k = ri()
a, b = rl()
for i in range(k, 1001, k):
if a <= i <= b:
print ("OK")
return
print ("NG")
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
| def Qa():
k = int(input())
a, b = map(int, input().split())
lis = range(a, b + 1)
ans = 'NG'
for v in lis:
if v % k == 0:
ans = 'OK'
print(ans)
if __name__ == '__main__':
Qa()
| 1 | 26,491,255,848,448 | null | 158 | 158 |
a, b = map(int, input().split())
d = a // b
r = a % b
f = a / b
print(d, r, '{:.5f}'.format(f))
| x = input().split()
x_int = [int(i) for i in x]
d = x_int[0]//x_int[1]
r = x_int[0] % x_int[1]
f = (x_int[0]) / (x_int[1])
print('{0} {1} {2:f}'.format(d,r,f)) | 1 | 609,915,699,140 | null | 45 | 45 |
N, K = map(int, input().split())
mod = 1000000007
ans = 0
for i in range(K, N+1+1):
num_min = i*(i-1)//2
num_max = i*(N+N-i+1)//2
# print(num_min, num_max)
ans += (num_max - num_min + 1)%mod
print(ans%mod) | n = input()
debt = 100000
for i in range(n):
debt *= 1.05
if(debt % 1000):
debt -= debt % 1000
debt += 1000
print(int(debt)) | 0 | null | 16,475,010,528,912 | 170 | 6 |
#全点対間最短経路を求めるアルゴリズム
def warshall_floyd(d):
#d[i][j]:iからjに行く最短経路
for k in range(1,n+1):
for i in range(1,n+1):
for j in range(1,n+1):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
return d
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)
n, m , l = map(int, input().split())
INF = 10 ** 11
d = [[INF]*(n+1) for _ in range(n+1)]
for i in range(m):
x, y, z = map(int, input().split())
if z <= l:
d[x][y] = z
d[y][x] = z #無向グラフならつける
for i in range(1,n+1):
d[i][i] = 0
ss = warshall_floyd(d)
for i in range(1,n+1):
for j in range(1,n+1):
if ss[i][j] <= l:
ss[i][j] = 1
#補給回数
vv = warshall_floyd(ss)
for i in range(1,n+1):
for j in range(1,n+1):
if vv[i][j] == INF:
vv[i][j] = -1
q = int(input())
for _ in range(q):
x, y = map(int, input().split())
if vv[x][y] != -1:
print(vv[x][y]-1)
else:
print(vv[x][y]) | from math import gcd
def main():
K = int(input())
ans = 0
for i in range(1, K+1):
for j in range(1, K+1):
temp = gcd(i, j)
for l in range(1, K+1):
ans += gcd(temp, l)
print(ans)
if __name__ == '__main__':
main() | 0 | null | 104,783,979,670,732 | 295 | 174 |
n=int(input())
a=list(map(int,input().split()))
ans=[0 for s in range(n)]
for i in range(n-1):
x = int(a[i])
ans[x-1] +=1
for j in range(n):
print(ans[j]) | A1, A2, A3 = map(int, input().split())
print('win') if A1 + A2 + A3 <= 21 else print('bust') | 0 | null | 75,508,709,037,498 | 169 | 260 |
s = str(input())
t = str(input())
ans = len(t)
for i in range(len(s) - len(t) + 1):
tmp_ans = 0
for j in range(len(t)):
if s[i+j] != t[j]:
tmp_ans += 1
ans = min(ans, tmp_ans)
print(ans) | S = input()
T = input()
ans = len(S)
for i in range(len(S)-len(T)+1):
tmp = 0
for j in range(len(T)):
if S[i+j] != T[j]:
tmp += 1
ans = min(ans, tmp)
print(ans) | 1 | 3,709,072,632,640 | null | 82 | 82 |
a, b, c = map(int, input().split())
x = c-a-b
if x <= 0:
print('No')
elif 4*a*b < x*x:
print('Yes')
else:
print('No') | from decimal import Decimal
a,b,c = map(int,input().split())
a = Decimal(a)
b = Decimal(b)
c = Decimal(c)
if Decimal.sqrt(a) + Decimal.sqrt(b) < Decimal.sqrt(c):
print('Yes')
else:
print('No') | 1 | 51,703,369,341,728 | null | 197 | 197 |
x, k, d = map(int, input().split())
x = abs(x)
num = x // d
if num >= k:
ans = x - k*d
else:
if (k-num)%2 == 0:
ans = x - num*d
else:
ans = min(abs(x - num*d - d), abs(x - num*d + d))
print(ans) | n=int(input())
if n==2:
count=1
else:
count=2
for i in range(2,int(n**0.5)+1):
if n%i==0:
k=n//i
while k>0:
if k%i==0:
k=k//i
else:
if k%i==1:
count+=1
break
elif (n-1)%i==0:
count+=1
if i!=(n-1)//i:
count+=1
print(count)
| 0 | null | 23,151,196,686,812 | 92 | 183 |
import sys
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
H,W = map(int,readline().split())
grid = ''
grid += '#'* (W+2)
for _ in range(H):
grid += '#' + readline().decode().rstrip() + '#'
grid += '#'*(W+2)
L = len(grid)
INF = float('inf')
def bfs(start):
dist = [-INF] * L
q = [start]
dist[start] = 0
while q:
qq = []
for x,dx in itertools.product(q,[1,-1,W+2,-W-2]):
y = x+dx
if dist[y] != -INF or grid[y] == '#':
continue
dist[y] = dist[x] + 1
qq.append(y)
q = qq
return max(dist)
ans = 0
for i in range(L):
if grid[i] == '.':
start = i
max_dist = bfs(start)
ans = max(ans,max_dist)
print(ans) | from itertools import product
h, w = map(int, input().split())
maze = [input() for _ in range(h)]
def neighbors(ih, iw):
for ih1, iw1 in (
(ih - 1, iw),
(ih + 1, iw),
(ih, iw - 1),
(ih, iw + 1),
):
if 0 <= ih1 < h and 0 <= iw1 < w and maze[ih1][iw1] == '.':
yield (ih1, iw1)
def len_maze(ih, iw):
# BFS
if maze[ih][iw] == '#':
return 0
stepped = [[False] * w for _ in range(h)]
q0 = [(ih, iw)]
l = -1
while q0:
q1 = set()
for ih0, iw0 in q0:
stepped[ih0][iw0] = True
for ih1, iw1 in neighbors(ih0, iw0):
if not stepped[ih1][iw1]:
q1.add((ih1, iw1))
q0 = list(q1)
l += 1
return l
answer = max(len_maze(ih, iw) for ih, iw in product(range(h), range(w)))
print(answer)
| 1 | 94,974,173,068,150 | null | 241 | 241 |
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
#from collections import deque
#import heapq
#from fractions import gcd
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=1
d={x:0 for x in range(n)}
for i in range(n):
if a[i]==0:
d[0]+=1
else:
m=a[i]
ans=(ans*(d[m-1]-d[m]))%mod
if ans<=0:
print(0)
exit()
d[m]+=1
if d[a[i]]>3:
print(0)
exit()
if d[0]==1:
print(ans*3%mod)
elif d[0]==2:
print(ans*6%mod)
elif d[0]==3:
print(ans*6%mod) | n = list(map(int, input().split()))
a = n[0]
b = n[1]
d = a // b
r = a % b
f = a / b
print('{} {} {:.5f}'.format(d, r, f)) | 0 | null | 65,476,872,718,360 | 268 | 45 |
import math
I = lambda: list(map(int, input().split()))
n, d, a = I()
l = []
for _ in range(n):
x, y = I()
l.append([x,y])
l.sort()
j = 0
limit = []
for i in range(n):
while l[j][0] - l[i][0] <= 2*d:
j+=1
if j == n: break
j-=1
limit.append(j)
ans = 0
num=[0]*(n+1)
cnt=0
for i in range(n):
l[i][1]-=(ans-cnt)*a
damage_cnt=max(0,(l[i][1]-1)//a + 1)
ans+=damage_cnt
num[limit[i]]+=damage_cnt
cnt+=num[i]
print(ans) | S=[]
T=[]
S_num=int(input())
S=input().split()
T_num=int(input())
T=input().split()
cnt=0
for i in range(T_num):
for j in range(S_num):
if(S[j]==T[i]):
cnt+=1
break
print(cnt)
| 0 | null | 41,143,604,297,060 | 230 | 22 |
from itertools import accumulate
N, K = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(lambda x: (x+1)/2, P))
Q_cum = list(accumulate([0] + Q))
res = 0
for i in range(N-K+1):
temp = Q_cum[i+K]- Q_cum[i]
res = max(res, temp)
print(res) | N, K = map(int, input().split())
p = list(map(int, input().split()))
import numpy as np
data = np.array(p) + 1
Pcum = np.zeros(N + 1, np.int32)
Pcum[1:] = data.cumsum()
length_K_sums = Pcum[K:] - Pcum[0:-K]
print(np.max(length_K_sums)/2)
| 1 | 74,673,462,184,932 | null | 223 | 223 |
#---------------------------------------------------------------
# coding: utf-8
# Python 3+
import sys
#file = open("test.txt")
file = sys.stdin
a, b, c = map(int, file.readline().split())
if a < b < c :
print("Yes")
else :
print("No") | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.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
t1, t2 = LI()
a1, a2 = LI()
b1, b2 = LI()
p = (a1 - b1) * t1
q = (a2 - b2) * t2
if p > 0:
p = -p
q = -q
if p + q == 0:
print('infinity')
elif p + q < 0:
print(0)
else:
print((-p // (p + q)) * 2 + bool(-p % (p + q))) | 0 | null | 65,710,644,789,882 | 39 | 269 |
A, B, C, K = map(int, input().split())
if A >= K:
print(K)
else:
K = K - A
if B >= K:
print(A)
else:
K = K - B
print(A - K) |
a,b,c,k = map(int,input().split())
ans = min(a,k)
k -= ans
if k == 0:
print(ans)
exit(0)
k -= min(b,k)
if k == 0:
print(ans)
exit(0)
ans -= min(c,k)
print(ans) | 1 | 21,882,100,839,600 | null | 148 | 148 |
N, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
s = 0
for i in h:
if i >= k:
s += 1
print(s) | def main():
n, k = map(int,input().split())
inlis = list(map(int, input().split()))
ans = 0
for i in range(n):
if inlis[i] >= k:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| 1 | 178,209,992,799,940 | null | 298 | 298 |
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.sort()
h.reverse()
if k>n:
k=n
for i in range (k):
h[i] = 0
print(sum(h)) | input_line = input().split()
a = int(input_line[0])
b = int(input_line[1])
if a > b:
symbol = ">"
elif a < b:
symbol = "<"
else:
symbol = "=="
print("a",symbol,"b") | 0 | null | 39,460,482,576,170 | 227 | 38 |
X = int(input())
for i in range(1,1000000000):
if ( X * i ) % 360 == 0:
print(i)
quit()
| from math import gcd
s = int(input())
print(360//gcd(360,s)) | 1 | 13,251,218,181,152 | null | 125 | 125 |
r = input()
if len(r) & 1:
print("No")
else:
for i in range(0, len(r), 2):
if not (r[i] == 'h' and r[i + 1]=='i'):
print("No")
exit()
print("Yes") | 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())
N = NI()
N0 = 2**(N.bit_length())
st = [0] * (N0*2)
def gindex(l, r):
L = l + N0; R = r + N0
lm = (L // (L & -L)) // 2
rm = (R // (R & -R)) // 2
while L < R:
if R <= rm:
yield R - 1
if L <= lm:
yield L - 1
L //= 2; R //= 2
while L > 0:
yield L - 1
L //= 2
def update(i,s):
x = 2 ** (ord(s) - ord('a'))
i += N0-1
st[i] = x
while i > 0:
i = (i-1) // 2
st[i] = st[i*2+1] | st[i*2+2]
def query(l,r):
l += N0
r += N0
ret = 0
while l < r:
if l % 2:
ret |= st[l-1]
l += 1
if r % 2:
r -= 1
ret |= st[r-1]
l //= 2 ; r //= 2
return ret
for i,s in enumerate(sys.stdin.readline().rstrip()):
update(i+1,s)
Q = NI()
for _ in range(Q):
c,a,b = sys.stdin.readline().split()
if c == '1':
update(int(a),b)
else:
ret = query(int(a),int(b)+1)
cnt = 0
b = 1
for i in range(26):
cnt += (b & ret) > 0
b <<= 1
print(cnt)
if __name__ == '__main__':
main() | 0 | null | 58,104,781,225,568 | 199 | 210 |
mod=998244353
n,s=map(int,input().split())
ar=list(map(int,input().split()))
dp=[0 for y in range(s+1)]
dp[0]=1
for i in range(n):
for j in range(s,-1,-1):
if j+ar[i]<=s:
dp[j+ar[i]]=(dp[j]+dp[j+ar[i]])%mod
dp[j]=(dp[j]*2)%mod
print(dp[s])
| import random
class Dice(object):
def __init__(self, *args):
self.faces = [None]
self.faces.extend(args)
self.top = self.faces[1]
self.up = self.faces[5]
self.down = self.faces[2]
self.left = self.faces[4]
self.right = self.faces[3]
def roll(self, direction):
if direction == "N":
self.top, self.up, self.down = self.down, self.top, self.faces[7 - self.faces.index(self.top)]
elif direction == "S":
self.top, self.up, self.down = self.up, self.faces[7 - self.faces.index(self.top)], self.top
elif direction == "W":
self.top, self.left, self.right = self.right, self.top, self.faces[7 - self.faces.index(self.top)]
elif direction == "E":
self.top, self.left, self.right = self.left, self.faces[7 - self.faces.index(self.top)], self.top
else:
raise ValueError("{} is not valid direction.".format(direction))
f = [int(i) for i in input().split()]
dice = Dice(*f)
n = int(input())
for i in range(n):
top, down = [int(i) for i in input().split()]
while dice.top != top:
dice.roll(random.choice("NSWE"))
if dice.down == down:
print(dice.right)
elif dice.right == down:
print(dice.up)
elif dice.up == down:
print(dice.left)
elif dice.left == down:
print(dice.down)
else:
raise ValueError()
| 0 | null | 9,004,495,859,960 | 138 | 34 |
def main():
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
dp = [[0] * (S+5) for _ in range(N+5)]
dp[0][0] = 1
for i in range(N):
for j in range(S+1):
dp[i+1][j] += 2 * dp[i][j]
dp[i+1][j] %= MOD
if j + A[i] <= S:
dp[i+1][j+A[i]] += dp[i][j]
dp[i+1][j+A[i]] %= MOD
print(dp[N][S])
if __name__ == "__main__":
main() | from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=10**19
###############################################################################\n=17
d,t,s=INPUT()
if d/s<=t:
print("Yes")
else:
print("No")
| 0 | null | 10,707,463,923,904 | 138 | 81 |
from collections import defaultdict
BS, SL = '\\', '/'
diagram = list(input())
flood = defaultdict(int)
total = 0
stack = []
for cur, terrain in enumerate(diagram):
if terrain == BS:
stack.append(cur)
elif terrain == SL and stack:
first = stack.pop()
water = cur-first
total += water
for (f_first, f_last) in list(flood):
if first < f_first < cur:
flood[(first, cur)] += flood.pop((f_first, f_last))
flood[(first, cur)] += water
print(total)
print(' '.join(map(str, [len(flood)] + list(flood.values()))))
| downs, ponds = [], []
for i, s in enumerate(input()):
if s == "\\":
downs.append(i)
elif s == "/" and downs:
i_down = downs.pop()
area = i - i_down
while ponds and ponds[-1][0] > i_down:
area += ponds.pop()[1]
ponds.append([i_down, area])
print(sum(p[1] for p in ponds))
print(len(ponds), *(p[1] for p in ponds))
| 1 | 58,699,071,392 | null | 21 | 21 |
INF = int(1e18)
def merge(A, left, mid, right):
n1 = mid - left
n2 = right - mid
L = [A[left + i] for i in range(n1)]
R = [A[mid + i] for i in range(n2)]
L.append(INF)
R.append(INF)
i, j = 0, 0
count = 0
for k in range(left, right):
count += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return count
def merge_sort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
c1 = merge_sort(A, left, mid)
c2 = merge_sort(A, mid, right)
c = merge(A, left, mid, right)
return c + c1 + c2
else:
return 0
if __name__ == '__main__':
n = int(input())
A = list(map(int, input().split()))
c = merge_sort(A, 0, n)
print(" ".join(map(str, A)))
print(c)
| w = input()
t = []
while True:
s = [1 if i.lower() == w else 'fin' if i == 'END_OF_TEXT' else 0 for i in input().split()]
t += s
if 'fin' in s:
break
print(t.count(1))
| 0 | null | 959,754,153,804 | 26 | 65 |
n = int(input())
a,b = divmod(n,2)
if b == 0:
a -= 1
print(a) | N = int(input())
if N % 2 == 0:
ans = (N // 2) - 1
ans = (N // 2) - 1
else:
ans = (N - 1) // 2
print(ans)
| 1 | 153,704,850,319,008 | null | 283 | 283 |
h, w = map(int, input().split())
s = [input() for _ in range(h)]
m = [[-1]*w for _ in range(h)]
def dp(x, y):
if m[x][y] == -1:
if x == 0 and y == 0:
m[x][y] = 1 if s[x][y] == "#" else 0
elif x == 0:
a = dp(x, y-1)
m[x][y] = a+1 if s[x][y] == "#" and s[x][y-1] == "." else a
elif y == 0:
b = dp(x-1, y)
m[x][y] = b+1 if s[x][y] == "#" and s[x-1][y] == "." else b
else:
a = dp(x, y-1)
b = dp(x-1, y)
c = a+1 if s[x][y] == "#" and s[x][y-1] == "." else a
d = b+1 if s[x][y] == "#" and s[x-1][y] == "." else b
m[x][y] = min(c, d)
return m[x][y]
print(dp(h-1, w-1)) | n=int(input())
ans =0
for i in range(2,int(n**0.5)+5):
cnt = 0
while n%i==0:
n//=i
cnt += 1
s=1
while cnt-s>=0:
cnt -= s
s +=1
ans += 1
if n!=1:ans+=1
print(ans)
| 0 | null | 33,308,126,672,482 | 194 | 136 |
import sys
print('Yes' if len(set(sys.stdin.read().strip())) >= 2 else 'No') | S = input()
T = input()
ans = 1001
for i in range(len(S)-len(T)+1):
ans = min(ans, sum(S[i+j] != T[j] for j in range(len(T))))
print(ans) | 0 | null | 29,106,119,706,646 | 201 | 82 |
n, m = map(int, input().split())
temp = list(['?'] * n)
# print(temp)
if (m == 0):
if (n == 1):
ans = 0
else:
ans = '1' + '0' * (n - 1)
else:
for _ in range(m):
s, c = map(int, input().split())
if (s == 1 and c == 0 and n >= 2):
print(-1)
exit()
else:
pass
if (temp[s-1] == '?'):
temp[s - 1] = str(c)
elif (temp[s - 1] == str(c)):
pass
else:
print(-1)
exit()
if (temp[0] == '?'):
temp[0] = '1'
ans01 = ''.join(temp)
ans = ans01.replace('?', '0')
print(ans)
| n,m = map(int,input().split())
c1 = []
c2 = []
c3 = []
for i in range(m):
sc = list(map(int,input().split()))
if sc[0] == 1:
c1.append(sc[1])
elif sc[0] == 2:
c2.append(sc[1])
else:
c3.append(sc[1])
if len(set(c1)) <= 1 and len(set(c2)) <= 1 and len(set(c3)) <= 1:
if 0 in list(set(c1)):
if n == 1 and len(set(c1)) == 1 and len(set(c2)) == 0 and len(set(c3)) == 0:
print('0')
exit()
else:
print('-1')
exit()
elif not c1 and not c2 and not c3:
if n == 1:
print('0')
exit()
elif n == 2:
print('10')
exit()
else:
print('100')
exit()
else:
if list(set(c1)):
ans_c1 = list(set(c1))[0]
else:
ans_c1 = 1
if list(set(c2)):
ans_c2 = list(set(c2))[0]
else:
ans_c2 = 0
if list(set(c3)):
ans_c3 = list(set(c3))[0]
else:
ans_c3 = 0
else:
print('-1')
exit()
if n == 1:
print(ans_c1)
elif n == 2:
print(ans_c1*10 + ans_c2)
else:
print(ans_c1*100 + ans_c2*10 + ans_c3) | 1 | 60,419,097,425,268 | null | 208 | 208 |
def solve():
S,T = input().split()
A,B = [int(i) for i in input().split()]
U = input()
if U == S:
print(A-1, B)
else:
print(A, B-1)
if __name__ == "__main__":
solve() | s, t = input().split()
a, b = map(int, input().split())
if s == input():
a -= 1
else:
b -= 1
print("{} {}".format(a, b)) | 1 | 72,142,544,235,524 | null | 220 | 220 |
A = int(input())
print(A//2+A%2) | d = int(input())
if d % 2 == 0:
print(d//2)
else:
print((d//2)+1) | 1 | 59,122,430,563,520 | null | 206 | 206 |
h = int(input())
w = int(input())
n = int(input())
total = h*w
kesu = max(h, w)
if n%kesu==0:
print(n//kesu)
else:
print(n // kesu + 1) | H = int(input())
W = int(input())
N = int(input())
for i in range(min(H,W)):
N -= max(H, W)
if N <= 0:
print(i+1)
exit() | 1 | 89,089,150,632,428 | null | 236 | 236 |
pi = 3.14159265359
r = float(input())
a,d = r*r*pi,2*r*pi
print(a,d,sep=' ') | import math
r = float(input())
print('%.5f' % (r * r * math.pi), '%.5f' % (2 * math.pi * r)) | 1 | 647,238,723,702 | null | 46 | 46 |
from collections import defaultdict
def main():
N, P = map(int, input().split())
S = list(map(int,list(input())))
S_mod = [0] * N
if P == 2:
for i in range(N-1,-1,-1):
if S[i] % 2 == 0:
S_mod[i] = 1
S_mod.reverse()
ans = 0
cnt = 0
for i in range(N):
if S_mod[i] == 1:
cnt += 1
ans += cnt
else:
ans += cnt
print(ans)
exit()
if P == 5:
for i in range(N-1,-1,-1):
if S[i] % 5 == 0:
S_mod[i] = 1
S_mod.reverse()
ans = 0
cnt = 0
for i in range(N):
if S_mod[i] == 1:
cnt += 1
ans += cnt
else:
ans += cnt
print(ans)
exit()
ten = 1
for i in range(N-1,-1,-1):
S_mod[i] = (S[i] * ten) % P
ten *= 10
ten %= P
S_mod.reverse()
S_acc = [0] * (N+1)
for i in range(N):
S_acc[i+1] = (S_acc[i] + S_mod[i]) % P
d = defaultdict(int)
for i in range(N+1):
d[S_acc[i]] += 1
ans = 0
for i, j in d.items():
if j >= 2:
ans += (j * (j-1)) // 2
print(ans)
if __name__ == "__main__":
main() | #http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_4_A
#?????¢??¢?´¢
#???????????§?¨????????????????????????¨?????§??????????????\????????????????????????????????????
def linear_search(list_1, list_2):
count = 0
for a in list_1:
i = 0
list_2.append(a)
while not a == list_2[i]:
i += 1
if not i == len(list_2) - 1:
count += 1
list_2 = list_2[:-1]
return count
def main():
n_listA = int(input())
a = list(set([n for n in input().split()]))
n_listB = int(input())
b = list(set([n for n in input().split()]))
print(linear_search(a,b))
if __name__ == "__main__":
main() | 0 | null | 29,295,555,581,694 | 205 | 22 |
(a, b, c) = map(lambda s:int(s), input().split())
r = 0
for n in range(a, b+1):
if c % n == 0:
r += 1
print(r) | f=lambda:map(int,input().split())
n,st,sa=f()
g=[set() for _ in range(n)]
for _ in range(n-1):
a,b=f()
g[a-1].add(b-1)
g[b-1].add(a-1)
def bfs(s):
l=[-1]*n; l[s]=0; q=[s]
while q:
v=q.pop(); d=l[v]+1
for c in g[v]:
if l[c]<0: l[c]=d; q+=[c]
return l
lt=bfs(st-1)
la=bfs(sa-1)
print(max(la[i] for i in range(n) if lt[i]<la[i])-1) | 0 | null | 59,265,442,250,280 | 44 | 259 |
n = int(input())
res = 0
a = n // 500
n %= 500
b = n // 5
print(1000*a + 5*b) | while True:
inputs = input().split(' ')
a = int(inputs[0])
op = inputs[1]
b = int(inputs[2])
if op == "?":
break
elif op == "+": # (和)
print(a + b)
elif op == "-": # (差)
print(a - b)
elif op == "*": #(積)
print(a * b)
else: # "/"(商)
print(a // b)
| 0 | null | 21,799,939,412,764 | 185 | 47 |
import sys
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
n, k, s = nm()
ans_h = [str(s) for _ in range(k)]
if s==10**9 :
ans_t = ['1' for _ in range(n-k)]
else:
ans_t = [str(s+1) for _ in range(n-k)]
print(' '.join(ans_h + ans_t)) |
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
ub = 10 ** 12 + 10
lb = 0
while ub - lb > 1:
mid = (ub + lb) // 2
cnt = 0
for x, y in zip(A, F):
res = max(0, x * y - mid)
cnt += -(-res // y)
if cnt <= K:
ub = mid
else:
lb = mid
if sum(A) <= K:
print(0)
else:
print(ub)
| 0 | null | 127,579,951,650,402 | 238 | 290 |
while 1:
a,b = sorted(map(int, raw_input().split(' ')))
if a or b:
print a, b
else:
break | def swap(a, b ,item):
c = item[a]
item[a] = item[b]
item[b] = c
AB = input().split()
a = int(AB[0])
b = int(AB[1])
while a!=0 or b!=0:
if a>b:
swap(0, 1, AB)
print(int(AB[0]), int(AB[1]))
AB = input().split()
a = int(AB[0])
b = int(AB[1]) | 1 | 514,161,917,190 | null | 43 | 43 |
s=input()
ans=0
tmp=0
for i in s:
if i=='R':
tmp+=1
else:
ans=max(ans,tmp)
tmp=0
print(max(ans,tmp))
| num = input()
streaks = []
streak = 0
for letter in num:
if letter == "R":
streak += 1
elif letter != "R":
streaks.append(streak)
streak = 0
else:
streaks.append(streak)
print(max(streaks)) | 1 | 4,882,390,028,012 | null | 90 | 90 |
n,d = map(int, input().split())
x = []
y = []
for i in range(n):
a,b = map(int, input().split())
x.append(a)
y.append(b)
count = 0
for i in range(n):
if (x[i]**2 + y[i]**2)**(1/ 2) <= d:
count += 1
print(count) | import math
N,D = map(int,input().split())
X = [None]*N
Y = [None]*N
for i in range(N):
X[i],Y[i] = map(int,input().split())
ans=0
for i in range(N):
if(math.sqrt(X[i]**2+Y[i]**2) <=D):
ans+=1
print(ans)
| 1 | 5,896,396,083,422 | null | 96 | 96 |
def main():
N = int(input())
L = []
for i in range(N):
xi, li = map(int, input().split())
s = xi - li
f = xi + li
L.append((f, s))
L.sort()
ans = 0
finish = -float("inf")
for i in L:
if finish <= i[1]:
ans += 1
finish = i[0]
print(ans)
if __name__ == "__main__":
main()
| from operator import itemgetter
n = int(input())
lis = []
for _ in range(n):
x,l = map(int,input().split())
lis.append([x-l,x+l])
lis.sort(key = itemgetter(1))
ans = 0
last = -float("inf")
for i in range(n):
if lis[i][0] >= last:
ans += 1
last = lis[i][1]
print(ans) | 1 | 89,982,013,830,036 | null | 237 | 237 |
def resolve():
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y, c = [], [], []
dis = []
for i in range(M):
xt, yt, ct = list(map(int, input().split()))
dis.append(a[xt-1] + b[yt-1] - ct)
x.append(xt)
y.append(yt)
c.append(ct)
a.sort()
b.sort()
dis.sort()
ans = min(a[0] + b[0], dis[0])
print(ans)
return
resolve() | a,b,m = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Min = (min(A)+min(B))
for _ in range(m):
x,y,c = map(int,input().split())
if Min > A[x-1]+B[y-1]-c:
Min=A[x-1]+B[y-1]-c
print(Min) | 1 | 53,827,387,191,328 | null | 200 | 200 |
n,m,l = [int(x) for x in input().split()]
A = [[int(x) for x in input().split()] for _ in range(n)]
B = [[int(x) for x in input().split()] for _ in range(m)]
ans = []
for i in range(n):
blocks = []
for j in range(l):
block = 0
for k in range(m):
block += A[i][k]*B[k][j]
blocks.append(block)
ans.append(blocks)
for _ in ans:
print(*_)
| N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [0] * (S+1)
dp[0] = 1
for a in A:
for j in range(S, -1, -1):
if j-a >= 0:
dp[j] = dp[j]*2 + dp[j-a]
else:
dp[j] = dp[j]*2
print(dp[S]%mod) | 0 | null | 9,550,740,473,532 | 60 | 138 |
n=int(input())
print((n//2)+(n%2)) | import math
n = int(input())
print(2 * n * math.pi) | 0 | null | 45,321,045,359,228 | 206 | 167 |
num=int(input())
r_1=int(input())
r_2=int(input())
max_profit=r_2-r_1
if r_1<r_2:
min_value=r_1
else:
min_value=r_2
for i in range(2,num):
x=int(input())
t=x-min_value
if max_profit<t:
max_profit=t
if x<min_value:
min_value=x
print(max_profit) | n = int(raw_input())
r = []
for i in range(n):
r.append(int(raw_input()))
min_v = r[0]
max_profit = -1000000000000
for i in range(1,n):
if max_profit < r[i] - min_v:
max_profit = r[i]-min_v
if r[i] < min_v:
min_v = r[i]
print max_profit | 1 | 13,372,456,900 | null | 13 | 13 |
from collections import deque
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
tree=[[]for _ in range(n)]
for a,b in l:
a-=1
b-=1
tree[a].append(b)
tree[b].append(b)
ans_num=0
for i in tree:
ans_num=max(ans_num,len(i))
dq=deque()
dq.append((0,0))
seen=set()
seen.add(0)
ans_dict={}
while dq:
x,color=dq.popleft()
i=0
for nx in tree[x]:
if nx in seen:
continue
i+=1
if i==color:
i+=1
seen.add(nx)
dq.append((nx,i)),
ans_dict[x+1,nx+1]=i
ans_dict[nx+1,x+1]=i
print(ans_num)
for i in l:
print(ans_dict[tuple(i)]) | import sys
sys.setrecursionlimit(9**9)
n=int(input())
T=[[] for _ in range(n)]
for i in range(n-1):
a,b=map(int,input().split())
T[a-1].append([b-1,i])
C=[0]*(n-1)
def f(i,r):
c=1
for (x,y) in T[i]:
c+=(c==r)
C[y]=c
f(x,c)
c+=1
f(0,0)
print(max(C))
for c in C:
print(c) | 1 | 135,515,382,201,472 | null | 272 | 272 |
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) | def main():
import sys
input = sys.stdin.readline
N = int(input())
arms = []
for i in range(N):
x, l = map(int,input().split())
t = min(x+l,10**9)
s = max(x-l,0)
arms.append((t,s))
arms.sort()
ans = 0
tmp = -1
for t,s in arms:
if s >= tmp:
tmp = t
ans += 1
print(ans)
main() | 0 | null | 45,364,375,650,960 | 56 | 237 |
n = int(input())
hats = list(map(int, input().split()))
mod = 1000000007
cnt = [0] * 3
ans = 1
for i in range(n):
count = 0
minj = 4
for j in range(3):
if hats[i] == cnt[j]:
count += 1
minj = min(minj, j)
if count == 0:
ans = 0
break
cnt[minj] += 1
ans = ans * count % mod
print(ans) | N,K = map(int,input().split())
for i in range(N):
if N >=K**i and N <K**(i+1):
print(i+1)
break | 0 | null | 97,777,875,286,910 | 268 | 212 |
k,x = [int(i) for i in input().split()]
ans=''
if k*500 >= x: ans = 'Yes'
else: ans='No'
print(ans)
| a,b=map(int,input().split())
print("Yes" if (a*500>=b) else "No") | 1 | 98,297,444,852,640 | null | 244 | 244 |
from collections import Counter
def dis(i,j, x,y):
return min(j-i, abs(x-i)+1+abs(j-y), abs(y-i)+1+(j-x))
n, x, y = map(int, input().split())
x,y = x-1,y-1
D = []
for i in range(n-1):
for j in range(i+1, n):
D.append(dis(i,j, x,y))
cD = Counter(D)
for i in range(1, n):
print(cD[i]) | from collections import deque, defaultdict
def main():
N, X, Y = map(int, input().split())
g = [[] for _ in range(N)]
for i in range(N-1):
g[i].append(i+1)
g[i+1].append(i)
g[X-1].append(Y-1)
g[Y-1].append(X-1)
ans = defaultdict(int)
for i in range(N):
q = deque()
q.append(i)
visit_time = [0 for _ in range(N)]
while len(q):
v = q.popleft()
time = visit_time[v]
for j in g[v]:
if visit_time[j] == 0 and j != i:
q.append(j)
visit_time[j] = time + 1
else:
visit_time[j] = min(time + 1, visit_time[j])
for v in visit_time:
ans[v] += 1
for i in range(1, N):
print(ans[i] // 2)
if __name__ == '__main__':
main()
| 1 | 44,387,939,442,420 | null | 187 | 187 |
H, N = map(int, input().split())
A = map(int, input().split())
print("Yes" if H <= sum(A) else "No") | n = int(input())
a = list(map(int,input().split()))
ans = [0]*(n+1)
a.insert(0,0)
for i in range(1,n+1):
ans[a[i]] += i
ans.pop(0)
ans = [str(ans[s]) for s in range(n)]
print(" ".join(ans)) | 0 | null | 129,817,436,510,412 | 226 | 299 |
N=2*10**5+1
mod=10**9+7
f=[None]*N
fi=[None]*N
f[0]=1
for i in range(1,N):
f[i]=i*f[i-1]%mod
for i in range(N):
fi[i]=pow(f[i],mod-2,mod)
def com(n,k):
return f[n]*fi[n-k]%mod*fi[k]%mod
def hcom(n,k):
return com(n+k-1,n-1)
n,k=map(int,input().split())
ans=1
for i in range(1,min(k+1,n)):
ans=(ans+com(n,i)*hcom(n-i,i)%mod)%mod
print(ans) | #coding:utf-8
n = int(input())
numbers = list(map(int, input().split()))
def selectionSort(ary):
count = 0
for i in range(len(ary)):
minj = i
for j in range(i, len(ary)):
if ary[minj] > ary[j]:
minj = j
if minj != i:
ary[minj], ary[i] = ary[i], ary[minj]
count += 1
return (ary, count)
result = selectionSort(numbers)
print(*result[0])
print(result[1]) | 0 | null | 33,651,665,250,820 | 215 | 15 |
def main():
N, K = (int(x) for x in input().split())
scores = [int(x) for x in input().split()]
first, last = 0, K-1
while last < N-1:
last += 1
if scores[first] < scores[last]: print('Yes')
else: print('No')
first += 1
if __name__ == '__main__':
main() | N,M=map(int,input().split())
A_M=list(map(int,input().split()))
if N >= sum(A_M):
print(N-sum(A_M))
else:
print(-1) | 0 | null | 19,652,351,088,420 | 102 | 168 |
def base_10_to_n(x, n):
ans = []
while x > 0:
x -= 1
ans.append(str(x % n + 1))
x //= n
return ans[::-1]
a = base_10_to_n(int(input()), 26)
ans1 = ''
for i in a:
ans1 += chr(ord('a') + int(i) - 1)
print(ans1)
| def main():
n, k = map(int, input().split())
h_lst = list(map(int, input().split()))
ans = 0
for h in h_lst:
if h >= k:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 95,251,518,609,490 | 121 | 298 |
N = int(input())
from itertools import permutations
P=tuple(map(int, input().split()))
Q=tuple(map(int, input().split()))
A=list(permutations([i for i in range(1, N+1)]))
a=A.index(P)
b=A.index(Q)
print(abs(a-b)) | #C - Count Order
#DFS
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
a = 0
b = 0
cnt = 0
def dfs(A):
global cnt
global a
global b
if len(A) == N:
cnt += 1
if A == P:
a = cnt
if A == Q:
b = cnt
return
for v in range(1,N+1):
if v in A:
continue
A.append(v)
dfs(A)
A.pop()
dfs([])
print(abs(a-b)) | 1 | 100,311,551,562,808 | null | 246 | 246 |
def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
N=II()
A=LI()
cnt=[0]*((10**6)+1)
for elem in A:
cnt[elem]+=1
unique=[]
for i in range((10**6)+1):
if cnt[i]==1:
unique.append(i)
cnt=[0]*((10**6)+1)
A=list(set(A))
for elem in A:
for m in range(elem*2,10**6+1,elem):
cnt[m]=1
ans=0
for i in unique:
if cnt[i]==0:
ans+=1
print(ans) | N = int(input())
As = sorted(list(map(int, input().split())))
sieve = [True] * 1000001
prev = 0
for i in range(N):
if As[i] == prev:
sieve[As[i]] = False
continue
else:
prev = As[i]
try:
for j in range(2, 1000000 // prev + 1):
sieve[prev * j] = False
except:
continue
count = 0
As = list(set(As))
for i in range(len(As)):
if sieve[As[i]] is True:
count += 1
print(count) | 1 | 14,305,632,207,090 | null | 129 | 129 |
import sys
a, b = [ int( val ) for val in sys.stdin.readline().split( ' ' ) ]
print( "{:d} {:d} {:7f}".format( a//b, a%b, a/b ) ) | s = []
p = []
a = i = 0
for c in input():
if c == "\\":
s += [i]
elif c == "/" and s:
j = s.pop()
t = i-j
a += t
while p and p[-1][0] > j:
t += p[-1][1]
p.pop()
p += [(j,t)]
i += 1
print(a)
if p:
print(len(p),*list(zip(*p))[1])
else:
print(0)
| 0 | null | 337,063,362,820 | 45 | 21 |
import sys
from bisect import *
from collections import deque
pl=1
#from math import *
from copy import *
#sys.setrecursionlimit(10**6)
if pl:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('outpt.txt','w')
def li():
return [int(xxx) for xxx in input().split()]
def fi():
return int(input())
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
def find(i):
if i==a[i]:
return i
a[i]=find(a[i])
return a[i]
def union(x,y):
xs=find(x)
ys=find(y)
if xs!=ys:
if rank[xs]<rank[ys]:
xs,ys=ys,xs
rank[xs]+=1
a[ys]=xs
t=1
while t>0:
t-=1
n,m=mi()
a=[i for i in range(n+1)]
rank=[0 for i in range(n+1)]
for i in range(m):
x,y=mi()
union(x,y)
s=set()
for i in range(1,n+1):
a[i]=find(i)
s.add(a[i])
print(len(s)-1)
| N = int(input())
c = 0
b = [0]*1000
p = 0
while N % 2 == 0:
b[p] += 1
N //= 2
if b[p]!=0:
p += 1
i = 3
while i * i <= N:
if N % i == 0:
b[p] += 1
N //= i
else:
i += 2
if b[p]!=0:
p += 1
if N==i:
b[p] += 1
N //= i
if N!=1:
p += 1
b[p] += 1
for v in b:
for i in range(1,v+1):
if i<=v:
c += 1
v -= i
else:
break
print(c) | 0 | null | 9,619,402,254,190 | 70 | 136 |
count = 0
for _ in range(int(input())):
n = int(input())
if n == 2 or pow(2,n-1,n) == 1:
count += 1
print(count)
| # usr/bin/python
# coding: utf-8
################################################################################
#Write a program which prints multiplication tables in the following format:
#
#1x1=1
#1x2=2
#.
#.
#9x8=72
#9x9=81
#
################################################################################
if __name__ == "__main__":
for i in range(1, 10):
for j in range(1, 10):
print("{0}x{1}={2}".format(i,j,i*j))
exit(0) | 0 | null | 5,593,842,808 | 12 | 1 |
while True:
a, op, b = input().split() # 3変数ともに文字列として読み込む
a = int(a) # a を整数に変換
b = int(b) # b を整数に変換
if op == '?':
break
elif op == '+':
print("%d"%(a+b))
elif op == '-':
print("%d"%(a-b))
elif op == '/':
print("%d"%(a/b))
else:
print("%d"%(a*b))
| #coding:utf-8
a,op,b=map(str,input().split())
a,b=int(a),int(b)
while op!="?":
if op=="+":
ans=a+b
elif op=="-":
ans=a-b
elif op=="*":
ans=a*b
elif op=="/":
ans=a//b
print(ans)
a,op,b=map(str,input().split())
a,b=int(a),int(b) | 1 | 682,285,762,302 | null | 47 | 47 |
n,k = map(int, input().split())
s = list(map(int,input().strip().split()))
t = 0
ss = sorted(s)
for kk in range(k):
t += ss[kk]
print(t) | A,B,K = list(map(int, input().split()))
if A > K:
A -= K
else:
K -= A
A = 0
if B > K:
B -= K
else:
B = 0
print(A,B)
A -= min(A, K)
| 0 | null | 57,996,189,331,368 | 120 | 249 |
def resolve():
N = int(input())
ans = 0
for i in range(1, N+1):
n = N//i
ans += (n*(n+1)*i)//2
print(ans)
if '__main__' == __name__:
resolve()
| # 正整数Xの正約数個数をf(X)とするときの \sum_(K=1)^N {K*f(K)}
# 正整数jの倍数でありN以下のものの総和をg(j)とするときの \sum_(j=1)^N g(j)
N = int(input())
ans = 0
for j in range(1, N+1):
# Y = N/j とすると g(j) = j+2j+...+Yj = (1+2+...+Y)j = Y(Y+1)/2 *j
g = (N//j)*(N//j+1)*j//2
ans += g
print(ans) | 1 | 10,996,949,307,700 | null | 118 | 118 |
N, K = map(int,input().split())
i = 0
while True:
if N/(K**i)<K:
break
i += 1
print(i+1)
| import math
N,K=map(int,input().split())
if(N==1):
print(1)
exit()
print(math.ceil(math.log(N,K)))
| 1 | 64,111,996,178,362 | null | 212 | 212 |
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')
ans = r * g * b
for i in range(n):
for d in range(1, n):
j = i + d
k = j + d
if k >= n:
break
if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
ans -= 1
print(ans) | N = int(input())
S = list(input())
r = 0
g = 0
b = 0
for i in range(N):
if S[i] == 'R':
r += 1
elif S[i] == 'G':
g += 1
else:
b += 1
allcnt = r * g * b
sub = 0
for i in range(N):
for j in range(i+1,N):
if S[i] == S[j]:
None
else:
k = 2*j-i
if k >= N or S[i] == S[k] or S[j] == S[k]:
None
else:
sub += 1
print(allcnt - sub) | 1 | 36,260,730,225,928 | null | 175 | 175 |
x, y = map(int, input().split())
z = map(int, input().split())
if sum(z) >= x:
print("Yes")
else:
print("No") | H,N=map(int,input().split())
print("NYoe s"[H<=sum(map(int,input().split()))::2]) | 1 | 78,192,745,297,120 | null | 226 | 226 |
X = int(input())
i = 0
x = 0
while x<X:
x = i*1000
i+=1
print (x-X) | def main():
n = int(input())
if n % 1000 == 0:
print(0)
else:
print(1000 - int(n%1000))
if __name__ == '__main__':
main()
| 1 | 8,469,438,408,028 | null | 108 | 108 |
H,N = map(int,input().split())
INF = 10 ** 10
dp = [INF] * (H + 1)
dp[0] = 0
for i in range(N):
attack,magic = map(int,input().split())
for j in range(len(dp)):
if dp[j] == INF:
continue
target = j + attack
if j + attack > H:
target = H
if dp[target] > dp[j] + magic:
dp[target] = dp[j] + magic
print(dp[-1]) | n, m, l = map(int, input().split())
mat_a = [list(map(int, input().split())) for _ in range(n)]
mat_b = [list(map(int, input().split())) for _ in range(m)]
for i in range(n):
row = []
for j in range(l):
tmp = 0
for k in range(m):
tmp += mat_a[i][k]*mat_b[k][j]
row.append(tmp)
print(*row)
| 0 | null | 41,522,730,824,708 | 229 | 60 |
# 解説AC
mod = 10 ** 9 + 7
n, k = map(int, input().split())
dp = [-1] * (k + 1)
ans = 0
for i in range(k, 0, -1):
dp[i] = pow(k // i, n, mod)
t = 0
t += 2 * i
while t <= k:
dp[i] -= dp[t]
dp[i] %= mod
t += i
ans += i * dp[i]
ans %= mod
print(ans)
| #!/usr/bin/env python
n, k = map(int, input().split())
mod = 10**9+7
d = [-1 for _ in range(k+1)]
d[k] = 1
for i in range(k-1, 0, -1):
d[i] = pow(k//i, n, mod)
j = 2*i
while j <= k:
d[i] -= d[j]
j += i
#print('d =', d)
ans = 0
for i in range(1, k+1):
ans += (i*d[i])%mod
print(ans%mod)
| 1 | 36,992,185,016,668 | null | 176 | 176 |
# Problem D - Sum of Divisors
# input
N = int(input())
# initialization
count = 0
# count
for j in range(1, N+1):
M = N // j
count += j * ((M * (M+1)) // 2)
# output
print(count)
| K = int(input())
S = input()
ans = S
if len(S) > K:
ans = S[:K] + '...'
print(ans) | 0 | null | 15,314,012,600,130 | 118 | 143 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.