code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
N ,K = map(int, input().split())
A = list(map(int, input().split()))
d = [0] * N
#二分探索
min1 = 0
max1 = max(A) + 1
while True:
X = (min1 + max1)//2
for i in range(N):
if A[i] % X == 0:
d[i] = A[i]//X - 1
else:
d[i] = A[i]//X
if sum(d) <= K:
max1 = X
else:
min1 = X
#print(min1, max1)
if max1 - min1 <= 1:
print(int(max1))
break
| n = int(input())
num_list = list(map(int, input().split()))
sets = set(num_list)
if len(num_list) == len(sets):
ans = 'YES'
else:
ans = 'NO'
print(ans) | 0 | null | 40,353,345,694,688 | 99 | 222 |
a,b,c,d = map(float,input().split())
print(abs(complex(c-a,d-b))) | def main():
N = int(input())
A_ls = map(int, input().split(' '))
ls = [0] * N
for i in A_ls:
ls[i - 1] += 1
for i in ls:
print(i)
if __name__ == '__main__':
main() | 0 | null | 16,218,752,089,772 | 29 | 169 |
N=int(input())
*A,=map(int,input().split())
M=max(A)
B=[1]*(M+1)
B[0]=B[1]=1
i=2
while i<=M:
if B[i]:
j=2
while i*j<=M:
B[i*j]=0
j+=1
i+=1
C=[0]*(M+1)
for a in A:
C[a]=1
from math import*
now=A[0]
for a in A:
now=gcd(now,a)
if now==1:
ans='pairwise coprime'
i=2
while i<=M:
if B[i]:
count=0
j=1
while i*j<=M:
count+=C[i*j]
j+=1
if count>1:
ans='setwise coprime'
i+=1
print(ans)
else:
print('not coprime') | import sys
from math import gcd
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
A = list(map(int, input().split()))
nowgcd = A[0]
# 全体のGCDを取る
for i in A:
nowgcd = gcd(nowgcd, i)
if nowgcd != 1:
print('not coprime')
exit()
# osa_k法で前処理
MAXN = 10**6 + 5
sieve = [i for i in range(MAXN + 1)]
p = 2
while p * p <= MAXN:
# まだチェックされていないなら
if sieve[p] == p:
# 次のqの倍数からp刻みでチェック入れていく
for q in range(2 * p, MAXN + 1, p):
if sieve[q] == q:
sieve[q] = p
p += 1
check = set()
for a in A:
tmp = set()
while (a > 1):
tmp.add(sieve[a])
a //= sieve[a]
for p in tmp:
if p in check:
print('setwise coprime')
exit()
check.add(p)
print('pairwise coprime')
| 1 | 4,084,213,198,692 | null | 85 | 85 |
# -*- coding: utf-8 -*-
def main():
S, W = map(int, input().split())
if S <= W:
ans = 'unsafe'
else:
ans = 'safe'
print(ans)
if __name__ == "__main__":
main() | S = input()
if S[-1] == "s":
S = S + "es"
print(S)
else:
S = S + "s"
print(S) | 0 | null | 15,845,264,258,518 | 163 | 71 |
S = len(input())
answer = ('x' * S)
print(answer) | t = input()
leng = len(t)
print('x' * leng) | 1 | 72,806,083,977,052 | null | 221 | 221 |
n = input()
A = map(int, raw_input().split())
q = input()
M = map(int, raw_input().split())
def solve(i, m):
if m == 0:
return True
if n <= i or sum(A) < m:
return False
x = (solve(i+1, m) or solve(i+1, m-A[i]))
return x
for m in M:
if solve(0, m):
print "yes"
else:
print "no" | N = int(input())
L = list(map(int, input().split()))
ans = 0
if N > 2:
for i in range(N - 2):
for j in range(i + 1, N - 1):
for k in range(j + 1, N):
tmp = [L[i], L[j], L[k]]
if (len(tmp) == len(set(tmp))) and (L[i] + L[j] > L[k]) and (
L[j] + L[k] > L[i]) and (L[k] + L[i] > L[j]):
ans += 1
print(ans) | 0 | null | 2,582,644,870,752 | 25 | 91 |
import sys
def main():
k = int(input())
a =7%k
if a == 0:
print(1)
sys.exit()
for i in range(2,10**7):
a = (10*a+7) % k
if a == 0:
print(i)
sys.exit()
print(-1)
main() | k=int(input())
if k%2==0 or k%5==0:
print(-1)
else:
i=1
t=7
while t%k!=0:
i+=1
t=(t*10+7)%k
print(i) | 1 | 6,119,682,386,390 | null | 97 | 97 |
X, Y = map(int, input().split(' '))
print('Yes' if (X * 2 <= Y <= X * 4) and (Y % 2 == 0) else 'No')
| x, y = list(map(int, input().split()))
if y % 2 == 0 and 2 * x <= y and y <= 4 * x:
print("Yes")
else:
print("No") | 1 | 13,737,755,218,762 | null | 127 | 127 |
import sys
line = sys.stdin.readline()
output = []
for i in range( len( line )-1 ):
c = ord( line[i] )
if ord( 'a' ) <= c and c <= ord( 'z' ):
c = chr( c ).upper()
elif ord( 'A' ) <= c and c <= ord( 'Z' ):
c = chr( c ).lower()
else:
c = chr( c )
output.append( c )
print( "".join( output ) ) | import string
print raw_input().translate(string.maketrans("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')) | 1 | 1,489,168,470,158 | null | 61 | 61 |
W,H,x,y,r = (int(i) for i in input().split())
answer = "Yes"
if x - r < 0 :
answer = "No"
elif y - r < 0 :
answer = "No"
elif x + r > W :
answer = "No"
elif y + r > H :
answer = "No"
print(answer) | W,H,x,y,r=map(int, input().split(" "))
if x<r or y<r or x+r>W or y+r>H :
print('No')
else :
print('Yes') | 1 | 454,187,102,498 | null | 41 | 41 |
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
N = int(input())
pos = []
zero = []
neg = []
for _ in range(N):
S = input().rstrip()
m = s = 0
for c in S:
if c == '(':
s += 1
else:
s -= 1
m = min(m, s)
if s > 0:
heappush(pos, (-m, s)) # take larger mins first
elif s == 0:
heappush(zero, (m, s))
else:
heappush(neg, (m - s, s)) # take smaller mins first
num = 0
while pos:
m, s = heappop(pos)
if num - m < 0:
print('No')
exit()
num += s
while zero:
m, s = heappop(zero)
if num + m < 0:
print('No')
exit()
while neg:
m, s = heappop(neg)
m += s
if num + m < 0:
print('No')
exit()
num += s
if num == 0:
print('Yes')
else:
print('No')
| N = int(input())
DG = {}
node_ls = []
is_visited = {}
#有効グラフをdictで管理することにする
for _ in range(N):
tmp = input().split()
node_id = tmp[0]
node_ls.append(node_id)
is_visited[node_id] = False
adj_num = int(tmp[1])#各頂点の次元が入っている
if adj_num != 0:
DG[node_id] = tmp[2:]
else:
DG[node_id] = []
d = {}#最初に発見したときの時刻を記録
f = {}#隣接リストを調べ終えたときの完了時刻を記録
t = 1
def dfs(node):
global t
#終了条件
if is_visited[node]:
return
is_visited[node] = True
d[node] = t
t += 1
for no in DG[node]:
dfs(no)
f[node] = t
t += 1
for node in node_ls:
dfs(node)
#print(d,f)
for node in node_ls:
print(node, d[node], f[node])
| 0 | null | 11,787,129,833,582 | 152 | 8 |
n=int(input())
print('Yes' if n>=30 else 'No') | S = input()
print(S[:3]) | 0 | null | 10,188,599,986,588 | 95 | 130 |
ST = list(map(str, input().split()))
word = ST[::-1]
print("".join(word)) | def resolve():
a, b = input().split()
print(b+a)
resolve() | 1 | 103,227,785,221,870 | null | 248 | 248 |
days = ('SUN','MON','TUE','WED','THU','FRI','SAT')
Day_of_the_week = input()
for index, day in enumerate(days):
if Day_of_the_week == day:
print(7 - index) | # A, Can'tWait for Holiday
# 今日の曜日を表す文字列Sが与えられます。
# Sは'SUN','MON','TUE','WED','THU','FRI','SAT'のいずれかであり、それぞれ日曜日、月曜日、火曜日。水曜日、木曜日、金曜日、土曜日を表します。
# 月の日曜日(あす以降)が何日後か求めてください。
# Sは'SUN','MON','TUE','WED','THU','FRI','SAT'のいずれか。
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)
else:print(7) | 1 | 133,229,818,960,050 | null | 270 | 270 |
d=input()
a,b,c=d.split()
if(int(a)<int(b)<int(c)):print('Yes')
else:print('No') | t = input().split()
if len(t) != 3:
raise ValueError("??´??°???3?????\?????????????????????")
a = int(t[0])
b = int(t[1])
c = int(t[2])
if a < b & b < c:
print("Yes")
else:
print("No") | 1 | 392,240,708,640 | null | 39 | 39 |
n = int(input())
S=[]
for i in range(n):
S.append(input())
S.sort()
c=1
for i in range(n-1):
if S[i]!=S[i+1] :
c+=1
print( c ) | from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
data = Counter(s)
print(len(data.keys())) | 1 | 30,307,593,815,264 | null | 165 | 165 |
from fractions import gcd
from functools import reduce
import numpy as np
def lcm_base(x, y):
return (x * y) // gcd(x, y)
def lcm(numbers):
return reduce(lcm_base, numbers, 1)
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: x // 2 , A))
A = np.array(A)
l = lcm(A)
if ((l//A % 2 == 1).sum() != N):
print(0)
else:
ans = (M//l + 1) // 2
print(ans) | from fractions import gcd
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [a[i]//2 for i in range(n)]
lcm_a = 1
for i in range(n):
lcm_a = (lcm_a * b[i]) // gcd(lcm_a, b[i])
for i in range(n):
if (lcm_a//b[i]) % 2 == 0:
print(0)
exit()
if m < lcm_a:
print(0)
else:
m -= lcm_a
print(1 + m // (lcm_a*2)) | 1 | 101,804,420,566,212 | null | 247 | 247 |
#dpでできないかな?
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
h,w=MI()
lis=[list(SI()) for i in range(h)]
al=[[-1]*w for i in range(h)]
dp=[[inf]*w for i in range(h)]
'''for i in range(h):
for j in range(w):
if lis[i][j]=="#":
dp[i][j]=-1'''
dp[0][0]= 0 if lis[0][0]=="." else 1
q=deque([[0,0]])
step=[[0,1],[1,0]]
#print(lis)
while q:
x,y=q.popleft()
if lis[x][y]==".":
state=1
else:
state=-1
for i,j in step:
if x+i>h-1 or y+j>w-1:
continue
elif state==1:
if al[x+i][y+j]<0:
al[x+i][y+j]=0
q.append([x+i,y+j])
if lis[x+i][y+j]=="#":
dp[x+i][y+j]=min(dp[x+i][y+j],dp[x][y]+1)
else:
dp[x+i][y+j]=min(dp[x+i][y+j],dp[x][y])
elif state==-1:
if al[x+i][y+j]<0:
al[x+i][y+j]=0
q.append([x+i,y+j])
dp[x+i][y+j]=min(dp[x+i][y+j],dp[x][y])
print(dp[-1][-1]) | INF = 10**9
def solve(h, w, s):
dp = [[INF] * w for r in range(h)]
dp[0][0] = int(s[0][0] == "#")
for r in range(h):
for c in range(w):
for dr, dc in [(-1, 0), (0, -1)]:
nr, nc = r+dr, c+dc
if (0 <= nr < h) and (0 <= nc < w):
dp[r][c] = min(dp[r][c], dp[nr][nc] + (s[r][c] != s[nr][nc]))
return (dp[h-1][w-1] + 1) // 2
h, w = map(int, input().split())
s = [input() for r in range(h)]
print(solve(h, w, s))
| 1 | 49,208,286,405,180 | null | 194 | 194 |
n = input()
xi = map(int, raw_input().split())
print ("%d %d %d") %(min(xi), max(xi), sum(xi)) | while True:
l = map(int, raw_input().split())
num = map(int, raw_input().split())
print "%d %d %d" % (min(num),max(num),sum(num))
break | 1 | 733,558,038,828 | null | 48 | 48 |
A, B = 0, 0
num = int(input())
for i in range(num):
a, b = input().split()
if a < b:
B += 3
elif a > b:
A += 3
else:
A += 1
B += 1
print(A, B)
| t=0
h=0
for i in range(int(input())):
l=input().split()
if l[0]==l[1]:
t+=1
h+=1
elif l[0]>l[1]: t+=3
else: h+=3
print(t,h) | 1 | 1,989,818,847,590 | null | 67 | 67 |
N, P = map(int, input().split())
S = [int(s) for s in input()]
if P == 2 or P == 5:
print(sum(i for i, s in enumerate(S, 1) if s % P == 0))
quit()
C = [0] * P
tens = 1
cur = 0
for s in reversed(S):
cur = (cur + s * tens) % P
C[cur] += 1
tens = (tens * 10) % P
print(C[0] + sum(c * (c - 1) // 2 for c in C)) | ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
n,p = mi()
s = input()
srev = s[::-1]
if p == 2 or p == 5:
ans = 0
for i in range(n):
if int(s[i]) % p == 0:
ans += i +1
print(ans)
exit()
acum = []
from collections import defaultdict
d = defaultdict(lambda :0)
d = [0] * p
num = 0
tenpow = 1
for i in range(0,n):
a = int(srev[i])
a = num + a *tenpow
tenpow = tenpow * 10 % p
modd = a % p
num = modd
d[modd] += 1
acum.append((modd,d[modd]))
ans = d[0]
for i in range(n):
ans += d[acum[i][0]] - acum[i][1]
print(ans)
| 1 | 58,248,597,470,492 | null | 205 | 205 |
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
n = int(input())
l_list = list(map(int, input().split()))
l_combo = itertools.combinations(l_list, 3)
ans = 0
for i in l_combo:
if i[0] + i[1] > i[2] and i[1]+i[2] > i[0] and i[0] + i[2] > i[1] and i[0] != i[1] and i[1] != i[2] and i[0] != i[2]:
ans += 1
print(ans)
| import sys
input=sys.stdin.readline
count=0
res=""
str=input()
list=[]
for i in range(len(str)):
list.append(str[i])
for i in range(len(str)):
if str[i]=="?":
if i==0:
if list[1]=="D":
list[0]="P"
else:
list[0]="D"
elif i+1==len(str):
list[i]="D"
else:
if list[i-1]=="P":
list[i]="D"
else:
if list[i+1]=="D" or list[i+1]=="?":
list[i]="P"
else:
list[i]="D"
for i in range(len(str)):
res+=list[i]
print(res)
| 0 | null | 11,766,488,016,800 | 91 | 140 |
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
U = max(A)+1
L = 0
def can(x, K):
ct = 0
for i in range(N):
ct += (A[i]-1)//x
if ct <= K:
return True
else:
return False
while U-L > 1:
x = (U+L+1)//2
if can(x, K):
U = x
else:
L = x
print(U)
| import sys
input = sys.stdin.readline
def main():
N = int(input())
ans = ''
while N > 0:
N -= 1
ans += chr(ord('a') + N % 26)
N = N // 26
print(ans[::-1])
main() | 0 | null | 9,220,624,523,780 | 99 | 121 |
N = int(input())
res = 0
cnt = 0
for i in range(N):
D = input().split()
if D[0] == D[1]:
cnt += 1
if cnt == 3:
res += 1
cnt = 0
else:
cnt = 0
if res > 0:
print('Yes')
else:
print('No') | # -*- coding: utf-8 -*-
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 998244353
class BIT2:
def __init__(self, N):
self.N = (N+1)
self.data0 = [0] * (N+1)
self.data1 = [0] * (N+1)
def _add(self, data, k, x):
while k < self.N: #k <= Nと同義
data[k] += x
k += k & -k
def _sum(self, data, k):
s = 0
while k:
s += data[k]
k -= k & -k
return s
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 sum(self, l, r):
return self._sum(self.data1, r-1) * (r-1) + self._sum(self.data0, r-1) - self._sum(self.data1, l-1) * (l-1) - self._sum(self.data0, l-1)
N, K = map(int, readline().split())
bit = BIT2(N)
d = []
for _ in range(K):
L,R = map(int, readline().split())
d.append((L,R))
bit.add(1,2,1)
for i in range(2,N+1):
for k in range(K):
L,R = d[k]
tmp = bit.sum(max(1,i-R),max(1,i-L+1))%MOD
bit.add(i,i+1,tmp)
print(bit.sum(N,N+1)%MOD) | 0 | null | 2,601,650,513,252 | 72 | 74 |
N, X, M = map(int, input().split())
visited = [False] * M
tmp = X
total_sum = X
visited[tmp] = True
total_len = 1
while True:
tmp = (tmp ** 2) % M
if visited[tmp]:
loop_start_num = tmp
break
total_sum += tmp
visited[tmp] = True
total_len += 1
path_len = 0
tmp = X
path_sum = 0
while True:
if tmp == loop_start_num:
break
path_len += 1
path_sum += tmp
tmp = (tmp ** 2) % M
loop_len = total_len - path_len
loop_sum = total_sum - path_sum
result = 0
if N <= path_len:
tmp = X
for i in range(N):
result += X
tmp = (tmp ** 2) % M
print(result)
else:
result = path_sum
N -= path_len
loops_count = N // loop_len
loop_rem = N % loop_len
result += loop_sum * loops_count
tmp = loop_start_num
for i in range(loop_rem):
result += tmp
tmp = (tmp ** 2) % M
print(result)
# print("loop_start_num", loop_start_num)
# print("path_sum", path_sum)
# print("loop_sum", loop_sum)
| K = int(input())
A, B = map(int, input().split())
exist = False
for i in range(A, B+1):
if i % K == 0:
exist = True
print('OK' if exist else 'NG') | 0 | null | 14,669,332,842,318 | 75 | 158 |
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for x in a:
for y in a:
ans = x * y
print(str(x)+'x'+str(y)+'='+str(ans))
| p =input()
if p[len(p) - 1] == 's':
print(p+'es')
else:
print(p+'s')
| 0 | null | 1,201,838,474,698 | 1 | 71 |
nkc = list(map(int, input().split()))
s = input()
ok = [i for i in range(nkc[0]) if s[i]=='o']
L = []
today = -1000000
for x in ok:
if x-today >= nkc[2]+1:
today = x
L.append(x)
if len(L) == nkc[1]:
break
R = []
today = 1000000
ok.reverse()
for x in ok:
if today-x >= nkc[2]+1:
today = x
R.append(x)
if len(R) == nkc[1]:
break
R.reverse()
for i in range(nkc[1]):
if L[i] == R[i]:
print(L[i]+1) | def f(s):
a=[-c]
for i,s in enumerate(s,1):
if s<'x'and a[-1]+c<i:a+=i,
return a[1:k+1]
n,s=open(0)
n,k,c=map(int,n.split())
for a,b in zip(f(s[:n]),f(s[-2::-1])[::-1]):
if a==n+1-b:print(a) | 1 | 40,637,086,711,450 | null | 182 | 182 |
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline.rstrip()
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return tuple(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n = inp()
P = inpl()
Q = inpl()
i = 0
a = 0
b = 0
for p in permutations(range(1,n+1)):
i += 1
if p == P:
a = i
if p == Q:
b = i
print(abs(a-b)) | from itertools import permutations
n = int(input())
l = [tuple(map(int,input().split())) for _ in range(2)]
a = list(permutations(range(1,n+1)))
print(abs(a.index(l[0]) - a.index(l[1]))) | 1 | 100,814,038,853,920 | null | 246 | 246 |
from itertools import combinations
N=int(input())
d=list(map(int,input().split()))
c=list(combinations(d,2))
ans=0
for i in range(len(c)):
a=c[i][0]*c[i][1]
ans+=a
print(ans)
| A,B,C,D=map(int,input().split())
while A>0 and C>0:
C-=B
A-=D
if C<=0:
print("Yes")
break
elif A<=0:
print("No")
| 0 | null | 99,371,095,050,512 | 292 | 164 |
S = str(input())
T = str(input())
lenS = len(S)
lenT = len(T)
splitS = []
for i in range(lenS - lenT +1):
tempS = S[i : i+lenT]
splitS.append(tempS)
answer = lenT
for tempS in splitS:
count = 0
for i in range(lenT):
if tempS[i] != T[i]:
count += 1
answer = min(answer, count)
print(answer) | n = int(input())
a = list(map(int,input().split()))
c = 0
for i in range(n):
j = i + 1
while j < n:
c = c + (a[i] * a[j])
j += 1
print(c) | 0 | null | 86,205,821,317,890 | 82 | 292 |
n=int(input())
s=list(input())
if n%2==1:
print("No")
elif s[:n//2]==s[n//2:n]:
print("Yes")
else:
print("No")
| n, k = map(int,input().split())
H = sorted(list(map(int, input().split())), reverse=True)
cnt = 0
for i in range(n):
if H[i] >= k:
cnt += 1
elif H[i] < k:
break
print(cnt) | 0 | null | 162,602,078,559,900 | 279 | 298 |
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = []
for i in range(k,n):
ans.append(a[i] - a[i-k])
for j in ans:
if j > 0:
print('Yes')
else:
print('No') | n=int(input())#nはデータセットの数
for i in range(n):#n回繰り返す
edge=input().split()#入力
edge=[int(j) for j in edge]#入力
edge.sort()#ここでedge[2]が最大になる
if(edge[0]**2+edge[1]**2==edge[2]**2):#直角三角形かどうか
print("YES")
else:#そうでないなら
print("NO") | 0 | null | 3,553,668,807,090 | 102 | 4 |
N = int(input())
P = list(map(int,input().split()))
Pm = P[0]
ans = 0
for i in range(N):
if P[i] <= Pm:
ans += 1
Pm = P[i]
print(ans) | AB = list(map(int, input().split()))
print(AB[0]*AB[1]) | 0 | null | 50,857,607,913,658 | 233 | 133 |
import sys
input = sys.stdin.readline
K, X = map(int, input().split())
print('Yes' if X <= 500 * K else 'No') | #! /usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)
YES = "Yes" # type: str
NO = "No" # type: str
INF=10**20
def solve(K: int, X: int):
print(YES if K*500 >= X else NO)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
K = int(next(tokens)) # type: int
X = int(next(tokens)) # type: int
solve(K, X)
if __name__ == "__main__":
main()
| 1 | 98,047,756,909,142 | null | 244 | 244 |
def main():
t = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
circle = a[0] * t[0] + a[1] * t[1] - b[0] * t[0] - b[1] * t[1]
if circle == 0:
print('infinity')
return
d = [0, 0]
cd = 0
ans = -1
for i in range(2):
d[i] = cd + a[i] * t[i] - b[i] * t[i]
if cd * d[i] <= 0:
ans += 1
cd = d[i]
if ans == 0:
print(0)
return
if circle < 0:
if d[0] > 0:
ans += d[0] // -circle * 2
if d[0] % (-circle) == 0:
ans -= 1
elif d[1] > 0:
ans += d[1] // -circle * 2
if d[1] % (-circle) == 0:
ans -= 1
else:
if d[0] < 0:
ans += -d[0] // circle * 2
if -d[0] % (circle) == 0:
ans -= 1
elif d[1] < 0:
ans += -d[1] // circle * 2
if -d[1] % (circle) == 0:
ans -= 1
print(ans)
main() | import sys
input = sys.stdin.readline
def main():
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
D1 = T1 * A1 + T2 * A2
D2 = T1 * B1 + T2 * B2
if D1 == D2:
print('infinity')
else:
if D2 > D1:
A1, B1 = B1, A1
A2, B2 = B2, A2
D1, D2 = D2, D1
M1 = T1 * A1
M2 = T1 * B1
if M1 > M2:
print(0)
else:
cnt = (M2 - M1) // (D1 - D2)
ans = cnt * 2
diff = (M2 - M1) % (D1 - D2)
if diff > 0:
ans += 1
print(ans)
if __name__ == '__main__':
main()
| 1 | 131,761,379,209,952 | null | 269 | 269 |
N = int(input())
A = [int(a) for a in input().split(" ")]
swop = 0
for i, a in enumerate(A):
j = N - 1
while j >= i + 1:
if A[j] < A[j - 1]:
tmp = A[j]
A[j] = A[j - 1]
A[j - 1] = tmp
swop += 1
j -= 1
print(" ".join([str(a) for a in A]))
print(swop) | # -*- coding:utf-8 -*-
def solve():
import math
a, b, x = list(map(int, input().split()))
if x > a*a*b/2:
s = x/a
# a*b-s = a*h*(1/2)
h = (a*b-s)*2/a
theta = math.atan2(h, a)
ans = math.degrees(theta)
print(ans)
else:
s = x/a
h = (s*2)/b
theta = math.atan2(h, b)
ans = 180-90-math.degrees(theta)
print(ans)
if __name__ == "__main__":
solve()
| 0 | null | 81,850,248,611,100 | 14 | 289 |
import sys
input = sys.stdin.readline
N, M, L = (int(i) for i in input().split())
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
graph = [[0]*N for i in range(N)]
for i in range(M):
a, b, c = (int(i) for i in input().split())
graph[a-1][b-1] = c
graph[b-1][a-1] = c
graph = csr_matrix(graph)
d = floyd_warshall(csgraph=graph, directed=False)
new_graph = [[0]*N for i in range(N)]
for i in range(N):
for j in range(N):
if d[i][j] <= L:
new_graph[i][j] = 1
new_graph[j][i] = 1
graph = csr_matrix(new_graph)
d = floyd_warshall(csgraph=graph, directed=False)
Q = int(input())
for i in range(Q):
s, t = (int(i) for i in input().split())
if d[s-1][t-1] == float("inf"):
print("-1")
else:
print(int(d[s-1][t-1]-1)) | # -*- coding: utf-8 -*-
"""
E - Travel by Car
https://atcoder.jp/contests/abc143/tasks/abc143_e
"""
import sys
from scipy.sparse.csgraph import floyd_warshall
def main(args):
N, M, L = map(int, input().split())
g1 = [[float('inf')] * (N+1) for _ in range(N+1)]
for i in range(N+1):
g1[i][i] = 0
for _ in range(M):
A, B, C = map(int, input().split())
g1[A][B] = g1[B][A] = C
d1 = floyd_warshall(g1)
g2 = [[float('inf')] * (N+1) for _ in range(N+1)]
for i in range(N+1):
for j in range(N+1):
if i == j:
g2[i][j] = 0
elif d1[i][j] <= L:
g2[i][j] = g2[j][i] = 1
d2 = floyd_warshall(g2)
Q = int(input())
for _ in range(Q):
s, t = map(int, input().split())
print(-1 if d2[s][t] == float('inf') else int(d2[s][t]) - 1)
if __name__ == '__main__':
main(sys.argv[1:])
| 1 | 172,959,870,914,108 | null | 295 | 295 |
X, N = map(int,input().split())
p_n = list(map(int,input().split()))
p = list(range(102))
for i in p_n:
for j in range(len(p)):
if p[j] == i:
p.pop(j)
break
p_X = list(map(lambda x: x - X, p))
p_abs = list(map(abs,p_X))
print(p[p_abs.index(min(p_abs))]) | X,N = map(int,input().split())
P = list(map(int,input().split()))
for n in range(100):
if X-n not in P:
print(X-n)
break
if X+n not in P:
print(X+n)
break | 1 | 14,128,439,632,000 | null | 128 | 128 |
import math
def abc173a_payment():
n = int(input())
print(math.ceil(n/1000)*1000 - n)
abc173a_payment() | import sys
for v in iter(sys.stdin.readline,""):
a,op,b = v.split()
a = int(a)
b = int(b)
if op == '+':
print(a+b)
elif op == '-':
print(a-b)
elif op == '*':
print(a*b)
elif op == '/':
print(a/b)
elif op == '?':
break | 0 | null | 4,616,460,147,548 | 108 | 47 |
input_line = input().rstrip().split(' ')
l = int(input_line[0])
r = int(input_line[1])
d = int(input_line[2])
output = 0
for i in range(l,r+1):
if i % d == 0:
output = output + 1
print(output) | t = raw_input()
s = t.split()
if s[0] == s[1]:
print "a == b"
else:
if int(s[0]) > int(s[1]):
print "a > b"
else:
print "a < b" | 0 | null | 3,964,078,163,040 | 104 | 38 |
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
mod = 10**9+7
def comb(n, k):
c = 1
for i in range(k):
c *= n - i
c %= mod
d = 1
for i in range(1, k + 1):
d *= i
d %= mod
return (c * pow(d, mod - 2, mod)) % mod
x,y = map(int, input().split())
if (x + y) % 3 != 0:
print(0)
exit()
n = (x + y) // 3
x -= n
y -= n
if x < 0 or y < 0:
print(0)
exit()
print(comb(x + y, x))
| import numpy as np
R = int(input())
print(R * 2 * np.pi) | 0 | null | 90,478,519,595,112 | 281 | 167 |
N = int(input())
P = list(map(int,input().split()))
P_min = []
a = 200000
ans = 0
for i in range(N):
if a >= P[i]:
ans += 1
a = P[i]
print(ans) | N, M = map(int, input().split())
ans = []
n = M // 2
m = 2 * n + 1
l = 2 * M + 1
for i in range(n):
ans.append([i + 1, m - i])
for i in range(M - n):
ans.append([m + i + 1, l - i])
for v in ans:
print(*v)
| 0 | null | 56,981,284,227,360 | 233 | 162 |
n = int(input())
AB = [[] * 2 for _ in range(n - 1)]
graph = [[] for _ in range(n + 1)]
for i in range(n - 1):
a, b = map(int, input().split())
AB[i].append(a)
AB[i].append(b)
graph[a].append(b)
graph[b].append(a)
root = 1
parent = [0] * (n + 1)
order = []
stack = [root] # 根を stack に入れる
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
color = [-1] * (n + 1)
for x in order:
ng = color[x]
c = 1
for y in graph[x]:
if y == parent[x]:
continue
if c == ng:
c += 1
color[y] = c
c += 1
res = []
for a, b in AB:
if parent[a] == b:
res.append(color[a])
else:
res.append(color[b])
print(max(res)) # root
print('\n'.join(map(str, res))) | import queue
n = int(input())
e = []
f = [{} for i in range(n)]
for i in range(n-1):
a,b = map(int, input().split())
a-=1
b-=1
e.append([a,b])
f[a][b]=0
f[b][a]=0
k = 0
for i in range(n-1):
k = max(k,len(f[i]))
q = queue.Queue()
q.put(0)
used = [[0] for i in range(n)]
while not q.empty():
p = q.get()
for key,c in f[p].items():
if c == 0:
if used[p][-1]<k:
col = used[p][-1]+1
else:
col = 1
f[p][key] = col
f[key][p] = col
used[p].append(col)
used[key].append(col)
q.put(key)
print(k)
for a,b in e:
print(max(f[a][b],f[b][a]))
| 1 | 136,189,883,281,882 | null | 272 | 272 |
R =int(input())
print(R*3.14159*2) | print(int(input())*6.28) | 1 | 31,310,342,402,624 | null | 167 | 167 |
from sys import stdin
import sys
import math
from functools import reduce
import itertools
n,m = [int(x) for x in stdin.readline().rstrip().split()]
check = [0 for i in range(n)]
count = [0 for i in range(n)]
for i in range(m):
p, q = [x for x in stdin.readline().rstrip().split()]
p = int(p)
if q == 'AC':
check[p-1] = 1
if q == 'WA' and check[p-1] == 0:
count[p-1] = count[p-1] + 1
for i in range(n):
if check[i] == 0: count[i] = 0
print(sum(check), sum(count))
| N,M=list(map(int, input().split()))
P=[0]*M
S=[0]*M
for i in range(M):
P[i],S[i]=list(input().split())
P[i]=int(P[i])
flagac=[False]*N
pnlt=[0]*N
for i in range(M):
p=P[i]-1
s=S[i]
if s=='AC':
flagac[p]=True
else:
pnlt[p]+=(flagac[p]+1)%2
# print(flagac)
# print(pnlt)
ctac=0
ctwa=0
for i in range(N):
if flagac[i]:
ctac+=1
ctwa+=pnlt[i]
print(ctac, ctwa) | 1 | 93,199,317,284,282 | null | 240 | 240 |
n=input()
t,h=0,0
for i in range(n):
a,b=raw_input().split()
if a>b: t+=3
elif a<b: h+=3
else:
t+=1
h+=1
print t,h | n = int(input())
t = 0
h = 0
for i in range(n):
taro,hana = input().split()
if taro == hana:
t += 1
h += 1
else:
m = list((taro,hana))
m.sort()
if m == list((taro,hana)):
h += 3
else:
t += 3
print("{} {}".format(t,h)) | 1 | 2,019,564,201,110 | null | 67 | 67 |
s = input()
if s == "RRR":
x = 3
elif s == "RRS" or s == "SRR":
x = 2
elif s == "SSS":
x = 0
else:
x = 1
print(x) | # https://atcoder.jp/contests/abc152/submissions/9693323
import sys
read = sys.stdin.read
N, *A = map(int, read().split())
mod = 10 ** 9 + 7
def min_factor(n):
sieve = list(range(n + 1))
sieve[2::2] = [2] * (n // 2)
for i in range(3, int(n ** 0.5) + 2, 2):
if sieve[i] == i:
sieve[i * i::2 * i] = [i] * ((n - i * i) // (2 * i) + 1)
return sieve
def prime_factorize(n):
a = {}
while n != 1:
b = table[n]
if b in a:
a[b] += 1
else:
a[b] = 1
n //= b
return a
table = min_factor(10**6)
dic = {}
for i in A:
for key, value in prime_factorize(i).items():
if key in dic:
dic[key] = max(dic[key], value)
else:
dic[key] = value
lcm = 1
for i, j in dic.items():
lcm *= pow(i, j, mod)
lcm %= mod
answer = sum(lcm * pow(i, mod - 2, mod) for i in A) % mod
print(answer)
| 0 | null | 46,136,344,648,450 | 90 | 235 |
print((float(input())**3)/27) | '''
自宅用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)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
def main():
n,m,k = map(int,ipt().split())
fl = [[] for i in range(n)]
bl = [set() for i in range(n)]
for i in range(m):
a,b = map(int,ipt().split())
fl[a-1].append(b-1)
fl[b-1].append(a-1)
for i in range(k):
c,d = map(int,ipt().split())
bl[c-1].add(d-1)
bl[d-1].add(c-1)
ans = [-1]*n
al = [True]*n
for i in range(n):
if al[i]:
q = [i]
al[i] = False
st = set([i])
while q:
qi = q.pop()
for j in fl[qi]:
if al[j]:
st.add(j)
al[j] = False
q.append(j)
lst = len(st)
for j in st:
tmp = lst-len(fl[j])-1
for k in bl[j]:
if k in st:
tmp -= 1
ans[j] = tmp
print(" ".join(map(str,ans)))
return None
if __name__ == '__main__':
main()
| 0 | null | 54,327,056,331,042 | 191 | 209 |
H,W = map(int,input().split())
if(H == 1 or W == 1):
print("1")
elif((H*W)%2 == 0):
print(str((H*W)//2))
else:
print(str((H*W)//2+1)) | n,k = map(int,input().split())
a = [0]*n
for _ in range(k):
kind = int(input())
for i in list(map(int,input().split())):
a[i-1] += 1
print(a.count(0) if 0 in a else 0) | 0 | null | 37,851,976,117,420 | 196 | 154 |
u,s,e,w,n,b = list(map(int, input().split()))
rolls = input()
for roll in rolls:
if roll == 'N':
n,u,e,w,b,s = u,s,e,w,n,b
elif roll == 'S':
s,b,e,w,u,n = u,s,e,w,n,b
elif roll == 'E':
e,s,b,u,n,w = u,s,e,w,n,b
elif roll == 'W':
w,s,u,b,n,e = u,s,e,w,n,b
else:
print('Error')
raise(-1)
print(u) | class Dice(object):
"""docstring for Dice"""
def __init__(self, numeric_column):
self.numeric_column=numeric_column
def roll_to_S_direction(self):
self.numeric_column=[self.numeric_column[4],self.numeric_column[0],self.numeric_column[2],self.numeric_column[3],self.numeric_column[5],self.numeric_column[1]]
def roll_to_N_direction(self):
self.numeric_column=[self.numeric_column[1],self.numeric_column[5],self.numeric_column[2],self.numeric_column[3],self.numeric_column[0],self.numeric_column[4]]
def roll_to_E_direction(self):
self.numeric_column=[self.numeric_column[3],self.numeric_column[1],self.numeric_column[0],self.numeric_column[5],self.numeric_column[4],self.numeric_column[2]]
def roll_to_W_direction(self):
self.numeric_column=[self.numeric_column[2],self.numeric_column[1],self.numeric_column[5],self.numeric_column[0],self.numeric_column[4],self.numeric_column[3]]
dice=Dice(map(int,raw_input().split()))
direction=raw_input()
for i in direction:
if i=='S': dice.roll_to_S_direction()
elif i=='N': dice.roll_to_N_direction()
elif i=='E': dice.roll_to_E_direction()
else: dice.roll_to_W_direction()
print dice.numeric_column[0] | 1 | 236,892,026,728 | null | 33 | 33 |
#!/usr/bin/env python3
import sys
import collections as cl
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
N = II()
graph = [[] for i in range(N)]
prev = [-1 for i in range(N)]
colors = {}
edges = []
for _ in range(N-1):
a, b = MI()
graph[a-1].append(b-1)
graph[b-1].append(a-1)
edges.append([a-1, b-1])
max_edge = 0
max_edge_idx = -1
for i in range(len(graph)):
length = len(graph[i])
if length >= max_edge:
max_edge = length
max_edge_idx = i
deque = cl.deque([max_edge_idx])
while len(deque) > 0:
target = deque.popleft()
pre = prev[target]
pre_key = (target, pre) if target < pre else (pre, target)
used_color = 0
if pre != -1:
used_color = colors[pre_key]
connecteds = graph[target]
color = 1
for connected in connecteds:
key = (target, connected) if target < connected else (
connected, target)
if key in colors:
continue
if color == used_color:
color += 1
colors[key] = color
prev[connected] = target
deque.append(connected)
color += 1
print(max_edge)
for edge in edges:
print(colors[(edge[0], edge[1])])
main()
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
N = int(input())
AB = [tuple(map(int,input().split())) for i in range(N-1)]
es = [[] for _ in range(N)]
for i,(a,b) in enumerate(AB):
a,b = a-1,b-1
es[a].append((b,i))
es[b].append((a,i))
ans = [None] * (N-1)
def dfs(v,p=-1,c=-1):
nc = 1
for to,e in es[v]:
if to==p: continue
if nc==c: nc += 1
ans[e] = nc
dfs(to,v,nc)
nc += 1
dfs(0)
print(max(ans))
print(*ans, sep='\n') | 1 | 135,675,034,242,176 | null | 272 | 272 |
n=int(input())
print((n/3)*(n/3)*(n/3)) | #!/usr/bin/env python3
import sys
import collections as cl
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
N = II()
print((N/3)**3)
main()
| 1 | 46,851,152,929,412 | null | 191 | 191 |
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
n,k=mp()
h=sorted(lmp())
if n<=k:
print(0)
else:
print(sum(h[:n-k])) | n, k = map(int, input().split())
H = list(map(int, input().split()))
H.sort(reverse=True)
H = H[k:]
print(sum(H))
| 1 | 79,450,249,650,980 | null | 227 | 227 |
n=int(input())
p=list(map(int,input().split()))
min_t=10**6
cnt=0
for i in range(n):
if min_t>=p[i]:
cnt+=1
min_t=min(min_t,p[i])
print(cnt) | n=int(input())
p=[int(x) for x in input().split()]
a=1
b=p[0]
for i in range(1,n):
if p[i-1]<b:
b=p[i-1]
if p[i]<=b:
a+=1
print(a) | 1 | 85,434,782,014,972 | null | 233 | 233 |
import math
x,k,d = map(int,input().split())
abs_x = abs(x)
max_len = math.ceil(abs_x/d)*d
min_len = max_len-d
if abs_x-k*d >= 0:
print(abs_x-k*d)
exit()
if (math.ceil(abs_x/d)-1)%2 == k%2:
print(abs(abs_x-min_len))
else:
print(abs(abs_x-max_len)) | # -*- coding: utf-8
x,k,d = map(int,input().split())
x = abs(x)
straight = min(k,x//d)
k -= straight
x -= straight*d
if k%2==0:
print(int(x))
else:
print(int(d-x)) | 1 | 5,238,680,953,990 | null | 92 | 92 |
#!/usr/bin/env python3
N = int(input())
D = [int(s) for s in input().split()]
life = 0
for i in range(N):
for j in range(i+1, N):
life += D[i] * D[j]
print(life)
| import sys
# from math import sqrt, gcd, ceil, log
# from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))
# sys.setrecursionlimit(10**6)
def solve():
n = int(input()); arr = read()
ans= 0
for i in range(n):
for j in range(i+1, n):
ans += arr[i]*arr[j]
print(ans)
if __name__ == "__main__":
solve()
| 1 | 168,602,700,602,860 | null | 292 | 292 |
import numpy as np
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
m = np.zeros(max(a)+1, dtype=int)
cnt = 0
for i in range(n):
x = a[i]
if i == n-1:
if m[x] == 0:
cnt +=1
else:
if m[x] == 0 and a[i] != a[i+1]:
cnt +=1
m[x::x] += 1
print(cnt) | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
#import numpy as np
from collections import Counter
def main():
n, *a = map(int, read().split())
if 1 in a:
count1 = a.count(1)
if count1 == 1:
print(1)
sys.exit()
else:
print(0)
sys.exit()
maxa = max(a)
seq = [0] * (maxa + 1)
ac = Counter(a)
for ae in ac.items():
if ae[1] == 1:
seq[ae[0]] = 1
for ae in a:
t = ae * 2
while t <= maxa:
seq[t] = 0
t += ae
r = sum(seq)
print(r)
if __name__ == '__main__':
main()
| 1 | 14,456,646,397,860 | null | 129 | 129 |
n,m = map(int,input().split())
A = list(map(int,input().split()))
judge = sum(A) / (4 * m)
ans = []
for i in range(n):
if A[i] < judge :
continue
else:
ans.append(A[i])
print("Yes") if len(ans) >= m else print("No") | n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [x for x in a if x >= sum(a)/4/m]
if len(b)>=m:
print("Yes")
else:
print("No")
| 1 | 38,523,681,046,240 | null | 179 | 179 |
def Reverse(str, A, B):
a = int(A)
b = int(B)
if a == 0:
str = str[0:a] + str[b::-1] + str[b + 1:]
else:
str = str[0:a] + str[b:a - 1:-1] + str[b + 1:]
return str
def Replace(str, a, b, c):
str2 = ''
Str = list(str)
for i in range(int(b) - int(a) + 1):
Str[i + int(a)] = c[i]
for i in range(len(Str)):
str2 += Str[i]
return str2
str = input()
n = int(input())
for i in range(n):
a = input()
A = a.split()
if A[0] == 'print':
print(str[int(A[1]):int(A[2]) + 1])
elif A[0] == 'reverse':
str = Reverse(str, A[1], A[2])
elif A[0] == 'replace':
str = Replace(str, A[1], A[2], A[3])
| n = int(input())
arr = [int(x) for x in input().split()]
d = {}
for ele in arr:
if ele in d:
d[ele] += 1
else:
d[ele] = 1
q = int(input())
s = sum(arr)
while(q>0):
a,b = [int(x) for x in input().split()]
if a in d:
x = d[a]
s -= int(x*a)
s += int(x*b)
d.pop(a)
if b in d:
d[b]+=x
else:
d[b] = x
print(s)
q-=1 | 0 | null | 7,123,564,919,200 | 68 | 122 |
mod = 998244353
n, s = map(int, input().split())
arr = list(map(int, input().split()))
dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
var = arr[i - 1]
for j in range(0, s + 1):
dp[i][j] = 2 * dp[i - 1][j]
dp[i][j] %= mod
if j - var >= 0 and dp[i - 1][j - var] != 0:
dp[i][j] += dp[i - 1][j - var]
dp[i][j] %= mod
print(int(dp[n][s]))
| import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 998244353
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
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 main():
N, S = LI()
a = LI()
dp = [[0 for _ in range(S+1)] for _ in range(N+1)]
for i in range(1, N+1):
dp[i][0] = dp[i-1][0] * 2 + 1
dp[i][0] %= mod
for i in range(N):
for j in range(1, S+1):
if j - a[i] >= 0:
dp[i+1][j] = (dp[i][j-a[i]] % mod) + (dp[i][j] * 2 % mod)
else:
dp[i+1][j] = dp[i][j] * 2 % mod
if j == a[i]:
dp[i+1][j] += 1
dp[i+1][j] %= mod
print(dp[N][S])
main()
| 1 | 17,649,906,280,330 | null | 138 | 138 |
import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]
#隣接リスト 1-order
def make_adjlist_d(n, edges):
res = [[] for _ in range(n + 1)]
for edge in edges:
res[edge[0]].append(edge[1])
res[edge[1]].append(edge[0])
return res
def make_adjlist_nond(n, edges):
res = [[] for _ in range(n + 1)]
for edge in edges:
res[edge[0]].append(edge[1])
return res
#nCr
def cmb(n, r):
return math.factorial(n) // math.factorial(r) // math.factorial(n - r)
def main():
N = NI()
A = NLI()
A = sorted(A)
ma = A[-1]
hurui = [0] * (ma + 10)
for a in A:
if hurui[a] == 0:
hurui[a] = 1
else:
hurui[a] = 10
for a in A:
if hurui[a] == 0:
continue
for i in range(a*2, ma+10, a):
hurui[i] = 0
print(hurui.count(1))
if __name__ == "__main__":
main() | x=[(i) for i in input().split()]
for i in range(len(x)-1):
print(x[i].swapcase(),"",end="")
print(x[len(x)-1].swapcase()) | 0 | null | 7,995,757,424,928 | 129 | 61 |
import math
a, b, x = map(float, input().split())
vol = a * a * b
if x <= vol/2:
height = (x * 2.0) / (b * a)
ans = math.atan(b / height) * 180 / math.pi
else:
height = ((vol - x) * 2.0) / (a * a)
ans = math.atan(height / a) * 180 / math.pi
print(ans) | import math
a, b, x = map(int, input().split())
c = x/a**2 # c : height of water
if c >= b/2:
tanth = 2*(b-c)/a
deg = math.atan(tanth)*180/math.pi
else:
tanth = b**2/(2*a*c)
deg = math.atan(tanth)*180/math.pi
print(deg) | 1 | 163,069,584,161,150 | null | 289 | 289 |
X, Y = tuple(map(int, input().split()))
# Calculate prize for "Coding Contest"
prize_code = 0;
if X == 1:
prize_code = 300000;
elif X == 2:
prize_code = 200000;
elif X == 3:
prize_code = 100000;
# Calculate prize for "Robot Maneuver"
prize_device = 0;
if Y == 1:
prize_device = 300000;
elif Y == 2:
prize_device = 200000;
elif Y == 3:
prize_device = 100000;
# Calculate prize for "two victories"
prize_both = 0
if X == 1 and Y == 1:
prize_both = 400000
# Calculate the sum and print the answer
prize_total = prize_code + prize_device + prize_both
print(prize_total) | X, Y = map(int, input().split())
ans = 0
if X <= 3:
ans += (4-X) * 100000
if Y <= 3:
ans += (4-Y) * 100000
if X == Y == 1:
ans += 400000
print(ans) | 1 | 140,409,572,327,652 | null | 275 | 275 |
from itertools import groupby
S=input()
T=groupby(S)
s=0
total=0
keys=[]
groups=[]
for key,group in T:
keys.append(key)
groups.append(len(list(group)))
if keys[0]==">":
total+=sum([i for i in range(groups[0]+1)])
if keys[-1]=="<":
total+=sum([i for i in range(groups[-1]+1)])
for i in range(len(keys)-1):
if keys[i]=="<":
if groups[i]<=groups[i+1]:
total+=sum([j for j in range(groups[i])])
total+=sum([j for j in range(groups[i+1]+1)])
else:
total+=sum([k for k in range(groups[i]+1)])
total+=sum([k for k in range(groups[i+1])])
print(total) | S = input()
l = len(S)
x = [0]*(l+1)
y = [0]*(l+1)
for i in range(l):
if S[i] == "<":
x[i+1] = x[i]+1
for i in range(l):
if S[l-i-1] == ">":
y[l-i-1] = y[l-i]+1
res = 0
for a, b in zip(x, y):
res += max(a, b)
print(res) | 1 | 156,366,274,263,760 | null | 285 | 285 |
W=input()
num=0
while True:
T=input()
t=str.lower(T)
if (T == 'END_OF_TEXT'):break
t_split=(t.split())
for i in range(len(t_split)):
if t_split[i] == W:
num+=1
print(num)
| def main():
n, k = map(int, input().split())
MOD = 10**9 + 7
a = [0]*(k+1)
for i in range(1, k+1):
a[i] = pow(k//i, n, MOD)
for i in reversed(range(1, k+1)):
for j in range(2*i, k+1, i):
a[i] -= a[j]
a[i] %= MOD
ans = 0
for i in range(1, k+1):
ans += a[i]*i
ans %= MOD
print(ans)
if __name__ == "__main__":
main() | 0 | null | 19,386,070,049,628 | 65 | 176 |
n = input()
result = ""
for x in xrange(1,n+1):
if x % 3 == 0:
result = result + " " + str(x)
elif x % 10 == 3:
result = result + " " + str(x)
else :
i = x
while i :
i /= 10
if i % 10 == 3:
result = result + " " + str(x)
break
print result | # -*- coding: utf-8 -*-
def call(n):
print '',
for i in xrange(1, n+1):
if check(i):
print(i),
print
def check(i):
if i % 3 == 0:
return True
elif i % 10 == 3:
return True
elif i / 10 > 0:
x = i
x /= 10
while (x > 0):
if x % 10 == 3:
return True
else:
x /= 10
return False
n = int(raw_input())
call(n) | 1 | 944,550,298,300 | null | 52 | 52 |
def main():
n, r = map(int, input().split(" "))
print(r+100*(10-min(10,n)))
if __name__ == "__main__":
main() | N,R = map(int,input().split())
if N <= 9:
R += 100*(10-N)
print(R) | 1 | 63,613,605,496,480 | null | 211 | 211 |
x=input()
x=str.swapcase(x)
print(x)
| while True:
n = list(map(int,input().split()))
if(n[0] == n[1] == 0):break
print(" ".join(map(str,sorted(n)))) | 0 | null | 999,925,920,590 | 61 | 43 |
n=int(input())
s=[0]*n
t=[0]*n
for i in range(n):
s[i],t[i]=input().split()
t[i]=int(t[i])
print(sum(t[s.index(input())+1:])) | x,y,z= map(str, input().split())
print(z,x,y, sep=' ') | 0 | null | 67,663,393,316,662 | 243 | 178 |
n, k = map(int, input().split())
data = list(map(int, input().split()))
ans = 0
for d in data:
if d >= k:
ans += 1
print(ans)
| import sys
N,K = map(int,input().split())
array_hight = list(map(int,input().split()))
if not ( 1 <= N <= 10**5 and 1 <= K <= 500 ): sys.exit()
count = 0
for I in array_hight:
if not ( 1 <= I <= 500): sys.exit()
if I >= K:
count += 1
print(count) | 1 | 178,995,429,588,800 | null | 298 | 298 |
def resolve():
n = int(input())
a = list(map(int, input().split()))
all_xor = 0
for ai in a:
all_xor ^= ai
ans = []
for ai in a:
ans.append(str(all_xor ^ ai))
print(' '.join(ans))
resolve() | x = input().split()
print(x.index('0') + 1) | 0 | null | 12,982,806,938,790 | 123 | 126 |
def bubble_sort(data):
for i in range(len(data) - 1):
for j in range(len(data) - 1, i, -1):
if int(data[j][1]) < int(data[j - 1][1]):
data[j], data[j - 1] = data[j - 1], data[j]
def selection_sort(data):
for i in range(len(data)):
min_j = i
for j in range(i, len(data)):
if int(data[j][1]) < int(data[min_j][1]):
min_j = j
if min_j != i:
data[i], data[min_j] = data[min_j], data[i]
input()
cards = [x for x in input().split()]
cards_b = cards.copy()
cards_s = cards.copy()
bubble_sort(cards_b)
selection_sort(cards_s)
for data in [cards_b, cards_s]:
print(' '.join(data))
if data == cards_b:
print("Stable")
else:
print("Not stable") | import sys
class Card:
def __init__(self, kind, num):
self.kind = kind
self.num = num
def __eq__(self, other):
return (self.kind == other.kind) and (self.num == other.num)
def __ne__(self, other):
return not ((self.kind == other.kind) and (self.num == other.num))
def __str__(self):
return self.kind + self.num
def list_to_string(array):
s = ""
for n in array:
s += str(n) + " "
return s.strip()
def swap(array, i, j):
tmp = array[i]
array[i] = array[j]
array[j] = tmp
def is_stable(array1, array2):
if reduce(lambda x, y: x and y, map(lambda x: x[0] == x[1], zip(array1, array2))):
return "Stable"
else:
return "Not stable"
def bubble_sort(array):
for i in range(0, len(array)):
for j in reversed(range(i+1, len(array))):
if array[j].num < array[j-1].num:
swap(array, j, j-1)
return array
def selection_sort(array):
for i in range(0, len(array)):
min_index = i
for j in range(i, len(array)):
if array[min_index].num > array[j].num:
min_index = j
swap(array, i, min_index)
return array
def main():
num = int(sys.stdin.readline().strip())
array = map(lambda x: Card(x[0], x[1]), sys.stdin.readline().strip().split(" "))
a = list(array)
b = list(array)
print list_to_string(bubble_sort(a))
print "Stable"
print list_to_string(selection_sort(b))
print is_stable(a, b)
if __name__ == "__main__":
main() | 1 | 23,661,675,660 | null | 16 | 16 |
import numpy as np
N=int(input())
A=input().split()
n=np.zeros(N)
for i in range(N-1):
n[int(A[i])-1]+=1
for l in n :
print(int(l)) | n = int(input())
pr = {}
for i in range(n):
s = input()
if pr != s:
pr[s] = True
print(len(pr))
| 0 | null | 31,534,498,396,768 | 169 | 165 |
a,b,c,k = map(int,input().split())
#l = [1 for i in range(a)] + [0 for i in range(b)] + [-1 for i in range(c)]
#ans = sum(l[:k])
if k <= a:
ans = k
elif (a < k) & (k <= a + b):
ans = a
elif (a + b < k) & (k <= a + b + c):
ans = a - (k - (a + b))
print(ans) | n,k = map(int, input().split())
price = list(map(int, input().split()))
count = 0
sum = 0
while count < k:
abc = min(price)
sum += abc
price.pop(price.index(abc))
count += 1
print(sum) | 0 | null | 16,656,040,614,080 | 148 | 120 |
bb = []
input()
aa = [ int(i) for i in input().split()]
for kk in aa[::-1]:
bb.append(kk)
print(' '.join(map(str, bb))) #map(func, iterable) | # -*- coding: utf-8 -*-
"""
Created on Thu May 7 00:03:02 2020
@author: shinba
"""
L = int(input())
L = L/3
print(L**3)
| 0 | null | 24,087,888,207,460 | 53 | 191 |
S = input()
Q= int(input())
r = False
h = []
t = []
for i in range(Q):
Query = input().split()
if int(Query[0]) == 1:
r = not r
else:
if int(Query[1]) == 1 and not r or int(Query[1]) == 2 and r:
h.append(Query[2])
else:
t.append(Query[2])
if not r:
print(''.join(reversed(h))+S+''.join(t))
else:
print(''.join(reversed(t))+S[::-1]+''.join(h))
| n = int(input())
taro = 0
hanako = 0
for ni in range(n):
t, h = input().split()
if t < h:
hanako += 3
elif t > h:
taro += 3
else:
hanako += 1
taro += 1
print(taro, hanako) | 0 | null | 29,660,936,998,548 | 204 | 67 |
# coding: utf-8
x=int(input())
i=1
while x!=0:
print("Case "+str(i)+": "+str(x))
x=int(input())
i+=1 | n = int(input())
a = [int(i) for i in input().split()]
a.reverse()
print(*a)
| 0 | null | 741,995,661,012 | 42 | 53 |
import sys,math
def is_prime_number(arg):
arg_sqrt=int(math.floor(math.sqrt(arg)))
i=2
while i <=arg_sqrt:
if arg %i ==0:
return False
i+=1
return True
n=0
prime_numbers=0
for line in sys.stdin:
l=int(line)
if n == 0:
n=l
continue
if is_prime_number(l):
prime_numbers+=1
print prime_numbers | import math
N = int(input())
ans = 0
def solve(x):
if x==2:
return 1
elif x%2==0:
return 0
else:
for i in range(3, math.ceil(math.sqrt(x)) + 1, 2):
if x%i ==0:
return 0
return 1
for i in range(N):
if solve(int(input())) ==1:
ans +=1
print(ans) | 1 | 11,011,245,490 | null | 12 | 12 |
s=[]
for i in input().split():
n=len(s)-1
if i=='+':s.append(s[n-1]+s[n]);s.pop(n-1);s.pop(n-1)
elif i=='-':s.append(s[n-1]-s[n]);s.pop(n-1);s.pop(n-1)
elif i=='*':s.append(s[n-1]*s[n]);s.pop(n-1);s.pop(n-1)
elif i=='/':s.append(s[n-1]/s[n]);s.pop(n-1);s.pop(n-1)
else:s.append(int(i))
print(*s)
| N=int(input())
*A,=map(int,input().split())
Q=int(input())
*M,=map(int,input().split())
mf=['no']*Q
t=[]
for i in range(0,2**N):
ans=0
for j in range(N):
if (i>>j&1):
ans+=A[j]
t.append(ans)
tset=set(t)
for i in range(Q):
if M[i] in tset:
mf[i] = 'yes'
for i in mf:
print(i)
| 0 | null | 70,159,196,492 | 18 | 25 |
import sys
n, m = map(int, sys.stdin.readline().split())
if n == m:
print('Yes')
else:
print('No') | def solve():
n, m = map(int, input().split())
print('YNeos'[n!=m::2])
if __name__ == '__main__':
solve()
| 1 | 83,199,537,555,748 | null | 231 | 231 |
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 isIncremental(a, b, c):
"""
a: int
b: int
c: int
returns "Yes" if a < b < c, otherwise "No"
>>> isIncremental(1, 3, 8)
'Yes'
>>> isIncremental(3, 8, 1)
'No'
>>> isIncremental(1, 1, 1)
'No'
"""
if a >= b:
return "No"
elif b >= c:
return "No"
else:
return "Yes"
if __name__ == '__main__':
# import doctest
# doctest.testmod()
ival = input().split(' ')
print(isIncremental(int(ival[0]), int(ival[1]), int(ival[2]))) | 0 | null | 202,893,383,538 | 11 | 39 |
S = input()
t = 'i'
for l in S:
if t == 'h' and l == 'i':
t = 'i'
elif t == 'i' and l == 'h':
t = 'h'
else:
print('No')
exit()
if t == 'h':
print('No')
exit()
print('Yes') | S=input()
ans='Yes'
i=0
while i<len(S):
if S[i:i+2]!='hi':
ans='No'
i+=2
print(ans) | 1 | 53,074,034,950,530 | null | 199 | 199 |
l = []
while True:
i = str(input())
if i == '0':
break
else:
l.append(i)
t = 0
for i in l:
t += 1
print('Case '+str(t)+': '+i)
| i=0
while 1:
a = int(input())
if a == 0 : break
i+=1
print "Case %d: %d" % (i, a) | 1 | 482,976,357,188 | null | 42 | 42 |
a,b=[],[]
for _ in range(int(input())):
x,y=map(int,input().split())
a+=[x-y]
b+=[x+y]
print(max(max(a)-min(a),max(b)-min(b))) | N, P = map(int, input().split())
S = input()
if P in [2, 5]:
ans = 0
for i, s in enumerate(S, 1):
if int(s) % P == 0:
ans += i
print(ans)
else:
dp = [0] * (N+1)
for i, s in enumerate(S, 1):
dp[i] = (dp[i-1]*10 + int(s)) % P
digit = 1
for i in range(N):
j = N - i
dp[j] = (dp[j] * digit) % P
digit = (digit * 10) % P
d = {}
ans = 0
for r in dp:
if r in d:
ans += d[r]
d[r] += 1
else:
d[r] = 1
print(ans) | 0 | null | 30,886,031,965,564 | 80 | 205 |
S = input()
length = len(S)
print('x' * length)
| s=input()
n=len(s)
a="x"
for i in range(n-1):
a+="x"
print(a)
| 1 | 72,519,558,216,250 | null | 221 | 221 |
r = int(input()) % 1000
print((1000 - r) % 1000) | from decimal import *
a,b = map(str,input().split())
a,b = Decimal(a),Decimal(b)
ans = a*b
print(int(ans)) | 0 | null | 12,572,399,933,128 | 108 | 135 |
n,k,c = list(map(int, input().split()))
s = input()
ls = list(s)
ortho = [0]*k
rever = [0]*k
a = 0
skip = []
for i in range(len(ls)):
if a >= k: break
if ls[i] == "o" and i not in skip:
ortho[a] = i
a += 1
skip = [i+j for j in range(1, c+1)]
a = 0
skip = []
ls.reverse()
for i in range(len(ls)):
if a >= k: break
if ls[i] == "o" and i not in skip:
rever[a] = i
a += 1
skip = [i+j for j in range(1, c+1)]
rever.reverse()
rever = [len(ls)-1-i for i in rever]
for i in range(k):
if ortho[i] == rever[i]:
print(ortho[i]+1) | import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
n,k=mp()
h=lmp()
ans=0
for i in range(n):
if h[i]>=k:
ans+=1
print(ans) | 0 | null | 109,998,217,615,858 | 182 | 298 |
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
if A < B:
if A + (V*T) >= B + (W*T):
print("YES")
else:
print("NO")
else:
if A - (V*T) <= B - (W*T):
print("YES")
else:
print("NO") | a=[0]*26
w='abcdefghijklmnopqrstuvwxyz'
try:
while True:
s=list(input().upper())
for i in s:
if i=='A':
a[0]+=1
elif i=='B':
a[1]+=1
elif i=='C':
a[2]+=1
elif i=='D':
a[3]+=1
elif i=='E':
a[4]+=1
elif i=='F':
a[5]+=1
elif i=='G':
a[6]+=1
elif i=='H':
a[7]+=1
elif i=='I':
a[8]+=1
elif i=='J':
a[9]+=1
elif i=='K':
a[10]+=1
elif i=='L':
a[11]+=1
elif i=='M':
a[12]+=1
elif i=='N':
a[13]+=1
elif i=='O':
a[14]+=1
elif i=='P':
a[15]+=1
elif i=='Q':
a[16]+=1
elif i=='R':
a[17]+=1
elif i=='S':
a[18]+=1
elif i=='T':
a[19]+=1
elif i=='U':
a[20]+=1
elif i=='V':
a[21]+=1
elif i=='W':
a[22]+=1
elif i=='X':
a[23]+=1
elif i=='Y':
a[24]+=1
elif i=='Z':
a[25]+=1
except EOFError:
pass
for i in range(26):
print(w[i:i+1], ':', str(a[i])) | 0 | null | 8,346,590,789,290 | 131 | 63 |
n = int(input())
s, t = input().split()
ans = ""
for i, j in zip(s, t):
ans += i + j
print(ans)
| N=int(input())
S,T=input().split()
list=[]
i=0
while i<N:
list.append(S[i])
list.append(T[i])
i=i+1
print(*list, sep='') | 1 | 112,350,582,292,310 | null | 255 | 255 |
x = raw_input()
x = int(x)
x = x * x * x
print x | n = int(input()) - 1 # n=n-1
print(sum([(n//x - x)*2 + 1 for x in range(1, int(n**0.5) + 1)]))
| 0 | null | 1,419,914,923,760 | 35 | 73 |
N,K=map(int,input().split())
A=[]
people=list(range(1,N+1,1))
for idx in range(K):
d=int(input())
X=list((map(int,input().split())))
for i in range(len(X)):
A.append(X[i])
ans =[i for i in people if not i in A]
print(len(ans)) | # A, Can'tWait for Holiday
# 今日の曜日を表す文字列Sが与えられます。
# Sは'SUN','MON','TUE','WED','THU','FRI','SAT'のいずれかであり、それぞれ日曜日、月曜日、火曜日。水曜日、木曜日、金曜日、土曜日を表します。
# 月の日曜日(あす以降)が何日後か求めてください。
# Sは'SUN','MON','TUE','WED','THU','FRI','SAT'のいずれか。
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)
else:print(7) | 0 | null | 79,015,997,789,398 | 154 | 270 |
import random
S=input()
r = random.randint(0,len(S)-3)
result =""
result = S[r]+S[r+1]+S[r+2]
print(result)
| n, m = map(int, input().split())
s = input()
s = s[::-1]
loc = 0
anslist=[]
while True:
if loc >= n-m:
anslist.append(n-loc)
break
quit()
next = m
while s[loc+next]=="1":
next-=1
if next == 0:
print(-1)
quit()
anslist.append(next)
loc+=next
ans=anslist[::-1]
ans = list(map(str, ans))
print(" ".join(ans)) | 0 | null | 76,972,603,111,606 | 130 | 274 |
n=int(input())
c=input()
d=c.count("R")
e=c[:d].count("R")
print(d-e) | n = int(input())
s = input().rstrip()
i=0
j=n-1
c= 0
while i!=j:
while s[j]!='R' and j>i:
j-=1
while s[i]=='R' and j>i:
i+=1
if i!=j:
c+= 1
i+= 1
j-=1
if i>=j:
break
print(c) | 1 | 6,338,229,464,648 | null | 98 | 98 |
x,y,z=map(int,input().split())
count=0
for i in range(x,y+1):
if(i%z==0):
count+=1
print(count)
| def count(n, d):
return n // d
def main():
L, R, d = map(int, input().split())
ans = count(R, d) - count(L - 1, d)
print(ans)
if __name__ == '__main__':
main()
| 1 | 7,560,960,263,072 | null | 104 | 104 |
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
A = []
for _ in range(int(input())):
x, l = map(int, input().split())
A.append((x - l, x + l))
A.sort(key = lambda x : x[1])
ans = 0
now = -INF
for l, r in A:
if now <= l:
now = r
ans += 1
print(ans)
resolve() | N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
H.sort(reverse=True)
s = 0
for i in range(K, N):
s += H[i]
print(s) | 0 | null | 84,793,878,283,322 | 237 | 227 |
n,k=map(int,input().split())
#階乗
F = 200005
mod = 10**9+7
fact = [1]*F
inv = [1]*F
for i in range(2,F):
fact[i]=(fact[i-1]*i)%mod
inv[F-1]=pow(fact[F-1],mod-2,mod)
for i in range(F-2,1,-1):
inv[i] = (inv[i+1]*(i+1))%mod
ans=1
for i in range(1,min(n,k+1)):
comb=(fact[n]*inv[i]*inv[n-i])%mod
h=(fact[n-1]*inv[i]*inv[n-1-i])%mod
ans=(ans+comb*h)%mod
print(ans) | n,k =list(map(int,input().split()))
mod = 10**9+7
ans = 1%mod
left_combination = 1
right_combination = 1
for i in range(1,min(k,n-1)+1):
left_combination = (left_combination*(n+1-i)*pow(i,mod-2,mod))%mod
right_combination = (right_combination*(n-i)*pow(i,mod-2,mod))%mod
ans = (ans + (left_combination*right_combination)%mod)%mod
print(ans) | 1 | 67,324,670,757,904 | null | 215 | 215 |
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
def root(x):
if par[x] == x:
return x
par[x] = root(par[x])
return par[x]
def unite(x,y):
x = root(x)
y = root(y)
if rank[x] < rank[y]:
par[x] = y
else:
par[y] = x
if rank[x] == rank[y]:
rank[x] += 1
n,m = LI()
rank = [0]*n
par = [i for i in range(n)]
for _ in range(m):
a,b = LI()
a -= 1
b -= 1
if root(a) != root(b):
unite(a,b)
cnt = [0]*n
for i in range(n):
cnt[root(i)] += 1
print(max(cnt))
return
#Solve
if __name__ == "__main__":
solve()
| # union find
def find_root(x):
if parent[x] == x:
return x
else:
return find_root(parent[x])
def unite(x, y):
'''x,yの属する集合の併合'''
x = find_root(x)
y = find_root(y)
if x != y:
if rank[x] < rank[y]:
parent[x] = y
size[y] += size[x]
else:
parent[y] = x
size[x] += size[y]
if rank[x] == rank[y]:
rank[x] += 1
def roots():
'''rootリストを返す'''
roots = []
for i in range(N):
roots.append(find_root(i))
return roots
def group_size(x):
'''xが所属するグループのサイズ'''
return size[find_root(x)]
# 入力
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
# 初期化
parent = [i for i in range(N)] # 根
rank = [1] * N # 深さ
size = [1] * N # iを根とするグループのサイズ
# 前処理
edge = [[ab[M - 1 - i][0] - 1, ab[M - 1 - i][1] - 1] for i in range(M)]
# 結合
for i in range(M):
unite(edge[i][0], edge[i][1])
ans = 0
for i in range(N):
ans = max(ans, group_size(i))
print(ans)
| 1 | 3,970,998,722,250 | null | 84 | 84 |
S=input()
flg = True
for i in range(len(S)):
if len(S)%2 == 1:
flg = False
break
if i%2==0:
if S[i]+S[i+1] != "hi":
flg = False
if flg == True:
print("Yes")
else:
print("No") | S = input()
if len(S) %2 == 1:
print("No")
exit()
for i in range(len(S)):
if S[i] != "hi"[i%2]:
print("No")
exit()
print("Yes") | 1 | 53,346,731,559,180 | null | 199 | 199 |
n = int(input())
card =[i+" "+str(j) for i in ["S","H","C","D"] for j in range(1,14)]
for i in range(n):
card.remove(input())
for i in card:
print(i)
| mod = 1000000007
n = int(input())
ans = pow(10, n, mod) - 2*pow(9, n, mod) + pow(8, n, mod)
print(ans % mod)
| 0 | null | 2,104,766,186,080 | 54 | 78 |
'''
着想:大きいaほど左右の端に移動したい、小さいaを先に端にやるより必ず大きくなるから
問題:単純に貪欲に大きいaから左端(x-1)と右端(N-x)の大きい方に移動すると、
残りのaの組み合わせ的に最適でない場合がある
アイテムの左右端の単純な割り振りはO(2^N)
解決策の着想:大きい順のk個を(k=L+R)となる
左L個右R個にどのように割り振っても(k+1)個目の最適な割り振り方は変わらない
解決策:アイテムk個左右に割り振る状態をdp[L][R]で保存O(N^2)
'''
def solve():
N = int(input())
A = [[a, i] for a,i in zip(map(int, input().split()), range(N))]
A.sort(key=lambda a: a[0], reverse=True)
dp = [[0]*(N+1) for _ in range(N+1)] # 左からxマス右からyマス埋める
for i in range(0,N):
a, l = A[i]
for x in range(0,i+1):
y = i - x # 合計x+y=iマス既に埋まっている、次にi+1マス目を考える
dp[x+1][y] = max(dp[x+1][y], dp[x][y] + a * abs(l - x))
dp[x][y+1] = max(dp[x][y+1], dp[x][y] + a * abs(l - (N-y-1)))
print(max(dp[N-i][i] for i in range(N+1)))
solve() | A,B,C,K=map(int,input().split())
ans=0
if A>K:
ans+=K
else:
ans+=A
if B>K-A:
ans+=0
else:
if (K-A-B)<C:
ans+=-(K-A-B)
else:
ans+=-C
print(ans) | 0 | null | 27,619,577,066,820 | 171 | 148 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.