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
|
---|---|---|---|---|---|---|
def resolve():
H = int(input())
ans = 1
while H > 0:
ans *= 2
H //= 2
print(ans - 1)
resolve()
| import sys
line = sys.stdin.readline()
print(line[0:3])
| 0 | null | 47,463,310,107,558 | 228 | 130 |
R = int(input())
print(R * 6.28318530717958623200) | r = int(input())
import math
ans = 2 * math.pi * r
print(ans) | 1 | 31,639,742,577,574 | null | 167 | 167 |
import sys
a,b,c = map(int,sys.stdin.readline().split())
if a < b and b < c:
print('Yes')
else:
print('No') | a,b,c = map(int,input().split())
if a < b < c :
print('Yes')
else :
print('No')
| 1 | 379,234,504,860 | null | 39 | 39 |
from collections import defaultdict
N,K=map(int,input().split())
alist=list(map(int,input().split()))
#print(alist)
slist=[0]
for i in range(N):
slist.append(slist[-1]+alist[i])
#print(slist)
sslist=[]
for i in range(N+1):
sslist.append((slist[i]-i)%K)
#print(sslist)
answer=0
si_dic=defaultdict(int)
for i in range(N+1):
if i-K>=0:
si_dic[sslist[i-K]]-=1
answer+=si_dic[sslist[i]]
si_dic[sslist[i]]+=1
print(answer) | a, b, k = map(int, input().split())
after_a = max(0, a - k)
after_b = b
if after_a == 0:
k -= a
after_b = max(0, b - k)
print(after_a, after_b) | 0 | null | 121,108,162,101,376 | 273 | 249 |
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def main():
S = SI()
Q = NI()
que = deque(list(S))
reverse = False
for q in range(Q):
query = input()
if query == "1":
if reverse == False:
reverse = True
else:
reverse = False
else:
x,y,z = map(str,query.split())
if reverse == False:
if y == "1":
que.appendleft(z)
else:
que.append(z)
else:
if y == "1":
que.append(z)
else:
que.appendleft(z)
if reverse==True:
print("".join(reversed(list(que))))
else:
print("".join(list(que)))#print(x,y,z)
if __name__ == '__main__':
main() | 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) | 1 | 57,184,655,312,890 | null | 204 | 204 |
def main():
import sys
readline = sys.stdin.buffer.readline
n, x, y = map(int, readline().split())
l = [0] * (n-1)
for i in range(1, n):
for j in range(i+1, n+1):
s = min(j-i, abs(x-i)+abs(j-y)+1)
l[s-1] += 1
for i in l:
print(i)
main() | N,X,Y=map(int,input().split())
d=[0]*N
for i in range(N):
for j in range(N):
if not i<j:
continue
dist=min([j-i,abs((X-1)-i)+1+abs(j-(Y-1))])
d[dist]+=1
print(*d[1:],sep='\n') | 1 | 44,114,497,243,388 | null | 187 | 187 |
x, n = map(int, input().split())
p = sorted(list(map(int, input().split())))
a = 100
b = 0
for i in range(0, 102):
if i not in p and abs(x - i) < a:
a = abs(x - i)
b = i
print(b)
| import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
N, T = map(int, readline().split())
dishes = []
for _ in range(N):
A, B = map(int, readline().split())
dishes.append([A, B])
dp1 = [[0]*T for _ in range(N)] # i and less than i
dp2 = [[0]*T for _ in range(N+1)] # more than i
for i, dish in enumerate(dishes[:-1]):
a, b = dish
i = i + 1
for t in range(T):
if a > t:
dp1[i][t] = dp1[i-1][t]
else:
if dp1[i-1][t-a] + b > dp1[i-1][t]:
dp1[i][t] = dp1[i-1][t-a] + b
else:
dp1[i][t] = dp1[i-1][t]
for i, dish in enumerate(reversed(dishes[1:])):
a, b = dish
i = N - i - 1
for t in range(T):
if a > t:
dp2[i][t] = dp2[i+1][t]
else:
if dp2[i+1][t-a] + b > dp2[i+1][t]:
dp2[i][t] = dp2[i+1][t-a] + b
else:
dp2[i][t] = dp2[i+1][t]
ans = 0
for last in range(1, N+1):
for j in range(T):
a = dishes[last-1][1]
a += dp1[last-1][T-1-j] + dp2[last][j]
ans = a if ans < a else ans
print(ans)
if __name__ == '__main__':
solve() | 0 | null | 82,858,640,910,260 | 128 | 282 |
inputted = list(map(int, input().split()))
N = inputted[0]
M = inputted[1]
answer = 'Yes' if N == M else 'No';
print(answer);
| ans = []
while True:
tmp = input().split()
a, b = map(int, [tmp[0], tmp[2]])
op = tmp[1]
if op == "?":
break
if op == "+":
ans.append(a + b)
if op == "-":
ans.append(a - b)
if op == "*":
ans.append(a * b)
if op == "/":
ans.append(a // b)
print("\n".join(map(str, ans)))
| 0 | null | 41,899,094,835,950 | 231 | 47 |
A1, A2, A3 = (int(x) for x in input().split())
if A1+A2+A3>=22:
print("bust")
else:
print("win") | a, b, c = [int(x) for x in input().split()]
if a + b + c >= 22:
print("bust")
else:
print("win")
| 1 | 118,651,818,835,980 | null | 260 | 260 |
str = raw_input()
li = []
for c in list(str):
if c.isupper():
li.append(c.lower())
elif c.islower():
li.append(c.upper())
else:
li.append(c)
print ''.join(li) | *abc, k = map(int, input().split())
n = [0] * 3
for i, v in enumerate(abc):
if k >= v:
n[i] = v
k -= v
else:
n[i] = k
break
print(n[0] + n[2] * -1) | 0 | null | 11,767,818,285,858 | 61 | 148 |
def main():
mod=1000000007
s=int(input())
m=s*2
inv=lambda x: pow(x,mod-2,mod)
Fact=[1] #階乗
for i in range(1,m+1):
Fact.append(Fact[i-1]*i%mod)
Finv=[0]*(m+1) #階乗の逆元
Finv[-1]=inv(Fact[-1])
for i in range(m-1,-1,-1):
Finv[i]=Finv[i+1]*(i+1)%mod
def comb(n,r):
if n<r:
return 0
return Fact[n]*Finv[r]*Finv[n-r]%mod
ans=0
num=s//3
for i in range(1,num+1):
n=s-i*3
ans+=comb(n+i-1,n)
ans%=mod
print(ans)
if __name__=='__main__':
main() | # dp[i][j]:=(総和がiで長さがjの数列の個数)とする
# このままだとO(s^3)だが、全てのjに対してΣ(k=0→i-3)dp[k][j]をあらかじめ持っておけばO(s^2)となる
# dpの遷移式立てたときはちゃんと紙に書いて眺めなきゃ(使命感)
s=int(input())
mod=10**9+7
dp=[[0]*(s+1) for _ in range(s+1)]
accum=[0]*(s+1)
dp[0][0]=1
for i in range(3,s+1):
for j in range(s):
accum[j]+=dp[i-3][j]
dp[i][j+1]+=accum[j]
dp[i][j+1]%=mod
print(sum(dp[s])%mod) | 1 | 3,293,337,039,410 | null | 79 | 79 |
def solve():
S = input()
T = input()
ans = float('inf')
for i in range(0,len(S)-len(T)+1):
cnt = 0
for j in range(len(T)):
if S[i+j] != T[j]:
cnt += 1
ans = min(cnt,ans)
print(ans)
if __name__ == '__main__':
solve()
| #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LS()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]
n, m = LI()
c = LI()
c = sorted(c)
dp = [n+1]*(n+1)
dp[0] = 0
for i in range(n+1):
for coin in c:
if (i+coin <= n) and (dp[i+coin] > dp[i]+1):
dp[i+coin] = dp[i]+1
print(dp[n])
| 0 | null | 1,922,283,319,768 | 82 | 28 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
MAX_PRIME = 10**4
def prime_list():
sqrt_max = int(MAX_PRIME ** 0.5)
primes = [True for i in range(MAX_PRIME+1)]
primes[0] = primes[1] = False
for p in range(sqrt_max):
if primes[p]:
for px in range(p*2, MAX_PRIME, p):
primes[px] = False
p_list = [i for i in range(MAX_PRIME) if primes[i]]
return p_list
def is_prime(n, prime_list):
sqrt_n = int(n ** 0.5)
for i in prime_list:
if i > sqrt_n:
break
if n % i == 0:
return False
return True
p_list = prime_list()
n = int(sys.stdin.readline())
num_p = 0
for i in range(n):
x = int(sys.stdin.readline())
if is_prime(x, p_list):
num_p += 1
print(num_p)
| N, K = map(int, input().split())
*A, = map(int, input().split())
def f(t):
if t!=0:
c = 0
for i in A:
c += i//t if i!=t else 0
return c<=K
else:
return all(i<=t for i in A)
left, right = -1, 10**10
while right-left>1:
m = (right+left)//2
if f(m):
right = m
else:
left = m
print(right)
| 0 | null | 3,249,914,108,992 | 12 | 99 |
c = 0
def merge(A, l, m, r):
global c
L = A[l:m]
L.append(1e10)
R = A[m:r]
R.append(1e10)
i, j = 0, 0
for k in range(l, r):
c += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
def sort(A, l, r):
if r-l > 1:
m = (l+r)//2
sort(A, l, m)
sort(A, m, r)
merge(A, l, m, r)
N = int(input())
A = list(map(int, input().split()))
sort(A, 0, N)
print(" ".join(map(str, A)))
print(c)
| n=int(input())
if n%2:
a=list(map(int,input().split()))
s=[[a[0],0,0],[0,a[1],0],[a[0]+a[2],0,a[2]]]+[[0,0,0]for i in range(3,n)]
for i in range(3,n):
if i%2:
s[i][1]=max(s[i-2][1],s[i-3][0])+a[i]
else:
s[i][0]=s[i-2][0]+a[i]
s[i][2]=max([s[i-2][2],s[i-3][1],s[i-4][0]])+a[i]
print(max([s[-1][2],s[-2][1],s[-3][0]]))
else:
a=list(map(int,input().split()))
s=[a[0],a[1]]+[0 for i in range(2,n)]
for i in range(2,n):
if i%2:
s[i]=max([s[i-2],s[i-3]])+a[i]
else:
s[i]=s[i-2]+a[i]
print(max(s[-2:])) | 0 | null | 18,608,145,501,388 | 26 | 177 |
s = input()
w = ['SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN']
print(w.index(s)+1)
| import math
# 素数か否かを判定する関数
def is_prime(n):
for i in range(2, int(math.sqrt(n))+1):
if n%i == 0:
return False
return True
# nまでの素数を返す関数(エラトステネスの篩)
def getPrime(n):
n_sqrt = int(math.sqrt(n))
array = [True]*(n_sqrt+1)
result = []
for i in range(2, n_sqrt+1):
if array[i]:
array[i] = False
result.append(i)
for j in range(i*2, n_sqrt+1, i):
array[j] = False
return result
N = int(input())
n = N
prime = getPrime(n)
prime_exp = []
# print(prime)
for p in prime:
cnt = 0
while n%p == 0:
n = int(n/p)
# print(n)
cnt += 1
if cnt != 0:
prime_exp.append([p, cnt])
if is_prime(n) and n != 1:
prime_exp.append([n, 1])
ans = 0
for pe in prime_exp:
ans += int((-1+math.sqrt(1+8*pe[1]))/2)
print(ans) | 0 | null | 75,059,233,247,448 | 270 | 136 |
input_str = input().split()
amount_to_make = int(input_str[0])
lot_size = int(input_str[1])
time_to_make_one_lot = int(input_str[2])
proceeded_time = 0
made_amount = 0
while made_amount < amount_to_make:
made_amount += lot_size
proceeded_time += time_to_make_one_lot
print(proceeded_time)
| n,x,t = map(int,(input().split()))
i = 1
while 1:
if n > x*i:
i += 1
if n <= x*i:
break
print(t*i) | 1 | 4,272,544,627,740 | null | 86 | 86 |
import numpy as np
D = int(input())
c = np.array(list( map(int,input().split())))
S = np.zeros((D,26))
for i in range(D):
S[i] = np.array(list( map(int,input().split())))
T = np.array([])
for i in range(D):
T = np.append(T,int(input()))
"""
D = 365
c = np.random.randint(0,100,size=(26))
S = np.random.randint(0,20000,size=(D,26))
"""
def calc_score(T,D,c,S):
last = np.ones(26) * (-1)
scores = []
score = 0
for d in range(D):
i = int(T[d])-1
score += S[d,i]
last[i] = d
score -= np.sum(c*(d-last))
scores.append(score)
score = max([10**6+score,0])
return score,scores
_,ans = calc_score(T,D,c,S)
for a in ans:
print(int(a)) | D=int(input())
c=[None]+list(map(int, input().split()))
s=[None]+[list(map(int, input().split())) for _ in range(D)]
T=[None]+[int(input()) for _ in range(D)]
lastdi=[None]+[0]*26
v=0
for i in range(1, D+1):
v+=s[i][T[i]-1]
lastdi[T[i]]=i
for x in range(1, 27):
v-=(i-lastdi[x])*c[x]
print(v) | 1 | 9,996,999,801,088 | null | 114 | 114 |
import fractions
from functools import reduce
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
A[i] = A[i] // 2
p = 0
de_2 = 0
x = A[0]
while (p == 0):
if x % 2 == 0:
x = x // 2
de_2 += 1
else:
p = 1
de = 2 ** de_2
for i in range(1, N):
if A[i] % de == 0:
if A[i] % (de * 2) != 0:
continue
else:
print("0")
quit()
else:
print("0")
quit()
lcm = lcm_list(A)
p = M // lcm
if p % 2 == 0:
ans = p // 2
else:
ans = (p + 1) // 2
print(ans)
| import fractions
N,M = map(int,input().split())
A = list(map(int,input().split()))
t=1
while A:
b=0
for i in range(N):
A[i]=int(A[i]/2)
if A[i]%2==1:
b+=1
if b==N:
break
elif 0<b<N:
t=0
break
else:
t+=1
if t==0:
print(0)
else:
ans = A[0]
for i in range(1, N):
ans = ans * A[i] // fractions.gcd(ans, A[i])
ans=min(ans,(M+1))
c=int(M/(2**(t-1))/ans)
d=int(M/(2**(t))/ans)
print(c-d) | 1 | 101,902,695,235,770 | null | 247 | 247 |
import itertools
for x, y in itertools.product(range(1, 10), range(1, 10)):
print("%dx%d=%d" % (x, y, x * y)) | a = 1
while a<10:
b=1
while b<10:
print(str(a)+'x'+str(b)+'='+str(a*b))
b=b+1
a=a+1 | 1 | 1,508,402 | null | 1 | 1 |
import math
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if abs(a-b) <= (v-w)*t :
print('YES')
else:
print('NO')
| import math
import sys
import collections
import bisect
readline = sys.stdin.readline
def main():
n = int(readline().rstrip())
S = [readline().rstrip() for _ in range(n)]
c = collections.Counter(S)
keys = sorted(c.keys())
maxS = c.most_common()[0][1]
for key in keys:
if c[key] == maxS:
print(key)
if __name__ == '__main__':
main()
| 0 | null | 42,576,411,328,934 | 131 | 218 |
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N,K = LI()
f = [1]
r = [1]
s = 1
for i in range(1,N+2):
s = (s * i) % MOD
f.append(s)
r.append(pow(s,MOD-2,MOD))
def comb(a,b):
return f[a] * r[b] * r[a-b]
ans = 0
for k in range(min(K,N-1)+1):
ans = (ans + comb(N,k) * comb(N-1,k)) % MOD
print(ans)
if __name__ == '__main__':
main() | import random
s=input()
a=len(s)
b=random.randint(0,a-3)
print(s[b:b+3]) | 0 | null | 40,696,417,154,568 | 215 | 130 |
n,k=map(int,input().split())
mod=10**9+7
count=[0]*(k+1)
def getnum(m):
ret = pow(k//m,n,mod)
mul=2
while m*mul<=k:
ret-=count[m*mul]
mul+=1
return ret%mod
ans=0
for i in range(1,k+1)[::-1]:
g=getnum(i)
count[i]=g
ans+=g*i
ans%=mod
print(ans) | import sys
input = sys.stdin.readline
P = 10 ** 9 + 7
def main():
N, K = map(int, input().split())
ans = 0
n_gcd = [0] * (K + 1)
for k in reversed(range(1, K + 1)):
n = pow(K // k, N, mod=P)
for kk in range(2 * k, K + 1, k):
n -= n_gcd[kk]
n_gcd[k] = n % P
ans += k * n_gcd[k]
ans %= P
print(ans)
if __name__ == "__main__":
main()
| 1 | 36,678,381,190,660 | null | 176 | 176 |
n = int(input())
mn = int(input())
ans = -1 * 10 ** 10
for i in range(n - 1):
r = int(input())
diff = r - mn
if diff > ans:
ans = diff
mn = min(mn, r)
print(ans)
| import math
R = int(input())
round_R = 2 * R * math.pi
print(round(round_R, 10)) | 0 | null | 15,731,072,740,420 | 13 | 167 |
def main():
import sys
from collections import Counter
input = sys.stdin.readline
input()
a = tuple(map(int, input().split()))
ans = sum(a)
a = Counter(a)
for _ in range(int(input())):
b, c = map(int, input().split())
if b in a:
ans += (c - b) * a[b]
a[c] = a[c] + a[b] if c in a else a[b]
del a[b]
print(ans)
if __name__ == "__main__":
main() | #!/usr/bin/env python3
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
N = int(readline())
print(math.ceil(N / 2) / N)
if __name__ == '__main__':
main()
| 0 | null | 94,816,477,658,112 | 122 | 297 |
n=list(input())
N=len(n)
k=int(input())
dp1=[[0 for i in range(k+1)] for j in range(N+1)]
dp2=[[0 for i in range(k+1)] for j in range(N+1)]
dp1[0][0]=1
for i in range(1,N+1):
x=int(n[i-1])
if i!=N and x!=0:
for j in range(k+1):
if j==0:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]
else:
dp1[i][j]=dp1[i-1][j-1]
dp2[i][j]=dp1[i-1][j]+dp1[i-1][j-1]*(x-1)+dp2[i-1][j]+dp2[i-1][j-1]*9
elif i!=N and x==0:
for j in range(k+1):
if j==0:
dp1[i][j]=dp1[i-1][j]
dp2[i][j]=dp2[i-1][j]
else:
dp1[i][j]=dp1[i-1][j]
dp2[i][j]=dp2[i-1][j]+dp2[i-1][j-1]*9
elif i==N and x!=0:
for j in range(k+1):
if j==0:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]
else:
dp2[i][j]=dp1[i-1][j]+dp1[i-1][j-1]*x+dp2[i-1][j]+dp2[i-1][j-1]*9
else:
for j in range(k+1):
if j==0:
dp2[i][j]=dp2[i-1][j]
else:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]+dp2[i-1][j-1]*9
print(dp2[N][k]) | import sys
def input(): return sys.stdin.readline().rstrip()
def main():
s=input()
n=len(s)
K=int(input())
dp_0=[[0]*(K+1) for _ in range(n+1)]
dp_1=[[0]*(K+1) for _ in range(n+1)]
dp_0[0][0]=1
for i in range(n):
for j in range(K+1):
for k in range(2):
nd=int(s[i])-0
for d in range(10):
ni=i+1
nj=j
if d!=0:nj+=1
if nj>K:continue
if k==0:
if d>nd:continue
if d<nd:dp_1[ni][nj]+=dp_0[i][j]
else:dp_0[ni][nj]+=dp_0[i][j]
else:dp_1[ni][nj]+=dp_1[i][j]
print(dp_0[n][K]+dp_1[n][K])
if __name__=='__main__':
main() | 1 | 76,025,721,553,198 | null | 224 | 224 |
from collections import Counter
n = int(input())
s = input()
b = Counter(s)
ans = min(b["R"],b["W"])
a = 0
for i in range(b["R"]):
if s[i] == "W":
a += 1
print(min(ans,a)) | #!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def solve():
N = int(input())
C = input()
num_r = C.count("R")
num_w = C.count("W")
ans = min(num_r, num_w)
left_r = 0
left_w = 0
for i in range(N):
left_r += C[i] == 'R'
left_w += C[i] == 'W'
right_r = num_r - left_r
right_w = num_w - left_w
ans = min(ans, min(left_w, right_r) + abs(left_w - right_r))
print(ans)
def main():
solve()
if __name__ == '__main__':
main()
| 1 | 6,292,609,318,018 | null | 98 | 98 |
s = input()
res = 0
if s == "SUN":
res = 7
elif s == "MON":
res = 6
elif s == "TUE":
res = 5
elif s == "WED":
res = 4
elif s == "THU":
res = 3
elif s == "FRI":
res = 2
elif s == "SAT":
res = 1
print(res) | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
s = input()
day = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7 - day.index(s)) | 1 | 133,229,832,094,200 | null | 270 | 270 |
data = list(map(int, input().split()))
n = int(input())
dice = ['12431', '03520', '01540', '04510', '02530', '13421']
for i in range(n):
up, front = map(int, input().split())
u = data.index(up)
f = data.index(front)
a = dice[u].find(str(f))
print(data[int(dice[u][a+1])]) | def II(): return int(input())
def LII(): return list(map(int, input().split()))
n=II()
town=[LII() for _ in range(n)]
distance=0
for i in range(n-1):
for j in range(i+1,n):
[xi,yi]=town[i]
[xj,yj]=town[j]
distance += ((xi-xj)**2+(yi-yj)**2)**0.5
print(distance*2/n) | 0 | null | 74,050,272,947,290 | 34 | 280 |
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
for i in range(N-2):
if D[i][0] == D[i][1] and D[i+1][0] == D[i+1][1] and D[i+2][0] == D[i+2][1]:
print('Yes')
exit()
print('No')
| n = int(input())
cnt=0
for _ in range(n):
a,b=map(int,input().split())
if a==b:
cnt+=1
if cnt>=3:
break
else:
cnt=0
if cnt>=3:
print("Yes")
else:
print("No") | 1 | 2,462,186,963,130 | null | 72 | 72 |
import sys
#list = sys.stdin.readlines()
#i=0
list = []
for line in sys.stdin.readlines():
list = line.split(" ")
print str(len(str(int(list[0]) + int(list[1])))) | from sys import stdin
import math
import fileinput
for line in fileinput.input():
a, b = [int(n) for n in line.split()]
print(math.floor(math.log10(a + b) + 1))
# x1, y1, x2, y2, x3, y3, xp, yp = [float(r) for r in line]
# print(x1, y1, x2, y2, x3, y3, xp, yp) | 1 | 98,527,712 | null | 3 | 3 |
n, p = map(int, input().split())
s = input()
a = []
c = 0
if p == 2:
b = [0]*n
for i in range(n):
if int(s[i])%2 == 0:
b[i] += 1
for i in range(n):
if b[i] == 1:
c += i+1
elif p == 5:
b = [0]*n
for i in range(n):
if int(s[i])%5 == 0:
b[i] += 1
for i in range(n):
if b[i] == 1:
c += i+1
else:
b = [0]*p
b[0] = 1
d = [1]
a.append(int(s[-1])%p)
for i in range(n-1):
d.append(d[-1]*10%p)
for i in range(1, n):
a.append((int(s[-i-1])*d[i]+a[i-1])%p)
for i in range(n):
b[a[i]] += 1
for i in range(p):
c += int(b[i]*(b[i]-1)/2)
print(c) | n, W = map(int, input().split())
ab = [tuple(map(int, input().split()))for _ in range(n)]
ab.sort()
ans = 0
dp = [0]*W
for a, b in ab:
if ans < dp[-1]+b:
ans = dp[-1]+b
for j in reversed(range(W)):
if j-a < 0:
break
if dp[j] < dp[j-a]+b:
dp[j] = dp[j-a]+b
print(ans)
| 0 | null | 104,657,423,027,828 | 205 | 282 |
n = int(raw_input())
F = [0] * (n+1)
def fibonacci(n):
global F
if n == 0 or n == 1:
F[n] = 1
return F[n]
if F[n] != 0:
return F[n]
F[n] = fibonacci(n-2) + fibonacci(n-1)
return F[n]
def makeFibonacci(n):
global F
F[0] = 1
F[1] = 1
for i in xrange(2,n+1):
F[i] = makeFibonacci(i-2) + makeFibonacci(i-1)
return F[n]
def main():
ans = fibonacci(n)
print ans
return 0
main() | N,M = map(int,input().split())
A_ls = list(map(int,input().split()))
cnt = 0
vote = sum(A_ls) / (4 * M)
for i in range(N):
if A_ls[i] >= vote:
cnt += 1
print("Yes" if cnt >= M else "No") | 0 | null | 19,429,382,555,968 | 7 | 179 |
import sys
import math
from collections import defaultdict
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
if row <= 0:
return [[] for _ in range(col)]
elif col == 1:
return [I() for _ in range(row)]
else:
read_all = [LI() for _ in range(row)]
return map(list, zip(*read_all))
#################
T1,T2 = LI()
A1,A2 = LI()
B1,B2 = LI()
if A1 > B1 and A2 > B2:
print(0)
exit()
if A1 < B1 and A2 < B2:
print(0)
exit()
if A1 > B1:
t = (A1-B1)*T1 / (B2-A2)
delta = (A1-B1)*T1+(A2-B2)*T2
if t == T2:
print('infinity')
exit()
elif t > T2:
print(0)
exit()
else:
if delta > 0:
print(math.floor((T2-t)*(B2-A2)/delta) + 1)
exit()
else:
x = (A1-B1)*T1 / (-delta)
if int(x) == x:
print(2*int(x))
else:
print(2*math.floor(x)+1)
else:
t = (B1-A1)*T1 / (A2-B2)
delta = (B1-A1)*T1+(B2-A2)*T2
if t == T2:
print('infinity')
exit()
elif t > T2:
print(0)
exit()
else:
if delta > 0:
print(math.floor((T2-t)*(A2-B2)/delta) + 1)
exit()
else:
x = (B1-A1)*T1 / (-delta)
if int(x) == x:
print(2*int(x))
else:
print(2*math.floor(x)+1) | n=int(input())
if n%2==0:
print(int(n/2))
if not n%2==0:
print(int(n/2+1)) | 0 | null | 94,896,355,858,232 | 269 | 206 |
n,k = map(int, input().split())
a = list(map(int, input().split()))
gki = sum(a[0:k])
tmp = gki
rng = k
for i in range(k,n):
tmp = tmp-a[i-k]+a[i]
if tmp>gki:
gki = tmp
rng = i+1
E = 0
for i in a[rng-k:rng]:
E += (i+1)/2
print(E) | x,n=map(int,input().split())
p=set(list(map(int,input().split())))
if x not in p :
print(x)
exit()
i=1
while True:
if x-i not in p:
print(x-i)
exit()
if x+i not in p:
print(x+i)
exit()
i+=1
| 0 | null | 44,375,587,668,480 | 223 | 128 |
n = int(input())
ai = list(map(int, input().split()))
# n=3
# ai = np.array([1, 2, 3])
# ai = ai[np.newaxis, :]
#
# ai2 = ai.T.dot(ai)
# ai2u = np.triu(ai2, k=1)
#
# s = ai2u.sum()
l = len(ai)
integ = [ai[0]] * len(ai)
for i in range(1, len(ai)):
integ[i] = integ[i-1] + ai[i]
s = 0
for j in range(l):
this_s = integ[-1] - integ[j]
s += ai[j] * this_s
ans = s % (1000000000 + 7)
print(ans)
| N = int(input())
A = list(map(int, input().split()))
s = sum(A)
res = 0
mod = 10**9 + 7
for i in range(N-1):
s -= A[i]
res += s*A[i]
print(res%mod) | 1 | 3,806,335,258,180 | null | 83 | 83 |
# PDF参考
# スタックS1
S1 = []
# スタックS2
S2 = []
tmp_total = 0
counter = 0
upper = 0
# 総面積
total_layer = 0
for i,symbol in enumerate(input()):
if (symbol == '\\'):
S1.append(i)
elif (symbol == '/') and S1:
i_p = S1.pop()
total_layer = i - i_p
if S2 :
while S2 and S2[-1][0] > i_p:
cal = S2.pop()
total_layer += cal[1]
S2.append((i, total_layer))
print(sum([j[1] for j in S2]))
if (len(S2) != 0):
print(str(len(S2)) + ' ' + ' '.join([str(i[1]) for i in S2]))
else:
print(str(len(S2)))
| l = input()
stack1 = []
stack2 = []
all_area = 0
for val in range(len(l)):
if l[val] == "\\":
stack1.append(val)
elif l[val] == "/" and stack1 != []:
temp = stack1.pop(-1)
all_area = all_area + (val - temp)
each_area = val - temp
while stack2 != [] and stack2[-1][0] > temp:
each_area = each_area + stack2.pop(-1)[1]
stack2.append([temp, each_area])
else:
pass
print(all_area)
print(len(stack2), end="")
for i in range(len(stack2)):
print(" ", end="")
print(stack2[i][1],end="")
print("")
| 1 | 57,221,562,138 | null | 21 | 21 |
K, X = map(int,input().split())
price = 500
ans = "No"
if price*K >= X:
ans = "Yes"
print(ans)
| import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
def main():
x = int(input())
if x >= 30:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 0 | null | 52,188,179,654,520 | 244 | 95 |
import sys
K,X = map(int,input().split())
if not ( 1 <= K <= 100 and 1 <= X <= 10**5 ): sys.exit()
print('Yes') if 500 * K >= X else print('No') | #! /usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)
YES = "Yes" # type: str
NO = "No" # type: str
INF=10**20
def solve(K: int, X: int):
print(YES if K*500 >= X else NO)
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
X = int(next(tokens)) # type: int
solve(K, X)
if __name__ == "__main__":
main()
| 1 | 97,819,098,731,168 | null | 244 | 244 |
import sys
def dfs(u):
global time
color[u] = "GRAY"
time += 1
d[u] = time
for v in range(n):
if M[u][v] and color[v] == "WHITE":
dfs(v)
color[u] = "BLACK"
time += 1
f[u] = time
if __name__ == "__main__":
n = int(sys.stdin.readline())
color = ["WHITE"] * n
time = 0
d = [-1] * n
f = [-1] * n
M = [[0] * n for i in range(n)]
for inp in sys.stdin.readlines():
inp = list(map(int, inp.split()))
for i in inp[2:]:
M[inp[0]-1][i-1] = 1
for i in range(n):
if d[i] == -1:
dfs(i)
for i in range(n):
print(i+1, d[i], f[i]) | def d(u):
global t
C[u]=1;t+=1;D[u]=t
for v in range(N):
if M[u][v]and C[v]==0:d(v)
C[u]=2;t+=1;F[u]=t
N=int(input())
M=[[0]*N for _ in[0]*N]
for e in[list(map(int,input().split()))for _ in[0]*N]:
for v in e[2:]:M[e[0]-1][v-1]=1
C,D,F=[0]*N,[0]*N,[0]*N
t=0
for i in range(N):
if C[i]==0:d(i)
for i in range(N):print(i+1,D[i],F[i])
| 1 | 2,758,668,550 | null | 8 | 8 |
x, y, z = input().split()
x, y = y, x
x, z = z, x
print(x, y, z) | n, m = input().split()
a = list(map(int, input().split()))
b = []
s = 0
for i in a:
s += i
for i in a:
if float(i) >= float(int(s)/(4*int(m))):
b.append(i)
if len(b) == int(m):
break
if len(b) == int(m):
print("Yes")
else:
print("No") | 0 | null | 38,541,703,662,980 | 178 | 179 |
def gcd(a,b):
if b == 0:
return a
else:
return gcd(b, a%b)
k = int(input())
ans = 0
for a in range(1,k+1):
for b in range(1,k+1):
for c in range(1,k+1):
ans += gcd(gcd(a,b),c)
print(ans)
| while 1:
h,w=map(int,raw_input().split())
if h==w==0:break
else:
for i in range(h):
print '#'*w
print'' | 0 | null | 18,197,785,335,410 | 174 | 49 |
N = int(input())
for i in range(N):
a = list(map(int, input().split()))
a.sort()
if (a[2] ** 2 == a[0] ** 2 + a[1] ** 2):
print("YES")
else:
print("NO")
| radius = int(input())
print(44/7*radius) | 0 | null | 15,675,865,889,692 | 4 | 167 |
s = input()
t = list(reversed(s))
ans = 0
for i in range(len(s)):
if s[i] != t[i]:
ans += 1
ans = (ans+1) // 2
print(ans) | import sys
input = sys.stdin.readline
s = list(input())
a = 0
#print(len(s))
for i in range((len(s) - 1) // 2):
#print(s[i], s[-2-i])
if s[i] != s[-2-i]:
a += 1
print(a) | 1 | 119,833,021,877,892 | null | 261 | 261 |
import math
def lcm(x, y):
return (x * y) // math.gcd(x, y)
if __name__ == '__main__':
a, b = map(int, input().split())
print(lcm(a, b)) | X = int(input())
for k in range(3, 361):
if (k*X)%360==0:
print(k)
exit() | 0 | null | 62,951,570,255,522 | 256 | 125 |
import math
N=int(input())
if N==2:
print(1)
exit()
def yaku(n):
a=set()
s=int(math.sqrt(n))
for i in range(2,s+1):
if n%i==0:
a.add(i)
a.add(n//i)
return a
ans=len(yaku(N-1))+1
a=yaku(N)
for i in a:
n=N
while n%i==0:
n=n//i
if n%i==1:
ans+=1
print(ans+1) | def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
n = int(input())
l = make_divisors(n - 1)
l2 = make_divisors(n)
del l2[0]
ans = len(l) - 1
for i in l2:
k2 = n
while True:
if k2 % i == 1:
ans += 1
k2 /= i
if k2 % 1 != 0:
break
print(ans) | 1 | 41,426,161,005,718 | null | 183 | 183 |
X,Y=map(int,input().split());print((max((4-X),0)+max((4-Y),0)+((0,4)[X*Y==1]))*10**5) | import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n = int(input())
ans = 0
for i in range(1, n+1):
ans += i*(1 + n//i)*(n//i)//2
print(ans)
if __name__=='__main__':
main() | 0 | null | 76,161,344,613,948 | 275 | 118 |
import math
x1, y1, x2, y2 = map(float, input().split())
x = abs(x1 - x2)
y = abs(y1 - y2)
ans = math.sqrt(x**2 + y**2)
print('{:.5f}'.format(ans))
| wee=["SUN","MON","TUE","WED","THU","FRI","SAT"]
print((7-wee.index(input())))
| 0 | null | 66,335,847,386,468 | 29 | 270 |
import math
print(2**(int(math.log2(int(input())))+1)-1) | from functools import lru_cache
@lru_cache(maxsize=None)
def solve(n):
if n == 1:
return 1
else:
return solve(n//2) * 2 + 1
H = int(input())
print(solve(H))
| 1 | 80,218,036,326,662 | null | 228 | 228 |
n=int(input())
l=['AC','WA','TLE','RE']
d=[0,0,0,0]
for i in range(n):
s=input()
if(s=='AC'):
d[0]+=1
elif(s=='WA'):
d[1]+=1
elif(s=='TLE'):
d[2]+=1
else:
d[3]+=1
for i in range(4):
print(l[i],'x',d[i])
| n, m = map(int, input().split())
if n % 2 or m < n//4:
for i in range(m):
print(i+1, n-i)
else:
for i in range(n//4):
print(i+1, n-i)
for i in range(n//4, m):
print(i+1, n-i-1) | 0 | null | 18,785,169,064,324 | 109 | 162 |
n=int(input())
for i in range(1,361):
if (n*i)%360==0:
print(i);exit() | X = int(input())
cnt = 1
while True:
tmp = X * cnt
m, d = divmod(tmp, 360)
if m >= 1 and d == 0:
print(cnt)
exit()
cnt += 1 | 1 | 13,029,163,953,042 | null | 125 | 125 |
import numpy as np
MOD = 998244353
N,S = map(int,input().split())
A = list(map(int,input().split()))
coefs = np.array([0]*(S+1))
coefs[0] = 1
for i in range(N):
tmp = coefs[:]
coefs = coefs*2
coefs[A[i]:] += tmp[:-A[i]]
coefs%=MOD
print(coefs[-1])
| import sys
mod = 998244353
def solve():
input = sys.stdin.readline
N, S = map(int, input().split())
A = [int(a) for a in input().split()]
DP = [[0 for _ in range(S + 1)] for i in range(N)]
DP[0][0] = 2
if A[0] <= S: DP[0][A[0]] = 1
ans = 0
for i, a in enumerate(A[1:]):
for s in range(S + 1):
if DP[i][s] > 0:
DP[i+1][s] += (DP[i][s] * 2) % mod
DP[i+1][s] %= mod
if s + a <= S:
DP[i+1][s+a] += DP[i][s]
DP[i+1][s+a] %= mod
print(DP[N-1][S])
#print(DP)
return 0
if __name__ == "__main__":
solve() | 1 | 17,590,958,493,248 | null | 138 | 138 |
s=int(input())
a=1
mod=10**9+7
x=s//3
y=s%3
ans=0
while x>=1:
xx=1
for i in range(1,x):
xx*=i
xx%=mod
yy=1
for j in range(1,1+y):
yy*=j
yy%=mod
fx=pow(xx,mod-2,mod)
fy=pow(yy,mod-2,mod)
xxyy=1
for k in range(1,x+y):
xxyy*=k
xxyy%=mod
ans+=(xxyy*fx*fy)%mod
x-=1
y+=3
print(ans%mod) | d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(d)]
lastd = [0] * 26
for i in range(1, d + 1):
ans = 0
tmp = 0
for j in range(26):
if tmp < s[i - 1][j] + (i - lastd[j]) * c[j]:
tmp = s[i - 1][j] + (i - lastd[j]) * c[j]
ans = j + 1
lastd[ans - 1] = i
print(ans) | 0 | null | 6,561,794,272,210 | 79 | 113 |
# Sheep and Wolves
S, W = map(int, input().split())
print(['safe', 'unsafe'][W >= S]) | s = int(input())
mod = 10**9+7
import numpy as np
if s == 1 or s == 2:
print(0)
elif s == 3:
print(1)
else:
array = np.zeros(s+1)
array[0] = 1
for i in range(3, s+1):
array[i] = np.sum(array[:i-2]) % mod
print(int(array[s]))
| 0 | null | 16,301,474,427,660 | 163 | 79 |
num = int(input())
if num%2==0:
print((num//2) / num)
else:
print(((num//2)+1) / num) | n = int(input())
if n%2 == 0:
print(1/2)
else :
print((n//2+1)/n)
| 1 | 177,081,599,660,290 | null | 297 | 297 |
a = []
for i in range(0,2):
l = list(map(int,input().split()))
a.append(l)
d = a[1][::-1]
print(' '.join(map(str,d))) | num = int(input())
line = input().split(" ")
line.reverse()
print(*line)
| 1 | 985,728,674,622 | null | 53 | 53 |
import sys
def gcd(a, b):
"?????§??¬?´???°????±???????"
if a < b:
c = a
a = b
b = c
if b == 0:
return a
else:
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return g * (a // g) * (b // g)
for line in sys.stdin:
a, b = map(int, line.split())
print("%d %d" % (gcd(a, b), lcm(a, b))) | # Aizu - 0005
def De(a):
res = []
tmp = 2
while a != 1:
while not (a % tmp):
a = round(a / tmp)
res.append(tmp)
tmp += 1
return res
while True:
try:
tmp = input()
a = [int(i) for i in tmp.split(' ')]
except:
break
b = De(a[1])
a = De(a[0])
pa, pb = 0, 0
GCD, LCM = 1, 1
while True:
if pa == len(a):
for i in range(pb, len(b)):
LCM *= b[i]
break;
if pb == len(b):
for i in range(pa, len(a)):
LCM *= a[i]
break;
if a[pa] == b[pb]:
GCD *= a[pa]
LCM *= a[pa]
pa += 1
pb += 1
continue
if a[pa] < b[pb]:
LCM *= a[pa]
pa += 1
continue
if a[pa] > b[pb]:
LCM *= b[pb]
pb += 1
continue
print('%d %d'%(GCD, LCM)) | 1 | 664,561,780 | null | 5 | 5 |
from collections import Counter
n,p = map(int,input().split())
S = input()
dp = [0]
mod = p
if p==2:
ans =0
for i in reversed(range(n)):
if int(S[i])%2==0:
ans += i+1
print(ans);exit()
elif p==5:
ans =0
for i in reversed(range(n)):
if int(S[i])%5==0:
ans += i+1
print(ans);exit()
for i in reversed(range(n)):
dp.append(dp[-1]%mod + pow(10,n-1-i,mod)*int(S[i]))
dp[-1]%=mod
count = Counter(dp)
ans = 0
for key,val in count.items():
if val>=2:
ans += val*(val-1)//2
print(ans) | a, b = input().split()
a = int(a)
b = int(b.replace('.', ''))
ans = a * b // 100
print(ans) | 0 | null | 37,307,560,236,858 | 205 | 135 |
M1,D1 = map(int,input().split())
M2,D2 = map(int,input().split())
print(1) if(M1 != M2) else print(0) | from collections import Counter
s = input()
ls = len(s)
t = [0]
j = 1
for i in range(ls):
u = (int(s[ls-1-i])*j + t[-1]) % 2019
t.append(u)
j = (j * 10) % 2019
c = Counter(t)
k = list(c.keys())
ans = 0
for i in k:
ans += c[i]*(c[i]-1)/2
print(int(ans)) | 0 | null | 77,281,785,104,982 | 264 | 166 |
def abc170_c_2():
"""
もっとシンプルに考えると
Xから-1、+1と順番に探索して、見つかったものをリターンすればOKなはず。
±0~99までを調べる?
"""
def solve():
x, n = map(int, input().split(' '))
if n == 0:
return x
p = list(map(int, input().split(' ')))
for i in range(100):
for s in [-1, +1]:
a = x + i * s
if a not in p:
return a
print(solve())
if __name__ == '__main__':
abc170_c_2() | n,r=map(int,input().split())
def rate(n,r):
if n>=10:
return r
else:
return r+100*(10-n)
print(rate(n,r)) | 0 | null | 38,703,139,007,540 | 128 | 211 |
def main():
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
Sum = sum(a)
if n<Sum:
print('-1')
else:
print(n-Sum)
main()
| import math
def main():
n,m = map(int,input().split())
a = list(map(int,input().strip().split()))
if n >= sum(a):
print(n-sum(a))
return
else:
print(-1)
return
main()
| 1 | 31,931,797,456,050 | null | 168 | 168 |
data = []
for i in range(10):
data.append(int(input()))
data = sorted(data)
print(data[-1])
print(data[-2])
print(data[-3]) | m=[]
for i in range(10):
x = input()
m.append(x)
m.sort()
m.reverse()
for i in range(0,3):
print m[i]
| 1 | 27,317,410 | null | 2 | 2 |
m1 = input().split()[0]
m2 = input().split()[0]
print(int(m1 != m2))
| from decimal import Decimal, getcontext
a,b,c = input().split()
getcontext().prec = 65
a = Decimal(a).sqrt()
b = Decimal(b).sqrt()
c = Decimal(c).sqrt()
if a+b < c:
print("Yes")
else:
print("No")
| 0 | null | 87,608,087,106,880 | 264 | 197 |
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==[]: #1の場合はここ
arr.append([n, 1])
return arr
def count(X):
cnt = 0
now = 1
while cnt+now <=X:
cnt += now
now += 1
return now-1
#print(count(3))
N = int(input())
if N == 1:
print(0)
exit()
A = factorization(N)
#print(A)
ans = 0
for i in range(len(A)):
ans += count(A[i][1])
print(ans)
| #169D
#Div Game
n=int(input())
def factorize(n):
fct=[]
b,e=2,0
while b**2<=n:
while n%b==0:
n/=b
e+=1
if e>0:
fct.append([b,e])
b+=1
e=0
if n>1:
fct.append([n,1])
return fct
l=factorize(n)
ans=0
for i in l:
c=1
while i[1]>=c:
ans+=1
i[1]-=c
c+=1
print(ans) | 1 | 17,009,344,584,288 | null | 136 | 136 |
n = int(input())
A = {}
for i in range(n):
a, b = input().split()
if a[0] == "i":
A[b] = 1
elif a[0] == "f":
if b in A:
print("yes")
else:
print("no")
| n = input()
dic = set([])
for i in xrange(n):
order = raw_input().split()
if order[0][0] == 'i':
dic.add(order[1])
else:
print "yes" if order[1] in dic else "no" | 1 | 79,739,066,288 | null | 23 | 23 |
H, W = map(int, input().split())
if (H*W) % 2 == 0:
if H == 1 or W == 1:
res = 1
else:
res = int(H * W / 2)
else:
if H == 1 or W == 1:
res = 1
else:
res = int(H * (W//2) + int(H/2) + 1)
print('{0:d}'.format(res)) | mod=10**9+7
n,k=map(int,input().split())
cnt=[0]*k
for i in range(k,0,-1):
cnt[i-1]=pow(k//i,n,mod)
for j in range(i*2,k+1,i):
cnt[i-1]-=cnt[j-1]
cnt[i-1]%=mod
ans=0
for i in range(k):
ans+=cnt[i]*(i+1)%mod
print(ans%mod) | 0 | null | 43,685,655,104,520 | 196 | 176 |
l,r,d = map(int, input().split())
if l%d == 0:
print(r//d - l//d + 1)
else:
print(r//d - l//d) | W = input()
lis = []
cot = 0
while True:
x = input().split()
if x == ["END_OF_TEXT"]:
break
lis += x
for y in lis:
if y.lower() == W:
cot += 1
print(str(cot))
| 0 | null | 4,673,864,601,728 | 104 | 65 |
A, B, K = map(int, input().split())
if K >= A+B:
print("0 0")
elif K <= A:
print("{} {}".format(A-K, B))
elif K > A:
print("0 {}".format(B-(K-A))) | import numpy as np #numpyの練習がてら
n = int(input())
tmp = list(map(int,input().split()))
mod = 10**9 + 7
a = np.array(tmp,np.int64)
ans = 0
for i in range(60 + 1):
b = (a >> i) & 1 #すべてのaについて2**n乗目のビットが1か否か
iti = np.count_nonzero(b) #すべてのaのうち2**n乗目が1であるものの個数
zero = n - iti #同様に0であるものの個数
ans += (iti * zero) * pow(2,i,mod) % mod#片方1で片方0なら1なので1の個数×0の個数
ans %= mod
print(ans)
| 0 | null | 113,779,944,510,020 | 249 | 263 |
def main():
x = int(input())
for A in range(-118,120):
for B in range(-119,119):
if (A**5 - B**5) == x:
return([A,B])
ans = main()
print(' '.join(str(n) for n in ans))
| X = int(input())
for a in range(-119, 120):
for b in range(-119, 120):
if X == a**5 - b**5:
la = a
lb = b
print(la, lb)
| 1 | 25,540,665,318,220 | null | 156 | 156 |
nxt = input().split()
#print(nxt)
N = int(nxt[0])
X = int(nxt[1])
T = int(nxt[2])
#print(N,X,T)
tmp = N/X - int(N/X)
if tmp == 0:
counter = int(N/X)
else:
counter = int(N/X) + 1
#print(counter)
print(counter * T) | x1, x2, x3, x4, x5 = map(int, input().split())
l = [x1, x2, x3, x4, x5]
print(l.index(0)+1) | 0 | null | 8,834,883,362,116 | 86 | 126 |
n = int(input())
A=[int(i) for i in input().split()]
MOD = 1000000007
ans = 1
cnt = [0]*(n+1)
cnt[0]=3
for i in range(n):
ans = ans * cnt[A[i]] %MOD
cnt[A[i]]-=1
cnt[A[i]+1]+=1
if ans==0:
break
print(ans)
| def depth_search(u, t):
t += 1
s.append(u)
d[u] = t
for v in range(N):
if adjacency_list[u][v] == 0:
continue
if d[v] == 0 and v not in s:
t = depth_search(v, t)
t += 1
s.pop()
f[u] = t
return t
N = int(input())
adjacency_list = [[0 for j in range(N)] for i in range(N)]
for _ in range(N):
u, k, *v = input().split()
for i in v:
adjacency_list[int(u)-1][int(i)-1] = 1
s = []
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]
t = 0
for u in range(N):
if d[u] == 0:
t = depth_search(u, t)
for i in range(N):
print("{} {} {}".format(i+1, d[i], f[i]))
| 0 | null | 65,408,201,171,292 | 268 | 8 |
#!/usr/bin/env python3
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
X = int(input())
y = 100
ans = 0
while y < X:
ans += 1
y += y // 100
print(ans)
if __name__ == '__main__':
main()
| import sys
import math
n = (int)(input())
money = 100000.0
for i in range(n):
money = math.ceil(money * 1.05 / 1000) * 1000
print((int)(money)) | 0 | null | 13,451,178,303,280 | 159 | 6 |
n=int(input())
d=list(map(int,input().split()))
d2=[m**2 for m in d]
print((sum(d)**2-sum(d2))//2) | from math import *
x1, y1, x2, y2 = map(float, raw_input().split())
distance = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
print distance | 0 | null | 84,124,501,673,632 | 292 | 29 |
s,t=map(str,input().split())
a,b=map(int,input().split())
u=input()
if u==s:
print("{0} {1}".format(a-1,b))
else:
print("{0} {1}".format(a,b-1)) | S, T = input().split()
A, B = map(int, input().split())
print(A-1, B) if input()==S else print(A, B-1) | 1 | 72,037,745,114,650 | null | 220 | 220 |
S = list(input())
q = int(input())
for i in range(q):
cmd, a, b, *c = input().split()
a = int(a)
b = int(b)
if cmd == "replace":
S[a:b+1] = c[0]
elif cmd == "reverse":
S[a:b+1] = reversed(S[a:b+1])
else:
print(*S[a:b+1], sep='')
| def rvrs(base, start, end):
r = base[int(start):int(end) + 1][::-1]
return base[:int(start)] + r + base[int(end) + 1:]
def rplc(base, start, end, string):
return base[:int(start)] + string + base[int(end) + 1:]
ans = input()
q = int(input())
for _ in range(q):
ORD = list(input().split())
if ORD[0] == 'print':
print(ans[int(ORD[1]):int(ORD[2])+1])
elif ORD[0] == 'reverse':
ans = rvrs(ans, int(ORD[1]), int(ORD[2]))
elif ORD[0] == 'replace':
ans = rplc(ans, int(ORD[1]), int(ORD[2]), ORD[3])
| 1 | 2,108,717,286,368 | null | 68 | 68 |
n=int(input())
l=list(map(int,input().split()))
f=0
for i in l:
if(i%2==0):
if(i%3!=0 and i%5!=0):
f=1
break
if(f==1):
print("DENIED")
else:
print("APPROVED")
| a = 0
for c in map(int, input()):
a += c
print("Yes" if a % 9 == 0 else "No") | 0 | null | 36,541,110,021,388 | 217 | 87 |
from collections import defaultdict
from bisect import bisect_left, bisect_right, insort_left, insort_right
import sys
input = sys.stdin.readline
def main():
N = int(input())
S = list(input())
q = int(input())
Q = [input() for _ in range(q)]
dd = defaultdict(list) # 各アルファベットが出現するインデックスをddに登録
for i in range(ord('a'), ord('z') + 1):
dd[chr(i)] = []
for i, st in enumerate(S):
dd[st].append(i)
ans = []
for q in Q:
t, a, b = q.split()
a = int(a) - 1
if int(t) == 1:
if S[a] == b: continue
# 二分探索で該当するインデックスを取得
id = bisect_left(dd[S[a]], a)
dd[S[a]].pop(id) # 取ってくる
insort_left(dd[b], a) # 新規に挿入する
S[a] = b
else:
b = int(b) - 1
cnt = 0
for l in dd.values():
# liの中身が存在し,
# そのアルファベットの最後のインデックスが指定されている最初のindexよりも大きく.
# a以上の最初のindexがb以下の時は,そのアルファベットの存在は保証される
if l and a <= l[-1] and l[bisect_left(l, a)] <= b:
cnt += 1
ans.append(cnt)
print(*ans, sep='\n')
if __name__ == '__main__':
main() | class Binary_Indexed_Tree:
def __init__(self, n):
"""
:param n: 最大の要素数
"""
self.n = n
self.tree = [0] * (n + 1)
self.depth = n.bit_length() - 1
def sum(self, i):
""" 区間[0,i) の総和を求める """
s = 0
i -= 1
while i >= 0:
s += self.tree[i]
i = (i & (i + 1)) - 1
return s
def built(self, array):
""" array を初期値とするBITを構築 """
for i, a in enumerate(array):
self.add(i, a)
def add(self, i, x):
""" i 番目の要素に x を足す """
while i < self.n:
self.tree[i] += x
i |= i + 1
def get(self, i, j):
""" 部分区間和 [i, j) """
if i == 0:
return self.sum(j)
return self.sum(j) - self.sum(i)
def lower_bound(self, x, equal=False):
""" (a0+a1+...+ai < x となる最大の i, その時の a0+a1+...+ai )
a0+a1+...+ai <= x としたい場合は equal = True
二分探索であるため、ai>=0 を満たす必要がある"""
sum_ = 0
pos = -1 # 1-indexed の時は pos = 0
if not equal:
for i in range(self.depth, -1, -1):
k = pos + (1 << i)
if k < self.n and sum_ + self.tree[k] < x: # 1-indexed の時は k <= self.n
sum_ += self.tree[k]
pos += 1 << i
if equal:
for i in range(self.depth, -1, -1):
k = pos + (1 << i)
if k < self.n and sum_ + self.tree[k] <= x: # 1-indexed の時は k <= self.n
sum_ += self.tree[k]
pos += 1 << i
return pos, sum_
def __getitem__(self, i):
""" [a0, a1, a2, ...] """
return self.get(i, i + 1)
def __iter__(self):
""" [a0, a1, a2, ...] """
for i in range(self.n):
yield self.get(i, i + 1)
def __str__(self):
text1 = " ".join(["element: "] + list(map(str, self)))
text2 = " ".join(["cumsum(1-indexed): "] + list(str(self.sum(i)) for i in range(1, self.n + 1)))
return "\n".join((text1, text2))
def str2int(s):
return ord(s) - ord("a")
n = int(input())
s = [str2int(i) for i in input()]
B = [Binary_Indexed_Tree(n) for i in range(26)]
for i in range(n):
B[s[i]].add(i, 1)
for _ in range(int(input())):
t, a, b = input().split()
if t == "1":
a = int(a) - 1
b = str2int(b)
B[s[a]].add(a, -1)
B[b].add(a, 1)
s[a] = b
else:
a, b = int(a) - 1, int(b)
ans = 0
for v in B:
ans += v.get(a, b) > 0
print(ans)
| 1 | 62,485,188,065,172 | null | 210 | 210 |
s = int(input())
sec = s % 60
minbuff = int(s / 60)
m = minbuff % 60
h = int(minbuff / 60)
print("{}:{}:{}".format(h, m, sec))
| num =raw_input()
num = int(num)
h = num/3600
m = (num-h*3600)/60
s = num-h*3600-m*60
h,m,s = map(str,(h,m,s))
print h+':'+m+':'+s | 1 | 330,134,153,688 | null | 37 | 37 |
string = input()
q = int(input())
for i in range(q):
order = list(input().split())
a, b = int(order[1]), int(order[2])
if order[0] == "print":
print(string[a:b+1])
elif order[0] == "reverse":
string = string[:a] + (string[a:b+1])[::-1] + string[b+1:]
else:
string = string[:a] + order[3] + string[b+1:]
| from collections import Counter
n = int(input())
A = [int(i) for i in input().split()]
all = sum(A)
Q = int(input())
bc = [[int(i) for i in input().split()] for _ in range(Q)]
nums = {i:0 for i in range(1, 10 ** 5 + 1)}
for a in A:
nums[a] += 1
for i in range(Q):
#print(nums)
b, c = bc[i][0], bc[i][1]
if b in nums.keys(): all += (c - b) * nums[b]
print(all)
nums[c] += nums[b]
nums[b] = 0 | 0 | null | 7,158,110,742,862 | 68 | 122 |
a = list(map(int,input().split()))
b = list(map(int,input().split()))
if a[0]<= sum(b):
print("Yes")
else:
print("No") | #a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in b:
# c.append(i)
H,N = map(int,input().split())
f = list(map(int,input().split()))
#j = [input() for _ in range(a)]
# h = []
# for i in range(e1):
# h.append(list(map(int,input().split())))
if sum(f)>=H:
print("Yes")
else:
print("No") | 1 | 77,944,103,731,936 | null | 226 | 226 |
s = input()
MOD = 2019
d = [0] * MOD
d[0] = 1
r = 0
t = 1
for i in reversed(s):
r += int(i) * t
r %= MOD
t *= 10
t %= MOD
d[r] += 1
print(sum(i * (i - 1) // 2 for i in d)) | print(int(input()) * 3.142 * 2)
| 0 | null | 31,095,652,487,214 | 166 | 167 |
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
INF = float('inf')
def solve():
n = II()
print((n + 1) // 2)
if __name__ == '__main__':
solve() | N=list(map(int,input()))
K=int(input())
L = len(N)
dp = [[[0]*(L+1) for _ in range(4)] for _ in range(2)]
dp[0][0][0] = 1
for i in range(2):
for j in range(4):
for k in range(L):
for d in range(10 if i else N[k]+1):
fl = 1 if i == 1 or d < N[k] else 0
cnt = j+1 if d != 0 else j
if cnt > K:
continue
dp[fl][cnt][k+1] += dp[i][j][k]
print(dp[0][K][L]+dp[1][K][L]) | 0 | null | 67,412,576,565,480 | 206 | 224 |
n, m, l = map(int, input().split())
a = [[int(num) for num in input().split()] for i in range(n)]
b = [[int(num) for num in input().split()] for i in range(m)]
c = [[0 for i in range(l)] for j in range(n)]
for i in range(l):
for j in range(n):
for k in range(m):
c[j][i] += a[j][k] * b[k][i]
for i in range(n):
for j in range(l):
if j == l - 1:
print(c[i][j])
else:
print("{0} ".format(c[i][j]), end = "") | #ITP1_7_D
n,m,l=map(int,input().split())
a=[]
b=[]
for _ in range(n):
a.append(list(map(int,input().split())))
for _ in range(m):
b.append(list(map(int,input().split())))
c=[[0 for _ in range(l)] for _ in range(n)]
for i in range(n):
for j in range(l):
for k in range(m):
c[i][j]+=a[i][k]*b[k][j]
for i in range(n):
for j in range(l-1):
print(c[i][j],end=" ")
print(c[i][-1])
| 1 | 1,422,449,216,608 | null | 60 | 60 |
import math
N, K = map(int, input().split())
A = list(map(float, input().split()))
min_A = 0
max_A = 10**10
while( max_A - min_A > 1):
now = (min_A + max_A) // 2
temp = 0
for i in A:
if i > now:
temp += (i // now)
if temp > K:
min_A = now
else:
max_A = now
print(int(min_A) + 1) | N, K = map(int, input().split())
A = list(map(int, input().split()))
def is_ok(x):
cnt = 0
for a in A:
cnt += a // x
if a % x == 0:
cnt -= 1
return cnt <= K
ng = 0
ok = 10**9
while ok - ng > 1:
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
print(ok) | 1 | 6,538,982,002,228 | null | 99 | 99 |
x,y = map(int, input().split())
ans = 'false'
for i in range(0,x+1):
if y == 2*i + 4*(x-i):
ans = 'true'
break
if ans == 'true':
print('Yes')
else:
print('No') | s, w = [int(i) for i in input().split()]
ans = 'safe' if s > w else 'unsafe'
print(ans) | 0 | null | 21,301,610,533,152 | 127 | 163 |
A,B = map(int, input().split())
c = A-(2*B)
if A <= 2*B:
print("0")
else:
print(c)
| import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect_left,bisect
def main():
h, w, m = map(int,input().split())
h_lis = [0] * (h+1)
w_lis = [0] * (w+1)
bombs = set([tuple(map(int,input().split())) for i in range(m)])
for hh, ww in bombs:
h_lis[hh] += 1
w_lis[ww] += 1
max_h = max(h_lis)
max_w = max(w_lis)
h_max_index = [i for i, h in enumerate(h_lis) if h == max_h]
w_max_index = [i for i, w in enumerate(w_lis) if w == max_w]
for h_i in h_max_index:
for w_i in w_max_index:
if not (h_i, w_i) in bombs:
print(h_lis[h_i] + w_lis[w_i])
sys.exit()
else:
print(h_lis[h_i] + w_lis[w_i] - 1)
if __name__=='__main__':
main() | 0 | null | 85,577,537,968,420 | 291 | 89 |
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse = True)
ans = 0
for i in range(len(l)):
for j in range(i+1,len(l)):
for k in range(j+1,len(l)):
if l[i] != l[j] != l[k] and l[i] < l[j] + l[k]:
ans +=1
print(ans) | import itertools
N=int(input())
L=list(map(int,input().split()))
c=0
if len(L) >=3:
for v in itertools.combinations(L, 3):
if (v[0] != v[1] and v[1] != v[2]) and v[0] != v[2]:
if sorted(v)[-2]+min(v) > max(v):
c=c+1
else:
c=c
else:
c=c
else:
c=0
print(c) | 1 | 4,997,743,500,640 | null | 91 | 91 |
# coding: utf-8
from scipy.sparse.csgraph import floyd_warshall
N,M,L=map(int, input().split())
RG=[[0 for i in range(N)] for j in range(N)]
for i in range(M):
f,t,c = map(int, input().split())
if c <= L:
RG[f-1][t-1] = c
RG[t-1][f-1] = c
Rd = floyd_warshall(RG, directed=False)
FG=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
for j in range(i+1, N):
if Rd[i][j] <= L:
FG[i][j] = 1
FG[j][i] = 1
Fd = floyd_warshall(FG, directed=False)
Q=int(input())
for i in range(Q):
s, t = map(int, input().split())
v = Fd[s-1][t-1]
if s == t:
print (str(0))
if v == float('inf'):
print (str(-1))
else:
print (str(int(v-1)))
| N, M, L = map(int, input().split())
dist = [[10**12] * N for _ in range(N)]
for i in range(N):
dist[i][i] = 0
for _ in range(M):
a, b, c = map(int, input().split())
if c <= L:
dist[a-1][b-1] = dist[b-1][a-1] = c
for k in range(N):
for i in range(N):
for j in range(N):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
old_dist = [row[:] for row in dist]
for i in range(N):
for j in range(N):
if old_dist[i][j] <= L:
dist[i][j] = 1
for k in range(N):
for i in range(N):
for j in range(N):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
Q = int(input())
for _ in range(Q):
start, end= map(int, input().split())
if dist[start-1][end-1] < 10**12:
print(dist[start-1][end-1] - 1)
else:
print(-1) | 1 | 173,835,486,449,376 | null | 295 | 295 |
def draw(h,w):
s = "#" * w
for i in range(0,h):
print s
print
if __name__ == "__main__":
while True:
h,w = map(int, raw_input().split())
if h==0 and w==0:
break
else:
draw(h,w) | while True:
(H,W) = [int(x) for x in input().split()]
if H == W == 0:
break
for h in range(0, H):
for w in range(0, W):
print("#", end="")
if w == W - 1:
print()
break
print() | 1 | 777,434,118,980 | null | 49 | 49 |
a,b,c,k=[int(i) for i in input().split()]
if a>=k:
print(k)
elif a+b>=k:
print(a)
else:
print(a-(k-a-b)) | n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
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
cnt=0
ans=0
LCM=1
for i in range(n):
Q=lcm(LCM,A[i])
cnt*=Q//LCM
LCM=Q
cnt+=Q//A[i]
print(cnt%mod) | 0 | null | 54,829,423,154,896 | 148 | 235 |
K = int(input())
S = str(input())
SK = S[0: (K)]
if len(S) <= K:
print(S)
else:
print(SK + '...') | 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)) | 0 | null | 86,555,282,367,960 | 143 | 283 |
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
if sum(a) > n:
print(-1)
else:
print(n - sum(a)) | N, M = map(int, input().split())
Alst = list(map(int, input().split()))
k = sum(Alst)
ans = N - k
if ans >= 0:
print(ans)
else:
print(-1) | 1 | 32,017,451,911,710 | null | 168 | 168 |
import decimal
a, b = input().split()
x, y = decimal.Decimal(a), decimal.Decimal(b)
print(int(x * y)) | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
a, b, c = mapint()
if c-(a+b)>=0:
if 4*a*b<(c-a-b)**2:
print('Yes')
else:
print('No')
else:
print('No') | 0 | null | 34,191,977,190,852 | 135 | 197 |
n, k, c = map(int, input().split())
s = list(str(input()))
def getpos(s):
l = []
i = 0
while i <= n-1 and len(l) < k:
if s[i] == 'o':
l.append(i)
i += c+1
else:
i += 1
return l
l = getpos(s)
s.reverse()
r = getpos(s)
for i in range(len(r)):
r[i] = n-1-r[i]
#print(l)
#print(r)
lastl = [-1]*(n+1)
lastr = [-1]*(n+1)
for i in range(k):
lastl[l[i]+1] = i
for i in range(n):
if lastl[i+1] == -1:
lastl[i+1] = lastl[i]
for i in range(k):
lastr[r[i]] = i
for i in reversed(range(n)):
if lastr[i] == -1:
lastr[i] = lastr[i+1]
#print(lastl)
#print(lastr)
ans = []
s.reverse()
for i in range(n):
if s[i] != 'o':
continue
cnt = 0
cnt += lastl[i]+1
cnt += lastr[i+1]+1
if lastl[i] != -1 and lastr[i+1] != -1 and r[lastr[i+1]] - l[lastl[i]] <= c:
cnt -= 1
if cnt < k:
ans.append(i+1)
for i in range(len(ans)):
print(ans[i]) |
def resolve():
N, K, C = map(int, input().split())
S = input()
left = [0]*N
i = 0
cnt = 1
while i < N:
if S[i] == "o":
left[i] = cnt
i += C
cnt += 1
i += 1
right = [0]*N
i = 0
cnt = K
T = S[::-1]
while i < N:
if T[i] == "o":
right[i] = cnt
i += C
cnt -= 1
i += 1
right = right[::-1]
for i in range(N):
if left[i] == 0:
continue
if left[i] == right[i]:
print(i+1)
if __name__ == "__main__":
resolve()
| 1 | 40,644,026,420,122 | null | 182 | 182 |
import math
while True:
try:
a = list(map(int,input().split()))
b = (math.gcd(a[0],a[1]))
c = ((a[0]*a[1])//math.gcd(a[0],a[1]))
print(b,c)
except EOFError:
break
| s = input()
n = len(s) // 2
j = -1
t = 0
for i in range(n):
if s[i] != s[j]:
t += 1
j -= 1
print(t) | 0 | null | 59,854,706,862,720 | 5 | 261 |
import math
K = int(input())
ans = 0
A = {}
for a in range(1, K+1):
A[a] = 0
for a in range(1, K+1):
for b in range(1, K+1):
num = math.gcd(a, b)
A[num] += 1
for c in range(1, K+1):
for k in A.keys():
num = math.gcd(c, k) * A[k]
ans += num
print(ans) | N = int(input())
S, T = input().split()
charac = []
for i in range(N):
charac += S[i]
charac += T[i]
print(''.join(charac))
| 0 | null | 73,634,912,950,848 | 174 | 255 |
def isPrime(n):
i = 2
while i * i <= n:
if n % i == 0:
return False
i += 1
return True
N = int(input())
cnt = 0
for _ in range(N):
a = int(input())
if isPrime(a):
cnt += 1
print(cnt) | W,H,x,y,r = [int(s) for s in input().split()]
if 0 <= (x-r) <= (x+r) <= W:
if 0 <= (y-r) <= (y+r) <= H:
print("Yes")
else:
print("No")
else:
print("No") | 0 | null | 228,411,539,488 | 12 | 41 |
n = int(input())
list_ = []
for _ in range(n):
x, l = map(int, input().split())
list_.append([x-l, x+l])
list_.sort(key=lambda x: x[1])
res = n
pos = -float('inf')
for l, r in list_:
if l < pos:
res -= 1
else:
pos = r
print(res) | def main():
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
total_T_in_A = [0] * (N+1)
total_T_in_A[1] = A[0]
total_T_in_B = [0] * M
total_T_in_B[0] = B[0]
for i in range(1, N+1):
total_T_in_A[i] = total_T_in_A[i-1] + A[i-1]
for i in range(1, M):
total_T_in_B[i] = total_T_in_B[i-1] + B[i]
result = 0
for i in range(N+1):
# A から i 冊読むときにかかる時間
i_A_T = total_T_in_A[i]
if K < i_A_T:
continue
if K == i_A_T:
result = max(result, i)
continue
rem_T = K - i_A_T
# total_T_in_B は累積和を格納した、ソート済の配列
# B_i <= rem_T < B_i+1 となるような B_i を二分探索によって探す
first = total_T_in_B[0]
last = total_T_in_B[M-1]
if rem_T < first:
result = max(result, i)
continue
if last <= rem_T:
result = max(result, i + M)
continue
# assume that first <= rem_T <= last
first_i = 0
last_i = M - 1
while first_i < last_i:
if abs(last_i - first_i) == 1:
break
mid_i = (first_i + last_i) // 2
if rem_T < total_T_in_B[mid_i]:
last_i = mid_i
else:
first_i = mid_i
result = max(result, i + first_i + 1)
print(result)
main()
| 0 | null | 50,089,479,862,770 | 237 | 117 |
n = int(raw_input())
numbers = map(int, raw_input().split())
print min(numbers), max(numbers), sum(numbers) | T = input()
print(T.replace('?', 'D'))
| 0 | null | 9,561,788,373,722 | 48 | 140 |
a=int(input())
if 400<=a and a<=599:
print(8)
if 600<=a and a<=799:
print(7)
if 800<=a and a<=999:
print(6)
if 1000<=a and a<=1199:
print(5)
if 1200<=a and a<=1399:
print(4)
if 1400<=a and a<=1599:
print(3)
if 1600<=a and a<=1799:
print(2)
if 1800<=a and a<=1999:
print(1) | value = int(input())
kyu_rated = 8
lvalue = 400
rvalue = 599
for i in range(0, 8):
if lvalue <= value <= rvalue:
print(kyu_rated)
flag = 1
break
else:
lvalue += 200
rvalue += 200
kyu_rated -= 1
| 1 | 6,661,377,604,320 | null | 100 | 100 |
n = int(input())
def calc(m, res):
q, mod = divmod(m, 26)
if (mod == 0):
q = q - 1
mod = 26
res = chr(ord("a") + (mod - 1)) + res
else:
res = chr(ord("a") + (mod - 1)) + res
if (q > 0):
calc(q, res)
else:
print(res)
return
calc(n, "") | X = int(input())
d = {}
for i in range(0, 26):
d[i+1] = chr(97+i)
a = []
while X > 0:
if X%26 != 0:
a.append(d[(X % 26)])
X -= X % 26
else:
a.append(d[26])
X -= 26
X //= 26
for i in a[::-1]:
print(i, end='')
print() | 1 | 11,968,912,357,798 | null | 121 | 121 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.