code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
178,025B
⌀ | question_pair_id
float64 27.1M
177,113B
⌀ | code1_group
int64 1
297
| code2_group
int64 1
297
|
---|---|---|---|---|---|---|
N = int(input())
# Nを 1以上 9以下の 2つの整数の積として表すことができるなら Yes を、できないなら No を出力せよ。
for i in range(1, 9+1):
for j in range(1, 9+1):
if i * j == N:
print("Yes")
exit()
else:
print("No") | def main():
s = int(input())
mod = 10**9 + 7
dp = [0] * (s+1)
dp[0] = 1
# for i in range(1, s+1):
# for j in range(0, (i-3)+1):
# dp[i] += dp[j]
# dp[i] %= mod
for i in range(1, s+1):
if i < 3:
dp[i] = 0
else:
dp[i] = dp[i-1] + dp[i-3]
dp[i] %= mod
print(dp[-1])
if __name__ == "__main__":
main()
| 0 | null | 81,622,066,098,990 | 287 | 79 |
N=int(input())
#people
li = list(map(int, input().split()))
Ave1=sum(li)//N
Ave2=sum(li)//N+1
S1=0
S2=0
for i in range(N):
S1=S1+(Ave1-li[i])**2
for i in range(N):
S2=S2+(Ave2-li[i])**2
if S1>S2:
print(S2)
else:
print(S1) | n = input()
s = list(map(int,input().split()))
m = 10000000
for p in range(0,101):
t = 0
for x in s:
t+=(x-p)**2
m = min(t,m)
print(m) | 1 | 65,490,086,778,590 | null | 213 | 213 |
s = list(str(input()))
q = int(input())
from collections import deque
s = deque(s)
cnt = 0
for i in range(q):
query = list(map(str, input().split()))
if len(query) == 1:
cnt += 1
else:
t, f, c = query
if f == '1':
if cnt%2 == 0:
s.appendleft(c)
else:
s.append(c)
else:
if cnt%2 == 0:
s.append(c)
else:
s.appendleft(c)
s = list(s)
if cnt%2 == 1:
s.reverse()
print(''.join(s))
| s=input()
q=int(input())
f=""
b=""
r=0
for i in range(q):
query=input().split()
if int(query[0])==1:
r=1-r
else:
if (r^(int(query[1])-1))==0:
f+=query[2]
else:
b+=query[2]
ret=f[::-1]+s+b
if r:
ret=ret[::-1]
print(ret) | 1 | 57,083,693,907,280 | null | 204 | 204 |
A, B, K = [int(s) for s in input().split(' ')]
print(max(0, A - K), max(0, (B - max(0, K - A))))
| N = int(input())
if N == 1:
print(0)
exit()
if N == 2:
print(2)
exit()
# N >= 3
# 全事象
all_pattern = 10 ** N
# 0も9もない
pattern_a = 8 ** N
# 0あるが9ない
pattern_b = 9 ** N - 8 ** N
ans = all_pattern - pattern_a - pattern_b * 2
ans = ans % (10**9 + 7)
print(ans) | 0 | null | 53,844,859,171,562 | 249 | 78 |
from collections import Counter
s = list(input())
k = int(input())
ans = 0
s_d = s*2
for i in range(1,len(s_d)):
if s_d[i-1]==s_d[i]:
s_d[i] = '_'
if i>=len(s_d)//2:
ans+=k-1
else:
ans+=1
s_s = set(s)
if len(s_s)==1 and len(s)%2!=0:
ans = len(s)*(k//2)+(k%2==1)*(len(s)//2)
print(ans) | n,m = map(int,input().split())
alist = list(map(int,input().split()))
alist.sort(reverse=True)
allvote = sum(alist)
count = 0
for i in range(n):
if alist[i] >= allvote/(4*m):
count+=1
if count >= m:
print("Yes")
else:
print("No") | 0 | null | 107,076,120,307,308 | 296 | 179 |
import sys
from builtins import enumerate
from io import StringIO
import unittest
import os
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
# 実装を行う関数
def resolve(test_def_name=""):
# 数値取得サンプル
# 1行1項目 n = int(input())
# 1行2項目 x, y = map(int, input().split())
# 1行N項目 x = list(map(int, input().split()))
# N行1項目 x = [int(input()) for i in range(n)]
# N行N項目 x = [list(map(int, input().split())) for i in range(n)]
# 文字取得サンプル
# 1行1項目 x = input()
# 1行1項目(1文字ずつリストに入れる場合) x = list(input())
n, k = map(int, input().split())
p_s = [0] + list(map(int, input().split()))
avr_s = [0]
cumsum = 0
for i in range(1, 1001):
cumsum += i
avr_s.append(cumsum / i)
ans = 0
val = 0
for i in range(1, len(p_s)):
val += avr_s[p_s[i]]
if i < k:
continue
elif i == k:
ans = val
else:
val -= avr_s[p_s[i - k]]
ans = max(ans, val)
print(ans)
# テストクラス
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 = """5 3
1 2 2 4 5"""
output = """7.000000000000"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """4 1
6 6 6 6"""
output = """3.500000000000"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """10 4
17 13 13 12 15 20 10 13 17 11"""
output = """32.000000000000"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def tes_t_1original_1(self):
test_input = """データ"""
output = """データ"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
r = [0]*(n + 1)
for i in range(1,n + 1):
r[i] += r[i - 1] + (p[i - 1] + 1) / 2
ans = 0
for j in range(n - k + 1):
ans = max(ans, r[j+k] - r[j])
print(ans)
| 1 | 74,452,501,717,020 | null | 223 | 223 |
(h,n),*t=[map(int,o.split())for o in open(0)]
d=[0]+[9e9]*h
for a,b in t:
for j in range(h+1):d[j]=min(d[j],d[max(0,j-a)]+b)
print(d[h]) | import sys
from itertools import combinations_with_replacement
input = sys.stdin.readline
def main():
N, M, Q = map(int, input().split())
abcd = [None] * Q
for i in range(Q):
abcd[i] = list(map(int, input().split()))
abcd[i][0] -= 1
abcd[i][1] -= 1
ans = 0
for A in combinations_with_replacement(range(1, M + 1), N):
score = 0
for a, b, c, d in abcd:
if A[b] - A[a] == c:
score += d
if score > ans:
ans = score
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 54,464,037,820,940 | 229 | 160 |
h = int(input())
w = int(input())
n = int(input())
if h >= w and n%h != 0:
print(n//h+1)
elif h >= w and n%h == 0:
print(n//h)
elif w >= h and n%w != 0:
print(n//w+1)
else:
print(n//w) | H = int(input())
W = int(input())
N = int(input())
p = -1
if H > W:
p = H
else:
p = W
count = 1
result = 1
while True:
result = count * p
if result >= N:
print(count)
break
else:
count += 1
| 1 | 88,644,825,815,718 | null | 236 | 236 |
def getDivisor(a,b,c):
l = 0
for i in range(a, b+1):
if (c % i == 0):
l += 1
return l
a, b, c = map(int, input().split())
print(getDivisor(a,b,c)) | #ALDS_3_B 16D8103010K Ko Okasaki
from collections import deque
n,q=map(int,input().split())
que=deque()
for i in range(n):
name,time=input().split()
time=int(time)
que.append([name,time])
t=0
while len(que)>0:
que_t=que.popleft()
if que_t[1]>q:
que_t[1]-=q
t+=q
que.append(que_t)
else:
t+=que_t[1]
print(que_t[0],t)
| 0 | null | 296,013,119,600 | 44 | 19 |
n=int(input())
a=list(map(int,input().split()))
import sys
import math
def setwise_coprime(a):
ans=a[0]
for i in range(1,n):
ans=math.gcd(ans,a[i])
return ans
#エラストテネスのふるい
def create_sieve(n):
sieve=[0]*(n+1)
for i in range(2,n+1):
if sieve[i]==0:
for j in range(i*i,n+1,i):
sieve[j]=i
return sieve
#高速素因数分解
def fast_factorization(n, sieve):
prime={}
while n>1:
p=sieve[n]
#nが素数の場合
if p==0:
prime[n]=prime.get(n,0)+1
break
#nが素数ではない場合
else:
prime[p]=prime.get(p,0)+1
n=n//p
return prime
check=set()
if setwise_coprime(a)==1:
#素因数のダブリをcheck
sieve=create_sieve(10**6)
for i in range(n):
if a[i]!=1:
s=fast_factorization(a[i], sieve)
for i in s:
if i in check:
print("setwise coprime")
sys.exit()
else:
check.add(i)
print("pairwise coprime")
else:
print("not coprime")
|
def gen_factorization(N):
tables=[-1]*(N+1)
for i in range(2,N+1):
if tables[i]!=-1:continue
tmp=i
while tmp<=N:
tables[tmp]=i
tmp+=i
def fuctorization(n):
if n==1:return {1:1}
elif n<0:n=abs(n)
if n>N:return "error"
ans={}
while n!=1:
tmp=tables[n]
#debug print
#print(tmp,n)
ans.setdefault(tmp,0)
ans[tmp]+=1
n//=tmp
return ans
return fuctorization
N=int(input())
f=gen_factorization(10**6+10)
A=list(map(int,input().split()))
primes={}
for i in A:
d=f(i)
for j in d:
primes.setdefault(j,0)
primes[j]+=1
primes[1]=1
ansMax=max(primes.values())
if ansMax==1:
print('pairwise coprime')
elif ansMax==N:
print('not coprime')
else:
print('setwise coprime') | 1 | 4,117,614,567,462 | null | 85 | 85 |
import sys
sys.setrecursionlimit(10**7)
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 LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
S = LS2()
N = len(S)+1
ANS = [0]*N
for i in range(N-1):
if S[i] == '<':
ANS[i+1] = ANS[i]+1
for i in range(N-2,-1,-1):
if S[i] == '>':
ANS[i] = max(ANS[i],ANS[i+1]+1)
print(sum(ANS))
| import copy
def main():
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
if V <= W:
print('NO')
elif (abs(A-B) / (V-W)) <= T:
print('YES')
else:
print('NO')
main() | 0 | null | 85,971,082,899,712 | 285 | 131 |
arr = list(map(int, input().split()))
arr.sort()
if (arr[0] == arr[1]) and (arr[2] != arr[1]):
print("Yes")
elif (arr[1] == arr[2]) and (arr[0] != arr[1]):
print("Yes")
else:
print("No") | #!/usr/bin/env python3
x, y = [int(x) for x in input().split()]
p = [300000, 200000, 100000]
if x == 1 and y == 1:
print(1000000)
elif x <= 3 and y <= 3:
print(p[x - 1] + p[y - 1])
elif x <= 3:
print(p[x - 1])
elif y <= 3:
print(p[y - 1])
else:
print(0)
| 0 | null | 104,254,113,393,170 | 216 | 275 |
X, K, D = map(int, input().split())
XX = abs(X)
if XX > K*D:
print(XX - K*D)
else:
if (K - X//D)%2 == 0:
print(X%D)
else:
print(abs(X%D -D))
| #ABC 175 C
x, k, d = map(int, input().split())
x = abs(x)
syou = x // d
amari = x % d
if k <= syou:
ans = x - (d * k)
else:
if (k - syou) % 2 == 0: #残りの動ける数が偶数
ans = amari
else:#残りの動ける数が奇数
ans = abs(amari - d)
print(ans) | 1 | 5,222,530,647,008 | null | 92 | 92 |
from itertools import accumulate
def solve(string):
n, m, k, *ab = map(int, string.split())
a, b = [0] + ab[:n], [0] + ab[n:]
a, b = list(accumulate(a)), list(accumulate(b))
i, j = n, 0
while a[i] > k:
i -= 1
while j <= m and a[i] + b[j] <= k:
j += 1
ans = i + j - 1
for i in range(i, -1, -1):
while j <= m and a[i] + b[j] <= k:
j += 1
ans = max(ans, i + j - 1)
return str(ans)
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| from itertools import accumulate
from bisect import bisect_right
N, M, K = map(int,input().split())
A = [0]+list(accumulate(map(int,input().split()), lambda x,y:x+y))
B = [0]+list(accumulate(map(int,input().split()), lambda x,y:x+y))
ans = 0
for i in range(N+1):
left = K-A[i]
if left < 0:
break
j = bisect_right(B, left)
ans = max(ans, i+j-1)
print(ans) | 1 | 10,702,221,458,308 | null | 117 | 117 |
for n in range(1, 10):
for m in range(1, 10):
print(str(n) + "x" + str(m) + "=" + str(n*m)) | for i in range(1,10):
for j in range(1,10):
print(i,"x",j,"=",i*j,sep="")
j+=1
i+=1
| 1 | 260,370 | null | 1 | 1 |
from math import *
a,b,C=map(int,input().split())
C=C*pi/180
S=a*b*sin(C)/2
print(S,a+b+(a*a+b*b-2*a*b*cos(C))**0.5,2*S/a,sep='\n') | import math
def toRad(theta):
return theta * math.pi / 180
def calc_S(_a, _b, _c):
return (_a * _b * math.sin(toRad(_c))) / 2
def calc_L(_a, _b, _c):
return _a + _b + math.sqrt(_a**2 + _b**2 - 2*a*b*math.cos(toRad(_c)))
def calc_H(_a, _b, _c):
return _b * math.sin(toRad(_c))
a, b, c = map(int, input().split())
print(calc_S(a, b, c))
print(calc_L(a, b, c))
print(calc_H(a, b, c)) | 1 | 177,792,682,742 | null | 30 | 30 |
H, N = map(int, input().split())
l = []
for i in range(N):
l.append(list(map(int, input().split())))
dp = [0] * 20000
for i in range(1, 20001):
dp[i] = min(dp[i-a]+b for a, b in l)
if i == H:
break
print(dp[H]) | import sys
import math
n, k = map(int, input().split())
# n_start = math.floor(n / k)
# # print(n_start)
# n = n - n_start*k
# # print(n)
n = n % k
while True:
min_n = n
n = abs(n-k)
# print("n, k =", n, k)
if min_n > n:
min_n = n
else:
break
print(min_n)
| 0 | null | 59,935,569,426,250 | 229 | 180 |
import bisect,collections,copy,heapq,itertools,math,string
import sys
import fractions
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
a, b = M()
ans = lcm(a, b)
print(ans) | n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=a[0]
ch=1
for i in range(1,n):
if ch==n-1:
break
else:
ans+=a[i]
ch+=1
if ch==n-1:
break
else:
ans+=a[i]
ch+=1
print(ans) | 0 | null | 61,549,376,330,500 | 256 | 111 |
import numpy as np
from collections import defaultdict
N = int(input())
A = tuple(map(int, input().split()))
Q = int(input())
BC= [list(map(int,input().split())) for _ in range(Q)]
counter = defaultdict(int)
for x in A:
counter[x] += 1
total = sum(A)
for b, c in BC:
total += (c - b) * counter[b]
counter[c] += counter[b]
counter[b] = 0
print(total)
| n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[0]*q
c=[0]*q
for i in range(q):
b[i],c[i]=map(int,input().split())
N=[0]*(10**5)
s=0
for i in range(n):
N[a[i]-1]+=1
s+=a[i]
for i in range(q):
s+=(c[i]-b[i])*N[b[i]-1]
N[c[i]-1]+=N[b[i]-1]
N[b[i]-1]=0
print(s) | 1 | 12,189,784,321,792 | null | 122 | 122 |
#!/usr/bin/env python
#coding: UTF-8
while True:
h,w = map(int,raw_input().split())
if h+w==0:
break
else:
print w*'#'# ??????####
for hight in range(h-2):
print '#'+(w-2)*'.'+'#'
print w*'#'#????????????####
print | import sys
from functools import lru_cache
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def com(n, r):
if n < r or n < 0 or r < 0:
return 0
r = min(r, n - r)
numer = denom = 1
for i in range(n - r + 1, n + 1):
numer = numer * i
for i in range(1, r + 1):
denom = denom * i
return numer // denom
def main():
N, K = map(int, read().split())
S = str(N)
L = len(S)
@lru_cache(maxsize=None)
def rec(i, k, smaller):
if i == L:
if k == 0:
return 1
else:
return 0
if k == 0:
return 1
if smaller:
return com(L - i, k) * pow(9, k)
if S[i] == '0':
return rec(i + 1, k, False)
ans = 0
ans += rec(i + 1, k, True)
ans += rec(i + 1, k - 1, True) * (int(S[i]) - 1)
ans += rec(i + 1, k - 1, False)
return ans
ans = rec(0, K, False)
print(ans)
return
if __name__ == '__main__':
main()
| 0 | null | 38,313,482,853,408 | 50 | 224 |
p=list(input())
ans=''
for i in p:
if i=='P':
ans+='P'
else:
ans+='D'
print(ans) | t = input()
n = len(t)
t += "a"
ans = ""
for i in range(n):
if t[i] == "?":
ans += "D"
else:
ans += t[i]
print(ans) | 1 | 18,468,286,074,512 | null | 140 | 140 |
X = int(input())
P = 360
ans = 1
x = X
while x%P != 0:
ans += 1
x += X
print(ans)
| X = int(input())
for i in range(1,1000000000):
if ( X * i ) % 360 == 0:
print(i)
quit()
| 1 | 13,226,883,974,290 | null | 125 | 125 |
s = input()
n = len(s)
cnt = 0
t =s[::-1]
for i in range(n//2):
if s[i]!=t[i]:
cnt += 1
print(cnt) |
n, m, l = map(int, input().split())
A = []
B = []
for i in range(n):
A.append([int(j) for j in input().split()])
for i in range(m):
B.append([int(j) for j in input().split()])
# ??????????????????????????????B?????¢??????????????¨???????????????
B_T = list(map(list, zip(*B)))
C = [[0 for j in range(l)] for i in range(n)]
for i in range(n):
for j in range(l):
C[i][j] = sum([a * b for (a, b) in zip(A[i], B_T[j])])
for i in range(n):
print(*C[i]) | 0 | null | 60,665,730,084,128 | 261 | 60 |
n = int(input())
for i in range(0, n):
a, b, c = sorted(map(int, input().split()))
print("YES" if c*c == a*a+b*b else "NO") | s = input()
d = {'ABC': 'ARC', 'ARC': 'ABC'}
print(d[s]) | 0 | null | 11,996,514,076,078 | 4 | 153 |
from math import atan, degrees
a, b, x = map(int, input().split())
if x == a * b * b:
print(0)
else:
x = x / a ** 2
if x >= b / 2:
print(90-degrees(atan(a / (2 * b - 2 * x))))
else:
print(90-degrees(atan(2 * a * x / b ** 2)))
| # -*- coding: utf-8 -*-
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
k_max = 10100
score = [-10**18-1] * N
for i in range(N):
score_i = [-10**18-1] * k_max # iからスタートしてK回操作する場合の累積和
score_i[0] = C[P[i]-1]
index = P[i]-1
for k in range(1, K):
if index == i:
# 既に進んだことがあるマスの場合
loop_score = score_i[k-1] # 1ループで増えるスコア
if loop_score > 0:
loop_num = k # ループする要素数はk(indexが0 ~ k-1)
tmp_score = [-10**18-1] * k_max
tmp_score[0] = (K//k -1) * loop_score
# print("loop_score", loop_score)
# print("tmp_score", tmp_score)
tmp_index = index
# print("loop_num + K%k + 1", loop_num + K%k + 1)
for j in range (1, loop_num + K%k + 1):
tmp_score[j] = tmp_score[j-1] + C[P[tmp_index]-1]
tmp_index = P[tmp_index]-1
# print("max(tmp_score)", max(tmp_score))
score_i[k] = max(tmp_score)
break
score_i[k] = score_i[k-1] + C[P[index]-1]
index = P[index]-1
score[i] = max(score_i)
print(max(score)) | 0 | null | 84,588,705,681,350 | 289 | 93 |
s=input()
if s=='SUN':
print(7)
if s=='MON':
print(6)
if s=='TUE':
print(5)
if s=='WED':
print(4)
if s=='THU':
print(3)
if s=='FRI':
print(2)
if s=='SAT':
print(1)
| N, P = map(int, input().split())
S = input()
a = [0] * (N + 1)
if P != 2 and P != 5:
tenfactor=1
for i in range(1,N+1):
a[i] = ((int(S[N-i])*tenfactor+a[i-1])%P)
tenfactor*=10
tenfactor%=P
ans = 0
from collections import Counter
C=Counter(a)
for v,i in C.items():
ans += (i * (i - 1) // 2)
elif P == 2:
ans = 0
for i in range(N):
if int(S[i]) % 2 == 0:
ans += i + 1
elif P == 5:
ans = 0
for i in range(N):
if int(S[i]) == 0 or int(S[i]) == 5:
ans += i + 1
print(ans)
| 0 | null | 95,265,893,311,488 | 270 | 205 |
R,C,k = map(int,input().split())
dp1 = [[0]*(C+1) for i in range(R+1)]
dp2 = [[0]*(C+1) for i in range(R+1)]
dp3 = [[0]*(C+1) for i in range(R+1)]
for i in range(k):
r,c,v = map(int,input().split())
dp1[r][c] = v
for i in range(1,R+1):
for j in range(1,C+1):
a = dp1[i][j]
dp3[i][j] = max(dp2[i][j-1]+a,dp3[i][j-1])
dp2[i][j] = max(dp1[i][j-1]+a,dp2[i][j-1])
dp1[i][j] = max(dp1[i-1][j]+a,dp2[i-1][j]+a,dp3[i-1][j]+a,dp1[i][j-1],a)
print(max(dp1[R][C],dp2[R][C],dp3[R][C])) | R, C, K = map(int, input().split())
goods = [[0] * C for _ in range(R)]
for _ in range(K):
r, c, v = map(int, input().split())
goods[r-1][c-1] = v
dp = [[[0] * C for _ in range(4)] for _ in range(R)]
dp[0][1][0] = goods[0][0]
for i in range(R):
for j in range(4):
for k in range(C):
if i < R - 1:
dp[i+1][0][k] = max(dp[i+1][0][k], dp[i][j][k])
dp[i+1][1][k] = max(dp[i+1][1][k], dp[i][j][k] + goods[i+1][k])
if k < C - 1:
dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j][k])
if j < 3:
dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k] + goods[i][k+1])
res = 0
for i in range(4):
res = max(res, dp[R-1][i][C-1])
print(res) | 1 | 5,546,460,767,030 | null | 94 | 94 |
n,m=map(int,input().split())
data=[0]*n
s=set()
for i in range(m):
p,a=input().split()
p=int(p)-1
if p in s:
continue
else:
if a=='WA':
data[p]-=1
else:
data[p]*=-1
s.add(p)
print(len(s),sum([data[i] for i in range(n) if data[i]>0])) | N, M = map(int,input().split())
li = []
for _ in range(M):
p, S = input().split()
li.append([int(p), S])
ac = [0] * N
wa = [0] * N
c1 = 0
c2 = 0
for i in range(M):
j = li[i][0] - 1
if li[i][1] == "WA":
wa[j] += 1
if ac[j] == 0 and li[i][1] == "AC":
ac[j] = 1
c1 += 1
c2 += wa[j]
print(c1, c2)
| 1 | 93,370,620,048,810 | null | 240 | 240 |
list = input().split()
m1 = int(list[0])*60 + int(list[1])
m2 = int(list[2])*60 + int(list[3])
#print(m1,m2)
ans = m2 - m1
print(ans-int(list[4]))
| import math
h1, m1, h2, m2, k = map(int, input().split(" "))
t1 = h1 * 60 + m1
t2 = h2 * 60 + m2
print(t2 - t1 - k) | 1 | 18,038,460,515,712 | null | 139 | 139 |
while True:
try:
a,b = map(int,raw_input().split())
c=str(a+b)
print len(c)
except EOFError:
break | K=int(input());S=""
for i in range(K):
S=S+"ACL"
print(S) | 0 | null | 1,083,877,587,312 | 3 | 69 |
def selectionsort(A, N):
count = 0
for i in range(N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
A[i], A[minj] = A[minj], A[i]
if (A[i] != A[minj]):
count += 1
return count
def main():
n = int(input())
data = list(map(int, input().split()))
c = selectionsort(data, n)
print(*data)
print(c)
if __name__ == "__main__":
main() | count = 0
input()
num = [int(n) for n in input().split()]
for i in range(len(num)):
minj = i
for j in range(i, len(num)):
if num[j] < num[minj]:
minj = j
if minj != i:
num[i], num[minj] = num[minj], num[i]
count += 1
print(*num)
print(count) | 1 | 22,313,708,062 | null | 15 | 15 |
a,b,c = map(int,input().split())
tmp = a
a = b
b = tmp
tmp = a
a = c
c = tmp
print(a,b,c) | n = int(input())
A = list(map(int,input().split()))
q = int(input())
M = list(map(int,input().split()))
flag = [0]*(2000+1)
for status in range(2**n):
tmp = 0
for mask in range(n):
if status&(1<<mask):
tmp += A[mask]
flag[tmp] = True
for m in M:
print('yes' if flag[m] else 'no')
| 0 | null | 19,100,144,841,692 | 178 | 25 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
h1,m1,h2,m2,K = map(int, readline().split())
wakeup = h1 * 60 + m1
sleep = h2 * 60 + m2
ans = sleep - K - wakeup
print(ans)
if __name__ == "__main__":
main()
| #! python3
# counting_characters.py
import sys
sents = [line.strip() for line in sys.stdin.readlines()]
dic = {chr(x):0 for x in range(ord('a'), ord('z')+1)}
for sent in sents:
for c in sent:
x = c.lower()
if ord('a') <= ord(x) and ord(x) <= ord('z'):
dic[x] += 1
for k, v in dic.items():
print(k + ' : ' + str(v))
| 0 | null | 9,931,474,364,580 | 139 | 63 |
a = int(input())
x = input()
y = x.split(' ')
c =[]
for i in range(a):
c.append(y[(a-1)-i])
b = ' '.join(c)
print(b) | # -*- coding: utf-8 -*-
n = int(raw_input())
num = map(int, raw_input().split())
for e in num[::-1]:
if e == num[0]:
print e
break
print e, | 1 | 986,346,897,468 | null | 53 | 53 |
n=int(input())
A=[int(x) for x in input().split()]
q=int(input())
m=[int(x) for x in input().split()]
A_sum = []
for bit in range(1,2**n):
a_sum = 0
for i in range(n):
if bin((bit>>i) & 0b1) == '0b1':
a_sum += A[i]
A_sum.append(a_sum)
for mi in m:
if mi in A_sum:
print('yes')
else:
print('no')
| n = int(raw_input())
A = map(int, raw_input().split())
d = {}
def soleve(i, m, n):
if m == 0:
return True
if i >= n:
return False
if d.has_key((i, m)):
return d[(i, m)]
res = soleve(i + 1, m, n) or soleve(i + 1, m - A[i], n)
d[(i, m)] = res
return res
q = int(raw_input())
M = map(int, raw_input().split())
for m in M:
if soleve(0, m, n):
print 'yes'
else:
print 'no' | 1 | 101,649,946,160 | null | 25 | 25 |
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
if abs(a-b)+w*t <= v*t: print('YES')
else: print('NO') | A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
if A > B:
x = A
A = B
B = x
if V <= W:
ans="NO"
elif T*V+A-B >= T*W:
ans="YES"
else:
ans="NO"
print(ans) | 1 | 15,265,148,289,060 | null | 131 | 131 |
n,k,s = map(int, input().split())
if s < 10**9:
ans = [s+1] * n
else:
ans = [1]*n
ans[:k] = [s]*k
print(" ".join(map(str,ans))) | import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
n,k,s=map(int,input().split())
ans=np.array([0]*n)
ans[:k]+=s
if s!=10**9:
ans[k:]+=10**9
else:
ans[k:]+=10**9-1
print(*ans)
if __name__=='__main__':
main() | 1 | 91,018,128,959,440 | null | 238 | 238 |
n = int(input())
ans = 0
for i in range(1, n + 1):
j = i
while j <= n:
ans += j
j += i
print(ans) | n = int(input())
ans = (n + 1) * n // 2
for i in range(2, n + 1):
j = 1
while i * j <= n:
ans += i * j
j += 1
print(ans)
| 1 | 11,148,841,050,718 | null | 118 | 118 |
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
total = a[0]
for i in range(n-2):
total += a[i//2+1]
print(total)
| n,m = map(int,input().split())
h = list(map(int,input().split()))
ab = [list(map(int,input().split())) for _ in range(m)]
place = [True]*n
for i in range(m):
a,b = ab[i][0],ab[i][1]
if h[a-1] < h[b-1]:
place[a-1] = False
elif h[a-1] == h[b-1]:
place[a-1] = False
place[b-1] = False
else:
place[b-1] = False
print(place.count(True))
| 0 | null | 17,166,177,063,178 | 111 | 155 |
x, k, d = map(int, input().split())
cur = abs(x)
rem = k
cnt = min(cur // d, k)
cur = cur - d * cnt
rem = rem - cnt
if rem > 0:
if rem % 2 == 1:
cur = cur - d
ans = abs(cur)
print(ans) | n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
for i in range(n):
asum.append(asum[-1]+a[i])
for i in range(m):
bsum.append(bsum[-1]+b[i])
ans=0
for i in range(n+1):
if asum[i]>k:
break
while asum[i]+bsum[m]>k and m>0:
m-=1
ans=max(ans,i+m)
print(ans) | 0 | null | 7,984,355,299,678 | 92 | 117 |
class Dice:
"""Dice class"""
def __init__(self): # ?????????????????????
self.eyeIndex = 1 #center
self.eyeIndex_E = 3 #east
self.eyeIndex_W = 4 #west
self.eyeIndex_N = 5 #north
self.eyeIndex_S = 2 #south
self.eye = 0
self.eye_S = 0
self.eye_E = 0
self.eyes = []
def convEyesIndexToEyes(self):
self.eye = self.eyes[self.eyeIndex]
self.eye_S = self.eyes[self.eyeIndex_S]
self.eye_E = self.eyes[self.eyeIndex_E]
def shakeDice(self, in_command):
pre_eyeIndex = self.eyeIndex
if in_command == "E":
self.eyeIndex = self.eyeIndex_W
self.eyeIndex_E = pre_eyeIndex
self.eyeIndex_W = 7 - self.eyeIndex_E
elif in_command == "W":
self.eyeIndex = self.eyeIndex_E
self.eyeIndex_W = pre_eyeIndex
self.eyeIndex_E = 7 - self.eyeIndex_W
elif in_command == "N":
self.eyeIndex = self.eyeIndex_S
self.eyeIndex_N = pre_eyeIndex
self.eyeIndex_S = 7 - self.eyeIndex_N
elif in_command == "S":
self.eyeIndex = self.eyeIndex_N
self.eyeIndex_S = pre_eyeIndex
self.eyeIndex_N = 7 - self.eyeIndex_S
self.convEyesIndexToEyes()
def rotateDice(self):
#rotate clockwise
pre_E = self.eyeIndex_E
pre_S = self.eyeIndex_S
pre_W = self.eyeIndex_W
pre_N = self.eyeIndex_N
self.eyeIndex_E = pre_N
self.eyeIndex_S = pre_E
self.eyeIndex_W = pre_S
self.eyeIndex_N = pre_W
self.convEyesIndexToEyes()
def getEye(self):
return self.eye
def getEye_S(self):
return self.eye_S
def getEye_E(self):
return self.eye_E
def setEyes(self, eyes): # setEyes()???????????? ???????????????
eyes = "0 " + eyes
self.eyes = list(map(int, eyes.split(" ")))
self.convEyesIndexToEyes()
dice_1 = Dice()
dice_1.setEyes(input().rstrip())
command_time = int(input().rstrip())
for i in range(command_time):
in_eye, in_eye_S = map(int, input().rstrip().split(" "))
shake_direction = "E"
def_eye = dice_1.getEye()
while True:
dice_1.shakeDice(shake_direction)
if dice_1.getEye() == in_eye:
break
if dice_1.getEye() == def_eye:
shake_direction = "N"
while True:
if dice_1.getEye_S() == in_eye_S:
break
dice_1.rotateDice()
print(dice_1.getEye_E()) | class Dice:
dice = {'N':2, 'E':4, 'S':5, 'W':3}
currTop = 1
def top(self):
return self.currTop
def rot(self, direction):
newTop = self.dice[direction]
currTop = self.currTop
self.currTop = newTop
if direction == 'N':
self.dice['N'] = 7 - currTop
self.dice['S'] = currTop
elif direction == 'S':
self.dice['N'] = currTop
self.dice['S'] = 7 - currTop
elif direction == 'E':
self.dice['E'] = 7 - currTop
self.dice['W'] = currTop
elif direction == 'W':
self.dice['E'] = currTop
self.dice['W'] = 7 - currTop
def yaw(self, direction):
newDice = {}
if direction == 'E':
newDice['N'] = self.dice['E']
newDice['E'] = self.dice['S']
newDice['S'] = self.dice['W']
newDice['W'] = self.dice['N']
if direction == 'W':
newDice['N'] = self.dice['W']
newDice['E'] = self.dice['N']
newDice['S'] = self.dice['E']
newDice['W'] = self.dice['S']
self.dice = newDice
faces = list(map(int, input().split()))
q = int(input())
d = Dice()
for i in range(q):
top, front = list(map(int, input().split()))
topIdx = faces.index(top) + 1
frontIdx = faces.index(front) + 1
if d.top() != topIdx:
# search topIdx and rotate to make topIdx top.
key = [k for k,v in d.dice.items() if topIdx == v]
if len(key) == 0:
d.rot('N')
key = [k for k,v in d.dice.items() if topIdx == v]
d.rot(key[0])
# rotate(yaw) to make frontIdx front.
while True:
if d.dice['N'] == frontIdx:
break
d.yaw('E')
print(faces[d.dice['W']-1]) | 1 | 248,583,172,878 | null | 34 | 34 |
n = int(input())
ss = []
tt = []
for _ in range(n):
s,t = input().split()
ss.append(s)
tt.append(int(t))
x = input()
for i in range(n):
if ss[i] == x:
ans = sum(tt[i+1:])
break
print(ans) | n,m,k = map(int,input().split())
A = [[] for i in range(n+1)]
for i in range(m):
a,b = map(int,input().split())
A[a].append(b)
A[b].append(a)
C = [[] for i in range(n+1)]
for i in range(k):
c,d = map(int,input().split())
C[c].append(d)
C[d].append(c)
from collections import deque
reach = [0]*(n+1)
for i in range(1,n+1):
if reach[i] != 0:
pass
else:
reach[i] = i
q = deque([])
q.append(i)
while q:
x = q.popleft()
for s in A[x]:
if reach[s] == 0:
q.append(s)
reach[s] = i
dis_count = [0]*(n+1)
for i,C0 in enumerate(C):
for CC in C0:
if reach[CC] == reach[i]:
dis_count[i] += 1
import collections
D = collections.Counter(reach)
for i in range(1,n+1):
print(D[reach[i]]-len(A[i])-dis_count[i]-1,end="")
print(" ",end="")
print("") | 0 | null | 79,491,082,394,560 | 243 | 209 |
s = input()
l = len(s)
lst = [0] * (l+1)
for idx in range(l):
if s[idx] is '<':
lst[idx+1] = max(lst[idx+1], lst[idx]+1)
for inv in range(1, l+1):
if s[-inv] is '>':
lst[-(inv+1)] = max(lst[-(inv+1)], lst[-inv]+1)
print(sum(lst)) | s=input()
#><となるところを見つける<<となるところを見つける>>となるところを見つける<>となるところについて考える
n=len(s)
ans=[0]*(n+1)
#左から>>となる部分を探す
for i in range(n):
if s[i]=='<':
ans[i+1]=max(ans[i+1],ans[i]+1)
for i in reversed(range(n)):
if s[i]=='>':
ans[i]=max(ans[i],ans[i+1]+1)
print(sum(ans))
#rangeの挙動に注意しよう | 1 | 156,526,603,768,472 | null | 285 | 285 |
import bisect
n=int(input())
s=list(input())
#アルファベットの各文字に対してからのリストを持つ辞書
alpha={chr(i):[] for i in range(97,123)}
#alpha[c]で各文字ごとに出現場所をソートして保管
for i,c in enumerate(s):
bisect.insort(alpha[c],i+1)
for i in range(int(input())):
p,q,r=input().split()
if p=='1':
q=int(q)
b=s[q-1]
if b!=r:
alpha[b].pop(bisect.bisect_left(alpha[b],q))
bisect.insort(alpha[r],q)
s[q-1]=r
else:
count=0
for l in alpha.values():
pos=bisect.bisect_left(l,int(q))
if pos<len(l) and l[pos]<=int(r):
count+=1
print(count)
| import bisect
n = int(input().strip())
S = list(input().strip())
L=[[] for _ in range(26)]
for i,s in enumerate(S):
L[ord(s)-ord("a")].append(i)
q = int(input().strip())
for _ in range(q):
query=input().strip().split()
if query[0]=="1":
i=int(query[1])
i-=1
c=query[2]
if S[i]!=c:
delInd=bisect.bisect_left(L[ord(S[i])-ord("a")],i)
del L[ord(S[i])-ord("a")][delInd]
bisect.insort(L[ord(c)-ord("a")], i)
S[i]=c
else:
l,r=map(int,[query[1],query[2]])
l-=1; r-=1
ans=0
for j in range(26):
ind=bisect.bisect_left(L[j],l)
if ind<len(L[j]) and L[j][ind]<=r:
ans+=1
print(ans) | 1 | 62,872,631,362,958 | null | 210 | 210 |
import sys; input = sys.stdin.readline
# n, m , k = map(int, input().split())
# matrix = [list(input().strip()) for _ in range(n)]
n = int(input())
lis = sorted(map(int, input().split()), reverse=True)
ans = lis[0]
i = 1
c = 1
while c<n-1:
if c < n-1: ans += lis[i]; c+=1
if c < n-1: ans += lis[i]; c+=1
i+=1
print(ans)
| import numpy as np
n=int(input())
A=np.array(input().split(),np.int64)
A.sort()
A=A[::-1]
ans=int(0)
for i in range(n-1):
ans+=A[(i+1)//2]
print(ans)
| 1 | 9,235,808,750,680 | null | 111 | 111 |
n = int(input())
c = input()
d = c.count('R')
e = c[:d].count('R')
print(d-e) | n = int(input())
stone = list(input())
l = 0
r = n-1
ans = 0
while l < r:
if stone[l]=='W':
if stone[r]=='R':
ans += 1
l += 1
r -= 1
else:
r -= 1
else:
l += 1
if stone[r]=='W':
r -= 1
print(ans) | 1 | 6,240,928,135,602 | null | 98 | 98 |
n,k=input().split();print(sum(sorted(list(map(int,input().split())))[:int(k)])) | total,amount=[int(x) for x in input().split()]
array=sorted([int(x) for x in input().split()])
print(sum(array[0:amount])) | 1 | 11,589,338,663,222 | null | 120 | 120 |
import statistics
import math
N = int(input())
min_x = []
max_x = []
for i in range(N):
A, B = map(int, input().split())
min_x.append(A)
max_x.append(B)
min_x.sort()
max_x.sort()
result = []
if len(min_x) % 2 == 0:
min_median = (min_x[len(min_x)//2-1] + min_x[len(min_x)//2])
max_median = (max_x[len(min_x)//2-1] + max_x[len(min_x)//2])
print(len(range(math.floor(min_median), math.ceil(max_median) + 1)))
else:
min_median = min_x[len(min_x)//2]
max_median = max_x[len(min_x)//2]
print(max_median - min_median + 1)
| from collections import defaultdict
n = int(input())
a = [0]
a.extend(map(int, input().split()))
mp = defaultdict(int)
ans = 0
for i in range(1, n+1):
ans += mp[i-a[i]]
mp[i+a[i]] += 1
print(ans) | 0 | null | 21,674,079,234,028 | 137 | 157 |
list = []
while True:
H, W = [int(i) for i in input().split()]
if H == 0 and W == 0:
break
list.append([H, W])
for i in range(len(list)):
for j in range(list[i][0]):
for k in range(list[i][1]):
if j % 2 == 1:
print('#',end='') if k % 2 == 1 else print('.',end='')
else:
print ('#',end='') if k % 2 == 0 else print('.',end='')
print()
print() | l='#.'*999
while 1:
h,w=map(int,raw_input().split());s=""
if h==0:break
for i in range(h):s+=l[i%2:w+i%2]+"\n"
print s | 1 | 857,839,893,460 | null | 51 | 51 |
N = int(input())
ns = [int(input()) for _ in range(N)]
#primes = set()
#def is_prime(n):
# if n in primes:
# return True
#
# for m in range(2, n):
# if is_prime(m) and n % m == 0:
# return False
#
# primes.add(n)
# return True
# Proof:
# if n < d ^ 2 and n mod d = 0;
# n = ad (a in N)
# ad < d ^ 2
# a < d
# QED
def is_prime(n):
if n < 2: return False
if n == 2: return True
if n % 2 == 0: return False
d = 3
while d ** 2 <= n:
if n % d == 0:
return False
d += 2
return True
print(len([n for n in ns if is_prime(n)])) | from math import sqrt
def isprime(inlst, chk, sq):
for i in range(3, sq, 2):
inlst = [x for x in inlst if x%i > 0 or x == i]
i += 2
return inlst
n = int(input())
inlst = [input() for i in range(n)]
inlst = [int(i) for i in inlst]
inlst = [x for x in inlst if x%2 > 0 or x == 2]
inlst = isprime(inlst, 3, int(sqrt(max(inlst))) + 1)
print(len(inlst)) | 1 | 10,307,888,528 | null | 12 | 12 |
from collections import Counter
N = int(input())
S = input()
counter = Counter(list(S))
ans = counter['R'] * counter['G'] * counter['B']
for d in range(1, N // 2 + 1):
for a, b, c in zip(S, S[d:], S[2 * d:]):
if a != b and b != c and c != a:
ans -= 1
print(ans)
| def main():
import re
n = int(input())
s = input()
rindex = set()
gindex = set()
bindex = set()
for i in range(n):
if s[i] == "R":
rindex.add(i)
elif s[i] == "G":
gindex.add(i)
else:
bindex.add(i)
ans = len(rindex) * len(gindex) * len(bindex)
for r in rindex:
for g in gindex:
if r > g:
gap = r - g
b1 = r + gap
b2 = g - gap
b3 = g + (gap/2)
elif r < g:
gap = g - r
b1 = g + gap
b2 = r - gap
b3 = r + (gap/2)
if b1 in bindex:
ans -= 1
if b2 in bindex:
ans -= 1
if b3 in bindex:
ans -= 1
print(ans)
if __name__ == "__main__":
main()
| 1 | 36,048,085,536,206 | null | 175 | 175 |
import math
r = float(input())
print(float(r ** 2 * math.pi), float(r * 2 * math.pi))
| #dpでできないかな?
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
h,w=MI()
lis=[list(SI()) for i in range(h)]
al=[[-1]*w for i in range(h)]
dp=[[inf]*w for i in range(h)]
'''for i in range(h):
for j in range(w):
if lis[i][j]=="#":
dp[i][j]=-1'''
dp[0][0]= 0 if lis[0][0]=="." else 1
q=deque([[0,0]])
step=[[0,1],[1,0]]
#print(lis)
while q:
x,y=q.popleft()
if lis[x][y]==".":
state=1
else:
state=-1
for i,j in step:
if x+i>h-1 or y+j>w-1:
continue
elif state==1:
if al[x+i][y+j]<0:
al[x+i][y+j]=0
q.append([x+i,y+j])
if lis[x+i][y+j]=="#":
dp[x+i][y+j]=min(dp[x+i][y+j],dp[x][y]+1)
else:
dp[x+i][y+j]=min(dp[x+i][y+j],dp[x][y])
elif state==-1:
if al[x+i][y+j]<0:
al[x+i][y+j]=0
q.append([x+i,y+j])
dp[x+i][y+j]=min(dp[x+i][y+j],dp[x][y])
print(dp[-1][-1]) | 0 | null | 24,853,564,128,188 | 46 | 194 |
from math import gcd
from functools import reduce
from sys import exit
# O(A+N)解
MAX_A = 1000000
lowerst_prime = [0] * (MAX_A + 1) # 最小の素因数をいれる(2以上をみていけばいい)
primes = [] # MAX_A以下の素数の集合
count = [0] * (MAX_A + 1) # 約数として出てくる回数を数える
for i in range(2, MAX_A + 1): # 線形時間で処理してくれる
if lowerst_prime[i] == 0:
lowerst_prime[i] = i
primes.append(i)
for p in primes:
if p > lowerst_prime[i] or i * p > MAX_A:
break
lowerst_prime[i * p] = p # p が i * p のもっとも小さな素因数となるときのみ更新されるので、線形時間アルゴリズムとなる
# 入力
N = int(input())
A = [*map(int, input().split())]
if reduce(gcd, A) != 1:
print("not coprime")
exit(0)
for i in range(N):
while A[i] > 1:
divide = lowerst_prime[A[i]]
if count[divide]:
# A[x] % i == A[y] % i == 0 となるx != yが存在するので、i | gcd(x, y) となる
print("setwise coprime")
exit(0)
count[divide] += 1
while A[i] % divide == 0: # 割れるだけ割る
A[i] //= divide
print("pairwise coprime") | n, k = map(int, input().split())
W = [int(input()) for _ in range(n)]
def can_load(W, k, q, n):
i = 0
for _ in range(k):
s = 0
while i < n and s + W[i] <= q:
s += W[i]
i += 1
if i == n:
return True
else:
return False
# 積載量をmidと仮定して二分探索
hi = 10 ** 9 # OK
lo = 0 # NG
while hi - lo > 1:
mid = (hi + lo) // 2
if can_load(W, k, mid, n):
hi = mid
else:
lo = mid
print(hi)
| 0 | null | 2,129,868,603,640 | 85 | 24 |
n=int(input())
print((n/3)*(n/3)*(n/3)) | N=int(input())
A=list(map(int,input().split()))
s=sum(A)
ans=1
eda=1
if N==0:
if A[0]==1:
print(1)
else:
print(-1)
exit()
if A[0]!=0:
print(-1)
exit()
for i in range(1,N+1):
if eda*2<=s:
eda*=2
else:
eda=s
ans+=eda
eda-=A[i]
s-=A[i]
if eda<=0 and i != N:
print(-1)
exit()
if eda!=0:
print(-1)
exit()
print(ans) | 0 | null | 32,779,838,383,940 | 191 | 141 |
a,b=map(int,input().split())
c=b*10
for i in range(c,c+10):
if int(i*0.08)==a:
print(i)
exit()
print(-1) | a,b = map(int,input().split())
astart, aend = int(a//0.08+1), int((a+1)//0.08) #[astart, aend)
bstart, bend = int(b//0.10+1), int((b+1)//0.10)
alst = set(range(astart,aend))
blst = set(range(bstart,bend))
share = alst & blst
if len(share) == 0:
print(-1)
else:
print(list(share)[0]) | 1 | 56,299,931,082,720 | null | 203 | 203 |
#11_A
import random
class Dice:
def __init__(self):
self.dice=[i for i in range(6)]
self.workspace=[i for i in range(6)]
self.top=self.dice=[0]
def set(self,numbers):
self.dice=[i for i in numbers]
self.workspace=[i for i in numbers]
def rotate(self,command):
if command == "W":
self.workspace=[self.dice[2], self.dice[1], self.dice[5], self.dice[0], self.dice[4], self.dice[3]]
self.dice=self.workspace
elif command == "E":
self.workspace=[self.dice[3], self.dice[1], self.dice[0], self.dice[5], self.dice[4], self.dice[2]]
self.dice = self.workspace
if command == "S":
self.workspace=[self.dice[4], self.dice[0], self.dice[2], self.dice[3], self.dice[5], self.dice[1]]
self.dice=self.workspace
elif command == "N":
self.workspace=[self.dice[1], self.dice[5], self.dice[2], self.dice[3], self.dice[0], self.dice[4]]
self.dice=self.workspace
def get_top(self):
self.top=self.dice[0]
print(self.top)
def predict(self, num):
for i in range(num):
top, front = map(int, input().split())
while(True):
if top == self.dice[0] and front == self.dice[1]:
break
command_num=random.randint(1,4)
if command_num == 1:
self.rotate("W")
elif command_num == 2:
self.rotate("E")
elif command_num == 3:
self.rotate("S")
elif command_num == 4:
self.rotate("N")
print(self.dice[2])
def getter(self):
return self.dice[0], self.dice[1], self.dice[2]
def predict_same(self, top, front, right):
for n in range(30):
if top ==self.dice[0] and front== self.dice[1] and right ==self.dice[2]:
print("Yes")
break
command_num=random.randint(1,4)
if command_num == 1:
self.rotate("W")
elif command_num == 2:
self.rotate("E")
elif command_num == 3:
self.rotate("S")
elif command_num == 4:
self.rotate("N")
if top!=self.dice[0] or front!=self.dice[1] or front!=self.dice[2]:
print("No")
numbers=list(map(int,input().split()))
dice=Dice()
dice.set(numbers)
# commands=input()
# for i in range(len(commands)):
# dice.rotate(commands[i])
# dice.get_top()
q=int(input())
dice.predict(q)
| x,y=map(int,input().split())
print(['No','Yes'][y%2==0 and 2*x <= y <= 4*x]) | 0 | null | 7,088,873,886,016 | 34 | 127 |
s=input().split()
print(s[1]+s[0])
| import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
D = int(input())
c = [0] + list(map(int, input().split()))
s = [[0]*27]
t = [0]
satisfy = 0
last = [0] * 27
for _ in range(D):
s.append([0] + list(map(int, input().split())))
for _ in range(D):
t += [int(input())]
for i in range(1, D+1):
decrease = 0
last[t[i]] = i
for j in range(1, 27):
decrease += (c[j] * (i - last[j]))
satisfy += (s[i][t[i]] - decrease)
print(satisfy)
if __name__ == '__main__':
main() | 0 | null | 56,220,878,082,880 | 248 | 114 |
s = input()
line = int(input())
for i in range(line):
param = input().split(" ")
if len(param) == 4: ope, a, b, p = param
else: ope, a, b = param
a,b = int(a), int(b)
if ope == "print":
print(s[a:b+1])
elif ope == "reverse":
rev = s[a:b+1][::-1]
s = (s[:a] + rev + s[b+1:])
elif ope == "replace":
s = (s[:a] + p + s[b+1:]) | a = int(input())
res = 0
for i in range(a+1):
if i % 3 ==0 or i % 5 ==0:
pass
else:
res += i
print(res) | 0 | null | 18,356,266,659,630 | 68 | 173 |
n=int(input())
if n%2:
print(0)
else:
c=0
n//=2
while n:
n//=5
c+=n
print(c) | from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
n = INT()
ans = 0
if n % 2 == 0:
c5 = 0
c2 = 0
for i in range(30,0,-1):
c5 += i*(n//(2*5**i) - n//(2*5**(i+1)))
for i in range(60,0,-1):
c2 += i*(n//(2**i) - n//(2**(i+1)))
ans = min(c5, c2)
print(ans) | 1 | 116,231,540,679,240 | null | 258 | 258 |
import sys
inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())
n = inint()
P = inintl()
min_l = []
now_min = P[0]
ans = 0
for p in P:
if p < now_min:
now_min = p
min_l.append(now_min)
for i in range(n):
if min_l[i] == P[i]:
ans += 1
print(ans)
| n, *aa = map(int, open(0).read().split())
# aa = aa
bb = []
tmp = aa[0]
for a in aa:
tmp = min(a,tmp)
bb.append(tmp)
# bb = bb[:-1]
print(sum([a<=b for a, b in zip(aa, bb)])) | 1 | 85,303,042,318,660 | null | 233 | 233 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from bisect import bisect_left
from itertools import product
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def LF(): return list(map(float, input().split()))
def LC(): return [c for c in input().split()]
def LLI(n): return [LI() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]
def array2d(N, M, initial=0):
return [[initial]*M for _ in range(N)]
def copy2d(orig, N, M):
ret = array2d(N, M)
for i in range(N):
for j in range(M):
ret[i][j] = orig[i][j]
return ret
INF = float("inf")
MOD = 10**9 + 7
def main():
X, K, D = MAP()
# 到達候補は0に近い正と負の二つの数
d, m = divmod(X, D)
cand = (m, m-D)
if X >= 0:
if K <= d:
print(X-K*D)
return
else:
rest = (K-d)
if rest % 2 == 0:
print(cand[0])
return
else:
print(-cand[1])
return
else:
if K <= -d-1:
print(abs(X+K*D))
return
else:
rest = K-(-d-1)
if rest % 2 == 0:
print(-cand[1])
return
else:
print(cand[0])
return
return
if __name__ == '__main__':
main()
| from sys import setrecursionlimit
setrecursionlimit(10 ** 6)
N = int(input())
Gb = [ [] for _ in range(N) ]
Gu = [ [] for _ in range(N) ]
Es = {}
for n in range(N - 1):
a, b = map(lambda x: int(x) - 1, input().split())
Es[f'{a:06}{b:06}'] = None
Gb[a].append(b)
Gb[b].append(a)
Gu[a].append(b)
colors = list(range(max(map(len, Gb))))
def dfs(base_node, edge_color):
global Es
valid_colors = filter(lambda color: color != edge_color, colors)
for child_node, color in zip(Gu[base_node], valid_colors):
Es[f'{base_node:06}{child_node:06}'] = color + 1
dfs(child_node, color)
print(len(colors))
dfs(0, None)
for color in Es.values():
print(color) | 0 | null | 70,566,242,416,488 | 92 | 272 |
a, b, c = (int(i) for i in ((input()).split()))
if a < b < c:
print('Yes')
else:
print('No') | from copy import deepcopy
d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
a=list(map(int,input().split()))
s.append(a)
def score_calculator(l):
score=0
last=[0]*26
for i in range(d):
for j in range(26):
last[j]+=1
last[l[i]]=0
for j in range(26):
score-=last[j]*c[j]
score+=s[i][l[i]]
return score
for i in range(1,26):
highest_sum_score=-1000000000000
last=[0]*26
temp_ans_lst=[]
for j in range(d):
daily_highest_score=-10000000000000
for k in range(26):
temp_score=s[j][k]
temp_last=deepcopy(last)
for p in range(26):
temp_last[p]+=1
temp_last[k]=0
for p in range(26):
down=temp_last[p]
for q in range(i):
qdown=down+i+1
down+=qdown
temp_score-=down*c[p]
if temp_score>daily_highest_score:
daily_highest_score=temp_score
daily_choice=k
temp_ans_lst.append(daily_choice)
if score_calculator(temp_ans_lst)>highest_sum_score:
ans_lst=temp_ans_lst
for i in ans_lst:
print(i+1) | 0 | null | 4,977,957,502,738 | 39 | 113 |
import sys
input = sys.stdin.readline
class UnionFind():
def __init__(self, N):
self.N = N
self.r = [-1] * (N+1)
def root(self, x):
if (self.r[x] < 0):
return x
else:
self.r[x] = self.root(self.r[x])
return self.r[x]
def unite(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return False
if self.r[x] > self.r[y]:
x, y = y, x
self.r[x] += self.r[y]
self.r[y] = x
return True
def size(self, x):
return -self.r[self.root(x)]
def same(self, x, y):
return self.root(x) == self.root(y)
def main():
N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
A, B = map(lambda i: int(i)-1, input().split())
uf.unite(A, B)
ans = 0
for i in range(N):
ans = max(ans, uf.size(i))
print(ans)
main() | class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N,M = list(map(int,input().split()))
Network = UnionFind(N)
out=0
for i in range(M):
a,b = list(map(int,input().split()))
Network.union(a-1,b-1)
print(-1*min(Network.parents)) | 1 | 3,942,179,102,848 | null | 84 | 84 |
m = map(int,raw_input().split())
print m[0]*m[1],2*(m[0]+m[1]) | [print(1) if(int(input())==0) else print(0)] | 0 | null | 1,635,025,171,988 | 36 | 76 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
s = input()
if 'RRR' in s:
print(3)
elif 'RR' in s:
print(2)
elif 'R' in s:
print(1)
else:
print(0)
if __name__ == '__main__':
main() | s = input().rstrip()
best = 0
c = 0
for char in s:
if char=='R':
c+=1
else:
c=0
best = max(best,c)
print(best) | 1 | 4,899,048,370,240 | null | 90 | 90 |
s = input()
print('x'*len(s)) | R,C,K= map(int,input().split(" "))
original=[[0]*(C+1) for i in range(R+1)]
for _ in range(K):
r,c,v= map(int,input().split(" "))
original[r][c]=v
d1=[[0]*(C+1) for i in range(R+1)]
d2=[[0]*(C+1) for i in range(R+1)]
d3=[[0]*(C+1) for i in range(R+1)]
for i in range(1,R+1):
for j in range(1,C+1):
curr= original[i][j]
d1[i][j]=max(d1[i-1][j]+curr,d2[i-1][j]+curr,d3[i-1][j]+curr,d1[i][j-1],curr)
d2[i][j]=max(d2[i][j-1],d1[i][j-1]+curr)
d3[i][j]=max(d3[i][j-1],d2[i][j-1]+curr)
print(max(d1[-1][-1],d2[-1][-1],d3[-1][-1])) | 0 | null | 39,483,847,847,520 | 221 | 94 |
print('YNeos'[input()!=input()[:-1]::2]) | A = int(input())
B = int(input())
print(6//(A*B)) | 0 | null | 65,897,742,349,922 | 147 | 254 |
num = int(input())
A = input().split(" ")
B = A.copy()
#bubble sort
for i in range(num):
for j in range(num-1,i,-1):
#英字ではなく、数字で比較する
m1 = int(A[j][1:])
m2 = int(A[j-1][1:])
if m1 < m2:
A[j],A[j-1] = A[j-1],A[j]
print(*A)
print("Stable")
#selection sort
for i in range(num):
minv = i
for j in range(i+1,num):
m1 = int(B[minv][1:])
m2 = int(B[j][1:])
if m1 > m2:
minv = j
B[i],B[minv] = B[minv],B[i]
print(*B)
if A == B:
print("Stable")
else:
print("Not stable")
| s=input()
l1=[]
l2=[]
num1=0 #0は反転なし 1はあり
def ap1(str1):
l1.append(str1)
def ap2(str2):
l2.append(str2)
nq=int(input())
for i in range(nq):
q=list(input().split())
if q[0]=="1":
num1=(num1+1)%2
else:
f=int(q[1])
if (num1+f)%2==1: #1で先頭 2で末尾
ap1(q[2])
else:
ap2(q[2])
if num1==0:
ans=""
for i in range(len(l1)):
ans+=l1[-1-i]
ans+=s
for i in range(len(l2)):
ans+=l2[i]
else:
ans=""
for i in range(len(l2)):
ans+=l2[-1-i]
for i in range(len(s)):
ans+=s[-1-i]
for i in range(len(l1)):
ans+=l1[i]
print(ans)
| 0 | null | 28,525,024,465,168 | 16 | 204 |
a = int(input())
ans = a * (1 + a + a * a)
print(ans) | N = int(input())
S = input()
count = 0
for i in range(0, N - 2):
if S[i] == 'A':
if S[i+1] == 'B':
if S[i+2] == 'C':
count += 1
print(count) | 0 | null | 54,869,974,150,658 | 115 | 245 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().decode()
if 'A' in S and 'B' in S:
print('Yes')
else:
print('No') | s = input()
prev = s[0]
for i in range(1, 3):
if s[i] != prev:
print('Yes')
break
else:
print('No')
| 1 | 54,904,267,671,162 | null | 201 | 201 |
n = int(input())
ab = []
for i in range(n-1):
a, b = map(int,input().split())
ab.append([a, b])
graph = [[] for _ in range(n+1)]
for a,b in ab:
graph[a].append(b)
graph[b].append(a)
root = 1
parent = [0] * (n+1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
color = [-1] * (n+1)
for x in order:
ng = color[x]
c = 1
for y in graph[x]:
if y == parent[x]:
continue # 子に対応させる
if c == ng:
c += 1
color[y] = c
c += 1
print(max(color))
for a,b in ab:
if parent[a] == b:
print(color[a])
else:
print(color[b]) | #!/usr/bin/python3
# import bisect
# from collections import Counter, deque, OrderedDict, defaultdict
from copy import copy, deepcopy # pythonのみ.copyは1次元,deepcopyは多次元.
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np # Pythonのみ!
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components # Pythonのみ!
# ↑cf. https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
n = int(input())
import math
# cf. https://qiita.com/suecharo/items/14137fb74c26e2388f1f
def make_prime_list_2(num):
if num < 2:
return []
# 0のものは素数じゃないとする
prime_list = [i for i in range(num + 1)]
prime_list[1] = 0 # 1は素数ではない
num_sqrt = math.sqrt(num)
for prime in prime_list:
if prime == 0:
continue
if prime > num_sqrt:
break
for non_prime in range(2 * prime, num, prime):
prime_list[non_prime] = 0
return [prime for prime in prime_list if prime != 0]
def prime_factorization_2(num):
"""numの素因数分解
素因数をkeyに乗数をvalueに格納した辞書型dict_counterを返す"""
if num <= 1:
return False
else:
num_sqrt = math.floor(math.sqrt(num))
prime_list = make_prime_list_2(num_sqrt)
dict_counter = {} # 何度もこの関数を呼び出して辞書を更新したい時はこれを引数にして
# cf. https://atcoder.jp/contests/arc034/submissions/12251452
for prime in prime_list:
while num % prime == 0:
if prime in dict_counter:
dict_counter[prime] += 1
else:
dict_counter[prime] = 1
num //= prime
if num != 1:
if num in dict_counter:
dict_counter[num] += 1
else:
dict_counter[num] = 1
return dict_counter
def divisor_count(num):
"""numの約数の個数を求める"""
if num < 0:
return None
elif num == 1:
return 1
else:
divisor_num = 1
dict_fact = prime_factorization_2(num)
for value in dict_fact.values():
divisor_num *= (value + 1)
return divisor_num
ans = divisor_count(n-1)
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i: # 平方数の場合n**0.5を1つだけにしてる
divisors.append(n//i)
# divisors.sort() # ソートしたけりゃして
return divisors
l = make_divisors(n)
def main():
cnt = 0
for i in l:
if i==1: continue
v = copy(n)
while v % i == 0:
v /= i
v%=i
if v==1: cnt += 1
return cnt
print(ans+main()-1)
resolve() | 0 | null | 88,303,105,462,534 | 272 | 183 |
def solve(n):
su = 0
for i in range(1, n+1):
m = n//i
su += m*(2*i + (m-1)*i)//2
return su
n = int(input())
print(solve(n)) | def chk(l):
s=0
for r in l:
s+=r
if (s<0)|(s>9):
return False
return True
def nml(l):
ln=len(l)
for i in range(1,ln):
if l[-i]==2:
l[-i]=-1
l[-i-1]+=1
if l[0]==10:
return True
return False
a=[1]
for i in range(int(input())-1):
while True:
if len(a)==1:
a[0]+=1
if a[0]==10:
a=[1,-1]
else:
a[-1]+=1
if nml(a):
a=[1]+[-(j==0) for j in range(len(a))]
if chk(a):
break
rt=""
ss=0
for i in a:
ss+=i
rt+=str(ss)
print(rt) | 0 | null | 25,560,756,329,430 | 118 | 181 |
#!/usr/bin/env python3
#input
import math
var = [int(input()) for _ in range(3)]
print(math.ceil(var[2]/max(var[0],var[1]))) | # import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
h=int(input())
w=int(input())
n=int(input())
v=max(h,w)
cnt=0
while n>0:
n-=v
cnt+=1
print(cnt)
resolve() | 1 | 88,769,318,748,768 | null | 236 | 236 |
import sys
input = sys.stdin.readline
_, m = map(int, input().split())
d = {}
for _ in range(m):
p, s = input().split()
p = int(p)
if p in d: # やっている(やった)問題
if d[p][0]: # AC済の問題だった場合
continue
if s == "WA":
d[p][1] += 1
else:
d[p][0] = True
else: # 初めての問題
if s == "WA":
d[p] = [False, 1] # 中身:AC判定と、ACまでのWAの数
else:
d[p] = [True, 0]
cnt_ac = 0
cnt_wa = 0
for v in d.values():
if v[0]:
cnt_ac += 1
cnt_wa += v[1]
print(cnt_ac, cnt_wa) | n, m = map(int, input().split())
prob = [0]*n
AC = 0
WA = 0
for _ in range(m):
p, s = input().split()
p = int(p)
if prob[p-1] == -1:
continue
if s == 'WA':
prob[p-1] += 1
else:
WA += prob[p-1]
AC += 1
prob[p-1] = -1
print(AC, WA)
| 1 | 93,436,507,896,448 | null | 240 | 240 |
N,K = map(int,input().split())
import numpy as np
A = np.array(input().split(),np.int64)
B = np.array(input().split(),np.int64)
A.sort() ; B.sort()
B=B[::-1]
right = max(A*B) #時間の可能集合の端点
left = -1 #時間の不可能集合の端点
def test(t):
C = A-t//B
D= np.where(C<0,0,C)
return D.sum()<=K
while left+1<right:
mid = (left+right)//2
if test(mid):
right=mid
else:
left = mid
print(right) | N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
def check(mid):
cnt = 0
for i in range(N):
tmp = mid // F[i]
cnt += max(A[i] - tmp, 0)
return cnt <= K
check(2)
l, r = -1, 10**30
while r-l > 1:
mid = (l+r)//2
if check(mid):
r = mid
else:
l = mid
print(r)
| 1 | 165,251,379,927,790 | null | 290 | 290 |
S = input()
#print(S.count("R"))
con = S.count("R")
if con == 1:
print(1)
elif con == 3:
print(3)
elif con == 2:
for j in range(3):
if S[j] =="R":
if S[j+1] =="R":
print(2)
break
else:
print(1)
break
elif con == 0:
print(0)
| def resolve():
s = str(input())
ans = 0
if 'R' in s:
ans = 1
if 'RR' in s:
ans = 2
if 'RRR' in s:
ans = 3
print(ans)
resolve() | 1 | 4,863,565,232,130 | null | 90 | 90 |
import math
X,K,D = map(int,input().split())
X = abs(X)
if X > K*D:
print(X-K*D)
else:
c=math.floor(X/D)
print( abs(X-D*c-((K-c)%2)*D) )
| x, k, d = map(int, input().split())
cur = x
numTimes = x // d
if numTimes == 0:
cur -= d
k -= 1
else:
numTimes = min(abs(numTimes), k)
if x < 0:
numTimes *= -1
cur -= numTimes * d
k -= numTimes
if k % 2 == 0:
print(abs(cur))
else:
result = min(abs(cur - d), abs(cur + d))
print(result) | 1 | 5,230,477,038,930 | null | 92 | 92 |
import math
A,B,H,M = map(int,input().split())
#短針は1分間に0.5度動くことに注意
dig = abs((H*30 + M*0.5)-M*6)
if dig > 180:
dig = 360 - dig
ans = math.sqrt((A**2+B**2)-(2*A*B*math.cos(math.radians(dig))))
print(ans) | import math
a, b, h, m = map(int, input().split())
minute = 60 * h + m
argA = minute / 720 * 2 * math.pi
argB = minute / 60 * 2 * math.pi
a_x = a * math.cos(argA)
a_y = a * math.sin(argA)
b_x = b * math.cos(argB)
b_y = b * math.sin(argB)
d = math.sqrt((a_x - b_x) ** 2 + (a_y - b_y) ** 2)
print(d) | 1 | 20,152,891,397,372 | null | 144 | 144 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
numbers = input().split(' ')
height = int(numbers[0])
width = int(numbers[1])
print(height * width ,height * 2 + width * 2)
return
if __name__ == '__main__':
main() | s = input().split(" ")
n = int(s[0])
m = int(s[1])
l = int(s[2])
a = [[0 for i in range(m)] for j in range(n)]
b = [[0 for i in range(l)] for j in range(m)]
for i in range(n):
s = input().split(" ")
for j in range(m):
a[i][j] = int(s[j])
for i in range(m):
s = input().split(" ")
for j in range(l):
b[i][j] = int(s[j])
for i in range(n):
for j in range(l):
sk = 0
for k in range(m):
sk += a[i][k] * b[k][j]
if j == l-1:
print(sk)
else:
print(sk,end=" ") | 0 | null | 863,545,292,820 | 36 | 60 |
import sys
import heapq
from decimal import Decimal
input = sys.stdin.readline
x = int(input())
for i in range(-1000,1000):
for j in range(-1000,1000):
if i**5 - j**5 == x:
print(i,j)
exit(0) | X = int(input())
for i in range(-201, 201):
done = False
for j in range(-201, 201):
if i ** 5 - j ** 5 == X:
print(i, j)
done = True
break
if done:
break | 1 | 25,593,078,511,340 | null | 156 | 156 |
# -*- coding: utf-8 -*-
def main():
from collections import deque
import sys
input = sys.stdin.readline
n, x, y = map(int, input().split())
x -= 1
y -= 1
inf = 10 ** 7
ans = [0 for _ in range(n)]
# See:
# https://www.youtube.com/watch?v=zG1L4vYuGrg&feature=youtu.be
# KeyInsight:
# △: 全探索 + 深さ優先探索
# ×: どのように実装すればいいか、見当がつかなかった
for i in range(n):
# グラフを陽に持たない場合
# 始点からの距離を管理
dist = [inf for _ in range(n)] # 距離無限大で初期化
dist[i] = 0
# キューを用意して、頂点を管理
d = deque()
d.append(i)
# BFS
while d:
v = d.popleft() # 最も左側の内容(=最初に突っ込んだ値)を取り出す
dj = dist[v]
# 場合分け
# 範囲外参照を回避しながら、次の頂点に移動したときの距離を計算
if v - 1 >= 0 and dist[v - 1] == inf:
dist[v - 1] = dj + 1
# 次の頂点をキューに突っ込む
d.append(v - 1)
if v + 1 < n and dist[v + 1] == inf:
dist[v + 1] = dj + 1
d.append(v + 1)
if v == x and dist[y] == inf:
dist[y] = dj + 1
d.append(y)
if v == y and dist[x] == inf:
dist[x] = dj + 1
d.append(x)
# 距離ごとの個数を計算
for j in range(n):
ans[dist[j]] += 1
# 始点と終点を区別
for k in range(n):
ans[k] //= 2
# 答えを出力
for ii in range(1, n):
print(ans[ii])
if __name__ == '__main__':
main()
| N, K = map(int, input().split())
d = []
A = []
for i in range(K) :
d.append(int(input()))
A.append(list(map(int,input().split())))
a = set()
ans = 0
for i in range(K) :
for j in range(len(A[i])) :
a.add(A[i][j])
for i in range(1,N+1):
if i not in a :
ans += 1
print(ans) | 0 | null | 34,344,773,439,520 | 187 | 154 |
x = int(input())
a = x // 100
b = x - a * 100
while b > 5:
b = b - 5
a -= 1
if a>=1:
print(1)
else:
print(0) | import sys
def I(): 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, m = MI()
ac = [False]*(n+1)
wa = [0]*(n+1)
for _ in range(m):
temp = input().split()
p, s = int(temp[0]), temp[1]
if not ac[p]:
if s == 'AC':
ac[p] = True
else:
wa[p] += 1
penalty = 0
for i in range(n+1):
if ac[i]:
penalty += wa[i]
print('{} {}'.format(sum(ac), penalty))
if __name__ == '__main__':
main() | 0 | null | 110,538,482,634,790 | 266 | 240 |
from math import sqrt, ceil
def divisors(n):
out = []
nn = ceil(sqrt(n))
for i in range(1, nn):
if n % i == 0:
out.append(i)
out.append(n//i)
if nn ** 2 == n:
out.append(nn)
out.sort()
return out
n = int(input())
a = len(divisors(n-1)[1:])
d = divisors(n)
for dd in d[1:]:
nn = n
while nn % dd == 0:
nn = nn // dd
if nn % dd == 1:
a += 1
print(a)
| n,m=map(int,input().split())
A=list(map(int,input().split()))
ans=0
for i in range(n):
if 4*m*A[i]<sum(A):
continue
else:
ans+=1
if ans<m:
print('No')
else:
print('Yes') | 0 | null | 40,034,174,434,408 | 183 | 179 |
N,S=int(input()),input()
r,g,b=0,0,0
for i in list(S):
if i=='R':r+=1
if i=='G':g+=1
if i=='B':b+=1
ans=r*g*b
for i in range(N-2):
for j in range(i+1,N-1):
if j-i>N-j-1:break
if S[i]!=S[j]and S[j]!=S[2*j-i]and S[2*j-i]!=S[i]:
ans-=1
print(ans) | n = int(input())
s = input()
r, g, b = s.count("R"), s.count("G"), s.count("B")
cnt = 0
for i in range(n):
for j in range(i + 1, n):
try:
k = j + (j - i)
if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
cnt += 1
except:
pass
print(r * g * b - cnt) | 1 | 36,209,048,509,028 | null | 175 | 175 |
n=int(input())
if n==0:
p=0
print("%.9f"%p)
elif n&1:
p=(n//2)+1
print("%.9f"%(p/n))
else:
p=n//2
print("%.9f"%(p/n)) | import math
h , w = map(int , input().strip().split())
if h != 1 and w != 1:
print(math.ceil(h * w / 2))
else:
print(1)
| 0 | null | 113,862,119,696,348 | 297 | 196 |
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
worst_score = 10 ** 12
n, k = ns()
a = na()
f = na()
a.sort()
f.sort(reverse=True)
score = [ai * fi for ai, fi in zip(a, f)]
l = 0
r = worst_score
while True:
middle = (l + r) // 2
tmp_k = k
for i in range(n):
tmp = (score[i] - middle + f[i] - 1) // f[i]
tmp_k -= max(0, tmp)
if tmp_k < 0:
break
if r - l == 1:
print(middle if tmp_k >= 0 else middle + 1)
exit(0)
if tmp_k < 0:
l = middle
else:
r = middle
if __name__ == '__main__':
main()
| N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
ng = -1
ok = 10**12+100
while ok - ng > 1:
mid = (ok + ng) // 2
if sum(max(0,a-mid//f) for a,f in zip(A,F)) <= K:
ok = mid
else:
ng = mid
print(ok)
| 1 | 165,632,595,151,854 | null | 290 | 290 |
import sys
def gcm(a, b):
if a<b: a,b=b,a
if (a%b==0):
return b
else:
return gcm(b,a%b)
for s in sys.stdin:
a,b=map(int,s.split())
c=gcm(a,b)
print "%d %d" %(c,a/c*b) | n, k = input(), int(input())
dp0 = [[0] * (k + 2) for _ in range(len(n) + 1)]
dp1 = [[0] * (k + 2) for _ in range(len(n) + 1)]
dp1[0][0] = 1
for i in range(len(n)):
for j in range(k + 1):
dp0[i + 1][j] += dp0[i][j]
dp0[i + 1][j + 1] += dp0[i][j] * 9
if n[i] != '0':
dp0[i + 1][j] += dp1[i][j]
dp0[i + 1][j + 1] += dp1[i][j] * (int(n[i]) - 1)
dp1[i + 1][j + 1] += dp1[i][j]
elif n[i] == '0':
dp1[i + 1][j] += dp1[i][j]
print(dp0[len(n)][k] + dp1[len(n)][k])
| 0 | null | 38,191,304,948,814 | 5 | 224 |
dataset = []
while True:
h, w = map(int, input().split())
if (h >= 1 and h <= 300) and (w >= 1 and w <= 300):
listed = []
listed.append(h)
listed.append(w)
dataset.append(listed)
elif h != 0 and w != 0:
break
else:
break
for listed in dataset:
h = listed[0]
w = listed[1]
for i in range(h):
if i % 2 == 0:
for j in range(w):
if j % 2 == 0:
print("#", end="")
elif j % 2 == 1:
print(".", end="")
print()
elif i % 2 == 1:
for j in range(w):
if j % 2 == 0:
print(".", end="")
elif j % 2 == 1:
print("#", end="")
print()
print() | while True:
h,w = map(int,input().split())
if h==0 and w==0: break
for i in range(h):
s = ''
for j in range(w):
if (i+j)%2==0: s += '#'
else: s+='.'
print(s)
print()
| 1 | 887,392,251,838 | null | 51 | 51 |
a,b,k=map(int,input().split())
if a<=k:
k-=a
a=0
if b<=k:
print(0,0)
else:
b-=k
print(a,b)
elif k<a:
a-=k
print(a,b)
| n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
list=[]
for j in range(3):
D=0
for i in range(n):
if x[i]<y[i]:
d = (y[i]-x[i])
else:
d = (x[i]-y[i])
list.append(d)
D += (d**(j+1))
print(f"{D**(1/(j+1)):.6f}")
print(f"{max(list):.6f}")
| 0 | null | 52,532,226,312,992 | 249 | 32 |
A, B = map(int,input().split())
for i in range(max(A,B),0,-1):
if A%i==0 and B%i==0:
print(A*B//i)
break | n,ms = map(int, input().split())
a = [list(map(str, input().split())) for _ in range(n)]
total = 0
for i in a:
tmp = int(i[1]) - ms
if tmp <= 0:
total += ms + tmp
print("{} {}".format(i[0], total))
else:
total += ms
a.append([i[0], tmp])
| 0 | null | 56,586,367,200,730 | 256 | 19 |
s = list(input())
ans = []
for c in s:
if c.islower():
ans.append(c.upper())
elif c.isupper():
ans.append(c.lower())
else:
ans.append(c)
print("".join(ans))
| def ok(p,w,k):
track= 1
weight= 0
flag= True
for i in w:
if i > p:
flag=False
break
elif weight+ i> p:
weight= i
track+= 1
else:
weight+= i
if track<=k and flag:
return True
else:
return False
n,k= map(int, input().split())
w=[]
for i in range(n):
w.append(int(input()))
l=0
h=10**11
while l+1 < h:
p= (l+h)//2
if ok(p,w,k):
h= p
else:
l= p
print(h)
| 0 | null | 788,882,318,742 | 61 | 24 |
def main():
s = input()
ok = False
hi = ""
for _ in range(5):
hi += "hi"
if s == hi:
ok = True
if ok:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | s = int(input())
m = 0
h = 0
if s >= 60:
m = int(s / 60)
s = s % 60
if m >= 60:
h = int(m / 60)
m = m % 60
print(h,end = ":")
print(m,end = ":")
print(s)
| 0 | null | 26,932,477,384,832 | 199 | 37 |
X,Y = map(int,input().split())
key1 = Y - 2*X
key2 = 4*X - Y
if key1 % 2 != 0:
print('No')
elif key2 % 2 != 0:
print('No')
elif key1 < 0:
print('No')
elif key2 < 0:
print('No')
else:
print('Yes') | s = input()
c = s.count('R')
if c == 2 and s[1] == 'S':
c = 1
print(c) | 0 | null | 9,289,021,440,090 | 127 | 90 |
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a.sort()
dp = [0] * a[-1]
c = Counter(a)
for i in a:
for j in range(i, a[-1]+1, i):
dp[j-1] += 1
ans = 0
for i in a:
if dp[i-1] == 1 and c[i]:
ans += 1
print(ans) | import collections
n = int(input())
A = list(map(int, input().split()))
A.sort()
cnt = collections.Counter(A)
#print(cnt)
for a in A:
if cnt[a] >= 2:
del cnt[a]
for j in range(2*a, A[-1]+1, a):
del cnt[j]
#print(cnt)
print(len(cnt))
| 1 | 14,377,028,123,282 | null | 129 | 129 |
S = input()
l = len(S) // 2
ll = l // 2
former = S[:l]
latter = S[l+1:]
for i in range(l):
if S[i] != S[-i-1]:
print("No")
break
else:
for i in range(ll):
if former[i] != former[-i-1] or latter[i] != latter[-i-1]:
print("No")
break
else:
print("Yes") | number, base = map(int, input().split())
result_list = []
while number / base > 0:
mod = number % base
result_list.append(str(mod))
number = number // base
result_list.reverse()
result = "".join(result_list)
print(len(result))
| 0 | null | 55,384,225,487,238 | 190 | 212 |
strargs = input()
n, a, b = map(lambda x: int(x), strargs.split())
if (b - a) % 2 == 0:
print((b - a)//2)
elif a - 1 < n - b:
newB = b - a
mid = (newB - 1)//2 + 1
print(a + mid - 1)
else:
newA = (a + (n - b + 1))
mid = newA + (n - newA)//2
print((n - b + 1) + (n - newA)//2) | import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
MOD = 10 ** 4 + 7
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
print(min(A - 1, N - B) + 1 + (B - A - 1) // 2) | 1 | 109,268,243,208,220 | null | 253 | 253 |
# encoding: utf-8
from collections import deque
def round_robin_scheduling(N, Q, A):
t = 0
while A:
process = A.popleft()
if process[1] <= Q:
t += process[1]
print(process[0],t)
else:
t += Q
A.append([process[0],process[1]-Q])
if __name__ == '__main__':
N,Q = map(int,input().split())
A = deque()
for i in range(N):
a = input()
A.append([a.split()[0],int(a.split()[1])])
round_robin_scheduling(N,Q,A) | a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if v<w:
print("NO")
exit()
diff=abs(a-b)
for _ in range(t):
diff=diff-v+w
if diff<=0:
print("YES")
exit()
print("NO") | 0 | null | 7,603,562,377,600 | 19 | 131 |
def main():
n = int(input())
ans = 0
x = n // 2
for i in range(1, n + 1):
m = n // i
ans += i * ((m + 1) * m) // 2
print(ans)
if __name__ == "__main__":
main()
| #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) | 1 | 11,054,101,006,818 | null | 118 | 118 |
s = input()
if len(s) %2 !=0:
print("No")
else:
c =0
for i in range(len(s)//2):
hi = s[2*i:2*i+2]
if hi == "hi":
pass
else:
c = 1
break
if c ==0:
print("Yes")
else:
print("No")
| n = input()
n = int(n)
if(n==2):
print(1)
elif(n%2==0):
print(int(n/2))
else:
print(int(n/2)+1) | 0 | null | 56,361,472,827,580 | 199 | 206 |
a,b,n=map(int,input().split())
score=0
if (n<b):
print( int(a*n/b))
elif(b==1):
print(0)
else:
c = int(n/b)
score = 0
for i in range(1,c+1):
n_ = b*i-1
t = int(a*n_/b)-a*int(n_/b)
score = max(score,t)
t = int(a*n/b)-a*int(n/b)
score = max(score,t)
print(score) | n = int(input())
mod = 1000000007
def _mod(x, y):
res = 1
for i in range(y):
res = (res * x) % mod
return res
ans = _mod(10, n) - _mod(9, n) - _mod(9, n) + _mod(8, n)
ans %= mod
print(ans)
| 0 | null | 15,537,321,690,318 | 161 | 78 |