code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
178,025B
⌀ | question_pair_id
float64 27.1M
177,113B
⌀ | code1_group
int64 1
297
| code2_group
int64 1
297
|
---|---|---|---|---|---|---|
n = int(input())
A = [int(i) for i in input().split()]
product = 1
A.sort()
for i in range(n):
product *= A[i]
if(product > 10**18):
print("-1")
break
if(product <= 10**18):
print(product)
|
n = int(input())
mod = 7+10**9
a = 10**n % mod
b = 9**n % mod
c = 8**n % mod
print((a - 2*b + c)%mod)
| 0 | null | 9,669,585,603,808 | 134 | 78 |
from collections import Counter
N, M, K = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
friend_g = [set() for i in range(N)]
for a, b in AB:
a, b = a-1, b-1
friend_g[a].add(b)
friend_g[b].add(a)
friend_count = [len(s) for s in friend_g]
g_nums = [-1]*N
current_g_num = 0
for i in range(N):
if g_nums[i] == -1:
g_nums[i] = current_g_num
q = [i]
while q:
t = q.pop()
for friend in friend_g[t]:
if g_nums[friend] == -1:
g_nums[friend] = current_g_num
q.append(friend)
# print(i, t, g_nums)
current_g_num += 1
block_count = [0]*N
for c, d in CD:
c, d = c-1, d-1
if g_nums[c] == g_nums[d]:
block_count[c] += 1
block_count[d] += 1
g_nums_counter = Counter(g_nums)
print(*(g_nums_counter[g_nums[i]] - friend_count[i] - block_count[i] - 1 for i in range(N)))
|
N = int(input())
A = [int(x) for x in input().split()]
cnt = dict()
for i in range(N):
cnt[A[i]] = cnt.get(A[i], 0) + 1
if max(cnt.values()) > 1:
print('NO')
else:
print('YES')
| 0 | null | 67,730,061,307,402 | 209 | 222 |
s = int(input())
print('%d:%d:%d' % (s / 3600, (s % 3600) / 60, s % 60))
|
t = input()
h = t / 3600
t %= 3600
m = t / 60
s = t % 60
print str(h) + ":" + str(m) + ":" + str(s)
| 1 | 338,596,648,248 | null | 37 | 37 |
n=input()
ans=0
if n=="0":
print("Yes")
else:
for i in n:
ans+=int(i)
if ans%9==0:
print("Yes")
else:
print("No")
|
n = input()
res = 0
for i in range(len(n)):
res += int(n[i])
print("Yes" if res%9 == 0 else "No")
| 1 | 4,390,057,871,208 | null | 87 | 87 |
n=input()
print(n[0:3])
|
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 13 21:27:14 2020
@author: NEC-PCuser
"""
print(input()[0:3])
| 1 | 14,813,852,639,108 | null | 130 | 130 |
n, m, l = map(int, raw_input().split(" "))
a = [[0 for i in range(m)] for j in range(n)]
b = [[0 for k in range(l)] for i in range(m)]
for j in range(n):
a[j] = map(int, raw_input().split(" "))
for i in range(m):
b[i] = map(int, raw_input().split(" "))
c = [[0 for k in range(l)] for j in range(n)]
for j in range(n):
for k in range(l):
for i in range(m):
c[j][k] += a[j][i] * b[i][k]
for j in range(n):
print " ".join(map(str, (c[j])))
|
N, M, K = map(int,input().split())
MOD = 998244353
fac = [1 for i in range(N+1)]
for n in range(1,N+1):
fac[n] = (n*fac[n-1])%MOD
fac_inv = [1 for i in range(n+1)]
fac_inv[N] = pow(fac[N],MOD-2,MOD)
for n in range(N-1,-1,-1):
fac_inv[n] = (fac_inv[n+1]*(n+1))%MOD
def C(n,k):
global MOD
return (fac[n]*fac_inv[k]*fac_inv[n-k])%MOD
print(sum([C(N-1,b)*M*pow(M-1,N-1-b,MOD)%MOD for b in range(K+1)])%MOD)
| 0 | null | 12,330,178,935,620 | 60 | 151 |
import math
def isprime(n):
if n==1:
return False
elif n==2:
return True
k=int(math.sqrt(n))+1
for i in range(2,k+1):
if n%i==0:
return False
return True
N=int(input())
ans=0
for i in range(N):
if isprime(int(input())):
ans+=1
print(ans)
|
def is_prime(x):
if x == 1:
return 0
l = x ** 0.5
n = 2
while n <= l:
if x % n == 0:
return 0
n += 1
return 1
import sys
def solve():
N = int(input())
cnt = 0
for i in range(N):
cnt += is_prime(int(input()))
print(cnt)
solve()
| 1 | 10,853,965,892 | null | 12 | 12 |
n=int(input())
a,b=[],[]
for i in range(n):
A,B=map(int,input().split())
a.append(A)
b.append(B)
a.sort()
b.sort(reverse=True)
ans=0
if n%2==1:
s=a[n//2]
g=b[n//2]
ans=g-s+1
else:
s1,s2=a[n//2-1],a[n//2]
g2,g1=b[n//2-1],b[n//2]
ans=(g2+g1)-(s2+s1)+1
print(ans)
|
N=int(input())
A,B=[],[]
for i in range(N):
a,b=map(int,input().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
I=~-N//2
print(B[I]-A[I]+1 + (B[I+1]-A[I+1] if N%2==0 else 0))
| 1 | 17,258,198,332,284 | null | 137 | 137 |
import sys
from scipy.sparse.csgraph import floyd_warshall
N, M, L = map(int, input().split())
INF = 10 **9 +1
G = [[float('inf')] * N for i in range(N)]
for i in range(M):
a, b, c = map(int, input().split())
a, b, = a - 1, b -1
G[a][b] = c
G[b][a] = c
#全点間最短距離を計算
G = floyd_warshall(G)
#コストL以下で移動可能な頂点間のコスト1の辺を張る
E = [[float('inf')] * N for i in range(N)]
for i in range(N):
for j in range(N):
if G[i][j] <= L:
E[i][j] = 1
#全点間最短距離を計算
E = floyd_warshall(E)
#クエリに答えていく
Q = int(input())
for i in range(Q):
s, t = map(int, input().split())
s, t = s - 1, t-1
print(int(E[s][t] - 1) if E[s][t] != float('inf') else -1)
|
import sys
input = sys.stdin.readline
N, m, l = map(int, input().split())
graph = [[] for i in range(N+1)]
INF = 2 ** 31 - 1
d = [[INF for i in range(N+1)] for j in range(N+1)]
for i in range(N+1):
d[i][i] = 0
for i in range(m):
a, b, c = map(int, input().split())
d[a][b] = c
d[b][a] = c
for k in range(N+1):
for i in range(N+1):
for j in range(N+1):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
d2 = [[INF for i in range(N+1)] for j in range(N+1)]
for i in range(N+1):
d[i][i] = 0
for i in range(N+1):
for j in range(N+1):
if d[i][j] <= l:
d2[i][j] = 1
for k in range(N+1):
for i in range(N+1):
for j in range(N+1):
d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j])
q = int(input())
for i in range(q):
s, t = map(int, input().split())
if d2[s][t] == INF:
print(-1)
else:
print(d2[s][t] - 1)
| 1 | 173,717,801,875,352 | null | 295 | 295 |
A,B,N=map(int,input().split())
def func(t):
return int(t)
#NはBより大きいかもしれないし小さいかもしれない
#B-1が最高だが、NがB-1より小さいとどうしようもない
x=min(B-1,N)
print(func(A*x/B)-A*func(x/B))
|
a,b,n = map(int,input().split())
if b <= n:
k = b-1
else:
k = n
m = int(k*a/b) - a*int(k/b)
print(m)
| 1 | 28,117,940,064,060 | null | 161 | 161 |
class Stack():
def __init__(self):
self.stack = [0 for _ in range(1000)]
self.top = 0
def push(self, n):
self.top += 1
self.stack[self.top] = n
def pop(self):
a = self.stack[self.top]
del self.stack[self.top]
self.top -= 1
return a
def lol(self):
return self.stack[self.top]
def main():
input_data = raw_input()
data = input_data.strip().split(" ")
st = Stack()
for l in data:
if l == "+":
a = st.pop()
b = st.pop()
st.push(a + b)
elif l == "-":
a = st.pop()
b = st.pop()
st.push(b - a)
elif l == "*":
a = st.pop()
b = st.pop()
st.push(a * b)
else:
st.push(int(l))
print st.lol()
if __name__ == '__main__':
main()
|
ops = [op for op in input().split(" ")]
stack = []
for op in ops:
if op == "+":
stack = stack[:-2]+[stack[-2]+stack[-1]]
elif op == "-":
stack = stack[:-2]+[stack[-2]-stack[-1]]
elif op == "*":
stack = stack[:-2]+[stack[-2]*stack[-1]]
else:
stack.append(int(op))
print(stack[0])
| 1 | 37,785,056,678 | null | 18 | 18 |
from collections import deque
N, M = [int(x) for x in input().split()]
conn = [[] for _ in range(N + 1)]
for i in range(M):
A, B = [int(x) for x in input().split()]
conn[A].append(B)
conn[B].append(A)
q = deque([1])
signpost = [0] * (N + 1)
while q:
v = q.popleft()
for w in conn[v]:
if signpost[w] == 0:
signpost[w] = v
q.append(w)
print('Yes')
for i in range(2, N + 1):
print(signpost[i])
|
from collections import deque
import sys
N, M = list(map(int, input().split()))
ans = [-1] * N
visited = [False] * N
dq = deque([0])
path = [[] for _ in range(N)]
for s in sys.stdin.readlines():
a, b = list(map(lambda x: int(x)-1, s.split()))
path[a].append(b)
path[b].append(a)
while dq:
i = dq.popleft()
if visited[i]:
continue
visited[i] = True
next_rs = path[i]
for j in range(len(next_rs)):
if not visited[next_rs[j]]:
dq.append(next_rs[j])
if ans[next_rs[j]] == -1:
ans[next_rs[j]] = i
if sum(visited) == N:
print('Yes')
for i in range(N):
if i == 0:
continue
else:
print(ans[i]+1)
else:
print(-1)
| 1 | 20,654,997,261,402 | null | 145 | 145 |
from collections import deque
n = int(input())
g = [[] for _ in range(n)]
ab = []
for _ in range(n-1):
a, b = map(int, input().split())
a, b = a - 1, b - 1
g[a].append(b)
g[b].append(a)
ab.append((a, b))
q = deque([0])
chk = [False] * n
chk[0] = True
res = [0] * n
par = [0] * n
while q:
x = q.popleft()
cnt = 1
for y in g[x]:
if chk[y]:
continue
if res[x] == cnt:
cnt += 1
res[y], par[y], chk[y] = cnt, x, True
cnt += 1
q.append(y)
ans = []
for a, b in ab:
if par[a] == b:
ans.append(res[a])
else:
ans.append(res[b])
print(max(ans), *ans, sep="\n")
|
N = int(input())
ad = {}
status = {}
edge=[]
for n in range(N):
ad[n+1]=set([])
status[n+1] = -1
for n in range(N-1):
a,b = list(map(int,input().split()))
edge.append((a,b))
ad[a].add(b)
ad[b].add(a)
color = set([])
parent = [0] * (N+1)
ans={}
#BFS
from collections import deque
start = 1
status[start] = 0
que = deque([start])
while len(que) > 0:
start = que[0]
# print(start,parent[start])
c = 1
for v in ad[start]:
if status[v] == -1:
que.append(v)
status[v]=0
if parent[start] == c:
c += 1
parent[v] = c
color.add(c)
s = min(start,v)
e = max(start,v)
ans[s,e]=c
c+=1
# print(parent,que)
que.popleft()
print(len(color))
for e in edge:
print(ans[e])
| 1 | 136,145,454,783,478 | null | 272 | 272 |
# 解説を参考に作成
def solve():
N, M = map(int, input().split())
m = 0
# 奇数の飛び
oddN = M
oddN += (oddN + 1) % 2
for i in range(oddN // 2):
print(i + 1, oddN - i)
m += 1
if m == M:
return
# 偶数の飛び
for i in range(M):
print(oddN + i + 1, M * 2 + 1 - i)
m += 1
if m == M:
return
if __name__ == '__main__':
solve()
|
import math
a = int(input())
print(math.ceil(a/2))
| 0 | null | 43,999,734,093,308 | 162 | 206 |
A, B, C = [int(x) for x in input().split()]
if len({A, B, C}) == 2:
print('Yes')
else:
print('No')
|
print( 'Yes' if len(set(input().split())) == 2 else 'No')
| 1 | 68,374,617,336,102 | null | 216 | 216 |
import copy
def BubbleSort(C, N):
for i in range(N):
for j in reversed(range(i+1, N)):
if C[j][1:2] < C[j-1][1:2]:
C[j], C[j-1] = C[j-1], C[j]
print(*C)
stableCheck(C, N)
def SelectionSort(C, N):
for i in range(N):
minj = i
for j in range(i, N):
if C[j][1:2] < C[minj][1:2]:
minj = j
C[i], C[minj] = C[minj], C[i]
print(*C)
stableCheck(C, N)
def stableCheck(C, N):
global lst
flag = 1
for i in range(N):
for j in range(i+1, N):
if lst[i][1:2] == lst[j][1:2]:
fir = lst[i]
sec = lst[j]
for k in range(N):
if C[k] == fir:
recf = k
if C[k] == sec:
recs = k
if recf > recs:
print("Not stable")
flag = 0
break
if flag ==0:
break
if flag :
print("Stable")
N = int(input())
lst = list(map(str, input().split()))
lst1 = copy.deepcopy(lst)
lst2 = copy.deepcopy(lst)
BubbleSort(lst1, N)
SelectionSort(lst2, N)
|
import sys
import copy
def print_data(data):
last_index = len(data) - 1
for idx, item in enumerate(data):
print(item, end='')
if idx != last_index:
print(' ', end='')
print('')
def bubbleSort(data, N):
for i in range(N):
j = N -1
while j >= i+1:
if data[j][1] < data[j-1][1]:
hoge = data[j]
data[j] = data[j-1]
data[j-1] = hoge
j -= 1
return data
def selectSort(data, N):
for i in range(N):
mini = i
for j in range(i, N):
if data[j][1] < data[mini][1]:
mini = j
if i == mini:
pass
else:
hoge = data[mini]
data[mini] = data[i]
data[i] = hoge
return data
def isStable(inData, outData, N):
for i in range(N):
for j in range(i+1, N):
if inData[i][1] == inData[j][1]:
a = outData.index(inData[i])
b = outData.index(inData[j])
if a > b :
return False
return True
def main():
N = int(input())
data0 = list(input().split())
data1 = copy.deepcopy(data0)
data2 = copy.deepcopy(data0)
bubbleData = bubbleSort(data1, N)
selectData = selectSort(data2, N)
print_data(bubbleData)
if isStable(data0, bubbleData, N):
print('Stable')
else:
print('Not stable')
print_data(selectData)
if isStable(data0, selectData, N):
print('Stable')
else:
print('Not stable')
if __name__ == '__main__':
main()
| 1 | 25,907,637,448 | null | 16 | 16 |
s=input()
l=set(s)
if(len(l)==1):
print("No")
else:
print("Yes")
|
N = input()
print(('Yes', 'No')[N[0] == N[1] == N[2]])
| 1 | 54,713,255,224,012 | null | 201 | 201 |
while True:
hw = [int(x) for x in input().split()]
h, w = hw[0], hw[1]
if h == 0 and w == 0:
break
for hh in range(h):
for ww in range(w):
if hh == 0 or hh == h - 1 or ww == 0 or ww == w - 1:
print('#', end = '')
else:
print('.', end = '')
print('')
print('')
|
x = 0
while x == 0:
m = map(int,raw_input().split())
if m[0] == 0 and m[1] == 0:
break
print "#" * m[1]
for i in xrange(m[0]-2):
print "#" + "." * (m[1]-2) + "#"
print "#" * m[1]
print ""
| 1 | 801,120,083,402 | null | 50 | 50 |
import functools, operator
r,c = tuple(int(n) for n in input().split())
A = [[int(a) for a in input().split()] for i in range(r)]
for a in A:
a.append(sum(a))
R = [functools.reduce(operator.add, x) for x in zip(*A)]
A.append(R)
for j in A:
print(" ".join(map(str,j)))
|
N=int(input())
*A,=map(int,input().split())
Q=int(input())
*M,=map(int,input().split())
mf=['no']*Q
t=[]
for i in range(0,2**N):
ans=0
for j in range(N):
if (i>>j&1):
ans+=A[j]
t.append(ans)
tset=set(t)
for i in range(Q):
if M[i] in tset:
mf[i] = 'yes'
for i in mf:
print(i)
| 0 | null | 721,995,038,774 | 59 | 25 |
n = int(input())
fives = [0]
if n % 2 == 1:
print(0)
else:
i = 0
while 1:
temp5 = (n // (5** (i +1))) //2
if temp5 != 0:
fives.append(temp5)
i += 1
else:
break
print(sum(fives))
|
#!/usr/bin/env python3
import collections as cl
import sys
def II():
return int(sys.stdin.readline())
def main():
n = II()
if n % 2 == 1:
print(0)
return
n_int = n // 2
ans_int = 0
k = 5
while k <= n_int:
ans_int += n_int//k
k *= 5
print(ans_int)
main()
| 1 | 115,575,681,236,612 | null | 258 | 258 |
n,p = map(int,input().split())
s = input()
ans = 0
if p == 2 or p == 5:
for i,c in enumerate(s,1):
if int(c)%p == 0: ans += i
else:
cnt = [0]*p
cnt[0] = 1
x = 0
d = 1
for c in s[::-1]:
x += d*int(c)
x %= p
cnt[x%p] += 1
d *= 10
d %= p
# print(cnt)
for v in cnt: ans += v*(v-1)//2
print(ans)
|
from collections import Counter
n, p = map(int, input().split())
s = list(map(int, list(input())))
ans = 0
if p in {2, 5}:
for i, num in enumerate(s):
if num % p == 0:
ans += i + 1
else:
bfo, cnt = 0, [1] + [0] * (p - 1)
for i, num in enumerate(s[::-1]):
bfo = (bfo + pow(10, i, p) * num) % p
ans += cnt[bfo]
cnt[bfo] += 1
print(ans)
| 1 | 58,075,731,661,746 | null | 205 | 205 |
y,x = [int(x) for x in input().split()]
while(x > 0 or y > 0):
print('#' * x)
st = '#'
st += '.' * (x-2)
st += '#'
for i in range(1, y-1):
print(st)
print('#' * x)
print()
y,x = [int(x) for x in input().split()]
|
while True:
h,w = map(int, input().split())
if h == 0 and w == 0:
break
for i in range(h):
if i == 0 or i == h-1:
print("#"*w)
else:
print("#" + "."*(w-2) + "#")
print()
| 1 | 831,659,853,840 | null | 50 | 50 |
N = int(input())
A = [0]+list(map(int, input().split(" ")))
dp_list = [{0, 0}, {0: 0, 1: A[1]}, {0: 0, 1: A[1] if A[1] > A[2] else A[2]}]
for i in range(3, N+1):
b = (i-1)//2
f = (i+1)//2
dp_list.append({})
for j in range(b, f+1):
if j in dp_list[i-1]:
dp_list[i][j] = dp_list[i-2][j-1]+A[i] if dp_list[i -
2][j-1]+A[i] > dp_list[i-1][j] else dp_list[i-1][j]
else:
dp_list[i][j] = dp_list[i-2][j-1]+A[i]
print(dp_list[-1][N//2])
|
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])
| 1 | 37,644,319,601,092 | null | 177 | 177 |
s = input()
a = [0] * (len(s)+1)
larger_count = 0
for i in range(len(s)):
if s[i] == '>':
larger_count += 1
continue
for j in range(larger_count+1):
a[i-j] = max(a[i-j], j)
larger_count = 0
a[i+1] = a[i] + 1
for j in range(larger_count+1):
a[len(a)-j-1] = max(a[len(a)-j-1], j)
print(sum(a))
|
from collections import *
n, p = map(int, input().split())
s = list(map(int, input()))
if 10%p==0:
r = 0
for i in range(n):
if s[i]%p==0:
r += i+1
print(r)
exit()
c = Counter()
c[0] += 1
v = r = 0
k = 1
for i in s[::-1]:
v += int(i)*k
v %= p
r += c[v]
c[v] += 1
k *= 10
k %= p
print(r)
| 0 | null | 106,892,899,854,378 | 285 | 205 |
k = int(input())
a,b = map(int,input().split())
count = 1
flag = 0
while k * count <= b:
if k * count >= a and k * count <= b:
flag = 1
count += 1
else:
count += 1
if flag == 1:
print("OK")
else:
print("NG")
|
ST = list(map(str, input().split()))
print(ST[1]+ST[0])
| 0 | null | 64,525,228,072,240 | 158 | 248 |
x=int(input())
kosu=0
for i in range(1000):
kosu+=1
if 100*kosu<=x<=105*kosu:
print(1)
quit()
print(0)
|
x = int(input())
flag = 0
if x >= 2000:
print(1)
exit()
else:
for i in range(20):
for j in range(20):
for k in range(20):
for l in range(20):
for m in range(20):
for n in range(20):
if i*100+j*101+k*102+l*103+m*104+n*105 == x:
flag = 1
print(1)
exit()
if flag != 1:
print(0)
| 1 | 127,114,662,641,520 | null | 266 | 266 |
def comb(n):
if n <= 1:
return 0
return n * (n - 1) // 2
def check(L):
r = {}
a = 0
c = 0
for i in range(len(L)):
if a != L[i]:
if i != 0:
r[a] = [comb(c), comb(c - 1)]
a = L[i]
c = 1
else:
c += 1
r[a] = [comb(c), comb(c - 1)]
#print(r)
return r
N = int(input())
A = [int(n) for n in input().split(" ")]
D = {}
for i in range(len(A)):
D[i] = A[i]
D = sorted(D.items(), key=lambda x: x[1])
V = {}
for i in range(len(D)):
V[D[i][0]] = i
AA = sorted(A)
rr = check(AA)
ss = 0
for k, v in rr.items():
ss += v[0]
#print(ss)
for k in range(N):
index = A[k]
a = rr[index][0] - rr[index][1]
print(ss - a)
|
from collections import deque
n = int(input())
a = deque()
for i in range(n):
s = input()
if s == 'deleteFirst':
a.popleft()
elif s == 'deleteLast':
a.pop()
else:
s ,t = s.split()
if s == 'insert':
a.appendleft(t)
elif s == 'delete':
if t in a:
a.remove(t)
print(*a, sep = ' ')
| 0 | null | 24,033,920,039,620 | 192 | 20 |
from sys import stdin
import collections
def ip(): return [int(i) for i in stdin.readline().split()]
def sp(): return [str(i) for i in stdin.readline().split()]
# 4 6
# 1 2
# 1 3
# 1 4
# 2 3
# 2 4
# 3 4
def find(d,x):
root = x
while root != d[root]:
root = d[root]
while x != root:
nxt = d[x]
d[x] = root
x = nxt
return d,root
def merge(d,s,x,y):
d,x = find(d,x)
d,y = find(d,y)
if x == y: return d,s
if s[x] > s[y]:
s[x] += s[y]
d[y] = d[x]
else:
s[y] += s[x]
d[x] = d[y]
return d,s
n,m = ip()
d = {i+1: i+1 for i in range(n)}
s = {i+1: 1 for i in range(n)}
seen = set()
for _ in range(m):
# print(d,s)
x,y = ip()
if (x,y) in seen or (y,x) in seen: continue
seen.add((x,y))
seen.add((y,x))
d,s = merge(d,s,x,y)
ans = 0
for i in s:
ans = max(ans, s[i])
print(ans)
|
class UnionFind(): # 0インデックス
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
if __name__ == "__main__":
N, M = map(int, input().split()) # N人、M個の関係
union_find = UnionFind(N)
for _ in range(M):
A, B = map(int, input().split())
A -= 1
B -= 1
union_find.union(A, B)
answer = 0
for i in range(N):
answer = max(answer, union_find.size(i))
print(answer)
| 1 | 3,938,832,054,608 | null | 84 | 84 |
def check(x, A, K):
import math
sumA = 0
for a in A:
if a > x:
sumA += math.ceil(a / x) - 1
if sumA <= K:
return True
else:
return False
def resolve():
_, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
ok = max(A) # maxVal when minimize
ng = -1 # maxVal when maximize
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if mid > 0 and check(mid, A, K):
ok = mid
else:
ng = mid
print(ok)
resolve()
|
import math
a, b, x = [int(i) for i in input().split()]
if a**2 * b / 2 <= x:
y = 2 * x / a**2 - b
tntheta = (b - y) / a
else:
y = a - 2 * x / (a * b)
tntheta = b / (a - y)
print(math.degrees(math.atan(tntheta)))
| 0 | null | 85,106,003,556,640 | 99 | 289 |
sum = 1
input()
for i in map(int,input().split()):
sum|=sum<<i
input()
for j in map(int,input().split()):
print(['no','yes'][(sum>>j)&1])
|
def main():
input()
array_a = list(map(int, input().split()))
input()
array_q = map(int, input().split())
def can_construct_q (q, i, sum_sofar):
if sum_sofar == q or sum_sofar + array_a[i] == q:
return True
elif sum_sofar > q or i >= len (array_a) - 1:
return False
if can_construct_q(q, i + 1, sum_sofar + array_a[i]):
return True
if can_construct_q(q, i + 1, sum_sofar):
return True
sum_array_a = sum(array_a)
for q in array_q:
#print(q)
if sum_array_a < q:
print('no')
elif can_construct_q(q, 0, 0):
print('yes')
else:
print('no')
return
main()
| 1 | 104,134,389,440 | null | 25 | 25 |
N=int(input())
A=0
for i in range(1,N+1):
if i%3!=0 and i%5!=0:
A=A+i
print(int(A))
|
n=int(input())
print(*[chr(65+(ord(a)+n-65)%26) for a in input()], sep='')
| 0 | null | 84,897,362,999,120 | 173 | 271 |
A11,A12,A13 = map(int,input().split())
A21,A22,A23 = map(int,input().split())
A31,A32,A33 = map(int,input().split())
Alist = []
Alist.append(A11)
Alist.append(A12)
Alist.append(A13)
Alist.append(A21)
Alist.append(A22)
Alist.append(A23)
Alist.append(A31)
Alist.append(A32)
Alist.append(A33)
bingolist =[0]*9
N = int(input())
#print (N)
for i in range(N):
b = int(input())
#print (b)
for j in range(len(bingolist)):
if b ==Alist[j]:
bingolist[j] = 1
if sum(bingolist[0:3])==3 or sum(bingolist[3:6])==3 or sum(bingolist[6:9])==3 or (bingolist[0]+bingolist[3]+bingolist[6])==3 or (bingolist[1]+bingolist[4]+bingolist[7])==3 or (bingolist[2]+bingolist[5]+bingolist[8])==3 or (bingolist[0]+bingolist[4]+bingolist[8])==3 or (bingolist[2]+bingolist[4]+bingolist[6])==3:
print ("Yes")
else :
print ("No")
#print (bingolist[0:3])
#print (bingolist[3:6])
#print (bingolist[6:9])
#print (bingolist)
|
seen = [0,0,0,0,0,0,0,0,0]
seen[0],seen[1],seen[2] = (map(int,input().split()))
seen[3],seen[4],seen[5] = (map(int,input().split()))
seen[6],seen[7],seen[8] = (map(int,input().split()))
over = False
N = int(input())
for x in range(N):
num = int(input())
if num in seen:
seen[seen.index(num)] = "O"
if seen[0] == "O":
if seen[1] == seen[2] == "O":
over = True
elif seen[3] == seen[6] == "O":
over = True
elif seen[4] == seen[8] == "O":
over = True
elif seen[4] == "O":
if seen[2] == seen[6] == "O":
over = True
elif seen[1] == seen[7] == "O":
over = True
elif seen[3] == seen[5] == "O":
over = True
elif seen[8] == "O":
if seen[6] == seen[7] == "O":
over = True
if seen[2] == seen[5] == "O":
over = True
if not over:
print("No")
else:
print("Yes")
| 1 | 59,838,963,434,612 | null | 207 | 207 |
from functools import reduce
MOD = 10**9 + 7
n, a, b = map(int, input().split())
def comb(n, k):
def mul(a, b):
return a*b%MOD
x = reduce(mul, range(n, n-k, -1))
y = reduce(mul, range(1, k+1))
return x*pow(y, MOD-2, MOD) % MOD
ans = (pow(2, n, MOD)-1-comb(n,a)-comb(n,b)) % MOD
print(ans)
|
mod=10**9+7
n,a,b = map(int,input().split())
def combination(n, r,mod=10**9+7):
r = min(r, n-r)
res = 1
for i in range(r):
res = res * (n - i) * pow(i+1, mod-2, mod) % mod
return res
N = pow(2,n,mod)-1
A = combination(n,a)
B = combination(n,b)
print((N-A-B)%mod)
| 1 | 66,328,699,912,908 | null | 214 | 214 |
n, k = map(int, input().split())
A = list(map(int, input().split()))
now = 1000
for i in range(k, n):
#print(A[i], A[i-k])
if A[i] > A[i-k]:
print("Yes")
else:
print("No")
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
r = int(readline())
print(r * r)
if __name__ == '__main__':
solve()
| 0 | null | 76,414,165,002,988 | 102 | 278 |
s = input()
w = ['SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN']
print(w.index(s)+1)
|
w = "SUN,MON,TUE,WED,THU,FRI,SAT".split(",")
S = input().strip()
for i, d in enumerate(w):
if d == S:
print(7 - i)
| 1 | 133,436,831,800,698 | null | 270 | 270 |
from itertools import combinations
N = int(input())
L = list(map(int, input().split()))
count = 0
for C in combinations(L, 3):
l_list = list(C)
l_list.sort()
if l_list[2] > l_list[1] and l_list[1] > l_list[0]:
if l_list[2] < l_list[1] + l_list[0]:
count += 1
print(count)
|
while True:
[n, m] = [int(x) for x in raw_input().split()]
if [n, m] == [0, 0]:
break
data = []
for x in range(n, 2, -1):
for y in range(x - 1, 1, -1):
for z in range(y - 1, 0, -1):
s = x + y + z
if s < m:
break
if s == m:
data.append(s)
print(len(data))
| 0 | null | 3,202,786,118,610 | 91 | 58 |
def main():
INF = 10 ** 10
H, N = list(map(int, input().split(' ')))
magic = [list(map(int, input().split(' '))) for _ in range(N)]
MAX_A = max(list(map(lambda x: x[0], magic)))
dp = [INF for _ in range(MAX_A + H + 1)]
dp[0] = 0
for h in range(1, MAX_A + H + 1):
for i in range(N):
a, b = magic[i]
if h - a < 0:
continue
dp[h] = min(dp[h], b + dp[h - a])
print(min(dp[H:]))
if __name__ == '__main__':
main()
|
H, N = map(int, input().split())
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]
# dp[damage] := モンスターに damage を与えるために必要な最小コスト
dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
for damage, cost in Magic:
next_index = min(h + damage, H)
dp[next_index] = min(dp[next_index], dp[h] + cost)
print(dp[-1])
| 1 | 81,234,343,504,862 | null | 229 | 229 |
K, X = map(int, input().split())
print('Yes' if 500 * K >= X else 'No')
|
K,X=map(int,input().split())
print("Yes" if 500*K>=X else "No")
| 1 | 98,100,013,475,938 | null | 244 | 244 |
import sys
N = int(input())
p = list(map(int, input().split()))
for i in range(N):
if p[i] == 0:
print(0)
sys.exit()
product = 1
for i in range(N):
product = product * p[i]
if product > 10 ** 18:
print(-1)
sys.exit()
break
print(product)
|
N = int(input())
A = list(map(int, input().split()))
if 0 in A:
ans = 0
else:
ans = 1
max_limit = 10 ** 18
for i in range(N):
if ans * A[i] > max_limit:
ans = -1
break
else:
ans *= A[i]
print(str(ans))
| 1 | 16,043,277,846,692 | null | 134 | 134 |
#coding: UTF-8
def X_Cubic(x):
return x*x*x
if __name__=="__main__":
x = input()
ans = X_Cubic(int(x))
print(ans)
|
x=input()
a=int(x)*int(x)*int(x)
print(a)
| 1 | 284,313,636,350 | null | 35 | 35 |
import math
x = int(input())
def lcm(a, b):
return (a * b) // math.gcd(a, b)
rad = lcm(360, x)
print(rad//x)
|
x=int(input())
a=1
while True:
if (a*x%360==0):
print(a)
break
a+=1
| 1 | 13,168,089,756,360 | null | 125 | 125 |
s = list(input())
if s[2] == s[3]:
if s[4] == s[5]:
print('Yes')
else:
print('No')
else:
print('No')
|
#!/usr/bin/env python3
import sys
YES = "Yes" # type: str
NO = "No" # type: str
def solve(S: str):
if S[2] == S[3] and S[4] == S[5]:
print(YES)
else:
print(NO)
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()
S = next(tokens) # type: str
solve(S)
if __name__ == '__main__':
main()
| 1 | 42,012,606,284,608 | null | 184 | 184 |
D = int(input())
c = [int(i) for i in input().split()]
s = [[int(i) for i in input().split()] for _ in range(D)]
t = [int(input())-1 for _ in range(D)]
ans = 0
llst = [0]*26
for day,i in enumerate(range(D),1):
llst[t[i]] = day
ans += s[i][t[i]]
for j in range(26): ans -= c[j]*(day-llst[j])
print(ans)
|
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
test=[int(input()) for i in range(D)]
lastday=[0 for j in range(26)]
points=[0 for i in range(D)]
lastday=[lastday[i]+1 for i in range(26)]
lastday[test[0]-1]=0
minus=sum([x*y for (x,y) in zip(c,lastday)])
points[0]=s[0][test[0]-1]-minus
for i in range(1,D):
lastday=[lastday[i]+1 for i in range(26)]
lastday[test[i]-1]=0
minus=sum([x*y for (x,y) in zip(c,lastday)])
points[i]=points[i-1]+s[i][test[i]-1]-minus
for ps in points:
print(ps)
| 1 | 9,872,961,492,932 | null | 114 | 114 |
s = list(input())
n = len(s)
m = n//2
s_f = []
s_l = []
for i in range(m):
s_f.append(s[i])
for i in range(1,m + 1):
s_l.append(s[-i])
s_r = list(reversed(s))
s_f_r = list(reversed(s_f))
s_l_r = list(reversed(s_l))
if s_r == s:
if s_f_r == s_f and s_l_r == s_l:
print("Yes")
else:
print("No")
else:
print("No")
|
s = input()
n = len(s)
ans = "No"
cnt = 0
if s[::1] == s[::-1]:
cnt += 1
if s[:int((n-1)/2):1] == s[int((n-1)/2)-1::-1]:
cnt += 1
if s[int((n+1)/2)::1] == s[:int((n-1)/2):-1]:
cnt += 1
if cnt == 3:
ans = "Yes"
print(ans)
| 1 | 46,289,002,341,988 | null | 190 | 190 |
N = int(input())
for i in range(10):
pay = (i + 1) * 1000
if(pay >= N):
break
if(pay < N):
print("たりません")
else:
print(pay - N)
|
N, K =map(int,input().split())
K = [tuple(map(int,input().split())) for i in range(K)]
M = 998244353
dp = [0] * N
dp[1] = 1
prefix = [1] * N
for i in range(1, N):
cur = 0
for L, R in K:
a = i - R
b = i - L
if b < 0:
continue
cur += prefix[b] - (prefix[a - 1] if a - 1 >= 0 else 0)
dp[i] = cur % M
prefix[i] = prefix[i - 1] + dp[i]
prefix[i] %= M
print(dp[N - 1])
| 0 | null | 5,653,151,101,348 | 108 | 74 |
n = int(input())
for i in range(n):
nums = sorted(map(int, input().split()))
print("YES" if nums[2]**2 == nums[1]**2 + nums[0]**2 else "NO")
|
ans = []
for i in range(int(input())):
a, b, c = map(int, input().split())
lst = [a, b, c]
lst.sort()
if lst[2]**2 == lst[0]**2 + lst[1]**2:
ans.append("YES")
else:
ans.append("NO")
for i in ans:
print(i)
| 1 | 272,642,048 | null | 4 | 4 |
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
from collections import defaultdict
def get_sieve_of_eratosthenes(n, D):
limit = int(n ** 0.5) + 1
cnt_list = [0] * (n + 1)
for i in range(2, limit + 1):
if cnt_list[i] == 0:
k = n // i
for j in range(1, k + 1):
s = i * j
if cnt_list[s] == 0:
D[s] = i
cnt_list[s] = 1
for l in range(limit, n + 1):
if cnt_list[l] == 0:
D[l] = l
cnt_list[l] = 1
return D
N = I()
A = LI()
D = defaultdict()
max_a = max(A)
num_list = [0] * (max_a + 1)
if max_a == 1:
print("pairwise coprime")
exit()
g = A[0]
for a in A:
g = math.gcd(g, a)
if g > 1:
print('not coprime')
exit()
A_ = set(A)
A_.discard(1)
if len(A_) >= 90000:
print('setwise coprime')
exit()
D = get_sieve_of_eratosthenes(max_a, D)
for a in A:
P_list = defaultdict(int)
while a != 1:
x = D[a]
P_list[x] += 1
a //= x
for key in P_list.keys():
if num_list[key] != 0:
print('setwise coprime')
exit()
num_list[key] = 1
print('pairwise coprime')
if __name__ == "__main__":
main()
|
from math import gcd
from functools import reduce
from sys import exit
# O(A+N)解
MAX_A = 1000000
lowerst_prime = [0] * (MAX_A + 1) # 最小の素因数をいれる(2以上をみていけばいい)
primes = [] # MAX_A以下の素数の集合
count = [0] * (MAX_A + 1) # 約数として出てくる回数を数える
for i in range(2, MAX_A + 1): # 線形時間で処理してくれる
if lowerst_prime[i] == 0:
lowerst_prime[i] = i
primes.append(i)
for p in primes:
if p > lowerst_prime[i] or i * p > MAX_A:
break
lowerst_prime[i * p] = p # p が i * p のもっとも小さな素因数となるときのみ更新されるので、線形時間アルゴリズムとなる
# 入力
N = int(input())
A = [*map(int, input().split())]
if reduce(gcd, A) != 1:
print("not coprime")
exit(0)
for i in range(N):
while A[i] > 1:
divide = lowerst_prime[A[i]]
if count[divide]:
# A[x] % i == A[y] % i == 0 となるx != yが存在するので、i | gcd(x, y) となる
print("setwise coprime")
exit(0)
count[divide] += 1
while A[i] % divide == 0: # 割れるだけ割る
A[i] //= divide
print("pairwise coprime")
| 1 | 4,139,558,585,280 | null | 85 | 85 |
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cA = Counter(A)
allS = 0
for key in cA:
allS += cA[key] * (cA[key] - 1) / 2
for i in range(N):
if A[i] in cA.keys():
print(int(allS - (cA[A[i]] - 1)))
else:
print(int(allS))
|
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))))
| 1 | 48,022,538,429,880 | null | 192 | 192 |
s=input()
t=input()
a=0
for i in range(len(s)):
if s[i]==t[i]:
a+=1
if a==len(s):
print('Yes')
else:
print('No')
|
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
distance = abs(A-B)
speed = V-W
if distance <= speed*T:
print("YES")
else:
print("NO")
| 0 | null | 18,161,126,324,134 | 147 | 131 |
n = int(input())
a = []
cnt = 0
for i in range(n):
a.append(int(input()))
def insertionSort(a, n, g):
global cnt
for i in range(g, n):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j+g] = a[j]
j = j - g
cnt = cnt + 1
a[j+g] = v
g = []
g.append(1)
m = 0
while g[m] < n:
if n > 3 * g[m] + 1:
m = m + 1
g.append(3 * g[m-1] + 1)
else:
break
m = m + 1
g.reverse()
for i in range(m):
insertionSort(a,n,g[i])
print(m)
print(*g)
print(cnt)
for i in range(n):
print(a[i])
|
n,k=map(int,input().split())
L=[1]*n
for i in range(k):
d=int(input())
A=list(map(int,input().split()))
for a in A:
L[a-1] = 0
print(sum(L))
| 0 | null | 12,246,285,410,674 | 17 | 154 |
a,b = raw_input().split(" ")
a = int(a)
b = int(b)
if a < b:
print "a < b"
elif a > b:
print "a > b"
else:
print "a == b"
|
s = input()
n = len(s)
t = s[:(n-1)//2]
u = s[(n+3)//2-1:]
if (s == s[::-1]
and t == t[::-1]
and u == u[::-1]):
print('Yes')
else:
print('No')
| 0 | null | 23,173,789,354,390 | 38 | 190 |
n = int(input())
x = list(map(int,input().split()))
avg1 = sum(x)//n
avg2 = avg1+1
ans1 = int(sum([(i - avg1)**2 for i in x]))
ans2 = int(sum([(i - avg2)**2 for i in x]))
print(min(ans1,ans2))
|
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline
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 lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []
def main():
n = i_input()
xs = i_list()
min_list = []
for i in range(1, 101):
tmp = 0
for x in xs:
tmp += (i - x)**2
min_list.append(tmp)
print(min(min_list))
if __name__ == '__main__':
main()
| 1 | 65,180,296,628,092 | null | 213 | 213 |
import sys
input = sys.stdin.readline
n = int(input())
flag = False
for i in range(1, 10):
if n % i == 0 and 1 <= n // i <= 9:
flag = True
break
if flag:
print("Yes")
else:
print("No")
|
n,x,y = map(int,input().split())
l= [0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
k = min(abs(j-i),abs(x-i)+1+abs(j-y))
l[k] += 1
for k in range(1,n):
print(l[k])
| 0 | null | 102,276,923,925,910 | 287 | 187 |
from collections import deque
n, k = map(int, input().split())
a = [-1] + list(map(int, input().split()))
town = [-1] * (n + 1)
town[1] = 0
now_town = 1
second_first = 0
while True:
if town[a[now_town]] != -1:
second_first = a[now_town]
break
town[a[now_town]] = town[now_town] + 1
if town[a[now_town]] == k:
print(a[now_town])
exit()
now_town = a[now_town]
# print(town)
start_index = town[second_first]
end_index = max(town)
rest = k - end_index
div = (rest-1) % (end_index - start_index + 1)
# print(rest, div)
ans = town.index((start_index) + div)
print(ans)
|
import statistics
import sys
data_sets = sys.stdin.read().split("\n")
for i in data_sets[1:-1:2]:
data_set = [int(j) for j in i.split()]
print(statistics.pstdev(data_set))
| 0 | null | 11,446,436,773,002 | 150 | 31 |
n = input()
k = int(input())
dp = [[[0] * (k+1) for _ in range(2)] for _ in range(len(n)+1)]
dp[0][0][0] = 1
for i in range(1, len(n) + 1):
t = int(n[i-1])
for j in range(k+1):
if t != 0:
if j != 0:
dp[i][0][j] += dp[i-1][0][j-1]
dp[i][1][j] += dp[i-1][1][j-1] * 9 + dp[i-1][0][j-1] * (t-1)
dp[i][1][j] += (dp[i-1][1][j] + dp[i-1][0][j])
else:
dp[i][0][j] += dp[i-1][0][j]
if j != 0:
dp[i][1][j] += dp[i-1][1][j-1] * 9
dp[i][1][j] += dp[i-1][1][j]
print(dp[len(n)][0][k] + dp[len(n)][1][k])
|
N,X,M = map(int,input().split())
ans = X
A = X
TF = True
srt = 1000000
retu = [X]
d = dict()
d[X] = 0
loop = X
flag = False
for i in range(N-1):
if TF:
A = A**2 % M
if d.get(A) != None:
srt = d[A]
goal = i
TF = False
if TF:
retu.append(A)
d[A] = i + 1
loop += A
else:
flag = True
break
if flag:
n = (N-srt)//(goal-srt+1)
saisyo = sum(retu[:srt])
loop -= saisyo
print(saisyo + loop*n + sum(retu[srt:N-n*(goal-srt+1)]))
else:
print(sum(retu[:N]))
| 0 | null | 39,298,908,116,288 | 224 | 75 |
H1, M1, H2, M2, K = map(int, input().split())
getUpTime = H1 * 60 + M1
goToBed = H2 * 60 + M2
DisposableTime = goToBed - getUpTime
if K > DisposableTime:
print(0)
else:
print(DisposableTime - K)
|
import numpy as np
mod = 998244353
n, s = map(int, input().split())
dp = np.zeros((n+1, s+1), dtype=int)
dp[0, 0] = 1
for i, a in enumerate(map(int, input().split())):
dp[i+1] = dp[i] * 2 % mod
dp[i+1][a:] = (dp[i+1][a:] + dp[i][:-a]) % mod
print(dp[-1, -1])
| 0 | null | 17,898,688,211,262 | 139 | 138 |
while True:
H, W = map(int, input().split())
if H == 0 and W == 0:
break
else:
if W % 2 == 0:
i = H//2
while i > 0:
print("#."*(W//2))
print(".#"*(W//2))
i -= 1
if H % 2 == 1:
print("#."*(W//2))
else:
i = H // 2
while i > 0:
print("#."*(W//2)+"#")
print(".#"*(W//2)+".")
i -= 1
if H % 2 == 1:
print("#."*(W//2)+"#")
print("")
|
while True:
H,W = map(int, raw_input().split(" "))
if H == 0 and W == 0:
break
else:
for h in xrange(H):
sw = True if (h % 2) == 0 else False
s = ""
for w in xrange(W):
s += "#" if sw else "."
sw = not sw
print s
print ""
| 1 | 892,591,835,872 | null | 51 | 51 |
#!/usr/bin/env python3
import sys
input = iter(sys.stdin.read().splitlines()).__next__
D, T, S = map(int, input().split())
print('Yes' if D <= T*S else 'No')
|
d,t,s = [int(x) for x in input().split()]
if d/s <= t:
print("Yes")
else:
print("No")
| 1 | 3,527,443,515,232 | null | 81 | 81 |
N,K =map(int,input().split())
count=0
while 1:
if N//(K**count)==0:
break
count +=1
print(count)
|
n,k=[int(s) for s in input().split()]
count=0
while n>0:
n=n//k
count=count+1
print(count)
| 1 | 64,643,077,992,480 | null | 212 | 212 |
print("Yes") if (input()*2).find(input())>-1 else print("No")
|
s2 = list(input()*2)
p = list(input())
for i in range(len(s2)-len(p)):
a = [ s2[i+j] for j in range(len(p))]
if a == p:
print("Yes")
break
else:
print("No")
| 1 | 1,750,527,784,698 | null | 64 | 64 |
while True:
t = input()
if t.find("?") > 0:
break
print(int(eval(t)))
|
def main():
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(60):
c=0
for j in A:
if j>>i&1:
c+=1
ans+=pow(2,i,mod)*c*(N-c)
ans%=mod
print(ans)
if __name__=='__main__':
main()
| 0 | null | 62,112,476,386,730 | 47 | 263 |
s=input()
ans=0
tmp=0
for i in s:
if i=='R':
tmp+=1
else:
ans=max(ans,tmp)
tmp=0
print(max(ans,tmp))
|
from itertools import accumulate
h,w,k=map(int,input().split())
s=[[0]*(w+1)]+[[0]+[int(i) for i in input()] for _ in range(h)]
for i in range(h+1):
s[i]=list(accumulate(s[i]))
for j in range(w+1):
for i in range(h):
s[i+1][j]+=s[i][j]
ans=10**18
for i in range(1<<h-1):
a=[]
for j in range(h-1):
if (i>>j)&1:a+=[j+1]
a+=[h]
cnt=len(a)-1
q=1
for j in range(1,w+1):
p=0
flag=0
for l in a:
if s[l][j]-s[l][j-1]-s[p][j]+s[p][j-1]>k:flag=1
elif s[l][j]-s[l][q-1]-s[p][j]+s[p][q-1]>k:
q=j
cnt+=1
break
else:p=l
if flag:break
else:
ans=min(cnt,ans)
print(ans)
| 0 | null | 26,572,675,889,630 | 90 | 193 |
#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
n,m=map(int,input().split())
a=list(map(int,input().split()))
def lcm(a,b):
g=math.gcd(a,b)
return b*(a//g)
l=a[0]//2
for i in range(n):
r=a[i]//2
l=lcm(l,r)
for i in range(n):
if (l//(a[i]//2))%2==0:
print(0)
exit()
res=m//l
print((res+1)//2)
|
from fractions import gcd
def lcm(a,b):
return a*b//gcd(a,b)
N,M = map(int,input().split())
A = [int(i) for i in input().split()]
a = 0
b = A[0]
while b % 2 == 0:
a += 1
b = b//2
for i in range(1,N):
if A[i] % (2**a) != 0 or A[i] % (2**(a+1)) == 0:
print(0)
exit()
c = A[0]
for i in range(N-1):
c = lcm(c,A[i+1])
print((M+c//2)//c)
| 1 | 101,882,896,184,960 | null | 247 | 247 |
while True:
h, w = map(int, raw_input().split())
if (h == 0) & (w == 0):
break
line0 = ""
line1 = "."
for i in range(w):
if i % 2 == 0:
line0 += "#"
else:
line0 += "."
line1 += line0[:-1]
for j in range(h):
if j % 2 == 0:
print line0
else:
print line1
print ""
|
while(True):
H, W = map(int, input().split())
if(H == W == 0):
break
str = "#." * (W // 2 + 1)
for i in range(H):
if(i % 2 == 0):
print(str[:W:])
else:
print(str[1:W + 1:])
print()
| 1 | 877,667,918,982 | null | 51 | 51 |
a = input()
a = [int(n) for n in a.split()]
print(a[0] * a[1])
|
def solve(n):
su = 0
for i in range(1, n+1):
m = n//i
su += m*(2*i + (m-1)*i)//2
return su
n = int(input())
print(solve(n))
| 0 | null | 13,384,293,432,300 | 133 | 118 |
L = int(input())
L = L/3
V=1
for i in range (3):
V*=L
print (V)
|
s = int(input())
n = (s/3)
print(n*n*n)
| 1 | 47,015,930,278,042 | null | 191 | 191 |
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
ps = sorted(p)
print(sum(ps[:k]))
|
N, K = map(int, input().split())
P=list(map(int,input().split()))
list.sort(P)
from itertools import accumulate
ans = list(accumulate(P))
print(ans[K-1])
| 1 | 11,729,255,079,398 | null | 120 | 120 |
def resolve():
X, Y, Z = list(map(int, input().split()))
print(Z, X, Y)
if '__main__' == __name__:
resolve()
|
a=list(map(int,input().split()))
print(*[a[2],a[0],a[1]],sep=' ')
| 1 | 38,000,007,106,712 | null | 178 | 178 |
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
|
from math import sqrt
n=int(input())
while 1:
k=0
for i in range(2,int(sqrt(n))+1):
if(n%i==0):
k=1
break
if(k==0):
print(n)
break
n+=1
| 0 | null | 52,545,647,820,200 | 12 | 250 |
a,b,c = map(int, raw_input().split())
ans = 0
for i in range(c):
num = c % (i + 1)
if num == 0:
if a <= i + 1 and i + 1 <= b:
ans += 1
print ans
|
def main():
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n, k = map(int, readline().split())
a = list(map(int, readline().split()))
memo = [0] * (n + 1)
for _ in range(k):
flag = True
for i, aa in enumerate(a):
bf = (i - aa if i - aa >= 0 else 0)
af = (i + aa + 1 if i + aa < n else n)
memo[bf] += 1
memo[af] -= 1
for i in range(n):
memo[i + 1] += memo[i]
a[i] = memo[i]
if a[i] != n:
flag = False
memo[i] = 0
if flag:
break
print(*a)
if __name__ == '__main__':
main()
| 0 | null | 8,063,204,833,608 | 44 | 132 |
S=input()
if S == "ABC":print("ARC")
else : print("ABC")
|
S = input()
print("ABC" if S[1] == "R" else "ARC" )
| 1 | 24,114,227,351,478 | null | 153 | 153 |
from math import factorial
N, M = map(int, input().split())
if N <= 1:
combN = 0
else:
combN = factorial(N) // (factorial(N - 2) * factorial(2))
if M <= 1:
combM = 0
else:
combM = factorial(M) // (factorial(M - 2) * factorial(2))
print(combN + combM)
|
# floor(a/b)=(a-(a%b))/b
# ax%b=a(x%b)%b
a,b,n=map(int,input().split())
if(n>=b-1):
print(a*(b-1)//b)
else:
print(a*n//b)
| 0 | null | 36,714,890,952,894 | 189 | 161 |
X, Y = map(int, input().split())
temp = [0, 300000, 200000, 100000]
ans = 0
if X == Y == 1:
ans += 400000
if X <= 3:
ans += temp[X]
if Y <= 3:
ans += temp[Y]
print(ans)
|
from itertools import combinations
n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = map(int, input().split())
s = set()
for i in range(1, n):
for j in combinations(a, i):
s.add(sum(j))
for ans in m:
print('yes' if ans in s else 'no')
| 0 | null | 70,230,226,560,860 | 275 | 25 |
n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
print((b-a) // 2)
exit()
else:
c = min(a - 1, n - b)
print(c + (b - a + 1) // 2)
exit()
|
def rollDice(dice, direction):
buf = [x for x in dice]
if direction == "S":
buf[0] = dice[4]
buf[1] = dice[0]
buf[4] = dice[5]
buf[5] = dice[1]
elif direction == "E":
buf[0] = dice[3]
buf[2] = dice[0]
buf[3] = dice[5]
buf[5] = dice[2]
elif direction == "W":
buf[0] = dice[2]
buf[2] = dice[5]
buf[3] = dice[0]
buf[5] = dice[3]
elif direction == "N":
buf[0] = dice[1]
buf[1] = dice[5]
buf[4] = dice[0]
buf[5] = dice[4]
for i in range(6):
dice[i] = buf[i]
def rollDiceSide(dice):
buf = [x for x in dice]
buf[1] = dice[2]
buf[2] = dice[4]
buf[3] = dice[1]
buf[4] = dice[3]
for i in range(6):
dice[i] = buf[i]
d = list(map(int, input().split()))
n = int(input())
for i in range(n):
q1, q2 = list(map(int, input().split()))
wq = d.index(q1)
if wq == 1:
rollDice(d, "N")
elif wq == 2:
rollDice(d, "W")
elif wq == 3:
rollDice(d, "E")
elif wq == 4:
rollDice(d, "S")
elif wq == 5:
rollDice(d, "S")
rollDice(d, "S")
wq = d.index(q2)
if wq == 2:
rollDiceSide(d)
elif wq == 3:
rollDiceSide(d)
rollDiceSide(d)
rollDiceSide(d)
elif wq == 4:
rollDiceSide(d)
rollDiceSide(d)
print(d[2])
| 0 | null | 54,943,612,865,382 | 253 | 34 |
a,b,h,m = map(int, input().split())
import math
print((a**2+b**2-2*a*b*math.cos(math.radians((360*h/12+30*m/60)-360*m/60)))**(1/2))
|
# 最大公約数
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
# 最小公倍数
def lcm(a, b):
return a * b // gcd(a, b)
N, M = map(int, input().split())
A = list(map(int, input().split()))
cnt = [0] * N
for i in range(N):
a = A[i]
while a % 2 == 0:
a = a // 2
cnt[i] += 1
if len(set(cnt)) != 1:
print(0)
exit()
x = A[0] // 2
for a in A[1:]:
x = lcm(x, a // 2)
ans = M // x
print(ans - ans // 2)
| 0 | null | 60,767,131,561,002 | 144 | 247 |
N = int(input())
A = map(int, input().split())
A = sorted(enumerate(A), key=lambda x: x[1], reverse=True)
dp = [[0]*(N+1) for _ in range(N+1)]
for n, (from_i, a) in enumerate(A):
for j in range(n + 1):
dp[n+1][j+1] = max(dp[n+1][j+1], dp[n][j] + a*(from_i - j))
dp[n+1][j] = max(dp[n+1][j], dp[n][j] + a*(N - (n - j) - 1 - from_i))
print(max(dp[N]))
|
from math import gcd
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
mod = 1000000007
#%%
kai = [1]*(n+1)
gyaku = [1]*(n+1)
for i in range(2, n+1):
kai[i] = kai[i-1]*i % mod
gyaku[i] = gyaku[i-1]*pow(i, mod-2, mod) %mod
azero = 0
bzero = 0
zerozero = 0
dict_patterns = {}
dict_patterns_minus = {}
all_effective = 0
answer = 0
dict_patterns["1,0"] = 0
dict_patterns["0,-1"] = 0
for i in range(n):
minus = False
a, b = ab[i]
if a == 0 and b == 0:
zerozero += 1
continue
elif b == 0:
dict_patterns["1,0"] += 1
continue
elif a == 0:
dict_patterns["0,-1"] += 1
continue
common = gcd(a,b)
a = a//common
b = b//common
#%%
if a < 0 and b < 0:
a = -a
b = -b
elif a < 0:
a = -a
b = -b
to_str = str(a)+","+str(b)
if to_str not in dict_patterns:
dict_patterns[to_str] = 1
else:
dict_patterns[to_str] += 1
keys = list(dict_patterns.keys())
patterns = []
test = []
for i in range(len(keys)):
pattern_A = dict_patterns[keys[i]]
dict_patterns[keys[i]] = 0
pattern_B = 0
a, b = map(int, keys[i].split(","))
if str(b)+","+str(-a) in dict_patterns:
pattern_B += dict_patterns[str(b)+","+str(-a)]
dict_patterns[str(b)+","+str(-a)] = 0
if str(-b)+","+str(a) in dict_patterns:
pattern_B += dict_patterns[str(-b)+","+str(a)]
dict_patterns[str(-b)+","+str(a)] = 0
if pattern_A != 0 or pattern_B != 0:
patterns.append(max(2**pattern_A-1,0) + max(2**pattern_B-1,0)+1)
test.append([pattern_A, pattern_B])
answer = 1
for i in range(len(patterns)):
answer = answer*patterns[i] % mod
print((answer-1+zerozero)%mod)
| 0 | null | 27,544,175,684,288 | 171 | 146 |
S = int(input())
MOD = 10 ** 9 + 7
DP = [0] * (S+1)
DP[0] = 1
for i in range(S):
for nex in range(i+3, S+1):
DP[nex] += DP[i]
DP[nex] %= MOD
print(DP[S] % MOD)
|
N=int(input())
DP=[0]*(N+1)
tmp=0
mod=10**9+7
if N<3:
print(0)
exit()
DP[3]=1
for i in range(4,N+1):
DP[i]=(DP[i-1]+DP[i-3])%mod
print(DP[N]%mod)
| 1 | 3,292,706,185,990 | null | 79 | 79 |
from sys import exit
N,K = map(int,input().split())
town = [None]+list(map(int,input().split()))
flag = [None]+[0]*N
remain = K
piece = 1
cnt = 1
while remain > 0:
if flag[town[piece]] != 0:
q = cnt-flag[town[piece]]
piece = town[piece]
remain -= 1
break
else:
piece = town[piece]
flag[piece] = cnt
remain -= 1
cnt += 1
if remain == 0:
print(piece)
exit(0)
remain %= q
while remain > 0:
piece = town[piece]
remain -= 1
print(piece)
|
def f():
n,k=map(int,input().split())
l=list(map(int,input().split()))
now=1
for d in range(k.bit_length()):
k,f=divmod(k,2)
if f:now=l[now-1]
l=tuple(l[i-1]for i in l)
print(now)
if __name__ == "__main__":
f()
| 1 | 22,868,023,418,940 | null | 150 | 150 |
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[1]
C=["#"]*N
roop=False
for i in range(K):
if C[B[i]-1]=="#":
C[B[i]-1]="$"
else:
roop=True
break
B.append(A[B[i]-1])
if roop==True:
f=B.index(B[i])
T=i-f
if T==0:
print(B[f])
else:
r=(K-f)%T
print(B[f+r])
else:
print(B[K])
|
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
mod = 10 ** 9 + 7
b = 1
ans = 0
for i in range(k - 1, n):
ans += b * (a[i] - a[n - i - 1])
ans %= mod
b = (i+1)*pow(i-k+2, mod - 2, mod) * b % mod
print(ans)
| 0 | null | 59,030,851,797,504 | 150 | 242 |
n, m = map(int, input().split())
G = [[] for _ in range(n)]
for i in range(m):
a, b = map(int, input().split())
a, b = a - 1, b - 1
G[a].append(b)
G[b].append(a)
ans = [-1] * n
from collections import deque
d = deque([0])
while d:
u = d.popleft()
for v in G[u]:
if ans[v] == -1:
ans[v] = u
d.append(v)
if -1 in ans[1:]:
print('No')
else:
print('Yes')
for v in ans[1:]:
print(v + 1)
|
def main():
n, a, b = map(int, input().split())
ab_diff = abs(a-b)
if ab_diff%2 == 0:
print(ab_diff//2)
return
a_edge_diff = min(abs(a-1),abs(n-a))
b_edge_diff = min(abs(b-1),abs(n-b))
# near_diff = min(a_edge_diff, b_edge_diff)
if a_edge_diff <= b_edge_diff:
print(a_edge_diff+1+ (ab_diff-1)//2)
else:
print(b_edge_diff+1+ (ab_diff-1)//2)
if __name__ == "__main__":
main()
| 0 | null | 65,194,924,533,470 | 145 | 253 |
n,k = map(int,input().split())
A = [int(i) for i in input().split()]
A.sort()
F = [int(i) for i in input().split()]
F.sort(reverse=True)
left = -1
right = 10**12
def f(x): return sum(max(A[i]-x//F[i],0) for i in range(n)) <= k
while right - left > 1:
mid = (left+right)//2
if f(mid): right = mid
else: left = mid
print(right)
|
n , k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse=True)
lef = -1
rig = 10**13
while rig - lef != 1:
now = (rig + lef) //2
cou = 0
for i in range(n):
t = now // f[i]
cou += max(0,a[i]-t)
if cou <= k:
rig = now
elif cou > k:
lef = now
print(rig)
| 1 | 164,500,893,426,250 | null | 290 | 290 |
a,b,c = map(int,input().split())
print("%d %d %d" %(c,a,b))
|
a,b,c=list(map(int,input().split()))
print(c,a,b)
| 1 | 37,920,977,577,978 | null | 178 | 178 |
n = int(input())
a = map(int, input().split())
re = 0
from collections import Counter
c = Counter(a)
for i, v in c.items():
if v >= 2:
re += 1
if re >= 1:
print("NO")
else:
print("YES")
|
a = list(str(input()))
b = list(str(input()))
count=0
for i in range(len(a)):
if a[i] != b[i]:
count +=1
print(count)
| 0 | null | 41,981,784,397,210 | 222 | 116 |
import collections
import heapq
import math
import random
import sys
input = sys.stdin.readline
sys.setrecursionlimit(500005)
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
rs = lambda: input().rstrip()
n = ri()
a = rl()
N = 1000000
f = [0] * (N + 10)
for v in a:
f[v] += 1
for i in range(N, 0, -1):
if f[i] == 0:
continue
j = i * 2
while j <= N:
f[j] += f[i]
j += i
cnt = sum(f[i] == 1 for i in a)
print(cnt)
|
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A.sort()
A_max = A[-1]
dp = [1]*(A_max+1)
# dp[i] = 1: iはAのどの要素の倍数でもない
# dp[i] = 0: iはAの要素の倍数である
for a in A:
if not dp[a]:
continue
y = a*2
while y <= A_max:
dp[y] = 0
y += a
# Aの要素それぞれについて、dp[a] = 1ならよいが
# Aの要素ai,ajでai=ajとなる場合、上の篩では通過しているのに
# 条件を満たさない
cnt = dict(Counter(A))
ans = 0
for a in A:
if cnt[a] >= 2:
continue
if dp[a]:
ans += 1
print(ans)
| 1 | 14,353,543,823,450 | null | 129 | 129 |
ring = input()*2
words = input()
if words in ring:
print("Yes")
else:
print("No")
|
n = int(input())
def sieve1(n):
isPrime = [True] * (n+1)
isPrime[0] = False
isPrime[1] = False
for i in range(2*2, n+1, 2):
isPrime[i] = False
for i in range(3, n+1):
if isPrime[i]:
for j in range(i+i, n+1, i):
isPrime[j] = False
return isPrime
numOfDivisors = [2] * (n+1)
numOfDivisors[1] = 1
numOfDivisors[0] = 0
isPrime = sieve1(n)
for i in range(2, n+1):
if isPrime[i]:
for j in range(2*i, n+1, i):
x = j // i
numOfDivisors[j] += numOfDivisors[x] - 1
ans = 0
for k in range(1, n+1):
ans += numOfDivisors[k] * k
print (ans)
| 0 | null | 6,453,051,632,622 | 64 | 118 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
r = False
for i in range(1,10):
if n % i == 0:
if n // i < 10:
r = True
break
if r:
print('Yes')
else:
print('No')
|
import sys
N = int(sys.stdin.readline())
for i in range(1, 10):
for j in range(1, 10):
if i * j == N:
print("Yes")
sys.exit()
print("No")
| 1 | 160,181,830,907,290 | null | 287 | 287 |
# !/use/bin/python3
"""
https://atcoder.jp/contests/abc151/tasks/abc151_a
Next Alphabate
"""
def solve(c):
ans = ord(c)
return chr(ans+1)
if __name__ == "__main__":
c = input()
print(solve(c))
|
import sys
from collections import deque
n = int(sys.stdin.readline())
G = [[] for _ in range(n+1)]
G_order = []
for i in range(n-1):
a,b = map(lambda x:int(x)-1, sys.stdin.readline().split())
G[a].append(b)
G_order.append(b)
que = deque([0])
C = [0]*(n+1)
while que:
nw = que.popleft()
c = 1
for nx in G[nw]:
if c==C[nw]:
c+=1
C[nx] = c
c += 1
que.append(nx)
print(max(C))
for i in G_order:
print(C[i])
| 0 | null | 114,301,096,298,036 | 239 | 272 |
i = input()
i = i.split(" ")
i = list(map(int,i))
if i[0] < i[1]:
print("a < b")
elif i[0] > i[1]:
print("a > b")
elif i[0] == i[1]:
print("a == b")
|
a,b = input().split()
a = int(a)
b = int(b)
sign = "=="
if (a < b) : sign = "<"
if (a > b) : sign = ">"
print("a",sign,"b")
| 1 | 358,450,204,348 | null | 38 | 38 |
from sys import stdin
def ip(): return [int(i) for i in stdin.readline().split()]
def sp(): return [str(i) for i in stdin.readline().split()]
s = str(input())
c = 0
for i in s:
c += int(i)
if (c % 9) == 0: print("Yes")
else: print("No")
|
while True:
n,x = map(int,input().split())
if n==0 and x==0:
break
count=0
for a in range(1,n-1):
for b in range(a+1,n):
for c in range(b+1,n+1):
if a+b+c == x:
count += 1
print(count)
| 0 | null | 2,847,912,776,388 | 87 | 58 |
n=int(input())
li=list(map(int,input().split()))
dic={}
ans=0
for i in range(n):
val=dic.get(li[i],-1)
if val==-1:
dic[li[i]]=1
else:
dic[li[i]]=val+1
ans+=li[i]
q=int(input())
for i in range(q):
a,b=map(int,input().split())
val=dic.get(a,-1)
if val==-1 or val==0:
print(ans)
else:
nb=dic.get(b,-1)
if nb==-1:
dic[b]=val
else:
dic[b]=val+nb
ans+=(b-a)*val
dic[a]=0
print(ans)
|
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
S=[list(map(int,input().split())) for i in range(Q)]
l=[0]*10**6
total=0
for i in range(N) :
l[A[i]]+=1 #各数字の個数
total+=A[i] #初期総和
for i in range(Q) :
s0=S[i][0] #Bの値、交換した値
s1=S[i][1] #Cの値、交換する値
total+=s1*l[s0]-s0*l[s0]
l[s1]+=l[s0]
l[s0]=0
print(total)
| 1 | 12,186,867,474,340 | null | 122 | 122 |
a = '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'.split(', ')
print(a[int(input()) - 1])
|
M=[0,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]
K=int(input())
print(int(M[K]))
| 1 | 50,099,205,055,628 | null | 195 | 195 |
from collections import Counter
s=input()[::-1]
DP=[0]
num,point=0,1
for i in s:
num +=int(i)*point
num %=2019
DP.append(num)
point *=10
point %=2019
ans=0
DP=Counter(DP)
for v,m in DP.items():
if m>=2:
ans +=m*(m-1)//2
print(ans)
|
# https://atcoder.jp/contests/abc164/tasks/abc164_d
import sys
input = sys.stdin.readline
S = input().rstrip()
res = 0
T = [0]
x = 0
p = 1
L = len(S)
MOD = 2019
for s in reversed(S):
""" 累積和 """
x = (int(s)*p + x)%MOD
p = p*10%MOD
T.append(x)
reminder = [0]*2019
for i in range(L+1):
reminder[T[i]%MOD] += 1
for c in reminder:
res += c*(c-1)//2
print(res)
| 1 | 30,687,306,593,130 | null | 166 | 166 |
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)
|
s = input()
k = int(input())
n = len(s)
l = [1]*n
'''
S = set(s)
n1 = len(s)
n2 = len(S)
l = [0]*n1
for i in range(n2):
for j in range(n1):
temp = 0
chk = 0
if s[i] == s[j]:
l[chk] += 1
else:
chk += 1
'''
chk = 0
temp = 0
for i in range(n-1):
if s[i+1] == s[i]:
l[chk] += 1
else:
chk += 1
if s[0] == s[n-1]:
temp = 1
memo = 0
edge = 0
ans = 0
for i in range(n-1,-1,-1):
if l[i] != 1 and memo == 0 and temp == 1:
memo += 1
edge = i
ans += k*(l[i]//2)
if temp == 1 and edge != 0:
if (l[0] + l[edge]) % 2 == 0 and l[0] % 2 == 1:
ans += k-1
elif temp == 1:
if l[0] % 2 == 1:
ans += k//2
if n == 1:
ans = k//2
print(ans)
| 0 | null | 91,538,642,489,162 | 103 | 296 |
A,B=map(int,input().split())
if A>9 or B>9:
print(-1)
else:
print(A*B)
|
import sys
a, b = map(int, sys.stdin.readline().split())
if a <= 9 and b <= 9:
print(a*b)
else:
print(-1)
| 1 | 158,128,853,635,520 | null | 286 | 286 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
import numpy as np
n, m = map(int, readline().split())
a = np.array(read().split(), np.int64)
a.sort()
def check(mid):
mid = np.searchsorted(a, mid - a)
return n * n - mid.sum() >= m
left = 0
right = 10 ** 6
while left + 1 < right:
mid = (left + right) // 2
if check(mid):
left = mid
else:
right = mid
mid = np.searchsorted(a, right - a)
cumsum = np.zeros(n + 1, np.int64)
cumsum[1:] = np.cumsum(a)
ans = (cumsum[-1] - cumsum[mid]).sum() + (a * (n - mid)).sum() + (m - n * n + mid.sum()) * left
print(ans)
|
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
S = [0]*(n+1)
for i in range(n):
S[i+1] = S[i] + A[i]
def cnt(x,A,S):
res = 0
for i,a in enumerate(A):
res += bisect.bisect_left(A,x - a)
return res
def ans(x,A,S):
res = 0
for i,a in enumerate(A):
res += a*bisect.bisect_left(A,x-a) + S[bisect.bisect_left(A,x-a)]
return res
top = A[-1]*2+1
bottom = 0
# mid以上が何個あるか
while top - bottom > 1:
mid = (top + bottom)//2
if n*n - cnt(mid,A,S) > m:
bottom = mid
else:
top = mid
print(S[-1]*2*n - ans(top,A,S) + bottom*(m - (n*n - cnt(top,A,S))))
| 1 | 108,612,968,821,500 | null | 252 | 252 |
D=int(input())
c=list(map(int,input().split()))
s=[]
t=[]
v=0
lastday=[0 for i in range(26)]
for i in range(D):
tmp=list(map(int,input().split()))
s.append(tmp)
for i in range(D):
tmp=int(input())-1
t.append(int(tmp))
for i in range(1,D+1):
v+=s[i-1][t[i-1]]
lastday[t[i-1]]=i
for j in range(26):
v-=c[j]*(i-lastday[j])
print(v)
|
D = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(D):
s.append(list(map(int, input().split())))
t = []
for _ in range(D):
t.append(int(input()))
# last(d, i)を計算するためのメモ
dp = [0] * 26
def dec(d):
# d日の終わりに起こる満足度の減少計算の関数
s = 0
for j in range(26):
s += c[j] * (d - dp[j])
return s
# vは満足度
v = 0
for i in range(D):
# 初日の満足度
if (i == 0):
v += s[i][t[i] - 1]
# 開催されたコンテストの日付をメモ
dp[t[i] - 1] = (i + 1)
v -= dec(i + 1)
print(v)
continue
# elif (0 < i and i < D - 1):
v += s[i][t[i] - 1]
dp[t[i] - 1] = (i + 1)
v -= dec(i + 1)
print(v)
| 1 | 9,855,537,029,338 | null | 114 | 114 |
import math
n,m=map(int,input().split())
print(math.ceil(n/m))
|
import numpy as np
from numba import njit
@njit
def update(a):
n = len(a)
b = np.zeros_like(a)
for i,x in enumerate(a):
l = max(0, i-x)
r = min(n-1, i+x)
b[l] += 1
if r+1 < n:
b[r+1] -= 1
b = np.cumsum(b)
return b
n,k = map(int, input().split())
a = np.array(list(map(int, input().split())))
for _ in range(k):
a = update(a)
if np.all(a==n):
break
print(' '.join(map(str, a)))
| 0 | null | 46,246,142,694,150 | 225 | 132 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions 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
#
#
#
# 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
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())
l,r,d = readInts()
print(r//d - (l-1)//d)
|
l=list(map(int, input().split(' ')))
a=l[0]
v=l[1]
l=list(map(int, input().split(' ')))
b=l[0]
w=l[1]
s=int(input())
ans=True
if a>b:
ans=a-v*s<=b-w*s
else:
ans=a+v*s>=b+w*s
if ans:
print("YES")
else:
print("NO")
| 0 | null | 11,229,124,114,840 | 104 | 131 |
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int,input().split())))
cnt = 0
for i in range(N-2):
for j in range(i+1,N-1):
tmp = bisect_left(L,L[i]+L[j])
cnt += tmp - j - 1
print(cnt)
|
import sys
def main():
input = sys.stdin.readline
N,P = map(int, input().split())
S = input().rstrip()
D = list(map(int, S))
ans = 0
if P == 2:
for i, d in enumerate(D):
if d&1 == 0: ans += i + 1
return ans
if P == 5:
for i, d in enumerate(D):
if d == 0 or d == 5: ans += i + 1
return ans
A = [0] * P
num = Mint(0, P)
for i in range(N):
num += Mint(D[-1-i], P) * pow(10, i, P)
A[num.value] += 1
for a in A:
ans += a * (a-1) // 2
ans += A[0]
return ans
class Mint:
def __init__(self, value=0, mod=10**9+7):
self.value = ((value % mod) + mod) % mod
self.mod = mod
@staticmethod
def get_value(x): return x.value if isinstance(x, Mint) else x
def inverse(self):
a, b = self.value, self.mod
u, v = 1, 0
while b:
t = a // b
b, a = a - t * b, b
v, u = u - t * v, v
return (u + self.mod) % self.mod
def __repr__(self): return str(self.value)
def __eq__(self, other): return self.value == other.value
def __neg__(self): return Mint(-self.value, self.mod)
def __hash__(self): return hash(self.value)
def __bool__(self): return self.value != 0
def __iadd__(self, other):
self.value = (self.value + Mint.get_value(other)) % self.mod
return self
def __add__(self, other):
new_obj = Mint(self.value, self.mod)
new_obj += other
return new_obj
__radd__ = __add__
def __isub__(self, other):
self.value = (self.value - Mint.get_value(other) + self.mod) % self.mod
return self
def __sub__(self, other):
new_obj = Mint(self.value, self.mod)
new_obj -= other
return new_obj
def __rsub__(self, other):
new_obj = Mint(Mint.get_value(other), self.mod)
new_obj -= self
return new_obj
def __imul__(self, other):
self.value = self.value * Mint.get_value(other) % self.mod
return self
def __mul__(self, other):
new_obj = Mint(self.value, self.mod)
new_obj *= other
return new_obj
__rmul__ = __mul__
def __ifloordiv__(self, other):
other = other if isinstance(other, Mint) else Mint(other, self.mod)
self *= other.inverse
return self
def __floordiv__(self, other):
new_obj = Mint(self.value, self.mod)
new_obj //= other
return new_obj
def __rfloordiv__(self, other):
new_obj = Mint(Mint.get_value(other), self.mod)
new_obj //= self
return new_obj
if __name__ == '__main__':
ans = main()
print(ans)
| 0 | null | 115,468,608,524,220 | 294 | 205 |
h = int(input())
w = int(input())
n = int(input())
c = n // max(h,w)
if(n % max(h,w) != 0):c+=1
print(c)
|
from collections import defaultdict
MOD = 998244353
N,S = map(int,input().split())
A = map(int,input().split())
dp = [0]*(S+1)
dp[0] = 1
for a in A:
ndp = [0]*(S+1)
for total,cnt in enumerate(dp):
ndp[total] += dp[total]*2
ndp[total] %= MOD
if total+a <= S:
ndp[total+a] += dp[total]
ndp[total+a] %= MOD
dp = ndp
print(dp[-1]%MOD)
| 0 | null | 53,039,620,662,028 | 236 | 138 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.