code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
import numpy as np
D = int(input())
c = np.array( list(map(int, input().split())) )
#
s = [[] for i in range(D)]
for i in range(D):
s[i] = np.array( list(map(int, input().split())) )
#
v = 0
cc = np.array( [0]*26 )
last = np.array( [-1]*26 )
for d in range(D):
cc += c
av = s[d] - sum( cc ) + cc
av2 = av + cc*min((D-d-1),13)
m = max(av2)
for t in range(26):
if av2[t] == m:
cc[t] = 0
v += av[t]
print(t+1)
break
#
#print( v )
|
import random,time
def score(D,c,s,t):
v=list()
last=[0]*26
legacy=0
for i in range(D):
minus=0
v.append(legacy)
v[i]+=s[i][t[i]-1]
last[t[i]-1]=i+1
for j in range(26):
minus+=c[j]*(i+1-last[j])
v[i]-=minus
legacy=v[i]
return v[D-1]
time_sta = time.perf_counter()
s=list()
t=list()
D=int(input())
c=list(map(int,input().split()))
for i in range(D):
s.append(list(map(int,input().split())))
t=[random.randint(1,26)]*D
time_end=time.perf_counter()
tim=time_end-time_sta
while tim<1.9:
d=random.randint(1,D)
q=random.randint(1,26)
old=t[d-1]
oldscore=score(D,c,s,t)
t[d-1]=q
if score(D,c,s,t)<oldscore:
t[d-1]=old
time_end=time.perf_counter()
tim=time_end-time_sta
for i in range(D):
print(t[i])
| 1 | 9,716,485,360,596 | null | 113 | 113 |
N = int(input())
xs, ys = [], []
for _ in range(N):
x, y = map(int, input().split())
xs.append(x)
ys.append(y)
A = [x + y for x, y in zip(xs, ys)]
B = [x - y for x, y in zip(xs, ys)]
ans = max([max(A) - min(A), max(B) - min(B)])
print(ans)
|
while True:
a, b, c = map(int, input().split())
if a == -1 and b == -1 and c == -1:
break
if a == -1 or b == -1 or a + b < 30:
print("F")
elif a + b >= 80:
print("A")
elif a + b >= 65:
print("B")
elif a + b >= 50 or c >= 50:
print("C")
else:
print("D")
| 0 | null | 2,327,279,877,300 | 80 | 57 |
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
for i in range(N - 2):
if all(x == y for (x, y) in A[i:i+3]):
print('Yes')
break
else:
print('No')
|
n, u, v = map(int, input().split())
matrix = [[] for _ in range(n)]
import sys
sys.setrecursionlimit(10**8)
for _ in range(n-1):
a,b = map(int, input().split())
matrix[a-1].append(b-1)
matrix[b-1].append(a-1)
C = [0]*n
D = [0]*n
def dfs(x, pre, cnt, c):
c[x] = cnt
cnt += 1
for a in matrix[x]:
if a == pre:
continue
dfs(a, x, cnt, c)
dfs(v-1, -1, 0, C)
dfs(u-1, -1, 0, D)
ans=0
for i in range(n):
if C[i] > D[i]:
ans = max(ans, C[i]-1)
print(ans)
| 0 | null | 60,050,995,498,880 | 72 | 259 |
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N - 1, 1, -1):
for j in range(i - 1, 0, -1):
x = bisect.bisect(L, L[i] - L[j])
ans += max((j - x), 0)
print(ans)
|
N = int(input())
X = list(map(int, input().split()))
ans = 50 ** 2 * 100
for P in range(1,101):
sum = 0
for i in range(N):
sum += (X[i] - P) ** 2
if sum < ans:
ans = sum
print(ans)
| 0 | null | 118,690,357,520,680 | 294 | 213 |
import re
W = input()
T = []
count = 0
while(1):
line = input()
if (line == "END_OF_TEXT"):
break
words = list(line.split())
for word in words:
T.append(word)
for word in T:
matchOB = re.fullmatch(W, word.lower())
if matchOB:
count += 1
print(count)
|
search_s = input()
cnt = 0
while True:
s = input()
if s == "END_OF_TEXT": break
word_list = s.lower().split()
for word in word_list:
if word == search_s:cnt += 1
print(cnt)
| 1 | 1,824,222,990,980 | null | 65 | 65 |
#!/usr/bin/env python3
x,y = map(int,input().split())
if x == 1 and y == 1:
#if False:
print(10**6)
else:
print((max(0,4-x)+max(0,4-y))*(10**5))
|
x,y = list(map(int, input().split()))
ans=0
prize=[0, 300000, 200000, 100000, 0]
if x ==1 and y == 1:
print(1000000)
else:
print(prize[min(x,4)] + prize[min(y,4)])
| 1 | 140,241,402,537,900 | null | 275 | 275 |
#! /usr/bin/env python
# -*- coding: utf-8 -*-
height, width = map(int, raw_input().split())
print("%d %d") % (height * width, (height + width) * 2)
|
l = input()
l = l.split()
a = int(l[0])
b = int(l[1])
print(a*b,end=" ")
print(2*a + 2*b)
| 1 | 301,115,851,058 | null | 36 | 36 |
def gcd(a,b):
if(b==0):
return a
return gcd(b,a%b)
while True:
try:
a,b = map(int, input().split())
g = gcd(a,b)
print("%s %d"%(g,a/g*b))
except:
break
|
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def main():
N, X, M = NMI()
tmp = X%M
ls = []
ls.append(tmp)
for n in range(N-1):
tmp = (tmp ** 2)%M
if tmp in ls:
ls_before_loop = ls[:ls.index(tmp)]
ls_in_loop = ls[ls.index(tmp):]
break
else:
ls.append(tmp)
if len(ls) == N:
print(sum(ls))
else:
sum_before_loop = sum(ls_before_loop)
sum_in_loop = ((N-len(ls_before_loop))//(len(ls_in_loop)))*sum(ls_in_loop)
sum_after_loop = sum(ls_in_loop[:(N-((N-len(ls_before_loop))//(len(ls_in_loop)))*len(ls_in_loop))-len(ls_before_loop)])
print(sum_before_loop+sum_in_loop+sum_after_loop)
if __name__ == '__main__':
main()
| 0 | null | 1,383,125,481,412 | 5 | 75 |
import sys
def main():
input_str = sys.stdin.readline()
a, b, c = [int(i) for i in input_str.split(' ')]
if a < b & b < c:
print('Yes')
else:
print('No')
return
if __name__ == '__main__':
main()
|
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for i in range(M):
x, y, c = map(int, input().split())
p = a[x-1] + b[y-1] - c
if p < ans:
ans = p
print(ans)
| 0 | null | 27,232,935,980,794 | 39 | 200 |
n=int(input())
print('Yes' if n>=30 else 'No')
|
x=int(input())
if x>29:
print("Yes")
else:
print("No")
| 1 | 5,754,796,988,028 | null | 95 | 95 |
import bisect
n = int(input())
arr = list(map(int,input().split()))
arr.sort()
ans = 0
for i in range(n-2):
for j in range(i+1,n-1):
x = arr[i]+arr[j]
ind = bisect.bisect_left(arr,x)
ans+=(ind-j-1)
print(ans)
|
def have_ABC_string(n, str):
count = 0
for i in range(n-2):
if str[i] == 'A' and str[i+1] == 'B' and str[i+2] == 'C':
count += 1
return count
N = int(input())
S = input()
result = have_ABC_string(N, S)
print(result)
| 0 | null | 135,147,912,239,510 | 294 | 245 |
import collections
n,m = map(int,input().split())
g = [[] for i in range(n+1)]
for i in range(m):
a,b = map(int,input().split())
g[a].append(b)
g[b].append(a)
q = collections.deque()
q.append(1)
check = [0]*(n+1)
check[1] = 1
ans = [0]*(n+1)
while len(q)!=0:
v = q.popleft()
for j in g[v]:
if check[j] == 0:
check[j] = 1
ans[j] = v
q.append(j)
print('Yes')
for k in range(2,n+1):
print(ans[k])
|
from collections import deque
n, m = map(int, input().split())
eg = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = map(int, input().split())
eg[a].append(b)
eg[b].append(a)
xs = [0] * (n + 1)
q = deque()
q.append(1)
seen = {1}
while len(q) > 0:
v = q.popleft()
for t in eg[v]:
if t in seen:
continue
q.append(t)
seen.add(t)
xs[t] = v
print("Yes")
print(*xs[2:], sep="\n")
| 1 | 20,483,393,002,072 | null | 145 | 145 |
n, q = map(int, input().split())
array = [[s for s in input().split()] for i in range(n)]
total_time = 0
while len(array) != 0:
a = array.pop(0)
a_t = int(a[1])
if a_t - q <= 0:
total_time += a_t
a[1] = total_time
print(a[0], a[1])
else:
a[1] = a_t - q
array.append(a)
total_time += q
|
import sys
from collections import deque
def m():
s=sys.stdin.readlines()
q=int(s[0].split()[1])
f=lambda x,y:(x,int(y))
d=deque(f(*e.split())for e in s[1:])
t,a=0,[]
while d:
k,v=d.popleft()
if v>q:v-=q;t+=q;d.append([k,v])
else:t+=v;a+=[f'{k} {t}']
print('\n'.join(a))
if'__main__'==__name__:m()
| 1 | 41,015,351,818 | null | 19 | 19 |
n,m=map(int,input().split())
par=[i for i in range(n+1)]
def find(x):
if par[x] == x:
return x
else:
par[x] = find(par[x]) #経路圧縮
return par[x]
def same(x,y):
return find(x) == find(y)
def unite(x,y):
x = find(x)
y = find(y)
if x == y:
return 0
par[x] = y
for i in range(m):
a,b=map(int,input().split())
unite(a,b)
ans=[find(i) for i in range(1,n+1)]
ans=set(ans)
print(len(ans)-1)
|
import math
pages = int(input())
print(math.ceil(pages/2))
| 0 | null | 30,484,205,745,382 | 70 | 206 |
import math
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if abs(a-b) <= (v-w)*t :
print('YES')
else:
print('NO')
|
# いきぬきreview 忘れた問題
# gluttony
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
F.sort()
A.sort(reverse=True)
def func(X):
s = 0
for i in range(N):
a, f = A[i], F[i]
s += max(0, a-X//f)
return s <= K
R = 10**12
L = -1
while R-L > 1:
m = (R+L)//2
if func(m):
R = m
else:
L = m
print(R)
| 0 | null | 90,212,610,217,970 | 131 | 290 |
string = list(map(str, input()))
ans =[]
for char in string:
if char.islower():
ans.append(char.upper())
elif char.isupper():
ans.append(char.lower())
else:
ans.append(char)
print(ans[-1], end="")
print()
|
import re
stt = ""
line = input()
for i in range(len(line)):
if re.compile("[A-Z]").search(line[i]):
stt += line[i].lower()
elif re.compile("[a-z]").search(line[i]):
stt += line[i].upper()
else:
stt += line[i]
print(stt)
| 1 | 1,489,164,119,678 | null | 61 | 61 |
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
h,n = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
if h <= s:
print("Yes")
else:
print("No")
|
H,N=map(int,input().split())
attack = list(map(int,input().split()))
total = sum(attack)
if H - total <= 0:
print("Yes")
else:
print("No")
| 1 | 77,486,280,847,700 | null | 226 | 226 |
while True:
H,W = map(int, input().split())
if H==0 and W==0: break
for y in range(0,H):
for x in range(0,W):
if y%2==1:
if x%2==1: print("#",end="")
else: print(".",end="")
else:
if x%2==1: print(".",end="")
else: print("#",end="")
print()
print()
|
l=[chr(i) for i in range(97, 97+26)]
print( l[int(l.index(input()))+1] )
| 0 | null | 46,786,846,995,370 | 51 | 239 |
import sys
s, t = [line.rstrip("\n") for line in sys.stdin.readlines()]
if s == t[:-1]:
print("Yes")
else:
print("No")
|
f = [0 for i in range(0, 10001)]
for x in range(1,100):
for y in range(1,100):
for z in range(1,100):
n = x**2 + y**2 + z**2 + x*y + y*z + z*x
if n <= 10000:
f[n] += 1
N = int(input())
for n in range(1, N+1):
print(f[n])
| 0 | null | 14,756,571,698,518 | 147 | 106 |
N, K = map(int, input().split())
MOD = 10 ** 9 + 7
ans = 1
for i in range(K, N + 1):
ans += i * (2 * N - i + 1) // 2 % MOD - i * (i - 1) // 2 % MOD + 1
ans %= MOD
print(ans)
|
def search(S, n, t):
i=0
S[n]=t
while (S[i] != t):
i+=1
return i!=n
sum=0
n=int(input())
S=list(map(int, input().split()))
S.append([0]*10000)
q=int(input())
T=list(map(int, input().split()))
for i in range(0,q):
if search(S,n,T[i]):
sum+=1
print(sum)
| 0 | null | 16,635,218,304,760 | 170 | 22 |
# author: Taichicchi
# created: 19.09.2020 00:14:21
import sys
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N - 2):
for j in range(i + 1, N - 1):
try:
k = 2 * j - i
if (S[i] != S[j]) & (S[j] != S[k]) & (S[k] != S[i]):
ans -= 1
except:
continue
print(ans)
|
N=int(input())
S=str(input())
ans = S.count("R")*S.count("G")*S.count("B")
#print(ans)
for i in range(N-2):
for j in range(i+1,N-1):
k = 2*j-i
#print(i,j,k)
if k <= N-1:
if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
ans -= 1
print(ans)
| 1 | 36,014,785,777,860 | null | 175 | 175 |
INPUT = list(input().split())
a = int(INPUT[0])
b = int(INPUT[1])
if a == b:
print("Yes")
else:
print("No")
|
a, b, c, d = input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
def m():
if -1000000000<=a<=b<=1000000000 and -1000000000<=c<=d<=1000000000:
if a>=0 and d<=0:
max=a*d
print(max)
elif a>=0 and c>=0:
max=b*d
print(max)
elif b<=0 and c>=0:
max=b*c
print(max)
elif b<=0 and d<=0:
max=a*c
print(max)
elif a<=0 and b>=0 and c<=0 and d>=0:
if a*c>=b*d:
max=a*c
print(max)
else:
max=b*d
print(max)
elif a>=0 and c<=0 and d>=0:
max=b*d
print(max)
elif b<=0 and c<=0 and d>=0:
max=a*c
print(max)
elif a<=0 and b>=0 and c>=0:
max=b*d
print(max)
elif a<=0 and b>=0 and d<=0:
max=a*c
print(max)
m()
| 0 | null | 43,419,149,615,490 | 231 | 77 |
# coding: utf-8
# Your code here!
import math
r = int(input())
print(math.floor(r * r))
|
from sys import stdin
r = int(stdin.readline().rstrip())
print(r**2)
| 1 | 145,258,441,167,480 | null | 278 | 278 |
n, p = map(int, input().split())
s = input()
if 10%p==0:
ans = 0
for r in range(n):
if int(s[r])%p == 0:
ans += r+1
print(ans)
exit()
d = [0]*(n+1)
ten = 1
for i in range(n-1, -1, -1):
a = int(s[i])*ten%p
d[i] = (d[i+1]+a)%p
ten *= 10
ten %= p
cnt = [0]*p
ans = 0
for i in range(n, -1, -1):
ans += cnt[d[i]]
cnt[d[i]] += 1
print(ans)
|
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
print(sum(map(lambda p: p>=k, nums)))
| 0 | null | 118,817,361,671,360 | 205 | 298 |
n = int(input())
dna = set()
for i in range(n):
command = input().split()
if command[0] == 'insert':
dna.add(command[1])
else:
print('yes' if command[1] in dna else 'no')
|
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 30 13:14:10 2018
ALDS1-4c implementation with dictionary
@author: maezawa
"""
n = int(input())
a = dict([])
for s in range(n):
cmd, word = input().split()
if cmd == 'insert':
a[word]=''
else:
if word in a:
print('yes')
else:
print('no')
| 1 | 73,657,151,670 | null | 23 | 23 |
s = input()
if s == "SSS":
print("0")
elif s == "RRS" or s == "SRR":
print("2")
elif s == "RRR":
print("3")
else:
print("1")
|
class BalancingTree:
"""平衡二分木のクラス
Pivotを使った実装.
0以上2^n - 2以下の整数を扱う
"""
def __init__(self, n):
"""
2の指数nで初期化
"""
self.N = n
self.root = self.node(1<<n, 1<<n)
def debug(self):
"""デバッグ用の関数"""
def debug_info(nd_):
return (nd_.value - 1, nd_.pivot - 1, nd_.left.value - 1 if nd_.left else -1, nd_.right.value - 1 if nd_.right else -1)
def debug_node(nd):
re = []
if nd.left:
re += debug_node(nd.left)
if nd.value: re.append(debug_info(nd))
if nd.right:
re += debug_node(nd.right)
return re
print("Debug - root =", self.root.value - 1, debug_node(self.root)[:50])
def append(self, v):
"""
v を追加(その時点で v はない前提)
"""
v += 1
nd = self.root
while True:
if v == nd.value:
# v がすでに存在する場合に何か処理が必要ならここに書く
return 0
else:
mi, ma = min(v, nd.value), max(v, nd.value)
if mi < nd.pivot:
nd.value = ma
if nd.left:
nd = nd.left
v = mi
else:
p = nd.pivot
nd.left = self.node(mi, p - (p&-p)//2)
break
else:
nd.value = mi
if nd.right:
nd = nd.right
v = ma
else:
p = nd.pivot
nd.right = self.node(ma, p + (p&-p)//2)
break
def leftmost(self, nd):
if nd.left: return self.leftmost(nd.left)
return nd
def rightmost(self, nd):
if nd.right: return self.rightmost(nd.right)
return nd
def find_l(self, v):
"""
vより真に小さいやつの中での最大値(なければ-1)
"""
v += 1
nd = self.root
prev = 0
if nd.value < v: prev = nd.value
while True:
if v <= nd.value:
if nd.left:
nd = nd.left
else:
return prev - 1
else:
prev = nd.value
if nd.right:
nd = nd.right
else:
return prev - 1
def find_r(self, v):
"""
vより真に大きいやつの中での最小値(なければRoot)
"""
v += 1
nd = self.root
prev = 0
if nd.value > v: prev = nd.value
while True:
if v < nd.value:
prev = nd.value
if nd.left:
nd = nd.left
else:
return prev - 1
else:
if nd.right:
nd = nd.right
else:
return prev - 1
@property
def max(self):
"""最大値の属性"""
return self.find_l((1<<self.N)-1)
@property
def min(self):
"""最小値の属性"""
return self.find_r(-1)
def delete(self, v, nd = None, prev = None):
"""
値がvのノードがあれば削除(なければ何もしない)
"""
v += 1
if not nd: nd = self.root
if not prev: prev = nd
while v != nd.value:
prev = nd
if v <= nd.value:
if nd.left:
nd = nd.left
else:
return
else:
if nd.right:
nd = nd.right
else:
return
if (not nd.left) and (not nd.right):
if nd.value < prev.value:
prev.left = None
else:
prev.right = None
elif not nd.left:
if nd.value < prev.value:
prev.left = nd.right
else:
prev.right = nd.right
elif not nd.right:
if nd.value < prev.value:
prev.left = nd.left
else:
prev.right = nd.left
else:
nd.value = self.leftmost(nd.right).value
self.delete(nd.value - 1, nd.right, nd)
def __contains__(self, v: int) -> bool:
return self.find_r(v - 1) == v
class node:
"""ノードをあらわすクラス
v: 値
p: ピボット値
で初期化
"""
def __init__(self, v, p):
self.value = v
self.pivot = p
self.left = None
self.right = None
Trees = [BalancingTree(50) for _ in range(26)]
N = int(input())
S = input()
Q = int(input())
alphabets = list("abcdefghijklmnopqrstuvwxyz")
c2n = {c: i for i, c in enumerate(alphabets)}
for i in range(N):
Trees[c2n[S[i]]].append(i+1)
S = list(S)
for _ in range(Q):
tmp = list(input().split())
if tmp[0] == "1":
_, i, c = tmp
i = int(i)
bef = S[i-1]
if bef == c:
continue
Trees[c2n[bef]].delete(i)
Trees[c2n[c]].append(i)
S[i-1] = c
else:
_, l, r = tmp
l = int(l)
r = int(r)
ans = 0
for char in range(26):
res = Trees[char].find_r(l-1)
if l <= res <= r:
ans += 1
print(ans)
| 0 | null | 33,883,791,363,174 | 90 | 210 |
def main():
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
sorted_p = sorted(p, reverse=True)[:X]
sorted_q = sorted(q, reverse=True)[:Y]
sorted_r = sorted(r, reverse=True)
p_itr, q_itr, r_itr = X-1, Y-1, 0
while r_itr < C:
look_p = sorted_p[p_itr]
look_q = sorted_q[q_itr]
look_r = sorted_r[r_itr]
if look_p <= look_q and p_itr >=0:
if look_p <= look_r:
sorted_p[p_itr] = look_r
p_itr -= 1
r_itr += 1
else:
break
elif q_itr >= 0:
if look_q <= look_r:
sorted_q[q_itr] = look_r
q_itr -= 1
r_itr += 1
else:
break
else:
break
res = sum(sorted_p) + sum(sorted_q)
print(res)
if __name__ == "__main__":
main()
|
X,Y,A,B,C = map(int,input().split())
AList = sorted(list(map(int,input().split())),reverse=True)
BList = sorted(list(map(int,input().split())),reverse=True)
CList = sorted(list(map(int,input().split())),reverse=True)
FullList = sorted(AList[:X] + BList[:Y])
counter = 0
for i in range(min(C,X+Y)):
if CList[i] <= FullList[i]:
break
else:
counter += 1
ans = sum(CList[:counter])+sum(FullList[counter:])
print(ans)
| 1 | 44,644,299,476,256 | null | 188 | 188 |
x = int(input())
for i in range(1,121):
for j in range(-121,121):
if x == i**5 - j**5:
print(i,j)
exit()
|
import math
def fact(n):
ans = 1
for i in range(2, n+1):
ans*= i
return ans
def comb(n, c):
return fact(n)//(fact(n-c)*c)
x = int(input())
a = 0
b = 0
done = False
for f in range(-300, 300):
for l in range(-300, 300):
if((f**5)-(l**5)==x):
a = f
b = l
done = True
break
if(done):
break
print(a,b)
| 1 | 25,724,535,888,480 | null | 156 | 156 |
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_9_D
def reverse(s, a, b):
s1 = s[0:a]
s2 = s[a:b+1]
s2 = s2[::-1]
s3 = s[b+1:len(string)]
return s1 + s2 + s3
def replace(s, a, b, p):
s1 = s[0:a]
s2 = p
s3 = s[b+1:len(string)]
return s1 + s2 + s3
string = input()
q = int(input())
for _ in range(q):
c = input().split()
if c[0] == "print":
print(string[int(c[1]):int(c[2])+1])
if c[0] == "reverse":
string = reverse(string, int(c[1]), int(c[2]))
if c[0] == "replace":
string = replace(string, int(c[1]), int(c[2]), c[3])
|
import math
A, B = input().split()
A = int(A)
B = float(B)
B = int(B * 100 + 1e-5)
res = int(math.floor((A * B) // 100))
print(res)
| 0 | null | 9,351,581,321,668 | 68 | 135 |
K = int(input())
if K % 2 == 0 or K % 5 == 0:
print(-1)
exit()
i = 0
ai = 0
while True:
ai = (ai * 10 + 7) % K
i += 1
if ai == 0:
break
print(i)
|
import sys
k = int(input())
a = dict()
cnt = 0
base = 0
while True:
cnt += 1
base = (base*10+7)%k
if base == 0:
break
if base in a:
cnt = -1
break
else:
a[base] = 1
print(cnt)
| 1 | 6,156,121,857,640 | null | 97 | 97 |
import sys
sys.setrecursionlimit(300000)
from math import sqrt, ceil
from collections import defaultdict
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')
N = I()
n = ceil(sqrt(N))
d = defaultdict(int)
for x in range(1, n + 1):
for y in range(1, n + 1):
for z in range(1, n + 1):
a = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
if a <= N:
d[a] += 1
for i in range(1, N + 1):
print(d[i])
|
print(1-int(input()))
| 0 | null | 5,433,290,921,672 | 106 | 76 |
A, B, N = map(int, input().split())
from math import floor
if B - 1 <= N:
x = B - 1
else:
x = N
print(floor(A*x/B) - A*floor(x/B))
|
A,B,N=map(int,input().split())
# A,B,N=11, 10, 5
ans=0
if N>=B:
ans=(A*(B-1))//B - A*((B-1)//B)
else:
ans=(A*N)//B - A*(N//B)
print(ans)
| 1 | 28,192,448,203,760 | null | 161 | 161 |
A,B,C=[int(s) for s in input().split()]
X=int(input())
count=0
while A>=B:
B*=2
count+=1
while B>=C:
C*=2
count+=1
if count<=X:
print('Yes')
else:
print('No')
|
#
# m_solutions2020 b
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """7 2 5
3"""
output = """Yes"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """7 4 2
3"""
output = """No"""
self.assertIO(input, output)
def resolve():
A, B, C = map(int, input().split())
K = int(input())
for i in range(K):
if A >= B:
B *= 2
elif B >= C:
C *= 2
if A < B < C:
print("Yes")
break
else:
print("No")
if __name__ == "__main__":
# unittest.main()
resolve()
| 1 | 6,864,056,618,976 | null | 101 | 101 |
S = input()
s_rev = S[::-1]
r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
num += d*int(s_rev[i])
num %= 2019
r_list[num] += 1
d *= 10
d %= 2019
ans = 0
for i in range(2019):
ans += r_list[i]*(r_list[i]-1)//2
print(ans)
|
import sys
heights = sorted([int(h) for h in sys.stdin], reverse=True)
print(heights[0])
print(heights[1])
print(heights[2])
| 0 | null | 15,537,066,530,762 | 166 | 2 |
n,k = map(int,input().split())
h = sorted(map(int,input().split()),reverse=True)
print(sum(h[k:]))
|
N,K=list(map(int, input().split()))
H=list(map(int, input().split()))
if K>=N:
print(0)
exit()
H.sort(reverse=True)
H=H[K:]
print(sum(H))
| 1 | 78,792,163,007,216 | null | 227 | 227 |
def prepare(n, MOD):
# 1! - n! の計算
f = 1
factorials = [1] # 0!の分
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
# n!^-1 の計算
inv = pow(f, MOD - 2, MOD)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return factorials, invs
def main():
n,k=map(int, input().split())
A=[int(i) for i in input().split()]
MOD = 10**9 + 7
fac, invs = prepare(n,MOD)
ans = 0
A.sort()
for i in range(n):
tmp=0
tmp2=0
if i<n-k+1:
tmp = (fac[n-(i+1)]%MOD * invs[k-1]%MOD * invs[n-(i+1) - (k-1)]%MOD)%MOD
if i>=k-1:
tmp2 = (fac[i]%MOD * invs[k-1]%MOD * invs[i-(k-1)]%MOD)%MOD
#print("最大になる回数", tmp2, " 最小になる回数", tmp, "A[i]", A[i])
ans = ans%MOD + (tmp2*A[i]%MOD - tmp*A[i]%MOD)%MOD
ans%=MOD
if k==1:
ans = 0
print(ans)
if __name__ == '__main__':
main()
|
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")
n,m = I()
g = [[] for _ in range(n)]
for i in range(m):
a,b = I()
g[a-1].append(b-1)
g[b-1].append(a-1)
q = deque([0])
d = [-1]*n
d[0] = 0
while q:
v = q.popleft()
for i in g[v]:
if d[i] != -1:
continue
d[i] = v
q.append(i)
if -1 in d:
print("No")
else:
print("Yes")
for i in d[1:]:
print(i+1)
| 0 | null | 58,043,651,965,134 | 242 | 145 |
N = int(input())
A = list(map(int, input().split()))
if 0 in A:
print(0)
exit()
prod = 1
for a in A:
prod *= a
if prod > 1e18:
print(-1)
exit()
print(prod)
|
import math
pi=math.pi
a,b,si=map(float,input().split())
S=(1/2)*a*b*math.sin(math.radians(si))
c2=a*a+b*b-2*a*b*math.cos(math.radians(si))
L=a+b+math.sqrt(c2)
h=(2*S)/a
print(S)
print(L)
print(h)
| 0 | null | 8,189,517,171,452 | 134 | 30 |
a, b, c= map(int, input().split())
if a<b<c:print( "Yes")
else :print ("No")
|
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque
x = int(stdin.readline().rstrip())
for i in range(-150,150):
for j in range(-150,150):
if i**5-j**5 == x: print(i,j); sys.exit()
| 0 | null | 12,930,238,709,498 | 39 | 156 |
a,b,c=list(map(int,input().split()))
print(c,a,b)
|
a,b = map(int, input().split())
area = a * b
dis = a*2 + b*2
print(area, dis)
| 0 | null | 19,140,876,231,218 | 178 | 36 |
import itertools
N = int(input())
L = list(map(int,(input().split())))
Combination = list(itertools.permutations(L, 3))
count = 0
for i in Combination:
# a+b>c かつ b+c>a かつ c+a>b
a = int(i[0])
b = int(i[1])
c = int(i[2])
if((a+b)> c and (b+c) >a and (c+a) >b and a!=b and b!= c and a!= c and a<b and b<c):
count+=1
print(count)
|
def solve():
N = int(input())
L = list(map(int, input().split()))
count = 0
for i in range(N):
for j in range(i+1, N):
for k in range(j+1, N):
if(L[i] != L[j] and L[j] != L[k] and L[k] != L[i]):
if(L[i]+L[j] > L[k] and L[j]+L[k] > L[i] and L[k]+L[i] > L[j]):
count += 1
print(count)
if __name__ == "__main__":
solve()
| 1 | 5,050,935,074,548 | null | 91 | 91 |
from functools import lru_cache
@lru_cache(maxsize=None)
def solve(n):
if n == 1:
return 1
else:
return solve(n//2) * 2 + 1
H = int(input())
print(solve(H))
|
n = int(input())
seq = list(map(int, input().split()))
q = int(input())
mlist = list(map(int, input().split()))
mins = min(seq)
sums = 0
for a in seq:
sums += a
def check(i, m):
global mins
if m == 0:
return True
elif i >= n or mins > m:
return False
res = check(i+1, m) or check(i+1, m - seq[i])
return res
for m in mlist:
if (mins > m or sums < m):
print('no')
elif(check(0,m)):
print('yes')
else:
print('no')
| 0 | null | 40,318,027,108,294 | 228 | 25 |
N=int(input())
D=list(map(int,input().split()))
MOD=998244353
if D[0]!=0:
print(0)
exit()
b=[0]*N
for d in D:
b[d]+=1
if b[0]!=1:
print(0)
exit()
cnt=1
#print(b)
#print(b[1:])
for v1,v2 in zip(b,b[1:]):
#print(v1)
#print(v2)
cnt *= v1**v2 % MOD
print(cnt%MOD)
|
def main():
n = int(input())
d = list(map(int,input().split()))
mod = 998244353
if d[0]!=0:
print(0)
return
D = {0:1}
for i in range(1,n):
if d[i]==0:
print(0)
return
if D.get(d[i]) == None:
D[d[i]] = 1
else:
D[d[i]] += 1
ans = 1
if sorted(D.keys())[-1]!=len(D.keys())-1:
print(0)
return
for k in range(1,len(D.keys())):
ans *= pow(D[k-1],D[k],mod)
ans = ans % mod
print(ans)
if __name__ == "__main__":
main()
| 1 | 154,824,956,865,790 | null | 284 | 284 |
n, k = map(int, input().split(" "))
MOD = (10**9) + 7
def dSum(s, e):
s -= 1
_s = s * (s + 1) // 2
_e = e * (e + 1) // 2
return _e - _s
ans = 0
for i in range(k, n + 1):
# _sum = dSum(n - i - 1, n) - dSum(0, i - 1) + 1
ans += dSum(i, n) - dSum(0, n - i) + 1
print((ans + 1) % MOD)
|
import itertools
N, K = map(int, input().split())
N_acum = list(itertools.accumulate(range(N+1)))
mod = 10**9+7
ans = 0
for i in range(K, N+1):
ans += (N_acum[-1] - N_acum[-(i+1)]) - N_acum[i-1] + 1
ans %= mod
ans = (ans+1)%mod
print(ans)
| 1 | 33,225,274,465,624 | null | 170 | 170 |
# coding: utf-8
# Here your code !
def func():
data=[]
while(True):
try:
line=[ int(item) for item in input().rstrip().split(" ") ]
if(line == [0,0]):
break
data.append(line)
except EOFError:
break
except:
return inputError()
left=1
numbers=3
[print(len(sumcombination(left,line[0],numbers,line[1]))) for line in data]
def sumcombination(left,right,numbers,total):
'''
left ~ right??????????????°??????(numbers)????????´??°???????¨????total?????????????????????????????????????????????
'''
result=[]
if(numbers==1):
if( (left <= total) and (right >= total) ):
result=[total]
return(result)
for i in range(left,right+1):
if( numbers == 2):
if(i >= total-i):
break
elif( (i != total-i) and (left <= total-i) and (right >= total-i) ):
result.append([i,total-i])
elif( ( len( range(i,right+1) ) < numbers ) or ( sum( range(i+1,i+numbers) ) > total-i ) ):
break
elif( sum( range(right-numbers+2,right+1) ) < total-i ):
continue
else:
sub = sumcombination(i+1,right,numbers-1,total-i)
if(len(sub)>0):
[items.insert(0,i) for items in sub]
result.extend(sub)
return(result)
def inputError():
print("input error")
return -1
func()
|
def main():
MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
ans = 1
d = [0] * (max(A) + 1)
for a in A:
if a == 0:
ans *= 3 - d[a]
ans %= MOD
d[a] += 1
else:
ans *= d[a-1] - d[a]
d[a] += 1
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 65,560,416,071,282 | 58 | 268 |
n = int(input())
a = ["a","b","c","d","e","f","g","h","i","j"]
def dfs(s):
m = len(s)
if m == n:
ans = ""
for i in range(n):
ans += a[int(s[i])]
print(ans)
else:
for i in range(int(max(list(s)))+2):
dfs(s+str(i))
dfs("0")
|
import math
def koch(d,p1x,p1y,p2x,p2y):
if d == 0:
return 0
sin = math.sin(math.radians(60))
cos = math.cos(math.radians(60))
ax = (2 * p1x + 1 * p2x)/3
ay = (2 * p1y + 1 * p2y)/3
bx = (1 * p1x + 2 * p2x)/3
by = (1 * p1y + 2 * p2y)/3
ux = (bx - ax)* cos - (by - ay)*sin + ax
uy = (bx - ax)* sin + (by - ay)*cos + ay
koch(d-1,p1x,p1y,ax,ay)
print(ax,ay)
koch(d-1,ax,ay,ux,uy)
print(ux,uy)
koch(d-1,ux,uy,bx,by)
print(bx,by)
koch(d-1,bx,by,p2x,p2y)
d = int(input())
print(0,0)
koch(d,0,0,100,0)
print(100,0)
| 0 | null | 26,151,075,239,568 | 198 | 27 |
N = int(input())
def func(x):
if len(x) == N:
print("".join(x))
return
last = ord(max(x)) - ord("a") + 1 if x else 0
for i in range(min(26, last) + 1):
x.append(chr(ord("a") + i))
func(x)
x.pop()
func([])
|
import itertools
n=[x for x in range(1,int(input())+1)]
P=list(map(int, input().split()))
Q=list(map(int, input().split()))
for i, a in enumerate(itertools.permutations(n), start=1):
if list(a)==P:
p=i
if list(a)==Q:
q=i
print(abs(p-q))
| 0 | null | 76,563,664,772,980 | 198 | 246 |
n , k , c = map(int,input().split())
s = input()
L = []
R = []
i = 0
j = n-1
while i<n and len(L)<k :
if s[i] == "o" :
L.append(i)
i += c
i += 1
while j>-1 and len(R)<k :
if s[j] == "o" :
R.append(j)
j -= c
j -= 1
R.reverse()
for x in range(k):
if R[x] == L[x]:
print(R[x]+1)
|
cards = {
"S": [0 for n in range(13)],
"H": [0 for n in range(13)],
"C": [0 for n in range(13)],
"D": [0 for n in range(13)]
}
t = int(input())
for n in range(t):
a,b = input().split()
cards[a][int(b)-1] = 1
for a in ("S", "H","C", "D"):
for b in range(13):
if cards[a][b] == 0:
print(a,b+1)
| 0 | null | 20,883,547,222,250 | 182 | 54 |
a, b = input().split()
a = int(a)
b = round(100*float(b))
ans = a*b
print(int(ans//100))
|
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
a,b = input().split()
b = b[:-3] + b[-2:]
ans = int(a) * int(b)
ans = ans // 100
print(ans)
| 1 | 16,541,253,887,382 | null | 135 | 135 |
n = int(input())
list = [[0 for i in range(10)] for j in range(12)]
for i in range(n):
b,f,r,v = map(int,input().split())
list[3*(b - 1)+(f - 1)][r - 1] += v
for i in range(12):
if i % 3 == 0 and i != 0:
print('####################')
for j in range(10):
print(' {}'.format(list[i][j]),end = "")
if j == 9:
print('')
|
if __name__ == '__main__':
nums = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
n = int(input())
for i in range(n):
b, f, r, v = [int(i) for i in input().split()]
nums[b-1][f-1][r-1] += v
for b in range(4):
for f in range(3):
print(' ' + ' '.join([str(i) for i in nums[b][f]]))
if b == 3: break
print('#'*20)
| 1 | 1,088,675,996,540 | null | 55 | 55 |
a, b = input().split()
if a < b:
print(a * int(b))
elif a > b:
print(b * int(a))
else:
print(a * int(a))
|
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 1
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
a,b = I()
A = str(a)*b
B = str(b)*a
print(min(A,B))
| 1 | 84,179,567,886,570 | null | 232 | 232 |
from itertools import permutations
import math
N = int(input())
l = [list(map(int, input().split())) for i in range(N)]
waru = 1
for i in range(N):
waru*= i+1
a = [i+1 for i in range(N)]
c = 0
su = 0
for i in permutations(a,N):
li = list(i)
for j in range(len(li)-1):
start = l[li[j]-1]
g = l[li[j+1]-1]
su += math.sqrt((start[0]-g[0]) ** 2 + (start[1]-g[1]) ** 2)
print(su/waru)
|
n = int(input())
a = [list(map(int,input().split())) for i in range(n)]
sum = 0
for i in range(n):
for j in range(i+1,n):
sum += ((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)**0.5
print(2*sum/n)
| 1 | 148,700,548,559,478 | null | 280 | 280 |
from collections import deque
import sys
def bfs(graph, N, start):
visited = [0] * N
visited[start] = 1
que = deque([start])
while que:
node = que.popleft()
for n in graph[node]:
if not visited[n]:
visited[n] = node + 1
que.append(n)
return visited
input = sys.stdin.readline
def main():
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for i in range(M):
A, B = map(lambda n: int(n) - 1, input().split())
graph[A].append(B)
graph[B].append(A)
visited = bfs(graph, N, 0)[1:]
if all(visited):
print("Yes")
print(*visited, sep="\n")
else:
print("No")
main()
|
from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
graph[a - 1].append(b - 1)
graph[b - 1].append(a - 1)
ans = [-1] * (n - 1)
q = deque()
q.append(0)
used = {0}
while q:
node = q.popleft()
for next_node in graph[node]:
if next_node in used:
continue
q.append(next_node)
used.add(next_node)
ans[next_node - 1] = node + 1
print('Yes')
print(*ans, sep='\n')
| 1 | 20,560,148,281,060 | null | 145 | 145 |
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, combinations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from operator import itemgetter
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7
DEBUG = 'ONLINE_JUDGE' not in sys.argv
def meg(f, ok, ng):
while abs(ok-ng)>1:
mid = (ok+ng)//2
if f(mid):
ok=mid
else:
ng=mid
return ok
def get_inv(n, modp):
return pow(n, modp-2, modp)
def factorials_list(n, modp): # 10**6
fs = [1]
for i in range(1, n+1):
fs.append(fs[-1] * i % modp)
return fs
def invs_list(n, fs, modp): # 10**6
invs = [get_inv(fs[-1], modp)]
for i in range(n, 1-1, -1):
invs.append(invs[-1] * i % modp)
invs.reverse()
return invs
def comb(n, k, modp):
num = 1
for i in range(n, n-k, -1):
num = num * i % modp
den = 1
for i in range(2, k+1):
den = den * i % modp
return num * get_inv(den, modp) % modp
def comb_from_list(n, k, modp, fs, invs):
return fs[n] * invs[n-k] * invs[k] % modp
#
class UnionFindEx:
def __init__(self, size):
#正なら根の番号、負ならグループサイズ
self.roots = [-1] * size
def getRootID(self, i):
r = self.roots[i]
if r < 0: #負なら根
return i
else:
r = self.getRootID(r)
self.roots[i] = r
return r
def getGroupSize(self, i):
return -self.roots[self.getRootID(i)]
def connect(self, i, j):
r1, r2 = self.getRootID(i), self.getRootID(j)
if r1 == r2:
return False
if self.getGroupSize(r1) < self.getGroupSize(r2):
r1, r2 = r2, r1
self.roots[r1] += self.roots[r2] #サイズ更新
self.roots[r2] = r1
return True
Yes = 'Yes'
No = 'No'
def dprint(*args, **kwargs):
if DEBUG:
print(*args, **kwargs)
def main():
N, K = mis()
P = list(map(lambda x: x-1, mis()))
C = lmis()
ans = -INF
for i in range(N):
p = i
tmp_score = 0
k = K
cycle = 0
while k:
p = P[p]
tmp_score += C[p]
ans = max(ans, tmp_score)
k -= 1
cycle += 1
if p==i:
if tmp_score < 0:
break
elif k > cycle*2:
skip_loop = (k - cycle)//cycle
tmp_score *= skip_loop + 1
k -= skip_loop * cycle
ans = max(ans, tmp_score)
print(ans)
main()
|
# -*- coding: utf-8 -*-
import sys
from itertools import accumulate
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = map(int, readline().split())
P = [0] + list(map(int,readline().split()))
C = [0] + list(map(int,readline().split()))
ans = -10 ** 10
for i in range(1,N+1):
l = 1
j = P[i]
s = C[j]
ans = max(ans, s) #iを始まりとして
while j != i: # 1周期もしないときの最大値
j = P[j]
s += C[j]
l += 1
if K >= l:
ans = max(ans, s)
c = 1
j = P[j]
t = C[j]
ans = max(ans, t + ((K - c) // l) * s) # 1回と周期分
while j != i:
j = P[j]
t += C[j]
c += 1
if K >= c:
ans = max(ans, t + ((K - c) // l) * s) # c回と周期分
print(ans)
| 1 | 5,384,024,103,558 | null | 93 | 93 |
s = input()
p = input()
s *= 2
if p in s:
print('Yes')
else:
print('No')
|
import sys
if __name__ == '__main__':
a, b, c = map(int, input().split())
print(c, a, b)
| 0 | null | 19,815,679,528,832 | 64 | 178 |
def main():
N = int(input())
for i in range(1, 10):
if N // i < 10 and N % i == 0:
print('Yes')
return
print('No')
main()
|
n = int(input())
if n < 10:
print("Yes")
exit(0)
for i in range(2, 10):
if n % i != 0:
continue
v = n // i
if v < 10:
print("Yes")
exit(0)
print("No")
| 1 | 159,775,574,188,118 | null | 287 | 287 |
i = 0
while True:
x = int(input()); i += 1
if x == 0:
break
print("Case {}: {}".format(i, x))
|
ii = 1
while True:
x = input()
if x == '0':
break
print("Case {0}: {1}".format(ii, x))
ii = ii + 1
| 1 | 478,511,895,040 | null | 42 | 42 |
def solve():
def combis(n, k, mod):
from math import factorial
numerator = 1
denominator = 1
for i in range(k):
numerator = numerator * (n-i) % mod
denominator = denominator * (i+1) % mod
return numerator * pow(denominator, mod-2, mod) % mod
n,a,b = [int(i) for i in input().split()]
mod = 10**9 + 7
ans = pow(2, n, mod) - 1 - combis(n, a, mod) - combis(n, b, mod)
print(ans % mod)
if __name__ == "__main__":
solve()
|
def power(x, y, p) :
res = 1 # Initialize result
# Update x if it is more
# than or equal to p
x = x % p
if (x == 0) :
return 0
while (y > 0) :
# If y is odd, multiply
# x with result
if ((y & 1) == 1) :
res = (res * x) % p
# y must be even now
y = y >> 1 # y = y/2
x = (x * x) % p
return res
def ncr(n, r, p):
# initialize numerator
# and denominator
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den, p - 2, p)) % p
n,a,b=map(int,input().split())
m=10**9+7;
ans=power(2,n,m)
ans-=ncr(n,a,m)
ans-=ncr(n,b,m)
print(ans%m-1)
| 1 | 66,143,095,077,528 | null | 214 | 214 |
n,nWorks,nSp = map(int,input().split())
s = input()
leftList = [0]*n
rightList = [0]*n
num = 0
count = 0
while num < n:
if s[num] == "o":
leftList[num] = 1
count +=1
num += 1 + nSp
else:
num +=1
if count > nWorks:
exit()
num = n-1
count = 0
while num >= 0:
if s[num] == "o":
rightList[num] = 1
count +=1
num -= (1 + nSp)
else:
num -=1
for kk in range(n):
if leftList[kk] and rightList[kk]:
print(kk+1)
|
n,k,c = map(int,raw_input().split())
s = raw_input()
most = [0]*(n+1)
i = n
days = 0
while i > 0:
if s[i-1] == 'o':
days += 1
for j in xrange(min(max(1,c),i-1)):
#print days
#print i,j,1,days
most[i-j-1] = days
i -= (c+1)
else:
i -= 1
if i<n:
most[i] = most[i+1]
remain = k
i = 1
while i<=n:
if s[i-1] == 'o':
if most[i] < remain:
print i
remain -= 1
i += c+1
else:
i += 1
| 1 | 40,683,891,884,932 | null | 182 | 182 |
n=int(input())
p=10**9+7
A=list(map(int,input().split()))
binA=[]
for i in range(n):
binA.append(format(A[i],"060b"))
lis=[0 for i in range(60)]
for binAi in binA:
for j in range(60):
lis[j]+=int(binAi[j])
binary=[0 for i in range(60)]
for i in range(n):
for j in range(60):
if binA[i][j]=="0":
binary[j]+=lis[j]
else:
binary[j]+=n-lis[j]
binary[58]+=binary[59]//2
binary[59]=0
explis=[1]
for i in range(60):
explis.append((explis[i]*2)%p)
ans=0
for i in range(59):
ans=(ans+binary[i]*explis[58-i])%p
print(ans)
|
MOD = 1000000007
n = int(input())
aas = list(map(int, input().split()))
KET = 60
arr_0 = [0]*KET
arr_1 = [0]*KET
for i in aas:
bits = format(i,'060b')
for j in reversed(range(KET)):
if bits[j] == '0':
arr_0[KET-j-1] += 1
else:
arr_1[KET-j-1] += 1
res = 0
for i in range(KET):
res += (arr_0[i]%MOD * arr_1[i]%MOD)%MOD * pow(2,i,MOD)
res %= MOD
print(res)
| 1 | 123,087,013,035,612 | null | 263 | 263 |
(W, H, x, y, r) = [int(i) for i in input().rstrip().split()]
if x + r <= W and x - r >= 0 and y + r <= H and y - r >= 0:
print('Yes')
else:
print('No')
|
def gcd(a,b):
a,b=max(a,b),min(a,b)
return a if b==0 else gcd(b,a%b)
x=int(input())
g=gcd(360,x)
print(360//g)
| 0 | null | 6,829,420,101,868 | 41 | 125 |
n,m = map(int,input().split())
print("Yes" if n == m else "No")
|
N = int(input())
As = list(map(int, input().split()))
P = 10**9 + 7
rlt = 0
pw = 1
for i in range(61):
c0 = 0
c1 = 0
for j in range(N):
a = As[j]
if a % 2 == 0:
c0 += 1
else:
c1 += 1
As[j] = a//2
rlt += c0*c1*pw % P
rlt %= P
pw *= 2
print(rlt)
| 0 | null | 102,790,223,811,964 | 231 | 263 |
import sys, math, re
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7
def input():
return sys.stdin.readline()[:-1]
def mi():
return map(int, input().split())
def ii():
return int(input())
def i2(n):
tmp = [list(mi()) for i in range(n)]
return [list(i) for i in zip(*tmp)]
def main():
N = ii()
A = list(mi())
s = sum(A)
t = 0
m = math.inf
for i in range(N):
t += A[i]
m = min(m, abs(s-2*t))
print(m)
if __name__ == '__main__':
main()
|
import math
N, K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A=sorted(A, reverse=False)
F=sorted(F, reverse=True)
a=-1
b=max([A[i]*F[-i-1] for i in range(N)])
while b-a>1:
tmp=(a+b)//2
c=sum([max(0, math.ceil(A[i]-tmp/F[i])) for i in range(N)])
if c<=K:
b=tmp
else:
a=tmp
print(b)
| 0 | null | 153,855,455,795,938 | 276 | 290 |
#coding: utf-8
p = [0,0]
n = int(input())
for i in range(n):
c1 = input().split(" ")
c2 = sorted(c1)
if c1[0] == c1[1]:
p[0] += 1
p[1] += 1
elif c1[0] == c2[0]:
p[1] += 3
else:
p[0] += 3
print(str(p[0]) + " " + str(p[1]))
|
def modpow(a, n, p):
if n == 0:
return 1
elif n == 1:
return a % p
if n % 2 == 1:
return (a * modpow(a, n-1, p)) % p
tmp = modpow(a, n//2, p)
return (tmp * tmp) % p
def modfactrial(a, p):
ret = 1
for i in range(a, 1, -1):
ret = ret * i % p
return ret
def main():
mod = 10 ** 9 + 7
n, a, b = map(int, input().split())
# まずは繰り返し2乗法によって全部の組み合わせを求める
# すべての組み合わせは、花を選ぶ/選ばないで組み合わせを決めれる
ans = (modpow(2, n, mod) - 1) % mod
# a本選んだときの数を引く
c_a = 1
for i in range(n, n-a, -1):
c_a *= i
c_a %= mod
c_a *= modpow(modfactrial(a, mod), mod-2, mod)
ans -= c_a
ans %= mod
# b本選んだときの数を引く
c_b = 1
for i in range(n, n-b, -1):
c_b *= i
c_b %= mod
c_b *= modpow(modfactrial(b, mod), mod-2, mod)
ans -= c_b
ans %= mod
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 34,083,378,335,948 | 67 | 214 |
n = input()
l = map(int,raw_input().split())
print min(l), max(l), sum(l)
|
num = int(input())
num_list = list(map(int,input().split(" ")))
print(min(num_list),max(num_list),sum(num_list))
| 1 | 738,902,307,562 | null | 48 | 48 |
import collections
import math
def cmb_factorial(s):
return math.factorial(s) // (math.factorial(2) * math.factorial(s - 2))
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
f = {}
cmb = 0
for x in c.values():
f[1] = 0
f[2] = 1
if x >= 3:
f[x] = cmb_factorial(x)
if x - 1 not in f:
f[x - 1] = cmb_factorial(x - 1)
cmb += f.get(x)
for z in a:
y = c.get(z)
ans = cmb
if y >= 2:
ans = cmb - f.get(y) + f.get(y - 1)
print(ans)
|
N=int(input())
A=list(map(int,input().split()))
d=dict()
for i in range(N):
if A[i] not in d:
d[A[i]]=0
d[A[i]]+=1
x=sum(x*(x-1)//2 for x in d.values())
for i in range(N):
y=d[A[i]]
print(x-y*(y-1)//2+(y-1)*(y-2)//2)
| 1 | 47,686,432,060,800 | null | 192 | 192 |
def main():
N, M = map(int, input().split())
cond = N == M
print('Yes' if cond else 'No')
if __name__ == '__main__':
main()
|
n,m=map(int,raw_input().split())
if m ==n:
print "Yes"
else:
print "No"
| 1 | 83,260,785,833,108 | null | 231 | 231 |
#!/usr/bin/env python3
import collections as cl
import sys
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def main():
N, R = MI()
if N >= 10:
print(R)
else:
print(R + 100 * (10 - N))
main()
|
import sys
import math
n, k = map(int, input().split())
# n_start = math.floor(n / k)
# # print(n_start)
# n = n - n_start*k
# # print(n)
n = n % k
while True:
min_n = n
n = abs(n-k)
# print("n, k =", n, k)
if min_n > n:
min_n = n
else:
break
print(min_n)
| 0 | null | 51,094,312,783,778 | 211 | 180 |
n=int(input())
s = input()
ans = 0
if n%2 != 0:
print('No')
if n%2 == 0:
for i in range(n//2):
if s[i] == s[i+n//2]:
ans += 1
if ans == n//2:
print('Yes')
if ans != n//2:
print('No')
|
N=int(input())
S=input()
x="Yes"
if N%2==1:
print("No")
else:
for i in range(0,N//2):
if S[i]!=S[i+N//2]:
x="No"
break
print(x)
| 1 | 146,699,961,433,480 | null | 279 | 279 |
def main():
N, M = map(int, input().split())
A = tuple(map(int,input().split()))
ans = count(A, N, M)
print(ans)
def count(A, N, M):
t = hMt(A[0])
B = [A[0]//(2**t)]
for val in A[1:]:
if hMt(val) != t:
ans = 0
return ans
B.append(val//(2**t))
T = nlcm(B)
MdivT = (M//(2**(t-1)))//T
ans = countodd(MdivT)
return ans
def countodd(num):
if num%2 == 0:
ans = num//2
else:
ans = num//2 + num%2
return ans
def nlcm(A):
LCM = A[0]
for val in A[1:]:
#print("%d %d gcm:%d LCM:%d"%(LCM,val,gcm(LCM,val),lcm(LCM,val)))
LCM = lcm(LCM,val)
return LCM
def gcm(a, b):
abtuple = (a,b)
abmin = min([0,1], key=lambda x:abtuple[x])
remainder = abtuple[1-abmin]%abtuple[abmin]
if remainder == 0:
return abtuple[abmin]
return gcm(abtuple[abmin], remainder)
def lcm(a,b):
prod = a*b
ans = prod//gcm(a,b)
return ans
def hMt(num):
ans = 0
tmp = num
while tmp%2 == 0:
tmp = tmp//2
ans += 1
return ans
main()
|
from fractions import gcd
from functools import reduce
import sys
def lcm_base(x, y):
return (x * y) // gcd(x, y)
def lcm_list(numbers, maxvalue):
first = 1
second = 1
for i in numbers:
second = i
lcm_result = lcm_base(first, second)
if lcm_result > max_value:
return -1
first = lcm_result
return lcm_result
n, m = map(int, input().split())
A = list(map(int, input().split()))
max_value = 2 * m
lcm = lcm_list(A, 2 * m)
if lcm == -1:
print("0")
sys.exit(0)
if any((lcm / a) % 2 != 1 for a in A):
print("0")
sys.exit(0)
max_product = max_value // lcm
print((max_product + 1) // 2)
| 1 | 101,639,620,786,438 | null | 247 | 247 |
N=int(input())
A=list(map(int,input().split()))
A.sort()
for i in range(N-1):
if A[i]==A[i+1]:
print("NO")
break
if i==N-2:
print("YES")
|
# coding: utf-8
n, k = map(int, input().rstrip().split())
w = [0 for _ in range(n)]
for i in range(n):
w[i] = int(input())
# from random import randint
# n = 100000
# k = 10000
# w = [0 for _ in range(n)]
# for i in range(n):
# w[i] = randint(1, 10000)
# print(w)
count = 0
def check(P):
m = 0
ik = 1
for i in range(n):
global count
count += 1
new = m + w[i]
if new > P:
m = w[i]
ik += 1
if ik > k:
return False
else:
m = new
return True
s = max(sum(w)//k, max(w))
e = sum(w)
while True:
P = (s + e)//2
# print("s:{}, e:{}, P:{}".format(s, e, P))
if s == e:
break
if check(P):
e = P
else:
s = P + 1
print(P)
# print(count)
| 0 | null | 36,868,124,256,938 | 222 | 24 |
from collections import deque
N, M, Q = map(int, input().split())
I = [list(map(int, input().split())) for _ in range(Q)]
que = deque()
ans = 0
for i in range(1, M+1):
que.append([i])
while que:
seq = que.popleft()
if len(seq) == N:
p = 0
for i in range(Q):
if seq[I[i][1]-1] - seq[I[i][0]-1] == I[i][2]:
p += I[i][3]
ans = max(ans, p)
else:
for i in range(seq[-1], M+1):
seq_next = seq + [i]
que.append(seq_next)
print(ans)
|
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import combinations_with_replacement
import numpy as np
def main():
n, m, q = map(int, input().split())
A = np.array(list(combinations_with_replacement(range(1, m + 1), n)))
numA = len(A)
score = np.zeros(numA, np.int32)
ma = map(int, read().split())
for a, b, c, d in zip(ma, ma, ma, ma):
a -= 1
b -= 1
eachA_is_equalOrNot = A[:, b] - A[:, a] == c
score += d * eachA_is_equalOrNot
# print(score)
print(score.max())
if __name__ == '__main__':
main()
| 1 | 27,494,532,158,978 | null | 160 | 160 |
a,b = map(int, input().split())
print(0--a//b)
|
a,b = raw_input().split(" ")
x = int(a)*2+int(b)*2
y = int(a)*int(b)
print "%d %d"%(y,x)
| 0 | null | 38,549,521,853,610 | 225 | 36 |
print("aA"[input()<"a"])
|
alphabet = input()
if alphabet.isupper():
print('A')
else:
print('a')
| 1 | 11,313,158,408,510 | null | 119 | 119 |
a = []
for i in range(0,2):
l = list(map(int,input().split()))
a.append(l)
d = a[1][::-1]
print(' '.join(map(str,d)))
|
h,n=map(int,input().split())
A=list(map(int,input().split()))
attack = sum(A)
if h > attack:
print('No')
else:
print('Yes')
| 0 | null | 39,240,286,263,092 | 53 | 226 |
def gcd(a, b):
while b:
a, b = b, a%b
return a
x, y = map(int,input().split())
print(gcd(x, y))
|
def gcd(x, y):
if x < y:
return gcd(y, x)
if y == 0:
return x
return gcd(y, x % y)
x, y = map(int, input().split())
print(gcd(x, y))
| 1 | 8,200,076,800 | null | 11 | 11 |
s = input()
n = len(s)
dp = [0 for _ in range(n)]
dp[-1] = int(s[-1])
cnt_dic = {}
tmp = 1
ans = 0
cnt_dic[0] = 1
cnt_dic[dp[-1]] = 1
for i in range(n-2, -1, -1):
dp[i] = (dp[i+1] + int(s[i]) * pow(10, n-i-1, 2019)) % 2019
if not dp[i] in cnt_dic:
cnt_dic[dp[i]] = 0
ans += cnt_dic[dp[i]]
cnt_dic[dp[i]] += 1
print(ans)
|
def main():
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
target = 1
for i in A:
if i == target:
target += 1
if target == 1:
print(-1)
return
print(N - target + 1)
main()
| 0 | null | 72,872,535,171,500 | 166 | 257 |
h, w, k = map(int, input().split())
s = [input() for _ in range(h)]
ans = []
vacant = 0
cnt = 0
for x in range(h):
if s[x] == '.' * w:
vacant += 1
continue
else:
cnt += 1
tmp = []
yet = False
for y in range(w):
if s[x][y] == '#':
if not yet:
yet = True
else:
cnt += 1
tmp.append(cnt)
for _ in range(vacant + 1):
ans.append(tmp)
vacant = 0
for _ in range(vacant):
ans.append(ans[-1])
for a in ans:
print(*a, sep=" ")
|
h,w,k=map(int,input().split())
s=[]
ans=[[0 for k in range(w)] for _ in range(h)]
for _ in range(h): s.append(input())
temp=0
for i in range(h):
flag=0
for j in range(w):
if flag:
if s[i][j]=="#": temp+=1
ans[i][j]=temp
else:
if s[i][j]=="#":
temp+=1
flag=1
ans[i][j]=temp
temp=[ans[i].count(0) for i in range(h)]
for i,val in enumerate(temp):
if 0<val<w:
j=w-1
while ans[i][j]!=0: j-=1
while j>=0:
ans[i][j]=ans[i][j+1]
j-=1
for i in range(h):
if i>0 and ans[i][0]==0: ans[i]=ans[i-1]
for i in range(h-1,-1,-1):
if i<h-1 and ans[i][0]==0: ans[i]=ans[i+1]
for i in range(h):
for j in range(w):
print(ans[i][j],end=" ")
print()
| 1 | 143,189,899,828,520 | null | 277 | 277 |
n,k = map(int, input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
def is_ok(x):
c = 0
for a, f in zip(A, F):
c += max(0, a-x//f)
if c <= k:
return True
else:
return False
ng = -1
ok = 10**18
while ng+1 < ok:
c = (ng+ok)//2
if is_ok(c):
ok = c
else:
ng = c
print(ok)
|
n = int(input())
s = input()
ans = ""
for i in range(len(s)):
x = ord(s[i]) - ord('A') + n
ans += chr(x % 26 + ord('A'))
print(ans)
| 0 | null | 149,919,492,984,670 | 290 | 271 |
import math
import sys
n=int(input())
d=list(map(int,input().split()))
if d[0]!=0 or 0 in d[1:]:
print(0)
sys.exit()
lis=[0 for i in range(n)]
for i in range(n):
lis[d[i]]+=1
for i in range(1,n-1):
if lis[i]==0 and lis[i+1]!=0:
print(0)
sys.exit()
s=1
i=0
while i+1<=n-1 and lis[i+1]!=0:
s=(s*pow(lis[i],lis[i+1],998244353))%998244353
i+=1
print(s)
|
import collections
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
f = collections.Counter(d)
# print(f)
if d[0] != 0 or f[0] != 1: # 0は一個だけ
print(0)
exit()
ans = 1
box = 1 # 値自体の個数を保存
maxd = max(d)
for i in range(maxd+1):
ans = ans*box**f[i]
ans %= mod
box = f[i]
print(ans)
| 1 | 154,693,842,049,750 | null | 284 | 284 |
num = list(map(int, input().split()))
class Dice:
def __init__(self, num):
self.state = {}
for i in range(1,6+1):
self.state[i] = num[i-1]
self.reversed_state = {}
for key,val in zip(self.state.keys(), self.state.values()):
self.reversed_state[val] = key
def search_side(self, x,y):
a = self.reversed_state[x]
b = self.reversed_state[y]
if str(a)+str(b) in '12651':
side = self.state[3]
elif str(b)+str(a) in '12651':
side = self.state[4]
elif str(a)+str(b) in '13641':
side = self.state[5]
elif str(b)+str(a) in '13641':
side = self.state[2]
elif str(a)+str(b) in '23542':
side = self.state[1]
elif str(b)+str(a) in '23542':
side = self.state[6]
return side
dice = Dice(num)
q = int(input())
for _ in range(q):
x,y = map(int, input().split())
ans = dice.search_side(x,y)
print(ans)
|
n=list(map(int,input().split()))
p=['2354','3146','2651','1562','1364','2453']
for _ in range(int(input())):
t,m=map(int,input().split())
t=n.index(t)
m=str(n.index(m)+1)
print(n[int(p[t][(p[t].index(m)+1)%4])-1])
| 1 | 258,935,509,700 | null | 34 | 34 |
n = int(input())
print(sum((n - 1) // i for i in range(1, n)))
|
n = int(input())
s = 0
a = 1
b = 1
while a*b < n:
while a*b < n and b <= a:
if a == b:
s += 1
else:
s += 2
b += 1
a += 1
b = 1
print(s)
| 1 | 2,589,155,642,338 | null | 73 | 73 |
count = int(input())
point = {'taro': 0, 'hanako': 0}
for i in range(count):
(taro, hanako) = [s for s in input().split()]
if (taro > hanako) - (taro < hanako) == 0:
point['taro'] += 1
point['hanako'] += 1
elif (taro > hanako) - (taro < hanako) > 0:
point['taro'] += 3
else:
point['hanako'] += 3
print(point['taro'], point['hanako'])
|
m1,d1 = map(int,input().split())
m2,d2 = map(int,input().split())
print(1 if m1!=m2 else 0)
| 0 | null | 63,069,458,345,792 | 67 | 264 |
D = int(input())
c = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]
T = [int(input()) for i in range(D)]
SUM = 0
last = [0] * 28
for d in range(1, D + 1):
i = T[d - 1]
SUM += S[d - 1][i - 1]
SU = 0
last[i] = d
for j in range(1, 27):
SU += (c[j - 1] * (d - last[j]))
SUM -= SU
print(SUM)
|
import math
r = float(input())
a = math.pi * r**2
b = math.pi * r * 2
print(str(a) + " " + str(b))
| 0 | null | 5,351,357,561,120 | 114 | 46 |
target = input()
sum = 0
for each in target:
sum += int(each)
if sum % 9 == 0:
print("Yes")
else:
print("No")
|
n=input()
div=0
for ch in n:
num=int(ch)
div+=num
if div%9==0:
print("Yes")
else:
print('No')
| 1 | 4,409,371,971,190 | null | 87 | 87 |
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
N = k()
ans = N-1
for i in range(1,int(N**0.5)+1):
if N % i == 0:
b = N // i
ans = min(ans, b+i-2)
print(ans)
|
# -*- coding: utf-8 -*-
# モジュールのインポート
import sys
def get_input() -> tuple:
"""
標準入力を取得する.
Returns:\n
tuple: 標準入力
"""
N = int(input())
x, y = [], []
for i in range(N):
x_i, y_i = list(map(int, input().split()))
x.append(x_i)
y.append(y_i)
return N, x, y
def main(N: int, x: list, y: list) -> None:
"""
メイン処理.
Args:\n
N (int): 点の数(2 <= N <= 2 * 10**5)
x (list): x座標(1 <= x_i <= 10**9)
y (list): y座標(1 <= y_i <= 10**9)
"""
# 求解処理
max_z = -sys.maxsize
min_z = sys.maxsize
max_w = -sys.maxsize
min_w = sys.maxsize
for x_i, y_i in zip(x, y):
z_i = x_i + y_i
max_z = max(max_z, z_i)
min_z = min(min_z, z_i)
w_i = x_i - y_i
max_w = max(max_w, w_i)
min_w = min(min_w, w_i)
ans = max(max_z - min_z, max_w - min_w)
# 結果出力
print(ans)
if __name__ == "__main__":
# 標準入力を取得
N, x, y = get_input()
# メイン処理
main(N, x, y)
| 0 | null | 82,186,437,374,236 | 288 | 80 |
N, M = map(int, input().split())
parent = [-1] * N
def get_group_root(x):
if parent[x] < 0:
return x
return get_group_root(parent[x])
for i in range(0, M):
A, B = map(int, input().split())
A -= 1
B -= 1
groupA = get_group_root(A)
groupB = get_group_root(B)
if groupA == groupB:
continue
elif parent[groupA] < parent[groupB]:
parent[groupB] = A
parent[groupA] -= 1
else:
parent[groupA] = B
parent[groupB] -= 1
def check(x):
return x < 0
print(sum(list(map(check, parent))) - 1)
|
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
N, M = list(map(int, input().split()))
paths = [list(map(int, input().split())) for _ in range(M)]
result = solve(N, paths)
print(result)
def solve(N, paths) -> int:
uf = UnionFind(N)
for x, y in paths:
uf.union(x - 1, y - 1)
return uf.group_count() - 1
if __name__ == '__main__':
main()
| 1 | 2,257,526,091,680 | null | 70 | 70 |
input()
print('APPROVED' if all(map(lambda x: x % 3 == 0 or x % 5 == 0, filter(lambda x: x % 2 == 0, map(int, input().split())))) else 'DENIED')
|
n = int(input())
q = list(map(int,input().split()))
ans = 0
for i in range(n):
for j in range(n):
if i == j:
continue
ans += q[i] * q[j]
print(ans//2)
| 0 | null | 119,182,155,813,732 | 217 | 292 |
a=list(map(int,input().split()))
print(*[a[2],a[0],a[1]],sep=' ')
|
import math
while True:
n = int(input())
if n == 0 :
break
nums = [int(x) for x in input().split(" ")]
mean = sum(nums) / n
variance = sum([(x - mean) ** 2 for x in nums]) / n
std = math.sqrt(variance)
print(std)
| 0 | null | 19,140,512,777,880 | 178 | 31 |
import sys
sys.setrecursionlimit(10 ** 6)
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
A = []
def rec(itr, lst):
if itr == N:
res = 0
for a, b, c, d in abcd:
if A[b-1] - A[a-1] == c:
res += d
return res
else:
res = 0
for i in range(lst, M):
A.append(i)
res = max(res, rec(itr + 1, i))
A.pop()
return res
print(rec(0, 0))
|
num_l = set(map(int, input().split()))
print('Yes' if len(num_l) == 2 else 'No')
| 0 | null | 47,905,708,385,372 | 160 | 216 |
# 7
# 100 130 130 130 115 115 150
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
m = 1000
kabu = 0
buy = True
buy_val = 100000
for i in range(len(a)):
if i == len(a)-1:
m += kabu * a[i]
kabu = 0
elif not buy and a[i] > a[i+1]:
m += kabu * a[i]
kabu=0
buy=True
elif buy and a[i] < a[i+1]:
kabu=int(m/a[i])
m -= kabu * a[i]
buy=False
print(m)
|
D = int(input())
clist = list(map(int, input().split()))
slist = [list(map(int, input().split())) for _ in range(D)]
tlist = [int(input()) for _ in range(D)]
zlist = []
dlist = [0] * 26
ans = 0
'''
print(sum(clist))
print('--------------')
print(slist[0][0])
print(slist[1][16])
print(clist[16])
print('--------------')
'''
for i in range(D):
#print(slist[i],tlist[i]-1)
zlist.append(clist[tlist[i]-1] * ((i+1) - dlist[tlist[i]-1]))
dlist[tlist[i]-1] = i+1
ans += slist[i][tlist[i]-1] - ((i+1) * sum(clist)) + sum(zlist)
print(ans)
| 0 | null | 8,705,644,033,218 | 103 | 114 |
S=input()
N=len(S)
M=(N-1)//2
def iskaibun(T):
K=len(T)
for i in range(K):
if T[i]==T[-i-1]:
pass
else:
return False
return True
if iskaibun(S) and iskaibun(S[:M]) and iskaibun(S[M+1:]):
print("Yes")
else:
print("No")
|
N=int(input())
d={"AC":0,"WA":0,"TLE":0,"RE":0}
for _ in range(N):
d[input()]+=1
print("AC x",d["AC"])
print("WA x",d["WA"])
print("TLE x",d["TLE"])
print("RE x",d["RE"])
| 0 | null | 27,414,267,134,788 | 190 | 109 |
a, b = map(int, input().split())
print('%d %d %.8f' %(a//b, a%b, float(a)/b))
|
x = input().split()
print(x[1]+x[0])
| 0 | null | 52,090,416,900,512 | 45 | 248 |
s = input()
if s == "RRR":
print(3)
elif s == "RRS" or s == "SRR":
print(2)
elif s == "RSS" or s == "RSR" or s == "SRS" or s == "SSR":
print(1)
else:
print(0)
|
s = input()
count = 0
for i in range(len(s)):
if s[i] == "R":
count += 1
if i + 1 >= 3:
break
elif s[i+1] == "S":
break
print(count)
| 1 | 4,861,948,525,308 | null | 90 | 90 |
k = int(input())
s =str(input())
s_print = ''
if k >= len(s):
print(s)
exit()
else:
for i in range(k):
s_print += s[i]
s_print += '...'
print(s_print)
|
k=int(input())
s=str(input())
long =len(s)
i =0
ans = str()
if k>long:
print(s)
else:
for i in range(long):
if i<k:
ans = str(ans+s[i])
else:
ans = str(ans+"...")
break
print(ans)
| 1 | 19,632,353,117,102 | null | 143 | 143 |
S,T = input().split()
print(T,S, sep='')
|
n, k = map(int, input().split())
h = list(map(int, input().split()))
h.sort(reverse=True)
ans = 0
for i in range(k, n): ans += h[i]
print(ans)
| 0 | null | 90,908,462,405,112 | 248 | 227 |
x, y = map(int, input().split())
if x == 1 and y == 1:
print(100000 * (8 - (x + y)) + 400000)
elif x <= 3 and y <= 3:
print(100000 * (8 - (x + y)))
elif x <= 3:
print(100000 * (4 - x))
elif y <= 3:
print(100000 * (4 - y))
else:
print(0)
|
import math
a,b=[int(i) for i in input().split()]
c=a//b
e=abs(a-(b*c))
f=abs(a-(b*(c+1)))
print(min(e,f))
| 0 | null | 90,020,666,765,652 | 275 | 180 |
a,b,c=map(int,input().split())
if a<=b*c:print("Yes")
else:print("No")
#連続acしなきゃ……
|
text = [int(e) for e in input().split()]
if text[1] * text[2] >= text[0]:
print("Yes")
else:
print("No")
| 1 | 3,537,437,322,794 | null | 81 | 81 |
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if v<w:
print("NO")
elif v==w:
if a==b:
print("YES")
else:
print("NO")
elif v>w:
t0 = abs((a-b)/(v-w))
if t0<=t:
print("YES")
else:
print("NO")
|
N = input ()
P = '0168'
H = '24579'
if N[-1] in P:
print ('pon')
elif N[-1] in H:
print ('hon')
else:
print ('bon')
| 0 | null | 17,203,910,135,908 | 131 | 142 |
import sys
r, c = map(int, raw_input().split())
table = {}
for i in range(r):
a = map(int, raw_input().split())
for j in range(c):
table[(i,j)] = a[j]
for i in range(r+1):
for j in range(c+1):
if(i != r and j != c):
sys.stdout.write(str(table[(i,j)]))
sys.stdout.write(' ')
elif(i != r and j == c):
print sum(table[(i,l)] for l in range(c))
elif(i == r and j != c):
sys.stdout.write(str(sum(table[(k,j)] for k in range(r))))
sys.stdout.write(' ')
elif(i == r and j == c):
total = 0
for k in range(r):
for l in range(c):
total += table[(k,l)]
print total
|
import sys
a, b = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
print( "{} {}".format( a*b, a*2+b*2 ) )
| 0 | null | 839,467,189,728 | 59 | 36 |
from math import*
print(2**ceil(log2(int(input())+1))-1)
|
from math import log2
N = int(input())
log = int(log2(N)+1)
ans = (2**log-1)
print(ans)
| 1 | 79,761,506,026,710 | null | 228 | 228 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.