code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
import sys
input = sys.stdin.readline
def main():
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [0] * M
for i in range(M):
xyc[i] = map(int, input().split())
ans = min(a) + min(b)
for x, y, c in xyc:
price = a[x - 1] + b[y - 1] - c
if price < ans:
ans = price
print(ans)
if __name__ == "__main__":
main()
|
from sys import stdin
import math
import re
import queue
input = stdin.readline
MOD = 1000000007
INF = 122337203685477580
def solve():
A,B,M = map(int, input().split())
v1 =list(map(int, input().split()))
v2 =list(map(int, input().split()))
res = INF
for i in range(M):
X,Y,C = map(int, input().split())
res = min(res,v1[X-1] + v2[Y-1] - C)
res = min(res,min(v1) + min(v2))
res = max(0,res)
print(res)
if __name__ == '__main__':
solve()
| 1 | 54,181,134,981,890 | null | 200 | 200 |
# encoding: utf-8
def main():
n = input()
t = map(int, raw_input().split())
q = input()
s = map(int, raw_input().split())
sum = 0
for a in s:
sum += 1 if a in t else 0
print sum
main()
|
if __name__ == "__main__":
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
for i in T:
if i in S:
ans += 1
print(ans)
| 1 | 64,834,091,728 | null | 22 | 22 |
from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]
arr1 = []
arr2 = []
for i in range(1, n + 1):
arr1.append(i - a[i - 1])
arr2.append(i + a[i - 1])
dis1 = Counter(arr1)
dis2 = Counter(arr2)
ans = 0
for i in dis1.keys():
ans += dis1[i] * dis2[i]
print(ans)
|
import sys
l = [int(i) for i in sys.stdin.readline().split()]
l.sort()
print(" ".join(map(str, l)))
| 0 | null | 13,238,442,765,700 | 157 | 40 |
import sys
from numba import njit
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
@njit(cache=True)
def solve(n, k, a):
if k == 0:
return a
b = [0]*n
for _ in range(k):
for i in range(n):
if i > a[i]:
b[i-a[i]] += 1
else:
b[0] += 1
if i + a[i] + 1 < n:
b[i + a[i] + 1] -= 1
for i in range(n-1):
b[i+1] += b[i]
a[i] = 0
a[-1] = 0
b, a = a, b
if min(a) >= n:
break
return a
solve(0, 0, [0, 1, 2])
n, k = nm()
a = nl()
print(*solve(n, k, a))
|
def main(n,k,a):
for _ in range(k):
b=[0]*(n+1)
for i,j in enumerate(a):
b[max(0,i-j)]+=1
b[min(n,i+j+1)]-=1
for i in range(n):
b[i+1]+=b[i]
if a==b:break
a=b
print(*a[:-1])
N,K,*A=map(int,open(0).read().split())
main(N,K,A)
| 1 | 15,510,677,845,056 | null | 132 | 132 |
while True:
line = list(map(int,input().split()))
if line==[0,0]: break
for i in range(line[0]):
if i==0 or i==line[0]-1: print('#'*line[1])
else: print('#'+'.'*(line[1]-2)+'#')
print()
|
n = input()
x = len(n)
inf = 10 ** 9
#dp[i][flg]...i桁目まで、未満フラグ=1
dp = [[inf] * 2 for _ in range(x+1)]
dp[0][0] = 0
dp[0][1] = 1
for i in range(x):
s = int(n[i])
dp[i+1][0] = min(dp[i][0] + s, dp[i][1] + 10 - s)
dp[i+1][1] = min(dp[i][0] + s + 1, dp[i][1] + 9 - s)
print(dp[x][0])
| 0 | null | 35,767,302,744,280 | 50 | 219 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
?´???°
?´???°??? 1 ??¨????????°??????????????§????????????????????¶??°????´???°??¨?¨?????????????
n ????????´??°???????????????????????????????????????????´???°?????°???????????????????????°????????????????????????????????????
"""
import math
def isPrime(x):
""" ??¨???????????????????¢¨?´???°?????? """
if x == 2: # ??¶??°??§?´???°??????????????°
return True
if x % 2 == 0: # 2??\????????¶??°????´???°??§?????????
return False
rx = int(math.sqrt(x)) + 1
for i in range(3, rx, 2): # ?????????????????°?????????????????????
if x % i == 0:
return False
return True
# ?????????
n = int(input().strip())
a = []
for i in range(n):
a.append(int(input().strip()))
cnt = 0
for i in a:
if isPrime(i) == True:
cnt += 1
print(cnt)
|
import sys
from collections import Counter
from itertools import accumulate
read = sys.stdin.read
N, K, *A = map(int, read().split())
a = list(accumulate([0] + A))
a = [(a[i] - i) % K for i in range(N + 1)]
answer = 0
if N < K:
for i in Counter(a).values():
answer += i * (i - 1) // 2
else:
dic = Counter(a[:K])
for i in dic.values():
answer += i * (i - 1) // 2
here = K
for i, x in enumerate(a[K:]):
dic[a[i]] -= 1
answer += dic[x]
dic[x] += 1
print(answer)
| 0 | null | 69,148,942,837,618 | 12 | 273 |
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
x = [0] * (N + 1)
y = [0] * (M + 1)
for i in range(N):
x[i + 1] = x[i] + A[i]
for i in range(M):
y[i + 1] = y[i] + B[i]
j = M
ans = 0
for i in range(N + 1):
if x[i] > K:
continue
while j >= 0 and x[i] + y[j] > K:
j -= 1
ans = max(ans, i + j)
print(ans)
|
def main():
X, Y = map(int, input().split())
print(gcd(X, Y))
def gcd(a, b):
if a < b:
a, b = b, a
r = a % b
if r == 0:
return b
else:
a = b
b = r
return gcd(a, b)
main()
| 0 | null | 5,388,052,598,400 | 117 | 11 |
x = int(input())
print(0 if x else 1)
|
print(int(not int(input())))
| 1 | 2,978,322,261,612 | null | 76 | 76 |
R = int(input())
a = (44/7)*R
print(a)
|
r = int(input())
import math
ans = 2 * math.pi * r
print(ans)
| 1 | 31,664,317,862,880 | null | 167 | 167 |
A, B = map(int,input().split())
def gcd(a,b):
if b == 0:
return a
return gcd(b,a%b)
def lcm(a,b):
return a*b//gcd(a,b)
print(lcm(A,B))
|
A, B = map(int, input().split(" "))
if A % B == 0:
print(A)
elif B % A == 0:
print(B)
else:
A_, B_ = A, B
common = 1
n_max = int(min(A,B)**0.5+1)
for n in range(2, n_max+1):
while True:
if (A_ % n == 0) and (B_ % n == 0):
common *= n
A_ = A_ // n
B_ = B_ // n
else:
break
print(common * A_ * B_)
| 1 | 113,543,513,316,170 | null | 256 | 256 |
n,k = map(int,input().split())
m = n%k
a = abs(k - m)
l = [m,a]
print(min(l))
|
n,k=map(int,input().split())
m=n%k
print(min(m,abs(m-k)))
| 1 | 39,176,229,943,632 | null | 180 | 180 |
import collections
n,u,v=map(int,input().split())
g=[[] for _ in range(n+1)]
for _ in range(n-1):
a,b=map(int,input().split())
g[a].append(b)
g[b].append(a)
q=collections.deque()
q.append((v,0))
checked=[0]*(n+1)
dist1=[0]*(n+1)
while len(q)!=0:
tv,td=q.popleft()
checked[tv]=1
dist1[tv]=td
for tu in g[tv]:
if checked[tu]==1:
continue
q.append((tu,td+1))
q=collections.deque()
q.append((u,0))
checked=[0]*(n+1)
dist2=[0]*(n+1)
while len(q)!=0:
tv,td=q.popleft()
checked[tv]=1
dist2[tv]=td
for tu in g[tv]:
if checked[tu]==1:
continue
q.append((tu,td+1))
ans=0
for tv in range(1,n+1):
if dist1[tv]>dist2[tv]:
ans=max(ans,dist1[tv]-1)
print(ans)
|
from collections import deque
import sys
sys.setrecursionlimit(10**7)
N,u,v=map(int, input().split())
D=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int, input().split())
a-=1
b-=1
D[a].append(b)
D[b].append(a)
Taka=[0]*(N+1)
Aoki=[0]*(N+1)
def f(n,p,A):
for i in D[n]:
if i!=p:
A[i]=A[n]+1
f(i,n,A)
f(u-1,-1,Taka)
f(v-1,-1,Aoki)
ans=0
for i in range(N):
if Taka[i]<Aoki[i]:
ans=max(ans,Aoki[i]-1)
print(ans)
| 1 | 117,637,053,051,520 | null | 259 | 259 |
#輸入字串並分隔,以list儲存
str_in = input()
num = [int(n) for n in str_in.split()]
num =list(map(int, str_in.strip().split()))
#print(num) #D,T,S
#若T<(D/S)->遲到
if num[1] >= (num[0]/num[2]):
print("Yes")
else:
print("No")
|
d, t, s = map(int, input().split())
print('Yes') if d / s <= t else print('No')
| 1 | 3,525,145,554,738 | null | 81 | 81 |
# uppercase = A, lowercase = a
n = input()
if n.isupper():
print('A')
else:
print('a')
|
A=input()
if str.isupper(A):
print('A')
else:
print('a')
| 1 | 11,318,589,782,252 | null | 119 | 119 |
#!/usr/bin/env python3
import sys
MOD = 1000000007 # type: int
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1] # 階乗を求めるためのキャッシュ
self.invModulos = [0, 1] # n^-1のキャッシュ
self.invFactorial_ = [1, 1] # (n^-1)!のキャッシュ
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0]*(n+1-len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n+1):
prev = nextArr[i-initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0]*(n+1-len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n+1)):
next = -self.invModulos[p % i]*(p//i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0]*(n+1-len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n+1):
prev = nextArr[i-initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def choose_k_from_n(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n-k)
f = self.factorial
return f.calc(n)*f.invFactorial(max(n-k, k))*f.invFactorial(min(k, n-k)) % self.MOD
def solve(N: int, K: int, A: "List[int]"):
c = Combination(MOD)
A.sort()
minSum = 0
for i in range(N-K+1):
remain = N-i-1
minSum = (minSum + A[i]*c.choose_k_from_n(remain, K-1)) % MOD
maxSum = 0
A.reverse()
for i in range(N-K+1):
remain = N-i-1
maxSum = (maxSum + A[i]*c.choose_k_from_n(remain, K-1)) % MOD
print((maxSum - minSum + MOD) % MOD)
return
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
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
K = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, K, A)
if __name__ == '__main__':
main()
|
# coding: utf-8
# Your code here!
num_str = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
num_str = num_str.split(", ")
input_str = input()
print(num_str[int(input_str)-1])
| 0 | null | 73,274,830,981,660 | 242 | 195 |
import sys
from itertools import combinations
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W, K = map(int, readline().split())
S = [readline().strip() for _ in range(H)]
ans = INF
for r in range(H):
for comb in combinations(range(1, H), r):
sep = [0]
sep.extend(list(comb))
sep.append(H)
res = r
A = [0] * (r + 1)
for j in range(W):
B = [0] * (r + 1)
for k in range(r + 1):
for i in range(sep[k], sep[k + 1]):
if S[i][j] == '1':
B[k] += 1
ok = True
divided = False
for k in range(r + 1):
if B[k] > K:
ok = False
break
if A[k] + B[k] > K:
divided = True
break
else:
A[k] += B[k]
if not ok:
res = INF
break
if divided:
A = B
res += 1
if ans > res:
ans = res
print(ans)
return
if __name__ == '__main__':
main()
|
from collections import defaultdict
H,W,K = map(int,input().split())
S = [0] * H
for i in range(H):
S[i] = input()
INF = H + W - 2
def bi(x):
global H
o = [0]*(H-1)
i = 0
while x != 0:
o[i] = x % 2
i += 1
x //= 2
return o
def hoge(n):
global K
b = bi(n)
d = defaultdict(set)
j = 0
for i in range(H):
d[j].add(i)
if i == H - 1:
break
if b[i]:
j += 1
dlen = len(d)
T = [0]*dlen
for k,V in d.items():
T[k] = [0]*W
for i in range(W):
for v in V:
T[k][i] += int(S[v][i])
if T[k][i] > K:
return INF
ans = dlen - 1
U = [T[x][0] for x in range(dlen)]
for i in range(1,W):
flag = 0
for k in range(dlen):
U[k] += T[k][i]
if U[k] > K:
flag = 1
if flag == 1:
ans += 1
for k in range(dlen):
U[k] = T[k][i]
return ans
ANS = INF
for i in range(2**(H-1)):
ANS = min(ANS,hoge(i))
print(ANS)
| 1 | 48,583,996,629,796 | null | 193 | 193 |
n = int(input())
dp = [1] * (n+1)
for j in range(n-1):
dp[j+2] = dp[j+1] + dp[j]
print(dp[n])
|
#!/usr/bin/env python3
import sys
YES = "Yes" # type: str
NO = "No" # type: str
def solve(N: str):
B = [0]
for i in range(len(N)):
T = B[i] + int(N[i])
B.append(T)
A = B[len(N)] - B[0]
if A % 9 ==0:
return print(YES)
else:
return print(NO)
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = next(tokens) # type: str
solve(N)
if __name__ == '__main__':
main()
| 0 | null | 2,228,045,981,436 | 7 | 87 |
deg = int(input())
if deg >= 30:
print("Yes")
else:
print("No")
|
def ac_control(q):
if q >= 30:
print("Yes")
else:
print("No")
if __name__ == '__main__':
q = int(input())
ac_control(q)
| 1 | 5,735,838,942,760 | null | 95 | 95 |
import math
a,b,c,d = map(int,input().split(" "))
taka = math.ceil(c/b)
aoki = math.ceil(a/d)
if taka <= aoki:
print("Yes")
else:
print("No")
|
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
a, b, c, d = map(int, input().split())
while a > 0 and c > 0:
c -= b
if c <= 0:
print('Yes')
sys.exit()
a -= d
if a <= 0:
print('No')
sys.exit()
if __name__ == '__main__':
main()
| 1 | 29,732,557,796,840 | null | 164 | 164 |
n=int(input())
a=list(map(int,input().split()))
b=[]
s=0
for aa in a:
s^=aa
for aa in a:
b.append(s^aa)
print(*b)
|
N,A,B = map(int,input().split())
a = N//(A+B)
b = N%(A+B)
if b>A:
print(a*A+A)
else:
print(a*A+b)
| 0 | null | 33,942,402,766,630 | 123 | 202 |
s =input()
n = len(s)
if s[:(n-1)//2] ==s[:(n-1)//2][::-1] and s == s[::-1] and s[(n+3)//2-1:] == s[(n+3)//2-1:][::-1]:
print('Yes')
else:
print('No')
|
import sys
from collections import Counter
input = sys.stdin.readline
N = int(input())
S = input().strip()
counter = Counter(S)
if len(counter) < 3:
print(0)
sys.exit()
exclude = 0
max_w = N // 2
for w in range(1, max_w+1):
for i in range(N):
if N <= i + 2*w:
continue
if S[i] != S[i+w] and S[i] != S[i+2*w] and S[i+w] != S[i+2*w]:
exclude += 1
# print(exclude)
print(counter["R"] * counter["G"] * counter["B"] - exclude)
| 0 | null | 41,204,857,412,250 | 190 | 175 |
n,m,k = map(int,input().split())
ans = 0
g = [[i for i in input()] for i in range(n)]
for maskY in range(1 << n):
ng = [[0]*m for i in range(n)]
for bit in range(n):
if maskY & (1 << bit):
for i in range(m):
ng[bit][i] = 1
for maskX in range(1 << m):
ngg = [[i for i in j] for j in ng]
# print(ngg)
for bit in range(m):
if maskX & (1 << bit):
for i in range(n):
ngg[i][bit] = 1
cnt = 0
for y in range(n):
for x in range(m):
if g[y][x]=="#" and ngg[y][x]==0:
cnt += 1
# print(cnt)
if cnt == k:
ans += 1
print(ans)
|
#!/usr/bin/env python3
import sys
from itertools import combinations as comb
from itertools import chain
import numpy as np
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
def solve(H, W, K, C):
answer = 0
for hn in range(H + 1):
for wn in range(W + 1):
for h_idxs in comb(range(H), hn):
for w_idxs in comb(range(W), wn):
cs = C.copy()
cs[h_idxs, :] = 0
cs[:, w_idxs] = 0
answer += cs.sum() == K
return answer
def main():
tokens = chain(*(line.split() for line in sys.stdin))
H = int(next(tokens))
W = int(next(tokens))
K = int(next(tokens))
C = np.array(
[
list(map(lambda x: {"#": 1, ".": 0}[x], line))
for line in tokens
]
)
answer = solve(H, W, K, C)
print(answer)
if __name__ == "__main__":
main()
| 1 | 8,961,436,140,160 | null | 110 | 110 |
import sys
dict = {}
n = int(input())
l = []
line = map(lambda x:x.split(), sys.stdin.readlines())
s = ""
for (c,arg) in line:
if c == "insert":
dict[arg] = 0
elif c == "find":
if arg in dict:
s += "yes\n"
else:
s += "no\n"
print(s,end="")
|
# -*- coding: utf-8 -*-
# input
a, b = map(int, input().split())
x = list(map(int, input().split()))
print('Yes') if a <= sum(x) else print('No')
| 0 | null | 38,907,780,243,768 | 23 | 226 |
# A - Don't be late
D, T, S = map(int, input().split())
if (D + S - 1) // S <= T:
print('Yes')
else:
print('No')
|
a = input()
if a == "AAA" or a == "BBB" :
print ("No")
else : print ("Yes")
| 0 | null | 29,092,972,762,976 | 81 | 201 |
def SelectionSort(A, n):
sw = 0
for i in xrange(n):
minj = i
for j in xrange(i, n):
if A[j] < A[minj]:
minj = j
temp = A[minj]
A[minj] = A[i]
A[i] = temp
if i != minj:
sw += 1
return sw
def printArray(A, n):
for i in xrange(n):
if i < n-1:
print A[i],
else:
print A[i]
n = input()
arr = map(int, raw_input().split())
cnt = SelectionSort(arr, n)
printArray(arr, n)
print cnt
|
a=int(input())
b=list(map(int,input().split()))
n=1
result=0
for i in range(a):
if b[i]!=n:
result+=1
elif b[i]==n:
n+=1
if result==a:
print(-1)
else:
print(result)
| 0 | null | 57,299,203,664,652 | 15 | 257 |
S=input()
N=len(S)+1
LEFT=[0]
RIGHT=[0]
left=0
right=0
for i in range(N-1):
if S[i]==">":
left=0
else:
left+=1
LEFT+=[left]
for i in range(N-2,-1,-1):
if S[i]=="<":
right=0
else:
right+=1
RIGHT+=[right]
ans=0
for i in range(N):
ans+=max(LEFT[i],RIGHT[N-1-i])
print(ans)
|
a, b, c = map(int, input().split())
cnt = 0
for num in range(a, b + 1):
if c % num == 0:
cnt += 1
print(cnt)
| 0 | null | 78,301,339,961,142 | 285 | 44 |
def solve(n, k, a):
for i in range(k, n):
print("Yes" if a[i-k] < a[i] else "No")
n, k = map(int, input().split())
a = list(map(int, input().split()))
solve(n, k, a)
|
import numpy as np
mod = 10**9+7
n=int(input())
A=np.array(list(map(int,input().split())))
ans = 0
for i in range(60):
n1 = np.count_nonzero((A>>i)&1)
n0 = n-n1
ans += (2**i)*n1*n0 % mod
ans %= mod
print(ans)
| 0 | null | 65,278,789,402,668 | 102 | 263 |
#!/usr/bin/env python3
def main():
N = int(input())
print(-(-N // 2))
main()
|
x = int(input())
print(x//2+x%2)
| 1 | 58,984,412,508,800 | null | 206 | 206 |
import sys
x = int(input())
import math
# 素数判定関数
def isPrime(num):
# 2未満の数字は素数ではない
if num < 2: return False
# 2は素数
elif num == 2: return True
# 偶数は素数ではない
elif num % 2 == 0: return False
# 3 ~ numまでループし、途中で割り切れる数があるか検索
# 途中で割り切れる場合は素数ではない
for i in range(3, math.floor(math.sqrt(num))+1, 2):
if num % i == 0:
return False
# 素数
return True
# 素数判定
def callIsPrime(input_num=1000):
numbers = []
# ループしながら素数を検索する
for i in range(1, input_num):
if isPrime(i):
numbers.append(i)
# 素数配列を返す
return numbers
# 関数の呼び出し
# print(callIsPrime(100000+4)[-1])
for i in callIsPrime(100000+4):
if i>=x:
print(i)
sys.exit()
|
import math
n = int(input())
print(math.floor(n / 2) - (1-n%2))
| 0 | null | 129,620,530,425,668 | 250 | 283 |
num = int(input())
A=list(map(int,input().split(" ")))
chg = 0
for i in range(num-1):
minv = i+1
for j in range(i+2,num):
if A[minv] > A[j]:
minv = j
if A[i] > A[minv]:
A[i],A[minv] = A[minv],A[i]
chg += 1
print(*A)
print(chg)
|
n=int(input())
c=0
a=list(map(int,input().split()))
for i in range(n):
m=i
for j in range(i,n):
if a[m]>a[j]:m=j
if i!=m:a[m],a[i]=a[i],a[m];c+=1
print(*a)
print(c)
| 1 | 21,027,946,380 | null | 15 | 15 |
tmp = map(int, raw_input().split())
tmp.sort()
for i in tmp:
print i,
|
a, b, c = map(int, input().split())
if(a > b) :
a, b = b, a
if(b > c) :
b, c = c, b
if(a > b) :
a, b = b, a
else :
pass
else :
pass
print(a, b, c)
else :
if(b > c) :
b, c = c, b
if(a > b) :
a, b = b, a
else :
pass
else :
pass
print(a, b, c)
| 1 | 418,746,061,732 | null | 40 | 40 |
n, p = map(int,input().split())
D = input()
out = 0
if 10 % p == 0:
for i in range(n):
if int(D[i]) % p == 0:
out += i + 1
else:
mod = 0
count = [0] * p
ten = 1
count[mod] += 1
for i in range(n):
mod = (mod + int(D[n-i-1]) * ten) % p
ten = ten * 10 % p
count[mod] += 1
for c in count:
out += (c * (c - 1)) // 2
print(out)
|
N = int(raw_input())
A = map(int, raw_input().split())
def selectionSort(A, N):
count = 0
for i in range(0, N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
if i != minj:
temp = A[i]
A[i] = A[minj]
A[minj] = temp
count += 1
return count
count = selectionSort(A, N)
print " ".join(map(str, A))
print count
| 0 | null | 29,063,353,259,648 | 205 | 15 |
from collections import deque
V = int(input())
edge = [[] for _ in range(V)]
for _ in range(V):
u, _, *v = map(lambda x: int(x)-1, input().split())
edge[u] = sorted(v)
dist = [-1] * V
dist[0] = 0
que = deque([0])
while len(que):
v = que.popleft()
for c in edge[v]:
if dist[c] == -1:
dist[c] = dist[v] + 1
que.append(c)
for i, d in enumerate(dist):
print(i+1, d)
|
from collections import deque
def bfs(g,v):
q=deque([v]) ; vis=[0]*n
vis[v]=1 ; stg[v]=0
while q:
v=q[0]
for p in g[v]:
if vis[p]==0:
q.append(p)
vis[p]=1
stg[p]=stg[v]+1
q.popleft()
n=int(input())
g=[[] for i in range(n)]
for _ in range(n):
a=[int(i)-1 for i in input().split()]
for i in a[2:]: g[a[0]].append(i)
stg=[-1]*n
bfs(g,0)
for i in range(n):
print(i+1,stg[i])
| 1 | 3,677,129,050 | null | 9 | 9 |
alist = list(map(int, input().split()))
print(alist.index(0)+1)
|
print(15-sum(map(int,input().split())))
| 1 | 13,394,880,774,098 | null | 126 | 126 |
def main():
N = int(input())
S = input()
fusion = [S[0]]
prev = S[0]
for s in S[1:]:
if s == prev:
continue
fusion.append(s)
prev = s
print(len(fusion))
main()
|
H, N = map(int, input().split())
list_A = list(map(int,input().split()))
sum_list_A = sum(list_A)
if sum_list_A >= H:
print("Yes")
else:
print("No")
| 0 | null | 123,967,145,952,608 | 293 | 226 |
n = int(input())
mod = 10 ** 9 + 7
ans = (pow(10, n, mod) - pow(9, n, mod)) * 2 - (pow(10, n, mod) - pow(8, n, mod))
ans %= mod
print(ans)
|
N = int(input())
if N == 1:
print(0)
else:
mod = 10**9+7
print((10**N - (2*(9**N) - 8**N)) % mod)
| 1 | 3,221,744,706,630 | null | 78 | 78 |
import sys
readline = sys.stdin.readline
N = int(readline())
D = list(map(int,readline().split()))
counts = [0] * (max(D) + 1)
from collections import Counter
counter = Counter(D)
for k,v in counter.items():
counts[k] = v
if D[0] != 0 or counts[0] != 1:
print(0)
exit(0)
ans = 1
DIV = 998244353
for i in range(1, len(counts)):
ans *= pow(counts[i - 1],counts[i],DIV)
ans %= DIV
print(ans)
|
print(max(0,eval(input().replace(' ','-')+'*2')))
| 0 | null | 161,250,162,168,218 | 284 | 291 |
n,k=map(int,input().split())
count = 0
while n/k >0:
n//=k
count+=1
print(count)
|
N = int(input())
if N % 2 == 0:
ans = (N / 2) - 1
else:
ans = (N - 1) / 2
print(int(ans))
| 0 | null | 108,754,521,951,750 | 212 | 283 |
W,H,X,Y,R=map(int,input().split())
ok=True
if X<R or W-R<X:
ok=False
if Y<R or H-R<Y:
ok=False
if ok:
print("Yes")
else:
print("No")
|
def main():
W,H,x,y,r=map(int,input().split())
if x-r>=0 and y-r>=0 and W>=x+r and H>=y+r:
print('Yes')
else:
print('No')
if __name__=='__main__':
main()
| 1 | 447,991,278,538 | null | 41 | 41 |
n = float(input())
print((n - (n // 2)) / n)
|
n = int(input())
print(((n + 1) // 2) / n)
| 1 | 176,539,461,174,050 | null | 297 | 297 |
k = int(input())
a, b = map(int, input().split())
x = 0
while True:
x += k
if a <= x <= b:
print('OK')
break
if x > b:
print('NG')
break
|
n=int(input())
j,k=map(int,input().split())
f=1
if k-j>=n:
print('OK')
f=0
else:
for i in range(j,k+1):
if i%n==0:
print('OK')
f=0
break
if f==1:
print("NG")
| 1 | 26,597,250,121,912 | null | 158 | 158 |
from collections import defaultdict
N = int(input())
As = list(map(int, input().split()))
l_count = defaultdict(int)
r_count = defaultdict(int)
for i, A in enumerate(As):
l_count[i + A] += 1
r_count[i - A] += 1
ans = 0
for k, lv in l_count.items():
rv = r_count[k]
ans += lv * rv
print(ans)
|
n = int(input())
X = [[] for _ in range(n)]
for i in range(n):
x,l = list(map(int, input().split()))
X[i] = [x-l,x+l]
X.sort(key = lambda x: x[1])
cnt = 1
mx = X[0][1]
for i in range(1,n):
if mx <= X[i][0]:
cnt += 1
mx = X[i][1]
print(cnt)
| 0 | null | 57,987,171,196,076 | 157 | 237 |
s = input()
s = s[::-1]
n = len(s)
# stmp = s[::-1]
# for i in range(len(s)):
# for j in range(i,len(s)):
# sint = int(stmp[i:j+1])
# if sint % 2019 == 0:
# print(n-j,n-i)
# print(sint)
# print()
rem2019_cnts = [0]*2019
rem2019_cnts[0] = 1
curr_rem = int(s[0])
rem2019_cnts[curr_rem] = 1
curr_10_rem = 1
ans = 0
for i,si in enumerate(s[1:]):
sint = int(si)
next_10_rem = (curr_10_rem*10)%2019
next_rem = (next_10_rem*sint + curr_rem)%2019
ans += rem2019_cnts[next_rem]
rem2019_cnts[next_rem] += 1
curr_10_rem = next_10_rem
curr_rem = next_rem
# print(i+2, curr_rem)
print(ans)
|
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions import gcd
#input=sys.stdin.readline
#import bisect
a,b=input().split()
a=int(a)
ans=math.floor(((a*int(b[0]))*100+(a*int(b[2]))*10+(a*int(b[3])))//100)
print(ans)
| 0 | null | 23,800,455,890,158 | 166 | 135 |
k, n = map(int, input().split())
a = list(map(int, input().split()))
diff = []
for i in range(len(a)):
if (i == len(a) - 1):
distance = a[0] + (k - a[-1])
else:
tar2 = a[i + 1]
tar1 = a[i]
distance = tar2 - tar1
diff.append(distance)
# スタート位置を見つける
index = diff.index(max(diff))
ans = sum(diff) - max(diff)
print(ans)
# print(index)
# > 2なので、15~5は避ける。
# if (index == len(diff)):
|
s =input()
n = len(s)
if s[:(n-1)//2] ==s[:(n-1)//2][::-1] and s == s[::-1] and s[(n+3)//2-1:] == s[(n+3)//2-1:][::-1]:
print('Yes')
else:
print('No')
| 0 | null | 44,664,302,378,018 | 186 | 190 |
while True:
n,x = map(int,input().split())
if n == 0 and x == 0:
break
ans = 0
for i in range(1,n+1):
for j in range(1,n+1):
if j <= i:
continue
k = x-(i+j)
if k > j and k <= n:
ans += 1
print(ans)
|
x1, y1, x2, y2 = map(float,input().split())
print(f'{((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5:8f}')
| 0 | null | 718,228,902,510 | 58 | 29 |
import sys
A, B, M = map(int, input().split())
a = list(map(int, sys.stdin.readline().rsplit()))
b = list(map(int, sys.stdin.readline().rsplit()))
res = min(a) + min(b)
for i in range(M):
x, y, c = map(int, input().split())
res = min(res, a[x - 1] + b[y - 1] - c)
print(res)
|
A, B, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
c = []
for i in range(m):
xx, yy, cc = map(int, input().split())
x.append(xx)
y.append(yy)
c.append(cc)
ans = min(a) + min(b)
for i in range(m):
ans = min(ans,a[x[i]-1] + b[y[i]-1] - c[i])
print (ans)
| 1 | 54,200,055,412,258 | null | 200 | 200 |
n,a,b = map(int,input().split())
if (b-a) % 2 == 0:
ans = (b-a) // 2
else:
if a-1 < n-b:
ans = b-1
x = b-(a-1)-1
ans = min(ans, a + (x-1) // 2)
else:
ans = n-a
x = a + (n-b) + 1
ans = min(ans, (n-b) + 1 + (n-x) // 2)
print(ans)
|
import sys
read = sys.stdin.read
def main():
h, n = map(int, input().split())
m = map(int, read().split())
mm = zip(m, m)
large_num = 10**9
dp = [large_num] * (h + 10**4 + 1)
dp[0] = 0
for a, b in mm:
for i1 in range(h + 1):
if dp[i1 + a] > dp[i1] + b:
dp[i1 + a] = dp[i1] + b
r = min(dp[h:])
print(r)
if __name__ == '__main__':
main()
| 0 | null | 95,238,795,769,598 | 253 | 229 |
x, y, z = map(int, input().split())
y, x = x, y
z, x = x, z
print(x, y, z)
|
x, y, z = map(int, input().split())
x, y = y, x
x, z = z, x
print(str(x) + ' ' + str(y) + ' ' + str(z))
| 1 | 37,842,147,245,302 | null | 178 | 178 |
H,W,K=map(int,input().split())
S=[input() for _ in range(H)]
ans=[[0]*W for _ in range(H)]
zero = -1
count = 1
for i in range(H):
if zero == -1 and S[i].count('#')==0:
zero = i
continue
if zero != -1 and S[i].count('#')==0:
continue
last=0
for j in range(W):
if S[i][j]=='.':
if zero != -1:
for k in range(zero,i):
ans[k][j] = count
ans[i][j] = count
if S[i][j]=='#':
if zero != -1:
for k in range(zero,i):
ans[k][j] = count
ans[i][j] = count
if j<W-1 and S[i][j+1:].count('#')==0:
last = 1
else:
count += 1
if j == W-1 and last:
last = 0
count += 1
if j == W-1:
zero = -1
if zero != -1:
for i in range(zero,H):
ans[i] = ans[zero-1]
for i in range(H):
print(*ans[i])
|
taro_point = 0
hanako_point = 0
N = int(input())
for _ in range(N):
taro,hanako = input().split()
list = [taro,hanako]
list_new = sorted(list)
if taro == hanako:
taro_point += 1
hanako_point += 1
elif list_new[1] == hanako:
hanako_point +=3
elif list_new[1] == taro:
taro_point += 3
print(str(taro_point),str(hanako_point))
| 0 | null | 72,755,382,968,532 | 277 | 67 |
import math
def isprime(x):
if x == 2:
return True
if x < 2 or x % 2 == 0:
return False
i = 3
while(i <= math.sqrt(x)):
if x % i == 0:
return False
i += 2
return True
num = raw_input()
count = 0
for i in range(int(num)):
x = raw_input()
if isprime(int(x)):
count += 1
print count
|
import math
def is_prime(n):
if n % 2 == 0 and n > 2:
return False
return all(n % i for i in range(3, int(math.sqrt(n)) + 1, 2))
while True:
try:
n = int(raw_input())
total = 0
for k in range(n):
if is_prime(int(raw_input())):
total +=1
print total
except EOFError:
break
| 1 | 10,185,779,802 | null | 12 | 12 |
# coding: utf-8
import math
#N, K, M = map(int,input().split())
alp = [chr(i) for i in range(97, 97+26)]
#print(alp)
#N = int(input())
#K = int(input())
c = input()
ans = 0
#l = list(map(int,input().split()))
#A = list(map(int,input().split()))
print(alp[alp.index(c)+1])
|
C =input()
L =[]
for i in range(97, 123):
L.append(chr(i))
print(L[ord(C)-96])
| 1 | 92,374,397,530,886 | null | 239 | 239 |
a= int(input())
h = a//3600
m = (a%3600)//60
s = (a%3600)%60
print('%d:%d:%d' % (h, m, s))
|
MOD = 10**9+7
n,k = map(int,input().split())
L = [0]*(k+1)
for i in range(k,0,-1):
L[i] = pow(k//i,n,MOD)
for j in range(2,k//i+1):
L[i] -= L[i*j]
ans = 0
for i in range(1,k+1):
ans = (ans + i*L[i]) % MOD
print(ans)
| 0 | null | 18,498,789,360,210 | 37 | 176 |
S = input().rstrip()
T = input().rstrip()
count = 0
for i in range(len(S)):
if S[i] != T[i]:
count+=1
print(count)
|
#E - Logs
import math
# 入力
N,K = map(int,input().split())
A = list(map(int,input().split()))
Amax = int(max(A))
high = Amax
Cancut = Amax
low = 0
while ( (high - low) > 0.01 ) :
Cut = 0
X = (high + low) / 2.0
for i in range(N):
Cut = Cut + math.ceil(A[i]/X) - 1
if Cut <= K:
high = X
Cancut = X
else:
low = X
# 出力
if (math.floor(high) != math.floor(low)):
Cancut = math.floor( 100 * Cancut) /100.0
print(math.ceil(Cancut))
| 0 | null | 8,425,124,380,188 | 116 | 99 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
A = int(input())
print(A + A**2 + A**3)
if __name__ == "__main__":
main()
|
N = int(input())
print(N+N*N+N*N*N)
| 1 | 10,273,061,967,040 | null | 115 | 115 |
import sys
import itertools
def resolve(in_):
return len(set(s.strip() for s in itertools.islice(in_, 1, None)))
def main():
answer = resolve(sys.stdin.buffer)
print(answer)
if __name__ == '__main__':
main()
|
import sys
N = int(input())
S = [str(s) for s in sys.stdin.read().split()]
print(len(set(S)))
| 1 | 30,061,640,195,110 | null | 165 | 165 |
def lcm(x, y):
if x > y:
greater = x
else:
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1
return lcm
num1 = int(input())
a=lcm(num1,360)
b=a/num1
print(int(b))
|
def a():
x = int(input())
k = 1
while (k * x) % 360 != 0:
k += 1
print(k)
a()
| 1 | 13,121,550,020,990 | null | 125 | 125 |
class dice:
def __init__(self,A):
self.side = {
"TOP":A[0],
"S":A[1],
"E":A[2],
"W":A[3],
"N":A[4],
"BOT":A[5],
}
self.reverse = {
"E":"W",
"W":"E",
"S":"N",
"N":"S"}
def main(self,A):
for s in A:
var = int(self.side[s])
self.side[s] = self.side["TOP"]
self.side["TOP"] = self.side[self.reverse[s]]
self.side[self.reverse[s]] = self.side["BOT"]
self.side["BOT"] = var
print("{}".format(self.side["TOP"]))
var = dice(list(map(int,input().split())))
var.main(input())
|
n = int(input())
a = []
for i in range(n):
s = str(input())
a.append(s)
b = set(a)
print(len(b))
| 0 | null | 15,124,132,072,420 | 33 | 165 |
num = int(input())
data = list()
for i in range(1,10):
for j in range(1, 10):
data.append(i*j)
if num in data:
print('Yes')
else:
print('No')
|
import sys
from collections import deque
import copy
import math
def main():
A, B, N = map(int, input().split())
if B - 1 <= N:
x = B - 1
else:
x = N
ans = math.floor(A * x / B) - A * math.floor(x / B)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 93,749,237,985,820 | 287 | 161 |
a, b = map(int,input().split())
c = str(a) * b
d = str(b) * a
L = []
L += c,d
L = sorted(L)
print(L[0])
|
[a, b] = [str(i) for i in input().split()]
A = a*int(b)
B = b*int(a)
s = [A, B]
S = sorted(s)
print(S[0])
| 1 | 84,423,075,323,558 | null | 232 | 232 |
N = int(input())
dp = [[0]*10 for _ in range(10)]
for i in range(1, N+1):
if i%10==0: continue
strI = str(i)
f,l = strI[-1], strI[0]
dp[int(f)][int(l)] += 1
res = 0
for i in range(1,10):
for j in range(1,10):
res += dp[i][j] * dp[j][i]
print(res)
|
K, N= map(int, input().split())
A = list(map(int, input().split()))
max=K-(A[N-1]-A[0])
for i in range(N-1):
a=A[i+1]-A[i]
if max<a:
max=a
print(K-max)
| 0 | null | 64,943,792,874,558 | 234 | 186 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
A = int(readline())
B = int(readline())
print(6 - A - B)
if __name__ == '__main__':
main()
|
R = int(input())
L = 2*R*3.141592
print(L)
| 0 | null | 71,241,106,380,460 | 254 | 167 |
x = int(input())
i=1
while x!=0:
print('Case {0}: {1}'.format(i,x))
x = int(input())
i+=1
|
K = int(input())
A, B = map(int, input().split())
print("NOGK"[-(-A//K)*K <= B::2])
| 0 | null | 13,648,252,786,702 | 42 | 158 |
#!/usr/bin/env python3
import sys
import itertools
def solve(N: int, P: "List[int]", Q: "List[int]"):
l = []
for i in range(N):
l.append(i+1)
p = 0
q = 0
c = 0
for i in itertools.permutations(l, N):
c += 1
t = list(i)
if t == P:
p = c
if t == Q:
q = c
if p != 0 and q != 0:
print(abs(q - p))
break
return
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
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 = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
Q = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, P, Q)
if __name__ == '__main__':
main()
|
s = input()
if s in ["RRR"]:
print(3)
if s in ["RRS", "SRR"]:
print(2)
if s in ["RSR", "RSS", "SRS", "SSR"]:
print(1)
if s == "SSS":
print(0)
| 0 | null | 52,932,898,195,008 | 246 | 90 |
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
dp = dict()
dm = dict()
for i,ai in enumerate(a):
dp[i+ai] = dp.get(i+ai,0)+1
dm[i-ai] = dm.get(i-ai,0)+1
for wa,i in dm.items():
ans += i*dp.get(wa,0)
print(ans)
|
N = int(input())
deg = [0 for _ in range(N)]
edges = [[] for _ in range(N - 1)]
a = []
for i in range(N - 1):
in1, in2 = map(int, input().split())
a.append([in1, in2, i])
a = sorted(a, key = lambda x: x[0])
for i in range(N - 1):
edges[i] = [a[i][0] - 1, a[i][1] - 1, a[i][2]]
deg[a[i][0] - 1] += 1
deg[a[i][1] - 1] += 1
deg_max = max(deg)
print(deg_max)
co = [0 for _ in range(N)]
ans = [0 for _ in range(N - 1)]
for i in range(N - 1):
a = edges[i][0]
b = edges[i][1]
temp = 1 + (co[a] % deg_max)
co[a] = temp
co[b] = temp
ans[edges[i][2]] = temp
for i in range(N - 1): print(ans[i])
| 0 | null | 81,261,557,769,660 | 157 | 272 |
a = int(input())
print(2*a*3.14)
|
while True:
x = input()
if x == "0":
break
num = [int(i) for i in x]
print(sum(num))
| 0 | null | 16,592,012,934,222 | 167 | 62 |
n = int(input())
cif = [[0]*10 for i in range(10)]
for i in range(1, n+1):
s = str(i)
f = int(s[0])
r = int(s[-1])
cif[f][r] += 1
res = 0
for i in range(10):
for j in range(10):
res += cif[i][j]*cif[j][i]
print(res)
|
N, M = map(int, input().split())
S = input()
p = N
prev = N
flag = True
ans = []
for i in range(N, -1, -1):
if (prev - i) > M:
ans.append(prev - p)
prev = p
if (prev - i) > M:
flag = False
break
if S[i] == "0":
p = i
ans.append(prev)
if flag:
print(" ".join(map(str, ans[::-1])))
else:
print(-1)
| 0 | null | 112,614,605,393,118 | 234 | 274 |
#Macで実行する時
import sys
import os
if sys.platform=="darwin":
base = os.path.dirname(os.path.abspath(__file__))
name = os.path.normpath(os.path.join(base, '../atcoder/input.txt'))
#print(name)
sys.stdin = open(name)
a = str(input())
print(chr(ord(a)+1))
|
c = input()
alpha_list = 'abcdefghijkfmnopqrstuvrxyz'
for i in range(len(alpha_list)):
if c == alpha_list[i]:
print(alpha_list[i+1])
break
| 1 | 92,385,931,054,142 | null | 239 | 239 |
# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()]
su = [0 for _ in range(n)] #鉄の棒の切れ目の座標
for i in range(n):
su[i] = su[i-1] + a[i]
#print(su)
tmp = 2 * pow(10, 10) + 1
for i in su:
#if abs(i - su[-1]/2) < tmp:
# tmp = abs(i - su[-1]/2)
tmp = min(tmp, abs(i - su[-1]/2))
#print(su[-1]/2, tmp)
"""
#中心に一番近い鉄の棒の切れ目と中心との距離の差
l = 0
r = n-1
while (l - r) >= 1:
c = (l + r) // 2
#print(l, r, c)
if su[c] < su[-1] / 2:
l = c
elif su[c] > su[-1] / 2:
r = c
#print(su[l], su[r])
tmp = min(abs(su[l] - su[-1]/2), abs(su[r] - su[-1]/2))
print(tmp)
"""
ans = 2 * tmp
print(int(ans))
|
n,k =list(map(int,input().split()))
for i in range(31):
if n < k ** i:
print(i)
break
| 0 | null | 102,692,026,266,720 | 276 | 212 |
print(1&~int(input()))
|
def main():
S, W = map(int, input().split())
cond = S <= W
print('unsafe' if cond else 'safe')
if __name__ == '__main__':
main()
| 0 | null | 16,107,745,922,368 | 76 | 163 |
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
mins=[]
maxs=[]
for i in range(n):
a,b=nm()
mins.append(a)
maxs.append(b)
smn = sorted(mins)
smx = sorted(maxs)
if n%2==1:
mn = smn[(n+1)//2-1]
mx = smx[(n+1)//2-1]
print(round((mx-mn)+1))
else:
mn = (smn[n//2-1]+smn[n//2])/2.0
mx = (smx[n//2-1]+smx[n//2])/2.0
print(round((mx-mn)*2+1))
|
n = int(input())
a= [0]*n
b= [0]*n
for i in range(n):
a[i], b[i] = map(int, input().split())
if n%2 ==1:
a.sort()
b.sort()
xmin= a[int((n-1)/2)]
xmax= b[int((n - 1) / 2)]
print(int(xmax-xmin+1))
if n%2 ==0:
a.sort()
b.sort()
xmin = a[int(n/2-1)]+a[int(n/2)]
xmax = b[int(n / 2 - 1)] + b[int(n / 2)]
print(int((xmax-xmin)+1))
| 1 | 17,422,616,231,168 | null | 137 | 137 |
n = int(input())
aas = list(map(int, input().split()))
cnts = [0]*(n+1)
for i in range(n):
cnts[aas[i]] += 1
t = 0
for i in range(1,n+1):
tmp = cnts[i]
t += tmp*(tmp-1)//2
for i in range(n):
tmp = cnts[aas[i]]
print(int(t-tmp*(tmp-1)/2*(1-1/tmp*(tmp-2))))
|
def mergeSort(A, left, right, n):
if left + 1 < right:
mid = int((right + left ) / 2 )
mergeSort(A, left, mid, n)
mergeSort(A, mid, right, n)
return (merge(A, left, mid, right, n))
def merge(A, left, mid, right, n):
n1 = mid - left
n2 = right - mid
L = A[left:mid] + [10 ** 9 + 1]
R = A[mid:right] + [10 ** 9 + 1]
i , j = 0, 0
for k in range(left, right):
A[n] += 1
if L[i] <= R[j]:
key = L[i]
A[k] = key
i += 1
else:
key = R[j]
A[k] = key
j += 1
return A
n = int(input())
A = list(map(int, input().split()))
A.append(0)
S = mergeSort(A, 0, len(A) - 1, n)
print(" ".join(list(map(str, S[:n]))))
print(S[n])
| 0 | null | 24,100,710,838,042 | 192 | 26 |
n = int(input())
a = list(map(int, input().split()))
L = sum(a)
l = 0
i = 0
while l < L / 2:
l += a[i]
i += 1
print(min(abs(sum(a[:i - 1]) - sum(a[i - 1:])), abs(sum(a[:i]) - sum(a[i:]))))
|
def solve(n,m):
if not n:return 1
n%=m
return-~solve(n,bin(n).count('1'))
n=int(input())
s=input()
a=int(s,2)
*x,=map(int,s)
h=sum(x)
try:a,b=a%(h-1),a%(h+1)
except:b=a%(h+1)
for i in range(n):
if x[i]:
if not h-1:
print(0)
continue
x[i]=0
t=(a-pow(2,~i+n,h-1))%(h-1)
else:
x[i]=1
t=(b+pow(2,~i+n,h+1))%(h+1)
r=solve(t,bin(t).count('1'))
x[i]^=1
print(r)
| 0 | null | 75,123,161,305,472 | 276 | 107 |
n = int(input().split()[0])
c = list(map(int,input().split()))
minimum = [ i for i in range(n+1) ]
for i in range(2,n+1):
for j in c:
if j <= i and minimum[i-j] + 1 < minimum[i]:
minimum[i] = minimum[i-j]+1
print(minimum[n])
|
a,b,c,d=map(int,input().split())
ans=-10**20
if ans<a*c:
ans=a*c
if ans<a*d:
ans=a*d
if ans<b*c:
ans=b*c
if ans<b*d:
ans=b*d
print(ans)
| 0 | null | 1,610,319,375,750 | 28 | 77 |
a, b, c = (int(x) for x in input().split())
tmp = 0
for i in range(2):
if a > b:
tmp = a
a = b
b = tmp
if b > c:
tmp = b
b = c
c = tmp
if a > c:
tmp = a
a = c
c = tmp
print(a, b, c)
|
a,b,c = input().split()
a = int(a)
b = int(b)
c = int(c)
tmp = 0
if c < b:
tmp = b
b = c
c = tmp
if b < a:
tmp = a
a = b
b = tmp
if c < b:
tmp = b
b = c
c = tmp
print (str(a) + " " + str(b) + " " + str(c))
| 1 | 422,143,681,428 | null | 40 | 40 |
import math
import itertools
n = int(input())
l = []
for _ in range(n):
a = list(map(int,input().split()))
l.append(a)
dis = 0
for case in itertools.permutations(l):
for i in range(n-1):
dis += math.sqrt((case[i][0]-case[i+1][0])**2+(case[i][1]-case[i+1][1])**2)
result = dis/math.factorial(n)
print(result)
|
N,K=map(int,input().split())
x=998244353
dp=[0 for i in range(N)]
sdp=[0 for i in range(N)]
L=[]
R=[]
dp[0]=1
sdp[0]=1
for i in range(K):
l,r=map(int,input().split())
L.append(l)
R.append(r)
for i in range(1,N):
for j in range(K):
dp[i]+=(sdp[max(i-L[j],-1)]-sdp[max(i-R[j]-1,-1)])
dp[i]%=x
sdp[i]=(sdp[i-1]+dp[i])%x
print(dp[-1]%x)
| 0 | null | 75,684,781,526,280 | 280 | 74 |
import bisect
n = int(input())
arr = list(map(int,input().split()))
arr.sort()
ans = 0
for i in range(n-2):
for j in range(i+1,n-1):
x = arr[i]+arr[j]
ind = bisect.bisect_left(arr,x)
ans+=(ind-j-1)
print(ans)
|
N=int(input())
L=list(map(int,input().split()))
sort_L=sorted(L,reverse=True)
ans=0
for n in range(N-2):
for o in range(n+1,N-1):
lar=sort_L[n]
kouho=sort_L[o+1:]
mid=sort_L[o]
sa=lar-mid
left=0
right=N-o-2
if kouho[-1]>sa:
ans+=right+1
else:
while right > left + 1:
half = (right + left) // 2
if kouho[half] <= sa:
right = half
else:
left = half
if kouho[right]<=sa and kouho[left]<=sa:
continue
elif kouho[right]>sa:
ans+=right+1
else:
ans+=left+1
print(ans)
| 1 | 171,796,241,213,910 | null | 294 | 294 |
import sys
for e in sys.stdin:print(len(str(sum(map(int,e.split())))))
|
import math
while True:
try:
a =map(int,raw_input().split())
b = a[0] + a[1]
print len(str(a[0]+a[1]))
except EOFError:
break
| 1 | 106,365,632 | null | 3 | 3 |
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
N, K = map(int, readline().split())
A = list(map(int, readline().split()))
A.sort()
lenA = len(A)
ans = 0
if K == 1:
print(0)
sys.exit()
def com(n, r, mod):
r = min(r, n - r)
if r == 0:
return 1
res = ilist[n] * iinvlist[n - r] * iinvlist[r] % mod
return res
def modinv(a, mod=10 ** 9 + 7):
return pow(a, mod - 2, mod)
ilist = [0]
iinvlist = [1]
tmp = 1
for i in range(1, N + 1):
tmp *= i
tmp %= mod
ilist.append(tmp)
iinvlist.append(modinv(tmp, mod))
sum_of_com = []
now = 0
for i in range(K-2, N+1):
now += com(i, K-2, mod)
sum_of_com.append(now)
ans = 0
for first in range(lenA-K+1):
ans -= A[first] * sum_of_com[lenA-first-K]
for last in range(K-1, lenA):
ans += A[last] * sum_of_com[last-K+1]
ans %= mod
print(ans)
if __name__ == '__main__':
solve()
|
import sys
sys.setrecursionlimit(2147483647)
n,k=map(int,input().split())
#n個の中からk個選んだ時の最大と最小
a=list(map(int,input().split()))
"""
seta=set([])
dic={}
for v in a:
if v in seta:
dic[v]+=1
else:
dic[v]=1
seta.add(v)
a=list(seta)
"""
a.sort()
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 10**9+7 #割る数
N = 10 ** 6 # N は必要分だけ用意する
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
result=0
for i,v in enumerate(a):
if i>=k-1:
result+=v*cmb(i, k-1, p)
if k-1<=n-i-1:
result-=v*cmb(n-i-1, k-1, p)
print(result%p)
| 1 | 95,692,459,689,374 | null | 242 | 242 |
k = int(input())
ans = k * "ACL"
print(ans)
|
K = int(input())
a=''
for i in range(K):
a = a + 'ACL'
print(a)
| 1 | 2,167,105,508,150 | null | 69 | 69 |
from sys import stdin
def main():
_in = [_.rstrip() for _ in stdin.readlines()]
a, b, c, d = list(map(int, _in[0].split(' '))) # type:list(int)
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
ans = -float('inf')
for _ in [a * c, a * d, b * c, b * d]:
ans = max(ans, _)
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
print(ans)
if __name__ == "__main__":
main()
|
a=[int(x) for x in input().split()]
b=[a[0]*a[2],a[0]*a[3],a[1]*a[2],a[1]*a[3]]
print(max(b))
| 1 | 3,034,259,381,552 | null | 77 | 77 |
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#solve
def solve():
t1, t2 = LI()
a1, a2 = LI()
b1, b2 = LI()
if t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2:
print("infinity")
return
if t1 * a1 > t1 * b1:
if t1 * a1 + t2 * a2 > t1 * b1 + t2 * b2:
print(0)
return
else:
x = t1 * (a1 - b1) / (-t1 * (a1 - b1) + t2 * (b2 - a2))
if x.is_integer():
print(2 * (t1 * (a1 - b1) // (-t1 * (a1 - b1) + t2 * (b2 - a2))))
else:
print(2 * (t1 * (a1 - b1) // (-t1 * (a1 - b1) + t2 * (b2 - a2))) + 1)
return
elif t1 * a1 < t1 * b1:
if t1 * a1 + t2 * a2 < t1 * b1 + t2 * b2:
print(0)
return
else:
x = t1 * (b1 - a1) / (-t1 * (b1 - a1) + t2 * (a2 - b2))
if x.is_integer():
print(2 * (t1 * (b1 - a1) // (-t1 * (b1 - a1) + t2 * (a2 - b2))))
else:
print(2 * (t1 * (b1 - a1) // (-t1 * (b1 - a1) + t2 * (a2 - b2))) + 1)
return
return
#main
if __name__ == '__main__':
solve()
|
#atcoder
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
d1=a1-b1
d2=a2-b2
if d1*d2>0:
print(0)
else:
if d1>0 and d2<0:
plus=d1*t1+d2*t2
if plus>0:
print(0)
elif plus==0:
print("infinity")
elif plus<0:
d=-plus
k=d1*t1
if k%d==0:
print(2*k//d)
else:
print(2*(k//d)+1)
else:
d1=-d1
d2=-d2
plus=d1*t1+d2*t2
if plus>0:
print(0)
elif plus==0:
print("infinity")
elif plus<0:
d=-plus
k=d1*t1
if k%d==0:
print(2*k//d)
else:
print(2*(k//d)+1)
| 1 | 131,516,723,976,718 | null | 269 | 269 |
# coding: utf-8
# 標準入力 <int>
K = int(input())
k = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
kl = k.split(", ")
print(kl[K-1])
|
S = str(input())
T = str(input())
if S == T[:-1]:
print("Yes")
else:
print("No")
| 0 | null | 35,669,717,510,710 | 195 | 147 |
import heapq
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans=[]
for i in range(x):
ans.append(p[i])
for j in range(y):
ans.append(q[j])
ans.sort()
heapq.heapify(ans)
for j in range(c):
min_a=heapq.heappop(ans)
if min_a<=r[j]:
heapq.heappush(ans,r[j])
else:
heapq.heappush(ans,min_a)
break
print(sum(ans))
|
N = int(input())
s = [input() for i in range(N)]
'''
for v in ["AC", "WA", "TLE", "RE"]:
print("{0} x {1}".format(v, s.count(v)))
'''
print("AC x",s.count("AC"))
print("WA x",s.count("WA"))
print("TLE x",s.count("TLE"))
print("RE x",s.count("RE"))
| 0 | null | 26,572,537,451,880 | 188 | 109 |
n = int(input())
cards = [[0 for i in range(13)] for j in range(4)]
for i in range(n):
Input = input().split()
if Input[0] == "S":
cards[0][int(Input[1])-1]= 1
if Input[0] == "H":
cards[1][int(Input[1]) - 1] = 1
if Input[0] == "C":
cards[2][int(Input[1]) - 1] = 1
if Input[0] == "D":
cards[3][int(Input[1]) - 1] = 1
for i in range(4):
for j in range(13):
if cards[i][j] == 0:
if i == 0:
print("S",j+1)
if i == 1:
print("H",j+1)
if i == 2:
print("C", j + 1)
if i == 3:
print("D", j + 1)
|
if __name__ == '__main__':
# ??????????????\???
my_cards = [] # ????????¶?????\??????????????????????????§
card_num = int(input())
for i in range(card_num):
data = [x for x in input().split(' ')]
suit = data[0]
rank = int(data[1])
my_cards.append((suit, rank))
full_cards = [] # 52?????¨????????£??????????????????
for r in range(1, 13+1):
full_cards.append(('S', r))
full_cards.append(('H', r))
full_cards.append(('D', r))
full_cards.append(('C', r))
# ??????????????¨???????¶??????????????¢???????????????°??????????????????
missing_cards = set(my_cards) ^ set(full_cards)
missing_spades = [x for x in missing_cards if x[0]=='S']
missing_hearts = [x for x in missing_cards if x[0] == 'H']
missing_clubs = [x for x in missing_cards if x[0] == 'C']
missing_diamonds = [x for x in missing_cards if x[0] == 'D']
missing_spades.sort(key=lambda x: x[1])
missing_hearts.sort(key=lambda x: x[1])
missing_clubs.sort(key=lambda x: x[1])
missing_diamonds.sort(key=lambda x: x[1])
# ????¶???????????????¨???
for s, r in missing_spades:
print('{0} {1}'.format(s, r))
for s, r in missing_hearts:
print('{0} {1}'.format(s, r))
for s, r in missing_clubs:
print('{0} {1}'.format(s, r))
for s, r in missing_diamonds:
print('{0} {1}'.format(s, r))
| 1 | 1,032,857,480,518 | null | 54 | 54 |
import numpy as np
h,w,m=map(int, input().split())
hw=[tuple(map(int,input().split())) for i in range(m)]
H=np.zeros(h)
W=np.zeros(w)
for i in range(m):
hi,wi=hw[i]
H[hi-1]+=1
W[wi-1]+=1
mh=max(H)
mw=max(W)
hmax=[i for i, x in enumerate(H) if x == mh]
wmax=[i for i, x in enumerate(W) if x == mw]
f=0
for i in range(m):
hi,wi=hw[i]
if H[hi-1]==mh and W[wi-1]==mw:
f+=1
if len(hmax)*len(wmax)-f<1:
print(int(mh+mw-1))
else:
print(int(mh+mw))
|
import copy
n = int(input())
a = list(map(int, input().split()))
k = 1 + n%2
INF = 10**18
dp = [[-INF]*4 for i in range(n+5)]
dp[0][0] = 0
for i in range(n):
for j in range(k+1):
dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j])
now = copy.deepcopy(dp[i][j])
if (i+j) % 2 == 0:
now += a[i]
dp[i+1][j] = max(dp[i+1][j], now)
print(dp[n][k])
| 0 | null | 21,195,504,918,952 | 89 | 177 |
s=input()
t=input()
count=0
for i in range(0,len(s)):
if(s[i]==t[i]):
continue
else:
count+=1
print(count)
|
input()
S,T=input().split()
print(''.join([s+t for s,t in zip(S,T)]))
| 0 | null | 60,994,159,981,580 | 116 | 255 |
def f(w, n, k, v):
# how many things in list w of length n can fill in k cars with capacity v?
i = 0
space = 0
while i < n:
if space >= w[i]:
space -= w[i]
i += 1
else:
# space < w[i]
if k == 0:
break
k -= 1
space = v
return i
if __name__ == '__main__':
n, k = map(int, raw_input().split())
w = []
maxv = -1
for i in range(n):
x = int(raw_input())
w.append(x)
maxv = max(maxv, x)
left = 0
right = n * maxv
# range: (left, right]
# loop until left + 1 = right, then right is the answer
# why? because right works, but right - 1 doesn't work
# so right is the smallest capacity
while right - left > 1:
mid = (left + right) / 2
v = f(w, n, k, mid)
if v >= n:
# range: (left, mid]
# in fact, v cannot > n
right = mid
else:
# range: (mid, right]
left = mid
print right
|
def check(p):
i = 0
for j in range(track):
s = 0
while s + A[i] <= p:
s += A[i]
i += 1
if i == budget:
return True
return False
def solve():
left = max(A)
right = sum(A)
while (right - left > 1):
mid = int((left + right) / 2)
if check(mid):
right = mid
else :
left = mid
if check(left):
return left
else :
return right
if __name__ == '__main__':
budget, track = list(map(int, input().split()))
A = []
for n in range(budget):
A.append(int(input()))
ans = solve()
print(ans)
| 1 | 92,962,529,802 | null | 24 | 24 |
import collections
N = int(input())
edges = [[] for _ in range(N)]
for i in range(N-1):
a, b = map(int, input().split())
edges[a-1].append([b-1,i])
edges[b-1].append([a-1,i])
q = collections.deque()
q.append([0,-1,-1])
colors = [0]*(N-1)
while len(q) != 0:
v, color, num = q.popleft()
if colors[num] == 0 and color != -1:
colors[num] = color
next_color = 0
for w in edges[v]:
if colors[w[1]] != 0:
continue
next_color += 1
if next_color == colors[num]:
next_color += 1
q.append([w[0],next_color,w[1]])
print(len(set(colors)))
for i in colors:
print(i)
|
from collections import deque
N = int(input())
g = [[] for _ in range(N)]
hen = []
dic = {}
for i in range(N-1):
#iが辺のID
a,b = map(int,input().split())
a -= 1; b -= 1
g[a].append((b,i))
g[b].append((a,i))
#これが答え。辺の本数だけ空を用意する。
ans = [0 for _ in range(N-1)]
Q = deque([])
Q.append(0)
used = [0 for _ in range(N)] #訪れた頂点をここに記録
used[0] = 1
#pre = [-1 for _ in range(N)]
while Q:
v = Q.popleft()
#p = pre[v] #vの親
c = -1
for i in range(len(g[v])): #vとvの親が繋がっている色を探す。
TO = g[v][i][0]
ID = g[v][i][1]
if used[TO] == 1:
c = ans[ID]
k = 1
for i in range(len(g[v])): #vとつながっている親以外の色を塗っていく。
TO = g[v][i][0]
ID = g[v][i][1]
if used[TO] == 1:
continue
if k == c:
k += 1
ans[ID] = k
k += 1
Q.append(TO)
used[TO] = 1
#bfs(0,0,-1) #根を0として、仮想親の-1から仮想色0で繋がっている。
print(max(ans))
for i in ans:
print(i)
| 1 | 136,560,034,939,910 | null | 272 | 272 |
while True:
cards = input()
if cards == '-':
break
n = int(input())
for i in range(n):
h = int(input())
cards = cards[h:] + cards[:h]
print(cards)
|
m = []
for _ in range(10):
r = int(input())
m.append(r)
m.sort()
print (m[9]);
print (m[8]);
print (m[7]);
| 0 | null | 941,773,819,362 | 66 | 2 |
m1=m2=m3=0
for i in range(10):
m3=max(m3,int(input()))
if m3>m2:m2,m3=m3,m2
if m2>m1:m1,m2=m2,m1
print(m1)
print(m2)
print(m3)
|
A, B, C, K = map(int, input().split())
D = A + B
if D >= K:
print(min(K,A))
else:
K -= D
print(A-K)
| 0 | null | 10,876,142,341,262 | 2 | 148 |
import math
R = int(input())
pi = math.pi
ans = 2*R * pi
print(ans)
|
print(int(input())*3.141592*2)
| 1 | 31,330,883,607,492 | null | 167 | 167 |
def Find(x, par):
if par[x] < 0:
return x
else:
par[x] = Find(par[x], par)
return par[x]
def Unite(x, y, par, rank):
x = Find(x, par)
y = Find(y, par)
if x != y:
if rank[x] < rank[y]:
par[y] += par[x]
par[x] = y
else:
par[x] += par[y]
par[y] = x
if rank[x] == rank[y]:
rank[x] += 1
def Same(x, y, par):
return Find(x, par) == Find(y, par)
def Size(x, par):
return -par[Find(x, par)]
import sys
input = sys.stdin.readline
n, m, k = map(int, input().split())
par = [-1]* n
rank = [0]*n
C = [0]*n
for i in range(m):
a, b = map(int, input().split())
a, b = a-1, b-1
C[a] += 1
C[b] += 1
Unite(a, b, par, rank)
ans = [0]*n
for i in range(n):
ans[i] = Size(i, par)-1-C[i]
for i in range(k):
c, d = map(int, input().split())
c, d = c-1, d-1
if Same(c, d, par):
ans[c] -= 1
ans[d] -= 1
print(*ans)
|
import math
a, b, c, d = map(int, input().split())
takahashi_attacks = math.ceil(c / b)
aoki_attacks = math.ceil(a / d)
if takahashi_attacks <= aoki_attacks:
print('Yes')
else:
print('No')
| 0 | null | 45,856,032,199,710 | 209 | 164 |
#!/usr/bin/python3
def countpars(s):
lc = 0
rc = 0
for ch in s:
if ch == '(':
lc += 1
else:
if lc > 0:
lc -= 1
else:
rc += 1
return (lc, rc)
n = int(input())
ssl = []
ssr = []
for i in range(n):
(clc, crc) = countpars(input())
if clc >= crc:
ssl.append((clc, crc))
else:
ssr.append((clc, crc))
ssl.sort(key=lambda x: x[1])
ssr.sort(reverse=True)
lc = 0
rc = 0
for (clc, crc) in ssl:
lc -= crc
if lc < 0:
print('No')
exit()
lc += clc
for (clc, crc) in ssr:
lc -= crc
if lc < 0:
print('No')
exit()
lc += clc
if lc == 0:
print('Yes')
else:
print('No')
|
N = int(input())
pl = []
mi = []
for i in range(N):
_m = 0
_t = 0
s = input()
for c in s:
if c == ")":
_t -= 1
_m = min(_m, _t)
else:
_t += 1
if _t > 0:
pl.append([-_m, -_t]) # sortの調整のために負にしている
else:
mi.append([- _t + _m, _m, _t])
pl = sorted(pl)
mi = sorted(mi)
#import IPython;IPython.embed()
if len(pl) == 0:
if mi[0][0] == 0:
print("Yes")
else:
print("No")
exit()
if len(mi) == 0:
print("No")
exit()
tot = 0
for m, nt in pl:
if tot - m < 0: # これはひくではないのでは?
print("No")
exit()
else:
tot -= nt
for d, m, nt in mi:
if tot + m <0:
print("No")
exit()
else:
tot += nt
if tot != 0:
print("No")
else:
print("Yes")
# どういう時できるか
# で並べ方
# tot, minの情報が必要
# totが+のものはminとtotを気をつける必要がある
# minがsum以上であればどんどん足していけばいい.
# なのでminが大きい順にsortし,totの大きい順にsort
# その次はtotがminusの中ではminが小さい順に加える
# 合計が0になる時Yes,それ意外No.
| 1 | 23,793,709,525,650 | null | 152 | 152 |
n = int(input())
a = list(map(int, input().split()))
d = {}
d[0] = 1000
for i in range(n):
e = d.copy()
for stock, money in e.items():
# sell
d[0] = max(d[0], money + stock * a[i])
# buy
k = money // a[i]
stock += k
money -= k * a[i]
d[stock] = max(d.get(stock, 0), money)
print(d[0])
|
N = int(input())
A = list(map(int,input().split()))
minval = 0
ans = 1000
for i in range(1, N):
if A[i] > A[minval]:
pstock = ans // A[minval]
ans = ans%A[minval] + A[i]*pstock
minval = i
print(ans)
| 1 | 7,294,750,642,788 | null | 103 | 103 |
a = input()
N = int(a)
A = list(map(int,input().split()))
flag = 0
y = 1000
for i in range(1,N):
if A[i-1] < A[i] and flag == 0:
x = y//A[i-1]
y = y % A[i-1]
flag = 1
if (A[i-1] > A[i]) and flag == 1:
y = y + A[i-1]*x
flag = 0
if flag == 1 and i == N-1:
y = y + A[i]*x
print(y)
|
from sys import stdin
inp = lambda : stdin.readline().strip()
n= int(inp())
prices = [int(x) for x in inp().split()]
money= 1000
buy = -1
if prices[0] <=money:
buy = prices[0]
for i in range(1, len(prices)):
if prices[i] > prices[i - 1]:
if buy != -1:
money = money%buy + (money//buy)*prices[i]
buy = prices[i]
else:
if prices[i] < buy and prices[i] < money:
buy = prices[i]
print(money)
| 1 | 7,303,284,037,980 | null | 103 | 103 |
n,k = map(int, input().split())
lag = []
for l in range(n):
lag.append(int(input()))
w_max = 100000*100000
w_min = 0
while w_min < w_max:
w_mid = (w_max + w_min) // 2
tracks = 0
current = 0
for i in range(n):
if lag[i] > w_mid:
tracks = k
break
elif lag[i] + current > w_mid:
tracks += 1
current = lag[i]
else:
current += lag[i]
if tracks < k:
w_max = w_mid
else:
w_min = w_mid + 1
print(w_max)
|
n, k = map(int,input().split())
w_in = list()
for i in range(n):
w_in.append(int(input()))
def alloc(p):
load = 0
track = 1
for w in w_in:
if w > p:
return False
if load + w <= p:
load += w
else:
load = w
track += 1
if track > k:
return False
return True
def binsearch():
upper = sum(w_in)
lower = max(w_in)
while(upper != lower):
mid = int((upper + lower) / 2)
if alloc(mid):
upper = mid
else:
lower = mid + 1
return upper
print(binsearch())
| 1 | 86,525,975,522 | null | 24 | 24 |
x = int(input())
cnt = 1
mod = 7
for i in range(x):
if mod % x == 0:
print(cnt)
exit()
mod = (10 * mod + 7) % x
cnt += 1
print(-1)
|
N = int(input())
ans = [0 for _ in range(N + 1)]
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
v = x * x + y * y + z * z + x * y + y * z + z * x
if v > N:
continue
ans[v - 1] += 1
for i in range(N):
print(ans[i])
| 0 | null | 7,078,604,007,312 | 97 | 106 |
a,b,c=[int(i) for i in input().split()]
num=0
#s=[i for i in range(1,c+1) if c%i==0]
# print(s)
for i in range(1,c+1):
if c%i==0:
if i>=a and i<=b:
num=num+1
print(num)
|
import math
H, W = map(int, input().split(' '))
if H == 1 or W == 1:
print(1)
exit()
res = math.ceil((H*W)/2)
print(res)
| 0 | null | 25,679,108,485,814 | 44 | 196 |
h, w, k = list(map(int, input().split()))
grid = [input() for _ in range(h)]
ans = [[0]*w for _ in range(h)]
cnt = 0
for j in range(h):
for i in range(w):
if grid[j][i] == "#":
cnt += 1
l = i
r = i
u = j
d = j
moving = True
while moving and l > 0:
moving = False
if ans[j][l-1] == 0 and grid[j][l-1] == ".":
moving = True
l -= 1
moving = True
while moving and r < w-1:
moving = False
if ans[j][r+1] == 0 and grid[j][r+1] == ".":
moving = True
r += 1
moving = True
while moving and u > 0:
moving = False
canMove = True
for x in range(l, r+1):
if not (ans[u-1][x] == 0 and grid[u-1][x] == "."):
canMove = False
break
if canMove:
moving = True
u -= 1
moving = True
while moving and d < h-1:
moving = False
canMove = True
for x in range(l, r+1):
if not (ans[d+1][x] == 0 and grid[d+1][x] == "."):
canMove = False
break
if canMove:
moving = True
d += 1
for y in range(u, d+1):
for x in range(l, r+1):
ans[y][x] = cnt
for row in ans:
print(" ".join(map(str, row)))
|
H,W,K = map(int, input().split())
def cv(S,cn,pr):
SS=S
ans = []
for i in range(cn):
ans += [pr+i+1]*(SS.find("#")+1)
if SS.find("#")<len(SS):
SS = SS[SS.find("#")+1:]
else:
SS = ""
ans += [pr+cn]*len(SS)
return ans
cnt_pre = 0 #最初のall #no
cnt = 0 # "#"の個数
for i in range(H):
Lin = input()
tmp = Lin.count("#")
if tmp == 0 and cnt == 0:
cnt_pre +=1
elif tmp == 0:
print(*pS)
else:
pS = cv(Lin,tmp,cnt)
for i in range(0,cnt_pre+1):
print(*pS)
cnt_pre = 0
cnt += tmp
| 1 | 144,060,526,821,860 | null | 277 | 277 |
print(int(input()[:2] != input()[:2]))
|
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal
def input():
x=sys.stdin.readline()
return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False):
inds=sorted(range(len(s)), key=lambda k: s[k])
if return_sorted: return inds, [s[i] for i in inds]
return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
K,N,M=len(B),len(A),len(B[0])
return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
N,size=len(v),len(M)
return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
n,m=len(M),len(M[0])
return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
mod = 1000000007
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
N = input()
K= int(input())
#N, K = map(int, input().split())
#A = tuple(map(int, input().split())) #1行ベクトル
#L = tuple(int(input()) for i in range(N)) #改行ベクトル
#S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
keta=100+1
dp=[[0]*(keta+1) for _ in range(keta+1)]
dp[0][0]=1
for i in range(1,keta+1):
for j in range(0,i+1):
dp[i][j]+=dp[i-1][j]+dp[i-1][j-1]*9
l=len(N)
cur0=0
tot=0
for i,si in enumerate(N):
n=int(si)
if n!=0:
tot+=(n-1)*dp[l-1-i][K-i-1+cur0]+dp[l-1-i][K-i+cur0]
else:
cur0+=1
ic=0
for s in N:
if s!='0':ic+=1
if ic==K:tot+=1
print(tot)
if __name__ == "__main__":
main()
| 0 | null | 99,764,950,509,214 | 264 | 224 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.