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())
i=0
a=[]
while n!=0:
a.append(n%k)
n=n//k
i=i+1
print(len(a))
| n, k = map(int, input().split())
ans = 0
while n != 0:
n //= k
ans += 1
print(ans) | 1 | 64,503,200,001,508 | null | 212 | 212 |
from itertools import combinations as C
N = int(input())
d = list(map(int, input().split()))
D = list(C(d, 2))
ans = 0
for i in D:
ans += i[0] * i[1]
print(ans) | def main():
n = int(input())
d_lst = list(map(int, input().split()))
sum_d_lst = sum(d_lst)
ans = 0
for i in range(n):
ans += d_lst[i] * (sum_d_lst - d_lst[i])
print(ans // 2)
if __name__ == "__main__":
main()
| 1 | 167,635,590,471,910 | null | 292 | 292 |
N = int(input())
_L = list(map(int,input().split()))
L =[(v,i) for i,v in enumerate(_L)]
L = sorted(L,key = lambda x:(-x[0],x[1]))
dp = [[0]*(N+1) for _ in range(N+1)]
for i in range(N):#i番目の数字まで見た
for k in range(N):#k回(i-pi)のパターン
if k>i:
continue
val,ind = L[i]
dp[i+1][k+1] = max(dp[i+1][k+1],dp[i][k] + val * abs(ind-k))#先頭からk番目に動かす
dp[i+1][k] = max(dp[i+1][k],dp[i][k]+val * abs(N-1-(i-k)-ind))#すでに後ろからi-k個は使ってる=>後ろからN- (i-k)+1番目に動かす
print(max(dp[-1]))
|
"""
Writer: SPD_9X2
https://atcoder.jp/contests/abc163/tasks/abc163_e
dpか?
なにを基準にdpすればよい?
まとめられる状態は?
小さいことを考えると貪欲かなぁ
かいてみるか
挿入dp?
前から決めていけば、累積和で減る量がわかる
&増える寄与も計算できる
O(N**2)
全探索はむり
======答えを見ました======
今より右に行く、左に行くの集合に分けたとすると
大きい奴をより左にする方が最適
よって、途中まで単調減少、途中から単調増加が最適であるとわかる
dp[大きい方からi番目まで見た][左にl個つめた] = 最大値
で解ける
"""
N = int(input())
A = list(map(int,input().split()))
ai = []
for i in range(N):
ai.append([A[i],i])
ai.sort()
ai.reverse()
ans = 0
dp = [ [float("-inf")] * (N+1) for i in range(N+1) ]
dp[0][0] = 0
for i in range(N):
na,nind = ai[i]
for l in range(i+1):
r = N-1-(i-l)
dp[i+1][l+1] = max(dp[i+1][l+1] , dp[i][l] + na*abs(nind-l) )
dp[i+1][l] = max(dp[i+1][l] , dp[i][l] + na*abs(nind-r) )
print (max(dp[N]))
| 1 | 33,871,984,328,732 | null | 171 | 171 |
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
x=a[i]
b[x-1]=i+1
print(*b) | n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
point = 0
flg=[0]*n
for i in range(n):
if t[i] == 'r' and flg[i] == 0:
point += p
elif t[i] == 's' and flg[i] == 0:
point += r
elif t[i] == 'p' and flg[i] == 0:
point += s
if i+k < n and t[i+k] == t[i]:
if t[i] == 'r' and flg[i] == 0:
flg[i+k] = 'r'
elif t[i] == 's' and flg[i] == 0:
flg[i+k] = 's'
elif t[i] =='p' and flg[i] == 0:
flg[i+k] = 'p'
print(point) | 0 | null | 143,646,873,373,850 | 299 | 251 |
def main():
n = int(input())
a = [0,0]
for i in range(1, n+1):
a[0] += 1
a[1] = a[1] + 1 if i % 2 != 0 else a[1]
print(a[1] / a[0])
if __name__ == '__main__':
main() | # 142 A
n = int(input())
odd = 0
for i in range(1, n+1):
if i % 2 != 0:
odd += 1
x = odd/n
print('%.10f' % x) | 1 | 177,134,917,728,100 | null | 297 | 297 |
n=int(input())
l=list(map(int,input().split()))
l.sort()
count=0
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
if l[i]+l[j]>l[k] and l[i]!=l[j] and l[j]!=l[k] and l[i]!=l[k]:
count+=1
print(count)
| import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
H, W = map(int, input().split())
I = [list(map(str, input())) for _ in range(H)]
dp = [[0] * W for _ in range(H)]
for i in range(H):
for j in range(W):
if i == 0 and j == 0:
continue
if i == 0:
dp[i][j] = dp[i][j-1] if I[i][j] == I[i][j-1] else dp[i][j-1] + 1
continue
if j == 0:
dp[i][j] = dp[i-1][j] if I[i][j] == I[i-1][j] else dp[i-1][j] + 1
continue
dp[i][j] = dp[i][j-1] if I[i][j] == I[i][j-1] else dp[i][j-1] + 1
if I[i][j] == I[i-1][j]:
dp[i][j] = min(dp[i][j], dp[i-1][j])
else:
dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
t = dp[-1][-1]
if I[0][0] == "#":
t += 1
ans = -(-t//2)
print(ans)
| 0 | null | 27,208,221,699,168 | 91 | 194 |
import sys
from collections import deque
n,m=map(int,input().split())
s=input()
if n<=m:
print(n)
sys.exit()
lst=[0]*(n+1)
for i in range(1,m+1):
if s[i]=="0":
lst[i]=i
left=1
right=m+1
k=0
while left<n:
if s[left]=="0":
while right-left<=m:
if s[right]=="0":
lst[right]=right-left
right+=1
if right==n+1:
k=n
break
left+=1
if left==right or k==n:
break
if lst[n]==0:
print(-1)
else:
ans=deque([])
while k>0:
c=lst[k]
ans.appendleft(c)
k-=c
print(*ans) | n,m = map(int,input().split())
s = input()
ans = []
p = n
flag = 1
while flag:
for j in range(m,0,-1):
if p-j<=0:
ans.append(p)
flag = 0
break
elif s[p-j]=='0':
ans.append(j)
p-=j
break
elif j == 1:
ans.append(-1)
flag = 0
break
print(' '.join(map(str,reversed(ans))) if ans[-1]!=-1 else -1)
| 1 | 138,797,339,480,900 | null | 274 | 274 |
import math
x1, y1, x2, y2 = map(float, input().split())
x = x2 - x1
y = y2 - y1
result = x**2 + y**2
print(math.sqrt(result)) | x,y,xx,yy=map(float, input().split())
print('%5f'%((x-xx)**2+(y-yy)**2)**0.5) | 1 | 157,231,097,198 | null | 29 | 29 |
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
M = list(map(int,input().split()))
def bitsearch():
nums = [0] * (2 ** N)
for i in range(2 ** N):
num = 0
for j in range(N):
if (i >> j) & 1:
num += A[j]
nums[i] = num
for q in range(Q):
if M[q] in nums:
print("yes")
else:
print("no")
bitsearch()
| n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
memory = [[-1 for i in range(max(m)+1)]for j in range(n)]
def f(i, m):
if m == 0:
return 1
elif i >= n:
return 0
elif memory[i][m] != -1:
return memory[i][m]
elif m - a[i] >= 0:
res0 = f(i+1, m)
res1 = f(i+1, m-a[i])
if res0 or res1:
memory[i][m] = 1
return 1
else:
memory[i][m] = 0
return 0
else:
res = f(i+1, m)
memory[i][m] = res
return res
for k in m:
print('yes' if f(0, k) else 'no')
| 1 | 103,014,900,548 | null | 25 | 25 |
def A():
n, x, t = map(int, input().split())
print(t * ((n+x-1)//x))
def B():
n = list(input())
s = 0
for e in n:
s += int(e)
print("Yes" if s % 9 == 0 else "No")
def C():
int(input())
a = list(map(int, input().split()))
l = 0
ans = 0
for e in a:
if e < l: ans += l - e
l = max(l, e)
print(ans)
A()
| N, X, T = map(int, input().split())
ANS = -(-N // X) * T
print(ANS) | 1 | 4,241,177,489,430 | null | 86 | 86 |
from math import *
a, b, C = (int(i) for i in input().split())
C = pi * C / 180
c = sqrt(a**2 + b**2 - 2 * a * b * cos(C))
h = b * sin(C)
S = a * h / 2
L = a + b + c
print("{:.8f} {:.8f} {:.8f}".format(S, L, h)) | n = int(input())
A = []
B = []
for i in range(n):
a, b = map(int, input().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
if n % 2:
l = A[n // 2]
r = B[n // 2]
ans = r - l + 1
print(ans)
else:
l = A[n // 2 - 1] + A[n // 2]
r = B[n // 2 - 1] + B[n // 2]
ans = r - l + 1
print(ans)
| 0 | null | 8,832,944,361,120 | 30 | 137 |
def bubbleSort(A, N):
count = 0
for j in range(N - 1):
for i in reversed(range(j + 1, N)):
if A[i - 1] > A[i]:
temp = A[i]
A[i] = A[i - 1]
A[i - 1] = temp
count = count + 1
for i in range(N):
print A[i],
print
print count
N = input()
A = map(int, raw_input().split())
bubbleSort(A, N) | def bubble(A,N):
flag=1
cnt=0
while flag==1:
flag=0
for j in range(1,N):
if A[j]<A[j-1]:
k=A[j-1]
A[j-1]=A[j]
A[j]=k
flag=1
cnt+=1
return A,cnt
n=int(raw_input())
list=map(int,raw_input().split())
list,cnt=bubble(list,n)
for x in list:
print x,
print
print cnt, | 1 | 17,920,077,682 | null | 14 | 14 |
x, N = map(int, input().split())
p = list(map(int, input().split()))
min =10000
temp = 0
num = 10000
for i in range(-1000, 1000):
temp = abs(x- i)
if temp < min and i not in p:
min = temp
num = i
print(num)
| N = int(input())
S = input()
plus = N % 26
result = ''
for c in S:
next = ord(c) + plus
result += chr(next - 26) if next > 90 else chr(next)
print(result)
| 0 | null | 74,070,507,909,574 | 128 | 271 |
N, M = list(map(int, input().split()))
A = list(map(lambda x: int(x),input().split()))
cnt = [0 for _ in range(N)]
for i in range(N):
a = A[i]
while a%2 == 0:
a = a // 2
cnt[i] += 1
if max(cnt) > min(cnt):
print(0)
exit(0)
C = max(cnt)
A = list(map(lambda x: x // pow(2,C), A))
def gcd(a,b):
if a<b:
a,b = b,a
while a%b > 0:
a,b = b,a%b
return b
def lcm(a,b):
return a*b//gcd(a,b)
x = A[0]
for a in A[1:]:
x = lcm(x,a)
x = x * pow(2,C-1)
print((M // x + 1) // 2) | import math
from functools import reduce
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm(*numbers):
return reduce(lcm_base, numbers, 1)
def div2_n(x):
n = 0
while x % 2 == 0:
if x % 2 == 0:
n += 1
x >>= 1
return n
n, m = map(int, input().split())
a = list(map(int, input().split()))
a2 = [i//2 for i in a]
n0 = div2_n(a2[0])
for i in range(1,n):
if div2_n(a2[i]) != n0:
print(0)
exit()
a2_l = lcm(*a2)
print(m//a2_l - m//(a2_l*2))
| 1 | 101,808,351,116,540 | null | 247 | 247 |
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(0,n):
b[a[i]-1]=i+1
ans=''
for i in range(n):
ans+=str(b[i])+' '
print(ans) | N = int(input())
A = list(map(int, input().split()))
d = []
for n in range(N):
d.append([A[n], n])
d = sorted(d, key=lambda x:x[0])
for i, j in d:
print(j+1, end=" ") | 1 | 181,322,186,848,884 | null | 299 | 299 |
from math import gcd
N, M = map(int, input().split())
A = [a//2 for a in map(int, input().split())]
lcm = 1
for a in A:
lcm = lcm*a//gcd(lcm, a)
if lcm > M:
print(0)
exit()
for a in A:
div = lcm//a
if div % 2 == 0:
print(0)
exit()
ans = (M//lcm+1)//2
print(ans)
| N,S=int(input()),input()
r,g,b=0,0,0
for i in list(S):
if i=='R':r+=1
if i=='G':g+=1
if i=='B':b+=1
ans=r*g*b
for i in range(N-2):
for j in range(i+1,N-1):
if j-i>N-j-1:break
if S[i]!=S[j]and S[j]!=S[2*j-i]and S[2*j-i]!=S[i]:
ans-=1
print(ans) | 0 | null | 68,658,453,469,298 | 247 | 175 |
x = 1
y = 1
while x != 0 or y != 0:
n = map(int,raw_input().split())
x = n[0]
y = n[1]
if x == 0 and y == 0:
break
elif x <= y:
print x,y
elif x > y:
print y,x | while 1:
x, y = map(int, raw_input().split())
if x == 0 and y == 0:
break
print min(x, y),
print max(x, y) | 1 | 526,422,900,080 | null | 43 | 43 |
mountain = [int(input()) for _ in range(10)]
mountain.sort()
for _ in -1, -2, -3 : print(mountain[_]) | a = [int(input()) for i in range(10)]
a.sort()
for i in range(1, 4):
print(a[-i]) | 1 | 43,192,320 | null | 2 | 2 |
a, b, k = map(int, input().split())
if a>=k:
print(a-k,b)
elif a<k and a+b>k:
print(0,b-(k-a))
else:
print(0,0) |
A,B,K=map(int, input().split())
if A >= K:
print(f'{A-K} {B}')
elif (A+B) >= K:
print(f'0 {B-(K-A)}')
else:
print('0 0') | 1 | 104,258,926,112,088 | null | 249 | 249 |
a, b = list(map(int, input().split()))
my_result = a*b
print(my_result) | n,k=map(int,input().split())
p=list(map(int,input().split()))
a=[0]*n
b=[0]*n
for i in range(n):
a[i]=(p[i]+1)/2
b[0]=a[0]
for i in range(1,n):
b[i]=b[i-1]+a[i]
ans=b[k-1]
for i in range(1,n-k+1):
ans=max(ans,b[i+k-1]-b[i-1])
print(ans) | 0 | null | 45,238,869,774,432 | 133 | 223 |
import itertools
N = int(input())
D = list(input().split())
a = itertools.combinations(D,2)
sum= 0
for i,j in a:
sum += eval("{} * {}".format(i,j))
print(sum) | import sys, bisect, math, itertools, string, queue, copy
#import numpy as np
#import scipy
from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# from fractions import gcd
# input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
s = input()
q = int(input())
ql = [input().split() for i in range(q)]
ans = deque(s)
isrev=False
for i in range(q):
if ql[i][0] == '1':
isrev = not isrev
continue
if (ql[i][1] == '2') == isrev:
ans.appendleft(ql[i][2])
else:
ans.append(ql[i][2])
if isrev:
ans.reverse()
s = ''.join(ans)
print(s)
| 0 | null | 112,992,887,352,198 | 292 | 204 |
import math
t1,t2 = map(int,(input().split(' ')))
a1,a2 = map(int,(input().split(' ')))
b1,b2 = map(int,(input().split(' ')))
n = t1*a1+t2*a2
m = t1*b1+t2*b2
if(n==m):
print("infinity")
exit(0)
ans1 = max(0,math.ceil((b1-a1)*t1/(n-m)))
ans2 = max(0,math.ceil((t1*(b1-a1)+t2*(b2-a2))/(n-m))-1)
#if((t1*(b1-a1))%(n-m) == 1):
# ans3 = 1
#else:
# ans3 = 0
ans3 = max(0,math.floor(t1*(b1-a1)/(n-m))+1)
print(max(ans1+ans2+ans3-1,0)) | n = int(input())
A = list(map(int,input().split()))
def factorize(n):
fct = [] # prime factor
b, e = 2, 0 # base, exponent
while b * b <= n:
while n % b == 0:
n = n // b
e = e + 1
if e > 0:
fct.append((b, e))
b, e = b + 1, 0
if n > 1:
fct.append((n, 1))
return fct
def gcd(a, b):
while b:
a, b = b, a % b
return a
pc = True
fac = [0]*(10**6+1)
for a in A:
lst = factorize(a)
for p in lst:
if not fac[p[0]]:
fac[p[0]] = 1
else:
pc = False
break
if not pc:
break
if pc:
print('pairwise coprime')
else:
g = A[0]
for i in range(1,n):
g = gcd(g, A[i])
if g == 1:
print('setwise coprime')
else:
print('not coprime') | 0 | null | 68,146,180,624,728 | 269 | 85 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
S, T = readline().strip().split()
print(T + S)
return
if __name__ == '__main__':
main()
| import sys
a, b = sys.stdin.readline().split()
print(b+a) | 1 | 103,124,104,328,360 | null | 248 | 248 |
from collections import deque
n=int(input())
arr=[[] for _ in range(n)]
for i in range(n-1):
a,b=map(int,input().split())
arr[a-1].append([b-1,i])
arr[b-1].append([a-1,i])
que=deque([0])
ans=[0]*(n-1)
par=[0]*n
par[0]=-1
while que:
x=que.popleft()
p=par[x]
color=1
for tup in arr[x]:
if p==color:
color+=1
if ans[tup[1]]==0:
ans[tup[1]]=color
par[tup[0]]=color
color+=1
que.append(tup[0])
print(max(ans))
print(*ans,sep='\n') | # ['表面', '南面', '東面', '西面', '北面', '裏面']
dice = input().split()
com = [c for c in input()]
rolling = {
'E': [3, 1, 0, 5, 4, 2],
'W': [2, 1, 5, 0, 4, 3],
'S': [4, 0, 2, 3, 5, 1],
'N': [1, 5, 2, 3, 0, 4]
}
for c in com:
dice = [dice[i] for i in rolling[c]]
print(dice[0])
| 0 | null | 67,772,073,446,390 | 272 | 33 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
L=int(input())
print(L**3/27)
if __name__=='__main__':
main() | #!/usr/bin/env python3
n = int(input())
n /= 3
print(n**3) | 1 | 47,358,925,078,008 | null | 191 | 191 |
S = input()
ss = str()
for s in S:
ss = ss + s
if len(ss)==3:
print (ss)
break | s=input()
nn = s[0]+s[1]+s[2]
print(nn) | 1 | 14,761,489,255,260 | null | 130 | 130 |
n = int(input())
playlists = []
for _ in range(n):
title, playtime = input().split()
playlists.append([title, int(playtime)])
titles, playtimes = list(zip(*playlists))
lastmusic = input()
lastmusic_timing = titles.index(lastmusic)
print(sum(playtimes[lastmusic_timing + 1:])) | def resolve():
N = int(input())
s = []
t = []
for i in range(N):
S, T = input().split()
s.append(S)
t.append(int(T))
X = input()
print(sum(t[s.index(X)+1:]))
resolve() | 1 | 97,202,347,611,738 | null | 243 | 243 |
N = int(input())
for i in range(N):
a, b, c = map(int, input().split())
a2 = a ** 2
b2 = b ** 2
c2 = c ** 2
if a2 + b2 == c2 or a2 + c2 == b2 or b2 + c2 == a2:
print('YES')
else:
print('NO') | s=""
import fileinput
a=fileinput.input()
for i in a:
s+=i
s=list(s)
res=[0 for i in range(26)]
for i in s:
if i.isalpha():
i=i.lower()
res[ord(i)-ord("a")]+=1
for i in range(26):
s=chr(i+ord("a"))+" : "+str(res[i])
print(s) | 0 | null | 828,568,335,858 | 4 | 63 |
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) | N = int(input())
A = list([int(x) for x in input().split()])
xor_base = A[0]
for a in A[1:]:
xor_base ^= a
result = []
for a in A:
result.append(a ^ xor_base)
print(*result)
| 1 | 12,473,261,240,252 | null | 123 | 123 |
n = int(input())
l = [1]*(n+1)
l[0] = 0
ans = l[1]
for i in range(2,n+1):
for j in range(i,n+1,i):
l[j] += 1
ans += (l[i]*i)
print(ans)
| # Problem D - Sum of Divisors
# input
N = int(input())
# initialization
count = 0
# count
for j in range(1, N+1):
M = N // j
count += j * ((M * (M+1)) // 2)
# output
print(count)
| 1 | 11,075,604,754,360 | null | 118 | 118 |
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
n, r = inm()
print(r if n >= 10 else r + 100 * (10 - n)) | i = list(map(int, input().split()))
a = i[0]
b = i[1]
c = i[2]
answer = 0
for j in range(a, b + 1) :
if c % j == 0 :
answer += 1
print(answer) | 0 | null | 32,216,461,447,940 | 211 | 44 |
# 解説を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
import math
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, K, As):
ans = max(As)
l, r = 1, ans
for _ in range(30):
m = (l + r) // 2
cnt = 0
for A in As:
cnt += math.ceil(A / m) - 1
if cnt <= K:
ans = min(ans, m)
r = m - 1
else:
l = m + 1
if l > r:
break
print(ans)
if __name__ == '__main__':
# S = input()
# N = int(input())
N, K = map(int, input().split())
As = [int(i) for i in input().split()]
# Bs = [int(i) for i in input().split()]
solve(N, K, As)
| import heapq
import math
def solve():
N, K = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)
l = 0
r = A[0]
# (l, r]
#print(A)
#print("K=",K)
while r - l> 1:
m = (r + l) // 2
cuts = 0
for a in A:
cuts += (a-1) // m
#print(l, m,r, cuts)
if cuts <= K:
r = m
else:
l = m
print(r)
solve() | 1 | 6,505,735,024,672 | null | 99 | 99 |
n = str(input())
ns = n.swapcase()
print(ns)
| import math
k=int(input())
if(k%2)==0:
print("-1")
else:
flag=0
for x in range(1,1000001):
if (7%(9*k)*(pow(10,x,k*9)-1)%(9*k))==0:
print(x)
flag=1
break
if flag==0:
print(-1)
| 0 | null | 3,788,208,742,120 | 61 | 97 |
a, b = map(int, input().split(' '))
if a < b:
print('a < b')
elif a > b:
print('a > b')
else:
print('a == b')
| input_line = input().split()
a = int(input_line[0])
b = int(input_line[1])
if a > b:
symbol = ">"
elif a < b:
symbol = "<"
else:
symbol = "=="
print("a",symbol,"b") | 1 | 361,345,605,202 | null | 38 | 38 |
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
def f(n):
for i in range(50,-1,-1):
if n>=(i*(i+1)//2):
return i
break
n=int(input())
cnt=0
alist=factorization(n)
for i in range(len(alist)):
cnt+=f(alist[i][1])
if n==1:
cnt=0
print(cnt) | N = int(input())
if N == 1:
print(0)
exit()
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
def p_num(m):
ret = 0
for j in range(1,10**12):
ret += j
if ret <= m < ret+(j+1):
ans = j
break
return ans
p = factorization(N)
cnt = 0
for k in range(len(p)):
cnt += p_num(p[k][1])
print(cnt) | 1 | 16,988,231,995,670 | null | 136 | 136 |
Nin = int(input())
noguchi = (Nin // 1000)
if (Nin % 1000):
noguchi += 1
print(noguchi*1000 - Nin)
| N = input()
for i in range(1,12):
if i * 1000 - int(N) < 0:
continue
else:
print(i * 1000 - int(N))
break | 1 | 8,378,494,204,872 | null | 108 | 108 |
import math
x1,y1,x2,y2= map(float,(input().split()))
D=(x2-x1)**2+(y2-y1)**2
d= math.sqrt(D)
print(d) | 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 ) | 0 | null | 15,131,324,333,532 | 29 | 165 |
a,b=map(int, raw_input().split())
print a/b, a%b, "%.6f"%(float(a)/b) | while True:
x = []
x = input().split( )
y = [int(s) for s in x]
if sum(y) == -3:
break
if y[0] == -1 or y[1] == -1:
print("F")
elif y[0] + y[1] < 30:
print("F")
elif y[0] + y[1] >= 30 and y[0] + y[1] <50:
if y[2] >= 50:
print("C")
else:
print("D")
elif y[0] + y[1] >= 50 and y[0] + y[1] <65:
print("C")
elif y[0] + y[1] >= 65 and y[0] + y[1] <80:
print("B")
elif y[0] + y[1] >= 80:
print("A")
| 0 | null | 929,728,831,570 | 45 | 57 |
import sys
n = int(sys.stdin.readline())
dict = {}
for _ in range(n):
op, key = input().split()
if op == "insert":
dict[key] = "insert"
continue
if op == "find":
print("yes") if key in dict.keys() else print("no")
| s=input()
n=int(input())
for _ in range(n):
tmp=list(map(str,input().split()))
a,b=int(tmp[1]),int(tmp[2])+1
if tmp[0]=="print":
print(s[a:b])
elif tmp[0]=="reverse":
stmp=s[a:b]
s=s[:a]+stmp[::-1]+s[b:]
else:
p=tmp[3]
s=s[:a]+p+s[b:]
| 0 | null | 1,109,415,744,272 | 23 | 68 |
A,B,C,K=map(int,input().split())
print(1*min(A,K)-1*max(0,K-A-B))
| a,b,c,k= map(int,input().split())
ans=a
if k<a:
ans = k
if a+b<k:
ans = ans-k+a+b
print(ans) | 1 | 21,699,398,756,128 | null | 148 | 148 |
x = input().split()
a,b,c=[int(x) for x in x]
ans=0
for x in range(a,b+1):
if c%x==0:ans+=1
print(ans)
| import itertools
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
ANS = set()
for i in range(1,n+1):
A_pairs = list(itertools.combinations(A, i))
for j in range(len(A_pairs)):
ANS.add(sum(A_pairs[j]))
for i in range(q):
if m[i] in ANS:
print('yes')
else:
print('no')
| 0 | null | 329,077,514,240 | 44 | 25 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
p = [int(i)-1 for i in input().split()]
c = list(map(int, input().split()))
rc = [0] * n
rp = [0] * n
for i in range(n):
if rc[i]!=0:
continue
else:
nw = set([i])
np = c[i]
nx = p[i]
while not nx in nw:
nw.add(nx)
np += c[nx]
nx = p[nx]
cnt = len(nw)
for x in nw:
rc[x] = cnt
rp[x] = np
ret = - 10 ** 18
for i in range(n):
if rc[i] == 1:
if rp[i]>=0:
ret = max(ret, k*rp[i])
else:
ret = max(ret, rp[i])
continue
pseq = [0]
nx = p[i]
for j in range(1,rc[i]+1):
pseq.append(pseq[-1]+c[nx])
nx = p[nx]
pseq = pseq[1:]
if k <= rc[i]:
ret = max(ret, max(pseq[:k]))
elif rp[i] < 0:
ret = max(ret, max(pseq))
else:
tmp = max(pseq)
if k%rc[i]!=0:
tmp = max(tmp, rp[i] + max(pseq[:k%rc[i]]))
tmp += rp[i]*(k//rc[i]-1)
ret = max(ret, tmp)
print(ret)
| import sys
input = sys.stdin.readline
n,K=map(int,input().split())
p=list(map(lambda x:int(x)-1,input().split()))
c=list(map(int,input().split()))
if K == 1:
print(max(c));exit()
ans = -10**10
def cycle(k):
mo=k
clen=0
cscore=0
flg = True
cmax=[-10**10]
while (mo != k or flg):
clen+=1
cscore+=c[mo]
mo = p[mo]
cmax.append(max(cmax[-1],cscore))
if mo == k:
flg = False
if cscore<0:
return cmax[min(K-1,clen-1)]
return cscore*((K-1)//clen)+cmax[(K-1)%clen+1]
for i in range(n):
a=cycle(i)
if a>ans:
ans = a
print(ans)
| 1 | 5,382,423,792,108 | null | 93 | 93 |
n=int(input())
a=list(map(int, input().split()))
mi = n+2
ans = 0
for i in a:
if mi > i:
ans+=1
mi=min(i,mi)
print(ans) | S = input()
K = int(input())
INNER = 0
if len(set(list(S))) == 1:
print(K*len(S)//2)
else:
i = 0
while i < len(S)-1:
if S[i] == S[i+1]:
INNER += 1
i += 1
i += 1
if (S[0] != S[-1]):#最初の文字と最後の文字が違うなら、
print(INNER*K)
else:
same_from_start = 0
same_from_end = 0
count_from_start = 0
count_from_end = 0
flag_same_from_start = 0
flag_same_from_end = 0
while flag_same_from_start == 0:
if S[count_from_start] == S[count_from_start+1]:
count_from_start += 1
else:
count_from_start += 1
flag_same_from_start = 1
while flag_same_from_end == 0:
if S[len(S)-count_from_end-1] == S[len(S)-count_from_end-2]:
count_from_end += 1
else:
count_from_end += 1
flag_same_from_end = 1
print(INNER*K + (K -1) * ((count_from_start+count_from_end)//2 -\
count_from_start//2- count_from_end//2)) | 0 | null | 130,459,483,597,728 | 233 | 296 |
import sys
s = sys.stdin.readline().rstrip("\n")
print(s[:3]) | import math
from sys import stdin,stdout
#% 998244353
from heapq import heapify,heappop,heappush
import collections
s = stdin.readline()[:-1]
print(s[:3])
| 1 | 14,687,671,873,250 | null | 130 | 130 |
MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
S = sum(A) % MOD
ans = 0
for x in A:
S -= x
S %= MOD
ans += S * x
ans %= MOD
ans %= MOD
print(ans) | def main():
n = int(input())
xym, xyM, x_ym, x_yM = 10**9, -10**9, 10**9, -10**9
for _ in range(n):
x, y = map(int, input().split())
xy, x_y = x+y, x-y
xym, xyM, x_ym, x_yM = min(xym, xy), max(xyM, xy), min(x_ym, x_y), max(x_yM, x_y)
print(max(xyM-xym, x_yM-x_ym))
if __name__ == "__main__":
main() | 0 | null | 3,627,947,465,412 | 83 | 80 |
N=int(input())
ans=0
if ~N%2:
for i in range(1,30):
ans+=N//(10*5**i)
ans+=N//10
print(ans) | import math
n = int(input())
cnt = 0
mod = 10
if n%2 == 1:
print(0)
exit()
while mod<=n:
cnt += n//mod
mod*=5
print(cnt)
| 1 | 116,074,206,921,218 | null | 258 | 258 |
import sys
N, M = map(int,input().split())
S = input()
S = S[::-1]
i = 0
ans = []
while i < N:
flag = 0
for j in range(M,0,-1):
if i + j <= N and S[i + j] == '0':
i += j
flag = 1
ans.append(j)
break
if flag:
continue
print(-1)
sys.exit()
ans.reverse()
print(*ans) | n, m = map(int,input().split())
s = list(input())
s.reverse()
ng = False
c = 0
ans = []
while ng == False and c < n:
for i in range(m, 0, -1):
if c+i < n+1 and s[c+i] == '0':
c += i
ans.append(str(i))
break
elif i == 1:
ng = True
if ng:
print(-1)
else:
ans.reverse()
print(' '.join(ans))
| 1 | 139,446,967,351,908 | null | 274 | 274 |
N=input().split()
X=N[0]
Y=N[1]
Z=N[2]
print(Z + ' ' + X + ' ' + Y) | A,B,C=[i for i in input().split(" ")]
print(" ".join([C,A,B]))
| 1 | 38,254,694,649,444 | null | 178 | 178 |
while True:
a = input()
b = a.split(' ')
H = int(b[0])
W = int(b[1])
if H == 0 and W ==0:
break
for i in range(H):
c = '#'*W
print(c)
print() | # -*- coding: utf-8 -*-
import random
import sys
import os
import pprint
#fd = os.open('ALDS1_5_A.txt', os.O_RDONLY)
#os.dup2(fd, sys.stdin.fileno())
n = int(input())
A = list(map(int, input().split()))
# memo table T[i][m]
row_num = len(A)
column_num = 2000
T = [[None for i in range(column_num)] for j in range(row_num)]
#pprint.pprint(T)
def solve(i, m):
# out of index
if i >= len(A):
return False
if m < 0:
return False
if T[i][m] is not None:
return T[i][m]
if m == 0:
T[i][m] = True
elif m == A[i]:
T[i][m] = True
#elif i >= len(A):
# T[i][m] = False
elif solve(i+1, m):
T[i][m] = True
elif solve(i+1, m - A[i]):
T[i][m] = True
else:
T[i][m] = False
return T[i][m]
test_num = int(input())
test_values = map(int, input().split())
for v in test_values:
result = solve(0, v)
if result is True:
print('yes')
else:
print('no') | 0 | null | 425,762,877,568 | 49 | 25 |
from collections import deque
# end,cnt
dq = deque()
(n,d,a),*xh = [list(map(int, s.split())) for s in open(0)]
xh.sort()
total_bomb = 0
eff_bomb = 0
for x,h in xh:
while dq and dq[0][0] < x:
end, cnt = dq.popleft()
eff_bomb -= cnt
resid = h - eff_bomb * a
if resid > 0:
cnt = 0--resid//a
end = x + 2 * d
dq.append((end,cnt))
eff_bomb += cnt
total_bomb += cnt
print(total_bomb) | from math import atan, degrees
a,b,x= map(int,input().split())
yoseki = a**2*b
if x <= yoseki/2:
# b*y*a/2==x
y= 2*x/b/a
# 90からシータを引けば良い
print(90-degrees(atan(y/b)))
else:
# a*y*a/2==yoseki-x
y = 2*(yoseki-x)/a**2
print(degrees(atan(y/a)))
| 0 | null | 122,187,749,799,180 | 230 | 289 |
import sys
# input = sys.stdin.readline
def main():
S, T =input().split()
print(T,S,sep="")
if __name__ == "__main__":
main() |
s,t=map(str,input().split())
print(t+s,sep='') | 1 | 102,584,513,078,430 | null | 248 | 248 |
abc = input().split()
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])
# 12
if a > b:
a, b = b, a
# 13
if a > c:
a, c = c, a
# 23
if b > c:
b, c = c, b
print("{0} {1} {2}".format(a, b, c)) | n = int(input())
print(n//2 + (n % 2)*1)
| 0 | null | 29,863,436,019,888 | 40 | 206 |
first_flag = True
while True:
H, W = map(int, input().split())
if H == 0 and W == 0: break
if not first_flag:
print()
first_flag = False
print(("#" * W + "\n") * H) | n = int(input())
for i in range(1, n+1):
if i%3 == 0 or str(i).find('3') != -1:
print(f" {i}", end = '')
print()
| 0 | null | 839,467,351,392 | 49 | 52 |
import math
def factorization(n):
arr = []
temp = n
for i in range(2, int(math.ceil(n**0.5))):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i,cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
n = int(input())
if n == 1:
print(0)
exit(0)
fact_1i = factorization(n)
res = 0
for _, num in fact_1i:
temp_num = 1
while temp_num <= num:
res += 1
num -= temp_num
temp_num += 1
print(res) | 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:])) | 0 | null | 57,248,543,208,530 | 136 | 243 |
n, m = list(map(int, input().split()))
ac = [0] * n
wa = [0] * n
penalty = 0
for i in range(m):
p, s = list(input().split())
p = int(p)
if s == "AC" and ac[p - 1] == 0:
ac[p - 1] = 1
penalty += wa[p - 1]
if s == "WA":
wa[p - 1] += 1
print(sum(ac), penalty) | # シェルソート
N = int(input())
A = []
for i in range(N):
A.append(int(input()))
cnt = 0
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
for j in range(i-g, -1, -g):
if A[j+g] < A[j]:
A[j + g], A[j] = A[j], A[j + g]
cnt += 1
else:
break
def shellSort(A, n):
# gn+1 = 3gn + 1
h = 1
G = []
while h <= n:
G.append(h)
h = 3 * h + 1
G.reverse()
print(len(G))
print(" ".join([str(x) for x in G]))
for g in G:
insertionSort(A, n, g)
shellSort(A, N)
print(cnt)
for a in A:
print(a)
| 0 | null | 46,427,794,207,082 | 240 | 17 |
n = input()
s = input().split()
q = input()
t = input().split()
ans = 0
for c1 in t:
for c2 in s:
if c1 == c2:
ans += 1
break
print(ans) | #coding:utf-8
#1_4_A
def isFound(array, x):
""" linear search """
array.append(x)
i = 0
while array[i] != x:
i += 1
if i == len(array)-1:
return False
return True
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
count = 0
for i in range(q):
if isFound(S, T[i]):
count += 1
print(count) | 1 | 66,561,607,700 | null | 22 | 22 |
n = int(input())
*li, = map(int, input().split())
input()
*Q, = map(int, input().split())
bits = 1
for i in li:
# print(f"{i=}")
# print(f"{bin(bits)=}")
bits |= bits << i
# print(f"{bin(bits)=}")
# print()
# print()
for q in Q:
# print(f"{bin(bits)=}")
print("yes"*((bits >> q) & 1) or "no")
# print()
| N = int(input())
A = list(map(int, input().split()))
se = set()
for i in range(1<<N):
tot = 0
for j in range(N):
if i&(1<<j): tot += A[j]
se.add(tot)
_ = int(input())
Q = list(map(int, input().split()))
for q in Q:
if q in se:
print("yes")
else:
print("no")
| 1 | 98,480,734,340 | null | 25 | 25 |
n = int(input())
if n%2 == 1:
print(0)
else:
answer = 0
count = 1
n=n//2
while 5**count <= n:
answer += n//pow(5,count)
count+=1
print(answer) | import math , sys, bisect
N , M , K = list( map( int , input().split() ))
A = list( map( int , input().split() ))
B = list( map( int , input().split() ))
if N > M:
N , M = M , N
A, B = B , A
Asum=[0]
Bsum=[]
if A[0] > K and B[0] > K:
print(0)
sys.exit()
for i in range(N):
if i ==0:
tot = A[i]
else:
tot += A[i]
Asum.append(tot)
for i in range(M):
if i ==0:
tot = B[i]
else:
tot += B[i]
Bsum.append(tot)
#ans=bisect.bisect(Bsum,K)
ans=0
for i in range(N+1):
tot = Asum[i]
if tot > K:
print(ans)
sys.exit()
num = bisect.bisect(Bsum,K-tot)
if i + num >ans:
ans=i+num
print(ans) | 0 | null | 63,085,932,937,120 | 258 | 117 |
N, K = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
d = sum(p[0:K])
print(d) | n = input()
for i in range(n):
a, b, c = map(int, raw_input().strip().split(' '))
if a*a+b*b == c*c or a*a+c*c == b*b or c*c+b*b == a*a:
print "YES"
else:
print "NO" | 0 | null | 5,755,664,753,642 | 120 | 4 |
class Dice:
def __init__(self,u,s,e,w,n,d):
self.n = n
self.e = e
self.s = s
self.w = w
self.u = u
self.d = d
def roll(self,dir):
if (dir == "N"):
tmp = self.n
self.n = self.u
self.u = self.s
self.s = self.d
self.d = tmp
elif (dir == "E"):
tmp = self.e
self.e = self.u
self.u = self.w
self.w = self.d
self.d = tmp
elif (dir == "S"):
tmp = self.s
self.s = self.u
self.u = self.n
self.n = self.d
self.d = tmp
elif (dir == "W"):
tmp = self.w
self.w = self.u
self.u = self.e
self.e = self.d
self.d = tmp
spots = raw_input().split()
operations = raw_input()
dice = Dice(*spots)
for i in operations:
dice.roll(i)
print dice.u | s=list(input())
n=len(s)
ans=['x']*n
print(''.join(ans)) | 0 | null | 36,805,156,555,670 | 33 | 221 |
n, m = map(int, input().split())
l = list(map(int, input().split()))
l.sort(reverse=True)
n_vote = sum(l)
if l[m-1] >= n_vote/(4*m):
print('Yes')
else:
print('No') | N,M = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort(reverse=True)
if a[M-1]<sum(a)/(4*M):
print("No")
else:
print("Yes")
| 1 | 38,646,680,984,758 | null | 179 | 179 |
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if sum(A)+sum(B)<=k:
print(n+m)
exit()
for i in range(1,n):
A[i] += A[i-1]
for i in range(1,m):
B[i] += B[i-1]
from bisect import bisect_right
ans = bisect_right(B,k)
for i in range(n):
if A[i]>k:
break
ans = max(ans, i+1+bisect_right(B,k-A[i]))
print(ans) | n=int(raw_input())
ans=''
for i in range(1,n+1):
if i%3==0:ans+=" " + str(i)
else :
x=i
while x:
if x%10==3:
ans+=' '+str(i)
break
x/=10
print ans | 0 | null | 5,809,153,456,528 | 117 | 52 |
num = raw_input()
num = num.split()
a = int(num[0])
b = int(num[1])
if a < b:
print "a < b"
elif a > b:
print "a > b"
else:
print "a == b" | #A - Repeat ACL
K = int(input())
a = "ACL"*K
print(a) | 0 | null | 1,286,226,493,408 | 38 | 69 |
import sys
n,m=map(int,input().split())
ans=[0]*n
for i in range(m):
s,c=map(int,input().split())
s-=1
if ans[s]!=0 and ans[s]!=c:
print(-1)
sys.exit()
else:
ans[s]=c
if n==3 and m==1 and ans==[0,0,0]:
print(-1)
sys.exit()
if n!=1 and ans[0]==0:
ans[0]=1
for i in range(n):
ans[i]=str(ans[i])
print("".join(ans)) |
def main():
n, m = map(int, input().split(" "))
s = [0] * m
c = [0] * m
for i in range(m):
s[i], c[i] = map(int, input().split(" "))
ans = [-1] * n
for i in range(m):
if ans[s[i]-1] != -1 and ans[s[i]-1] != c[i]:
print(-1)
return
ans[s[i]-1] = c[i]
if ans[0] == 0:
if n == 1:
print(0)
return
print(-1)
return
for i in range(n):
if ans[i] == -1:
if i == 0:
if n == 1:
print(0)
return
print(1, end="")
else:
print(0, end = "")
else:
print(ans[i], end ="")
print()
if __name__ == "__main__":
main() | 1 | 60,751,430,969,460 | null | 208 | 208 |
a,b,c,d,e=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
e=int(e)
if a==0:
print('1')
elif b==0:
print('2')
elif c==0:
print('3')
elif d==0:
print('4')
elif e==0:
print('5') | x = list(map(int, input().split()))
for i, c in enumerate(x):
if c == 0:
print(i+1)
break
| 1 | 13,390,563,271,260 | null | 126 | 126 |
def DFS(n = 1, A = [0], i = 0, d = [0], f = [0], time = 1):
for j in range(n):
if A[i][j] == 1 and d[j] == 0:
time = time + 1
d[j] = time
time = DFS(n, A, j, d, f, time)
time = time + 1
f[i] = time
return time
n = int(raw_input())
A = [0] * n
for i in range(n):
A[i] = [0] * n
for i in range(n):
value = map(int, raw_input().split())
u = value[0] - 1
k = value[1]
nodes = value[2:]
for j in range(k):
v = nodes[j] - 1
A[u][v] = 1
d = [0] * n
f = [0] * n
time = 0
for i in range(n):
if d[i] == 0:
time = time + 1
d[i] = time
time = DFS(n, A, i, d, f, time)
for i in range(n):
print(str(i + 1) + " " + str(d[i]) + " " + str(f[i])) | import sys
sys.setrecursionlimit(10 ** 9)
N = int(input())
graph = list()
for i in range(N):
x = list(map(int, input().split()))
graph.append(x[2:])
start = [0] * N
end = [0] * N
visited = [False] * N
time = 0
def dfs(n):
if visited[n]:
return
visited[n] = True
global time
time += 1
start[n] = time
for i in graph[n]:
dfs(i-1)
time += 1
end[n] = time
for i in range(N):
dfs(i)
for i in range(N):
print(i+1, start[i], end[i])
| 1 | 2,481,132,248 | null | 8 | 8 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
P=[-1]*N#親から来た辺の色だけ持っておく
C=[0]*(N-1)
adj=[[]for _ in range(N)]
from collections import defaultdict
dd = defaultdict(lambda : -1)
dd2 = defaultdict(lambda : -1)
for i in range(N-1):
a,b=MI()
a-=1
b-=1
adj[a].append(b)
adj[b].append(a)
dd[(a,b)] = i
dd2[i]=(a,b)
import queue
q=queue.Queue()
q.put((0,-1))
while not q.empty():
v,p=q.get()
col=0
for i in range(len(adj[v])):
nv=adj[v][i]
if nv==p:
continue
if col==P[v]:
col+=1
a=min(v,nv)
b=max(v,nv)
ii=dd[(a,b)]
C[ii]=col
P[nv]=col
col+=1
q.put((nv,v))
K=0
for i in range(N):
K=max(K,len(adj[i]))
print(K)
for i in range(N-1):
print(C[i]+1)
main()
| # import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, ABs):
tree_top = [[] for _ in range(N + 1)]
for i in range(N - 1):
tree_top[ABs[i][0]].append(i)
tree_top[ABs[i][1]].append(i)
max_color = 0
for tt in tree_top:
max_color = max(max_color, len(tt))
ans = [0 for _ in range(N - 1)]
for tt in tree_top:
colored = []
for i in tt:
if ans[i] != 0:
colored.append(ans[i])
colored.sort()
now_color = 1
colored_point = 0
for i in tt:
if ans[i] != 0:
continue
if colored_point < len(colored) \
and now_color == colored[colored_point]:
now_color += 1
colored_point += 1
ans[i] = now_color
now_color += 1
print(max_color)
for a in ans:
print(a)
if __name__ == '__main__':
# S = input()
N = int(input())
# N, M = map(int, input().split())
# As = [int(i) for i in input().split()]
# Bs = [int(i) for i in input().split()]
ABs = [[int(i) for i in input().split()] for _ in range(N - 1)]
solve(N, ABs)
| 1 | 136,139,789,723,432 | null | 272 | 272 |
D = int(input())
Cs = list(map(int,input().split()))
Ss = [list(map(int,input().split())) for i in range(D)]
ts = []
for i in range(D):
ts.append(int(input()))
last = [0]*26
satisfy = 0
for day,t in enumerate(ts):
day += 1
last[t-1] = day
satisfy += Ss[day-1][t-1]
for i in range(26):
satisfy -= Cs[i]*(day-last[i])
print(satisfy) | #! python3
# stack.py
symbols = input().split(' ')
stack = []
def calc(op):
global stack
if op == '+':
return stack.pop()+stack.pop()
elif op == '-':
return -1 * stack.pop()+stack.pop()
elif op == '*':
return stack.pop()*stack.pop()
for s in symbols:
if s in ['+', '-', '*']:
stack.append(calc(s))
else:
stack.append(int(s))
print(stack.pop())
| 0 | null | 5,044,310,460,930 | 114 | 18 |
x, k, d = map(int, input().split())
if x < 0:
x = -x
if k * d <= x:
print(x - k * d)
else:
t = x // d
x -= t * d
k -= t
if x >= d:
x -= d
k -= 1
if k % 2 == 1:
x -= d
print(abs(x))
| while 1:
m,f,r=map(int,raw_input().split())
if m==f==r==-1 :break
ans=''
if m==-1 or f==-1 :ans= 'F'
else :
mp=m+f
if mp>=80:ans='A'
elif mp>=65:ans='B'
elif mp>=50 or (mp>=30 and r>=50):ans='C'
elif mp>=30:ans='D'
else :ans='F'
print ans | 0 | null | 3,221,570,491,942 | 92 | 57 |
t = []
w = input().lower()
while True:
s = input()
if s == "END_OF_TEXT":
break
t.extend(s.lower().split())
print(t.count(w))
| import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
n,m,x = I()
book = [l() for i in range(n)]
money = []
for i in range(2**n):
ccc = 0
bag = [0]*(m+1)
for j in range(n):
for k in range(m+1):
if ((i>>j)&1):
bag[k] += book[j][k]
for p in range(1,m+1):
if bag[p] >= x:
ccc += 1
if ccc == m:
money.append(bag[0])
if len(money) == 0:
print(-1)
else:
print(min(money))
| 0 | null | 11,956,438,178,048 | 65 | 149 |
n, m = map(int, input().split())
lst = [int(i) for i in input().split()]
s = 0
for i in range(n):
s += lst[i]
count = 0
for i in range(n):
if lst[i] * 4 * m >= s:
count += 1
if count >= m:
print('Yes')
else:
print('No') | # abc161_b.py
# https://atcoder.jp/contests/abc161/tasks/abc161_b
# B - Popular Vote /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点
# 問題文
# N種類の商品に対して人気投票を行いました。商品 i は Ai票を得ています。
# この中から人気商品 M個を選びます。ただし、得票数が総投票数の 14M未満であるような商品は選べません。
# 人気商品 M個を選べるなら Yes、選べないなら No を出力してください。
# 制約
# 1≤M≤N≤100
# 1≤Ai≤1000
# Aiは相異なる
# 入力は全て整数
# 入力
# 入力は以下の形式で標準入力から与えられる。
# N M
# A1 ... AN
# 出力
# 人気商品 M個を選べるなら Yes、選べないなら No を出力せよ。
# 入力例 1
# 4 1
# 5 4 2 1
# 出力例 1
# Yes
# 総投票数は 12です。1 位の得票数は 5なので、これを選ぶことができます。
# 入力例 2
# 3 2
# 380 19 1
# 出力例 2
# No
# 総投票数は 400です。
# 2,3 位の得票数は総得票数の 14×2 未満なので、これらを選ぶことはできず、人気商品 2個を選べません。
# 入力例 3
# 12 3
# 4 56 78 901 2 345 67 890 123 45 6 789
# 出力例 3
# Yes
global FLAG_LOG
FLAG_LOG = False
def log(value):
# FLAG_LOG = True
# FLAG_LOG = False
if FLAG_LOG:
print(str(value))
def calculation(lines):
# S = lines[0]
# N = int(lines[0])
N, M = list(map(int, lines[0].split()))
values = list(map(int, lines[1].split()))
# values = list(map(int, lines[2].split()))
# values = list()
# for i in range(N):
# values.append(int(lines[i]))
# valueses = list()
# for i in range(N):
# valueses.append(list(map(int, lines[i+1].split())))
values.sort()
values = values[::-1]
log(f'values[M-1]=[{values[M-1]}]')
log(f'1/(4*M)=[{1/(4*M)}]')
if values[M-1]/sum(values) < 1/(4*M):
result = 'No'
else:
result = 'Yes'
return [result]
# 引数を取得
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
# テストデータ
def get_testdata(pattern):
if pattern == 1:
lines_input = ['4 1', '5 4 2 1']
lines_export = ['Yes']
if pattern == 2:
lines_input = ['3 2', '380 19 1']
lines_export = ['No']
if pattern == 3:
lines_input = ['12 3', '4 56 78 901 2 345 67 890 123 45 6 789']
lines_export = ['Yes']
return lines_input, lines_export
# 動作モード判別
def get_mode():
import sys
args = sys.argv
global FLAG_LOG
if len(args) == 1:
mode = 0
FLAG_LOG = False
else:
mode = int(args[1])
FLAG_LOG = True
return mode
# 主処理
def main():
import time
started = time.time()
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(2)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
# if mode > 0:
# print(f'lines_input=[{lines_input}]')
# print(f'lines_export=[{lines_export}]')
# print(f'lines_result=[{lines_result}]')
# if lines_result == lines_export:
# print('OK')
# else:
# print('NG')
# finished = time.time()
# duration = finished - started
# print(f'duration=[{duration}]')
# 起動処理
if __name__ == '__main__':
main()
| 1 | 38,690,285,261,900 | null | 179 | 179 |
a, b, c = map(int, input().split())
d = 0
if a > b:
d = a
a = b
b = d
else: pass
d = 0
if b > c:
d = b
b = c
c = d
else: pass
d = 0
if a > b:
d = a
a = b
b = d
else: pass
print(a, b, c)
| def comb(n, m, p=10**9+7):
if n < m:
return 0
if n < 0 or m < 0:
return 0
m = min(m, n-m)
top = bot = 1
for i in range(m):
top = top*(n-i) % p
bot = bot*(i+1) % p
bot = pow(bot, p-2, p)
return top*bot % p
x, y = map(int, input().split())
j = 2*x-y
if j % 3:
print(0)
exit()
j //= 3
i = x - 2*j
if i < 0 or j < 0:
print(0)
exit()
ans = comb(i+j, i)
print(ans)
| 0 | null | 75,095,347,417,002 | 40 | 281 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
N = input()
s = 0
for i in range(len(N)):
s += int(N[i])
if s%9 == 0:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| n,k=map(int,input().split())
a=list(map(int,input().split()))
import math
x=0
y=10**9
z=5*(10**8)
s=0
for i in range(100):
t=0
for j in range(n):
t+=a[j]//z
if t<=k:
s=t
y=z
z=(x+y)/2
else:
x=z
z=(x+y)/2
print(math.ceil(z))
| 0 | null | 5,451,836,658,908 | 87 | 99 |
# coding:UTF-8
import sys
from math import factorial
MOD = 10 ** 9 + 7
INF = float('inf')
N = int(input()) # 数字
A = list(map(int, input().split())) # スペース区切り連続数字
m = max(A)
num = [0] * (m + 1)
for a in A:
num[a] += 1
for a in A:
if num[a] > 1:
num[a] = 0
i = 2
while a * i <= m:
num[a * i] = 0
i += 1
res = 0
for n in num:
if n != 0:
res += 1
print("{}".format(res))
| #!/usr/bin/env python3
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n=int(input())
A=list(map(int, input().split()))
counts=[0]*(10**6+5)
for AA in A:
counts[AA]+=1
ans=0
for i in range(1,10**6+5):
if counts[i]>0:
for j in range(i+i,10**6+5,i):
counts[j]=-1
if counts[i]==1:
ans+=1
print(ans)
if __name__ == '__main__':
main()
| 1 | 14,330,164,947,968 | null | 129 | 129 |
N = int(input())
ans = pow(10, N, mod=1000000007) - pow(9, N, mod=1000000007) - pow(9, N, mod=1000000007) + pow(8, N, mod=1000000007)
ans %= 1000000007
print(ans)
| n=int(input())
m=10**9+7
print((pow(10,n,m)-pow(9,n,m)*2+pow(8,n,m))%m if n!=1 else 0)
| 1 | 3,144,073,627,990 | null | 78 | 78 |
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
class UnionFind():
def __init__(self, n):
self.n = n
# parents[i]: 要素iの親要素の番号
# 要素iが根の場合、parents[i] = -(そのグループの要素数)
self.parents = [-1] * n
def find(self, x):
if 0 > self.parents[x]:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
# 要素xが属するグループの要素数を返す
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
# 要素xが属するグループに属する要素をリストで返す
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
# 全ての根の要素をリストで返す
def roots(self):
return [i for i, x in enumerate(self.parents) if 0 > x]
# グループの数を返す
def group_count(self):
return len(self.roots())
# 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
# print()での表示用
# all_group_members()をprintする
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M, K = MAP()
tree = UnionFind(N)
friends = [[] for _ in range(N)]
for _ in range(M):
A, B = MAP()
tree.union(A-1, B-1)
friends[A-1].append(B-1)
friends[B-1].append(A-1)
blocks = [[] for _ in range(N)]
for _ in range(K):
C, D = MAP()
blocks[C-1].append(D-1)
blocks[D-1].append(C-1)
for i in range(N):
blocks_cnt = sum([tree.same(i, j) for j in blocks[i]])
print(tree.size(i) - len(friends[i]) - 1 - blocks_cnt, end=" ")
print()
| # happendはsetで保持しておき,roopはlistで保持しておく
N, X, M = map(int, input().split()) # modMは10**5以下が与えられる
happend = set()
A = [X]
MOD = M
# 第1~N項まで計N項の和をもとめる
start = 0
for _ in range(N-1):
if A[-1]**2 % MOD not in happend:
happend.add(A[-1]**2 % MOD)
A.append(A[-1]**2 % MOD)
else:
start = A.index(A[-1]**2 % MOD)
break
roop_count = (N-start)//len(A[start:])
ans = sum(A[:start]) + sum(A[start:])*roop_count + sum(A[start:start+(N-start) % len(A[start:])])
# print(A[:start], A[start:], A[start:start+(N-start) % len(A[start:])])
print(ans)
| 0 | null | 31,992,777,148,540 | 209 | 75 |
import numpy as np
n, t = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
dp = np.zeros(t, dtype=np.int64)
ans = 0
for a, b in ab:
ans = max(ans, dp[-1] + b)
np.maximum(dp[a:], dp[:-a] + b, out=dp[a:])
print(ans)
| # コード整理
import sys
from operator import itemgetter
input = sys.stdin.readline
#################
# 定数
#################
TIME = 0
VAL = 1
##################
# 入力処理
##################
N, T = [int(a) for a in input().split()]
time_value = [(-1, -1)] + [tuple(int(a) for a in input().split()) for _ in range(N)]
# Sort the array in the increasing order of value
time_value.sort(key = itemgetter(VAL))
###########################
# 動的計画法(Knapsack problem)のテーブル埋め
# 時間の最大値は T - 1
##########################
dp = [[-1] * T for _ in range(N + 1)] # (N+1)行 x T列 2次元リスト
for t in range(0, T):
dp[0][t] = 0
for n in range(1, N + 1):
dp[n][0] = 0
for t in range(1, T):
if time_value[n][TIME] > t:
dp[n][t] = dp[n - 1][t]
else:
dp[n][t] = max(dp[n - 1][t],
time_value[n][VAL] + dp[n - 1][t - time_value[n][TIME]])
##########################
# DPテーブルを用いて問題を解く
##########################
# t = T - 1に食べ始める料理が N, N-1, N-2, ..., 2, 1それぞれの場合で
# 美味しさの最大値を出し、更にその最大値を取る
# 最後に食べる料理がNの場合
val_acum = time_value[N][VAL]
t = T - 1 # N以外の料理を食べるのに使える時間
max_val = val_acum + dp[N - 1][t]
for n in range(N - 1, 0, -1): # 最後に食べる料理が n = N-1, N-2, ..., 2, 1の場合
val_acum += time_value[n][VAL] # 料理 N, N-1, ..., nの美味しさ合計
t -= time_value[n + 1][TIME] # その他の料理 1, 2, ..., n-1を食べるのに使える時間
if t < 0:
break
else:
max_val = max(max_val, val_acum + dp[n - 1][t])
print(max_val)
| 1 | 152,083,605,407,424 | null | 282 | 282 |
N = int(input())
A = list(map(int, input().split()))
res = "APPROVED"
for i in A:
if i % 2 == 0:
if i % 3 != 0 and i % 5 != 0:
res = "DENIED"
print(res) | #bubble
N=int(input())
A=[int(i) for i in input().split()]
fl=1
C=0
while fl==1:
fl=0
for j in range(N-1):
if A[N-1-j]<A[N-2-j]:
t=A[N-1-j]
A[N-1-j]=A[N-2-j]
A[N-2-j]=t
C+=1
fl=1
for j in range(N):
A[j]=str(A[j])
print(" ".join(A))
print(C) | 0 | null | 34,434,486,065,852 | 217 | 14 |
cards = []
suits = ['S', 'H', 'C', 'D']
for i in range(len(suits)):
for j in range(1, 14):
cards.append(suits[i] + ' ' + str(j))
n = int(input())
for i in range(n):
cards.remove(input())
for i in range(len(cards)):
print(cards[i]) | s=input()
if s=="hi" or s=="hihi" or s=="hihihi" or s=="hihihihi" or s=="hihihihihi":
print("Yes")
else:
print("No") | 0 | null | 27,115,867,392,150 | 54 | 199 |
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
for keta in range(61):
now = 0
for x in a:
if x & (1 << keta):
now += 1
ans += (now*(n-now))*2**keta
ans %= mod
print(ans)
| from copy import copy
n = int(input())
a_ls = list(map(int, input().split()))
c_bin = [[0]*60 for _ in range(n)]
a_bin_ls = [[0]*60 for _ in range(n)]
now_bin = [0] * 60
for i in range(n-1,-1,-1):
a = a_ls[i]
j = 0
while True:
if a == 1:
now_bin[j] += 1
a_bin_ls[i][j] = 1
break
elif a == 0:
break
a,r = divmod(a,2)
now_bin[j] += r
a_bin_ls[i][j] = r
j += 1
c_bin[i] = copy(now_bin)
ans_bin = [0]*60
for i in range(n-1):
a_bin = a_bin_ls[i]
for j in range(60):
if a_bin[j] == 0:
times = c_bin[i+1][j]
else:
times = n - (i+1) - c_bin[i+1][j]
ans_bin[j] += times
ans = 0
mod = 10**9+7
for i in range(60):
ans += 2**i * (ans_bin[i]%mod)
ans %= mod
print(ans)
| 1 | 122,633,598,785,290 | null | 263 | 263 |
n = int(input())
ans = (n//2) + (n%2)
print (ans) | import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
N = I()
S = _S()
print("Yes" if S[:int(len(S)/2)]==S[int(len(S)/2):] else "No")
main()
| 0 | null | 103,243,814,585,668 | 206 | 279 |
n = int(input())
if n in range(400, 600):
print("8")
if n in range(600, 800):
print("7")
if n in range(800, 1000):
print("6")
if n in range(1000, 1200):
print("5")
if n in range(1200, 1400):
print("4")
if n in range(1400, 1600):
print("3")
if n in range(1600, 1800):
print("2")
if n in range(1800, 2000):
print("1")
| n=int(input());
print(10-(n//200)); | 1 | 6,686,115,580,790 | null | 100 | 100 |
a, b = map(int, input().split())
import numpy
count = 0
for i in range(a):
c, d = map(int, input().split())
e = c ** 2 + d ** 2
if numpy.sqrt(e) <= b:
count += 1
print(count) | k, x = [int(i) for i in input("").split(" ")]
if(500*k >= x):
print('Yes')
else:
print('No') | 0 | null | 52,290,092,839,592 | 96 | 244 |
h,w = map(int, raw_input().split(' '))
def f(h,w):
if h == 1 or w == 1:
return 1
x = w - w/2
y = w/2
count = 0
count += (h - (h/2)) * x
count += ((h/2)) * y
return count
print f(h,w) | import sys
sys.setrecursionlimit(10**9)
INF = 110110110
H, W, K = list(map(int, input().split()))
S = [''] * H
for i in range(H):
S[i] = input()
ans = H * W
for bit in range(2**(H-1)):
cnt = bin(bit).count('1')
id = [0] * H
for i in range(H-1):
if bit>>i & 1:
id[i+1] = id[i] + 1
else:
id[i+1] = id[i]
num = [[0] * W for i in range(id[H-1]+1)]
for i in range(H):
for j in range(W):
if S[i][j] == '1':
num[id[i]][j] += 1
for i in range(id[H-1]+1):
for j in range(W):
if num[i][j] > K:
cnt = INF
sum = [0] * (id[H-1]+1)
for j in range(W):
need = False
for i in range(id[H-1]+1):
if sum[i] + num[i][j] > K:
need = True
if need:
cnt += 1
for i in range(id[H-1]+1):
sum[i] = num[i][j]
else:
for i in range(id[H-1]+1):
sum[i] += num[i][j]
ans = min(ans, cnt)
print(ans)
| 0 | null | 49,626,984,226,940 | 196 | 193 |
# https://atcoder.jp/contests/abc146/submissions/8617148
def solve(N, M, S):
from collections import namedtuple
from heapq import heappop, heappush
INF = N * 2
V = namedtuple('V', 'cnt index')
cnt_from_N = [INF] * (N + 1)
cnt_from_N[N] = 0
parent = [0] * (N + 1)
h = [V(cnt=0, index=N)]
for j in range(N - 1, -1, -1):
# S[j]に到達する最小回数とその経路を求める
if S[j]:
continue
while h:
cnt, par = h[0]
if par > j + M:
# jまで移動できない(距離>M)
heappop(h)
continue
break
# jまで最小回数で到達できる頂点par
# parまでの回数cnt
if not h:
return -1,
# jまで到達できる頂点がない
cnt_from_N[j] = cnt + 1
parent[j] = par
heappush(h, V(cnt=cnt + 1, index=j))
ret = []
curr = 0
while curr < N:
par = parent[curr]
ret.append(par - curr)
curr = par
return ret
def main():
N, M = map(int, input().split())
*S, = map(int, input())
print(*solve(N, M, S))
if __name__ == '__main__':
main()
| N,M = map(int,input().split())
S = input()
c = 0
flag = 0
for i in S:
if i == '0':
if c >= M:
flag = 1
break
c = 0
else:
c += 1
if flag == 1:
print(-1)
else:
T = S[::-1]
now = 0
ans = []
while now != N:
delta = 0
for i in range(1,M+1):
if now + i == N:
delta = i
break
if T[now+i] == '0':
delta = i
ans.append(delta)
now += delta
Answer = ans[::-1]
print(*Answer) | 1 | 139,203,022,705,362 | null | 274 | 274 |
N = int(input())
ACcount = 0
WAcount = 0
TLEcount = 0
REcount = 0
for i in range(N):
S=input()
if S == "AC":
ACcount = ACcount + 1
elif S == "WA":
WAcount = WAcount + 1
elif S == "TLE":
TLEcount = TLEcount + 1
elif S == "RE":
REcount = REcount + 1
print("AC x", ACcount)
print("WA x", WAcount)
print("TLE x", TLEcount)
print("RE x", REcount)
| import math
a,b = map(int,input().split())
d = (int)((a*b+1)/2)
if a == 1 or b == 1:
print(1)
else :
print(d)
| 0 | null | 29,812,471,172,988 | 109 | 196 |
N = int(input())
evidences = [[] for _ in range(N)]
for i in range(N):
A = int(input())
for _ in range(A):
x, y = map(int, input().split())
evidences[i].append((x - 1, y))
ans = 0
for i in range(1, 2 ** N):
consistent = True
for j in range(N):
if (i >> j) & 1 == 0:
continue
for x, y in evidences[j]:
if (i >> x) & 1 != y:
consistent = False
break
#if not consistent:
#break
if consistent:
ans = max(ans, bin(i)[2:].count('1'))
print(ans) | def main():
a, b = map(int, input().split())
if a == b:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | 0 | null | 102,484,632,868,112 | 262 | 231 |
from sys import stdin
n = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
ans = [0] * n
for i, a in enumerate(A):
ans[a-1] = i+1
print(' '.join(map(str, ans))) | import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
# b,r = map(str, readline().split())
# A,B = map(int, readline().split())
br = LS()
AB = LI()
U = _S()
def main():
brAB = zip(br, AB)
tmp=[]
for c,n in brAB:
if c==U:
tmp.append(n - 1)
else:
tmp.append(n)
return str(tmp[0])+' '+str(tmp[1])
print(main())
| 0 | null | 126,581,412,359,292 | 299 | 220 |
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
B = reduce(lambda x, y: x^y, A)
ans = []
for a in A:
ans.append(B^a)
print(*ans) | def main():
import sys
input = sys.stdin.readline
from bisect import bisect_left, insort_left
N = int(input())
S = list(input())
Q = int(input())
dic = {chr(i): [] for i in range(ord('a'), ord('z')+1)}
for i in range(N):
dic[S[i]].append(i)
for _ in range(Q):
query, a, c = input().split()
if query == "1":
i = int(a)-1
if S[i] == c:
continue
ind = bisect_left(dic[S[i]], i)
dic[S[i]].pop(ind)
insort_left(dic[c], i)
S[i] = c
else:
l, r = int(a)-1, int(c)-1
ans = 0
for inds in dic.values():
if inds and l <= inds[-1] and inds[bisect_left(inds, l)] <= r:
ans += 1
print(ans)
if __name__ == '__main__':
main() | 0 | null | 37,663,794,195,940 | 123 | 210 |
N,R = list(map(int,input().split()))
ans=R
if N < 10:
ans += 100*(10-N)
print(ans) | D,T,S = map(int,input().split())
if D <= T*S:
print("Yes")
else:print("No") | 0 | null | 33,606,733,107,910 | 211 | 81 |
print('No') if int(input())%9 else print('Yes') | import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
from math import ceil
def main():
n = tuple(map(int, tuple(input())))
if sum(n) % 9 == 0:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 1 | 4,407,203,020,220 | null | 87 | 87 |
has, need = [int(x) for x in input().split()]
print(["No", "Yes"][has * 500 >= need]) | m = input().split()
K = int(m[0])
X = int(m[1])
ans = 'Yes'
if 500 * K < X:
ans = 'No'
print(ans) | 1 | 98,220,771,599,398 | null | 244 | 244 |
N=int(input())
base = ["ACL"]*N
print("".join(base)) | n, k = map(int, input().split())
mod = 10**9 + 7
cnt = [0]*(k + 1)
ans = 0
for i in range(k, 0, -1):
cnt[i] = (pow(k//i, n, mod) - sum(cnt[2*i:k+1:i])) % mod
ans = (ans + i*cnt[i]) % mod
print(ans)
| 0 | null | 19,332,884,697,696 | 69 | 176 |
h = int(input())
ans = 0
n_enemy = 1
while h > 1:
h //= 2
ans += n_enemy
n_enemy *= 2
if h == 1:
ans += n_enemy
print(ans) | h=int(input())
num=1
cnt=0
while h!=1:
h=h//2
cnt+=num
num*=2
cnt+=num
print(cnt) | 1 | 80,259,887,030,762 | null | 228 | 228 |
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
import bisect
n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
def hand(x):
cnt=0
for i in range(n):
p=x-A[i]
cnt+=n-bisect.bisect_left(A,p)
return cnt
def main():
l=0
h=2*10**5+1
mid=(l+h)//2
while l+1<h:
mid=(l+h)//2
if hand(mid)<m:
h=mid
else:
l=mid
B=A[::-1]
for i in range(n-1):
B[i+1]+=B[i]
B=B[::-1]
ans=0
cnt=0
for i in range(n):
y=l-A[i]+1
index=bisect.bisect_left(A,y)
if n==index:
continue
else:
ans+=(n-index)*A[i]+B[index]
cnt+=(n-index)
ans+=(m-cnt)*l
print(ans)
if __name__ == "__main__":
main()
| 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) | 1 | 108,617,226,584,648 | null | 252 | 252 |
d_num = int(input())
graph = [[] for _ in range(d_num+1)]
for _ in range(d_num):
u, k, *neighbors = map(int, input().split())
graph[u] = neighbors
visited = set()
timestamps = [None for _ in range(d_num+1)]
def dfs(u, stmp):
visited.add(u)
entry = stmp
stmp += 1
for v in graph[u]:
if v not in visited:
stmp = dfs(v, stmp)
timestamps[u] = entry, stmp
return stmp+1
stmp = 1
for v in range(1, d_num+1):
if v not in visited:
stmp = dfs(v, stmp)
for num, (entry, leave) in enumerate(timestamps[1:], 1):
print(num, entry, leave)
| from sys import stdin
global time
time = 0
def dfs(graph,start,state,discover,finish):
state[start-1] = 1
global time
time = time + 1
discover[start-1] = time
# print str(time) + " go to " + str(start)
neighbours = sorted(graph[start])
for neighbour in neighbours:
if state[neighbour-1] == 0:
dfs(graph,neighbour,state,discover,finish)
state[start-1] = 2
time = time + 1
finish[start - 1] = time
# print str(time) + " out of " + str(start)
def main():
# g = {1: [2, 3],
# 2: [3, 4],
# 3: [5],
# 4: [6],
# 5: [6],
# 6: []}
# deal with input
n = int(stdin.readline())
g = {}
d = [0]*n
f = [0]*n
all_vertex = []
for i in xrange(n):
entry = [int(s) for s in stdin.readline().split()[2:]]
g[i+1] = entry
all_vertex.append(i+1)
# exp = []
# state represent vertex visited state: 0 not visited 1 visiting 2 finished
state = [0]*n
for node in all_vertex:
if state[node-1] == 0:
dfs(g,node,state,d,f)
# print 'state ' + str(state)
# print 'd' + str(d)
# print 'f' + str(f)
# deal with output
for i in xrange(n):
print str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i])
main()
| 1 | 3,177,210,080 | null | 8 | 8 |
def main():
r = int(input())
print(r**2)
if __name__ == "__main__":
main()
| import sys
n = int(input())
r0 = int(input())
r1 = int(input())
mx = r1-r0
mn = min(r1,r0)
l = map(int,sys.stdin.readlines())
for i in l:
if mx < i - mn:
mx = i - mn
elif mn > i:
mn = i
print(mx) | 0 | null | 72,628,744,580,384 | 278 | 13 |
n,m = map(int,input().split())
C = sorted(map(int,input().split()))
T = [float("inf")]*(n+1)
T[0]= 0
for i in range(m):
for j in range(C[i],n+1):
T[j] = min(T[j],T[j-C[i]]+1)
print(T[n]) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,m,*c = map(int,read().split())
INF = 9**9
dp = [INF] * (n+1)
dp[0] = 0
for i in range(1,n+1):
for j in c:
if i-j>= 0:
dp[i] = min(dp[i],dp[i-j]+1)
print(dp[n])
| 1 | 143,890,869,412 | null | 28 | 28 |
N,M = map(int, input().split())
flag = [False]*N
ac = wa = 0
wal = [0]*N
for i in range(M):
p, s = input().split()
if s == "AC":
if flag[int(p)-1] == False:
ac+=1
wa+=wal[int(p)-1]
flag[int(p)-1] = True
if s == "WA":
if flag[int(p)-1] == False:
wal[int(p)-1]+=1
print(ac,wa) | # 入力
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
# ライブラリ
import itertools
l = [i+1 for i in range(n)]
perms = itertools.permutations(l, n)
# 処理
a = 0
b = 0
for i, perm in enumerate(perms):
perm = list(perm)
if perm == p:
a = i
if perm == q:
b = i
import numpy as np
print(np.abs(a-b)) | 0 | null | 97,105,708,628,082 | 240 | 246 |
N=int(input())
S=input()
ans=[]
for i in range(len(S)):
temp=ord(S[i])
if temp+N>90:
ans.append(chr(temp+N-26))
else:
ans.append(chr(temp+N))
print("".join(ans))
| val = input().split()
N = int(val[0])
M = int(val[1])
if N - M == 0:
print("Yes")
else:
print("No")
| 0 | null | 109,130,833,586,080 | 271 | 231 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.