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 ...
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) a...
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 ...
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: re...
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) pri...
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 o...
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...
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...
#!/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))...
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: ...
# 素因数分解 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を法とす...
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(a...
#!/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 ...
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 += ...
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: ...
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_fra...
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[...
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 = [...
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 L...
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): ...
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(s...
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 inp...
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] ar...
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_va...
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: ...
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('Bor...
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...
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]...