text
stringlengths 37
1.41M
|
---|
N = int(input())
def digit_sum(n):
a = 0
s = str(n)
for digit in s:
a += int(digit)
return a
print(['No','Yes'][N % digit_sum(N) == 0]) |
a=input()
a=[int(x) for x in a.split()]
b=a[0]+a[1]
c=a[2]
print("Yes" if b>c or b==c else "No") |
print('a' if input().islower()==True else 'A') |
N = int(input())
def sum(n):
return n*(n+1)//2
# for i in range(1, N+1):
# if i % 3 != 0 and i % 5 != 0:
# ans += i
ans = sum(N)-sum(N//3)*3-sum(N//5)*5+sum(N//15)*15
print(ans)
|
import sys
import decimal # 10進法に変換,正確な計算
def input():
return sys.stdin.readline().strip()
def main():
n = int(input())
n = decimal.Decimal(n)
if n % 2 == 0:
print(1/decimal.Decimal(2))
return
print(((n-1)/2+1)/n)
main() |
a,b = map(int, input().split())
def gcd(x, y):
if y < x:
x,y = y,x
while x%y != 0:
x,y = y,x%y
return y
def lcm(x, y):
return (x*y)//gcd(x,y)
print(lcm(a,b)) |
s = input()
length = 0
max_length = 0
for i in range(len(s)):
if s[i] in 'ACGT':
length += 1
else:
length = 0
if length > max_length:
max_length = length
print(max_length) |
numbers_x = []
numbers_y = []
while True:
x,y=map(int, input().split())
if x==0 and y==0:
break
if x > y:
x,y = y,x
numbers_x.append(x)
numbers_y.append(y)
for i in range(len(numbers_x)):
print(numbers_x[i],numbers_y[i])
|
'''
問題:
a,b,c からなる長さ 3 の文字列 S が与えられます。
S を abc を並び替えて作ることができるかどうか判定してください。
'''
'''
制約:
|S|=3
S は a,b,c からなる
'''
def abc093a(input: str) -> str:
str_list = ["abc", "acb", "bac", "bca", "cab", "cba"]
if input not in str_list:
return "No"
else:
return "Yes"
s = str(input())
print(abc093a(s))
|
# -*- coding: utf-8 -*-
a, b, c, d = map(int, input().split())
ac = abs(a-c) <= d
ab = abs(a-b) <= d
bc = abs(b-c) <= d
print(['No', 'Yes'][ac or (ab and bc)]) |
K=int(input())
i=0
if K%2==0 or K%5==0:
print('-1')
else:
for d in range(K):
i=(10*i+7)%K
if i==0:
print(d+1)
break
|
x = int(input())
ans = int((x * 2) ** 0.5)
while 1:
if ans * (ans + 1) // 2 >= x:
print(ans)
break
ans += 1 |
a=input()
print("No") if a[0]==a[1] or a[1]==a[2] or a[0]==a[2] else print("Yes") |
S = input()
stack = []
for s in S:
if not stack and s!="B":
stack.append(s)
elif s=="B":
if stack:stack.pop()
else:continue
else:
stack.append(s)
print("".join(stack)) |
import math
n = int(input())
o = n / 1.080
o_floor = math.floor(o)
o_ceil = math.ceil(o)
if math.floor(o_floor * 1.08) == n:
print(o_floor)
elif math.floor(o_ceil * 1.08) == n:
print(o_ceil)
else:
print(':(') |
X,A,B=map(int,input().split())
if B<=A:
print("delicious")
elif B>A and (A+X)>=B:
print("safe")
else:
print("dangerous") |
sen = input()
target = input()
def cilcle(s, n):
result = ""
for i in range(n):
result += sen[i%len(sen)]
return result
if target in cilcle(sen, len(sen)**2):
print("Yes")
else:
print("No")
|
import math
in_line = raw_input().split()
a = float(in_line[0])
b = float(in_line[1])
c = float(in_line[2])
print 0.5*a*b*math.sin(math.radians(c))
print a+b+math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(c)))
print b*math.sin(math.radians(c)) |
try:
age,money=map(int, input().split())
assert 0<=age<=100 and 2<=money<=1000 and money%2==0
if age<=5:
print('0')
elif 6<=age<=12:
print(money//2)
else:
print(money)
except AssertionError:
print('')
|
#20 C - Write and Erase
N = int(input())
A = [int(input()) for _ in range(N)]
paper = set()
for a in A:
if not(a in paper):
paper.add(a)
else:
paper.remove(a)
print(len(paper)) |
from decimal import Decimal
A, B = input().split()
A = int(A)
if len(B) == 1:
B = int(B[0] + '00')
elif len(B) == 3:
B = int(B[0] + B[2] + '0')
else:
B = int(B[0]+B[2]+B[3])
x = str(A*B)
print(x[:-2] if len(x) > 2 else 0)
|
from math import ceil
n=int(input())
money=100000
for i in range(n):
money=ceil(money*1.05/1000)*1000
print(money)
|
INF = 2*int(1e9)
cnt = 0
def merge(A, left, mid, right):
global cnt
nl = mid - left
nr = right - mid
L = A[left:mid]
R = A[mid:right]
L.append(INF)
R.append(INF)
i = 0
j = 0
for k in range(left, right):
cnt = cnt + 1
if L[i] <= R[j]:
A[k] = L[i]
i = i + 1
else:
A[k] = R[j]
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)
def main():
n = int(input())
s = [int(i) for i in input().split()]
mergeSort(s, 0, n)
for i in range(n):
if i == n-1:
print(s[i])
else:
print(s[i], end=' ')
print(cnt)
main()
|
import string as st
string=[]
try:
while True:
s = input()#入力
string =list(string)#list変換
if not s :#空入力のときループぬける
break
string.extend(s)#list追加
string=map(str,string)
string="".join(string).lower()#str型変換と小文字
except EOFError:
for i in range(len(st.ascii_lowercase)):
print("{} : {}".format(st.ascii_lowercase[i],string.count(st.ascii_lowercase[i])))
|
import fractions
def lcm(x,y):
return x*y//fractions.gcd(x,y)
N, M = map(int, input().split())
S = input()
T = input()
L = lcm(N,M)
ST_idx = set([i*(L//N) for i in range(N)]) & set([i*(L//M) for i in range(M)])
for x in ST_idx:
if S[(N*x)//L] != T[(M*x)//L]:
print(-1)
break
else:
print(L) |
import math
from functools import reduce
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm(numbers):
return reduce(lcm_base, numbers, 1)
n = int(input())
an = list(map(int, input().split()))
l = lcm(an)-1
an = [l%i for i in an]
print(sum(an)) |
i = list(input())
s = 0
k = 0
while k <= 3:
if i[k] == "2":
s += 1
k += 1
print (s) |
A,B= input().split(' ')
if int(A)*int(B)%2 == 0:
print("Even")
else:
print("Odd") |
import math
x=int(input())
def get_sieve_of_eratosthenes(n):
prime = []
limit = math.sqrt(n)
data = [i + 1 for i in range(1, n)]
while True:
p = data[0]
if limit <= p:
return prime + data
prime.append(p)
data = [e for e in data if e % p != 0]
data = get_sieve_of_eratosthenes(x*2)
for i in data:
if i>=x:
print(i)
break
#print(data) |
def read_n_lows_input(n):
Alist=[int(input()) for i in range(n)]
return Alist
def print_list(A):
print(*A, sep=" ")
def print_list_multi_low(A):
for i in A:
print(i)
def insertion_sort(A, n, g, cnt):
for i in range(g-1, n):
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
return A, cnt
def shell_sort(A, n):
cnt = 0
G0 = [797161, 265720, 88573, 29524, 9841, 3280, 1093, 364, 121, 40, 13, 4, 1]
G = [i for i in G0 if i <= n]
m = len(G)
print(m)
print_list(G)
for i in range(m):
A, cnt = insertion_sort(A, n, G[i], cnt)
print(cnt)
print_list_multi_low(A)
n=int(input())
A = read_n_lows_input(n)
shell_sort(A, n)
|
def main():
import math
from collections import Counter
N,M = map(int,input().split())
a = []
def prime_factorize(n):
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
prime_factorize(M)
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
divisors = Counter(a)
count = 1
for k,v in divisors.items():
count *= combinations_count(v+N-1,v)
print(count%(10**9+7))
main() |
def bubble(A, N):
c = 0
flag = True
while flag:
flag = False
for j in range(N-1, 0, -1):
if A[j] < A[j-1]:
A[j], A[j-1] = A[j-1], A[j]
c += 1
flag = True
return A, c
if __name__ == "__main__":
N = int(input())
A = [int(i) for i in input().split()]
A, c = bubble(A, N)
print (*A)
print (c) |
def round_up_division(num1, num2):
# 切り上げ除算
div = -(-num1 // num2)
return div
def binary_search(search_range, max_num, logs):
search_min = 1
search_max = search_range
# 二分探索
while True:
# max_numを超えない最大回数にする
count_a = 0
# count_aより1短い長さ
count_b = 0
# 最小値と最大値の中間の値を出す
half_num = (search_min + search_max - 1) // 2 + 1
for i in range(logs):
# 木を切る回数は(⌈(木の長さ)//(切りたい長さ)⌉-1)回
count_a += round_up_division(A[i], half_num) - 1
if half_num != 1:
count_b += round_up_division(A[i], half_num - 1) - 1
if count_a > K:
# 多ければ長い半分で探索
search_min = round_up_division(search_min + search_max, 2)
elif half_num != 1 and count_b <= K:
# 少なければ短い半分で探索
search_max = half_num - 1
else:
# count_aが最大になれば終了
return half_num
break
N, K = map(int, input().split())
A = list(map(int, input().split()))
length_max = binary_search(max(A), K, N)
print(length_max) |
ab=[list(map(int,input().split(" "))) for _ in range(3)]
d=[]
for i in ab:
d.append(i[0])
d.append(i[1])
if d.count(1)>=3 or d.count(2)>=3 or d.count(3)>=3 or d.count(4)>=3:
print("NO")
else:
print("YES") |
class Dice:
def __init__(self, num_list):
self.vertical_faces = [num_list[0], num_list[1], num_list[5], num_list[4]]
self.horizonal_faces = [num_list[0], num_list[3], num_list[5], num_list[2]]
def roll(self, direction):
if direction == 'N':
self.vertical_faces = self.vertical_faces[1:] + self.vertical_faces[:1]
self.horizonal_faces[0] = self.vertical_faces[0]
self.horizonal_faces[2] = self.vertical_faces[2]
elif direction == 'S':
self.vertical_faces = self.vertical_faces[3:] + self.vertical_faces[:3]
self.horizonal_faces[0] = self.vertical_faces[0]
self.horizonal_faces[2] = self.vertical_faces[2]
elif direction == 'E':
self.horizonal_faces = self.horizonal_faces[1:] + self.horizonal_faces[:1]
self.vertical_faces[0] = self.horizonal_faces[0]
self.vertical_faces[2] = self.horizonal_faces[2]
else:
self.horizonal_faces = self.horizonal_faces[3:] + self.horizonal_faces[:3]
self.vertical_faces[0] = self.horizonal_faces[0]
self.vertical_faces[2] = self.horizonal_faces[2]
num_list = list(map(int, input().split()))
dice = Dice(num_list)
directions = input()
for i in directions:
dice.roll(i)
print(dice.vertical_faces[0]) |
n = int(input())
l = len(set(input().split()))
if l==4:
print("Four")
elif l==3:
print("Three") |
h = int(input())
ans = 0
i = 0
while True:
if(2**i>=h):
break
i+=1
if(i == 0):
print(1)
elif(2**i==h):
print(2**(i+1)-1)
else:
print(2**i-1)
|
word = input()
start = 0
end = len(word)
while(True):
i = word.find('?', start, end)
if (i == -1):
break
elif (i == (end-1)):
word = word.replace('?', "D", 1)
elif (word[i-1] == 'P'):
word = word.replace('?', "D", 1)
elif ((word[i+1] == "?") or (word[i+1] == "D")):
word = word.replace('?', "P", 1)
else:
word = word.replace('?', "D", 1)
start = i + 1
print(word) |
s=input()
t=input()
def rote(st):
return st[1:]+st[0]
ans="No"
for i in range(len(s)):
if s==t:
ans="Yes"
break
t=rote(t)
print(ans) |
arr = input().split()
arr = list(map(int,arr))
a = arr[0]
b = arr[1]
if a % 3 == 0 or b % 3 == 0 or (a+b) % 3 == 0:
print('Possible')
else:
print('Impossible')
|
s = str(input())
num = len(s)
numS = str(num - 2)
print(s[0] + numS + s[-1])
|
S = list(input())
chars = [chr(ord('a')+i) for i in range(26)]
for i in chars:
if i not in S:
print(i)
exit()
print('None') |
import math
N = int(input())
odd = math.ceil(N/2)
print(odd/N) |
#!/usr/bin/env python3
import math
def lcm(x, y):
return (x * y) // math.gcd(x, y)
def main():
n, m = map(int, input().split())
s = input()
t = input()
ans = lcm(n, m)
ln = ans // n
lm = ans // m
l = lcm(ln, lm)
i = 0
while i * l // ln < n and i * l // lm < m:
if s[i * l // ln] != t[i * l // lm]:
ans = -1
break
i += 1
print(ans)
if __name__ == "__main__":
main()
|
while True:
data = map(int, raw_input().split())
if data[0] == 0 and data[1] == 0:
break
else:
for i in range(data[0]):
if i % 2 == 0:
if data[1] % 2 == 0:
print "#." * (data[1] / 2)
else :
print "#." * (data[1] / 2) + "#"
elif i % 2 == 1:
if data[1] % 2 == 0:
print ".#" * (data[1] / 2)
else :
print ".#" * (data[1] / 2) + "."
print |
"""Binary Indexed Tree (Fenwick Tree)"""
class BIT:
def __init__(self, n):
self.n = n
#BIT木データ
self.data = [0]*(n+1)
#元配列
self.el = [0]*(n+1)
"""A1~Aiまでの累積和"""
def Sum(self, i):
s = 0
while i > 0:
s += self.data[i]
#LSB(Least Significant Bit)の獲得:i&(-i)
i -= i & (-i)
return s
"""Ai += x"""
def Add(self, i, x):
self.el[i] += x
while i <= self.n:
self.data[i] += x
i += i & -i
"""Ai ~ Ajまでの累積和"""
def Get(self, i, j=None):
if j is None:
return self.el[i]
return self.Sum(j) - self.Sum(i)
s = input()
s = s.replace('BC', 'D')
mode = 0
res = 0
for i in range(len(s)):
if s[i] == 'B' or s[i]=='C':
mode = 0
elif s[i] == 'A':
mode += 1
else:
res += mode
print(res) |
class Dice:
def __init__(self, n1, n2, n3, n4, n5, n6):
self.elements = [n1, n2, n3, n4, n5, n6]
def rotateW(self):
n5 = self.elements[0]
n1 = self.elements[2]
n3 = self.elements[5]
n6 = self.elements[4]
self.elements[4] = n5
self.elements[0] = n1
self.elements[2] = n3
self.elements[5] = n6
def rotateN(self):
n2 = self.elements[0]
n1 = self.elements[3]
n4 = self.elements[5]
n6 = self.elements[1]
self.elements[1] = n2
self.elements[0] = n1
self.elements[3] = n4
self.elements[5] = n6
def rotateS(self):
n4 = self.elements[0]
n1 = self.elements[1]
n2 = self.elements[5]
n6 = self.elements[3]
self.elements[3] = n4
self.elements[0] = n1
self.elements[1] = n2
self.elements[5] = n6
def rotateE(self):
n3 = self.elements[0]
n1 = self.elements[4]
n5 = self.elements[5]
n6 = self.elements[2]
self.elements[2] = n3
self.elements[0] = n1
self.elements[4] = n5
self.elements[5] = n6
elements = map(int, raw_input().split(" "))
dice = Dice(elements[0], elements[4], elements[2], elements[1], elements[3], elements[5])
rule = raw_input()
for i in rule:
if i == "S": dice.rotateS()
elif i == "W": dice.rotateW()
elif i == "N": dice.rotateN()
elif i == "E": dice.rotateE()
print(str(dice.elements[0])) |
S = [i for i in input()]
if len(S) == 3:
for i in reversed(S):
print(i, end="")
else:
for i in S:
print(i, end="") |
N = int(input())
X = -(-N//1.08)
n = X*108//100
if(int(N)==int(n)):
print(int(X))
else:
print(':(') |
[a,b] = list(map(int,input().split()))
if (a*b) %2 ==0:
print('Even')
else:
print('Odd') |
def main2():
N = int(input())
mod = 10**9 + 7
ans = 10**N - 9**N - 9**N + 8**N
print(ans % mod)
if __name__ == "__main__":
main2() |
import typing
n = int(input())
res = 0
str_num = ""
def dfs(str_num: str, i: int, finish:int):
global res
if i == finish:
# print(str_num)
if str_num and int(str_num) <= n and len(set(str_num)) == 3:
res += 1
# print(res, str_num)
return 0
dfs(str_num + "3", i + 1, finish)
dfs(str_num + "5", i + 1, finish)
dfs(str_num + "7", i + 1, finish)
# dfs(str_num, i + 1)
if __name__ == "__main__":
for i in range(3, 10):
dfs(str_num, 0, i)
print(res)
|
s = str(input())
z = 'Yes'
for i in range(len(s)):
if i%2 == 0:
if s[i] != 'R' and s[i] != 'U' and s[i] != 'D':
z = 'No'
break
else:
if s[i] != 'L' and s[i] != 'U' and s[i] != 'D':
z = 'No'
break
print(z) |
s=[]
p=[]
s=input()
s+=s
p=input()
if (p in s)==True:
print("Yes")
else:
print("No")
|
from collections import deque
d = deque()
for a in range(int(input())):
com = input().split()
if com[0] == "insert":
d.appendleft(com[1])
elif com[0] == "delete":
if com[1] in d:
d.remove(com[1])
elif com[0] == "deleteFirst":
d.popleft()
elif com[0] == "deleteLast":
d.pop()
else:
break
print(*d)
|
while True :
a = raw_input().split()
x = int(a[0])
y = int(a[1])
if x == 0 and y == 0 :
break
elif x < y :
print u"%d %d" % (x, y)
else :
print u"%d %d" % (y, x) |
N = int(input())
candidates = [True]*(2*(10**5)+1)
candidates[0] = candidates[1] = False
for i in range(2, N):
for j in range(i, 2*(10**5)+1, i):
candidates[j] = False
for n, n_is_prime in enumerate(candidates):
if n_is_prime:
print(n)
break |
# -*- coding:utf-8 -*-
x = int(input())
if x == False:
print("1")
else:
print("0") |
a = int(input())
b = int(input())
c = int(input())
d = int(input())
result = min(a, b) + min(c, d)
# result = int(min(a, b)) + int(min(c, d))
print(result) |
a,b,c,d = list(input())
if a==b or b==c or c==d:
print('Bad')
else:print('Good') |
i = 1
while True:
a = int(input())
if (a == 0):
break
else:
print("Case " + str(i) + ": " + str(a))
i += 1 |
a = int(input())
ans = 0
for i in range(3):
ans += a**(i+1)
print(ans) |
S = input()
List = []
for i in range(len(S)):
if i % 2 == 0:
List.append(S[i])
print(''.join(List)) |
x = input()
y = len(x)
if y==3:
x = x[::-1]
print(x) |
S = input()
a = len(S)
b = -1
for i in range(len(S)):
if S[i] == "C":
a = i
break
for i in range(len(S)):
if S[len(S)-i-1] == "F":
b = len(S)-i-1
break
if a < b:
print("Yes")
else:
print("No") |
N = int(input())
pre = input()
dict = {pre:1}
for i in range(N-1):
now = input()
if now[0]!=pre[-1]:
print('No')
exit(0)
elif now in dict:
print('No')
exit(0)
else:
dict[now] = 1
pre = now
print('Yes') |
N=int(input())
A=list(map(int,input().split()))
A1=set(A)
ans="NO"
if len(A)==len(A1):
ans="YES"
print(ans) |
word = input()
if word[-1] == 's':
print(word, end='es\n')
else:
print(word, end='s\n') |
A=int(input())
B=int(input())
if A>B: print("GREATER")
elif A<B: print("LESS")
else: print("EQUAL") |
H, W = [int(hoge) for hoge in input().split()]
print("Possible") if sum([input().count("#") for h in range(H)]) == H+W-1 else print("Impossible")
|
s = input().split()
x1=s[0][0]
x2=s[0][1]
x3=s[0][2]
flag = False
A = 'A'
B = 'B'
if x1==A and x2==A and x3==A:
flag = True
elif x1==B and x2==B and x3==B:
flag = True
else:
flag = False
if (flag):
result = 'No'
else:
result = 'Yes'
print(result) |
from decimal import Decimal
l = input()
t = Decimal(l) / Decimal("3")
v = t ** 3
print(v) |
n=(input())
if n.endswith('s'):
print(n+'es')
else:
print(n+'s')
|
words = input()
makeword = input()
words = words + words
if makeword in words:
print('Yes')
else:
print('No')
|
N = int(input())
a = int(N/2)
if N % 2 ==0:
print(a**2)
else:
print(a*(a+1)) |
z = input()
a,b = z.split()
c = int(a)
d = int(b)
if c < d:
print('a < b')
elif c > d:
print('a > b')
else:
print('a == b') |
X,A,B=map(int,input().split())
if A>=B:
print("delicious")
elif A<B and (A+X)>=B:
print("safe")
else:
print("dangerous") |
def main2():
A, B, C = map(int, input().split())
ans = 0
if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
print(ans)
exit()
elif (2 * A - B - C) == 0 and (2 * B - A - C) == 0 and (2 * C - A - B) == 0:
print(-1)
exit()
else:
while True:
if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
print(ans)
exit()
A, B, C = (B + C)//2, (A + C)//2, (A + B)//2
ans += 1
if __name__ == "__main__":
main2() |
a = 1; b = 1
while True:
print(a,"x",b,"=",a*b,sep="")
b += 1
if b == 10:
a += 1; b = 1
if a == 10:
break
|
a = int(input())
b = int(input())
ab = a + b
if ab == 3:
print(3)
elif ab == 4:
print(2)
else:
print(1)
|
# A - Sharing Cookies
# https://atcoder.jp/contests/abc067/tasks/abc067_a
A, B = map(int, input().split())
result = 'Impossible'
if A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0:
result = 'Possible'
print(result)
|
def parseSpaceDivideIntArgs(arg):
tmpArr = arg.split()
ret = []
for s in tmpArr:
ret.append(int(s))
return ret
instr = input()
# instr = "1 2 3"
instrSpl = parseSpaceDivideIntArgs(instr)
a = instrSpl[0]
b = instrSpl[1]
c = instrSpl[2]
if a < b & b < c:
print("Yes")
else:
print("No")
|
moji = str(input())[-1]
if int(moji) == 3:
print("bon")
else:
print(("hon","pon")[int(moji) in [0,1,6,8]]) |
S = input()
if S[-1] == "s":
ans = S+"es"
else:
ans = S+"s"
print(ans) |
#!/usr/bin/env python3
import sys
def BellmanFord(graph: "List[List[int]]", s: int):
"""
特定の始点から各点への最短距離を求めます。
重みが負であっても動作します。
================
s: 始点
graph: 隣接リスト
----------------
第一返り値: 負の閉路があるかいなか
第二返り値: 最短距離のリスト
"""
INF = 1e18
n = len(graph)
dist = [INF] * n
dist[s] = 0
for i in range(n):
for v in range(n):
for k in range(len(graph[v])):
e = graph[v][k]
if dist[v] != INF and dist[e[0]] > dist[v] + e[1]:
dist[e[0]] = dist[v] + e[1]
if i == n-1 and e[0] == n-1:
return True, dist
return False, dist
def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]"):
G = [[] for _ in range(N)]
for i in range(M):
G[a[i]-1].append((b[i]-1, c[i]))
flag, cost = BellmanFord(G, 0)
if flag:
print('inf')
else:
print(-cost[N-1])
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
a = [int()] * (M) # type: "List[int]"
b = [int()] * (M) # type: "List[int]"
c = [int()] * (M) # type: "List[int]"
for i in range(M):
a[i] = int(next(tokens))
b[i] = int(next(tokens))
c[i] = -1 * int(next(tokens))
solve(N, M, a, b, c)
if __name__ == '__main__':
main()
|
N = int(input())
num = []
for i in range(1, 9+1):
for j in range(1, 9+1):
num.append(i * j)
if N in num:
print("Yes")
else:
print("No") |
C1 = list(str(input()))
C2 = list(str(input()))[::-1]
for i in range(3):
if not C1[i]==C2[i]:
print('NO')
break
else:
print('YES') |
# coding: utf-8
def main():
S = input()
K = int(input())
ans = '1'
tmp = -1
for i, s in enumerate(S):
if s != '1':
ans = s
break
else:
tmp = i
if K - 1 <= tmp:
ans = '1'
print(ans)
if __name__ == "__main__":
main()
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
n = input()
debt = 1e5
for i in range(0, n):
debt *= 1.05
debt = math.ceil(debt/1000) * 1000
print int(debt) |
Clist=list(input())
Dlist=list(input())
if Clist==Dlist[::-1]:
print("YES")
else:
print("NO") |
n = int(raw_input())
score_taro, score_hana = 0, 0
for i in range(n):
taro, hana = raw_input().split(" ")
if taro > hana:
score_taro += 3
elif taro < hana:
score_hana += 3
else:
score_taro += 1
score_hana += 1
print(str(score_taro) + " " + str(score_hana)) |
def main():
T = input()
ans = ""
for i in range(len(T)):
t = T[i]
if t=='P' or t=='D':
ans += t
else:
ans += 'D'
print(ans)
main()
|
x=int(1)
for var in range(1,10):
y=int(1)
for var in range(1,10):
print("{}x{}={}".format(x,y,x*y))
y+=1
x+=1 |
# A - Good Integer
# https://atcoder.jp/contests/abc079/tasks/abc079_a
s = input()
if len(set(s[:3])) == 1 or len(set(s[1:])) == 1:
print('Yes')
else:
print('No')
|
n = int(input())
if n == 1:
ans = "Hello World"
else:
a, b = [int(input()) for _ in range(2)]
ans = a + b
print(ans)
|
stay = int(input())
change_day = int(input())
first_cost = int(input())
change_cost = int(input())
total_cost = 0
for i in range(stay):
if(i < change_day):
total_cost += first_cost
else:
total_cost += change_cost
print(total_cost) |
x,a,b=input().split()
x=int(x)
a=int(a)
b=int(b)
if x<a:
distance_xa=a-x
else:
distance_xa=x-a
if x<b:
distance_xb=b-x
else:
distance_xb=x-b
if distance_xa<distance_xb:
print("A")
else:
print("B") |
import math
a, b = map(int, input().split())
def is_prime(num):
if num == 2:
return True
elif num < 3 or num % 2 == 0:
return False
for i in range(3, int(math.sqrt(num)) + 1, 2):
if num % i == 0:
return False
return True
if b > a:
a, b = b, a
c = []
for i in range(1, int(math.sqrt(b))+1):
if b%i == 0:
k = b//i
if a%k == 0:
if is_prime(k):
c.append(k)
if a%i == 0:
if is_prime(i):
c.append(i)
print(len(set(c))+1) |
def candy(N):
return (N**2 +N)//2
N = int(input())
print(candy(N)) |
def fib_iter(n):
fib_n = 1
fib_n2 = 1
fib_n1 = 1
for i in range(n - 1):
fib_n = fib_n1 + fib_n2
fib_n2 = fib_n1
fib_n1 = fib_n
return fib_n
x = int(raw_input())
print fib_iter(x) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.