code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
from sys import exit
def main():
N = int(input())
a = list(map(int,input().split()))
index = -1
num = 1
for i in range(index+1, N):
if a[i] != num:
continue
elif a[i] == num:
index = i
num += 1
if index != -1:
print(N-(num-1))
exit()
#indexに更新がなければ-1のまま
print(index)
main()
|
N = int(input())
a = list(map(int,input().split()))
check = 1
ans = 0
for i in a:
ans+=1
if i == check:
ans -=1
check+=1
if a==[j for j in range(1,N+1)]:
print(0)
exit()
elif ans==N:
print(-1)
exit()
print(ans)
| 1 | 115,065,155,473,532 | null | 257 | 257 |
n = int(input())
s = [input() for i in range(n)]
c0 = 0
c1 = 0
c2 = 0
c3 = 0
for i in range(len(s)):
if s[i] == "AC":
c0 += 1
elif s[i] == "WA":
c1 += 1
elif s[i] == "TLE":
c2 += 1
else:
c3 += 1
print("AC x ", str(c0))
print("WA x ", str(c1))
print("TLE x ", str(c2))
print("RE x ", str(c3))
|
n = int(input())
count_ac, count_wa, count_tle, count_re = 0, 0, 0, 0
for i in range(n):
s = input()
if s == "AC":
count_ac += 1
if s == "WA":
count_wa += 1
if s == "TLE":
count_tle += 1
if s == "RE":
count_re += 1
print("AC x", count_ac)
print("WA x", count_wa)
print("TLE x", count_tle)
print("RE x", count_re)
| 1 | 8,717,465,277,180 | null | 109 | 109 |
mod = 10**9+7
M = 2*10**6
fact = [1]*(M+1)
factinv = [1]*(M+1)
inv = [1]*(M+1)
for n in range(2,M+1):
fact[n] = n*fact[n-1]%mod
inv[n] = -inv[mod%n]*(mod//n)%mod
factinv[n] = inv[n]*factinv[n-1]%mod
def comb(n,k):
return fact[n]*factinv[k]*factinv[n-k]%mod
def main(K,S):
n = len(S)
ans = 0
for k in range(K+1):
ans += comb(n+k-1,k)*pow(25,k,mod)*pow(26,K-k,mod)
ans %= mod
print(ans)
if __name__ == '__main__':
K = int(input())
S = input()
main(K,S)
|
n,m,l = map(int,input().split())
g = [[float('inf')]*n for _ in range(n)]
for _ in range(m):
a,b,c = map(int,input().split())
a-=1
b-=1
g[a][b] = c
g[b][a] = c
for k in range(n):
for i in range(n):
for j in range(n):
g[i][j] = min(g[i][j],g[i][k] + g[k][j])
h = [[float('inf')]*n for _ in range(n)]
for i in range(n):
for j in range(n):
if g[i][j]<=l:
h[i][j] = 1
for k in range(n):
for i in range(n):
for j in range(n):
h[i][j] = min(h[i][j],h[i][k] + h[k][j])
Q = int(input())
for _ in range(Q):
s,t = map(int,input().split())
s -=1
t-=1
if h[s][t] ==float('inf'):
print(-1)
else:
print(h[s][t]-1)
| 0 | null | 93,074,641,738,390 | 124 | 295 |
def main():
H,W,M = map(int,input().split())
s = []
h_cnt = [0 for i in range(H)]
w_cnt = [0 for i in range(W)]
for i in range(M):
h,w = map(int,input().split())
s.append([h-1,w-1])
h_cnt[h-1] += 1
w_cnt[w-1] += 1
h_m,w_m = max(h_cnt), max(w_cnt)
h_mp,w_mp = [],[]
for i in range(H):
if h_cnt[i] == h_m:
h_mp.append(i)
for i in range(W):
if w_cnt[i] == w_m:
w_mp.append(i)
f = 0
for i in range(M):
if h_cnt[s[i][0]] == h_m and w_cnt[s[i][1]] == w_m:
f += 1
if len(w_mp)*len(h_mp)-f<1:
print(h_m+w_m-1)
else:
print(h_m+w_m)
if __name__ == "__main__":
main()
|
X = int(input())
x1 = X // 100
x2 = X % 100
if x2 <= x1 * 5:
print(1)
else:
print(0)
| 0 | null | 65,857,423,597,278 | 89 | 266 |
import math
n = int(input())
def koch(n, p1_x, p2_x, p1_y, p2_y):
if n == 0:
return
s_x = (2*p1_x + p2_x) / 3
s_y = (2*p1_y + p2_y) / 3
t_x = (p1_x + 2*p2_x) / 3
t_y = (p1_y + 2*p2_y) / 3
u_x = (t_x - s_x)/2 - (t_y - s_y) * math.sqrt(3)/2 + s_x
u_y = (t_x - s_x) * math.sqrt(3)/2 + (t_y - s_y)/2 + s_y
koch(n-1, p1_x, s_x, p1_y, s_y)
print (s_x, s_y)
koch(n-1, s_x, u_x, s_y, u_y)
print (u_x, u_y)
koch(n-1, u_x, t_x, u_y, t_y)
print (t_x, t_y)
koch(n-1, t_x, p2_x, t_y, p2_y)
p1_x = 0.0
p1_y = 0.0
p2_x = 100.0
p2_y = 0.0
print (p1_x, p1_y)
koch(n, 0, 100, 0, 0)
print (p2_x, p2_y)
|
import sys
import math
#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
N = ini()
S = input()
ans = 0
for i in range(1000):
V = str(i).zfill(3)
p1 = S.find(V[0])
if p1 != -1:
p2 = S.find(V[1], p1+1)
if p2 != -1:
p3 = S.find(V[2], p2+1)
if p3 != -1:
ans += 1
print(ans)
| 0 | null | 64,227,290,815,336 | 27 | 267 |
A, B, C = map(int, input().split())
K = int(input())
flg = 0
for i in range(K):
if B > A:
if C > B or 2*C > B:
flg = 1
else:
C = 2*C
else:
B = 2*B
continue
if flg:
print('Yes')
else:
print('No')
|
S = input()
if S[-1] != 's':
S = S + 's'
elif S[-1] == 's':
S = S + 'es'
print(S)
| 0 | null | 4,680,030,219,808 | 101 | 71 |
import sys, math
input = sys.stdin.readline
MAX = 2e9
def merge(A, left, mid, right):
n1 = mid - left
n2 = right - mid
L = A[left:mid]
L.append(MAX)
R = A[mid:right]
R.append(MAX)
merged = []
index_L = 0
index_R = 0
comp_cnt = 0
for _ in range(n1+n2):
cand_L = L[index_L]
cand_R = R[index_R]
comp_cnt += 1
if (cand_L < cand_R):
merged.append(cand_L)
index_L += 1
else:
merged.append(cand_R)
index_R += 1
A[left:right] = merged
return comp_cnt
def merge_sort(A, left, right):
comp_cnt = 0
if (left + 1 < right):
# Devide
mid = (left + right) // 2
# Solve
_, cnt = merge_sort(A, left, mid)
comp_cnt += cnt
_, cnt = merge_sort(A, mid, right)
comp_cnt += cnt
# Conquer
comp_cnt += merge(A, left, mid, right)
return A, comp_cnt
def main():
N = int(input())
S = list(map(int, input().split()))
left = 0
right = len(S)
merged, cnt = merge_sort(S, left, right)
print(" ".join([str(x) for x in merged]))
print(cnt)
if __name__ == "__main__":
main()
|
import math
def merge(a,l,m,r):
global cnt
L = a[l:m]+[math.inf]
R = a[m:r]+[math.inf]
i = 0
j = 0
for k in range(l,r):
cnt+=1
if L[i]<=R[j]:
a[k] = L[i]
i+=1
else:
a[k]=R[j]
j+=1
def mergeSort(a,l,r):
if l+1<r:
m = (l+r)//2
mergeSort(a,l,m)
mergeSort(a,m,r)
merge(a,l,m,r)
n = int(input())
a = list(map(int, input().split()))
cnt = 0
mergeSort(a,0,n)
print(*a)
print(cnt)
| 1 | 112,848,556,602 | null | 26 | 26 |
# Aizu Problem ALDS_1_4_C: Dictionary
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
D = set()
N = int(input())
for _ in range(N):
cmd, string = input().split()
if cmd == "insert":
D.add(string)
elif cmd == "find":
print("yes" if string in D else "no")
|
data = []
for i in range(10):
data.append(int(input()))
data = sorted(data)
print(data[-1])
print(data[-2])
print(data[-3])
| 0 | null | 38,449,194,930 | 23 | 2 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
N = int(input())
a = [[0]*10 for i in range(10)]
for i in range(1,N+1):
n = str(i)
a[int(n[0])][int(n[-1])] += 1
ans = 0
for i in range(1,10):
for j in range(1, 10):
ans += a[i][j]*a[j][i]
print(ans)
|
K = str(input())
print(K[0:3])
| 0 | null | 50,669,483,558,940 | 234 | 130 |
S = str(input())
L = len(S)
ans = "x" * L
print(ans)
|
s = input()
n = len(s)
a = 'x'*n
print(a)
| 1 | 72,769,880,037,840 | null | 221 | 221 |
N,A,B=map(int,input().split())
if (A+B)%2==0:
P=(B-A)//2
else:
P=float("inf")
if (A+B)%2==1:
Q=A
Q+=(B-Q-(B-Q+1)//2)
else:
Q=float("inf")
if (A+B)%2==1:
R=N-B+1
B=N
A+=R
R+=B-(A+B)//2
else:
R=float("inf")
print(min(P,Q,R))
|
import bisect
X, N=map(int, input().split())
if N==0:print(X);exit()
p=sorted(list(map(int, input().split())))
#print(p)
m=min(p)-1
M=max(p)+1
#for i in range(m,M+1):
# p.append(i)
#p=sorted(p)
m=X;i=0
for i in range(m,min(p)-2,-1):
if i not in p:break
M=X;j=0
for j in range(M,max(p)+2):
if j not in p:break
if abs(i-X)==abs(j-X):print(min(i,j))
elif abs(i-X)<abs(j-X):
print(i)
else:print(j)
| 0 | null | 61,969,718,167,668 | 253 | 128 |
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
N = int(input())
A = list(map(int, input().split()))
from itertools import accumulate
B = [0] + A
B = list(accumulate(B)) # 累積和を格納したリスト作成
# この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り
S=B[-1]
minans = 10 ** 20
for i in range(1,N):
val=abs(B[i]-(S-B[i]))
minans=min(minans,val)
print(minans)
resolve()
|
n, m = map(int, input().split())
am = list(map(int, input().split()))
if n-sum(am) < 0:
print(-1)
else:
print(n-sum(am))
| 0 | null | 87,299,285,050,800 | 276 | 168 |
N = int(input())
num_list = [int(i) for i in input().split()]
result = 0
mod = 10 ** 9 + 7
right = sum(num_list)
for number in num_list:
#A*B + A * C = A*(B+C)で計算
right -= number
result += (number * right) % mod
print(result % mod)
|
from decimal import *
from math import *
a, b, h, m = map(float, input().split())
ana = 360*(60*h+m)/720
anb = 360*m/60
an = min(abs(ana-anb), abs(anb-ana))
sint = sin(radians(an))
cost = cos(radians(an))
l = Decimal(((b-a*cost)**2 + (a*sint)**2)**.5)
print(l)
| 0 | null | 11,956,711,909,270 | 83 | 144 |
def abc(n,i):
if i==1:
return 0
while not n%i:
n=n//i
return not (n-1)%i
n=int(input())
e={}
for i in range(1,int(pow(n,0.5))+1):
if not n%i:
if abc(n,i):
e[i]=0
if abc(n,n//i):
e[n//i]=0
n-=1
c=0
for i in range(1,int(pow(n,0.5))+1):
if not n%i:
c+=1
if i!=n//i:
c+=1
print(len(e)+c-1)
|
n = int(input())
def yakusu(x):
xx = 2
y = []
while xx**2 < x:
if x%xx == 0:
y.append(xx)
y.append(x//xx)
xx += 1
if xx**2 == x:
y.append(xx)
y.append(x)
return y
if n == 2:
ans = 0
else:
ans = len(yakusu(n-1))
for i in yakusu(n):
nn = n
while True:
if nn%i == 0:
nn = nn//i
else:
break
if nn%i == 1:
ans += 1
print(ans)
| 1 | 41,071,884,979,268 | null | 183 | 183 |
K = int(input())
A, B = map(int, input().split())
ok_flag = False
for i in range(A, B + 1):
if i % K == 0:
ok_flag = True
break
if ok_flag:
print('OK')
else:
print('NG')
|
h,w,k=map(int,input().split())
s=[]
ans=[[0 for k in range(w)] for _ in range(h)]
for _ in range(h): s.append(input())
temp=0
for i in range(h):
flag=0
for j in range(w):
if flag:
if s[i][j]=="#": temp+=1
ans[i][j]=temp
else:
if s[i][j]=="#":
temp+=1
flag=1
ans[i][j]=temp
temp=[ans[i].count(0) for i in range(h)]
for i,val in enumerate(temp):
if 0<val<w:
j=w-1
while ans[i][j]!=0: j-=1
while j>=0:
ans[i][j]=ans[i][j+1]
j-=1
for i in range(h):
if i>0 and ans[i][0]==0: ans[i]=ans[i-1]
for i in range(h-1,-1,-1):
if i<h-1 and ans[i][0]==0: ans[i]=ans[i+1]
for i in range(h):
for j in range(w):
print(ans[i][j],end=" ")
print()
| 0 | null | 85,060,934,751,260 | 158 | 277 |
K=int(input())
res=1
x=0
for i in range(K):
x+=7*res
x%=K
if x%K==0:
print(i+1)
break
res*=10
res%=K
else:
print(-1)
|
from collections import deque
N,u,v = map(int,input().split())
u -= 1
v -= 1
adj = [ [] for _ in range(N) ]
for _ in range(N-1):
a,b = map(int,input().split())
a -= 1
b -= 1
adj[a].append(b)
adj[b].append(a)
def bfs(v):
visited = [False] * N
q = deque([v])
span = [-1] * N
s = 0
while q:
l = len(q)
newq = deque([])
for _ in range(l):
node = q.popleft()
visited[node] = True
span[node] = s
for nei in adj[node]:
if not visited[nei]:
newq.append(nei)
q = newq
s += 1
return span
t = bfs(u)
a = bfs(v)
ans = 0
for i in range(N):
if t[i] <= a[i]:
ans = max(ans, a[i]-1)
print(ans)
| 0 | null | 61,697,311,811,200 | 97 | 259 |
N = int(input())
A = list(map(int, input().split()))
min = 1
check = True
count = 0
for i in range(N):
if A[i] != min:
A[i] = 0
count += 1
elif A[i] == min:
min += 1
if A == [0] * N:
print(-1)
else:
print(count)
|
n = int(input())
A = list(map(int,input().split()))
from collections import deque
q = deque(A)
i = 1
ans = []
while i <= n and q:
a = q.popleft()
if a==i:
ans.append(a)
i += 1
if len(ans)==0:
print(-1)
else:
print(n-len(ans))
| 1 | 114,998,169,914,108 | null | 257 | 257 |
def resolve():
n=int(input())
print((n-1)//2)
resolve()
|
# from collections import Counter
# n = int(input())
# li = list(map(int, input().split()))
# a, b = map(int, input().split())
n = int(input())
print(n//2 if n&1 else n//2-1)
| 1 | 152,509,382,433,218 | null | 283 | 283 |
N, A, B = map(int, input().split())
A, B = min(A, B), max(A, B)
d = B - A
if d % 2 == 0:
print(d // 2)
else:
if (A - 1 <= N - B):
A, B = A - 1, B - 1
else:
A, B = N - B, N - A
ans = min(B, A + 1 + (B - A - 1) // 2)
print(ans)
|
n,k = map(int, input().split())
n_list=list(range(n+1))
saisyou=sum(n_list[0:k])
saidai=sum(n_list[n-k+1:n+1])
ans=saidai-saisyou+1
for i in range(k+1,n+2):
saisyou+=n_list[i-1]
saidai+=n_list[-(i)]
ans+=saidai-saisyou+1
ans%=10**9+7
print(ans)
| 0 | null | 71,128,290,736,958 | 253 | 170 |
import numpy as np
N = int(input())
A = []
B = []
for i in range(N):
a, b = [int(x) for x in input().split()]
A.append(a)
B.append(b)
C = np.array(A)
D = np.array(B)
m_inf = np.median(C)
m_sup = np.median(D)
if N % 2 == 0:
ans = 2 * m_sup - 2 * m_inf + 1
else:
ans = m_sup - m_inf + 1
print(int(ans))
|
A,B = input().split()
print((int(A)*round(100*float(B)))//100)
| 0 | null | 16,888,752,012,188 | 137 | 135 |
import sys
S = input()
if not ( len(S) == 6 and S.islower() ): sys.exit()
print('Yes') if S[2] == S[3] and S[4] == S[5] else print('No')
|
kazu = int(input())
kazu2 = (kazu % 100) % 10
if kazu2 == 3:
print("bon")
elif kazu2 == 0 or kazu2 == 1 or kazu2 == 6 or kazu2 == 8:
print("pon")
else:
print("hon")
| 0 | null | 30,688,056,403,202 | 184 | 142 |
import sys
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
now = D[0]
zorome = 0
if now[0] == now[1]:
zorome += 1
else:
zorome = 0
for i in range(1, N):
now = D[i]
if now[0] == now[1]:
zorome += 1
if zorome == 3:
print('Yes')
sys.exit()
else:
zorome = 0
print('No')
|
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return map(int,input().split())
def onem(): #Nとかの取得
return int(input())
def s(x): #圧縮
a = []
if len(x) == 0:
return []
aa = x[0]
su = 1
for i in range(len(x)-1):
if aa != x[i+1]:
a.append([aa,su])
aa = x[i+1]
su = 1
else:
su += 1
a.append([aa,su])
return a
def jo(x): #listをスペースごとに分ける
return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
return max(map(max,x))
def In(x,a): #aがリスト(sorted)
k = bs.bisect_left(a,x)
if k != len(a) and a[k] == x:
return True
else:
return False
def pow_k(x, n):
ans = 1
while n:
if n % 2:
ans *= x
x *= x
n >>= 1
return ans
"""
def nibu(x,n,r):
ll = 0
rr = r
while True:
mid = (ll+rr)//2
if rr == mid:
return ll
if (ここに評価入れる):
rr = mid
else:
ll = mid+1
"""
n = onem()
co = 0
for i in range(n):
a,b = m()
if a == b:
co += 1
if co >= 3:
print("Yes")
exit()
else:
co = 0
print("No")
| 1 | 2,506,882,107,168 | null | 72 | 72 |
h, n = map(int, input().split())
a = list(map(int, input().split()))
x = sum(a)
if (h - x) <= 0:
print('Yes')
else:
print('No')
|
n,k=map(int,input().split())
dp=[0 for i in range(n+1)]
acc=[0 for i in range(n+1)]
dp[1]=1
mod=998244353
acc[1]=1
l,r=[],[]
for i in range(k):
a,b=map(int,input().split())
l.append(a)
r.append(b)
for i in range(2,n+1):
for j in range(k):
if i-l[j]<0:
continue
dp[i]+=(acc[i-l[j]]-acc[max(0,i-r[j]-1)])
dp[i]%=mod
acc[i]=(acc[i-1]+dp[i])%mod
print(dp[-1])
| 0 | null | 40,151,713,696,068 | 226 | 74 |
list = input().split(" ")
a = int(list[0])
b = int(list[1])
print(a * b)
|
while 1:
h,w=map(int,input().split())
if h==0 and w==0: break
for y in range(h): print(('#.'*w)[y % 2:][:w])
print('')
| 0 | null | 8,401,277,444,572 | 133 | 51 |
N,X,M=map(int,input().split())
table=[X]
visited=[-1]*M
visited[X]=1
ans=X
for i in range(N-1):
nx=table[i]**2
nx%=M
if visited[nx]>0:
first=table.index(nx)
oneloop=i+1-first
rest=N-i-1
loops=rest//oneloop
totalofoneloop=sum(table[first:])
ans+=totalofoneloop*loops
remain=rest%oneloop
ans+=sum(table[first:first+remain])
print(ans)
exit()
else:
table.append(nx)
visited[nx]=1
ans+=nx
print(ans)
|
N = input().strip()
INFTY = 10**8
dp = [[INFTY for _ in range(2)] for _ in range(len(N)+1)]
a = int(N[-1])
for i in range(10):
if i<a:
dp[1][1] = min(dp[1][1],i+10-a)
else:
dp[1][0] = min(dp[1][0],i+i-a)
for k in range(2,len(N)+1):
a = int(N[-k])
for i in range(10):
if i>=a:
dp[k][0] = min(dp[k][0],dp[k-1][0]+i+i-a)
if i-1>=a:
dp[k][0] = min(dp[k][0],dp[k-1][1]+i+i-1-a)
if i<a:
dp[k][1] = min(dp[k][1],dp[k-1][0]+i+10-a)
if i==0:
dp[k][1] = min(dp[k][1],dp[k-1][1]+9-a)
if 0<=i-1<a:
dp[k][1] = min(dp[k][1],dp[k-1][1]+i+10-a+i-1)
print(min(dp[len(N)][0],dp[len(N)][1]+1))
| 0 | null | 36,724,421,871,762 | 75 | 219 |
import re
W = input()
T = []
count = 0
while(1):
line = input()
if (line == "END_OF_TEXT"):
break
words = list(line.split())
for word in words:
T.append(word)
for word in T:
matchOB = re.fullmatch(W, word.lower())
if matchOB:
count += 1
print(count)
|
W = input().rstrip()
lst = []
while True:
line = input().rstrip()
if line == "END_OF_TEXT":
break
lst += line.lower().split()
print(lst.count(W))
| 1 | 1,819,988,503,610 | null | 65 | 65 |
#coding:utf-8
n,m=list(map(int,input().split()))
A,b=[],[]
for i in range(n):
A.append(list(map(int,input().split())))
for j in range(m):
b.append(int(input()))
ans=[0 for i in range(n)]
for i in range(n):
for j in range(m):
ans[i]+=A[i][j]*b[j]
for i in ans:
print(i)
|
def judge():
if t > h:
point["t"] += 3
elif t < h:
point["h"] += 3
else:
point["t"] += 1; point["h"] += 1
n = int(input())
point = {"t": 0, "h": 0}
for i in range(n):
t, h = input().split()
judge()
print(point["t"], point["h"])
| 0 | null | 1,579,694,515,164 | 56 | 67 |
f=n=0
while 1:
a=input()
if a.isdigit():
if n==1:s=s[int(a):]
n=1
else:
if f==1:print(s[:l])
if'-'==a:break
f=1
n=0
l=len(a)
s=a*100
|
N,K=map(int,input().split())
A = list(map(int,input().split()))
count = 0
now = 1
city = [1]
city2 = {1}
while count < K:
count += 1
now = A[now-1]
if now in city2:
break
else:
city.append(now)
city2.add(now)
if count == K:
print(now)
else:
n = city.index(now)
K -= n
count -= n
K %= count
print(city[n+K])
| 0 | null | 12,374,683,123,682 | 66 | 150 |
n, m = list(map(int, input().split()))
s = input()
if s.find('1' * m) != -1:
print('-1')
exit(0)
i = n
rans = []
flag = True
while flag:
for j in range(m, 1 - 1, -1):
if i - j == 0:
flag = False
if i - j >= 0 and s[i - j] == '0':
rans.append(j)
i = i - j
break
print(' '.join(map(str,reversed(rans))))
|
a, b, c, k = map(int, input().split())
ans = 0
ans += min(a, k)
k -= min(a, k)
k -= min(b, k)
ans -= min(c, k)
print(ans)
| 0 | null | 80,335,523,424,970 | 274 | 148 |
X=int(input())
from math import gcd
ans=360//gcd(X, 360)
print(ans)
|
N,K = map(int,input().split())
import numpy as np
A = np.array(input().split(),np.int64)
B = np.array(input().split(),np.int64)
A.sort() ; B.sort()
B=B[::-1]
right = max(A*B) #時間の可能集合の端点
left = -1 #時間の不可能集合の端点
def test(t):
C = A-t//B
D= np.where(C<0,0,C)
return D.sum()<=K
while left+1<right:
mid = (left+right)//2
if test(mid):
right=mid
else:
left = mid
print(right)
| 0 | null | 89,036,751,777,470 | 125 | 290 |
import math
r = input()
print '%.10f %.10f' %(r*r*math.pi , r*2*math.pi)
|
input();print(*input().split()[::-1])
| 0 | null | 816,456,687,228 | 46 | 53 |
def fib(n):
if n==0 or n==1:
return 1
x=[1,1]
for i in range(2,n+1):
x.append(x[i-1]+x[i-2])
return x[-1]
print(fib(int(input())))
|
import sys
import math
from collections import defaultdict, deque
from copy import deepcopy
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
def fib(num):
d = defaultdict(int)
d[0] = 1
d[1] = 1
if num <= 1:
return d[num]
else:
for i in range(1,num):
d[i+1] = d[i]+d[i-1]
return d[num]
def main():
num = I()
print(fib(num))
if __name__ == "__main__":
main()
| 1 | 2,116,279,580 | null | 7 | 7 |
S, W = map(int, input().split())
print('unsafe') if S <= W else print('safe')
|
n, a, b = map(int, input().strip().split())
if (b - a) % 2 == 1:
dt1 = a - 1
dt1 += 1
b1 = b - dt1
t1 = dt1 + (b1 - 1) // 2
dt2 = n - b
dt2 += 1
a1 = a + dt2
t2 = dt2 + (n - a1) // 2
print(min(t1, t2))
else:
print((b - a) // 2)
| 0 | null | 69,549,987,338,340 | 163 | 253 |
INF = 10**18
def solve(n, a):
# 現在の位置 x 選んだ個数 x 直前を選んだかどうか
dp = [{j: [-INF, -INF] for j in range(i//2-1, (i+1)//2 + 1)} for i in range(n+1)]
dp[0][0][False] = 0
for i in range(n):
for j in dp[i].keys():
if (j+1) in dp[i+1]:
dp[i+1][j+1][True] = max(dp[i+1][j+1][True], dp[i][j][False] + a[i])
if j in dp[i+1]:
dp[i+1][j][False] = max(dp[i+1][j][False], dp[i][j][False])
dp[i+1][j][False] = max(dp[i+1][j][False], dp[i][j][True])
return max(dp[n][n//2])
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))
|
#!/usr/bin/env python
n, k = map(int, input().split())
a = list(map(int ,input().split()))
def check(x):
now = 0
for i in range(n):
now += (a[i]-1)//x
return now <= k
l = 0
r = int(1e9)
while r-l > 1:
mid = (l+r)//2
if check(mid):
r = mid
else:
l = mid
print(r)
| 0 | null | 21,840,119,390,440 | 177 | 99 |
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
N=int(input())
A=[]
for i in range(N):
X,L=map(int,input().split())
A.append([X-L,X+L])
A=sorted(A, key=lambda x: x[1])
cur=-(10**10)
cnt=0
for i in range(N):
if A[i][0]<cur: continue
else:
cur=A[i][1]
cnt+=1
print(cnt)
resolve()
|
n = int(input())
ranges = []
for i in range(n):
x, l = map(int, input().split())
ranges.append([max(x-l, 0), x+l])
ranges.sort(key=lambda x: x[1])
start = 0
ans = 0
for range in ranges:
if range[0] >= start:
start = range[1]
ans += 1
print(ans)
| 1 | 90,164,023,714,908 | null | 237 | 237 |
n = int(input())
s = input()
rinds, ginds, binds = [], [], set()
for i in range(n):
if s[i] == 'R': rinds.append(i)
elif s[i] == 'G': ginds.append(i)
else: binds.add(i)
rlen, glen, blen = len(rinds), len(ginds), len(binds)
ans = 0
for i in rinds:
for j in ginds:
dist = abs(i-j)
i_ = min(i, j)
j_ = max(i, j)
ans += blen
# i' < j' < k
if j_ + dist in binds:
ans -= 1
if dist%2==0 and i_ + dist//2 in binds:
ans -= 1
if i_ - dist in binds:
ans -= 1
# if binsearch_same(binds, blen, dist, j_):
# ans -= 1
# # i'< k < j'
# if dist%2==0 and binsearch_same(binds, blen, dist//2, i_):
# ans -= 1
# # # k < i' < j'
# if binsearch_same(binds, blen, -dist, i_):
# ans -= 1
print(ans)
# n = input()
# print('Yes' if '7' in n else 'No')
# n = int(input())
# ans = 0
# for i in range(1, n+1):
# if i%3 == 0 or i%5==0:
# pass
# else:
# ans += i
# print(ans)
# k = int(input())
# def gcd(a, b):
# if b == 0:
# return a
# return gcd(b, a%b)
# 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)
|
N = int(input())
S = input()
R = []
G = []
B = []
for i in range(N):
if S[i] == 'R':
R.append(i+1)
elif S[i] == 'G':
G.append(i+1)
elif S[i] == 'B':
B.append(i+1)
lenb = len(B)
cnt = 0
for r in R:
for g in G:
up = max(r, g)
down = min(r, g)
diff = up - down
chk = 0
if up + diff <= N:
if S[up+diff-1] == 'B':
chk += 1
if down-diff >= 1:
if S[down-diff-1] == 'B':
chk += 1
if diff%2 == 0:
if S[int(up-diff/2-1)] == 'B':
chk += 1
cnt += lenb - chk
print(cnt)
| 1 | 36,120,280,277,496 | null | 175 | 175 |
from functools import lru_cache
@lru_cache(maxsize=None)
def Fib(n):
if n==0:
return 1
elif n==1:
return 1
else:
return Fib(n-1)+Fib(n-2)
n=int(input())
print(Fib(n))
|
from itertools import product
n = int(input())
ans = n-1
for a in range(1, int(n**0.5)+1):
if n%a==0:
b = n//a
ans = min(ans, b+a-2)
print(ans)
| 0 | null | 80,998,328,691,712 | 7 | 288 |
n = int(input())
ans = []
def dfs(A):
if len(A) == n:
ans.append(''.join(A))
return
for i in range(len(set(A))+1):
v = chr(i+ord('a'))
A.append(v)
dfs(A)
A.pop()
dfs([])
ans.sort()
for i in range(len(ans)):
print(ans[i])
|
from bisect import bisect_right
def bisectsearch_right(L,a):
i=bisect_right(L,a)
return(i)
N,M,K= list(map(int, input().split()))
A= list(map(int, input().split()))
B= list(map(int, input().split()))
Asum=[0]*N
Bsum=[0]*M
Asum[0]=A[0]
Bsum[0]=B[0]
for i in range(1,N):
Asum[i]=Asum[i-1]+A[i]
for j in range(1,M):
Bsum[j]=Bsum[j-1]+B[j]
# print(Asum)
# print(Bsum)
ans=[0]*(N+1)
ans[0]=bisectsearch_right(Bsum,K)
# print(ans[0])
for i in range(1,N+1):
if Asum[i-1]>K:
continue
j=bisectsearch_right(Bsum,K-Asum[i-1])
# print(j)
ans[i]=i+j
# print(ans)
print(max(ans))
| 0 | null | 31,608,775,210,140 | 198 | 117 |
n = int(input())
ascii_letters = 'abcdefghijklmnopqrstuvwxyz'
for i in range(1,15):
if n<=26**i:
order=i
n-=1
break
n-=26**i
for i in range(order):
print(ascii_letters[n//(26**(order-i-1))],end='')
n%=(26**(order-i-1))
print()
|
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, "")
| 1 | 11,868,574,795,210 | null | 121 | 121 |
if input().islower() == True:
print("a")
else:
print("A")
|
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
print(len([a for a in A if a >= K]))
| 0 | null | 95,628,384,681,468 | 119 | 298 |
s,t=map(str,input().split())
a,b=map(int,input().split())
u=input()
print(str(a-1) + " " + str(b) if s==u else str(a) + " " + str(b-1))
|
n,b,r = map(int, input().split())
t = n % (b+r)
q = n // (b+r) * b
if t > b:
t = b
print(q+t)
| 0 | null | 63,788,667,897,808 | 220 | 202 |
import math
from functools import reduce
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm(*numbers):
return reduce(lcm_base, numbers, 1)
N,M = map(int,input().split())
a = list(map(lambda a: int(a)//2, input().split()))
g = lcm(*a)
if any([g // item % 2 == 0 for item in a]):
print(0)
else:
ans = M//g
ans = max(math.ceil(ans/2),0)
print(ans)
|
import math
from sys import stdin
input = stdin.readline
def prime_fatorization(n):
# O(sqrt(n))
from collections import defaultdict
# a = []
a = defaultdict(int)
while not(n % 2):
# a.append(2)
a[2] += 1
n //= 2
f = 3
while f * f <= n:
if not(n % f):
# a.append(f)
a[f] += 1
n //= f
else:
f += 2
if n != 1:
# a.append(n)
a[n] += 1
return a
def main():
N, M = list(map(int, input().split()))
A = list(map(lambda x: int(x)//2, input().split()))
pre = A[0]
for i in range(1, N):
if pre % 2 != A[i] % 2:
print(0)
return
if not A[0] % 2:
fac2 = prime_fatorization(A[0])[2]
for i in range(1, N):
if not A[i]//(2**fac2) % 2:
print(0)
return
lcm = A[0]
for i in range(1, N):
lcm = lcm * A[i] // math.gcd(lcm, A[i])
print((M // lcm + 1) // 2)
if(__name__ == '__main__'):
main()
| 1 | 102,006,083,625,380 | null | 247 | 247 |
a, b, c = map(int, input().split())
i = a
ans = 0
while i <= b:
if c % i == 0:
ans += 1
i += 1
print(ans)
|
A, B = [int(n) for n in input().split()]
print(max(0, int(A-2*B)))
| 0 | null | 83,878,900,836,160 | 44 | 291 |
l = list(map(int, input().split()))
for i in range(5):
if l[i] == 0:
print(i + 1)
|
a = list(map(int,input().split()))
print(15-sum(a))
| 1 | 13,407,555,043,208 | null | 126 | 126 |
n = int(input())
x = list(map(int, input().split()))
sum1 = 100*100**2
for i in range(101):
sum2 = 0
for j in range(len(x)):
sum2 += (x[j] - i)**2
if sum2 < sum1:
sum1 = sum2
print(sum1)
|
inp = input()
if inp[0] == inp[1] and inp[1] == inp[2]:
print("No")
else:
print("Yes")
| 0 | null | 60,260,018,022,620 | 213 | 201 |
NUM = 1000000007
N = int(input())
all_colab = pow(10, N)
except_0or9_colab = pow(9, N)
except_0and9_colab = pow(8, N)
include_0and9_colab = all_colab - (2*except_0or9_colab - except_0and9_colab)
print(include_0and9_colab % NUM)
|
def main():
n = int(input())
ans = 0
for i in range(1, n + 1):
if (i % 3 != 0) and (i % 5 != 0):
ans += i
print(ans)
main()
| 0 | null | 19,108,477,022,768 | 78 | 173 |
n=int(input())
print(2*3.14*n)
|
n = input()
n2 = n * 2
x = input()
if x in n2:
print('Yes')
else: print('No')
| 0 | null | 16,497,217,693,920 | 167 | 64 |
n = int(input())
ans = 0
for a in range (1,n):
for b in range(1, n):
if n <= a * b:
break
ans += 1
print(ans)
|
import math
n = int(input())
ans = 0
for i in range(1, n):
ans += (math.ceil(n/i))-1
print (ans)
| 1 | 2,606,180,064,220 | null | 73 | 73 |
A = set(map(int,input().split()))
print("Yes" if len(A)==2 else "No")
|
n,m = map(int,raw_input().split())
A = [[0 for i in range(m)] for i in range(n)]
B = [ 0 for i in range(m)]
for i in range(n):
A[i] = map(int,raw_input().split())
for i in range(m):
B[i] = input()
for i in range(n):
sum = 0
for j in range(m):
sum += A[i][j] * B[j]
print sum
| 0 | null | 34,490,081,137,372 | 216 | 56 |
from enum import Enum
class Type(Enum):
win_Taro = 0
win_Hanako = 1
Even = 2
def comp_str(A, B):
if A > B:
return Type.win_Taro
elif A < B:
return Type.win_Hanako
else:
return Type.Even
N = int(input())
point_Taro = 0
point_Hanako = 0
for loop in range(N):
line = str(input()).split()
ret_type = comp_str(line[0], line[1])
if ret_type == Type.win_Taro:
point_Taro += 3
elif ret_type == Type.win_Hanako:
point_Hanako += 3
else:
point_Taro += 1
point_Hanako += 1
print("%d %d"%(point_Taro, point_Hanako))
|
N = int(input())
count1 = N // 500
count2 = ( N%500 ) // 5
print( 1000*count1 + 5*count2 )
| 0 | null | 22,352,893,232,258 | 67 | 185 |
"""
n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
mod = 1000000007
ab1 = []
ab2 = []
ab3 = []
ab4 = []
count00 = 0
count01 = 0
count10 = 0
for i in range(n):
if ab[i][0] != 0 and ab[i][1] != 0:
ab1.append(ab[i][0]/ab[i][1])
ab2.append(-ab[i][1]/ab[i][0])
if ab[i][0]/ab[i][1] > 0:
ab3.append((ab[i][0]/ab[i][1],-ab[i][1]/ab[i][0]))
else:
ab4.append((ab[i][0]/ab[i][1],-ab[i][1]/ab[i][0]))
elif ab[i][0] == 0 and ab[i][1] == 0:
count00 += 1
elif ab[i][0] == 0 and ab[i][1] == 1:
count01 += 1
else:
count10 += 1
dict1 = {}
dict2 = {}
ab3.sort()
ab4.sort(reverse = True)
print(ab3)
print(ab4)
for i in ab1:
if i in dict1:
dict1[i] += 1
else:
dict1[i] = 1
for i in ab2:
if i in dict2:
dict2[i] += 1
else:
dict2[i] = 1
sorted1 = sorted(dict1.items(), key = lambda x: x[0])
sorted2 = sorted(dict2.items(), key = lambda x: x[0])
print(sorted1)
print(sorted2)
cnt = 0
num1 = n - count00 - count01 - count10
ans = 0
for i in range(len(ab3)):
a,b = ab3[i]
num1 -= 1
if cnt < len(sorted2):
while cnt < len(sorted2):
if sorted2[cnt][0] == a:
ans += pow(2, num1+count01+count10-sorted2[cnt][1], mod)
ans %= mod
break
elif sorted2[cnt][0] < a:
cnt += 1
else:
ans += pow(2, num1+count01+count10, mod)
ans %= mod
break
else:
ans += pow(2, num1+count01+count10, mod) - pow(2, )
ans %= mod
print(ans)
for i in range(len(ab4)):
num1 -= 1
ans += pow(2, num1+count01+count10, mod)
ans %= mod
print(ans)
ans += pow(2, count01, mod) -1
print(ans)
ans += pow(2, count10, mod) -1
print(ans)
ans += count00
print(ans)
print(ans % mod)
"""
from math import gcd
n = int(input())
dict1 = {}
mod = 1000000007
cnt00 = 0
cnt01 = 0
cnt10 = 0
for _ in range(n):
a,b = map(int,input().split())
if a == 0 and b == 0:
cnt00 += 1
elif a == 0:
cnt01 += 1
elif b == 0:
cnt10 += 1
else:
c = gcd(a,b)
if b < 0:
a *= -1
b *= -1
set1 = (a//c, b//c)
if set1 in dict1:
dict1[set1] += 1
else:
dict1[set1] = 1
ans = 1
for k,v in dict1.items():
a,b = k
if dict1[(a,b)] == -1:
continue
if a > 0:
if (-b,a) in dict1:
ans *= 2**v + 2**dict1[(-b,a)] - 1
dict1[(-b,a)] = -1
else:
ans *= 2**v
else:
if (b,-a) in dict1:
ans *= 2**v + 2**dict1[(b,-a)] - 1
dict1[(b,-a)] = -1
else:
ans *= 2**v
ans %= mod
ans *= 2 ** cnt01 + 2 ** cnt10 - 1
ans += cnt00 - 1
print(ans%mod)
|
H_1, M_1, H_2, M_2, K = list(map(int, input().split(' ')))
print((H_2-H_1)*60+(M_2-M_1)-K)
| 0 | null | 19,413,351,149,140 | 146 | 139 |
import sys
A, B = (int(x) for x in input().split())
num=0
while int(num*0.08)<=A:
if int(num*0.08)==A and int(num*0.1)==B:
print(num)
sys.exit(0)
num+=1
print(-1)
|
a, b = map(int, input().split())
ans = -1
for money in range(pow(10, 4)):
if int(money*0.08) == a and int(money*0.1) == b:
ans = money
break
print(ans)
| 1 | 56,472,616,663,228 | null | 203 | 203 |
n,m=map(int,input().split())
left=m//2
right=(m+1)//2
for i in range(left):
print(i+1,2*left+1-i)
for i in range(right):
print(2*left+1+i+1,2*left+1+2*right-i)
|
import math
import fractions
import collections
import itertools
import pprint
N,M=map(int,input().split())
#rotateすれば他の部屋で同じ組み合わせが出てしまう<=>他の部屋の2数の数字の差が同じになってしまう
#前半分を偶数差、後ろ半分を奇数差と言った感じで上から詰めれば良い
#部屋数をMとして、1,2,...,Mの差を考える
l=[]
maemin=1
usiromax=N
for i in range(M,0,-1):
if i%2==0:
l.append([maemin,maemin+i])
maemin=maemin+1
else:
l.append([usiromax-i,usiromax])
usiromax=usiromax-1
#print(l)
for i in range(M):
print(*l[i],sep=" ")
| 1 | 28,705,374,255,008 | null | 162 | 162 |
N = int(input())
a = list(map(int, input().split()))
ans = 0
i = 1
for num in a:
if num != i:
ans += 1
else:
i += 1
print(ans if ans < len(a) else -1)
|
n=int(input())
a=list(map(int,input().split()))
if not 1 in set(a):
print("-1")
exit()
b=1
for i in range(n):
if a[i]==b:
b+=1
print(n-b+1)
| 1 | 114,851,197,091,750 | null | 257 | 257 |
d = int(input())
if d >= 30:
print("Yes")
else:
print("No")
|
def resolve():
import math
x, k, d = list(map(int, input().split()))
ans = abs(x)
x = abs(x)
if x - d * k >= 0:
ans = x - d * k
else:
k -= math.floor(x / d)
x -= math.floor(x / d) * d
if k % 2 == 1: x = abs(x - d)
ans = x
print(ans)
resolve()
| 0 | null | 5,424,262,117,938 | 95 | 92 |
n=int(input())
taro=0
hanako=0
for i in range(n):
t,h=map(str,input().split())
if t>h:
taro += 3
elif h>t:
hanako += 3
else:
taro += 1
hanako += 1
print(taro,hanako)
|
line = input()
for _ in range(int(input())):
x = input().split()
order = x[0]
a = int(x[1])
b = int(x[2])+1
if order == "print":
print(line[a:b])
elif order == "reverse":
line = line[:a] + line[a:b][::-1] + line[b:]
elif order == "replace":
line = line[:a] + x[3] + line[b:]
| 0 | null | 2,030,454,242,400 | 67 | 68 |
nums = input().split()
if len(set(nums)) == 2:
print('Yes')
else:
print('No')
|
input_line = list(map(int, input().split(' ')))
result = False
for x in list(set(input_line)):
if input_line.count(x) == 2:
result = True
if result:
print('Yes')
else:
print('No')
| 1 | 68,069,612,275,492 | null | 216 | 216 |
N = int(input())
S = list(input())
cn = 1
for i in range(N-1):
if S[i] == S[i+1]:
continue
else:
cn = cn + 1
print(cn)
|
a = [i for i in input().split()]
b = []
for i in range(len(a)):
b.append(a.pop(a.index(min(a))))
print(" ".join([str(i) for i in b]))
| 0 | null | 84,970,727,361,238 | 293 | 40 |
x = int(input())
h = x // 3600
m = (x -h*3600)//60
s = x - h*3600 - m*60
print(h, ':',m , ':', s, sep="")
|
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
import math
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())
INF, NINF = float('inf'), float('-inf')
def main():
L, R, d = rli()
ans = 0
for x in range(L, R+1):
if x % d == 0:
ans += 1
print(ans)
stdout.close()
if __name__ == "__main__":
main()
| 0 | null | 3,904,786,116,280 | 37 | 104 |
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
n = I()
suuretu = LI()
q = I()
dic = collections.Counter(suuretu)
nowsum = sum(suuretu)
for _ in range(q):
b,c = LI()
cnt = dic[b]
nowsum += (c-b)*cnt
print(nowsum)
dic[b] = 0
dic[c] += cnt
main()
|
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)
| 1 | 12,206,901,345,950 | null | 122 | 122 |
N=int(input())
S=set()
for i in range(1,N):
x=i
y=N-i
if x<y:
S.add(x)
print(len(S))
|
n=int(raw_input())
print (n-1)/2
| 1 | 152,871,115,060,060 | null | 283 | 283 |
n = int(input())
ls = list(map(int, input().split()))
rsw = [0]*1005
for i in ls:
rsw[i] += 1
for i in range(1,1005):
rsw[i] = rsw[i-1] + rsw[i]
res = 0
for i in range(n):
for j in range(i+1,n):
a = ls[i]
b = ls[j]
low = abs(a-b)
high = a+b
tmp = rsw[min(high,1004)-1] - rsw[low]
if low < a < high:
tmp -= 1
if low < b < high:
tmp -= 1
res += tmp
print(res//3)
|
x,y=map(int,input().split())
if x==y==1:
print(1000000);exit()
A=[300000,200000,100000]+[0]*1000
print(A[x-1]+A[y-1])
| 0 | null | 156,357,779,321,820 | 294 | 275 |
m = 100000
for i in range(int(raw_input())):
m*=1.05
m=(int((m+999)/1000))*1000
print m
|
n = input()
d = 100000
for x in range(n):
d += int(d*0.05)
d = str(d)
if d[-3:] != "000":
d = d[:-3] + "000"
d = int(d) +1000
else:
d = int(d)
print d
| 1 | 1,257,725,712 | null | 6 | 6 |
n,*a = map(int,open(0).read().split())
a = sorted([(j,i) for i,j in enumerate(a)],reverse=True)
dp = [0]
for i,(j,k) in enumerate(a):
ldp = [abs(k-i+a)*j+b for a,b in enumerate(dp)]
rdp = [abs(n-1-k-a)*j+b for a,b in enumerate(dp)]
dp = [max(a,b) for a,b in zip(ldp+[0],[0]+rdp)]
print(max(dp))
|
import sys
try:
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
except:
pass
input = sys.stdin.readline
n = int(input())
arr = list(map(int,input().split()))
arr = list(enumerate(arr))
arr.sort(reverse = True, key = lambda x:(x[1]))
dp = [[0 for c in range(n+1)] for r in range(n+1)]
ans = 0
for r in range(n+1):
st = r-1
for c in range(n+1-r):
if r==c==0:
pass
elif r-1<0:
dp[r][c] = dp[r][c-1] + ( arr[st][1] * abs((arr[st][0]+1) - (n+1-c)) )
elif c-1<0:
dp[r][c] = dp[r-1][c] + ( arr[st][1] * abs((arr[st][0]+1) - r) )
else:
dp[r][c] = max( dp[r-1][c] + ( arr[st][1] * abs((arr[st][0]+1) - r) ),
dp[r][c-1] + ( arr[st][1] * abs((arr[st][0]+1) - (n+1-c)) )
)
ans = max(ans, dp[r][c])
st += 1
print(ans)
| 1 | 33,570,283,590,152 | null | 171 | 171 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
ans = 0
for a in range(1, N):
ans += (N-1)//a
print(ans)
|
import math
n = int(input())
ans = 0
for i in range(1, n):
ans += (math.ceil(n/i))-1
print (ans)
| 1 | 2,585,988,197,260 | null | 73 | 73 |
k = int(input())
s = 'ACL' * k
print(s)
|
word = 'ACL'
a = int(input())
word = word *a
print(word)
| 1 | 2,165,485,355,440 | null | 69 | 69 |
import sys
x = sys.stdin.readline()
a, b = x.split(" ")
a = int(a)
b = int(b)
S = a * b
l = 2 * (a + b)
print '%d %d' % (S,l)
|
a=map(int,raw_input().split())
print(str(a[0]*a[1])+" "+str(2*(a[0]+a[1])))
| 1 | 301,994,605,650 | null | 36 | 36 |
n,k = map(int,input().split())
t = [1]*n
for i in range(k):
input()
for j in map(int,input().split()):
t[j-1] = 0
print(sum(t))
|
n,m = map(int,input().split())
if m%2 == 1:
a = 1
b = a+2*(m//2)+2
for i in range(m//2+1):
print(a,a+2*(m//2-i)+1)
a += 1
for i in range(m//2):
print(b,b+2*(m//2-i))
b += 1
else:
a = 1
b = a+2*(m//2)+1
for i in range(m//2):
print(a,a+2*(m//2-i))
a += 1
for i in range(m//2):
print(b,b+2*(m//2-i-1)+1)
b += 1
| 0 | null | 26,749,851,212,480 | 154 | 162 |
A, B = map(int, input().split())
ans = A*B
if A > 9 or B > 9:
ans = -1
print(ans)
|
l=list(map(int,input().split()))
a=l[0]
b=l[1]
if(a>9 or a<1 or b>9 or b<1):
print(-1)
else:
print(a*b)
| 1 | 157,554,166,213,192 | null | 286 | 286 |
#coding:utf-8
#1_1_C 2015.3.6
a,b = input().split()
area = int(a) * int(b)
circumference = (int(a) + int(b)) * 2
print(area,circumference)
|
#cording; UTF-8
a,b=[int(x) for x in input().split()]
S = a*b
L = 2*(a+b)
print(S,L)
| 1 | 303,173,017,772 | null | 36 | 36 |
n_m_str=input().split()
n_m=list(map(lambda i : int(i),n_m_str))
n,m=n_m[0],n_m[1]
a=[input() for i in range(n)]
A=[]
for i in a:
A.append(i.split())
b=[input() for i in range(m)]
Ab=[]
for i in range(n):
Ab.append(0)
for i in range(n):
for j in range(m):
Ab[i]+=int(A[i][j])*int(b[j])
for i in Ab:
print(i)
|
N = int(input())
x = input().strip()
cnt = 0
for i in range(N):
if x[i]=="R":
cnt += 1
if cnt==0 or cnt==N:
print(0)
else:
ans = 0
for i in range(cnt):
if x[i]=="W":
ans += 1
print(ans)
| 0 | null | 3,702,185,094,712 | 56 | 98 |
def solve():
N,K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(K):
arr = [0] * (N + 1)
for ind,j in enumerate(A):
arr[max(ind-j,0)] += 1
arr[min(ind+j+1, N)] -= 1
A[0] = arr[0]
for k in range(N-1):
A[k+1] = A[k] + arr[k+1]
if arr[0] ==N and arr[-1] == -N:
return A
return A
if __name__ == "__main__":
ans = solve()
print(*ans)
|
a,b,c = map(int, input().split())
X = c
Y = a
Z = b
print (X,Y,Z)
| 0 | null | 26,704,061,972,980 | 132 | 178 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
T=LI()
A=LI()
B=LI()
SA=T[1]*A[1]+T[0]*A[0]
SB=T[1]*B[1]+T[0]*B[0]
if SA == SB:
print("infinity")
else:
#t1+t2分後に確実にAが先行するように.
if SB>SA:
SB,SA=SA,SB
A,B=B,A
if A[0]>=B[0]:
print(0)
else:
diff1=(B[0]-A[0])*T[0]
diff2=SA-SB
cnt=(diff1//diff2+1)
ans=(cnt)*2-1
#基本,1ループで2回,初回は0,0のため-1
#さらに,cnt回目のループでぎり1回だけという場合があるので,その場合は1ひく
if diff2*(cnt-1) == diff1:
ans-=1
print(ans)
main()
|
for x in range(1, 10):
for y in range(1, 10):
print "{}x{}={}".format(x, y, x*y)
| 0 | null | 66,154,943,888,838 | 269 | 1 |
# coding: utf-8
# Your code here!
n = int(input())
ta = 0
ha = 0
for i in range(n):
a, b = list(input().split())
if a == b:
ta += 1
ha += 1
elif a > b:
ta += 3
else:
ha += 3
print(ta,ha)
|
A,B,C,D=map(int,input().split())
x=(A-1)//D+1
y=(C-1)//B+1
if x<y:
print("No")
else:
print("Yes")
| 0 | null | 15,851,889,932,052 | 67 | 164 |
MOD=10**9+7
def powmod(a,n,m): #a^n mod m
ans=1
while n!=0:
if n&1: ans=ans*a%m
a=a*a%m
n>>=1
return ans%m
def fact(a,b):
ans=1
for i in range(a,b+1): ans=ans*i%MOD
return ans
n,a,b=map(int,input().split())
ans=powmod(2,n,MOD)-1
ta1=fact(n-a+1,n)
tb1=fact(n-b+1,n)
ta2=pow(fact(1,a),MOD-2,MOD)
tb2=pow(fact(1,b),MOD-2,MOD)
a=ta1*ta2%MOD
b=tb1*tb2%MOD
print((ans-a-b)%MOD)
|
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
if n: return [0 for _ in range(n)]
else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
if n: return ["" for _ in range(n)]
else: return sinput().split()
def adj(n): return [[] for _ in range(n)]
#整数問題セット
def gcd(numbers): return func.reduce(frac.gcd, numbers)
def lcm(numbers): return func.reduce(LCM, numbers)
def inv(a): return pow(a, MOD-2, MOD) #逆元
def comb(n,r):
ans = 1
for i in range(r): ans *= n-i; ans *= inv(r-i); ans %= MOD
return ans
n,a,b = imap()
ans = pow(2,n,MOD) - comb(n,a) - comb(n,b) - 1
print(ans%MOD)
| 1 | 66,177,055,178,560 | null | 214 | 214 |
S,W = map(int,input().split())
print(("safe","unsafe")[W >= S])
|
arr = input().split()
arr.sort()
for i in range(len(arr)):
if i == len(arr) - 1:
print(arr[i])
else:
print(arr[i], end = " ")
| 0 | null | 14,908,229,971,910 | 163 | 40 |
import string
a=string.ascii_lowercase
A=string.ascii_uppercase
n=input()
if n in a :
print("a")
else :
print("A")
|
#!/usr/bin/env python3
import sys
import collections as cl
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
N = II()
num = 0
for i in range(N):
a, b = MI()
if a == b:
num += 1
if num == 3:
print("Yes")
return
else:
num = 0
print("No")
main()
| 0 | null | 6,876,628,073,338 | 119 | 72 |
import math
h,w = map(int,input().split())
ans = 0
if h == 1 or w ==1 :
ans += 1
else:
#奇数行目+偶数行目
ans += math.ceil(h/2)*math.ceil(w/2)+(h//2)*(w//2)
print(ans)
|
s=int(raw_input())
print str(s//3600)+':'+str(s//60%60)+':'+str(s%60)
| 0 | null | 25,445,526,243,324 | 196 | 37 |
a, b, c = map(int, input().split())
k = int(input())
r = 0
while b <= a :
b = 2 * b
r += 1
while c <= b:
c = 2 * c
r += 1
if r <= k:
print("Yes")
else:
print("No")
|
a,b,c=map(int,input().split())
K=int(input())
isCheck = None
for i in range(K+1):
for j in range(K+1):
for k in range(K+1):
x = a*2**(i)
y = b*2**(j)
z = c*2**(k)
if i+j+k <= K and x < y and y < z:
isCheck = True
if isCheck:
print("Yes")
else:
print("No")
| 1 | 6,910,701,609,100 | null | 101 | 101 |
def main():
x, y = map(int, input().split())
print('Yes' if 2*x <= y <= 4*x and y % 2 == 0 else 'No')
if __name__ == '__main__':
main()
|
X,Y = map(int,input().split())
check = False
for i in range(0,X+1):
for j in range(0,X+1):
if i + j == X and 2*i + 4*j == Y:
check = True
if check:
print("Yes")
else:
print("No")
| 1 | 13,717,219,415,042 | null | 127 | 127 |
import numpy as np
H, N = map(int, input().split())
A = []
B = []
for i in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
A = np.array(A)
B = np.array(B)
DP = np.zeros(H + 1)
for i in range(1, H + 1):
DP[i] = np.amin(DP[np.maximum(i - A, 0)] + B)
print(int(DP[-1]))
|
n=int(input())
vec=[0 for _ in range(10050)]
for x in range(1,105):
for y in range (1,105):
for z in range (1 , 105):
sum= x*x + y*y + z*z + x*y +y*z + z*x
if sum<10050:
vec[sum]+=1
for i in range(1,n+1):
print(vec[i])
| 0 | null | 44,570,298,790,810 | 229 | 106 |
X = int(input())
if ((2000-X)%200) == 0:
print((2000-X)//200)
else:
print((2000-X)//200+1)
|
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
x = inp()
if x < 600:
ans = 8
elif x < 800:
ans = 7
elif x < 1000:
ans = 6
elif x < 1200:
ans = 5
elif x < 1400:
ans = 4
elif x < 1600:
ans = 3
elif x < 1800:
ans = 2
elif x < 2000:
ans = 1
print(ans)
| 1 | 6,722,367,890,810 | null | 100 | 100 |
a,b=[int(x) for x in input().split()]
c=0
for i in range(1,12501):
if int(0.08*i)==a and int(0.1*i)==b:
ans=i
c=1
break
if c==1:
print(ans)
else:
print(-1)
|
A, B = map(int, input().split())
min_ans = int((12.5*A) // 1)
max_ans = int(-((-12.5*(A+1)) // 1))
ans = -1
for i in range(min_ans,max_ans):
temp_A = (i*0.08)//1
temp_B = (i*0.1)//1
if temp_A == A and temp_B == B :
ans = i
break
print(ans)
| 1 | 56,614,219,172,800 | null | 203 | 203 |
from itertools import accumulate
n,m,k = map(int,input().split())
deskA = list(map(int,input().split()))
deskB = list(map(int,input().split()))
cumA = list(accumulate(deskA))
cumB = list(accumulate(deskB))
cumA = [0] + cumA
cumB = [0] + cumB
ans = 0
l = m
for i in range(n+1):
tmp = k - cumA[i]
if tmp<0:
continue
j = l
tmp -= cumB[j]
while tmp < 0:
tmp += cumB[j]
j -= 1
tmp -= cumB[j]
l = j
ans = max(i+j,ans)
print(ans)
|
def gcd(u, v):
if (v == 0): return u
return gcd(v, u % v)
def lcm(u, v):
return (u * v) // gcd(u, v)
while 1:
try:
inp = input()
except EOFError:
break
else:
u, v = inp.split(' ')
u = int(u)
v = int(v)
print(gcd(u, v), lcm(u, v))
| 0 | null | 5,398,327,300,070 | 117 | 5 |
def resolve():
N = int(input())
print(1000 * ((1000 + (N-1)) // 1000) - N)
resolve()
|
import sys
for i in sys.stdin:
h,w = map(int,i.strip().split())
if h==0 and w==0:
break
for i in range(h):
for j in range(w):
if (i+j) % 2 == 0:
print('#',end='')
else:
print('.',end='')
print()
print()
| 0 | null | 4,619,435,202,880 | 108 | 51 |
N, T = map(int, input().split())
A = [0]*N
B = [0]*N
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])
dp = [[0]*(T) for _ in range(N+1)]
ans = 0
for i in range(N):
for j in range(T):
dp[i+1][j] = dp[i][j]
ans = max(ans, dp[i][j] + AB[i][1])
# 上は この時刻jまでで商品i-1個を入れた後に時間制約の無いi個目の商品を追加している
if j - AB[i][0] >= 0:
dp[i+1][j] = max(dp[i][j], dp[i][j-AB[i][0]] + AB[i][1])
print(ans)
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, T, *AB = map(int, read().split())
A = AB[::2]
B = AB[1::2]
dp1 = [[0] * T for _ in range(N + 1)]
for i in range(N):
for t in range(T):
if 0 <= t - A[i]:
dp1[i + 1][t] = dp1[i][t - A[i]] + B[i]
if dp1[i + 1][t] < dp1[i][t]:
dp1[i + 1][t] = dp1[i][t]
dp2 = [[0] * T for _ in range(N + 1)]
for i in range(N - 1, -1, -1):
for t in range(T):
if 0 <= t - A[i]:
dp2[i][t] = dp2[i + 1][t - A[i]] + B[i]
if dp2[i][t] < dp2[i + 1][t]:
dp2[i][t] = dp2[i + 1][t]
ans = 0
for i in range(N):
tmp = max(dp1[i][t] + dp2[i + 1][T - t - 1] for t in range(T)) + B[i]
if ans < tmp:
ans = tmp
print(ans)
return
if __name__ == '__main__':
main()
| 1 | 151,685,728,108,250 | null | 282 | 282 |
one_word = raw_input()
word_count = 0
word_list = []
while 1:
temp = raw_input()
word_list += temp.split()
if word_list[len(word_list)-1] == "END_OF_TEXT":
break
for word in word_list:
if one_word.lower() == word.lower():
word_count += 1
print word_count
|
import sys
W = sys.stdin.readline().strip()
num = 0
while True:
T = sys.stdin.readline().strip()
if T == 'END_OF_TEXT':
break
t = T.lower()
T_line = t.split()
for i in T_line:
if W == i:
num += 1
print(num)
| 1 | 1,837,528,415,526 | null | 65 | 65 |
k = int(input())
str = ''
for _ in range(k):
str += 'ACL'
print(str)
|
s = input()
n = len(s)
dp = [0]*(n+1)
t = 0
for e,i in enumerate(s,1):
if i=='<' :
dp[e]=dp[e-1]+1
# print(dp)
t = 0
for e in range(n-1,-1,-1):
i = s[e]
# print(t)
if i=='>' :
dp[e]=max(dp[e],dp[e+1]+1)
# print(dp)
print(sum(dp))
| 0 | null | 79,400,077,943,648 | 69 | 285 |
from math import floor
from fractions import Fraction
a,b=map(str,input().split())
a=int(a)
b=Fraction(b)
print(int(a*b))
|
while True:
s=input().split()
t=[int(i) for i in s]
H=t[0]
W=t[1]
if H==0:
break
else:
print("#"*W)
for i in range(H-2):
print("#"+"."*(W-2)+"#")
print("#"*W)
print()
| 0 | null | 8,684,421,586,650 | 135 | 50 |
import time
start=time.time()
k=int(input())
ans=0
x=k
for i in range(10**9):
while x%10!=7:
x+=k
if time.time()-start>=1.9:exit(print(-1))
x//=10
if x==0:exit(print(i+1))
|
if __name__ == '__main__':
from sys import stdin
while True:
m, f, r = (int(n) for n in stdin.readline().rstrip().split())
if m == f == r == -1:
break
s = m + f
result = "F" if m == -1 or f == -1 \
else "A" if 80 <= s \
else "B" if 65 <= s \
else "C" if 50 <= s or 50 <= r \
else "D" if 30 <= s \
else "F"
print(result)
| 0 | null | 3,654,434,621,588 | 97 | 57 |
import sys
read = sys.stdin.read
def main():
N, K = map(int, read().split())
dp1 = [0] * (K + 1)
dp2 = [0] * (K + 1)
dp1[0] = 1
for x in map(int, str(N)):
for j in range(K, -1, -1):
if j > 0:
dp2[j] += dp2[j - 1] * 9
if x != 0:
dp2[j] += dp1[j - 1] * (x - 1) + dp1[j]
dp1[j] = dp1[j - 1]
else:
dp1[j] = 0
dp2[j] = 1
print(dp1[K] + dp2[K])
return
if __name__ == '__main__':
main()
|
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)
MAXN = 100
n = input()
k = int(input())
dl = [[None] * (MAXN + 1) for _ in range(MAXN + 1)]
de = [[None] * (MAXN + 1) for _ in range(MAXN + 1)]
def n_num_e(d, i):
# d: n of digits
# i: n of nonzero digits
if d == 0:
if i == 0:
return 1
else:
return 0
elif de[d][i] is not None:
return de[d][i]
else:
if int(n[d - 1]) == 0:
result = n_num_e(d - 1, i)
else:
result = n_num_e(d - 1, i - 1)
de[d][i] = result
return result
def n_num_l(d, i):
# d: n of digits
# i: n of nonzero digits
if d == 0:
return 0
elif dl[d][i] is not None:
return dl[d][i]
else:
if int(n[d - 1]) == 0:
ne = 0
nl = 9 * n_num_l(d - 1, i - 1) + n_num_l(d - 1, i)
result = ne + nl
else:
ne = (int(n[d - 1]) - 1) * n_num_e(d - 1, i - 1) + n_num_e(d - 1, i)
nl = 9 * n_num_l(d - 1, i - 1) + n_num_l(d - 1, i)
result = ne + nl
dl[d][i] = result
return result
answer = n_num_e(len(n), k) + n_num_l(len(n), k)
print(answer)
| 1 | 76,225,691,170,148 | null | 224 | 224 |
d={}
for _ in[0]*int(input()):
c,g=input().split()
if'i'==c[0]:d[g]=0
else:print(['no','yes'][g in d])
|
# AOJ ALDS1_4_C Dictionary
# Python3 2018.7.3 bal4u
dic = {}
n = int(input())
for i in range(n):
id, s = input().split()
if id == "insert": dic[s] = 1
else: print("yes" if s in dic else "no")
| 1 | 78,004,880,888 | null | 23 | 23 |
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
def resolve():
import sys
input = sys.stdin.readline
n, a, b = [int(x) for x in input().rstrip().split(" ")]
if a > n - b + 1:
tmp = a
a = n - b
b = n - tmp
else:
a = a - 1
b = b - 1
if (b - a) % 2 == 0:
print(abs(a - b) // 2)
else:
count = a + 1 + ((b - a - 1) // 2)
print(count)
if __name__ == "__main__":
resolve()
|
import math
import statistics
import collections
a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in b:
# c.append(i)
#e1,e2 = map(int,input().split())
# f = list(map(int,input().split()))
g = [input() for _ in range(a)]
# h = []
# for i in range(e1):
# h.append(list(map(int,input().split())))
g.sort()
ma=0
count=1
#最大値求める
for i in range(a-1):
if g[i]==g[i+1]:
count+=1
else:
ma=max(ma,count)
count=1
ma=max(ma,count)
count=1
ans=[]
#最大値の位置
for i in range(a-1):
if g[i]==g[i+1]:
count+=1
else:
if count==ma:
ans.append(g[i])
count=1
if count==ma:
ans.append(g[-1])
for i in ans:
print(i)
| 0 | null | 89,807,623,632,332 | 253 | 218 |
#!/usr/bin/env python3
import sys
from itertools import chain
YES = "Yes" # type: str
NO = "No" # type: str
def solve(H: int, N: int, A: "List[int]"):
if H <= sum(A):
return YES
else:
return NO
def main():
tokens = chain(*(line.split() for line in sys.stdin))
H = int(next(tokens)) # type: int
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
answer = solve(H, N, A)
print(answer)
if __name__ == "__main__":
main()
|
L = input().split()
L.reverse()
print(*L, sep="")
| 0 | null | 90,304,430,717,890 | 226 | 248 |
n = int(input())
q = list(map(int,input().split()))
ans = 0
count = 0
for i in q:
if i%2 == 0:
alm = i
count += 1
if alm%3 == 0 or alm%5 == 0:
ans += 1
if ans == count:
print("APPROVED")
else:
print("DENIED")
|
N = int(input())
ints = map(int, input().split())
for i in ints:
if i % 2 == 0:
if i % 3 != 0 and i % 5 != 0:
print('DENIED')
exit()
print('APPROVED')
| 1 | 69,046,797,508,300 | null | 217 | 217 |
H,W,*L = open(0).read().split()
H,W = map(int, (H,W))
dp = [[0]*W for i in range(H)]
for i in range(1,H):
if L[i][0]!=L[i-1][0]:
dp[i][0] = dp[i-1][0]+1
else:
dp[i][0] = dp[i-1][0]
for j in range(1,W):
if L[0][j]!=L[0][j-1]:
dp[0][j] = dp[0][j-1]+1
else:
dp[0][j] = dp[0][j-1]
for i in range(1,H):
for j in range(1,W):
if L[i][j]!=L[i-1][j] and L[i][j]!=L[i][j-1]:
dp[i][j] = min(dp[i-1][j],dp[i][j-1])+1
elif L[i][j]!=L[i-1][j]:
dp[i][j] = min(dp[i-1][j]+1,dp[i][j-1])
elif L[i][j]!=L[i][j-1]:
dp[i][j] = min(dp[i-1][j],dp[i][j-1]+1)
else:
dp[i][j] = min(dp[i-1][j],dp[i][j-1])
if L[0][0]=='.':
ans = (dp[H-1][W-1]+1)//2
else:
ans = (dp[H-1][W-1]+2)//2
print(ans)
|
n, m = map(int, input().split())
total = sum(list(map(int, input().split())))
if n - total >= 0:
print(n-total)
else:
print("-1")
| 0 | null | 40,415,780,417,520 | 194 | 168 |
from math import sqrt, log
def factor(number):
i = 2
s = set()
while i * i <= number:
if number % i == 0:
if i != 2:
s.add(i)
if (number // i) != 2:
s.add(number//i)
i += 1
return s
def newFactor(number):
n = number
i = 2
ans = set()
while i * i <= number:
if number % i == 0:
while number % i == 0:
number //= i
if number % i == 1:
ans.add(i)
number = n
i += 1
return ans
n = int(input())
if n == 2:
print(1)
exit()
if n == 3:
print(2)
exit()
s = set()
s.add(2)
s.add(n-1)
s.add(n)
s = s.union(factor(n-1))
s = s.union(newFactor(n))
print(len(s))
|
s =int(list(input())[-1])
if s in [2,4,5,7,9]:print('hon')
elif s in [0,1,6,8]:print('pon')
else:print('bon')
| 0 | null | 30,306,024,745,990 | 183 | 142 |
N = input()
K = int(input())
def solve(N, K):
l = len(N)
dp = [[[0] * (10) for i in range(2)] for _ in range(l+1)]
dp[0][0][0] = 1
for i in range(l):
D = int(N[i])
for j in range(2):
for k in range(K+1):
for d in range(10):
if j == 0 and d > D: break
dp[i+1][j or (d < D)][k if d == 0 else k+1] += dp[i][j][k]
return dp[l][0][K] + dp[l][1][K]
print(solve(N,K))
|
N=input()
K=int(input())
l=len(N)
dp=[[[0]*(K+2) for _ in range(2)] for _ in range(l+1)]
dp[0][1][0]=1
for i,c in enumerate(N):
x=int(c)
for j in range(2):
for d in range(x+1 if j==1 else 10):
for k in range(K+1):
dp[i+1][x==d if j==1 else 0][k+1 if 0<d else k]+=dp[i][j][k]
print(dp[l][0][K]+dp[l][1][K])
| 1 | 75,798,858,973,340 | null | 224 | 224 |
import sys
def GcdLCM():
for line in sys.stdin:
x,y=map(int,line.split())
if x==None:
break
gcd = Gcd(x,y)
lcm = int(x*y/gcd)
print("{} {}".format(gcd,lcm))
def Gcd(x,y):
while x!=0:
x,y=y%x,x
return y
GcdLCM()
|
s = input()
t = ""
for _ in range(len(s)):
t += "x"
print(t)
| 0 | null | 36,432,962,016,412 | 5 | 221 |
import sys
L = sys.stdin.readlines()
for line in L:
N = line[:-1].split(' ')
sums = int(N[0]) + int(N[1])
print(len(str(sums)))
|
import sys
from operator import add
from math import log10
for i in sys.stdin:
print(int(log10(add(*list(map(int, i.split()))))) + 1)
| 1 | 108,041,120 | null | 3 | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.