text
stringlengths
37
1.41M
def atc_089b(input_value: str) -> str: N = input_value[0] Si = input_value[1] colors = ["P" in Si, "W" in Si, "G" in Si, "Y" in Si] if colors.count(True) == 3: return "Three" elif colors.count(True) == 4: return "Four" else: return "other" N_input = input() Si_input = input() print(atc_089b([N_input, Si_input]))
def main(N): if N==1: return 0 elif N==2: return 2 else: return (10**N - (9**N*2 - 8**N))%(10**9 + 7) if __name__ == '__main__': N = int(input()) ans = main(N) print(ans)
N = int(input()) ansAC = 0 ansWA = 0 ansTLE = 0 ansRE = 0 for i in range(N): S = input() if S == "AC": ansAC += 1 elif S == "TLE": ansTLE += 1 elif S == "WA": ansWA += 1 elif S == "RE": ansRE += 1 print("AC x " + str(ansAC)) print("WA x " + str(ansWA)) print("TLE x " + str(ansTLE)) print("RE x " + str(ansRE))
N = str(input()) N_List = ["3","5","7"] if N in N_List: print("YES") else: print("NO")
import sys def input(): return sys.stdin.readline().strip() mod = 10**9+7 def get_sieve_of_eratosthenes(n): """ エラトステネスの篩。√N以下の数に対して2から順にその数の倍数を消していく。 計算量は「調和級数」になるのがミソ。具体的には N/2 + N/3 + N/5 + ... + N/(√N) = N * (1/2 + 1/3 + 1/5 + ... + 1/√N) = N * loglog(√N) (素数の逆数和の発散スピードがこれ) = N(loglogN - log2) """ if not isinstance(n, int): raise TypeError('n is int type.') if n < 2: return [0] * (n + 1) prime = [1] * (n + 1) prime[0] = prime[1] = 0 for i in range(2, int(n**0.5) + 1): if not prime[i]: continue for j in range(i * 2, n + 1, i): prime[j] = 0 return prime def main(): n = int(input()) primes = get_sieve_of_eratosthenes(n) ans = 1 for p in range(2, n + 1): if primes[p] == 0: continue cur = p num = 0 while cur <= n: num += n // cur cur *= p ans *= (num + 1) ans %= mod print(ans) if __name__ == "__main__": main()
import math def is_prime(n): for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return n != 1 n = int(input()) answer = 0 for _ in range(0, n): m = int(input()) if is_prime(m): answer = answer + 1 print(answer)
import re S = input() print('AC' if S.startswith('A') and (S[2:-1]).count('C') == 1 and len(re.findall('[A-Z]', S)) == 2 else 'WA')
def main(): x, a, b = map(int, input().split()) if b <= a: print("delicious") elif a < b and b <= a + x: print("safe") elif a + x < b: print("dangerous") main()
N,M = (int(x) for x in input().split()) Even = N*(N-1)//2 Odd = M*(M-1)//2 print(Even+Odd)
order=[] for number in range(10): hight=int(input()) order.append(hight) for j in range(9): for i in range(9): if order[i] < order[i+1]: a = order[i] b = order[i+1] order[i] = b order[i+1] = a for i in range(3): print(order[i])
x = int(input().rstrip()) if x >= 30: print("Yes") else: print("No")
num1, op, num2 = input().split() if op == "+": print(int(num1) + int(num2)) elif op == "-": print(int(num1) - int(num2))
from math import pi, tan, atan, degrees a, b, x = [int(i) for i in input().split()] theta = (pi * 0.5) - atan(2 * x / (a * b**2)) if b * tan(pi * 0.5 - theta) <= a: print(degrees(theta)) else: theta = atan(((2 * b) / a) - (2 * x / a**3)) print(degrees(theta))
import math t = float(input()) a = math.pi * t**2 b = 2 * t * math.pi print(str("{0:.8f}".format(a)) + " " + "{0:.8f}".format(b))
uppers = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' lowers = 'abcdefghijklmnopqrstuvwxyz' s = str(input()) for i in range(len(s)): if s[i] in uppers: print(s[i].lower(), end='') elif s[i] in lowers: print(s[i].upper(), end='') else: print(s[i], end='') print('')
n = int(raw_input()) def isprime(m): if m == 2: return 1 elif m < 2 or m % 2 == 0: return 0 else: p = 3 while p <= m**0.5: if m % p == 0: return 0 p = p + 2 return 1 cnt = 0 for i in range(n): cnt += isprime(int(raw_input())) #print("*{:}".format(cnt)) #print("") print cnt
s = list(input()) ans = 'Yes' if s[2] == s[3] and s[4] == s[5] else 'No' print(ans)
import math def factrization_prime(number): factor = {} div = 2 s = math.sqrt(number) while div < s: div_cnt = 0 while number % div == 0: div_cnt += 1 number //= div if div_cnt != 0: factor[div] = div_cnt div += 1 if number > 1: factor[number] = 1 return factor N = int(input()) dic = factrization_prime(N) ans = 0 for d in dic.keys(): x = dic[d] minus = 1 while(x>0): x -= minus minus += 1 if x >= 0: ans += 1 print(ans)
#!/usr/bin/env python3 n = [int(x) for x in input().split()] print("YES" if sorted(n) == [1, 4, 7, 9] else "NO")
s = input() q = int(input()) for i in range(q): command = input().split() command[1] = int(command[1]) command[2] = int(command[2]) if command[0] == 'print': print(s[command[1]:command[2]+1]) elif command[0] == 'reverse': s = s[command[1]:command[2]+1][::-1].join([s[:command[1]], s[command[2]+1:]]) elif command[0] == 'replace': s = command[3].join([s[:command[1]], s[command[2]+1:]])
input_str = input().split(' ') a = int(input_str[0]) b = int(input_str[1]) c = int(input_str[2]) print('Yes' if a < b < c else 'No');
ABC = [int(i) for i in input().split()] if(ABC[0]==ABC[1] and ABC[1]==ABC[2]): print("Yes") else: print("No")
# -*- coding: utf-8 -*- import sys import os import math n = int(input()) A = list(map(int, input().split())) cnt = 0 def merge(A, left, mid, right): global cnt S = A[left:mid] T = A[mid:right] S.append(float('inf')) T.append(float('inf')) s_i = 0 t_i = 0 for i in range(right - left): cnt += 1 if S[s_i] < T[t_i]: A[left + i] = S[s_i] s_i += 1 else: A[left + i] = T[t_i] t_i += 1 def merge_sort(A, left, right): if left + 1 == right: # ??????????????? return else: # ?????????????????? mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) merge_sort(A, 0, len(A)) print(*A) print(cnt)
def main(): s = input() k = int(input()) ss = set() sss = sorted(s) for i in range(len(s)): for j in range(i+1, i+6): ss |= {s[i:j]} print(sorted(ss)[k-1]) if __name__ == "__main__": main()
num, num1, num2 = input("").split() num = int(num) num1 = int(num1) print(int(num*num1/2))
a = input() weather_today = {'Sunny':0 , 'Cloudy':1 , 'Rainy':2} weather_next = ['Cloudy', 'Rainy','Sunny'] print(weather_next[weather_today[a]])
N = int(input()) ans = 0 for i in range(1, N+1): n = N // i temp_sum = n / 2 * (i + n*i) ans += int(temp_sum) print(ans)
c = [] c.append(list(input())) c.append(list(input())) if c[0][0] == c[1][2] and c[0][2] == c[1][0] and c[1][1] == c[0][1]: print("YES") else: print("NO")
x=int(input()) if x>=10000 or x//100*5>=x%100: print(1) else: print(0)
str = input() if(len(str)==3): str = str[2]+str[1]+str[0] print(str)
arr = [] for i in range (10): arr.append(int(input())) arr.sort() arr.reverse() for a in range (3): print(arr[a])
x=int(input()) if x<=6: print(1) else: ans=(x//11)*2 if x%11==0: pass elif (x//11)%2==0: if x%11<=6: ans+=1 else: ans+=2 else: if x%11<=5: ans+=1 else: ans+=2 print(ans)
from math import atan from math import degrees a,b,x=map(int,input().split()) X=x/a if X>a*b/2: print(degrees(atan(2/a**2*(a*b-X)))) else: print(90-(degrees(atan(2*X/b**2))))
import math N=int(input()) while True: if math.sqrt(N).is_integer(): print(N) break N-=1
N = int(input()) L0 = 2 L1 = 1 if N == 1: print(L1) else: for i in range(N-1): L1, L0 = L1 + L0, L1 print(L1)
a, b = map(int,input().split()) area = a * b perimeter = (a + b) * 2 print(str(area) + ' ' + str(perimeter))
def main(): N = int(input()) FN = 0 res = N while res >0: FN = FN + res%10 res = res//10 if N%FN == 0: print('Yes') else: print('No') return main()
''' def num_div(n): cnt = 0 for i in range(1, n+1, 2): if n % i == 0: cnt += 1 return cnt l = [] for i in range(1, 201): if num_div(i) == 0: l.append(i) ''' l = [105, 135, 165, 189, 195] n = int(input()) for i in range(5): if n < l[i]: print(i) exit() print(5)
A = int(input()) B = int(input()) if (A, B) == (1, 2) or (A, B) == (2, 1): print(3) elif (A, B) == (1, 3) or (A, B) == (3, 1): print(2) else: print(1)
n = "keyence" s = input() for i in s: if n[0] == i: n = n[1:] else: break for i in s[::-1]: if n == "": print("YES") exit() elif n[-1] == i: n = n[:-1] else: break print("NO")
x=int(input()) #階差数列 y,i=1,1 while y<x: i+=1 y+=i print(i)
s = input() if "L" in s[0::2] or "R" in s[1::2]: print("No") else: print("Yes")
input() S=input() k=int(input()) for s in S:print(s if s==S[k-1] else "*",end="")
x=int(input()) if(x<=6): print(1) elif(x<=11): print(2) elif(x>11 and x%11==0): print((x//11)*2) elif(x>11 and x%11<=6): print((x//11)*2+1) elif(x>11 and x%11>6): print((x//11)*2+2)
import math r = float(input()) e = 2 * math.pi * r m = r * r * math.pi print("{0:.6f} {1:.6f}".format(m, e))
N = int(input()) ans = [" " + str(i) for i in range(1, N + 1) if i % 3 == 0 or '3' in str(i)] print("".join(ans))
def actual(N): f = lambda x: sum(map(int, str(N))) if N % f(N) == 0: return 'Yes' return 'No' N = int(input()) print(actual(N))
a,b = list(map(int,input().split())) c = a*b//2 if (c*2 == a*b): print("Even") else: print("Odd")
def root(x): if data[x]<0:return x else: data[x]=root(data[x]) return data[x] def unite(x,y): x,y=root(x),root(y) if x!=y: if data[x]>data[y]:x,y=y,x data[x]+=data[y] data[y]=x from collections import* r=range h,*s=open(0) h,w=map(int,h.split()) data=[-1]*h*w for i in r(h): for j in r(w): if i+1<h and s[i][j]!=s[i+1][j]: unite(i*w+j,-~i*w+j) if j+1<w and s[i][j]!=s[i][j+1]: unite(i*w+j,i*w+j+1) d=defaultdict(lambda:[0,0]) for i in r(h*w):d[root(i)][s[i//w][i%w]<'.']+=1 print(sum(i*j for i,j in d.values()))
# 配列の宣言 A = [] B = [] # 文字列の取得と加工 LENGTH =int(input()) A = input().split() B = A.copy() def bubble (A, LENGTH): N = 0 M = LENGTH - 1 CHANGE = 0 while N <= LENGTH -1: M = LENGTH - 1 while M >= N + 1: if int(A[M][1:]) < int(A[M-1][1:]): tmp = A[M-1] A[M-1] = A[M] A[M] = tmp CHANGE += 1 M -= 1 N += 1 print(" ".join(map(str,A))) print("Stable") def selection (B, LENGTH): i = 0 CHANGE_COUNT = 0 while i <= LENGTH -1: j = i + 1 mini = i while j <= LENGTH -1: if int(B[j][1:]) < int(B[mini][1:]): mini = j j += 1 if mini != i: tmp = B[i] B[i] = B[mini] B[mini] = tmp CHANGE_COUNT += 1 i += 1 print(" ".join(map(str,B))) if A == B: print("Stable") else: print("Not stable") bubble (A, LENGTH) selection (B, LENGTH)
a,b=[int(x) for x in input().split()] op = ">" if a > b else "<" if a < b else "==" print("a",op,"b")
from math import sqrt x = int(input()) l = [] if x == 1: print(1) exit() for i in range(1, int(sqrt(x))+1): for j in range(2, x+1): if 1 <= i**j <= x: l.append(i**j) print(max(l))
n = int(input()) A = list(map(int,input().split())) odd = 0 for a in A: if a%2!=0: odd += 1 print('YES' if odd%2==0 else 'NO')
n = int(input()) s = set([]) for i in range(n): cmd, str1 = input().split() if cmd == "insert": s.add(str1) else: if str1 in s: print("yes") else: print("no")
spam = [int(input()) for i in range(0, 10)] spam.sort() spam.reverse() for i in range(0,3): print(spam[i])
import math r = float(input()) area = math.pi * r * r circumference = math.pi * r * 2 print("%.5f %.5f" % (area, circumference))
count = 0 N = input() for i in N: if int(i) == 2: count += 1 print(count)
from math import gcd from functools import reduce MOD = 10 ** 9 + 7 def calc_lcm(x, y): return x * y // gcd(x, y) def calc_lcm_list(numbers): return reduce(calc_lcm, numbers, 1) N, *A = map(int, open(0).read().split()) lcm = calc_lcm_list(A) print(sum(lcm // v for v in A) % MOD)
while 1: H, W = map(int, raw_input().split()) if H == 0 and W == 0: break print "#"*W for i in range(1, H-1): print ("#"+"."*(W-2)+"#") print "#"*W print ""
n = int(input()) rule = [] w = input() rule.append(w) now = w[-1] for i in range(n - 1): w = input() if w in rule: print("No") exit() elif now != w[0]: print("No") exit() else: rule.append(w) now = w[-1] print("Yes")
N = int(input()) A = int(input()) condition = (N % 500 <= A) print('Yes' if condition is True else 'No')
def main(): n = int(input()) count = 0 for _ in range(n): x = int(input()) count += isprime(x) print(count) def isprime(x: int): if x == 2: return True if x % 2 == 0: return False for y in range(3, int(x**0.5)+1, 2): if x % y == 0: return False return True if __name__ == '__main__': main()
s = list(input().strip()) len_s = len(s) if s[len_s-1] == "s": s += "es" else: s += "s" s= "".join(s) print(s)
x = input() x = int(x) # OUTPUTS # Print 1 if input is equal to 0 if x == 0: print(1) exit() # Print 0 if input is equal to 1 if x == 1: print(0) exit()
a=[x for x in input()] b=[x for x in input()][::-1] print('YES' if a==b else 'NO')
s = [i for i in input().split()] print('YES' if s[0][-1]==s[1][0] and s[1][-1]==s[2][0] else 'NO')
#!/usr/bin/env python # coding: utf-8 # In[14]: from collections import deque # In[21]: S = deque(input()) Q = int(input()) rev_cnt = 0 for _ in range(Q): q = input().split() if len(q) == 1: rev_cnt += 1 else: if (rev_cnt+int(q[1]))%2 == 0: S.append(q[2]) else: S.appendleft(q[2]) if rev_cnt%2 == 0: print("".join(S)) else: print("".join(list(reversed(S)))) # In[ ]:
N = int(input()) A = list(map(int, input().split())) for i in A: if i % 2 == 0 and i % 3 != 0 and i % 5 != 0: result = 'No' break else: result = 'Yes' if result == 'No': print('DENIED') else: print('APPROVED')
class Dice: def __init__(self,num): self.num = num.copy() def east(self): temp = self.num.copy() self.num[1-1] = temp[4-1] self.num[4-1] = temp[6-1] self.num[6-1] = temp[3-1] self.num[3-1] = temp[1-1] def north(self): temp = self.num.copy() self.num[1-1] = temp[2-1] self.num[2-1] = temp[6-1] self.num[6-1] = temp[5-1] self.num[5-1] = temp[1-1] def south(self): temp = self.num.copy() self.num[1-1] = temp[5-1] self.num[5-1] = temp[6-1] self.num[6-1] = temp[2-1] self.num[2-1] = temp[1-1] def west(self): temp = self.num.copy() self.num[1-1] = temp[3-1] self.num[3-1] = temp[6-1] self.num[6-1] = temp[4-1] self.num[4-1] = temp[1-1] num = list(map(int,input().split())) dice = Dice(num) command = input() for c in command: if c == 'E': dice.east() elif c == 'N': dice.north() elif c == 'S': dice.south() elif c == 'W': dice.west() print(dice.num[0])
n = int(input()) tmp, nx = 0, n while nx: tmp += nx%10 nx //= 10 if n % tmp: print("No") else: print("Yes")
from itertools import product n = int(input()) i = len(str(n)) cnt = 0 for j in range(3, i+1): for k in product(["3", "5", "7"], repeat=j): if len(set(k)) != 3: continue if int("".join(k)) <= n: cnt += 1 print(cnt)
# -*- coding: utf-8 -*- loop = 1 while(loop): l = input().strip().split() H = int(l[0]) W = int(l[1]) if(H == 0 and W == 0): break else: for y in (range(H)): for x in (range(W)): if(x == 0 or y == 0 or x == (W-1) or y == (H-1)): print("#",end="") else: print(".",end="") print() print()
def gcd(a,b): while True: if a > b: a %= b else: b %= a if a == 0 or b == 0: return max(a,b) def lcm(a,b,g): return int(a*b/g) from sys import stdin for l in stdin: a,b = list(map(int,l.split())) g = gcd(a,b) print ("%s %s"%(g,lcm(a,b,g)))
s = list(input()) n = int(input()) for i in range(n): d = input().split(" ") if d[0] == "replace": a = int(d[1]) b = int(d[2]) c = list(d[3]) k = 0 for j in range(a, b+1): s[j] = c[k] k += 1 elif d[0] == "reverse": a = int(d[1]) b = int(d[2]) c = list(s) k = b for j in range(a, b+1): s[j] = c[k] k -= 1 else: a = int(d[1]) b = int(d[2]) for j in range(a, b+1): print(s[j],end="") print("")
abc = list(map(int,input().split())) ans = "NO" if 5 in abc: abc.remove(5) if 5 in abc and 7 in abc: ans = "YES" print(ans)
a=list(input()) b=list(input()) c=list(input()) ans="a" while True: try: if ans == "a": ans=a[0] a=a[1:] elif ans == "b": ans = b[0] b=b[1:] elif ans == "c": ans = c[0] c=c[1:] except: print(ans.upper()) break
import math import itertools # 与えられた数値の桁数と桁値の総和を計算する. def calc_digit_sum(num): digits = sums = 0 while num > 0: digits += 1 sums += num % 10 num //= 10 return digits, sums n = int(input()) p = list(map(int, input().split())) q = list(map(int, input().split())) pidx, qidx = 0, 0 candidates = list(itertools.permutations(range(1, n+1), n)) for index, candidate in enumerate(candidates): candidate = list(candidate) if candidate == p: pidx = index if candidate == q: qidx = index print(abs(pidx - qidx))
a,b = input().split() dic = {'A':0, 'B':1, 'C':2, 'D':3, 'E':4, 'F':5} if dic[a] > dic[b]: print(">") elif dic[a] == dic[b]: print("=") else: print("<")
import math n=int(input()) s=math.factorial(n) ans=s%(10**9+7) print(ans)
a = str(input()) b = str(input()) if a[:len(a)] == b[:len(a)] and len(b)==len(a)+1: print("Yes") else: print("No")
s = input() result = 'No' if len(s) % 2 == 0: result = 'Yes' for i in range(int(len(s) / 2)): if s[i*2:i*2+2] != 'hi': result = 'No' break print(result)
# ABC155 B - Papers, Please N =int(input()) A = list(map(int,input().split())) B=[] for i in range(len(A)): if A[i]%2 ==0: B.append(A[i]) if all([B[j]%3==0 or B[j]%5==0 for j in range(len(B))]): print('APPROVED') else: print('DENIED')
def bubbleSort(R, N): flag = True cnt = 0 while flag == True: flag = False for j in range(N - 1, 0, -1): if R[j] < R[j - 1]: tmp = R[j] R[j] = R[j - 1] R[j - 1] = tmp cnt = cnt + 1 flag = 1 print(" ".join(map(str, R))) return cnt if __name__ == '__main__': n = int(input()) A = list(map(int, input().split())) ans = bubbleSort(A, n) print(ans)
N = input() good_ints = (str(i) * 3 for i in range(9 + 1)) for good_int in good_ints: if good_int in N: print('Yes') exit() print('No')
import math if __name__ == '__main__': n =int(input()) a = int(math.sqrt(n)) max=1 for i in range(2,a+1): now = i*i while now <= n: if max < now: max =now now = now*i print(max)
k = int(input()) from math import gcd s = 0 for a in range(1, k+1): for b in range(1, k+1): g = gcd(a, b) for c in range(1, k+1): s += gcd(g, c) print(s)
#!/usr/bin/env python3 import sys sys.setrecursionlimit(300000) def solve(N: int, M: int): ret = 0 if N > 1: ret += N * (N - 1) // 2 if M > 1: ret += M * (M - 1) // 2 print(ret) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int M = int(next(tokens)) # type: int solve(N, M) if __name__ == '__main__': main()
#!/usr/bin/env python3 # from numba import njit # input = stdin.readline # @njit def solve(a,b,c,d,s): if '##' in s[a:c+1] or '##' in s[b:d+1]: return False if c < d: return True elif c > d: if "..." in s[b-1:d+2]: return True else: return False else: raise ValueError def main(): N,A,B,C,D = map(int,input().split()) A -= 1 B -= 1 C -= 1 D -= 1 S = input() print("Yes" if solve(A,B,C,D,S) else "No") return if __name__ == '__main__': main()
X = int(input()) wk = (X-7)*(X-5)*(X-3) if wk == 0: print("YES") else: print("NO")
def actual(n): if 1 <= n <= 999: return 'ABC' return 'ABD' n = int(input()) print(actual(n))
l=str(input()) if(l[-1]!="s"): l=l+"s" else: l=l+"es" print(l)
a = list(input()[::-1]) b = list(input()[::-1]) c = list(input()[::-1]) now = a while len(now): next_ = now.pop() if next_ == 'a':now=a elif next_ == 'b':now=b else:now=c print(next_.upper())
num = sorted([ int(v) for v in input().split() ]) if num == [1,4,7,9]: print("YES") else: print("NO")
def fib(n): if n == 0 or n == 1: return 1 if A[n] is not None: return A[n] A[n] = fib(n - 1) + fib(n - 2) return A[n] A = [None] * (44 + 1) n = int(input()) print(fib(n))
S = list(map(str,input())) for i in range(len(S)): S[i] = 'x' print(''.join(map(str,S)))
x = input().split(" ") a = int(x[0]) b = int(x[1]) r = (a * 3) + b print(r // 2)
# -*- coding: utf-8 -*- import math class Point_Class: def __init__(self, x, y): self.x = x self.y = y def printPoint(self): print "%f %f" %(self.x, self.y) def koch(n, p1, p2): if n == 0: return sin60 = math.sin(math.radians(60)) cos60 = math.cos(math.radians(60)) s = Point_Class((2*p1.x+p2.x)/3, (2*p1.y+p2.y)/3) t = Point_Class((p1.x+2*p2.x)/3, (p1.y+2*p2.y)/3) u = Point_Class((t.x-s.x)*cos60-(t.y-s.y)*sin60+s.x, (t.x-s.x)*sin60+(t.y-s.y)*cos60+s.y) koch(n-1, p1, s) s.printPoint() koch(n-1, s, u) u.printPoint() koch(n-1, u, t) t.printPoint() koch(n-1, t, p2) n = int(raw_input()) p1 = Point_Class(0.0, 0.0) p2 = Point_Class(100.0, 0.0) p1.printPoint() koch(n, p1, p2) p2.printPoint()
from collections import deque d = deque() X = input() for c in X: if d: last = d.pop() if last == "S" and c == "T": pass else: d.append(last) d.append(c) else: d.append(c) print(len(d))
n=int(input()) s=input().split() x=set(s) if len(x)==3: print('Three') else: print('Four')
a = raw_input().split() if (a[0] < a[1] and a[1] < a[2]): print "Yes" else: print "No"