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
|
---|---|---|---|---|---|---|
x = int(input())
rl = 400
for i in range(8, 0, -1):
if (rl <= x) and (x <= rl+199):
print(i)
rl += 200 | N,K= map(int,input().split())
p = list(map(int,input().split()))
sum1=0.0
for i in range (K):
sum1=((p[i]+1)/2.0)+sum1
sum2=sum1
for i in range(N-K):
sum1=sum1+((p[i+K]-p[i])/2.0)
if sum1>sum2:
sum2=sum1
print(sum2) | 0 | null | 40,909,271,154,688 | 100 | 223 |
A, B, C = map(int, input().split())
print(C, A, B) | y=100000
n = int(input())
for i in range(n):
y=y*1.05
if y%1000==0:
pass
else:
y=y//1000
y=y+1
y=y*1000
print(f"{y:.0f}")
| 0 | null | 19,103,298,817,802 | 178 | 6 |
S=input()
h=S/3600
r=S%3600/60
s=S-h*3600-r*60
print str(h)+':'+str(r)+':'+str(s) | S = raw_input()
S = int(S)
h = S / 3600
m = (S - h * 3600) / 60
s = S - 3600 * h - 60 * m
print u"%d:%d:%d" % (h,m,s) | 1 | 340,988,544,010 | null | 37 | 37 |
x1,x2,x3,x4,x5 = map(int,input().split())
P=[x1,x2,x3,x4,x5]
for i in range(5):
if P[i]==0:
print(str(i+1))
else:
continue | n, d = map(int, input().split(" "))
p = []
ans = 0
for i in range(n):
p.append(list(map(int, input().split(" "))))
for i, [x, y] in enumerate(p):
if(x > d or y > d):
continue
if(x**2 + y**2 <= d**2):
ans += 1
print(ans) | 0 | null | 9,683,464,139,690 | 126 | 96 |
import sys
s = sys.stdin.read()
for c in [chr(i) for i in range(97,97+26)]:
print(c, ":", s.lower().count(c)) | n = int(input())
s = input()
if n % 2 == 1:
print('No')
exit()
mid= int(len(s)/2)
if s[:mid] == s[mid:]:
print('Yes')
else:
print('No')
| 0 | null | 74,170,702,368,540 | 63 | 279 |
L = int(input())
l3 = L/3
print(pow(l3,3)) | N, K = list(map(int, input().split()))
pt = list(map(int, input().split()))
T = input()
pc_hand = [0]*N
my_hand = [0]*N
for i in range(N):
if T[i] == 'r':
pc_hand[i] = 0
elif T[i] == 's':
pc_hand[i] = 1
else:
pc_hand[i] = 2
point = 0
for i in range(N):
if i >= K and T[i] == T[i - K] and (my_hand[i - K] + 1) % 3 == pc_hand[i - K]:
my_hand[i] = pc_hand[i]
else:
my_hand[i] = (pc_hand[i] - 1) % 3
point += pt[my_hand[i]]
print(point) | 0 | null | 77,072,778,688,160 | 191 | 251 |
n = input()
array = []
i = 1
while i <= n:
x = i
if x % 3 == 0:
array.append(i)
else:
while x != 0:
if x % 10 == 3:
array.append(i)
break
x /= 10
i += 1
print str(array).replace('[', ' ').replace(']', '').replace(',', '') | n = int(input())
for i in range(1, n + 1):
if i % 3 == 0 or str(i).find("3") != -1:
print(" {}".format(i), end = '')
print()
| 1 | 920,273,423,440 | null | 52 | 52 |
n=int(input())
s=input()
tmp=s[0]
ans=1
for i in range(1,n):
if s[i]!=tmp:
tmp=s[i]
ans+=1
print(ans) | import sys
readline = sys.stdin.readline
N = int(readline())
S = readline().rstrip()
ans = 1
for i in range(1,len(S)):
if S[i] != S[i - 1]:
ans += 1
print(ans) | 1 | 169,428,837,500,582 | null | 293 | 293 |
n, k = map(int, input().split())
print(sum([i >= k for i in list(map(int,input().split()))])) | import math
n, m = map(int, input().split(" "))
start = 1
end = n
wq = n // 4
for i in range(m):
if i == wq and n % 2 == 0:
start += 1
print(start, end)
start += 1
end -= 1 | 0 | null | 103,754,298,137,600 | 298 | 162 |
a,b=map(int,input().split())
if (a>=10) or (b>=10):
print(-1)
exit()
else:
print(a*b) | a, b = map(str, input().split())
if (len(a) == 1 and len(b) ==1):
print(int(a) * int(b))
else:
print(-1) | 1 | 157,769,396,562,850 | null | 286 | 286 |
(a, b) = tuple([int(i) for i in input().split(' ')])
d = int(a / b)
r = a % b
f = a / b
print('{0} {1} {2:.8f}'.format(d, r, f)) | a=list(map(int,input().split()))
string=str(a[0]//a[1])+" "+str(a[0]%a[1])+" "+str("%.10f"%(a[0]/a[1]))
print(string) | 1 | 596,240,086,640 | null | 45 | 45 |
N = int(input())
A = [int(d) for d in input().split()]
MOD = int(1e9+7)
A_cum = [0]
for i in range(N):
A_cum.append((A_cum[-1] + A[i]) % MOD)
ans = 0
for i in range(N-1):
t = (A[i] * (A_cum[-1] - A_cum[i+1]) % MOD ) % MOD
ans = (t + ans)% MOD
print(ans) | N = int(input())
A = list(map(int, input().split(' ')))
const = 1000000007
ans = 0
total = sum(A)
for i in range(N):
total -= A[i]
ans += A[i] * total
print(ans%const) | 1 | 3,816,484,612,788 | null | 83 | 83 |
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
n, m = map(int, input().split())
if n % 2 == 0:
n -= 1
ans = []
left_range = n//2
right_range = n//2 - 1
left1 = 1
right1 = 1 + left_range
left2 = right1 + 1
right2 = left2 + right_range
while True:
if left1 >= right1:
break
ans.append([left1, right1])
left1 += 1
right1 -= 1
while True:
if left2 >= right2:
break
ans.append([left2, right2])
left2 += 1
right2 -= 1
for i in range(m):
print(*ans[i])
| N = int(input())
S = input()
uns = 0
for d in range(1, (N - 1) // 2 + 1):
for i in range(N - 2 * d):
s, t, u = S[i], S[i + d], S[i + 2 * d]
if s != t and t != u and u != s:
uns += 1
r = S.count('R')
g = S.count('G')
b = N - r - g # = S.count('B')
ans = r * g * b - uns
print(ans) | 0 | null | 32,420,568,989,212 | 162 | 175 |
n = int(input())
num = int(n / 2)
if n % 2 == 1:
num += 1
print(num) | n = int(input())
print(n//2+1 if n%2!=0 else n//2) | 1 | 59,007,860,426,400 | null | 206 | 206 |
n, m = map(int, input().split())
s = input()
s = s[::-1]
loc = 0
anslist=[]
while True:
if loc >= n-m:
anslist.append(n-loc)
break
quit()
next = m
while s[loc+next]=="1":
next-=1
if next == 0:
print(-1)
quit()
anslist.append(next)
loc+=next
ans=anslist[::-1]
ans = list(map(str, ans))
print(" ".join(ans)) | n = int(input())
lis = list(map(int, input().split()))
t = lis[0]
for i in range(1, n):
t ^= lis[i]
ans = [0] * n
for i , j in enumerate(lis):
ans[i] = t ^ j
print(*ans) | 0 | null | 75,846,804,305,528 | 274 | 123 |
n,k,c=map(int,input().split())
s=input()
def greedy_work(days,rest,plan):
day_count=0
go=[0]*n
while day_count < days:
if plan[day_count]=='o':
go[day_count]=1
day_count += rest+1
else:
day_count += 1
return(go)
front = greedy_work(n,c,s)
back = greedy_work(n,c,s[::-1])
back = back[::-1]
if front.count(1)==k:
for i in range(n):
if front[i]==1 and back[i]==1:
print(i+1) | H, W = map(int, input().split())
if H > 1 and W > 1:
if H*W % 2 == 0:
s = (H * W) // 2
elif H*W % 2 != 0:
s = (H * W + 1) // 2
elif H == 1 or W == 1:
s = 1
print(s) | 0 | null | 45,960,645,476,928 | 182 | 196 |
import sys
for line in sys.stdin:
n = [int(i) for i in line.replace("\n", "").split(" ")]
n.sort()
low = n[0]
hi = n[1]
while hi % low:
hi, low = low, hi % low
print("%d %d" % (low, n[0] / low * n[1])) | from collections import deque
n = int(input())
edges=[[]for i in range(n)]
nodes=[None]*n
for i in range(1,n):
a , b = map(int, input().split())
edges[a-1].append(i)
edges[b-1].append(i)
nodes[i]=(a-1,b-1)
ma =0
for i in range(n):
ma=max(ma,len(edges[i]))
col=[None]*n
d = deque([(0,0)])
while d:
t=1
v , ex_col = d.pop()
for i in edges[v]:
if col[i] is None:
if t==ex_col:
t+=1
col[i]=t
a1,b1=nodes[i]
if a1==v:
d.append((b1,t))
else:
d.append((a1,t))
t+=1
print(ma)
for i in range(1,n):
print(col[i])
| 0 | null | 68,207,639,686,340 | 5 | 272 |
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, combinations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from operator import itemgetter
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7
DEBUG = 'ONLINE_JUDGE' not in sys.argv
def meg(f, ok, ng):
while abs(ok-ng)>1:
mid = (ok+ng)//2
if f(mid):
ok=mid
else:
ng=mid
return ok
def get_inv(n, modp):
return pow(n, modp-2, modp)
def factorials_list(n, modp): # 10**6
fs = [1]
for i in range(1, n+1):
fs.append(fs[-1] * i % modp)
return fs
def invs_list(n, fs, modp): # 10**6
invs = [get_inv(fs[-1], modp)]
for i in range(n, 1-1, -1):
invs.append(invs[-1] * i % modp)
invs.reverse()
return invs
def comb(n, k, modp):
num = 1
for i in range(n, n-k, -1):
num = num * i % modp
den = 1
for i in range(2, k+1):
den = den * i % modp
return num * get_inv(den, modp) % modp
def comb_from_list(n, k, modp, fs, invs):
return fs[n] * invs[n-k] * invs[k] % modp
#
class UnionFindEx:
def __init__(self, size):
#正なら根の番号、負ならグループサイズ
self.roots = [-1] * size
def getRootID(self, i):
r = self.roots[i]
if r < 0: #負なら根
return i
else:
r = self.getRootID(r)
self.roots[i] = r
return r
def getGroupSize(self, i):
return -self.roots[self.getRootID(i)]
def connect(self, i, j):
r1, r2 = self.getRootID(i), self.getRootID(j)
if r1 == r2:
return False
if self.getGroupSize(r1) < self.getGroupSize(r2):
r1, r2 = r2, r1
self.roots[r1] += self.roots[r2] #サイズ更新
self.roots[r2] = r1
return True
Yes = 'Yes'
No = 'No'
def dprint(*args, **kwargs):
if DEBUG:
print(*args, **kwargs)
def main():
N, K = mis()
P = list(map(lambda x: x-1, mis()))
C = lmis()
ans = -INF
for i in range(N):
p = i
tmp_score = 0
k = K
cycle = 0
while k:
p = P[p]
tmp_score += C[p]
ans = max(ans, tmp_score)
k -= 1
cycle += 1
if p==i:
if tmp_score < 0:
break
elif k > cycle*2:
skip_loop = (k - cycle)//cycle
tmp_score *= skip_loop + 1
k -= skip_loop * cycle
ans = max(ans, tmp_score)
print(ans)
main()
| n = int(input()) % 10
if n == 3:
print('bon')
elif n == 0 or n == 1 or n == 6 or n == 8:
print('pon')
else:
print('hon') | 0 | null | 12,217,013,946,208 | 93 | 142 |
while True:
m,f,r = map(int,input().split())
score = ""
if(m == -1 and f == -1 and r == -1): break
if(m == -1 or f == -1): score = "F"
elif(m+f >= 80): score = "A"
elif(m+f >= 65): score = "B"
elif(m+f >= 50): score = "C"
elif(m+f >= 30):
if(r >= 50): score = "C"
else: score = "D"
else:
score = "F"
print(score)
| while(True):
m, f, r = map(int, input().split(" "))
if (m == -1) and (f == -1) and (r == -1):
exit()
if (m == -1) or (f == -1):
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")
else:
print("F") | 1 | 1,229,093,310,550 | null | 57 | 57 |
N = int(input())
A = list(map(int, input().split()))
dic = {i:0 for i in range(1, N + 1)}
for i in range(N):
a = A[i]
dic[a] = i + 1
for i in range(1, N + 1):
print(dic[i], end="")
if i != N:
print(" ", end="")
print() | N = int(input())
S = list(map(int,input().split()))
m = [0 for _ in range(N)]
for i in range(N):
m[S[i]-1] = i+1
print(*m,sep=" ")
| 1 | 180,856,560,177,020 | null | 299 | 299 |
a, b = map(int, raw_input().split())
print "%d %d %.6f"%(a/b, a%b, a*1.0/b) | a, b = map(int, input().split())
print(a // b, a % b, round(a / b, 6)) | 1 | 583,528,915,270 | null | 45 | 45 |
# F - Playing Tag on Tree
# https://atcoder.jp/contests/abc148/tasks/abc148_f
from heapq import heappop, heappush
INF = float("inf")
def dijkstra(n, G, s):
dist = [INF] * n
dist[s] = 0
hq = [(0, s)]
while hq:
d, v = heappop(hq)
if dist[v] < d:
continue
for child, child_d in G[v]:
if dist[child] > dist[v] + child_d:
dist[child] = dist[v] + child_d
heappush(hq, (dist[child], child))
return dist
n, u, v = map(int, input().split())
graph = [[] for _ in range(n)]
edge = [list(map(int, input().split())) for _ in range(n - 1)]
for a, b in edge:
graph[a - 1].append((b - 1, 1))
graph[b - 1].append((a - 1, 1))
from_u = dijkstra(n, graph, u - 1)
from_v = dijkstra(n, graph, v - 1)
# print(from_u)
# print(from_v)
fil = filter(lambda x : x[0] < x[1], [[fu, fv] for fu, fv in zip(from_u, from_v)])
sfil = sorted(list(fil), key=lambda x: [-x[1], -x[0]])
# print(sfil)
print(sfil[0][1] - 1)
| import copy
from collections import deque
n, st, sa = map(int,input().split())
st -= 1
sa -= 1
e = [[] for i in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
a -= 1
b -= 1
e[a].append(b)
e[b].append(a)
visited = [False] * n
visited[st] = True
d = deque()
d.append([st, 0])
tx = {}
if len(e[st]) == 1:
tx[st] = 0
cnt = 0
while d:
f, cnt = d.popleft()
flg = True
for t in e[f]:
if not visited[t]:
flg = False
d.append([t, cnt+1])
visited[t] = True
if flg:
tx[f] = cnt
visited = [False] * n
visited[sa] = True
d = deque()
d.append([sa, 0])
ax = {}
if len(e[sa]) == 1:
ax[sa] = 0
cnt = 0
while d:
f, cnt = d.popleft()
flg = True
for t in e[f]:
if not visited[t]:
flg = False
d.append([t, cnt+1])
visited[t] = True
if flg:
ax[f] = cnt
ax = sorted(ax.items(), key=lambda x:x[1], reverse=True)
for i in range(len(ax)):
x, d = ax[i][0], ax[i][1]
if d > tx[x]:
ans = d - 1
break
print(ans) | 1 | 117,043,584,049,392 | null | 259 | 259 |
# -*- coding: utf-8 -*-
line = map(str, raw_input())
place = 0
area = 0
stack1 = []
stack2 = []
for i in line:
if i == '\\':
stack1.append(place)
elif i == '/':
if len(stack1) != 0:
j = stack1.pop()
s = place-j
area += s
while len(stack2) != 0:
if stack2[-1][0] <= j:
break
tmp = stack2.pop()
s += tmp[1]
stack2.append([j, s])
place += 1
print area
temp = []
for a in stack2:
temp.append(a[1])
if len(stack2) > 0:
print len(stack2),
print " ".join(map(str, temp))
else:
print len(stack2) | # A - Connection and Disconnection
S = input()
K = int(input())
S = S + '1'# 番兵
# 連続する文字数をカウント
cnt = []
conti = 1
for i in range(1,len(S)):
if S[i-1] == S[i]:
conti += 1
else:
cnt.append(conti)
conti = 1
# 最初と最後の文字が同じときの補正値
comp = 0
if S[0] == S[-2]:
# 奇数個 + 奇数個のとき
if cnt[0]%2 == 1 and cnt[-1]%2 == 1:
comp = K - 1
# S =aaa などのとき
if len(set(S[:-1])) == 1 and len(S[:-1])%2 == 1:
comp = K // 2
ans = [a//2 for a in cnt if a >= 2]
ans = sum(ans)*K + comp
print(ans) | 0 | null | 87,828,066,199,192 | 21 | 296 |
MOD = 998244353
N, K = list(map(int, input().split()))
dp = [0] * (N+1)
dp[1] = 1
LR = []
for i in range(K):
l, r = list(map(int, input().split()))
LR.append([l, r])
for i in range(2, N+1):
dp[i] = dp[i-1]
for j in range(K):
l, r = LR[j]
dp[i] += dp[max(i-l, 0)] - dp[max(i-r-1, 0)]
dp[i] %= MOD
print((dp[N]-dp[N-1]) % MOD) | # coding: utf-8
# Your code here!
S = input()
T = input()
ans = 10000000
for i in range(len(T), len(S)+1):
sub_S = S[i-len(T):i]
count = 0
for j in range(len(sub_S)):
if T[j] != sub_S[j]:
count += 1
ans = min(ans, count)
print(ans) | 0 | null | 3,194,765,144,352 | 74 | 82 |
X, Y, Z = map(int, input().split())
print(Z)
print(X)
print(Y) | a,b,c=list(map(int,input().split()))
print(str(c)+" "+str(a)+" "+str(b)) | 1 | 37,985,254,527,528 | null | 178 | 178 |
def main():
N, P = (int(i) for i in input().split())
L = [int(s) for s in input()][::-1]
ans = 0
if P == 2 or P == 5:
for i, e in enumerate(L):
if e % P == 0:
ans += N-i
else:
A = [0]*N
d = 1
for i, e in enumerate(L):
A[i] = (e*d) % P
d *= 10
d %= P
S = [0]*(N+1)
for i in range(N):
S[i+1] = S[i] + A[i]
S[i+1] %= P
from collections import Counter
c = Counter(S)
for v in c.values():
ans += v*(v-1)//2
print(ans)
if __name__ == '__main__':
main()
| from collections import defaultdict
import sys
def input():return sys.stdin.readline().strip()
def main():
N, P = map(int, input().split())
S = input()
ans = 0
if P in [2, 5]:
for i, c in enumerate(S[::-1]):
if int(c) % P == 0:
ans += N-i
else:
d = defaultdict(int)
d[0] = 1
num = 0
ten = 1
for c in S[::-1]:
num += int(c) * ten
num %= P
d[num] += 1
ten *= 10
ten %= P
ans = sum([d[i]*(d[i]-1)//2 for i in range(P)])
print(ans)
if __name__ == "__main__":
main() | 1 | 58,271,317,731,198 | null | 205 | 205 |
n,k = map(int, input().split())
s = {i:0 for i in range(n+1)}
for i in range(k):
d = int(input())
a = list(map(int, input().split()))
for i in a:
s[i] += 1
cnt = -1
for i in s:
if s[i] == 0:
cnt +=1
print(cnt)
| N = int(input())
S = input()
total = S.count('R') * S.count('G') * S.count('B')
cnt = 0
for i in range(N):
for j in range(i+1,N):
k = 2 * j - i
if k >= N:
break
if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
cnt += 1
print(total-cnt) | 0 | null | 30,304,919,269,640 | 154 | 175 |
import fractions
A,B=map(int,input().split())
def lcm(x,y):
return int((x*y)/fractions.gcd(x,y))
print(lcm(A,B)) | a,b=map(int,input().split())
#a,bの最大公約数
def gcd(a, b):
while b:
a, b = b, a % b
return a
#a,bの最小公倍数
def lcm(a, b):
return a * b // gcd (a, b)
print(lcm(a,b)) | 1 | 113,073,859,716,642 | null | 256 | 256 |
# -*-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))) | (n, k), p, c = [[*map(int, i.split())] for i in open(0)]
def solve(x, t):
visit = [0] * n
visit[x] = 1
loop = [0] * n
count = 0
ans = c[p[x] - 1]
l = True
sub = 0
while True:
x = p[x] - 1
if l:
if visit[x]:
if loop[x]:
ln = sum(loop)
if t > ln:
sub += (t//ln -1)*count*(count>0)
t %= ln
t += ln
l = False
count += c[x]
loop[x] = 1
visit[x] = 1
sub += c[x]
t -= 1
ans = max(sub, ans)
if t < 1:
return ans
print(max(solve(i, k) for i in range(n))) | 0 | null | 2,672,370,734,388 | 3 | 93 |
a, b = map(int, input().split())
print((a * b) if 0 < a < 10 and 0 < b < 10 else -1) | n=int(input())
a=list(map(int,input().split()))
ans=['-']*n
for i in range(n):
ans[a[i]-1]=str(i+1)
print(' '.join(ans)) | 0 | null | 169,248,254,195,548 | 286 | 299 |
n, k = [int(i) for i in input().split()]
cnt = 0
if n == 0:
print(1)
exit()
while n != 0:
n = n // k
cnt += 1
print(cnt) | n,k = map(int, input().split())
ans = 0
while n > 0:
n /= k
n = int(n)
ans += 1
print(ans)
| 1 | 64,214,899,782,264 | null | 212 | 212 |
D, T, S = list(map(int, input().split()))
print("Yes" if T*S>=D else "No") | list1 = input().split(" ")
if int(list1[0]) <= int(list1[1]) * int(list1[2]):
print("Yes")
else:
print("No") | 1 | 3,540,953,928,360 | null | 81 | 81 |
n = input()
if n != 0:
l = [int(x) for x in raw_input().split()]
print min(l), max(l), sum(l)
else:
print "0 0 0" | #coding:utf-8
input()
data = [int(x) for x in input().split()]
print(str(min(data))+" "+str(max(data)) + " "+str(sum(data))) | 1 | 735,203,615,650 | null | 48 | 48 |
n = int(input())
s = input()
print(sum([1 for i in range(n-2) if s[i:i+3] == 'ABC'])) | a,b,c = map(int,input().split(" "))
ptn = 0
if a==b and a==c:
print(1)
ptn = 1
if a==b and a!=c:
if a < c:
print(1)
ptn=2
else:
print(0)
ptn=2
cnt = 0
for i in range(a,b+1):
if c%i == 0:
cnt += 1
if ptn != 1 and ptn != 2:
print(cnt) | 0 | null | 49,913,880,783,616 | 245 | 44 |
def main():
H,W,K = list(map(int, input().split()))
S = ['' for i in range(H)]
for i in range(H):
S[i] = input()
ans = H*W
for i in range(0,1<<(H-1)):
g = 0
id = [0 for j in range(H)]
for j in range(0,H):
id[j] = g
if i>>j&1 == 1:
g += 1
g_cnt = [0 for j in range(g+1)]
c_ans = g
j = 0
div_w = 0
while j < W:
for k in range(0, H):
if S[k][j] == '1':
g_cnt[id[k]] += 1
for k in range(0,g+1):
if g_cnt[k] > K:
c_ans += 1
g_cnt = [0 for j in range(g+1)]
if div_w == j:
c_ans += H*W
break
j -= 1
div_w = j
break
j += 1
if c_ans > ans:
break
ans = min(ans, c_ans)
print(ans)
main() | n, d, a = map(int, input().split())
xh = []
for _ in range(n):
x, h = map(int, input().split())
h = (h - 1) // a + 1
xh.append([x, h])
xh.sort()
damage = xh[0][1]
ans = damage
damage_lst = [[xh[0][0] + d * 2, damage]]
pos = 0
for i, (x, h) in enumerate(xh[1:], start = 1):
while x > damage_lst[pos][0]:
damage -= damage_lst[pos][1]
pos += 1
if pos == i:
break
damage_tmp = max(h - damage, 0)
ans += damage_tmp
damage += damage_tmp
damage_lst.append([x + d * 2, damage_tmp])
print(ans) | 0 | null | 65,171,247,147,190 | 193 | 230 |
floor = [[[0] * 10 for x in range(3)] for y in range(4)]
for c in range(int(input())):
(b,f,r,v) = [int(x) for x in input().split()]
floor[b-1][f-1][r-1] += v
for x in range(3 * 4):
if x % 3 == 0 and not x == 0:
print('#' * 20)
print('',' '.join(str(y) for y in floor[int(x / 3)][x % 3])) | k,x=map(int,input().split());print("YNeos"[x>k*500::2]) | 0 | null | 49,780,216,918,068 | 55 | 244 |
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
N = int(readline())
if N==1:
print('a')
exit()
d = deque(['a'])
ans = []
while d:
s = d.popleft()
last = ord(max(s))
for i in range(97,last+2):
S = s + chr(i)
if len(S)==N:
ans.append(S)
else:
d.append(S)
ans.sort()
for s in ans:
print(s)
if __name__ == '__main__':
main() | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
res = set()
a = ord("a")
mx = lambda x: max(list(map(ord, x))) - a
def dfs(s):
if len(s) == N:
res.add("".join(s))
return
for k in range(mx(s) + 2): dfs(s + [chr(k + a)])
dfs(["a"])
for r in sorted(res): print(r) | 1 | 52,211,155,448,890 | null | 198 | 198 |
n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
l.append([a[i], i+1])
l = sorted(l)
ans = []
for j in range(n):
ans.append(str(l[j][1]))
print(" ".join(ans)) | import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def solve():
la = [(item,i+1) for i,item in enumerate(a)]
la.sort()
for rep in la:
print(f"{rep[1]} ",end="")
return
if __name__=='__main__':
n = I()
a = list(IL())
solve() | 1 | 180,620,829,025,418 | null | 299 | 299 |
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
| H = int(input())
W = int(input())
N = int(input())
A = H if H > W else W
if N%A == 0:
print(N//A)
else:
print(N//A+1) | 1 | 89,025,166,662,880 | null | 236 | 236 |
# -*- coding: utf-8 -*-
def main():
S = input()
week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
for i, name in enumerate(week):
if name == S:
ans = 7 - i
print(ans)
if __name__ == "__main__":
main() | day = ["SUN","MON","TUE","WED","THU","FRI","SAT" ]
s = input()
pos = day.index(s)
print(7-pos) | 1 | 132,776,617,862,630 | null | 270 | 270 |
N,M = map(int,input().split())
A = list(map(int,input().split()))
for i in range(M):
N -= A[i]
if N<0:
print("-1")
exit()
elif N>=0 and i+1 == M:
print(N)
exit() | n, m = (int(x) for x in input().split())
list_a = [int(x) for x in input().split()]
for i in range(0, m):
n -= list_a[i]
if n < 0:
print('-1')
exit()
print(n) | 1 | 31,802,603,731,532 | null | 168 | 168 |
i = input()
print(i.swapcase())
| n,k=(int(i) for i in input().split())
a=list(map(int, input().split()))
a.sort()
sum=0
for i in range(k):
sum+=a[i]
print(sum)
| 0 | null | 6,578,034,831,944 | 61 | 120 |
k = int(input())
acl = "ACL"
print(acl*k) | X=int(input())
A=0
B=0
for i in range(-120,120):
for k in range(-120,120):
if i**5==X+k**5:
A=i
B=k
break
print(A,B) | 0 | null | 13,871,372,708,550 | 69 | 156 |
import math
N = int(input())
A = [0]*(N)
for i in range(0,N):
A[i] = math.floor((N-1)/(i+1))
print(sum(A)) | n=int(input())
ans=10**12
d=2
while d<=n**(1/2):
if n%d==0:
ans=min(ans,d+n//d-2)
d+=1
if ans==10**12:
print(n-1)
exit()
print(ans) | 0 | null | 81,658,879,338,890 | 73 | 288 |
alphabetlist=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
N=int(input())
S=[0 for i in range(0,N)]
string=''
for i in range(0,N):
string+='a'
print(string)
digit=N-1
while True:
if digit!=0:
if S[digit]==max(S[0:digit])+1:
digit-=1
else:
S[digit]+=1
for j in range(digit+1,N):
S[j]=0
digit=N-1
if S[0]==1:
break
string=[0 for i in range(0,N)]
for i in range(0,N):
string[i]=alphabetlist[S[i]]
print(''.join(string))
else:
break | def dfs(S, mx):
if len(S) == N:
print(S)
else:
for i in range(a, mx+2):
if i == mx+1:
dfs(S+chr(i), mx+1)
else:
dfs(S+chr(i), mx)
return
N = int(input())
a = ord('a')
dfs('a', a) | 1 | 52,137,350,413,454 | null | 198 | 198 |
def main():
num = list(map(int,input().split()))
if num[0]+num[1]+num[2]<22:
print('win')
else:
print('bust')
main() | S = input()
l1 = []
l2 = []
total_area = 0
for i, j in enumerate(S):
if j == '\\':
l1.append(i)
elif j == '/' and l1:
i_p = l1.pop()
v = i -i_p
total_area += v
while l2 and l2[-1][0] > i_p:
v += l2.pop()[1]
l2.append([i_p, v])
ans = [str(len(l2))] + [str(k[1]) for k in l2]
print(total_area)
print(' '.join(ans))
| 0 | null | 59,385,129,885,198 | 260 | 21 |
print((1000 - (int(input()) % 1000)) % 1000) | import sys
n = int(input())
if n % 1000 == 0:
print(0)
sys.exit()
while n > 1000:
n -= 1000
print(1000 - n) | 1 | 8,458,432,955,376 | null | 108 | 108 |
import sys
s = sys.stdin.readline().rstrip("\n")
print(s[:3]) | S=str(input())
n=[]
for i in range(3):
n.append(S[i])
print(''.join(n)) | 1 | 14,688,808,006,432 | null | 130 | 130 |
N,R=[int(i) for i in input().split()]
if N < 10:
R += 100 * (10- N)
print(R)
else:
print(R) |
import math
def run():
x1,y1,x2,y2=tuple(map(float,input().split()))
r=math.sqrt((x1-x2)**2+(y1-y2)**2)
print(f"{r:.30f}")
run()
| 0 | null | 31,676,740,250,616 | 211 | 29 |
def alp(c):
return chr(c+64)
def Base10to(n,k):
if(int(n/k)):
if n%k ==0 and n/k==1:
return str(alp(26))
elif n%k ==0:
return Base10to(int((n/k)-1),k)+str(alp(26))
else:
return Base10to(int(n/k),k)+str(alp(n%k))
return str(alp(n%k))
n = int(input())
k = 26
ans = Base10to(n,k)
print(ans.lower()) | OFFSET = 97
def main():
n = int(input())
ans = []
while True:
n -= 1
n,mod = divmod(n,26)
ans.append(chr(mod+OFFSET))
if n==0:
break
print(''.join(ans)[::-1])
return
if __name__ == '__main__':
main() | 1 | 11,817,378,156,980 | null | 121 | 121 |
import math
while 1:
n = int(input())
if n == 0:
break
s = list(map(int,input().split()))
m = sum(s) / len(s)
x = 0
for i in range(n):
x += (s[i] -m )**2 / n
a = math.sqrt(x)
print(a) | from math import sqrt
while True:
n = int(input())
if n == 0:
break
scores = list(map(int,input().split()))
m = sum(scores)/len(scores)
print(sqrt(sum((sc -m)**2 for sc in scores)/len(scores))) | 1 | 200,182,926,428 | null | 31 | 31 |
import math
a,b,c=(int(x) for x in input().split())
s=1/2*a*b*math.sin(c/180*math.pi)
l=math.sqrt(a**2+b**2-2*a*b*math.cos(c/180*math.pi))+a+b
h=s/a*2
print('{:.05f}'.format(s))
print('{:.05f}'.format(l))
print('{:.05f}'.format(h))
| for a in range(1,10):
for b in range(1,10):
print(a, end="")
print("x", end="")
print(b, end="")
print("=", end="")
print(a*b) | 0 | null | 87,943,884,540 | 30 | 1 |
n,m=map(int,input().split())
ac=[False]*n
wa=[0]*n
for i in range(m):
p,s=input().split()
p=int(p)-1
if s=="AC":
ac[p]=True
else:
if not ac[p]:
wa[p]+=1
a=0
b=0
for i in range(n):
if ac[i]:
a+=1
b+=wa[i]
print(a,b,sep=" ")
| N,M=map(int, input().split())
a=[0]*(N+1)
w=[0]*(N+1)
for _ in range(M):
p,s=input().split()
p=int(p)
if s=='AC':
a[p]=1
else:
if a[p]==0:
w[p]+=1
a2=0
w2=0
for n in range(N+1):
if a[n]==1:
a2+=a[n]
w2+=w[n]
print(a2, w2)
| 1 | 93,697,551,069,030 | null | 240 | 240 |
L = int(input())
ans = (L/3)**3
print("{:.10f}".format(ans))
| import sys
l = int(input())
print((l / 3)**3)
| 1 | 47,154,234,123,308 | null | 191 | 191 |
n = int(input())
mod = 10 ** 9 + 7
start,zero,nine,ans = 1,0,0,0
for i in range(n):
ans = (ans * 10 + zero + nine) % mod
zero = (zero * 9 + start) % mod
nine = (nine * 9 + start) % mod
start = (start * 8) % mod
print(ans) | n = int(input())
buf = [0]*n
def solv(idx,char):
aida = n - idx
if idx == n:
print("".join(buf))
return
for i in range(char + 1):
buf[idx] = chr(ord('a') + i)
solv(idx+1,max(i + 1,char))
solv(0,0) | 0 | null | 27,739,582,793,780 | 78 | 198 |
#coding:utf-8
n = int(input().rstrip())
toku =[0,0]
narabe = []
for i in range(n):
taro, hana = input().rstrip().split()
if taro == hana:
toku[0] +=1
toku[1] +=1
else:
narabe = [taro, hana]
narabe.sort()
toku[0] += narabe.index(taro)*3
toku[1] += narabe.index(hana)*3
print(" ".join(list(map(str,toku)))) | input_data = [int(i) for i in input().split()]
if input_data[0] > input_data[1]:
print("a > b")
elif input_data[0] < input_data[1]:
print("a < b")
else :
print("a == b") | 0 | null | 1,202,422,399,740 | 67 | 38 |
import sys
input = sys.stdin.readline
from collections import *
S = input()[:-1]
if S=='SUN':
print(7)
elif S=='MON':
print(6)
elif S=='TUE':
print(5)
elif S=='WED':
print(4)
elif S=='THU':
print(3)
elif S=='FRI':
print(2)
elif S=='SAT':
print(1) | d='SUN,MON,TUE,WED,THU,FRI,SAT'.split(',')
s=input()
print(7 - d.index(s)) | 1 | 132,919,308,801,588 | null | 270 | 270 |
def calc(X):
A = 1
B = 1
if X == 0:
return A,B
else:
l_bound = 1
h_bound = 200
for i in range(l_bound,h_bound):
for j in range(0,i+1):
if i ** 5 - j ** 5 == X:
A = i
B = j
return A,B
if i ** 5 + j ** 5 == X:
A = i
B = -j
return A,B
def resolve():
X = int(input())
A,B = calc(X)
print(str(A) + " " + str(B))
resolve() | n=int(input())
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
ans=0
l=len(factorization(n))
s=factorization(n)
for i in range(l):
for j in range(1,1000):
if s[i][1]>=j:
ans+=1
s[i][1]-=j
else:
break
if n==1:
print(0)
else:
print(ans)
| 0 | null | 21,039,714,609,060 | 156 | 136 |
a,b = map(int,input().split())
print("{0} {1} {2:.5f}".format((a//b),(a%b),(a/b)))
| #coding: UTF-8
l = raw_input().split()
a = int(l[0])
b = int(l[1])
if 1 <= a and b <= 10**9:
d = a / b
r = a % b
f = float (a )/ b
print "%d %d %f" %(d, r, f) | 1 | 599,707,804,180 | null | 45 | 45 |
[print("YES" if x[0] + x[1] == x[2] else "NO") for x in [sorted([x * x for x in [int(i) for i in input().split(" ")]]) for _ in range(int(input()))]] | N = int(input())
for i in range(N):
a, b, c = map(int, input().split())
if(a > c):
a, c = c, a
if(b > c):
b, c = c, b
if(c**2 == a**2 + b**2):
print("YES")
else:
print("NO") | 1 | 292,285,202 | null | 4 | 4 |
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N-K):
if A[i] < A[i+K]:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | vec1 = []
vec2 = []
n, m = map(int, input().split())
for x in range(1, n+1):
vec1.append(list(map(int, input().split())))
for y in range(m):
vec2.append(int(input()))
for j in vec1:
result = 0
for w, z in zip(j, vec2):
result += w * z
print(result)
| 0 | null | 4,147,706,585,528 | 102 | 56 |
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
import bisect
con = 10 ** 9 + 7; INF = float("inf")
def getlist():
return list(map(int, input().split()))
def Binary_Search(A, N, M):
#初期化
left = 0
right = 10 ** 7
ans = 0
#累積和
Asum = [0]
for i in range(N):
Asum.append(Asum[i] + A[-1 - i])
leftj = [INF, INF]
rightj = [0, 0]
#二分探索
while left <= right:
mid = (left + right) // 2
var = 0
happiness = 0
for i in range(N):
ind = bisect.bisect_left(A, mid - A[i])
ind = N - ind
var += ind
happiness += ind * A[i] + Asum[ind]
# print(var, happiness)
if var == M:
return happiness
elif var > M:
leftj = min(leftj, [var, -mid])
left = mid + 1
else:
ans = max(ans, happiness)
rightj = max(rightj, [var, -mid])
right = mid - 1
# print(ans)
# print(leftj)
# print(rightj)
ans = ans + (M - rightj[0]) * (-leftj[1])
return ans
#処理内容
def main():
N, M = getlist()
A = getlist()
A.sort()
ans = Binary_Search(A, N, M)
print(ans)
if __name__ == '__main__':
main() | N = int(input())
S = input()
ret = ''
for s in S:
o = ord(s) - ord('A') + N
ret += chr(ord('A') + o % 26)
print(ret) | 0 | null | 121,424,418,966,930 | 252 | 271 |
h,n = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
dp = [float("inf") for i in range(10**5)]
dp[0] = 0
for a,b in ab:
for k in range(a+1):
dp[k] = min(dp[k], b)
for k in range(a+1,h+1):
dp[k] = min(dp[k], dp[k-a] + b)
print(dp[h]) | #!/usr/bin/env python
# encoding: utf-8
class Solution:
"""
@param prices: Given an integer array
@return: Maximum profit
"""
@staticmethod
def bubble_sort():
# write your code here
array_length = int(input())
unsorted_array = [int(x) for x in input().split()]
flag = 1
count = 0
while flag:
flag = 0
for j in range(array_length - 1, 0, -1):
if unsorted_array[j] < unsorted_array[j - 1]:
unsorted_array[j], unsorted_array[j - 1] = unsorted_array[j - 1], unsorted_array[j]
flag = 1
count += 1
print(" ".join(map(str, unsorted_array)))
print(str(count))
if __name__ == '__main__':
solution = Solution()
solution.bubble_sort() | 0 | null | 40,316,020,500,380 | 229 | 14 |
import math
n = int(input())
count = 0
for i in range(n):
t = int(input())
a = int(t ** (1 / 2))
end = 0
for j in range(2, a + 1):
if t % j == 0:
end = 1
break
if end == 0:
count += 1
print(count)
| N =int(input())
c = 0
for i in range(N):
c += (N-1)//(i+1)
print(c)
| 0 | null | 1,307,123,669,020 | 12 | 73 |
import math
a = int(input())
for i in range(50001):
if math.floor(i*1.08) == a:
print(i)
exit()
print(":(") | a,b=map(int,input().split())
l=list(map(int,input().split()))
z=0
l=sorted(l)
for i in range(a-b):
z+=l[i]
print(z) | 0 | null | 101,977,650,974,620 | 265 | 227 |
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
SA = [0]
SB = [0]
tmp_A, tmp_B = 0 ,0
for i in range(N):
tmp_A += A[i]
if tmp_A <= K:
SA.append(tmp_A)
else:
break
for i in range(M):
tmp_B += B[i]
if tmp_B <= K:
SB.append(tmp_B)
else:
break
ans = 0
cursol_B = len(SB) - 1
for i in range(len(SA)):
while SA[i] + SB[cursol_B] > K:
cursol_B -= 1
ans = max(ans, i + cursol_B)
print(ans) | from itertools import accumulate
def solve(string):
n, m, k, *ab = map(int, string.split())
a, b = [0] + ab[:n], [0] + ab[n:]
a, b = list(accumulate(a)), list(accumulate(b))
i, j = n, 0
while a[i] > k:
i -= 1
while j <= m and a[i] + b[j] <= k:
j += 1
ans = i + j - 1
for i in range(i, -1, -1):
while j <= m and a[i] + b[j] <= k:
j += 1
ans = max(ans, i + j - 1)
return str(ans)
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| 1 | 10,683,882,138,948 | null | 117 | 117 |
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
bl = N == M
print('Yes' if bl else 'No')
| S,T = map(int,input().split())
if S == T:
print('Yes')
else:
print('No') | 1 | 82,933,416,167,550 | null | 231 | 231 |
from collections import defaultdict
dic = defaultdict(int)
n,x,y = map(int,input().split())
for i in range(1,n+1):
for j in range(i,n+1):
val = min(abs(i-j), abs(x-i) + abs(y-j) + 1)
dic[val] += 1
for i in range(1,n):
print(dic[i]) | import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
if N % 2 == 1:
i = N // 2
AB.sort()
L = AB[i][0]
AB.sort(key=lambda x: x[1])
R = AB[i][1]
ans = R - L + 1
else:
i = N // 2 - 1
j = i + 1
AB.sort()
L = AB[i][0] + AB[j][0]
AB.sort(key=lambda x: x[1])
R = AB[i][1] + AB[j][1]
ans = R - L + 1
print(ans) | 0 | null | 30,742,799,153,856 | 187 | 137 |
N = int(input())
def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
mdn = make_divisors(N)
aa = []
for x in mdn:
aa.append(x+N//x)
print(min(aa)-2) | import sys
def I(): return int(sys.stdin.readline().rstrip())
N = I()
for i in range(int(N**.5),0,-1):
if N % i == 0:
print(i+(N//i)-2)
exit()
| 1 | 161,439,172,297,810 | null | 288 | 288 |
def warshall_floyd(v_count: int, matrix: list) -> list:
""" ワーシャルフロイド
v_count: 頂点数
matrix: 隣接行列(到達不能はfloat("inf"))
"""
for i in range(v_count):
for j, c2 in enumerate(row[i] for row in matrix):
for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
if c1 > c2+c3:
matrix[j][k] = c2+c3
return matrix
INF = 10 ** 16
n, m, l = map(int, input().split())
mat = [[INF] * n for _ in range(n)]
for i in range(n):
mat[i][i] = 0
for _ in range(m):
a, b, c = map(int, input().split())
mat[a - 1][b - 1] = c
mat[b - 1][a - 1] = c
mat = warshall_floyd(n, mat)
fuel_mat = [[INF] * n for _ in range(n)]
for i in range(n):
for j in range(n):
if i == j:
fuel_mat[i][j] = 0
elif mat[i][j] <= l:
fuel_mat[i][j] = 1
fuel_mat = warshall_floyd(n, fuel_mat)
q = int(input())
for _ in range(q):
s, t = map(int, input().split())
d = fuel_mat[s - 1][t - 1]
if d == INF:
print(-1)
else:
print(d - 1)
| S=input().replace("hi","")
print("Yes" if S=="" else "No") | 0 | null | 113,485,417,263,972 | 295 | 199 |
w=input()
a=0
while True:
t=input().split()
l=[]
for T in t:
l.append(T.lower())
a+=l.count(w)
if t[0]=="END_OF_TEXT":
break
print(a)
| # -*- coding: utf-8 -*-
import sys
w = sys.stdin.readline().strip()
count = 0
while True:
t = list(map(str, input().split()))
if 'END_OF_TEXT' in t:
break
for i in range(len(t)):
if t[i].lower() == w:
count += 1
print(count)
| 1 | 1,805,707,098,170 | null | 65 | 65 |
n = int(input())
alst = list(map(int, input().split()))
alst.sort()
bef = -1
for a in alst:
if bef == a:
print("NO")
break
bef = a
else:
print("YES") | a=str(input())
if a[0]==a[1] and a[2]==a[0] :
print('No')
else:
print('Yes')
| 0 | null | 64,234,498,543,780 | 222 | 201 |
H, W, K = map(int, input().split())
Ss = [list(map(int, input().replace("\n", ""))) for _ in range(H)]
cut_yoko_patterns = ["0","1"]
options = ["0","1"]
import copy
for i in range(H-2):
cut_yoko_patterns = [cut_yoko_patterns[i] + options[j] for i in range(len(cut_yoko_patterns)) for j in range(len(options))]
answer = int(1e+5)
for cut_yoko_pattern in cut_yoko_patterns:
yoko_cut_num = cut_yoko_pattern.count("1")
boxs = [0 for _ in range(yoko_cut_num+1)]
box_num = [0 for _ in range(H)]
for i in range(H-1):
if cut_yoko_pattern[i] == "1":
box_num[i+1] = box_num[i] + 1
else:
box_num[i+1] = box_num[i]
tate_cut_num = 0
for j in range(W):
temp_boxs = [0 for _ in range(yoko_cut_num+1)]
for i in range(H):
if Ss[i][j] == 1:
temp_boxs[box_num[i]] += 1
Impossible = False
Should_cut = False
for i in range(yoko_cut_num+1):
if temp_boxs[i] > K:
Impossible = True
elif boxs[i] + temp_boxs[i] > K:
Should_cut = True
if Impossible == True:
break
elif Should_cut ==True:
boxs = copy.deepcopy(temp_boxs)
tate_cut_num += 1
else:
for i in range(yoko_cut_num+1):
boxs[i] += temp_boxs[i]
else:
if tate_cut_num+yoko_cut_num < answer:
answer = tate_cut_num + yoko_cut_num
print(answer) | a = 100000;
n = int(input())
while n > 0:
n -= 1
a = 105*a//100
a = ((a - 1) // 1000 + 1) * 1000
print(a)
| 0 | null | 24,138,041,758,818 | 193 | 6 |
n = int(input())
playlists = []
for _ in range(n):
title, playtime = input().split()
playlists.append([title, int(playtime)])
titles, playtimes = list(zip(*playlists))
lastmusic = input()
lastmusic_timing = titles.index(lastmusic)
print(sum(playtimes[lastmusic_timing + 1:])) | from itertools import product
N=int(input())
datas=[]
for i in range(N):
A=int(input())
for j in range(A):
x,y=map(int,input().split())
datas.append((i,x-1,y)) #誰が 誰に どう判断した?
#print(datas)
ans=0
for i in product([0,1],repeat=N):
ok=True
for j in datas:
if i[j[0]]==1 and i[j[1]]!=j[2]:
ok=False
break
if ok:
ans=max(ans,sum(i))
print(ans) | 0 | null | 109,362,248,544,020 | 243 | 262 |
from collections import deque
# データの入力
N = int(input())
DG = {}
for i in range(N):
tmp = input().split()
if int(tmp[1]) != 0:
DG[i] = [int(x)-1 for x in tmp[2:]]
else:
DG[i] = []
result = {}
is_visited = {key: False for key in range(N)}
# bfs
# 初期queue
que = deque([(0, 0)]) # 必要なものはnodeidと原点からの距離
while que:
nodeid, cost = que.popleft() # 先入れ先出し
result[nodeid] = cost
is_visited[nodeid] = True # この文は最初の1for目しか意味ないんだけどなんかうまい方法ないのか
for nextnode in DG[nodeid]:
if is_visited[nextnode]:
pass
else: # 未訪問のものについては探索候補に入れる
que.append((nextnode, cost + 1))
is_visited[nextnode] = True # 探索候補に入れた瞬間に訪問管理しないと重複を生じる場合がある
for i in range(N):
if is_visited[i]:
print(i + 1, result[i])
else:
print(i+1, -1)
| def merge(A,left,mid,right):
global cnt
n1 = mid - left
n2 = right - mid
cnt += n1+n2
L = [A[left+i] for i in range(n1)]
R = [A[mid+i] for i in range(n2)]
L.append(float("inf"))
R.append(float("inf"))
i = 0
j = 0
for k in range(left,right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
def mergesort(A,left,right):
if left +1 < right:
mid = int((left+right)/2)
mergesort(A,left,mid)
mergesort(A,mid,right)
merge(A,left,mid,right)
n = int(input())
A = list(map(int,input().split()))
cnt = 0
mergesort(A,0,n)
print(" ".join(map(str,A)))
print(cnt)
| 0 | null | 59,594,181,142 | 9 | 26 |
n,k,s=map(int,input().split())
a=[1 for i in range(n)]
for i in range(k):
a[i]=s
for i in range(k,n):
if s!=10**9:
a[i]+=s
else:
a[i]=1
if k==0:
if s!=10**9:
a=[10**9 for i in range(n)]
else:
a=[1 for i in range(n)]
print(*a) | N = int(input())
if (N - 1) % 2 == 0:
a = (N-1) / 2
print(int(a))
else:
b = N / 2 - 1
print(int(b)) | 0 | null | 121,972,596,089,432 | 238 | 283 |
n = int(input())
tmp = int(n/1.08)
ans_lists = [tmp + i for i in range(2)]
ans = 0
for j in ans_lists:
if int(j*1.08) == n:
ans = j
break
else:
ans = ':('
print(ans) | import sys
import time
import math
def inpl():
return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------
N = int(input())
ls = [0] * 50505
for i in range(len(ls)):
ls[i] = int(i * 1.08)
for i in range(N, 0, -1):
if ls[i] == N:
print(i)
sys.exit()
print(':(')
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
| 1 | 125,491,964,769,482 | null | 265 | 265 |
n=int(input())
s,t=input().split()
ans=""
for i,j in zip(list(s),list(t)):ans+=i+j
print(ans) | def insertion_sort(A, n, g, cnt):
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and v < A[j]:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
return cnt
def shell_sort(A, n):
cnt = 0
h = 1
g = []
while h <= n:
g.append(h)
h = 3*h + 1
g.reverse()
m = len(g)
for i in range(m):
cnt = insertion_sort(A, n, g[i], cnt)
show(n, m, g, A, cnt)
def show(n, m, G, A, cnt):
print(m)
for i in range(m):
if i != m-1:
print(G[i], end = " ")
else:
print(G[i])
print(cnt)
for i in range(n):
print(A[i])
if "__main__" == __name__:
n = int(input())
data = []
for i in range(n):
data.append(int(input()))
shell_sort(data, n)
| 0 | null | 55,785,878,452,952 | 255 | 17 |
n = input()
cnt = 0
for i in n:
cnt += int(i)
if cnt % 9 == 0:
print('Yes')
else:
print('No') | N=int(input())
print("Yes" if N%9==0 else "No") | 1 | 4,394,034,424,000 | null | 87 | 87 |
import sys
S = int(sys.stdin.readline())
h = int(S / 60 / 60)
m = int(S % 3600 / 60)
s = S % 60
print("%d:%d:%d" % (h, m, s)) | D = int(input())
c = [*map(int, input().split())]
s = [0] + [[*map(int, input().split())] for _ in range(D)]
t = [0] + [int(input()) for _ in range(D)]
v = 0
last = [0] * 26
for d in range(1, D+1):
select = t[d] - 1
v += s[d][select]
last[select] = d
v -= sum(c[i] * (d - last[i]) for i in range(26))
print(v)
| 0 | null | 5,119,002,299,814 | 37 | 114 |
s = raw_input()
ans = ""
for x in xrange(len(s)):
if s[x].islower():
ans += s[x].upper()
else:
ans += s[x].lower()
print ans | n = str(input())
ns = n.swapcase()
print(ns)
| 1 | 1,502,186,729,940 | null | 61 | 61 |
def main():
from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 7)
inf = 2 * 10 ** 14 + 1
N = int(input())
*a, = map(int, input().split())
@lru_cache(maxsize=None)
def recursion(cur, need):
"""
cur: pickableなindex
"""
if cur >= N:
if need == 0:
return 0
else:
return -inf
rest = N - cur
if (rest + 1) // 2 < need:
return -inf
return max(
a[cur] + recursion(cur + 2, need - 1),
recursion(cur + 1, need)
)
ans = recursion(0, N // 2)
print(ans)
if __name__ == '__main__':
main()
| n = int(input())
a = list(map(int, input().split()))
if n%2 == 0:
dp = a[:2]
for i in range(1, n//2):
dp = dp[0] + a[2*i], max(dp) + a[2*i+1]
else:
dp = a[:3]
for i in range(1, n//2):
dp = dp[0] + a[2*i], max(dp[:2]) + a[2*i+1], max(dp) + a[2*i+2]
print(max(dp)) | 1 | 37,561,794,508,900 | null | 177 | 177 |
import math
n = int(input())
for i in range(int(math.sqrt(n)),0,-1):
if n % i == 0:
print(int(i + (n / i) - 2))
break | def divisor(x):
table = []
i = 1
while i * i <= x:
if x%i == 0:
table.append(i)
table.append(n//i)
i +=1
table.sort()
return table
n = int(input())
l = divisor(n)
c = len(l)
ans = 100100100100100
for i in range(c):
x = l[i] - 1
y = l[c-i-1] - 1
tot = x + y
ans = min(ans,tot)
print(ans) | 1 | 161,019,416,345,080 | null | 288 | 288 |
n=int(input())
A=list(map(int,input().split()))
for i in range(1,n):
print(" ".join(map(str,A)))
j=i
while A[j]<A[j-1] and j>0:
(A[j],A[j-1])=(A[j-1],A[j])
j=j-1
else:
print(" ".join(map(str,A))) | n = int(input())
array = [int(a) for a in input().split()]
for i in range(n):
j = i
while j < n:
if j != 0 and array[j-1] > array[j]:
array[j-1], array[j] = array[j], array[j-1]
j -= 1
continue
else:
break
for k in range(n):
if k != n-1:
print(array[k], end=' ')
else:
print(array[k]) | 1 | 5,216,307,316 | null | 10 | 10 |
#coding:utf-8
#1_2_C
def BubbleSort(cards, n):
for i in range(n):
for j in range(n-1, i, -1):
if cards[j][1] < cards[j-1][1]:
cards[j], cards[j-1] = cards[j-1], cards[j]
return cards
def SelectionSort(cards, n):
for i in range(n):
minj = i
for j in range(i, n):
if cards[minj][1] > cards[j][1]:
minj = j
cards[i], cards[minj] = cards[minj], cards[i]
return cards
n = int(input())
cardsR = input().split()
cardsS = cardsR[:]
print(' '.join(BubbleSort(cardsR, n)))
print("Stable")
print(*SelectionSort(cardsS, n))
print("Stable" if cardsR == cardsS else "Not stable") | t1, t2 = (int(x) for x in input().split())
a1, a2 = (int(x) for x in input().split())
b1, b2 = (int(x) for x in input().split())
if a1 < b1:
a1, b1 = b1, a1
a2, b2 = b2, a2
if a1 * t1 + a2 * t2 > b1 * t1 + b2 * t2:
print(0)
exit()
elif a1 * t1 + a2 * t2 == b1 * t1 + b2 * t2:
print("infinity")
exit()
d1 = (a1 - b1) * t1
d2 = (b2 - a2) * t2
k = d1 // (d2 - d1)
if d1 % (d2 - d1) == 0:
print(2 * k)
else:
print(2 * k + 1)
| 0 | null | 65,527,065,710,538 | 16 | 269 |
D = list(input())
ans = 0
cnt = 0
for i in D:
if i == 'R':
cnt += 1
else:
cnt = 0
if ans < cnt:
ans = cnt
print(ans) | #a問題(できなかった)
s = input()
p=s[0]=='R'
q=s[1]=='R'
r=s[2]=='R'
if p and q and r==True:
print(3)
elif (p and q)or(q and r)==True:
print(2)
elif p or q or r ==True:
print(1)
else:
print(0)
| 1 | 4,909,279,653,258 | null | 90 | 90 |
days = ["SUN", 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
days.reverse()
d = input()
print(days.index(d)+1)
| import math
a, b, C = map(int, input().split())
C = math.radians(C)
print(0.5*a*b*math.sin(C))
print(a+b+math.sqrt(a*a+b*b-2*a*b*math.cos(C)))
print(b*math.sin(C)) | 0 | null | 66,631,631,966,748 | 270 | 30 |
def main():
S, W = map(int, input().split())
print("safe" if W < S else "unsafe")
return
main()
| def main():
s,w = map(int,input().split())
if s <= w:
print('unsafe')
else:
print('safe')
main() | 1 | 29,076,838,121,706 | null | 163 | 163 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
def check(mid):
cnt = 0
for i in range(N):
tmp = mid // F[i]
cnt += max(A[i] - tmp, 0)
return cnt <= K
check(2)
l, r = -1, 10**30
while r-l > 1:
mid = (l+r)//2
if check(mid):
r = mid
else:
l = mid
print(r)
| n = int(input())
s = input()
if n % 2 == 1:
print('No')
else:
sa = s[:n//2]
sb = s[n//2:]
if sa == sb:
print('Yes')
else:
print('No') | 0 | null | 156,134,167,106,218 | 290 | 279 |
from functools import reduce
print(reduce(lambda a, b: 'a {} b'.format('<' if a < b else (
'>' if a > b else '==')),
map(int, input().split()))) | import operator
def poland(A):
l = []
ops = { "+": operator.add, "-": operator.sub, '*' : operator.mul }
for i in range(len(A)):
item = A.pop(0)
if item in ops:
l.append(ops[item](l.pop(-2),l.pop()))
else:
l.append(int(item))
return l.pop()
if __name__ == '__main__':
A = input().split()
print (poland(A[:])) | 0 | null | 198,129,736,060 | 38 | 18 |
# -*- coding:utf-8 -*-
n = int(input())
data = input()
data = data.split()
for i in range(len(data)):
data[i] = int(data[i])
sum = 0
for i in range(n):
sum += data[i]
print(min(data), max(data), sum, sep = ' ') | import sys
strs = sys.stdin.readlines()
for s in strs:
a, b = map(int, s.split())
print(len(str(a + b))) | 0 | null | 374,705,180,888 | 48 | 3 |
import sys
N = int(input())
S = input()
if N%2!=0 :
print("No")
sys.exit(0)
else:
for i in range(int(N/2)):
if S[i]!=S[i+int(N/2)]:
print("No")
sys.exit(0)
print("Yes") | import queue
h,w=map(int,input().split())
s=[]
for _ in range(h):
s.append(input())
ans=0
for i in range(h):
for j in range(w):
if s[i][j]==".":
seen=[[0 for _ in range(w)] for _ in range(h)]
length=[[0 for _ in range(w)] for _ in range(h)]
q=queue.Queue()
q.put([i,j])
seen[i][j]=1
while not q.empty():
ci,cj=q.get()
for ni,nj in [[ci-1,cj],[ci+1,cj],[ci,cj-1],[ci,cj+1]]:
if 0<=ni<h and 0<=nj<w and s[ni][nj]=="." and seen[ni][nj]==0:
q.put([ni,nj])
length[ni][nj]=length[ci][cj]+1
seen[ni][nj]=1
ans=max(ans,length[ci][cj])
print(ans) | 0 | null | 120,430,973,317,340 | 279 | 241 |
def main():
# r:ぐー,s:ちょき,p:ぱー
# 相手のn回目の手についてn%Kの値によってグループ分け
# 連続して同じ手を出せずに最高点を出す方法を知れば良い
# 最後に全てを足し合わせる
N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = input()
hands = [[] for i in range(K)]
for i in range(N):
if T[i]=='r': hands[i%K].append(0)
elif T[i]=='s': hands[i%K].append(1)
else: hands[i%K].append(2)
# 貪欲に前から勝てば良い..わけではなさそう
ans = 0
points = [R,S,P]
for i in range(K):
# dp[j][k] := j回目にkを出した時の最大得点
dp = [[0]*3 for _ in range(len(hands[i])+1)]
for j in range(len(hands[i])):
for k in range(3):
# kが勝ち手かどうかで場合分け
if hands[i][j]==(k+1)%3:
dp[j+1][k] = max(dp[j+1][k], dp[j][(k+1)%3]+points[k])
dp[j+1][k] = max(dp[j+1][k], dp[j][(k+2)%3]+points[k])
else:
dp[j+1][k] = max(dp[j+1][k], dp[j][(k+1)%3])
dp[j+1][k] = max(dp[j+1][k], dp[j][(k+2)%3])
ans += max(dp[-1])
print(ans)
main()
| def A():
a,b = list(map(int, input().split()))
print(a*b)
A() | 0 | null | 61,326,342,749,112 | 251 | 133 |
N = int(input())
xys = set([tuple(map(int, input().split())) for _ in range(N)])
z = []
w = []
for xy in xys:
z.append(xy[0]+xy[1])
w.append(xy[0]-xy[1])
#print(z)
#print(w)
print(max(abs(max(z) - min(z)), abs(max(w) - min(w)))) | N = int(input())
A = list(map(int,input().split()))
s = [0]*(N+1)
for i in range(N):
s[i+1] = s[i] + A[i]
cnt = 0
for j in range(N):
cnt = (cnt + (A[j]*(s[N] - s[j+1])))%(10**9+7)
print(cnt) | 0 | null | 3,597,319,334,350 | 80 | 83 |
N=input()
A=map(int,raw_input().split())
for i in range(N-1):
for k in range(N-1):
print A[k],
print A[N-1]
v=A[i+1]
j=i
while j>=0 and A[j] >v:
A[j+1]=A[j]
j=j-1
A[j+1]=v
for m in range(N-1):
print str(A[m]),
print A[N-1] | def selection_sort(numbers, n):
"""selection sort method
Args:
numbers: a list of numbers to be sorted
n: len(numbers)
Returns:
sorted numberd, number of swapped times
"""
counter = 0
for i in range(0, n - 1):
min_j = i
for j in range(i + 1, n):
if numbers[j] < numbers[min_j]:
min_j = j
if min_j != i:
numbers[min_j], numbers[i] = numbers[i], numbers[min_j]
counter += 1
return numbers, counter
length = int(raw_input())
numbers = [int(x) for x in raw_input().split()]
numbers, number_of_swapped_times = selection_sort(numbers, length)
print(" ".join([str(x) for x in numbers]))
print(number_of_swapped_times) | 0 | null | 13,080,844,700 | 10 | 15 |
s = int(input())
a = [0] * (s+1)
if s == 1:
print(0)
else:
a[0]=1
a[1]=0
a[2]=0
mod = 10**9+7
for i in range(3,s+1):
a[i] = a[i-1]+a[i-3]
print(int(a[s] % mod)) | s = int(input())
mod = 10 ** 9 + 7
dp = [1, 0, 0]
for _ in range(s - 2):
dp.append((dp[-1] + dp[-3]) % mod)
print(dp[s])
| 1 | 3,277,754,123,040 | null | 79 | 79 |
A,B,C = list(map(int,input().split(" ")))
print(C,A,B) | x = list(map(int,input().split()))
x[0],x[1] = x[1],x[0]
x[0],x[2] = x[2],x[0]
print(str(x[0]) +" " + str(x[1]) + " "+ str(x[2])) | 1 | 37,750,557,378,842 | null | 178 | 178 |
A, B, C = [int(v) for v in input().strip().split(" ")]
K = int(input().strip())
while K > 0:
if B <= A:
B *= 2
K -= 1
elif C <= B:
C *= 2
K -= 1
else:
break
if C > B > A:
print("Yes")
else:
print("No") | from collections import deque
def main():
d = deque()
for _ in range(int(input())):
command = input()
if command[0] == 'i':
d.appendleft(command[7:])
elif command[6] == ' ':
try:
d.remove(command[7:])
except ValueError:
pass
elif len(command) == 11:
d.popleft()
else:
d.pop()
print(*d)
if __name__ == '__main__':
main()
| 0 | null | 3,463,733,113,932 | 101 | 20 |
k = int(input())
a, b = map(int, input().split())
f = False
for i in range(a, b+1):
if i%k == 0:
print('OK')
f = True
break
if f is False:
print('NG')
|
n = int(input())
def isPrime(x):
if x < 2:
return false
if x == 2:
return True
return pow(2, x-1, x) == 1
s = []
for i in range(n):
s.append(int(input()))
prime = 0
for i in s:
if isPrime(i):
prime += 1
print(prime) | 0 | null | 13,335,975,170,902 | 158 | 12 |
n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(n):
l.append([a[i], i+1])
l = sorted(l)
ans = []
for j in range(n):
ans.append(str(l[j][1]))
print(" ".join(ans)) | A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[list(map(int,input().split()))for i in range(M)]
ans=min(a)+min(b)
for i in range(M):
tmp = a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2]
if ans > tmp:
ans=tmp
print(ans) | 0 | null | 117,288,725,702,468 | 299 | 200 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.