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 = int(input())
if(n % 2 !=0):
print(0)
exit()
ketasu = len(str(n))
ans = 0
for i in range(1, 100):
ans += n // (2 * 5 **i)
print(ans) | N=int(input())
if N%2==1:
print(0)
exit()
elif N==0:
print(0)
exit()
L=len(str(N))
ans=0
now=5
while N//now>0:
ans+=((N//now)//2)
now*=5
print(ans)
| 1 | 116,151,050,221,008 | null | 258 | 258 |
import sys,math
inputs = list()
for n in sys.stdin:
inputs.append(list(map(int,n.split())))
for n in inputs:
print(math.floor(math.log10(n[0]+n[1]))+1) | import math
def main():
n = int(input())
tax = 1.08
ans = math.ceil(n / tax)
ans_check = ans * tax
if math.floor(ans * tax) == n:
print(ans)
else:
print(":(")
if __name__ == "__main__":
main() | 0 | null | 63,002,078,130,112 | 3 | 265 |
#coding:UTF-8
while True:
n = map(int,raw_input().split())
if (n[0] or n[1]) == 0:
break
n.sort()
print n[0],n[1] | try:
s=[]
while True:
t = input()
s.append(t)
except EOFError:
for i in range(len(s)):
print(len(str(int(s[i].split(' ')[0])+int(s[i].split(' ')[1])))) | 0 | null | 269,297,671,200 | 43 | 3 |
import math
n = int(input())
print(math.floor(n / 2) - (1-n%2)) | c = {"N": (1, 5, 2, 3, 0, 4), "S": (4, 0, 2, 3, 5, 1), "E": (3, 1, 0, 5, 4, 2), "W": (2, 1, 5, 0, 4, 3)}
d = list(map(int, input().split()))
for x in input():
d = [d[y] for y in c[x]]
print(d[0])
| 0 | null | 76,935,324,334,308 | 283 | 33 |
n = input()
cube = n ** 3
print cube | import math
def main():
a,b,c = map(int,input().split())
left = 4*a*b
right = (c-a-b)**2
if (c-a-b)<0:
return 'No'
if left < right:
return 'Yes'
else:
return 'No'
print(main())
| 0 | null | 26,011,079,720,220 | 35 | 197 |
# 雰囲気で書いたら通ってしまったがなんで通ったかわからん
# i<jという前提を無視しているのではと感じる
N = int(input())
A = list(map(int, input().split()))
# i<jとして、条件は j-i = A_i + A_j
# i + A_i = j - A_j
dict1 = {}
for i in range(1, N + 1):
tmp = i + A[i - 1]
if tmp not in dict1:
dict1[tmp] = 1
else:
dict1[tmp] += 1
dict2 = {}
for i in range(1, N + 1):
tmp = i - A[i - 1]
if tmp not in dict2:
dict2[tmp] = 1
else:
dict2[tmp] += 1
# print(dict1, dict2)
ans = 0
for k, v in dict1.items():
if k in dict2:
ans += v * dict2[k]
print(ans)
| def main():
input_lines_lrd = input()
arrLRD = input_lines_lrd.split(" ")
l = int(arrLRD[0])
r = int(arrLRD[1])
d = int(arrLRD[2])
cnt = 0
for n in range(l, r+1):
if n % d == 0:
cnt = cnt + 1
print(cnt)
if __name__ == "__main__":
main()
| 0 | null | 16,699,664,167,538 | 157 | 104 |
#N = int(input())
l = [int(x) for x in input().split()]
if l[0] == l[1]:
print("Yes")
else:
print("No") | n,m=input().split()
if(n==m):
print("Yes\n")
else:
print("No\n")
| 1 | 83,181,659,911,590 | null | 231 | 231 |
N=list(input())
print('Yes' if '7' in N else 'No')
| N=str(input())
if "7" in N:
print("Yes")
else:
print("No")
| 1 | 34,365,143,494,308 | null | 172 | 172 |
T = input()
T = ['D' if c == '?' else c for c in T]
print(*T, sep='') | a,b,c=map(int,input().split())
k=int(input())
x=0
while a>=b:
b=b*2
x=x+1
while b>=c:
c=c*2
x=x+1
if k>=x:
print('Yes')
else:
print('No') | 0 | null | 12,721,844,760,612 | 140 | 101 |
n = int(input())
s = list(map(int, input().split()))
cnt = 0
def merge(A, left, mid, right):
L = A[left:mid]
R = A[mid:right]
L.append(float('inf'))
R.append(float('inf'))
i = 0
j = 0
global cnt
for k in range(left, right):
cnt += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
def mergeSort(A, left, right):
if left+1 < right:
mid = (left+right) // 2
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
mergeSort(s, 0, n)
print(' '.join(map(str, s)))
print(cnt)
| n = int(input())
score = [0,0]
for _ in range(n):
tc, hc = input().split()
if tc == hc:
score[0] += 1
score[1] += 1
elif tc > hc:
score[0] += 3
else:
score[1] += 3
print(*score)
| 0 | null | 1,064,076,771,196 | 26 | 67 |
D=int(input())
c=list(map(int,input().split()))
c_memo=[0]*26
s=[]
for i in range(D):
ss=list(map(int,input().split()))
s.append(ss)
ans_b=[]
for i in range(D):
t=int(input())
c_down=0
for j in range(26):
if j==t-1:
c_memo[t-1]=i+1
continue
else:
c_down+=(i+1-c_memo[j])*c[j]
ans=s[i][t-1]-c_down
ans_b.append(ans)
ans=0
for x in ans_b:
ans+=x
print(ans)
| from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
res = 0
for i in range(h):
for j in range(w):
if s[i][j] == "#":
continue
dist = [[-1] * w for _ in range(h)]
dist[i][j] = 0
d = deque()
d.append([i, j])
while d:
pos_x, pos_y = d.popleft()
dist_max = dist[pos_x][pos_y]
for k in range(4):
x, y = pos_x + dx[k], pos_y + dy[k]
if 0 <= x < h and 0 <= y < w and s[x][y] == "." and dist[x][y] == -1:
dist[x][y] = dist[pos_x][pos_y] + 1
d.append([x, y])
res = max(res, dist_max)
print(res) | 0 | null | 52,265,235,035,860 | 114 | 241 |
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if a[0]*t[0]+a[1]*t[1]==b[0]*t[0]+b[1]*t[1]:
print('infinity')
elif a[0]*t[0]+a[1]*t[1]>b[0]*t[0]+b[1]*t[1]:
if a[0]*t[0]>b[0]*t[0]:
print(0)
elif a[0]*t[0]==b[0]*t[0]:
print(1)
else:
n=t[0]*(b[0]-a[0])
m=t[0]*(a[0]-b[0])+t[1]*(a[1]-b[1])
q=n//m
if n%m==0:
print(2*q)
else:
print(2*q+1)
else:
if a[0]*t[0]<b[0]*t[0]:
print(0)
elif a[0]*t[0]==b[0]*t[0]:
print(1)
else:
n=-t[0]*(b[0]-a[0])
m=-t[0]*(a[0]-b[0])-t[1]*(a[1]-b[1])
q=n//m
if n%m==0:
print(2*q)
else:
print(2*q+1) | def solve():
INF = float('inf')
def WarshallFloyd(adjList):
numV = len(adjList)
D = [[INF]*numV for _ in range(numV)]
for u, adj in enumerate(adjList):
for v, wt in adj:
D[u][v] = wt
D[u][u] = 0
for k in range(numV):
Dk = D[k]
for i in range(numV):
Di = D[i]
Dik = Di[k]
for j in range(numV):
D2 = Dik + Dk[j]
if D2 < Di[j]:
D[i][j] = D2
return D
N, M, L = map(int, input().split())
adjL = [[] for _ in range(N)]
for _ in range(M):
A, B, C = map(int, input().split())
A, B = A-1, B-1
adjL[A].append((B, C))
adjL[B].append((A, C))
D = WarshallFloyd(adjL)
adjL2 = [[] for _ in range(N)]
for i in range(N):
for j in range(i+1, N):
if D[i][j] <= L:
adjL2[i].append((j, 1))
adjL2[j].append((i, 1))
D = WarshallFloyd(adjL2)
Q = int(input())
anss = []
for _ in range(Q):
s, t = map(int, input().split())
s, t = s-1, t-1
if D[s][t] == INF:
anss.append(-1)
else:
anss.append(D[s][t]-1)
print('\n'.join(map(str, anss)))
solve()
| 0 | null | 152,609,969,146,490 | 269 | 295 |
def get_cusum(lst):
cusum = [0] + lst
for i in range(1, len(cusum)):
cusum[i] = cusum[i] + cusum[i-1]
return cusum
def main():
n, m, k = map(int, input().split(" "))
book_a = get_cusum(list(map(int, input().split(" "))))
book_b = get_cusum(list(map(int, input().split(" "))))
ans = 0
top = m
# print(book_a)
# print(book_b)
for i in range(n + 1):
if book_a[i] > k:
break
while book_b[top] > k - book_a[i]:
top -= 1
ans = max(ans, i+top)
print(ans)
main()
| def insertionSort(A, n, g):
cnt = 0
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
return cnt
def shellSort(A, n):
cnt = 0
nn = n
G = []
g = 1
while g <= n:
G.insert(0, g)
g = g*3 + 1
m = len(G)
for g in G:
cnt += insertionSort(A, n, g)
return cnt, m, G
n = int(input())
A = [int(input()) for i in range(n)]
cnt, m, G = shellSort(A, n)
print(m)
print(" ".join(map(str, G)))
print(cnt)
for a in A:
print(a)
| 0 | null | 5,398,904,285,100 | 117 | 17 |
n = int(input())
sumOfN = sum(int(i) for i in list(str(n)))
print("No" if sumOfN%9 else "Yes") | #k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
n = int(input())
s = input()
ans = 0
aDec = False
bDec = False
for i in range(n):
if s[i] == "A":
aDec = True
bDec = False
elif s[i] == "B":
if (aDec):
bDec = True
else:
bDec = False
aDec = False
elif s[i] == "C":
if (bDec):
ans += 1
bDec = False
aDec = False
else:
bDec = False
aDec = False
print(ans)
| 0 | null | 52,108,733,516,608 | 87 | 245 |
N, S = map(int,input().split())
A = [int(s) for s in input().split()]
DP = [[0 for j in range(S + 1)] for i in range(N + 1)]
mod = 998244353
DP[0][0] = 1
for i in range(N):
for j in range(S + 1):
DP[i + 1][j] += 2 * DP[i][j]
DP[i + 1][j] %= mod
if j + A[i] <= S:
DP[i + 1][j + A[i]] += DP[i][j]
DP[i + 1][j + A[i]] %= mod
print(DP[N][S]) | MOD = 998244353
N, S = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0 for j in range(S + 1)] for i in range(N + 1)]
dp[0][0] = 1
p = [[0 for k in range(N + 1)] for j in range(S + 1)]
p[0][0] = 1
for i in range(N):
for j in range(S + 1):
dp[i + 1][j] += dp[i][j] * 2
p[j]
if j >= A[i]:
dp[i + 1][j] += dp[i][j - A[i]]
dp[i + 1][j] %= MOD
print(dp[N][S]) | 1 | 17,736,975,335,492 | null | 138 | 138 |
import sys
import heapq
input = sys.stdin.readline
n, k, s = map(int, input().split())
for i in range(n):
if i < k:
print(s)
else:
if s >= 10**9:
print(1)
else:
print(s+1) | from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")
# 処理内容
def main():
X = int(input())
print(10 - X // 200)
if __name__ == '__main__':
main() | 0 | null | 49,000,129,919,030 | 238 | 100 |
#!/usr/bin/env python
letters = []
for i in range(26):
letters.append(chr(i + 97) + " : ")
contents = []
while True:
try:
text = input()
except EOFError:
break
contents.append(text)
#65-90 uppercase
#97-122lowercase
i = 0
for y in letters:
value = 0
for text in contents:
for x in text:
if x.isupper():
x = x.lower()
if x in y:
value += 1
elif x.islower():
if x in y:
value += 1
letters[i] = letters[i] + str(value)
i += 1
for x in letters:
print(x) | import sys
l=[0]*26
for h in sys.stdin:
for i in h:
k=ord(i.lower())
if 96<k<123:l[k-97]+=1
for i in range(26):print chr(i+97),':',l[i] | 1 | 1,665,147,519,160 | null | 63 | 63 |
from itertools import chain, combinations
def power_set(x):
return chain.from_iterable(combinations(x, r) for r in range(len(x)+1))
def main():
n = int(input())
A = input()
#print(n)
A = list(map(int, A.split()))
q = int(input())
m = input()
ms = list(map(int, m.split()))
powerset = power_set(A)
sum_set = [sum(s) for s in powerset if len(s)!=0]
for m in ms:
if m in sum_set:
print('yes')
else:
print('no')
if __name__ == '__main__':
main() | (H,N) = map(int,input().split())
l = []
for i in range(N):
l.append([int(x) for x in input().split()])
dp = [10**10 for i in range(H+10**4+1)]
dp[0] = 0
for i in range(H+10**4+1):
for j in range(N):
if l[j][0] <= i:
dp[i] = min(dp[i],dp[i-l[j][0]]+l[j][1])
ans = dp[H]
for i in range(1,10**4+1):
ans = min(ans,dp[H+i])
print(ans) | 0 | null | 40,578,902,339,008 | 25 | 229 |
#coding: utf-8
import sys
def gojo(a,b):
if b % a == 0:
return a
else:
return gojo(b % a, a)
for line in sys.stdin:
l = map(int,line.split())
l.sort()
a = l[0]
b = l[1]
print gojo(a,b),a*b/gojo(a,b) | n=list(input())
N=len(n)
k=int(input())
dp1=[[0 for i in range(k+1)] for j in range(N+1)]
dp2=[[0 for i in range(k+1)] for j in range(N+1)]
dp1[0][0]=1
for i in range(1,N+1):
x=int(n[i-1])
if i!=N and x!=0:
for j in range(k+1):
if j==0:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]
else:
dp1[i][j]=dp1[i-1][j-1]
dp2[i][j]=dp1[i-1][j]+dp1[i-1][j-1]*(x-1)+dp2[i-1][j]+dp2[i-1][j-1]*9
elif i!=N and x==0:
for j in range(k+1):
if j==0:
dp1[i][j]=dp1[i-1][j]
dp2[i][j]=dp2[i-1][j]
else:
dp1[i][j]=dp1[i-1][j]
dp2[i][j]=dp2[i-1][j]+dp2[i-1][j-1]*9
elif i==N and x!=0:
for j in range(k+1):
if j==0:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]
else:
dp2[i][j]=dp1[i-1][j]+dp1[i-1][j-1]*x+dp2[i-1][j]+dp2[i-1][j-1]*9
else:
for j in range(k+1):
if j==0:
dp2[i][j]=dp2[i-1][j]
else:
dp2[i][j]=dp1[i-1][j]+dp2[i-1][j]+dp2[i-1][j-1]*9
print(dp2[N][k]) | 0 | null | 37,879,254,222,098 | 5 | 224 |
nm = input().split()
n, m = map(int, nm)
A = [[int(i) for i in input().split()] for j in range(n)]
b = [int(input()) for i in range(m)]
for row in A:
s = 0
for i, elm in enumerate(row):
s += (elm*b[i])
print(s) | [r,c] = raw_input().split()
r = int(r)
c = int(c)
M = []
V = []
for y in range(0,r):
s = raw_input().split()
k = []
for x in range(0,c):
v = int(s[x])
k.append(v)
M.append(k)
for y in range(0,c):
s = int(raw_input())
V.append(s)
for y in range(0,r):
ss = 0
for x in range(0,c):
ss = ss + M[y][x] * V[x]
print ss | 1 | 1,158,105,208,060 | null | 56 | 56 |
w, h, x, y, r = [int(x) for x in input().split()]
if x + r <= w and x - r >= 0 and y + r <= h and y - r >= 0:
print('Yes')
else:
print('No') | import random
class Dice:
def __init__(self, labels):
self.labels = labels
def north(self):
self.change([2, 6, 3, 4, 1, 5])
def south(self):
self.change([5, 1, 3, 4, 6, 2])
def east(self):
self.change([4, 2, 1, 6, 5, 3])
def west(self):
self.change([3, 2, 6, 1, 5, 4])
def change(self, convert):
result = []
for i in range(6):
result.append(self.labels[convert[i] - 1])
self.labels = result
dice = Dice(list(map(int, input().split())))
for i in range(int(input())):
up, front = map(int, input().split())
while(True):
direction = random.randint(0, 3)
if direction == 0:
dice.north()
if direction == 1:
dice.south()
if direction == 2:
dice.east()
if direction == 3:
dice.west()
if dice.labels[0] == up and dice.labels[1] == front:
print(dice.labels[2])
break | 0 | null | 351,535,831,790 | 41 | 34 |
X,Y = map(int,input().split())
prize = [0]*206
prize[1] = 300000
prize[2] = 200000
prize[3] = 100000
money = 0
if X == 1 and Y == 1:
money += 400000
print(money+prize[X]+prize[Y]) | x,y=map(int,input().split())
if x==y==1:
print(1000000);exit()
A=[300000,200000,100000]+[0]*1000
print(A[x-1]+A[y-1])
| 1 | 140,404,556,621,380 | null | 275 | 275 |
word = input()
if word[-1] == 's':
word += "e"
print(word + "s") | s = input()
l = []
for i in range(len(s)):
l.append(s[i])
if l[len(l)-1] == "s":
print(s+str("es"))
else:
print(s+str("s"))
| 1 | 2,410,505,627,968 | null | 71 | 71 |
n=int(input())
str1,str2=input().split()
for i in range(len(str1)):
print(str1[i]+str2[i],end="") | def num2alpha(num):
if num<=26:
return chr(64+num)
elif num%26==0:
return num2alpha(num//26-1)+chr(90)
else:
return num2alpha(num//26)+chr(64+num%26)
print(num2alpha(int(input())).lower()) | 0 | null | 61,976,246,067,562 | 255 | 121 |
n=int(input())
a=list()
for i in range(n):
s,t=input().split()
a.append([s,int(t)])
x=input()
flag=False
ans=0
for i in a:
if flag:
ans+=i[1]
if i[0]==x:
flag=True
print(ans) | n = int(input())
playlist = []
duration = []
for i in range(n):
s, t = input().split()
playlist.append(s)
duration.append(int(t))
index = playlist.index(input())
durations = sum(duration[index + 1: ])
print(durations) | 1 | 97,350,319,501,568 | null | 243 | 243 |
a = list(map(int,input().split()))
if a[0] == a[1]:print("Yes")
else:print("No") | N, K = map(int, input().split())
P = [0] + list(map(int, input().split()))
C = [0] + list(map(int, input().split()))
ans = -10 ** 9
for i in range(1, N + 1):
start = i
next_ = start
loop_score = 0
loop_count = 0
while True:
loop_count += 1
loop_score += C[next_]
next_ = P[next_]
if next_ == start:
break
in_score = 0
in_count = 0
for k in range(K):
in_count += 1
in_score += C[next_]
loop_num = (K - in_count) // loop_count
score = in_score + max(0, loop_score) * loop_num
ans = max(ans, score)
next_ = P[next_]
if next_ == start:
break
print(ans)
| 0 | null | 44,063,343,977,932 | 231 | 93 |
s = input()
l1 = len(s)
res = 0
for i in range(l1//2):
if s[i]!=s[-i-1]:res +=1
print(res) | N, M = map(int, input().split())
a = [False] * N
w = [0] * N
for i in range(M):
p, S = input().split()
if S == 'AC':
a[int(p)-1] = True
elif not a[int(p)-1]:
w[int(p)-1] += 1
print(a.count(True), sum([w[i] if a[i] else 0 for i in range(N)]))
| 0 | null | 106,814,584,242,012 | 261 | 240 |
import math
a = float(input())
print(str("{0:.6f}".format((a * a) * math.pi)) + " " + str("{0:.5f}".format((a + a) * math.pi)))
| N = int(input())
count = 0
for i in range(1,N):
if int(N/i)-N/i == 0:
count += int(N/i)-1
else:
count += int(N/i)
print(count) | 0 | null | 1,603,406,768,100 | 46 | 73 |
while 1:
n,m=map(int,input().split())
if n==0 and m==0:
break
if n<m:
print(n,m)
else:
print(m,n)
| import math, itertools
n = int(input())
X = list(list(map(int,input().split())) for _ in range(n))
L = list(itertools.permutations(range(n),n))
ans = 0
for l in L:
dist = 0
for i in range(n-1):
s,t = l[i],l[i+1]
vx = X[s][0] - X[t][0]
vy = X[s][1] - X[t][1]
dist += math.sqrt(vx**2 + vy**2)
ans += dist
print(ans/len(L)) | 0 | null | 74,385,976,569,392 | 43 | 280 |
L = int(input())
n = L/3
print(n*n*n) | import sys
read = sys.stdin.read
def main():
l = int(input())
print((l/3)**3)
if __name__ == '__main__':
main()
| 1 | 47,031,235,217,230 | null | 191 | 191 |
o = ['unsafe','safe']
s,w = map(int,input().split())
f = 0
if w >= s:
f = 0
else:
f = 1
print(o[f]) | S, W = (int(x) for x in input().split())
if W>=S:
print("unsafe")
else:
print("safe")
| 1 | 29,033,948,466,900 | null | 163 | 163 |
a = int(input())
if a % 2 == 0:
print(str(int(a//2)))
else:
print(str(int(a//2)+1)) | N=int(input())
result=N/2
if N%2 != 0:
result+=0.5
print(int(result)) | 1 | 59,038,816,950,772 | null | 206 | 206 |
import itertools
n,k=map(int,input().split())
d=[]
a=[]
for i in range(k):
d.append(int(input()))
a.append(list(map(int,input().split())))
a_1=itertools.chain.from_iterable(a)
print(n-len(list(set(a_1)))) | S = str(input())
print('x'*len(S))
| 0 | null | 48,851,363,159,156 | 154 | 221 |
from collections import Counter
counter = Counter()
while True:
try:
s = input()
for c in s:
counter[c.lower()] += 1
except:
break
for c in range(ord('a'), ord('z')+1):
print('{} : {}'.format(chr(c), counter[chr(c)])) | import sys
dic = {}
for i in range(ord('a'), ord('z') + 1):
dic[chr(i)] = 0
for line in sys.stdin:
for i in range(len(line)):
char = line[i].lower()
if char in dic.keys():dic[char] += 1
for i in range(ord('a'), ord('z') + 1):
print("{} : {}".format(chr(i), dic[chr(i)])) | 1 | 1,665,811,241,810 | null | 63 | 63 |
input()
S=input()
l=S[0]
c=1
for i in S[1:]:
if l!=i:
c+=1
l=i
print(c) | # -*- coding: utf-8 -*-
n = int(input())
s = input()
ans = 1
tmp = s[0]
for c in s:
if tmp != c:
ans += 1
tmp = c
print(ans)
| 1 | 169,921,674,404,680 | null | 293 | 293 |
def solve():
N = int(input())
return N*N
print(solve()) | #!/usr/bin/env python3
import sys
def main():
input = sys.stdin.readline
d, t, s = map(int, input().split())
if d / s <= t:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| 0 | null | 74,155,462,424,860 | 278 | 81 |
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0]
bb = [0]
for i in range(n):
aa.append(aa[-1]+a[i])
for i in range(m):
bb.append(bb[-1]+b[i])
c = m
ans = 0
for i in range(n+1):
u = k - aa[i]
for j in range(c, -1, -1):
if bb[j] <= u:
ans = max(ans, i+j)
c = j
break
print(ans) | n, m, k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
asum = [0]
bsum = [0]
for i in range(len(aa)):
asum.append(asum[i]+aa[i])
for i in range(len(bb)):
bsum.append(bsum[i]+bb[i])
j = len(bsum)-1
ans = 0
for i in range(len(asum)):
while j >= 0:
if k >= asum[i] + bsum[j]:
ans = max(ans, i+j)
break
else:
j -= 1
print(ans)
| 1 | 10,697,661,235,650 | null | 117 | 117 |
D = int(input())
clist = list(map(int, input().split()))
slist = [list(map(int, input().split())) for _ in range(D)]
tlist = [int(input()) for _ in range(D)]
zlist = []
dlist = [0] * 26
ans = 0
'''
print(sum(clist))
print('--------------')
print(slist[0][0])
print(slist[1][16])
print(clist[16])
print('--------------')
'''
for i in range(D):
#print(slist[i],tlist[i]-1)
zlist.append(clist[tlist[i]-1] * ((i+1) - dlist[tlist[i]-1]))
dlist[tlist[i]-1] = i+1
ans += slist[i][tlist[i]-1] - ((i+1) * sum(clist)) + sum(zlist)
print(ans) | import os, sys, re, math
r = int(input())
print(r * r)
| 0 | null | 77,574,462,586,618 | 114 | 278 |
N = int(input())
A = list(map(int, input().split()))
A_all = A[0]
for i in range(1,N):
A_all ^= A[i]
B = [0] * N
for j in range(N):
B[j] = A[j] ^ A_all
print(' '.join(map(str, B)))
| from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
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
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.parents[self.find(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 x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,m=nii()
uf=UnionFind(n)
for i in range(m):
a,b=nii()
a-=1
b-=1
uf.union(a,b)
root=uf.roots()
ans=0
for i in root:
ans=max(ans,uf.size(i))
print(ans) | 0 | null | 8,317,281,730,228 | 123 | 84 |
def MI(): return map(int, input().split())
from collections import deque
def bfs(field,s):
q=deque([(0,s)])
dist=[[-1]*W for _ in range(H)]
d,i,j=-1,-1,-1
MOVE=[(-1,0),(0,-1),(1,0),(0,1)]
while q:
d,(i,j)=q.popleft()
if dist[i][j]!=-1:
continue
dist[i][j]=d
for di,dj in MOVE:
ni,nj=i+di,j+dj
if not 0<=ni<H or not 0<=nj<W:
continue
if field[ni][nj]=='#':
continue
if dist[ni][nj]!=-1:
continue
q.append((d+1,(ni,nj)))
return d,i,j
H,W=MI()
field=[input() for _ in range(H)]
ans=0
for i in range(H):
for j in range(W):
if field[i][j]=='.':
d,i,j=bfs(field,(i,j))
ans=max(ans,d)
print(ans) | n, d = map(int, input().split())
x = [0 for i in range(n)]
y = [0 for i in range(n)]
for i in range(n):
x[i],y[i] = map(int, input().split())
cnt = 0
for i in range(n):
dis = x[i]*x[i] + y[i]*y[i]
if(dis<=d*d):
cnt+=1
print(cnt) | 0 | null | 50,041,009,847,598 | 241 | 96 |
import sys
X = int(input())
for i in range(1,1000):
if 360*i % X == 0:
print(360*i//X)
sys.exit() | import sys
import math
import numpy as np
import functools
import operator
import collections
import itertools
X=int(input())
ans=1
for i in range(1,100000):
if (X*i)%360==0:
print(ans)
sys.exit()
ans+=1 | 1 | 13,219,511,020,310 | null | 125 | 125 |
a, b = map(int, input().split())
if (a < 10):
if (b < 10):
ans = a * b
else:
ans = -1
else:
ans = -1
print(ans) | A,B=map(int,input().split())
print(A*B if 1<=A<=9 and 0<B<10 else -1) | 1 | 158,349,294,894,880 | null | 286 | 286 |
#約数全列挙
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
n=int(input())
#n%k!=0
cnt=len(make_divisors(n-1))-1
#n%k==0
lst=make_divisors(n)
for k in lst:
if k!=1:
t=n
while t%k==0:
t//=k
if (t-1)%k==0:
cnt+=1
print(cnt) | N = int(input())
if N == 2:
print(1)
exit()
ans = 1
divisors = []
d = 2
while d*d < N:
if N % d == 0:
divisors.append(d)
divisors.append(N//d)
d += 1
if d*d == N:
divisors.append(d)
for d in divisors:
dummyN = N
while dummyN % d == 0:
dummyN //= d
if dummyN % d == 1:
ans += 1
N -= 1
divisors = []
d = 2
while d*d < N:
if N % d == 0:
divisors.append(d)
divisors.append(N//d)
d += 1
if d*d == N:
divisors.append(d)
ans += len(divisors)+1
print(ans) | 1 | 41,450,985,801,098 | null | 183 | 183 |
N, M = map(int, input().split())
WA = [0] * (N+1)
AC = [0] * (N+1)
Q = [list(input().split()) for _ in range(M)]
for p, s in Q:
p = int(p)
if AC[p] == 1:
continue
if s == "WA":
WA[p] += 1
else:
AC[p] = 1
ans = 0
for w, a in zip(WA, AC):
if a:
ans += w
print(sum(AC), ans) | 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,257,580,598,922 | null | 240 | 240 |
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10 ** 9 + 7
N, K = map(int, readline().split())
d = [0] * (K+1)
for i in range(K,0,-1):
t = K // i
cnt = pow(t,N,MOD)
for j in range(2,t+1):
cnt -= d[i*j]
cnt %= MOD
d[i] = cnt
ans = 0
for num,cnt in enumerate(d):
ans += num * cnt
ans %= MOD
print(ans) | N,M = map(int, input().split())
A_list = [int(i) for i in input().split()]
playable_days = N - sum(A_list)
if playable_days >= 0:
print(playable_days)
else:
print("-1") | 0 | null | 34,582,588,849,940 | 176 | 168 |
import sys
from collections import defaultdict
def solve():
input = sys.stdin.readline
N, P = map(int, input().split())
S = input().strip("\n")
modSum = 0
modDict = defaultdict(int)
modDict[0] += 1
ans = 0
if P == 2 or P == 5:
for i in range(N):
if int(S[i]) % P == 0:
ans += i + 1
else:
for i in range(N):
modSum += int(S[N-i-1]) * pow(10, i, P)
modSum %= P
modDict[modSum] += 1
for key in modDict:
v = modDict[key]
ans += v * (v - 1) // 2
print(ans)
return 0
if __name__ == "__main__":
solve() | N,P=map(int,input().split());S,a,i,j,c=input(),0,0,1,[1]+[0]*P
if 10%P:
for v in S[::-1]:i,j=(i+int(v)*j)%P,j*10%P;a+=c[i];c[i]+=1
else:
for v in S:
i+=1
if int(v)%P<1:a+=i
print(a) | 1 | 57,883,030,135,190 | null | 205 | 205 |
n = int(input())
s = input()
pw, pw1, pw2 = [0] * n, [0] * n, [0] * n
pw[0], pw1[0], pw2[0] = 1, 1, 1
v, mod1, mod2 = 0, 0, 0
for i in range(n):
if s[i] == '1':
v += 1
for i in range(1, n):
pw1[i] = int(pw1[i - 1] * 2) % (v + 1)
if v >= 2:
pw2[i] = int(pw2[i - 1] * 2) % (v - 1)
for i in range(n):
if s[i] == '1':
mod1 = (mod1 + pw1[n - i - 1]) % (v + 1)
if v >= 2:
mod2 = (mod2 + pw2[n - i - 1]) % (v - 1)
for i in range(n):
copy, x, cnt = 0, v, 1
if s[i] == '0':
x += 1
copy = (mod1 + pw1[n - i - 1]) % x
else:
x -= 1
if x >= 1:
copy = (mod2 - pw2[n - i - 1]) % x
else:
copy = -1
if copy == -1:
print(0)
else:
x = bin(copy).count('1')
while copy > 0:
copy %= x
x = bin(copy).count('1')
cnt += 1
print(cnt)
| from sys import stdin,stdout #
import math #
import heapq #
#
t = 1 #
def aint(): #
return int(input().strip()) #
def lint(): #
return list(map(int,input().split())) #
def fint(): #
return list(map(int,stdin.readline().split())) #
#
########################################################
def f(n):
if n==0:
return 0
# print(n)
N=n
cnt=0
while(N):
cnt+=N&1
N>>=1
return f(n%cnt)+1
def main():
n=aint()
x=input()
c=x.count("1")
if(c==0):
for i in range(n):
print("1")
return
elif(c==1):
for i in range(n):
if(x[i]=="1"):
print(0)
elif x[i]=="0":
if x[n-1]=="1"or i==(n-1):
print("2")
else:
print(1)
return
mod1=c+1
mod2=c-1
mul1=1
mul2=1
rem1=0
rem2=0
for i in range(n-1,-1,-1):
if(x[i]=='1'):
rem1=(rem1+mul1)%mod1
rem2=(rem2+mul2)%mod2
mul1=(2*mul1)%mod1
mul2=(2*mul2)%mod2
ans=[]
mul1=1
mul2=1
# print(mod1,mod2)
# print(rem1,rem2)
for i in range(n-1,-1,-1):
if(x[i]=='0'):
# print("At index",i,"val",(rem1+mul1)%mod1)
ans.append(f((rem1+mul1)%mod1)+1)
else:
# print("At index",i,"val",(rem2-mul2)%mod2)
ans.append(f((rem2-mul2)%mod2)+1)
mul1=(2*mul1)%mod1
mul2=(2*mul2)%mod2
# print("Ans:")
for i in range(n-1,-1,-1):
print(ans[i])
return
#t=int(input())
########################################################
for i in range(t): #
#print("Case #"+str(i+1)+":",end=" ") #
main() # | 1 | 8,220,123,551,092 | null | 107 | 107 |
D=int(input())
c=list(map(int,input().split()))
c_memo=[0]*26
s=[]
for i in range(D):
ss=list(map(int,input().split()))
s.append(ss)
ans_b=[]
for i in range(D):
t=int(input())
c_down=0
for j in range(26):
if j==t-1:
c_memo[t-1]=i+1
continue
else:
c_down+=(i+1-c_memo[j])*c[j]
ans=s[i][t-1]-c_down
ans_b.append(ans)
ans=0
for x in ans_b:
ans+=x
print(ans)
| A = list(map(int,input().split()))
if sum(A) > 21:print("bust")
else:print('win') | 0 | null | 64,611,613,156,742 | 114 | 260 |
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
def mycol(data,col):
return [ row[col] for row in data ]
def mysort(data,col,reverse=False):
data.sort(key=lambda x:x[col],reverse=revese)
return data
def mymax(data):
M = -1*float("inf")
for i in range(len(data)):
m = max(data[i])
M = max(M,m)
return M
def mymin(data):
m = float("inf")
for i in range(len(data)):
M = min(data[i])
m = min(m,M)
return m
def mycount(ls,x):
# lsはソート済みであること
l = bisect_left(ls,x)
r = bisect_right(ls,x)
return (r-l)
def mydictvaluesort(dictionary):
return sorted( dictionary.items(), key=lambda x:x[1] )
def mydictkeysort(dictionary):
return sorted( dictionary.items(), key=lambda x:x[0] )
def myoutput(ls,space=True):
if space:
if len(ls)==0:
print(" ")
elif type(ls[0])==str:
print(" ".join(ls))
elif type(ls[0])==int:
print(" ".join(map(str,ls)))
else:
print("Output Error")
else:
if len(ls)==0:
print("")
elif type(ls[0])==str:
print("".join(ls))
elif type(ls[0])==int:
print("".join(map(str,ls)))
else:
print("Output Error")
def I():
return int(input())
def MI():
return map(int,input().split())
def RI():
return list(map(int,input().split()))
def CI(n):
return [ int(input()) for _ in range(n) ]
def LI(n):
return [ list(map(int,input().split())) for _ in range(n) ]
def S():
return input()
def MS():
return input().split()
def RS():
return list(input())
def CS(n):
return [ input() for _ in range(n) ]
def LS(n):
return [ list(input()) for _ in range(n) ]
# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())
n,k = MI()
a = RI()
L = max(a)
def mycheck(l):
count = 0
for i in range(n):
count += a[i]//l
return count <= k
lb = 0
ub = L
for i in range(100):
# print(ub,lb)
mid = (lb+ub)/2
# print(mid)
flag = mycheck(mid)
# print(flag)
if flag:
ub = mid
else:
lb = mid
ans = ceil(lb)
print(ans) | from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))
from functools import reduce
def main():
N, K = ril()
A = ril()
l = 1
r = 1000000000
while l < r:
m = (l + r) // 2
f = lambda i, j : i + (j - 1) // m
k = reduce(f, A, 0)
if k <= K:
r = m
else:
l = m + 1
print(r)
if __name__ == '__main__':
main()
| 1 | 6,529,042,857,172 | null | 99 | 99 |
n, k = map(int, input().split())
MOD = 1000000007
def combinations(n, r, MOD):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * fact_inv[r] * fact_inv[n - r] % MOD
fact = [1, 1]
fact_inv = [1, 1]
inv = [0, 1]
for i in range(2, n + 1):
fact.append((fact[-1] * i) % MOD)
inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
fact_inv.append((fact_inv[-1] * inv[-1]) % MOD)
s = 0
for num_zero in range(min(k + 1, n)):
# nCz
x = combinations(n, num_zero, MOD)
# n-zCx
y = combinations(n - 1, n - num_zero - 1, MOD)
s += (x * y) % MOD
print(s % MOD)
| import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): 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
count = 0
ans = 0
inf = float("inf")
a,v = I()
b,w = I()
t = k()
sa = v-w
if sa <= 0:
print("NO")
sys.exit()
kyori = abs(b-a)
if (kyori / sa)<=t:
print("YES")
else:
print("NO")
| 0 | null | 41,147,103,769,760 | 215 | 131 |
# swag
from collections import deque
class SWAG_Stack():
def __init__(self, F):
self.stack1 = deque()
self.stack2 = deque()
self.F = F
self.len = 0
def push(self, x):
if self.stack2:
self.stack2.append((x, self.F(self.stack2[-1][1], x)))
else:
self.stack2.append((x, x))
self.len += 1
def pop(self):
if not self.stack1:
while self.stack2:
x, _ = self.stack2.pop()
if self.stack1:
self.stack1.appendleft((x, self.F(x, self.stack1[0][1])))
else:
self.stack1.appendleft((x, x))
self.stack1.popleft()
self.len -= 1
def sum_all(self):
if self.stack1 and self.stack2:
return self.F(self.stack1[0][1], self.stack2[-1][1])
elif self.stack1:
return self.stack1[0][1]
elif self.stack2:
return self.stack2[-1][1]
else:
raise IndexError
n,m = map(int, input().split())
s = input()
stack = SWAG_Stack(min)
stack.push((0,n))
turn = [-1]*(n+1)
turn[-1] = 0
for i in range(n-1, -1, -1):
if s[i] == "1":
stack.push((float("inf"), i))
else:
cost, ind = stack.sum_all()
if cost == float("inf"):
break
turn[i] = cost+1
stack.push((cost+1, i))
if stack.len > m:
stack.pop()
# print(turn)
if turn[0] == -1:
print(-1)
exit()
prev_turn=turn[0]
prev_ind = 0
ans = []
for i in range(1, n+1):
if prev_turn-turn[i] == 1:
ans.append(i-prev_ind)
prev_ind = i
prev_turn = turn[i]
print(*ans)
| n, m = map(int, input().split())
s = input()
x = n
roulette = []
while x > m:
for i in range(m, 0, -1):
if s[x-i] == '0':
x -= i
roulette.append(i)
break
else:
print(-1)
exit()
roulette.append(x)
roulette.reverse()
print(' '.join(map(str, roulette))) | 1 | 139,142,394,278,160 | null | 274 | 274 |
n = int(input())
print(n * n * n) | A,B = map(int, input().split())
A1,B1 = str(A), str(B)
A2 = int(str(A)*B)
B2 = int(str(B)*A)
if A2 >= B2:
print(A2)
else:
print(B2) | 0 | null | 42,246,968,034,260 | 35 | 232 |
N, K = list(map(int, input().split(' ')))
marks = list(map(int, input().split(' ')))
for i in range(N-K):
if marks[i] < marks[K+i]:
print('Yes')
else:
print('No') | import numpy as np
# 解説みた
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(K, N):
if A[i] / A[i - K] > 1:
print("Yes")
else:
print("No")
"""
・書き始める前に式変形等考える
・判定分を吟味する。(実際の数、今回でいうと積、で比較しない)
"""
| 1 | 7,091,166,099,640 | null | 102 | 102 |
X = int(input())
flag = 0
for i in range(-150,150):
for j in range(-150,150):
if(i**5 - j**5 == X):
print(i,j)
flag = 1
break
if(flag==1):
break | import sys
input = sys.stdin.readline
X = int(input())
A = 1
B = 0
while True:
while A**5 - B**5 < X:
B -= 1
if A**5 - B**5 == X:
print(A,B)
exit()
B = A
A += 1 | 1 | 25,662,261,223,940 | null | 156 | 156 |
a = list(map(int, input().split()))
suma = a[0] + a[1] + a[2]
if suma >= 22:
print('bust')
else:
print('win') | print('bust' if sum(list(map(int,input().split()))) > 21 else 'win') | 1 | 119,035,867,309,590 | null | 260 | 260 |
def Qb():
k = int(input())
s = input()
if len(s) <= k:
print(s)
else:
print(f'{s[:k]}...')
if __name__ == '__main__':
Qb()
| from collections import Counter
N,MOD=map(int,input().split())
S=input()
res=0
if MOD==2 or MOD==5:
for i in range(N):
if(int(S[N-i-1])%MOD==0):
res+=N-i
else:
Cum=[0]*(N+1)
for i in range(N):
Cum[i+1]=(Cum[i]+int(S[N-i-1])*pow(10,i,MOD))%MOD
c=Counter(Cum).most_common()
for a,b in c:
res+=b*(b-1)//2
print(res) | 0 | null | 38,849,561,313,850 | 143 | 205 |
S = list(map(str, input().split()))
print(S[1] + S[0]) | a,b=map(int,input().split())
c,d=map(int,input().split())
t=int(input())
if abs(a-c)<=(b-d)*t:
print('YES')
else:
print('NO')
| 0 | null | 59,150,189,419,420 | 248 | 131 |
import itertools
n, m, x = map(int, input().split())
A = []
for _ in range(n):
A.append(list(map(int, input().split())))
c = [ (0, 1) for _ in range(n)]
min_price = float('inf')
for cc in itertools.product(*c):
xx = [0] * m
price = 0
for i, ccc in enumerate(cc):
if ccc==1:
price += A[i][0]
xx = [a +b for a, b in zip(xx, A[i][1:])]
if min(xx) >= x:
min_price = min(min_price, price)
if min_price==float('inf'):
print(-1)
else:
print(min_price) | u, s, e, w, n, d = input().split()
insts = input()
for inst in insts:
if inst == 'N':
u, s, n, d = s, d, u, n
elif inst == 'E':
u, e, w, d = w, u, d, e
elif inst == 'S':
u, s, n, d = n, u, d, s
elif inst == 'W':
u, e, w, d = e, d, u, w
print(u) | 0 | null | 11,167,816,140,420 | 149 | 33 |
d=list(map(int,input().split()))
q=int(input())
class dice(object):
def __init__(self, d):
self.d = d
def roll(self,com):
a1,a2,a3,a4,a5,a6=self.d
if com=="E":
self.d = [a4,a2,a1,a6,a5,a3]
elif com=="W":
self.d = [a3,a2,a6,a1,a5,a4]
elif com=="S":
self.d = [a5,a1,a3,a4,a6,a2]
elif com=="N":
self.d = [a2,a6,a3,a4,a1,a5]
dice1=dice(d)
l=[]
for i in range(q):
l.append(list(map(int,input().split())))
c=["E","W","S","N"]
import random
for i in l:
while 1:
if dice1.d[0]==i[0] and dice1.d[1]==i[1]:
break
else:
dice1.roll(c[random.randint(1,2)])
print(dice1.d[2]) | n,k=input().split()
n=int(n)
k=int(k)
clist=list(map(int,input().split()))
clist.sort()
print(sum(clist[:k])) | 0 | null | 5,991,559,628,530 | 34 | 120 |
import sys
sys.setrecursionlimit(10 ** 9)
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
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
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
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 x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M, K = map(int, input().split())
uf = UnionFind(N)
FG = [0] * N
BG = [0] * N
for _ in range(M):
a, b = map(int, input().split())
a, b = a-1, b-1
uf.union(a, b)
FG[a] += 1
FG[b] += 1
for _ in range(K):
c, d = map(int, input().split())
c, d = c-1, d-1
if uf.same(c, d):
BG[c] += 1
BG[d] += 1
ans = []
for i in range(N):
ans.append(uf.size(i) - FG[i] - BG[i] - 1)
print(*ans) | N = int(input())
M = 10
ans = 0
if N % 2 == 0:
while N >= M:
ans += N//M
M *= 5
print(ans) | 0 | null | 88,379,390,072,860 | 209 | 258 |
import bisect
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
A.sort()
INF = 10 ** 9
A.append(INF)
left, right = 0, 2 * max(A)
while left + 1 < right:
mid = (left + right) >> 1
cnt = sum(N - bisect.bisect_left(A, mid-A[i]) for i in range(N))
if cnt >= M:
left = mid
else:
right = mid
acc = [0]
for i in range(N):
acc.append(acc[-1] + A[i])
ans = 0
cnt, min_val = 0, INF
for i in range(N):
idx = bisect.bisect_left(A, left-A[i])
cnt += N - idx
min_val = min(min_val, A[i] + A[idx])
ans += (N - idx) * A[i] + acc[N] - acc[idx]
ans -= (cnt - M) * min_val
print(ans)
| from math import sqrt
def solve(n):
s = list(map(float,input().split()))
m = sum(s)/n
a = sqrt(sum([(si-m)**2 for si in s])/n)
print('{0:.6f}'.format(a))
while True:
n = int(input())
if n==0:break
solve(n)
| 0 | null | 53,920,247,736,622 | 252 | 31 |
import itertools
n = input()
a = list(map(int, input().split()))
q = input()
aset = set()
for i in range(1, len(a) + 1):
aset |= set(sum(combi) for combi in itertools.combinations(a, i))
for m in map(int, input().split()):
print('yes' if m in aset else 'no') | n=int(input())
output=''
for _ in range(n):
output+='ACL'
print(output) | 0 | null | 1,156,221,496,052 | 25 | 69 |
n = int(input())
a = sorted(map(int, input().split()), reverse=True)
ans, que, cnt = 0, [a[0]], 0
for i in a[1:]:
ans += que[cnt]
que += [i, i]
cnt += 1
print(ans)
| import sys; input = sys.stdin.readline
# n, m , k = map(int, input().split())
# matrix = [list(input().strip()) for _ in range(n)]
n = int(input())
lis = sorted(map(int, input().split()), reverse=True)
ans = lis[0]
i = 1
c = 1
while c<n-1:
if c < n-1: ans += lis[i]; c+=1
if c < n-1: ans += lis[i]; c+=1
i+=1
print(ans)
| 1 | 9,142,840,574,120 | null | 111 | 111 |
a,b,c=map(int,raw_input().split())
if a>b:
a,b=b,a
if b>c:
b,c=c,b
if a>b:
a,b=b,a
print a,b,c | x = sorted([int(i) for i in input().split()])
print("{0} {1} {2}".format(x[0],x[1],x[2])) | 1 | 425,894,713,002 | null | 40 | 40 |
n = int(input())
i = 1
while i <= n:
x = i
if x % 3 == 0:
print(" {:d}".format(i),end="")
else:
while x:
if x % 10 == 3:
print(" {:d}".format(i),end="")
break
x = x // 10
i += 1
print("")
| def Check_Num(n):
for i in range(1,n + 1):
x = i
if (x % 3 == 0):
print(' {}'.format(i),end = '')
continue
elif (x % 10 == 3):
print(' {}'.format(i),end = '')
continue
x //= 10
while (x > 0):
if (x % 10 == 3):
print(' {}'.format(i),end = '')
break
x //= 10
print()
if __name__ == '__main__':
n = int(input())
Check_Num(n)
| 1 | 914,178,066,758 | null | 52 | 52 |
import itertools
import math
N = int(input())
XY = [list(map(int, input().split())) for i in range(N)]
n = [i for i in range(N)]
dist = 0
cnt = 0
for target_list in list(itertools.permutations(n)):
for i in range(len(target_list)):
if i == 0:
continue
dist += math.sqrt((XY[target_list[i]][0] - XY[target_list[i-1]][0]) ** 2 + (XY[target_list[i]][1] - XY[target_list[i-1]][1]) ** 2)
cnt += 1
print(dist / cnt) | K = int(input())
if(7%K == 0):
print(1)
else:
mod = 7%K
for i in range(2, K+1):
if(mod * 10 + 7)%K == 0:
print(i)
break
mod = (mod * 10 + 7)%K
else:
print(-1) | 0 | null | 77,255,387,897,522 | 280 | 97 |
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
def main():
N,K = map(int,input().split())
a = list(map(int,input().split()))
d = defaultdict(int)
cum = [0]
for i in range(N):
cum.append((cum[-1]+a[i]-1)%K)
ans = 0
for i in range(N+1):
ans += d[cum[i]]
d[cum[i]] += 1
if i >= K-1:
d[cum[i-K+1]] -= 1
print(ans)
if __name__ == "__main__":
main()
| d, t, s = map(int, input().split())
if s * t >= d:
print("Yes")
else:
print("No") | 0 | null | 70,251,661,456,000 | 273 | 81 |
#Union Find
#xの根を求める
def find(x):
if par[x] < 0:
return x
else:
par[x] = find(par[x])
return par[x]
#xとyの属する集合の併合
def unite(x,y):
x = find(x)
y = find(y)
if x == y:
return False
else:
#sizeの大きいほうがx
if par[x] > par[y]:
x,y = y,x
par[x] += par[y]
par[y] = x
return True
#xとyが同じ集合に属するかの判定
def same(x,y):
return find(x) == find(y)
#xが属する集合の個数
def size(x):
return -par[find(x)]
#初期化
#根なら-size,子なら親の頂点
n,m = map(int,input().split())
par = [-1]*n
for i in range(m):
a,b = map(int,input().split())
unite(a-1,b-1)
ans = 0
for i in range(n):
if par[i] < 0:
ans += 1
print(ans-1) | n,m = list(map(int, input().split()))
parent = list(range(n))
def root(x):
if parent[x] == x: return x
rt = root(parent[x])
parent[x] = rt
return rt
def unite(x,y):
x = root(x)
y = root(y)
if x == y: return
parent[y] = x
for _ in range(m):
a,b = list(map(lambda x: int(x)-1, input().split()))
unite(a,b)
for i in range(n):
root(i)
cnt = len(set(parent)) - 1
print(cnt) | 1 | 2,313,631,448,180 | null | 70 | 70 |
data = []
try:
while True:
data.append(raw_input())
except EOFError:
pass
n = int(data[0])
if n <= 1000:
for i in range(1, n+1):
x, y, z = data[i].split()
x, y, z = int(x), int(y), int(z)
if x <= 1000 and y <= 1000 and z <= 1000:
if (z * 0.8 == x and z * 0.6 == y
or z * 0.8 == y and z * 0.6 == x
or y * 0.8 == x and y * 0.6 == z
or y * 0.8 == z and y * 0.6 == x
or x * 0.8 == z and x * 0.6 == y
or x * 0.8 == y and x * 0.6 == z):
print "YES"
else:
print "NO" | n = int(input())
for i in range(n):
a,b,c = map(int,input().split(" "))
if a**2 == b**2 + c**2:
print("YES")
elif b**2 == a**2 + c**2:
print("YES")
elif c**2 == a**2 + b**2:
print("YES")
else:
print("NO") | 1 | 355,495,348 | null | 4 | 4 |
debt = 100000
n=int(raw_input())
for i in range(1,n+1):
debt = debt*1.05
if(debt % 1000) != 0:
debt = (debt - (debt%1000)) + 1000
print int(debt) | debt=100000
week=input()
for i in range(week):
debt=debt*1.05
if debt%1000!=0:
debt=int(debt/1000)*1000+1000
print debt | 1 | 1,067,934,714 | null | 6 | 6 |
INF = int(1e18)
def merge(A, left, mid, right):
n1 = mid - left
n2 = right - mid
L = [A[left + i] for i in range(n1)]
R = [A[mid + i] for i in range(n2)]
L.append(INF)
R.append(INF)
i, j = 0, 0
count = 0
for k in range(left, right):
count += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return count
def merge_sort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
c1 = merge_sort(A, left, mid)
c2 = merge_sort(A, mid, right)
c = merge(A, left, mid, right)
return c + c1 + c2
else:
return 0
if __name__ == '__main__':
n = int(input())
A = list(map(int, input().split()))
c = merge_sort(A, 0, n)
print(" ".join(map(str, A)))
print(c)
| def m(L,R):
global c
T=[];i=j=0
for _ in L[:-1]+R[:-1]:
if L[i]<R[j]:T+=[L[i]];i+=1
else:T+=[R[j]];j+=1
c+=1
return T
def d(A):s=len(A)//2;return m(d(A[:s])+[1e9],d(A[s:])+[1e9]) if len(A)>1 else A
c=0
input()
print(*d(list(map(int,input().split()))))
print(c)
| 1 | 110,816,616,392 | null | 26 | 26 |
r=int(input())
print(2*(22/7)*r) | def main():
a, b, c = map(int, input().split())
if(a+b+c >= 22):
print('bust')
else:
print('win')
return 0
if __name__ == '__main__':
main() | 0 | null | 74,867,254,823,200 | 167 | 260 |
line = raw_input()
line2 = ''
for s in line:
if s == '\n':
break
elif s.islower():
line2 += s.upper()
elif s.isupper():
line2 += s.lower()
else:
line2 += s
print line2 | '''
ITP-1_8-A
??§????????¨?°????????????\?????????
????????????????????????????°?????????¨??§???????????\????????????????????°????????????????????????????????????
???Input
????????????1???????????????????????????
???Output
????????????????????????????°?????????¨??§???????????\????????????????????????????????????????????????
??¢????????????????????\???????????????????????????????????????????????????
'''
# inputData
inputData = input()
for i in range(len(inputData)):
if "a"<=inputData[i]<="z":
# ??§????????????
print(inputData[i].upper(),end='')
elif "A"<=inputData[i]<="Z":
# ?°?????????????
print(inputData[i].lower(),end='')
else:
# ??¢????????????????????\?????????????????????
print(inputData[i],end='')
# ????????????
print('') | 1 | 1,516,611,329,222 | null | 61 | 61 |
def mapt(fn, *args):
return tuple(map(fn, *args))
def main():
n, k = mapt(int, (input().split(" ")))
a = sorted(mapt(int, input().split(" ")))
if k >= len(a): print(0); exit()
while k > 0:
a.pop()
k -= 1
print(sum(a))
main() | n, k = map(int, input().split())
h = sorted(list(map(int, input().split())))
if k==0: print(sum(h))
else: print(sum(h[:-k]))
| 1 | 78,959,017,855,718 | null | 227 | 227 |
#!/usr/bin/env python3
import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter # itemgetter(1), itemgetter('key')
# from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict # subclass of dict. defaultdict(facroty)
# from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate # accumulate(iter[, f])
# from functools import reduce # reduce(f, iter[, init])
# from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy # to copy multi-dimentional matrix without reference
# from fractions import gcd # for Python 3.4 (previous contest @AtCoder)
def main():
mod = 1000000007 # 10^9+7
inf = float('inf') # sys.float_info.max = 1.79...e+308
# inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19
sys.setrecursionlimit(10**6) # 1000 -> 1000000
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def mi_0(): return map(lambda x: int(x)-1, input().split())
def lmi(): return list(map(int, input().split()))
def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
def li(): return list(input())
n = ii()
l_p_only = []
r_p_only = []
r_p_l_p = []
for _ in range(n):
s = input()
left_cnt = 0
right_cnt = 0
for char in s:
if char == ')':
if left_cnt > 0:
left_cnt -= 1
else:
right_cnt += 1
else:
left_cnt += 1
if left_cnt == 0 and right_cnt == 0:
pass
elif right_cnt == 0:
l_p_only.append(left_cnt)
elif left_cnt == 0:
r_p_only.append(- right_cnt)
else:
r_p_l_p.append([- right_cnt, left_cnt])
# print(l_p_only)
# print(r_p_l_p)
# print(r_p_only)
current_left = sum(l_p_only)
pos = []
neg = []
for elm in r_p_l_p:
if elm[0] + elm[1] >= 0:
pos.append(elm)
else:
neg.append(elm)
pos.sort(key=lambda x: x[0], reverse=True) # 負の値が大きい順、0 に近い順
for elm in pos:
current_left += elm[0]
if current_left >= 0:
current_left += elm[1]
else:
print('No')
exit()
neg.sort(key=lambda x: x[0]) # 負の値が小さい順、- に大きい順に最初のうちにやっておく
for elm in neg:
current_left += elm[0]
if current_left >= 0:
current_left += elm[1]
else:
print('No')
exit()
if current_left >= 0 and current_left == - sum(r_p_only):
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
| def count(i, s):
left = right = 0
for e in s:
if e == "(":
left += 1
else:
if left == 0:
right += 1
else:
left -= 1
return left-right, left, right, i
n = int(input())
S = [input() for i in range(n)]
s1 = []
s2 = []
for i, e in enumerate(S):
c = count(i, e)
# print(i, c)
if c[0] >= 0:
s1.append((c[2], c[3]))
else:
s2.append((-c[1], c[3]))
s1.sort()
s2.sort()
# print(s1, s2)
s = []
for e in s1:
s.append(S[e[1]])
for e in s2:
s.append(S[e[1]])
# print(s)
_, left, right, _ = count(0, "".join(s))
if left == right == 0:
print("Yes")
else:
print("No")
| 1 | 23,670,422,231,170 | null | 152 | 152 |
while(True):
a = input()
if '?' in a:
break
print(int(eval(a)))
| while True:
t = input()
if t.find("?") > 0:
break
print(int(eval(t))) | 1 | 685,125,182,042 | null | 47 | 47 |
import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
n,m,l = map(int, input().split())
d=[[sys.maxsize]*(n) for _ in range(n)]
e=[[sys.maxsize]*(n) for _ in range(n)]
for i in range(n):
d[i][i] = 0
e[i][i] = 0
for _ in range(m):
a,b,c = map(int, input().split())
d[a-1][b-1]=c
d[b-1][a-1]=c
d=floyd_warshall(csr_matrix(d))
for i in range(n):
for j in range(n):
if d[i][j] <= l:
e[i][j] = 1
e=floyd_warshall(csr_matrix(e))
q=int(input())
for _ in range(q):
s,t = map(int, input().split())
if e[s-1][t-1] == sys.maxsize:
print(-1)
else:
print(int(e[s-1][t-1]-1)) | import sys
input = sys.stdin.readline
n, m, l = map(int, input().split())
INF = float("inf")
def warshall_floyd(d, n):
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
return d
d = [[INF] * n for _ in range(n)]
for i in range(n):
d[i][i] = 0
for i in range(m):
a, b, c = map(int, input().split())
d[a - 1][b - 1] = c
d[b - 1][a - 1] = c
d = warshall_floyd(d, n)
d2 = [[INF] * n for _ in range(n)]
for i in range(n):
for j in range(n):
if d[i][j] <= l:
d2[i][j] = 1
d2[i][i] = 0
d2 = warshall_floyd(d2, n)
q = int(input())
for _ in range(q):
s, t = map(int, input().split())
res = d2[s - 1][t - 1]
print(-1 if res == INF else res - 1) | 1 | 173,459,464,532,158 | null | 295 | 295 |
#! /usr/bin/env python3
import itertools
import sys
sys.setrecursionlimit(10**9)
INF=10**20
def solve(N: int, P: "List[int]", Q: "List[int]"):
X = list(range(1,N+1))
R = []
for r in itertools.permutations(X,N):
R.append(int("".join(list(map(str,r)))))
R.sort()
P = int("".join(P))
Q = int("".join(Q))
a,b = 0,0
for i,r in enumerate(R):
if r == P:
a = i
if r == Q:
b = i
print(abs(a-b))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
P = [str(next(tokens)) for _ in range(N)] # type: "List[int]"
Q = [str(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, P, Q)
if __name__ == "__main__":
main()
| N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in A:
N -= i
if N >= 0:
print(N)
else:
print(-1)
| 0 | null | 66,412,023,842,430 | 246 | 168 |
A = int(input())
B = int(input())
if A != 1 and B != 1:
print('1')
elif A != 2 and B != 2:
print('2')
else:
print('3')
| N=int(input())
a=1
sum=0
while a in range(N+1):
if a%3 !=0 and a%5 !=0:
sum=sum+a
a = a + 1
else:a=a+1
print(sum)
| 0 | null | 73,130,295,527,508 | 254 | 173 |
d=int(input())
*c,=map(int, input().split())
s=[]
for _ in range(d):
*si,=map(int, input().split())
s.append(si)
t=[int(input())-1 for _ in range(d)]
last=[-1]*26
smx=0
ss=0
for i in range(d):
ss+=s[i][t[i]]
last[t[i]]=i
for j in range(26):
ss-= c[j]*(i-last[j])
print(ss)
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: B
# CreatedDate: 2020-06-28 21:02:34 +0900
# LastModified: 2020-06-28 22:01:44 +0900
#
import os
import sys
# import numpy as np
# import pandas as pd
def main():
d = int(input())
c = list(map(int, input().split()))
s = [] # 満足度
box = [-1]*26 # 各コンテストの実施日
for i in range(d):
s.append(list(map(int, input().split())))
total_satisfy = 0
for i in range(d):
t = int(input())
total_satisfy += s[i][t-1]
box[t-1] = i
for j in range(26):
if box[j] == -1:
total_satisfy -= c[j]*(i+1)
else:
total_satisfy -= c[j]*(i-box[j])
# print(box)
print(total_satisfy)
if __name__ == "__main__":
main()
| 1 | 9,936,680,575,678 | null | 114 | 114 |
def merge(targ,first,mid,last):
left = targ[first:mid] + [10 ** 9 + 1]
right = targ[mid:last] + [10 ** 9 + 1]
leftcnt = rightcnt = 0
global ans
for i in range(first,last):
ans += 1
#print(left,right,left[leftcnt],right[rightcnt],targ,ans)
if left[leftcnt] <= right[rightcnt]:
targ[i] = left[leftcnt]
leftcnt += 1
else:
targ[i] = right[rightcnt]
rightcnt += 1
def mergesort(targ,first,last):
if first +1 >= last:
pass
else:
mid = (first + last) // 2
mergesort(targ,first,mid)
mergesort(targ,mid,last)
merge(targ,first,mid,last)
ans = 0
num = int(input())
targ = [int(n) for n in input().split(' ')]
mergesort(targ,0,num)
print(" ".join([str(n) for n in targ]))
print(ans) | import math
def merge(a, left, mid, right):
global c
n1 = mid - left
n2 = right - mid
l = a[left:left + n1]
r = a[mid:mid + n2]
l.append(10e10)
r.append(10e10)
i = 0
j = 0
for k in range(left, right):
c += 1
if l[i] < r[j]:
a[k] = l[i]
i += 1
else:
a[k] = r[j]
j += 1
def mergeSort(a, left, right):
if left + 1 < right:
mid = math.ceil((left + right) / 2)
mergeSort(a, left, mid)
mergeSort(a, mid, right)
merge(a, left, mid, right)
n = int(input())
a = list(map(int,input().split()))
c = 0
mergeSort(a, 0, n)
print(" ".join(map(str, a)))
print(c)
| 1 | 114,257,360,030 | null | 26 | 26 |
A, B, M=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c = [list(map(int, input().split())) for i in range(M)]
# とりあえず最小
minc=min(a)+min(b)
for v in c:
minc = min(minc, (a[v[0]-1]+b[v[1]-1]-v[2]))
print(minc) | from sys import stdin
input = lambda: stdin.readline().rstrip()
na, nb, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for i in range(m):
x, y, c = map(int, input().split())
x -= 1
y -= 1
ans = min(ans, a[x] + b[y] - c)
print(ans)
| 1 | 54,011,287,532,468 | null | 200 | 200 |
import sys
import bisect
def input():
return sys.stdin.readline().rstrip()
def main():
N = int(input())
A = []
B = []
for i in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
pass
A.sort()
B.sort()
if N % 2 == 0:
n = N // 2
mini = (A[n]+A[n-1]) /2
maxi = (B[n]+B[n-1]) /2
print(int((maxi-mini)*2)+1)
else:
n = N//2
mini = A[n]
maxi = B[n]
print(maxi-mini+1)
if __name__ == "__main__":
main()
| import sys,math
input = sys.stdin.readline
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
c = [(i*j,j) for i,j in zip(a,f)]
m = max(c)
def is_ok(arg):
# 条件を満たすかどうか?問題ごとに定義
chk = 0
for i,j in c:
chk += math.ceil(max(0,(i-arg))/j)
return chk <= k
def bisect_ok(ng, ok):
'''
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
まずis_okを定義
ng = 最小の値-1 ok = 最大の値+1 で最小
最大最小が逆の場合はng ok をひっくり返す
'''
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
print(bisect_ok(-1,m[0]+1)) | 0 | null | 91,232,640,695,480 | 137 | 290 |
A, B, C = map(int, input().split())
K = int(input())
while B <= A and K:
B *= 2
K -= 1
while C <= B and K:
C *= 2
K -= 1
print('Yes' if A < B < C else 'No')
| S=str(input())
ls = ["SAT","FRI","THU","WED","TUE","MON","SUN"]
for i in range(7):
if S == ls[i]:
print(i+1)
| 0 | null | 69,640,159,855,556 | 101 | 270 |
n, k = map(int, input().split())
nums = list(map(int, input().split()))
# (sums[j] - sums[i]) % K = j - i
# (sums[j] - j) % K = (sums[i] - i) % K
# 1, 4, 2, 3, 5
# 0, 1, 5, 7, 10, 15
# 0, 0, 3, 0, 2, 2
sums = [0]
for x in nums:
sums.append(sums[-1] + x)
a = [(sums[i] - i) % k for i in range(len(sums))]
res = 0
memo = {}
i = 0
for j in range(len(a)):
memo[a[j]] = memo.get(a[j], 0) + 1
if j - i + 1 > k:
memo[a[i]] -= 1
i += 1
res += memo[a[j]] - 1
print(res) | n = int(input())
a = list(map(int, input().split()))
x = 0
for a_i in a:
x ^= a_i
for a_i in a:
print(x ^ a_i) | 0 | null | 75,149,806,056,588 | 273 | 123 |
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
n = II()
aa = MII()
q = II()
bc = [MII() for _ in range(q)]
sumv = sum(aa)
numbers = [0]*(10**5+1)
for a in aa:
numbers[a] += 1
for b,c in bc:
numb = numbers[b]
sumv += numb*(c-b)
print(sumv)
numbers[b] = 0
numbers[c] += numb
if __name__ == '__main__':
main() | x,y = map(int,input().split())
if(x+y==2):
print(1000000)
else:
answer = 0
if(x==2):
answer+=200000
elif(x==3):
answer+=100000
elif(x==1):
answer+=300000
if(y==2):
answer+=200000
elif(y==3):
answer+=100000
elif(y==1):
answer+=300000
print(answer)
| 0 | null | 76,393,074,021,856 | 122 | 275 |
import sys
# 再起回数上限変更
sys.setrecursionlimit(1000000)
N, R = map(int, input().split())
if N >= 10:
print(R)
sys.exit()
print(R + 100 * (10 - N))
| x = int(input())
print('Yes' if x >= 30 else 'No') | 0 | null | 34,648,461,128,256 | 211 | 95 |
import sys
sys.setrecursionlimit(1000000)
N = int(input())
X = input()
pc = X.count('1')
if pc == 0:
print(*[1]*N, sep='\n')
exit()
elif pc == 1:
if int(X, 2) == 1:
for i in range(N-1):
print(2)
print(0)
exit()
else:
for i in range(N):
if i == N-1:
print(2)
elif X[i] == '0':
print(1)
else:
print(0)
exit()
mod_plus_1, mod_minus_1 = 0, 0
for i in range(N):
mod_plus_1 = (mod_plus_1*2+int(X[i])) % (pc+1)
mod_minus_1 = (mod_minus_1*2+int(X[i])) % (pc-1)
def f(x):
if x == 0:
return 0
else:
return f(x % bin(x).count('1'))+1
mods_p1, mods_m1 = [1 % (pc+1)], [1 % (pc-1)]
for i in range(N-1):
mods_p1.append(mods_p1[-1]*2 % (pc+1))
mods_m1.append(mods_m1[-1]*2 % (pc-1))
mods_p1 = mods_p1[::-1]
mods_m1 = mods_m1[::-1]
for i in range(N):
if X[i] == '0':
x = mod_plus_1 + mods_p1[i]
x %= (pc+1)
else:
x = mod_minus_1 - mods_m1[i]
x %= (pc-1)
if x == 0:
print(1)
else:
print(f(x)+1)
| from collections import defaultdict
n, k = map(int, input().split())
A = list(map(int, input().split()))
delta_count = defaultdict(int)
sum = [0]
delta_count[0] += 1
for i in range(n):
sum.append(sum[i] + A[i])
ans = 0
for i in range(1, min(n + 1, k)):
x = (sum[i] - i) % k
ans += delta_count[x]
delta_count[x] += 1
for i in range(min(n + 1, k), n + 1):
delta_count[(sum[i - k] - i - k) % k] -= 1
x = (sum[i] - i) % k
ans += delta_count[x]
delta_count[x] += 1
print(ans) | 0 | null | 73,213,070,836,962 | 107 | 273 |
N = int(input())
P = []
for i in range(N):
s = [int(i) for i in input().split()]
P.append(s)
L = []
for i in range(N-1):
for j in range(i+1, N):
l = (P[i][0] - P[j][0])**2 + (P[i][1] - P[j][1])**2
L.append(l**0.5)
S = sum(L)
print(2*S/N) | a, b = map(int, input().split())
print('%d %d %f' % (a / b, a % b, a / b))
| 0 | null | 74,812,515,111,180 | 280 | 45 |
N = int(input())
P = list(map(int,input().split()))
a = 0
s = 10**6
for p in P:
if p<s:
a+=1
s = min(s,p)
print(a) | n=int(input())
p=list(map(int,input().split()))
res=p[0]
cnt=0
for i in p:
if res>=i:
cnt+=1
res=min(res,i)
print(cnt)
| 1 | 85,408,717,162,970 | null | 233 | 233 |
def solve():
H,W,M = map(int,input().split())
h_counter = [0] * H
w_counter = [0] * W
opponents = []
for _ in range(M):
h, w = map(lambda x:int(x)-1, input().split())
h_counter[h] += 1
w_counter[w] += 1
opponents.append((h,w))
h_max = max(h_counter)
w_max = max(w_counter)
h_max_area_cnt = 0
h_max_area_nums = set()
for h in range(H):
if h_counter[h] == h_max:
h_max_area_nums.add(h)
h_max_area_cnt += 1
w_max_area_cnt = 0
w_max_area_nums = set()
for w in range(W):
if w_counter[w] == w_max:
w_max_area_nums.add(w)
w_max_area_cnt += 1
max_area_cnt = h_max_area_cnt * w_max_area_cnt
opponent_in_max_area = 0
for h,w in opponents:
if h in h_max_area_nums and w in w_max_area_nums:
opponent_in_max_area += 1
if max_area_cnt > opponent_in_max_area:
print(h_max + w_max)
else:
print(h_max + w_max - 1)
if __name__ == '__main__':
solve()
| H, W, M = map(int, input().split())
row=[0]*H #x座標を入れるっちゅうかカウント
col=[0]*W #y座標を入れる
mat=[] #座標を入れる
for i in range(M):
h, w = map(int, input().split())
row[h-1]+=1
col[w-1]+=1
mat.append((h-1,w-1))
r=max(row)
c=max(col)
rr=[1 if row[i]==r else 0 for i in range(H)] #maxな列のインデックス
cc=[1 if col[i]==c else 0 for i in range(W)] #maxな行のインデックス
x=0 #maxな列と行の交差点にある爆弾の個数をカウント
for k in mat:
if rr[k[0]]==1 and cc[k[1]]==1:
x+=1
if sum(rr)*sum(cc)==x: #行と列の全ての交差点に爆弾があれば-1する
print(r+c-1)
else:
print(r+c) | 1 | 4,696,846,551,968 | null | 89 | 89 |
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
S = LS2()
r = 0
left,right = [],[]
Q = I()
for i in range(Q):
A = LS()
if A[0] == '1':
r = 1-r
else:
f,c = A[1],A[2]
if (r == 0 and f == '1') or (r == 1 and f == '2'):
left.append(c)
else:
right.append(c)
if r == 0:
left.reverse()
print(''.join(left+S+right))
else:
S.reverse()
right.reverse()
print(''.join(right+S+left))
| def main():
n = int(input())
a_lst = list(map(int, input().split()))
dic = dict()
for i in range(n - 1):
if a_lst[i] in dic:
dic[a_lst[i]] += 1
else:
dic[a_lst[i]] = 1
dic_keys = dic.keys()
for i in range(1, n + 1):
if i in dic_keys:
print(dic[i])
else:
print(0)
if __name__ == "__main__":
main()
| 0 | null | 44,981,912,057,440 | 204 | 169 |
_ = int(input())
hoge = [int(x) for x in input().split()]
_ = int(input())
def exSearch(i, m):
if m == 0:
return True
if i >= len(hoge) or m > sum(hoge):
return False
res = exSearch(i+1, m) or exSearch(i+1, m-hoge[i])
return res
if __name__ == '__main__':
for val in (int(x) for x in input().split()):
if exSearch(0, val):
print ('yes')
else:
print ('no')
| def power_set(A, s):
if len(A) == 0:
return {s}
else:
return power_set(A[1:], s) | power_set(A[1:], s+A[0])
def main():
n = int(input())
A = input()
#print(n)
A = list(map(int, A.split()))
q = int(input())
m = input()
ms = list(map(int, m.split()))
powerset = power_set(A, 0)
for m in ms:
if m in powerset:
print('yes')
else:
print('no')
if __name__ == '__main__':
main() | 1 | 97,034,343,140 | null | 25 | 25 |
a,b = map(int, raw_input().split(" "))
result = ""
if a < b:
result = "a < b"
elif a > b:
result = "a > b"
else:
result = "a == b"
print result |
import queue
WHITE = 0
GRAY = 1
BLACK = 2
NIL = -1
INF = 1000000000
def bfs(u):
global Q
Q.put(u)
for i in range(n):
d[i] = NIL
d[u] = 0
while not Q.empty():
u = Q.get()
for v in range(n):
if (m[u][v] == 1) and (d[v] == NIL):
d[v] = d[u] + 1
Q.put(v)
n = int(input())
m = [[0 for i in range(n + 1)] for j in range(n + 1)]
vid = [0] * n
d = [0] * n
f = [0] * n
Q = queue.Queue()
color = [WHITE] * n
time = 0
nt = [0] * n
tmp = []
for i in range(n):
nums=list(map(int,input().split()))
tmp.append(nums)
vid[i] = nums[0]
for i in range(n):
for j in range(tmp[i][1]):
m[i][vid.index(tmp[i][j + 2])] = 1
bfs(0)
for i in range(n):
print(vid[i], d[i])
| 0 | null | 178,065,118,308 | 38 | 9 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort(reverse=True)
F.sort()
C = [None] * N
for i, (a, f) in enumerate(zip(A, F)):
C[i] = (a * f, f)
def solve(x):
global K, N
t = 0
for c, f in C:
temp = ((c - x) + f - 1) // f
t += max(0, temp)
if t > K:
result = False
break
else:
result = True
return result
ok = A[0] * F[N - 1]
ng = -1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if solve(mid):
ok = mid
else:
ng = mid
print(ok)
| n, k = map(int, input().split())
a_list = [int(i) for i in input().split()]
f_list = [int(i) for i in input().split()]
a_list.sort(reverse=True)
f_list.sort()
if k >= sum(a_list):
print(0)
exit()
point = []
for i in range(n):
point.append(a_list[i] * f_list[i])
import math
def binary_search(point, k):
left = 0
right = 10 ** 12
while left + 1< right:
ans = 0
center = (left + right) // 2
for i in range(n):
if point[i] > center:
ans += a_list[i] - (center // f_list[i])
if ans <= k:
right = center
else:
left = center
return left
value = binary_search(point, k)
print(value + 1)
| 1 | 165,040,776,564,146 | null | 290 | 290 |
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
D1 = abs(A-B)
D2 = (V-W)*T
if (D1 - D2) <=0:
print("YES")
else:
print("NO")
| a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a <= b:
print("YES" if a + v * t >= b + w * t else "NO")
else:
print("YES" if b - w * t >= a - v * t else "NO")
| 1 | 15,001,594,914,150 | null | 131 | 131 |
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
from collections import defaultdict
g = defaultdict(list)
for a, b in ab:
a -= 1
b -= 1
g[a].append(b)
g[b].append(a)
k = 0
for key in g:
k = max(k, len(g[key]))
print(k)
ans = dict()
q = [(0, -1)] # (pos, used_color)
visited = set([0])
while q:
cur, col = q.pop()
if col == 0:
tmp = 1
else:
tmp = 0
for target in g[cur]:
if target not in visited:
q.append((target, tmp))
visited.add(target)
ans[(cur, target)] = tmp
if tmp + 1 == col:
tmp += 2
else:
tmp += 1
for a, b in ab:
key = (a-1, b-1)
print(ans[key] + 1)
| #create date: 2020-07-05 13:34
import sys
stdin = sys.stdin
from collections import deque
def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def main():
n = ni()
g = [list() for _ in range(n)]
to = list()
for i in range(n-1):
a, b = na()
a -= 1; b -= 1
g[a].append(b)
to.append(b)
l = [-1] * n
l[0] = 10**10
q = deque([0])
while q:
v = q.popleft()
vcolor = l[v]
for i, w in enumerate(g[v]):
q.append(w)
if i < vcolor:
l[w] = i
else:
l[w] = i + 1
print(max(l[1:])+1)
for i in to:
print(l[i]+1)
if __name__ == "__main__":
main() | 1 | 136,264,595,410,702 | null | 272 | 272 |
N=int(input())
DMY=10**9
mmax=None
mmin=None
dmax=None
dmin=None
for i in range(N):
x,y = map(int, input().split())
if not mmax:
mmax=(x,y,x+y)
mmin=(x,y,x+y)
dmax=(x,y,x+DMY-y)
dmin=(x,y,x+DMY-y)
continue
if x+y > mmax[2]:
mmax=(x,y,x+y)
elif x+y < mmin[2]:
mmin=(x,y,x+y)
if x+DMY-y > dmax[2]:
dmax=(x,y,x+DMY-y)
elif x+DMY-y < dmin[2]:
dmin=(x,y,x+DMY-y)
print(max(mmax[2]-mmin[2],dmax[2]-dmin[2]))
| L=list(map(int,input().split()))
L[2],L[0]=L[0],L[2]
L[1],L[2]=L[2],L[1]
print(*L) | 0 | null | 20,666,354,410,272 | 80 | 178 |
count = 0
W = input().lower()
T = [0]
while True:
try:
if T[0] == "END_OF_TEXT":
break
for t in T:
if W == t:
count += 1
T = [x.lower() for x in input().split()]
except EOFError:
break
except IndexError:
break
print(count) | W=input()
a=0
while True:
T=input()
if T=='END_OF_TEXT':
break
else:
a +=T.lower().split().count(W)
print(a)
| 1 | 1,839,230,082,180 | null | 65 | 65 |
import math
L,R,d = map(int, input().strip().split())
x=math.ceil(L/d)
y=math.floor(R/d)
print(y-x+1)
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
count = 0
l, r, d= [int(x) for x in readline().rstrip().split()]
#print(l,r,d)
for i in range(l,r+1):
if i % d == 0:
count += 1
print(count)
| 1 | 7,548,392,596,678 | null | 104 | 104 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.