code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
end = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if d1 == end[m1-1]:
print(1)
else:
print(0) | m1,d1=map(int,input().split())
m2,d2=map(int,input().split())
if m1!=m2:
print(1)
else:print(0) | 1 | 124,862,822,582,640 | null | 264 | 264 |
import math
def myceil(x,n):
return math.pow(10,-n)*math.ceil(x*math.pow(10,n))
def debt(principal,w):
if w==1:
return int(myceil(principal*1.05,-3))
else:
return int(debt(myceil(principal*1.05,-3),w-1))
w=int(input())
print(debt(100000,w)) | def main():
a = []
for i in range(10):
a.append(int(input()))
a.sort()
a.reverse()
for i in range(3):
print(a[i])
if __name__ == '__main__':
main() | 0 | null | 736,298,882 | 6 | 2 |
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
if sum(a) > n:
print(-1)
else:
print(n - sum(a)) | import numpy as np
N, M = map(int, input().split())
A = []
A = map(int, input().split())
dif = N - sum(A)
if dif >= 0:
print(dif)
else:
print('-1') | 1 | 32,111,043,762,440 | null | 168 | 168 |
x, k, d = [int(i) for i in input().split()]
if x < 0:
x = -x
l = min(k, x // d)
k -= l
x -= l * d
if k % 2 == 0:
print(x)
else:
print(d - x) | for i in range(9):
for j in range(9):
print "%dx%d=%d" %(i+1,j+1, (i+1)*(j+1)) | 0 | null | 2,641,807,600,740 | 92 | 1 |
def main():
x, k, d = map(int,input().split())
abs_x = abs(x)
times = abs_x // d
if(times > k):
print(abs_x - k * d)
else:
if((k - times) % 2 == 0):
print(abs_x - times * d)
else:
print(abs(abs_x - (times + 1) * d))
if __name__ == '__main__':
main() | N = int(input())
for i in range(1,11):
need = 1000 * i
if N <= need:
print(need - N)
break | 0 | null | 6,792,480,711,276 | 92 | 108 |
from collections import deque
n,q = tuple([int(i) for i in input().split()])
lines = [input().split() for i in range(n)]
pro = deque([[i[0], int(i[1])] for i in lines])
time = 0
while True:
left = pro.popleft()
if left[1] - q > 0:
time += q
pro.append([left[0], left[1] - q])
else:
time += left[1]
print(' '.join([left[0], str(time)]))
if len(pro) == 0:
break; | class Queue:
def __init__(self,values):
self.values = values
def empty(self):
if len(self.values) == 0:
return True
else:
return False
def enqueue(self,v):
self.values.append(v)
def dequeue(self):
if len(self.values) <= 0:
raise
else:
v = self.values[0]
del self.values[0]
return v
n,q = map(int,raw_input().split(' '))
processes = []
for i in range(n):
n,t = raw_input().split(' ')
processes.append((n,int(t)))
queue = Queue(processes)
clock = 0
done = []
while not queue.empty():
p = queue.dequeue()
n = p[0]
t = p[1]
if t <= q:
clock+=t
done.append((n,clock))
else:
queue.enqueue((n,t-q))
clock+=q
for p in done:
print p[0],p[1] | 1 | 42,943,390,752 | null | 19 | 19 |
A,B,C = map(int,input().split())
K = int(input())
for i in range(K):
if A >= B:
B = B*2
else:
C = C*2
print("Yes" if A < B and B < C else "No") | N = int(input())
if N == 1:
print(1)
elif N%2 == 0:
print(0.5)
else:
print((N+1)/2/N) | 0 | null | 92,343,541,249,432 | 101 | 297 |
a,b,c = [int(x) for x in input().split()]
import math
si = math.sin(math.radians(c))
co = math.cos(math.radians(c))
s = a*b*si/2
l = a + b + (a**2 + b**2 - 2*a*b*co)**(1/2)
h = 2*s/a
print("{:.6f}".format(s))
print("{:.6f}".format(l))
print("{:.6f}".format(h))
| import math
a, b, C = map(int, input().split())
C2 = math.radians(C)
sin = math.sin(C2)
cos = math.cos(C2)
c = math.sqrt(a**2 + b**2 - 2*a*b*cos)
S =(a*b*sin) / 2
L = a+b+c
#L**2 = a**2 + b**2 - 2*a*b*cos
h = (a*b*sin/2)/(a/2)
print("{0:.8f}".format(S))
print("{0:.8f}".format(L))
print("{0:.8f}".format(h)) | 1 | 181,461,945,148 | null | 30 | 30 |
import sys
read = sys.stdin.buffer.read
n, k, *p = map(int, read().split())
p.sort()
print(sum(p[:k])) | (r, c) = [int(i) for i in input().split()]
src = []
for _ in range(r):
row = [int(i) for i in input().split()]
row.append(sum(row))
src.append(row)
last_row = [0 for _ in range(c + 1)]
for rc in range(r):
for cc in range(c+1):
last_row[cc] += src[rc][cc]
src.append(last_row)
for rc in range(r+1):
print(' '.join([str(a) for a in src[rc]])) | 0 | null | 6,476,834,503,204 | 120 | 59 |
fibo_list=[0 for i in range(48)]
def fibo(n):
f=fibo_list[n]
if f:
return f
else:
if n==0 or n==1:
return 1
else:
f=fibo(n-1)+(fibo(n-2))
fibo_list[n]=f
return f
n=input()
print(fibo(n)) | prime = 10 ** 9 + 7
n = int(input())
ans = 10 ** n - (9 ** n) * 2 + 8 ** n
ans %= prime
print(ans) | 0 | null | 1,562,249,589,472 | 7 | 78 |
while True:
m, f, r = [int (x) for x in input().split(' ')]
if m == -1 and f == -1 and r == -1: break
if m == -1 or f == -1 or m + f < 30:
print('F')
elif m + f >= 80:
print('A')
elif m + f >= 65 and m + f < 80:
print('B')
elif m + f >= 50 and m + f < 65:
print('C')
elif m + f >= 30 and m + f < 50:
if r >= 50:
print('C')
else:
print('D') | from decimal import Decimal
a,b,c = list(map(Decimal,input().split()))
d = Decimal('0.5')
A = a ** d
B = b ** d
C = c ** d
if A + B < C:
print('Yes')
else:
print('No')
| 0 | null | 26,460,694,581,530 | 57 | 197 |
a,b = map(int,raw_input().split())
print a/b
print a%b
print "%.5f" % (a/float(b)) | n = int(input())
a_line = []
b_line = []
for i in range(n):
a, b = map(int, input().split())
a_line.append(a)
b_line.append(b)
a_line.sort()
b_line.sort()
if n % 2 == 0:
left = a_line[n // 2 - 1] + a_line[n // 2]
right = b_line[n // 2 - 1] + b_line[n // 2]
print(right - left + 1)
else:
print(b_line[n // 2] - a_line[n // 2] + 1) | 0 | null | 8,944,429,513,500 | 45 | 137 |
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
S = input()
if S == "AC":
AC += 1
elif S == "WA":
WA += 1
elif S == "TLE":
TLE += 1
else:
RE += 1
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE)) | #!/usr/bin/env python3
import sys
from itertools import chain
from collections import Counter
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# import numpy as np
def solve(N: int, S: "List[str]"):
d = Counter(S)
for key in ("AC", "WA", "TLE", "RE"):
print(f"{key} x {d.get(key, 0)}")
def main():
tokens = chain(*(line.split() for line in sys.stdin))
# N, S = map(int, line.split())
N = int(next(tokens)) # type: int
S = [next(tokens) for _ in range(N)] # type: "List[str]"
solve(N, S)
if __name__ == "__main__":
main()
| 1 | 8,649,720,052,960 | null | 109 | 109 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = [int(x)-48 for x in read().rstrip()]
ans = 0
dp = [[0]*(len(N)+1) for i in range(2)]
dp[1][0] = 1
dp[0][0] = 0
for i in range(1, len(N)+1):
dp[0][i] = min(dp[0][i-1] + N[i-1],
dp[1][i-1] + (10 - N[i-1]))
dp[1][i] = min(dp[0][i-1] + N[i-1] + 1,
dp[1][i-1] + (10 - (N[i-1] + 1)))
print(dp[0][len(N)])
| N,K=map(int,input().split())
*A,=map(int,input().split())
def C(x):
return sum([(A[i]-.5)//x for i in range(N)]) <= K
def binary_search2(func, n_min, n_max):
left,right=n_min,n_max
while right-left>1:
middle = (left+right)//2
y_middle = func(middle)
if y_middle: right=middle
else: left=middle
return right
print(binary_search2(C, 0, max(A)+1)) | 0 | null | 38,820,960,173,472 | 219 | 99 |
n, m = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
n_vote = sum(l)
if l[m-1] >= n_vote/(4*m):
print('Yes')
else:
print('No') | n, m = map(int, input().split())
a = list(map(int, input().split()))
print("Yes" if len([i for i in a if i/sum(a) >= 1/(4 * m)]) >= m else "No") | 1 | 38,523,527,126,188 | null | 179 | 179 |
# -*-coding:utf-8
import fileinput
if __name__ == '__main__':
for line in fileinput.input():
digit = 0
tokens = list(map(int, line.strip().split()))
a, b = tokens[0], tokens[1]
num = a + b
print(len(str(num))) | from math import log10 as log
from sys import stdin
A = []
for po in stdin:
S = list(map(int,po.split()))
A.append(int(log(S[0]+S[1])+1))
for i in A:
print(i) | 1 | 151,079,218 | null | 3 | 3 |
n=int(input())
a=list(map(int,input().split()))
l=[]
flag=0
for aa in a:
if aa%2==0:
flag=1
l.append(aa)
if flag==1:
for ll in l:
if ll % 3!=0 and ll % 5!=0:
flag=2
if flag==0:
print('APPROVED')
elif flag==1:
print('APPROVED')
elif flag==2:
print('DENIED')
| n,m = map(int,input().split())
dac = {}
for i in range(1,n+1):
dac[str(i)] = 0
dwa = {}
for i in range(1,n+1):
dwa[str(i)] = 0
for i in range(m):
p,s = input().split()
if s == 'AC':
dac[p] = 1
if s == 'WA' and dac[p] == 0:
dwa[p] += 1
ac = 0
wa = 0
for k,v in dac.items():
ac += v
for k,v in dwa.items():
if dac[k] == 1:
wa += v
print(ac,wa) | 0 | null | 81,378,705,657,522 | 217 | 240 |
X = int(input())
print(10 - X // 200) | INF = 1 << 60
h, n = map(int, input().split())
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n):
a[i], b[i] = map(int, input().split())
MAX = h - 1 + max(a)
dp = [[INF for j in range(MAX + 1)] for i in range(n)]
dp[0][0] = 0
if 0 <= a[0] < MAX + 1:
dp[0][a[0]] = b[0]
for j in range(MAX + 1):
if 0 <= j - a[0] < MAX + 1:
dp[0][j] = min(dp[0][j], dp[0][j - a[0]] + b[0])
for i in range(1, n):
for j in range(MAX + 1):
dp[i][j] = min(dp[i][j], dp[i - 1][j])
if 0 <= j - a[i] < MAX + 1:
dp[i][j] = min(dp[i][j], dp[i][j - a[i]] + b[i])
ans = INF
for j in range(h, MAX + 1):
ans = min(ans, dp[-1][j])
print(ans) | 0 | null | 44,085,804,504,092 | 100 | 229 |
N,M,K=map(int,input().split())
par=[0]*(N+1)
num=[0]*(N+1)
group = [1]*(N+1)
for i in range(1,N+1): par[i]=i
def root(x):
if par[x]==x: return x
return root(par[x])
def union(x,y):
rx = root(x)
ry = root(y)
if rx==ry: return
par[max(rx,ry)] = min(rx,ry)
group[min(rx,ry)] += group[max(rx,ry)]
def same(x,y):
return root(x)==root(y)
for _ in range(M):
a,b=map(int,input().split())
union(a,b)
num[a]+=1
num[b]+=1
for _ in range(K):
c,d=map(int,input().split())
if same(c,d):
num[c]+=1
num[d]+=1
for i in range(1,N+1):
print(group[root(i)]-num[i]-1,end=" ") | for val in range(input()):
x = map(int,raw_input().split(' '))
x.sort()
if x[0]**2+x[1]**2==x[2]**2: print 'YES'
else: print 'NO' | 0 | null | 30,929,666,384,692 | 209 | 4 |
import math
foo = []
while True:
n = int(input())
if n == 0:
break
a = [int(x) for x in input().split()]
ave = sum(a)/len(a)
hoge = 0
for i in a:
hoge += (i - ave) ** 2
hoge /= len(a)
foo += [math.sqrt(hoge)]
for i in foo:
print(i) | while(True):
n=int(input())
if(n==0):
break
val=list(map(int, input().split()))
sum=0
for i in val:
sum+=i
mean=sum/n
disp=0
for i in val:
disp+=(i-mean)**2
disp=disp/n
print(disp**0.5)
| 1 | 193,888,787,030 | null | 31 | 31 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop, heapify
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
A = LIST()
LR = [[A[-1], A[-1]]]
for i, b in enumerate(A[::-1][1:], 1):
if N-i+1 < 30:
LR.append([-(-LR[-1][0]//2)+b, min(LR[-1][1]+b, pow(2, N-i+1))])
else:
LR.append([-(-LR[-1][0]//2)+b, LR[-1][1]+b])
LR = LR[::-1]
if LR[0][0] <= 1 <= LR[0][1]:
pass
else:
print(-1)
exit()
ans = 1
tmp = 1
for i, (L, R) in enumerate(LR[1:], 1):
tmp = min(2*tmp-A[i], R-A[i])
ans += tmp+A[i]
print(ans) | N = input()
result = int(N) ** 3
print(result)
| 0 | null | 9,667,712,499,666 | 141 | 35 |
N, M = map(int, input().split())
ac = 0
pena = 0
count = [0 for _ in range(N+1)]
for _ in range(M):
p, S = input().split()
p = int(p)
if S == 'AC':
if count[p] > -1:
pena += count[p]
ac += 1
count[p] = -10**5-1
else:
count[p] += 1
print(ac, pena)
| N,K=list(map(int, input().split()))
H=list(map(int, input().split()))
if K>=N:
print(0)
exit()
H.sort(reverse=True)
H=H[K:]
print(sum(H)) | 0 | null | 86,227,202,989,550 | 240 | 227 |
a,b = map(int,input().split())
print(a*b if a<=9 and b<=9 else -1) | # ALDS_2_B.
# バブルソート。
from math import sqrt, floor
def intinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
def show(a):
# 配列の中身を出力する。
_str = ""
for i in range(len(a) - 1):
_str += str(a[i]) + " "
_str += str(a[len(a) - 1])
print(_str)
def selection_sort(a):
# 選択ソート。その番号以降の最小値を順繰りにもってくる。
# 交換回数は少ないが比較回数の関係で結局O(n^2)かかる。
count = 0
for i in range(len(a)):
# a[i]からa[len(a) - 1]のうちa[j]が最小っていうjを取る。
# このときiとjが違うならカウントする。
# というかa[i]とa[j]が違う時カウントでしたね。
minj = i
for j in range(i, len(a)):
if a[j] < a[minj]: minj = j
if a[i] > a[minj]: count += 1; a[i], a[minj] = a[minj], a[i]
return count
def main():
N = int(input())
A = intinput()
count = selection_sort(A)
show(A); print(count)
if __name__ == "__main__":
main()
| 0 | null | 79,162,238,309,030 | 286 | 15 |
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
N,K,S=map(int,input().split())
if S>1:
print(*[S]*(K)+[S-1]*(N-K))
else:
print(*[S]*(K)+[S+1]*(N-K))
resolve() | n, k, s = map(int, input().split())
ans = []
for i in range(k):
ans.append(s)
for i in range(n-k):
if s == 10**9:
ans.append(10**9-1)
else:
ans.append(s+1)
print(*ans, sep=' ')
| 1 | 91,236,053,142,190 | null | 238 | 238 |
# coding:UTF-8
import sys
from math import factorial
MOD = 998244353
INF = 10000000000
def main():
n, k = list(map(int, input().split())) # スペース区切り連続数字
lrList = [list(map(int, input().split())) for _ in range(k)] # スペース区切り連続数字(行列)
s = []
for l, r in lrList:
for i in range(l, r+1):
s.append(i)
s.sort()
sum = [0] * (n + 1)
Interm = [0] * (2 * n + 1)
sum[1] = 1
for i in range(1, n):
for j in range(k):
l, r = lrList[j][0], lrList[j][1]
Interm[i+l] += sum[i]
Interm[i+r+1] -= sum[i]
sum[i+1] = (sum[i] + Interm[i+1]) % MOD
# result = Interm[n]
result = (sum[n] - sum[n-1]) % MOD
# ------ 出力 ------#
print("{}".format(result))
if __name__ == '__main__':
main()
| N, K = map(int, input().split())
mod = 998244353
move = []
for _ in range(K):
L, R = map(int, input().split())
move.append((L, R))
S = [0]*K
dp = [0]*(2*N)
dp[N] = 1
for i in range(N+1, 2*N):
for k, (l, r) in enumerate(move):
S[k] -= dp[i-r-1]
S[k] += dp[i-l]
dp[i] += S[k]
dp[i] %= mod
print(dp[-1]) | 1 | 2,693,343,461,742 | null | 74 | 74 |
n, k = list(map(int, input().split()))
enemy = list(map(int, input().split()))
enemy = sorted(enemy, reverse=True)
enemy = enemy[k:]
print(sum(enemy)) | from math import *
while True:
n = int(input())
if n == 0:
break
s = list(map(int, input().split()))
sum_s = sum(s)
m = sum_s / n
print(sqrt(sum((a - m) ** 2 for a in s) / n))
| 0 | null | 39,748,392,427,702 | 227 | 31 |
n,x,y = map(int,input().split())
ans_ls = [0] * (n-1)
for start in range(1,n):
for end in range(start+1,n+1):
cost_1 = end - start
cost_2 = abs(start - x) + abs(end - y) + 1
cost = min(cost_1,cost_2)
ans_ls[cost-1] += 1
for ans in ans_ls:
print(ans)
| #!/usr/bin/env python3
def get_points_and_convert(pts):
x, y = pts
return x + y, x - y
def main():
n = int(input())
points = [
get_points_and_convert(map(int, input().split()))
for _ in range(n)
]
plus_coords, minus_coords = list(zip(*points))
plus_dist = max(plus_coords) - min(plus_coords)
minus_dist = max(minus_coords) - min(minus_coords)
print(max(plus_dist, minus_dist))
if __name__ == '__main__':
main()
| 0 | null | 23,795,032,235,480 | 187 | 80 |
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
def main():
n = int(input())
a = list(map(int,input().split()))
cnt = [0] * (n + 1)
cnt[0] = 3
ans = 1
for num in a:
ans *= cnt[num]
ans %= MOD
cnt[num] -= 1
cnt[num + 1] += 1
print(ans)
if __name__ =='__main__':
main()
| s=str(input())
if s[0]==s[1] and s[0]==s[2]:
print('No')
else :
print('Yes') | 0 | null | 92,515,906,368,542 | 268 | 201 |
from time import time
from random import random
limit_secs = 2
start_time = time()
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
def calc_score(t):
score = 0
S = 0
last = [-1] * 26
for d in range(len(t)):
S += s[d][t[d]]
last[t[d]] = d
for i in range(26):
S -= c[i] * (d - last[i])
score += max(10 ** 6 + S, 0)
return score
def solution1():
return [i % 26 for i in range(D)]
def solution2():
t = None
score = -1
for i in range(26):
nt = [(i + j) % 26 for j in range(D)]
if calc_score(nt) > score:
t = nt
return t
def solution3():
t = []
for _ in range(D):
score = -1
best = -1
t.append(0)
for i in range(26):
t[-1] = i
new_score = calc_score(t)
if new_score > score:
best = i
score = new_score
t[-1] = best
return t
def optimize0(t):
return t
def optimize1(t):
score = calc_score(t)
while time() - start_time + 0.15 < limit_secs:
d = int(random() * D)
q = int(random() * 26)
old = t[d]
t[d] = q
new_score = calc_score(t)
if new_score < score:
t[d] = old
else:
score = new_score
return t
t = solution3()
t = optimize0(t)
print('\n'.join(str(e + 1) for e in t))
| N, M = map(int, input().split())
s = []
c = []
for i in range(M):
x,y = map(int,input().split())
s.append(x)
c.append(y)
ans_list = [-1 for i in range(N)]
for i in range(M):
if ans_list[s[i]-1] != -1 and ans_list[s[i]-1] != c[i]:
print(-1)
exit()
else:
ans_list[s[i]-1] = c[i]
#print(ans_list)
if ans_list[0] == 0 and N>=2:
print(-1)
exit()
ans = 0
for i in range(N):
if ans_list[i] == -1 and i != 0:
ans_list[i] = 0
if ans_list[i] == -1 and i == 0 and N >= 2:
ans_list[i] = 1
if ans_list[i] == -1 and i == 0 and N == 1:
ans_list[i] = 0
ans += ans_list[i] * (10**(N-i-1))
print(ans)
| 0 | null | 35,300,186,267,500 | 113 | 208 |
n = input()
for i in range(len(n)):
if n[i] == '7':
print('Yes')
exit()
print('No')
| import math
r = input()
print '%.10f %.10f' %(r*r*math.pi , r*2*math.pi) | 0 | null | 17,559,031,951,008 | 172 | 46 |
from collections import deque
N = int(input())
c = [chr(ord("a") + i) for i in range(26)]
q = deque("a")
ans = []
while q:
s = q.pop()
if len(s) == N:
ans.append(s)
continue
for x in c[:c.index(max(s)) + 2]:
q.append(s + x)
[print(a) for a in sorted(ans)] | a, b, c, d = map(int, input().split())
x = 0
y = 0
while c > 0:
c -= b
x += 1
while a > 0:
a -= d
y += 1
if x <= y:
print('Yes')
else:
print('No')
| 0 | null | 41,019,636,907,852 | 198 | 164 |
def solve(n, A, q, m):
memo = dict()
for i in range(2**n):
tmp = 0
for j in range(n):
if i >> j & 1:
tmp += A[j]
memo[tmp] = 1
for val in m:
print("yes" if val in memo else "no")
if __name__ == "__main__":
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
solve(n, A, q, m)
| N, M = map(int, input().split())
f = 0
A = [-1 for i in range(N)]
for i in range(M):
s, c = map(int, input().split())
if A[s-1] != -1 and A[s-1] != c:
print(-1)
f = 1
break
A[s-1] = c
if f == 0:
if N == 1 and (A[0] <= 0):
print(0)
elif N > 1 and A[0] == 0:
print(-1)
else:
ans = 0
for i in range(N):
if i == 0:
ans = ans * 10 + max(A[i], 1)
else:
ans = ans * 10 + max(A[i], 0)
print(ans) | 0 | null | 30,520,077,249,438 | 25 | 208 |
def max(a,b,c):
if a >= b and a >= c:
return a
if b >= a and b >= c:
return b
else:
return c
def min(a,b,c):
if a <= b and a <= c:
return a
if b <= a and b <= c:
return b
else:
return c
def mid(a,b,c):
if (b-a)*(c-a) <= 0:
return a
if (a - b) * (c - b) <= 0:
return b
else:
return c
s = input()
s = s.split()
n = []
for i in s:
n.append(int(i))
a = n[0]
b = n[1]
c = n[2]
print(min(a,b,c),mid(a,b,c),max(a,b,c))
| word = input()
text = []
count = 0
while True:
x = input()
if x == "END_OF_TEXT":
break
x = x.split()
for i in x:
if i.lower() == word:
count += 1
print(count)
| 0 | null | 1,123,351,955,680 | 40 | 65 |
n = int(input())
s = [None] * n
for i in range(n):
s[i] = input()
print(len(list(set(s)))) | N=int(input())
S=[input() for _ in range(N)]
a=0
w=0
t=0
r=0
for i in range(N):
if S[i] =="AC":
a+=1
elif S[i] =="WA":
w+=1
elif S[i] =="TLE":
t+=1
elif S[i] =="RE":
r+=1
print("AC x "+ str(a))
print("WA x "+ str(w))
print("TLE x "+ str(t))
print("RE x "+ str(r))
| 0 | null | 19,375,712,445,774 | 165 | 109 |
N,M = map(int,input().split())
L = map(int,input().split())
work = 0
for i in L :
work += i
if N >= work :
print ( N - work )
else :
print ("-1") | n=int(input())
def make(floor,kind,name): #floor=何階層目か,kind=何種類使ってるか
if floor==n+1:
print(name)
return
num=min(floor,kind+1)
for i in range(num):
use=0 #新しい文字使ってるか
if kind-1<i:
use=1
make(floor+1,kind+use,name+chr(i+97))
make(1,0,"") | 0 | null | 42,245,008,221,052 | 168 | 198 |
import math
from functools import reduce
from copy import deepcopy
n,m = map(int,input().split())
A = list(map(int,input().split()))
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
Acopy = deepcopy(A)
flag = -1
for i in range(n):
cnt = 0
while True:
if Acopy[i] % 2 == 1:
break
else:
Acopy[i] //= 2
cnt += 1
if i == 0:
flag = cnt
else:
if flag != cnt:
print(0)
break
else:
A = [a//2 for a in A]
lcm = lcm_list(A)
print((lcm+m)//2//lcm)
| import math
def makelist(n, m):
return [[0 for _ in range(m)] for _ in range(n)]
N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
# 最小公倍数
# ユークリッドの互除法
def lcm(a, b):
def gcd(a, b): # a >= b
if b == 0:
return a
else:
return gcd(b, a % b)
return a * b // gcd(a, b)
c = 1
for e in a:
c = lcm(c, e // 2)
hoge = [ (c // (e // 2)) % 2 == 1 for e in a ]
if all(hoge):
ans = 0
if c <= M:
ans += 1
M -= c
ans += M // (c * 2)
print(ans)
else:
print(0)
| 1 | 102,137,961,117,570 | null | 247 | 247 |
def selection_sort(A):
count = 0
for i in range(len(A)):
min_j = i
for j in range(i, len(A)):
if A[j] < A[min_j]:
min_j = j
if i != min_j:
A[i], A[min_j] = A[min_j], A[i]
count += 1
return A, count
if __name__ == '__main__':
n = int(input())
array, count = selection_sort(list(map(int, input().split())))
print(' '.join(map(str, array)))
print(count) | n = int(input())
plus_bracket = []
minus_bracket = []
for _ in range(n):
mini = 0
cur = 0
for bracket in input():
if bracket == '(':
cur += 1
else:
cur -= 1
if cur < mini:
mini = cur
if cur > 0:
plus_bracket.append([-mini, cur])
else:
minus_bracket.append([cur - mini, -cur])
success = True
cur = 0
plus_bracket.sort()
minus_bracket.sort()
for bracket in plus_bracket:
if cur < bracket[0]:
success = False
break
cur += bracket[1]
back_cur = 0
for bracket in minus_bracket:
if back_cur < bracket[0]:
success = False
break
back_cur += bracket[1]
if cur != back_cur:
success = False
if success:
print('Yes')
else:
print('No') | 0 | null | 11,721,809,891,680 | 15 | 152 |
#!/usr/bin/env python3
import sys
from fractions import gcd
from functools import reduce
input = lambda: sys.stdin.readline().strip()
MOD = 1000000007
def lcm(a, b):
return a // gcd(a, b) * b
n = int(input())
A = [int(x) for x in input().split()]
x = reduce(lcm, A)
print(sum(x // ai for ai in A) % MOD)
| #
import sys
from fractions import gcd
input=sys.stdin.readline
def main():
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
if N==1:
print(1)
exit()
l=(A[0]*A[1])//gcd(A[0],A[1])
for i in range(2,N):
l=(l*A[i])//gcd(A[i],l-A[i])
l%=MOD
ans=0
for i in range(N):
ans+=l*pow(A[i],MOD-2,MOD)
ans%=MOD
print(ans)
if __name__=="__main__":
main()
| 1 | 88,015,081,924,518 | null | 235 | 235 |
from collections import deque
import sys
N, u, v = map(int, input().split())
u -= 1; v -= 1
edge = [[] for _ in range(N)]
for s in sys.stdin.readlines():
A, B = map(lambda x: int(x) - 1, s.split())
edge[A].append(B)
edge[B].append(A)
INF = float('inf')
# Aoki
pathV = [INF] * N
pathV[v] = 0
q = deque()
q.append((v, 0))
while q:
p, d = q.popleft()
nd = d + 1
for np in edge[p]:
if pathV[np] > nd:
pathV[np] = nd
q.append((np, nd))
# Takahashi
ans = 0
pathU = [INF] * N
pathU[u] = 0
q = deque()
q.append((u, 0))
while q:
p, d = q.popleft()
nd = d + 1
if len(edge[p]) == 1:
ans = max(ans, pathV[p] - 1)
for np in edge[p]:
if pathU[np] > nd and pathV[np] > nd:
pathU[np] = nd
q.append((np, nd))
print(ans)
| import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
l=set([1,2,3])
for i in range(2):
l=l-set([int(input())])
print(int(list(l)[0])) | 0 | null | 114,551,633,884,412 | 259 | 254 |
from bisect import bisect_left
N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
l = 0
r = 2*10**5+5
while l+1 < r:
mid = (l+r) // 2
m = 0
for a in A:
idx = bisect_left(A, mid-a)
m += N-idx
if m >= M: l = mid
else: r = mid
s = [0] * (N+1)
for i in range(N):
s[i+1] = s[i] + A[i]
ans = 0
m = 0
for a in A:
idx = bisect_left(A, l-a)
m += N-idx
ans += s[N]-s[idx]
ans += a*(N-idx)
ans -= (m-M)*l
print(ans) | N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
B = [0 for i in range(10**5+1)]
S = [0]
s = 0
for i in range(N):
B[A[i]] += 1
s += A[i]
S.append(s)
for i in range(2,10**5+2):
B[-i] += B[-i+1]
d = 0
u = 2*10**5
for i in range(30):
x = (u+d)//2
if i == 28:
x += 1
m = 0
for i in range(N):
a = A[i]
y = max(x - a,0)
if y <= 10**5:
m += B[y]
if m >= M:
d = x
else:
u = x
ans = 0
for i in range(N):
a = A[i]
x = max(d - a,0)
if x <= 10**5:
y = B[x]
else:
y = 0
ans += (S[N] - S[N-y]) + a*y
ans -= (m-M)*d
print(ans) | 1 | 108,214,198,780,770 | null | 252 | 252 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n,x,y=nii()
x-=1
y-=1
ans=[0 for i in range(n)]
for i in range(n-1):
for j in range(i+1,n):
dist1=j-i
dist2=abs(i-x)+1+abs(j-y)
dist=min(dist1,dist2)
ans[dist]+=1
for i in ans[1:]:
print(i) | from collections import defaultdict
def main():
n, x, y = map(int, input().split())
x -= 1
y -= 1
klist = defaultdict(int)
for i in range(n):
for j in range(i+1, n):
if (i <= x and j <= x) or (y <= i and y <= j):
k = j - i
klist[k] += 1
elif i <= x and x < j <= y:
k = min(j - i, (x - i + y - j) + 1)
klist[k] += 1
elif i <= x and y <= j:
k = (j - i) - (y - x) + 1
klist[k] += 1
else:
k = min((j - i), ((i - x) + abs(y - j) + 1))
klist[k] += 1
for i1 in range(1, n):
print(klist[i1])
if __name__ == '__main__':
main()
| 1 | 43,974,600,552,220 | null | 187 | 187 |
a, b, m = map(int, input().split())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))
cost = []
for i in range(m):
x, y, c = map(int, input().split())
cost.append(arr_a[x - 1] + arr_b[y - 1] - c)
cost.append(min(arr_a) + min(arr_b))
ans = min(cost)
print(ans) | while 1 :
try:
h,w=map(int,input().split())
#print(h,w)
if( h==0 and w==0 ):
break
else:
for hi in range(h):
print("#" * w)
print() #??????
if( h==0 and w==0 ): break
except (EOFError):
#print("EOFError")
break | 0 | null | 27,322,029,681,188 | 200 | 49 |
s=list(input())
t=list(input())
ans=[]
for i in range(len(s)-len(t)+1):
u=s[i:len(t)+i]
a=0
for j in range(len(t)):
if not t[j-1]==u[j-1]:
a=a+1
ans.append(a)
print(min(ans)) | N = int(input())
Numbers = list(map(int,input().split()))
temp_min = Numbers[0]
count = 0
for i in range(N):
if Numbers[i] <= temp_min:
temp_min = Numbers[i]
count = count+1
print(count) | 0 | null | 44,573,008,206,240 | 82 | 233 |
N=int(input())
S=input()
print(bytes((s-65+N)%26+65 for s in S.encode()).decode()) | n=int(input())
S=input()
ans = ""
for s in S:
if (ord(s)+n) > 90:
ans += chr(64+((ord(s)+n)%90))
else:
ans += chr(ord(s)+n)
print(ans) | 1 | 134,808,944,195,492 | null | 271 | 271 |
n = input()
a = False
for i in n:
if i == '7':
a = True
print('Yes' if a else 'No') | n = int(input())
ans = 0
for a in range (1,n):
for b in range(a, n, a):
ans += 1
print(ans) | 0 | null | 18,446,920,256,358 | 172 | 73 |
# i>j とする.
# |i-j|=Ai+Aj
# i-j = Ai+Aj
N=int(input())
A=list(map(int,input().split()))
cnt=[0]*300000
ans=0
for i in range(N):
if i-A[i]>=0:
ans=ans+cnt[i-A[i]]
if i+A[i]<len(cnt):
cnt[i+A[i]]=cnt[i+A[i]]+1
print(ans)
| #! python3
a, b = [int(x) for x in input().strip().split(' ')]
if a > b:
print('a > b')
elif a < b:
print('a < b')
else:
print('a == b') | 0 | null | 13,191,113,212,190 | 157 | 38 |
M = 10**9 + 7
n = int(input())
a = [int(i) for i in input().split()] #; print(a)
counter = [0] * (n+1) ; counter[0] = 3
ans = 1
for i in range(n):
ans *= counter[a[i] - 1 +1] - counter[a[i] +1]
ans = ans % M
counter[a[i] +1] += 1
print(ans) | import sys
# sys.setrecursionlimit(100000)
def input():
return sys.stdin.readline().strip()
def input_int():
return int(input())
def input_int_list():
return [int(i) for i in input().split()]
def main():
n = input_int()
A = input_int_list()
MOD = 10**9 + 7
cnt = 1
x, y, z = 0, 0, 0
for a in A:
tmp = 0
is_used = False # x,y,zのどこかに配った。
if a == x:
tmp += 1
if not is_used:
x += 1
is_used = True
if a == y:
tmp += 1
if not is_used:
y += 1
is_used = True
if a == z:
tmp += 1
if not is_used:
z += 1
is_used = True
cnt *= tmp
cnt = cnt % MOD
print(cnt)
return
if __name__ == "__main__":
main()
| 1 | 130,381,209,117,600 | null | 268 | 268 |
from sys import stdin, stdout # only need for big input
def solve():
s = input()
left = 0
right = len(s) - 1
count = 0
while left < right:
count += (s[left] != s[right])
left += 1
right -= 1
print(count)
def main():
solve()
if __name__ == "__main__":
main() | from collections import deque
H, W, K = map(int, input().split())
S = []
for _ in range(H):
S.append(list(input()))
def cut(bit):
"""
横の切れ目の場所をビットで管理する。
"00...0" <= bit <= "11...1"(H - 1桁)の時に、縦に入れる切れ目の最小回数を返す。
"""
end = [] # 板チョコを横区切りにした結果、上から何段目で各板チョコのピースが終わるか
for i in range(H - 1):
if bit[i] == '1':
end.append(i)
end.append(H - 1)
chocolates = [0] * (len(end))
#print("end={}".format(end))
"""
ここまでで板チョコを横に切ったわけだが、こうして分割した横長の部分板チョコを
上からsection = 0, 1, 2,..., len(end)-1と呼び分けることにする。
"""
cut = 0
whites_sum = [0] * len(end) # w列目までの白チョコの累積数をsectionごとに管理。cutが入れば初期化。
for w in range(W):
whites = [0] * len(end) # whites[section] = (w列目にある白チョコをsectionごとに保存)
section = 0 # 現在のsection
coarse = False # 横切りが荒過ぎて1列に白チョコがK個より多く並んだ場合に探索を打ち切るフラグ
for h in range(H + 1):
# sectionを跨いだ場合の処理
if h > end[section]:
if whites[section] > K:
coarse = True
break
elif whites_sum[section] + whites[section] > K:
cut += 1
whites_sum = whites
whites = [0] * len(end)
section += 1
else:
whites_sum[section] += whites[section]
section += 1
# 白チョコカウント
if h < H and S[h][w] == '1':
whites[section] += 1
# coarseフラグが立っていたら-1を返す。
if coarse:
return -1
return cut
ans = 10 ** 10
for h in range(2 ** (H - 1)):
bit = bin(h)[2:] # "0b..."を除くため
l = len(bit)
bit = '0' * (H - 1 - l) + bit # bitの桁数をH - 1にする。
#print("bit={}".format(bit))
vertical_cuts = cut(bit)
if vertical_cuts != -1:
preans = vertical_cuts + bit.count('1')
ans = min(ans, preans)
#print("vertical_cut={}, cut={} -> ans={}".format(vertical_cuts, preans, ans))
print(ans)
| 0 | null | 84,602,072,611,840 | 261 | 193 |
N = int(input())
A = list(map(int, input().split()))
LN = max(A) + 1
L = [0 for i in range(LN)]
count = 0
for i in A:
for j in range(i, LN, i):
L[j] += 1
for i in A:
if L[i] == 1:
count += 1
print(count) | # -*- coding: utf-8 -*-
s, t = map(str, input().split())
a, b = map(int, input().split())
u = str(input())
dic = {s:a, t:b}
dic[u] = dic[u] - 1
print(dic[s], dic[t]) | 0 | null | 43,359,043,231,690 | 129 | 220 |
from collections import deque
n, q = map(int, input().split())
name = deque()
time = deque()
for i in range(n):
tmp_name, tmp_time = input().split()
name.append(tmp_name)
time.append(int(tmp_time))
ans_time = 0
while len(time)>0:
tmp_time = time.popleft()
tmp_name = name.popleft()
if tmp_time<=q:
ans_time += tmp_time
print(tmp_name + " " + str(ans_time))
else:
ans_time += q
time.append(tmp_time-q)
name.append(tmp_name) | N = int(input())
ans = set()
for i in range(N):
ans.add(input())
print(len(ans)) | 0 | null | 15,036,569,631,480 | 19 | 165 |
s = input()
S = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7-S.index(s)) | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
s = input()
day = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7 - day.index(s)) | 1 | 133,308,634,094,792 | null | 270 | 270 |
N = int(input())
if N%1000 == 0:
print(0)
else:
print(1000-(N%1000)) | #coding: UTF-8
def Circle(W,H,x,y,r):
if x <= W - r and x >= r and y <= H-r and y >= r:
return "Yes"
else:
return "No"
if __name__=="__main__":
a = input().split(" ")
ans = Circle(int(a[0]),int(a[1]),int(a[2]),int(a[3]),int(a[4]))
print(ans) | 0 | null | 4,464,807,823,168 | 108 | 41 |
from collections import deque
def main():
n = int(input())
_next = [[] for _ in range(n)]
for _ in range(n):
u, k, *v = map(lambda s: int(s) - 1, input().split())
_next[u] = v
queue = deque()
queue.append(0)
d = [-1] * n
d[0] = 0
while queue:
u = queue.popleft()
for v in _next[u]:
if d[v] == -1:
d[v] = d[u] + 1
queue.append(v)
for i, v in enumerate(d, start=1):
print(i, v)
if __name__ == '__main__':
main()
| n = list(map(int,input().split()))
if max(n)>9:
print(-1)
else:
print(n[0]*n[1]) | 0 | null | 79,182,101,022,590 | 9 | 286 |
import numpy as np
import sys
N,K = map(int, input().split())
A = np.array(sys.stdin.readline().split(), np.int64)
maxa = np.max(A)
mina = maxa // (K+1)
while maxa > mina + 1:
mid = (maxa + mina)// 2
div = np.sum(np.ceil(A/mid-1))
if div > K:
mina = mid
else:
maxa = mid
print(maxa)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
r = int(readline())
print(r ** 2)
| 0 | null | 75,952,280,211,494 | 99 | 278 |
def chmin(dp, i, *x):
dp[i] = min(dp[i], *x)
INF = float("inf")
# dp[i] := min 消耗する魔力 to H -= i
h, n = map(int, input().split())
dp = [0] + [INF]*h
for _ in [None]*n:
a, b = map(int, input().split())
for j in range(h + 1):
chmin(dp, min(j + a, h), dp[j] + b)
print(dp[h]) | N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
p = -1
q = -1
jun = []
a = [(k+1) for k in range(N)]
def make(now):
if len(now) == N:
jun.append(now)
return 0
for item in a:
if item not in now:
make(now+ [item])
make([])
for k in range(len(jun)):
if jun[k] == P:
p = k
if jun[k] == Q:
q = k
if p >=0 and q >=0:
break
print(abs(p-q)) | 0 | null | 90,979,258,145,468 | 229 | 246 |
import sys
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
data = [[a,i] for i,a in enumerate(LI())]
data.sort(reverse=True)
dp = [[0] * (N+1) for _ in range(N+1)]
for i in range(N):
a, p = data[i]
for j in range(i+1):
dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + abs(N-1-j-p)*a)
dp[i+1][j] = max(dp[i+1][j], dp[i][j] + abs(i-j-p)*a)
print(max(dp[-1]))
| inputStr = input()
numList = inputStr.split(' ')
numList = [int(x) for x in numList]
#print('a: ',numList[0])
#print('b: ',numList[1])
if numList[0]==numList[1]:
print('a == b')
elif numList[0]>numList[1]:
print('a > b')
elif numList[0]<numList[1]:
print('a < b') | 0 | null | 17,173,173,866,380 | 171 | 38 |
a,b,c=map(int,input().split())
k=int(input())
for i in range(1,k+1):
if a>=b>=c or a>=c>=b:
c=c*2
elif b>=a>=c or b>=c>=a:
c=c*2
elif c>=b>a:
c=c*2
elif c>b==a:
b=b*2
elif c>a>=b:
b=b*2
if c>b>a:
print('Yes')
else:
print('No')
| # M-SOLUTIONS プロコンオープン 2020: B – Magic 2
A, B, C = [int(i) for i in input().split()]
K = int(input())
is_success = 'No'
for i in range(K + 1):
for j in range(K + 1):
for k in range(K + 1):
if i + j + k <= K and A * 2 ** i < B * 2 ** j < C * 2 ** k:
is_success = 'Yes'
print(is_success) | 1 | 6,870,197,818,260 | null | 101 | 101 |
N = int(raw_input())
num_list = map(int, raw_input().split())
c = 0
for i in range(0,N,1):
flag =0
minj =i
for j in range(i,N,1):
if num_list[j] < num_list[minj]:
minj = j
flag = 1
c += flag
num_list[i], num_list[minj] = num_list[minj], num_list[i]
print " ".join(map(str,num_list))
print c | n = int(input())
a = [int(s) for s in input().split(" ")]
cnt = 0
for i in range(n):
mi = min(a[i:])
if a[i] > mi:
j = a[i:].index(mi)+i
a[i], a[j] = a[j], a[i]
cnt += 1
print(" ".join([str(i) for i in a]))
print(cnt) | 1 | 21,122,449,780 | null | 15 | 15 |
n=int(input())
a=[]
x=[]
for _ in range(n):
A=int(input())
X=[list(map(int,input().split())) for _ in range(A)]
a.append(A)
x.append(X)
ans=0
for i in range(2**n):
tmp=[0]*n
for j in range(n):
if (i>>j)&1:
tmp[j]=1
for k in range(n):
if a[k]==0:
continue
for h in range(a[k]):
hito=x[k][h][0]-1
singi=x[k][h][1]
if tmp[k]==1:
if tmp[hito]!=singi:
break
else:
continue
break
else:
ans=max(ans,sum(tmp))
print(ans)
| N = int(input())
syougen = [ [] for _ in range(N) ]
for i in range(N):
num = int(input())
for j in range(num):
x, y = map(int, input().split())
syougen[i].append([x, y])
#print(syougen)
ans = 0
for bit in range(1 << N):
break_flag = 0
for i in range(N):
if (bit >> i) & 1:
for j in range(len(syougen[i])):
if ((bit>>(syougen[i][j][0]-1))&1) != syougen[i][j][1]:
break_flag = 1
break
if break_flag == 1:
break
if i == N-1:
ans = max(ans, bin(bit).count("1"))
print(ans) | 1 | 121,787,131,788,060 | null | 262 | 262 |
#!/usr/bin/env python3
import sys
from itertools import chain
from collections import Counter
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# import numpy as np
def solve(N: int, S: "List[str]"):
d = Counter(S)
for key in ("AC", "WA", "TLE", "RE"):
print(f"{key} x {d.get(key, 0)}")
def main():
tokens = chain(*(line.split() for line in sys.stdin))
# N, S = map(int, line.split())
N = int(next(tokens)) # type: int
S = [next(tokens) for _ in range(N)] # type: "List[str]"
solve(N, S)
if __name__ == "__main__":
main()
| l = int(input())
print(l * l * l / 27) | 0 | null | 27,715,571,541,920 | 109 | 191 |
while 1:
x, y =map(int,input().split())
if not x+y:break
if x>y:x,y=y,x
print(x,y)
| s=input()
for c in s:
if 'A' <= c and c <= 'Z':
print(c.lower(), end='')
elif 'a' <= c and c <= 'z':
print(c.upper(), end='')
else:
print(c,end='')
print()
| 0 | null | 1,012,604,481,984 | 43 | 61 |
S1 = []
S2= []
sum = 0
for i, s in enumerate(input()):
if s == "\\":
S1.append(i)
elif s == "/" and len(S1) > 0:
j = S1.pop()
sum += i - j
a = i - j
while len(S2) > 0 and S2[-1][0] > j:
a += S2.pop()[1]
S2.append((j, a))
print(sum)
sum2 = [str(len(S2))]
for s in S2:
sum2.append(str(s[1]))
print(" ".join(sum2))
| X, Y = map(int, input().split())
if Y % 2 == 0 and 2 * X <= Y <= 4 * X:
print("Yes")
else:
print("No")
| 0 | null | 6,973,985,306,760 | 21 | 127 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
H, W = list(map(int, input().split()))
S = []
for i in range(H):
S.append(input())
def bfs(u):
stack = deque([u])
visited = set()
seen = set()
p = [[INF for j in range(W)] for i in range(H)]
p[u[0]][u[1]] = 0
for i in range(H):
for j in range(W):
if S[i][j] == "#":
p[i][j] = -1
while len(stack) > 0:
v = stack.popleft()
###
visited.add(v)
###
a = (v[0] + 1, v[1])
b = (v[0] , v[1] + 1)
c = (v[0] - 1, v[1])
d = (v[0] , v[1] - 1)
e = [a, b, c, d]
for ee in e:
if ee[0] >= 0 and ee[0] <= H-1 and ee[1] >= 0 and ee[1] <= W-1:
if S[ee[0]][ee[1]] == ".":
if ee not in visited:
p[ee[0]][ee[1]] = min(p[ee[0]][ee[1]], p[v[0]][v[1]] + 1)
if ee not in seen:
stack.append(ee)
seen.add(ee)
ans = 0
for i in range(H):
ans = max(ans, max(p[i]))
return ans
sol = 0
for i in range(H):
for j in range(W):
if S[i][j] == ".":
sol = max(sol, bfs((i,j)))
print(sol) | from sys import stdin
S = stdin.readline().rstrip()
print(S[:3]) | 0 | null | 54,709,266,112,280 | 241 | 130 |
#! /usr/bin/python3
m=100
for _ in range(int(input())):
m = int(m*1.05+0.999)
print(m*1000) | import math
n = input()
a = 100000
for val in range(1,n+1):
a *= 1.05
A = math.ceil(a/1000) * 1000
a = A
print int(a) | 1 | 1,186,543,680 | null | 6 | 6 |
w = input()
cnt = 0
while(True):
t = input()
if t == "END_OF_TEXT":
break
t = t.lower()
tlist = t.split()
for i in tlist:
if i == w:
cnt += 1
print(cnt)
| import math
def merge(a,l,m,r):
global cnt
L = a[l:m]+[math.inf]
R = a[m:r]+[math.inf]
i = 0
j = 0
for k in range(l,r):
cnt+=1
if L[i]<=R[j]:
a[k] = L[i]
i+=1
else:
a[k]=R[j]
j+=1
def mergeSort(a,l,r):
if l+1<r:
m = (l+r)//2
mergeSort(a,l,m)
mergeSort(a,m,r)
merge(a,l,m,r)
n = int(input())
a = list(map(int, input().split()))
cnt = 0
mergeSort(a,0,n)
print(*a)
print(cnt)
| 0 | null | 989,021,187,662 | 65 | 26 |
a=input()
a=int(a)
b=a/1000
import math
c=math.ceil(b)
c=c*1000
print(c-a) | n = input()
card = []
for i in range(n):
card.append(raw_input())
for a in ['S','H','C','D']:
for b in range(1,14):
check = a + " " + str(b)
for c in card:
if check == c:
flg = 0
break
else:
flg = 1
if flg == 1:
print check | 0 | null | 4,810,584,802,210 | 108 | 54 |
r,c,k = list(map(int, input().split()))
import copy
dp=[[[0]*4 for _ in range(c)] for _ in range(2)]
F = [[0]*c for _ in range(r)]
for _ in range(k):
x,y,v = list(map(int, input().split()))
x-=1
y-=1
F[x][y] = v
for nn in range(r):
for j in range(c):
i = 1
val = F[nn][j]
mxv = max(dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3])
dp[i][j][3] = max(dp[i][j-1][3], dp[i][j-1][2] + val)
dp[i][j][2] = max(dp[i][j-1][2], dp[i][j-1][1] + val)
dp[i][j][1] = max(dp[i][j-1][1], dp[i][j-1][0] + val, mxv + val)
dp[i][j][0] = mxv
dp[0] = dp[1]
dp[1] = [[0]*4 for _ in range(c)]
best = 0
for k in range(4):
best = max(best, dp[0][c-1][k])
print(best)
| R,C,K=map(int,input().split())
Value=[[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
r,c,v=map(int,input().split())
Value[r][c]=v
DP=[[0,0,0,0] for _ in range(C+1) ]
for y in range(1,R+1):
#下に移動
for x in range(1,C+1):
DP[x][0]=max(DP[x])
DP[x][1]=DP[x][0]+Value[y][x]
DP[x][2]=DP[x][3]=0
#右に移動
for x in range(1,C+1):
for k in range(0,3+1):
DP[x][k]=max(DP[x][k],DP[x-1][k])
for k in range(1,3+1):
DP[x][k]=max(DP[x][k],DP[x-1][k-1]+Value[y][x])
print(max(DP[-1])) | 1 | 5,643,504,168,094 | null | 94 | 94 |
t = raw_input()
s = t.split()
if s[0] == s[1]:
print "a == b"
else:
if int(s[0]) > int(s[1]):
print "a > b"
else:
print "a < b" | a,b = raw_input().split(" ")
a = int(a)
b = int(b)
if a < b:
print "a < b"
elif a > b:
print "a > b"
else:
print "a == b" | 1 | 355,224,648,548 | null | 38 | 38 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n=int(input())
mod=10**9+7
MAX_N = n+5
fac = [1,1] + [0]*MAX_N
finv = [1,1] + [0]*MAX_N
inv = [0,1] + [0]*MAX_N
for i in range(2, MAX_N):
fac[i] = fac[i-1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
finv[i] = finv[i-1] * inv[i] % mod
def nCk(n,k):
if n<k:
return 0
if n<0 or k<0:
return 0
return fac[n] * (finv[k] * finv[n-k] % mod) % mod
ans=0
lim=n//3
for i in range(1,lim+1):
q=n-3*i
ans+=nCk(q+i-1,i-1)
ans%=mod
print(ans) | import sys
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
def main():
N = int(input())
A = list(map(int, input().split()))
RGB = [1, 0, 0]
ans = 1
if A[0] !=0:
print(0)
return
for i in range(1, N):
a = A[i]
if a == 0:
if 0 in RGB:
j = RGB.index(a)
RGB[j] += 1
else:
print(0)
return
elif a not in RGB:
print(0)
return
else:
k = RGB.count(a)
ans *= k
ans %= MOD
j = RGB.index(a)
RGB[j] += 1
z = RGB.count(0)
if z == 0:
ans *= 6
ans %= MOD
elif z == 1:
ans *= 6
ans %= MOD
else:
ans *= 3
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 66,784,184,893,536 | 79 | 268 |
import sys
l = []
for i in sys.stdin:
l.append(i.split())
for i in range(0,len(l)):
for j in range(0,len(l[i])):
l[i][j] = int(l[i][j])
for i in range(1,len(l)):
l[i].append(sum(l[i]))
result = []
for i in range(0,l[0][1]+1):
count = 0
for j in range(1,l[0][0]+1):
count += l[j][i]
result.append(count)
l.append(result)
for i in range(1,len(l)):
for j in range(0,len(l[i])):
print(l[i][j],end='')
if j < len(l[i]) - 1:
print(" ",end='')
print()
| raws, columns = map(int, input().strip().split())
a = []
for i in range(raws):
a.append(list(map(int, input().strip().split())))
for i in range(raws):
a[i].append(sum(a[i]))
a.append([sum(i) for i in zip(*a)])
for r in a:
print(' '.join(str(x) for x in r)) | 1 | 1,379,071,492,798 | null | 59 | 59 |
n, k = map(int, input().split())
H = list(map(int, input().split()))
L = [h for h in H if h >= k]
print(len(L)) | n,k=map(int,input().split())
h=list(map(int,input().split()))
h.append(k)
print(len(h[sorted(h).index(k)+1:])) | 1 | 178,503,793,432,182 | null | 298 | 298 |
def d_semi_common_multiple():
from fractions import gcd
from functools import reduce
N, M = [int(i) for i in input().split()]
A = [int(i) // 2 for i in input().split()] # 先に2で割っておく
def count_divide_2(n):
"""n に含まれる因数 2 の指数"""
return (n & -n).bit_length()
def lcm(a, b):
return a * b // gcd(a, b)
# A の全要素について,2で割れる回数は等しいか?
tmp = count_divide_2(A[0])
for a in A:
if count_divide_2(a) != tmp:
return 0
t = reduce(lambda x, y: lcm(x, y), A)
return (M // t) - (M // (2 * t))
print(d_semi_common_multiple()) | # https://atcoder.jp/contests/abc159/tasks/abc159_e
import sys
ans = sys.maxsize
H, W, K = map(int, input().split())
s = [input() for _ in range(H)]
for h in range(1 << (H - 1)):
g = 0
ids = [-1 for _ in range(H)]
for i in range(H):
ids[i] = g
if (h >> i) & 1:
g += 1
g += 1
num = g - 1
if num >= ans:
continue
c = [[0] * W for _ in range(g)]
for i in range(H):
for j in range(W):
c[ids[i]][j] = c[ids[i]][j] + (s[i][j] == '1')
now = [0 for _ in range(g)]
def add(j):
for i in range(g):
now[i] += c[i][j]
for i in range(g):
if now[i] > K:
return False
return True
for j in range(W):
if not add(j):
num += 1
if num >= ans:
continue
now = [0 for _ in range(g)]
if not add(j):
num = sys.maxsize
break
ans = min(ans, num)
print(ans)
| 0 | null | 75,366,327,742,970 | 247 | 193 |
def sample(n):
return n * n * n
n = input()
x = sample(n)
print x | # coding: utf-8
a = input()
print(int(a)*int(a)*int(a)) | 1 | 285,619,776,412 | null | 35 | 35 |
import sys
input = sys.stdin.readline
n, t = map(int, input().split())
DISHES = [(0, 0)]
for _ in range(n):
a, b = map(int, input().split())
DISHES.append((a, b))
DISHES.sort()
DP = [[0] * (t + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
a, b = DISHES[i]
for j in range(1, t + 1):
if j - a < 0:
DP[i][j] = DP[i - 1][j]
else:
DP[i][j] = max(DP[i - 1][j], DP[i - 1][j - a] + b)
answer = 0
for k in range(1, n + 1):
answer = max(answer, DP[k - 1][t - 1] + DISHES[k][1])
print(answer)
| N, K = map(int, input().split())
SC = list(map(int, input().split()))
T = input()
Q = []
for i in range(len(T)):
if T[i] == "r":
Q.append(0)
elif T[i] == "s":
Q.append(1)
else:
Q.append(2)
my = [0 for i in range(N)]
ans = 0
for i in range(N):
if i < K:
my[i] = (Q[i] - 1) % 3
ans += SC[my[i]]
else:
n = (Q[i] - 1) % 3
if my[i - K] != n:
my[i] = n
ans += SC[my[i]]
else:
if i + K < N:
my[i] = Q[i+K]
print(ans) | 0 | null | 129,582,540,396,080 | 282 | 251 |
A, B, C, K = map(int, input().split())
ret = 0
for numberOfCards, point in [(A, 1), (B, 0), (C, -1)]:
if K >= numberOfCards:
K -= numberOfCards
ret += numberOfCards * point
else:
ret += K * point
break
print(ret)
| from functools import reduce
import sys
N, M = map(int, input().split())
A = list(map(int, input().split()))
def lcm(a,b):
return int(a * b / gcd(a, b))
def gcd(a, b):
import fractions
return fractions.gcd(a, b)
def temp(a):
return int(a * 0.5)
max_a = max(A)
i = 0
while True:
num = int((i+0.5) * max_a)
if num > M:
print(0)
sys.exit()
found = True
for a in A:
if int(num - 0.5 * a) % a != 0:
found = False
break
if found:
ans = 1
break
i += 1
aa = reduce(lcm, A)
ans += (M - num) // aa
print(int(ans))
| 0 | null | 61,620,065,488,268 | 148 | 247 |
S, T = map(str, input().split())
print('{}{}'.format(T, S)) | st = input().split(' ')
print(st[1]+st[0]) | 1 | 103,394,315,091,090 | null | 248 | 248 |
import sys
readline = sys.stdin.readline
N = int(readline())
A = []
B = []
for _ in range(N):
a, b = map(int, readline().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
if N % 2 == 0:
mi = A[N//2-1]+A[N//2]
ma = B[N//2-1]+B[N//2]
else:
mi = A[N//2]
ma = B[N//2]
print(ma-mi+1)
| N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
max_a = max(A)
max_f = max(F)
left = 0
right = max_a * max_f
while left <= right:
x = (left + right) // 2
sum_ = 0
for i in range(N):
if A[i] * F[i] > x:
sum_ += (A[i] - int(x / F[i]))
if sum_ > K:
left = x + 1
if sum_ <= K:
right = x - 1
print(left)
| 0 | null | 91,527,278,478,190 | 137 | 290 |
m_one = list(map(int, input().split()))
m_two = list(map(int,input().split()))
print(1 if m_one[1] > m_two[1] else 0) | m1, d1 = input().split()
m2, d2 = input().split()
print('1' if m1 != m2 else '0')
| 1 | 124,292,432,022,580 | null | 264 | 264 |
def main2():
K = int(input())
rem = set()
n = ans = 0
while True:
n = n * 10 + 7
ans += 1
if n % K == 0:
print(ans)
break
else:
n = n % K
if n in rem:
print(-1)
break
else:
rem.add(n)
if __name__ == "__main__":
main2() | import sys
k = int(input())
ans = [0]*(k+1)
ans[0] = 7 % k
if ans[0] == 0:
print(1)
else:
for i in range(k):
ans[i+1] = (ans[i]*10 + 7) % k
if ans[i+1] == 0:
print(i+2)
sys.exit()
print(-1) | 1 | 6,086,563,321,800 | null | 97 | 97 |
import math
def hensa(n, S):
m = sum(S)/n
x = 0
for i in S:
x += (i - m) ** 2
hensa = math.sqrt(x / n)
return hensa
n = int(input())
while n != 0:
S = list(map(int, input().split()))
print("{0:04f}".format(hensa(n, S)))
n = int(input()) | def main():
n, k, s = map(int, input().split())
other = 0
if s == 10**9:
other = 10**9 - 1
else:
other = s + 1
if n > k:
ans = [s for _ in range(k)] + [other for _ in range(n-k)]
else:
ans = [s for _ in range(n)]
print(*ans)
if __name__ == "__main__":
main() | 0 | null | 45,786,852,840,380 | 31 | 238 |
a = input()
for i in range(int(input())):
b = list(input().split(' '))
if 'print' in b:
f = int(b[1])
s = int(b[2])
print(a[f:s+1])
elif 'reverse' in b:
f = int(b[1])
s = int(b[2])
a = a[:f] + a[f:s+1:][::-1] + a[s+1:]
else:
f = int(b[1])
s = int(b[2])
a = a[:f] + b[3] + a[s+1:]
| #coding: utf-8
#itp1_9d
def rev(s,a,b):
b=b+1
t=s[a:b]
u=t[::-1]
x=s[:a]
y=s[b:]
return x+u+y
def rep(s,a,b,w):
b=b+1
x=s[:a]
y=s[b:]
return x+w+y
s=raw_input()
n=int(raw_input())
for i in xrange(n):
d=raw_input().split()
a=int(d[1])
b=int(d[2])
if d[0]=="print":
print s[a:b+1]
elif d[0]=="reverse":
s=rev(s,a,b)
elif d[0]=="replace":
w=d[3]
s=rep(s,a,b,w) | 1 | 2,094,988,819,208 | null | 68 | 68 |
import random
S=input()
r = random.randint(0,len(S)-3)
result =""
result = S[r]+S[r+1]+S[r+2]
print(result)
| n,k,c = list(map(int,input().split()));s=[True if i=="o" else False for i in input()]
front=[0]*n;back=[0]*n;count=0
day = 0
while day < n:
if s[day]:
count += 1
front[day]= 1
day += c+1
else:
day += 1
s = s[::-1]
day = 0
while day < n:
if s[day]:
back[day]= 1
day += c+1
else:
day += 1
back = back[::-1]
if count ==k:
for i in range(n):
if front[i] ==1 and back[i] == 1:
print(i+1) | 0 | null | 27,823,939,868,256 | 130 | 182 |
def insertionSort( nums, n, g ):
cnt = 0
for i in range( g, n ):
v = nums[i]
j = i - g
while j >= 0 and nums[j] > v:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
return cnt
def shellSort( nums, n ):
g = []
v = 1
while v <= n:
g.append( v )
v = 3*v+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( input( ) )
nums = [ int( input( ) ) for i in range( n ) ]
nums.append( 0 )
shellSort( nums, n )
nums.pop( )
for v in nums:
print( v ) | import sys
N = str(input())
for i in N:
if i == '7':
print('Yes')
sys.exit()
print('No') | 0 | null | 17,224,241,885,380 | 17 | 172 |
x = int(input())
a, b = map(int, input().split())
ans=0
for i in range(a,b+1):
if i%x==0:
ans=1
break
if ans==1:
print('OK')
else:
print('NG') | n = int(input())
lim_min, lim_max = map(int, input().split())
if lim_min % n == 0 :
print('OK')
elif lim_min + n - (lim_min % n) <= lim_max:
print('OK')
else:
print('NG')
| 1 | 26,560,161,081,860 | null | 158 | 158 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N, K = getNM()
P = [i - 1 for i in getList()]
C = getList()
ignore = [-1] * N
ans = -float('inf')
for i in range(N):
if ignore[i] >= 0:
continue
### ループ生成 ###
ignore[i] = 1
opt_l = [i]
to = P[i]
while ignore[to] == -1:
opt_l.append(to)
ignore[to] = 1
to = P[to]
###
### 作成したループで得点リスト生成 ###
n = len(opt_l)
point = [0] * n
for i in range(n):
point[i] = C[opt_l[i]]
###
### 得点リスト内の連続する区間の総和のうちの最大値を累積和を使って求める ###
sum_roop = sum(point)
# ループの累積和作成
imos = [0]
point += point
for i in range(len(point)):
imos.append(imos[i] + point[i])
#
ran = min(n, K)
for i in range(n):
# 区間の大きさran以下についての総和を求める
for j in range(1, ran + 1):
if sum_roop >= 0:
opt = imos[i + j] - imos[i] + ((K - j) // n) * sum_roop
else:
opt = imos[i + j] - imos[i]
ans = max(ans, opt)
###
print(ans) | def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
X,Y = list(map(int,input().split()))
if (X+Y)%3 != 0:
print(0)
exit()
N = (X+Y)//3
K = min(2*N-X,X-N)
print(cmb(N,K,mod)) | 0 | null | 77,454,698,924,950 | 93 | 281 |
# -*- coding: utf-8 -*-
def main():
S, W = map(int, input().split())
if S <= W:
ans = 'unsafe'
else:
ans = 'safe'
print(ans)
if __name__ == "__main__":
main() | n=int(input())
s=input()
A=[]
for i in range(n):
A.append(s[i])
W=0
R=A.count('R')
ans=float('inf')
for i in range(n+1):
if i!=0:
if A[i-1]=='W':
W+=1
else:
R-=1
ans=min(max(W,R),ans)
print(ans) | 0 | null | 17,816,619,884,898 | 163 | 98 |
x,y,z= map(str, input().split())
print(z,x,y, sep=' ') | def main() :
N = int(input())
A = list(map(int, input().split()))
sum = 0
t = A[0]
for i in range(1, N):
if A[i] <= t:
sum += t - A[i]
else:
t = A[i]
print(sum)
if __name__ == "__main__":
main() | 0 | null | 21,222,895,360,942 | 178 | 88 |
X,N = map(int,input().split())
p = list(map(int,input().split()))
count = -1
while True:
count +=1
if X-count not in p:
print(X-count)
break
elif X+count not in p:
print(X+count)
break | a,b=input().split()
if a*int(b)>=b*int(a):
print(b*int(a))
else:
print(a*int(b)) | 0 | null | 49,359,941,630,440 | 128 | 232 |
import sys
def gcd(x, y):
if x % y != 0:
return gcd(y, x % y)
return y
for i in sys.stdin:
x, y = map(int, i.split())
g = gcd(x,y)
print(g, int(x*y/g)) | a, b, c, d = map(int, input().split())
x = 0
y = 0
while c > 0:
c -= b
x += 1
while a > 0:
a -= d
y += 1
if x <= y:
print('Yes')
else:
print('No')
| 0 | null | 14,938,154,429,238 | 5 | 164 |
import itertools
N, M, Q = map(int, input().split())
A = [list(map(int, input().split())) for i in range(Q)]
a_list = []
ans = 0
for i in itertools.combinations_with_replacement(range(1,M+1),N):
ans2 = 0
for t in A:
if i[t[1]-1] - i[t[0]-1] == t[2]:
ans2 += t[3]
ans = max(ans,ans2)
print(ans)
| N, M, Q = map(int, input().split())
A = []
for i in range(Q):
A.append(list(map(int, input().split())))
def calc(B, n):
ans = 0
#not enough length
if len(B) < N:
for i in range(n, M + 1):
ans = max(ans, calc(B + [i], i))
#enough length
else:
#print("B:", B)
for j in range(Q):
if B[A[j][1]-1] - B[A[j][0]-1] == A[j][2]:
ans += A[j][3]
#print("ans:", ans)
return ans
print(calc([], 1))
| 1 | 27,536,023,663,490 | null | 160 | 160 |
x = input().split()
a = int(x[0])
b = int(x[1])
c = int(x[2])
count = 0
# a =< b
for i in range(a,b+1):
if c % i == 0:
count += 1
print(count)
| x = raw_input().split()
a = x[0]
b = x[1]
c = x[2]
A = 0
for i in range(int(a),int(b)+1):
if int(c) % int(i) ==0:
A += 1
elif int(c) % int(i) != 0:
A += 0
print A | 1 | 567,862,212,280 | null | 44 | 44 |
n, m, l = map(int, input().split())
a = [input().split()for _ in range(n)]
b = [input().split()for _ in range(m)]
c = [[0]*l for _ in range(n)]
for i in range(n):
for j in range(l):
for k in range(m):
c[i][j] += int(a[i][k])*int(b[k][j])
for i in range(n):
print(*c[i])
| from collections import Counter
def prime_factorization(n):
A = []
while n % 2 == 0:
n //= 2
A.append(2)
i = 3
while i * i <= n:
if n % i == 0:
n //= i
A.append(i)
else:
i += 2
if n != 1:
A.append(n)
return A
n = int(input())
A = list(Counter(prime_factorization(n)).values())
ans = 0
e = 1
while True:
cnt = 0
for i in range(len(A)):
if A[i] >= e:
A[i] -= e
cnt += 1
if cnt == 0:
break
ans += cnt
e += 1
print(ans)
| 0 | null | 9,102,536,648,978 | 60 | 136 |
import sys
import bisect
input = sys.stdin.readline
n, d, a = map(int, input().split())
xh = sorted([tuple(map(int, input().split()))for _ in range(n)])
x_list = [x for x, h in xh]
damage = [0]*(n+1)
ans = 0
for i in range(n):
x, h = xh[i]
h -= damage[i]
if h <= 0:
damage[i+1] += damage[i]
continue
cnt = -(-h//a)
ans += cnt
damage[i] += cnt*a
end_idx = bisect.bisect_right(x_list, x+2*d)
damage[end_idx] -= cnt*a
damage[i+1] += damage[i]
print(ans) | from math import *
from collections import *
N, D, A = list(map(int, input().split()))
ans = 0
t = 0
q = deque()
XH = sorted([list(map(int, input().split())) for i in range(N)])
for x, h in XH:
if q:
while q and q[0][0] < (x-D):
_, c = q.popleft()
t -= c
h = h - t * A
if h <= 0: continue
x += D
c = ceil(h/A)
t += c
ans += c
q.append((x, c))
print(ans) | 1 | 81,749,356,742,662 | null | 230 | 230 |
while True:
x,y = [int(i) for i in input().split()]
if x == 0 and y == 0:
break
if x>y:
print(str(y) + " " + str(x))
else:
print(str(x) + " " + str(y))
| N = list(input())
if '7' in N:
print('Yes')
else:
print('No') | 0 | null | 17,491,417,889,920 | 43 | 172 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
x = []
for _ in range(N):
X, L = MAP()
x.append([X-L, X+L])
x.sort(key = lambda x: x[1])
ans = 0
tmp = -INF
for l, r in x:
if tmp <= l:
tmp = r
ans += 1
print(ans) | N = int(input())
XL = [list(map(int, input().split())) for x in range(N)]
XL = sorted(XL, key=lambda x: x[0]+x[1])
cnt = 0
prev_right = -10**9+10
for x, l in XL:
left = x - l
right = x + l
if left >= prev_right:
cnt += 1
prev_right = right
print(cnt)
| 1 | 89,924,620,648,230 | null | 237 | 237 |
s=input()
lis=list(s)
n=len(lis)
X=["x" for i in range(n)]
print("".join(X)) | s = len(input())
print("x" * s)
| 1 | 72,941,030,043,350 | null | 221 | 221 |
n=input()
for i in range(n):
l=map(int,raw_input().split())
l.sort()
if l[0]**2+l[1]**2==l[2]**2:print"YES"
else:print"NO" | r, c = map(int, input().split())
x = []
for _ in range(r):
x.append(list(map(int, input().split())))
c_line_sum = []
for i in range(c): # 列の総和の計算
t = []
for j in range(r):
t.append(x[j][i])
c_line_sum.append(sum(t))
for i in range(r): # 行の総和の計算
x[i].append(sum(x[i]))
c_line_sum.append(sum(c_line_sum))
x.append(c_line_sum)
for m in x:
print(*m)
| 0 | null | 690,731,043,520 | 4 | 59 |
import math
R = int(input())
p = math.pi
print(2 * p * R) | r = int(input())
pi = 3.14159265359
print(r*2*pi) | 1 | 31,447,312,263,730 | null | 167 | 167 |
a,b,c=map(int,input().split())
if (b*c >= a):
print('Yes')
else:
print('No') | def dontbelate(D,T,S):
if T < D//S:
return 'No'
elif T > D//S:
return 'Yes'
else:
if D%S == 0:
return 'Yes'
else:
return 'No'
if __name__ == "__main__":
D,T,S = map(int, input().split())
print(dontbelate(D,T,S)) | 1 | 3,529,201,247,976 | null | 81 | 81 |
a = [int(v) for v in input().rstrip().split()]
r = 'bust' if sum(a) >= 22 else 'win'
print(r)
| #!/usr/bin/env python3
print("bwuisnt"[eval(input().replace(" ", "+")) < 22::2])
| 1 | 119,054,012,947,532 | null | 260 | 260 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.