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
e=[list(map(int,x.split()))for x in sys.stdin];n=e[0][0]+1
[print(*x)for x in[[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])]for c in e[1:n]]]
| def bubblesort(N, A):
"""Do BubbleSort"""
m = 0
flag = True
while(flag):
flag = False
for i in range(N-1, 0, -1):
if (A[i-1] > A[i]):
tmp = A[i-1]
A[i-1] = A[i]
m += 1
A[i] = tmp
flag = True
b = list(map(str, A))
print(" ".join(b))
print(m)
A = []
N = int(input())
s = input()
A = list(map(int, s.split()))
bubblesort(N, A) | 0 | null | 718,542,492,860 | 60 | 14 |
X,N = map(int,input().split())
min = 100
if N !=0:
Plist = list(map(int,input().split()))
anslist = [i for i in range(102)]
anslist.append(-1)
#anslist.remove(0)
Plist = sorted(Plist)
#print (anslist)
for i in range(N):
anslist.remove(Plist[i])
temp =100
for i in range(len(anslist)):
if min >abs(anslist[i]-X) :
min = abs(anslist[i]-X)
temp = anslist[i]
print (temp)
else :
print (X) | import sys
x,n = map(int,input().split())
p = list(map(int,input().split()))
s = 100
min_i = -1
if x not in p:
print(x)
sys.exit()
for i in range(-1,102):
if i not in p and abs(i-x) < s:
s = abs(i-x)
min_i = i
print(min_i)
| 1 | 14,118,341,094,628 | null | 128 | 128 |
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n //= i
table.append(i)
i += 1
if n > 1:
table.append(n)
return table
from itertools import groupby
N = int(input())
P = prime_decomposition(N)
ans = 0
for v, g in groupby(P):
n = len(list(g))
for i in range(1, 100000):
n -= i
if n >= 0:
ans += 1
else:
break
print(ans)
| def factorization(n):
if n==1:
return [[1,1]]
temp=n
ans=[]
for i in range(2, int(n**0.5+1.01)):
if temp % i ==0:
ct=0
while temp % i == 0:
temp //= i
ct += 1
ans.append([i, ct])
if temp != 1:
ans.append([temp, 1])
return ans
N=int(input())
L=factorization(N)
if N==1:
print(0)
exit()
ans=0
for l in L:
ct=0
fac=1
while fac<=l[1]:
ct+=1
fac+=ct+1
ans+=ct
print(ans) | 1 | 16,806,380,634,250 | null | 136 | 136 |
from math import cos , sin, sqrt, radians
import sys
A , B , H , M = list( map( int, input().split() ) )
th1 = H * 30 + 0.5 * M
th2 = M * 6
theta = min( abs( th1 - th2 ) , 360 - abs( th1 - th2 ))
if theta == 180.0:
print(A+B)
sys.exit()
theta = radians(theta)
ans = sqrt( (B * sin(theta))**2 + ( B*cos(theta) - A )**2 )
print(ans) | import sys
import math
from decimal import Decimal
def input(): return sys.stdin.readline().rstrip()
A,B,H,M = map(float,(input().split()))
minute = H * 60 + M
short = minute / (60 * 12) * 2 * math.pi
long = M / 60 * 2 * math.pi
rad = abs(long - short)
ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(rad))
print(ans) | 1 | 20,110,985,631,392 | null | 144 | 144 |
import sys,math
input = sys.stdin.readline
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
c = [(i*j,j) for i,j in zip(a,f)]
m = max(c)
def is_ok(arg):
# 条件を満たすかどうか?問題ごとに定義
chk = 0
for i,j in c:
chk += math.ceil(max(0,(i-arg))/j)
return chk <= k
def bisect_ok(ng, ok):
'''
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
まずis_okを定義
ng = 最小の値-1 ok = 最大の値+1 で最小
最大最小が逆の場合はng ok をひっくり返す
'''
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
print(bisect_ok(-1,m[0]+1)) | n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
def solve(x):
lk = k
for i, j in zip(a, f):
if i*j<=x:
continue
lk -= (j*(i+1)-x-1)//j
if lk<0:
return False
return True
ok = 10**12
ng = -1
while abs(ok-ng)>1:
mid = (ok+ng)//2
if solve(mid):
ok = mid
else:
ng = mid
print(ok)
| 1 | 165,342,057,257,598 | null | 290 | 290 |
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
m = reduce(lambda a, b: a^b, A)
l = list(map(str, [a ^ m for a in A]))
ans = ' '.join(l)
print(ans) | import sys,math,collections,itertools
input = sys.stdin.readline
N=int(input())
a=list(map(int,input().split()))
xa=a[0]
for i in range(1,len(a)):
xa ^= a[i]
b = []
for ai in a:
b.append(xa^ai)
print(*b)
| 1 | 12,515,101,268,670 | null | 123 | 123 |
H, W, K = map(int, input().split())
grid = [input() for _ in range(H)]
ans = [[0]*W for _ in range(H)]
empty_index = [False]*H
first_flg = False
cnt = 0
for i in range(H):
if '#' not in grid[i]:
empty_index[i] = True
for i in range(H):
if not empty_index[i] and not first_flg:
first_flg = True
first_index = i
if not first_flg:
continue
if empty_index[i]:
for k in range(W):
ans[i][k] = ans[i-1][k]
else:
cnt += 1
flg = False
for k in range(W):
if grid[i][k] == '#':
if not flg:
flg = True
else:
cnt += 1
ans[i][k] = cnt
for i in range(H):
if not empty_index[i]:
break
for k in range(W):
ans[i][k] = ans[first_index][k]
for i in ans:
print(*i) | 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() | 1 | 143,313,955,621,832 | null | 277 | 277 |
import math
n = int(input())
mod = 1000000007
ab = [list(map(int,input().split())) for _ in range(n)]
dic = {}
z = 0
nz,zn = 0,0
for a,b in ab:
if a == 0 and b == 0:
z += 1
continue
elif a == 0:
zn += 1
continue
elif b == 0:
nz += 1
if a< 0:
a = -a
b = -b
g = math.gcd(a,b)
tp = (a//g,b//g)
if tp not in dic:
dic[tp] = 1
else:
dic[tp] += 1
ans = 1
nn = n - z - zn - nz
for tp,v in dic.items():
if v == 0:
continue
vt = (tp[1],-1*tp[0])
if vt in dic:
w = dic[vt]
#print(tp)
e = pow(2,v,mod) + pow(2,w,mod) - 1
ans *= e
ans %= mod
nn -= v + w
dic[tp] = 0
dic[vt] = 0
ans *= pow(2,nn,mod)
if zn == 0:
ans *= pow(2,nz,mod)
elif nz == 0:
ans *= pow(2,zn,mod)
else:
ans *= pow(2,nz,mod) + pow(2,zn,mod) - 1
ans += z - 1
print(ans%mod)
#print(dic)
| from math import gcd
n = int(input())
ration = dict()
used = dict()
for _ in range(n):
a, b = map(int, input().split())
if a == 0 or b == 0:
if a == b == 0:
r = '0'
elif a == 0:
r = '0a'
else:
r = '0b'
else:
s = '-' if (a < 0) ^ (b < 0) else '+'
a = abs(a)
b = abs(b)
g = gcd(a, b)
r = f'{s} {a//g} {b//g}'
ration[r] = ration.get(r, 0) + 1
used[r] = 0
res = 1
mod = 10**9+7
add = 0
for k, v in ration.items():
if used[k]:
continue
if k == '0':
add += v
used[k] = 1
elif k == '0a' or k == '0b':
res *= 2**ration.get('0a', 0) + 2**ration.get('0b', 0) - 1
used['0a'] = used['0b'] = 1
else:
r = k.split()
l = f'{"-" if r[0]=="+" else "+"} {r[2]} {r[1]}'
res *= 2**v + 2**ration.get(l, 0) - 1
used[k] = used[l] = 1
res %= mod
res += add
res -= 1
if res < 0:
res += mod
print(res)
| 1 | 21,012,825,801,692 | null | 146 | 146 |
def main():
N_ko, K_kai = map(int, input().split())
init_light = list(map(int, input().split()))
for k in range(min(42,K_kai)):
light_list = [0 for i in range(N_ko)]
for i in range(N_ko):
left = max(0, i - init_light[i])
right = min(N_ko - 1, i + init_light[i])
light_list[left] += 1
if (right + 1 < N_ko):
light_list[right + 1] -= 1
for i in range(1, N_ko):
light_list[i] += light_list[i - 1]
init_light = light_list
print(' '.join(map(str,light_list)))
if __name__ == '__main__':
main()
| import numpy as np
from numba import njit
@njit('i8[:](i8,i8,i8[:])')
def solve(N, K, A):
for _ in range(K):
B = np.zeros(N + 1, dtype=np.int64)
for i in range(N):
a = A[i]
B[max(0, i - a)] += 1
B[min(N, i + a + 1)] -= 1
A = np.cumsum(B)[:-1]
if np.all(A == N):
return A
return A
N, K = map(int, input().split())
A = np.array(input().split(), dtype=int)
print(' '.join(map(str, solve(N, K, A)))) | 1 | 15,427,389,063,464 | null | 132 | 132 |
M = 10 ** 6
d = [0] * (M+1)
for a in range(1, M+1):
for b in range(a, M+1):
n = a * b
if n > M:
break
d[n] += 2 - (a==b)
N = int(input())
ans = 0
for c in range(1, N):
ans += d[N - c]
print(ans) | import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n = int(input())
ans = 0
for a in range(1,n):
if a ** 2 >= n:
break
for b in range(a,n):
if a * b >= n:
break
if a == b:
ans += 1
else:
ans += 2
print(ans)
if __name__=='__main__':
main() | 1 | 2,598,984,903,600 | null | 73 | 73 |
a = int(input())
l = []
c,f =0, 0
for i in range(a):
ta,tb = map(int,input().split())
if ta==tb : c+=1
else: c = 0
if c>=3 : f = 1
if f:
print("Yes")
else:
print("No")
| from collections import Counter
n=int(input())
s=list(input())
cnt = Counter(s)
rn=cnt['R']
gn=cnt['G']
bn=n-rn-gn
ans=bn*gn*rn
if n>2:
for x in range(n-2):
y=(n-1-x)//2
for i in range(1,y+1):
if (not s[x]==s[x+i]) & (not s[x]==s[x+i+i]) & (not s[x+i]==s[x+i+i]):
ans-=1
print(ans)
else:
print(0)
| 0 | null | 19,442,510,131,830 | 72 | 175 |
n, m = map(int, input().split())
A = list(map(int, input().split()))
s = 0
for i in range(m):
s += A[i]
if s > n:
print(-1)
elif s <= n:
print(n - s) | n,m=map(int,input().split())
lst=list(map(int,input().split()))
if n<sum(lst) : print(-1)
else : print(n-sum(lst)) | 1 | 31,966,041,860,718 | null | 168 | 168 |
# -*- coding: utf-8 -*-
## Library
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
## input
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split())
# P = [list(map(int,input().split())) for i in range(M)]
# S = []
# for _ in range(N):
# S.append(list(input()))
N=int(input())
for i in range(1,N+1):
if floor(i*1.08)==N:
print(i)
sys.exit()
print(":(") | n=int(input())
for i in range(n+1):
if int(i*1.08)==n:
print(i)
exit()
print(':(') | 1 | 125,777,006,797,988 | null | 265 | 265 |
from __future__ import (division, absolute_import, print_function,
unicode_literals)
import sys
from fractions import gcd
for line in sys.stdin:
small, large = sorted(int(n) for n in line .split())
G = gcd(large, small)
print(G, large // G * small) | import sys
def gcm(a,b):
return gcm(b,a%b) if b else a
for s in sys.stdin:
a,b=map(int,s.split())
c=gcm(a,b)
print c,a/c*b | 1 | 642,199,392 | null | 5 | 5 |
def pre_combi1(n, p):
fact = [1]*(n+1) # fact[n] = (n! mod p)
factinv = [1]*(n+1) # factinv[n] = ((n!)^(-1) mod p)
inv = [0]*(n+1) # factinv 計算用
inv[1] = 1
# 前処理
for i in range(2, n + 1):
fact[i]= fact[i-1] * i % p
inv[i]= -inv[p % i] * (p // i) % p
factinv[i]= factinv[i-1] * inv[i] % p
return fact, factinv
def combi1(n, r, p, fact, factinv):
"""
k<n<10**7でpが素数のときのnCr % pを求める
"""
# 本処理
if r < 0 or n < r:
return 0
r = min(r, n-r)
return fact[n] * factinv[r] * factinv[n-r] % p
p=998244353
fact,finv=pre_combi1(2*10**5+1,p)
n,m,k=map(int,input().split())
ans=0
dup=[0] * n
dup[0] = 1
for j in range(1,n):
dup[j]=dup[j-1]*(m-1) % p
for i in range(k+1):
ans += m*combi1(n-1,i,p,fact,finv)*dup[n-i-1]
ans %= p
print(ans) | n,m,k=map(int, input().split())
mod=998244353
ans=0
c=1
for i in range(k+1):
ans+=c*m*pow(m-1, n-1-i, mod)
ans%=mod
c*=(n-i-1)*pow(i+1, mod-2, mod)
c%=mod
print(ans%mod)
| 1 | 23,107,819,291,388 | null | 151 | 151 |
import sys
x = int(sys.stdin.read())
print(x ** 3) | if __name__ == "__main__":
n = int(raw_input())
print n * n * n | 1 | 283,497,276,480 | null | 35 | 35 |
S = input()
N = len(S)
if S == S[::-1]:
if S[:(N-1)//2] == S [(N+1)//2:]:
print("Yes")
else:
print("No")
else:
print("No") | def main():
S = str(input())
n = len(S)
frontN = (n - 1) // 2
backN = (n + 3) // 2
checkFN = frontN // 2
checkFNW = S[0:frontN]
for i in range(checkFN):
temp = (i + 1) * -1
if checkFNW[i] == checkFNW[temp]:
continue
else:
print('No')
return
checkBN = n - backN
checkBNW = S[backN - 1:n]
for i in range(checkBN // 2):
temp = (i + 1) * -1
if checkBNW[i] == checkBNW[temp]:
continue
else:
print('No')
return
for i in range(n // 2):
temp = (i + 1) * -1
if S[i] == S[temp]:
continue
else:
print('No')
return
print('Yes')
main() | 1 | 46,269,651,369,600 | null | 190 | 190 |
N, *a = map(int, open(0).read().split())
print(sum(1 for e in a[::2] if e % 2 == 1))
| # import bisect
from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math
import sys
# import numpy as np
ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
h, w, k = list(map(int,ipti().split()))
s = [list(input()) for i in range(h)]
empty_row = []
exist_row = []
berry_id = 1
for row in range(h):
is_empty = True
for col in range(w):
if s[row][col] == "#":
s[row][col] = berry_id
berry_id += 1
is_empty = False
if is_empty:
empty_row.append(row)
else:
exist_row.append(row)
# まず空ではない行を埋める
for row in range(h):
if row in exist_row:
berry_col = deque()
for col in range(w):
if s[row][col] != ".":
berry_col.append(col)
first = 0
fill_id = 0
while berry_col:
last = berry_col.popleft()
fill_id = s[row][last]
for j in range(first, last+1):
s[row][j] =fill_id
first = last + 1
for j in range(first, w):
s[row][j] = fill_id
for row in empty_row:
is_filled = False
for row2 in range(row+1, h):
if row2 in exist_row:
for col in range(w):
s[row][col] = s[row2][col]
is_filled = True
break
if not is_filled:
for row2 in range(row-1, -1 , -1):
if row2 in exist_row:
for col in range(w):
s[row][col] = s[row2][col]
is_filled = True
break
for row in range(h):
print(*s[row])
if __name__ == '__main__':
main() | 0 | null | 75,426,870,267,488 | 105 | 277 |
def main():
A = [list(map(int,input().split())) for i in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
for i in range(N):
for j in range(3):
for h in range(3):
if A[j][h] == b[i]:
A[j][h] = 0
if A[0][0]==0 and A[0][1]==0 and A[0][2]==0:
return 'Yes'
elif A[1][0]==0 and A[1][1]==0 and A[1][2]==0:
return 'Yes'
elif A[2][0]==0 and A[2][1]==0 and A[2][2]==0:
return 'Yes'
elif A[0][0]==0 and A[1][0]==0 and A[2][0]==0:
return 'Yes'
elif A[0][1]==0 and A[1][1]==0 and A[2][1]==0:
return 'Yes'
elif A[0][2]==0 and A[1][2]==0 and A[2][2]==0:
return 'Yes'
elif A[0][0]==0 and A[1][1]==0 and A[2][2]==0:
return 'Yes'
elif A[0][2]==0 and A[1][1]==0 and A[2][0]==0:
return 'Yes'
return ('No')
print(main())
| print('pphbhhphph'[int(input()[-1])]+'on') | 0 | null | 39,670,589,567,570 | 207 | 142 |
def gcd(a,b):
if a%b==0:
return b
return gcd(b,a%b)
while True:
try:
a,b=sorted(map(int,input().split()))
except:
break
print(gcd(a,b),a//gcd(a,b)*b) | n,m = map(int,input().split())
a = []; b= [];
for i in range(n): a.append(list(map(int,input().split())))
for i in range(m): b.append(int(input()))
for i in range(n):
c = 0
for j in range(m):
c += a[i][j]*b[j]
print(c)
| 0 | null | 591,388,548,450 | 5 | 56 |
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 18 19:19:52 2020
@author: ezwry
"""
s=list(input())
t=list(input())
u=len(s)
ans=0
for i in range(u):
if s[i] != t[i]:
ans+=1
print(ans) | INF = int(1e18)
def merge(A, left, mid, right):
n1 = mid - left
n2 = right - mid
L = [A[left + i] for i in range(n1)]
R = [A[mid + i] for i in range(n2)]
L.append(INF)
R.append(INF)
i, j = 0, 0
count = 0
for k in range(left, right):
count += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return count
def merge_sort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
c1 = merge_sort(A, left, mid)
c2 = merge_sort(A, mid, right)
c = merge(A, left, mid, right)
return c + c1 + c2
else:
return 0
if __name__ == '__main__':
n = int(input())
A = list(map(int, input().split()))
c = merge_sort(A, 0, n)
print(" ".join(map(str, A)))
print(c)
| 0 | null | 5,361,928,358,180 | 116 | 26 |
N = int(input())
a_list = list(map(int, input().split()))
#print(a_list)
myans = 0
for a, b in enumerate(a_list):
#print(a,b)
if (a+1)%2 != 0 and b%2 != 0:
myans += 1
print(myans) | #from collections import deque
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**6)
#def mypopleft(que, index):
# if len(que) > index:
# return que.pop(index)
# else:
# return []
def main():
# input
n = int(input())
graph = []
for i in range(n):
u, k, *tmp = [int(i) for i in readline().split()]
graph.append(tmp)
#print(graph)
d = [-1]*n
#que = deque([1])
que = [1]
#count = 0
d[0] = 0
check = []
while True:
v = que.pop(0)
#print(v)
#count += 1
#print(d)
for u in graph[v-1]:
#print(u)
if d[u-1] == -1:
d[u-1] = d[v-1] + 1
que.append(u)
if len(que) == 0:
break
for i in range(n):
print("{} {}".format(i+1, d[i]))
if __name__ == "__main__":
main()
| 0 | null | 3,845,148,939,828 | 105 | 9 |
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
def main():
t1,t2 = map(int,ipt().split())
a1,a2 = map(int,ipt().split())
b1,b2 = map(int,ipt().split())
d1 = t1*(a1-b1)
d2 = t2*(a2-b2)
if d1*(d1+d2) > 0:
print(0)
elif d1+d2 == 0:
print("infinity")
else:
dt = d1+d2
if abs(d1)%abs(dt):
print(abs(d1)//abs(dt)*2+1)
else:
print(abs(d1)//abs(dt)*2)
return None
if __name__ == '__main__':
main()
| import sys
while 1 > 0:
height, width = map(int, raw_input().split())
if height == 0 and width == 0:
break
for i in range(width):
sys.stdout.write("#")
print ""
for i in range(height - 2):
sys.stdout.write("#")
for j in range(width - 2):
sys.stdout.write(".")
sys.stdout.write("#")
print ""
for i in range(width):
sys.stdout.write("#")
print ""
print | 0 | null | 66,414,271,575,300 | 269 | 50 |
# https://atcoder.jp/contests/abc144/tasks/abc144_d
import math
a, b, x = list(map(int, input().split()))
if a * a * b * (1/2) <= x:
tmp = 2 * (a*a*b-x) / (a*a*a)
print(math.degrees(math.atan(tmp)))
else:
tmp = a*b*b / (2*x)
print(math.degrees(math.atan(tmp)))
| x = int(input())
c1 = x//500
x -= 500*c1
c2 = x//5
print(1000*c1 + 5*c2) | 0 | null | 102,979,148,810,274 | 289 | 185 |
while(True):
a=list(map(int,input().split()))
if(a[0]==0 and a[1]==0):
break
for x in range(a[0]):
if x==0 or x==a[0]-1:
print("#"*a[1])
else:
print("#"+"."*(a[1]-2)+"#")
print() | l = [int(x) for x in input().split()]
anser = 0
for i in l:
anser += 1
if i == 0:
print(anser) | 0 | null | 7,179,186,572,484 | 50 | 126 |
a, b = input().split()
print(str(min(int(a), int(b)))*max(int(a),int(b))) | a,b = input().split()
A = (a*int(b))
B = (b*int(a))
if A < B:
print(A)
else:
print(B) | 1 | 83,950,966,915,524 | null | 232 | 232 |
N = int(input())
X = list(map(int, input().split()))
cur = 1000
stock = 0
state = 0 # 1=increase, 0=decrease
for i in range(N - 1):
if state == 1 and X[i] > X[i + 1]:
cur += X[i] * stock
stock = 0
state = 0
elif state == 0 and X[i] < X[i + 1]:
n = cur // X[i]
cur -= X[i] * n
stock += n
state = 1
print(cur + stock * X[-1])
| import math
A,B,H,M = map(int,input().split())
x = abs((60*H+M)*0.5 - M*6)
theta = math.radians(x)
L = (A**2+B**2-2*A*B*math.cos(theta))**(1/2)
print(L) | 0 | null | 13,673,505,039,182 | 103 | 144 |
s=[_ for _ in input()]
print(''.join(s[:3])) | import random as random
s=input()
s_=s[:-2]
s1=random.choice(s_)
l=s_.index(s1)
s2=s[l+1]
s3=s[l+2]
s4=s1+s2+s3
print(s4) | 1 | 14,757,254,723,512 | null | 130 | 130 |
n = str(input())
if n[-1] in ['2', '4', '5', '7', '9']:
how_to_read = 'hon'
elif n[-1] in ['0', '1', '6', '8']:
how_to_read = 'pon'
else:
how_to_read = 'bon'
print(how_to_read) | r=int(input())
print(r*6.28318530717958623200)
| 0 | null | 25,511,019,485,170 | 142 | 167 |
n = int(input())
ans = 0
count = 0
a, b, c = 1, 1, 1
while a <= n:
# print("A : {0}".format(a))
# print("追加パターン : {0}".format( (n // a) ))
if a == 1 :
ans = ans + ( (n // a) - 1)
else :
if n // a == 1 :
ans = ans + 1
else :
if n % a == 0 :
ans = ans + ( (n // a) - 1)
else :
ans = ans + ( (n // a) )
# if n % a == 0 :
# ans = ans + ( (n / a) - 1 )
# else :
# ans = ans + ( (n // a) - 1 )
# ans = ans + (n / a) - 1
# print("A : {0}".format(a))
# while a * b < n:
# print("B : {0}".format(b))
# ans += 1
# b += 1
# c = 1
a += 1
b, c = 1, 1
# print("計算実行回数 : {0}".format(count))
print(ans - 1) | n = int(input())
cnt = 0
for i in range(1,n+1):
cnt += n//i
if n%i == 0:
cnt -= 1
print(cnt) | 1 | 2,615,846,843,584 | null | 73 | 73 |
x,y,a,b,c = map(int,input().split())
p=[int(x) for x in input().rstrip().split()]
q=[int(x) for x in input().rstrip().split()]
r=[int(x) for x in input().rstrip().split()]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p=p[:x]
q=q[:y]
pq=p+q
pqr=pq+r
pqr.sort(reverse=True)
print(sum(pqr[:x+y])) | #!/usr/bin/env python3
def solve(S: int, W: int):
if W >= S:
return "unsafe"
return "safe"
def main():
S, W = map(int, input().split())
answer = solve(S, W)
print(answer)
if __name__ == "__main__":
main()
| 0 | null | 37,054,835,516,128 | 188 | 163 |
import math
def main():
a, b, C = map(int, input().split())
C /= 180
C *= math.pi
S = 1 / 2 * a * b * math.sin(C)
L = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(C)) + a + b
h = 2 * S / a
print(S)
print(L)
print(h)
if __name__ == "__main__":
main() | import math
class Triangle():
def __init__(self, edge1, edge2, angle):
self.edge1 = edge1
self.edge2 = edge2
self.angle = angle
self.edge3 = math.sqrt(edge1 ** 2 + edge2 ** 2 - 2 * edge1 * edge2 * math.cos(math.radians(angle)))
self.height = edge2 * math.sin(math.radians(angle))
self.area = edge1 * self.height / 2
a, b, theta = [int(i) for i in input().split()]
triangle = Triangle(a, b, theta)
print(triangle.area)
print(triangle.edge1 + triangle.edge2 + triangle.edge3)
print(triangle.height)
| 1 | 170,432,438,722 | null | 30 | 30 |
H, W, K = map(int, input().split())
C = [[(c=="#") for c in input()] for _ in range(H)]
cnt0 = sum(sum(c) for c in C)
ans = 0
for sy in range(1<<H):
for sx in range(1<<W):
D = [c.copy() for c in C]
cnt = cnt0
for y in range(H):
for x in range(W):
if sy>>y&1 | sx>>x&1:
cnt -= D[y][x]
D[y][x] = False
if cnt == K:
ans += 1
print(ans)
| # coding=utf-8
class Dice(object):
def __init__(self, label):
self.label = label
def rotateS(self):
s1, s2, s3, s4, s5, s6 = self.label
self.label = [s5, s1, s3, s4, s6, s2]
def rotateN(self):
s1, s2, s3, s4, s5, s6 = self.label
self.label = [s2, s6, s3, s4, s1, s5]
def rotateE(self):
s1, s2, s3, s4, s5, s6 = self.label
self.label = [s4, s2, s1, s6, s5, s3]
def rotateW(self):
s1, s2, s3, s4, s5, s6 = self.label
self.label = [s3, s2, s6, s1, s5, s4]
def rotate(self, r):
if r == 'S':
self.rotateS()
elif r == 'N':
self.rotateN()
elif r == 'E':
self.rotateE()
elif r == 'W':
self.rotateW()
else:
print 'Cannot rotate into ' + r + 'direction.'
def getTopLabel(self):
return self.label[0]
if __name__ == '__main__':
d = Dice(map(int, raw_input().split()))
rotations = raw_input()
for r in rotations:
d.rotate(r)
print d.getTopLabel() | 0 | null | 4,577,161,292,184 | 110 | 33 |
import sys
import math
from collections import defaultdict
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
if N<=0:
return [[]]*num
elif num==1:
return [I() for _ in range(N)]
else:
read_all = [tuple(II()) for _ in range(N)]
return map(list, zip(*read_all))
#################
from bisect import bisect_left
#Binary Indexed Tree(区間加算)
#1-indexed
class Range_BIT():
def __init__(self, N):
self.size = N
self.data0 = [0]*(N+1)
self.data1 = [0]*(N+1)
def _add(self, data, k, x):
while k <= self.size:
data[k] += x
k += k & -k
# 区間[l,r)にxを加算
def add(self, l, r, x):
self._add(self.data0, l, -x*(l-1))
self._add(self.data0, r, x*(r-1))
self._add(self.data1, l, x)
self._add(self.data1, r, -x)
def _get(self, data, k):
s = 0
while k:
s += data[k]
k -= k & -k
return s
# 区間[l,r)の和を求める
def query(self, l, r):
return self._get(self.data1, r-1)*(r-1)+self._get(self.data0, r-1)\
-self._get(self.data1, l-1)*(l-1)-self._get(self.data0, l-1)
N,M = II()
A = III()
A.sort()
def is_ok(x):
num = 0
for a in A:
p = bisect_left(A,x-a)
num += N-p
if num>=M:
return True
else:
return False
#l:その値以上の幸福度の握手がM通り以上ある最大値
l = 0
r = 2*10**5 + 1
while abs(r-l)>1:
mid = (l+r)//2
if is_ok(mid):
l = mid
else:
r = mid
#値l以上の握手で用いるA[i]の個数を調べる
bit = Range_BIT(N)
for i in range(1,N+1):
p = bisect_left(A,l-A[i-1])
if p!=N:
bit.add(p+1,N+1,1)
bit.add(i,i+1,N-p)
x = [0]*N
for i in range(N):
x[i] = bit.query(i+1,i+2)
ans = 0
for i in range(N):
ans += A[i]*x[i]
#握手の回数がM回になるように調整
ans -= l*((sum(x)-2*M)//2)
print(ans) | while True:
s = raw_input()
if s == '-':
break
m = input()
for i in range(m):
h = input()
s = s[h:]+s[:h]
print s | 0 | null | 55,262,076,708,580 | 252 | 66 |
def solve():
can_positive = False
if len(P) > 0:
if k < n: can_positive = True
else: can_positive = len(M)%2 == 0
else: can_positive = k%2 == 0
if not can_positive: return sorted(P+M, key=lambda x:abs(x))[:k]
P.sort()
M.sort(reverse = True)
p, m = [], []
while len(p) + len(m) < k:
if len(P) > 0 and len(M) <= 0: p.append(P.pop())
elif len(P) <= 0 and len(M) > 0: m.append(M.pop())
elif P[-1] < -M[-1]: m.append(M.pop())
else: p.append(P.pop())
if len(m)%2:
Mi = M.pop() if len(p)*len(M) else 1 # 1 is no data
Pi = P.pop() if len(m)*len(P) else -1 # -1 is no data
if Mi < 0 and Pi >= 0:
if abs(p[-1] * Pi) < abs(m[-1] * Mi):
p.pop()
m.append(Mi)
else:
m.pop()
p.append(Pi)
elif Mi < 0:
p.pop()
m.append(Mi)
elif Pi >= 0:
m.pop()
p.append(Pi)
return p + m
n, k = map(int, input().split())
P, M = [], [] # plus, minus
for a in map(int, input().split()):
if a < 0: M.append(a)
else: P.append(a)
ans, MOD = 1, 10**9 + 7
for a in solve(): ans *= a; ans %= MOD
ans += MOD; ans %= MOD
print(ans)
| import sys
sys.setrecursionlimit(10**9)
def main():
N,K = map(int,input().split())
A = [0] + sorted(list(map(int,input().split())))
MOD = 10**9+7
def get_fact(maxim,mod):
maxim += 1
fact = [0]*maxim
fact[0] = 1
for i in range(1,maxim):
fact[i] = fact[i-1] * i % mod
invfact = [0]*maxim
invfact[maxim-1] = pow(fact[maxim-1],mod-2,mod)
for i in reversed(range(maxim-1)):
invfact[i] = invfact[i+1] * (i+1) % mod
return fact, invfact
def powerful_comb(n,r,mod,fact,invfact):
if n < 0 or n < r: return 0
return fact[n] * invfact[r] * invfact[n-r] % mod
ans = 0
fact,invfact = get_fact(N,MOD)
for i in range(K,N+1):
ans += ((A[i]-A[N-i+1]) * powerful_comb(i-1,K-1,MOD,fact,invfact)) % MOD
print(ans % MOD)
# print(A)
if __name__ == "__main__":
main() | 0 | null | 52,400,460,801,380 | 112 | 242 |
import sys
input = sys.stdin.readline
def inp():
return(int(input()))
print("Yes" if inp() >=30 else "No") | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
S = input()
l = len(S)
print("x" * l)
if __name__ == '__main__':
main()
| 0 | null | 39,076,920,851,618 | 95 | 221 |
#同値なものはリストでまとめる
n = int(input())
c = [[[] for i in range(9)] for i in range(9)]
for i in range(1,n+1):
s = str(i)
if s[-1] == '0':
continue
c[int(s[0])-1][int(s[-1])-1].append(i)
ans = 0
for i in range(9):
for j in range(9):
ans += len(c[i][j])*len(c[j][i])
print(ans) | import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(input())
res = 0
numbers = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
ss = str(i)
numbers[int(ss[0])][int(ss[-1])] += 1
for j in range(1, 10):
for k in range(1, 10):
res += numbers[j][k] * numbers[k][j]
print(res)
if __name__ == '__main__':
resolve()
| 1 | 86,864,652,758,820 | null | 234 | 234 |
number = list(map(int, input().split()))
print(number[0]*number[1]) | A, B = input().split()
total = int(A) * int(B)
print(total)
| 1 | 15,953,256,474,572 | null | 133 | 133 |
import math
N = int(input())
n = math.ceil(N/1000)
print(1000*n-N) | N = int(input())
As = list(map(int, input().split()))
Q = int(input())
sumAs = 0
dictAs = [0] * 100000
for i in range(len(As)):
sumAs += As[i]
dictAs[As[i] - 1] += 1
for _ in range(Q):
b, c = map(int, input().split())
sumAs += dictAs[b - 1] * (c - b)
dictAs[c - 1] += dictAs[b - 1]
dictAs[b - 1] = 0
print(sumAs) | 0 | null | 10,304,604,774,880 | 108 | 122 |
n,m=map(int,input().split(" "))
l=max(n,m)
s=min(n,m)
while s!=0:
tmp = s
s = l % s
l = tmp
print(n*m // l) | n, k =map(int,input().split())
MOD = 10**9 + 7
ans = 0
for i in range(k,n+2):
L = (i-1)*i / 2 #初項0,末項l,項数iの等差数列の和
H = ((n-i)+(n+1))*i //2 #初項a,末項l,項数iの等差数列の和
ans += H - L + 1
ans %= MOD
print(int(ans)) | 0 | null | 73,427,901,214,178 | 256 | 170 |
n=int(input())
s,t=input().split()
ans=str()
for i in range(n):
ans+=s[i]+t[i]
print(ans)
| N = int(input())
S,T = input().split()
for s,t in zip(S,T):
print(s+t,end="") | 1 | 112,385,875,442,640 | null | 255 | 255 |
data = [int(i) for i in input().split()]
out = ' '.join([str(i) for i in sorted(data)])
print(out)
| a,b,c=map(int,input().split())
if a>b:
a,b = b,a
if c<a:
a,b,c = c,a,b
if c<b:
a,b,c = a,c,b
print(a,b,c) | 1 | 418,455,470,720 | null | 40 | 40 |
from sys import stdin
import sys
import math
from functools import reduce
a,b = [int(x) for x in stdin.readline().rstrip().split()]
c = int(b*10)
for i in range(10):
if a == int(c*0.08):
print(c)
sys.exit()
c = c + 1
print(-1)
| a,b = map(int,input().split())
for i in range(1,1300):
if int(i*0.08) == a and int(i*0.1) == b:
print(i)
exit()
print(-1) | 1 | 56,625,647,332,410 | null | 203 | 203 |
a = input().split()
i = 0
for j in range(int(a[0]),int(a[1])+1):
if (int(a[2]) % j) == 0:
i = int(i) + 1
print(i)
| if __name__ == "__main__":
a,b,c = map(int,input().split())
count = 0
for i in range(a,b+1):
if c % i == 0:
count += 1
print("%d"%(count)) | 1 | 561,532,645,280 | null | 44 | 44 |
import math
p = map(float, raw_input().split())
print("%.10f" %(math.sqrt((p[2] - p[0]) * (p[2] - p[0]) + (p[3] - p[1]) * (p[3] - p[1])))) | x1,y1,x2,y2=map(float, input().split())
if x1<x2:
x1,x2=x2,x1
if y1<y2:
y1,y2=y2,y1
n=((x1-x2)**2+(y1-y2)**2)**(1/2)
print(n)
| 1 | 154,718,182,880 | null | 29 | 29 |
point_a,point_b = 0,0
for i in range(int(input())):
k =[]
a,b = input().split()
k = [[i,j] for i,j in zip(a,b) if i != j]
if k == []:
if len(a) < len(b):
point_b+=3
elif len(a) > len(b):
point_a += 3
else:
point_a+=1
point_b+=1
elif ord(k[0][0]) < ord(k[0][1]):
point_b += 3
else :
point_a += 3
print(point_a,point_b) | n,k = map(int,input().split())
n2 = k
count = 0
while n2 <= n:
n2*=k
count+=1
print(count+1) | 0 | null | 33,169,782,540,762 | 67 | 212 |
class SegmentTree:
def __init__(self,n,ele=0):
self.ide_ele = ele
self.num =2**(n-1).bit_length()
self.seg=[self.ide_ele]*2*self.num
def segfunc(self,x,y):
return x|y
def init(self,init_val):
for i in range(len(init_val)):
self.seg[i+self.num-1]=init_val[i]
for i in range(self.num-2,-1,-1) :
self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2])
def update(self,k,x):
k += self.num-1
if self.seg[k]==x:
return 0
self.seg[k] = x
while k:
k = (k-1)//2
self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
def query(self,p,q):
if q<=p:
return self.ide_ele
p += self.num-1
q += self.num-2
res=self.ide_ele
while q-p>1:
if p&1 == 0:
res = self.segfunc(res,self.seg[p])
if q&1 == 1:
res = self.segfunc(res,self.seg[q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = self.segfunc(res,self.seg[p])
else:
res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
return res
N,S,Q=int(input()),input(),int(input())
d={'a': 1, 'b': 2, 'c': 4, 'd': 8, 'e': 16, 'f': 32, 'g': 64, 'h': 128, 'i': 256, 'j': 512, 'k': 1024, 'l': 2048, 'm': 4096, 'n': 8192, 'o': 16384, 'p': 32768, 'q': 65536, 'r': 131072, 's': 262144, 't': 524288, 'u': 1048576, 'v': 2097152, 'w': 4194304, 'x': 8388608, 'y': 16777216, 'z': 33554432}
initial=[d[c] for c in list(S)]
ST=SegmentTree(N)
ST.init(initial)
for _ in range(Q):
typ,a,b=input().split()
if typ=='1':
i,c=int(a),d[b]
ST.update(i-1,c)
else:
l,r=int(a)-1,int(b)
x=bin(ST.query(l,r))[2:]
print(sum(map(int,list(x)))) | K = int(input())
a = 'ACL'
b = ''
for i in range(K):
b += a
print(b) | 0 | null | 32,279,954,230,812 | 210 | 69 |
l,r,d = map(int,input().split())
#print(l,r,d)
ans = 0
for i in range(101):
if d * i > r:
break
elif d * i >= l:
ans += 1
continue
else:
continue
print(ans) | l, r, d = map(int, input().split())
ans = 0
for i in range(l, r+1):
if i % d == 0: ans += 1
print(ans) | 1 | 7,588,554,304,338 | null | 104 | 104 |
import math
n=int(input())
x=list(map(int,input().split(" ")))
y=list(map(int,input().split(" ")))
def minkowski(x,y,p):
tmp=[math.fabs(x[i]-y[i])**p for i in range(len(x))]
return sum(tmp)**(1/p)
ans=[minkowski(x,y,i) for i in range(1,4)]
ans.append(max([math.fabs(x[i]-y[i])for i in range(len(x))]))
for i in ans:
print(i)
| import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
def p1(x, y, n):
D = []
for i in range(n):
D.append(abs(x[i] - y[i]))
return sum(D)
def p2(x, y, n):
D = []
for i in range(n):
D.append(abs(x[i] - y[i]))
D[i] *= D[i]
Sum = sum(D)
return math.sqrt(Sum)
def p3(x, y, n):
D = []
for i in range(n):
D.append(abs(x[i] - y[i]))
D[i] = D[i] * D[i] * D[i]
Sum = sum(D)
return math.pow(Sum, 1 / 3)
def pX(x, y, n):
D = []
for i in range(n):
D.append(abs(x[i] - y[i]))
return max(D)
print('{:6f}'.format(p1(x, y, n)))
print('{:6f}'.format(p2(x, y, n)))
print('{:6f}'.format(p3(x, y, n)))
print('{:6f}'.format(pX(x, y, n)))
| 1 | 211,342,187,830 | null | 32 | 32 |
x=int(input())
n=x//500
m=x%500
k=m//5
print(1000*n+5*k) | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
n, x, m = map(int, input().split())
d1 = defaultdict(int)
r = 0
while n:
if d1[x]:
cycle = d1[x] - n
t0 = 0
cycle2 = cycle
while cycle2:
t0 += x
x = x**2 % m
cycle2 -= 1
c, rem = divmod(n, cycle)
r += c * t0
while rem:
r += x
x = x**2 % m
rem -= 1
print(r)
sys.exit()
else:
d1[x] = n
r += x
x = x**2 % m
n -= 1
print(r)
if __name__ == '__main__':
main() | 0 | null | 22,934,779,064,552 | 185 | 75 |
N, X, Y = map(int, input().split())
ans = [0] * (N + 1)
for i in range(1, N):
for j in range(i+1, N+1):
dis1 = j-i
dis2 = abs(X-i) + 1 + abs(Y - j)
dis3 = abs(Y-i) + 1 + abs(X - j)
d = min(dis1,dis2,dis3)
ans[d] += 1
for i in range(1, N):
print(ans[i]) | N, *A = map(int, open(0).read().split())
A.sort()
dp = [True]*3*int(1e6)
x = -1
for a in A:
if a == -1: continue
x = a
while x <= A[-1]:
x += a
dp[x] = False
x = a
res = 0
for i, a in enumerate(A):
if i > 0 and a == A[i-1]: continue
if i < N-1 and a == A[i+1]: continue
if dp[a]: res += 1
print(res) | 0 | null | 29,378,155,870,008 | 187 | 129 |
#!/usr/bin/python3
# -*- coding:utf-8 -*-
import numpy
def main():
n = int(input())
la, lb = [], []
for _ in range(n):
a, b = map(int, input().split())
la.append(a)
lb.append(b)
la.sort(), lb.sort()
if n % 2 == 0:
s = (n-1)//2
e = s + 2
ma = sum(la[s:e]) / 2.0
mb = sum(lb[s:e]) / 2.0
print(int(2 * (mb - ma) + 1))
if n % 2 == 1:
ma = la[n//2]
mb = lb[n//2]
print(mb - ma + 1)
if __name__=='__main__':
main()
| n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
a = [_ab[0] for _ab in ab]
b = [_ab[1] for _ab in ab]
a.sort()
b.sort()
if n % 2 == 1:
m = a[n // 2]
M = b[n // 2]
print(M - m + 1)
else:
m = (a[n // 2 - 1] + a[n // 2]) / 2
M = (b[n // 2 - 1] + b[n // 2]) / 2
print(int((M - m) * 2 + 1))
| 1 | 17,375,650,278,240 | null | 137 | 137 |
N = int(input())
ans = [0] * (N + 1)
for x in range(1, 10 ** 2 + 1):
for y in range(1, 10 ** 2 + 1):
for z in range(1, 10 ** 2 + 1):
n = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
if N < n:
continue
ans[n] += 1
print(*ans[1:], sep='\n')
| import math
A, B, H, M = map(int, input().split())
h_rad = (H / 12 + M / 12 / 60)* 2 * math.pi
m_rad = M / 60 * 2 * math.pi
dif_rad = abs(h_rad - m_rad)
ans = math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(dif_rad))
print(ans) | 0 | null | 14,018,560,169,130 | 106 | 144 |
import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
MOD = 10**9+7
N = int(input())
dic = defaultdict(int)
zero = 0
left_zero = 0
right_zero = 0
for i in range(N):
a, b = map(int, input().split())
if b < 0:
a = -a
b = -b
if a == 0 and b == 0:
zero += 1
elif a == 0:
left_zero += 1
elif b == 0:
right_zero += 1
else:
g = math.gcd(a, b)
a //= g
b //= g
dic[a,b] += 1
done = set()
ans = 1
for a,b in dic:
k = (a, b)
if k in done: continue
rk = (-b, a)
rk2 = (b, -a)
done.add(k)
done.add(rk)
done.add(rk2)
c = pow(2, dic[k], MOD)-1
if rk in dic:
c += pow(2, dic[rk], MOD)-1
if rk2 in dic:
c += pow(2, dic[rk2], MOD)-1
c += 1
ans *= c
ans %= MOD
c1 = pow(2, left_zero, MOD)-1
c2 = pow(2, right_zero, MOD)-1
c = c1+c2+1
ans *= c
ans += zero
print((ans-1)%MOD)
| import math
def heikatu(A,B):
c = math.gcd(A,B)
return (A//c,B//c)
def pow_r(x, n,mod=10**9+7):
"""
O(log n)
"""
if n == 0: # exit case
return 1
if n % 2 == 0: # standard case ① n is even
return pow_r((x ** 2)%1000000007 , n // 2) % mod
else: # standard case ② n is odd
return (x * pow_r((x ** 2)%1000000007, (n - 1) // 2) % mod) % mod
def resolve():
N = int(input())
km = dict()
kp = dict()
zero = [0,0]
zerozero = 0
for i in range(N):
A,B = map(int,input().split())
if A == 0 and B == 0:
zerozero+=1
continue
if A == 0:
B = -abs(B)
if B == 0:
A = abs(A)
if A <0:
A *= -1
B *= -1
xx = heikatu(A,B)
if B < 0:
if not xx in km:
km[xx]=0
km[xx]+=1
else:
if not xx in kp:
kp[xx]=0
kp[xx]+=1
ans = 1
groups = []
for (x,y),v in km.items():
if (-y,x) in kp:
groups.append((v,kp[(-y,x)]))
del kp[(-y,x)]
else:
groups.append((v,0))
for v in kp.values():
groups.append((v,0))
for i,j in groups:
ans *= (pow_r(2,i)+pow_r(2,j)-1)%1000000007
ans %= 1000000007
print((ans+zerozero-1)%(10**9+7))
resolve() | 1 | 20,926,549,423,328 | null | 146 | 146 |
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
def run():
N = input()
S = input()
dp = [0] * 1000
ans = 0
for n in S:
n = int(n)
#print(dp)
for i in range(1000):
if i // 100 == n and dp[i] == 0:
dp[i] = 1
#print(f'{i} -> 1')
elif (i // 10) % 10 == n and dp[i] == 1:
dp[i] = 2
#print(f'{i} -> 2')
elif i % 10 == n and dp[i] == 2:
dp[i] = 3
#print(f'{i} -> 3')
ans += 1
print(ans)
#print(factorials)
if __name__ == "__main__":
run() | W = input().lower()
T = ""
while True:
inp = input().strip()
if inp == 'END_OF_TEXT':
break
T += inp.strip().lower()+' '
print(T.split().count(W)) | 0 | null | 65,265,700,383,744 | 267 | 65 |
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(input())
A = list(map(int, input().split()))
A_and_i = [[a, i] for i, a in enumerate(A)]
A_and_i.sort(reverse=True)
DP = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N):
a, idx = A_and_i[i]
for j in range(N):
# 右に持っていく
if j <= i:
DP[i + 1][j] = max(DP[i + 1][j], DP[i][j] +
a * abs(N - 1 - (i - j) - idx))
DP[i + 1][j + 1] = max(DP[i + 1][j + 1], DP[i]
[j] + a * abs(idx - j))
ans = max(DP[N])
print(ans)
| import numpy as np
n, k = map(int, input().split())
a = np.arange(n+1, dtype='int')
b = np.cumsum(a)
s = 0
for i in range(k, n+1):
s += (b[n] - b[n-i]) - b[i-1] + 1
s = s % 1000000007
s += 1
s = s % 1000000007
print(s)
| 0 | null | 33,358,625,573,748 | 171 | 170 |
n, k = map(int, input().split())
li_a = list(map(int, input().split()))
for idx, v in enumerate(li_a):
if idx <= (k - 1):
pass
else:
if v > li_a[idx - k]:
print('Yes')
else:
print('No')
| a,b,c=map(int,input().split())
k=int(input())
cnt=0
while a>=b:
b*=2
cnt+=1
while b>=c:
c*=2
cnt+=1
print("Yes" if cnt<=k else "No") | 0 | null | 6,969,866,438,880 | 102 | 101 |
from bisect import bisect_left, bisect_right
n = int(input())
stick = list(map(int, input().split()))
stick.sort()
count = 0
for i in range(n):
for j in range(i + 1, n):
l = bisect_right(stick, stick[j] - stick[i])
r = bisect_left(stick, stick[i] + stick[j]) # [l, r) が範囲
if j + 1 >= r:
continue
count += r - max(l, j + 1)
print(count) | n=int(input())
edges=[[] for i in range(1+n)]
e={}
for i in range(n-1):
"""#weighted->erase_,__,___=map(int,input().split())
edges[_].append((__,___))
edges[__].append((_,___))
"""
_,__=map(int,input().split())
edges[_].append(__)
edges[__].append(_)
e[(_,__)]=i
e[(__,_)]=i
"""
"""#weighted->erase
f=max(len(j)for j in edges)
print(f)
ret=[0]*(n-1)
from collections import deque
dq=deque([(1,1)])
#pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす)
while dq:
a,c=dq.popleft()
for to in edges[a]:
if ret[e[(a,to)]]:continue
ret[e[(a,to)]]=c
c=c%f+1
dq.append((to,c))
print(*ret,sep="\n") | 0 | null | 153,904,229,678,628 | 294 | 272 |
import sys
import math
from collections import deque
from collections import defaultdict
def main():
n, k = list(map(int,sys.stdin.readline().split()))
ans = n//k
if n%k != 0:
ans += 1
print(ans)
return 0
if __name__ == "__main__":
main() | import math
h,a = map(int,input().split())
if h % a != 0:
ans = math.floor(h/a+1)
else:
ans = math.floor(h/a)
print(ans) | 1 | 76,586,405,467,540 | null | 225 | 225 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
N = int(readline())
odd = 0
for i in range(1, N + 1):
if i % 2 == 1:
odd += 1
print(odd / N)
if __name__ == '__main__':
main()
| n=int(input())
if n%2==1:
x=((n//2)+1)/n
print(x)
else:
print(1/2)
| 1 | 177,504,701,118,140 | null | 297 | 297 |
n = int(input())
d = {}
t = 0
for i in range(n):
s = input()
d[s] = d.get(s, 0) + 1
t = max(t, d[s])
for key in sorted(d):
if d[key] == t:
print(key) | # A - Station and Bus
# https://atcoder.jp/contests/abc158/tasks/abc158_a
s = input()
if len(set(s)) == 2:
print('Yes')
else:
print('No')
| 0 | null | 62,583,353,418,468 | 218 | 201 |
import sys
input = sys.stdin.readline
def solve(N, K, L):
dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(L + 1)]
dp[0][0][0] = 1
for i in range(L):
D = N[i]
for j in range(2):
d_max = 9 if j == 1 else D
for k in range(K + 1):
if k < K:
for d in range(d_max + 1):
dp[i + 1][int(j or (d < D))][k + int(d > 0)] += dp[i][j][k]
else:
dp[i + 1][j][k] += dp[i][j][k]
return dp[L][0][K] + dp[L][1][K]
def main():
N = list(map(int, input().rstrip()))
K = int(input())
L = len(N)
ans = solve(N, K, L)
print(ans)
if __name__ == "__main__":
main()
| N = input()
K = int(input())
m = len(N)
dp = [[[0] * (K+1) for _ in range(2)] for _ in range(m+1)]
dp[0][0][0] = 1
for i in range(1,m+1):
l = int(N[i-1])
for k in range(K+1):
if k-1>=0:
if l!=0:
dp[i][0][k]=dp[i-1][0][k-1]
dp[i][1][k] = dp[i-1][1][k] + 9 * dp[i-1][1][k-1]+dp[i-1][0][k] + (l-1) * dp[i-1][0][k-1]
else:
dp[i][0][k] = dp[i-1][0][k]
dp[i][1][k] = dp[i-1][1][k] + 9 * dp[i-1][1][k-1]
else:
dp[i][0][k] = 0
dp[i][1][k] = 1
print(dp[m][0][K] + dp[m][1][K]) | 1 | 75,551,616,302,988 | null | 224 | 224 |
S = list(input())
A = [0]*(len(S)+1)
node_value = 0
for i in range(len(S)):
if S[i] == "<":
node_value += 1
A[i+1] = node_value
else:
node_value = 0
node_value = 0
for i in range(len(S)-1,-1,-1):
if S[i] == ">":
node_value += 1
A[i] = max(A[i], node_value)
else:
node_value = 0
print(sum(A)) | S = list(input())
L = len(S)
count = 0
count_minus = [0] * L
for i in range(L):
if S[i] == ">":
count = 0
else:
count += 1
count_minus[i] = count
count = 0
count_plus = [0] * L
for i in reversed(range(L)):
if S[i] == "<":
count = 0
else:
count += 1
count_plus[i] = count
result_list = [0] * (L-1)
for i in range(len(result_list)):
result_list[i] = max(count_minus[i], count_plus[i+1])
result = sum(result_list) + count_minus[L-1] + count_plus[0]
print(result) | 1 | 156,470,739,517,938 | null | 285 | 285 |
a,b,c = sorted(map(int,raw_input().split()))
print a,b,c | # coding: utf-8
import sys
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10**7)
def run():
N = list(map(int, list(input())))
N = N[::-1] + [0]
count = 0
seq = 0
for idx, n in enumerate(N[:]):
if seq == 1 and (n >= 5 or (n == 4 and N[idx+1] >= 5)):
count += 9 - n
elif seq == 0 and (n >= 6 or (n == 5 and N[idx+1] >= 5)):
count += 10 - n
seq = 1
else:
count += n + seq
seq = 0
print(count)
if __name__ == "__main__":
run() | 0 | null | 35,522,057,852,902 | 40 | 219 |
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
if i in d: d[i] += 1
else: d[i] = 1
ans = 0
for i in d.values(): ans += i*(i-1)//2
for i in a:
print(ans - (d[i]-1)) | from collections import Counter
def f(n):
if n<2:
return 0
return n*(n-1)//2
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
ans = 0
for c in cnt.values():
ans += f(c)
for a in A:
print(ans-cnt[a]+1) | 1 | 47,651,601,942,950 | null | 192 | 192 |
import math
x1,y1,x2,y2 = tuple(float(n) for n in input().split())
D = math.sqrt((x2-x1)**2 + (y2-y1)**2)
print("{:.8f}".format(D))
| def main(a, b,c,k):
m = 0
if k <=a:
m = k
elif k <=(a+b):
m = a
elif k <= a+b+c:
m = (a-(k-(a+b)))
return m
a, b, c , k = map(int, input().split())
print(main(a,b,c,k)) | 0 | null | 11,028,220,755,452 | 29 | 148 |
X = int(input())
happy = 0
happy += (X // 500) * 1000
happy += ((X - X // 500 * 500) // 5) * 5
print(happy) | import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
N = int(readline())
if N==1:
print('a')
exit()
d = deque(['a'])
ans = []
while d:
s = d.popleft()
last = ord(max(s))
for i in range(97,last+2):
S = s + chr(i)
if len(S)==N:
ans.append(S)
else:
d.append(S)
ans.sort()
for s in ans:
print(s)
if __name__ == '__main__':
main() | 0 | null | 47,479,788,899,890 | 185 | 198 |
n = int(input())
a = input()
print(a)
a = [int(x) for x in a.split(' ')]
for i in range(1, n):
v = a[i]
j = i - 1
while j >= 0 and a[j] > v:
a[j + 1] = a[j]
j -= 1
a[j + 1] = v
print(' '.join([str(x) for x in a])) | N = int(input())
A = [int(s) for s in input().split()]
print(' '.join([str(item) for item in A]))
for i in range(1, N):
key = A[i]
j = i - 1
while j >= 0 and A[j] > key:
A[j+1] = A[j]
j = j - 1
A[j+1] = key
print(' '.join([str(item) for item in A])) | 1 | 5,790,906,752 | null | 10 | 10 |
#!/usr/bin/env python3
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
N, K = map(int, input().split())
ans = N % K
ans = min(ans, abs(ans - K))
print(ans)
if __name__ == '__main__':
main()
| N,K = map(int, input().split())
y = N%K
z = abs(K-y)
ans = min(y,z)
print(ans) | 1 | 39,058,452,115,878 | null | 180 | 180 |
S=input()
T=input()
ls = []
flg = False
for i in range(26):
#print(S+chr(ord("a")+i))
#print(type(T),type(S+chr(ord("a")+i)))
if T == S+chr(ord("a")+i):
flg = True
#print("Yes")
break
else:
continue
if flg == True:
print("Yes")
else:
print("No")
| S = input()
T = input()
if(S == T[0:-1] and len(S) + 1 == len(T)):
print("Yes")
else:
print("No") | 1 | 21,338,221,692,698 | null | 147 | 147 |
n = int(input())
ans = int(n/1.08)
for i in range(2):
if int(ans*1.08) == n:
print(ans)
exit()
ans += 1
print(":(") | N = int(input())
for i in range(1, N + 1):
if i + (i * 8) // 100 == N:
print(i)
break
else:
print(":(") | 1 | 126,146,744,461,088 | null | 265 | 265 |
def 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)
return sorted(divisors)
N = int(input())
ans = len(divisors(N-1)) -1
for k in divisors(N)[1:]:
N_ = N
while N_ % k == 0:
N_ = N_//k
if N_ % k == 1:
ans += 1
print(ans)
| import sys
sys.setrecursionlimit(1000000)
def II(): return int(input())
def MI(): return map(int, input().split())
N=II()
edge=[[] for i in range(N)]
a=[0]*N
b=[0]*N
for i in range(N-1):
a[i],b[i]=MI()
a[i]-=1
b[i]-=1
edge[a[i]].append(b[i])
edge[b[i]].append(a[i])
k=0
color_dict={}
def dfs(to,fm=-1,ban_color=-1):
global k
color=1
for nxt in edge[to]:
if nxt==fm:
continue
if color==ban_color:
color+=1
color_dict[(to,nxt)]=color
dfs(nxt,to,color)
color+=1
k=max(k,color-1)
dfs(0)
print(k)
for i in range(N-1):
print(color_dict[(a[i],b[i])]) | 0 | null | 88,404,582,642,560 | 183 | 272 |
import sys
MAXINT = 1000000001
n = int(input())
S = list(map(int,input().split()))
def merge(A, l, m, r, cnt):
n1 = m - l
n2 = r - m
L = [A[i] for i in range(l, l+n1)]
R = [A[i] for i in range(m, m+n2)]
L.append(MAXINT)
R.append(MAXINT)
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
return cnt
def mergesort(A, l, r, cnt):
if l + 1 < r:
m = (l + r) // 2
cnt = mergesort(A, l, m, cnt)
cnt = mergesort(A, m, r, cnt)
cnt = merge(A,l,m,r, cnt)
return cnt
cnt = 0
cnt = mergesort(S, 0, n, cnt)
print(" ".join(map(str,S)))
print(cnt)
| def merge(a, l, m, r):
global count
Left = a[l:m]
Left.append(1e10)
Right = a[m:r]
Right.append(1e10)
i, j = 0, 0
for k in range(l, r):
count += 1
if Left[i] <= Right[j]:
a[k] = Left[i]
i += 1
else:
a[k] = Right[j]
j += 1
def sort(a, l, r):
if r-l > 1:
m = (l+r)//2
sort(a, l, m)
sort(a, m, r)
merge(a, l, m, r)
count=0
n=int(input())
a=[int(i) for i in input().split()]
sort(a, 0, n)
print(*a)
print(count)
| 1 | 113,101,302,050 | null | 26 | 26 |
N = int(input())
an = x = [int(i) for i in input().split()]
count = 0
for i in range(len(an)):
if ((i + 1) % 2 == 0):
continue
if (an[i] % 2 != 0):
count = count + 1
print(count) | while True:
H, W = map(int, input().split())
if not(H or W):
break
print('#' * W)
for i in range(H-2):
print('#', end='')
for j in range(W-2):
print('.', end='')
print('#')
print('#' * W, end='\n\n') | 0 | null | 4,305,048,542,688 | 105 | 50 |
H,W=[int(i) for i in input().split()]
if H==1 or W==1:
print(1)
else:
print(int(H*W/2)+(H*W)%2)
| import math
def resolve():
H, W = [int(i) for i in input().split()]
if H==1 or W==1:
print(1)
else:
print(math.ceil(H*W/2))
resolve() | 1 | 51,052,958,018,792 | null | 196 | 196 |
cards_num = int(input())
cards = []
missing_cards = []
for i in range(cards_num):
cards.append(input())
for i in range(1, 14):
if "S {0}".format(i) not in cards:
missing_cards.append("S {0}".format(i))
for i in range(1, 14):
if "H {0}".format(i) not in cards:
missing_cards.append("H {0}".format(i))
for i in range(1, 14):
if "C {0}".format(i) not in cards:
missing_cards.append("C {0}".format(i))
for i in range(1, 14):
if "D {0}".format(i) not in cards:
missing_cards.append("D {0}".format(i))
for i in missing_cards:
print(i) | n = input()
mark = ['S', 'H', 'C', 'D']
cards = ["{} {}".format(mark[i], j+1) for i in range(4) for j in range(13)]
for i in range(n):
cards.remove(raw_input())
while len(cards) != 0:
print cards.pop(0) | 1 | 1,034,792,774,712 | null | 54 | 54 |
n = int(input())
x = list(input())
sx = len(set(x))
if sx == 1:
print(0)
exit()
cnt_r = x.count("R")
cnt = 0
for i in range(cnt_r):
if x[i] == "W":
cnt += 1
print(cnt) | N = int(input())
#stones = list(input())
stones = input()
#print(stones)
a = stones.count('W')
b = stones.count('R')
left_side =stones.count('W', 0, b)
print(left_side) | 1 | 6,271,070,893,582 | null | 98 | 98 |
N, A, B = map(int, input().split())
q = N // (A + B)
r = N % (A + B)
if r <= A:
print(q * A + r)
else:
print(q * A + A) | n = int(input())
a = list(map(int, input().split()))
ans = [0]*n
for boss in a:
ans[boss-1] += 1
for sub in ans:
print(sub) | 0 | null | 43,963,267,004,020 | 202 | 169 |
n, k = map(int, input().split())
W = [int(input()) for i in range(n)]
left = max(W)-1; right = sum(W)
while left+1 < right:
mid = (left + right) // 2
cnt = 1; cur = 0
for w in W:
if mid < cur + w:
cur = w
cnt += 1
else:
cur += w
if cnt <= k:
right = mid
else:
left = mid
print(right) | n = int(input())
S = set(input().split())
q = int(input())
T = set(input().split())
print(len(S & T))
| 0 | null | 77,328,926,290 | 24 | 22 |
k, n = map(int, input().split())
a = sorted(map(int, input().split()))
ans = a[-1]-a[0]
for i in range(1, n-1):
path = k- a[-i] + a[-i-1]
ans = min(ans, path)
print(ans) | import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
n = ni()
s = str(n)
K = ni()
dp = [[[0] * 2 for _ in range(K + 2)] for _ in range(len(s) + 1)]
dp[0][0][0] = 1
for i in range(len(s)):
for j in range(K + 1):
for k in range(2):
dmax = 9 if k else int(s[i])
for d in range(dmax + 1):
ni = i + 1
nj = j + (d != 0)
nk = k | (d < dmax)
dp[ni][nj][nk] += dp[i][j][k]
print(dp[len(s)][K][0] + dp[len(s)][K][1]) | 0 | null | 59,963,625,194,648 | 186 | 224 |
#1st line
input_str = input().strip()
#2nd line
command_max_times = int(input().strip())
command_cnt = 0
while command_cnt < command_max_times:
command_cnt = command_cnt + 1
input_line = input().strip().split(" ")
input_command = input_line[0]
input_sta = int(input_line[1])
input_end = int(input_line[2])
if input_command == "print":
print(input_str[input_sta:input_end+1])
elif input_command == "replace":
str_replace = input_line[3]
input_str = input_str[:input_sta] + str_replace + input_str[input_end+1:]
elif input_command == "reverse":
str_temp = input_str[input_sta:input_end+1]
input_str = input_str[:input_sta] + str_temp[::-1] + input_str[input_end+1:] | def rvrs(base, start, end):
r = base[int(start):int(end) + 1][::-1]
return base[:int(start)] + r + base[int(end) + 1:]
def rplc(base, start, end, string):
return base[:int(start)] + string + base[int(end) + 1:]
ans = input()
q = int(input())
for _ in range(q):
ORD = list(input().split())
if ORD[0] == 'print':
print(ans[int(ORD[1]):int(ORD[2])+1])
elif ORD[0] == 'reverse':
ans = rvrs(ans, int(ORD[1]), int(ORD[2]))
elif ORD[0] == 'replace':
ans = rplc(ans, int(ORD[1]), int(ORD[2]), ORD[3])
| 1 | 2,097,896,715,628 | null | 68 | 68 |
import sys
from operator import itemgetter
N = int(input())
S = sys.stdin.read().split()
HT_high = []
HT_low = []
for s in S:
t = 0
h = 0
for c in s:
if c == "(":
h += 1
else:
h -= 1
if h < t:
t = h
if h >= 0:
HT_high.append((h, t))
else:
HT_low.append((h, t))
HT_high.sort(key=itemgetter(1), reverse=True)
HT_low.sort(key=lambda x: x[0]-x[1], reverse=True)
h0 = 0
for h, t in HT_high + HT_low:
if h0 + t < 0:
print("No")
exit()
h0 += h
if h0 != 0:
print("No")
else:
print("Yes")
| # -*- coding: utf-8 -*-
N = int(input().strip())
S_list = [input().strip() for _ in range(N)]
#-----
def count_brackets(brackets):
L = R = 0
L_rev = R_rev = 0
max_R = -float("inf")
max_L = -float("inf")
for i in range(len(brackets)):
if brackets[i] == "(":
L += 1
else: # brackets[i] == ")"
R += 1
max_R = max(max_R, R - L)
if brackets[len(brackets)-1-i] == "(":
L_rev += 1
max_L = max(max_L, L_rev - R_rev)
else: # brackets[len(brackets)-1-i] == ")"
R_rev += 1
if max_L < 0: max_L = 0
if max_R < 0: max_R = 0
return max_L, max_R
tmp_cnt1 = [] # the number of "(" >= the number of ")"
tmp_cnt2 = [] # the number of "(" < the number of ")"
for S in S_list:
cnt_L,cnt_R = count_brackets(S)
if cnt_L == cnt_R == 0:
continue
if cnt_L >= cnt_R:
tmp_cnt1.append( (cnt_L,cnt_R) )
else:
tmp_cnt2.append( (cnt_L,cnt_R) )
tmp_cnt1.sort(key=lambda x: x[1])
tmp_cnt2.sort(key=lambda x: -x[0])
sum_bracket = 0
flag = True
for cnt_L,cnt_R in (tmp_cnt1 + tmp_cnt2):
sum_bracket -= cnt_R
if sum_bracket < 0: flag = False
sum_bracket += cnt_L
if sum_bracket < 0: flag = False
if flag == False:
break
if (sum_bracket == 0) and flag:
print("Yes")
else:
print("No")
| 1 | 23,807,841,828,858 | null | 152 | 152 |
n = int(input())
a = list(map(int, input().split()))
f = [0 for i in range(10**6+5)]
for x in a:
f[x] += 1
for i in range(1, len(f)):
if f[i] == 0:
continue
for j in range(2*i, len(f), i):
f[j] = 0
ans = 0
for v in f:
if v == 1:
ans += 1
print(ans)
| # ABC159
# String Palindrome
S = input()
n = len(S)
n
m = int(((n - 1)/2)-1)
l = int(((n + 3)/2)-1)
if S[::1] == S[::-1]:
if S[:m+1:] == S[m::-1]:
if S[l::] == S[:l-1:-1]:
print('Yes')
exit()
print('No') | 0 | null | 30,319,333,608,992 | 129 | 190 |
n,m = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
a,b = [],[]
for i in range(m):
a1,b1 = [int(x) for x in input().split()]
a.append(a1-1)
b.append(b1-1)
ans = [1] * n
for i in range(m):
if h[a[i]] < h[b[i]]:
ans[a[i]] = 0
elif h[a[i]] > h[b[i]]:
ans[b[i]] = 0
else:
ans[a[i]] = 0
ans[b[i]] = 0
c = 0
for i in range(n):
if ans[i] == 1:
c += 1
#print(ans)
print(c) | from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())
def main():
A, B, C, D = i_map()
print(max([A * C, A * D, B * C, B * D]))
if __name__ == "__main__":
main()
| 0 | null | 14,007,121,219,210 | 155 | 77 |
N, K = map(int,input().split())
a = []
n = 1
while n <= N:
a = a + [n]
n += 1
for i in range(K):
d = int(input())
A = list(map(int,input().split()))
for j in range(d):
if A[j] in a:
a.remove(A[j])
ans = len(a)
print(ans) | def main():
N = int(input())
total = 0
for i in range(N):
i = i + 1
if i % 3 == 0 and i % 5 == 0:
continue
elif i % 3 == 0:
continue
elif i % 5 == 0:
continue
total = total + i
print(total)
main() | 0 | null | 29,928,801,343,068 | 154 | 173 |
n = int(input())
s = input()
int_s = [int(i) for i in s]
pc = s.count('1')
def f(x):
bi = bin(x)
pc = bi.count('1')
cnt = 1
while True:
if x == 0:
break
x = x % pc
bi = bin(x)
pc = bi.count('1')
cnt += 1
return cnt
num_pl = 0
for i in range(n):
num_pl = (num_pl*2) % (pc+1)
num_pl += int_s[i]
num_mi = 0
for i in range(n):
if pc-1 <= 0:
continue
num_mi = (num_mi*2) % (pc-1)
num_mi += int_s[i]
ans = [0]*n
pc_pl, pc_mi = pc+1, pc-1
r_pl, r_mi = 1, 1
for i in range(n-1, -1, -1):
if int_s[i] == 0:
num = num_pl
num = (num+r_pl) % pc_pl
else:
num = num_mi
if pc_mi <= 0:
continue
num = (num-r_mi+pc_mi) % pc_mi
ans[i] = f(num)
r_pl = (r_pl*2) % pc_pl
if pc_mi <= 0:
continue
r_mi = (r_mi*2) % pc_mi
print(*ans, sep='\n') | from bisect import bisect_right
N, D, A = map(int, input().split())
xh = sorted([list(map(int, input().split())) for _ in range(N)])
ds = [0]*(N+2)
b = 0
for i, (x, h) in enumerate(xh, 1):
ds[i] += ds[i-1]###(*)
###これまでのやつに与えたダメージは引き継がれるものとする
d = ds[i]
if d>=h:
continue###すでに体力以上のダメージを与えた敵
h -= d###ダメージを与える
times = h//A if h%A==0 else h//A+1
ds[i] += times*A
ds[bisect_right(xh, [x+2*D, float('inf')])+1] -= times*A
###(*)のせいで, 2Dよりも向こう側にも、今考えたダメージの影響が
###出てしまうので. それを打ち消すために与えるダメージを引いておく
b += times
print(b)
| 0 | null | 45,380,916,477,520 | 107 | 230 |
d = list(map(int, input().split()))
order = input()
class Dice():
def __init__(self, d):
self.dice = d
def InsSN(self, one, two, five, six):
self.dice[0] = one
self.dice[1] = two
self.dice[4] = five
self.dice[5] = six
def InsWE(self, one, three, four, six):
self.dice[0] = one
self.dice[2] = three
self.dice[3] = four
self.dice[5] = six
def S(self):
one = self.dice[4]
two = self.dice[0]
five = self.dice[5]
six = self.dice[1]
self.InsSN(one, two, five, six)
def N(self):
one = self.dice[1]
two = self.dice[5]
five = self.dice[0]
six = self.dice[4]
self.InsSN(one, two, five, six)
def W(self):
one = self.dice[2]
three = self.dice[5]
four = self.dice[0]
six = self.dice[3]
self.InsWE(one, three, four, six)
def E(self):
one = self.dice[3]
three = self.dice[0]
four = self.dice[5]
six = self.dice[2]
self.InsWE(one, three, four, six)
def roll(self, order):
if order == 'S':
self.S()
elif order == 'N':
self.N()
elif order == 'E':
self.E()
elif order == 'W':
self.W()
d = Dice(d)
for o in order:
d.roll(o)
print(d.dice[0]) | N, K = list(map(int,input().split()))
def sum_(i, j):
return (a[i] + a[j]) * (j - i + 1) // 2
a = [i for i in range(N + 1)]
ans = 0
for i in range(K, N + 2):
min_ = sum_(0, i - 1)
max_ = sum_(N - i + 1, N)
ans += (max_ - min_ + 1)
ans %= 10 ** 9 + 7
print(ans) | 0 | null | 16,647,565,674,156 | 33 | 170 |
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")
| n = int(input())
a = int(n**0.5+1)
ans = [0]*n
for x in range(1, a):
for y in range(1, a):
for z in range(1, a):
if x**2 + y**2 + z**2 + x*y + y*z + z*x <= n:
ans[x**2 + y**2 + z**2 + x*y + y*z + z*x -1] += 1
[print(i) for i in ans] | 0 | null | 17,178,345,436,010 | 158 | 106 |
from collections import deque
n, m = map(int,input().split())
graph = [[] for _ in range(n+1)]
for i in range(m):
a,b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
# dist = [-1]*(n+1)
# dist[0] = 0
# dist[1] = 0
mark = [-1]*(n+1)
mark[0] - 0
mark[1] = 0
d = deque()
d.append(1)
while d:
v = d.popleft()
for i in graph[v]:
if mark[i] != -1:
# if dist[i] != -1:
continue
mark[i] = v
# dist[i] = dist[v] + 1
d.append(i)
if '-1' in mark:
print('No')
else:
print('Yes')
print(*mark[2:], sep='\n')
| from collections import defaultdict
G = defaultdict(set)
N, M = [int(_) for _ in input().split()]
for _ in range(M):
A, B = [int(_) for _ in input().split()]
G[A].add(B)
G[B].add(A)
f = [-1 for _ in range(N+1)]
f[1] = 0
pool = set([1])
np = set()
cnt = 0
while pool:
np = set()
for p in pool:
for v in G[p]:
if f[v] == -1:
f[v] = p
cnt += 1
np.add(v)
pool = np
print("Yes")
for i in range(2, N+1):
print(f[i])
| 1 | 20,564,260,329,820 | null | 145 | 145 |
# -*- coding: utf-8 -*-
def converter(a, b):
larger = max(a, b)
smaller = min(a, b)
if larger == 0 or smaller == 0:
return larger
else:
return converter(smaller, larger % smaller)
def main():
a, b = [int(x) for x in raw_input().strip().split(' ')]
print converter(a, b)
if __name__ == '__main__':
main() | #!usr/bin/env python3
import sys
def main():
while True:
m, f, r = [int(score) for score in sys.stdin.readline().split()]
if m == f == r == -1:
break
if m == -1 or f == -1:
print('F')
elif m+f >= 80:
print('A')
elif 80 > m+f >= 65:
print('B')
elif 65 > m+f >= 50:
print('C')
elif 50 > m+f >= 30:
if r >= 50:
print('C')
else:
print('D')
elif m+f < 30:
print('F')
if __name__ == '__main__':
main() | 0 | null | 625,015,044,110 | 11 | 57 |
import sys
W = input().lower()
T = sys.stdin.read().lower()
print(T.split().count(W)) | W = raw_input()
S = []
while True:
tmp = map(str, raw_input().split())
if tmp[0] == "END_OF_TEXT":
break
else:
S.append(tmp)
cnt = 0
for i in range(len(S)):
for j in range(len(S[i])):
if W == S[i][j].lower():
cnt += 1
print cnt | 1 | 1,807,061,629,080 | null | 65 | 65 |
k=int(input())
v='ACL'
print(k*v) | x = int(input())
print("ACL" * x) | 1 | 2,165,468,720,470 | null | 69 | 69 |
a=int(input())
b=int(input())
print(6//(a*b)) | A=int(input())
B=int(input())
ans=[1,2,3]
for a in ans:
if a!=A and a!=B:
print(a) | 1 | 111,144,965,514,634 | null | 254 | 254 |
string1 = input()
string2 = input()
n, m = len(string1), len(string2)
best = float("inf")
for i in range(n - m + 1):
current = string1[i:i+m]
differences = 0
for i in range(m):
if current[i] != string2[i]:
differences += 1
best = min(differences, best)
if best == float("inf"):
print(0)
else:
print(best) | import math
def triangle(co1, co2):
ans = []
x1 = co1[0]
y1 = co1[1]
x2 = co2[0]
y2 = co2[1]
part1 = [(2 * x1 + x2) /3, (2 * y1 + y2) / 3]
part2 = [(x1 + 2 * x2) /3, (y1 + 2 * y2) / 3]
#part2をpart1中心に60度回転
edge = [(part2[0] - part1[0])/2 - (part2[1] - part1[1])/ 2 * math.sqrt(3) + part1[0], (part2[0] - part1[0])/2 * math.sqrt(3) + (part2[1] - part1[1])/ 2 + part1[1]]
ans.extend([part1, edge, part2, co2])
return ans
def rec(A, n):
if n == 0:
return
rec(A, n-1)
for i in range(4 ** (n-1)):
A[n].extend(triangle(A[n-1][i], A[n-1][i+1]))
n = int(input())
koch = [[[0.0, 0.0]] for i in range(n + 1)]
koch[0].append([100.0, 0.0])
rec(koch, n)
for i in range(4 ** n + 1):
print(*koch[n][i])
| 0 | null | 1,875,192,406,390 | 82 | 27 |
N = int(input())
A = list(map(int,input().split()))
mode = 0
money = 1000
kabu = 0
for i in range(N):
if i == 0:
if A[i+1] > A[i]:
kabu += 1000//A[i]
money -= kabu*A[i]
mode = 1
else:
continue
elif i == N-1:
money += kabu*A[i]
else:
if mode == 1:
if A[i] >= A[i-1]:
if A[i] > A[i+1]:
money += kabu*A[i]
kabu = 0
mode = 0
else:
continue
else:
if A[i] < A[i+1]:
kabu += money//A[i]
money -= kabu*A[i]
mode = 1
else:
continue
print(money) | a=100000
for _ in range(int(input())):
a=((a*1.05)//1000+1)*1000 if (a*1.05)%1000 else a*1.05
print(int(a)) | 0 | null | 3,634,426,172,648 | 103 | 6 |
ans = 0
N = int(input())
for i in range(N):
a = int(input())
if a == 2:
ans += 1
elif a%2 == 0:
continue
else:
if pow(2, a-1, a) == 1:
ans += 1
print(ans) | x = int(input())
n = x // 100
if n * 105 >= x:
print(1)
else:
print(0) | 0 | null | 63,799,605,377,120 | 12 | 266 |
n = 0
list = []
while n < 10:
x = int(input())
list.append(x)
n += 1
list.sort()
print(list[9])
print(list[8])
print(list[7]) | a = []
for i in range(10) :
a.append(int(input()))
a.sort()
a.reverse()
print("%d\n%d\n%d" % (a[0], a[1], a[2])) | 1 | 32,200,820 | null | 2 | 2 |
w = str(input()).lower()
ans = 0
while True:
t = str(input())
if t == 'END_OF_TEXT': break
words = t.lower().split()
for word in words:
if word == w: ans += 1
print(ans)
| import sys
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
P = str(input()).upper()
line = []
while True:
tmp_line = str(input())
if tmp_line == 'END_OF_TEXT':
break
line += tmp_line.upper().split()
ans = 0
for tmp_word in line:
if tmp_word == P:
ans += 1
print("%d"%(ans))
| 1 | 1,840,924,044,330 | null | 65 | 65 |
k = int(input())
acl = "ACL"
print(acl*k) | def main():
k = int(input())
acl = 'ACL'
ans = ''
for i in range(k):
ans += acl
print(ans)
if __name__ == "__main__":
main() | 1 | 2,199,919,349,770 | null | 69 | 69 |
n = int(input())
d = {}
t = [0]*n
for i in range(n):
S,T = input().split()
d[S] = i
t[i] = int(T)
x = input()
idx = d[x]
print(sum(t[idx+1:]))
| import math
def lcm(a,b):
return (a*b)//math.gcd(a,b)
def co(num):
return format(num, 'b')[::-1].find('1')
N,M=map(int,input().split())
L=list(map(int,input().split()))
L2=[co(i) for i in L]
if len(set(L2))!=1:
print(0)
exit()
L=[i//2 for i in L]
s=L[0]
for i in range(N):
s=lcm(s,L[i])
c=M//s
print((c+1)//2) | 0 | null | 99,888,297,796,160 | 243 | 247 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.