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) while True: try: a, b = map(int, raw_input().split()) except EOFError: break print "%d %d" % (gcd(a, b), lcm(a, b))
input_str = input() for i in input_str: if i.islower(): print(i.upper(), end='') else: print(i.lower(), end='') print()
import collections s = input() count = collections.Counter(s) _max = 0 for i in count.values(): if _max < i: _max = i if _max >= 2: print("no") else: print("yes")
def gcd_(a, b): if a < b: a, b = b, a if b == 0: return a return gcd_(b, a % b) def gcd(l): ans = l[0] for i in l: ans = gcd_(ans, i) return ans N = int(input()) print(gcd(list(map(int,input().split()))))
x = int(input()) xd = x//100 if xd*100 <= x <= xd*105: print(1) else: print(0)
s=input() if 'C' in s: if 'F' in s[s.index('C'):]: print('Yes') else: print('No') else: print('No')
n = int(input()) if n < 100: result = "ABC"# + "00" + str(n) elif n > 999: n = n - 999 result = "ABD" #+ str(n) else: result = "ABC" #+ str(n) print(result)
#!/usr/bin/env python3 a = [] a = list(map(int, input().split())) if a[0] == a[1] and a[1] == a[2]: print('Yes') else: print('No')
def swap(A, i, j): tmp = A[i] A[i] = A[j] A[j] = tmp def bubble_sort(A, n): count = 0 for i in range(0, n): for j in range(n-1, i, -1): if A[j] < A[j-1]: swap(A, j, j-1) count += 1 return A, count n = int(input()) A = [int(x) f...
def insertion_sort(seq): print(' '.join(map(str, seq))) for i in range(1, len(seq)): key = seq[i] j = i - 1 while j >= 0 and seq[j] > key: seq[j+1] = seq[j] j -= 1 seq[j+1] = key print(' '.join(map(str, seq))) return seq n = int(input()) seq =...
# -*- coding: utf-8 -*- #重み付きUnion-Findによる実装 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines #xの根を求める def find(x): if par[x] < 0: return x else: px = find(par[x]) wei[x] += wei[par[x]] par[x] = px return...
n = input() x = list(n) length = len(x) if x[length-1] == "3": print("bon") elif x[length-1] == "0" or x[length-1] == "1" or x[length-1] == "6" or x[length-1] =="8": print("pon") else: print("hon")
def solve(): X, A, B = [int(input()) for i in range(3)] return (X - A) % B if __name__ == '__main__': print(solve())
X, Y = map(int, input().split()) if Y%2!=0 or Y<(X*2) or Y>(X*4): print("No") else: print("Yes")
from math import sqrt, pow x1, y1, x2, y2 = list(map(float, input().split())) print(sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)))
from itertools import product H, W = map(int, input().split()) S = [list(input()) for _ in range(H)] def has_neighbor(_i: int, _j: int) -> bool: patterns = [ (-1, 0), (1, 0), (0, -1), (0, 1), ] cnt = 0 for pattern in patterns: y, x = _i + pattern[0], _j + pattern[1] if y in ra...
def gcd(a, b): return gcd(b, a%b) if b else a while True: try: a, b = map(int, raw_input().split()) ans = gcd(a, b) print ans, a*b//ans except EOFError: break
import math r = float(input()) S = math.pi * r**2 L = 2 * math.pi * r print(S, L)
letters = input() if letters[2] == letters[3] and letters[4] == letters[5] : print('Yes') else : print('No')
#coding: UTF-8 import sys table = [0]*26 letters = [chr(i) for i in range(97, 97+26)] input_str = sys.stdin.read() for A in input_str: index = 0 for B in letters: if A == B or A == B.upper(): table[index] += 1 break index += 1 for i in range(len(letters)): print("...
import math while True: x = input().split() a = int(x[0]) b = int(x[2]) oprnd = x[1] if oprnd=="+": print(a+b) elif oprnd=="-": print(a-b) elif oprnd=="*": print(a*b) elif oprnd=="/": print(math.floor(a/b)) elif oprnd=="?": break
for A in range(1, 10): for B in range(1, 10): print str(A) + 'x' + str(B) + '=' + str(A * B)
""" 与えられた数列の奇数番目の数と偶数番目の数をそれぞれ確認し、 要素数の多いものにそれぞれ書き換える。 文字種が1種類にならないように注意する """ from collections import Counter N = int(input()) V_LI = list(map(int, input().split())) if len(set(V_LI)) == 1: # そもそも一種類しかなかったら print(N // 2) exit() odd_li = [V_LI[i] for i in range(0, N, 2)] even_li = [V_LI[i] for i in range(1...
a,b,c = map(int,input().split()) if(b < c and a > c): print("Yes") elif(a < c and b > c): print("Yes") else: print("No")
N = int(input()) """nを素因数分解""" """2以上の整数n => [[素因数, 指数], ...]の2次元リスト""" def factorization(n): if (n == 1): return [] arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= ...
while True: x = input().split() x_int = [int(i) for i in x] if x_int[0] == 0 and x_int[1] == 0: break for i in range(x_int[0]): for j in range(x_int[1]): if i == 0 or i == x_int[0]-1: print('#',end='') else: if j == 0 or j == x_int...
a,b=input().split() ab=a*int(b) ba=b*int(a) print(ab if ab < ba else ba)
def selectionSort(numbers): n = len(numbers) count = 0 for i in range(n): min_j = i for j in range(i + 1, n): if numbers[j] < numbers[min_j]: min_j = j if min_j != i: temp = numbers[i] numbers[i] = numbers[min_j] numbers...
#!/usr/bin/env python3 import sys try: from typing import List except ImportError: pass def solve(x: "List[int]", y: "List[int]"): x1, x2 = x y1, y2 = y x3 = x2 - (y2 - y1) y3 = y2 + (x2 - x1) x4 = x3 - (y3 - y2) y4 = y3 + (x3 - x2) print(x3, y3, x4, y4) def main(): def itera...
a,b=input().split();print('=' if a==b else '<' if a<b else '>')
n=int(input()) if "Y" in list(map(str,input().split())): print("Four") else: print("Three")
def lcm(a, b): return a // gcd(a, b) * b def gcd(a, b): if(b == 0): return a else: return gcd(b, a % b) def cnt(a): res = 0 while(a and a % 2 == 0): a //= 2 res += 1 return res n, m = map(int, input().split()) A = list(map(int, input().split())) l = 1 c = cnt(A[0]) for a in A: if cnt(a) != c o...
N = int(input()) ans = 0 for i in range(N): n = i + 1 if n % 3 == 0 or n % 5 == 0: continue else: ans += n print(ans)
N = int(input()) number1 = [2,4,5,7,9] number2 = [3] number3 = [0,1,6,8] if N % 10 in number1: print('hon') elif N % 10 in number2: print('bon') elif N % 10 in number3: print('pon')
# A - Next Alphabet https://atcoder.jp/contests/abc151/tasks/abc151_a number=ord(input()) moji=chr(number+1) print(moji)
dict_1 = {"A":"T","G":"C"} dict_2 = {"T":"A","C":"G"} s = input() if s in dict_1: ans = dict_1[s] else: ans = dict_2[s] print(ans)
s = input() a = "abcdefghijklmnopqrstuvwxyz" for i in s: a = a.replace(i, "") else: if len(a): print(a[0]) else: print("None")
n = input() if n >= 'A' and n <= 'Z': print('A') if n >= 'a' and n <= 'z': print('a')
X = int(input()) n = X//100 k = X % 100 if k <= 5*n: print(1) else: print(0)
import math N = int(input()) for n in range(N): num = N - n sqrt_num = math.sqrt(num) if (int(sqrt_num) == sqrt_num): print(num) break
N = int(input()) T = ("3","5","7") def dfs(x): if x != "" and int(x) > N: return 0 res = 0 if len(set(x)) == 3: res = 1 for t in T: res += dfs(x + t) return res print(dfs(""))
if __name__ == "__main__": while True: a,op,b = map(str,input().split()) if op is "+": print("%d"%(int(a)+int(b))) elif op is "-": print("%d"%(int(a)-int(b))) elif op is "*": print("%d"%(int(a)*int(b))) elif op is "/": print("%d...
A, B, C = map(int, input().split()) if A * B * C % 2 == 0: print(0) else: M = max(A, B, C) if M == A: print(B * C) elif M == B: print(A * C) else: print(A * B)
import math cnt = 0 for i in range(int(input())): x = int(input()) flg = False # なんらかの数で割り切れるかどうか if x == 1: continue if x == 2: cnt += 1 continue for k in range(2, math.floor(math.sqrt(x))+1): if not(x % k): flg = True break if not flg: ...
import sys input = sys.stdin.readline N = int(input()) # 素因数分解 (dictバージョン) # 考え方:1~√nまで実際に割れるか試せば良いが、割れた場合は割れる限りその数で割り続ける # 計算量:O(√n) def prime_factorize(n, primes): i = 2 while i * i <= n: if n % i != 0: i += 1 continue exp = 0 while n % i == 0: exp...
s = list(input()) t = list(input()) s.sort() t.sort(reverse=True) S=''.join(s) T=''.join(t) ans_ = [S,T] ans_.sort() ans='Yes' if ans_[0] == T: ans='No' print(ans)
from math import sqrt def sd(nums): n = len(nums) ave = sum(nums)/n return abs(sqrt(sum([(s - ave)**2 for s in nums])/n)) def main(): while True: n = input() if n == '0': break nums = [int(x) for x in input().split()] print("{:f}".format(sd(nums))) if ...
def gcd(a,b): while a>0 and b>0: if a>b:a%=b else: b%=a return max(a,b) a,b =(int(i) for i in input().split()) print((a*b)//gcd(a,b))
import math r = float(input()) a = math.pi * r * r l = 2 * math.pi * r print(f'{a} {l}')
N = int(input()) import math n_sqrt = math.floor(math.sqrt(N)) print(n_sqrt ** 2)
n = int(input()) if n == 1: print("Hello World") else: answer = 0 for x in range(2): answer += int(input()) print(answer)
from collections import deque class peke: def __init__(self,Start,End,S): self.start=Start self.end=End self.S=S S1=deque() S2=deque() total=0 A=input() for n in range(len(A)): if A[n]=='\\': S1.append(n) elif A[n]=='/' and S1: j=S1.pop() now=n-j ...
#78 data=list(input().split()) if data[0]<data[1]: print('<') elif data[0]>data[1]: print('>') else: print('=')
def main(): n,a = (int(input()) for _ in range(2)) print('Yes' if n%500 <= a else 'No') if __name__ == '__main__': main()
n=int(input()) m=list(str(n)) res=0 for i in m:res+=int(i) print("Yes" if n % res == 0 else "No")
N = int(input()) 個数 = 0 for N in range(N+1): 個数 += N print(個数)
s = input() ans = s if s[-1] == "s": ans += "e" print(ans+"s")
s = str(input()) w = int(input()) word = "".join(s[h] for h in range(0,len(s),w)) print(word)
n=int(input()) ans=0 for i in range(n): if (i+1)%3==0 and (i+1)%5==0: continue elif (i+1)%3==0: continue elif (i+1)%5==0: continue else: ans+=i+1 print(ans)
n=int(input()) list=list(map(int,input().split(" "))) list.reverse() for i in range(n-1): print(str(list[i])+" ",end="") print(str(list[n-1]))
N = input() cnt = 0 for s in N: if s == "2": cnt += 1 print(cnt)
N = int(input().rstrip()) A = [] mx1 = 0 mx2 = 0 for i in range(N): A.append(int(input().rstrip())) if A[i] > mx1: mx1, mx2 = A[i], mx1 elif A[i] > mx2: mx2 = A[i] for j in range(N): if A[j] == mx1: print(mx2) else: print(mx1)
A = input() B = input() ref = '123' for i in ref: if i != A and i != B: print(i)
import re s=input() count=0 if re.search(r'a',s): count+=1 if re.search(r'b',s): count+=1 if re.search(r'c',s): count+=1 if count==3: print('Yes') else: print('No')
from collections import deque def main(): s = input() q = int(input()) d = deque(s) is_reversed = False for _ in range(q): query = list(input().split()) if query[0] == "1": if is_reversed: is_reversed = False else: is_revers...
N = int(input()) A = list(map(int, input().split())) # number_to_prime[i]: i の最小の素因数, iが素数ならば0 number_to_prime = [0] * (10**6 + 1) # preprocess for i in range(2, 10**6+1): if not number_to_prime[i]: j = 1 while j*i <= 10**6: number_to_prime[j*i] = i j += 1 def is_pair_cop...
s=input() t=input() n=len(s) d={} for i in range(n): ss=s[i] tt=t[i] if ss in d and (ss,tt) not in d.items(): print("No") exit() if tt in d.values() and (ss,tt) not in d.items(): print("No") exit() if ss not in d: d[ss]=tt print("Yes")
from math import gcd N = int(input()) A = list(map(int,input().split())) def lcm(a,b): return a*b//gcd(a,b) lcm_a = 1 for i in A: lcm_a = lcm(lcm_a,i) ans = 0 for i in A: ans += lcm_a//i print(ans%(10**9+7))
# encoding:utf-8 input = map(int, raw_input().split()) height = input[0] width = input[1] area = height * width circumference = (height + width) * 2 print(area), print(circumference)
n = int(input()) n = str(n) if n[0] == n[1] == n[2] or n[1] == n[2] == n[3]: print('Yes') else: print('No')
import math r = float(input()) print("%.7f %.7f" % (math.pi*r*r,2.0*r*math.pi))
s = input() s_list = list(s) if s_list[-1] == 's': output = s + 'es' else: output = s + 's' print(output)
# 数値で入力ではなく, 文字列で入力しlist関数を使う k = int(input()) s = input() n = len(s) list_s = list(s) # リストのスライス機能を使用 if n > k: tmp = list_s[0:k] print(''.join(tmp) + '...') else: print(''.join(list_s))
x = int(input("")) if -40 <= x <= 29: print("No") elif 30 <= x <= 40: print("Yes")
n = int(input()) d = {} for i in range(n): order,string = input().split() if order == "insert": d[string] = 1 else: try: if d[string] : print("yes") except: print("no")
n = int(input()) s = [input() for _ in range(2)] mod = 10 ** 9 + 7 def is_vertical(i): return s[0][i] == s[1][i] i = 0 if is_vertical(i): ans = 3 prev_is_vertical = True i += 1 else: ans = 3 * 2 prev_is_vertical = False i += 2 while i < n: if is_vertical(i): if prev_is_verti...
def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): tmp = [] if n % i == 0: tmp.append(i) tmp.append(n//i) if(len(tmp)>0): divisors.append(sum(tmp)) return divisors def main5(): n = int(input()) k = make_divisors(n) pr...
x = int(input()) def prime_check(n): f = 3 while f * f <= n: if n % f == 0: return False else: f += 2 else: return True if x != 2: if x % 2 == 0: x += 1 while 1: if prime_check(x) == True: print(x) break ...
n = input() cards = [] for i in range(n): cards.append(raw_input().split()) marks = ['S', 'H', 'C', 'D'] for i in marks: for j in range(1, 14): if [i, str(j)] not in cards: print i, j
a = input() if len(a) == 2: print(a) elif len(a) == 3: print(a[::-1])
a = input() b = input() if len(a)<len(b): print("LESS") elif len(a)==len(b): print("LESS" if a<b else "EQUAL" if a==b else "GREATER") else: print("GREATER")
N=int(input()) A=[int(input()) for _ in range(N)] B=sorted(A) for n in range(N): if A[n]!=B[-1]: print(B[-1]) else: print(B[-2])
def inp(): # n=1 return int(input()) def inpm(): # x=1,y=2 return map(int,input().split()) def inpl(): # a=[1,2,3,4,5,...,n] return list(map(int, input().split())) def inpls(): # a=['1','2','3',...,'n'] return list(input().split()) def inplm(n): # x=[] 複数行 return list(int(input()) for _ in range(n))...
import math def insertion_sort(alist, step): size = len(alist) count = 0 for i in range(step, size): v = alist[i] j = i - step while j >= 0 and alist[j] > v: alist[j+step] = alist[j] j -= step count += 1 alist[j+step] = v return (c...
a, b = map(int, input().split()) if a >= b + 2: print(a + a - 1) elif a == b + 1 or b == a + 1 or a == b: print(a + b) elif a + 2 <= b: print(b + b - 1)
n = int(input()) def gcd(a,b): while b != 0: a, b = b, a % b return a # 最小公倍数 def lcm(a,b): return a // gcd(a,b) * b ans = 1 for i in range(n): t = int(input()) ans = lcm(ans,t) print(ans)
N = list(input()) Nr = N[::-1] print("Yes") if N == Nr else print("No")
import math x1, y1, x2, y2 = [float(i) for i in input().split()] bottom = x2 - x1 height = y2 - y1 print(math.sqrt(bottom**2 + height**2))
from collections import Counter lst = [] for i in range(3): a, b = map(int, input().split()) lst.append(a) lst.append(b) if sorted(list(Counter(lst).values())) == [1, 1, 2, 2]: print('YES') else: print('NO')
#!/usr/bin/env python3 import sys def solve(A: int, B: int, C: int): ans = 0 s = set() while True: if A % 2 == 1 or B % 2 == 1 or C % 2 == 1: print(ans) break newA = B / 2 + C / 2 newB = A / 2 + C / 2 newC = A / 2 + B / 2 A = newA ...
x = int(input()) if x <= 6: print(1) else: ans = (x//11)*2 if x%11 == 0: print(int((x/11)*2)) elif (x//11)*11 +6 >= x: print(ans+1) else: print(ans+2)
# Python3 implementation of the approach # Function to find the number of divisors # of all numbers in the range [1,n] def findDivisors(n): # List to store the count # of divisors div = [0 for i in range(n + 1)] # For every number from 1 to n for i in range(1, n + 1): # Increase divisors c...
minute = int(input()) print('{}:{}:{}'.format(minute // 3600, (minute % 3600) // 60, (minute % 3600) % 60))
a, b, c = map(int, (input().split())) s="No" if a <= c and c <= b: s="Yes" print(s)
antennas = [int(input()) for _ in range(5)] distance = int(input()) antennas_distance = abs(sorted(antennas)[len(antennas)-1] - sorted(antennas)[0]) print(':(' if antennas_distance > distance else 'Yay!')
#!/usr/bin/env python3 import sys def input(): return sys.stdin.readline()[:-1] def main(): X = int(input()) y = 100 ans = 0 while y < X: ans += 1 y += y // 100 print(ans) if __name__ == '__main__': main()
s = input() if len(s) % 2 == 1: s = s[:-1] else: s = s[:-2] while True: if s[:len(s)//2] == s[len(s)//2:]: print(len(s)) exit() else: s = s[:-2]
# -*- coding: utf-8 -*- def call(n): print '', for i in xrange(1, n+1): if check(i): print(i), print def check(i): if i % 3 == 0: return True elif i % 10 == 3: return True elif i / 10 > 0: x = i x /= 10 while (x > 0): if x % 10 == 3: return True else: x /= 10 return False n = int...
#input an interget k=int(input()) #input an string str1=str(input()) #get the length of the string x=int(len(str1)) #initialise y y=0 #make a second string for the appending str2="..." #if statement about how the string will function #if the string is the same length as k then print it if x<=k: print(str1) #if not...
s = sorted(str(input())) t = sorted(str(input()), reverse = True) print("Yes" if s < t else "No")