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
|
---|---|---|---|---|---|---|
import sys
input = sys.stdin.readline
S=tuple(input().strip())
N=len(S)+1
sets = []
count = 0
for c in S:
d = 1 if c == '<' else -1
if count * d < 0:
sets.append(count)
count = d
else:
count += d
sets.append(count)
sum = 0
for i in range(len(sets)):
k=sets[i]
if k > 0:
sum += (k*(k+1))//2
else:
sum += (k*(k-1))//2
if i > 0:
sum -= min(sets[i-1], -k)
print(sum)
| s = input()
de_num = 0
le_num = 0
ans = [0]*(len(s)+1)
for i in range(len(s)):
if s[i] == "<":
de_num += 1
else:
de_num = 0
ans[i+1] = de_num
s = s[::-1]
ans.reverse()
for i in range(len(s)):
if s[i] == ">":
le_num += 1
else:
le_num = 0
ans[i+1] = max(le_num,ans[i+1])
print(sum(ans)) | 1 | 156,564,780,537,088 | null | 285 | 285 |
list =input().split()
list = [int(i) for i in list]
D=list[0]
S=list[1]
T=list[2]
if(D/S<=T):
print("Yes")
else:
print("No") | r = int(input())
print(2*r*3.1415926535) | 0 | null | 17,582,965,032,932 | 81 | 167 |
N, A, B = [int(x) for x in input().split()]
n = N//(A+B)
ans = n * A
d = N - n*(A+B)
if d >= A:
ans += A
else:
ans += d
print(ans) | from collections import deque
from collections import defaultdict
n = int(input())
graph = defaultdict(list)
for i in range(n):
u, k, *v = map(int, input().split())
for v in v:
graph[u].append(v)
ans = [-1] * (n + 1)
q = deque([1])
ans[1] = 0
while q:
c = q.popleft()
for v in graph[c]:
if ans[v] == -1:
ans[v] = ans[c] + 1
q.append(v)
for i in range(1, n + 1):
print(i, ans[i])
| 0 | null | 27,723,955,765,478 | 202 | 9 |
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(M):
a,b = map(int, input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
from collections import deque
def solve():
prev = [-1]*N
prev[0]='Yes'
d = deque([(0,0)])
while len(d):
v,cnt = d.popleft()
for u in edge[v]:
if prev[u]==-1:
prev[u]=v+1
d.append((u,cnt+1))
if -1 in prev:
return ['No']
return prev
print(*solve(),sep='\n')
| N, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
result = 0
mod = 10**9+7
def cmb(n, r, mod=mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
n = 10**5+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, n+1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
if k==1:
print(0)
else:
result = 0
for i in range(N-k+1):
result += (a[N-i-1]-a[i])*cmb(N-1-i, k-1)
result %= mod
print(result%mod) | 0 | null | 57,984,451,595,392 | 145 | 242 |
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
n = int(input())
C = input()
C_cunt = Counter(C)
cunt_r = C_cunt['R']
ans = 0
for i in range(cunt_r):
if C[i] == 'W':
ans += 1
print(ans)
if __name__=='__main__':
main() | def main():
N = int(input())
C = list(input())
C_ = sorted(C)
wr = rw = 0
for i in range(len(C_)):
if C[i] != C_[i]:
if C[i] == "R" and C_[i] == "W":
rw += 1
else:
wr += 1
print(max(wr, rw))
if __name__ == "__main__":
main() | 1 | 6,293,238,117,474 | null | 98 | 98 |
import sys
def solve():
input = sys.stdin.readline
A, B = map(int, input().split())
if A < 10 and B < 10: print(A * B)
else: print(-1)
return 0
if __name__ == "__main__":
solve() | import itertools
#h,w=map(int,input().split())
#S=[list(map(int,input().split())) for _ in range(h)]
n=int(input())
A=list(map(int,input().split()))
Ar=list(itertools.accumulate(A))
ans=0
for i in range(n-1):
ans+=A[i]*(Ar[n-1]-Ar[i])
ans%=10**9+7
print(ans)
| 0 | null | 81,341,165,064,188 | 286 | 83 |
from collections import deque
N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
a,b = map(int, input().split())
E[a-1].append(b-1)
E[b-1].append(a-1)
used = [-1]*N
for i in range(N):
if used[i] >= 0:
continue
q = deque()
q.append(i)
used[i] = i
while q:
temp = q.popleft()
for e in E[temp]:
if used[e] == i:
continue
used[e] = i
q.append(e)
L = [0]*N
for c in used:
L[c] += 1
ans = max(L)
print(ans) | class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0] * (n+1)
self.size = [1] * (n+1)
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.par[x] = y
self.size[y] += self.size[x]
else:
self.par[y] = x
self.size[x] += self.size[y]
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
n,m = map(int,input().split())
uf = UnionFind(n)
for i in range(m):
a,b = map(int,input().split())
uf.union(a,b)
print(max(uf.size)) | 1 | 3,992,666,184,470 | null | 84 | 84 |
def main():
n = input()
A = []
for i in xrange(n):
A.append(map(int,raw_input().split()))
c,d = bfs(n,A)
for i in xrange(n):
if c[i] == -1:
print i+1, -1
else:
print i+1, d[i]
def bfs(n,A):
color = [-1]*n
d = [-1]*n
Q = []
d[0] = 0
Q.append(0)
while(True):
if len(Q)==0:
break
u = Q.pop(0)
for i in A[u][2:]:
if color[i-1] == -1:
color[i-1] = 0
d[i-1] = d[u]+1
Q.append(i-1)
color[u] = 1
return color, d
if __name__ == '__main__':
main() | n,a,b = map(int,input().split())
if (a % 2 + b % 2) % 2 == 0:
print(abs(a - b) // 2)
exit(0)
if n - b < a - 1:
p = n - b + 1
a += n - b
b = n
print(abs(a - b) // 2 + p)
else:
p = a - 1 + 1
b -= a - 1
a = 1
print(abs(a - b) // 2 + p) | 0 | null | 54,597,181,236,052 | 9 | 253 |
import math
n = int(input())
print(math.floor(n / 2) - (1-n%2)) | A1,A2,A3=map(int,input().split())
total=A1+A2+A3
if total>=22:
print('bust')
else:
print('win') | 0 | null | 136,361,846,784,788 | 283 | 260 |
import sys
readline = sys.stdin.buffer.readline
n,t = map(int,readline().split())
dp = [0]*(t+1)
AB = [list(map(int,readline().split())) for i in range(n)]
AB.sort(reverse=True)
for i in range(n):
a,b = AB[i]
for j in range(t):
if j+a > t:
dp[j] = max(dp[j],b)
else:
dp[j] = max(dp[j],dp[j+a]+b)
print(dp[0]) | k = int(input())
a, b = map(int, input().split(" "))
ngflag = True
while(a <= b):
if a % k == 0:
print("OK")
ngflag = False
break
a += 1
if ngflag:
print("NG")
| 0 | null | 89,269,282,670,246 | 282 | 158 |
w=raw_input().lower()
c=0
while 1:
t=map(str,raw_input().split())
if t[0]=="END_OF_TEXT":
break
for i in range(len(t)):
if t[i].lower()==w:
c+=1
print c | N = int(input())
z = []
w = []
for i in range(N):
x,y = map(int,input().split())
z.append(x+y)
w.append(x-y)
z_max = max(z)
z_min = min(z)
w_max = max(w)
w_min = min(w)
print(max(z_max-z_min,w_max-w_min)) | 0 | null | 2,606,091,211,328 | 65 | 80 |
n, a, b = map(int, input().split())
lm = min(n, 2*10**5)
# ①nCrの各項のmod(10^9+7)を事前計算
p = 10 ** 9 + 7
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, lm + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
# ②事前計算した項を掛け合わせ
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
rt = 1
for i in range(r):
rt = (rt * (n-i)) % p
rt = rt*factinv[r] % p
return rt
def pow_r(x, n, p):
"""
O(log n)
"""
if n == 0: # exit case
return 1
if n % 2 == 0: # standard case ① n is even
return pow_r(x ** 2 % p, n // 2, p)
else: # standard case ② n is odd
return x * pow_r(x ** 2 % p, (n - 1) // 2, p) % p
rlt = pow_r(2,n,p)
rlt -= 1
rlt -= cmb(n,a,p) % p
rlt -= cmb(n,b,p) % p
while rlt < 0:
rlt += p
print(rlt) | n, a, b = map(int, input().split())
mod = 10**9+7
ans = pow(2, n, mod)-1
def choose(n, r):
res = 1
fac = 1
for i in range(r):
res *= n-i
res %= mod
fac *= i+1
fac %= mod
return res*pow(fac, mod-2, mod)%mod
ans -= choose(n, a)
ans -= choose(n, b)
print(ans%mod) | 1 | 66,130,792,165,210 | null | 214 | 214 |
A,B=map(int,input().split())
for x in range(1,1001):
if A==int(x*0.08) and B==int(x*0.1):
print(x)
break
elif x==1000:
print(-1)
| while 1:
w=raw_input()
if w=='-': break
n=int(raw_input())
for i in range(n):
l=int(raw_input())
w=w[l:]+w[:l]
print w | 0 | null | 29,212,392,717,298 | 203 | 66 |
# 入力
InpList=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
result=0
# 処理
print(InpList[K-1]) |
def main():
params = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
return params[int(input())-1]
print(main()) | 1 | 50,181,668,535,120 | null | 195 | 195 |
nm = raw_input().split()
n = int(nm[0])
m = int(nm[1])
d = raw_input().split()
c = [0] * 100000
c[0] = 0
for i in range(n):
min = 100000
for j in range(m):
if int(d[j]) < i + 2:
x = c[i + 1 - int(d[j])]
if x < min:
min = x
c[i + 1] = min + 1
print c[n] | import sys
argvs = sys.argv
for x in sys.stdin:
print str(int(x)**3) | 0 | null | 204,730,226,498 | 28 | 35 |
n = int(input())
a = n // 2
b = n % 2
print(a+b)
| # B
a, b, c, d = list(map(int, input().split(" ")))
numlist = [a*c, a*d, b*c, b*d]
maxnum = max(numlist)
print(maxnum) | 0 | null | 31,069,583,267,140 | 206 | 77 |
def check(P):
global k, T, n
i = 0
for j in range(k):
s = 0
while s + T[i] <= P:
s += T[i]
i += 1
if (i == n):
return n
return i
def solve():
left = 0
right = 100000 * 10000
while right - left > 1:
mid = (left + right) // 2
v = check(mid)
if (v >= n):
right = mid
else:
left = mid
return right
if __name__ == '__main__':
n, k = map(int, input().split())
T = [int(input()) for i in range(n)]
ans = solve()
print(ans) | n, k = [int(_) for _ in input().split()]
ary = [int(input()) for _ in range(n)]
def search_v(p):
v = 0
w = 0
tmp_k = 1
ind = 0
while True:
if tmp_k > k:
return v
if ind == n:
return n
tmp = ary[ind]
if w + tmp <= p:
w += tmp
v += 1
ind += 1
else:
w = 0
tmp_k += 1
max_p = n * 10000
ps = range(max_p + 1)
left = 0
right = max_p
while left + 1 < right:
mid = (left + right) // 2
v = search_v(ps[mid])
if v >= n:
right = mid
else:
left = mid
print(ps[right])
| 1 | 85,208,743,730 | null | 24 | 24 |
a, b = map(int, input().split())
c =1
if b > a:
a, b = b, a
while c != 0:
c = a % b
a = b
b = c
print(a) | def cgd(x,y):
while(True):
r=x%y
if r==0:
m=y
break
x=y
y=r
return m
a,b=map(int,input().split())
if a>b:
m=cgd(a,b)
elif a<b:
m=cgd(b,a)
else:
m=a
print(m)
| 1 | 7,721,204,758 | null | 11 | 11 |
X,K,D = map(int,input().split())
y = abs(X)//D
if K<=y:
print(abs(abs(X)-K*D))
else :
a = (abs(X)-y*D)
b = (abs(X)-(y+1)*D)
C = abs(a)
D = abs(b)
if (K-y)%2==0:
print(C)
else:
print(D)
#print(y+1)
#print(1000000000000000) | x,k,d=map(int,input().split())
x=abs(x)
if k>=round(x/d):
if (k-round(x/d))%2==0:
print(abs(x-d*round(x/d)))
else:
print(d-abs(x-d*round(x/d)))
else:
print(x-d*k) | 1 | 5,215,211,670,120 | null | 92 | 92 |
def pc(x):
return format(x, 'b').count('1')
N = int(input())
X = input()
Xo = int(X, 2)
count = 0
ans = 0
ori = pc(Xo)
X = list(X)
Xp = Xo%(ori + 1)
if ori == 1:
Xm = 0
else:
Xm = Xo % (ori - 1)
# for i in range(N-1, -1, -1):
for i in range(N):
if ori == 1 and X[i] == '1':
print(0)
continue
else:
if X[i] == '1':
# ans = Xm - pow(2, i, ori - 1)
ans = Xm - pow(2, N-1-i, ori - 1)
ans %= ori - 1
else:
# ans = Xp - pow(2, i, ori + 1)
ans = Xp + pow(2, N-1-i, ori + 1)
ans %= ori + 1
count = 1
while ans > 0:
# count += 1
# if ans == 1:
# break
ans %= pc(ans)
count += 1
print(count)
count = 1
| def solve():
N = int(input())
X = input()
X_10 = int(X,2)
r = X.count("1")
r0 = r-1
r1 = r+1
ans = []
s0 = X_10 % r0 if r != 1 else None
s1 = X_10 % r1
for i in range(N):
if X[i] == '0':
ans.append(f((s1 + pow(2,N-1-i,r1)) % r1))
else:
if r0 == 0:
ans.append(0)
else:
ans.append(f((s0 - pow(2,N-1-i,r0)) % r0))
print(*ans, sep='\n')
def f(N):
cnt = 1
while N != 0:
N = N % popcount(N)
cnt += 1
return cnt
def popcount(N):
b = bin(N)
cnt = 0
for i in range(2,len(b)):
if b[i] == '1':
cnt += 1
return cnt
if __name__ == '__main__':
solve() | 1 | 8,226,816,522,730 | null | 107 | 107 |
x, n = map(int, input().split())
if n == 0:
print(x)
else:
a = [int(x) for x in input().split()]
ans1 = x
while ans1 in a :
ans1 -= 1
ans2 = x
while ans2 in a :
ans2 += 1
if abs(x - ans1) <= abs(x - ans2):
print(ans1)
else:
print(ans2)
| x,n=map(int,input().split())
if n==0:
print(x)
exit()
p=list(map(int,input().split()))
p.sort()
t=0
while True:
if x-t in p and x+t in p:
t+=1
elif x-t in p and x+t not in p:
print(x+t)
exit()
elif x-t not in p:
print(x-t)
exit() | 1 | 14,110,521,099,032 | null | 128 | 128 |
a,b,c=map(int,input().split())
a1=b
b1=a
a2=c
c1=a1
print(a2, b1, c1) | input_lists = list(input().split(' '))
result = [input_lists[-1]]
result += input_lists[0:-1]
result = ' '.join(result)
print(result) | 1 | 37,889,068,342,788 | null | 178 | 178 |
n = int(input())
for x in range(1, 50005):
if x * 108//100 == n:
print(x)
exit()
else:
print(':(') | N = input()
if N.endswith('2') == True or N.endswith('4') == True or N.endswith('5') == True or N.endswith('7') == True or N.endswith('9') == True:
print('hon')
elif N.endswith('0') == True or N.endswith('1') == True or N.endswith('6') == True or N.endswith('8') == True:
print('pon')
else:
print('bon') | 0 | null | 72,387,360,088,472 | 265 | 142 |
# 163 B
N,M = list(map(int, input().split()))
A = list(map(int, input().split()))
print(N-sum(A)) if sum(A) <= N else print(-1) | n,m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
if n >= sum(a):
print(n - sum(a))
else:
print(-1) | 1 | 32,072,744,630,080 | null | 168 | 168 |
def LinearSearch1(S, n, t):
for i in range(n):
if S[i] == t:
return i
break
else:
return -1
"""
def LinearSearch2(S, n, t):
S.append(t)
i = 0
while S[i] != t:
i += 1
S.pop()
if i == n:
return -1
else:
return i
"""
n = int(input())
S = [int(s) for s in input().split()]
q = int(input())
T = {int(t) for t in input().split()}
ans = sum(LinearSearch1(S, n, t) >= 0 for t in T)
print(ans) | def selectionSort(A):
n = len(A)
cnt = 0
for i in range(n):
minj = i
for j in range(i,n):
if A[minj] > A[j]:
minj = j
if minj != i:
A[i], A[minj] = A[minj], A[i]
cnt += 1
print(*A)
print(cnt)
n = int(input())
A = list(map(int, input().split(" ")))
selectionSort(A)
| 0 | null | 43,563,228,420 | 22 | 15 |
import math
(a, b, C) = [float(i) for i in input().split()]
S = 0.5 * a * b * math.sin(math.radians(C))
c = math.sqrt(a * a + b * b - 2 * a * b * math.cos(math.radians(C)))
print("%8f" %(S))
print("%8f" %(a + b + c))
print("%8f" %(S / a * 2)) | N,P=map(int,input().split());S,a,i,j,c=input(),0,0,1,[1]+[0]*P
if 10%P:
for v in S[::-1]:i,j=(i+int(v)*j)%P,j*10%P;a+=c[i];c[i]+=1
else:
for v in S:
i+=1
if int(v)%P<1:a+=i
print(a) | 0 | null | 29,044,065,885,042 | 30 | 205 |
N = int(input())
b = list(map(int, input().split()))
MOD = 1000000007
sum_n = 0
a = []
for i in b:
a.append(i%MOD)
sum_sum = sum(a[1:])
for i in range(N):
sum_n = (sum_n + (a[i] * sum_sum) % MOD) % MOD
if i+1 < N:
sum_sum = sum_sum - a[i+1]
print(sum_n % MOD) | n,k = map(int, input().split())
scores = list(map(int, input().split()))
for i in range(k, n):
a = scores[i]
b = scores[i-k]
if a > b:
print('Yes')
else:
print('No') | 0 | null | 5,473,441,968,972 | 83 | 102 |
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
N, M = map(int, readline().split())
C = list(map(int, readline().split()))
# dp[i] := i円払うのに必要な枚数
dp = [INF] * (N+1)
dp[0] = 0
for c in C:
if c<=N:
for i in range(N-c+1):
dp[i+c] = min(dp[i]+1, dp[i+c])
print(dp[N])
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import collections as cl
import sys
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()))
MOD = 10 ** 9 + 7
def main():
N = II()
targets = LI()
colors = [0] * 3
ans = 1
for i in range(N):
count = 0
for k in range(3):
if colors[k] == targets[i]:
if count == 0:
colors[k] += 1
count += 1
ans *= count
ans %= MOD
print(ans)
main()
| 0 | null | 64,833,131,692,500 | 28 | 268 |
#!/usr/bin/env python
def solve(A: int, B: int, C: int, K: int):
if A >= K:
return K
K -= A
if B >= K:
return A
K -= B
return A - K
def main():
A, B, C, K = map(int, input().split())
answer = solve(A, B, C, K)
print(answer)
if __name__ == "__main__":
main()
| a,b,c,k=map(int,input().split())
if k<=a:
ans=k
elif k>a and k<=a+b:
ans=a
else:
ans=a-(k-(a+b))
print(ans) | 1 | 21,712,523,826,640 | null | 148 | 148 |
s=input()
print("A" if s.upper()==s else "a") | import sys
import math
import numpy as np
import copy
def dfs(now, group, groups, edges):
if groups[now] != -1:
return 0
groups[now] = group
cnt = 1
for to in edges[now]:
cnt += dfs(to, group, groups, edges)
return cnt
def main():
n, m, k = map(int, input().split())
edges = [list() for i in range(n)]
ngs = [list() for i in range(n)]
for i in range(m):
a, b = map(int, input().split())
a, b = a-1, b-1
edges[a].append(b)
edges[b].append(a)
for i in range(k):
c, d = map(int, input().split())
c, d = c-1, d-1
ngs[c].append(d)
ngs[d].append(c)
cnt = 0
groups = [-1 for i in range(n)]
nodes_cnt = list()
ans = [0 for i in range(n)]
for i in range(n):
if groups[i] == -1:
nodes_cnt.append(dfs(i, cnt, groups, edges))
cnt += 1
ans[i] = nodes_cnt[groups[i]] - len(edges[i]) - 1
for ng in ngs[i]:
if groups[i] == groups[ng]:
ans[i] -= 1
print(*ans, sep=" ")
if __name__ == '__main__':
sys.setrecursionlimit(1000000)
sys.exit(main()) | 0 | null | 36,428,994,151,198 | 119 | 209 |
N, M = map(int, input().split())
H = [int(x) for x in input().split()]
adj = [0] * N
good = [1]*N
for j in range(N):
adj[j] = set()
for k in range(M):
A, B = map(int, input().split())
if H[A - 1] >= H[B - 1]:
good[B - 1] = 0
if H[A - 1] <= H[B - 1]:
good[A - 1] = 0
print(sum(good))
| n,m = list(map(int, input("").split()))
h = list(map(int, input("").split()))
p = [1] * n
for i in range(m):
a,b = map(int, input().split())
if h[a-1] <= h[b-1]:
p[a-1]=0
if h[a-1] >= h[b-1]:
p[b-1]=0
print(sum(p)) | 1 | 24,980,804,392,788 | null | 155 | 155 |
n, k = map(int, input().split())
mod = 10 ** 9 + 7
dp = [0] * (k + 1)
ans = 0
for i in range(k, 0, -1):
num = k // i
dp[i] += pow(num, n, mod)
for j in range(1, num):
dp[i] -= dp[(j + 1) * i]
ans += i * dp[i]
ans %= mod
print(ans)
| N = int(input())
L = [[int(l) for l in input().split()] for _ in range(N)]
L1 = [0]*N
L2 = [0]*N
for i in range(N):
L1[i] = L[i][0]+L[i][1]
L2[i] = L[i][0]-L[i][1]
L1.sort()
L2.sort()
print(max(L1[-1]-L1[0], L2[-1]-L2[0])) | 0 | null | 20,124,251,567,850 | 176 | 80 |
k = int(input())
acl = "ACL"
print(acl*k) |
def resolve():
H, W, K = map(int, input().split())
G = [list(input()) for _ in range(H)]
ans = [[0] * W for _ in range(H)]
cnt, first = 1, -1
for i in range(H):
tmp = 0
if "#" in G[i]:
if first == -1:
first = i
for j in range(W):
if G[i][j] == "#":
tmp += 1
if tmp > 1:
cnt += 1
ans[i][j] = cnt
cnt += 1
else:
if i > 0:
ans[i] = ans[i - 1][:]
for q in range(first):
ans[q] = ans[first][:]
for i in range(H):
print(*ans[i])
if __name__ == "__main__":
resolve()
| 0 | null | 73,269,933,065,770 | 69 | 277 |
import math
a, b, x = map(int, input().split(' '))
base = a * a * b /2
if int(base) == x:
print(math.degrees(math.atan(b/a)))
elif base > x:
ah = 2 * x / (a * b)
print(math.degrees(math.atan(b/ah)))
else:
bh = 2 * x / a ** 2 - b
c = b - bh
print(math.degrees(math.atan(c/a)))
| #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
n = I()
def yaku(m):
ans = []
i = 1
while i*i <= m:
if m % i == 0:
j = m // i
ans.append(i)
i += 1
ans = sorted(ans)
return ans
a = yaku(n)
#print(a)
ans = float('inf')
for v in a:
ans = min(ans, (v-1)+(n//v)-1)
print(ans)
| 0 | null | 162,259,120,300,508 | 289 | 288 |
#!/usr/bin/env python
contents = []
counter = 0
word = input()
while True:
text = input()
if text == "END_OF_TEXT":
break
textWords = text.split()
contents.append(textWords)
for x in contents:
for y in x:
if y.lower() == word:
counter += 1
print(counter) | S = input()
if S == 'MON':
print("6")
elif S == 'TUE':
print("5")
elif S == 'WED':
print("4")
elif S == 'THU':
print("3")
elif S == 'FRI':
print("2")
elif S == 'SAT':
print("1")
elif S == 'SUN':
print("7")
| 0 | null | 67,299,037,052,572 | 65 | 270 |
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
c = [1 if _ == 'R' else 0 for _ in input()]
b = sum(c)
w=0
r=0
for i in range(n):
if c[i] == 0 and i < b:
r+=1
if c[i] == 1 and i >= b:
w+=1
print(max(w,r))
| def main():
n = int(input())
c = input()
r = 0
for i in range(n):
if c[i]=='R':
r += 1
ans = 0
for i in range(r):
if c[i]=='W':
ans += 1
print(ans)
if __name__ == "__main__":
main()
| 1 | 6,266,590,385,948 | null | 98 | 98 |
x = list(map(int, input().split()))
for i in range(len(x)):
if x[i] is 0:
print(i+1)
| nums = list(map(int, input().split()))
print(nums.index(0)+1) | 1 | 13,391,395,322,432 | null | 126 | 126 |
print((int(input())+1)//2-1) | def solve(n):
return (n - 1) // 2
assert solve(4) == 1
assert solve(999999) == 499999
n = int(input())
print(solve(n)) | 1 | 153,331,009,337,622 | null | 283 | 283 |
def is_prime(x):
if x == 2:
return True
if x < 2 or x % 2 == 0:
return False
i = 3
while i * i <= x:
if x % i == 0:
return False
i += 2
return True
n = int(raw_input())
ans = 0
for i in range(n):
x = int(raw_input())
if (is_prime(x)):
ans += 1
print ans | def isPrime(n):
if (n == 1): return False
if (n == 2): return True
if (0 == n % 2) : return False
i = 2
while(n >= i * i):
if (0 == n % i): return False
i += 1
return True
def main():
c = 0
n = input()
for i in range(n):
if (isPrime(input())):
c += 1
print(c)
main() | 1 | 9,123,939,220 | null | 12 | 12 |
#import numpy as np
#def area--------------------------#
#ryouno syokiti
class ryou:
def flinit(self):
room=list()
for i in range(10):
room+=[0]
return room
#def kaijo([a_1,a_2,a_3,a_4,a_5,a_6,a_7,a_8,a_9,a_10]):
#def kaijo(x):
# y=[]
# for i in x:
# y=y+ " "+x[i]
# return y
def kaijo(x):
print "",
for i in range(len(x)-1):
print str(x[i]),
print str(x[len(x)-1])
#----------------------------------#
floor_11=ryou().flinit()
floor_12=ryou().flinit()
floor_13=ryou().flinit()
floor_21=ryou().flinit()
floor_22=ryou().flinit()
floor_23=ryou().flinit()
floor_31=ryou().flinit()
floor_32=ryou().flinit()
floor_33=ryou().flinit()
floor_41=ryou().flinit()
floor_42=ryou().flinit()
floor_43=ryou().flinit()
fldic={"11":floor_11,
"12":floor_12,
"13":floor_13,
"21":floor_21,
"22":floor_22,
"23":floor_23,
"31":floor_31,
"32":floor_32,
"33":floor_33,
"41":floor_41,
"42":floor_42,
"43":floor_43
}
#----------------------------------#
#1kaime yomikomi
n=int(raw_input())
#nkaime syusyori
for l in range(n):
list_mojiretsu=raw_input().split(" ")
henka=map(int,list_mojiretsu)
fldic[str(henka[0])+str(henka[1])][henka[2]-1]+=henka[3]
kaijo(floor_11)
kaijo(floor_12)
kaijo(floor_13)
print "####################"
kaijo(floor_21)
kaijo(floor_22)
kaijo(floor_23)
print "####################"
kaijo(floor_31)
kaijo(floor_32)
kaijo(floor_33)
print "####################"
kaijo(floor_41)
kaijo(floor_42)
kaijo(floor_43) | def main():
L, R, d = map(int, input().split(' '))
total = 0
for i in range(L, R + 1):
if i % d == 0:
total += 1
print(total)
main() | 0 | null | 4,331,324,170,950 | 55 | 104 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
S = input()
p = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
print(7 - p.index(S))
if __name__ == '__main__':
main()
| s = input()
if s=='hi' or s=='hihi' or s=='hihihi' or s=='hihihihi' or s=='hihihihihi' :
print("Yes")
else:
print("No") | 0 | null | 92,896,381,279,702 | 270 | 199 |
N, K = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
done = [-1]*N
done[0] = 0
tmp = 0
done[0] = 0
for k in range(1, K + 1):
tmp = A[tmp]
if done[tmp] >= 0:
for _ in range((K - done[tmp]) % (k - done[tmp])):
tmp = A[tmp]
print(tmp + 1)
exit()
else:
done[tmp] = k
print(tmp + 1) | N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
k = int((10**9 + 8)/2)
sum = 0
sum_1 = 0
for i in range(N):
sum += A[i]
sum = (sum**2)%mod
for j in range(N):
sum_1 += A[j]**2
sum_1 = (sum_1)%mod
ans = sum - sum_1
ans = (ans*k)%mod
print(ans)
| 0 | null | 13,380,334,761,920 | 150 | 83 |
n = int(input())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
#divisors.sort()
return divisors
d1 = make_divisors(n)
d2 = make_divisors(n-1)
ans = 0
for k in d1:
if k == 1:
continue
temp = n
while temp%k == 0:
temp //= k
if temp%k == 1:
ans += 1
ans += len(d2)-1
print(ans)
| def get_divisors(n):
"""
引数の数字の約数を列挙し、setで返します。1および引数自身を含みます。
計算量はO(log(n))です。
"""
divisors = set()
i = 1
while i * i <= n:
if n % i == 0:
divisors.add(i)
divisors.add(n // i)
i += 1
return divisors
n = int(input())
n_ = get_divisors(n)
n_1 = get_divisors(n - 1)
n_.remove(1)
n_1.remove(1)
n_.difference_update(n_1)
# print(n_)
# print(n_1)
# print(n_.difference(n_1))
ans = len(n_1)
for cand in n_:
if cand == 2 or cand == n:
ans += 1
continue
tmp = n
while tmp % cand == 0:
tmp //= cand
tmp %= cand
if tmp == 1:
ans += 1
print(ans)
| 1 | 41,370,254,470,622 | null | 183 | 183 |
# ABC155E
s = input()
d0 = [0,1,2,3,4,5,6,7,8,9]
d1 = [0,1,2,3,4,5,5,4,3,2] # 通常時
a0 = d1[int(s[0])]
a1 = d1[int(s[0]) + 1] if int(s[0])<=8 else 1
for c in s[1:]:
c = int(c)
b0 = min(a0 + c, a1 + (10 - c))
b1 = min(a0 + c + 1, a1 + (9 - c)) if c <=8 else a1
a0, a1 = b0, b1
print(a0) | # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(H, N, AB):
INF = 10**9
dp = [INF] * (H + 1)
dp[H] = 0
for h in reversed(range(H + 1)):
for i, (a, b) in enumerate(AB):
nh = max(0, h - a)
dp[nh] = min(dp[nh], dp[h] + b)
print(dp[0])
if __name__ == '__main__':
input = sys.stdin.readline
H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
main(H, N, AB)
| 0 | null | 75,620,889,908,740 | 219 | 229 |
number=list(map(int,input().split()))
n,m=number[0],number[1]
height=list(map(int,input().split()))
load=[[] for i in range(n+1)]
for i in range(m):
tmp=list(map(int,input().split()))
if tmp[1] not in load[tmp[0]]:
load[tmp[0]].append(tmp[1])
if tmp[0] not in load[tmp[1]]:
load[tmp[1]].append(tmp[0])
box=[]
answer=0
for i in range(1,n+1):
box=[]
if len(load[i])==0:
answer+=1
for j in range(len(load[i])):
box.append(height[load[i][j]-1])
if box!=[]:
if max(box)<height[i-1]:
answer+=1
print(answer) | N, M = map(int, input().split())
H = list(map(int, input().split()))
table = []
for i in range(N):
table.append(set())
for i in range(M):
Ai, Bi = map(lambda x: x - 1, map(int, input().split()))
table[Ai].add(Bi)
table[Bi].add(Ai)
answer = 0
for i, h in enumerate(H):
highest = True
for path in table[i]:
if h <= H[path]:
highest = False
if highest:
answer += 1
print(answer)
| 1 | 25,009,932,438,684 | null | 155 | 155 |
# AtCoder Beginner Contest 146
# E - Rem of Sum is Num
# https://atcoder.jp/contests/abc146/tasks/abc146_e
from collections import defaultdict
N, K = map(int, input().split())
*A, = map(int, input().split())
A = [0]+A
d = []
c = defaultdict(int)
x = 0
ans = 0
for i, a in enumerate(A):
x += a - 1
x %= K
d.append(x)
if i-K >= 0:
c[d[i-K]] -= 1
ans += c[x]
c[x] += 1
print(ans) | count = int(input())
line = input().split()
line.reverse()
for i in range(count):
print(line[i], end = "")
if i != count-1:
print(" ", end = "")
print()
| 0 | null | 69,110,129,710,938 | 273 | 53 |
def main():
N = int(input())
print(IsPrime(N))
def IsPrime(N):
count = 0
for i in range(N):
inputNum = int(input())
if(inputNum == 2):
count += 1
continue
elif(inputNum % 2 == 0):
continue
flag = 0
for j in range(3, int(pow(inputNum, 1/2))+1):
if(inputNum % j == 0):
flag = 1
break
else:
continue
if(flag == 0):
count += 1
return count
if __name__ == '__main__':
main() | def is_prime(x):
if x == 2:
return True
if (x < 2) or (x%2 == 0):
return False
return all(x%i for i in xrange(3, int(x**(0.5) + 1), 2))
N = input()
print sum(is_prime(input()) for i in range(N)) | 1 | 10,277,015,882 | null | 12 | 12 |
n = int(input())
arm = []
for i in range(n):
x , l = map(int,input().split())
arm.append([x,l])
arm.sort()
dp = [[0,0] for i in range(n)]
dp[0][1] = arm[0][0] + arm[0][1]
for i in range(1,n):
if dp[i-1][1] <= arm[i][0] -arm[i][1]:
dp[i][0] = dp[i-1][0]
dp[i][1] = arm[i][0] + arm[i][1]
else:
dp[i][0] = dp[i-1][0] + 1
dp[i][1] = min(arm[i][0] + arm[i][1],dp[i-1][1])
print(n-dp[n-1][0]) | import math
from collections import deque
def main():
t = [int(t)for t in input().split()]
x,y = t[0],t[1]
earned = 0
if x == 1:
earned += 300000
elif x == 2:
earned += 200000
elif x == 3:
earned += 100000
if y == 1:
earned += 300000
elif y == 2:
earned += 200000
elif y == 3:
earned += 100000
if x == y and x == 1:
earned += 400000
print(earned)
if __name__ == "__main__":
main() | 0 | null | 114,933,627,635,750 | 237 | 275 |
# coding: utf-8
x=int(input())
i=1
while x!=0:
print("Case "+str(i)+": "+str(x))
x=int(input())
i+=1 | def gcd(a,b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a,b):
return (a*b) / gcd(a,b)
if __name__ == "__main__":
n1,n2=map(int,input().split(' '))
print(int(lcm(n1,n2))) | 0 | null | 56,704,294,637,438 | 42 | 256 |
x = int(input())
balance = 100
cnt = 0
while balance < x:
balance += int(balance//100)
cnt += 1
print(cnt) | X = int(input())
ASSET = 100
cnt = 0
while ASSET < X:
ASSET += ASSET // 100
cnt += 1
print(cnt) | 1 | 27,273,045,748,718 | null | 159 | 159 |
a, b, c, d = map(int, input().split())
ac = a * c
ad = a * d
bc = b * c
bd = b * d
max_a = max(ac, ad)
max_b = max(bc, bd)
print(max(max_a, max_b))
| l = list(map(int, input().split()))
r = []
for i in range(0, 2, 1):
for j in range(2, 4, 1):
r.append(l[i] * l[j])
print(max(r)) | 1 | 3,085,632,155,390 | null | 77 | 77 |
A,B,M=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
answer=min(alist)+min(blist)
for _ in range(M):
x,y,c=map(int,input().split())
disc=alist[x-1]+blist[y-1]-c
answer=min(answer,disc)
print(answer) | S = input()
n = len(S) + 1
A = []
mini = 0
for i in range(n-1):
if i==0:
if S[i]=="<":
A.append([1,0])
else:
A.append([0,1])
else:
if S[i]=="<" and S[i-1]==">":
A.append([1,0])
elif S[i]=="<":
A[-1][0] += 1
else:
A[-1][1] += 1
summ = 0
for x in A:
ma = max(x)
mi = min(x)
summ += (ma+1)*ma//2
summ += (mi-1)*mi//2
print(summ) | 0 | null | 105,158,497,779,970 | 200 | 285 |
n = int(input())
a = list(map(int,input().split()))
tl = [0 for i in range(n)]
for i in range(n):
tl[a[i] -1] = str(i+1)
print(' '.join(tl)) | n = map(int, input().split())
a = list(map(int, input().split()))
arr = [(x, i + 1) for i, x in enumerate(a)]
arr.sort()
ans = [x[1] for x in arr]
print(*ans) | 1 | 180,808,401,047,044 | null | 299 | 299 |
A,B,C,K=map(int,input().split())
if A>=K:
print(K)
elif B>=K-A:
print(A)
else:
print(A-1*(K-A-B))
| a, b, c, k = map(int, input().split())
ans = 0
if k <= a:
ans = k
elif k <= a+b:
ans = a
else:
ans = 2*a +b - k
print(ans) | 1 | 21,747,941,972,938 | null | 148 | 148 |
s = input()
p = input()
s = s + s
if p in s:
print('Yes')
else:
print('No')
| s = input()
p = input()
s = s+s
if s.find(p) < 0:
print('No')
else:
print('Yes')
| 1 | 1,722,893,571,740 | null | 64 | 64 |
while True:
data = input()
if(data == "-"):break
m = int(input())
tmp = []
for i in range(m):
num = int(input())
if(len(tmp) == 0):
tmp = data[num:] + data[:num]
data = ""
else:
data = tmp[num:] + tmp[:num]
tmp = ""
if(data): print(data)
else: print(tmp)
| while 1:
S = raw_input()
if (S == '-'):
break
N = input()
for i in range(N):
h = input()
S = S[h : len(S)] + S[0 : h]
print S
| 1 | 1,893,355,941,060 | null | 66 | 66 |
N = int(input())
A = list(map(int, input().split()))
mon = 1000
kabu = 0
for i in range(N-1):
if A[i] <= A[i+1]:
kabu, mon = divmod(mon, A[i])
mon += kabu * A[i+1]
print(mon) | N = int(input(""))
a = input("").split(" ")
a = [int(i) for i in a]
m = 1000
list_ = []
for j in range(0, N-1):
if a[j] < a[j + 1]:
n = m // a[j]
k = (a[j + 1] - a[j]) * n
m = m + k
print(m) | 1 | 7,376,648,649,968 | null | 103 | 103 |
from collections import deque
n, x, y = map(int, input().split())
a = []
for i in range(1, n + 1):
if i == 1:
a.append([2])
elif i == n:
a.append([n - 1])
else:
a.append([i - 1, i + 1])
a[x - 1].append(y)
a[y - 1].append(x)
d = {}
for i in range(n - 1):
d[i + 1] = 0
def solve(s):
queue = deque()
queue.append(a[s - 1])
visit = set()
visit.add(s)
depth = 0
while queue:
depth += 1
nn = queue.popleft()
adj = []
for i in nn:
if i not in visit:
d[depth] += 1
adj = adj + a[i-1]
visit.add(i)
if adj != []:
queue.append(adj)
for i in range(n):
solve(i + 1)
for i in range(n - 1):
print(d[i + 1] // 2)
| N = int(input())
ST = []
for i in range(N):
X, L = map(int, input().split())
ST.append((X - L, X + L))
ST.sort(key=lambda x: x[1])
ans = 0
cur = -1e9
for i in range(N):
S, T = ST[i]
if cur <= S:
ans += 1
cur = T
print(ans)
| 0 | null | 66,809,617,013,338 | 187 | 237 |
def gcd (a,b):
if a%b==0:
return b
if b%a==0:
return a
if a>b:
return gcd(b,a%b)
return gcd(a,b%a)
def lcm (a,b):
return ((a*b)//gcd(a,b))
inp=list(map(int,input().split()))
a=inp[0]
b=inp[1]
print (lcm(a,b)) | A, B = map(int, input().split())
n = 1
while True:
A_ = A * n
if A_ % B == 0:
print(A_)
exit()
n += 1 | 1 | 113,680,356,887,452 | null | 256 | 256 |
import math
N, K = map(int,input().split())
logs = list(map(int,input().split()))
a = 0
b = max(logs)
b_memo = set()
count=0
flg =0
while b-a > 1:
c = (a+b)//2
times = []
for i in logs:
times.append(math.ceil(i/c)-1)
if sum(times) > K:
a = c
else:
b = c
print(b) | K, N = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
A.append(A[0]+K)
res = []
for i in range(N):
res.append(abs(A[i]-A[i+1]))
print(K - max(res)) | 0 | null | 25,045,292,113,088 | 99 | 186 |
from math import ceil
from bisect import bisect_right
n, d, a = map(int, input().split())
l = []
l2 = []
l3 = []
l4 = [0 for i in range(n+1)]
l5 = [0 for i in range(n+1)]
ans = 0
for i in range(n):
x, h = map(int, input().split())
l.append([x, h])
l2.append(x + 2 * d)
l3.append(x)
l.sort(key=lambda x: x[0])
l2.sort()
l3.sort()
for i in range(n):
cnt = ceil((l[i][1] - l4[i] * a) / a)
if cnt > 0:
ans += cnt
ind = bisect_right(l3, l2[i])
l5[ind] += cnt
l4[i] += cnt
l4[i+1] = l4[i] - l5[i+1]
print(ans) | a = map(int, raw_input().split())
j = 0
for i in xrange(a[0], a[1]+1):
j=j if a[2] % i else j+1
print j | 0 | null | 41,430,825,221,888 | 230 | 44 |
n=int(input())
I=list(map(int,input().split()))
for i in range(n):
if (I[i]%2==0):
if (I[i]%3!=0) and (I[i]%5!=0):
print("DENIED")
exit()
print("APPROVED")
| N = int(input())
A = list(map(int, input().split()))
answer = 'DENIED'
for i in range(0, N):
if A[i] % 2 == 0:
if A[i] % 3 == 0 or A[i] % 5 == 0:
answer = 'APPROVED'
else:
answer = 'DENIED'
break
else:
answer = 'APPROVED'
print(answer) | 1 | 68,938,901,225,318 | null | 217 | 217 |
n = int(input())
count = [0]*n
ans = 1
flag = True
for d in map(int,input().split()):
if flag:
if d!=0:
print(0)
exit()
flag = False
count[d] += 1
for i in range(1,n):
if count[0]!=1:
ans = 0
break
if count[i]==0:
if any(k!=0 for k in count[i:]):
ans = 0
break
ans *= (count[i-1]**count[i])%998244353
print(ans%998244353) | from sys import stdin
while True:
n, x = [int(x) for x in stdin.readline().rstrip().split()]
if n == 0 and x == 0:
break
else:
count = 0
for i in range(1, n-1):
for j in range(i+1, n):
if j < x-i-j <= n:
count += 1
else:
print(count)
| 0 | null | 77,878,001,722,572 | 284 | 58 |
from fractions import gcd
N=int(input())
d={}
#l=[]
MOD = 1000000007
nz=0
for _ in range(N):
a,b=map(int,input().split())
if a==0 and b==0:
nz+=1
#p=(0,0)
continue
elif a==0:
p=(0,1)
elif b==0:
p=(1,0)
else:
c=gcd(a,b)
a,b=a//c,b//c
if b > 0:
p=(a,b)
else: # b < 0
p=(-a,-b)
#l.append(p)
if p in d:
d[p]+=1
else:
d[p] = 1
ans=1
#for p in l:
while len(d) > 0:
p,np=d.popitem()
if p==(1,0):
q=(0,1)
elif p==(0,1):
q=(1,0)
else:
pa,pb=p
if pa > 0:
q=(-pb,pa)
else: #pa < 0
q=(pb,-pa)
if q in d:
nq=d.pop(q)
else:
nq=0
ans *= ((2**np + 2**nq - 1) % MOD)
ans %= MOD
ans -= 1
ans += nz
ans %= MOD
print(ans) | N = int(raw_input())
lst = map(int, raw_input().split())
cnt = 0
for i in range(0, len(lst)):
m = i
for j in range(i, len(lst)):
if lst[m] > lst[j]:
m = j
if m != i:
lst[i], lst[m] = lst[m], lst[i]
cnt+=1
print " ".join(map(str,lst))
print (cnt) | 0 | null | 10,414,981,300,480 | 146 | 15 |
import math
d = int(input())
class point:
def __init__(self, arg_x, arg_y):
self.x = arg_x
self.y = arg_y
p1 = point(0, 0)
p2 = point(100, 0)
def koch(d, p1, p2):
pi = math.pi
cos60 = math.cos(pi/3)
sin60 = math.sin(pi/3)
if d == 0:
return
else:
s = point((2*p1.x + 1*p2.x)/3, (2*p1.y + 1*p2.y)/3)
t = point((1*p1.x + 2*p2.x)/3, (1*p1.y + 2*p2.y)/3)
u = point(s.x + cos60*(t.x-s.x) - sin60*(t.y-s.y), s.y + sin60*(t.x-s.x) + cos60*(t.y-s.y))
koch(d-1, p1, s)
print(s.x, s.y)
koch(d-1, s, u)
print(u.x, u.y)
koch(d-1, u, t)
print(t.x, t.y)
koch(d-1, t, p2)
print(p1.x, p1.y)
koch(d, p1, p2)
print(p2.x, p2.y)
| import math
def koch(n, ax, ay, bx, by):
if n == 0: return ;
sin = math.sin(math.radians(60))
cos = math.cos(math.radians(60))
sx = (2.0 * ax + 1.0 * bx) / 3.0
sy = (2.0 * ay + 1.0 * by) / 3.0
tx = (1.0 * ax + 2.0 * bx) / 3.0
ty = (1.0 * ay + 2.0 * by) / 3.0
ux = (tx - sx) * cos - (ty - sy) * sin + sx
uy = (tx - sx) * sin + (ty - sy) * cos + sy
koch(n-1, ax, ay, sx, sy)
print(str(sx)+ " " + str(sy))
koch(n-1, sx, sy, ux, uy)
print(str(ux)+ " " + str(uy))
koch(n-1, ux, uy, tx, ty)
print(str(tx)+ " " + str(ty))
koch(n-1, tx, ty, bx, by)
if __name__ == '__main__':
n = int(input())
ax = 0.00000000
ay = 0.00000000
bx = 100.00000000
by = 0.00000000
print(str(ax) + " " + str(ay))
koch(n, ax, ay, bx, by)
print(str(bx)+ " " + str(by))
| 1 | 126,895,703,392 | null | 27 | 27 |
#coding: utf-8
string = str(input())
X = 0
li = []
for a in range(len(string)):
if string[a] == " ":
li.append(string[X:a])
X = a+1
li.append(string[X:])
for aa in range(len(li)):
li[aa] = int(li[aa])
h1 = li[0]
m1 = li[1]
h2 = li[2]
m2 = li[3]
k = li[4]
Time = (h2 * 60 + m2) - (h1 * 60 + m1) - k
print(int(Time)) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H1, M1, H2, M2, K = map(int, read().split())
hr = (H2- H1) * 60
if M2 >= M1:
_min = M2 - M1
hr = (H2- H1) * 60
ans = hr + _min
else:
_min = (M2 + 60) - M1
hr = (H2- H1 -1) * 60
ans = hr + _min
print(ans - K) | 1 | 18,096,656,409,888 | null | 139 | 139 |
N = int(input())
As = []
Bs = []
for _ in range(N):
c = 0
m = 0
for s in input():
if s == '(':
c += 1
elif s == ')':
c -= 1
m = min(m, c)
if c >= 0:
As.append((-m, c - m))
else:
Bs.append((-m, c - m))
As.sort(key=lambda x: x[0])
Bs.sort(key=lambda x: x[1], reverse=True)
f = True
c = 0
for (l, r) in As:
if c < l:
f = False
break
c += r - l
if f:
for (l, r) in Bs:
if c < l:
f = False
break
c += r - l
f = f and (c == 0)
if f:
print('Yes')
else:
print('No') | # coding: utf-8
# Your code here!
import numpy as np
import math
A,B,H,M=map(int,input().split())
time=(60*H+M)
a=360/720*time
b=360/60*M
c=math.radians(b-a)
print((A**2+B**2-2*A*B*np.cos(c))**0.5)
| 0 | null | 21,782,294,993,472 | 152 | 144 |
K = int(input())
A, B = map(int, input().split(" "))
if B//K - ((A-1)//K)>0:
print('OK')
else:
print('NG') | import sys
str = input()
if str[2] == str[3]:
if str[4] == str[5]:
print("Yes")
sys.exit()
print("No") | 0 | null | 34,526,005,003,438 | 158 | 184 |
num = int(input())
result = num + num**2 + num**3
print(result) | #!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
N = int(input())
A = [0 for i in range(N)]
B = [0 for i in range(N)]
for i in range(N):
a,b = LI()
A[i] = a
B[i] = b
A.sort()
B.sort()
if N % 2 == 1:
min_mid = A[(N - 1) // 2]
else:
min_mid = (A[N //2 - 1] + A[N//2]) / 2
if N % 2 == 1:
max_mid = B[(N - 1) // 2]
else:
max_mid = (B[N //2 - 1] + B[N//2]) / 2
if N % 2 == 0:
print(int((max_mid - min_mid) / 0.5 + 1))
else:
print(math.ceil(max_mid) - math.floor(min_mid) + 1)
| 0 | null | 13,805,346,882,788 | 115 | 137 |
def main():
n = int(input())
a_lst = list(map(int, input().split()))
dic = dict()
for i in range(n - 1):
if a_lst[i] in dic:
dic[a_lst[i]] += 1
else:
dic[a_lst[i]] = 1
dic_keys = dic.keys()
for i in range(1, n + 1):
if i in dic_keys:
print(dic[i])
else:
print(0)
if __name__ == "__main__":
main()
| def main():
s = input()
t = input()
if s == t[0:len(t) - 1]:
print('Yes')
else:
print('No')
main() | 0 | null | 26,941,644,015,552 | 169 | 147 |
#!/usr/bin/env python3
import collections
import itertools as it
import math
import numpy as np
# A = input()
A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()
li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(li[A-1]) | #!/usr/bin/env python3
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
l = list(map(int, '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'.replace(',', '').split()))
K = int(input()) - 1
print(l[K])
if __name__ == '__main__':
main()
| 1 | 50,063,246,152,240 | null | 195 | 195 |
# Aizu Problem ITP_1_7_A: Grading
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
while True:
m, f, r = [int(_) for _ in input().split()]
score = m + f
if m == f == r == -1:
break
elif m == -1 or f == -1:
print('F')
elif score >= 80:
print('A')
elif score >= 65:
print('B')
elif score >= 50 or (score >= 30 and r >= 50):
print('C')
elif score >= 30:
print('D')
else:
print('F') | x,n=map(int,input().split())
*p,=map(int,input().split())
q=[0]*(102)
for pp in p:
q[pp]=1
diff=1000
ans=-1
for i in range(0,102):
if q[i]:
continue
cdiff=abs(i-x)
if cdiff<diff:
diff=cdiff
ans=i
print(ans) | 0 | null | 7,569,699,466,238 | 57 | 128 |
def main():
x = int(input())
grade = 0
for i in range(8):
if (400 + 200 * i) <= x < (400 + 200 * (i + 1)):
grade = 8 - i
print(grade)
if __name__ == "__main__":
main() | import math
def main():
N = int(input())
d = {}
za = zb = zab = r = 0
mod = 10**9 + 7
for i in range(N):
a, b = map(int, input().split())
if a== 0 and b == 0:
zab += 1
elif b == 0:
zb += 1
elif a == 0:
za += 1
else:
if a < 0:
a, b = -a, -b
x = math.gcd(abs(a), abs(b))
d[(a//x, b//x)] = d.get((a//x, b//x), 0) + 1
used = set()
l = []
for x in d:
if x in used:
continue
a, b = x[0], x[1]
used.add(x)
if a * b > 0:
t = (abs(b), -abs(a))
else:
t = (abs(b), abs(a))
used.add(t)
l.append((d[x], d.get(t, 0)))
r = pow(2, za) + pow(2, zb) - 1
for i in l:
r *= (pow(2, i[0]) + pow(2, i[1]) - 1)
r %= mod
return (r - 1 + zab) % mod
print(main())
| 0 | null | 13,928,577,631,138 | 100 | 146 |
import sys
from io import StringIO
import unittest
import os
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
def prepare(n, mod=998244353):
f = 1
factorials = [1]
for m in range(1, n + 1):
f *= m
f %= mod
factorials.append(f)
inv = pow(f, mod - 2, mod)
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= mod
invs[m - 1] = inv
return factorials, invs
def cmb(n, r):
mod = 998244353
ans = 1
for i in range(r):
ans *= n - i
ans %= mod
for i in range(1, r + 1):
ans *= pow(i, mod - 2, mod)
ans %= mod
return ans
# 実装を行う関数
def resolve(test_def_name=""):
n, m, k = map(int, input().split())
# 全組み合わせ数(重複順列)
# all_pattern = pow(m, n, 998244353)
# 使用方法サンプル(10 N 3= 10個の要素から3つを選ぶ場合の組み合わせ数)
fns, invs = prepare(2000000)
# さらに6 N 5= 6個の要素から5つを選ぶ場合の組み合わせ数 ->このように、大量のパターンが欲しいときはこっちを使う。
# aa = (fns[6] * invs[5] * invs[6 - 5]) % 998244353 # ans=120
# 許容される組み合わせを加算していく
ans = 0
for i in range(k + 1):
# ans += (m * pow(m - 1, m - i - 1, 998244353) * cmb(n - 1, i)) % 998244353
# ans = (fns[n-1] * invs[k] * invs[n-1 - k]) % 998244353
ans += m * pow(m - 1, n - i - 1, 998244353) * (fns[n - 1] * invs[i] * invs[n - 1 - i])
ans = ans % 998244353
print(ans)
# ans = (m * pow(m - 1, m - k - 1, 998244353) * cmb(n - 1, k)) % 998244353
# カウント外の組み合わせ数
# kpl1 = k + 1
# ng_pattern = m * pow((m - 1), n - (k + 1), 998244353)
# ng_pattern = ng_pattern % 998244353
# ans = all_pattern - ng_pattern
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve(sys._getframe().f_back.f_code.co_name)
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """3 2 1"""
output = """6"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """100 100 0"""
output = """73074801"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """60522 114575 7559"""
output = """479519525"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def test_1original_1(self):
test_input = """4 10 0"""
output = """7290"""
self.assertIO(test_input, output)
def test_1original_2(self):
test_input = """4 10 1"""
output = """9720"""
self.assertIO(test_input, output)
def test_1original_3(self):
test_input = """4 10 2"""
output = """9990"""
self.assertIO(test_input, output)
def test_1original_4(self):
test_input = """4 10 3"""
output = """10000"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| import math
n = int(raw_input())
x = map(lambda l: int(l)*1.0, (raw_input()).split(" "))
y = map(lambda l: int(l)*1.0, (raw_input()).split(" "))
for p in range(1,4):
d = [math.pow(math.fabs(x[i] - y[i]), p) for i in range(n)]
print math.pow(sum(d), 1.0/p)
d = [math.fabs(x[i]-y[i]) for i in range(n)]
print max(d) | 0 | null | 11,672,596,801,924 | 151 | 32 |
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
S = sr()
bl = False
if S[2] == S[3] and S[4] == S[5]:
bl = True
print('Yes' if bl else 'No')
| s=input().strip()
print("Yes"if s[2] == s[3] and s[4] == s[5] else "No") | 1 | 42,195,612,110,432 | null | 184 | 184 |
N = int(input())
S = list(input())
Q = int(input())
class Bit:
"""1-indexed"""
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
en2asc = lambda s: ord(s) - 97
Bits = [Bit(N) for _ in range(26)]
for i, s in enumerate(S):
Bits[en2asc(s)].add(i + 1, 1)
for _ in range(Q):
q = input().split()
if q[0] == '1':
i, c = int(q[1]), q[2]
old = S[i - 1]
Bits[en2asc(old)].add(i, -1)
Bits[en2asc(c)].add(i, 1)
S[i - 1] = c
else:
l, r = int(q[1]), int(q[2])
ans = 0
for b in Bits:
ans += bool(b.sum(r) - b.sum(l - 1))
print(ans)
| 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 = NI()
R = 2**(N.bit_length())
st = [0] * (R*2)
def update(i,s):
x = 2 ** (ord(s) - ord('a'))
i += R-1
st[i] = x
while i > 0:
i = (i-1) // 2
st[i] = st[i*2+1] | st[i*2+2]
def query(a,b,n,l,r):
ret = 0
if a <= l and r <= b: return st[n]
if a < r and b > l:
vl = query(a,b,n*2+1,l,(l+r)//2)
vr = query(a,b,n*2+2,(l+r)//2,r)
ret = vl | vr
return ret
for i,s in enumerate(sys.stdin.readline().rstrip()):
update(i+1,s)
Q = NI()
for _ in range(Q):
c,a,b = sys.stdin.readline().split()
if c == '1':
update(int(a),b)
else:
ret = query(int(a),int(b)+1,0,0,R)
cnt = 0
b = 1
for i in range(26):
cnt += (b & ret) > 0
b <<= 1
print(cnt)
if __name__ == '__main__':
main() | 1 | 62,437,371,467,350 | null | 210 | 210 |
from math import gcd
from collections import defaultdict
N = int(input())
d = {}
MOD = 10**9+7
zall = 0
for _ in range(N):
A, B = map(int, input().split())
if A==0 and B==0:
zall += 1
else:
if A and B:
if A<0 and B<0:
A *= -1
B *= -1
elif A<0 and B>0:
A *= -1
B *= -1
g = gcd(A, B)
A //= g
B //= g
elif A==0:
B = 1
elif B==0:
A = 1
if (A, B) in d:
d[(A, B)] += 1
else:
d[(A, B)] = 1
ans = 1
used = defaultdict(int)
for (i, j), v in d.items():
if used[(i, j)]:continue
used[(i, j)] = 1
buf = 0
if j>0:
if (j, -i) in d:
used[(j, -i)] = 1
buf = d[(j, -i)]
else:
buf = 0
else:
if (-j, i) in d:
used[(-j, i)] = 1
buf = d[(-j, i)]
else:
buf = 0
ans *= (pow(2, buf, MOD)+pow(2, v, MOD)-1)
ans %= MOD
print((ans+zall-1)%MOD)
| mod = 1000000007
n = int(input())
ab00 = 0
abx0 = 0
ab0x = 0
p = []
m = []
from math import gcd
for _ in range(n):
i, j = map(int, input().split())
if i == 0:
if j == 0:
ab00 += 1
else:
ab0x += 1
continue
elif j == 0:
abx0 += 1
continue
k = gcd(i, j)
i //= k
j //= k
if i > 0:
if j > 0:
p.append((i, j))
else:
m.append((-j, i))
elif j > 0:
m.append((j, -i))
else:
p.append((-i, -j))
m.sort()
p.sort()
ans = pow(2, ab0x, mod) + pow(2, abx0, mod) - 1
ans %= mod
mi = 0
pi = 0
while mi < len(m) and pi < len(p):
if m[mi] == p[pi]:
mi += 1
mnum = 1
while mi < len(m) and m[mi] == m[mi-1]:
mi += 1
mnum += 1
pi += 1
pnum = 1
while pi < len(p) and p[pi] == p[pi-1]:
pi += 1
pnum += 1
ans *= pow(2, mnum, mod) + pow(2, pnum, mod) - 1
ans %= mod
elif m[mi] < p[pi]:
mi += 1
mnum = 1
while mi < len(m) and m[mi] < p[pi]:
mi += 1
mnum += 1
ans *= pow(2, mnum, mod)
ans %= mod
else:
pi += 1
pnum = 1
while pi < len(p) and p[pi] < m[mi]:
pi += 1
pnum += 1
ans *= pow(2, pnum, mod)
ans %= mod
ans *= pow(2, len(p) - pi, mod)
ans %= mod
ans *= pow(2, len(m) - mi, mod)
ans %= mod
ans = (ans - 1 + ab00) % mod
print(ans) | 1 | 21,007,220,789,400 | null | 146 | 146 |
import sys
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
return int(readline())
def reads():
return map(int, readline().split())
a,b,n=reads()
x=min(b-1,n)
print(int((a*x)/b))
| from typing import List
def count_loadable_baggage_num(baggage_num: int, truck_num: int, baggages: List[int], truck_capacity: int) -> int:
loaded_baggage_num: int = 0
for _ in range(truck_num):
current_weight: int = 0
while current_weight + baggages[loaded_baggage_num] <= truck_capacity:
current_weight += baggages[loaded_baggage_num]
loaded_baggage_num += 1
if loaded_baggage_num == baggage_num:
return baggage_num
return loaded_baggage_num
def calc_turck_min_capacity(baggage_num: int, truck_num: int, baggages: List[int]) -> int:
ng: int = max(baggages) - 1
ok: int = sum(baggages) + 1
while ok - ng > 1:
mid = (ng + ok) // 2
loadable_baggage_num = count_loadable_baggage_num(baggage_num, truck_num, baggages, mid)
if loadable_baggage_num >= baggage_num:
ok = mid
else:
ng = mid
return ok
def main():
n, k = map(int, input().split())
w: List[int] = []
for _ in range(n):
w.append(int(input()))
P = calc_turck_min_capacity(n, k, w)
print(P)
if __name__ == "__main__":
main()
| 0 | null | 14,090,054,365,450 | 161 | 24 |
# coding: utf-8
n = int(input().rstrip())
count = 0
for i in range(1,n//2+1):
m = n - i
if i != m:
count += 1
print(count) | N = int(input())
ans = N // 2
if N % 2 == 0: ans -= 1
print(ans) | 1 | 153,298,739,471,370 | null | 283 | 283 |
A = list(map(int, input().split()))
L = []
for i in A:
if i not in L:
L.append(i)
if len(L) == 2:
print('Yes')
else:
print('No') | a = input()
b = input()
n = len(a)
count = 0
for i in range(n):
if a[i] != b[i]:
count = count +1
print(count) | 0 | null | 39,140,475,370,690 | 216 | 116 |
def gcd(a, b):
if a < b:
a, b = b, a
while b != 0:
a, b = b, a % b
return a
print(gcd(*map(int, input().split())))
| import math
def gcd(a,b):
if a<b: a,b=b,a
c=a%b
if c==0:
return b
else:
return gcd(b,c)
S=[ int(x) for x in input().split()]
print(gcd(S[0],S[1]))
| 1 | 8,086,586,288 | null | 11 | 11 |
i = 1
while True :
n = input()
if n==0 :
break
else :
print 'Case %d: %d' % (i,n)
i += 1 | l,r,d = map(int,input().split())
ans=0
for i in range(l, r + 1):
if i %d == 0:
ans += 1
print(ans) | 0 | null | 3,992,362,601,640 | 42 | 104 |
n,k = map(int,input().split())
A = list(map(int,input().split()))
c = 0
from collections import Counter
d = Counter()
d[0] = 1
ans = 0
r = [0]*(n+1)
for i,x in enumerate(A):
if i>=k-1:
d[r[i-(k-1)]]-=1#ここで範囲kからはみ出たものの数を減らす
c = (c+x-1)%k
ans += d[c]
d[c] += 1
r[i+1] = c
print(ans) | N,K = map(int,input().split())
A = list(map(int,input().split()))
A = [(a-1) % K for a in A]
S = [0 for i in range(N+1)]
for i in range(1, N+1):
S[i] = (S[i-1] + A[i-1]) % K
kinds = set(S)
counts = {}
ans = 0
for k in kinds:
counts[k] = 0
for i in range(N+1):
counts[S[i]] += 1
if i >= K:
counts[S[i-K]] -= 1
ans += (counts[S[i]] - 1)
print(ans) | 1 | 137,247,974,583,588 | null | 273 | 273 |
n = int(input())
print(n ** 3)
| m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
ans = 1
if m1 == m2:
ans = 0
print(ans) | 0 | null | 62,049,015,878,086 | 35 | 264 |
numbers = input().split(" ")
num = numbers.index("0")
print(num + 1) | '''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineering College
'''
from os import path
import sys
from heapq import heappush,heappop
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input().rstrip()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
# mod=1000000007
mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def bo(i):
return ord(i)-ord('a')
def solve():
# for _ in range(ii()):
n,k = mi()
seg = []
for i in range(k):
seg.append(li())
dp = [0]*(n+1)
dp[1] = 1
for i in range(2,n+1):
dp[i] += dp[i-1]
dp[i] %= mod
for j in range(k):
if seg[j][0] >= i:
continue
l = max(1,i - seg[j][1])
r = i - seg[j][0]
dp[i] += dp[r] - dp[l-1]
dp[i] += mod
dp[i] %= mod
print((dp[n] - dp[n-1] + mod)%mod)
if __name__ =="__main__":
if path.exists('input.txt'):
sys.stdin=open('input.txt', 'r')
sys.stdout=open('output.txt','w')
else:
input=sys.stdin.readline
solve() | 0 | null | 8,036,915,484,580 | 126 | 74 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def main():
n,k = LI()
a = LI()
for kk in range(k):
r = [0] * (n+1)
for i in range(n):
c = a[i]
r[max(0, i - c)] += 1
r[min(n, i + c + 1)] -= 1
if r[0] == n and r[n] == -n:
a = [n] * n
break
t = 0
for i in range(n):
t += r[i]
a[i] = t
return JA(a, " ")
print(main())
| N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ans = 0
s = sum(A)
for a in A:
s -= a
ans += s * a
ans %= MOD
print(ans) | 0 | null | 9,563,645,643,110 | 132 | 83 |
def main():
a, b = map(int, input().split(" "))
for i in range(1,1010):
ta = i*8//100
tb = i*10//100
if ta == a and tb == b:
print(i)
return
print(-1)
if __name__ == "__main__":
main() | a, b = map(int, input().split())
for price in range(0,1010) :
if int(price*0.08) == a and int(price*0.10) == b :
print(price)
break
else :
print("-1")
| 1 | 56,564,052,259,540 | null | 203 | 203 |
N = int(input())
A = list(map(int,input().split()))
minval = 0
ans = 1000
for i in range(1, N):
if A[i] > A[minval]:
pstock = ans // A[minval]
ans = ans%A[minval] + A[i]*pstock
minval = i
print(ans) |
# D Road to Millionaire
N = int(input())
A = list(map(int, input().split()))
i = 0
M =1000
while i in range(N - 1):
if A[i] >= A[i+1]:
i = i + 1
else:
m = (A[i+1] - A[i]) * (M // A[i])
M = M + int(m)
i = i + 1
print(M) | 1 | 7,377,357,758,980 | null | 103 | 103 |
#!/usr/bin/env python3
import sys
import numpy as np
input = sys.stdin.readline
def S():
return input().rstrip()
def I():
return int(input())
def MI():
return map(int, input().split())
H, W, M = MI()
R = np.zeros(H + 1)
C = np.zeros(W + 1)
bombs = []
for _ in range(M):
h, w = MI()
bombs.append((h, w))
R[h] += 1
C[w] += 1
R_max = [R == max(R)]
ans = max(R) + max(C)
C_max = [C == max(C)]
cnt = 0
for h, w in bombs:
if R_max[0][h] and C_max[0][w]:
cnt += 1
if cnt == np.count_nonzero(R_max) * np.count_nonzero(C_max):
print(int(ans - 1))
else:
print(int(ans))
| H, W, M = map(int, input().split())
row = [0] * (H + 1)
col = [0] * (W + 1)
bom = []
for i in range(M):
h, w = map(int, input().split())
bom.append([h, w])
row[h] += 1
col[w] += 1
rmax = max(row)
cmax = max(col)
cnt = row.count(rmax) * col.count(cmax)
for h, w in bom:
if rmax == row[h] and cmax == col[w]:
cnt -= 1
print(rmax + cmax - (cnt == 0))
| 1 | 4,711,721,662,240 | null | 89 | 89 |
import math
k = 1
x = float(input())
while x*k%360 != 0:
k += 1
print(k) | from math import gcd;print(360//gcd(int(input()),360)) | 1 | 13,126,772,176,638 | null | 125 | 125 |
import sys
n,m = map(int,input().split())
#input = sys.stdin.readline
sys.setrecursionlimit(10**9)
list1 = []
s = list(input())
s.reverse()
def maze(mass): #今いるマス、現状の手数
if mass+m >= n:
list1.append(n-mass)
return
for i in range(m,0,-1):
if s[mass+i] == "0":
list1.append(i)
maze(mass+i)
return
elif i == 1:
print(-1)
exit()
maze(0)
list1.reverse()
print(" ".join(map(str,list1))) | n=int(input())
s,t = map(str, input().split())
print(''.join([s[i] + t[i] for i in range(0,n)])) | 0 | null | 125,589,542,510,532 | 274 | 255 |
w = input().lower()
text = ''
while True:
t = input()
if t == 'END_OF_TEXT':
break
text += t.lower() + ' '
print(len([t for t in text.split(' ') if t == w])) | import sys
W = input().lower()
T = sys.stdin.read().lower()
print(T.split().count(W)) | 1 | 1,800,341,511,288 | null | 65 | 65 |
n = int(input())
cnt = [0] * (n+100)
A = list(map(int, input().split()))
for a in A:
cnt[a] += 1
for i in range(n):
print(cnt[i+1])
| N = int(input())
ls = list(map(int,input().split()))
cnt = [0] * (N+1)
for i in range(N-1):
cnt[ls[i]] += 1
for i in range(1,N+1):
print(cnt[i]) | 1 | 32,503,922,122,660 | null | 169 | 169 |
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
ls=[a,b,c]
ls.sort()
if ls[0]==ls[1]:
if ls[1]==ls[2]:
print("No")
else:
print("Yes")
else:
if ls[1]==ls[2]:
print("Yes")
else:
print("No") | #!/usr/bin/env python3
a = list(map(int, input().split()))
if len(a) - len(set(a)) == 1:
print('Yes')
else:
print('No') | 1 | 68,343,214,565,128 | null | 216 | 216 |
while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
dataset = []
for a in range(1, n + 1):
for b in range(a + 1, n + 1):
for c in range(b + 1, n + 1):
dataset.append([a,b,c])
count = 0
for data in dataset:
if sum(data) == x:
count += 1
print(count) | def solve(n,x):
count = 0
for i in range(1,n+1):
for j in range(1,n+1):
if i == j :
continue
for k in range(1,n+1):
if j == k or i == k:
continue
if i+j+k == x:
count += 1
return count//6
while True:
n,x = map(int,input().split())
if n == x == 0:
break;
print(solve(n,x)) | 1 | 1,313,839,817,468 | null | 58 | 58 |
N=int(input())
import math
print(360//math.gcd(360,N))
| N = int(input())
pi = 360
while True:
if pi % N == 0:
print(pi//N)
exit()
else:
pi+=360 | 1 | 13,179,603,275,680 | null | 125 | 125 |
a = list(map(int, input().split()))
sum_a = sum(a)
if sum_a >= 22:
print('bust')
else:
print('win') | A = sum([int(x) for x in input().split()])
if A >= 22:
print('bust')
else:
print('win')
| 1 | 118,715,953,163,818 | null | 260 | 260 |
n,a,b = map(int,input().split())
q = n//(a+b)
r = n%(a+b)
if r < a:
ans = a*q + r
else:
ans = a*q + a
print(ans) | n, a, b = map(int, input().split())
q = n // (a + b)
mod = n % (a + b)
if mod > a:
remain = a
else:
remain = mod
print(q * a + remain) | 1 | 55,705,163,273,750 | null | 202 | 202 |
s=list(input())
mod=2019
mdict={}
mdict[0]=1
ans=0
tmp=0
for i in range(len(s)):
n=s.pop()
key=(int(n)*pow(10,i,mod)+tmp)%mod
if key in mdict:
mdict[key]+=1
else:
mdict[key]=1
tmp=key
for var in mdict.values():
ans+=var*(var-1)//2
print(ans) | N,M = map(int, input().split())
A_list = [int(i) for i in input().split()]
playable_days = N - sum(A_list)
if playable_days >= 0:
print(playable_days)
else:
print("-1") | 0 | null | 31,449,932,674,740 | 166 | 168 |
s = input()
t = input()
len_s = len(s)
len_t = len(t)
ans = len_t
for i in range(len_s - len_t + 1):
tmp_cnt = 0
tmp_s = s[i:i + len_t]
for c1, c2 in zip(tmp_s, t):
if c1 != c2:
tmp_cnt += 1
ans = min(ans, tmp_cnt)
print(ans) | # import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque
# N = int(input())
S = input()
T = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()
# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)
# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)
# def dfs(tree, s):
# for l in tree[s]:
# if depth[l[0]] == -1:
# depth[l[0]] = depth[s] + l[1]
# dfs(tree, l[0])
# dfs(tree, 1)
# def factorization(n):
# arr = []
# temp = n
# for i in range(2, int(-(-n**0.5//1))+1):
# if temp%i==0:
# cnt=0
# while temp%i==0:
# cnt+=1
# temp //= i
# arr.append([i, cnt])
# if temp!=1:
# arr.append([temp, 1])
# if arr==[]:
# arr.append([n, 1])
# return arr
ma = 0
s = len(S)
t = len(T)
for i in range(s - t + 1):
cnt = 0
for j in range(t):
if S[i + j] == T[j]:
cnt += 1
if cnt > ma:
ma = cnt
print(t - ma) | 1 | 3,644,685,583,302 | null | 82 | 82 |