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
|
---|---|---|---|---|---|---|
h = int(input())
cnt = 0
for i in range(h.bit_length()):
cnt += 2**i
print(cnt) | N=int(input())
n500=N//500
n5=(N%500)//5
print(1000*n500+5*n5) | 0 | null | 61,426,203,773,440 | 228 | 185 |
num = int(input())
print("{0}".format(num**3))
| n=int(input())
K=int(input())
m=len(str(n))
N=list(map(int,str(n)))
dp=[[[0,0]for j in range(K+1)]for i in range(m+1)]
dp[0][0][0]=1
for i in range(1,1+m):
for j in range(K+1):
for k in range(10):
if k==0:
if N[i-1]==k:
dp[i][j][0]+=dp[i-1][j][0]
elif N[i-1]>k:
dp[i][j][1]+=dp[i-1][j][0]
dp[i][j][1]+=dp[i-1][j][1]
else:
if j<K:
if N[i-1]==k:
dp[i][j+1][0]+=dp[i-1][j][0]
elif N[i-1]>k:
dp[i][j+1][1]+=dp[i-1][j][0]
dp[i][j+1][1]+=dp[i-1][j][1]
print(sum(dp[-1][K])) | 0 | null | 38,257,988,389,476 | 35 | 224 |
s, t = input().split()
ans = '{}{}'.format(t, s)
print(ans) | S, T = map(str, input().split())
T += S
print(T) | 1 | 103,032,747,149,802 | null | 248 | 248 |
x, y = map(int, input().split())
mod = 10**9+7
if (2*y-x < 0) or (2*x-y < 0):
print(0)
exit()
if (2*y-x)%3 != 0 or (2*x-y)%3 != 0:
print(0)
exit()
xc = (2*y-x)//3
yc = (2*x-y)//3
p = 1
k = 1
for i in range(1, xc+1):
p *= (yc+i)
k *= i
p %= mod
k %= mod
ans = p*pow(k, mod-2, mod)%mod
print(ans) | N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [[0 for j in range(S+1)] for i in range(N+1)]
dp[0][0] = 1
for i in range(N):
for j in range(S+1):
dp[i+1][j] += 2*dp[i][j]
dp[i+1][j] %= mod
if j + A[i] <= S:
dp[i+1][j+A[i]] += dp[i][j]
dp[i+1][j+A[i]] %= mod
print(dp[N][S]) | 0 | null | 84,134,560,885,430 | 281 | 138 |
h,w=map(int,input().split())
ans=0
if h==1 or w==1:
ans=1
elif (h*w)%2==0:
ans=int(h*w//2)
else:
ans=(h*w//2+1)
print(ans) | H, W = map(int, input().split())
if min(H,W) == 1:
print(1)
elif H*W % 2 == 0:
print(int(H*W/2))
else:
print(int(H*W/2)+1)
| 1 | 50,622,415,641,834 | null | 196 | 196 |
n = int(input())
print(input().count("ABC")) | n = int(input())
s = input()
m = len(s.replace("ABC", ""))
print((n - m) // 3) | 1 | 99,518,247,904,018 | null | 245 | 245 |
print(str(input())[:3]) | # -*- coding: utf-8 -*-
buf = str(raw_input())
char_list = list(buf)
res = ""
for i in char_list:
if i.isupper():
res += i.lower()
elif i.islower():
res += i.upper()
else:
res += i
print res | 0 | null | 8,179,567,781,142 | 130 | 61 |
if __name__ == "__main__":
v = map( int, raw_input().split())
a = v[0]
b = v[1]
d = a / b
r = a - ( d * b )
s = (0.0 + a) / b
print "{0:d} {1:d} {2:.5f}".format( d, r, s) | a,b = map(int,raw_input().split())
print a/b, a%b, "{0:.10f}".format(a/float(b)) | 1 | 599,913,388,192 | null | 45 | 45 |
N=int(input())
X=input()
def calc(n,count):
if n==0:
return count
popcount=bin(n).count("1")
next_n=n%popcount
#print(next_n)
if next_n==0:
return count+1
else:
return calc(next_n, count+1)
popcount=X.count("1")
if popcount==1:
plus=0
for i in range(N):
x=X[i]
if x=="1":
plus+=pow(2,N-i-1,popcount+1)
for i in range(N):
x=X[i]
if x=="1":
print(0)
else:
ans=plus+pow(2,N-i-1,popcount+1)
ans%=(popcount+1)
print(calc(ans,1))
exit()
plus=0
minus=0
for i in range(N):
x=X[i]
if x=="1":
plus+=pow(2,N-i-1,popcount+1)
minus+=pow(2,N-i-1,popcount-1)
plus%=(popcount+1)
minus%=(popcount-1)
for i in range(N):
x=X[i]
if x=="1":
ans=minus-pow(2,N-i-1,popcount-1)
ans%=(popcount-1)
print(calc(ans,1))
else:
ans=plus+pow(2,N-i-1,popcount+1)
ans%=(popcount+1)
print(calc(ans,1))
| def solve():
N,R = [int(i) for i in input().split()]
if N >= 10:
print(R)
else:
print(R+100*(10-N))
if __name__ == "__main__":
solve() | 0 | null | 35,758,992,172,798 | 107 | 211 |
s = input()
if len(list(set(s))) == 1:
print('No')
else:
print('Yes') | s = input()
if s[0] == s[1] and s[1] == s[2]:
print('No')
else:
print('Yes') | 1 | 54,696,976,339,690 | null | 201 | 201 |
def solve(xy):
ans = 0
pos = [xy[0] for _ in range(4)]
for p in xy:
if pos[0][0] + pos[0][1] < p[0] + p[1]:
pos[0] = p
if pos[1][0] + pos[1][1] > p[0] + p[1]:
pos[1] = p
if pos[2][0] - pos[2][1] < p[0] - p[1]:
pos[2] = p
if pos[3][0] - pos[3][1] > p[0] - p[1]:
pos[3] = p
return max(pos[0][0]+pos[0][1]-pos[1][0]-pos[1][1], pos[2][0]-pos[2][1]-pos[3][0]+pos[3][1])
if __name__ == "__main__":
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
print(solve(xy))
| n = int(input())
plus_max = 10**20 * -1
plus_min = 10**20
minus_max = 10**20 * -1
minus_min = 10**20
for _ in range(n):
x, y = map(int, input().split())
plus_max = max(plus_max, x + y)
plus_min = min(plus_min, x + y)
minus_max = max(minus_max, x - y)
minus_min = min(minus_min, x - y)
print(max(plus_max - plus_min, minus_max - minus_min))
| 1 | 3,396,301,295,842 | null | 80 | 80 |
N=int(input())
c=-(-N//2)-1
print(c) | N = int(input())
ans = set()
for i in range(1, N + 1):
j = N - i
if i == j or i == 0 or j == 0:
continue
ans.add((min(i, j), max(i, j)))
print(len(ans)) | 1 | 152,990,273,147,700 | null | 283 | 283 |
print "\n".join(['{0}x{1}={2}'.format(x,y,x*y) for x in range(1,10) for y in range(1,10)]) | r, c = map(int, input().split())
tabl = [list(map(int, input().split())) for i in range(r)]
for i in range(r):
print(" ".join(map(str, tabl[i])) + " " + str(sum(tabl[i])))
ss = ""
for i in range(c):
ans = 0
for j in range(r):
ans += tabl[j][i]
ss += str(ans) + " "
print(ss+str(sum([int(i) for i in ss.split()]))) | 0 | null | 687,763,999,338 | 1 | 59 |
S = str(input())
r = len(S)
print('x'*r) | s = list(input())
count = len(s)
for i in range(count):
s[i] = "x"
changed = "".join(s)
print(changed) | 1 | 73,046,965,692,888 | null | 221 | 221 |
S = input()
n = len(S) + 1
a = [0] * n
S = ('<' if S[0] == '>' else '>') + S \
+ ('<' if S[-1] == '>' else '>') # 最初と最後にダミー追加、長さn+1
for i in range(n):
if S[i : i + 2] == '><': # 極小値
for j in range(i, 0, -1): # 左に辿る
if S[j] == '<': break
a[j - 1] = max(a[j - 1], a[j] + 1)
for j in range(i + 1, n): # 右に辿る
if S[j] == '>': break
a[j] = max(a[j], a[j - 1] + 1)
print(sum(a)) | s = input()
de_num = 0
le_num = 0
ans = [0]*(len(s)+1)
for i in range(len(s)):
if s[i] == "<":
de_num += 1
else:
de_num = 0
ans[i+1] = de_num
s = s[::-1]
ans.reverse()
for i in range(len(s)):
if s[i] == ">":
le_num += 1
else:
le_num = 0
ans[i+1] = max(le_num,ans[i+1])
print(sum(ans)) | 1 | 157,207,020,871,096 | null | 285 | 285 |
x,y = map(int,input().split())
def point(a):
if a == 1:
return 300000
elif a == 2:
return 200000
elif a == 3:
return 100000
else:
return 0
c = point(x)
b = point(y)
if x == 1 and y == 1:
print(1000000)
else:
print(c+b) | i=input()
print(int(i)**2) | 0 | null | 142,405,224,458,970 | 275 | 278 |
A,V = map(int,input().split(" "))
B,W = map(int,input().split(" "))
T, = map(int,input().split(" "))
kyori = abs(A-B)
dif = V-W
if dif>0:
if kyori/dif<=T:
print("YES")
else:
print("NO")
else:
print("NO") | n = int(input())
score = [0,0]
for _ in range(n):
tc, hc = input().split()
if tc == hc:
score[0] += 1
score[1] += 1
elif tc > hc:
score[0] += 3
else:
score[1] += 3
print(*score)
| 0 | null | 8,543,317,108,028 | 131 | 67 |
from collections import deque
D1 = {i:chr(i+96) for i in range(1,27)}
D2 = {val:key for key,val in D1.items()}
N = int(input())
heap = deque([(D1[1],1)])
A = []
while heap:
a,n = heap.popleft()
if n<N:
imax = 0
for i in range(len(a)):
imax = max(imax,D2[a[i]])
for i in range(1,min(imax+1,26)+1):
heap.append((a+D1[i],n+1))
if n==N:
A.append(a)
A = sorted(list(set(A)))
for i in range(len(A)):
print(A[i]) | n = int(input())
s = "abcdefghij"
def func(a):
if len(a) == n:
print(a)
else:
for i in range(len(set(a))+1):
func(a+s[i])
func("a") | 1 | 52,295,663,513,348 | null | 198 | 198 |
x1,y1,x2,y2=map(float,input().split())
import math
s=math.sqrt((x1-x2)**2+(y1-y2)**2)
print(f'{s:.08f}')
| S,W=map(int,input().split())
if S>W:
print("safe")
elif S<W:
print("unsafe")
elif S==W:
print("unsafe") | 0 | null | 14,694,318,174,650 | 29 | 163 |
n = int(input())
ans = 0
for i in range(1,n+1):
if i % 3 == 0 and i % 5 == 0:
ans += 0
elif i % 3 == 0 or i % 5 == 0:
ans += 0
else:
ans += i
print(ans) | n = int(input())
a = []
lists = []
for i in range(1, n+1):
if i % 3 == 0 and i % 5 == 0:
a.append('FizzBuzz')
elif i % 3 == 0:
a.append('Fizz')
elif i % 5 == 0:
a.append('Buzz')
else:
a.append(str(i))
for item in a:
item = item.replace('FizzBuzz', '0')
item = item.replace('Fizz', '0')
item = item.replace('Buzz', '0')
lists.append(item)
print(sum([int(i) for i in lists]))
| 1 | 34,990,044,569,920 | null | 173 | 173 |
h,k = map(int,input().split())
arr=list(map(int,input().split()))
arr.sort()
print(sum(arr[0:h-k]) if h>=k else 0) | from sys import stdin
import sys
import math
from functools import reduce
import itertools
n,k = [int(x) for x in stdin.readline().rstrip().split()]
h = [int(x) for x in stdin.readline().rstrip().split()]
if k<n:
h.sort()
print(sum(h[:n-k]))
else:
print(0) | 1 | 79,132,869,041,448 | null | 227 | 227 |
n=int(input())
slist=[]
tlist=[]
ans=0
yn=0
for i in range(n):
s,t=input().split()
slist.append(s)
tlist.append(int(t))
x=input()
for i in range(n):
if yn==1:
ans+=tlist[i]
if x==slist[i]:
yn=1
print(ans)
| import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def solve():
m = a[-1]+1
ava = [0]*m
for rep in a:
ava[rep] += 1
if ava[rep]==1:
for item in range(2*rep,m,rep):
ava[item] += 2
print(ava.count(1))
return
if __name__=='__main__':
n = I()
a = list(IL())
a.sort()
solve() | 0 | null | 55,714,622,434,140 | 243 | 129 |
def freq(my_list):
count = {}
for i in my_list:
count[i] = count.get(i, 0) + 1
return count
n = int(input())
l = list(map(int, input().split()))
s,f = sum(l), freq(l)
for _ in range(int(input())):
x, y = map(int, input().split())
if x in f:
v = f[x]
if y in f:
f[y]+=v
f.pop(x)
else:
f[y]=f.pop(x)
s += (y-x)*v
print(s) | ls = []
while True:
try:
n = int(raw_input())
except EOFError:
break
ls.append(n)
ls.sort(reverse=True)
print ls[0]
print ls[1]
print ls[2] | 0 | null | 6,132,526,042,146 | 122 | 2 |
a, b = map(int, input().split())
if b * 2 >= a:
print('0')
else:
print(a - b * 2) | kazu = input()
kazu = int(kazu)
for i in range( kazu ):
print("ACL",end = '') | 0 | null | 84,517,705,041,282 | 291 | 69 |
n, k = map( int, input().split() )
p = list( map( int, input().split() ) )
sum_k = sum( p[ : k ] )
max_sum_k = sum_k
for i in range( k, n ):
sum_k += p[ i ] - p[ i - k ]
if sum_k > max_sum_k:
max_sum_k = sum_k
print( ( max_sum_k + k ) / 2 ) | N, K = map(int, input().split())
plist = list(map(int, input().split()))
pre = sum(plist[:K])
ans = pre
for i in range(0, N-K):
pre = pre - plist[i] + plist[i+K]
ans = max(ans, pre)
print((ans + K)/2)
| 1 | 75,126,808,445,358 | null | 223 | 223 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
a,b,c = map(int, input().split())
print("{0} {1} {2}".format(c,a,b)) | import numpy as np
a, b = map(int, input().split())
ans = np.lcm(a, b)
print(ans) | 0 | null | 75,858,342,605,702 | 178 | 256 |
import math
m,n = map(int,input().split())
print(m*n//(math.gcd(m, n)))
| A,B=map(int,input().split())
ma,mi=0,0
ma=max(A,B)
mi=min(A,B)
if A%B==0 or B%A==0:
print(ma)
else :
for i in range(2,ma+1):
if (ma*i)%mi==0:
print(ma*i)
break
i+=(mi-1)
| 1 | 113,286,113,482,458 | null | 256 | 256 |
h, w = map(int, input().split())
if h==1 or w == 1:
print(1)
else:
ans = h * w //2 + (h*w)%2
print(ans) | a, b = (int(x) for x in input().split())
if a == 1 or b == 1:
print("1")
elif a * b % 2 == 0:
print(int(a * b / 2))
else:
print(int((a * b - 1) / 2 + 1)) | 1 | 50,892,313,681,522 | null | 196 | 196 |
import sys
input = sys.stdin.readline
def gcd(a, b):
while b:
a, b = b, a%b
return a
def lcm(a, b):
return a//gcd(a, b)*b
N, M = map(int, input().split())
a = list(map(int, input().split()))
b = [ai//2 for ai in a]
cnt = [0]*N
for i in range(N):
t = b[i]
while t%2==0:
cnt[i] += 1
t //= 2
if cnt!=[cnt[0]]*N:
print(0)
exit()
L = 1
for bi in b:
L = lcm(L, bi)
if L>M:
print(0)
else:
print((M-L)//(2*L)+1) | N, M = map(int, input().split())
a = list(map(int, input().split()))
from math import floor
from fractions import gcd
from functools import reduce
def lcm(x, y):
return x * y // gcd(x, y)
b = [n // 2 for n in a]
lcm_b = reduce(lcm, b)
for n in b:
if (lcm_b // n) % 2 == 0:
print(0)
exit()
n = floor((M / lcm_b - 1) / 2) + 1
print(n)
| 1 | 101,470,496,831,160 | null | 247 | 247 |
N = int(input())
tmp = 0
for i in range(3):
amari = N%10
N //= 10
if amari == 7:
print('Yes')
tmp = 1
break
if tmp != 1:
print('No')
| # (c) midandfeed
q = []
for i in range(4):
b = []
for j in range(3):
a = [0 for x in range(10)]
b.append(a)
q.append(b)
t = int(input())
for _ in range(t):
b, f, r, v = [int(x) for x in input().split()]
q[b-1][f-1][r-1] += v
a = 0
for x in q:
a += 1
for y in x:
for z in range(len(y)):
print(" {}".format(y[z]), end='')
if (z==(len(y))-1):
print()
if (a!=4):
print("#"*20) | 0 | null | 17,617,425,536,662 | 172 | 55 |
n,k = map(int,input().split())
mod = 10**9 +7
sum1 = 0
for i in range(k,n+2):
sum1 +=(-i*(i-1)//2 + i*(2*n-i+1)//2+1)%mod
print(sum1%mod) | n,k=map(int,input().split())
M=[n]*(n+1)
m=[0]*(n+1)
for i in range(1,n+1):
M[i]=M[i-1]+n-i
m[i]=m[i-1]+i
mod=10**9+7
ans=0
for i in range(k-1,n+1):
tmp=M[i]-m[i]+1
ans=(ans+tmp)%mod
ans=ans%mod
print(ans) | 1 | 33,134,215,109,490 | null | 170 | 170 |
n = int(input())
a = list(map(int,input().split()))
ok = True
for i in range(n):
if a[i] % 2 == 0 and a[i] % 3 != 0 and a[i] % 5 != 0:
ok = False
if ok:
print("APPROVED")
else:
print("DENIED") | import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re
N,R=map(int,input().split())
if N >= 10:
print(R)
else:
print( R + ( 100 * ( 10 - N )))
| 0 | null | 66,253,339,050,760 | 217 | 211 |
n, k = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(k)]
mod = 998244353
dp = [1]
acc = [0, 1]
for i in range(1, n):
new = 0
for l, r in LR:
if i < l:
continue
r = min(r, i)
new += acc[i-l+1] - acc[i-r]
new %= mod
dp.append(new)
acc.append((acc[-1]+new) % mod)
print(dp[-1]) | N, K = map(int, input().split())
answer = 0
while N // (K ** answer) >= 1:
answer += 1
print(answer) | 0 | null | 33,460,956,407,880 | 74 | 212 |
print("NYoe s"['7' in input()::2]) | s=input()
n=len(s)//2
s1=s[:n]
s2=s[-n:]
s2=s2[::-1]
cnt=0
for i in range(len(s1)):
if s1[i]!=s2[i]:
cnt+=1
print(cnt)
| 0 | null | 77,105,872,744,822 | 172 | 261 |
def main():
s = int(input())
mod = 10**9 + 7
dp = [0] * (s+1)
dp[0] = 1
# for i in range(1, s+1):
# for j in range(0, (i-3)+1):
# dp[i] += dp[j]
# dp[i] %= mod
for i in range(1, s+1):
if i < 3:
dp[i] = 0
else:
dp[i] = dp[i-1] + dp[i-3]
dp[i] %= mod
print(dp[-1])
if __name__ == "__main__":
main()
| NOT_FOUND = 0
FOUND = 1
FINISHED = 2
class Stack(object):
def __init__(self):
self._stack = []
def push(self, val):
self._stack.append(val)
def pop(self):
val = self._stack[-1]
del self._stack[-1]
return val
def top(self):
if len(self._stack) > 0:
return self._stack[-1]
else:
return None
def is_stacked(self, val):
if len(self._stack) > 0:
return val in self._stack
else:
return None
def get_len(self):
return len(self._stack)
def parse_line(line):
vals = [int(v) for v in line.split(' ')]
node, n_node, nodes = vals[0], vals[1], vals[2:]
# convert zero origin
nodes = [n - 1 for n in nodes]
return node, n_node, nodes
def main():
# get input
n = int(input().strip())
graph = []
for _ in range(n):
line = input().strip()
_, _, nodes = parse_line(line)
graph.append(nodes)
# initialize
stack = Stack()
stats = [NOT_FOUND for _ in range(n)]
found_times = [None for _ in range(n)]
finished_times = [None for _ in range(n)]
counter = 0
# dfs
while sum(stats) < n * FINISHED:
counter += 1
init_node = None
for node in range(n):
if stats[node] == NOT_FOUND:
init_node = node
break
assert init_node is not None
stack.push(init_node)
stats[init_node] = FOUND
found_times[init_node] = counter
while stack.get_len() > 0:
counter += 1
crr_node = stack.top()
adj_nodes = graph[crr_node]
for adj_node in adj_nodes:
# exist not stacked node
if stats[adj_node] == NOT_FOUND:
found_times[adj_node] = counter
stats[adj_node] = FOUND
stack.push(adj_node)
crr_node = adj_node
break
else:
# not exist not stacked node
finished_times[crr_node] = counter
stats[crr_node] = FINISHED
stack.pop()
crr_node = stack.top()
for i in range(n):
print('{} {} {}'.format(i + 1, found_times[i], finished_times[i]))
if __name__ == '__main__':
main()
| 0 | null | 1,615,954,680,560 | 79 | 8 |
n = int(input())
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
if n == 1:
print(0)
exit()
primes = prime_factorize(n)
max_primes = primes[-1]
dic = {}
tmp = 0
for i in primes:
if i not in dic:
dic[i] = 1
tmp = 0
continue
if tmp == 0:
tmp = i
else:
tmp *= i
if tmp not in dic:
dic[tmp] = 1
tmp = 0
print(len(dic)) | N = int(input())
hash = {}
end = int(N ** (1/2))
for i in range(2, end + 1):
while N % i == 0:
hash[i] = hash.get(i, 0) + 1
N = N // i
if N != 1:
hash[i] = hash.get(i, 0) + 1
count = 0
trans = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]
res = 0
for i in hash.values():
for j in range(len(trans)):
if i > trans[j]:
continue
elif i == trans[j]:
res += (j + 1)
break
else:
res += j
break
print(res) | 1 | 16,919,911,597,104 | null | 136 | 136 |
#coding:utf-8
m = 0
f = 0
r = 0
while m + f + r >-3:
m , f, r =[int(i) for i in input().rstrip().split(" ")]
if m+f+r == -3:
break
if m == -1:
print("F")
elif f == -1:
print("F")
elif m+f <30:
print("F")
elif m+f <50:
if r>=50:
print("C")
else:
print("D")
elif m+f <65:
print("C")
elif m+f <80:
print("B")
else:
print("A") | while 1:
m,f,r=map(int, raw_input().split())
if m==f==r==-1: break
s=m+f
if m==-1 or f==-1 or s<30: R="F"
elif s>=80: R="A"
elif s>=65: R="B"
elif s>=50: R="C"
elif r>=50: R="C"
else: R="D"
print R | 1 | 1,245,904,503,598 | null | 57 | 57 |
line = list(input())
for k,v in enumerate(line):
line[k] = v.swapcase()
print(''.join(line)) | s = list(input())
ans = []
for c in s:
if c.islower():
ans.append(c.upper())
elif c.isupper():
ans.append(c.lower())
else:
ans.append(c)
print("".join(ans))
| 1 | 1,489,084,179,608 | null | 61 | 61 |
n = int(input())
a = list(map(int,input().split()))
MOD = 10 ** 9 + 7
digit = 60
o=[0]*digit
z=[0]*digit
for i in a:
for j in range(digit):
if (i >> j) & 1:
o[j] += 1
else:
z[j] += 1
ans = 0
for j in range(digit):
ans += (o[j]*z[j]*pow(2,j,MOD))
print(ans % MOD) | x=int(input())
hundred=x//500
x-=hundred*500
five=x//5
print(hundred*1000+five*5)
| 0 | null | 82,841,233,561,920 | 263 | 185 |
import math
n = int(input())
paper = math.ceil(n/2)
print(paper) | x=int(input())
for i in range(-118,120):
for j in range(-118,120) :
if i**5-j**5==x :
print(i,j)
exit()
else :
continue | 0 | null | 42,501,467,055,464 | 206 | 156 |
A1, A2, A3 = map(int, input().split())
print('win') if A1 + A2 + A3 <= 21 else print('bust') | A1, A2, A3 = [int(s) for s in input().split(' ')]
print('win' if A1+A2+A3 < 22 else 'bust')
| 1 | 118,446,591,964,860 | null | 260 | 260 |
x,n=map(int, input().split())
a=list(map(int, input().split()))
for y in range(x+1):
for b in[-1,1]:
c=x+y*b
if a.count(c)==0:
print(c)
exit(0)
| X,N=map(int,input().split())
p=list(map(int,input().split()))
for i in range(102):
if (X-i)not in p:
print(X-i)
exit()
elif (X+i)not in p:
print(X+i)
exit() | 1 | 14,142,538,627,140 | null | 128 | 128 |
from sys import stdin
readline = stdin.readline
R, C, K = map(int, readline().split())
goods = [[0] * C for _ in range(R)]
for _ in range(K):
r, c, v = map(int, readline().split())
goods[r - 1][c - 1] = v
n = [0] * (C + 1)
for i in range(R):
c = [0] * 4
c[0] = n[0]
for j in range(C):
if goods[i][j] != 0:
for k in range(2, -1, -1):
if c[k] + goods[i][j] > c[k + 1]:
c[k + 1] = c[k] + goods[i][j]
for k in range(4):
if c[k] > n[j]:
n[j] = c[k]
if n[j + 1] > c[0]:
c[0] = n[j + 1]
print(max(c))
| import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)
R, C, K = rl()
I = [[0]*(C+2) for _ in range(R+2)]
for i in range(K):
r, c, v = rl()
I[r][c] = v
dp = [[0]*4 for _ in range(C+2)]
dp2 = [[0]*4 for _ in range(C+2)]
for i in range(R+1):
for j in range(C+1):
for m in range(4):
ni, nj = i, j+1
dp[nj][m] = max(dp[nj][m], dp[j][m])
if m < 3:
dp[nj][m+1] = max(dp[nj][m+1], dp[j][m]+I[ni][nj])
ni, nj = i+1, j
dp2[nj][0] = max(dp2[nj][0], dp[j][m])
dp2[nj][1] = max(dp2[nj][1], dp[j][m]+I[ni][nj])
dp = dp2
dp2 = [[0]*4 for _ in range(C+2)]
ans = 0
for m in range(4):
ans = max(ans, dp[C][m])
print(ans)
| 1 | 5,536,423,418,788 | null | 94 | 94 |
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
A, B = map(int, readline().split())
if (A <= 9) & (B <= 9):
print(A * B)
else:
print(-1)
if __name__ == '__main__':
main()
| def solve(n):
ans = 0
for i in range(1, n+1):
m = n // i
ans += m * (m+1) * i // 2
return ans
n = int(input())
print(solve(n)) | 0 | null | 84,426,140,901,814 | 286 | 118 |
from sys import stdin
W, H, x, y, r = (int(n) for n in stdin.readline().rstrip().split())
answer = "Yes" if r <= x <= W - r and r <= y <= H - r else "No"
print(answer)
| W, H, x, y, r = map(int, input().split())
print( 'Yes' if r <= x <= W - r and r <= y <= H - r else 'No') | 1 | 456,570,730,430 | null | 41 | 41 |
def ra(a): #圧縮された要素を非保持
ll,l=[],1
for i in range(len(a)-1):
if a[i]==a[i+1]:
l+=1
else:
ll.append(l)
l=1
ll.append(l)
return ll
n=input()
print(len(ra(input()))) | while True:
s = input().rstrip().split(" ")
h=int(s[0])
w=int(s[1])
if (h == 0) & (w == 0):
break
for i in range(h):
print("#"*w)
print() | 0 | null | 85,197,655,367,620 | 293 | 49 |
N, M = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(M)]
ans = [10] * N
for l in lst:
if ans[l[0]-1] < 10 and ans[l[0]-1] != l[1]:
print(-1)
exit()
ans[l[0]-1] = l[1]
if ans[0] == 10:
if N == 1:
ans[0] = 0
else:
ans[0] = 1
for i in range(1, N):
if ans[i] == 10:
ans[i] = 0
if N != 1 and ans[0] == 0:
print(-1)
exit()
ans = list(map(str, ans))
print("".join(ans)) | X = list(map(int, input().split()))
ans = None
for i, xi in enumerate(X):
if xi == 0:
ans = i + 1
print(ans) | 0 | null | 37,212,755,825,494 | 208 | 126 |
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
cnt_dict = {}
s = sum(A)
ans = []
for item in A:
if item not in cnt_dict:
cnt_dict[item] = 0
cnt_dict[item] += 1
for _ in range(Q):
b, c = map(int, input().split())
if b not in cnt_dict:
cnt_dict[b] = 0
if c not in cnt_dict:
cnt_dict[c] = 0
s -= b * cnt_dict[b]
s += c * cnt_dict[b]
cnt_dict[c] += cnt_dict[b]
cnt_dict[b] = 0
ans.append(s)
for i in range(Q):
print(ans[i]) | a,b,c = map(int, input().split())
X = c
Y = a
Z = b
print (X,Y,Z) | 0 | null | 25,022,665,231,652 | 122 | 178 |
def ALDS1_5A():
n, A, q = int(input()), list(map(int, input().split())), int(input())
S=[False for i in range(2001)]
for a in A:
for i in range(2001-a, 0, -1):
if S[i]: S[i+a] = True
S[a] = True
for mi in input().split():
if S[int(mi)]:
print('yes')
else:
print('no')
if __name__ == '__main__':
ALDS1_5A() | n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
def memoize(f):
cache = {}
def helper(x, y):
if (x, y) not in cache:
cache[(x, y)] = f(x, y)
return cache[(x, y)]
return helper
def main():
for number in m:
if solve(0, number):
print('yes')
else:
print('no')
@memoize
def solve(i, m):
if m == 0:
return True
if i >= n:
return False
res = solve(i + 1, m) or solve(i + 1, m - a[i])
return res
if __name__ == '__main__':
main()
| 1 | 101,068,830,626 | null | 25 | 25 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n, k = list(map(int, readline().split()))
comb1 = [0] * (n + 1)
comb2 = [0] * (n + 1)
comb1[0] = 1
comb2[0] = 1
for i in range(1, n + 1):
comb1[i] = comb1[i - 1] * (n + 1 - i)
comb2[i] = comb2[i - 1] * (n - i)
comb1[i] %= MOD
comb2[i] %= MOD
inv = pow(i, MOD - 2, MOD)
comb1[i] *= inv
comb2[i] *= inv
comb1[i] %= MOD
comb2[i] %= MOD
r = min(k, n - 1)
ans = 0
for i in range(r + 1):
ans += comb1[n - i] * comb2[n - 1 - i]
ans %= MOD
print(ans)
if __name__ == '__main__':
main()
| a=int(input())
b=list(map(int,input().split()))
b.sort()
c=0
for i in range(a-1):
if b[i]==b[i+1]:
c=c+1
if c==0:
print("YES")
else:
print("NO") | 0 | null | 70,375,198,291,232 | 215 | 222 |
#!/usr/bin/env python3
def solve(a,b):
str1 = str(a)*b
str2 = str(b)*a
if str1 < str2:
return str1
else:
return str2
def main():
a,b = map(int,input().split())
print(solve(a,b))
return
if __name__ == '__main__':
main()
| def main():
strTxt = input()
n = int(input())
for _ in range(n):
strCmd = input().split()
if strCmd[0] == 'print':
funcPrint(strTxt, int(strCmd[1]), int(strCmd[2]))
elif strCmd[0] == 'reverse':
strTxt = funcReverse(strTxt, int(strCmd[1]), int(strCmd[2]))
elif strCmd[0] == 'replace':
strTxt = funcReplace(strTxt, int(strCmd[1]), int(strCmd[2]), strCmd[3])
def funcPrint(strInput: str,a: int,b: int):
print(strInput[a:b+1])
def funcReverse(strInput: str,a: int,b: int):
return strInput[:a]+strInput[a:b+1][::-1]+strInput[b+1:]
def funcReplace(strInput: str,a: int,b: int, strAfter: str):
return strInput[:a]+strAfter+strInput[b+1:]
if __name__ == '__main__':
main()
| 0 | null | 43,079,818,487,848 | 232 | 68 |
N = int(input())
for i in range(N+1):
X = i * 1.08
if int(X) == N:
print(i)
exit()
print(':(') | def main():
N, K = (int(x) for x in input().split())
scores = [int(x) for x in input().split()]
first, last = 0, K-1
while last < N-1:
last += 1
if scores[first] < scores[last]: print('Yes')
else: print('No')
first += 1
if __name__ == '__main__':
main() | 0 | null | 66,760,549,287,992 | 265 | 102 |
n = int(input())
a = 0
for i in range(n+1):
if i%3== 0: continue
elif i%5 == 0:continue
elif i%3 ==0 and i %5 ==0:continue
else: a+=i
print(a) | n = int(input())
print(sum(i for i in range(1, n + 1) if i % 3 and i % 5)) | 1 | 35,018,340,716,102 | null | 173 | 173 |
# coding: utf-8
import sys
from collections import deque
n, q = map(int, input().split())
total_time = 0
tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))
for task in tasks:
task[1] = int(task[1])
while tasks:
t = tasks.popleft()
if t[1] <= q:
total_time += t[1]
print(t[0], total_time)
else:
t[1] -= q
total_time += q
tasks.append(t) | w=input().lower()
list=[]
while True:
s=input()
if s=="END_OF_TEXT":
break
c=s.lower().split().count(w)
list.append(c)
print(sum(list))
| 0 | null | 948,979,247,220 | 19 | 65 |
N = int(input())
S = ["*"]*(N+1)
S[1:] = list(input())
Q = int(input())
q1,q2,q3 = [0]*Q,[0]*Q,[0]*Q
for i in range(Q):
tmp = input().split()
q1[i],q2[i] = map(int,tmp[:2])
if q1[i] == 2:
q3[i] = int(tmp[2])
else:
q3[i] = tmp[2]
class BIT:
def __init__(self, n, init_list):
self.num = n + 1
self.tree = [0] * self.num
for i, e in enumerate(init_list):
self.update(i, e)
#a_kにxを加算
def update(self, k, x):
k = k + 1
while k < self.num:
self.tree[k] += x
k += (k & (-k))
return
def query1(self, r):
ret = 0
while r > 0:
ret += self.tree[r]
r -= r & (-r)
return ret
#通常のスライスと同じ。lは含み、rは含まない
def query2(self, l, r):
return self.query1(r) - self.query1(l)
s_pos = [BIT(N+1,[0]*(N+1)) for _ in range(26)]
for i in range(1,N+1):
s_pos[ord(S[i]) - ord("a")].update(i,1)
alphabets = [chr(ord("a") + i) for i in range(26)]
for i in range(Q):
if q1[i] == 1:
s_pos[ord(S[q2[i]]) - ord("a")].update(q2[i],-1)
S[q2[i]] = q3[i]
s_pos[ord(q3[i]) - ord("a")].update(q2[i],1)
else:
ans = 0
for c in alphabets:
if s_pos[ord(c) - ord("a")].query2(q2[i],q3[i]+1) > 0:
ans += 1
print(ans)
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return S().split()
def S(): return sys.stdin.readline().strip()
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)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007
class BIT:
def __init__(self, size):
self.bit = [0] * size
self.size = size
self.total = 0
def add(self, i, w):
x = i + 1
self.total += w
while x <= self.size:
self.bit[x - 1] += w
x += x & -x
return
def sum(self, i):
res = 0
x = i + 1
while x:
res += self.bit[x - 1]
x -= x & -x
return res
def interval_sum(self, i, j): # i <= x < j の区間
return self.sum(j - 1) - self.sum(i - 1) if i else self.sum(j - 1)
n = I()
s = list(S())
q = I()
D = defaultdict(lambda:BIT(n))
for j in range(n):
D[s[j]].add(j, 1)
for _ in range(q):
qi, i, c = LS()
if qi == "1":
i = int(i) - 1
D[s[i]].add(i, -1)
D[c].add(i, 1)
s[i] = c
else:
l, r = int(i) - 1, int(c)
ret = 0
for k in range(97, 123):
if D[chr(k)].interval_sum(l, r):
ret += 1
print(ret)
| 1 | 62,134,470,101,752 | null | 210 | 210 |
# D - Caracal vs Monster
H = int(input())
def rec(x):
if x==1:
return 1
else:
return 2*rec(x//2)+1
print(rec(H)) | #!/usr/bin/env python3
H = int(input())
i = 1
while H >= 2**i:
i += 1
ans = 0
for x in range(i):
ans += 2 ** x
print(ans)
| 1 | 79,831,605,242,632 | null | 228 | 228 |
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
'''
一つの整数
'''
return int(input())
def inpl():
'''
一行に複数の整数
'''
return list(map(int, input().split()))
n, k, c = inpl()
s = list(input())[:-1]
q = collections.deque()
cool = 0
left = [0] * n
right = [0] * n
val=-1
for i in range(n):
if cool<=0 and s[i]=="o" and val<k:
val += 1
cool = c
else:
cool-=1
left[i] = val
cool = 0
val+=1
for i in range(n-1,-1,-1):
if cool<=0 and s[i]=="o" and val>0:
val -= 1
cool = c
else:
cool-=1
right[i]=val
# print(left)
# print(right)
for i in range(n):
if left[i]==right[i] and (i == 0 or left[i] - left[i - 1] == 1) and (i == n - 1 or right[i + 1] - right[i] == 1):
print(i + 1)
| def solve():
for i in range(1,10):
for j in range(1,10):
print("{0}x{1}={2}".format(i,j,i*j))
solve() | 0 | null | 20,415,809,334,752 | 182 | 1 |
N = int(input())
X = input()
def popcount(x):
tmp = x
count = 0
while tmp > 0:
if tmp & 1 == 1:
count += 1
tmp >>= 1
return count
x = int(X, 2)
pcx = X.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)
for i in range(N):
if X[i] == '0':
X_next = pc2 + pow(2,N-1-i,pcx+1)
X_pop_next = pcx + 1
elif X[i] == '1' and pcx - 1 != 0:
X_next = pc1 - pow(2,N-1-i,pcx-1)
X_pop_next = pcx - 1
else :
print(0)
continue
if X_pop_next == 0:
print(0)
continue
X_next = X_next % X_pop_next
ans = 1
while X_next != 0:
X_next = X_next % popcount(X_next)
ans += 1
print(ans) | import sys
sys.setrecursionlimit(10**8)
n = int(input())
x = list(input())
bit_cnt = x.count('1')
# bitを一つ増やす場合
pos = [0] * n
pos_total = 0
# bitを一つ減らす場合
neg = [0] * n
neg_total = 0
base = 1
for i in range(n):
pos[-i-1] = base%(bit_cnt+1)
if x[-i-1] == '1':
# 同時にmod(bit_cnt+1)の法でトータルを作成
pos_total = (pos_total + base) % (bit_cnt+1)
base = (base*2) % (bit_cnt+1)
base = 1
if bit_cnt == 1:
# mod取れない
pass
else:
for i in range(n):
neg[-i-1] = base%(bit_cnt-1)
if x[-i-1] == '1':
# 同時にmod(bit_cnt-1)の法でトータルを作成
neg_total = (neg_total + base) % (bit_cnt-1)
base = (base*2) % (bit_cnt-1)
def popcount(n):
s = list(bin(n)[2:])
return s.count('1')
memo = {}
memo[0] = 0
def dfs(n, depth=0):
if n in memo:
return depth + memo[n]
else:
ret = dfs(n%popcount(n), depth+1)
# memo[n] = ret
return ret
ans = []
for i in range(n):
if x[i] == '0':
st = (pos_total + pos[i]) % (bit_cnt+1)
print(dfs(st, depth=1))
elif bit_cnt == 1:
# コーナーケース:すべてのbitが0となる
print(0)
else:
st = (neg_total - neg[i]) % (bit_cnt-1)
print(dfs(st, depth=1))
| 1 | 8,206,606,100,940 | null | 107 | 107 |
A,B=map(int,input().split())
import math
a=math.gcd(A,B)
ans=A*B//a
print(ans) | def gcd (a,b):
if a%b==0:
return b
if b%a==0:
return a
if a>b:
return gcd(b,a%b)
return gcd(a,b%a)
def lcm (a,b):
return ((a*b)//gcd(a,b))
inp=list(map(int,input().split()))
a=inp[0]
b=inp[1]
print (lcm(a,b)) | 1 | 113,409,999,121,244 | null | 256 | 256 |
from sys import exit
for i in input():
if i == '7':
print('Yes')
exit()
print('No')
| import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
N = I()
S,T = LS()
ans = ""
for i in range(N):
ans += S[i]
ans += T[i]
print(ans)
main()
| 0 | null | 72,952,346,256,988 | 172 | 255 |
N = int(input())
S = input()
counter = 0
for i in range(0,N-2):
if(S[i] == "A"):
if(S[i+1] == "B"):
if(S[i+2] == "C"):
counter += 1
print(counter) | A, B, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for _ in range(m):
x, y, c = map(int, input().split())
x -= 1
y -= 1
ans = min(ans, a[x] + b[y] - c)
print(ans)
| 0 | null | 76,507,969,844,178 | 245 | 200 |
n, m, l = map(int, raw_input().split(" "))
a = [map(int, raw_input().split(" ")) for j in range(n)]
b = [map(int, raw_input().split(" ")) for i in range(m)]
c = [[0 for k in range(l)] for j in range(n)]
for j in range(n):
for k in range(l):
for i in range(m):
c[j][k] += a[j][i] * b[i][k]
for j in range(n):
print " ".join(map(str, (c[j]))) | n = int(input())
d = {}
for i in range(n):
cmd, s = input().split()
if cmd == "insert":
d.update([(s, 0)])
else:
if s in d:
print("yes")
else:
print("no") | 0 | null | 747,017,014,542 | 60 | 23 |
x, y, p, q = map(float, input().split())
ans = ((p-x)**2 + (q-y)**2)**0.5
print(f"{ans:.8f}")
| import math
x1,y1,x2,y2=map(float,input().split())
n=(x1-x2)**2+(y1-y2)**2
n1=math.sqrt(n)
print(n1)
| 1 | 158,837,721,812 | null | 29 | 29 |
n = int(input())
dic = {}
for i in range(n):
line = input().split()
if line[0] == 'insert':
if dic.get(line[1]):
dic[line[1]] += 1
else:
dic[line[1]] = 1
elif line[0] == 'find':
if dic.get(line[1]):
print('yes')
else:
print('no') | def main():
n = int(stdinput())
st = [None] * (4**12)
for _ in range(n):
cmd, value = stdinput().split()
if cmd == 'insert':
st[get_hash(value)] = 1
elif cmd == 'find':
if st[get_hash(value)] == 1:
print('yes')
else:
print('no')
CODES = {'A' : 1, 'C' : 2, 'G' : 3, 'T' : 4}
def get_hash(s):
base = 1
h = 0
for c in s:
code = CODES[c]
h += code * base
base *= 4
return h
def stdinput():
from sys import stdin
return stdin.readline().strip()
if __name__ == '__main__':
main()
# import cProfile
# cProfile.run('main()')
| 1 | 78,608,190,400 | null | 23 | 23 |
a, b, c = [int(x) for x in input().split()]
if a + b + c >= 22:
print("bust")
else:
print("win")
| x, y = map(int, input().split())
a = max(0, 100000 * (4 - x))
b = max(0, 100000 * (4 - y))
c = 400000 if x == 1 and y == 1 else 0
print(a + b + c)
| 0 | null | 129,760,518,141,860 | 260 | 275 |
H = []
while True:
try:
H.append(input())
except EOFError:
break
H.sort()
print(H[-1])
print(H[-2])
print(H[-3]) | mount=[]
for i in range(10):
tmp=int(input())
mount.append(tmp)
mount.sort()
mount.reverse()
for i in range(3):
print(mount[i]) | 1 | 10,066,428 | null | 2 | 2 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
S = list(input())
lis = []
for s in S:
idx = ord(s)
if idx+N>90:
idx -= 26
lis.append(chr(idx+N))
print(''.join(lis)) | # B - Homework
# N M
N, M = map(int, input().split())
my_list = list(map(int, input().split(maxsplit=M)))
if N < sum(my_list):
answer = -1
else:
answer = N - sum(my_list)
print(answer)
| 0 | null | 83,087,299,114,398 | 271 | 168 |
import math
r = input()
area = r * r * math.pi * 1.0
cir = 2 * r * math.pi * 1.0
print '%f %f' % (area, cir) | import math
r = input()
S = math.pi * r ** 2
L = math.pi * r * 2
print "%f %f" %(S, L) | 1 | 650,785,864,172 | null | 46 | 46 |
import sys
input = sys.stdin.readline
# A - Number of Multiples
L, R, d = map(int, input().split())
ans = 0
for i in range(L, R + 1):
if i % d == 0:
ans += 1
print(ans) | n = str(input())
if '7' in n :
print('Yes')
if '7' not in n :
print('No') | 0 | null | 20,941,452,000,220 | 104 | 172 |
import sys
sys.setrecursionlimit(10**5)
n = int(input())
ab = [list(map(int,input().split()))for _ in range(n-1)]
graph = [[] for _ in range(n+1)]
ans = [0]*(n-1)
for i in range(n-1):
graph[ab[i][0]].append((ab[i][1],i))
graph[ab[i][1]].append((ab[i][0],i))
visit = [False]*(n+1)
def dfs(p,c):
color = 1
visit[p] = True
for n,i in graph[p]:
if visit[n] == False:
if color == c:
color += 1
ans[i] = color
dfs(n,color)
color += 1
dfs(1,0)
print(max(ans))
for t in ans:
print(t)
| from collections import deque
N = int(input())
# 有向グラフと見る、G[親] = [子1, 子2, ...]
G = [[] for _ in range(N + 1)]
# 子ノードを記録、これで辺の番号を管理
G_order = []
# a<bが保証されている、aを親、bを子とする
for i in range(N - 1):
a, b = map(lambda x: int(x) - 1, input().split())
G[a].append(b)
G_order.append(b)
# どこでも良いが、ここでは0をrootとする
que = deque([0])
# 各頂点と「親」を結ぶ辺の色
# 頂点0をrootとするのでC[0]=0で確定(「無色」), 他を調べる
colors = [0] * N
# BFS
while que:
# prt = 親
# 幅優先探索
prt = que.popleft()
color = 0
# cld = 子
for cld in G[prt]:
color += 1
# 「今考えている頂点とその親を結ぶ辺の色」と同じ色は使えないので次の色にする
if color == colors[prt]:
color += 1
colors[cld] = color
que.append(cld)
# それぞれの頂点とその親を結ぶ辺の色
# print(colors)
# 必要な最小の色数
print(max(colors))
# 辺の番号順に色を出力
for i in G_order:
print(colors[i])
| 1 | 136,190,030,779,708 | null | 272 | 272 |
list_data = input().split(" ")
if int(list_data[0]) > int(list_data[1]) * int(list_data[2]):
print("No")
else:
print("Yes") | S=input()
if S[-1]=='s':
Ans=S+'es'
else:
Ans=S+'s'
print(Ans) | 0 | null | 2,931,116,487,640 | 81 | 71 |
n, m = map(int, input().split())
print("YNeos"[n != m::2]) | N, M = [int(v) for v in input().rstrip().split()]
r = 'Yes' if N == M else 'No'
print(r)
| 1 | 83,365,407,734,310 | null | 231 | 231 |
import sys
import math
import collections
def set_debug(debug_mode=False):
if debug_mode:
fin = open('input.txt', 'r')
sys.stdin = fin
def int_input():
return list(map(int, input().split()))
def get(s):
return str(s % 9) + '9' * (s // 9)
if __name__ == '__main__':
# set_debug(True)
# t = int(input())
t = 1
for ti in range(1, t + 1):
n = int(input())
A = int_input()
cur = 0
for x in A:
cur = x ^ cur
res = []
for x in A:
res.append(cur ^ x)
print(*res)
| import math
a, b, C = map(float, input().split(' '))
rad = math.radians(C)
c = math.sqrt(a**2+b**2-2*a*b*math.cos(rad))
S = a*b*math.sin(rad)*1/2
L = a+b+c
h = abs(b*math.sin(rad))
print('{:.5f} {:.5f} {:.5f}'.format(S, L, h)) | 0 | null | 6,269,409,823,832 | 123 | 30 |
lit = input()
length = len(lit)
times = 0
if length != 1:
for i in range(int(length/2)):
if lit[i] != lit[length-1-i]:
times += 1
print(times)
else:
print(times) | s, hug = input(), 0
for i in range(len(s) // 2):
if s[i] != s[-(i+1)]:
hug += 1
print(hug) | 1 | 120,293,142,440,228 | null | 261 | 261 |
N = int(input())
S = input()
res = ""
pre = ""
for s in S:
if pre != s:
res += s
pre = s
print(len(res))
| def resolve():
def lcm(X, Y):
x = X
y = Y
if y > x:
x, y = y, x
while x % y != 0:
x, y = y, x % y
return X * Y // y
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
lsd = a[0]
for i in range(1, n):
lsd = lcm(lsd, a[i])
lsd = lsd % mod
ans = 0
for i in range(n):
ans += (lsd * pow(a[i], mod-2, mod)) % mod
print(int(ans % mod))
resolve() | 0 | null | 128,984,045,366,816 | 293 | 235 |
n,m=map(int,input().split())
l=list(map(int,input().split()))
l=list(set(l))
n=len(l)
ll=[]
for i in l:
ll.append(int(i/2))
newl=[]
for i in ll:
j=i
count=0
while j%2==0:
j//=2
count+=1
newl.append(count)
import collections
newl=collections.Counter(newl)
if len(newl)!=1:
print(0)
else:
from fractions import gcd
num=ll[0]
flag=True
for i in ll:
if num<=m:
num=int(i*num/gcd(i,num))
else:
flag=False
break
if flag==False:
print(0)
else:
k=m%(num*2)
if k>=num:
print(int(m//(num*2)+1))
else:
print(int(m//(num*2))) | def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
def two(val):
ret = 0
tmp = val
while True:
if tmp != 0 and tmp % 2 == 0:
ret += 1
tmp = tmp // 2
else:
break
return ret
n, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = []
for item in a_list:
b_list.append(item // 2)
cnt = -1
for item in b_list:
ret = two(item)
if cnt == -1:
cnt = ret
elif cnt != ret:
print(0)
exit()
val = b_list[0]
for item in b_list:
val = lcm(item, val)
ret = m // val
tmp1 = ret // 2
tmp2 = ret % 2
print(tmp1 + tmp2)
| 1 | 101,837,595,885,520 | null | 247 | 247 |
a=0
b=0
n=int(input())
for i in range(n):
x=input().split()
y=x[0]
z=x[1]
if y>z:a+=3
elif y<z:b+=3
else:
a+=1
b+=1
print(a,b) | t=0
h=0
for i in range(int(input())):
l=input().split()
if l[0]==l[1]:
t+=1
h+=1
elif l[0]>l[1]: t+=3
else: h+=3
print(t,h) | 1 | 1,976,142,743,760 | null | 67 | 67 |
n, k = map(int, input().split(" "))
def calc(n, k):
r = ""
while n > 0:
n, remainder = divmod(n, k)
r += str(remainder)
return r[::-1]
print(len(calc(n, k))) | import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
H, W = map(int, readline().split())
import math
if W == 1 or H == 1:
print(1)
exit()
w_can = W // 2
ans = w_can * H
if W % 2 != 0:
ans += math.ceil(H / 2)
print(ans) | 0 | null | 57,445,751,008,272 | 212 | 196 |
import sys
N = int(input())
p = list(map(int, input().split()))
for i in range(N):
if p[i] == 0:
print(0)
sys.exit()
product = 1
for i in range(N):
product = product * p[i]
if product > 10 ** 18:
print(-1)
sys.exit()
break
print(product) | a,b=open(0);c=1;
for i in sorted(b.split()):
c*=int(i)
if c>10**18:c=-1;break
print(c) | 1 | 16,033,647,101,980 | null | 134 | 134 |
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
n = int(input())
s = input()
if (n % 2 != 0):
print("No")
exit()
for i in range(n//2):
if (s[i] != s[n//2 + i]):
print("No")
exit()
print("Yes")
| S = input()
Q = int(input())
rev = False
l, r = "", ""
for _ in range(Q):
query = input()
if query[0] == "1":
rev = not rev
else:
T, F, C = query.split()
if F == "1":
if rev:
r += C
else:
l = C + l
else:
if rev:
l = C + l
else:
r += C
res = l + S + r
if rev:
res = res[::-1]
print(res) | 0 | null | 101,701,295,767,530 | 279 | 204 |
N, K = map(int, input().split())
Range = [None] * K
for i in range(K):
Range[i] = list(map(int, input().split()))
sweep = {1: 1}
M = 998244353
value = 0
for cell in range(1, N+1):
value += sweep.get(cell, 0)
value = (value + M) % M
for r in range(K):
sweep[cell + Range[r][0]] = (sweep.get(cell + Range[r][0], 0) + value + M) % M
sweep[cell + Range[r][1] + 1] = (sweep.get(cell + Range[r][1] + 1, 0) - value + M) % M
print(sweep.get(N, 0)) | from itertools import accumulate
N, K = map(int, input().split())
mod = 998244353
Move = [list(map(int, input().split())) for _ in range(K)]
DP = [0] * N
DP[0] = 1
DP[1] = -1
cnt = 0
for i in range(N):
DP[i] += cnt
DP[i] %= mod
cnt = DP[i]
for l, r in Move:
if i + l < N:
DP[i+l] += DP[i]
if i + r + 1 < N:
DP[i + r + 1] -= DP[i]
print(DP[-1]) | 1 | 2,718,736,955,970 | null | 74 | 74 |
'''
Created on 2020/09/26
@author: harurun
'''
#UnionFind(要素数)で初期化
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
#parents 各要素の親番号を格納するリストを返す
#要素xが属するグループを返す
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
#要素xとyが属するグループを併合する
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
#要素xが属するグループのサイズ
def size(self, x):
return -self.parents[self.find(x)]
#要素xとyが同じグループに属するかどうか
def same(self, x, y):
return self.find(x) == self.find(y)
#要素xが属するグループを返す
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
#すべての根の要素
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
#グループの数
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write
N,M=map(int,pin().split())
ans=0
uf=UnionFind(N)
for i in range(M):
A,B=map(int,pin().split())
uf.union(A-1, B-1)
print(uf.group_count()-1)
return
main()
| N, K = map(int, input().split())
mod = 10 ** 9 + 7
cnt = [0] * (K + 1)
answer = 0
for i in range(K, 0, -1):
tmp = pow(K // i, N, mod) - sum(cnt[::i])
cnt[i] = tmp
answer = (answer + tmp * i) % mod
print(answer)
| 0 | null | 19,497,115,530,588 | 70 | 176 |
N = int(input())
def solve(N):
fib = [1]*(N+1)
for i in range(2,N+1):
fib[i] = fib[i-1] + fib[i-2]
ans = fib[N]
return ans
print(solve(N))
| #ABC157E
n = int(input())
s = list(input())
q = int(input())
bits = [[0 for _ in range(n+1)] for _ in range(26)]
sl = []
for alp in s:
alpord = ord(alp) - 97
sl.append(alpord)
#print(bits) #test
#print(sl) #test
#print('クエリ開始') #test
def query(pos):
ret = [0] * 26
p = pos
while p > 0:
for i in range(26):
ret[i] += bits[i][p]
p -= p&(-p)
return ret
def update(pos, a, x):
r = pos
while r <= n:
bits[a][r] += x
r += r&(-r)
for i in range(n):
update(i+1, sl[i], 1)
#print(bits) #test
for _ in range(q):
quer, xx, yy = map(str, input().split())
if quer == '1':
x = int(xx)
y = ord(yy) - 97
if sl[x-1] == y:
continue
else:
update(x, sl[x-1], -1)
update(x, y, 1)
sl[x-1] = y
#print('クエリ1でした') #test
#print(bits) #test
#print(sl) #test
else:
x = int(xx)
y = int(yy)
cnt1 = query(y)
cnt2 = query(x-1)
#print('クエリ2です') #test
#print(cnt1) #test
#print(cnt2) #test
ans = 0
for i in range(26):
if cnt1[i] - cnt2[i] > 0:
ans += 1
print(ans) | 0 | null | 31,188,279,786,602 | 7 | 210 |
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
N,K,S = MI()
if S == 10**9:
ANS = [10**9]*K + [1]*(N-K)
else:
ANS = [S]*K + [10**9]*(N-K)
print(*ANS)
| n,k,s = map(int, input().split())
ans = []
if s == 10**9:
for i in range(k):
ans.append(10**9)
for i in range(n-k):
ans.append(1)
else:
for i in range(k):
ans.append(s)
for i in range(n-k):
ans.append(s+1)
print(*ans) | 1 | 91,048,846,594,922 | null | 238 | 238 |
import math
n=int(input())
while n != 0 :
sums = 0.0
s = list(map(float,input().split()))
m = sum(s)/n
for i in range(n):
sums += ((s[i]-m)**2)/n
print(math.sqrt(sums))
n = int(input())
| import math
while True:
n = input()
if n == "0":
break
else:
score = list(map(float, input().split()))
m = sum(score)/len(score)
for i in range(len(score)):
score[i] = (score[i]-m)**2
answer = math.sqrt(sum(score)/len(score))
print(answer) | 1 | 191,899,401,490 | null | 31 | 31 |
def main():
N = int(input())
print(int((N+1)/2))
main()
| #!/usr/bin/env python3
import sys
input = sys.stdin.readline
mod = 1000000007
def ST():
return input().rstrip()
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(MI())
N, K = MI()
MAX = sum(range(N - K + 2, N + 1))
MIN = sum(range(0, K - 1))
ans = 0
for k in range(K, N + 2):
MAX += N - k + 1
MIN += k - 1
ans += (MAX - MIN + 1) % mod
print(ans % mod)
| 0 | null | 45,955,066,154,228 | 206 | 170 |
_ = int(input())
a = map(int, raw_input().split(' '))
print min(a), max(a), sum(a) | A, B, C = map(int, input().split())
Z = A + B + C
if Z >= 22:
print("bust")
else:
print("win")
| 0 | null | 59,585,588,585,700 | 48 | 260 |
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if a<b and v<=w:
print("NO")
elif w>v:
print("NO")
else:
if abs(b-a)<=t*abs(v-w):
print("YES")
else:
print("NO")
| a, v = list(map(int, input().split(' ')))
b, w = list(map(int, input().split(' ')))
time = int(input())
if a>b:
x1 = a - v*time
x2 = b - w*time
if x1 <= x2:
print('YES')
else:
print('NO')
elif a<b:
x1 = a + v*time
x2 = b + w*time
if x1 >= x2:
print('YES')
else:
print('NO')
| 1 | 15,128,575,955,740 | null | 131 | 131 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.parents[self.find(x)]
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,m=nii()
uf=UnionFind(n)
for i in range(m):
a,b=nii()
a-=1
b-=1
uf.union(a,b)
root=uf.roots()
ans=0
for i in root:
ans=max(ans,uf.size(i))
print(ans) | from collections import Counter
N = int(input())
A = list(map(int,input().split()))
S1 = Counter()
S2 = Counter()
for i,a in enumerate(A):
S1[i+1+a] += 1
S2[(i+1)-a] += 1
res = 0
for k,v in S1.items():
if S2[k] > 0:
res += v*S2[k]
print(res)
| 0 | null | 15,024,439,797,920 | 84 | 157 |
S = input()
day = ['SUN','MON','TUE','WED','THU','FRI','SAT']
for i in range(len(day)):
if S == day[i]:
print(7-i)
break | N,M=input().split()
N=int(N)
M=int(M)
if N==M:
print("Yes")
else:
print("No") | 0 | null | 108,068,956,597,290 | 270 | 231 |
def func(A):
result = 0
min = 0
for a in A:
if a < min:
result += min - a
else:
min = a
return result
if __name__ == "__main__":
N = int(input())
A = list(map(int,input().split()))
print(func(A)) | n = int(input())
x = list(map(int, input().split()))
result = 0
for i in range(n - 1):
if x[i] > x[i + 1]:
result += (x[i] - x[i + 1])
x[i + 1] = x[i]
print(result) | 1 | 4,504,941,408,978 | null | 88 | 88 |
# for内をご丁寧に書いていたらTLEを食らった
# PyPyだとそのままで通った、すごい
# for内の冗長な部分を排除しまくったらPythonでも通った
# N=6とかで実験して、横で見ていたのを縦から眺めてみると良い(伝われ)
# (1+2+...+6) + (2+4+6) + ... + (6)と見る
# 結局何を足したいのか考えて約数のところを書き換える(伝われ)
N = int(input())
ans = 0
for i in range(1, N + 1):
n = N // i
temp = (n * (n + 1) * i) // 2
ans += temp
print(ans)
| import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n = ri()
ans=0
for i in range(1,n+1):
ans+=(n//i)*(n//i+1)*i//2
print(ans) | 1 | 11,021,088,072,188 | null | 118 | 118 |
[N, X, T] = list(map(int, input().split()))
#N個のたこ焼きを作るためにタコ焼き機を使う回数Y
if N % X == 0:
Y = N // X
else:
Y = N // X + 1
ans = T * Y
print(ans) | N, X, T = map(int, input().split())
ANS = -(-N // X) * T
print(ANS) | 1 | 4,237,717,738,072 | null | 86 | 86 |
S = raw_input()
n = int(raw_input())
for i in range(n):
command = (raw_input()).split(" ")
if command[0] == "print":
a = int(command[1])
b = int(command[2])
print S[a:b+1]
elif command[0] == "reverse":
a = int(command[1])
b = int(command[2])
T = S[a:b+1]
S = S[0:a] + T[::-1] + S[b+1:]
else:
a = int(command[1])
b = int(command[2])
S = S[0:a] + command[3] + S[b+1:] | def print_func(s, order):
print(s[order[1]:order[2]+1])
def reverse_func(s, order):
ans = list(s[order[1]:order[2]+1])
ans.reverse()
s = s[:order[1]]+''.join(ans)+s[order[2]+1:]
return s
def replace_func(s, order):
cnt = 0
s = list(s)
for i in range(order[1], order[2]+1):
s[i] = str(order[3])[cnt]
cnt += 1
s = ''.join(s)
return s
if __name__ == '__main__':
s = input()
for i in range(int(input())):
order = input().split()
order[1] = int(order[1])
order[2] = int(order[2])
if order[0] == 'print':
print_func(s, order)
elif order[0] == 'reverse':
s = reverse_func(s, order)
else:
s = replace_func(s, order) | 1 | 2,117,160,644,786 | null | 68 | 68 |
a = 1; b = 1
while True:
print(a,"x",b,"=",a*b,sep="")
b += 1
if b == 10:
a += 1; b = 1
if a == 10:
break
| # ABC 173 D
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ind=[(i+1)//2 for i in range(N-1)]
print(sum([A[i] for i in ind])) | 0 | null | 4,564,383,050,478 | 1 | 111 |
X = int(input())
SUM = 0
(X * 1000 / 500)
Z = X // 500
A = X % 500
SUM = SUM + (Z * 1000)
B = A // 5
SUM = SUM + (B * 5)
print(int(SUM)) | x = int(input())
a = x // 500
b = (x - (a * 500)) // 5
c = (a * 1000) + (b * 5)
print(c) | 1 | 42,667,543,014,490 | null | 185 | 185 |
s=input()
ans = 0
for i in range(len(s)):
j = len(s)-i-1
if i > j: break
if s[i] != s[j]: ans += 1
print(ans) | S = input()
ans = 0
for i in range(int(len(S) / 2)):
if S[i] != S[-1-i]:
ans += 1
print(ans) | 1 | 120,459,113,804,348 | null | 261 | 261 |
x1,y1,x2,y2=map(float,input().split())
print(f'{((x2-x1)**2+(y2-y1)**2)**0.5:.6f}')
| import math
x1, y1, x2, y2 = map(float, input().split())
x = math.fabs(x2 - x1)
y = math.fabs(y2 - y1)
d = math.sqrt(x**2 + y**2)
print('{:.8f}'.format(d))
| 1 | 157,905,513,866 | null | 29 | 29 |
def insertion_sort(numbers, n, g):
"""insertion sort method
(only elements whose distance is larger than g are the target)
Args:
numbers: list of elements to be sorted
n: len(numbers)
g: distance
Returns:
partially sorted list, counter
"""
counter = 0
copied_instance = []
for data in numbers:
copied_instance.append(data)
for i in range(g, n):
target = copied_instance[i]
j = i - g
while j >= 0 and target < copied_instance[j]:
copied_instance[j + g] = copied_instance[j]
j -= g
counter += 1
copied_instance[j + g] = target
return copied_instance, counter
def shell_sort(numbers, n, key=lambda x: x):
"""shell sort method
Args:
numbers: list of elements to be sorted
n: len(numbers)
Returns:
sorted numbers, used G, swapped number
"""
counter = 0
copied_instance = []
for data in numbers:
copied_instance.append(data)
G = [1]
g = 4
while g < len(numbers):
G.append(g)
g = g * 3 + 1
G = G[::-1]
for g in G:
copied_instance, num = insertion_sort(copied_instance, n, g)
counter += num
return copied_instance, G, counter
length = int(raw_input())
numbers = []
counter = 0
while counter < length:
numbers.append(int(raw_input()))
counter += 1
numbers, G, counter = shell_sort(numbers, length)
print(len(G))
print(" ".join([str(x) for x in G]))
print(counter)
for n in numbers:
print(str(n)) | N,M=list(map(int,input().split()))
C=list(map(int,input().split()))
dp = [[0]*len(C) for n in range(N+1)] #dp[n][c]
for n in range(1,N+1):
dp[n][0] = n
for n in range(1,N+1):
for c in range(1,len(C)):
if C[c] > n:
dp[n][c]=dp[n][c-1]
else:
dp[n][c]=min(dp[n][c-1],dp[n-C[c]][c]+1)
print(dp[-1][-1])
| 0 | null | 88,825,680,300 | 17 | 28 |
S = input()
companies = {company for company in S}
if len(companies) > 1:
print('Yes')
else:
print('No') | s = input()
prev = s[0]
for i in range(1, 3):
if s[i] != prev:
print('Yes')
break
else:
print('No')
| 1 | 54,994,275,832,548 | null | 201 | 201 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.