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] +... | 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)
... | 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)*... | 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 = l... | 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 combin... | 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(qu... | 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
... |
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={}
... | 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 s... | 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... | 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 = ... | 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().... | 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(): re... | 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[... | 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... | 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)] fo... | 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 inde... | 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():
... | 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... | 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... | 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(*da... | 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.item... | 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:
... | 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... | 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
... | 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... | 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
... | 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
... | 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+... | 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 ... | 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... | 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(a... | 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_... | 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('.',en... | 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 ... | 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(m... | 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)... | 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, heappus... | 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... | 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 ** ... | 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)
ex... | 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,... | 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 += [in... | 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... | 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 impo... | 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_... | 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(... | 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)
... | 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 ra... | 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... | 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 = ... | 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):
cu... | 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,n... | 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:... | 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 i... | #!/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 itert... | 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]+... | 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
... | 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+... | 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 ... | 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 ... | 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))
prin... | 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... | 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
# KeyIn... | 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 | 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 = divis... | 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... | 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... | 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 = li... | 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(... | 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
... | 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 ** ... | 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_... | 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... | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.