text
stringlengths 37
1.41M
|
---|
n = int(input())
dic_A = set()
dic_C = set()
dic_G = set()
dic_T = set()
for i in range(n) :
p, string = input().split()
if p == 'insert' :
if string[0] == 'A' :
dic_A.add(string)
elif string[0] == 'C' :
dic_C.add(string)
elif string[0] == 'G' :
dic_G.add(string)
else :
dic_T.add(string)
else :
if string[0] == 'A' :
if string in dic_A :
print('yes')
else :
print('no')
elif string[0] == 'C' :
if string in dic_C :
print('yes')
else :
print('no')
elif string[0] == 'G' :
if string in dic_G :
print('yes')
else :
print('no')
else :
if string in dic_T :
print('yes')
else :
print('no')
|
s = input()
even, odd = [], []
for i in range(len(s)):
if i%2:
odd.append(s[i])
else:
even.append(s[i])
e = list(set(odd))
o = list(set(even))
if('L' in o or 'R' in e):
print('No')
else:
print('Yes') |
import sys
input = sys.stdin.readline
S = input()[: -1]
if len(S) == 3: print(S[: : -1])
else: print(S) |
for i in range(0,9):
for j in range(0,9):
print("{0}x{1}={2}".format(i+1,j+1,(i+1)*(j+1))) |
s = input()
if s >= "A" and s <= "Z":
print("A")
elif s >= "a" and s <= "z":
print("a")
|
n = input()
res = "No"
for i in range(3):
if n[i] == "7":
res = "Yes"
print(res) |
#coding: UTF-8
import sys
import math
class Algo:
@staticmethod
def bubbleSort(r, n):
flag = 1
count = 0
while flag:
flag = 0
for j in range(n-1, 0, -1):
if r[j] < r[j-1]:
r[j], r[j-1] = r[j-1], r[j]
count += 1
flag = 1
for i in range(0, n):
if i == n-1:
print(r[i])
else:
print(r[i], " ", sep="", end="")
print(count)
N = int(input())
R= list(map(int, input().split()))
Algo.bubbleSort(R, N) |
#!/usr/bin python3
# -*- coding: utf-8 -*-
def main():
S = input()
S = S.replace('BC','Z')
S = S.replace('B',' ')
S = S.replace('C',' ')
S = S[::-1]
S = S.split()
ret = 0
for s in S:
zcn = 0
for si in s:
zcn += (si == 'Z')
ret += zcn * (si == 'A')
print(ret)
if __name__ == '__main__':
main() |
n, a, b = map(int, input().split())
a_fee = a * n
b_fee = b
if a_fee < b_fee:
print(a_fee)
else:
print(b_fee) |
ia = [int(i) for i in input().split(" ")]
W=ia[0]
H=ia[1]
x=ia[2]
y=ia[3]
r=ia[4]
print("Yes" if 0<=x-r and x+r<=W and 0<=y-r and y+r<=H else "No") |
N=int(input())
S=input()
a=ord("A")
z=ord("Z")
result=""
for i in range(len(S)):
word=ord(S[i])+N
if word>z:
word=word-z-1+a
x=chr(word)
result+=x
print(result)
|
# -*- coding: utf-8 -*-
def main():
N = int(input())
listN = list(map(int, str(N)))
if 7 in listN:
ans = 'Yes'
else:
ans = 'No'
print(ans)
if __name__ == "__main__":
main() |
from collections import deque
s=input()
d=[]
for i in s:
if i=="S":
d.append("S")
elif i=="T" and (not d or d[-1]=="T"):
d.append("T")
else:
d.pop()
print(len(d))
|
s = input()
t = ""
for i in range(1,len(s)+1):
if i % 2 == 1:
t += s[i-1]
print(t) |
n = int(input())
print("YES" if any((n == 3,n == 5,n == 7)) else "NO") |
import math
a,b,deg = map(float,input().split(" "))
sindeg = math.sin(math.radians(deg))
S = (a*b*sindeg)/2
cosdeg = math.cos(math.radians(deg))
z = a*a + b*b - 2*a*b*cosdeg
L = a + b + math.sqrt(z)
h = b*sindeg
print("{:.5f}".format(S))
print("{:.5f}".format(L))
print("{:.5f}".format(h))
|
a,b,c,=map(int,input().split())
if (a<=c<=b):print('Yes')
else:print('No') |
import copy
def SelectionSort(arr, n):
for i in range(n):
mini = i
for j in range(i, n):
if arr[j]['val'] < arr[mini]['val']:
mini = j
if mini != i:
arr[i], arr[mini] = arr[mini], arr[i]
return
def BubleSort(arr, n):
for i in range(n):
for j in range(n - 1, i, -1):
if arr[j]['val'] < arr[j-1]['val']:
arr[j], arr[j-1] = arr[j-1], arr[j]
return
def isStable(inarr, comparr, n):
i = 0
while i < n:
tmpVal = comparr[i]['val']
for j in range(n):
if inarr[j]['val'] == tmpVal:
if inarr[j]['crd'] == comparr[i]['crd']:
if i != n - 1 and comparr[i+1]['val'] == tmpVal:
i += 1
else:
break
else:
return 'Not stable'
i += 1
return 'Stable'
n = int(input())
arr = input().split()
tar = []
for s in arr:
tar.append({'crd': s[0], 'val': s[1], 'str': s})
bub = copy.copy(tar)
BubleSort(bub, n)
prt = []
for s in bub:
prt.append(s['str'])
print(*prt)
print(isStable(tar, bub, n))
bub = copy.copy(tar)
SelectionSort(bub, n)
prt = []
for s in bub:
prt.append(s['str'])
print(*prt)
print(isStable(tar, bub, n))
|
X = int(input())
ureshi = 0
# 500 yen
ureshi += (X // 500) * 1000
X = X % 500
# 5 yen
ureshi += (X // 5) * 5
print(ureshi) |
def func(K):
result = ""
for i in range(K):
result += "ACL"
return result
if __name__ == "__main__":
K = int(input())
print(func(K)) |
N=input()
N=int(N)
S=input()
count=0
for i in range(N-2):
if S[i]=="A" and S[i+1]=="B" and S[i+2]=="C":
count=count+1
print(count) |
s=input()
frag="yes"
for i in range(len(s)):
n=s.count(s[i])
if n >1:
frag="no"
break
print(frag) |
x=input()
if x=="A":
print("T")
if x=="T":
print("A")
if x=="G":
print("C")
if x=="C":
print("G")
|
# coding: utf-8
# https://atcoder.jp/contests/abc101
def main():
S = input()
ans = 0
for s in S:
if s == "+":
ans += 1
else:
ans -= 1
return ans
print(main())
|
a=input()
b=input()
if len(a)>len(b):
print('GREATER')
elif len(a)<len(b):
print('LESS')
else:
n=len(a)
for i in range(n):
if a[i]<b[i]:
print('LESS')
exit()
if a[i]>b[i]:
print('GREATER')
exit()
print('EQUAL') |
# だるいので強引
n = int(input())
d = {}
dd = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for _ in range(n):
s = input()
if s[0] in list("MARCH") and s not in d:
d[s] = True
dd[s[0]] += 1
ans = 0
ans += dd["M"] * dd["A"] * dd["R"]
ans += dd["M"] * dd["A"] * dd["C"]
ans += dd["M"] * dd["A"] * dd["H"]
ans += dd["M"] * dd["R"] * dd["C"]
ans += dd["M"] * dd["R"] * dd["H"]
ans += dd["M"] * dd["C"] * dd["H"]
ans += dd["A"] * dd["R"] * dd["C"]
ans += dd["A"] * dd["R"] * dd["H"]
ans += dd["A"] * dd["C"] * dd["H"]
ans += dd["R"] * dd["C"] * dd["H"]
print(ans)
|
N=input()
if int(N) >= 3:
num = int(N)/3
print(int(num))
else:
print('0') |
A = input()
B = input()
u = len(A)
v = len(B)
if u>v:
print("GREATER")
elif v>u:
print("LESS")
else:
i , j=0 , 0
while i<u:
if A[i]>B[i]:
print("GREATER")
exit()
elif A[i]<B[i]:
print("LESS")
exit()
i=i+1
print("EQUAL")
exit() |
import string
a=string.ascii_lowercase
A=string.ascii_uppercase
n=input()
if n in a :
print("a")
else :
print("A")
|
s=input()
ans=""
if len(s)==2:
print(s)
else:
ans=s[2]
ans+=s[1]
ans+=s[0]
print(ans) |
a = input()
print("Bad" if a[0]==a[1] or a[1]==a[2] or a[2]==a[3] else "Good") |
n = int(input())
for N in range(3, n+1):
if N % 3 == 0\
or N % 10 == 3\
or str(N).find("3") != -1:
print(" {0}".format(N), end = "")
print() |
x = int(input())
ans = (x // 11) * 2
if 0 < x % 11 < 7:
ans += 1
elif 6 < x % 11:
ans += 2
print(ans) |
#coding:utf-8
s = input()
res = 0
for i in s:
if i =='2':
res +=1
print(res) |
s = input()
n = len(s) - 1
for i in range(1 << n):
p_or_m = ['-'] * n
for j in range(n):
if i >> j & 1:
p_or_m[n-j-1] = '+'
formula = ''
for k in range(n):
formula += s[k] + p_or_m[k]
formula += s[3]
if eval(formula) == 7:
print(formula + '=7')
exit() |
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
A, B = read_ints()
if A == B:
return 'Draw'
if (A == 1 and B == 13):
return 'Alice'
if (A == 13 and B == 1):
return 'Bob'
if A > B:
return 'Alice'
return 'Bob'
if __name__ == '__main__':
print(solve())
|
s = input()
S = s.replace('A', '')
if S == 'KIHBR' and 'AA' not in s and 'KIH' in s:
print('YES')
else:
print('NO')
|
x = raw_input().split()
if float(x[0]) < float(x[1]):
print "a < b"
elif float(x[0]) > float(x[1]):
print "a > b"
else:
print "a == b" |
digits = int(input())
num_list = [int(i) for i in list(input())]
flag1 = 0
flag2 = 0
counter = 0
for num1 in range(10):
for num2 in range(10):
for num3 in range(10):
flag1 = 0
flag2 = 0
for digit in range(digits):
if flag1 == 0 and flag2 == 0 and num1 == num_list[digit]:
flag1 = 1
continue
if flag1 == 1 and num2 == num_list[digit]:
flag2 = 1
flag1 = 0
continue
if flag2 == 1 and num3 == num_list[digit]:
counter += 1
flag2 = 0
break
print(counter)
|
s=input()
if len(s)%2:
s=s[:-1]
else:
s=s[:-2]
while len(s)!=2:
if s[:len(s)//2]==s[len(s)//2:]:
break
s=s[:-2]
print(len(s)) |
n = int(input())
for i in range(1, n + 1):
ans = int(i * 1.08)
if ans == n:
print(i)
quit()
print(':(') |
words = input()
if words[-1] != "s":
words += "s"
else:
words += "es"
print(words)
|
a, b = input().split()
print('H' if (a == 'H') ^ (b == 'D') else 'D') |
# -*- coding: utf-8 -*-
num = int(raw_input())
a = int(raw_input())
b = int(raw_input())
diff = b - a
pre_min = min(a,b)
counter = 2
while counter < num:
current_num = int(raw_input())
if diff < current_num - pre_min:
diff = current_num - pre_min
if pre_min > current_num:
pre_min = current_num
counter += 1
print diff |
class UnionFind():
# 作りたい要素数nで初期化
# 使用するインスタンス変数の初期化
def __init__(self, n):
self.n = n
# root[x]<0ならそのノードが根かつその値が木の要素数
# rootノードでその木の要素数を記録する
self.root = [-1]*(n+1)
# 木をくっつける時にアンバランスにならないように調整する
self.rnk = [0]*(n+1)
# ノードxのrootノードを見つける
def Find_Root(self, x):
if(self.root[x] < 0):
return x
else:
# ここで代入しておくことで、後の繰り返しを避ける
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
# 木の併合、入力は併合したい各ノード
def Unite(self, x, y):
# 入力ノードのrootノードを見つける
x = self.Find_Root(x)
y = self.Find_Root(y)
# すでに同じ木に属していた場合
if(x == y):
return
# 違う木に属していた場合rnkを見てくっつける方を決める
elif(self.rnk[x] > self.rnk[y]):
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
# rnkが同じ(深さに差がない場合)は1増やす
if(self.rnk[x] == self.rnk[y]):
self.rnk[y] += 1
# xとyが同じグループに属するか判断
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
# ノードxが属する木のサイズを返す
def Count(self, x):
return -self.root[self.Find_Root(x)]
def main():
n, m = map(int, input().split())
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(m)]
tree = UnionFind(n)
for x, y in xy:
tree.Unite(x, y)
root = [[] for _ in range(n+1)]
f_root = []
for i in range(n):
x = tree.Find_Root(p[i])
root[x].append(i+1)
f_root.append(x)
out_put = 0
for i in range(n):
if f_root[i]==f_root[p[i]-1]:
out_put += 1
print(out_put)
if __name__=="__main__":
main() |
import math
import string
def intinput():
return int(input())
def listintinput():
return list(map(int,input().split()))
def splitintinput():
return map(int,input().split())
X, Y, Z = splitintinput()
print(int((X-Z)/(Y+Z)))
|
from collections import deque
S=input()
t = deque()
for s in S:
if s == 'B' and len(t) !=0:
t.pop()
elif s == '1' or s == '0':
t.append(s)
print(''.join(t))
|
s = input()
if s =='A':print('T')
elif s == 'T':print("A")
elif s == 'C':print("G")
elif s == 'G':print("C")
|
def red_or_blue(N: int, s: str)->bool:
r = sum(c == 'R' for c in s)
return r > N-r
if __name__ == "__main__":
N = int(input())
s = input()
yes = red_or_blue(N, s)
print('Yes' if yes else 'No')
|
w = input()
r = ''
for i in range(len(w)):
c = str(w[i])
if (w[i].islower()):
c = w[i].upper()
elif (w[i].isupper()):
c = w[i].lower()
r = r + c
print(r)
|
def main():
A, B, C, K = map(int, input().split())
d = abs(A - B)
if d > 10**18:
print("Unfair")
else:
if A > B:
if K % 2 == 0:
print(d)
else:
print(-d)
elif A < B:
if K % 2 == 0:
print(-d)
else:
print(d)
else:
print("0")
if __name__ == "__main__":
main() |
n = int(raw_input())
debt=100000
for i in range(n):
debt*=1.05
if debt % 1000 != 0:
debt = (int(debt / 1000)+1) * 1000
else:
debt = int(debt)
print debt |
while True:
s = input().replace("\r", "").replace("\n", "")
if s == "-":
break
n = int(input())
for i in range(n):
j = int(input())
s = s[j:] + s[:j]
print(s)
|
A,B = map(int,input().split())
def gcd(a, b):
if b==0:
return a
return gcd(b, a%b)
print(A*B//gcd(A,B)) |
s = input()
is_C = False
for i in range(len(s)):
if s[i] == "C":
is_C = True
if is_C and s[i] == "F":
print("Yes")
exit()
if i == len(s)-1:
print("No") |
s = input()
n = int(s)
count = 0
divisors = 0
arrays = []
for i in range(n+1):
arrays.append(False)
for i in range(n+1):
if i % 2 == 1:
divisors = 0
for j in range(len(arrays)):
arrays[j] = False
for j in range(1,i+1):
if i % j == 0:
arrays[j] = True
for j in range(len(arrays)):
if arrays[j]:
divisors += 1
if divisors == 8:
count += 1
print(count) |
def resolve():
s = input()
step_odd = 'RUD'
step_even = 'LUD'
ans = 'Yes'
for i,j in enumerate(s):
if i%2==0 and j not in step_odd:
ans = 'No'
elif i%2!=0 and j not in step_even:
ans = 'No'
else:
pass
print(ans)
resolve() |
a_num, b_num = map(int, input().split())
result = a_num * b_num
if result % 2 == 0:
print('Even')
else:
print('Odd')
|
S=list(input())
while len(S)>1:
if S[0] == 'h' and S[1] == 'i':
S.remove('h')
S.remove('i')
else:
break
if len(S) == 0:
print('Yes')
else:
print('No')
|
# 正の整数aとb
a, b = map(int, input().split())
# aとbの積が偶数か奇数か判別する
# 積が奇数なら'Odd'、偶数なら'Even'と出力する
if int(a * b / 2) < int(a * b / 2 + 0.5):
print('Odd')
else:
print('Even') |
n = int(input())
max_1 = 0
max_2 = 0
max_index = 0
for i in range(n):
item = int(input())
if item >= max_1:
max_1, max_2 = item, max_1
max_index = i
elif item > max_2:
max_2 = item
for i in range(n):
ans = max_2 if i == max_index else max_1
print(ans)
|
s = input()
three ='RRR'
two ='RR'
one ='R'
if three in s:
print('3')
elif two in s:
print('2')
elif one in s:
print('1')
else :
print('0') |
a=int(input())
b=int(input())
c=int(input())
d=int(input())
if a>=b:
ans=b
else:
ans=a
if c>=d:
ans+=d
else:
ans+=c
print(ans) |
import re
def reader():
p = re.compile("^{}$".format(input()), re.I)
yield 0
while True:
s = input()
if s == "END_OF_TEXT":
break
for w in s.split():
if p.match(w):
yield 1
print(sum(reader())) |
n=int(input())
a=[]
for i in range(1,10):
for j in range(1,10):
a.append(i*j)
else:
if n in a:
print('Yes')
else:
print('No') |
import itertools
N = int(input())
odd = N // 2 + N % 2
even = N // 2
print(odd * even)
|
target = input()
now_height = []
now_area = [0]
answer = []
continued = 0
depth = 0
depth_list = []
for t in target:
# print(now_height,depth_list,now_area,answer,continued)
if t == '\\':
now_height.append(continued)
depth_list.append(depth)
now_area.append(0)
depth -= 1
elif t == '_':
pass
elif t == '/' and len(now_height) > 0:
depth += 1
started = now_height.pop()
temp_area = continued - started
# print(depth_list[-1],depth)
now_area[-1] += temp_area
if depth > depth_list[-1]:
while depth > depth_list[-1]:
temp = now_area.pop()
now_area[-1] += temp
depth_list.pop()
continued += 1
now_area = list(filter(lambda x:x != 0,now_area))
answer.extend(now_area)
print(sum(answer))
print(len(answer),*answer) |
n = int(input())
for i in range(3, n + 1):
if i % 3 == 0 or i % 10 == 3 or '3' in str(i):
print('',"{0}".format(i),end='')
print() |
import fractions
n = int(input())
t = [int(input()) for _ in range(n)]
def lcm(a, b):
return a*b//fractions.gcd(a, b)
if n == 1:
print(t[0])
else:
ans = lcm(t[0], t[1])
for i in range(2, n):
ans = lcm(ans, t[i])
print(ans) |
N = int(input())
def dfs(s):
if len(s) > 0:
if int(s) > N:
return 0
count = 0
if "3" in s and "5" in s and "7" in s:
count += 1
for next_n in ["3", "5", "7"]:
count += dfs(s + next_n)
return count
print(dfs("")) |
name = input()
length = len(name)
if "s" == name[length-1]:
name = name + "es"
else:
name = name + "s"
print(name) |
#シェルソート
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
#その間隔で比較できる最も左から始める.vが基準値
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
n = int(input())
A = [int(input()) for i in range(n)]
cnt = 0
G = [1]
for i in range(100):
if n < 1 + 3*G[-1]:
break
G.append(1+3*G[-1])
m = len(G)
G.reverse()
for i in range(m):
insertionSort(A, n, G[i])
print(m)
print(*G)
print(cnt)
print(*A, sep='\n')
|
n = int(input())
d = set()
for i in range(n):
com = input().split()
if com[0] == 'insert':
d.add(com[1])
else:
print('yes' if com[1] in d else 'no') |
num = input()
num1,num2 = num.split(' ')
num1 = int(num1)
num2 = int(num2)
print(num1 * num2) |
while True:
X = input()
if X == "0":
break
num = sum([int(x) for x in X])
print(str(num))
|
s = int(input())
i = 1
if s == 1 or s == 2:
print(4)
exit()
while True:
if s == 4:
print(i+3)
exit()
if s%2 == 0:
s=s//2
else:
s=3*s+1
i += 1 |
s = input().split()
s1 = list(s[0])
s2 = list(s[1])
s3 = list(s[2])
print(s1[0].upper()+s2[0].upper()+s3[0].upper()) |
s = list(input())
if s[0] == s[2]:
print("=")
elif s[0] < s[2]:
print("<")
else:
print(">") |
#1st line
input_str = input().strip()
#2nd line
command_max_times = int(input().strip())
command_cnt = 0
while command_cnt < command_max_times:
command_cnt = command_cnt + 1
input_line = input().strip().split(" ")
input_command = input_line[0]
input_sta = int(input_line[1])
input_end = int(input_line[2])
if input_command == "print":
print(input_str[input_sta:input_end+1])
elif input_command == "replace":
str_replace = input_line[3]
input_str = input_str[:input_sta] + str_replace + input_str[input_end+1:]
elif input_command == "reverse":
str_temp = input_str[input_sta:input_end+1]
input_str = input_str[:input_sta] + str_temp[::-1] + input_str[input_end+1:] |
S = {'A': input(), 'B': input(), 'C': input()}
turn = 'A'
while S[turn] != '':
next = S[turn][0]
S[turn] = S[turn][1:]
turn = next.upper()
print(turn) |
S = input()
lis_S = list(S)
set_S = set(S)
if len(lis_S) == len(set_S):
print("yes")
else:
print("no") |
S = input()
d = S
left = 0
right = len(d) - 1
count = 0
while left < right:
#print(f'{left=}, {right=}')
if d[right] == d[left]:
left += 1
right -= 1
else:
if d[right] == 'x':
count += 1
right -= 1
elif d[left] == 'x':
count += 1
left += 1
else:
count = -1
print(-1)
break
if count != -1:
print(count)
|
c = 0
while True:
a = input().split(' ')
x = int(a[0])
y = int(a[1])
if (x or y) == 0:
break;
elif x < y:
print(x,y)
elif x > y:
print(y,x)
elif x == y:
print(x,y)
c += 1 |
# B - I miss you...
# S
S = input()
answer = '0'
for i in range(0, len(S)):
answer += 'x'
print(answer[1:len(S) + 1])
|
from decimal import Decimal
a,b,c = map(Decimal, input().split())
d = Decimal(0.5)
print("Yes" if a**d+b**d < c**d else "No") |
s=[x for x in input()]
t=[x for x in input()]
s=sorted(s)
t=sorted(t,reverse=True)
s=''.join(s)
t=''.join(t)
ans=[]
ans.append(s)
ans.append(t)
ans.sort()
if s==t:
print('No')
elif ans[0]==s:
print('Yes')
else:
print('No') |
dice = input().split()
dice.insert(4, dice.pop(3))
right = []
def rightSearch(up, front):
index_up = dice.index(up)
index_front = dice.index(front)
if 1 <= index_up <= 4 and 1 <= index_front <= 4:
if index_up == 4 and index_front == 1:
return dice[0]
if index_up == 1 and index_front == 4:
return dice[5]
if index_up < index_front:
return dice[0]
else:
return dice[5]
elif (index_front == 0 or index_front == 5) and (index_up != 0 or index_up != 5):
if index_front == 0:
if index_up == 1:
return dice[4]
else:
return dice[index_up - 1]
else:
if index_up == 4:
return dice[1]
else:
return dice[index_up + 1]
else:
if index_up == 0:
if index_front == 4:
return dice[1]
else:
return dice[index_front + 1]
else:
if index_front == 1:
return dice[4]
else:
return dice[index_front - 1]
number = int(input())
for i in range(number):
up, front = input().split()
right.append(rightSearch(up, front))
for r in right:
print(r)
|
# -*- coding: utf-8 -*-
def main():
w = input()
setW = set(w)
listW = list(w)
n = len(listW)
for i in setW:
if listW.count(i) % 2 == 1:
ans = 'No'
break
else:
ans = 'Yes'
print(ans)
if __name__ == "__main__":
main() |
def count(word, text):
"""Count the word in text.
Counting is done case-insensitively.
>>> count('a', 'A b c a')
2
>>> count('computer', 'Nurtures computer scientists' \
+ ' and highly-skilled computer engineers' \
+ ' who will create and exploit "knowledge"' \
+ ' for the new era. Provides an outstanding' \
+ ' computer environment.')
3
"""
return (text
.lower()
.split()
.count(word.lower()))
def run():
word = input()
text = ""
line = input()
while line != "END_OF_TEXT":
text += line + "\n"
line = input()
print(count(word, text))
if __name__ == "__main__":
run()
|
power=1
for i in range(1,int(input())+1):
power=(power*i)%(10**9+7)
print(power) |
h ,w = map(int, input().split())
board = [list(input()) for tate in range(h)]
now = 0
flag = False
for i in board:
direction = i.count("#")
if (flag != True):
now = direction
flag = True
else:
if(direction == 1):
continue
else:
now = now + direction - 1
if (now == w):
print("Possible")
else:
print("Impossible") |
s = input()
ans = []
if len(s) == 2:
print(s)
elif len(s) == 3:
for i in range(len(s)):
ans.append(s[2-i])
ans_ = map(str, ans)
print("".join(ans_)) |
n = int(input())
dic = {}
for i in range(n):
s = input()
if s not in dic:
dic[s] = 1
else:
dic[s] += 1
C = sorted(dic.items())
max_dic = max(dic.values())
for name,i in C:
if i == max_dic:
print(name) |
line = input()
a, b = [int(n) for n in line.split()]
if a > 8 or b > 8:
print(":(")
elif a == b or a < b or b < a:
print("Yay!")
|
N=input().split()
print('H' if (N[0]=='H' and N[1] == 'H') or (N[0]=='D' and N[1] == 'D') else 'D') |
#前の問題で、戻り値とかIDとか変更したつもりのリストが変わっていないことが
#頻発していたはずだがとりあえず並び替え自体は終わる。countどうしようか。
#いじると並び替え前の配列が返ってくることがある。
n=int(input())
A1=input().split( )
A=[int(A1[i]) for i in range(n)]
###疑似コードのコピペ
def merge(A, left, mid, right):
n1 = mid - left;
n2 = right - mid;
#いちいち[0 for i...]を作るのやめた
L=A[left:mid]+[10000000000]
R=A[mid:right]+[10000000000]
i = 0
j = 0
count=0
for k in range(left,right):
count+=1
if L[i] <= R[j]:
A[k] = L[i]
i = i + 1
else:
A[k] = R[j]
j = j + 1
#count+=1の位置を変更,比較ってinfinityとの比較も含めるのか
#計算量的には当然か。
return(count)
def mergeSort(A, left, right):
count=0
mid=0
if left+1 < right:
mid = int((left + right)/2)
#この辺で新しい変数をmergeSortの戻り値として定義
countL=mergeSort(A, left, mid)
countR=mergeSort(A, mid, right)
countM=merge(A, left, mid, right)
count=countL+countR+countM
return(count)
c=mergeSort(A,0,n)
print(*A)
print(c)
|
def main():
O = input()
E = input()
last = ""
if len(O) > len(E):
last = O[-1]
O = O[:-1]
ans = ""
for s1, s2 in zip(O, E):
ans += s1 + s2
ans += last
print(ans)
if __name__ == "__main__":
main() |
#!/usr/bin python3
# -*- coding: utf-8 -*-
mod = 10**9+7
n = int(input())
ret = 0
ret += pow(10,n,mod)
ret -= 2 * pow(9,n,mod)
ret %= mod
ret += pow(8,n,mod)
ret %= mod
print(ret)
|
'''
問題:
水を入れる容器が 2つあります。
容器 1には水を A ミリリットルまで入れることができ、
水が B ミリリットル入っています。
容器 2 には水が C ミリリットル入っています。
容器 2 から容器 1 に入るだけ水を移します。
容器 2 の中には何ミリリットルの水が残るでしょうか。
'''
'''
制約:
入力は全て整数である。
1 ≤ B ≤ A ≤ 20
1 ≤ C ≤ 20
'''
# 標準入力から A, B, C の値を取得する
a, b, c = map(int, input().split())
# 容器2の水の量を計算して出力する
result = c - (a - b)
if result > 0:
print(result)
else:
print(0) # 水は残ってないので、0 を出力する
|
def insertionSort(arr, N, g):
cnt = 0
for i in range(g, N):
tmp = arr[i]
j = i - g
while(j >= 0 and arr[j] > tmp):
arr[j + g] = arr[j]
j -= g
cnt += 1
arr[j + g] = tmp
return cnt
def shellSort(arr, N):
cnt = 0
G = []
h = 0
m = 0
while h <= N / 9:
h = 3 * h + 1
G.append(h)
m += 1
G = G[::-1]
cnt = sum([insertionSort(arr, N, g) for g in G])
return (cnt, G)
N = int(input())
arr = [int(input()) for i in range(N)]
(cnt, G) = shellSort(arr, N)
print(len(G), ' '.join(map(str, G)), cnt, '\n'.join(map(str, arr)), end='\n')
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.