text
stringlengths
37
1.41M
def gcd(a,b): if b==0: return a return gcd(b,a%b) def lcm(a,b): return a*b//(gcd(a,b)) N,M=map(int,input().split()) A=list(map(int,input().split())) LCM=1 for i in A: i=i//2 LCM=lcm(i,LCM) for i in A: i=i//2 if (LCM//i)%2==0: print(0) exit() ans=((M//LCM)+1)//2 print(ans)
n = int(input()) s = list(input().split()) s_set = set(s) print("Four" if len(s_set) == 4 else "Three")
K = int(input()) str = list(input()) if len(str) <= K: print("".join(str)) else: print("".join(str[0:K]) + "...")
while True: a=map(int,raw_input().split()) if a==[0,0]: break if a[0]>a[1]:print(str(a[1])+" "+str(a[0])) else: print(str(a[0])+" "+str(a[1]))
# coding: utf-8 stack = [] f = input().split() for s in f: if s in ('+', '-', '*'): stack.append(str(eval("{1}{2}{0}".format(stack.pop(), stack.pop(), s)))) else: stack.append(s) print(*stack)
while True: h,w = map(int,raw_input().split()) if h==0 and w==0: break sside="" #square side inside="" for x in xrange(1,w+1): sside += "#" if x==1 or x==w: inside += "#" else: inside += "." for x in xrange(1,h+1): if x==1 or x==h: ...
p,q= input().split() a,b =(int(p), int(q)) if a % 2==0 or b % 2==0: print('No') else: print('Yes')
#coding:utf-8 #1_11_B 2015.4.20 class Dice: def __init__(self,ary): self.top = ary[0] self.south = ary[1] self.east = ary[2] self.west = ary[3] self.north = ary[4] self.bottom = ary[5] def roll_n(self): self.top , self.south , self.bottom , self.north = s...
n = int(input()) a = [int(input()) for _ in range(n)] top1, top2 = sorted(a, reverse=True)[:2] for num in a: if num==top1: print(top2) else: print(top1)
N = int(raw_input()) count = 0 A_str = raw_input().split() A = map(int, A_str) def merge(left, right): global count sorted_list = [] l_index = 0 r_index = 0 while l_index < len(left) and r_index < len(right): count += 1 if left[l_index] <= right[r_index]: sorted_list.a...
S = input() base = ['A', 'T', 'G', 'C'] ans = '' a = '' for i in range(len(S)): if S[i] in base: a += S[i] if len(a) > len(ans): ans = a else: a = '' print(len(ans))
a = list(map(str,input().split())) if a[0] == a[1]: print("=") exit() b = sorted(a) if a == b: print("<") else: print(">")
import math def read_int(): return int(input().strip()) def read_ints(): return list(map(int, input().strip().split(' '))) def solve(): """ N = m*p+q = m*q+q = q*(m+1) q < m N%m = (m*p+q)%m = q%m = q = N/m = (m*p+q)/m = p 3*2+2 7*1+1 """ N = read_int() answer = 0 for...
n = list(input()) print("Yes") if any([i == "7" for i in n]) else print("No")
# coding: utf-8 # Your code here! S = input() # print(S) # print(len(S)) if len(S) == 2: print(S) elif len(S) == 3: s_reversed = reversed(S) # print(s_reversed) # print(S.reverse()) print(S[::-1]) else: pass
from math import sqrt n=int(input()) t=0 i=2 while i*i<=n: if n%i==0: c=0 while n%i==0: n//=i c+=1 t+=(int(sqrt(8*c+1))-1)//2 i+=1 if n>1: t+=1 print(t)
print("ABC"if int(input())<=999 else "ABD")
h = int(input()) def calc_need_atack_num(h): if h == 1: return 1 return calc_need_atack_num(h//2) * 2 + 1 print(calc_need_atack_num(h))
i = list(map(int, input().split())) H = i[0] W = i[1] while H != 0 or W != 0 : for i in range(H) : for j in range(W) : print('#', end='') if W != 0 : print() print() i = list(map(int, input().split())) H = i[0] W = i[1]
import sys def base_convert(n, b): if not n: return 0 res = '' while n: n, r = divmod(n, b) if r < 0: n += 1; r -= b res += str(r) return int(res[::-1]) n = int(sys.stdin.readline().rstrip()) def main(): print(base_convert(n, -2)) if __name__ == '__main__': main()
def is_prime(x): if x == 2: return True if x < 2 or x % 2 == 0: return False for i in range(3, int(x ** .5) + 1, 2): if x % i == 0: return False return True n = int(input()) print(sum(is_prime(int(input())) for _ in range(n)))
import sys import math def main(): N = int(input()) digit = int(math.log10(N)) c = N // (10**digit) if N < int(str(c) + '9'*digit): print(9 * digit + c -1) else: print(9 * digit + c) if __name__ == '__main__': main()
# -*- coding:utf-8 -*- string = input() array = string.split() a,b = int(array[0]),int(array[1]) if a < b: print("a < b") elif a > b: print("a > b") else: print("a == b")
def prime_factorize(n): # nの素因数分解 a = [] while n % 2 == 0: a.append(2) n = n // 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n = n // f else: f += 2 if n != 1: a.append(n) return a def abc052_c(): n = int(input()) if n == 1: print(1) return # 2...
from collections import deque n = int(input()) l = deque() for _ in range(n): command = input().split() if command[0] == "insert": l.appendleft(command[1]) elif command[0] == "delete": try: ind = l.remove(command[1]) except ValueError: pass elif command[...
s = input() if s=='AAA' or s=='BBB' : print('No') else : print('Yes')
import sys def reverse(str, a, b): head = str[0:a] tail = str[b + 1:] mid = str[a:b + 1] reversed_str = head + mid[::-1] + tail return reversed_str def replace(str, a, b, rstr): head = str[0:a] tail = str[b + 1:] replaced_str = head + rstr + tail return replaced_str #fin = open("test.txt", "r") fin = sys.s...
a = input().split() b = a[0] c = a[1] if b == c: print("Yes") else: print("No")
# xの根を求める def find(x): if par[x] < 0: return x else: par[x] = find(par[x]) return par[x] # xとyの属する集合の併合 def union(x, y): x = find(x) y = find(y) if x == y: return # sizeの大きいほうがx if par[x] > par[y]: x, y = y, x par[x] += par[y] par[y] =...
import math N = int(input()) cnt =0 for a in range(1,N): cnt += math.floor((N-1)/a) print(cnt)
def insertionSort(a): for i,v in enumerate(a): j=i-1 while j>=0 and a[j]>v: a[j+1]=a[j] j-=1 a[j+1]=v print(*a) n = int(input()) a = list(map(int,input().split())) insertionSort(a)
word = input() word_len = len(word) if word[word_len-1] == 's': print(word + 'es') else: print(word + 's')
n = int(input()) a = [int(input()) for _ in range(n)] b = sorted(a) for i in a: print(b[-1] if i != b[-1] else b[-2])
a = int(input()) if a == 1: print(3) else: print(int((a**3-1)*a/(a-1)))
import numpy as np def divisor(n): i = 1 table = [] while i * i <= n: if n%i == 0: table.append(i) table.append(n//i) i += 1 table = list(set(table)) table = sorted(table) return table def make_prime(U): is_prime = np.zeros(U,np.bool) is_prime[2...
S = input() flug = True for i, value in enumerate(S): if i % 2 == 0: if value == 'L': flug = False else: if value == 'R': flug = False if flug: print("Yes") else: print("No")
n = int(input()) a = [] for i in range(1, n+1): if i%3 == 0 or i%5 == 0: continue else: a.append(i) print(sum(a))
S = list(input()) odd = ["R", "U", "D"] even = ["L", "U", "D"] ans = "Yes" for i, s in enumerate(S): if i%2==0 and s not in odd: ans = "No" break elif i%2==1 and s not in even: ans = "No" break print(ans)
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) INF = float("inf") def solve(N: int, M: int): # N <= 10**5 # 差が異なる組み合わせならば、N回を通して同じ組み合わせにはならない。 # 前に奇数差、後ろに偶数差を作る ans = [] if N % 2 == 0: # 差は偶数 a, b = (0, N//2-1) # print(a, b) while a < b: ...
def gcd(a,b): while a%b : a,b=b,a%b return b def lcm(a,b): return a*b/gcd(a,b) while True : try: a,b = map(int,raw_input().split()) a,b = max(a,b), min(a,b) print "%d" % gcd(a,b), print "%d" % lcm(a,b) except EOFError: break
debt = 100000 for i in range(int(raw_input())): debt *= 1.05 if debt % 1000: debt = int(debt) / 1000 * 1000 + 1000 print debt
#!/user/bin/env pypy3 import sys from typing import List def fast_input(): return sys.stdin.readline()[:-1] def is_all_even(nums: List[int]) -> bool: for n in nums: if n % 2 == 1: return False return True def solve(n: int, nums: List[int]) -> int: manipulate_count = 0 while...
s="".join(sorted(str(input()))) t="".join(sorted(str(input()),reverse=True)) if s<t: print("Yes") else: print("No")
def main(): N, a, b, c, d = (int(i) for i in input().split()) S = input() if "##" in S[a:c] or "##" in S[b:d]: return print("No") if c < d: return print("Yes") # d < c if "..." in S[b-2:d+1]: print("Yes") else: print("No") if __name__ == '__main__': main...
a,b,c=map(int,raw_input().split()) if a<0 or a>100 or b<0 or b>100 or c<0 or c>100: pass elif a<b<c: print "Yes" else: print "No"
def calcTime(x): n = 0 while True: if n*(n+1)//2 > x: return n elif n*(n+1)//2 == x: return n else: n += 1 x = int(input()) ans = calcTime(x) print(ans)
""" https://atcoder.jp/contests/abc087/tasks/arc090_b xR-xL = D Mこの情報が正しいかどうかの判定 グループを作って、グループ内の拘束条件があっているか確認 重み付きunionfindを使う https://qiita.com/drken/items/cce6fc5c579051e64fab http://at274.hatenablog.com/entry/2018/02/03/140504 5 5 1 2 2 2 3 3 4 5 4 2 5 10 3 4 3 """ from collections import defaultdict class Union...
if __name__ == '__main__': # ??????????????\??? weeks = int(input()) principal = 100000 # ??????????¨???? for i in range(weeks): interest = principal * 0.05 principal += interest fraction = principal % 1000 if fraction != 0: principal += (1000 - fraction)...
while True: x = str(raw_input()) if int(x) == 0: break sum = 0 for i in range(len(x)): sum += int(x[i]) print sum
from math import gcd def lcm(a, b): return a * b / gcd(a, b) x = int(input()) ans = int(lcm(360, x) // x) print(ans)
class Dice(object): def __init__(self, num): self.num = num def rotate_S(self): self.num = [self.num[4], self.num[0], self.num[2], self.num[3], self.num[5], self.num[1]] def rotate_N(self): self.num = [self.num[1], self.num[5], self.num[2], self.num[3], self.num[0], self.num[4]] ...
N = int(input()) buttons = [int(input()) for i in range(N)] cur = 1 for i in range(N): cur = buttons[cur-1] if cur == 2: print(i+1) exit() print(-1)
st = str(input()) dum = st.split() d = int(dum[0]) t = int(dum[1]) s = int(dum[2]) tv = float(d / t) if tv <= s: print('Yes') else: print('No')
#好きに置いて好きに転がす #65のみ x = int(input()) ans = (x//11)*2 x%=11 if x: if x<=6: ans += 1 else: ans +=2 print(ans)
A,B=list(map(int,input().split())) def gcd(A, B): if B==0: return(A) else: return(gcd(B, A%B)) print(gcd(A,B))
a,b=map(int, input().split()) if a<b:print("a < b") elif a>b:print("a > b") else: print("a == b")
s = input() s_r = list(reversed(s)) count = 0 for i in range(len(s)): if s[i] != s_r[i]: count += 1 print(count//2)
N = int(input()) max_power = 0 for a in range(1, N + 1): if a**2 <= N: max_power = a**2 else: break print(max_power)
n = int(input()) a = 1 while a * 2 <= n: a *= 2 print(a)
import math a,b,c,d = (int(x) for x in input().split()) if math.ceil (a/d) < math.ceil (c/b): print ('No') else: print ('Yes')
s = input() n = int(input()) for _ in range(n): line = input().split() command, args = line[0], line[1:] start = int(args[0]) end = int(args[1]) + 1 if command == 'replace': s = s[:start] + args[2] + s[end:] elif command == 'reverse': s = s[:start] + str(''.join(list(reversed(s[s...
S = input() flag = 0 words = ("dream","erase","dreamer","eraser") count = 0 while len(S) >= 5: for i in words: N = len(i) if S[-N:] in words: n = len(S) - N S = S[:n] flag = 1 break else: flag = 0 continue if f...
def main(): N, M = (int(i) for i in input().split()) par = [i for i in range(N)] rank = [0 for i in range(N)] def find_root(x): if par[x] == x: return x else: par[x] = find_root(par[x]) return par[x] def is_same_group(x, y): return find_r...
#define S as string #print S until len is equal to K #time complexity O(1) K = int(input()) S = input() str = S if len(S) > K: print (str[0:K]+ "...") else: print(str)
# -*- coding: utf-8 -*- def main(): inline = [input() for i in range(1)] outline = 0 try: wk_inline = int(inline[0]) except Exception as e: print('整数値を入力してください') return 0 if wk_inline % 2 == 0: outline = wk_inline //2 -1 else: outline = wk_inline // 2 print(outline) return 0 ...
# -*- coding: utf-8 -*- import sys import os s = input().strip() N = int(input()) for i in range(N): lst = input().split() command = lst[0] if command == 'replace': a = int(lst[1]) b = int(lst[2]) p = lst[3] s = s[:a] + p + s[b+1:] elif command == 'reverse': a ...
#ABC096-D Five, Five Everywhere """ 問題: 55555以下の異なる素数をN個出力せよ。 但し、N個のうちどの5つの素数を組み合わせても素数にならないように しなければならない。 このような数列は必ず作れるものと仮定して良い。(5<=N<=55) 解法: 5で割って1余る素数の個数は55555以下のうち1408個存在する。 よってこのうち適当にN個とって出力すれば良い。 """ import sys readline = sys.stdin.buffer.readline def even(n): return 1 if n%2==0 else 0 n = int(readline()) imp...
N = int(input()) ans = 'No' for i in range(1, 10): if N % i == 0 and N / i < 10: ans = 'Yes' break print(ans)
def isprime(x): if x == 2: return True elif x < 2 or x%2 == 0: return False i = 3 while i <= pow(x,1/2): if x%i == 0: return False i = i + 2 return True count = 0 for s in range(int(input())): if isprime(int(input())): count += 1 print(count)
#!/usr/bin/env python # -*- coding: utf-8 -*- def main(): N = int(input()) mod = 10**9 + 7 print((10**N - 9**N - 9**N + 8**N) % mod) if __name__ == "__main__": main()
char = input() index = 3 print(char[:index] + '8' + char[index + 1:])
def main(): x = int(input()) cnt = x // 11 * 2 rem = x % 11 if rem > 6: cnt += 2 elif rem > 0: cnt += 1 print(cnt) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys from itertools import chain # floor(A x / B) - A * floor(x / B) # # x = B * x1 + x2 : (x2 < B) とする # # = floor(A (B*x1+x2) / B) - A floor((B*x1+x2) / B) # = A x1 + floor(A x2 / B) - A x1 # = floor(A x2 / B) def solve(A: int, B: int, N: int): if N >= B: x2 = B - 1 el...
# ALDS1_3_C.py ''' 本来はlinkedList を自前実装する必要がありそうだが、Python だとDequeで実装できる。 ''' from collections import deque N = int(input()) linkedList = deque([]) for i in range(N): command = input().split() if command[0] == "insert": linkedList.appendleft(command[1]) elif command[0] == "delete": if command[...
k = int(input()) even = 0 odd = 0 for i in range(k): if (i+1)%2 == 0: even += 1 else: odd += 1 print(even*odd)
def resolve(): a = input() b = input() c = input() count = "a" for i in range(len(a)+len(b)+len(c)): if count == "a": if len(a) != 0: count = a[0] a = a[1:] else: print("A") exit() elif count == "...
S = input() ng = False for i, c in enumerate(S): if ((i + 1) % 2 == 0 and c == 'R') or ((i + 1) % 2 == 1 and c == 'L'): ng = True break if ng: print('No') else: print('Yes')
n = int(input()) a = [int(input()) for _ in range(n)] b = sorted(a, reverse=True) max_a = max(a) for x in a: if x == max_a: print(b[1]) else: print(b[0])
def gcd(p,q): while q != 0: r = p % q p = q q = r return p k = int(input()) a = 0 for i in range(1,k+1): for j in range(1,k+1): for k in range(1,k+1): a += gcd(gcd(i,j),k) print(a)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- x = int(input()) r = 100 n=0 while True: n=n+1 #r = r+int(r*0.01) r = r+int(r//100) if r >= x: break print(n)
n = int(input()) text = input() count = 0 for i in range(n-2): target = text[i:i+3] if target == 'ABC': count += 1 print(count)
a, b = map(int, input().split()) zero = (a == 0 | b == 0) | (a < 0 and 0 < b) | (b < 0 and 0 < a) negative_a = (a < 0 and 0 < b) and (a + b + 1) % 2 != 0 negative_b = (a < 0 | b < 0) and (a + b + 1) % 2 != 0 if zero: print("Zero") elif negative_a | negative_b: print("Negative") else: print("Positive")
s=input() if 'C' in s: A=s.index('C') for i in range(A,len(s)): if s[i]=='F': print('Yes') break else: print('No') else: print('No')
s=input() n=len(s) for i in range(n): print("x",end="") print("")
a=int(input()) if a==2: print(int(input())+int(input())) else: print('Hello World')
s = input() ans = True if "a" not in s: ans = False if "b" not in s: ans = False if "c" not in s: ans = False if ans: print("Yes") else: print("No")
# 数値と文字の取得 num = int(input()) colors = list(map(str,input().split())) # 黄色があるか判定し結果を出力 if colors.count("Y") >0: print("Four") else: print("Three")
N = int(input()) print(0) MorF = input() if MorF == 'Vacant': exit() iSt = 1 iEn = N - 1 seat = MorF while True: iMid = (iSt + iEn) // 2 print(iMid) MorF = input() if MorF == 'Vacant': break if MorF == seat: if (iMid - iSt) % 2: iSt = iMid + 1 seat = M...
S = input() s = list(set(S)) if(len(s) == 2): if(S.count(s[0]) == 2 and S.count(s[1]) == 2): print('Yes') else: print('No') else: print('No')
N=int(input()) b=-2 temp=N ans="" while True: if temp%b!=0: ans="1"+ans temp=temp-(b//(-2)) else: ans="0"+ans b=b*(-2) if temp==0:break print(ans)
l = input().split() a, b, c = list(map(int, l)) if a < b < c: print('Yes') else: print('No')
# A - Between Two Integers # A B C の3つの整数が与えられる # 整数 C が A以上 かつ B以下である時 Yes # そうでないとき No # A B C を標準入力から得る A, B, C = map(int, input().split(maxsplit=3)) if A <= C <= B: answer = "Yes" else: answer = "No" # 結果を出力 print(answer)
import sys from collections import deque def input(): return sys.stdin.readline().strip() def get_sieve_of_eratosthenes(n): """ エラトステネスの篩 """ if not isinstance(n, int): raise TypeError('n is int type.') if n < 2: return [] prime = [2] limit = int(n**0.5) data = [i + 1 f...
print("Yes" if eval(input().replace(" ","+",1).replace(" ","-",1)) >= 0 else "No")
s1, s2, s3 = input().split() print(''.join([s1[0].upper(),s2[0].upper(), s3[0].upper()]))
S = list(input()) if S[0] == 'A': cnt = 0 for i in range(2, len(S)-1): if S[i] == 'C': cnt += 1 if cnt == 1: S.sort() for i in range(2, len(S)): if S[i].isupper(): print('WA') exit() print('AC') else: print(...
print((lambda x,y:'Yes'if y in x else'No')(input()*2,input()))
N = int(input()) A = int(input()) if N %500 == 0: print("Yes") #もしNが9999だったら、500円硬貨19枚と1円硬貨が499枚数によって支払い可能。 #その499の算出方法は9999を500で割った時の余り、つまりN%500  #この時、Aがもし499以上だったら支払い可能だが、498以下だったら不足しており支払い不可。 elif N %500 <= A: print("Yes") else: print("No")
# coding: utf-8 # Your code here! class dice(object): def __init__(self, arr): self.top = arr[0] self.side_s = arr[1] self.side_e = arr[2] self.side_w = arr[3] self.side_n = arr[4] self.bottom = arr[5] def roll(self, s): if s=='S': tmp = self....
n = input() cnt = 0 for i in range(len(n)): if n[i] == "2": cnt += 1 print(cnt)