text
stringlengths 37
1.41M
|
---|
s = str(input())
cnt_flag = False
for s_find in s:
if s.count(s_find)>1:
cnt_flag = True
if cnt_flag:
print("no")
else:
print("yes")
|
import math
ab=list(input().split())
s=int(''.join(ab))
root=int(math.sqrt(s))
if root*root==s: print('Yes')
else: print('No') |
d = int(input())
if d % 2 == 0:
print(d//2)
else:
print((d//2)+1) |
import math
n = int(input())
#探索範囲
sqrt_n = int(math.sqrt(n))
num_i = 0
for i in range(1, sqrt_n+1):
if n % i == 0:
num_i = i
num_j = n // num_i
ans = (num_i - 1) + (num_j - 1)
print(ans)
|
S = input()
T = input()
for i in range(len(S)):
if S == T:
print('Yes')
break
else:
lstS = list(S)
s = lstS.pop()
a = list(s) + lstS
S = ''.join(a)
else:
print('No') |
import math
def is_prime(n):
if n & 0: return False
for i in range(2, int(math.sqrt(n))+1):
if n % i == 0:
return False
return True
def prime(n):
if n < 2: return []
P = [2]
for i in range(3, n+1):
if is_prime(i):
P.append(i)
return P
n = int(input())
P = prime(n)
cnt = [0]*len(P)
for i in range(2, n+1):
x = i
pi = 0
while x > 1 and pi < len(P):
if x % P[pi] == 0:
cnt[pi] += 1
x //= P[pi]
else:
pi += 1
ans = 1
for c in cnt:
ans *= c+1
ans %= 10**9 + 7
print(ans) |
while True:
H, W = map(int, raw_input().split())
if H == 0 or W == 0:
break
even_line = ''
odd_line = ''
for i in xrange(W):
if i % 2 == 0:
even_line = even_line + '#'
odd_line = odd_line + '.'
else:
even_line = even_line + '.'
odd_line = odd_line + '#'
for i in xrange(H):
if i % 2 == 0:
print even_line
else:
print odd_line
print '' |
import sys
x=int(input())
a=int(input())
b=int(input())
x-=a
while(1):
if x<b:
print(x)
sys.exit()
else:
x-=b |
a,b,c=input().split()
print("Yes"*(a==b==c)or"No") |
s = input()
if s == 'Sunny':
result = 'Cloudy'
elif s == 'Cloudy':
result = 'Rainy'
else:
result = 'Sunny'
print(result)
|
a,b=input().split()
a=int(a)
b=int(b)
Hantei=(a * b) % 2
if Hantei == 1:
print("Odd")
else:
print("Even")
|
def main():
N = int(input())
power = 1
for i in range(1,N+1):
power *= i
power %= (10**9) + 7
return power
print(main())
|
# 集合A={2,3},B={2,4},C={3,5,7}がある。
# それぞれの集合から1つずつa,b,cを選ぶ。
# a+b+c = nとなる選び方は何通りあるか。
# -> f = (x^2+x^3)*(x^2+x^4)*(x^3+x^5+x^7)とするとき、fのx^nの係数が答え
# --> [x^n](x^2+x^3)(x^2+x^4)*(x^3+x^5+x^7)と表される。
# f = x^3 + x^4 + x^5 + ...
#[x^s]f^n
#->[x^s](for i in range(∞):f^n)
#A[n] = A[n-3] +A[n-4] +A[n-5] + ... + A[0]
#A[0] = 1
s = int(input())
MODINT = 1000000007
dp = [0]*(s+1)
dp[0] = 1
for i in range(1,s+1):
for j in range(0,(i-3)+1):
dp[i] += dp[j]
dp[i] %= MODINT
print(dp[s]) |
N = int(input())
A = list(map(int, input().split()))
from fractions import Fraction
def inverse(f):
return Fraction(f.denominator,f.numerator)
ans = 0
for i in A:
ans = ans + inverse(i)
print(float(inverse(ans))) |
S = list(input())
S.sort()
print(['No', 'Yes'][S[0] == S[1] and S[2] == S[3] and S[1] != S[2]]) |
def abc169c_multiplication3():
a, b = input().split()
a = int(a)
b = int(b[0] + b[2] + b[3])
print(a * b // 100)
abc169c_multiplication3()
|
class Modulo_Error(Exception):
pass
class Modulo():
def __init__(self,a,n):
self.a=a%n
self.n=n
def __str__(self):
return "{} (mod {})".format(self.a,self.n)
#+,-
def __pos__(self):
return self
def __neg__(self):
return Modulo(-self.a,self.n)
#等号,不等号
def __eq__(self,other):
if isinstance(other,Modulo):
return (self.a==other.a) and (self.n==other.n)
elif isinstance(other,int):
return (self-other).a==0
def __neq__(self,other):
return not(self==other)
#加法
def __add__(self,other):
if isinstance(other,Modulo):
if self.n!=other.n:
raise Modulo_Error("異なる法同士の演算です.")
return Modulo(self.a+other.a,self.n)
elif isinstance(other,int):
return Modulo(self.a+other,self.n)
def __radd__(self,other):
if isinstance(other,int):
return Modulo(self.a+other,self.n)
#減法
def __sub__(self,other):
return self+(-other)
def __rsub__(self,other):
if isinstance(other,int):
return -self+other
#乗法
def __mul__(self,other):
if isinstance(other,Modulo):
if self.n!=other.n:
raise Modulo_Error("異なる法同士の演算です.")
return Modulo(self.a*other.a,self.n)
elif isinstance(other,int):
return Modulo(self.a*other,self.n)
def __rmul__(self,other):
if isinstance(other,int):
return Modulo(self.a*other,self.n)
#Modulo逆数
def Modulo_Inverse(self):
x0, y0, x1, y1 = 1, 0, 0, 1
a,b=self.a,self.n
while b != 0:
q, a, b = a // b, b, a % b
x0, x1 = x1, x0 - q * x1
y0, y1 = y1, y0 - q * y1
if a!=1:
raise Modulo_Error("{}の逆数が存在しません".format(self))
else:
return Modulo(x0,self.n)
#除法
def __truediv__(self,other):
return self*other.Modulo_Inverse()
#累乗
def __pow__(self,m):
u=abs(m)
r=Modulo(1,self.n)
while u>0:
if u%2==1:
r*=self
self*=self
u=u>>1
if m>=0:
return r
else:
return r.Modulo_Inverse()
#-------------------------------------------------------------------------
M=10**9+7
n,a,b=map(int,input().split())
C=[Modulo(1,M)]*(b+1)
for k in range(1,b+1):
C[k]=C[k-1]*Modulo(n-(k-1),M)/Modulo(k,M)
print((Modulo(2,M)**n-(C[a]+C[b])-1).a)
|
#!/usr/bin/env python3
import sys
from random import randint
def main():
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
class RollingHash:
def __init__(self, s):
self.s = s # パターン探索を行われる側の文字列
self.size = len(s)
self.hashmod = 2 ** 64 - 1
self.base = randint(2 ** 10, 2 ** 11)
self.hash_list = self._make_rolling_hash_list()
def _make_rolling_hash_list(self):
hash_list = [0] * (self.size + 1) # [h(s[0:0]), h(s[0:1]), h(s[0:2]), h(s[0:3]), ..., h(s[0:size])]
prev = 0
for i in range(1, self.size + 1):
hash_num = (prev * self.base + ord(self.s[i-1])) % self.hashmod
hash_list[i] = hash_num
prev = hash_num
return hash_list
def calc_interval_hash(self, i, j):
"""
s[i:j] のハッシュを計算
"""
return (self.hash_list[j] - self.hash_list[i] * pow(self.base, (j - i), self.hashmod)) % self.hashmod
def span_bisect(rolling):
left = 1 # 絶対に発見成功するとわかっている
right = (n // 2) + 1 # 絶対に発見失敗するとわかっている
while right - left > 1:
d = dict()
mid_span = left + (right - left) // 2 # 二分探索で今回選ばれた span
for i in range(n - mid_span + 1):
j = i + mid_span
h = rolling.calc_interval_hash(i, j)
try:
first_j = d[h]
if first_j <= i:
left = mid_span
break
except KeyError:
d[h] = j
else:
right = mid_span
return left
n = ii()
s = input()
if len(list(set(list(s)))) == n:
print(0)
else:
# main
rolling = RollingHash(s)
print(span_bisect(rolling))
if __name__ == "__main__":
main() |
s=input().lower()
cnt=0
while True:
l=input().split()
if l[0]=='END_OF_TEXT': break
for i in range(len(l)):
lg=len(l[i])-1
if not l[i][lg].isalpha(): l[i]=l[i][:lg]
cnt+=(s==l[i].lower())
print(cnt) |
class Node:
def __init__(self, value):
self.value = value
self.next = None
class SimpleQeueue:
def __init__(self):
self.size = 0
self.head = None
self.tail = None
return
def enqueue(self, value):
node = Node(value)
if self.head == None:
self.head = node
self.tail = node
else:
self.tail.next = node
self.tail = node
self.size += 1
def dequeue(self):
if self.is_empty() == True:
return None
node = self.head
self.head = self.head.next
self.size -= 1
if self.is_empty() == True:
self.head = None
self.tail = None
return node.value
def peek(self):
if self.is_empty() == True:
return None
return self.head.value
def get_size(self):
return self.size
def is_empty(self):
return self.size == 0
def __str__(self):
str_ = '['
current = self.head
while current != None:
str_ += str(current.value)
current = current.next
if current != None:
str_ += ', '
str_ += ']['
if self.tail != None:
str_ += str(self.tail.value)
str_ += ']'
return str_
class Process:
def __init__(self, name, time):
self.name = name
self.time = int(time)
def set_time(self, time):
self.time = time
n, q = map(int, input().split())
myqueue = SimpleQeueue()
for i in range(n):
name, time = map(str, input().split())
myqueue.enqueue(Process(name, time))
time_elapsed = 0
while myqueue.is_empty() != True:
process = myqueue.dequeue()
time = process.time
if time > q:
process.set_time(time - q)
time_elapsed += q
myqueue.enqueue(process)
else:
time_elapsed += time
print(process.name + ' ' + str(time_elapsed))
|
s = input()
s = list(s)
sowth = s.count('S') if 'S' in s else 0
east = s.count('E') if 'E' in s else 0
north = s.count('N') if 'N' in s else 0
west = s.count('W') if 'W' in s else 0
if (sowth != 0 and north == 0) or\
(sowth == 0 and north != 0) or\
(west != 0 and east == 0) or\
(west == 0 and east != 0):
print('No')
else:
print('Yes')
|
#!/usr/bin/env python
# coding: utf-8
# In[20]:
A,B,C = map(int, input().split())
# In[22]:
A_ = A
B_ = B
C_ = C
ans = 0
while True:
if A_%2 != 0 or B_%2 != 0 or C_%2 != 0:
print(ans)
break
else:
A_tmp = B_//2 + C_//2
B_tmp = A_//2 + C_//2
C_tmp = A_//2 + B_//2
A_ = A_tmp
B_ = B_tmp
C_ = C_tmp
ans += 1
# print(A_,B_,C_)
if A_ == A and B_ == B and C_ == C:
print(-1)
break
# In[ ]:
|
s = input()
if s[0] == "A" and "C" in s[2:-1] and s[1:].replace("C","",1).islower():
print("AC")
else:
print("WA") |
def main():
number = input()
r_number = number[::-1]
if int(number) == int(r_number):
print("Yes")
else:
print("No")
main() |
A = int(input())
B = int(input())
print("GREATER" if (A > B) else "LESS" if (A < B) else "EQUAL")
|
s=input()
print("Yes"if s[0]!=s[1] and s[0]!=s[2] and s[1]!=s[2] else "No") |
n = int(input())
ans = list()
for i in range(n):
line = input().split(" ")
a = float(line[0])
b = float(line[1])
c = float(line[2])
if ((a**2 + b**2) == c**2) or ((b**2 + c**2) == a**2) or ((c**2 + a**2) == b**2):
ans.append("YES")
else:
ans.append("NO")
for j in range(n):
print(ans[j]) |
S=input()
i=len(S)-1
if S[i]=="s":
out=S+"es"
else:
out=S+"s"
print(out) |
# coding: utf-8
string = raw_input()
new_string = ""
for s in string:
if s.islower():
new_string += s.upper()
elif s.isupper():
new_string += s.lower()
else:
new_string += s
print new_string |
while True:
n = int(input())
if n == 0:
break
data = input().split()
import math
sum = 0
for i in range(n):
sum = sum + int(data[i])
average = sum / n
a = 0
for i in range(n):
a = a + (int(data[i]) - average)**2
print('{}'.format(math.sqrt(a/n)))
|
ass, bss, css = input().split(" ")
a = int(ass)
b = int(bss)
c = int(css)
if a < b:
if b < c:
print(a,b,c)
else:
if a < c:
print(a,c,b)
else:
print(c,a,b)
else:
if a < c:
print(b,a,c)
else:
if b < c:
print(b,c,a)
else:
print(c,b,a) |
N = input()
if int(N[-1]) in [2,4,5,7,9]:
ans = 'hon'
elif int(N[-1]) in [0,6,1,8]:
ans = 'pon'
else:
ans = 'bon'
print(ans)
|
from itertools import islice
def maximum_profit(rate):
ret = -float("inf")
mi = rate[0]
for r in islice(rate, 1, len(rate)):
ret = max(ret, r - mi)
mi = min(mi, r)
return ret
if __name__ == "__main__":
R = [int(input()) for _ in range(int(input()))]
print(maximum_profit(R)) |
a, b, c = [int(x) for x in input().split()]
print("Yes" if a + b == c or b + c == a or c + a == b else "No") |
X = int(input())
ans = (-1 + (1+8*X)**(1/2)) / 2
if ans % 1 <= 10**(-7):
print(int(ans))
else:
print(int(1 + ans//1)) |
s= input()
ans= ""
for i in range(int((len(s)+ 1)/ 2)):
ans+= s[i* 2]
print(ans) |
array = []
suum = 0
while True:
n = int(input())
if n == 0:
break
array.append(n)
for i in range(len(array)):
for i2 in range(len(str(array[i]))):
suum += int(str(array[i])[i2])
print(suum)
suum = 0 |
N = int(input())
if N == 1:
print(1)
exit()
for i in range(N+1):
if i == 0:
L_0 = 2
elif i == 1:
L_1 = 1
else:
L_2 = L_0 + L_1
L_0 = L_1
L_1 = L_2
print(L_2) |
nums = input().split()
area = int(nums[0]) * int(nums[1])
length_cirle = int(nums[0]) * 2 + int(nums[1]) * 2
print(str(area) + " " + str(length_cirle))
|
# coding: utf-8
# Your code here!
n=int(input())
flag=0
for i in range(1,10):
if n%i==0:
if 10>n/i:
flag=1
if flag:
print('Yes')
else:
print('No') |
s = raw_input()
ans = ""
for i in range(len(s)):
if('A' <= s[i] and s[i] <= 'Z'):
ans += s[i].lower()
elif('a' <= s[i] and s[i] <= 'z'):
ans += s[i].upper()
else:
ans += s[i]
print(ans) |
days = list(str(input()))
days_real = list(str(input()))
count = 0
for i in range(3):
if days[i] == days_real[i]:
count += 1
print(count) |
# -*- coding: utf-8 -*-
S = input()
space_cnt = 3
for i in range(2 ** space_cnt):
ops = ["-"] * space_cnt
for j in range(space_cnt):
if (i >> j) & 1:
ops[j] = "+"
formula = ""
for j in range(space_cnt):
formula += S[j]+ops[j]
formula += S[-1]
if eval(formula)==7:
break
print(formula+"=7")
|
# -*- coding: utf-8 -*-
"""
E - Double Factorial
https://atcoder.jp/contests/abc148/tasks/abc148_e
"""
import sys
def solve(N):
if N % 2:
return 0
ans, d = 0, 10
while True:
q = N // d
ans += q
if q == 0:
return ans
d *= 5
def main(args):
N = int(input())
ans = solve(N)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
|
X,Y=input().split()
number={"A":10,"B":11,"C":12,"D":13,"E":14,"F":15}
if number[X]==number[Y]:
print("=")
elif number[X]<number[Y]:
print("<")
else:
print(">") |
num = list(input())
for i in range(2**3):
n = []
pm = ["+","+","+"]
for j in range(3):
if ((i >> j) & 1):
pm[j] = "-"
for k in range(3):
n.append(num[k])
n.append(pm[k])
n.append(num[3])
formula = ""
for j in range(7):
formula += n[j]
if eval(formula) == 7:
[print(n[k],end="") for k in range(7)]
print("=7")
exit() |
A, B = map(int, input().split())
if A < 6:
price = 0
elif A < 13:
price =int(B/2)
else:
price = B
print(price) |
N = int(input())
def minus_binary(n, S: str):
if n == 0:
if S == "":
S = "0"
return S
if n == 1:
S = "1" + S
return minus_binary(0, S)
else:
if n%2 == 1:
n -= 1
S = "1" + S
else:
S = "0" + S
return minus_binary(n/(-2), S)
S = ""
print(minus_binary(N, S)) |
list1 = []
for i in range(3):
list1.append(int(input()))
print(int((list1[0] + list1[1]) * list1[2]/2)) |
A,B,C,D = input().split()
A = int(A)
B = int(B)
C = int(C)
D = int(D)
if A*B>C*D:
print(A*B)
elif C*D>A*B:
print(C*D)
elif A*B==C*D:
print(A*B) |
S = input()
if len(S) < 4:
print("No")
exit()
else:
if S[: 4] == "YAKI":
print("Yes")
else:
print("No")
|
s=input()
if len(s)==2:
print(s)
if len(s)==3:
ss = s[::-1]
print(ss)
|
from bisect import bisect_right
from itertools import product
def bisectsearch_right(L, a):
i = bisect_right(L, a)
return(i)
N = input()
d = len(N)
N = int(N)
a = [0]*d
for i in range(1, d):
a[i] = 3**i-3*2**i+3
# print(a)
S = {3, 5, 7}
L = set()
for k in product(S, repeat=d):
l = set(k)
if S == l:
t = [None]*d
for i in range(d):
t[i] = str(k[i])
L.add(int(''.join(t)))
# print(L)
L = list(L)
L.sort()
ct = bisectsearch_right(L, N)
print(sum(a)+ct)
|
s = input()
alphabets = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(alphabets)):
if not alphabets[i] in s:
print(alphabets[i])
exit()
print('None') |
S = input()
Ans = "No"
if S[2]==S[3] and S[4]==S[5]:
Ans = "Yes"
print (Ans) |
i=1
x = int(input())
while x != 0 :
print("Case {0}: {1}".format(i, x))
x = int(input())
i=i+1
|
s1,s2,s3=map(str,input().split())
if s1[len(s1)-1]==s2[0] and s2[len(s2)-1]==s3[0]:
print("YES")
else:
print("NO") |
alpha = input()
print('A' if alpha.isupper() else 'a') |
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 8 20:37:12 2020
@author: liang
"""
import math
X = int(input())
N = int(math.sqrt(X))
lis = list(range(2,N+1))
#print(N)
#print(lis)
ans = X
while True:
if all(ans%i != 0 for i in lis):
print(ans)
break
#print(ans)
ans += 1 |
n = int(input())
s = list(input().split())
for x in s:
if x == 'Y':
print('Four')
exit()
print('Three') |
import math
a,b=input().split()
c=int(a+b)
d=math.sqrt(c)
e=math.floor(d)
if e**2==c:
print('Yes')
else:
print('No') |
s = input()
if len(s)==2: print(s)
else: print(s[::-1]) |
lists = []
for x in range (0, 10):
num = int(input())
lists.append(num)
results = sorted(lists, reverse = True)
print(results[0])
print(results[1])
print(results[2]) |
a = input()
b = input()
if(len(a) > len(b)):
print("GREATER")
elif(len(a) < len(b)):
print("LESS")
elif(len(a) == len(b)):
if(int(a) == int(b)):
print("EQUAL")
elif(int(a) > int(b)):
print("GREATER")
else:
print("LESS") |
a = int(input())
if a >= 1800:
print('1')
elif a >= 1600:
print('2')
elif a >= 1400:
print('3')
elif a >= 1200:
print('4')
elif a >= 1000:
print('5')
elif a >= 800:
print('6')
elif a >= 600:
print('7')
elif a >= 400:
print('8')
else:
print('error') |
def main():
N = int(input())
P = list(map(int, input().split()))
diff = 0
for p_org, p_sort in zip(P, sorted(P)):
if p_org != p_sort:
diff += 1
if diff == 0 or diff == 2:
print("YES")
else:
print("NO")
if __name__ == '__main__':
main()
|
a, b = map(int, input().split())
if a%3 == 0 or (a+b)%3 == 0 or abs(a-b)%3:
print('Possible')
else:
print('Impossible') |
while True:
a, op, b =input().split()
a,b =int(a),int(b)
if op=="?": break
if op=="+": print(a+b)
if op=="-": print(a-b)
if op=="*": print(a*b)
if op=="/": print(a//b)
|
# 6月5日
a = int(input())
b = a%3
c = a//3
if a >= 3:
print(c)
else:
print(int(0))
|
def solve(arr, target):
memo = {}
return solve_rec(0, arr, target, memo)
def solve_rec(i, arr, target, memo):
res = False
key = str(i) + '-' + str(target)
if key in memo:
res = memo[key]
elif target == 0:
res = True
elif i >= len(arr):
res = False
else:
res1 = solve_rec(i + 1, arr, target, memo)
res2 = solve_rec(i + 1, arr, target - arr[i], memo)
res = res1 or res2
memo[key] = res
return res
n = int(input())
arr = list(map(int, input().split()))
q = int(input())
targets = list(map(int, input().split()))
for i in range(q):
res = solve(arr, targets[i])
if res == True:
print('yes')
else:
print('no')
|
n = int(input())
if n == 0:
print(2)
elif n == 1:
print(1)
else:
l1 = 2
l2 = 1
l3 = 0
for i in range(n-1):
l3 = l1
l1 = l2
l2 += l3
print(l2) |
a, b, c = list(map(int, input().split()))
s = (a + b + c) / 2
if s == a or s == b or s == c:
print('Yes')
else:
print('No') |
A=int(input())
B=int(input())
ans=[1,2,3]
for a in ans:
if a!=A and a!=B:
print(a) |
A=int(input())
B=int(input())
if A>B:print('GREATER')
elif A==B:print('EQUAL')
else:print('LESS') |
data = input()
length = len(data)
between = length - 1
num = 0
for i in range(2**between):
list_data = list(data)
for j in range(between):
if ((i >> j) & 1):
list_data[between - j] = '+'+list_data[between - j]
hoge = ''.join(list_data).split('+')
for k in hoge:
num += int(k)
print(num) |
import sys
count = 0
w = ""
w = raw_input()
while 1 :
adding = map(str,raw_input().split())
for i in adding:
if i == 'END_OF_TEXT':
print count
sys.exit()
if i.lower() == w:
count += 1 |
#!/usr/bin/env python3
def main():
from collections import deque
def prime_factorization_list(n: int):
"""
入力された整数nを素因数分解し,素因数が列挙されたリストで返却
Parameters
----------
n : int
素因数分解したい整数
Returns
-------
prime_factorization_lst : lst
[素因数]の形で素因数が列挙された素因数分解結果
"""
fct = [] # prime factor
b = 2 # base factor
while b * b <= n:
while n % b == 0:
n //= b
fct.append(b)
b += 1
if n > 1:
fct.append(n)
return fct
N = int(input())
q = deque(prime_factorization_list(N))
memo = []
while q:
p = q.popleft()
res = p
while res in memo and q:
can = q.popleft()
if can == p:
res *= can
else:
res = can
break
if res not in memo:
memo.append(res)
print(len(memo))
if __name__ == '__main__':
main()
|
s = input()
dic = {'A':'T', 'T':'A', 'C':'G', 'G':'C'}
print(dic[s]) |
a = int(input())
if a==1:
print('Hello World')
else:
num = [int(input()) for _ in range(2)]
print(num[0]+num[1]) |
l = []
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
f = int(input())
g = int(input())
h = int(input())
i = int(input())
j = int(input())
l.append(a)
l.append(b)
l.append(c)
l.append(d)
l.append(e)
l.append(f)
l.append(g)
l.append(h)
l.append(i)
l.append(j)
l.sort()
print(l[-1])
print(l[-2])
print(l[-3]) |
# A - Colorful Transceivers
# A,B,Cの3人が、直接的あるいは間接的に会話できるなら Yes を、
# そうでないなら No を返す
a, b, c, d = map(int, input().split())
ac = abs(a - c)
ab = abs(a - b)
bc = abs(b - c)
if ac <= d \
or (ab <= d and bc <= d):
print('Yes')
else:
print('No')
|
import sys
s = input()
while len(s) > 0:
if len(s) == 1:
print('No')
sys.exit()
else:
if s[:2] == 'hi':
s = s[2:]
else:
print('No')
sys.exit()
print('Yes') |
while True:
text = input()
if text == '0':
break
total = 0
for a in range(len(text)):
total += int(text[a])
print(total) |
def GCD(a,b):
while (a % b) != 0:
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())
print GCD(a,b),LCM(a,b)
except:
break |
from collections import deque
class UnionFind:
def __init__(self, v):
self.v = v
self._tree = list(range(v + 1))
def _root(self, a):
queue = deque()
while self._tree[a] != a:
queue.append(a)
a = self._tree[a]
while queue:
index = queue.popleft()
self._tree[index] = a
return a
def union(self, a, b):
root_a = self._root(a)
root_b = self._root(b)
self._tree[root_b] = root_a
def find(self, a, b):
return self._root(a) == self._root(b)
N, M = map(int, input().split(' '))
edges = [tuple(map(int, input().split(' '))) for _ in range(M)]
bridges = 0
for a1, b1 in edges:
union_find = UnionFind(N)
for a2, b2 in edges:
if a1 == a2 and b1 == b2:
continue
union_find.union(a2, b2)
if not union_find.find(a1, b1):
bridges += 1
print(bridges)
|
#!/usr/bin/env python3
a, b, c = map(int, input().split())
k = int(input())
for _ in range(k):
if a >= b:
b *= 2
elif b >= c:
c *= 2
print(["No", "Yes"][a < b < c])
|
import sys
for line in range(int(input())):
str = input().split(" ")
nums = sorted([int(str[2]), int(str[1]), int(str[0])])
if nums[2]*nums[2] == nums[1]*nums[1] + nums[0]*nums[0]:
print("YES")
else:
print("NO") |
#関数リスト
import sys
input = sys.stdin.readline
def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
def main():
num = I()
result = 0
for i in range(1,num+1,2):
temp = len(make_divisors(i))
if temp == 8:
result += 1
print(result)
if __name__ == "__main__":
main() |
N = int(input())
m = dict()
prev = input()
m[prev] = True
flg = True
for _ in range(N - 1):
s = input()
flg = all([flg, s not in m, prev[len(prev) - 1] == s[0]])
m[s] = True
prev = s
print("Yes" if flg else "No") |
import sys
def main():
for input_line in sys.stdin:
num1 = int(input_line.split(' ')[0])
num2 = int(input_line.split(' ')[1])
sum = str(num1 + num2)
count = 0
for num in sum:
count += 1
else:
print(count)
if __name__ == '__main__':
main() |
def resolve():
n = input()
check = ""
true_check = ""
for i in range(len(n)):
true_check += "T"
if n[i] == n[len(n)-i-1]:
check += "T"
else:
check += "F"
print("No")
break
if not("F" in check) and check == true_check:
print("Yes")
resolve() |
def prime_factors(n):
i = 2
factors = []
while i**2 <= n:
if n % i != 0:
i += 1
else:
factors.append(i)
n = n // i
if n > 1:
factors.append(n)
return factors
def resolve():
N = int(input())
import collections
factors = collections.Counter(prime_factors(N))
numbers = [0,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9]
cnt = 0
for k, v in factors.items():
cnt += numbers[v]
print(cnt)
if '__main__' == __name__:
resolve()
|
N = int(input())
A = input().split(" ")
def bubble_sort(A):
N = len(A)
for i in range(N):
for j in range(N - 1, i, -1):
if int(A[j][1]) < int(A[j - 1][1]):
A[j - 1], A[j] = A[j], A[j - 1]
return A
def selection_sort(A):
N = len(A)
for i in range(N):
mini = i
for j in range(i + 1, N):
if int(A[j][1]) < int(A[mini][1]):
mini = j
if mini != i:
A[mini], A[i] = A[i], A[mini]
return A
def is_stable(A, B):
map_a = {}
map_b = {}
for i in range(len(A)):
s_a = A[i][0]
s_b = B[i][0]
v_a = A[i][1]
v_b = B[i][1]
if v_a in map_a:
map_a[v_a].append(s_a)
else:
map_a[v_a] = [s_a]
if v_b in map_b:
map_b[v_b].append(s_b)
else:
map_b[v_b] = [s_b]
result = True
for k in map_a:
if len(map_a[k]) > 1:
result = result and (map_a[k] == map_b[k])
return result
A_sorted = bubble_sort(A[:])
print(" ".join(A_sorted))
print("Stable") if is_stable(A, A_sorted) else print("Not stable")
A_sorted = selection_sort(A[:])
print(" ".join(A_sorted))
print("Stable") if is_stable(A, A_sorted) else print("Not stable") |
def main():
n = int(input())
mod = 10**9+7
print((pow(10, n, mod)-pow(9, n, mod)*2+pow(8, n, mod))%mod)
if __name__ == "__main__":
main() |
x = int(input())
a = x//11
b = x%11
if b > 6:
c = 2
elif b > 0:
c = 1
else:
c = 0
print(2*a+c) |
from typing import Dict, List
N, M = [int(x) for x in input().split()]
class UnionFind:
def __init__(self, num_node: int):
self.__parent_index = [x for x in range(num_node)]
self.__tree_rank = [1] * num_node
def __is_root(self, index: int) -> bool:
return self.__parent_index[index] == index
def root(self, index: int) -> int:
"""Find root index."""
while not self.__is_root(index):
index = self.__parent_index[index] = self.root(self.__parent_index[index])
return index
def unite(self, x: int, y: int) -> bool:
"""Unite two trees."""
x = self.root(x)
y = self.root(y)
if x == y:
return False
if self.__tree_rank[x] < self.__tree_rank[y]:
x, y = y, x
self.__tree_rank[x] += self.__tree_rank[y]
self.__parent_index[y] = x
return True
def groups(self) -> Dict[int, List[int]]:
__groups: Dict[int, List[int]] = {}
for node, parent in enumerate(self.__parent_index):
__root = self.root(parent)
if __groups.get(__root) is None:
__groups[__root] = [node]
else:
__groups[__root].append(node)
return __groups
uni = UnionFind(N)
for i in range(M):
a, b = [int(x) - 1 for x in input().split()]
uni.unite(a, b)
print(len(uni.groups()) - 1)
|
word = input()
q = int(input())
for _ in range(q):
od = list(map(str, input().split()))
if od[0] == "print":
print(word[int(od[1]): int(od[2]) + 1])
elif od[0] == "reverse":
if int(od[1]) == 0:
word = "{}{}{}".format(word[: int(od[1])], word[int(
od[2])::-1], word[int(od[2]) + 1:])
else:
word = "{}{}{}".format(word[: int(od[1])], word[int(
od[2]): int(od[1]) - 1:-1], word[int(od[2]) + 1:])
elif od[0] == "replace":
word = "{}{}{}".format(
word[: int(od[1])], od[3], word[int(od[2]) + 1:])
|
import sys
input = sys.stdin.readline
class UnionFind:
"""Union Find class.
"Path compression" and "Union by rank" are used.
References:
<https://en.wikipedia.org/wiki/Disjoint-set_data_structure>
"""
def __init__(self, N):
self.N = N
self.__make_set()
def __make_set(self):
self._parent = list(range(self.N + 1))
self._rank = [0] * (self.N + 1)
self._size = [1] * (self.N + 1)
def find(self, x):
if self._parent[x] != x:
self._parent[x] = self.find(self._parent[x])
return self._parent[x]
def union(self, x, y):
x_root = self.find(x)
y_root = self.find(y)
if x_root == y_root:
return
x_rank = self._rank[x_root]
y_rank = self._rank[y_root]
if x_rank > y_rank:
self._parent[y_root] = x_root
self._size[x_root] += self._size[y_root]
elif x_rank < y_rank:
self._parent[x_root] = y_root
self._size[y_root] += self._size[x_root]
else:
self._parent[y_root] = x_root
self._rank[x_root] += 1
self._size[x_root] += self._size[y_root]
def same_set(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return self._size[self.find(x)]
def main():
N, M = map(int, input().split())
a = [None] * M
b = [None] * M
for i in range(M):
a[i], b[i] = map(int, input().split())
ans = 0
for i in range(M):
uf = UnionFind(N)
for j in range(M):
if j == i:
continue
uf.union(a[j], b[j])
if not uf.same_set(a[i], b[i]):
ans += 1
print(ans)
if __name__ == "__main__":
main()
|
class Card:
def __init__(self, s, n):
self.suit = s
self.num = n
class FindingMissingCards:
def __init__(self):
self.allCards = []
for s in ["S","H","C","D"]:
for n in range(1,14):
self.allCards.append(Card(s,n))
def find(self, cards):
for c in cards:
for ac in self.allCards:
if c.num == ac.num and c.suit == ac.suit:
self.allCards.remove(ac)
for c in self.allCards:
print "%s %d" % (c.suit, c.num)
if __name__ == "__main__":
n = int(raw_input())
cards = []
for i in range(n):
s, n = raw_input().split()
cards.append(Card(s, int(n)))
fmc = FindingMissingCards()
fmc.find(cards) |
weather = ["Sunny","Cloudy","Rainy"]
print(weather[(weather.index(input())+1)%3]) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.