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
|
---|---|---|---|---|---|---|
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
cnt = [0]*N
for _ in range(K):
d = int(input())
for a in list(map(int, input().split())):
a -= 1
cnt[a] += 1
ans = 0
for c in cnt:
ans += c == 0
print(ans)
| N = int(input())
if N %2 == 0:
K = N//2
else:
K = N//2+1
print(K/N)
| 0 | null | 100,800,086,135,840 | 154 | 297 |
from sys import stdin
input = stdin.readline
import math
import heapq
def solve():
n, k = map(int, input().split())
a = list(map(int, input().split()))
left = 1
right = max(a)
def ok(l):
s = sum([(i-1) // l for i in a])
return s <= k
while left < right:
mid = (left + right) // 2
if ok(mid):
right = mid
else:
left = mid + 1
print(left)
if __name__ == '__main__':
solve()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S, T = read().decode('utf-8').rstrip().split()
A = [None] * (N+N)
A[::2] = S
A[1::2] = T
ans = ''.join(A)
print(ans) | 0 | null | 59,087,707,932,640 | 99 | 255 |
N,K,C = map(int,input().split())
S = input()
L = []
R = []
i = 0
while i < N:
if S[i] == "o":
L.append(i)
if len(L) == K:
break
i += C+1
else:
i += 1
i = N-1
while i >= 0:
if S[i] == "o":
R.append(i)
if len(R) == K:
break
i -= C+1
else:
i -= 1
R.reverse()
for i in range(K):
if L[i] == R[i]:
print(L[i]+1)
| N,D = map(int,input().split())
count = 0
for i in range(N):
x,y = map(int,input().split())
if x**2+y**2 <= D**2:
count = count + 1
else:
count = count + 0
print(count) | 0 | null | 23,302,671,210,728 | 182 | 96 |
import statistics
def main():
while True:
try:
N = int(input())
S = tuple(map(int, input().split()))
print(statistics.pstdev(S))
except EOFError:
break
main() | while int(input()) != 0:
m = list(map(int, input().split()))
mean = sum(m) / len(m)
std = (sum([(i - mean) ** 2 for i in m]) / len(m)) ** 0.5
print("{:4f}".format(std))
| 1 | 197,956,783,420 | null | 31 | 31 |
def main():
from sys import stdin
input=stdin.readline
import numpy as np
import scipy.sparse.csgraph as sp
n, m, l = map(int, input().split())
abc = [list(map(int, input().split())) for _ in [0]*m]
q = int(input())
st = [list(map(int, input().split())) for _ in [0]*q]
inf = 10**12
dist = np.full((n, n), inf, dtype=np.int64)
for i in range(n):
dist[i][i] = 0
for a, b, c in abc:
dist[a-1][b-1] = c
dist[b-1][a-1] = c
dist = sp.shortest_path(dist)
inf = 10**3
dist2 = np.full((n, n), inf, dtype=np.int16)
for i in range(n):
for j in range(n):
if dist[i][j] <= l:
dist2[i][j] = 1
dist2 = sp.shortest_path(dist2)
for i in range(n):
for j in range(n):
if dist2[i][j] == inf:
dist2[i][j] = -1
else:
dist2[i][j] -= 1
for s, t in st:
print(int(dist2[s-1][t-1]))
main()
| from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
N,M,L=map(int,input().split())
A=[0]*M
B=[0]*M
C=[0]*M
for i in range(M):
A[i],B[i],C[i] = map(int,input().split())
A[i] -=1
B[i] -=1
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]
G = csr_matrix((C, (A, B)), shape=(N, N))
d = floyd_warshall(G, directed=False)
G=np.full((N,N), np.inf)
G[d<=L]=1
G = csr_matrix(G)
E = floyd_warshall(G, directed=False)
for s,t in ST:
if E[s-1][t-1]==float('inf'):
print(-1)
else:
print(int(E[s-1][t-1]-1)) | 1 | 173,523,618,069,920 | null | 295 | 295 |
s = input().split()
stack = []
for v in s:
# print("v", v)
# print("stack", stack)
if v in ["+", "-", "*"]:
v1 = stack.pop()
v2 = stack.pop()
statement = v2 + v + v1
r = eval(statement)
stack.append(str(r))
else:
stack.append(v)
assert len(stack) == 1
print(stack[0])
| list = input().split()
stack = []
for i in list:
if ( i.isdigit() ):
stack.append(int(i))
elif (i == '+'):
stack.append(stack.pop() + stack.pop())
elif (i == '*'):
stack.append(stack.pop() * stack.pop())
elif (i == '-'):
stack.append( (-1)*stack.pop() + stack.pop())
print(stack.pop()) | 1 | 37,837,914,362 | null | 18 | 18 |
N = int(input())
A = list(map(int,(input().split())))
sum=1
if 0 in A:
print(0)
else:
for i in range(N):
sum *= A[i]
if sum >= int(1e18):
break
print(sum if sum<= int(1e18) else -1) | N = int(input())
A = [int(a) for a in input().split()]
if A.count(0):
print(0)
exit(0)
ans=1
for a in A:
ans *= a
if ans > 10**18:
print(-1)
break
else:
print(ans)
| 1 | 16,195,252,160,138 | null | 134 | 134 |
from math import cos, radians, sin, sqrt
def g(a, b, c):
c_rad = radians(c)
yield a * b * sin(c_rad) / 2
yield a + b + sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(c_rad))
yield b * sin(c_rad)
a, b, c = list(map(int, input().split()))
for i in g(a, b, c):
print("{:.8f}".format(i)) | h,w=map(int,input().split())
print((h*w+1)//2 if h*w>h+w else 1) | 0 | null | 25,571,503,710,230 | 30 | 196 |
n,m = map(int, input().split())
l = list(map(int, input().split()))
c = 0
for index in l:
if index >= sum(l)/(4*m):
c += 1
print("Yes" if c >= m else "No") | n,m = list(map(int,input().split()))
A = list(map(int,input().split()))
sum_A = sum(A) / 4 / m
cnt = 0
for i in A:
if i >= sum_A:
cnt += 1
if cnt >= m:
print('Yes')
else:
print('No')
| 1 | 38,662,335,421,920 | null | 179 | 179 |
n = int(input())
S = list(str(input()))
S = [{ord(c)-ord('a')} for c in S]
def segfunc(x, y):
return x | y
def init(init_val):
# set_val
for i in range(n):
seg[i+num-1] = init_val[i]
# built
for i in range(num-2, -1, -1):
seg[i] = segfunc(seg[2*i+1], seg[2*i+2])
def update(k, x):
k += num - 1
seg[k] = x
while k:
k = (k-1)//2
seg[k] = segfunc(seg[2*k+1], seg[2*k+2])
def query(p, q):
if q <= p:
return ide_ele
p += num - 1
q += num - 2
res = ide_ele
while q-p>1:
if p&1 == 0:
res = segfunc(res, seg[p])
if q&1 == 1:
res = segfunc(res, seg[q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = segfunc(res, seg[p])
else:
res = segfunc(segfunc(res, seg[p]), seg[q])
return res
# identity element
ide_ele = set()
# num: n以上の最小の2のべき乗
num = 2**(n-1).bit_length()
seg = [ide_ele]*2*num
init(S)
import sys
input = sys.stdin.readline
q = int(input())
for i in range(q):
t, x, y = map(str, input().split())
if t == '1':
x = int(x)
y = ord(y)-ord('a')
update(x-1, {y})
else:
x = int(x)
y = int(y)
print(len(query(x-1, y)))
| class SegmentTree:
def __init__(self, lst, op, e):
self.n = len(lst)
self.N = 1 << ((self.n - 1).bit_length())
self.op = op # operation
self.e = e # identity element
self.v = self._build(lst) # self.v is set to be 1-indexed for simplicity
def _build(self, lst):
# construction of a tree
# total 2 * self.N elements (tree[0] is not used)
tree = [self.e] * (self.N) + lst + [self.e] * (self.N - self.n)
for i in range(self.N - 1, 0, -1): tree[i] = self.op(tree[i << 1], tree[(i << 1)|1])
return tree
def __getitem__(self, i):
return self.v[i + self.N]
# update a_i to be x
def update(self, i, x):
v, op = self.v, self.op
i += self.N
v[i] = x
while i > 0:
i >>= 1 # move to parent
v[i] = op(v[i << 1], v[(i << 1)|1])
# returns answer for the query interval [l, r)
def fold(self, l, r):
N, e, v, op = self.N, self.e, self.v, self.op
left = l + N; right = r + N
L = R = e
while left < right:
if left & 1: # self.v[left] is the right child
L = op(L, v[left])
left += 1
if right & 1: # self.v[right-1] is the left child
right -= 1
R = op(v[right], R)
left >>= 1; right >>= 1
return op(L, R)
def wa(set1, set2):
return set1 | set2
n = int(input())
s = input()
lst = []
for i in range(n):
lst.append(set([s[i]]))
st = SegmentTree(lst, wa, set([]))
ans = []
q = int(input())
for i in range(q):
que = input()
if que[0] == '1':
kind, i, c = que.split()
i = int(i) - 1
st.update(i, set([c]))
else:
kind, l, r = map(int, que.split())
l -= 1
ans.append(len(st.fold(l, r)))
for i in ans:
print(i) | 1 | 62,744,256,131,262 | null | 210 | 210 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
n = I()
A = readInts()
cum = list(accumulate(A))
ans = 0
for i in range(n-1):
ans += A[i] * (cum[n-1]-cum[i])
ans%=mod
print(ans%mod)
| num = int(input())
array = list(map(int,input().split()))
num_sum = 0
tmp_sum = 0
tmp_sum = sum(array)
for a in array:
tmp_sum -= a
num_sum += tmp_sum*a
print(num_sum % 1000000007) | 1 | 3,786,557,493,980 | null | 83 | 83 |
while True:
a, b, c = input().split()
a = int(a)
c = int(c)
if b == "?":
break
if b == "+":
print(a + c)
if b == "-":
print(a - c)
if b == "*":
print(a * c)
if b == "/":
print(a // c)
| def su(n):
if n < 0:
return 0
return n*(n+1)//2
MOD = 10 ** 9 + 7
N, K = map(int, input().split())
num = [i for i in range(N+1)]
ans = 0
su_N = su(N)
for i in range(K, N+2):
min = su(i-1)
max = su_N - su(N-i)
ans += max - min + 1
ans %= MOD
print(ans) | 0 | null | 16,888,111,656,130 | 47 | 170 |
from decimal import Decimal
def com_interest(n: int) -> int:
saving = 100
interest_per = 0.01
years = 0
while True:
years += 1
saving = int(saving * Decimal('1.01'))
if saving >= n:
break
return years
print(com_interest(int(input()))) | X = int(input())
ASSET = 100
cnt = 0
while ASSET < X:
ASSET += ASSET // 100
cnt += 1
print(cnt) | 1 | 27,266,207,280,090 | null | 159 | 159 |
A, B, K = map(int, input().split())
if A-K >= 0:
print(A-K, B)
else:
if B-(K-A)<0:
print(0, 0)
quit()
print(0, B-(K-A)) | a, b, k = map(int, input().split())
if k >= a + b:
print("0 0")
elif k >= a:
print("0" + " " + str(b - (k-a)))
else:
print(str(a-k) + " " + str(b))
| 1 | 104,618,893,661,782 | null | 249 | 249 |
l = map (int, raw_input().split())
if l[0]<l[1]:
if l[1]<l[2]:
print 'Yes'
else:
print 'No'
else:
print 'No' | a, b, c = (int(i) for i in ((input()).split()))
if a < b < c:
print('Yes')
else:
print('No') | 1 | 386,514,295,458 | null | 39 | 39 |
n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
m = arr[-1]
li = [0]*(m+1)
cnt = 0
for i in arr:
for j in range(i, m+1, i):
li[j] += 1
for i in arr:
if li[i] == 1:
cnt += 1
print(cnt) | import numpy as np
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
m = np.zeros(max(a)+1, dtype=int)
cnt = 0
for i in range(n):
x = a[i]
if i == n-1:
if m[x] == 0:
cnt +=1
else:
if m[x] == 0 and a[i] != a[i+1]:
cnt +=1
m[x::x] += 1
print(cnt) | 1 | 14,343,518,361,290 | null | 129 | 129 |
import math
n=int(input())
x=100000
for i in range(n):
x=x*1.05
# print('5%',x)
x=x/1000
#print('/1000',x)
x=math.ceil(x)
#print('cut',x)
x=x*1000
#print('*1000',x)
print(x) | #!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
r = int(input())
print(r**2)
if __name__ == '__main__':
main()
| 0 | null | 72,334,947,371,732 | 6 | 278 |
#!usr/bin/env python3
def string_five_numbers_spliter():
"""Split a given space-separated five numbers in a string into integers
Return five integer values from a given space-separated five integers in a string.
Returns:
Five integer values; namely, w, h, x, y and r
"""
w, h, x, y, r = [int(i) for i in input().split()]
return w, h, x, y, r
def main():
# Given that there are a rectangle and a circle.
# Let w, h, x, y and r be such that:
# w = width of the rectangle
# h = height of thek rectangle
# x = x coordinate for the centre of the circle
# y = y coordinate for the centre of the circle
# r = diameter of the circle
w, h, x, y, r = string_five_numbers_spliter()
if (not (x < 0) and not (y < 0) and
not (x + r < 0) and not (y + r < 0) and
not (x + r > w) and not (y + r > h)):
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | def main():
W,H,x,y,r=map(int,input().split())
if x<=0 or y<=0:
print('No')
elif W>=2*r and H>=2*r and W>=x+r and H>=y+r:
print('Yes')
else:
print('No')
if __name__=='__main__':
main()
| 1 | 446,752,306,380 | null | 41 | 41 |
def BubbleSort(C,N):
for i in range(N):
j = N-1
while True:
if j == 0:
break
a,b = list(C[j]),list(C[j-1])
if a[1] < b[1]:
tmp = C[j-1]
C[j-1] = C[j]
C[j] = tmp
j -= 1
return C
def SelectionSort(D,N):
for i in range(N):
minj = i
for j in range(i,N):
a,b = list(D[j]),list(D[minj])
if a[1] < b[1]:
minj = j
tmp = D[i]
D[i] = D[minj]
D[minj] = tmp
return D
n = int(input())
d = input().split()
d2 = list(d)
d = BubbleSort(d,n)
for i in range(len(d)-1):
print(d[i],end = ' ')
print(d[-1])
print('Stable')
d2 = SelectionSort(d2,n)
for i in range(len(d2)-1):
print(d2[i],end = ' ')
print(d2[-1])
if d2 == d:
print('Stable')
else:
print('Not stable') | # Aizu Problem ALDS_1_2_C: Stable Sort
#
import sys, math, os
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input2.txt", "rt")
def printA(A):
print(' '.join([str(a) for a in A]))
def bubble_sort(A):
for i in range(len(A) - 1):
for j in range(len(A) - 1, i, -1):
if A[j][1] < A[j - 1][1]:
A[j], A[j - 1] = A[j - 1], A[j]
return A
def selection_sort(A):
for i in range(len(A)):
mini = i
for j in range(i, len(A)):
if A[j][1] < A[mini][1]:
mini = j
if mini != i:
A[i], A[mini] = A[mini], A[i]
return A
def is_stable(A, B):
for val in range(1, 10):
v = str(val)
if [a[0] for a in A if a[1] == v] != [b[0] for b in B if b[1] == v]:
return False
return True
N = int(input())
A = list(input().split())
A_bubble = bubble_sort(A[:])
printA(A_bubble)
print("Stable" if is_stable(A, A_bubble) else "Not stable")
A_select = selection_sort(A[:])
printA(A_select)
print("Stable" if is_stable(A, A_select) else "Not stable") | 1 | 24,676,085,280 | null | 16 | 16 |
N = int(input())
A = input().split()
num_list = [0] * 10**5
ans = 0
for i in range(N):
num_list[int(A[i])-1] += 1
for i in range(10**5):
ans += (i+1) * num_list[i]
Q = int(input())
for i in range(Q):
B, C = map(int, input().split())
ans = ans + C * num_list[B-1] - B * num_list[B-1]
num_list[C-1] += num_list[B-1]
num_list[B-1] = 0
print(ans) | import collections
N=int(input())
A=list(map(int,input().split()))
X=collections.Counter(A)
Q=int(input())
ans=sum(A)
for i in range(Q):
B,C=map(int,input().split())
ans+=(C-B)*X[B]
print(ans)
X[C]+=X[B]
X[B]=0
| 1 | 12,168,874,061,344 | null | 122 | 122 |
h,w,k = map(int,input().split())
s = [list(map(int,input())) for _ in range(h)]
ans = h*w
for div in range(1<<(h-1)):
row = 0
S = [[0]*w]
S[row] = [s[0][i] for i in range(w)]
for i in range(1,h):
if 1&(div>>i-1):
row += 1
S.append([s[i][j] for j in range(w)])
else:
S[row] = [S[row][j]+s[i][j] for j in range(w)]
count = [0]*(row+1)
ans_ = row
a = True
for i in range(w):
for j in range(row+1):
if S[j][i] > k:
a = False
break
count[j] += S[j][i]
if count[j] > k:
ans_+=1
count = [0]*(row+1)
for l in range(row+1):
count[l] += S[l][i]
break
if ans_ >= ans or a==False:
break
if a:
ans = min(ans,ans_)
print(ans) | H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
def calc(L):
M = len(L)
cnt = [0] * M
ret = 0
for w in range(W):
for i, (t, b) in enumerate(zip(L, L[1:])):
for j in range(t, b):
if S[j][w] == '1':
cnt[i] += 1
if max(cnt) > K:
cnt = [0] * M
ret += 1
for i, (t, b) in enumerate(zip(L, L[1:])):
for j in range(t, b):
if S[j][w] == '1':
cnt[i] += 1
if max(cnt) > K:
return 10**18
return ret
ans = 10**18
for mask in range(1 << (H - 1)):
L = [0] + [d + 1 for d in range(H - 1) if (mask & (1 << d)) > 0] + [H]
ans = min(ans, len(L) - 2 + calc(L))
print(ans)
| 1 | 48,458,834,392,530 | null | 193 | 193 |
N,X,T = [int(i) for i in input().split()]
print((N+X-1)//X*T) | n,x,t=map(int,input().split())
count = n // x
if n % x == 0:
pass
else:
count += 1
print(count * t) | 1 | 4,226,350,202,520 | null | 86 | 86 |
arr = input().split()
n = {
0 : [(3, 1), (4, 3), (2, 4), (1, 2)],
1 : [(0, 3), (3, 5), (5, 2), (2, 0)],
2 : [(0, 1), (4, 0), (5, 4), (1, 5)],
3 : [(0, 4), (4, 5), (5, 1), (1, 0)],
4 : [(0, 2), (2, 5), (5, 3), (3, 0)],
5 : [(1, 3), (3, 4), (4, 2), (2, 1)],
}
q = int(input())
for _ in range(q):
a, b = input().split()
for i in range(6):
if (arr.index(a), arr.index(b)) in n[i]:
print(arr[i])
| import random
class Dice():
def __init__(self, *n):
self.rolls = n
def spin(self, order):
if order == "N":
self.rolls = [
self.rolls[1],
self.rolls[5],
self.rolls[2],
self.rolls[3],
self.rolls[0],
self.rolls[4]
]
if order == "E":
self.rolls = [
self.rolls[3],
self.rolls[1],
self.rolls[0],
self.rolls[5],
self.rolls[4],
self.rolls[2]
]
if order == "S":
self.rolls = [
self.rolls[4],
self.rolls[0],
self.rolls[2],
self.rolls[3],
self.rolls[5],
self.rolls[1]
]
if order == "W":
self.rolls = [
self.rolls[2],
self.rolls[1],
self.rolls[5],
self.rolls[0],
self.rolls[4],
self.rolls[3]
]
return self.rolls[0]
d = Dice(*[int(i) for i in input().split()])
directions = ['N','E','S','W']
for _ in range(int(input())):
a,b = [int(i) for i in input().split()]
while a != d.rolls[0] or d.rolls[1] != b:
d.spin(directions[random.randint(0,3)])
print(d.rolls[2]) | 1 | 251,766,875,022 | null | 34 | 34 |
# coding: utf-8
def main():
N = int(input())
A = list(map(int, input().split()))
B = [[a, i + 1] for i, a in enumerate(A)]
B.sort()
for i, j in B:
if i == N:
print(j)
else:
print(j, "", end='')
if __name__ == "__main__":
main()
| s,t=map(str,input().split());print(t+s) | 0 | null | 141,985,353,722,368 | 299 | 248 |
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
#??????
if __name__ == "__main__":
n_line = int(input())
l = set([])
for i in range(n_line):
input_line = input().split()
if input_line[0] == "insert":
l.add(input_line[1])
else:
if input_line[1] in l:
print("yes")
else:
print("no") | # 解法1
# def main():
# N, M = map(int, input().split())
# num = [-1] * N
# for _ in range(M):
# s, c = map(int, input().split())
# s -= 1
# if s == 0 and c == 0:
# if N != 1:
# print(-1)
# return
# if num[s] == -1:
# num[s] = c
# elif num[s] != c:
# print(-1)
# return
# ans = ""
# for i in range(len(num)):
# c = num[i]
# if c == -1:
# if i != 0 or N == 1:
# ans += "0"
# else:
# ans += "1"
# else:
# ans += str(c)
# print(ans)
# 解法2
def main():
N, M = map(int, input().split())
S = [0] * M
C = [0] * M
for i in range(M):
s, c = map(int, input().split())
S[i] = s-1
C[i] = c
if N == 1:
start = 0
else:
start = 10 ** (N - 1)
for n in range(start, 10 ** (N)):
n = str(n)
ok = True
for i in range(M):
s = S[i]
c = C[i]
if n[s] != str(c):
ok = False
break
if ok:
print(n)
return
print(-1)
main()
| 0 | null | 30,241,933,668,800 | 23 | 208 |
import sys
def m():
d={};input()
for e in sys.stdin:
if'f'==e[0]:print('yes'if e[5:]in d else'no')
else:d[e[7:]]=0
if'__main__'==__name__:m()
| n = input()
dict_ = set()
for _ in xrange(n):
cmd, str_ = raw_input().split()
if cmd == "insert":
dict_.add(str_)
elif cmd == "find":
if str_ in dict_:
print "yes"
else:
print "no" | 1 | 76,043,260,300 | null | 23 | 23 |
def readInt():
return list(map(int, input().split()))
h, w = readInt()
if h == 1 or w == 1:
print(1)
elif h*w%2 == 0:
print(h*w//2)
else:
print(h*w//2+1)
| X, Y, Z = map(int, input().split())
ans = [Z, X, Y]
print(*ans)
| 0 | null | 44,424,538,950,080 | 196 | 178 |
n = list(input())
tmp = 0
for i in n:
tmp += int(i) % 9
ans = "Yes" if tmp % 9 == 0 else "No"
print(ans)
| n = list(input())
for i in range(len(n)) :
n[i] = int(n[i])
if sum(n)%9==0 :
print("Yes")
else :
print("No") | 1 | 4,455,636,279,348 | null | 87 | 87 |
from itertools import product
N, M, X = map(int, input().split())
C = []
A = []
for _ in range(N):
c, *a = map(int, input().split())
C.append(c)
A.append(a)
ans = float("inf")
for buys in product((0, 1), repeat=N):
cost = 0
achivements = [0] * M
for i, buy in enumerate(buys):
if not buy:
continue
cost += C[i]
for j in range(M):
achivements[j] += A[i][j]
if all(a >= X for a in achivements):
ans = min(ans, cost)
print(ans) if ans != float("inf") else print(-1)
| n, m, x = map(int, input().split())
book = [list(map(int, input().split())) for i in range(n)]
min_num = 10**18
for i in range(1<<n):
cost = 0
l = [0]*m
for j in range(n):
if (i>>j)&1:
c, *a = book[j]
cost += c
for k ,ak in enumerate(a):
l[k] += ak
if all(lj >= x for lj in l):
min_num = min(min_num,cost)
print(-1 if min_num == 10**18 else min_num)
| 1 | 22,235,932,476,230 | null | 149 | 149 |
n, m = map(int, input().split())
def ark(a, b):
return min(abs(a - b), n - abs(a - b))
a, b = n, 1
S = set()
for i in range(m):
if 2 * ark(a, b) == n or ark(a, b) in S:
a -= 1
print(a, b)
S.add(ark(a, b))
a -= 1
b += 1
| N, M = map(int, input().split())
if N % 2 == 1:
for a in range(1, M + 1):
print(a, N - a + 1)
else:
for a in range(1, M + 1):
if a < -(-M // 2) + 1:
print(a, N - a + 1)
else:
print(a, N - a) | 1 | 28,505,291,883,442 | null | 162 | 162 |
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
K, X = map(int, readline().split())
if 500 * K >= X:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| def main():
K,X = map(int, input().split())
if 500*K>=X:
print("Yes")
else:
print("No")
main()
| 1 | 98,385,790,070,810 | null | 244 | 244 |
import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def solve():
m = a[-1]+1
ava = [0]*m
for rep in a:
ava[rep] += 1
if ava[rep]==1:
for item in range(2*rep,m,rep):
ava[item] += 2
print(ava.count(1))
return
if __name__=='__main__':
n = I()
a = list(IL())
a.sort()
solve() | import sys
x=[]
n=input()
for i in range(3,n+1):
if i%3==0:
x.append(i)
else:
j=i
while j!=0:
if j%10==3:
x.append(i)
break
j=j/10
X=iter(x)
for i in X:
sys.stdout.write(' ')
sys.stdout.write('%d'%i)
print('') | 0 | null | 7,695,284,604,030 | 129 | 52 |
N = int((input()))
C_p = []
C_m = []
for i in range(N):
kakko = input()
temp = 0
temp_min = 0
for s in kakko:
if s == "(":
temp += 1
else:
temp -= 1
temp_min = min(temp, temp_min)
if temp >= 0:
C_p.append((temp_min, temp))
else:
C_m.append((temp_min - temp, temp_min, temp))
C_p.sort(reverse=True)
flag = 0
final = 0
for l, f in C_p:
if final + l < 0:
flag = 1
final += f
C_m.sort()
for _, l, f in C_m:
if final + l < 0:
flag = 1
final += f
if final != 0:
flag = 1
print("Yes" if flag == 0 else "No") | #!/usr/bin/env python3
import sys
input = sys.stdin.readline
n = int(input())
increasing = []
decreasing = []
dec_special = []
for _ in range(n):
s = input().rstrip()
minima = 0
fin = 0
for ch in s:
if ch == ")":
fin -= 1
if fin < minima:
minima = fin
else:
fin += 1
if fin >= 0:
increasing.append((minima, fin))
elif minima < fin:
dec_special.append((minima, fin))
else:
decreasing.append((minima, fin))
increasing.sort(reverse=True)
decreasing.sort()
dec_special.sort()
current = 0
for minima, diff in increasing:
if current + minima < 0:
print("No")
exit()
current += diff
for minima, diff in dec_special:
if current + minima < 0:
print("No")
exit()
current += diff
for minima, diff in decreasing:
if current + minima < 0:
print("No")
exit()
current += diff
if current != 0:
print("No")
else:
print("Yes")
| 1 | 23,760,914,237,952 | null | 152 | 152 |
import numpy as np
n, s = map(int, input().split())
a = [int(i) for i in input().split()]
mod = 998244353
dp = np.zeros(s+1, dtype='i8')
dp[0] = 1
for aa in a:
tmp = 2 * dp % mod
tmp[aa:] += dp[:-aa]
tmp %= mod
dp = tmp
print(dp[s])
| N=int(input())
S=["a"]*N
T=[0]*N
for i in range(N):
S[i],T[i]=input().split()
X=input()
flag=0
x=0
for i in range(N):
if flag==1:
x+=int(T[i])
elif X==S[i]:
flag=1
print(x)
| 0 | null | 57,508,446,158,660 | 138 | 243 |
n, x, m = map(int, input().split())
lis = [x]
flag = [-1 for i in range(m)]
flag[x] = 0
left = -1
right = -1
for i in range(n-1):
x = x**2 % m
if flag[x] >= 0:
left = flag[x]
right = i
break
else:
lis.append(x)
flag[x] = i+1
ans = 0
if left == -1:
ans = sum(lis)
else:
ans += sum(lis[0:left])
length = right - left + 1
ans += sum(lis[left:]) * ((n-left)//length)
ans += sum(lis[left:left+((n-left)%length)])
print(ans) | n, x, m = map(int, input().split())
ans = 0
a = [0]
id = [0]*(m+1)
l = 1
while id[x] == 0:
a.append(x)
id[x] = l
ans += x
l += 1
x = x**2 % m
c = l - id[x]
s=0
for i in range(id[x],l):
s += a[i]
if n <= l-1:
ans = 0
for i in range(1,n+1):
ans += a[i]
else:
n -= l
n += 1
ans += s*(n//c)
n %= c
for i in range(n):
ans += a[id[x] + i]
print(ans) | 1 | 2,791,853,068,048 | null | 75 | 75 |
# coding=utf-8
inputs = raw_input().rstrip().split()
nums = [int(x) for x in inputs]
print ' '.join([str(x) for x in sorted(nums)]) | n = int(input())
tst = [[] for i in range(n)]
for i in range(n):
a = int(input())
for j in range(a):
x,y = map(int,input().split())
tst[i].append([x,y])
ans = 0
for bit in range(1<<n):
honest = [0]*n
check = 1
for i in range(n):
if (bit>>i)&1:
honest[-1-i] = 1
for i in range(n):
if not honest[i]:
continue
for l in tst[i]:
if l[1]!=honest[l[0]-1]:
check = 0
break
if check:
ans = max(ans,sum(honest))
print(ans) | 0 | null | 61,251,905,492,348 | 40 | 262 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: D_fix_3
# CreatedDate: 2020-08-30 13:22:07 +0900
# LastModified: 2020-08-30 13:41:03 +0900
#
import os
import sys
# import numpy as np
# import pandas as pd
def main():
S = input()
Q = int(input())
appendix_1 = ''
appendix_2 = ''
reverse = 0
for _ in range(Q):
q = list(input().split())
if q[0] == '1':
reverse += 1
else:
if q[1] == '1' and reverse % 2 == 0:
appendix_1 += q[2]
elif q[1] == '1' and reverse % 2 == 1:
appendix_2 += q[2]
if q[1] == '2' and reverse % 2 == 0:
appendix_2 += q[2]
elif q[1] == '2' and reverse % 2 == 1:
appendix_1 += q[2]
if reverse % 2 == 0:
print(appendix_1[::-1] + S + appendix_2)
else:
print(appendix_2[::-1] + S[::-1] + appendix_1)
if __name__ == "__main__":
main()
| import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
def main():
s = deque(input())
q = int(input())
reverse = False
for _ in range(q):
query = list(input().split())
if query[0] == '1':
reverse ^= True
else:
if reverse:
if query[1] == '1':
s.append(query[2])
else:
s.appendleft(query[2])
else:
if query[1] == '1':
s.appendleft(query[2])
else:
s.append(query[2])
s = ''.join(s)
if reverse:
s = s[::-1]
print(s)
if __name__ == '__main__':
main() | 1 | 57,179,147,597,640 | null | 204 | 204 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
inf = 10**17
mod = 10**9+7
n = int(input())
s = input()
ans = 0
for i in range(n):
if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C': ans += 1
print(ans)
| N = int(input())
S = input()
counter = 0
for i in range(0,N-2):
if(S[i] == "A"):
if(S[i+1] == "B"):
if(S[i+2] == "C"):
counter += 1
print(counter) | 1 | 99,072,229,771,488 | null | 245 | 245 |
N = int(input())
K = int(input())
def cmb(n, r):
if n - r < r: r = n - r
if r == 0: return 1
if r == 1: return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2,r+1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p-1,r,p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
def contain_one(n):
a = 100
max_num = 10**a
while 1:
if n // max_num == 0:
a -= 1
max_num = 10**a
else:
break
return 9*a+(n//max_num)
def contain_two(n):
if n <=10:
return 0
a = 100
max_num = 10**a
while 1:
if n // max_num == 0:
a -= 1
max_num = 10**a
else:
break
cnt = 0
#10^a位まで
for i in range(1, a):
cnt += 9*9*i
#10^a位
tmp = n // max_num
cnt += 9*a*(tmp-1)
#nの10^a桁より小さい数
tmp = n % max_num
#怪しい
if tmp != 0:
cnt += contain_one(tmp)
return cnt
def contain_three(n):
if n <=100:
return 0
a = 100
max_num = 10**a
while 1:
if n // max_num == 0:
a -= 1
max_num = 10**a
else:
break
cnt = 0
#10000以上の時ここがダメ
for i in range(2, a):
if i == 2:
cnt += 9**2 * 9
else:
#3H(a-2) = aCa-2
cnt += 9**2 * 9 * cmb(i, i-2)
#aH2
#cnt += 9**2 * 9 * (i*(i+1)//2)
# tmp = tmp * 3
# cnt += tmp
tmp = n // max_num
if a == 2:
cnt += 9**2 * (tmp-1)
else:
cnt += 9**2 * (tmp-1) * cmb(a, a-2)
tmp = n % max_num
if tmp != 0:
cnt += contain_two(tmp)
return cnt
if K == 1:
print(contain_one(N))
elif K == 2:
print(contain_two(N))
else:
print(contain_three(N))
| from math import factorial
def combination(n, r):
return factorial(n)//(factorial(n-r) * factorial(r))
def answer(n,k):
ans = 0
if k>1:
if n=='':
return 0
# 先頭が0の時
if n[0]=='0':
ans += answer(n[1:],k)
else:
# 先頭以外で3つ使う
if len(n)>k:
ans += combination(len(n)-1,k)*9**k
# 先頭で一つ使うが、先頭はNの先頭より小さい
if len(n)>k-1:
ans += (int(n[0])-1)*combination(len(n)-1,k-1)*9**(k-1)
# 先頭で、Nの先頭と同じ数を使う
ans += answer(n[1:],k-1)
else:
if n=='':
return 0
if n[0]=='0':
ans += answer(n[1:],k)
else:
if len(n)>1:
ans += combination(len(n)-1,1)*9
ans += int(n[0])
return ans
n = input()
k = int(input())
print(answer(n,k) if len(n)>=k else 0) | 1 | 75,842,842,240,900 | null | 224 | 224 |
import itertools
#h,w=map(int,input().split())
#S=[list(map(int,input().split())) for _ in range(h)]
n=int(input())
A=list(map(int,input().split()))
Ar=list(itertools.accumulate(A))
ans=0
for i in range(n-1):
ans+=A[i]*(Ar[n-1]-Ar[i])
ans%=10**9+7
print(ans)
| N = int(input())
A = list(map(int,input().split()))
mod = 1000000000 + 7
add = 0
tmp = sum(A)
for i in range(N):
tmp -= A[i]
add += tmp * A[i]
print(add%mod) | 1 | 3,870,733,888,128 | null | 83 | 83 |
str = input()
s_ans = 'Yes'
if len(str)%2 == 1:
s_ans ='No'
else:
for i in range(0,len(str),2):
moji = str[i:i+2]
if str[i:i+2] != 'hi':
s_ans = 'No'
break
print(s_ans) | h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]
dp = [[0] * w for i in range(h)]
for i in range(h):
for j in range(w):
if i == j == 0:
if maze[i][j] == "#":
dp[i][j] += 1
if i == 0 and j != 0:
if maze[0][j] != maze[0][j - 1]:
dp[0][j] = dp[0][j - 1] + 1
else:
dp[0][j] = dp[0][j - 1]
if j == 0 and i != 0:
if maze[i][0] != maze[i - 1][0]:
dp[i][0] = dp[i - 1][0] + 1
else:
dp[i][0] = dp[i - 1][0]
if i != 0 and j != 0:
dp[i][j] = min(dp[i - 1][j] + (1 if maze[i][j] != maze[i - 1][j] else 0), dp[i][j - 1] + (1 if maze[i][j] != maze[i][j - 1] else 0))
if i == h - 1 and j == w - 1:
if maze[i][j] == "#":
dp[i][j] += 1
ans = dp[h - 1][w - 1] // 2
print(ans) | 0 | null | 50,962,978,182,028 | 199 | 194 |
a,b,c=map(int,input().split())
print("Yes"*(a<b<c)or"No")
| nums = input().split()
a = nums[0]
b = nums[1]
c = nums[2]
if a < b and b < c:
print( "Yes")
else:
print( "No") | 1 | 395,100,858,880 | null | 39 | 39 |
import sys
(row, column) = sys.stdin.readline().rstrip('\r\n').split(' ')
row = int(row)
column = int(column)
a = []
b = []
c = []
for ii in range(row):
a.append([int(x) for x in input().rstrip('\r\n').split(' ')])
for ii in range(column):
b.append(int(input().rstrip('\r\n')))
for ii in range(len(a)):
work = 0
for jj in range(len(a[ii])):
work += a[ii][jj] * b[jj]
c.append(work)
for cc in c:
print(cc)
| n, m = list(map(int, input().split()))
mat = [list(map(int, input().split())) for _ in range(n)]
vec = [int(input()) for _ in range(m)]
for v in mat:
print(sum(a * b for a, b in zip(v, vec))) | 1 | 1,168,353,613,572 | null | 56 | 56 |
rs = [(x - l, x + l) for x, l in (map(int, input().split()) for _ in range(int(input())))]
rs.sort(key=lambda x: x[1])
last = - 10 ** 9
ans = 0
for l, r in rs:
if last <= l:
ans += 1
last = r
print(ans) | import numpy as np
N = int(input())
X = [[] for _ in range(N)]
L = [[] for _ in range(N)]
for i in range(N):
X[i], L[i] = map(int, input().split())
def indexSort(L):
D = dict(zip(range(len(L)), L))
E = sorted(D.items(), key=lambda x: x[1])
F = [e[0] for e in E]
return F
L1 = [x-l for x, l in zip(X, L)]
L2 = [x+l for x, l in zip(X, L)]
Ind = np.argsort(L2)
Remain = [Ind[0]]
i = 0
while i < len(Ind)-1:
now = Remain[-1]
After = Ind[i+1:]
skip = 0
for after in After:
if L2[now] > L1[after]:
# print(L2[now], L1[after])
skip += 1
else:
# print(after)
Remain.append(after)
break
i += 1 + skip
print(len(Remain)) | 1 | 89,693,553,832,498 | null | 237 | 237 |
for i in range(0, 10000):
print('Case {}: {}'.format(i + 1, input()))
| i = 0
while True :
x = int(input())
if(x == 0) :
break
else :
i += 1
print("Case ", i, ": ", x, sep = "")
| 1 | 487,736,836,390 | null | 42 | 42 |
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
pc_memo = defaultdict(int)
memo = defaultdict(int)
def to_next(x):
if x not in pc_memo.keys():
pc_memo[x] = x % "{:b}".format(x).count('1')
return pc_memo[x]
def f(x):
if x == 0:
return 0
if x not in memo.keys():
memo[x] = f(to_next(x))+1
return memo[x]
for i in range(2*10**5):
f(i)
n = int(input())
x = input().rstrip()
one_cnt = x.count('1')
mod_minus = 0
mod_plus = 0
for i, a in enumerate(reversed(x)):
if a == '1':
if 0 < one_cnt-1:
mod_minus += pow(2, i, one_cnt-1)
mod_minus %= one_cnt-1
mod_plus += pow(2, i, one_cnt+1)
mod_plus %= one_cnt+1
for i in range(n):
if x[i] == '0':
nx = mod_plus+pow(2, n-i-1, one_cnt+1)
nx %= one_cnt+1
print(f(nx)+1)
else:
if 0 < one_cnt-1:
nx = mod_minus-pow(2, n-i-1, one_cnt-1)
nx %= one_cnt-1
print(f(nx)+1)
else:
print(0)
| N = int(input())
X = input()
val = int(X,2)
C = X.count("1")
if C==1:
for i in range(N):
if X[i]=='1':
print(0)
elif i==N-1:
print(2)
else:
print(1)
exit()
# xをpopcountで割ったあまりに置き換える
def f(x):
if x==0: return 0
return 1 + f(x % bin(x).count("1"))
# 初回のpopcountでの割り方は、(C+1) or (C-1)
Y = val%(C+1)
if C-1 != 0:
Z = val%(C-1)
else:
Z = 0
for i in range(N):
if X[i] == "1":
if Z - 1 == 0:
print(0)
continue
k = (Z - pow(2,N-i-1,C-1)) % (C-1)
else:
k = (Y + pow(2,N-i-1,C+1)) % (C+1)
print(f(k)+1) | 1 | 8,211,627,221,700 | null | 107 | 107 |
n = int(input())
s,t = input().split()
ans = ''
for i in range(n):
ans += s[i]
ans += t[i]
print(ans) |
def main():
n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]
count = 0
for t in T:
for s in S:
if t == s:
count += 1
break
print(count)
if __name__ == '__main__':
main() | 0 | null | 56,160,211,708,380 | 255 | 22 |
n = int(input())
s = input()
if n % 2 != 0:
print('No')
elif s[:n//2] == s[n//2:]:
print("Yes")
else:
print("No")
| # 145 B
n = int(input())
s = input()
if len(s) % 2 == 0:
x = len(s) // 2
if s[:x] == s[x:]:
print("Yes")
else:
print("No")
else:
print("No") | 1 | 146,284,298,148,758 | null | 279 | 279 |
n = int(input())
A = list(map(int, input().split()))
T = [0]*n
for a in A:
T[a-1] += 1
for t in T:
print(t) | import sys
N = int(input())
A = list(map(int, input().split()))
ans = [0] * N
for i in A:
ans[i-1] += 1
for i in range(N):
print(ans[i] ,end=" ") | 1 | 32,436,858,847,500 | null | 169 | 169 |
#!/usr/bin/env python3
def main():
_ = int(input())
P = [int(x) for x in input().split()]
res = P[0]
ans = 0
for p in P:
if p <= res:
ans += 1
res = p
print(ans)
if __name__ == '__main__':
main()
| N = int(input())
li = list(map(int, input().split()))
minL = 2 * (10**6)
count = 0
for l in li:
if (minL >= l):
count += 1
minL = l
print(count) | 1 | 85,342,730,438,912 | null | 233 | 233 |
'''
Rjの最小値を保持することで最大利益の更新判定をn回で終わらせる
'''
r = []
n = int(input())
for i in range(n):
i = int(input())
r.append(i)
minv = r[0]
maxv = r[1] - r[0]
for j in range(1,n):
maxv = max(maxv, r[j]-minv)
minv = min(minv, r[j])
print(maxv)
| n = int(input())
DifMax = -9999999999999
R = [int(input())]
RMin = R[0]
for i in range(1, n):
if RMin > R[i-1]:
RMin = R[i-1]
R.append(int(input()))
if DifMax < R[i] - RMin:
DifMax = R[i] - RMin
print(DifMax) | 1 | 13,157,360,930 | null | 13 | 13 |
n=int(input())
a=[]
l=[]
for i in range(n):
A=int(input())
L=[list(map(int,input().split())) for _ in range(A)]
a.append(A)
l.append(L)
ans=0
for i in range(2**n):
b=[0]*n
for j in range(n):
if (i>>j)&1:
b[j]=1
for k in range(n):
for h in range(a[k]):
hito=l[k][h][0]-1
singi=l[k][h][1]
if b[k]==1 and b[hito]!=singi:
break
else:
continue
break
else:
ans=max(ans,sum(b))
print(ans)
| import math
r = float(raw_input())
print "%.5f %.5f" %(r**2*math.pi, 2*r*math.pi) | 0 | null | 61,179,570,681,540 | 262 | 46 |
import itertools
n = int(input())
for i in itertools.count():
if (i * 1000) >= n:
break
print(i * 1000 - n)
| import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n = inp()
s = input()
pre = ''
ans = 0
for t in s:
if(pre != t):
ans += 1
pre = t
print(ans) | 0 | null | 89,488,019,304,292 | 108 | 293 |
n = int(input())
l = list(map(int, input().split()))
ans=0
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
li = [l[i], l[j], l[k]]
m = max(li)
if 2*m < sum(li) and len(set(li)) == 3:
ans += 1
print(ans) | # https://atcoder.jp/contests/abc149/tasks/abc149_e
# すべての握手の組み合わせN**2を列挙しソートしM番目までを足し合わせればOK
# だけど制約からこれを行うことは困難
# すべてを列挙しなくともM番目の値を知ることは二分探索で可能(参考:億マス計算)
# Aの累積和を保持しておけば、M番目の値の探索中にMまでの値の合計もついでに計算できる
# 以下reverseでソート済みだと仮定
# XがM番目の数→X以上である数はM個以上(cntとする)→cntがM個以上の条件を満たすうちの最大となるXがM番目の値
# そのあと余分な分を引く処理とか必要
from bisect import bisect_right, bisect_left
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
class cumsum1d:
def __init__(self, ls: list):
'''
1次元リストを受け取る
'''
from itertools import accumulate
self.ls_accum = [0] + list(accumulate(ls))
def total(self, i, j):
# もとの配列lsにおける[i,j)の中合計
return self.ls_accum[j] - self.ls_accum[i]
N, M = read_ints()
A = read_ints()
A.sort() # bisectを使う都合上 reverseは抜き
A_reversed = list(reversed(A))
A_rev_acc = cumsum1d(A_reversed)
def is_ok(X):
# M番目の数はXである→X以上の個数>=M となるうちで最大のX(もっとも左の方のX)
# X以上の個数>=Mを返す
# X以下の個数はai+aj>=Xを満たす個数
cnt = 0
ans = 0
for a in A:
aa = X - a
idx_reverse = N - bisect_left(A, aa) # 大きい方からだと何番目か
# これはbisect_right(A_reversed,aa)に等しい
cnt += idx_reverse
ans += A_rev_acc.total(0, idx_reverse) + idx_reverse * a
return cnt >= M, ans, cnt
def meguru_bisect(ng, ok):
'''
define is_okと
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
ng ok は とり得る最小の値-1 とり得る最大の値+1
最大最小が逆の場合はよしなにひっくり返す
'''
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
flg, ans, cnt = is_ok(mid)
if flg:
ok = mid
ans_true = ans # さいごにokとなる状態がans
cnt_true = cnt
else:
ng = mid
return ans_true, ok, cnt_true
ans_tmp, M_th_num, M_plus_alpha_th = \
meguru_bisect(2 * 10 ** 5 + 1, 0)
# print(ans_tmp, M_th_num, M_plus_alpha_th)
print(ans_tmp - (M_plus_alpha_th - M) * M_th_num)
| 0 | null | 56,664,654,254,802 | 91 | 252 |
A,B,C,K=map(int,input().split())
if A>=K:
print(K)
exit()
elif A+B>=K:
print(A)
exit()
else:
c=K-A-B
print(A-c) | import math
while 1:
n=int(input())
if n==0:
break
ave=0.0
aru=0.0
m=[float(i) for i in input().split()]
for i in range(n):
ave=ave+m[i]
ave=ave/n
for i in range(n):
aru=aru+(m[i]-ave)*(m[i]-ave)
aru=math.sqrt(aru/n)
print("%.5f"% aru) | 0 | null | 10,973,761,704,140 | 148 | 31 |
print(abs(int(input())-2199)//200) | t = input('')
tlist = list(t)
for i in range(len(tlist)):
if tlist[i] == '?':
if i==0:
tlist[i] = 'D'
elif i==len(tlist)-1:
tlist[i] = 'D'
else:
if tlist[i-1] == 'P':
if tlist[i+1] == 'P':
tlist[i] = 'D'
elif tlist[i+1] == 'D':
tlist[i] = 'D'
elif tlist[i+1] == '?':
tlist[i] = 'D'
else:
# 1つ前が'D'
if tlist[i+1] == 'P':
tlist[i] = 'D'
elif tlist[i+1] == 'D':
tlist[i] = 'P'
elif tlist[i+1] == '?':
tlist[i] = 'P'
print("".join(tlist)) | 0 | null | 12,584,523,308,544 | 100 | 140 |
n, k = map(int, input().split())
print(sum(int(i) >= k for i in input().split())) | n, k = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
ans = len(h)
for height in h:
if height < k:
ans -= 1
else:
print(ans)
exit()
print(ans)
| 1 | 178,389,614,991,040 | null | 298 | 298 |
n=int(input())
s=[""]*n
t=[0]*n
for i in range(n):
s[i],t[i]=input().split()
t[i]=int(t[i])
x=input()
c=0
for i in range(n):
if s[i]==x:
c=i
break
ans=0
for i in range(c+1,n):
ans+=t[i]
print(ans) | 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 | 59,551,223,800,812 | 243 | 148 |
# ABC145D
import sys
input=sys.stdin.readline
MOD=10**9+7
factorial=[1]*(2*10**6+1)
for i in range(1,2*10**6+1):
factorial[i]=factorial[i-1]*i
factorial[i]%=MOD
def modinv(x):
return pow(x,MOD-2,MOD)
def comb(n,r):
return (factorial[n]*modinv(factorial[n-r])*modinv(factorial[r]))%MOD
def main():
X,Y=map(int,input().split())
a=(2*Y-X)
b=(2*X-Y)
A=a//3
B=b//3
ans=0
if a%3==0 and b%3==0 and a>=0 and b>=0:
ans=comb(A+B,A)
print(ans)
if __name__=="__main__":
main()
| n=int(input())
li = list(map(int,input().split()))
a=0
for i in range(n):
for j in range(n):
a += li[i]*li[j]
b=0
for i in range(n):
b+= li[i]*li[i]
print((a-b)//2)
| 0 | null | 158,615,138,531,990 | 281 | 292 |
n = int(input())
h = [[] for _ in range(n)]
u = [[] for _ in range(n)]
for i in range(n):
a = int(input())
for _ in range(a):
x, y = map(int, input().split())
if y == 1:
h[i].append(x)
elif y == 0:
u[i].append(x)
ans = 0
for i in range(2**n):
hs, us = set(), set()
honest, unkind = set(), set()
for j in range(n):
if i & (1 << j):
hs |= set(h[j])
us |= set(u[j])
honest.add(j+1)
else:
unkind.add(j+1)
if not hs <= honest:
continue
if not us <= unkind:
continue
ans = max(ans, len(honest))
print(ans) | #!/usr/bin/env python
# coding: utf-8
# In[15]:
N = int(input())
xy_list = []
for _ in range(N):
A = int(input())
xy = []
for _ in range(A):
xy.append(list(map(int, input().split())))
xy_list.append(xy)
# In[16]:
ans = 0
for i in range(2**N):
for j,a_list in enumerate(xy_list):
if (i>>j)&1 == 1:
for k,(x,y) in enumerate(a_list):
if (i>>(x-1))&1 != y:
break
else:
continue
break
else:
ans = max(ans, bin(i)[2:].count("1"))
print(ans)
# In[ ]:
| 1 | 121,373,820,411,470 | null | 262 | 262 |
"""AtCoder."""
n = int(input()[-1])
s = None
if n in (2, 4, 5, 7, 9):
s = 'hon'
elif n in (0, 1, 6, 8):
s = 'pon'
elif n in (3,):
s = 'bon'
print(s)
| a, b = map(int, input().split())
d = a/b
r = a%b
f = a/b
print("%d %d %.6f"%(d, r, f))
| 0 | null | 9,873,910,663,200 | 142 | 45 |
X=int(input())
MAX=2*int(X**(1/5))+1
MIN=-2*int(X**(1/5))-1
for A in range(MIN,MAX):
for B in range(MIN,MAX):
if A**5-B**5==X:
print(A,B)
exit() | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
????§???¢
????§???¢????????? a, b ??¨?????????????§? C ?????????
??????????§???¢?????¢??? S?????¨????????? L,
a ???????????¨????????¨???????????? h
????±???????????????°?????????????????????????????????
"""
import math
a, b, C = map(float,input().strip().split())
theta = math.radians(C) # ?????????????????¢??????
h = math.sin(theta) * b
S = a * h / 2
a1 = math.cos(theta) * b
a2 = a - a1
x = math.sqrt((h * h) + (a2 * a2))
L = a + b + x
print(S)
print(L)
print(h) | 0 | null | 12,845,181,510,112 | 156 | 30 |
import os, sys, re, math
(N, K) = [int(n) for n in input().split()]
H = [int(n) for n in input().split()]
H = sorted(H, reverse=True)[K:]
print(sum(H))
| #!/usr/bin/env python3
def main():
N, K = map(int, input().split())
H = sorted([int(x) for x in input().split()])
if K == 0:
print(sum(H))
elif N > K:
print(sum(H[:-K]))
else:
print(0)
if __name__ == '__main__':
main()
| 1 | 78,608,003,332,000 | null | 227 | 227 |
n=int(input())
a=False
for i in range(200):
for j in range(200):
if i**5-j**5==n:
print(i,j)
a=True
elif i**5+j**5==n:
print(i,-j)
a=True
if a:
break | N = int(input())
ans = 0
for a in range(1,N,1):
ans = ans + (N-1)//a
print(ans) | 0 | null | 14,076,165,481,060 | 156 | 73 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
def main():
n, k, *a = map(int, read().split())
def isOK(x):
kaisu = 0
for ae in a:
kaisu += ceil(ae / x) - 1
if kaisu <= k:
return True
else:
return False
ng = 0
ok = max(a)
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if isOK(mid):
ok = mid
else:
ng = mid
print(ok)
if __name__ == '__main__':
main()
| import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
start = 0
end = max(A)
ans = abs(end + start) // 2 + 1
while abs(start - end) > 1:
ans = abs(end + start) // 2
cnt = 0
for i in range(N):
cnt += math.floor(A[i]/ans - 0.0000000001)
if cnt > K: #ダメだったら
start = ans
break
else: #オッケーだったら
end = ans
continue
cnt = 0
for i in range(N):
cnt += math.floor((A[i] / ans) - 0.000000000001)
if cnt > K: # ダメだったら
print(ans + 1)
else: # オッケーだったら
print(ans)
| 1 | 6,519,412,269,052 | null | 99 | 99 |
S,T=map(str,input().split())
a,b=map(int,input().split())
U=input()
if U == S:
a +=-1
elif U == T:
b += -1
print(a,b) | S,T = (x for x in input().split())
A,B = map(int,input().split())
U = input()
if S == U:
A -= 1
else:
B -= 1
print(A,B) | 1 | 71,825,125,025,130 | null | 220 | 220 |
N,K=int(input()),int(input())
def f(n,k):
if k<1: return 1
if n<10:
if k<2: return n
return 0
d,m=n//10,n%10
return f(d,k-1)*m+f(d-1,k-1)*(9-m)+f(d,k)
print(f(N,K)) | n = int(input())
A = [[] for i in range(n)]
for i in range(n):
A[i] = list(map(int, input().split()))
f_inf = float("inf")
B = [[f_inf for i in range(2)] for j in range(n)]
B[0][1] = 0
for i in range(n):
B[i][0] = i+1
def dbs(a):
global order
l = len(A[a-1])-2
if l:
for i in range(l):
depth = B[a-1][1]+1
b = A[a-1][i+2]
if not b in order or depth < B[b-1][1]:
B[b-1][1] = depth
order.append(b)
dbs(b)
order = [1]
dbs(1)
for i in range(n):
if B[i][1] == f_inf:
B[i][1] = -1
print(" ".join(map(str, B[i])))
| 0 | null | 37,951,862,914,130 | 224 | 9 |
N = int(input())
S = [input() for _ in range(N)]
AC = 0
WA = 0
TLE = 0
RE = 0
for i in S:
if i == 'AC':
AC += 1
elif i == 'WA':
WA += 1
elif i == 'TLE':
TLE += 1
else:
RE += 1
print('AC x', AC)
print('WA x', WA)
print('TLE x', TLE)
print('RE x', RE) | N=int(input())
S=[input() for _ in range(N)]
a=0
w=0
t=0
r=0
for i in range(N):
if S[i] =="AC":
a+=1
elif S[i] =="WA":
w+=1
elif S[i] =="TLE":
t+=1
elif S[i] =="RE":
r+=1
print("AC x "+ str(a))
print("WA x "+ str(w))
print("TLE x "+ str(t))
print("RE x "+ str(r))
| 1 | 8,669,561,192,490 | null | 109 | 109 |
t = int(input())
if t >= 30:
print("Yes")
else:
print("No") | ans = input()
if int(ans) >= 30:
print("Yes")
else:
print("No") | 1 | 5,806,200,013,760 | null | 95 | 95 |
c = 0
while True:
a,b = map(int, input().split()); c+=1
if a < b:
print(a,b)
elif a >b:
print(b,a)
elif a ==b and a !=0 and b!=0:
print(a,b)
elif a ==0 and b == 0: break
| import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan, degrees, radians
sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7
def lcm(x,y):
return x*y//gcd(x,y)
def lgcd(l):
return reduce(gcd,l)
def llcm(l):
return reduce(lcm,l)
def powmod(n,i,mod):
return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
return x.bit_length()
def div10(x):
return len(str(x))-(x==0)
def perm(n,mod=None):
ans = 1
for i in range(1,n+1):
ans *= i
if mod!=None:
ans %= mod
return ans
def intput():
return int(input())
def mint():
return map(int,input().split())
def lint():
return list(map(int,input().split()))
def ilint():
return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
print(l[0] if x else l[1])
def lprint(l, sep='\n'):
for x in l:
print(x, end=sep)
def ston(c, c0='a'):
return ord(c)-ord(c0)
def ntos(x, c0='a'):
return chr(x+ord(c0))
class counter(dict):
def __init__(self, *args):
super().__init__(args)
def add(self,x,d=1):
self.setdefault(x,0)
self[x] += d
class comb():
def __init__(self, n, mod=None):
self.l = [1]
self.n = n
self.mod = mod
def get(self,k):
l,n,mod = self.l, self.n, self.mod
k = n-k if k>n//2 else k
while len(l)<=k:
i = len(l)
l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
return l[k]
H,W=mint()
s=[input() for _ in range(H)]
dp=[[0]*W for _ in range(H)]
dp[0][0]=int(s[0][0]=='#')
for i in range(H):
for j in range(W):
if i==j==0:
continue
tmp = INF
if i>0:
tmp = min(tmp,dp[i-1][j]+int(s[i-1][j]=='.' and s[i][j]=='#'))
if j>0:
tmp = min(tmp,dp[i][j-1]+int(s[i][j-1]=='.' and s[i][j]=='#'))
dp[i][j] = tmp
print(dp[H-1][W-1]) | 0 | null | 24,714,961,981,612 | 43 | 194 |
#!/usr/bin/env python3
print(len({*open(0).read().split()}) - 1)
| n = int(input())
lst = []
for i in range(n):
tmp = input().split()
lst.append(tmp)
d = {}
for i in range(n):
if lst[i][0] == 'insert':
d[lst[i][1]] = d.get(lst[i][1], 0) + 1
elif lst[i][0] == 'find':
print('yes') if lst[i][1] in d else print('no')
| 0 | null | 15,082,701,742,730 | 165 | 23 |
s = list(input())
n = len(s)-1
count = 0
if s != s[::-1]:
for i in range(0,(n+1)//2):
if s[i] != s[n-i]:
count += 1
print(count) | s = input()
k = 0
for i in range(len(s) // 2):
if s[i] == s[len(s) - i -1]:
next
else:
k += 1
print(k) | 1 | 120,408,088,464,202 | null | 261 | 261 |
def main():
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
if A[i] % 2 == 0 and (A[i] % 3 != 0 and A[i] % 5 != 0):
return "DENIED"
return "APPROVED"
if __name__ == '__main__':
print(main())
| x = int(input())
print("ACL" * x) | 0 | null | 35,530,925,444,900 | 217 | 69 |
import sys
import math
input=sys.stdin.buffer.readline
h,w=map(int,input().split())
ans=math.ceil(h*w/2)
print(1 if min(h,w)==1 else ans) | def gcd(a, b):
a, b = max(a, b), min(a, b)
if b == 0:
return a
return gcd(b, a % b)
def main():
X = int(input())
ans = 360 // gcd(X, 360)
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 31,902,218,007,648 | 196 | 125 |
n = int(raw_input())
while n > 0:
d = map(int, raw_input().split())
d.sort()
a = d[0]
b = d[1]
c = d[2]
if (c*c) == (a*a + b*b):
print "YES"
else:
print "NO"
n = n-1 |
def check(a, b, c):
a2 = a ** 2
b2 = b ** 2
c2 = c ** 2
if (a2 + b2) == c2:
return True
else:
return False
n = int(input())
for c in range(n):
line = input()
datas = map(int, line.split())
li = list(datas)
a = li[0]
b = li[1]
c = li[2]
if check(a, b, c) or check(b, c, a) or check(c, a, b):
print("YES")
else:
print("NO") | 1 | 264,800,358 | null | 4 | 4 |
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()
def main():
n, k = map(int, input().split())
p = tuple(map(int, input().split()))
c = tuple(map(int, input().split()))
ans = -10**18
for i in range(n):
start, count = i, 1
val = c[start]
while p[start]-1 != i:
start = p[start]-1
count += 1
val += c[start]
start = i
if val > 0:
a = (k//count-1)*val
ans = max(a, ans)
num = count + k % count
else:
a = 0
num = min(k, count)
for _ in range(num):
a += c[start]
start = p[start] - 1
ans = max(a, ans)
print(ans)
if __name__ == '__main__':
main() | N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
C = list(map(int, input().split()))
res = -10**10
for i in range(N):
j = i
total = 0
loop_values = []
while True:
j = P[j] - 1
loop_values.append(C[j])
total += C[j]
if j == i:
break
loop_length = len(loop_values)
point_sum = 0
for j in range(loop_length):
point_sum += loop_values[j]
result_cand = point_sum
if j+1 > K:
break
if total > 0:
loop_num = (K - j - 1) // loop_length
result_cand += total * loop_num
if res < result_cand:
res = result_cand
print(res) | 1 | 5,399,248,771,360 | null | 93 | 93 |
K = int(input())
num = 0
for i in range(0,K+1):
num = (num*10+7)%K
if num==0:
print(i+1,'\n')
break
if num:
print("-1\n") | k=int(input())
a=0
cnt=-1
for i in range(1,k+1):
a=(10*a+7)%k
if a==0:
cnt=i
break
print(cnt) | 1 | 6,095,364,259,840 | null | 97 | 97 |
n=int(input())
a= list(map(int, input().split()))
kt=1
a.sort()
for i in range (0,n-1):
if a[i]==a[i+1]:
kt=0
break
if kt==1:
print("YES")
else:
print("NO") | import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
# b,r = map(str, readline().split())
# A,B = map(int, readline().split())
N = I()
A = LI()
def main():
judge=False
if len(set(A))==N:
judge=True
if judge:
return 'YES'
else:
return 'NO'
print(main())
| 1 | 74,061,921,036,960 | null | 222 | 222 |
#
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
N,K = MI()
A=LI_()
ans = 0
before = defaultdict(int)
*cumsum,=accumulate(A)
for i,a in enumerate(cumsum):
cumsum[i] = a%K
# print(cumsum)
for i,a in enumerate(cumsum):
if i >= K:
before[cumsum[i-K]]-=1
ans += before[a]
before[a]+=1
ans += cumsum[:K-1].count(0)
print(ans)
if __name__ == '__main__':
main() | N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
ans = 1
dp = [0]*3
for a in A:
cnt = 0
for i in range(3):
if a == dp[i]:
cnt += 1
for i in range(3):
if a == dp[i]:
dp[i] += 1
break
ans = ans*cnt % MOD
print(ans)
| 0 | null | 133,879,463,762,800 | 273 | 268 |
import sys
a=[map(int,i.split())for i in sys.stdin]
for i,j in a:
c,d=i,j
while d:
if c > d:c,d = d,c
d%=c
print(c,i//c*j) | from time import time
import random
start = time()
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
def cal_score(t):
S = 0
last = [-1] * 26
score = 0
for d in range(D):
S += s[d][t[d]]
last[t[d]] = d
for i in range(26):
S -= c[i] * (d - last[i])
score += max(10 ** 6 + S, 0)
return score
def main():
t = [random.randint(0, 25) for _ in range(D)]
score = cal_score(t)
while time()-start + 0.2 < 2:
d = random.randint(0, D-1)
q = random.randint(0, 25)
old = t[d]
t[d] = q
new_score = cal_score(t)
if new_score < score:
t[d] = old
else:
score = new_score
return t
if __name__ == "__main__":
ans = main()
for t in ans:
print(t+1) | 0 | null | 4,838,218,522,050 | 5 | 113 |
R,G,B=map(int,input().split())
K=int(input())
M=0
while R>=G or G>=B:
if R>=G:
G*=2
M+=1
if G>=B:
B*=2
M+=1
if M<=K:
print('Yes')
else:
print('No')
| import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7
import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def main():
n,M = i_map()
a = i_list()
cd = []
new_a = []
for i in a:
cd.append(i//2)
new_a.append((i//2))
def pow2(x):
ret = 0
while x%2 == 0:
ret += 1
x//=2
return ret
P = []
for a in new_a:
P.append(pow2(a))
if len(set(P)) != 1:
print(0)
else:
m = 1
for a in new_a:
m = (m*a)//gcd(m,a)
print(-(-(M//m)//2))
if __name__=="__main__":
main()
| 0 | null | 54,493,230,805,662 | 101 | 247 |
def main():
n = int(input())
a = set(map(int, input().split(" ")))
print("YES" if len(a) == n else "NO")
main() | def resolve():
n = int(input())
a = tuple(map(int,input().split()))
print('YES' if len(a)==len(set(a)) else 'NO')
resolve() | 1 | 73,669,264,312,660 | null | 222 | 222 |
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353
def ddprint(x):
if DBG:
print(x)
s = ins()
t = ins()
ls = len(s)
lt = len(t)
mn = BIG
for i in range(ls-lt+1):
x = 0
for j in range(lt):
if s[i+j]!=t[j]:
x += 1
mn = min(mn,x)
print(mn)
| L=[]
R=[]
N,K,C=map(int,input().split())
S=list(input())
s=S[::-1]
i=0
while len(L)<K:
if S[i]=='o':
L.append(i+1)
if i+C<N:
for j in range(1,C+1):
S[i+j]='x'
i+=1
k=0
while len(R)<K:
if s[k]=='o':
R.append(N-k)
if k+C<N:
for l in range(1,C+1):
s[k+l]='x'
k+=1
R=R[::-1]
ans=[]
for i in range(K):
if L[i]==R[i]:
ans.append(L[i])
print(*ans) | 0 | null | 22,278,764,670,400 | 82 | 182 |
from collections import Counter
n = int(input())
verdicts = Counter([input() for i in range(n)])
for verdict in ["AC", "WA", "TLE", "RE"]:
print(f"{verdict} x {verdicts[verdict]}") | n=int(input())
ans=[]
for i in range(n):
ans.append(input())
def func(ans,moji):
num=ans.count(moji)
print(moji,"x",str(num))
mojis=["AC","WA","TLE","RE"]
for moji in mojis:
func(ans,moji) | 1 | 8,668,028,675,936 | null | 109 | 109 |
# import math
N = int(input())
# Nが奇数の場合は-2していくと全て奇数になるので答えは0
# Nが偶数の場合を検討するべし
# Nが偶数の場合、明らかに2の倍数より5の倍数の方が少ないので5の倍数がいくつかで考える
if (N % 2 == 1):
print(0)
exit()
bunbo = 0
sum_5 = 0
while (10 * 5 ** bunbo) <= N:
sum_5 += N // (10 * 5**bunbo)
bunbo += 1
print(sum_5)
| while True:
h, w = map(int, input().split())
if w+h == 0:
break
line = "#"*w
for y in range(h):
print(line)
print()
| 0 | null | 58,421,963,651,132 | 258 | 49 |
n=int(input())
sum=0
for i in range(n+1):
if i%3==0 or i%5==0:
sum+=0
else:
sum+=i
print(sum) | ans=0
N=int(input())
for x in range(1,N+1):
if x%3==0 or x%5==0:
pass
else:
ans += x
print(ans) | 1 | 34,824,760,831,652 | null | 173 | 173 |
input_num = int(input())
input_str = input()
if len(input_str) <= input_num:
print(input_str)
else:
print(input_str[:input_num]+"...") | class Dice:
def __init__(self,faces):
self.faces = tuple(faces)
def N(self):
self.faces = (self.faces[1], self.faces[5], self.faces[2],
self.faces[3], self.faces[0], self.faces[4])
def S(self):
self.faces = (self.faces[4], self.faces[0], self.faces[2],
self.faces[3], self.faces[5], self.faces[1])
def W(self):
self.faces = (self.faces[2], self.faces[1], self.faces[5],
self.faces[0], self.faces[4], self.faces[3])
def E(self):
self.faces = (self.faces[3], self.faces[1], self.faces[0],
self.faces[5], self.faces[4], self.faces[2])
def number(self, face_id):
return self.faces[face_id - 1]
dice = Dice(list(map(int, input().split())))
x=input()
for i in x:
if i == "N":
dice.N()
elif i == "S":
dice.S()
elif i == "W":
dice.W()
elif i == "E":
dice.E()
print(dice.number(1)) | 0 | null | 10,006,487,577,284 | 143 | 33 |
class UnionFind:
def __init__(self, n):
self.n = [-1]*n
self.r = [0]*n
self.co = n
def find(self, x):
if self.n[x] < 0:
return x
else:
self.n[x] = self.find(self.n[x])
return self.n[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
elif self.r[x] > self.r[y]:
self.n[x] += self.n[y]
self.n[y] = x
else:
self.n[y] += self.n[x]
self.n[x] = y
if self.r[x] == self.r[y]:
self.r[y] += 1
self.co -= 1
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.n[self.find(x)]
def set_count(self):
return self.co
n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
a, b = map(int, input().split())
uf.unite(a-1, b-1)
print(uf.set_count()-1)
| K = int(input())
S = str(input())
s_l = len(S)
s_k = list(S)
answer = s_k[slice(0, K)]
result = ''.join(answer)
if s_l <= K:
print(S)
else:
print(result + '...') | 0 | null | 10,881,282,554,490 | 70 | 143 |
MOD = 10 ** 9 + 7
N = int(input())
Sall = pow(10, N, MOD)
S0 = S9 = pow(9, N, MOD)
S09 = pow(8, N, MOD)
ans = (Sall - (S0 + S9 - S09)) % MOD
print(ans) | N=int(input())
MOD=10**9+7
in_9=10**N-9**N
in_0=10**N-9**N
nine_and_zero=10**N-8**N
ans=int(int(in_0+in_9-nine_and_zero)%MOD)
print(ans) | 1 | 3,165,064,291,588 | null | 78 | 78 |
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())
graph = {"r":P,"s":R,"p":S,"*":0}
for i,t in enumerate(T):
if len(T)-i-K > 0:
if t == T[i+K]:
T[i+K] = "*"
ans = 0
for t in T:
ans += graph[t]
print(ans) | N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
cnt=[0 for _ in range(N)]
score={'r':P,'s':R,'p':S}
for i in range(N):
if i<K:
cnt[i]=score[T[i]]
else:
if T[i-K]!=T[i]:
cnt[i]=score[T[i]]
else:
if cnt[i-K]==0:
cnt[i]=score[T[i]]
print(sum(cnt))
| 1 | 106,867,509,701,220 | null | 251 | 251 |
n = int(input())
c = input()
count = 0
i, j = 0, n - 1
if c.count('W') == 0:
count=0
elif c.count('R') == 0:
count = 0
else:
white_cnt = []
red_cnt = []
for i in range(n):
if c[i] == 'W':
white_cnt.append(i)
else:
red_cnt.append(i)
while 1:
white_num = white_cnt.pop(0)
red_num = red_cnt.pop()
if white_num < red_num:
count += 1
if len(white_cnt) == 0:
break
if len(red_cnt) == 0:
break
print(count)
| import bisect
n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
ng=-1
ok=A[-1]*2+1
B=[[0]*n for k in range(2)]
ii=0
while ok-ng>1:
mid=(ok+ng)//2
d=0
for i in range(n):
c=n-bisect.bisect_right(A,mid-A[i],lo=0,hi=len(A))
B[ii][i]=c
d=d+c
if d<m:
ok=mid
ii=(ii+1)%2
else:
ng=mid
D=[0]
for i in range(n):
D.append(D[-1]+A[n-i-1])
ans=0
for i in range(n):
x=B[(ii+1)%2][i]
ans=ans+A[i]*x+D[x]
ans=ans+(m-sum(B[(ii+1)%2]))*ok
print(ans) | 0 | null | 57,137,719,335,972 | 98 | 252 |
x=int(input())
for i in range(-200,200):
for j in range(-200,200):
if i**5-j**5==x:
print("{} {}".format(i,j))
exit() | a, b = map(int, input().split())
if (a >= 1 and a <= 1000000000) and (b >= 1 and b <= 1000000000):
d = int(a / b)
r = int(a % b)
f = float(a / b)
print("{0:d} {1:d} {2:f}".format(d, r, f))
else:
pass | 0 | null | 13,072,609,497,638 | 156 | 45 |
def main():
import sys
input = sys.stdin.readline
N = int(input())
arms = []
for i in range(N):
x, l = map(int,input().split())
t = min(x+l,10**9)
s = max(x-l,0)
arms.append((t,s))
arms.sort()
ans = 0
tmp = -1
for t,s in arms:
if s >= tmp:
tmp = t
ans += 1
print(ans)
main() | def resolve():
n = int(input())
p = tuple(map(int,input().split()))
min_p = p[0]
cnt = 1
for i in range(1,n):
if min_p > p[i]:
min_p = p[i]
cnt += 1
print(cnt)
resolve() | 0 | null | 87,736,068,527,670 | 237 | 233 |
ac = 0
wa = 0
tle = 0
re = 0
n = int(input())
for i in range(n):
testcase = input()
if testcase == 'AC':
ac += 1
elif testcase == 'WA':
wa += 1
elif testcase == 'TLE':
tle += 1
elif testcase == 'RE':
re += 1
print('AC x', ac)
print('WA x', wa)
print('TLE x', tle)
print('RE x', re) | n=int(input())
li=[input() for i in range(n)]
ans=[0,0,0,0]
for i in range(n):
if li[i]=="AC":
ans[0]+=1
elif li[i]=="WA":
ans[1]+=1
elif li[i]=="TLE":
ans[2]+=1
elif li[i]=="RE":
ans[3]+=1
print("AC x " + str(ans[0]))
print("WA x "+ str(ans[1]))
print("TLE x "+str(ans[2]))
print("RE x "+str(ans[3])) | 1 | 8,727,864,744,830 | null | 109 | 109 |
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)
class Uf:
def __init__(self, N):
self.p = list(range(N))
self.rank = [0] * N
self.size = [1] * N
def root(self, x):
if self.p[x] != x:
self.p[x] = self.root(self.p[x])
return self.p[x]
def same(self, x, y):
return self.root(x) == self.root(y)
def unite(self, x, y):
u = self.root(x)
v = self.root(y)
if u == v: return
if self.rank[u] < self.rank[v]:
self.p[u] = v
self.size[v] += self.size[u]
self.size[u] = 0
else:
self.p[v] = u
self.size[u] += self.size[v]
self.size[v] = 0
if self.rank[u] == self.rank[v]:
self.rank[u] += 1
def count(self, x):
return self.size[self.root(x)]
n, m, k = map(int, input().split())
friends = [[] for _ in range(n)]
block = [[] for _ in range(n)]
uf = Uf(n)
F = [list(map(int, input().split())) for _ in range(m)]
B = [list(map(int, input().split())) for _ in range(k)]
for e in F:
friends[e[0] - 1].append(e[1] - 1)
friends[e[1] - 1].append(e[0] - 1)
uf.unite(e[0]-1, e[1]-1)
for e in B:
block[e[0] - 1].append(e[1] - 1)
block[e[1] - 1].append(e[0] - 1)
ans = [0]*n
for i in range(n):
ans[i] = uf.size[uf.root(i)] - 1
for f in friends[i]:
if uf.same(i, f):
ans[i] -= 1
for b in block[i]:
if uf.same(i, b):
ans[i] -= 1
print(*ans)
| N = input()
L = len(N)
# dp[i][j]: 紙幣の最小枚数
# i: 決定した桁数
# j: 1枚多めに渡すフラグ
dp = [[float("inf")] * 2 for _ in range(L + 1)]
# 初期条件
dp[0][0] = 0
dp[0][1] = 1
# 貰うDP
for i in range(L):
n = int(N[i])
dp[i + 1][0] = min(dp[i][0] + n, dp[i][1] + (10 - n))
dp[i + 1][1] = min(dp[i][0] + (n + 1), dp[i][1] + (10 - (n + 1)))
print(dp[L][0]) | 0 | null | 66,588,128,190,180 | 209 | 219 |
a, b = map(int, raw_input().split())
print("%d %d %f" %(int(a / b), a % b, float(a) / b)) | a, b = map(int, input().split())
print(a // b, a % b, round(a / b, 6)) | 1 | 583,397,144,000 | null | 45 | 45 |
#!/usr/bin/env python3
class UnionFind():
def __init__(self, n):
self.parents = list(range(n))
self.size = [1] * n
def find(self, x):
if self.parents[x] == x:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x != y:
if self.size[x] < self.size[y]:
x, y = y,x
self.parents[y] = x
self.size[x] += self.size[y]
def main():
N, M, K = map(int, input().split())
friend_adj = [[] for _ in range(N)]
block_adj = [[] for _ in range(N)]
uf = UnionFind(N)
for _ in range(M):
a, b = map(lambda x: int(x)-1, input().split())
friend_adj[a].append(b)
friend_adj[b].append(a)
uf.union(a,b)
for _ in range(K):
c, d = map(lambda x: int(x)-1, input().split())
if uf.find(c) == uf.find(d):
friend_adj[c].append(d)
friend_adj[d].append(c)
ans = [uf.size[uf.find(i)]-1 for i in range(N)]
for i in range(N):
ans[i] -= len(friend_adj[i])
# for b in block_adj[i]:
# if uf.find(b) == uf.find(i):
# ans[i] -= 1
print(*ans)
if __name__ == "__main__":
main()
| import time
from collections import deque
N, M, K = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
F = [set() for _ in range(N)]
B = [set() for _ in range(N)]
for i, j in AB:
F[i - 1].add(j - 1)
F[j - 1].add(i - 1)
for i, j in CD:
B[i - 1].add(j - 1)
B[j - 1].add(i - 1)
Q = deque()
S = [0] * N
d = [0] * N
for i in range(N):
if d[i] != 0:
continue
L = {i}
d[i] = 1
Q.append(i)
while len(Q) > 0:
q = Q.pop()
for j in F[q]:
if d[j] == 0:
d[j] = 1
Q.append(j)
L.add(j)
for k in L:
S[k] = len(L) - len(L & F[k]) - len(L & B[k]) - 1
print(*S)
| 1 | 61,885,821,550,162 | null | 209 | 209 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
def inp():
return int(input())
def inps():
return input().rstrip()
def inpl():
return list(map(int, input().split()))
def _debug(obj):
print(obj, file=sys.stderr)
# import decimal
# from decimal import Decimal
# decimal.getcontext().prec = 10
# from heapq import heappush, heappop, heapify
# import math
# from math import gcd
# import itertools as it
# import collections
# from collections import deque
# ---------------------------------------
mod = 10**9 +7
N, K = inpl()
ans = 0
for i in range(K, N + 2):
ans += (N + 1 - i) * i + 1
ans %= mod
print(ans) | import math
import sys
input = sys.stdin.readline
def main():
a, b, x = map(int, input().split())
x /= a
h = x / a
if h < b/2:
t = 2 * x / b
ans = math.degrees(math.atan(b/t))
else:
ans = math.degrees(math.atan(2*(b-h)/a))
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 98,335,656,389,632 | 170 | 289 |
def abc164_d():
# 解説放送
s = str(input())
n = len(s)
m = 2019
srev = s[::-1] # 下の位から先に見ていくために反転する
x = 1 # 10^i ??
total = 0 # 累積和 (mod 2019 における累積和)
cnt = [0] * m # cnt[k] : 累積和がkのものが何個あるか
ans = 0
for i in range(n):
cnt[total] += 1
total += int(srev[i]) * x
total %= m
ans += cnt[total]
x = x*10 % m
print(ans)
abc164_d() | import bisect
N = int(input())
A = [int(x) for x in input().split()]
A=sorted(A)
index = 0
for i in range(1, N+1):
now = bisect.bisect_right(A, i)
print(now - index)
index = now
| 0 | null | 31,635,065,374,432 | 166 | 169 |
import random
def down_score(d, c, last_d, score):
sum = 0
for i in range(26):
sum += c[i]*(d-last_d[i])
return (score - sum)
def main():
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
#print(c)
#print(s)
last_d = [0 for i in range(26)]
ans = []
score = 0
for i in range(D):
max = 0
idx = 0
for j in range(26):
if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0:
max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2
idx = j
elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] > c[idx]:
idx = j
last_d[idx] = i+1
score += s[i][j]
down_score(i+1,c,last_d,score)
ans.append(idx)
for i in range(D):
print(ans[i]+1)
if __name__ == "__main__":
main() | #158_D
s = input()
q = int(input())
from collections import deque
s = deque(s)
rev = 1
for _ in range(q):
Q = list(input().split())
if Q[0] == "1":
rev *= -1
elif Q[0] == "2":
if (Q[1]=="1" and rev==1) or (Q[1]=="2" and rev==-1):
s.appendleft(Q[2])
elif (Q[1]=="2" and rev==1) or (Q[1]=="1" and rev==-1):
s.append(Q[2])
s = "".join(s)
if rev == -1:
s = s[::-1]
print(s) | 0 | null | 33,446,907,142,832 | 113 | 204 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.