code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,629B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
#!/usr/bin/env python3
def main():
a, b, c = map(int, input().split())
k = int(input())
for i in range(k):
if a < b < c:
break
elif a >= b:
b *= 2
elif b >= c:
c *= 2
if a < b < c:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
| import sys
a_b_c = list(map(int, input().split()))
r = a_b_c[0]
g = a_b_c[1]
b = a_b_c[2]
k = int(input())
while (g <= r and k >= 0):
g *= 2
k -= 1
while (b <= g and k >= 0):
b *= 2
k -= 1
if (k < 0):
print("No")
else:
print("Yes") | 1 | 6,932,536,228,352 | null | 101 | 101 |
x = input().split()
for i in range(5):
if x[i] == '0':
print(i+1) | S=input()
T=input()
N=len(S)
for i in range(N):
if S[i]!=T[i]:
print('No')
exit()
print('Yes') | 0 | null | 17,567,888,337,538 | 126 | 147 |
# https://atcoder.jp/contests/keyence2020/tasks/keyence2020_c
n, k, s = map(int, input().split())
if s == 10 ** 9:
ans = [1] * n
for i in range(k):
ans[i] = s
else:
ans = [s + 1] * n
for i in range(k):
ans[i] = s
print(*ans) | from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)
INF = int(1e10)
MOD = int(1e9 + 7)
def main():
from builtins import int, map
N, K, S = map(int, input().split())
# al + ... ar = SがちょうどK個
# S S S S S 1 1 1 1 1 1みたいな感じでいい?
if S == 10 ** 9:
ans = [S] * K + [1] * (N - K)
else:
ans = [S] * K + [S + 1] * (N - K)
print(*ans)
if __name__ == '__main__':
main()
| 1 | 90,876,582,966,752 | null | 238 | 238 |
memo = []
counter = 0
while(True):
m,f,r = list(map(int,input().split()))
if m is -1 and r is -1 and f is -1:
break
elif m is -1 or f is -1 or m + f < 30:
memo.append("F")
elif 30 <= m + f < 50 :
if r >= 50:
memo.append("C")
else:
memo.append("D")
elif 50 <= m + f < 65:
memo.append("C")
elif 65 <= m + f < 80:
memo.append("B")
elif 80 <= m + f:
memo.append("A")
counter += 1
for i in range(counter):
print(memo[i]) | x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p=sorted(p,reverse=True)
q=sorted(q,reverse=True)
r=sorted(r,reverse=True)
s=[]
for i in range(x):
s.append(p[i])
for i in range(y):
s.append(q[i])
s=sorted(s,reverse=True)
ws=[s[0]]
for i in range(x+y-1):
ws.append(ws[-1]+s[i+1])
wr=[r[0]]
for i in range(c-1):
wr.append(wr[-1]+r[i+1])
ans=ws[-1]
for i in range(min(x+y-1,c)):
ans=max(ans,ws[-2-i]+wr[i])
print(ans)
| 0 | null | 23,076,131,762,768 | 57 | 188 |
n, a, b = [int(i) for i in input().split()]
a_distance = a-1
b_distance = n-b
ab_distance = b - a
if ab_distance % 2 == 0:
result = ab_distance//2
else:
if a_distance < b_distance:
result = a_distance + (ab_distance-1)//2 + 1
else:
result = b_distance + (ab_distance-1)//2 + 1
print(result)
| n, a, b = map(int, input().strip().split())
if (b - a) % 2 == 1:
dt1 = a - 1
dt1 += 1
b1 = b - dt1
t1 = dt1 + (b1 - 1) // 2
dt2 = n - b
dt2 += 1
a1 = a + dt2
t2 = dt2 + (n - a1) // 2
print(min(t1, t2))
else:
print((b - a) // 2)
| 1 | 109,683,454,430,500 | null | 253 | 253 |
i = int(input())
print(i*(1+i*(1+i))) | a = [0, 0, 0, 0]
for t in range(10):
a[3] = input()
for i in range(2, -1, -1):
if (a[i] < a[i+1]):
a[i], a[i+1] = a[i+1], a[i]
for i in range(0, 3):
print a[i] | 0 | null | 5,151,735,555,274 | 115 | 2 |
data = [int(x) for x in input().split(" ")]
for i in range(len(data)):
if data[i] == 0: print(i+1)
| X = input().split()
for i in range(len(X)):
if X[i] == '0' :
print(i+1)
exit() | 1 | 13,461,858,834,020 | null | 126 | 126 |
import math
while True:
n = input()
if n == 0:
break
m = map(float,raw_input().split())
print "%5f" %(math.sqrt(sum([(m[i]-(sum(m)/len(m)))**2 for i in range(n)])/n)) | #
# abc165 c
#
import sys
from io import StringIO
import unittest
sys.setrecursionlimit(100000)
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """3 4 3
1 3 3 100
1 2 2 10
2 3 2 10"""
output = """110"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328"""
output = """357500"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """10 10 1
1 10 9 1"""
output = """1"""
self.assertIO(input, output)
def resolve():
global N, M
N, M, Q = map(int, input().split())
ABCD = [list(map(int, input().split())) for _ in range(Q)]
T = []
func([1], T)
ans = 0
for t in T:
score = 0
for abcd in ABCD:
a, b, c, d = abcd
if t[b-1] - t[a-1] == c:
score += d
ans = max(ans, score)
print(ans)
def func(L, T):
if len(L) == N:
T.append(L)
return
for i in range(L[-1], M+1):
NL = L + [i]
func(NL, T)
if __name__ == "__main__":
# unittest.main()
resolve()
| 0 | null | 13,790,098,559,242 | 31 | 160 |
MI = lambda :(map(int,input().split()))
x = int(input())
if x>1799:
print(1)
elif x>1599:
print(2)
elif x>1399:
print(3)
elif x>1199:
print(4)
elif x>999:
print(5)
elif x>799:
print(6)
elif x>599:
print(7)
else:
print(8) | X = int(input())
rankArr=[2000,1800,1600,1400,1200,1000,800,600,400]
for i in range(1,len(rankArr)):
if rankArr[i] <= X and X < rankArr[i-1] :
print(i)
exit() | 1 | 6,727,771,122,198 | null | 100 | 100 |
import os, sys, re, math
import itertools
N = int(input())
P = tuple([int(n) for n in input().split()])
Q = tuple([int(n) for n in input().split()])
nums = [n for n in range(1, N + 1)]
patterns = itertools.permutations(nums, N)
i = 0
for pattern in patterns:
if pattern == P:
pi = i
if pattern == Q:
qi = i
i += 1
print(abs(pi - qi)) | #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,425,660,398,040 | null | 246 | 246 |
num = int(input())
print('ACL'*num) | n=int(input())
r="ACL"*n
print(r) | 1 | 2,182,724,410,528 | null | 69 | 69 |
# B - Bishop
H,W = map(int,input().split())
if H>1 and W>1:
print((H*W+1)//2)
else:
print(1) | n, m = map(int, input().split())
if n == 1 or m == 1:
print(1)
elif n*m%2 == 0:
print(n*m//2)
else:
print(n*m//2+1) | 1 | 50,635,318,040,554 | null | 196 | 196 |
a, b, c, d = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
xy1 = a*c
xy2 = a*d
xy3 = b*c
xy4 = b*d
print(max([xy1, xy2, xy3, xy4])) | from math import sqrt, log
def factor(number):
i = 2
s = set()
while i * i <= number:
if number % i == 0:
if i != 2:
s.add(i)
if (number // i) != 2:
s.add(number//i)
i += 1
return s
def newFactor(number):
n = number
i = 2
ans = set()
while i * i <= number:
if number % i == 0:
while number % i == 0:
number //= i
if number % i == 1:
ans.add(i)
number = n
i += 1
return ans
n = int(input())
if n == 2:
print(1)
exit()
if n == 3:
print(2)
exit()
s = set()
s.add(2)
s.add(n-1)
s.add(n)
s = s.union(factor(n-1))
s = s.union(newFactor(n))
print(len(s))
| 0 | null | 22,248,657,234,478 | 77 | 183 |
def solve():
H1, M1, H2, M2, K = map(int, input().split())
print((H2*60 + M2) - (H1*60 + M1) - K)
if __name__ == '__main__':
solve()
| import sys
sys.setrecursionlimit(10**9)
def main():
X,Y,A,B,C = map(int,input().split())
P = sorted(list(map(int,input().split())),reverse=True)
Q = sorted(list(map(int,input().split())),reverse=True)
R = list(map(int,input().split()))
print(sum(sorted(P[:X]+Q[:Y]+R,reverse=True)[:X+Y]))
if __name__ == "__main__":
main()
| 0 | null | 31,473,990,051,110 | 139 | 188 |
# encoding=utf-8
n = int(raw_input())
min = int(raw_input())
keep = int(raw_input())
diff = keep - min
if keep > min:
keep = min
n = n - 2
for i in range(n):
v = int(raw_input())
if v - keep > diff:
diff = v - keep
min = keep
elif keep > v:
keep = v
print diff | n = int(raw_input())
minv = int(raw_input())
maxv = -1*10**9
for j in range(n-1):
a = int(raw_input())
b = a- minv
if maxv < b:
maxv = b
if minv > a:
minv = a
print maxv | 1 | 13,705,937,550 | null | 13 | 13 |
K, N = map(int, input().split())
A = list(map(int, input().split()))
res = A[0] + (K - A[N-1])
for i in range(1, N):
dist = A[i] - A[i-1]
if res < dist:
res = dist
print(K - res) | import math
k,n= map(int,input().split())
a = list(map(int,input().split()))
ans = a[0]+k-a[n-1]
for i in range(1,len(a)):
s = a[i]-a[i-1]
ans =max(ans,s)
print(k-ans)
| 1 | 43,379,259,315,168 | null | 186 | 186 |
N, K = map(int, input().split())
W = [int(input()) for w in range(N)]
def check(p):
i = 0
for _ in range(K):
s = 0
while s + W[i] <= p:
s += W[i]
i += 1
if i == N:
return N
return i
left = 0
right = 100000 * 10000
mid = 0
while 1 < right - left:
mid = (left + right) / 2
v = check(mid)
if v >= N:
right = mid
else:
left = mid
print(int(right))
| import sys
n = int(input())
minv = int(input())
maxv = -1000000000
for r in map(int,sys.stdin.readlines()):
m = r-minv
if maxv < m:
maxv = m
if m < 0: minv = r
elif m < 0: minv = r
print(maxv) | 0 | null | 51,916,768,568 | 24 | 13 |
N=int(input())
S=input()
ans=0
for i in range(N-2):
if S[i:i+3]=='ABC':
ans+=1
print(ans) | S = input()
if len(S) >= 1 and len(S) <= 1000:
if S[-1] == "s":
print (S, "es", sep = '')
else:
print (S, "s", sep = '') | 0 | null | 50,746,234,699,392 | 245 | 71 |
import sys
R, C, K = map(int, sys.stdin.readline().split())
grid = [[0 for _ in range(C)] for _ in range(R)]
for _ in range(K):
r, c, v = map(int, sys.stdin.readline().split())
grid[r-1][c-1] = v
# r行目、c列目にいるときに、その行でアイテムをi個取得している場合の最大価値
dp0 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp1 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp2 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp3 = [[0 for _ in range(C+1)] for _ in range(R+1)]
# print(dp)
for r in range(R):
for c in range(C):
# 取らない
dp0[r+1][c] = max((dp0[r][c], dp1[r][c], dp2[r][c], dp3[r][c]))
dp1[r][c+1] = max(dp1[r][c], dp1[r][c])
dp2[r][c+1] = max(dp2[r][c], dp2[r][c])
dp3[r][c+1] = max(dp3[r][c], dp3[r][c])
if grid[r][c] == 0:
continue
# 取る
dp0[r+1][c] = max(dp0[r][c] + grid[r][c], dp0[r+1][c])
dp0[r+1][c] = max(dp1[r][c] + grid[r][c], dp0[r+1][c])
dp0[r+1][c] = max(dp2[r][c] + grid[r][c], dp0[r+1][c])
dp1[r][c+1] = max(dp0[r][c] + grid[r][c], dp1[r][c+1])
dp2[r][c+1] = max(dp1[r][c] + grid[r][c], dp2[r][c+1])
dp3[r][c+1] = max(dp2[r][c] + grid[r][c], dp3[r][c+1])
# print(dp0)
# print(dp1)
# print(dp2)
# print(dp3)
# print(max((dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C])))
print(dp0[R][C-1]) | import sys
R, C, K = map(int, input().split())
item = [[0] * (C + 1) for _ in range(R + 1)] # dp配列と合わせるために, 0行目, 0列目を追加している.
for s in sys.stdin.readlines():
r, c, v = map(int, s.split())
item[r][c] = v
dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]
for i in range(R + 1):
for j in range(C + 1):
for k in range(4):
here = dp[k][i][j]
# 次の行に移動する場合
if i + 1 <= R:
# 移動先のアイテムを取らない場合
dp[0][i + 1][j] = max(dp[0][i + 1][j], here)
# 移動先のアイテムを取る場合
dp[1][i + 1][j] = max(dp[1][i + 1][j], here + item[i + 1][j])
# 次の列に移動する場合
if j + 1 <= C:
# 移動先のアイテムを取らない場合
dp[k][i][j + 1] = max(dp[k][i][j + 1], here)
# 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
if k < 3:
dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], here + item[i][j + 1])
ans = 0
for k in range(4):
ans = max(ans, dp[k][-1][-1])
print(ans) | 1 | 5,601,672,702,848 | null | 94 | 94 |
import sys
l = sys.stdin.readlines()
minv = int(l[1])
maxv = -1000000000
for r in map(int,l[2:]):
m = r-minv
if maxv < m:
maxv = m
if m < 0: minv = r
elif m < 0: minv = r
print(maxv) | import sys
class Card:
def __init__(self, card):
self.card = card
self.mark = card[0]
self.value = int(card[1])
def __str__(self):
return self.card
def print_cards(arr_print, arr_compare):
n = len(arr_print)
same = True
for i in range(n):
if arr_compare != None and arr_print[i].card != arr_compare[i].card: same = False
sys.stdout.write(str(arr_print[i]))
if i != n - 1:
sys.stdout.write(' ')
print()
return same
def swap(arr, i, j):
temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
def bubble_sort(arr):
n = len(arr)
for i in range(0, n):
for j in range(n - 1, i, -1):
if arr[j].value < arr[j - 1].value:
swap(arr, j, j - 1)
def selection_sort(arr):
n = len(arr)
for i in range(n):
minj = i
for j in range(i, n):
if arr[j].value < arr[minj].value:
minj = j
if minj != i:
swap(arr, i, minj)
n = int(input())
arr = list(map(str, input().split()))
cards1 = [None] * n
cards2 = [None] * n
for i in range(n):
cards1[i] = Card(arr[i])
cards2[i] = Card(arr[i])
bubble_sort(cards1)
selection_sort(cards2)
print_cards(cards1, None)
print('Stable')
stable = print_cards(cards2, cards1)
if stable == True:
print('Stable')
else:
print('Not stable')
| 0 | null | 17,515,908,928 | 13 | 16 |
a = input().split()
print(' '.join(sorted(a))) | a,b,c = sorted(map(int,raw_input().split()))
print a,b,c | 1 | 428,769,864,810 | null | 40 | 40 |
a,b,c=sorted(map(int,input().split()))
print(a,b,c) | print " ".join(sorted(map(str, map(int, raw_input().split(" "))))) | 1 | 409,508,990,240 | null | 40 | 40 |
n=list(input())
N=len(n)
k=int(input())
dp1=[[0 for i in range(k+1)] for j in range(N+1)]
dp2=[[0 for i in range(k+1)] for j in range(N+1)]
dp1[0][0]=1
for i in range(1,N+1):
x=int(n[i-1])
if i!=N and x!=0:
for j in range(k+1):
if j==0:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]
else:
dp1[i][j]=dp1[i-1][j-1]
dp2[i][j]=dp1[i-1][j]+dp1[i-1][j-1]*(x-1)+dp2[i-1][j]+dp2[i-1][j-1]*9
elif i!=N and x==0:
for j in range(k+1):
if j==0:
dp1[i][j]=dp1[i-1][j]
dp2[i][j]=dp2[i-1][j]
else:
dp1[i][j]=dp1[i-1][j]
dp2[i][j]=dp2[i-1][j]+dp2[i-1][j-1]*9
elif i==N and x!=0:
for j in range(k+1):
if j==0:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]
else:
dp2[i][j]=dp1[i-1][j]+dp1[i-1][j-1]*x+dp2[i-1][j]+dp2[i-1][j-1]*9
else:
for j in range(k+1):
if j==0:
dp2[i][j]=dp2[i-1][j]
else:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]+dp2[i-1][j-1]*9
print(dp2[N][k]) | N = int(input())
S,T=input().split()
retsu = ""
for i in range(0,N):
mozi = S[i]+T[i]
retsu += mozi
print(retsu) | 0 | null | 93,862,981,223,918 | 224 | 255 |
dic = {}
l = []
n = int(input())
for i in range(n):
s = input()
#sが新規キーか否かで操作を変える
if s in dic:
dic[s] += 1
#新規ではないならvalueを1増やす
else:
dic[s] = 1
m = max(dic.values())
for i in dic:
if dic[i] == m:
l += [i]
print(*sorted(l)) | n = int(input())
# 入力データ受取り時に、辞書に追加していくやり方
s_dict = {}
for i in range(n):
s = input()
if s not in s_dict:
s_dict[s] = 1
s_dict[s] += 1
max_value = max(s_dict.values())
ans = []
for key, value in s_dict.items():
if value == max_value:
ans.append(key)
ans.sort()
for i in ans:
print(i) | 1 | 70,256,097,364,798 | null | 218 | 218 |
from math import gcd
from functools import reduce
n = int(input())
A = list(map(int, input().split()))
res = ['pairwise coprime', 'setwise coprime', 'not coprime']
MAX = 10 ** 6 + 1000
dp = [i for i in range(MAX)]
# dp[x]はxを割り切る最小の素数
for x in range(2, MAX):
if dp[x] < x: continue
for y in range(x + x, MAX, x):
if dp[y] == y:
dp[y] = x
def get_factor(n):
factors = []
while n > 1:
factors.append(dp[n])
n //= dp[n]
return factors
prime_factors = []
for a in A:
factor = get_factor(a)
factor_set = list(set(factor))
prime_factors.extend(factor_set)
if len(prime_factors) == len(set(prime_factors)):
print(res[0])
elif reduce(gcd, A) == 1:
print(res[1])
else:
print(res[2])
| from math import gcd
n = int(input())
s = list(map(int, input().split()))
s.sort()
dp = [0] * ((10 ** 6) + 100)
res = s[0]
for ss in s:
dp[ss] += 1
res = gcd(res, ss)
A = max(s)
pairwise = True
setwise = (res == 1)
primes = set(range(2, A+1))
for i in range(2, int(A**0.5+1)):
if i not in primes:
i += 1
else:
ran = range(i*2, A+1,i)
primes.difference_update(ran)
primes = list(primes)
for i in primes:
cnt = 0
for j in range(i, A + 1, i):
cnt += dp[j]
if cnt > 1:
pairwise = False
break
if pairwise:
print("pairwise coprime")
elif setwise:
print("setwise coprime")
else:
print("not coprime")
| 1 | 4,133,314,877,800 | null | 85 | 85 |
while True:
a,op,b=input().split()
a,b=int(a),int(b)
if op=="+":
print(a+b)
elif op=="-":
print(a-b)
elif op=="*":
print(a*b)
elif op=="/":
print(a//b)
else:
break
| # encoding:utf-8
while True:
a, op, b = raw_input().split()
if op == "?":
break
a, b = map(int, (a,b))
if op == "+":
print(a+b)
elif op == "-":
print(a-b)
elif op == "*":
print(a*b)
else:
print(a/b) | 1 | 697,094,326,600 | null | 47 | 47 |
N = int(input())
jage = "No"
for l in range(1, 10):
for r in range(1,10):
if N == r * l:
jage = "Yes"
print(jage) | N = int(input())
multiplication = []
for x in range(1, 10):
for y in range(1, 10):
multiplication.append(x*y)
if N in multiplication:
print( "Yes" )
else:
print( "No" ) | 1 | 159,942,456,771,848 | null | 287 | 287 |
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import defaultdict
from collections import Counter
import bisect
from functools import reduce
def main():
H, N = MI()
A = LI()
A_sum = sum(A)
if A_sum >= H:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
| #153_B
h, n = map(int, input().split())
a = list(map(int, input().split()))
sum = 0
for i in range(n):
sum += a[i]
if sum >= h:
print('Yes')
else:
print('No') | 1 | 77,972,007,041,768 | null | 226 | 226 |
def main():
N, M = map(int, input().split())
*A, = map(int, input().split())
A.sort(reverse=True)
tot = sum(A)
cond = A[M - 1] * 4 * M >= tot
print('Yes' if cond else 'No')
if __name__ == '__main__':
main()
| # coding: utf-8
# Your code here!
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
total = sum(a)
if all([x >= total / (4 * m) for x in a[:m]]):
print('Yes')
else:
print('No')
| 1 | 38,731,502,985,340 | null | 179 | 179 |
X, Y, A, B, C = map(int, input().split())
ps = list(map(int, input().split()))
qs = list(map(int, input().split()))
rs = list(map(int, input().split()))
ps = sorted(ps, reverse=True)[:X]
qs = sorted(qs, reverse=True)[:Y]
rs = sorted(ps+qs+rs, reverse=True)[:X+Y]
r = sum(rs)
print(r)
| #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C&lang=jp
#??????????????????
#??????????????????????°???????????????£?????´???????????´?????¨??\?????????????????????????????????????????´????????????
#??????????????????????????????????°????????????????????????´???????????????????????????????????????????????¨??????
def bubble_sort(origin_list):
list_length = len(origin_list)
target_list = [i for i in origin_list]#??°????????????????????????
flag = True
change_count = 0
top_index = 1
while flag:
flag = False
for i in range(top_index, list_length)[::-1]:
if target_list[i][1] < target_list[i - 1][1]:
tmp = target_list[i]
target_list[i] = target_list[i - 1]
target_list[i - 1] = tmp
change_count += 1
flag = True
top_index += 1
return target_list
def selection_sort(origin_list):
list_length = len(origin_list)
target_list = [i for i in origin_list]#??°????????????????????????
change_count = 0
for i in range(list_length):
min_index = i
for j in range(i, list_length):
if target_list[j][1] < target_list[min_index][1]:
min_index = j
else:
if not i == min_index:
tmp = target_list[i]
target_list[i] = target_list[min_index]
target_list[min_index] = tmp
change_count += 1
return target_list
def check_stable(origin_list, target_list):
for i, origin_v in enumerate(origin_list):
for origin_v2 in origin_list[i+1:]:
if origin_v[1] == origin_v2[1]:
for j, target_v in enumerate(target_list):
for target_v2 in target_list[j+1:]:
if origin_v == target_v2 and origin_v2 == target_v:
return "Not stable"
return "Stable"
def stable_sort(target_list):
print(*bubble_sort(target_list))
print(check_stable(target_list, bubble_sort(target_list)))
print(*selection_sort(target_list))
print(check_stable(target_list, selection_sort(target_list)))
def main():
n_list = int(input())
target_list = [a for a in input().split()]
stable_sort(target_list)
if __name__ == "__main__":
main() | 0 | null | 22,545,816,326,940 | 188 | 16 |
list = []
while True:
n, x = map(int, input().split())
if n == x == 0:
break
cnt = 0
for a in range(1, n + 1):
for b in range(a + 1, n + 1):
for c in range(b + 1, n + 1):
if a + b + c == x:
cnt += 1
list.append(cnt)
for s in list:
print(s) | while(1):
n, x = map(int, input().split())
if n == 0 and x == 0:
break
count = 0
for i in range(1, n-1):
if i*3 >= x:
break
for j in range(i+1, n):
if i+2*j >= x:
break
if x-i-j <= n:
count += 1
print(count) | 1 | 1,282,004,490,240 | null | 58 | 58 |
def get_depth(graph,tmp_depth,vertex_list,depth_list):
new_vertex_list=[]
for vertex in vertex_list:
for j in range(len(depth_list)):
if(graph[vertex][j]!=0 and depth_list[j]==-1):
depth_list[j]=tmp_depth + 1
new_vertex_list.append(j)
if(len(new_vertex_list)!=0):
get_depth(graph,tmp_depth+1,new_vertex_list,depth_list)
#グラフの作成
n=int(input())
graph=[[0]*n for loop in range(n)]
for loop in range(n):
tmp_ope=list(map(int,input().split()))
for j in range(tmp_ope[1]):
graph[tmp_ope[0]-1][tmp_ope[j+2]-1]=1
depth_list=[-1]*n
depth_list[0]=0
vertex_list=[0]
get_depth(graph,0,vertex_list,depth_list)
for i in range(n):
print(f"{i+1} {depth_list[i]}")
| def main():
mod = 1000000007
n = int(input())
cnt = [0] * (n + 2)
cnt[0] = 3
res = 1
for x in input().split():
v = int(x)
res *= cnt[v] - cnt[v + 1]
res %= mod
cnt[v + 1] += 1
print(res)
main()
| 0 | null | 65,253,678,630,400 | 9 | 268 |
# %%
x = input()
if x[0]=="7" or x[1]=="7" or x[2]=="7":
ans = "Yes"
else:
ans = "No"
print(ans)
# %%
| a, b = map(int, input().split())
s=int(a)*int(b)
t=(int(a)+int(b))*2
print(s, t)
| 0 | null | 17,421,099,244,318 | 172 | 36 |
def resolve():
MOD = 10 ** 9 + 7
N, K = map(int, input().split())
ans = 0
for k in range(K, N + 2):
min_num = k * (k - 1) // 2
max_num = k * (N * 2 - k + 1) // 2
add = max_num - min_num + 1
ans = (ans + add) % MOD
print(ans)
if __name__ == "__main__":
resolve() | from collections import defaultdict
N, K, *A = map(int, open(0).read().split())
S = [0] * (N + 1)
for i in range(N):
S[i + 1] = S[i] + A[i]
d = defaultdict(int)
ans = 0
for j in range(N + 1):
v = (S[j] - j) % K
ans += d[v]
d[v] += 1
if j >= K - 1:
d[(S[j - K + 1] - (j - K + 1)) % K] -= 1
print(ans)
| 0 | null | 85,301,427,116,682 | 170 | 273 |
S = int(input())
DP = [0] * (S + 1)
Mod = 10 ** 9 + 7
if S >= 3:
DP[0] = 1
DP[1] = 0
DP[2] = 0
for TS in range(3,S+1):
DP[TS] = DP[TS-1] + DP[TS-3]
print(DP[S] % Mod)
else:
print(0) | MOD = 1000000007
S = int(input())
#dp[i]:=i桁の数列で条件を満たすものの数
dp = [0]*(S+1)
dp_sum = [0]*(S+1)
for i in range(3,S+1):
#dp[i]=sum(dp[0],..,dp[i-3])+1
dp[i] = (dp_sum[i-3]+1)%MOD
dp_sum[i] = (dp[i]+dp_sum[i-1])%MOD
print(dp[S]) | 1 | 3,297,814,895,100 | null | 79 | 79 |
N = input()
N = list(N)
if N[len(N)-1] == '3':
print('bon')
elif N[len(N)-1] == '0' or N[len(N)-1] == '1' or N[len(N)-1] == '6' or N[len(N)-1] == '8':
print('pon')
else:
print('hon') | from math import cos, sin, pi
class Coordinate:
def __init__(self, x, y):
self.x = x
self.y = y
def kock(n, p1, p2):
if n == 0:
return
s = Coordinate((2*p1.x+p2.x)/3, (2*p1.y+p2.y)/3)
t = Coordinate((p1.x+2*p2.x)/3, (p1.y+2*p2.y)/3)
ux = (t.x-s.x)*cos(pi/3) - (t.y-s.y)*sin(pi/3) + s.x
uy = (t.x-s.x)*sin(pi/3) + (t.y-s.y)*cos(pi/3) + s.y
u = Coordinate(ux, uy)
kock(n-1, p1, s)
print("%f %f"%(s.x, s.y))
kock(n-1, s, u)
print("%f %f"%(u.x, u.y))
kock(n-1, u, t)
print("%f %f"%(t.x, t.y))
kock(n-1, t, p2)
n = int(input())
p1 = Coordinate(0, 0)
p2 = Coordinate(100, 0)
print("%f %f"%(p1.x, p2.y))
kock(n, p1, p2)
print("%f %f"%(p2.x, p2.y))
| 0 | null | 9,746,645,523,772 | 142 | 27 |
N,M,K=map(int,input().split())
A=[];B=[]
for i in range(M):
a,b=map(int,input().split())
A.append(a);B.append(b)
C=[];D=[]
for i in range(K):
c,d=map(int,input().split())
C.append(c);D.append(d)
f=[set() for i in range(N)]
b=[set() for i in range(N)]
for i in range(M):
f[A[i]-1].add(B[i]-1)
f[B[i]-1].add(A[i]-1)
for i in range(K):
b[C[i]-1].add(D[i]-1)
b[D[i]-1].add(C[i]-1)
checked=[False for i in range(N)]
class UnionFind:
def __init__(self,n):
self.n=n
self.parents=[-1]*n
def root(self,x):
if self.parents[x]<0:
return x
else:
self.parents[x]=self.root(self.parents[x])
return self.parents[x]
def union(self,x,y):
x=self.root(x)
y=self.root(y)
if x==y:
return
if self.parents[x]>self.parents[y]:
x,y=y,x
self.parents[x]+=self.parents[y]
self.parents[y]=x
def same(self,x,y):
return self.root(x)==self.root(y)
def size(self,x):
return -self.parents[self.root(x)]
def roots(self):
return [i for i,x in enumerate(self.parents) if x<0]
def group_count(self):
return len(self.roots())
uf=UnionFind(N)
for i in range(N):
for people in f[i]:
uf.union(i,people)
ans=[]
for i in range(N):
c=uf.size(i)
bl=0
for x in b[i]:
if uf.same(i,x):
bl+=1
ans.append(c-bl-1-len(f[i]))
print(*ans) | import sys
from collections import deque
input = sys.stdin.readline
n, m, k = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(k)]
ff = [[] for _ in range(n+1)]
for a, b in ab:
ff[a].append(b)
ff[b].append(a)
visited = [False] * (n+1)
visited[0] = True
com = [-1] * (n+1)
def dfs(v, ff, visited, com, g):
q = deque([v])
visited[v] = True
com[v] = g
k = 1
while len(q) > 0:
w = q.pop()
for x in ff[w]:
if not visited[x]:
q.append(x)
visited[x] = True
com[x] = g
k += 1
return k
g = 0
group_num = []
for i in range(1, n+1):
if visited[i]:
pass
else:
k = dfs(i, ff, visited, com, g)
group_num.append(k)
g += 1
#print(com)
friends = [0] * (n+1)
for i in range(1, n+1):
friends[i] += group_num[com[i]] - 1
for a, b in ab:
if com[a] == com[b]:
friends[a] -= 1
friends[b] -= 1
for c, d in cd:
if com[c] == com[d]:
friends[c] -= 1
friends[d] -= 1
print(" ".join(map(str, friends[1:]))) | 1 | 61,328,669,182,600 | null | 209 | 209 |
S = int(input())
print("%d:%d:%d"%(S/3600,(S%3600)/60,S%60))
| S = int(input())
h = S // 3600
m = (S // 60) % 60
s = S % 60
print("%d:%d:%d" % (h, m, s))
| 1 | 325,227,516,148 | null | 37 | 37 |
week=["SUN","MON","TUE","WED","THU","FRI","SAT"]
s=input()
if s in week:
x=week.index(s)
print(7-x) | import math
x1, y1, x2, y2 = [ float( i ) for i in raw_input( ).split( " " ) ]
print( math.sqrt( ( x1 - x2 )**2 + ( y1 - y2 )**2 ) ) | 0 | null | 66,324,071,694,880 | 270 | 29 |
from scipy.special import comb
n, k = map(int, input().split())
num, ans = 0, 0
for i in range(n+1):
num += n-2*i
if i >= k-1:
ans += num+1
ans = ans%(10**9+7)
print(ans)
| setting = input().split();
package_count = int(setting[0]);
truck_count = int(setting[1]);
packages = [];
for i in range(package_count):
packages.append(int(input()));
def allocation():
max_p = sum(packages);
left = 0;
right = max_p;
while left < right:
mid = (left + right) // 2;
load = calculate_load(mid);
if load >= package_count:
right = mid;
else:
left = mid + 1;
return right;
def calculate_load(p):
i = 0;
j = 0;
current_truck_p = p;
while i < package_count and j < truck_count:
if packages[i] <= current_truck_p:
current_truck_p -= packages[i];
i += 1;
else:
j += 1;
current_truck_p = p;
return i;
print(allocation());
| 0 | null | 16,463,864,139,840 | 170 | 24 |
n = input()
A = [int(i) for i in input().split(' ')]
def trace(A):
for index, v in enumerate(A):
print(v, end='')
if index != len(A) - 1:
print(' ', end='')
print()
trace(A)
for i in range(1, len(A)):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
trace(A) | n = int(input())
data = list(map(int, input().split()))
for i in range(n):
v = data[i]
j = i - 1
while j >= 0 and data[j] > v:
data[j+1] = data[j]
j -= 1
data[j+1] = v
print(" ".join(map(str, data))) | 1 | 5,714,523,012 | null | 10 | 10 |
N = int(input()) #入力する整数
A = list(map(int,input().split())) #入力する数列A
SUMA = sum(A) #数列の和
MOD = 10**9 + 7 # mod
C = [0] * (N-1) #累積和数列
for i in range(N-1): #\sum_{j = i+1}^{N}を求めて数列に代入する
SUMA -= A[i]
C[i] = SUMA
ans = 0 #求める答え
for i in range(N-1):
ans += A[i]*C[i]
ans %= MOD #その都度modで割った余りにする
print(ans) #答えを出力する | N = int(input())
for i in range(1 , N + 1):
x = int(i * 1.08)
if x == N:
print(i)
exit()
print(':(') | 0 | null | 65,067,339,241,390 | 83 | 265 |
a, b = input().split()
op = ['==', '>', '<']
result = int(a) - int(b)
if result != 0:
result = result // abs(result)
print('a ' + op[result] + ' b') |
D = int(input())
c_list = list(map(int, input().split()))
s_list = [list(map(int, input().split())) for _ in range(D)]
last_open = [0] * 26
res = 0
res_list = []
for i in range(D):
t = int(input())
res += s_list[i][t-1]
bad = 0
last_open[t-1] = i+1
for ci in range(26):
bad += c_list[ci]*(i+1 - last_open[ci])
res -= bad
print(res)
res_list.append(res)
| 0 | null | 5,121,452,644,552 | 38 | 114 |
def sum_part(N, k):
return k*(2*N-k+1)/2-k*(k-1)/2+1
N, K = map(int, input().split())
ans = 0
for k in range(K,N+2):
ans += sum_part(N, k)
ans = ans % (10**9 + 7)
print(int(ans)) | # https://atcoder.jp/contests/abc163/tasks/abc163_d
def main():
MOD = 10**9 + 7
n, k = [int(i) for i in input().strip().split()]
table = [0] * (n + 2)
table[1] = 1
for i in range(2, n + 1):
table[i] = table[i - 1] + i
ans = 0
for i in range(k, n + 1):
_min = table[i - 1]
_max = table[n] - table[n - i]
ans += _max - _min + 1
ans %= MOD
print((ans + 1) % MOD)
if __name__ == "__main__":
main()
| 1 | 33,241,028,839,040 | null | 170 | 170 |
from collections import defaultdict
from math import gcd
import sys
input = sys.stdin.readline
N=int(input())
mod=10**9+7
dic=defaultdict(lambda: [0,0])
c=0
d=0
e=0
for i in [0]*N:
A,B = map(int,input().split())
if A==0 and B==0:
e+=1
elif A==0:
c+=1
elif B==0:
d+=1
else:
g=gcd(A,B)
A//=g
B//=g
if A*B>0:
dic[(abs(A),abs(B))][0]+=1
else:
dic[(abs(B),abs(A))][1]+=1
ans=1
for k in dic:
ans=ans*(pow(2,dic[k][0],mod)+pow(2,dic[k][1],mod) -1)
ans=ans*(pow(2,c,mod)+pow(2,d,mod)-1)
print((ans-1+e)%mod) | #!/usr/bin/env python3
import sys
import math
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 1000000007 # type: int
def solve(N: int, A: "List[int]", B: "List[int]"):
# 直交するイワシは選べない。
# 順にイワシを見て、直行するものをグループにする。
# 先に単純な整数比へ変換しておく(有理数としての扱い)
# aは整数、bは非負整数となるように整理する
d = Counter()
# (a, b) == (0, 0)については、他のイワシと同時に選ぶことができない。
# 個別にカウントする。
kodokunaiwashi = 0
for i, (a, b) in enumerate(zip(A, B)):
if a == 0 and b == 0:
kodokunaiwashi += 1
elif b == 0:
d[1, 0] += 1
elif b > 0:
g = math.gcd(b, a)
aa = a//g
bb = b//g
d[aa, bb] += 1
else:
g = math.gcd(-b, -a)
aa = -a//g
bb = -b//g
d[(aa, bb)] += 1
# 直交するグループを考える。
ans = 1
for a, b in d:
# (a, b)と直交するのは、(-b, a)と(b, -a)である。
# このうち、有理数としてカウントしている方を採用する
x, y = -b, a
if y < 0:
x = -x
y = -y
elif y == 0:
x = abs(x)
# すでに直交するイワシとしてカウントをしたらNoneとしている。
if d[a, b] == None:
continue
if d[x, y] == 0:
# 直交するイワシが存在しない場合、自由に選ぶことができる。
ans *= pow(2, d[a, b], MOD)
ans %= MOD
continue
else:
# 直交するイワシが存在する場合、どちらかのグループから自由に選ぶ。
# ただし、一つも選ばないという場合は、重複するためケア
buf = pow(2, d[a, b], MOD)
buf += pow(2, d[x, y], MOD)
buf -= 1
buf %= MOD
# print(buf)
ans *= buf
ans %= MOD
d[x, y] = None
print((ans-1+kodokunaiwashi) % MOD)
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
A = [int()] * (N) # type: "List[int]"
B = [int()] * (N) # type: "List[int]"
for i in range(N):
A[i] = int(next(tokens))
B[i] = int(next(tokens))
solve(N, A, B)
if __name__ == '__main__':
main()
| 1 | 20,875,077,387,500 | null | 146 | 146 |
n = int(input())
cards = [input().split() for i in range(n)]
taroScore = 0
hanakoScore = 0
for i in range(n):
sortedCards = sorted(cards[i])
if cards[i][0] == cards[i][1]:
taroScore += 1
hanakoScore += 1
elif cards[i][0] == sortedCards[0]:
hanakoScore += 3
else:
taroScore += 3
print(taroScore, hanakoScore)
| print('a' if input().islower()==True else 'A') | 0 | null | 6,610,652,437,632 | 67 | 119 |
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, K = map(int, input().split())
def sub_sum(l, r):
return (l + r) * (r - l + 1) / 2
ans = 0
for i in range(K, N+2):
l = sub_sum(0, i-1)
r = sub_sum(N-i+1, N)
ans += r - l + 1
ans = ans % (10**9+7)
print(int(ans))
| 1 | 33,098,643,583,740 | null | 170 | 170 |
n=int(input())
a=[-int(j) for j in input().split()]
a.sort()
import heapq
l=[a[0]]
heapq.heapify(l)
ans=0
for i in a[1:]:
heapq.heappush(l,i)
heapq.heappush(l,i)
p=heapq.heappop(l)
ans-=p
print(ans) | from collections import deque
def main():
n = int(input())
l = list(map(int, input().split()))
comfort = 0
l_sorted = sorted(l, reverse=True)
q = deque([l_sorted[0]])
for i in range(1, n):
comfort += q[0]
q.popleft()
for _ in range(2):
q.append(l_sorted[i])
print(comfort)
if __name__ == '__main__':
main()
| 1 | 9,128,000,331,650 | null | 111 | 111 |
a = input()
b = input()
n = len(a)
count = 0
for i in range(n):
if a[i] != b[i]:
count = count +1
print(count) | a,v,b,w,t=map(int,open(0).read().split())
if (a<b and a+v*t>=b+w*t)or(b<a and b-w*t>=a-v*t):print("YES")
else:print("NO") | 0 | null | 12,727,760,116,932 | 116 | 131 |
def main():
n = int(input())
s = list(input())
for i in range(len(s)):
s[i] = chr((ord(s[i]) + n - ord("A")) % 26 + ord("A"))
print(*s, sep="")
if __name__ == "__main__":
main()
| n = int(input())
P = list(map(int, input().split()))
ans = 0
prev_min = P[0]
for p in P:
if prev_min >= p:
ans += 1
prev_min = p
print(ans) | 0 | null | 109,640,213,646,012 | 271 | 233 |
import sys
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
N = int(input())
if N == 1:
print(0)
sys.exit()
a = factorization(N)
ans = 0
for i in range(len(a)):
k = a[i][1]
cnt = 1
while k-cnt>=0:
k -= cnt
cnt += 1
ans += cnt-1
print(ans) | import sys
from io import StringIO
import unittest
import os
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if not arr:
arr.append([n, 1])
return arr
# 実装を行う関数
def resolve(test_def_name=""):
n = int(input())
target_s = factorization(n)
# 素因数1だけ処理対象外。
if sum([i[1] for i in target_s]) == 1:
if target_s[0][0] == 1:
print(0)
else:
print(1)
return
# 少ない物から使っていく。
cnt = 0
for i in range(1, 1000):
if not any([True if j[1] >= i else False for j in target_s]):
break
for target in target_s:
if target[1] < i:
continue
target[1] -= i
cnt += 1
print(cnt)
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve(sys._getframe().f_back.f_code.co_name)
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """24"""
output = """3"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """1"""
output = """0"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """64"""
output = """3"""
self.assertIO(test_input, output)
def test_input_4(self):
test_input = """1000000007"""
output = """1"""
self.assertIO(test_input, output)
def test_input_5(self):
test_input = """997764507000"""
output = """7"""
self.assertIO(test_input, output)
def test_1original_1(self):
test_input = """108"""
output = """3"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| 1 | 16,878,530,822,790 | null | 136 | 136 |
from math import ceil
def binary(N,LIST,num): # 二分探索 # N:探索要素数
l, r = -1, N
while r - l > 1:
if LIST[(l + r) // 2] > num: # 条件式を代入
r = (l + r) // 2
else:
l = (l + r) // 2
return r + 1
n, d, a = map(int, input().split())
xh = sorted(list(map(int, input().split())) for _ in range(n))
x = [i for i, j in xh]
h = [j for i, j in xh]
bomb, bsum, ans = [0] * (n + 1), [0] * (n + 1), 0
for i, xi in enumerate(x):
j = binary(n, x, xi + 2 * d) - 1
bsum[i] += bsum[i - 1] + bomb[i]
bnum = max(ceil(h[i] / a - bsum[i]), 0)
bomb[i] += bnum
bomb[j] -= bnum
bsum[i] += bnum
ans += bnum
print(ans)
| n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = map(int, input().split())
count = 0
for key in T:
U = S + [key]
i = 0
while U[i] != key:
i = i+1
if i != n:
count = count + 1
print(count) | 0 | null | 41,250,280,578,880 | 230 | 22 |
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]) | X=int(input())
i=0
while True:
if 100*i<=X and X<=105*i:
print(1)
exit()
elif 105*i<X and X<100*(i+1):
print(0)
exit()
i+=1
| 0 | null | 81,025,767,813,100 | 172 | 266 |
A,B,C,D=map(int,input().split())
nT = 0
nA = 0
while C-B>0:
C -= B
nT += 1
while A-D>0:
A -= D
nA += 1
if nT <= nA:
print('Yes')
else:
print('No')
| d_pre=input().split()
d=[int(s) for s in d_pre]
A=d[0]
B=d[1]
C=d[2]
D=d[3]
for i in range(210):
if i%2==0:
C-=B
if C<=0:
print("Yes")
break
else:
A-=D
if A<=0:
print("No")
break | 1 | 29,625,562,467,940 | null | 164 | 164 |
from collections import defaultdict
def main():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
S = [0] * (N + 1) # 累積和
for i in range(1, N + 1):
S[i] = S[i - 1] + A[i - 1]
T = [(s - i) % K for i, s in enumerate(S)]
counter = defaultdict(int)
ans = 0
for j in range(N + 1):
if j >= K:
counter[T[j - K]] -= 1
ans += counter[T[j]]
counter[T[j]] += 1
print(ans)
if __name__ == '__main__':
main()
| import math
while 1:
# input the students number
n = input()
if n == 0:
break
# input the points
s = map(float, raw_input().split())
# get the average of points
ave = 0
for i in s:
ave += i
ave = ave / len(s)
# get the standard deviation
alpha = 0
for i in s:
alpha += (i - ave)*(i - ave)
alpha = math.sqrt( alpha/len(s) )
# print
print alpha | 0 | null | 68,538,290,106,950 | 273 | 31 |
n = int(input())
d = [-1]*(n+1)
adjacent_list = [[] for _ in range(n+1)]
for _ in range(n):
edge = list(map(int,input().split()))
if len(edge) >= 3:
adjacent_list[edge[0]].extend(edge[2:])
from collections import deque
que = deque()
que.append(1)
d[1] = 0
while len(que) != 0:
v = que.popleft()
for nv in adjacent_list[v]:
if d[nv] == -1:
d[nv] = d[v] + 1
else:
continue
que.append(nv)
for i,dist in enumerate(d):
if i == 0:
continue
print(i,dist)
| import sys
lines = sys.stdin.readlines()
l = map(int, lines[1].split())
print min(l),max(l),sum(l) | 0 | null | 359,903,378,368 | 9 | 48 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
def main():
mod = 10**9+7
K = int(input())
S = input()
Nk = len(S)
ret = 0
nCk = 1
pw25 = 1
pw26 = pow(26,K,mod)
inv26 = pow(26,mod-2,mod)
for i in range(K+1):
ret += nCk * pw25 * pw26
ret %= mod
nCk *= (i+Nk) * pow(i+1,mod-2,mod)
nCk %= mod
pw25 = (pw25*25)%mod
pw26 = (pw26*inv26)%mod
print(ret)
if __name__ == '__main__':
main()
| import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 998244353
N, K = MAP()
A = LIST()
dp = list2d(N+1, K+1, 0)
dp[0][0] = 1
for i, a in enumerate(A):
for j in range(K+1):
dp[i+1][j] += dp[i][j] * 2
dp[i+1][j] %= MOD
if j+a <= K:
dp[i+1][j+a] += dp[i][j]
dp[i+1][j+a] %= MOD
ans = dp[N][K]
print(ans)
| 0 | null | 15,292,234,994,700 | 124 | 138 |
import sys
input = sys.stdin.readline
def main():
ans = 0
H, W, M = map(int, input().split())
bombs = []
hs = [0]*(H)
ws = [0]*(W)
for _ in range(M):
h, w = map(int, input().split())
bombs.append(tuple([h-1, w-1]))
hs[h-1] += 1
ws[w-1] += 1
maxh = max(hs)
maxw = max(ws)
ans = maxh + maxw
maxhindex = [i for i, x in enumerate(hs) if x == maxh]
maxwindex = [i for i, x in enumerate(ws) if x == maxw]
isfound = False
bombs = set(bombs)
for i in maxhindex:
for j in maxwindex:
if (i, j) not in bombs:
print(ans)
exit()
print(ans-1)
if __name__ == '__main__':
main() | h,w,m = map(int,input().split())
t = [tuple(map(lambda x:int(x)-1,input().split())) for _ in range(m)]
ht = [0]*h
wt = [0]*w
for y,x in t:
ht[y] += 1
wt[x] += 1
htm = max(ht)
wtm = max(wt)
htt = [i for i in range(h) if ht[i]==htm]
wtt = [i for i in range(w) if wt[i]==wtm]
ans = htm+wtm-1
t = set(t)
for i in htt:
for j in wtt:
if (i,j) not in t:
print(htm+wtm)
exit()
print(htm+wtm-1) | 1 | 4,683,597,901,398 | null | 89 | 89 |
n, m = map(int, input().split())
def find(x):
if par[x] < 0:
return x
else:
par[x] = find(par[x])
return par[x]
#xとyの属する集合の併合
def unite(x,y):
x = find(x)
y = find(y)
if x == y:
return False
else:
#sizeの大きいほうがx
if par[x] > par[y]:
x,y = y,x
par[x] += par[y]
par[y] = x
return True
#xとyが同じ集合に属するかの判定
def same(x,y):
return find(x) == find(y)
#xが属する集合の個数
def size(x):
return -par[find(x)]
par = [-1]*(n+1)
for i in range(m):
a, b = map(int, input().split())
unite(a, b)
ans = 0
for i in range(1,n+1):
ans = max(ans, size(i))
print(ans) | t = list(map(int, input().split()))
m = (t[2] - t[0]) * 60 + (t[3] - t[1])
print(m - t[4]) | 0 | null | 10,963,153,177,018 | 84 | 139 |
def resolve():
print("Yes" if "7" in input() else "No")
if '__main__' == __name__:
resolve() | N = input()
flag = False
for i in range(len(N)):
if N[i] =="7":
flag =True
if flag:
print ("Yes")
else :
print ("No") | 1 | 34,477,113,322,510 | null | 172 | 172 |
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():
a, v = rl()
b, w = rl()
t = ri()
d = abs(a - b)
s = v - w
if t * s >= d:
print ("YES")
else:
print ("NO")
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
| A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
if B > A:
A = A + V*T
B = B + W*T
if A >= B:
print('YES')
else:
print('NO')
else:
A = A - V*T
B = B - W*T
if A <= B:
print('YES')
else:
print('NO') | 1 | 15,014,224,328,248 | null | 131 | 131 |
n = int(input())
a = list(map(int, input().split()))
p = sorted([(x, i) for i, x in enumerate(a)], reverse=True)
dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
for s in range(1, n+1):
for x in range(s+1):
y = s-x
if x > 0:
dp[x][y] = max(dp[x][y], dp[x-1][y] + abs(p[s-1][1] - x + 1) * p[s-1][0])
if y > 0:
dp[x][y] = max(dp[x][y], dp[x][y-1] + abs(n-y - p[s-1][1]) * p[s-1][0])
print(max(dp[x][n-x] for x in range(n+1))) | '''
ITP-1_3-C
2 ????????°?????????
???????????´??° x, y ?????????????????????????????????????°?????????????????????????????????°?????????????????????????????????
?????????????????????????????\?????????????????????????????????????????????????????????????????????????????¨?????¨?????????????????????
???Input
??\???????????°????????????????????????????§?????????????????????????????????????????????????????????§??????????????????????????´??° x, y ?????????
?????????????§?????????????????????????
???Output
??????????????????????????¨??????x ??¨ y ????°????????????????????????????????????????????????????????????????x ??¨ y ????????????????????????????????\??????????????????
'''
# import
import sys
# input???????????????
for inputData in sys.stdin:
inputData = inputData.split(" ")
inputData01, inputData02 = int(inputData[0]), int(inputData[1])
# 0?????´??? ????????????
if inputData01 == 0:
if inputData02 == 0:
break
if inputData01 > inputData02:
outputData01 = inputData02
outputData02 = inputData01
else:
outputData01 = inputData01
outputData02 = inputData02
# ????????????
print((outputData01), (outputData02)) | 0 | null | 16,997,884,514,040 | 171 | 43 |
n,m=map(int,raw_input().split())
c=map(int,raw_input().split())
dp=[[0]+[float('inf')]*n]+[[0]+[float('inf')]*n for i in xrange(m)]
for i in xrange(m):
for j in xrange(n+1):
if c[i]>j:
dp[i+1][j]=dp[i][j]
else:
dp[i+1][j]=min(dp[i][j],dp[i+1][j-c[i]]+1)
print(dp[m][n]) | cards = []
mark = ["S","H","C","D"]
for i in range(4):
mk = mark[i]
for j in range(1,14):
cards.append("{} {}".format(mk,j))
n = int(input())
for _ in range(n):
card = input()
cards.remove(card)
for i in cards:
print(i) | 0 | null | 591,534,789,692 | 28 | 54 |
N,T=map(int,input().split())
L=[]
for i in range(N):
a,b=map(int,input().split())
L.append((a,b))
L.sort()
DP=[[0 for i in range(T)] for j in range(N+1)]
for i in range(1,N+1):
for j in range(T):
if i>0 and j-L[i-1][0]>=0:
DP[i][j]=max(DP[i-1][j-L[i-1][0]]+L[i-1][1],DP[i-1][j])
else:
DP[i][j]=DP[i-1][j]
ans=0
for i in range(N+1):
if i!=N:
ans=max(ans,DP[i][T-1]+L[i][1])
else:
ans=max(ans,DP[i][T-1])
print(ans) | r, b = input().split()
a, b = map(int, input().split())
u = input()
if r == u:
print(a-1, b)
else:
print(a, b-1) | 0 | null | 111,587,615,513,640 | 282 | 220 |
(W,H,x,y,r)=map(int,raw_input().split())
if r<=x and r<=y and x<=W-r and y<=H-r : print "Yes"
else : print "No" | n, m, x = map(int,input().split())
c = [0] *(n)
a = [[0] for _ in range(n)]
ans = 10**10
for i in range(n):
ca = list(map(int,input().split()))
c[i] = ca[0]
a[i] = ca[1:]
for i in range(1 << n):
skill = [0] * m
total_cost = 0
for j in range(n):
if (i>>j) & 1:
total_cost += c[j]
skill = [skill[t] + a[j][t] for t in range(m)]
if all (y >= x for y in skill):
ans = min(ans, total_cost)
if ans == 10**10:
print(-1)
else:
print(ans) | 0 | null | 11,380,817,053,060 | 41 | 149 |
S = int(input())
print (S//3600, (S%3600)//60, S%60, sep = ":")
| x = input()
a = x/3600
b = x%3600/60
c = x - a*3600 - b*60
print '%d:%d:%d'%(a, b, c) | 1 | 340,989,309,220 | null | 37 | 37 |
a,b = map(int, raw_input().split())
print "%d %d %lf" % (a/b, a%b, a/(1.0*b)) | a,b = map(int,input().split())
d=(a-a%b)/b
r=a%b
f=a/b
print(f"{d} {r} {f:.5f}")
| 1 | 600,315,048,340 | null | 45 | 45 |
def main():
T = input()
T = T.replace('?', 'D')
# cnt = 0
# cnt_pd = t.count('PD')
# cnt_d = t.count('D')
# cnt = cnt_d + cnt_pd
print(T)
main() | def main():
from sys import stdin
from math import sqrt
readline = stdin.readline
N,D = list(map(int,readline().rstrip().split()))
count = 0
for X in range(N):
X1,X2 = list(map(int,readline().rstrip().split()))
if sqrt(X1**2 + X2**2) <= D :
count += 1
print(count)
main() | 0 | null | 12,269,820,951,962 | 140 | 96 |
from collections import Counter
N,*D = map(int, open(0).read().split())
MOD = 998244353
c = Counter(D)
cnt = 1
M = max(c.keys())
ans = 1
if D[0]!=0 or c[0]!=1:
print(0)
import sys
sys.exit()
while cnt<=M:
ans *= c[cnt-1]**c[cnt]
ans %= MOD
cnt += 1
print(ans) | from collections import Counter
N = input()
D_list = list(map(int, input().split()))
max_D = max(D_list)
cnt_dic = dict(Counter(D_list))
if (D_list[0] == 0) & (cnt_dic.get(0) == 1):
ans = 1
for n in range(1, max_D + 1):
ans *= cnt_dic.get(n - 1, 0) ** cnt_dic.get(n, 1)
print(ans % 998244353)
else:
print(0) | 1 | 154,443,402,850,112 | null | 284 | 284 |
# ABC151
# A Next Alphabet
c = input()
l = [chr(ord("a")+i) for i in range(26)]
for i in range(26):
if l[i] == c:
print(l[i+1])
break
| #a(n) = 2^ceiling(log_2(n+1))-1
import math
print(2**(math.ceil(math.log2(int(input())+1)))-1) | 0 | null | 86,078,707,552,640 | 239 | 228 |
if __name__ == "__main__":
W, H, x, y, r = input().split()
W, H, x, y, r = int(W), int(H), int(x), int(y), int(r)
if (x - r) < 0 or W < (x + r) or (y - r) < 0 or H < (y + r):
print("No")
else:
print("Yes") | w,h,x,y,r=map(int,raw_input().split())
f=0
if x+r>w:
f=1
if y+r>h:
f=1
if r>x:
f=1
if r>y:
f=1
if f==0:
print "Yes"
else:
print "No" | 1 | 449,974,483,168 | null | 41 | 41 |
from math import ceil
t1,t2 = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
a1 -= b1
a2 -= b2
a1 *= t1
a2 *= t2
if a1 + a2 == 0:
print("infinity")
exit()
if a1*(a1+a2) > 0:
print(0)
exit()
x = -a1/(a1+a2)
n = ceil(x)
if n == x:
print(2*n)
else:
print(2*n-1) | T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
d1 = T1*(A1-B1)
d2 = T2*(A2-B2)
if d1>d2:
d1 *= -1
d2 *= -1
if (d1>0 and d1+d2>0) or (d1<0 and d1+d2<0):
print(0)
elif d1+d2==0:
print("infinity")
else:
v = (abs(d1)//(d1+d2))
ans = v*2
pos = d1+v*(d1+d2)
if pos<0 and pos+d2>=0:
ans += 1
print(ans) | 1 | 131,511,766,591,400 | null | 269 | 269 |
import numpy as np
N = int(input())
#N,K,d= map(int,input().split())
#A = list(map(int,input().split()))
#S = str(input())
#T = str(input())
num=np.zeros(10**4+1)
for x in range(1,100):
for y in range(1,100):
for z in range(1,100):
ans = x**2 + y**2 + z**2 + x*y + y*z + z*x
if ans < 10**4+1:
num[ans]+=1
for i in range(N):
print(int(num[i+1]))
| n=int(input())
ans=[0 for i in range(10**5)]
for x in range(1,100):
for y in range(1,100):
for z in range(1,100):
tmp=x*x+y*y+z*z+x*y+y*z+z*x
ans[tmp]+=1
for i in range(1,n+1):
print(ans[i]) | 1 | 8,032,661,154,138 | null | 106 | 106 |
X = input()
S = input()
print(S.count("ABC")) | import math
a,b,h,m=map(int,input().split())
hc=360/12*h+30/60*m #時針の角度
mc=360/60*m #分針の角度
hm=abs(hc-mc) #時針と分針の角度の差
if hm > 180:
hm=360-hm
mcos=math.cos(math.radians(hm))
c=a**2+b**2-(2*a*b*mcos) #余剰定理
print(math.sqrt(c)) | 0 | null | 59,827,376,344,742 | 245 | 144 |
N = int(input())
print(-(N%-1000)) | n = int(input())
a = []
b = []
for i in range(n):
s = input()
x = 0
y = 0
for c in s:
if c == '(':
y += 1
else:
if y >= 1:
y -= 1
else:
x += 1
if x < y: a.append([x, abs(x-y)])
else: b.append([y, abs(x-y)])
def calc(a):
ret = 0
for x, y in sorted(a):
if ret < x: return -1
ret += y
return ret
res1 = calc(a)
res2 = calc(b)
print("Yes" if res1 >= 0 and res1 == res2 else "No") | 0 | null | 16,171,048,537,702 | 108 | 152 |
n = input().strip()
h = list(map(int, input().strip().split()))
m = 0
for i in range(len(h)):
d = h[i - 1] - h[i]
if i > 0 and d >= 0:
m += d
h[i] += d
print(m) |
def main():
n, m = map(int, input().split(" "))
a =list(map(int, input().split(" ")))
if n - sum(a) <0:
print(-1)
else:
print(n-sum(a))
if __name__ == "__main__":
main() | 0 | null | 18,285,052,775,360 | 88 | 168 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
s = input()
print("ARC") if s == "ABC" else print("ABC") | def main():
a, b, c = map(int, input().split())
if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| 0 | null | 37,749,923,481,742 | 153 | 197 |
K = int(input())
S = input()
s = len(S)
mod = int(1e9+7)
n = pow(26, K, mod)
ans = n
for i in range(K):
n = n*25*(s+i)*pow(26*(i+1),-1,mod)%mod
ans = (ans +n) % mod
print(ans) | import sys
def input(): return sys.stdin.readline().rstrip()
class Sieve: #区間[2,n]の値の素因数分解
def __init__(self,n=1):
self.primes=[]
self.f=[0]*(n+1) #ふるい(素数ならその値)
self.f[0]=self.f[1]=-1
for i in range(2,n+1): #素数リスト作成
if self.f[i]: continue
self.primes.append(i)
self.f[i]=i
for j in range(i*i,n+1,i):
if not self.f[j]:
self.f[j]=i # 最小の素因数を代入
def is_prime(self, x):
return self.f[x]==x
def prime_fact(self,x): # 素因数分解の昇順リスト, {2:p,3:q,5:r,...}
fact_dict=dict()
while x!=1:
p=self.f[x]
fact_dict[p]=fact_dict.get(p,0)+1
x//=self.f[x]
return fact_dict
def main():
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
p_lis={}
Prime=Sieve(10**6+5)
for a in A:
f=Prime.prime_fact(a)
#print(f)
for key in f:
p_lis[key]=max(p_lis.get(key,0),f[key])
lcm=1
#print(p_lis)
for key in p_lis:
lcm=(lcm*pow(key,p_lis[key],mod))%mod
ans=0
#print(lcm)
for a in A:
b=lcm*pow(a,mod-2,mod)%mod
ans=(ans+b)%mod
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 50,488,973,505,540 | 124 | 235 |
a= input()
c=""
for i in range(0, len(a)):
if a[i]=="?":
c=c+"D"
else:
c=c+a[i]
print(c) | from sys import stdin
a, b = map(int, stdin.readline().rstrip().split())
ans = max(0, a - 2 * b)
print(ans)
| 0 | null | 92,911,162,722,080 | 140 | 291 |
from collections import deque
n = int(input())
G = []
for _ in range(n):
u, k, *v = map(int, input().split())
u -= 1
G.append(v)
q = deque()
seen = [False] * n
dist = [-1] * n
def main():
q.append(0)
seen[0] = True
dist[0] = 0
while len(q) > 0:
now_v = q.popleft()
for new_v in G[now_v]:
new_v -= 1
if seen[new_v] is True:
continue
seen[new_v] = True
q.append(new_v)
# print(now_v, new_v)
dist[new_v] = dist[now_v] + 1
for i in range(n):
print(i+1, dist[i])
if __name__ == '__main__':
main()
| import sys
n = int(input())
input_line = [[int(i) for i in str.split()] for str in sys.stdin.read().splitlines()]
for i in range(n):
input_line[i] = [] if len(input_line[i]) == 2 else input_line[i][2:]
is_visit = [False] * n
distance = [0] * n
queue = [1]
while len(queue) != 0:
id = queue.pop(0)
is_visit[id-1] = True
for node_id in input_line[id-1]:
if not is_visit[node_id-1]:
distance[node_id-1] = distance[id-1] + 1
queue.append(node_id)
is_visit[node_id-1] = True
for i in range(n):
d = distance[i] if is_visit[i] else -1
print('{0} {1}'.format(i+1, d))
| 1 | 4,135,722,500 | null | 9 | 9 |
from math import gcd
K = int(input())
ans = 0
for h in range(1, K+1):
for i in range(1, K+1):
for j in range(1, K+1):
ans += gcd(h, gcd(i, j))
print(ans) | N = int(input())
kotae = []
for i in range(1,N+1):
for j in range(1,N+1):
for k in range(1,N+1):
s = i
t = j
u = k
x = 1
while x != 0:
v = t%s
if v != 0:
t = s
s = v
else:
t = s
x = u%t
if x != 0:
u = t
t = x
else:
kotae.append(t)
print(sum(kotae)) | 1 | 35,594,112,497,218 | null | 174 | 174 |
n, d = map(int, input().split())
cnt = 0
for i in range(n):
x, y = map(int, input().split())
if x*x + y*y <= d*d:
cnt += 1
print(cnt) | n = int(input())
cnt = [1] * (n + 1)
cnt[0] = 0
cnt[1] = 0
p = 2
while p <= n // 2:
for i in range(p*2, n+1, p):
cnt[i] += 1
p += 1
ans = 0
for i in range(1, n+1):
# print(i, cnt[i]+1)
ans += i * (cnt[i] + 1)
print(ans)
| 0 | null | 8,445,953,019,460 | 96 | 118 |
def print_frame(h, w):
"""
h: int(3 <= h <= 300)
w: int(3 <= w <= 300)
outputs a rectangle frame h x w
>>> print_frame(3, 4)
####
#..#
####
>>> print_frame(5, 6)
######
#....#
#....#
#....#
######
>>> print_frame(3, 3)
###
#.#
###
"""
print('#' * w)
for i in range(h-2):
print('#' + '.'*(w-2) + '#')
print('#' * w)
if __name__ == '__main__':
while True:
(h, w) = [int(i) for i in input().split(' ')]
if h == 0 and w == 0:
break
print_frame(h, w)
print() | from math import ceil
n = int(input())
a = [chr(i) for i in range(97, 97+26)]
s = 0
for i in range(1,100):
l = n - s
s += 26**i
if n <= s:
m = i
break #第m群l番目
name = [0] * m
div = [0] * m
rem = [0] * m
rem[-1] = l
for j in range(m):
div[j] = ceil(rem[j-1] / (26**(m-j-1)))
rem[j] = rem[j-1] % (26**(m-j-1))
if rem[j] == 0:
rem[j] == 26**(m-j-1)
name[j] = a[div[j]-1]
print(''.join(name)) | 0 | null | 6,325,336,936,192 | 50 | 121 |
from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
abcds = [tuple(map(int, input().split()))for _ in range(Q)]
def cal_score(A):
score = 0
for a, b, c, d in abcds:
if A[b-1] - A[a-1] == c:
score += d
return score
ans = 0
for A in combinations_with_replacement([i for i in range(M)], N):
ans = max(ans, cal_score(A))
print(ans)
| # -*- coding: utf-8 -*-
from itertools import combinations_with_replacement
def main():
n, m, q = map(int, input().split())
xs = []
for i in range(q):
xs.append(list(map(int, input().split())))
max = 0
for suretu in combinations_with_replacement(range(1, m + 1), n):
wa = 0
for x in xs:
a, b, c, d = x
if suretu[b - 1] - suretu[a - 1] == c:
wa += d
if wa > max:
max = wa
print(max)
if __name__ == "__main__":
main()
| 1 | 27,610,091,428,066 | null | 160 | 160 |
s=input()
t=input()
print(min(sum(x!=y for x,y in zip(s[i:],t))for i in range(-~len(s)-len(t)))) | value = int(input())
h, value = value // 3600, value - (value//3600) * 3600
m, value = value //60, value - (value // 60) * 60
s = value
print("%d:%d:%d" %(h,m,s))
| 0 | null | 2,030,795,290,358 | 82 | 37 |
x, y, z = map(int, input().split())
createNum = 0
createTime = 0
loopCnt = x//y
createNum = y*loopCnt
createTime = z*loopCnt
remain = x%y
if remain != 0:
createTime += z
print(createTime) | import numpy as np
list_data = [int(x) for x in input().split(" ")]
print(np.ceil(list_data[0] / list_data[1]).astype(int) * list_data[2]) | 1 | 4,290,991,182,170 | null | 86 | 86 |
X = int(input())
c1 = X//500
X = X - c1*500
c2 = X//5
print(c1*1000 + c2*5) | X=int(input())
a=int(X/500)
s=1000*a
X-=500*a
b=int(X/5)
s+=5*b
print(s) | 1 | 42,865,772,115,770 | null | 185 | 185 |
def main() :
n = int(input())
nums = [int(i) for i in input().split()]
flag = True
count = 0
index = 0
while flag :
flag = False
for i in reversed(range(index+1, n)) :
if nums[i-1] > nums[i] :
nums[i-1], nums[i] = nums[i], nums[i-1]
count += 1
flag = True
index += 1
nums_str = [str(i) for i in nums]
print(" ".join(nums_str))
print(count)
if __name__ == '__main__' :
main() | W, H, x, y, r = map(int, input().split())
if x == 0 or y == 0 or x < 0 or y < 0:
print("No")
elif W == x or H == y:
print("No")
elif W < x or H < y:
print("No")
elif W < x+r or H < y+r:
print("No")
else:
print("Yes") | 0 | null | 241,410,453,582 | 14 | 41 |
a, b, c = map(int, input().split())
if(a > b) :
a, b = b, a
if(b > c) :
b, c = c, b
if(a > b) :
a, b = b, a
else :
pass
else :
pass
print(a, b, c)
else :
if(b > c) :
b, c = c, b
if(a > b) :
a, b = b, a
else :
pass
else :
pass
print(a, b, c)
| N = int(input())
As = list(map(int,input().split()))
if(N == 0):
if(As[0] == 1):
print(1)
else:
print(-1)
else:
flag = True
if(As[0] != 0):
flag = False
if(flag):
D = [[0]*3 for i in range(N+1)]
D[0] = [1,1,0] # mind maxD Ed
for i in range(1,N+1):
if(As[i] > 2*D[i-1][1]):
flag = False
break
else:
D[i][0] = max(0,D[i-1][0] - As[i])
D[i][1] = min(2*D[i-1][1] - As[i],1 << i)
D[i][2] = As[i]
if(flag):
D[N][1] = 0
maxcnt = 0
for i in range(N,-1,-1):
depthmax = D[i][1] + D[i][2]
maxcnt += depthmax
if(i > 0):
D[i-1][1] = min(D[i-1][1],depthmax)
print(maxcnt)
else:
print(-1)
| 0 | null | 9,558,177,326,502 | 40 | 141 |
a1,a2,a3=map(int,input().split())
if a1+a2+a3<=21 :
print("win")
else :
print("bust") | a,b=map(int,input().split())
while b: a,b=b,a%b
print(a) | 0 | null | 59,451,123,084,450 | 260 | 11 |
def main():
A, B, K = map(int, input().split())
if A - K > 0:
print(A - K, B)
elif B + A - K > 0:
print(0, B + A - K)
else:
print(0, 0)
main()
| A,B,K = map(int,input().split())
if A>=K:
answer = A-K,B
elif A+B>=K:
answer = 0,B-(K-A)
else:
answer = 0,0
print(answer[0],answer[1]) | 1 | 104,698,617,265,530 | null | 249 | 249 |
N = int(input())
for i in range(10):
for j in range(10):
if i * j == N:
print("Yes")
exit(0)
else:
print("No") | def main():
N = int(input())
def check():
for i in range(1, 10):
for j in range(1, 10):
if i * j == N:
return True
return False
cond = check()
print('Yes' if cond else 'No')
if __name__ == '__main__':
main()
| 1 | 159,424,837,844,930 | null | 287 | 287 |
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
ans=0
for i in range(1,n+1):
num=n//i
ans+=(num*(i+num*i))//2
print(ans) | n = int(raw_input())
d = [0] * n
f = [0] * n
M = [[0]*n for _ in xrange(n)]
color = [0] * n
tt = 0
WHITE = 0
GRAY = 1
BLACK = 2
def dfs_visit(u):
global tt
color[u] = GRAY
tt += 1
d[u] = tt
for v in xrange(n):
if M[u][v] == 0:
continue
if color[v] == WHITE:
dfs_visit(v)
color[u] = BLACK
tt += 1
f[u] = tt
return 0
def dfs():
for u in xrange(n):
if color[u] == WHITE:
dfs_visit(u)
for u in xrange(n):
print "{} {} {}".format(u+1, d[u], f[u])
return 0
def main():
for i in xrange(n):
a = map(int, raw_input().split())
u = a[0]-1
k = a[1]
for j in xrange(k):
v = a[j+2] - 1
M[u][v] = 1
dfs()
return 0
main() | 0 | null | 5,574,193,727,906 | 118 | 8 |
while 1:
x=raw_input()
if x=='0':break
sum=0
for i in x:
sum+=int(i)
print sum | while 1:
x = raw_input()
if x == '0': break;
print sum([int(d) for d in x]) | 1 | 1,556,371,376,028 | null | 62 | 62 |
while True:
n = int(input())
if n == 0:
break
s = list(map(int, input().split()))
kei = 0
for p in s:
kei += p
m = kei / n
a = 0
for p in s:
a += ((p - m)**2) / n
import math
h = math.sqrt(a)
print(h) | import math
n = []
score = []
scores = []
while True:
input_n = int(input())
if input_n == 0:
break
n.append(input_n)
input_score = [int(i) for i in input().split()]
score.append(input_score)
def total(scorelist):
total = 0
for i in range(len(scorelist)):
total = total + scorelist[i]
return total
def ave(total,n):
return float(total / n)
def variance(scorelist,ave,n):
total = 0
for i in range(len(scorelist)):
total = total + math.pow(scorelist[i]-ave,2)
return total / n
for i in range(len(n)):
total_score = total(score[i])
average = ave(total_score,n[i])
var = variance(score[i],average,n[i])
print(math.sqrt(var)) | 1 | 190,086,148,838 | null | 31 | 31 |
# 解説AC
import sys
input = sys.stdin.buffer.readline
n = int(input())
A = list(map(int, input().split()))
B = []
for i, e in enumerate(A):
B.append((e, i + 1))
B.sort(reverse=True)
# dp[i][j]: Aiまで入れた時、左にj個決めた時の最大値
dp = [[-1] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(i + 1): # 左の個数
k = i - j # 右の個数
ni = i + 1
val, idx = B[i]
dp[ni][j] = max(dp[ni][j], dp[i][j] + abs(n - k - idx) * val)
dp[ni][j + 1] = max(dp[ni][j + 1], dp[i][j] + abs(idx - (j + 1)) * val)
ans = 0
for i in range(n + 1):
ans = max(ans, dp[n][i])
print(ans)
| n = int(input())
a = list(map(int,input().split()))
a = [(num,i) for i,num in enumerate(a)]
a.sort(reverse=True)
dp=[[0]*(n+1) for _ in range(n+1)]
for i in range(n+1):
for j in range(n-i+1):
if i>0:
dp[i][j] = max(dp[i][j],dp[i-1][j]+a[i+j-1][0]*abs(a[i+j-1][1]-(i-1)))
if j>0:
dp[i][j] = max(dp[i][j],dp[i][j-1]+ a[i+j-1][0]*abs(a[i+j-1][1]-(n-j)))
ans = max(dp[i][n-i] for i in range(n+1))
print(ans)
| 1 | 33,783,103,105,988 | null | 171 | 171 |
def coin(n, p, c):
global count
global m
if n % c[0] == 0:
count = min(count, p + n // c[0])
return count
elif p + n // c[0] >= count:
return n
elif c[0] < n:
return min(coin(n - c[0], p + 1, c), coin(n, p, c[1:]))
else:
return coin(n, p, c[1:])
n, m = map(int, input().split())
mon = list(map(int, input().split()))
mon.sort(reverse = True)
count = n
print(coin(n, 0, mon))
| a,b,c = [int(i) for i in input().split()]
print("Yes" if(a * a + b * b + c * c - 2 * a * b - 2 * b * c - 2 * c * a > 0 and c - a - b > 0) else "No") | 0 | null | 25,966,195,714,492 | 28 | 197 |
import math
def main():
h, a = list(map(int, input().split()))
print(math.ceil(h/a))
if __name__ == '__main__':
main() |
N, M = map(int, input().split())
A = list(map(int, input().split()))
line = sum(A)/(4*M)
cnt = 0
for a in A:
if a >= line:
cnt += 1
if cnt >= M:
print("Yes")
else:
print("No")
| 0 | null | 58,203,513,888,014 | 225 | 179 |
n,s=map(int,input().split())
a=list(map(int,input().split()))
#dp[n][s]
#nこめまで選んだ時の和がsの組
dp=[[0]*(s+1) for _ in range(n)]
a.sort()
#for i in range(s+1):
# dp[0][i]=2
if a[0]>s:
print(0)
exit()
mod=998244353
dp[0][0]=2
dp[0][a[0]]+=1
for i in range(1,n):
for j in range(s+1):
#i番目を入れて選択するパターン
dp[i][j]=dp[i-1][j]*2%mod
if j>=a[i]:
dp[i][j]+=dp[i-1][j-a[i]]%mod
print(dp[-1][s]%mod)
| def main():
from string import ascii_lowercase
c = input()
ind = ascii_lowercase.index(c)
ind += 1
print(ascii_lowercase[ind])
if __name__ == '__main__':
main()
| 0 | null | 55,277,270,499,880 | 138 | 239 |
# print('input >>')
N, K = map(int,(input().split()))
ps = list(map(int,(input().split())))
ps.sort()
# print('-----output-----')
print(sum(ps[:K])) | N, K = map(int,input().split())
P = list(map(int,input().split()))
P.sort()
price = sum(P[:K])
print(price) | 1 | 11,646,694,239,750 | null | 120 | 120 |