text
stringlengths 37
1.41M
|
---|
#ABC056A
x = input().split()
a = (x[0])
b = (x[1])
if((a == "H") & (b == "H")):
print("H")
elif ((a == "D") & (b == "D")):
print("H")
else:
print("D") |
# -*- coding: utf-8 -*-
N = int(input())
if N <=2:
print(0)
elif N % 3 == 0:
print(int(N/3))
elif N % 3 == 1:
print(int((N-1)/3))
elif N % 3 == 2:
print(int((N-2)/3))
|
S=input()
if 'C' in S and 'F' in S:
l=S.index('C')
r=-1
for i in reversed(range(len(S))):
if S[i]=='F':
r=i
break
if r==-1 or l>=r:
print('No')
else:
print('Yes')
else:
print('No') |
A,B,C=input().split()
print(['YES','NO'][A[-1]!=B[0] or B[-1]!=C[0]]) |
n = int(input())
kekw = input()
if n >= len(kekw):
print(kekw)
elif n < len(kekw):
kekwlist = list(kekw)
for i in range(0, n):
print(kekwlist[i], end = "")
print("...") |
a, b = list(map(str, input().split()))
print(b if a=='H' else ('H' if b=="D" else 'D')) |
point = [0, 0]
n = int(input())
for _ in range(n):
cards = input().split()
if cards[0] > cards[1]:
point[0] += 3
elif cards[0] < cards[1]:
point[1] += 3
else:
point = [n + 1 for n in point]
print(*point) |
ring = str(input())*2
search = str(input())
if search in ring:
print("Yes")
else:
print("No")
|
S = input()
ans = "None"
for i in range(97, 123):
alp = chr(i)
if alp not in S:
ans = alp
break
print(ans) |
s = input()
check = 0
flag = True
for i in range(97,123):
check =s.count(chr(i))
if check % 2 == 1 :
flag = False
if flag:
print("Yes")
else:
print("No") |
def input2():
return map(int,input().split())
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
return list(map(int,input().split()))
class UnionFind():
"""docstring for UnionFind"""
def __init__(self, n):
self.parents = [-1]*n
def find(self,x):
if self.parents[x] < 0: #自分が親である時
return x
else: #自分が子供である時
self.parents[x]=self.find(self.parents[x])
return self.parents[x]
def union(self,x,y):
# 各要素の親要素を返す
x=self.find(x)
y=self.find(y)
if x==y:
return
if self.parents[x] > self.parents[y]:
x,y=y,x
self.parents[x]+=self.parents[y]
self.parents[y]=x
# print(self.parents)
n,m=input2()
S=[input_array() for _ in range(m)]
uf=UnionFind(n) #uf.parents==[-1]*n
for s in S:
uf.union(s[0]-1,s[1]-1)
ans=min(uf.parents)
print(-ans) |
a = input()
b = input()
if b.count('R') > b.count('B'):
print('Yes')
else:
print('No') |
x1,y1,x2,y2 = map(float,input().split())
distance = ( (x1 - x2)**2 + (y1 - y2)**2 )**(1/2)
print('{}'.format(distance))
|
a,b,c = map(int, input().split())
ans = "Yes"
if a<=c and c<=b:
print(ans)
else:
ans = "No"
print(ans) |
from collections import defaultdict
S = input()
cnt = defaultdict(bool)
for s in S:
cnt[s] = True
if (cnt["S"] and cnt["N"]) and (cnt["E"] and cnt["W"]):
print("Yes")
elif (cnt["S"] and cnt["N"]) and not (cnt["E"] or cnt["W"]):
print("Yes")
elif not (cnt["S"] or cnt["N"]) and (cnt["E"] and cnt["W"]):
print("Yes")
else:
print("No")
|
a,b,c = input().split()
if (a+b+c).count('5')==2 and (a+b+c).count('7') ==1:
print("YES")
else:
print("NO")
|
age, fee = map(int, input().split())
if 13 <= age:
print(fee)
elif 6 <= age and age <= 12:
print(fee // 2)
elif age < 6:
print(0) |
n = input()
table = set()
for i in range(n):
com = raw_input().split()
if(com[0][0] == "i"):
table.add(com[1])
else:
if com[1] in table:
print("yes")
else:
print("no") |
while 1:
H,W=[int(i) for i in input().split()]
if H==W==0:
break
else:
for i in range(H):
for s in range (W):
print("#",end="")
print('')
print('') |
N=int(input())
result=0
for i in range(1,N+1):
if i%2!=0:
divisor=0
for j in range(1,i+1):
if i%j==0:
divisor+=1
if divisor==8:
result+=1
print(result)
|
class Dice:
def __init__(self, numbers):
self.dice = {"上" :numbers[0],
"下":numbers[5],
"前":numbers[1],
"後":numbers[4],
"左":numbers[3],
"右":numbers[2]
}
def order(self, order_seq):
for _, order in enumerate(order_seq):
if order == "N":
self.north()
elif order == "E":
self.east()
elif order == "W":
self.west()
elif order == "S":
self.south()
return self.dice["上"]
def north(self):
U, D, F, B = [self.dice["上"], self.dice["下"], self.dice["前"], self.dice["後"]]
self.dice["上"] = F
self.dice["前"] = D
self.dice["下"] = B
self.dice["後"] = U
def east(self):
U, D, L, R = [self.dice["上"], self.dice["下"], self.dice["左"], self.dice["右"]]
self.dice["上"] = L
self.dice["下"] = R
self.dice["左"] = D
self.dice["右"] = U
def west(self):
U, D, L, R = [self.dice["上"], self.dice["下"], self.dice["左"], self.dice["右"]]
self.dice["上"] = R
self.dice["下"] = L
self.dice["左"] = U
self.dice["右"] = D
def south(self):
U, D, F, B = [self.dice["上"], self.dice["下"], self.dice["前"], self.dice["後"]]
self.dice["上"] = B
self.dice["前"] = U
self.dice["下"] = F
self.dice["後"] = D
def set_position(self, n, position_seq):
self.ans = []
for i in range(n):
self.up = position_seq[i][0]
self.front = position_seq[i][1]
self.search()
self.west()
self.search()
self.west()
self.search()
self.north()
self.search()
self.west()
self.search()
self.west()
self.search()
return self.ans
def search(self):
# print("goal:now", self.up, ":", self.dice["上"])
if self.dice["上"] == self.up:
for _ in range(4):
# print("goal:now|up ", self.front, ":", self.dice["前"], "|", self.dice["上"], "→", self.dice["右"])
if self.dice["前"] == self.front:
break
self.rotate()
self.ans.append(self.dice["右"])
def rotate(self):
F, R, B, L = [self.dice["前"], self.dice["右"], self.dice["後"], self.dice["左"]]
self.dice["前"] = R
self.dice["右"] = B
self.dice["後"] = L
self.dice["左"] = F
numbers = list(map(int, input().split()))
n = int(input())
pos_seq = []
for _ in range(n):
pos_seq.append(list(map(int, input().split())))
dice = Dice(numbers)
ans = dice.set_position(n, position_seq = pos_seq)
for i in range(n):
print(ans[i])
|
x,y,z,w = input()
l = []
l.append(x)
l.append(y)
l.append(z)
l.append(w)
new_l = sorted(l)
if new_l[0] == new_l[1] and new_l[1] != new_l[2] and new_l[2] == new_l[3]:
print("Yes")
else:
print("No") |
# -*- coding: utf-8 -*-
import sys
N = int(input())
A = [int(input()) for _ in range(N)]
flag = False
for a in A:
if a%2 == 1:
flag = True
break
if flag:
print('first')
else:
print('second') |
n=int(input())
for i in range(1,n+1):
x = i
if x % 3 == 0: print('',i,end='')
else:
while x > 0:
if x % 10 == 3:
print('',i,end='')
break
x //= 10
print('')
|
def mergeSort(num_list, left, right):
if left + 1 < right:
mid = (left + right) / 2
mergeSort(num_list, left, mid)
mergeSort(num_list, mid, right)
merge(num_list, left, mid, right)
def merge(num_list, left, mid, right):
global count
L = list(num_list[left:mid])
L.append(float("inf"))
R = list(num_list[mid:right])
R.append(float("inf"))
i, j = 0, 0
for k in range(left, right):
if L[i] <= R[j]:
num_list[k] = L[i]
i += 1
count += 1
else:
num_list[k] = R[j]
j += 1
count += 1
count = 0
n = int(raw_input())
a = raw_input()
l = []
l = a.split(" ")
for i in range(len(l)):
l[i] = int(l[i])
mergeSort(l, 0, n)
print " ".join(map(str, l))
print count |
x = raw_input()
x = x.split(" ")
a = int(x[0])
b = int(x[1])
c = int(x[2])
if a < b < c:
print("Yes")
else:
print("No")
|
import sys
input = sys.stdin.readline
def readstr():
return input().strip()
def readint():
return int(input())
def readnums():
return map(int, input().split())
def readstrs():
return input().split()
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
def main():
N, M = readnums()
ml = make_divisors(M)
print(max([x for x in ml if x <= M // N]))
if __name__ == "__main__":
main()
|
def main():
a = list(input())
b = list(input())
if a[0] == b[2] and a[2] == b[0] and a[1] == b[1]:
print('YES')
else:
print('NO')
main() |
a,b=input().split()
c=int(a+b)
d=int(c**0.5)
print("Yes" if d**2==c else "No") |
def main():
n, n_truck = map(int, input().split())
w_list = []
for _ in range(n):
w_list.append(int(input()))
print(b_search(w_list, n_truck))
def b_search(w_list, n_truck):
left = max(w_list)
right = sum(w_list)
while left < right:
mid = int((left+right) / 2)
if check(w_list, n_truck, mid):
right = mid
else:
mid += 1
left = mid
return mid
def check(w_list, n_truck, p):
truck_count = 1
tmp_truck = 0
for w in w_list:
tmp_truck += w
if tmp_truck > p:
truck_count += 1
tmp_truck = w
if truck_count > n_truck:
return False
return True
if __name__ == '__main__':
main() |
s = sorted(input())
t = sorted(input(),reverse = True)
flag1 = True
flag2 = False
if len(s) < len(t):
for i in range(len(s)):
if s[i] != t[i]:
flag1 = False
break
else:
flag1 = False
for i in range(min(len(s), len(t))):
if s[i] < t[i]:
flag2 = True
break
elif s[i] > t[i]:
break
if flag1 or flag2:
print('Yes')
else:
print('No')
|
s = input()
s = list(s)
ans = 0
for i in range(len(s)-1):
if s[i]==s[i+1]:
if s[i+1]=="0":
s[i+1] = "1"
elif s[i+1]=="1":
s[i+1] = "0"
ans += 1
print(ans)
|
power = [2,3,4,5,6,7,8,9,10,11,12,13,1,]
A,B = map(int, input().split())
if power.index(A) > power.index(B):
print("Alice")
elif A == B:
print("Draw")
else:
print("Bob")
|
S=input()
flag=0
if S==S[::-1]:
s = S[:(len(S)-1)//2]
if s==s[::-1]:
s2 = S[(len(S)+3)//2-1:]
if s2==s2[::-1]:
flag=1
if flag:print('Yes')
else:print('No') |
lst = input().split()
if (int(lst[0]) * int(lst[1])) % 2 == 0:
print('Even')
else:
print('Odd') |
S = input()
N = len(S)
K = int(input())
S_list = sorted(set(list(S)))
memo = {}
for small_char in S_list:
for i in range(N):
if S[i] == small_char:
for j in range(i+1, i+K+1):
word = S[i:j]
memo[word] = None
if len(memo) >= K:
break
ans_list = sorted(list(memo.keys()))
print(ans_list[K-1])
|
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
N, M = map(int, input().split())
S = input()
T = input()
gcd_val = gcd(N, M)
for i in range(gcd_val):
if S[i * N // gcd_val] != T[i * M // gcd_val]:
print(-1)
exit()
print(lcm(N, M))
|
S = input()
print("ARC") if S=="ABC" else print("ABC") |
#-------------
N = int(input())
#-------------
cnt = 0
while True:
X = 2**cnt
if N//2 >= X:
cnt +=1
else:
break
print(X) |
x = input()
if x == 7:
print "YES"
elif x == 5:
print "YES"
elif x == 3:
print "YES"
else:
print "NO" |
s = input()
o = ""
for w in s:
if w.isupper():
o += w.lower()
elif w.islower():
o += w.upper()
else:
o += w
print(o)
|
def str_reverse(s, a, b):
s_new = s[0:a]
s_rev = s[a:b+1]
s_rev_len = len(s_rev)
for i in range(s_rev_len):
j = s_rev_len - i - 1
s_new += s_rev[j]
s_new += s[b+1:]
return s_new
def str_replace(s, a, b, new):
s_new = s[0:a]
s_new += new
s_new += s[b+1:]
return s_new
s = input()
n = int(input())
for q in range(n):
line = input()
if line.find('print') == 0:
cmd, a, b = line.split()
a = int(a)
b = int(b)
print(s[a:b+1])
elif line.find('reverse') == 0:
cmd, a, b = line.split()
a = int(a)
b = int(b)
s = str_reverse(s, a, b)
elif line.find('replace') == 0:
cmd, a, b, p = line.split()
a = int(a)
b = int(b)
s = str_replace(s, a, b, p) |
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
counter = Counter(S)
for k in ["AC", "WA", "TLE", "RE"]:
print(k, "x", counter[k]) |
p = input()
s = []
for i in range(len(p)):
s.append(p[i])
if len(s) == 3:
s.reverse()
print("".join(s)) |
def cal(a, op, b):
if op == '+':
r = a + b
elif op == '-':
r = a - b
elif op == '*':
r = a * b
else:
r = a / b
return r
while 1:
a,op,b = raw_input().split()
if op == '?':
break
else:
print(cal(int(a), op, int(b))) |
n = int(input())
s = input()
count = 0
for i,_ in enumerate(s) :
if s[i:i+3] == "ABC":
count += 1
print(count) |
from math import sqrt, sin, cos, radians
a, b, cc = map(int, input().split())
cc = radians(cc)
sinc = sin(cc)
s = a * b * sinc / 2
c = sqrt(a * a + b * b - 2 * a * b * cos(cc))
h = b * sinc
print(s)
print(a + b + c)
print(h) |
n = input()
k = int(n[-1])
if k == 3:
print("bon")
elif k == 0 or k == 1 or k == 6 or k == 8:
print("pon")
else:
print("hon")
|
import math
r = float(input())
a = r * r * math.pi
b = r * 2 * math.pi
print('{0:f} {1:f}'.format(a, b)) |
s = input().split("hi")
f = 0
for i in s:
if i != "":
f = 1
break
if f == 0:
print("Yes")
else:
print("No") |
S = input()
a = len(S)
if a%2==1:
print("No")
exit()
for i in range(0,a,2):
if S[i:i+2]!="hi":
print("No")
break
else:
print("Yes")
break |
a = list(input())
l = []
for i in zip(a, a[1:]):
l.append(i)
if any([l[i][0] == l[i][1] for i in range(3)]):
print('Bad')
else:
print('Good')
|
# 解説AC
# https://kkt89.hatenablog.com/entry/2020/06/21/ABC171_F-Strivore
# で理解
MOD = 10**9 + 7
class modint():
def __init__(self, value):
self.value = value % MOD
def __int__(self):
return int(self.value)
def __float__(self):
return float(self.value)
def __str__(self):
return str(self.value)
def __repr__(self):
return str(self.value)
def __add__(self, other):
return (modint(self.value + other.value) if isinstance(other, modint)
else modint(self.value + other))
def __sub__(self, other):
return (modint(self.value - other.value) if isinstance(other, modint)
else modint(self.value - other))
def __mul__(self, other):
return (modint(self.value * other.value) if isinstance(other, modint)
else modint(self.value * other))
def __truediv__(self, other):
return (modint(self.value * pow(other.value, MOD - 2, MOD))
if isinstance(other, modint)
else modint(self.value * pow(other, MOD - 2, MOD)))
def __pow__(self, other):
return (modint(pow(self.value, other.value, MOD))
if isinstance(other, modint)
else modint(pow(self.value, other, MOD)))
def __eq__(self, other):
return (self.value == other.value if isinstance(other, modint)
else self.value == (other % MOD))
def __ne__(self, other):
return (self.value == other.value if isinstance(other, modint)
else self.value == (other % MOD))
def __radd__(self, other):
return (modint(other.value + self.value) if isinstance(other, modint)
else modint(other + self.value))
def __rsub__(self, other):
return (modint(other.value - self.value) if isinstance(other, modint)
else modint(other - self.value))
def __rmul__(self, other):
return (modint(other.value * self.value) if isinstance(other, modint)
else modint(other * self.value))
def __rtruediv__(self, other):
return (modint(other.value * pow(self.value, MOD - 2, MOD))
if isinstance(other, modint)
else modint(other * pow(self.value, MOD - 2, MOD)))
def __rpow__(self, other):
return (modint(pow(other.value, self.value, MOD))
if isinstance(other, modint)
else modint(pow(other, self.value, MOD)))
def main():
K = int(input())
S = input()
N = len(S)
m = N+K + 5
fac = [0] * m
finv = [0] * m
inv = [0] * m
def COMBinitialize(m):
fac[0] = 1
finv[0] = 1
if m > 1:
fac[1] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, m):
fac[i] = fac[i-1] * i % MOD
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
def COMB(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
COMBinitialize(m)
M = K + N
ans = modint(pow(26, M, MOD))
for i in range(N):
v = COMB(M, i) * pow(25, M-i, MOD)
v %= MOD
ans -= v
print(ans)
if __name__ == '__main__':
main()
|
S = input()
truth = "CODEFESTIVAL2016"
c = 0
for i in range(len(S)) :
if (S[i] != truth[i]) :
c += 1
print(c) |
s = input()
while len(s) > 7:
if s[-5:] in ["dream", "erase"]:
s = s[:-5]
elif s[-6:] in ["eraser"]:
s = s[:-6]
elif s[-7:] in ["dreamer"]:
s = s[:-7]
else:
break
if (len(s)==5 and s in ["dream", "erase"]) or (len(s)==6 and s in ["eraser"]) or (len(s)==7 and s in ["dreamer"]):
print("YES")
else:
print("NO") |
from collections import deque
S = input()
d = deque()
for s in S:
if len(d) == 0:
d.append(s)
elif s == "T":
if d[-1] == "S":
d.pop()
else:
d.append(s)
elif s == "S":
d.append(s)
print(len(d)) |
def selection_sort(List):
cnt = 0
l=len(List)
for i in range(l):
num_index=i
for j in range(i,l):
if List[num_index]>List[j]:
num_index=j
if num_index != i:
temp=List[num_index]
List[num_index]=List[i]
List[i]=temp
cnt+=1
return cnt
N=input()
N_List=map(int,raw_input().split())
cnt=selection_sort(N_List)
print(" ".join(map(str,N_List)))
print(cnt) |
import numpy as np
def check_pali(S):
for i in range(0, len(S)):
if S[i] != S[-1 * i + -1]:
return False
elif i > (len(S) / 2) + 1:
break
return True
S = input()
N = len(S)
short_N = (N - 1) // 2
long_N = (N + 3) // 2
if check_pali(S) & check_pali(S[0:short_N]) & check_pali(S[long_N-1:N]):
print("Yes")
else:
print("No") |
# 周期的にループする明日の天気を予測してください
# ループする関数がわからんかったから調べた
# 結果 ループする必要なし
# for (変数名)in (イテラブル):
# (コードブロック)
today = input ()
if today == "Sunny":
print("Cloudy")
elif today == "Cloudy":
print("Rainy")
else:
print("Sunny")
|
A, B = map(int, input().split())
# F(A,B) = F(0,A-1) ^ F(0,B)
# 任意の偶数について、n ^ (n+1) = 1
# ex. F(0,6) = 0^1^2^3^4^5^6 = (0^1)^(2^3)^(4^5)^6 = 1^1^1^6
# 1^1^1^...について、1が偶数個なら0, 奇数個なら1
def xor_func(n):
if n % 2 == 0:
tmp = n // 2
if tmp % 2 == 0:
x = 0 ^ n
else:
x = 1 ^ n
else:
tmp = (n + 1) // 2
if tmp % 2 == 0:
x = 0
else:
x = 1
return x
f1 = xor_func(A - 1)
f2 = xor_func(B)
ans = f1 ^ f2
print(ans)
|
s = raw_input()
tmp = "YAKI"
if s.find(tmp) != 0:
print "No"
else:
print "Yes"
|
R = int(input())
import math
pi = math.pi
around = 2 * R * pi
print(around) |
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 = [int(i) for i in input().split()]
print(gcd(a, b), lcm(a, b))
except EOFError:
break |
import sys
input = sys.stdin.readline
class Dice:
"""
0:top, 1:south, 2:east, 3:west, 4:north, 5:bottom
"""
def __init__(self, surfaces):
self.init_surface = surfaces
self.surface = surfaces
def roll(self, direction: str):
if direction == "E":
self.surface = [self.surface[3], self.surface[1], self.surface[0],
self.surface[5], self.surface[4], self.surface[2]]
elif direction == "N":
self.surface = [self.surface[1], self.surface[5], self.surface[2],
self.surface[3], self.surface[0], self.surface[4]]
elif direction == "S":
self.surface = [self.surface[4], self.surface[0], self.surface[2],
self.surface[3], self.surface[5], self.surface[1]]
elif direction == "W":
self.surface = [self.surface[2], self.surface[1], self.surface[5],
self.surface[0], self.surface[4], self.surface[3]]
return
def spin(self):
self.surface = [self.surface[0], self.surface[3], self.surface[1],
self.surface[4], self.surface[2], self.surface[5]]
return
def get_surface(self, num):
return self.surface.index(num)
def get_top(self):
return self.surface[0]
def get_south(self):
return self.surface[1]
def get_east(self):
return self.surface[2]
def main():
surface = [int(i) for i in input().strip().split()]
cases = int(input().strip())
dice = Dice(surface)
for _ in range(cases):
top, south = [int(i) for i in input().strip().split()]
# get current surface
cur = dice.get_surface(top)
if cur == 0:
pass
elif cur == 1:
dice.roll("N")
elif cur == 2:
dice.roll("W")
elif cur == 3:
dice.roll("E")
elif cur == 4:
dice.roll("S")
elif cur == 5:
dice.roll("S")
dice.roll("S")
for _ in range(4):
dice.spin()
if dice.get_south() == south:
print(dice.get_east())
if __name__ == "__main__":
main()
|
s = sorted(input())
ans = "Yes" if s == list("abc") else "No"
print(ans)
|
def solve(n):
if n is 0:
return 0
return 1 + 2 * solve(n // 2)
print(solve(int(input()))) |
# すめけくんは
# 現在のレートが 1200未満ならば AtCoder Beginner Contest (ABC) に、
# そうでなければ AtCoder Regular Contest (ARC) に参加することにしました。
# すめけくんの現在のレート xが与えられます。
# すめけくんが参加するコンテストが ABC ならば ABC と、そうでなければ ARC と出力してください。
# 制約
# 1 ≦ x ≦ 3,000
# x は整数
# 標準入力から x を取得する
x = int(input())
# レートを判定して結果を出力する
result = "ret"
if x < 1200:
result = "ABC"
else:
result = "ARC"
print(result)
|
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 17:01:05 2020
@author: shinba
"""
a,b = map(int,input().split())
if a == 1:
if b == 1:
print("Draw")
else:
print("Alice")
elif b == 1:
print("Bob")
else:
if a > b:
print("Alice")
elif b > a:
print("Bob")
else:
print("Draw")
|
def main():
n = int(input())
s = input()
t = input()
mod = 10 ** 9 + 7
p = {"||": 2, "==": 3, "|=": 2, "=|": 1, "|": 3, "=": 6}
ans = 1
bf = ""
it = iter(range(n))
for i in it:
if s[i] == t[i]:
nw = "|"
else:
nw = "="
it.__next__()
ans *= p[bf + nw]
ans %= mod
bf = nw
print(ans % mod)
if __name__ == '__main__':
main()
|
import math
class Point(object):
def __init__(self, x,y):
self.x = x*1.0
self.y = y*1.0
def Koch(n,p1,p2):
s=Point((2*p1.x+p2.x)/3,(2*p1.y+p2.y)/3)
t=Point((p1.x+2*p2.x)/3,(p1.y+2*p2.y)/3)
u=Point((t.x-s.x)*math.cos(math.radians(60))-(t.y-s.y)*math.sin(math.radians(60))+s.x,(t.x-s.x)*math.sin(math.radians(60))+(t.y-s.y)*math.cos(math.radians(60))+s.y)
if n==0:
return
Koch(n-1,p1,s)
print s.x,s.y
Koch(n-1,s,u)
print u.x,u.y
Koch(n-1,u,t)
print t.x,t.y
Koch(n-1,t,p2)
n=input()
p1=Point(0,0)
p2=Point(100,0)
print p1.x,p1.y
Koch(n,p1,p2)
print p2.x,p2.y
|
num_list = [int(input()) for _ in range(3)]
X = num_list[0]
A = num_list[1]
B = num_list[2]
X -= A
while X >= B:
X -= B
print(X) |
import numpy as np
R = int(input())
pi = np.pi
print(2*R*pi)
|
arr = [1,2,3]
one = int(input())
two = int(input())
arr[one-1] = 0
arr[two-1] = 0
for i in arr:
if i > 0: print(i) |
import sys
X = int(input())
a = 0
if X <= 2:
print(X)
else:
for i in range(1,X):
a += i
if a >= X:
print(i)
sys.exit() |
int(input())
S = input()
K = int(input())
for s in S:print(s if s==S[K-1] else '*', end='') |
from collections import Counter
S = input()
cnt = Counter(list(S))
print('Yes' if list(cnt.values()) == [2, 2] else 'No')
|
n = int(input())
s = input()
k = int(input())
char = s[k-1]
ret_list = []
for i in range(len(s)):
if s[i] == char:
ret_list.append(s[i])
else:
ret_list.append('*')
print("".join(ret_list))
|
a = input()
b = input()
A = sorted(a)
B = sorted(b)
B.reverse()
if(A < B):
print('Yes')
else:
print('No') |
def main():
money_on_hand = int(input())
cake_cost = int(input())
donut_cost = int(input())
print((money_on_hand - cake_cost) % donut_cost)
if __name__ == '__main__':
main() |
p,q = input().split()
a = int(p)
b = int(q)
if a >= b *2:
print(a - 2*b)
else:
print(0)
|
x=int(input())
f=x//100
d=x%100
ff=bool(1)
dd=bool(1)
if f==0 or f>12:
ff=0
if d==0 or d>12:
dd=0
if ff==1 and dd==1:
print("AMBIGUOUS")
elif ff==0 and dd==0:
print("NA")
else:
if ff==1 and dd==0:
print("MMYY")
else:
print("YYMM") |
# Sum of Divisors
import math
N = int(input())
ans = 0
for i in range(1,N+1):
K = math.floor(N/i)
ans += (K * (K+1) * i)/2
print(int(ans))
|
S = input().rstrip()
T = input().rstrip()
from collections import defaultdict
s2t = defaultdict(int)
t2s = defaultdict(int)
for s,t in zip(S,T):
if (s2t[s] != 0 and s2t[s] != t) or (t2s[t] != 0 and t2s[t] != s):
print('No')
exit()
s2t[s] = t
t2s[t] = s
print('Yes') |
N=int(input())
def f(n):
for i in range(int(n**.5),0,-1):
if n%i==0:
return n//i
print(len(str(f(N)))) |
def solve():
S = input()
for i in range(len(S)-1):
if S[i:i+2]=='AC':
print('Yes')
return
print('No')
return
solve() |
s = str(input())
for i in range(len(s)):
s=s[:-2]
if s[:len(s)//2] ==s[len(s)//2:]:
print(len(s))
break |
cnt = 0
def merge(A,left,mid,right):
'''n1 = mid - left
n2 = right - mid
L = []
R = []
for i in range(0,n1):
L.append(A[left+i])
for i in range(0,n2):
R.append(A[mid+i])
L.append(1000000001)
R.append(1000000001)
'''
L = A[left:mid]+[1000000001]
R = A[mid:right]+[1000000001]
i = 0
j = 0
global cnt
for k in range(left,right):
cnt += 1
if L[i] <= R[j]:
A[k]=L[i]
i += 1
else:
A[k] = R[j]
j += 1
def mergeSort(A,left,right):
if left+1 < right:
mid = (left+right)//2
mergeSort(A,left,mid)
mergeSort(A,mid,right)
merge(A,left,mid,right)
if __name__ == '__main__':
n = (int)(input())
a = list(map(int,input().split()))
mergeSort(a,0,n)
print(*a)
print(cnt) |
from functools import reduce
print("Odd" if reduce(lambda x,y: x*y, list(map(int, input().split())))&1 else "Even") |
from collections import Counter
S = input()
T = input()
s = sorted(list(Counter(S).values()))
t = sorted(list(Counter(T).values()))
if s == t:
print("Yes")
else:
print("No") |
def main():
s = input()
cubes = []
for c in s:
if c == "0":
cubes.append("red")
else:
cubes.append("blue")
buffer = [] #キューブの一時保存場所。同じ色が続くとここにたまっていく
buffer.append(cubes.pop()) #cubesの最後の要素をbufferの最後に移し替える。
counter = 0
while cubes:
if len(buffer) <= 0 or buffer[-1] == cubes[-1]: #bufferが空じゃないことを確認してからbufferとcubesの最後の要素を比較
buffer.append(cubes.pop()) #同じ色はbufferに格納
else: #もし違う色だったら
buffer.pop() #bufferの最後のキューブをひとつ消す
cubes.pop() #cubesの最後のキューブをひとつ消す
counter += 2 #2個消去
print(counter)
if __name__ == '__main__':
main()
|
trump_dictionary = {}
keys = ['S', 'H', 'C', 'D']
for key in keys:
for num in range(13):
trump_dictionary[key + ' ' + str(num + 1)] = 0
num = int(raw_input())
counter = 0
while counter < num:
key = raw_input()
if key in trump_dictionary:
trump_dictionary.pop(key)
counter += 1
for key in keys:
for num in range(13):
if key + ' ' + str(num + 1) in trump_dictionary:
print(key + ' ' + str(num + 1)) |
class Dice:
def __init__(self):
self.numbers = map(int, raw_input().split())
def roll(self, direction):
if direction == "N":
before_inds = [0, 1, 5, 4]
after_inds = [1, 5, 4, 0]
elif direction == "S":
before_inds = [0, 1, 5, 4]
after_inds = [4, 0, 1, 5]
elif direction == "E":
before_inds = [0, 2, 5, 3]
after_inds = [3, 0, 2, 5]
elif direction == "W":
before_inds = [0, 2, 5, 3]
after_inds = [2, 5, 3, 0]
else:
return False
changed = [self.numbers[i] for i in after_inds]
for c_i, n_i in enumerate(before_inds):
self.numbers[n_i] = changed[c_i]
return True
dice = Dice()
for d in raw_input():
dice.roll(d)
print dice.numbers[0] |
s=input()
if s in ["RRR"]:
print(3)
elif s in ["RRS","SRR"]:
print(2)
elif s in ["RSS","SRS","SSR","RSR"]:
print(1)
else:
print(0) |
def prime_judge(x):
for i in range(2, int(x ** (1 / 2)) + 1):
if x % i == 0:
return False
return True
X = int(input())
while not prime_judge(X):
X += 1
print(X) |
ls = list(input().split(' '))
if ls.count(ls[0]) == 2 or ls.count(ls[1]) == 2:
print('Yes')
else:
print('No') |
x = int(input())
num = 0
i = 0
while num < x:
i += 1
num += i
if (num - x) < i:
print(i) |
def actual(a, b, c):
if (a + b) == c or (b + c) == a or (c + a) == b:
return 'Yes'
return 'No'
a, b, c = map(int, input().split())
print(actual(a, b, c)) |
s = input()
print("Yes" if len(set(s))==2 and len(s[0])==len(s[1])==len(s[2])==len(s[3]) else "No") |
# Crane and Turtle
X, Y = [int(i) for i in input().split()]
for t in range(0, X + 1):
legs = 2 * (X + t)
if Y == legs:
a = 'Yes'
break
if Y < legs:
a = 'No'
break
else:
a = 'No'
print(a)
|
N = int(input())
r = "ABC" + str(N)
print(r) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.