text
stringlengths 37
1.41M
|
---|
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+=1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
g = 1
G = [1]
m = 1
for i in range(1,101):
tmp = G[i-1]+(3)**i
if tmp <= n:
m = i+1
G.append(tmp)
g += 1
else:
break
G.reverse()
print(m) # 1行目
print(" ".join(list(map(str,G)))) # 2行目
for i in range(0,m):
insertionSort(A, n, G[i])
print(cnt) # 3行目
for i in range(0,len(A)):
print(A[i]) # 4行目以降
cnt = 0
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A,n)
|
S = input().split(" ")
N = int(S[0])
M = int(S[1])
def calculate(n,m):
if n == 1 and m == 1:
return 1
if n == 1:
return m - 2
if m == 1:
return n - 2
return (n - 2) * (m - 2)
result = calculate(N,M)
print(result) |
K = int(input())
def gcd(a, b):
if a < b:
return gcd(b, a)
elif a % b == 0:
return b
else:
r = a % b
return gcd(b, r)
ans = 0
for a in range(1, K+1):
for b in range(1, K+1):
for c in range(1, K+1):
n = gcd(a, b)
n = gcd(n, c)
ans += n
print(ans) |
s=input()
str1=s[0]
str2=""
ans=1
for i in range(len(str1),len(s)):
str2+=s[i]
if str1!=str2:
ans+=1
str1=str2
str2=""
print(ans)
|
import math as mt
x1 , y1 , x2,y2 = list(map(float, input().split()))
a = pow(x2 - x1,2 )
b = pow(y2 - y1,2)
c = mt.sqrt(a+b)
print(f'{c:.8f}')
|
#Union Find
#xの根を求める
def find(x):
if par[x] < 0:
return x
else:
par[x] = find(par[x])
return par[x]
#xとyの属する集合の併合
def unite(x,y):
x = find(x)
y = find(y)
if x == y:
return False
else:
#sizeの大きいほうがx
if par[x] > par[y]:
x,y = y,x
par[x] += par[y]
par[y] = x
return True
#xとyが同じ集合に属するかの判定
def same(x,y):
return find(x) == find(y)
#xが属する集合の個数
def size(x):
return -par[find(x)]
N, M = map(int, input().split())
bridges = []
for _ in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
bridges.append((a, b))
#初期化
#根なら-size,子なら親の頂点
par = [-1]*N
tot = N*(N-1)//2
ans = [tot]
for a, b in bridges[::-1]:
if not same(a, b):
tot -= size(a)*size(b)
unite(a, b)
ans.append(tot)
print('\n'.join(map(str, ans[:-1][::-1]))) |
import math
x1,y1,x2,y2 = (float(x) for x in input().split())
print(round(math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2), 8))
|
A, B = [int(s) for s in input().split(' ')]
a = 0 if A > 9 else A
b = 0 if B > 9 else B
print(a * b if a * b else -1)
|
s = input()
s = s.replace('hi', "")
if len(s) > 0:
print('No')
else:
print('Yes') |
# B_D
circle = input() * 2
target = input()
if target in circle:
print("Yes")
else:
print("No")
|
s = input()
bef = s[:2]
aft = s[2:]
if 1 <= int(bef) <= 12:
if 1 <= int(aft) <= 12:
print("AMBIGUOUS")
else:
print("MMYY")
else:
if 1 <= int(aft) <= 12:
print("YYMM")
else:
print("NA") |
def solve(s):
tmp = s // 11 * 2
if s % 11 > 6:
tmp += 2
elif 6 >= s % 11 > 0:
tmp+=1
return tmp
if __name__ == "__main__":
x = int(input())
print(solve(x)) |
import itertools
import sys
s = input()
ok = False
for i in range(len(s) - 1):
if (s[i] == 'A' and s[i + 1] == 'C'):
ok = True
if ok:
print("Yes")
else:
print("No")
|
#%%
s = list(input())
f1 = False
f2 = False
for i in range(len(s)):
if s[i] == 'C':
f1 = True
if f1 and s[i] == 'F':
f2 = True
if f1 and f2:
print('Yes')
else:
print('No')
|
def main():
S = input()
T = input()
N = len(S)
def check(S, T):
b = {s for s in S}
for t in T:
if t not in b:
return True # -1
return False
def is_ok(mid, now, ans):
if ans < now[mid]:
return True
else:
return False
def binary_search_meguru(now, ans):
ng = -1
ok = len(now)-1
while abs(ok - ng) > 1:
mid = ng + (ok - ng) // 2
if is_ok(mid, now, ans):
ok = mid
else:
ng = mid
return now[ok]
if check(S, T):
return print(-1)
from string import ascii_lowercase
dic = {a: [] for a in ascii_lowercase}
for i, s in enumerate(S):
dic[s].append(i+1)
ans = 0
cycle = 0
for t in T:
now = dic[t]
if now[-1] <= ans:
cycle += 1
ans = 0
idx = binary_search_meguru(now, ans)
ans = idx
print(ans + N*cycle)
if __name__ == '__main__':
main()
|
from fractions import gcd
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
def gcd_list(numbers):
return reduce(gcd, numbers)
print(gcd_list(a)) |
def gcd(x, y):
if y == 0:
return x
else:
return gcd(y, x % y)
K = int(input())
ans = 0
for a in range(1, K + 1):
for b in range(1, K + 1):
g1 = gcd(a, b)
if g1 == 1:
ans += K
else:
for c in range(1, K+1):
ans += gcd(g1, c)
print(ans)
|
def print_ab(s, a, b):
print(s[a:b+1])
def reverse_ab(s, a, b):
s_f = s[:a]
s_m = s[a:b+1]
s_l = s[b+1:]
return s_f+s_m[::-1]+s_l
def replace_ab(s, a, b, p):
s_f = s[:a]
s_l = s[b+1:]
return s_f+p+s_l
s = input()
q = int(input())
for i in range(q):
option = input().split()
if option[0] == "print":
print_ab(s,int(option[1]),int(option[2]))
elif option[0] == "reverse":
s = reverse_ab(s, int(option[1]), int(option[2]))
elif option[0] == "replace":
s = replace_ab(s, int(option[1]), int(option[2]), option[3]) |
a = [int(s) for s in input().split()]
if a[0] > 12:
print(a[1])
elif a[0] > 5:
print(int(a[1] / 2))
else:
print("0") |
x = float(input())
if float(x) == 0:
print(1)
elif float(x)==1:
print(0) |
_ = input()
print('Four' if len(set(input().split())) == 4 else 'Three') |
n = int(input())
fib = []
ans = 0
for i in range(n+1):
if i == 0 or i == 1:
ans = 1
fib.append(ans)
else:
ans = fib[i-1] + fib[i-2]
fib.append(ans)
print(ans)
|
a = int(input())
b=a+a*a+a*a*a
print(b) |
class Dice:
__table =[[0,1,2,3,4,5],[0,2,4,1,4,5],[0,4,3,2,1,5],[0,3,1,4,2,5],
[1,5,2,3,0,4],[1,2,0,5,3,4],[1,0,3,2,5,4],[1,3,5,0,2,4],
[2,5,4,1,0,3],[2,4,0,5,1,3],[2,0,1,4,5,3],[2,1,5,0,4,3],
[3,5,1,4,0,2],[3,1,0,5,4,2],[3,0,4,1,5,2],[3,4,5,0,1,2],
[4,2,5,0,3,1],[4,5,3,2,0,1],[4,3,0,5,2,1],[4,0,2,3,5,1],
[5,1,3,2,4,0],[5,3,4,1,2,0],[5,4,2,3,1,0],[5,2,1,4,3,0]]
__another = []
def __init__(self,dice):
self.dice = dice
for t in self.__table:
a = []
for k,v in enumerate(t):
a.append(dice[v])
self.__another.append(a)
def output(self):
print(self.dice[0])
def right_dise(self,a,b):
for t in self.__another:
if t[0] == a and t[1] == b:
return t[2]
def move(self,str):
if str == 'N':
temp = self.dice[0]
self.dice[0] = self.dice[1]
self.dice[1] = self.dice[5]
self.dice[5] = self.dice[4]
self.dice[4] = temp
elif str == 'S':
temp = self.dice[0]
self.dice[0] = self.dice[4]
self.dice[4] = self.dice[5]
self.dice[5] = self.dice[1]
self.dice[1] = temp
elif str == 'E':
temp = self.dice[0]
self.dice[0] = self.dice[3]
self.dice[3] = self.dice[5]
self.dice[5] = self.dice[2]
self.dice[2] = temp
elif str == 'W':
temp = self.dice[0]
self.dice[0] = self.dice[2]
self.dice[2] = self.dice[5]
self.dice[5] = self.dice[3]
self.dice[3] = temp
di = list(map(int,input().split()))
di = Dice(di)
num = int(input())
while num > 0:
v1,v2 = map(int,input().split())
re = di.right_dise(v1,v2)
print(re)
num -= 1
|
def showList(A, N):
for i in range(N-1):
print(A[i],end=' ')
print(A[N-1])
def selectionSort(A, N):
"""
選択ソート
O(n^2)のアルゴリズム
"""
count = 0
for i in range(N):
minj = i
for j in range(i,N):
if A[j] < A[minj]:
minj = j
if minj != i:
t = A[minj]
A[minj] = A[i]
A[i] = t
count += 1
showList(A, N)
print(count)
N = int(input())
A = [int(x) for x in input().split(' ')]
selectionSort(A, N)
|
#!/usr/bin/env python3
import sys
from itertools import chain
YES = "Yes" # type: str
NO = "No" # type: str
def solve(H: int, N: int, A: "List[int]"):
if H <= sum(A):
return YES
else:
return NO
def main():
tokens = chain(*(line.split() for line in sys.stdin))
H = int(next(tokens)) # type: int
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
answer = solve(H, N, A)
print(answer)
if __name__ == "__main__":
main()
|
a, b = map(int, open(0).read().split())
if a > b:
print('GREATER')
elif a < b:
print('LESS')
else:
print('EQUAL') |
n = int(input())
a=0
for i in range(10):
x = 2 ** i
if x <=n:
a=x
print(a) |
HW = input().split()
H = int(HW[0])
W = int(HW[1])
lst = []
for i in range(H):
lst.append('#' + input() + '#')
print('#' * (W+2))
for s in lst:
print(s)
print('#' * (W+2)) |
n = int(input())
a = int(input())
ans = "Yes" if a >= n % 500 else "No"
print(ans)
|
import functools
X = int(input())
@functools.lru_cache(maxsize=None)
def pow5(x):
return x ** 5
@functools.lru_cache(maxsize=None)
def root5(x):
i = 0
while True:
i5 = pow5(i)
if x < i5:
return None
if i5 == x:
return i
i += 1
a = 0
while True:
a5 = pow5(a)
b = root5(a5 + X)
if b is not None:
print(-a, -b)
break
if a5 <= X:
b = root5(X - a5)
if b is not None:
print(a, -b)
break
else:
b = root5(a5 - X)
if b is not None:
print(a, b)
break
a += 1 |
# 素因数分解
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n //= i
table.append(i)
i += 1
if n > 1:
table.append(n)
return table
def egcd(a, b):
if a == 0:
return b, 0, 1
else:
g, y, x = egcd(b % a, a)
return g, x - (b // a) * y, y
# mを法とするaの乗法的逆元
def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
return x % m
# nCr mod m
def combination(n, r, mod=10**9+7):
r = min(r, n-r)
res = 1
for i in range(r):
res = res * (n - i) * modinv(i+1, mod) % mod
return res
# nHr mod m
def H(n, r, mod=10**9+7):
return combination(n+r-1, r, mod)
from collections import defaultdict
N, M = map(int, input().split())
prime_table = prime_decomposition(M)
dic = defaultdict(int) #指数のリスト
for p in prime_table:
dic[p] += 1
ans=1
for p, b in dic.items():
ans *= H(N, b, mod=10**9+7)
print(ans%(10**9+7)) |
import copy
def insertion_sort(arr, n, g, cnt):
for i in range(g, n):
v = arr[i]
k = i - g
while k >= 0 and arr[k] > v:
arr[k + g] = arr[k]
k = k - g
cnt += 1
arr[k + g] = v
return arr, cnt
def shell_sort(arr, n, G):
A = copy.deepcopy(arr)
c = 0
for i in G:
A, c = insertion_sort(A, n, i, c)
return A, c
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
G = [1]
h = 1
while h * 3 + 1 <= n:
h = 3 * h + 1
G.append(h)
a, cnt = shell_sort(A, n, G[::-1])
print(len(G))
print(*G[::-1])
print(cnt)
for i in a:
print(i)
|
#!/user/bin/env pypy3
import sys
from typing import List
def fast_input():
return sys.stdin.readline()[:-1]
def solve(cards: List[int]) -> int:
sorted_cards = sorted(cards, reverse=True)
alice = 0
bob = 0
for i, card in enumerate(sorted_cards):
if i % 2 == 0:
alice += card
else:
bob += card
return alice - bob
def main():
n = int(fast_input())
a = list(map(int, fast_input().split()))
result = solve(a)
print(result)
main()
|
l = [int(x) for x in input().split(' ')]
if l[0] + l[1] < l[2] + l[3]:
print("Right")
elif l[0] + l[1] > l[2] + l[3]:
print("Left")
else:
print("Balanced") |
#1_10_A
n = int(input())
MEMO = [None] * (n + 1)
def Fib(i):
if i == 0 or i == 1:
return 1
if MEMO[i]:
return MEMO[i]
r = Fib(i-1) + Fib(i-2)
MEMO[i] = r
return r
print(Fib(n))
|
def main():
s=input()
a=s.find('C')
if(a==-1):
print('No')
else:
a2=s.find('F',a+1,len(s))
if(a2==-1):
print('No')
else:
print('Yes')
main()
|
X = input()
stack = []
for x in X:
if stack and stack[-1] == "S" and x == "T":
stack.pop()
else:
stack.append(x)
print(len(stack))
|
import fractions
#import math
def lcm(x, y):
#return (x * y) // math.gcd(x, y)
return (x * y) // fractions.gcd(x, y)
x, y = map(int,input().split())
if y < 2*x: #長さが1になる場合
print(1)
exit()
li = [x, 2*x]
i = 0
while True:
x = lcm(li[i], li[i+1])*2
if x <= y:
li.append(x)
i += 1
else:
print(len(li))
exit() |
def main():
s = input()
n = len(s)
ans = ""
for i in range(0, n, 2):
ans += s[i]
print(ans)
if __name__ == "__main__":
main() |
def resolve():
from collections import deque
n = int(input())
que = deque()
for _ in range(n):
cv = input().split()
if cv[0] == "insert":
x = int(cv[1])
que.appendleft(x)
elif cv[0] == "delete":
x = int(cv[1])
if x in que:
que.remove(x)
elif cv[0] == "deleteFirst":
que.popleft()
elif cv[0] == "deleteLast":
que.pop()
ans = list(que)
print(*ans)
resolve()
|
import math
p = math.pi
r = float(input())
print("{} {}".format(r*r*p, 2*r*p))
|
x = int(input())
eve = ''
for i in range(0, 25-x):
eve += ' Eve'
print('Christmas'+eve) |
import math
class Circle:
def output(self, r):
print "%.6f %.6f" % (math.pi * r * r, 2.0 * math.pi * r)
if __name__ == "__main__":
cir = Circle()
r = float(raw_input())
cir.output(r) |
s=list(input())
if s[0]=='0':
t=int(s[1])
else:
t=int(''.join(s[:2]))
if s[2]=='0':
u=int(s[3])
else:
u=int(''.join(s[2:]))
if t>=1 and t<=12:
if u>=1 and u<=12:
print('AMBIGUOUS')
else:
print('MMYY')
else:
if u>=1 and u<=12:
print('YYMM')
else:
print('NA') |
import math
n = input()
A = 0
def is_prime(m):
for i in range(2, int(math.sqrt(m)) + 1):
if (m % i == 0):
return False
return True
for i in range(n):
k = input()
if is_prime(k):
A += 1
print A |
if __name__ == '__main__':
n = int(input())
s = input()
A = []
A.append(s)
flg = True
for _ in range(n-1):
cmd = input()
if s[-1] == cmd[0] and cmd not in A:
A.append(cmd)
s = cmd
else:
flg = False
if flg :
print("Yes")
else:
print("No")
|
X = int(input())
count = 0
num = 1
jamp_count = 0
while count < X:
count += num
num += 1
jamp_count += 1
print(jamp_count)
|
S = input()
ans = 0
if S.find("RRR") >= 0:
ans = 3
elif S.find("RR") >= 0:
ans = 2
elif S.find("R") >= 0:
ans = 1
print(ans)
|
import math
numbers = []
n = raw_input()
for i in range(int(n)):
input_num = raw_input()
numbers.append(int(input_num))
count = 0
for num in numbers:
prime_frag = True
for i in range(2, int(math.sqrt(num)) + 1):
if num % i == 0:
prime_frag = False
break
if prime_frag:
count += 1
print count |
s = raw_input()
a,b = s.split(' ')
a,b = int(a),int(b)
def mul(a,b):
if a <= 9 and a >=1 and (1 <= b <= 9):
return a * b
else:
return -1
print mul(a,b) |
n = int(input())
count= 0
for i in range(1,n+1):
if len(str(i)) == 1 or len(str(i)) == 3 or len(str(i)) == 5:
count+=1
print(count) |
X = int(input())
price = 100
year = 0
while price<X:
price += price//100
year += 1
print(year) |
# KEYENCE Programming Contest 2019 / キーエンス プログラミング コンテスト 2019: B – KEYENCE String
S = input()
if (S[-7:] == 'keyence') or \
(S[:1] == 'k' and S[-6:] == 'eyence') or \
(S[:2] == 'ke' and S[-5:] == 'yence') or \
(S[:3] == 'key' and S[-4:] == 'ence') or \
(S[:4] == 'keye' and S[-3:] == 'nce') or \
(S[:5] == 'keyen' and S[-2:] == 'ce') or \
(S[:6] == 'keyenc' and S[-1:] == 'e') or \
S[:7] == 'keyence':
print('YES')
else:
print('NO') |
s=list(input())
a=0
z=0
for i in range(len(s)):
if s[i]=="A":
a=i
break
S=list(reversed(s))
for j in range(len(S)):
if S[j]=="Z":
z=j
break
print(len(s)-a-z) |
import re
print("Yes" if re.search(r".*?C.*?F.*?", input()) else "No") |
# cf17-finalA - AKIBA
def main():
S = input().rstrip()
SR = S.replace("A", "")
flg = SR == "KIHBR" and "AA" not in S and "KIH" in S
print("YES" if flg else "NO")
if __name__ == "__main__":
main() |
s=input()
n=len(s)
f=True
if s[0]!='A':
f=False
if s[2:n-1].count('C')!=1:
f=False
for ss in s:
if ss!='A' and ss!='C' and ss.isupper():
f=False
print('AC' if f else 'WA') |
class dice:
def __init__(self):
self.d = list(map(int, input().split()))
self.dir = list(input())
def move(self):
up = [0,1,2,3]
for a in self.dir:
if a == "E":
up = [0, 7-up[3], up[2], up[1]]
elif a == "W":
up = [0, up[3], up[2], 7-up[1]]
elif a == "N":
up = [0, up[2], 7-up[1], up[3]]
else:
up = [0, 7-up[2], up[1], up[3]]
print(self.d[up[1]-1])
ob = dice()
ob.move()
|
s = input()
if s == 'RRR':
print(3)
elif s[:2] == 'RR' or s[1:] == 'RR':
print(2)
elif s.count('R') >= 1:
print(1)
else:
print(0) |
import math
x = int(input())
money = 100
count = 1
while True:
money += money // 100
if money >= x:
break
count += 1
print(count) |
x,a,b = map(int, input().split())
dist_a = abs(x-a)
dist_b = abs(x-b)
if dist_a > dist_b:
print("B")
else:
print("A") |
z = input()
w,x,y = z.split()
a,b,c = int(w),int(x),int(y)
if a < b and b < c:
print("Yes")
else:
print("No") |
List = []
for i in range (3):
List.append(list(map(int, input().split())))
Row = int(input())
Ball = []
for i in range (Row):
Ball.append(int(input()))
for x in range(Row):
for i in range(3):
for j in range(3):
if Ball[x] == List[i][j]:
List[i][j] = 0
if List[0][0] == 0 and List[0][1] == 0 and List[0][2] == 0:
print("Yes")
elif List[1][0] == 0 and List[1][1] == 0 and List[1][2] == 0:
print("Yes")
elif List[2][0] == 0 and List[2][1] == 0 and List[2][2] == 0:
print("Yes")
elif List[0][0] == 0 and List[1][0] == 0 and List[2][0] == 0:
print("Yes")
elif List[0][1] == 0 and List[1][1] == 0 and List[2][1] == 0:
print("Yes")
elif List[0][2] == 0 and List[1][2] == 0 and List[2][2] == 0:
print("Yes")
elif List[0][0] == 0 and List[1][1] == 0 and List[2][2] == 0:
print("Yes")
elif List[0][2] == 0 and List[1][1] == 0 and List[2][0] == 0:
print("Yes")
else:
print("No") |
l = list(map(int,input().split()))
#print(l)
if l[0]==l[1]!=l[2]:
print('Yes')
elif l[0]!=l[1]==l[2]:
print('Yes')
elif l[0]==l[2]!=l[1]:
print('Yes')
else:
print('No') |
a,b = map(int,input().split())
if a>b and a!=1 and b!=1:
print("Alice")
elif a<b and a!=1 and b!=1:
print("Bob")
elif a==b:
print("Draw")
elif a==1:
print("Alice")
else:
print("Bob")
|
from itertools import accumulate
class SegTree: # 0-index !!!
"""
fx: モノイドXでの二項演算
ex: モノイドXでの単位元
init(seq, fx, ex): 配列seqで初期化 O(N)
update(i, x): i番目の値をxに更新 O(logN)
query(l, r): 区間[l,r)をfxしたものを返す O(logN)
get(i): i番目の値を返す
show(): 配列を返す
"""
def __init__(self, seq, fx, ex):
self.n = len(seq)
self.fx = fx
self.ex = ex
self.size = 1<<(self.n - 1).bit_length()
self.tree = [ex] * (self.size * 2)
# build
for i, x in enumerate(seq, start=self.size):
self.tree[i] = x
for i in reversed(range(1, self.size)):
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def set(self, i, x): # O(log(n))
i += self.size
self.tree[i] = x
while i:
i >>= 1
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, i, x):
i += self.size
self.tree[i] = x
while i > 1:
i >>= 1
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def query(self, l, r): # l = r の場合はたぶんバグるので注意
tmp_l = self.ex
tmp_r = self.ex
l += self.size
r += self.size
while l < r:
if l & 1:
tmp_l = self.fx(tmp_l, self.tree[l])
l += 1
if r & 1:
tmp_r = self.fx(self.tree[r - 1], tmp_r) # 交換法則を仮定しない(順序大事に)
l >>= 1
r >>= 1
return self.fx(tmp_l, tmp_r)
def get(self, i):
return self.tree[self.size + i]
def show(self):
return self.tree[self.size: self.size + self.n]
# ---------------------- #
n, c = (int(x) for x in input().split())
X = []
V = []
D = []
prev_x = 0
for _ in range(n):
x, v = (int(x) for x in input().split())
X.append(x)
D.append(x - prev_x)
V.append(v)
prev_x = x
D.append(c - X[-1])
rev_D = list(reversed(D))
rev_V = list(reversed(V))
ans = 0
# 時計回り
A = [0] * n
for i in range(n):
A[i] = V[i] - D[i]
acc_A = list(accumulate(A))
ans = max(ans, max(acc_A))
# 反時計回り
B = [0] * n
for i in range(n):
B[i] = rev_V[i] - rev_D[i]
acc_B = list(accumulate(B))
ans = max(ans, max(acc_B))
# 時計回りからの反時計回り i個まで食べて向きを変える
seg_B = SegTree(acc_B, fx=max, ex=-10**18)
tmp = 0
for i in range(n - 1):
tmp_cal = acc_A[i] - X[i] # 食べて原点まで戻った時点のカロリー
tmp = max(tmp, tmp_cal + seg_B.query(0, n-i-1))
ans = max(ans, tmp)
# 反時計回りからの時計回り
seg_A = SegTree(acc_A, fx=max, ex=-10**18)
tmp = 0
for i in range(n - 1):
tmp_cal = acc_B[i] - (c - X[-i - 1]) # 食べて原点まで戻った時点のカロリー
tmp = max(tmp, tmp_cal + seg_A.query(0, n-i-1))
ans = max(ans, tmp)
print(ans)
|
x,y = map(int,input().split())
ans = 'No'
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
if(x in a and y in a or
x in b and y in b or
x in c and y in c):
ans = 'Yes'
print(ans)
|
X,Y=map(str,input().split())
if X<Y:
ans="<"
elif X>Y:
ans=">"
else:
ans="="
print(ans) |
number = {1,2,3,4,5,6,7,8,9}
for a in number:
for b in number:
print(str(a)+"x"+str(b)+"="+str(a * b)) |
S = input()
for i in range(26):
a = chr(i + ord('a'))
if a not in S:
print(a)
exit()
print('None') |
import math
def main():
n = input()
for nn in n:
if int(nn) == 7:
print("Yes")
return
print("No")
return
main()
|
x = int(input())
y = [int(i) for i in input().split()]
print("{0}".format(y[-1]),end='')
for i in range(x-2, 0-1, -1):
print(' {0}'.format(y[i]), end='')
print() |
def is_prime(n):
n = abs(n)
if n==2: return True
if n<2 or n%2==0: return False
return pow(2, n-1, n) == 1
cnt = 0
for i in range(int(input())):
if is_prime(int(input())): cnt+=1
print(cnt) |
N = input()
N1 = [2,4,5,7,9]
N2 = [0,1,6,8]
N3 = [3]
N0 = int(N[-1])
if N0 in N1:
print('hon')
elif N0 in N2:
print('pon')
else:
print('bon') |
from decimal import Decimal
a, b, c = input().split()
a = Decimal(a)
b = Decimal(b)
c = Decimal(c)
if a.sqrt() + b.sqrt() < c.sqrt():
print('Yes')
else:
print('No') |
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
N = read_int()
S = input()
count = 1
for i in range(1, N):
if S[i] != S[i-1]:
count += 1
return count
if __name__ == '__main__':
print(solve())
|
import math
def average(l):
return sum(l) / len(l)
def var(l):
a = average(l)
return sum(map(lambda x: (x-a)**2, l)) / len(l)
def std(l):
return math.sqrt(var(l))
if __name__ == '__main__':
while True:
n = int(input())
if n == 0:
break
l = [int(i) for i in input().split()]
print("{0:.5f}".format(std(l))) |
def selection_sort(array):
count_swap = 0
for i in range(len(array)):
minj = i
for j in range(i + 1,len(array)):
if array[j] < array[minj]:
minj = j
if array[minj] is not array[i]:
tmp = array[minj]
array[minj] = array[i]
array[i] = tmp
count_swap += 1
return count_swap
def print_array(array):
print(str(array)[1:-1].replace(', ', ' '))
def main():
N = int(input())
array = [int(s) for s in input().split(' ')]
count = selection_sort(array)
print_array(array)
print(count)
if __name__ == '__main__':
main() |
import sys
input = sys.stdin.readline
def main():
s = str(input())
if s == 'ABC\n':
print('ARC')
else:
print('ABC')
main() |
S = input()
if ((("N" in S and "S" in S)
or("N" not in S and "S" not in S))
and(("E" in S and "W" in S)
or ("E" not in S and "W" not in S))):
print('Yes')
else:
print('No') |
while True:
text = input()
if text == '-':
break
count = int(input())
for c in range(count):
index = int(input())
text = text[index:] + text[:index]
print(text) |
N = int(input())
if N % 2 == 1:
print(0)
else:
i = 1
ans = 0
while 2*(5**i) <= N:
div = 2 * (5 ** i)
ans += int(N//div)
i += 1
print(ans) |
x,y=input().split()
if int(x)<=8 and int(y)<=8:
print('Yay!')
else:
print(':(') |
n = int(input())
for i in range(1, n+1):
if i%3 == 0:print(' '+str(i), end='')
else:
if '3' in str(i):print(' '+str(i), end='')
print()
|
X=int(input())
for a in range(10**4):
for b in range(10**4):
if a**5-b**5==X:print(a,b);exit()
elif a**5+b**5==X:print(a,-b);exit() |
res = ''
for i in range(3):
c = input()
res += c[i]
print(res) |
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)
n = int(input())
ans = []
def dfs(arr, max_val):
if len(arr) == n:
ans.append(arr)
return
for i in range(max_val + 2):
next_arr = arr[:]
next_arr.append(i)
dfs(next_arr, max(max_val, i))
dfs([0], 0)
ans.sort()
orda = ord("a")
for line in ans:
print("".join([chr(orda + item) for item in line])) |
S = input()
ok = True
for i, s in enumerate(S):
if not i % 2 and s == 'L':
ok = False
break
if i % 2 and s == 'R':
ok = False
break
if ok:
print('Yes')
else:
print('No') |
# coding: utf-8
from math import gcd
def getPrime(x):
num_list=[i for i in range(2,x+1)]
prime_list=[]
D=[x+1 for i in range(x+1)]
while num_list[0]<x**(1/2):
p=num_list.pop(0)
prime_list.append(p)
for i in range(len(num_list)):
if num_list[i]%p==0:
if D[num_list[i]]>p:
D[num_list[i]]=p
num_list = [e for e in num_list if e % p != 0]
prime_list = prime_list + num_list
for i in range(len(prime_list)):
D[prime_list[i]] = prime_list[i]
D[0]=1
D[1]=1
return D
N = int(input())
A = list(map(int,input().split()))
if max(A) == 1:
print("pairwise coprime")
exit()
D = getPrime(max(A))
pc_flg = True
x = A[0]
for i in range(N):
x = gcd(x,A[i])
prime_flg=[False for i in range(10**6+1)]
for i in range(N):
num = A[i]
primes = []
while True:
p = D[num]
num = num//p
primes.append(p)
if num == 1:
break
for j in set(primes):
if not(prime_flg[j]):
prime_flg[j] = True
else:
if j != 1:
pc_flg = False
if pc_flg:
print("pairwise coprime")
elif x==1:
print("setwise coprime")
else:
print("not coprime") |
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
alphabet = list(alphabet)
n = int(input())
s = input()
l = len(s)
for i in range(l):
k = alphabet.index(s[i])
print(alphabet[(k+n)%26], end = "")
print()
|
s = input()
map = {'SSS': 0, 'SSR': 1, 'SRS': 1, 'RSS': 1, 'SRR': 2, 'RSR': 1, 'RRS': 2, 'RRR': 3}
for key in map.keys():
if s == key:
print(map[key])
break |
s=input()
first_two=int(''.join(s[:2]))
last_two=int(''.join(s[2:]))
if 1<=first_two<=12 and 1<=last_two<=12:
print('AMBIGUOUS')
elif 1<=last_two<=12:
print('YYMM')
elif 1<=first_two<=12:
print('MMYY')
else:
print('NA') |
s = str(input())
def answer(s: str) -> str:
ans = ''
for i in range(len(s)):
if i % 2 == 0:
ans += s[i]
return ans
print(answer(s)) |
from collections import Counter
S = input()
Sd = Counter(S)
if len(Sd)==len(S):
print('yes')
else:
print('no') |
num_of_odd = num_of_even = 0
n, a, b = map(int, input().split())
if a == 1 and b == 2:
print('Borys')
elif a == n and b == n-1:
print('Borys')
elif a < b:
if (b-a) % 2:
print('Borys')
else:
print('Alice')
elif a > b:
if (a-b) % 2:
print('Alice')
else:
print('Borys') |
N=int(input())
count = 0
sum = 0
while N != 0:
count += 2**sum
sum += 1
N = int(N/2)
print(count) |
def isPrime(num):
if num <= 1:
return False
elif num == 2 or num == 3:
return True
elif num % 2 == 0:
return False
else:
count = 3
while True:
if num % count and count ** 2 <= num:
count += 2
continue
elif num % count == 0:
return False
else:
break
return True
if __name__ == '__main__':
count = 0
N = int(input())
for i in range(N):
i = int(input())
if isPrime(i):
count += 1
print(count)
|
a,b=map(int,input().split())
if a%2==0 or b%2==0:print('Even')
else:print('Odd')
|
def move_dice(d, dir):
if(dir == 'N'):
d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
if(dir == 'S'):
d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]
if(dir == 'E'):
d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
if(dir == 'W'):
d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]
def rotate_right_dice(d):
d[1], d[2], d[3], d[4] = d[3], d[1], d[4], d[2]
def to_up_dice(d, num):
num_index = d.index(num)
if(num_index==2 or num_index==3):
move_dice(d, 'E')
while(d[0] != num):
move_dice(d, 'N')
def to_front_dice(d, num):
while(d[1] != num):
rotate_right_dice(d)
dice = list(map(int, input().split()))
q = int(input())
for _ in range(q):
up, front = map(int, input().split())
to_up_dice(dice, up)
to_front_dice(dice, front)
print(dice[2]) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.