code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,629B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
import math
while True:
n = int(input());
if n == 0:
break;
A = list(map(int, input().split()));
h = sum(A) / len(A);
k = 0;
for j in range(0,n):
k += (A[j] - h)**2;
print(math.sqrt(k/n));
|
import math
n = int(input())
while (n != 0):
nlist = list(map(float, input().split()))
sum = 0
for i in range(n):
sum += nlist[i]
aver = sum/n
var = 0
for i in range(n):
var += (nlist[i] - aver)**2 / n
dev = math.sqrt(var)
print(dev)
n = int(input())
| 1 | 188,657,030,032 | null | 31 | 31 |
def shuffle(s,n):
if len(s) <= 1:
return s
ans = s[n:] + s[:n]
return ans
def main():
while True:
strings = input()
if strings == "-":
break
n = int(input())
li = []
for i in range(n):
li.append(int(input()))
for i in li:
strings = shuffle(strings, i)
print(strings)
if __name__ == "__main__":
main()
|
# -*- coding:utf-8 -*-
class Cards:
trump = [False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,False,]
def HaveCards(self,num):
self.trump[num] = True
def TransCards(self,s,num):
if(s == 'H'):
num += 13
elif(s == 'C'):
num +=26
elif(s == 'D'):
num += 39
return num
def CheckCards(self,num):
if(num <= 12):
return 'S' ,num+1
elif(num >= 13 and num <= 25):
return 'H' ,num-12
elif(num >= 26 and num <= 38):
return 'C',num-25
elif(num >= 39 and num <=51):
return 'D',num-38
n = int(input())
ob = Cards()
for i in range(n):
s,str_num = input().split()
number = int(str_num)
Num=ob.TransCards(s,number-1)
ob.HaveCards(Num)
for i in range(len(Cards.trump)):
if Cards.trump[i] == False:
Str,Num=ob.CheckCards(i)
print(Str,Num)
| 0 | null | 1,457,938,666,820 | 66 | 54 |
n=input()
print "",
for i in xrange(1,n+1):
if i%3==0 or '3' in str(i):
print i,
|
n = int(input())
for i in range(n):
if (i+1)%3==0:
print(" "+str(i+1), end="")
else:
x = i+1
while(x>0):
if x%10==3:
print(" "+str(i+1), end="")
break
else:
x = x//10
print("")
| 1 | 934,038,677,180 | null | 52 | 52 |
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
n, m, q = rl()
Q = []
for i in range(q):
Q.append(rl())
ways = [[i] for i in range(1, m + 1)]
for i in range(n - 1):
new_ways = []
for way in ways:
new_way = list(way)
for j in range(way[-1], m + 1):
new_ways.append(new_way + [j])
ways = new_ways
best = 0
for way in ways:
tot = 0
for a, b, c, d in Q:
if way[b - 1] - way[a - 1] == c:
tot += d
best = max(best, tot)
print (best)
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
|
A, B = [int(n) for n in input().split(" ")]
XstartA = A / 0.08
XendA = (A + 1) / 0.08
XstartB = B / 0.1
XendB = (B + 1) / 0.1
start = XstartA
if XstartA < XstartB:
start = XstartB
end = XendA
if XendB < XendA:
end = XendB
S = int(start)
E = int(end) + 1
ans = -1
for i in range(S, E + 1):
if start <= i and i < end:
ans = i
break
print(ans)
| 0 | null | 41,920,188,236,668 | 160 | 203 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
n = int(input())
r = 0
for i1 in range(1, n+1):
for i2 in range(1, n+1):
if i1 * i2 >= n:
break
else:
r += 1
print(r)
if __name__ == '__main__':
main()
|
def print8f(xy):
from decimal import Decimal, ROUND_HALF_UP
acc = Decimal("0.00000001")
x, y = xy
x = Decimal(str(x)).quantize(acc, rounding=ROUND_HALF_UP)
y = Decimal(str(y)).quantize(acc, rounding=ROUND_HALF_UP)
print("{:.8f} {:.8f}".format(x, y))
def kochCurve(p1p2, n, ang):
from math import sin, cos, radians, sqrt
if n == 0:
print8f(p1p2[1])
return
p1, p2 = p1p2
xd3 = (p2[0] - p1[0]) / 3
yd3 = (p2[1] - p1[1]) / 3
s = [p1[0] + xd3, p1[1] + yd3]
t = [p2[0] - xd3, p2[1] - yd3]
st = sqrt((s[0] - t[0])**2 + (s[1] - t[1])**2)
u = [s[0] + cos(radians(ang + 60)) * st,
s[1] + sin(radians(ang + 60)) * st]
kochCurve([p1, s], n - 1, ang)
kochCurve([s, u], n - 1, ang + 60)
kochCurve([u, t], n - 1, ang - 60)
kochCurve([t, p2], n - 1, ang)
def resolve():
n = int(input())
p1p2 = [[0, 0], [100, 0]]
print8f(p1p2[0])
kochCurve(p1p2, n, 0)
resolve()
| 0 | null | 1,353,517,987,442 | 73 | 27 |
i=0
while True:
N=int(input())
if N==0:
break
else:
a = list(map(float,input().split()))
m=sum(a)/N
#print(m)
for i in range(N):
a[i]=(float)(a[i]-m)**2
#print(a[i])
i+=1
A=(sum(a)/N)**(1/2)
print(A)
|
import math
while 1:
# input the students number
n = input()
if n == 0:
break
# input the points
s = map(float, raw_input().split())
# get the average of points
ave = 0
for i in s:
ave += i
ave = ave / len(s)
# get the standard deviation
alpha = 0
for i in s:
alpha += (i - ave)*(i - ave)
alpha = math.sqrt( alpha/len(s) )
# print
print alpha
| 1 | 194,854,898,954 | null | 31 | 31 |
s = input()
t = input()
result = [x != y for x, y in zip(s, t)]
print(sum(result))
|
import sys
input = sys.stdin.readline
def main():
s = input().rstrip('\n')
if s[-1] == 's':
s += 'es'
else:
s += 's'
print(s)
if __name__ == '__main__':
main()
| 0 | null | 6,496,839,824,160 | 116 | 71 |
h,w,k=map(int,input().split())
G=[["."]*w for i in range(h)]
for i in range(h):
G[i]=list(input())
ans=[[0]*w for i in range(h)]
GG=[[0] for i in range(h)]
for i in range(h):
for j in range(w):
if G[i][j]=="#":
GG[i].append(j)
GG[i].append(w)
B=[0]
a=1
for i in range(h):
if len(GG[i])==2:
continue
B.append(i)
ans[i][GG[i][0]:GG[i][2]]=[a]*(GG[i][2]-GG[i][0])
a=a+1
for j in range(len(GG[i])-3):
ans[i][GG[i][j+2]:GG[i][j+3]]=[a]*(GG[i][j+3]-GG[i][j+2])
a=a+1
B.append(h)
for i in range(B[2]-B[0]):
ans[i]=ans[B[1]]
for i in range(B[2],h):
if i not in B:
ans[i]=ans[i-1]
for i in range(h):
for j in range(w):
print(ans[i][j],end=" ")
print()
|
n = int(input())
al = list(map(int, input().split()))
al.sort(reverse=True)
ans = al[0]
for i in range(n-2):
ans += al[i//2+1]
print(ans)
| 0 | null | 76,190,621,654,940 | 277 | 111 |
N, M = map(int, input().split())
A = sum(map(int, input().split()))
if N-A >= 0:
print(N-A)
else:
print(-1)
|
n=int(input())
s = [input() for i in range(n)]
s.sort()
ans=n
for i in range(1,n):
if s[i]==s[i-1]:
ans-=1
print(ans)
| 0 | null | 31,077,030,303,898 | 168 | 165 |
def main():
import sys
from collections import deque
from operator import itemgetter
M=10**10
b=sys.stdin.buffer
n,d,a=map(int,b.readline().split())
m=map(int,b.read().split())
q=deque()
popleft,append=q.popleft,q.append
s=b=0
for x,h in sorted(zip(m,m),key=itemgetter(0)):
while q and q[0]//M<x:b-=popleft()%M
if h>b:
t=(b-h)//a
s-=t
t*=a
b-=t
append((x+d+d)*M-t)
print(s)
main()
|
from math import ceil
def binary(N,LIST,num): # 二分探索 # N:探索要素数
l, r = -1, N
while r - l > 1:
if LIST[(l + r) // 2] > num: # 条件式を代入
r = (l + r) // 2
else:
l = (l + r) // 2
return r + 1
n, d, a = map(int, input().split())
xh = sorted(list(map(int, input().split())) for _ in range(n))
x = [i for i, j in xh]
h = [j for i, j in xh]
bomb, bsum, ans = [0] * (n + 1), [0] * (n + 1), 0
for i, xi in enumerate(x):
j = binary(n, x, xi + 2 * d) - 1
bsum[i] += bsum[i - 1] + bomb[i]
bnum = max(ceil(h[i] / a - bsum[i]), 0)
bomb[i] += bnum
bomb[j] -= bnum
bsum[i] += bnum
ans += bnum
print(ans)
| 1 | 82,309,556,394,570 | null | 230 | 230 |
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import Counter
def resolve():
N, K, C = lr()
S = [i+1 for i, s in enumerate(sr()) if s == 'o']
l = [S[0]]
for i in S[1:]:
if l[-1]+C >= i or len(l) > K:
continue
l.append(i)
S = S[::-1]
r = [S[0]]
for i in S[1:]:
if r[-1]-C <= i or len(r) > K:
continue
r.append(i)
r = r[::-1]
for i in range(K):
if l[i] == r[i]:
print(l[i])
resolve()
|
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
s, w = rl()
if s > w:
print ("safe")
else:
print ("unsafe")
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
| 0 | null | 34,896,329,188,008 | 182 | 163 |
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n = ii()
A = iil()
sA = sum(A)
ans = float('inf')
l = [A[0]]
for i in A[1::]:
l.append(l[-1]+i)
if sA < 2*l[-1]:
print(min(abs(sA-2*l[-1]),abs(sA-2*l[-2])))
exit()
|
n = int(input())
a = list(map(int,input().split()))
l = sum(a)
half = 0
tmp=a[0]
while tmp<l/2:
half+=1
tmp+=a[half]
print(int(min(tmp-l/2,abs(tmp-a[half]-l/2))*2))
| 1 | 142,214,630,579,186 | null | 276 | 276 |
N,K = map(int,input().split())
if N % K >= abs(N % K - K):
print(abs(N % K - K))
else:
print(N % K)
|
N,K=map(int,input().split())
if N > K:
N %= K
ans = min(N, K-N)
print(ans)
| 1 | 39,259,174,171,648 | null | 180 | 180 |
#!/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 = 998244353
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def C(n, r):
return fact[n] * pow(fact[n-r], mod-2, mod) * pow(fact[r], mod-2, mod) % mod
n, m, k = LI()
fact = [1] * (n+1)
for i in range(1, n+1):
fact[i] = fact[i-1] * i
fact[i] %= mod
ans = 0
for i in range(k+1):
ans += C(n-1, i) * m * pow(m-1, n-1-i, mod)
ans %= mod
print(ans)
|
lines = input().split(' ')
x = int(lines[0])
y = int(lines[1])
print(x * y, (x + y) * 2)
| 0 | null | 11,738,673,894,752 | 151 | 36 |
# -*- coding: utf-8 -*-
x = int(input())
if x >= 30:
print('Yes')
else:
print('No')
|
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
for _ in range(K):
flg = True
imos = [0]*(N+1)
for i in range(N):
imos[max(0, i-A[i])] += 1
imos[min(N, i+A[i]+1)] -= 1
A = [0]*N
c = 0
for i in range(N):
c += imos[i]
A[i] = c
if c != N:
flg = False
if flg is True:
print(*([N]*N), sep=' ')
exit()
print(*A)
| 0 | null | 10,667,952,507,520 | 95 | 132 |
def main():
n=int(input())
d=[0]+[-10**18]*n
for j,(a,i)in enumerate(sorted((-a,i)for i,a in enumerate(map(int,input().split())))):
d=[max(t-a*abs(~i-j+k+n),d[k-1]-a*abs(~i+k))for k,t in enumerate(d)]
print(max(d))
main()
|
#!/usr/bin/env python3
import sys
import itertools
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
AA = [(a, i) for i, a in enumerate(A, start=1)]
AA.sort(reverse=True)
# print(AA)
DP = [[0]*(N+1) for _ in range(N+1)]
for wa in range(1, N+1):
# AA[:wa]までを考える
for x in range(wa+1):
y = wa - x
a, i = AA[wa-1]
if x - 1 >= 0:
DP[x][y] = max(DP[x][y], DP[x-1][y]+a*(i-x))
if y - 1 >= 0:
DP[x][y] = max(DP[x][y], DP[x][y-1]+a*(N-y-i+1))
# print(wa, (x, y), (a, i), DP[x][y])
M = -INF
for x in range(N):
y = N-x
M = max(DP[x][y], M)
print(M)
| 1 | 33,654,860,507,392 | null | 171 | 171 |
n = input()
s = list(map(str, input().split()))
news = ""
for i in range(int(n)):
news += s[0][i] + s[1][i]
print(news)
|
N=int(input())
S,T=map(str,input().split())
def ans148(N:int, S:str, T:str):
newstr=""
for i in range(0,N):
newstr=newstr+S[i]+T[i]
return newstr
print(ans148(N,S,T))
| 1 | 112,236,238,848,580 | null | 255 | 255 |
import sys
readline = sys.stdin.buffer.readline
s =readline().rstrip().decode()
t =readline().rstrip().decode()
if t[:-1] == s:
print('Yes')
else:
print('No')
|
s=str(input())
t=str(input())
n=len(s)
ans=0
for i in range(n):
if s[i]==t[i]:
ans+=1
print(n-ans)
| 0 | null | 15,903,971,200,612 | 147 | 116 |
while True:
try:
a, b = list(map(int, input().split()))
print(len(str(a + b)))
except EOFError:
break
except ValueError:
break
|
# -*- coding: utf-8 -*-
n = int(input())
s = input()
ans = 1
tmp = s[0]
for c in s:
if tmp != c:
ans += 1
tmp = c
print(ans)
| 0 | null | 85,213,093,180,530 | 3 | 293 |
n, k = map(int,input().split())
have = [False] * n
for _ in range(k):
d = input()
a = list(map(lambda x: int(x)-1, input().split()))
for x in a:
have[x] = True
print(have.count(False))
|
N, K = map(int, input().split())
have_sweets = []
for i in range(K):
d = int(input())
have_sweets += list(map(int, input().split()))
have_sweets = set(have_sweets)
print(len(list(set([i for i in range(1, N+1)])-have_sweets)))
| 1 | 24,765,026,813,030 | null | 154 | 154 |
n = int(input())
print(0 if n % 1000 == 0 else 1000 - n % 1000)
|
N,M = map(int,input().split())
C = list(map(int,input().split()))
INF = float('inf')
dp = [INF] * (N+1)
dp[0] = 0
for i in range(M):
c = C[i]
for j in range(N+1):
if j >= c:
dp[j] = min(dp[j], dp[j-c]+1)
print(dp[N])
| 0 | null | 4,274,344,364,990 | 108 | 28 |
import math
class Pos:
def init(x, y):
self.x = x
self.y = y
def kock(n, p1, p2):
if n == 0: return
s, t = Pos(), Pos()
s.x = (2 * p1.x + 1 * p2.x) / 3
s.y = (2 * p1.y + 1 * p2.y) / 3
t.x = (1 * p1.x + 2 * p2.x) / 3
t.y = (1 * p1.y + 2 * p2.y) / 3
cos60 = math.cos(math.radians(60))
sin60 = math.sin(math.radians(60))
u = Pos()
u.x = (t.x - s.x) * cos60 - (t.y - s.y) * sin60 + s.x
u.y = (t.x - s.x) * sin60 + (t.y - s.y) * cos60 + s.y
kock(n-1, p1, s)
print("{:.5f} {:.5f}".format(s.x, s.y))
kock(n-1, s, u)
print("{:.5f} {:.5f}".format(u.x, u.y))
kock(n-1, u, t)
print("{:.5f} {:.5f}".format(t.x, t.y))
kock(n-1, t, p2)
n = int(input())
p1, p2 = Pos(), Pos()
p1.x, p1.y = 0.0, 0.0
p2.x, p2.y = 100.0, 0.0
print("{:.5f} {:.5f}".format(p1.x, p1.y))
kock(n, p1, p2)
print("{:.5f} {:.5f}".format(p2.x, p2.y))
|
def koch(d,p0,p1):
#終了条件
if d == n:
return
#内分点:s,t
s=[(2*p0[0]+p1[0])/3,(2*p0[1]+p1[1])/3]
t=[(2*p1[0]+p0[0])/3,(2*p1[1]+p0[1])/3]
#正三角形の頂点:u
u=[(p0[0]+p1[0])/2-(p1[1]-p0[1])*(3**(1/2)/6),(p1[1]+p0[1])/2+(p1[0]-p0[0])*(3**(1/2)/6)]
koch(d+1,p0,s)
print(*s)
# point.append(s)
koch(d+1,s,u)
print(*u)
# point.append(u)
koch(d+1,u,t)
print(*t)
# point.append(t)
koch(d+1,t,p1)
p0=[0,0]
p1=[100,0]
n=int(input())
print(*p0)
koch(0,p0,p1)
print(*p1)
| 1 | 128,699,366,438 | null | 27 | 27 |
# coding: utf-8
x = int(input())
ans = x // 500
x = x - ans * 500
ans = ans * 1000
ans += (x // 5 * 5)
print(ans)
|
import math
A, B, H, M = map(int,input().split())
#時針:0.5°/min
#分針:6.0°/min
print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(5.5 * (H * 60 + M) * math.pi / 180 )))
| 0 | null | 31,555,553,797,518 | 185 | 144 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
dp = [[1<<60]*(N+1) for _ in range(M+1)]
dp[0][0] = 0
for i in range(M):
for j in range(N+1):
if A[i] <= j:
dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i]] + 1)
else:
dp[i + 1][j] = dp[i][j]
print(dp[M][N])
|
N,M,Q = map(int, input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
a[i], b[i], c[i], d[i] = map(int, input().split())
def dfs(n_list, o, l, L):
if o+l==0:
num = 1
pos = 0
L_child = [0]*N
for i in range(N+M-1):
if n_list[i]==1:
num += 1
else:
L_child[pos] = num
pos += 1
L.append(L_child)
if o>=1:
n_list[N+M-o-l-1] = 0
dfs(n_list, o-1,l, L)
if l>=1:
n_list[N+M-o-l-1] = 1
dfs(n_list, o, l-1, L)
A = [0]*(N+M-1)
L =[]
dfs(A,N,M-1,L)
ans = 0
for i in L:
score = 0
for j in range(Q):
if i[b[j]-1]-i[a[j]-1]==c[j]:
score += d[j]
if score > ans:
ans = score
print(ans)
| 0 | null | 13,891,243,542,400 | 28 | 160 |
R, G, B = map(int, input().split())
K = int(input())
cnt = 0
while not(R < G):
G *= 2
cnt += 1
while not(G < B):
B *= 2
cnt += 1
if cnt <= K:
print('Yes')
else:
print('No')
|
a, b, c = map(int,input().split(' '))
k = int(input())
while k > 0:
if c <= b:
c *= 2
elif b <= a:
b *= 2
k -= 1
if a < b and b < c:
print('Yes')
break
else:
print('No')
| 1 | 6,938,090,455,572 | null | 101 | 101 |
H = int(input())
W = int(input())
N = int(input())
m = max(H, W)
ans = int((N - 1) / m) + 1
print(ans)
|
n = int(input())
A = list(map(int ,input().split()))
total = 0
for a in A:
total ^= a
print(*(total ^ a for a in A), sep='\n')
| 0 | null | 50,878,347,286,768 | 236 | 123 |
#%%
from collections import Counter
n = input()
d = list(map(int, input().split()))
#%%
d_cnt =Counter(d)
d_cnt = dict(d_cnt)
d_cnt_keys = list(d_cnt.keys())
d_cnt_keys.sort()
if d[0] != 0 or d_cnt[0] != 1 or len(d_cnt_keys)!= d_cnt_keys[-1]+1:
print(0)
exit()
#%%
ans = 1
p = 998244353
for key in d_cnt_keys:
if key == 0:
continue
ans =ans*pow(d_cnt[key-1], d_cnt[key],p)%p
print(ans)
|
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
cnt = [0] * N
for i in range(N):
cnt[D[i]] += 1
if D[0] != 0 or cnt[0] > 1:
print(0)
exit()
ans = 1
for i in range(1, max(D) + 1):
ans = (ans * pow(cnt[i - 1], cnt[i], MOD)) % MOD
print(ans)
| 1 | 155,610,530,200,708 | null | 284 | 284 |
h = int(input())
p = 1
i = 1
while h > 1:
h = h // 2
p += 2 ** i
i += 1
print(p)
|
from sys import stdin
input = stdin.readline
def rec(H):
if H == 1:
return 1
# print(H)
return 1 + 2*rec(int(H/2))
def main():
H = int(input())
print(rec(H))
if(__name__ == '__main__'):
main()
| 1 | 80,291,469,228,650 | null | 228 | 228 |
print('Yes' if "7" in input() else 'No')
|
# coding: utf-8
#import math
#import numpy
#N = int(input())
def main():
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
A = list(map(int,input().split()))
#K =int(input())
ANS = []
#ANS.append(a)
for i in range(K,N):
if A[i-K] < A[i]:
print("Yes")
else:
print("No")
#ANS.append(a)
#print(ANS)
if __name__ == '__main__':
main()
| 0 | null | 20,718,230,711,530 | 172 | 102 |
#!/usr/bin/env python3
import sys
import math
a, b = map(int, input().split())
c = math.ceil(b / 0.1)
for i in range(c, c + 10):
if math.floor(i * 0.1) == b:
if math.floor(i * 0.08) == a:
print(i)
sys.exit()
print(-1)
|
A, B = [int(i) for i in input().split()]
# たかだか1250円
for i in range(1300):
a = (i * 8) // 100
b = i //10
if A == a and B == b:
print(i)
exit()
print(-1)
| 1 | 56,463,851,890,930 | null | 203 | 203 |
def solve(x):
if x >= 30:
return "Yes"
else:
return "No"
def main():
x = int(input())
res = solve(x)
print(res)
def test():
assert solve(25) == "No"
assert solve(30) == "Yes"
if __name__ == "__main__":
test()
main()
|
n = int(input())
lr_cnt = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, n + 1):
str_i = str(i)
start = int(str_i[0])
end = int(str_i[-1])
lr_cnt[start][end] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += lr_cnt[i][j] * lr_cnt[j][i]
print(ans)
| 0 | null | 46,180,133,478,710 | 95 | 234 |
i=0
while True:
i+=1
a=input()
if a==0:
break
else:
print("Case "+str(i)+": "+str(a))
|
#coding: UTF-8
l = raw_input()
a = int(l)
x = 1
while a != 0:
print "Case %d: %d" %(x,a)
x += 1
l = raw_input()
a = int(l)
if l == 0:
print "end"
| 1 | 474,013,479,610 | null | 42 | 42 |
n = int(input())
r = -10000000000
y = int(input())
m = y
x = y
for i in range(1, n):
x = int(input())
if r < (x - m):
r = (x - m)
if x < m:
m = x
print(r)
|
n = int(input())
lst = []
for i in range(n):
x, l = map(int, input().split())
left = x - l
right = x + l
lst.append([left, right])
lst = sorted(lst, key=lambda x: x[1])
ans = 1
limit = lst[0][1]
for i in range(n):
if lst[i][0] >= limit:
ans += 1
limit = lst[i][1]
print(ans)
| 0 | null | 44,976,086,265,934 | 13 | 237 |
def resolve():
N, K = list(map(int, input().split()))
ans = 0
mini = sum(range(K))
maxi = sum(range(N, N-K, -1))
for i in range(K, N+2):
ans += maxi - mini + 1
ans %= 10**9+7
mini += i
maxi += N - i
print(ans)
if '__main__' == __name__:
resolve()
|
# 10^100のクソデカ数値がクソデカすぎるため、+0,+1..+Nが束になってもいたくも痒くもない
# なのでもはや無視していい
# 最初の例でいうと、2つ選ぶのは[0,1,2,3]からなので、和のバリエーションは最小値1~最大値5の5つ
# 3つ選ぶのは最小値3~最大値6の4つ
# 4つ選ぶのは1つ
# 毎回最大値と最小値を計算して差+1を加えてやるとできあがり
# 計算には数列の和を使う
n, k = map(int, input().split())
mod = 10**9 + 7
ans = 1
for i in range(k, n + 1):
# 初項0,公差1,末項i-1までの和
min_s = i * (i - 1) // 2
# 初項n+1-i, 公差1, 末項i-1までの和
max_s = i * (2 * (n + 1 - i) + (i - 1)) // 2
ans += max_s - min_s + 1
ans %= mod
print(ans)
| 1 | 33,176,738,045,000 | null | 170 | 170 |
a = int(input())
print(a*a*a)
|
num = int(input())
print("{0}".format(num**3))
| 1 | 277,543,494,698 | null | 35 | 35 |
import copy
H, W, K, = list(map(int, input().split()))
C = [0] * H
for i in range(H):
C[i] = input()
C[i] = [1 if(C[i][j] == "#") else 0 for j in range(W)]
h = 2 ** H
w = 2 ** W
ans = 0
for i in range(2 ** H):
w = 2 ** W
for j in range(2 ** W):
D = copy.deepcopy(C)
for k in range(H):
for l in range(W):
if(bin(h)[k + 3] == "1" or bin(w)[l + 3] == "1"):
D[k][l] = 0
ans += (sum(map(sum, D)) == K)
w += 1
h += 1
print(ans)
|
import itertools
a,b,c=map(int, input().split())
l = [input() for i in range(a)]
ans = 0
Ans = 0
for i in itertools.product((1,-1),repeat=a):
for j in itertools.product((1,-1),repeat=b):
for k in range(a):
for m in range(b):
if i[k] == j[m] == 1 and l[k][m] == '#':
ans += 1
if ans == c:
Ans += 1
ans = 0
print(Ans)
| 1 | 8,935,417,186,560 | null | 110 | 110 |
def main():
string_s = input()
string_p = input()
print('Yes') if string_p in (string_s + string_s) else print('No')
main()
|
s = str(raw_input())
p = str(raw_input())
i = 0
while(1):
if i == len(s):
print "No"
break
if i+len(p) >= len(s):
str = s[i:len(s)] + s[0:len(p)-len(s[i:len(s)])]
else:
str = s[i:i+len(p)]
if str == p:
print "Yes"
break
else:
i += 1
| 1 | 1,742,354,865,192 | null | 64 | 64 |
n,a,b = map(int, input().split())
ans = (b-a)//2
if (b-a)%2 == 1:
ans += 1 + min(a-1,n-b)
print(ans)
|
import sys
n=int(input())
for i in range(n):
list=input().split()
list=[int(j) for j in list]
list.sort()
if list[0]*list[0]+list[1]*list[1]==list[2]*list[2]:
print("YES")
else:print("NO")
| 0 | null | 55,019,594,538,776 | 253 | 4 |
#!/usr/bin/env python3
a, b, c = map(int, input().split())
print("YNeos"[c - a - b < 0 or 0 <= 4 * a * b - (a + b - c)**2::2])
|
n = int(input())
lst = { input() for i in range(n) }
print(len(lst))
| 0 | null | 40,896,783,394,148 | 197 | 165 |
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
def countstep(a):
i = 0
while a>=i+1:
i += 1
a -= i
return i
def main():
n = int(input())
a = factorization(n)
if n==1:
print(0)
return
if a[0][0]==0:
print(0)
else:
count = 0
for i in range(len(a)):
count += countstep(a[i][1])
print(count)
if __name__ == "__main__":
main()
|
P = [1 for _ in range(10**6)]
P[0]=0
P[1]=0
for i in range(2,10**3):
for j in range(i*i,10**6,i):
P[j] = 0
Q = []
for i in range(2,10**6):
if P[i]==1:
Q.append(i)
N = int(input())
C = {}
for q in Q:
if N%q==0:
C[q] = 0
while N%q==0:
N = N//q
C[q] += 1
if N>1:
C[N] = 1
cnt = 0
for q in C:
k = C[q]
n = 1
while k>(n*(n+1))//2:
n += 1
if k==(n*(n+1))//2:
cnt += n
else:
cnt += n-1
print(cnt)
| 1 | 16,953,215,970,420 | null | 136 | 136 |
n = int(input())
p = list(map(int,input().split()))
mini = 10**9
ans =0
for i in range(n):
if p[i] <= mini:
mini = p[i]
ans += 1
print(ans)
|
N,*a = map(int,open(0).read().split())
max_num = a[0]
count = 0
for i in a:
if max_num>=i:
count+=1
max_num = min(i,max_num)
print(count)
| 1 | 85,878,689,865,990 | null | 233 | 233 |
n = int(input())
p = list(map(int, input().split()))
p.sort(reverse=True)
#追加していく際に追加した数の両脇を固める
s = 0
for i in range(1,n):
s += p[i//2]
print(s)
|
import sys
def div(x, y):
if x % y == 0:
print y
else:
div(y, x%y)
line = sys.stdin.readline()
x, y = line.split(" ")
x = int(x)
y = int(y)
if x < y:
x, y = y, x
if x == y:
print x
else:
div(x, y)
| 0 | null | 4,649,051,034,278 | 111 | 11 |
n = int(input())
al = list(map(int, input().split()))
if n == 1 and al[0] == 1:
print(0)
else:
i, j, num, ans = 0, 0, 1, 0
while i < n:
if al[i] != num:
i += 1
else:
ans += i-j
j = i+1
num += 1
i += 1
# print(i, j, ans)
if num != 1 and j != n:
ans += i-j
if num == 1:
print(-1)
else:
print(ans)
|
import math
val = str(input()).split()
numList = list(map(float, list(val)))
print(math.sqrt(((numList[2]-numList[0]) ** 2) + ((numList[3]-numList[1]) ** 2)))
| 0 | null | 57,269,653,368,070 | 257 | 29 |
_n = int(raw_input())
_a = [int(x) for x in raw_input().split()]
for i in range(1, _n):
print(" ".join([str(x) for x in _a]))
key = _a[i]
j = i - 1
while j >= 0 and _a[j] > key:
_a[j+1] = _a[j]
j -= 1
_a[j+1] = key
print(" ".join([str(x) for x in _a]))
|
h, w = map(int, input().split())
if h==1 or w == 1:
print(1)
else:
ans = h * w //2 + (h*w)%2
print(ans)
| 0 | null | 25,311,489,439,808 | 10 | 196 |
L = int(input())
a = L/3
m = a*a*a
print(m)
|
#!/usr/bin/env python3
n = int(input())
n /= 3
print(n**3)
| 1 | 47,031,473,466,472 | null | 191 | 191 |
from collections import deque
n, m = map(int, input().split())
INF = 1000000
to_room = [[] for _ in range(n + 1)]
for i in range(m):
a, b = map(int, input().split())
to_room[a].append(b)
to_room[b].append(a)
dp = [INF] * (n + 1)
dp[1] = 0
seen_room = deque()
seen_room.append(1)
ans = [0] * (n + 1)
while seen_room:
v = seen_room.popleft()
for next in to_room[v]:
if dp[next] <= dp[v] + 1:
continue
dp[next] = dp[v] + 1
ans[next] = v
seen_room.append(next)
# print(seen_room)
# print(to_room)
# print(dp)
if 0 in ans[2:]:
print("No")
else:
print("Yes")
for a in ans[2:]:
print(a)
|
from collections import defaultdict
def main():
height, width, target_count = [int(x) for x in input().split()]
count_by_height = defaultdict(int)
count_by_width = defaultdict(int)
bomb_locations = set()
for _ in range(target_count):
h, w = [int(x) - 1 for x in input().split()]
count_by_height[h] += 1
count_by_width[w] += 1
bomb_locations.add((h, w))
max_h = max(v for v in count_by_height.values())
max_w = max(v for v in count_by_width.values())
max_h_rows = [i for i, x in count_by_height.items() if x == max_h]
max_w_columns = [i for i, x in count_by_width.items() if x == max_w]
all_crossing_bomb = all((h, w) in bomb_locations
for h in max_h_rows for w in max_w_columns)
return max_h + max_w - all_crossing_bomb
if __name__ == '__main__':
print(main())
| 0 | null | 12,711,188,297,520 | 145 | 89 |
def gen(n):
g = '#.'
while True:
yield g[n%2]
n += 1
while True:
H, W = map(int, raw_input().split())
if H == 0 and W == 0:
break
for i in xrange(H):
g = gen(i)
print ''.join([g.next() for j in xrange(W)])
print
|
from itertools import permutations
N = int(input())
XY = []
for _ in range(N):
x, y = map(int, input().split())
XY.append((x, y))
ans = 0
c = 0
for p in permutations(range(N)):
dist = 0
x1, y1 = XY[p[0]]
for i in p[1:]:
x, y = XY[i]
dist += ((x1 - x) ** 2 + (y1 - y) ** 2) ** 0.5
ans += dist
c += 1
print(ans / c)
| 0 | null | 74,546,327,911,650 | 51 | 280 |
r,c,k = map(int, input().split())
rckl = [ [0]*c for _ in range(r) ]
for _ in range(k):
r_,c_,v_ = map(int, input().split())
rckl[r_-1][c_-1] = v_
dp0 = [ [0]*c for _ in range(r) ]
dp1 = [ [0]*c for _ in range(r) ]
dp2 = [ [0]*c for _ in range(r) ]
dp3 = [ [0]*c for _ in range(r) ]
dp1[0][0] = rckl[0][0]
for i in range(r):
for j in range(c):
if j+1 < c:
dp0[i][j+1] = max(dp0[i][j], dp0[i][j+1])
dp1[i][j+1] = max(dp1[i][j], dp1[i][j+1])
dp2[i][j+1] = max(dp2[i][j], dp2[i][j+1])
dp3[i][j+1] = max(dp3[i][j], dp3[i][j+1])
if rckl[i][j+1] > 0:
v = rckl[i][j+1]
dp1[i][j+1] = max(dp1[i][j+1], dp0[i][j] + v)
dp2[i][j+1] = max(dp2[i][j+1], dp1[i][j] + v)
dp3[i][j+1] = max(dp3[i][j+1], dp2[i][j] + v)
if i+1 < r:
dp0[i+1][j] = max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j], dp0[i+1][j])
if rckl[i+1][j] > 0:
v = rckl[i+1][j]
dp1[i+1][j] = max(dp1[i+1][j], dp0[i][j]+v, dp1[i][j]+v, dp2[i][j]+v, dp3[i][j]+v)
ans = max(dp0[-1][-1], dp1[-1][-1], dp2[-1][-1], dp3[-1][-1])
print(ans)
|
N = int(input())
for x in range(1,10):
for y in range(1,10):
if x * y == N:
print('Yes')
exit()
print('No')
| 0 | null | 82,592,874,458,500 | 94 | 287 |
n = input()
print pow(n, 3)
|
cube = input()
print(cube**3)
| 1 | 278,729,006,048 | null | 35 | 35 |
import sys
n = int(sys.stdin.buffer.readline())
z, w = [0]*n, [0]*n
for i, a in enumerate(sys.stdin.buffer.readlines()):
x, y = map(int, a.split())
z[i] = x+y
w[i] = x-y
print(max(abs(max(z)-min(z)), abs(max(w)-min(w))))
|
def insertion_sort(A):
n = len(A)
print(*A)
for i in range(1, n):
item = A[i]
cur_idx = i - 1
while cur_idx >= 0 and A[cur_idx] > item:
A[cur_idx], A[cur_idx + 1] = A[cur_idx + 1], A[cur_idx]
cur_idx -= 1
print(*A)
if __name__ == "__main__":
N = int(input())
A = [int(elem) for elem in input().split()]
insertion_sort(A)
| 0 | null | 1,725,943,787,520 | 80 | 10 |
def sample(n):
return n * n * n
n = input()
x = sample(n)
print x
|
n, k = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
prev = 0
count = 0
used = {prev: count}
for _ in range(min(k, n)):
prev = A[prev]
count += 1
if prev in used:
for _ in range((k - used[prev]) % (count - used[prev])):
prev = A[prev]
break
used[prev] = count
print(prev + 1)
| 0 | null | 11,469,438,548,160 | 35 | 150 |
n = int(input())
nums = [0]*n
a = int(n**0.5)+1
for x in range(1,a):
for y in range(1,a):
if x**2 + y**2 + x*y > n: break
for z in range(1,a):
s = x**2 + y**2 + z**2 + x*y + y*z + z*x
if s <= n: nums[s-1] += 1
print(*nums, sep="\n")
|
k = int(input())
a, b = map(int, input().split())
range_max = int(b / k) * k
if range_max >= a:
print('OK')
else:
print('NG')
| 0 | null | 17,135,105,650,080 | 106 | 158 |
n, k = map(int, input().split())
m = 0
while True:
m += 1
if k**m > n:
print(m)
break
|
from math import log
n, k = map(int, input().split())
print(int(log(n, k)) + 1)
| 1 | 64,777,093,207,528 | null | 212 | 212 |
n = int(input())
G = {i:[] for i in range(1, n+1)}
for _ in range(n):
ukv = list(map(int, input().split()))
u = ukv[0]
k = ukv[1]
for i in range(2, 2+k):
G[u].append(ukv[i])
d = [-1 for _ in range(n+1)]
f = [-1 for _ in range(n+1)]
counter = 0
def dfs(n):
global counter
counter += 1
d[n] = counter
for n_i in G[n]:
if d[n_i]==-1:
dfs(n_i)
counter += 1
f[n] = counter
for i in range(1, n+1):
if d[i]==-1:
dfs(i)
for id_i, (d_i, f_i) in enumerate(zip(d[1:], f[1:]), 1):
print(id_i, d_i, f_i)
|
d_num = int(input())
graph = [[] for _ in range(d_num+1)]
for _ in range(d_num):
u, k, *neighbors = map(int, input().split())
graph[u] = neighbors
visited = set()
timestamps = [None for _ in range(d_num+1)]
def dfs(u, stmp):
visited.add(u)
entry = stmp
stmp += 1
for v in graph[u]:
if v not in visited:
stmp = dfs(v, stmp)
timestamps[u] = entry, stmp
return stmp+1
stmp = 1
for v in range(1, d_num+1):
if v not in visited:
stmp = dfs(v, stmp)
for num, (entry, leave) in enumerate(timestamps[1:], 1):
print(num, entry, leave)
| 1 | 2,629,713,440 | null | 8 | 8 |
import sys
from collections import deque
N = int(input())
edge = [[] for _ in range(N)]
for i, s in enumerate(sys.stdin.readlines()):
a, b = map(int, s.split())
a -= 1; b -= 1
edge[a].append((b, i))
edge[b].append((a, i))
path = [None] * (N - 1)
q = deque()
q.append((0, 0))
while q:
v, pc = q.popleft()
c = 1
for nv, i in edge[v]:
if path[i] is None:
c = c + 1 if c == pc else c
path[i] = c
q.append((nv, c))
c += 1
print(max(path))
print(*path, sep='\n')
|
N = int(input())
ad = {}
status = {}
edge=[]
for n in range(N):
ad[n+1]=set([])
status[n+1] = -1
for n in range(N-1):
a,b = list(map(int,input().split()))
edge.append((a,b))
ad[a].add(b)
ad[b].add(a)
color = set([])
parent = [0] * (N+1)
ans={}
#BFS
from collections import deque
start = 1
status[start] = 0
que = deque([start])
while len(que) > 0:
start = que[0]
# print(start,parent[start])
c = 1
for v in ad[start]:
if status[v] == -1:
que.append(v)
status[v]=0
if parent[start] == c:
c += 1
parent[v] = c
color.add(c)
s = min(start,v)
e = max(start,v)
ans[s,e]=c
c+=1
# print(parent,que)
que.popleft()
print(len(color))
for e in edge:
print(ans[e])
| 1 | 136,685,380,260,130 | null | 272 | 272 |
def magic(a,b,c,k):
for i in range(k):
if(a>=b):
b*=2
elif(b>=c):
c*=2
if(a < b and b < c):
print("Yes")
else:
print("No")
d,e,f = map(int,input().split())
j = int(input())
magic(d,e,f,j)
|
A, B, C = map(int, input().split())
K = int(input())
for _ in range(K):
if A >= B:
B *= 2
elif B >= C:
C *= 2
if A < B < C:
print('Yes')
else:
print('No')
| 1 | 6,916,167,434,048 | null | 101 | 101 |
x = 1
y = 1
for x in range(9):
for y in range(9):
print((x+1),"x",(y+1),"=",(x+1)*(y+1),sep="")
y = y + 1
x = x + 1
|
for i in range(1,10):
for j in range(1,10):
print("{0}{1}{2}{3}{4}".format(i,"x",j,"=",i*j))
| 1 | 103,378 | null | 1 | 1 |
n,k = map(int,input().split())
mod = 10**9+7
from itertools import accumulate
N = list(range(n+1))
N_acc = [0]+list(accumulate(N))
ans = 0
for i in range(k,n+2):
ans += ((N_acc[-1]-N_acc[-i-1])-N_acc[i]+1)%mod
print(ans%mod)
|
while(1):
H, W = map(int, input().split())
if H==0 and W==0:
break
line = ""
for w in range(W):
line += "#"
for h in range(H):
print(line)
print("")
| 0 | null | 17,056,806,275,460 | 170 | 49 |
R, C, K = map(int, input().split())
item = {}
for _ in range(K):
r, c, v = map(int, input().split())
item[(r, c)] = v
dp = [[0] * 4 for _ in range(3010)]
ndp = [[0] * 4 for _ in range(3010)]
for r in range(1, R+1):
for c in range(1, C+1):
prer = max(dp[c])
ndp[c][0] = max(prer, ndp[c-1][0])
ndp[c][1] = max(prer, ndp[c-1][1])
ndp[c][2] = max(prer, ndp[c-1][2])
ndp[c][3] = max(prer, ndp[c-1][3])
if item.get((r, c)):
ndp[c][1] = max(ndp[c][1], max(prer, ndp[c-1][0]) + item[(r,c)])
ndp[c][2] = max(ndp[c][2], max(prer, ndp[c-1][1]) + item[(r,c)])
ndp[c][3] = max(ndp[c][3], max(prer, ndp[c-1][2]) + item[(r,c)])
dp = ndp
ndp = [[0] * 4 for _ in range(3010)]
#print(dp)
print(max(dp[C]))
|
S = input()
print('Yes' if S[2] == S[3] and S[4] == S[5] else 'No')
| 0 | null | 23,905,293,324,452 | 94 | 184 |
k, y = [int(i) for i in input().split()]
print('Yes' if 500 * k >= y else 'No')
|
import math
a=int(input())
b=int(input())
x=int(input())
print(math.ceil(x/max(a,b)))
| 0 | null | 93,732,870,541,410 | 244 | 236 |
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
from cmath import pi, rect
sys.setrecursionlimit(10**7)
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
A,B,H,M = LI()
H += M / 60
H = H/12 * 2*pi
M = M/60 * 2*pi
# 余弦定理
l = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(H-M) )
# 複素数座標 Aexp(iθ)
zA = A * np.exp(H*1j)
zB = B * np.exp(M*1j)
l=abs(zA - zB)
print(l)
|
import math
A, B, H, M = map(int, input().split())
wa = 360/12
wb = 360/1
t = H + M/60
theta = math.radians((wa*t)%360 - (wb*t)%360)
print(math.sqrt(A**2 + B**2 -2*A*B*math.cos(theta)))
| 1 | 20,112,571,873,618 | null | 144 | 144 |
H, A = map(int, input().split())
ans = int(H/A)
if (H%A) != 0:
ans += 1
print(ans)
|
N = int(input())
dct = {}
for i in range(N):
s = input()
if not s in dct:
dct[s] = 1
else:
dct[s] += 1
m = max(dct.values())
for s in sorted(k for k in dct if dct[k] == m):
print(s)
| 0 | null | 73,732,312,987,722 | 225 | 218 |
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
def main():
K = I()
ans = 0
for i in range(1, K+1):
for j in range(1, K+1):
for k in range(1, K+1):
ans += math.gcd(math.gcd(i, j), k)
print(ans)
main()
|
# Nを1位上9以下の2つの整数の積として表せるならYes,できないならNo
N = int(input())
for i in range(1, 9+1):
if N%i == 0 and N//i <= 9:
print('Yes')
exit()
print('No')
| 0 | null | 97,630,808,090,048 | 174 | 287 |
from sys import stdin,stdout
st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")
mod=1000000007
INF=float('inf')
for _ in range(1):
s=st()
if s[-1]=='s':
print(''.join(s)+'es')
else:
print(''.join(s)+'s')
|
print(int(not int(input())))
| 0 | null | 2,675,991,150,782 | 71 | 76 |
# -*- coding: utf-8 -*-
def bubble_sort(c):
c = list(c)
for i in range(len(c)):
for j in range(len(c)-1, i, -1):
if int(c[j][1]) < int(c[j-1][1]):
c[j], c[j-1] = c[j-1], c[j]
return c
def selection_sort(c):
c = list(c)
for i in range(len(c)):
minj = i
for j in range(i+1, len(c)):
if int(c[j][1]) < int(c[minj][1]):
minj = j
c[i], c[minj] = c[minj], c[i]
return c
input_num = int(input())
input_list = input().split()
bubble_list = bubble_sort(input_list)
selection_list = selection_sort(input_list)
for c in bubble_list:
print(c, end='')
if c != bubble_list[len(bubble_list)-1]:
print(' ', end='')
print("\nStable")
stable_flg = True
for i in range(len(input_list)):
if bubble_list[i] != selection_list[i]:
stable_flg = False
print(selection_list[i], end='')
if i < len(input_list)-1:
print(" ", end='')
if stable_flg:
print("\nStable")
else:
print("\nNot stable")
|
def fibonacci(i, num_list):
if i == 0 or i == 1:
num_list[i] = 1
else:
num_list[i] = num_list[i-2] + num_list[i-1]
n = int(input()) + 1
num_list = [0 for i in range(n)]
for i in range(n):
fibonacci(i, num_list)
print(num_list[-1])
| 0 | null | 13,764,612,470 | 16 | 7 |
N = int( input( ) )
x = N % 1000
if x == 0 :
print( '0' )
else :
print( 1000 - int(x) )
|
n = int(input())
for i in range(0,10001,1000):
if i - n >= 0:
print(i - n)
exit()
else:
continue
| 1 | 8,503,058,462,400 | null | 108 | 108 |
N,D,A = map(int,input().split())
XH = [list(map(int,input().split())) for i in range(N)]
XH.sort()
from math import ceil
times = ceil(XH[0][1]/A)
ans = times
damege = [times*A]
coor = [XH[0][0]+2*D]
start = 0
end = 1
dam = sum(damege[start:end])
for i in range(1,N):
st = start
while start < end and coor[start] < XH[i][0]:
start += 1
dam -= sum(damege[st:start])
H = XH[i][1] - dam
if H > 0:
times = ceil(H/A)
ans += times
damege.append(times*A)
dam += times*A
coor.append(XH[i][0]+2*D)
end += 1
print(ans)
|
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
def zaatsu(nums):
ref = list(set(copy.copy(nums)))
ref.sort()
dic = dict()
for i, num in enumerate(ref):
dic[num] = i
return [dic[num] for num in nums]
def solve():
n, d, a = getList()
li = []
for i in range(n):
li.append(getList())
li.sort()
ichi = [x[0] for x in li]
imos = [0] * n
cur = 0
ans = 0
for i, (x, h) in enumerate(li):
cur -= imos[i]
hp = h - cur * a
if hp <= 0:
continue
thr = hp // a
if hp % a != 0:
thr += 1
ans += thr
cur += thr
owari = bisect_right(ichi, x + 2 * d)
if owari != n:
imos[owari] += thr
print(ans)
def main():
n = getN()
for _ in range(n):
solve()
return
if __name__ == "__main__":
# main()
solve()
| 1 | 82,377,539,113,820 | null | 230 | 230 |
import sys,bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
# 区間加算、上書き、一点取得
class SegmentTree:
def __init__(self, n, ele, segfun):
#####単位元######要設定0or1orinf
self.ide_ele = ele
self.segfun = segfun
####################
self.n = n
self.N0 = 1 << n.bit_length()
self.data = [self.ide_ele] * (self.N0 * 2)
def update_add(self, l, r, val):
l += self.N0
r += self.N0
while l < r:
if l & 1:
self.data[l] += val
l += 1
if r & 1:
self.data[r - 1] += val
r -= 1
l //= 2
r //= 2
def update(self, l, r, val):
l += self.N0
r += self.N0
while l < r:
if l & 1:
self.data[l] = self.segfun(self.data[l], val)
l += 1
if r & 1:
self.data[r - 1] = self.segfun(self.data[r - 1], val)
r -= 1
l //= 2
r //= 2
def query(self, i):
i += len(self.data) // 2
ret = self.data[i]
while i > 0:
i //= 2
ret = self.segfun(ret, self.data[i])
return ret
N, D, A = map(int,readline().split())
X = [list(map(int,readline().split())) for _ in range(N)]
X.sort()
L = [0]*N
for i in range(N):
L[i] = X[i][0]
S = SegmentTree(N,0,lambda a, b: a+b)
ans = 0
for i,[x,h] in enumerate(X):
H = h - S.query(i)
if H<=0:
continue
ind = bisect.bisect(L,x+2*D)
need = (H-1)//A + 1
S.update(i,ind,need*A)
ans += need
print(ans)
return
if __name__ == '__main__':
main()
|
import math
H = int(input())
W = int(input())
N = int(input())
Big = W if W > H else H
print(math.ceil(N / Big))
| 0 | null | 85,468,198,480,190 | 230 | 236 |
a ,b = input().split(' ')
print(int(a) * int(b),(int(a) * 2) + (int(b) * 2))
|
data = [int(i) for i in input().split()]
print(f'{data[0] * data[1]} {data[0] * 2 + data[1] * 2}')
| 1 | 297,592,656,046 | null | 36 | 36 |
def main():
x, y = map(int, input().split())
print('Yes' if 2*x <= y <= 4*x and y % 2 == 0 else 'No')
if __name__ == '__main__':
main()
|
x,y = map(int,input().split())
ans = 0
for n in range(x+1):
kame = x - n
tsuru_leg = n*2
kame_leg = kame*4
if y == (tsuru_leg+kame_leg):
ans = ans + 1
if ans == 0:
print('No')
else:
print('Yes')
| 1 | 13,697,639,134,310 | null | 127 | 127 |
from collections import deque
n = int(input())
g = [[] for _ in range(n)]
ab = []
for _ in range(n-1):
a, b = map(int, input().split())
a, b = a - 1, b - 1
g[a].append(b)
g[b].append(a)
ab.append((a, b))
q = deque([0])
chk = [False] * n
chk[0] = True
res = [0] * n
par = [0] * n
while q:
x = q.popleft()
cnt = 1
for y in g[x]:
if chk[y]:
continue
if res[x] == cnt:
cnt += 1
res[y], par[y], chk[y] = cnt, x, True
cnt += 1
q.append(y)
ans = []
for a, b in ab:
if par[a] == b:
ans.append(res[a])
else:
ans.append(res[b])
print(max(ans), *ans, sep="\n")
|
import sys
input = sys.stdin.readline
from collections import deque
N = int(input())
G = [[] for _ in range(N)] # 辺の相手を保存
for i in range(N-1):
a, b = map(lambda x: int(x) - 1, input().split())
G[a].append([b, i])
G[b].append([a, i])
stack = deque([[0, 0]])
visited = [0] * N
visited[0] = 1
ans = [0] * (N-1)
while stack:
i, pc = stack.pop()
c = 1
for ni, ln in G[i]:
if not visited[ni]:
visited[ni] = 1
if c == pc:
c += 1
ans[ln] = c
c += 1
stack.append([ni, ans[ln]])
print(max(ans))
for c in ans:
print(c)
| 1 | 135,729,891,878,142 | null | 272 | 272 |
N = int(input())
A_ls = input().split(' ')
rst = set()
for i in A_ls:
rst.add(i)
if len(rst) == N:
print('YES')
else:
print('NO')
|
N = int(input())
A = [int(s) for s in input().split(' ')]
print('YES' if N == len(set(A)) else 'NO')
| 1 | 73,490,082,160,582 | null | 222 | 222 |
n=int(input())
x=list(input())
def str2int(z):
flag=1
a=0
for i in reversed(x):
if i=='1':a+=flag
flag*=2
return a
popc=x.count('1')
z=str2int(x)
if popc-1!=0:
fl_1=z%(popc-1)
fl_0=z%(popc+1)
for i in range(n):
if x[i]=='1':
if popc-1==0:
print(0)
continue
mod=(fl_1-pow(2,n-1-i,popc-1))%(popc-1)
else:mod=(fl_0+pow(2,n-1-i,popc+1))%(popc+1)
#print('mod : %s'%mod)
cnt=1
while mod!=0:
pp=bin(mod).count("1")
mod%=pp
cnt+=1
print(cnt)
|
N, M = map(int, input().split())
progress = {}
# initialize
for i in range(N):
progress[str(i+1)] = ["notCorrect",0]
correct = 0
for i in range(M):
question, result = map(str, input().split())
if (progress[question][0] == "notCorrect"):
if (result == "WA"):
progress[question][1] += 1
else:
progress[question][0] = "correct"
correct += 1
else:
continue
penalty = 0
for i in range(N):
if (progress[str(i+1)][0] == "correct"):
penalty += progress[str(i+1)][1]
print(str(correct)+" "+str(penalty))
| 0 | null | 51,035,293,557,248 | 107 | 240 |
while True:
m, f, r = map(int, raw_input().split())
if m == -1 and f == -1 and r == -1:
break
elif m == -1 or f == -1:
print "F"
elif m + f >= 80:
print "A"
elif m + f >= 65:
print "B"
elif m + f >= 50:
print "C"
elif m + f >= 30 and r >= 50:
print "C"
elif m + f >= 30:
print "D"
else:
print "F"
|
while True:
m, f, r = map(int, raw_input().split(" "))
if m==f==r==-1:
break
if m==-1 or f==-1:
print("F")
elif m+f >= 80:
print("A")
elif 65 <= m+f < 80:
print("B")
elif 50 <= m+f < 65:
print("C")
elif 30 <= m+f < 50:
if r >= 50:
print("C")
else:
print("D")
elif m+f < 30:
print("F")
| 1 | 1,228,689,739,730 | null | 57 | 57 |
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
# MOD = int(1e09) + 7
MOD = 998244353
INF = int(1e15)
def divisor(N):
res = []
i = 2
while i * i <= N:
if N % i == 0:
res.append(i)
if i != N // i:
res.append(N // i)
i += 1
if N != 1:
res.append(N)
return res
def solve():
N = Scanner.int()
d0 = divisor(N - 1)
ans = len(d0)
d1 = divisor(N)
for d in d1:
X = N
while X % d == 0:
X //= d
if X % d == 1:
ans += 1
print(ans)
def main():
# sys.setrecursionlimit(1000000)
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
|
nums = input().split()
W = int( nums[0])
H = int( nums[1])
x = int( nums[2])
y = int( nums[3])
r = int( nums[4])
if (x - r) >= 0 and (x + r) <= W:
if (y - r) >= 0 and (y + r) <= H:
print( "Yes")
else:
print( "No")
else:
print( "No")
| 0 | null | 20,942,853,014,890 | 183 | 41 |
n = input()
n = n.split()
d = int(n[1])
n = int(n[0])
c = 0
for a in range(n):
b = input()
b = b.split()
x = int(b[0])
y = int(b[1])
if x * x + y * y <= d * d:
c = c + 1
print(c)
|
n,d = map(int,input().split())
ans = 0
for i in range(n):
x1,y1 = map(int,input().split())
if(d*d >= x1*x1+y1*y1):
ans += 1
print(ans)
| 1 | 5,940,535,815,480 | null | 96 | 96 |
#coding: UTF-8
a = raw_input()
l = map(int, raw_input().split())
l.sort()
x =l[0]
l.reverse()
y = l[0]
z = sum(l)
print "%d %d %d" %(x, y, z)
|
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
N = int(input())
ans = len(make_divisors(N-1))-1
for i in make_divisors(N):
if i == 1:
continue
Ni = int(N/i)
while Ni % i == 0:
Ni = int(Ni/i)
if Ni % i == 1:
ans+=1
print(ans)
| 0 | null | 21,072,962,878,760 | 48 | 183 |
K = int(input())
S = input()
s = len(S)
base = 10 ** 9 + 7
L26 = [ 1 for i in range(K+1)] # 26^i mod base
for i in range(K):
L26[i+1] = (L26[i] * 26) % base
T1 = 1
T2 = 1
ans = 0
for i in range( s, s+K+1):
T3 = L26[K + s - i]
#T4 = pow(26, K + s - i, base)
#print(T3, T4)
p = (T1 * T2) % base
p = (p * T3) % base
ans += p
ans %= base
#print(ans, T1, T2, T3)
T1 *= 25
T1 %= base
# T2 = (T2 * i ) // (i+1-s) # T2 = (i, s-1) = (i-1, s-1) * i // (i+1-s)
T2 *= i
T2 %= base
T2 *= pow(i+1-s, base-2, base)
T2 %= base
print(ans % base)
|
MOD = 10**9 + 7
N = 2 * 10**6 + 10 # N は必要分だけ用意する
fact = [1, 1] # fact[n] = (n! mod MOD)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod MOD)
inv = [0, 1]
def nCr(n, r, mod):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % mod
for i in range(2, N + 1):
fact.append((fact[-1] * i) % MOD)
inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
factinv.append((factinv[-1] * inv[-1]) % MOD)
k = int(input())
s = len(input())
ans = 0
for i in range(k+1):
ansp = pow(26,i,MOD) * pow(25,k-i,MOD) * nCr(s+k-1-i,s-1,MOD) % MOD
ans = (ans + ansp) % MOD
print(ans)
| 1 | 12,845,867,849,528 | null | 124 | 124 |
# 解説見ました。
n = int(input())
ans = 0
if n%2 == 0:
m = 1
for _ in range(25):
ans += n//(m*10)
m *= 5
print(ans)
|
n = int(input())
res = 0
if n % 2 == 0:
for i in range(1,30):
p = n // (5 ** i)
#print(i,p)
if p % 2 == 1:
res += (p-1) // 2
else:
res += p // 2
print(res)
| 1 | 115,997,744,453,758 | null | 258 | 258 |
from math import ceil
H, A = map(int, input().split())
ans = ceil(round(H / A, 6))
print(ans)
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 1
mod = 10**9 + 7
c = 0
z = 0
for i in a:
if i < 0:
c += 1
elif i == 0:
z += 1
if c == n and k & 1:
a.reverse()
for i in range(k):
ans *= -a[i]
ans %= mod
print(-ans % mod)
elif c == n:
for i in range(k):
ans *= -a[i]
ans %= mod
print(ans)
elif k == n:
for i in a:
ans *= abs(i)
ans %= mod
print(((-1)**(c & 1) * ans) % mod)
else:
plus = [i for i in a if i > 0]
minus = [i for i in a if i <= 0]
plus.sort(reverse=1)
minus.sort()
plus += [0] * z
x = len(plus)
y = len(minus)
p, m = 0, 0
if k & 1:
ans *= plus[0]
p += 1
for i in range(k // 2):
if x - 1 <= p:
ans *= minus[m] * minus[m + 1]
m += 2
elif y - 1 <= m:
ans *= plus[p] * plus[p + 1]
p += 2
else:
if minus[m] * minus[m + 1] >= plus[p] * plus[p + 1]:
ans *= minus[m] * minus[m + 1]
m += 2
else:
ans *= plus[p] * plus[p + 1]
p += 2
ans %= mod
print(ans % mod)
| 0 | null | 43,069,728,411,996 | 225 | 112 |
while True:
m,f,r=map(int, input().split())
s=m+f
if m==-1 and f==-1 and r==-1:
break
elif m==-1 or f==-1 or s <30:
print('F')
elif s <50 and r <50:
print('D')
elif s <65:
print('C')
elif s <80:
print('B')
else:
print('A')
|
import sys
for i in sys.stdin.readlines():
m, f, r = [int(x) for x in i.split()]
if m == f == r == -1:
break
elif (m == -1 or f == -1) or (m + f < 30):
print('F')
elif m + f >= 80:
print('A')
elif m + f >= 65:
print('B')
elif m + f >= 50 or (30 <= m + f <= 50 and r >= 50):
print('C')
elif m + f >= 30:
print('D')
| 1 | 1,220,679,489,510 | null | 57 | 57 |
def resolve():
N = int(input())
S = list(input())
ans = [chr(((ord(s)-65+N)%26)+65) for s in S]
print("".join(ans))
if '__main__' == __name__:
resolve()
|
N=int(input())
S=input()
tmp=""
for i in range(len(S)):
chtmp=ord(S[i])+N
if(chtmp>ord('Z')):
chtmp-=(ord('Z') - ord('A') + 1)
tmp+=chr(chtmp)
print(tmp)
| 1 | 134,247,906,704,560 | null | 271 | 271 |
print(6.28318530717958623200*int(input()))
|
import sys
sys.setrecursionlimit(10**5)
n,m,k = map(int, input().split())
F = [[] for _ in range(n+1)]
B = [[] for _ in range(n+1)]
for _ in range(m):
x,y = map(int, input().split())
F[x].append(y)
F[y].append(x)
for _ in range(k):
x,y = map(int, input().split())
B[x].append(y)
B[y].append(x)
belongs = [-1 for _ in range(n+1)]
group_ID = 0
def f_search(root, group_ID):
for j in F[root]:
if belongs[j] == -1:
belongs[j] = group_ID
f_search(j, group_ID)
for i in range(n+1):
if belongs[i] == -1:
belongs[i] = group_ID
f_search(i, group_ID)
group_ID += 1
cnt_members = [0 for _ in range(len(set(belongs)))]
for i in belongs[1:]:
cnt_members[i] += 1
ans = [0 for _ in range(n+1)]
for i in range(1, n+1):
tmp = 0
for j in B[i]:
if belongs[j] == belongs[i]:
tmp += 1
ans[i] = cnt_members[belongs[i]] - 1 - len(F[i]) - tmp
print(*ans[1:])
| 0 | null | 46,385,348,482,550 | 167 | 209 |
def resolve():
def check(arr):
height = 0
for b, h in arr:
if height+b < 0:
return False
height += h
return True
N = int(input())
plus = []
minus = []
total = 0
for _ in range(N):
# 1つのパーツを処理
S = input()
cum = 0 # 累積和(最高地点)
bottom = 0 # 最下地点
for s in S:
if s == "(":
cum += 1
else:
cum -= 1
bottom = min(bottom, cum)
total += cum
if cum > 0:
plus.append((bottom, cum))
else:
minus.append((bottom-cum, -cum))
plus.sort(reverse=True)
minus.sort(reverse=True)
if check(plus) and check(minus) and total == 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
resolve()
|
S, T = input(), input()
print(sum(x != y for x, y in zip(S, T)))
| 0 | null | 17,167,284,158,818 | 152 | 116 |
class Dice:
def __init__(self, usr_input, command):
self.eyes = list(map(int, usr_input.split()))
self.pos = {label:eye for label, eye in zip(range(1, 7), self.eyes)}
self.com = list(command)
def roll(self):
for c in self.com:
self.eyes = [n for n in self.pos.values()]
if c == 'E':
self.pos[1] = self.eyes[3]
self.pos[3] = self.eyes[0]
self.pos[4] = self.eyes[5]
self.pos[6] = self.eyes[2]
elif c == 'N':
self.pos[1] = self.eyes[1]
self.pos[2] = self.eyes[5]
self.pos[5] = self.eyes[0]
self.pos[6] = self.eyes[4]
elif c == 'S':
self.pos[1] = self.eyes[4]
self.pos[2] = self.eyes[0]
self.pos[5] = self.eyes[5]
self.pos[6] = self.eyes[1]
elif c == 'W':
self.pos[1] = self.eyes[2]
self.pos[3] = self.eyes[5]
self.pos[4] = self.eyes[0]
self.pos[6] = self.eyes[3]
def top_print(self):
print(self.pos.get(1))
if __name__ == '__main__':
dice1 = Dice(input(), input())
dice1.roll()
dice1.top_print()
|
class Dice(object):
"""docstring for Dice"""
def __init__(self, numeric_column):
self.numeric_column=numeric_column
def roll_to_S_direction(self):
self.numeric_column=[self.numeric_column[4],self.numeric_column[0],self.numeric_column[2],self.numeric_column[3],self.numeric_column[5],self.numeric_column[1]]
def roll_to_N_direction(self):
self.numeric_column=[self.numeric_column[1],self.numeric_column[5],self.numeric_column[2],self.numeric_column[3],self.numeric_column[0],self.numeric_column[4]]
def roll_to_E_direction(self):
self.numeric_column=[self.numeric_column[3],self.numeric_column[1],self.numeric_column[0],self.numeric_column[5],self.numeric_column[4],self.numeric_column[2]]
def roll_to_W_direction(self):
self.numeric_column=[self.numeric_column[2],self.numeric_column[1],self.numeric_column[5],self.numeric_column[0],self.numeric_column[4],self.numeric_column[3]]
dice=Dice(map(int,raw_input().split()))
direction=raw_input()
for i in direction:
if i=='S': dice.roll_to_S_direction()
elif i=='N': dice.roll_to_N_direction()
elif i=='E': dice.roll_to_E_direction()
else: dice.roll_to_W_direction()
print dice.numeric_column[0]
| 1 | 242,871,879,920 | null | 33 | 33 |
input_data = input().split(" ")
items = [int(cont) for cont in input_data]
keys = ['T', 'S', 'E', 'W', 'N', 'B']
dice = dict(zip(keys, items))
def q1():
def rot_func_list(rot, dice):
if rot == "N":
keys = ['T', 'S', 'B', 'N']
items = dice['S'], dice['B'], dice['N'], dice['T']
new_dice = dict(zip(keys, items))
dice.update(new_dice)
if rot == "S":
keys = ['T', 'S', 'B', 'N']
items = dice['N'], dice['T'], dice['S'], dice['B']
new_dice = dict(zip(keys, items))
dice.update(new_dice)
if rot == "E":
keys = ['T', 'E', 'B', 'W']
items = dice['W'], dice['T'], dice['E'], dice['B']
new_dice = dict(zip(keys, items))
dice.update(new_dice)
if rot == "W":
keys = ['T', 'E', 'B', 'W']
items = dice['E'], dice['B'], dice['W'], dice['T']
new_dice = dict(zip(keys, items))
dice.update(new_dice)
controls = list(input())
for i in controls:
rot_func_list(i, dice)
print(dice["T"])
def q2():
def search_surf(conds, dice):
a,b=conds
a_key = [k for k, v in dice.items() if v == a ]
b_key = [k for k, v in dice.items() if v == b ]
key_list = a_key + b_key
part_st = ''.join(key_list)
def search(part_st):
if part_st in "TNBST":
return "W"
if part_st in "TSBNT":
return "E"
if part_st in "TEBWT":
return "N"
if part_st in "TWBET":
return "S"
if part_st in "NESWN":
return "B"
if part_st in "NWSEN":
return "T"
target_key = search(part_st)
print(dice[target_key])
a = input()
repeater = int(a)
for neee in range(repeater):
control_input = input().split(" ")
conds = [int(i) for i in control_input]
search_surf(conds, dice)
q2()
|
def gcd (x , y):
sur = x % y
while sur != 0:
x = y
y = sur
sur = x % y
return y
a,b = map(int,raw_input().split())
if a < b :
temp = a
a = b
b = temp
print gcd(a,b)
| 0 | null | 128,459,918,906 | 34 | 11 |
x = int(input()) - 400
l = [8,7,6,5,4,3,2,1]
print(l[x//200])
|
point = int(input())
rank = 1
for val in range(1800, 200, -200):
if point >= val:
break
else:
rank += 1
print(rank)
| 1 | 6,739,231,785,088 | null | 100 | 100 |
#!/usr/bin/env python3
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
L = int(input())
print((L/3)**3)
if __name__ == '__main__':
main()
|
L = int(input())
L /= 3
print(L**3)
| 1 | 46,974,329,762,220 | null | 191 | 191 |
N=int(input())
xy = [tuple(map(int,input().split())) for _ in range(N)]
ans = 0
def dist(tpl1, tpl2):
return abs(tpl1[0] - tpl2[0]) + abs(tpl1[1] - tpl2[1])
f0 = []
f1 = []
for i in range(N):
x, y = xy[i]
f0.append(x-y)
f1.append(x+y)
ans = max(ans,
max(f0) - min(f0),
max(f1) - min(f1))
print(ans)
|
n=int(input())
d={"AC":0,"WA":0,"TLE":0,"RE":0}
for _ in range(n):
d[input()]+=1
for d1, d2 in d.items():
print(d1,'x',d2)
| 0 | null | 6,089,586,025,278 | 80 | 109 |
s = input()
if s == "AAA":
print("No")
elif s == "BBB":
print("No")
else:
print("Yes")
|
s = input()
if s=='AAA' or s=='BBB' : print('No')
else : print('Yes')
| 1 | 54,934,231,123,168 | null | 201 | 201 |
def main():
H1,M1,H2,M2,K = [int(x) for x in input().split()]
if M2 >= M1:
diff = (H2-H1)*60 + M2-M1
else:
diff = (H2-H1)*60 + 60-M1+M2 -60
if diff <= 0:
print(0)
else:
print(diff - K)
if __name__ == '__main__':
main()
|
N,K = map(int,input().split())
H = list(map(int,input().split()))
print(sum(K<=h for h in H))
| 0 | null | 98,133,163,382,408 | 139 | 298 |
s = input()
if ("AB" in s) or ("BA" in s):
print("Yes")
else:
print("No")
|
s = input()
if(s == 'AAA' or s == 'BBB'):
print("No")
else:
print("Yes")
| 1 | 54,741,099,096,342 | null | 201 | 201 |
s = input()
st = []
leftn = 0
def pushv(s, x):
tmp = s.pop()
tmpsum = 0
while tmp[0] != 'left':
tmpsum += tmp[1]
tmp = s.pop()
else:
tmpsum += x - tmp[1]
s.append(('v', tmpsum))
for x in range(len(s)):
if s[x] == '\\':
st.append(('left', x))
leftn += 1
elif s[x] == '/':
if leftn != 0:
pushv(st, x)
leftn -= 1
st = [x[1] for x in st if x[0] == 'v']
if len(st) != 0:
print(sum(st))
print(len(st), ' '.join([str(x) for x in st]))
else:
print(0)
print(0)
|
import collections
import sys
S1 = collections.deque()
S2 = collections.deque()
S3 = collections.deque()
for i, j in enumerate(sys.stdin.readline()):
if j == '\\':
S1.append(i)
elif j == '/':
if S1:
left_edge = S1.pop()
new_puddle = i - left_edge
while True:
if S2:
if S2[-1] > left_edge:
S2.pop()
new_puddle += S3.pop()
else:
break
else:
break
S2.append(left_edge)
S3.append(new_puddle)
else:
pass
print(sum(S3))
print(len(S3), *S3)
| 1 | 60,077,942,198 | null | 21 | 21 |
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15,
2, 2, 5, 4, 1, 4, 1, 51]
index = input()
index = int(index)
print(list[index-1])
|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32
def solve(K: int):
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[K-1])
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
K = int(next(tokens)) # type: int
solve(K)
if __name__ == '__main__':
main()
| 1 | 50,076,317,871,830 | null | 195 | 195 |
def is_palindrome(text):
l = len(text)
for i in range(l // 2 if l % 2 == 0 else (l + 1) // 2):
if text[i] != text[l - 1 - i]:
return False
return True
s = input()
q1 = is_palindrome(text=s)
q2 = is_palindrome(text=s[0:(len(s) - 1) // 2])
q3 = is_palindrome(text=s[(len(s) + 3) // 2 - 1:len(s)])
print("Yes" if q1 and q2 and q3 else "No")
|
import numpy as np
def check_pali(S):
for i in range(0, len(S)):
if S[i] != S[-1 * i + -1]:
return False
elif i > (len(S) / 2) + 1:
break
return True
S = input()
N = len(S)
short_N = (N - 1) // 2
long_N = (N + 3) // 2
if check_pali(S) & check_pali(S[0:short_N]) & check_pali(S[long_N-1:N]):
print("Yes")
else:
print("No")
| 1 | 46,437,413,196,174 | null | 190 | 190 |
import sys
while True:
n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
if 0 == n and 0 == x:
break
cnt = 0
for i in range( 1, n-1 ):
if x <= i:
break
for j in range( i+1, n ):
if x <= ( i+j ):
break
for k in range( j+1, n+1 ):
s = ( i + j + k )
if x == s:
cnt += 1
break
elif x < s:
break
print( cnt )
|
def calc(n, x):
result = 0
for i in range(3, n + 1):
for j in range(2, i):
for k in range(1, j):
if sum([i, j, k]) == x:
result += 1
return str(result)
ans = []
while True:
n, x = map(int, input().split())
if n == x == 0:
break
ans.append(calc(n, x))
print("\n".join(ans))
| 1 | 1,291,219,195,630 | null | 58 | 58 |
h, w, n = map(int, open(0))
print(0 - -n // max(h, w))
|
s = len(input())
x = ''
for i in range(0, s):
x += 'x'
print(x)
| 0 | null | 80,895,658,415,072 | 236 | 221 |
num = int(input())
num_list = list(map(int,input().split(" ")))
print(min(num_list),max(num_list),sum(num_list))
|
import sys
_ = sys.stdin.readline()
x=sys.stdin.readline()
arr=x.split()
arrInt=list()
#print(arr, type(arr))
for i in arr:
# print(i)
arrInt.append(int(i))
#print(arrInt,type(arrInt))
print(min(arrInt),max(arrInt),sum(arrInt))
| 1 | 741,686,138,638 | null | 48 | 48 |
X = int(input())
Y = X % 500
answer = (X // 500 * 1000 + Y // 5 * 5)
print(answer)
|
x = int(input())
x500 = x // 500
y = x - x500*500
y5 = y // 5
z = y - y5*5
print(x500*1000+y5*5)
| 1 | 42,824,002,781,978 | null | 185 | 185 |
#!/usr/bin/env python3
n = int(input())
matrix = []
while n > 0:
values = [int(x) for x in input().split()]
matrix.append(values)
n -= 1
official_house = [[[0 for z in range(10)] for y in range(3)] for x in range(4)]
Min = 0
Max = 9
for b, f, r, v in matrix:
num = official_house[b - 1][f - 1][r - 1]
if Min >= num or Max >= num:
official_house[b - 1][f - 1][r - 1] += v
for i in range(4):
for j in range(3):
print('',' '.join(str(x) for x in official_house[i][j]))
if 3 > i:
print('#' * 20)
|
rooms = [0] * (4*3*10)
count = int(input())
for i in range(count):
b, f, r, v = [int(x) for x in input().split()]
rooms[30*(b-1) + 10*(f-1) + (r-1)] += v
for i, room in enumerate(rooms, start=1):
print('', room, end='')
if i%10 == 0:
print()
if i%30 == 0 and i%120 != 0:
print('#'*20)
| 1 | 1,111,530,422,772 | null | 55 | 55 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.