text
stringlengths 37
1.41M
|
---|
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
return a * b / gcd(a, b)
while True:
try:
a, b = map(int, raw_input().split())
except EOFError:
break
print "%d %d" % (gcd(a, b), lcm(a, b)) |
input_str = input()
for i in input_str:
if i.islower():
print(i.upper(), end='')
else:
print(i.lower(), end='')
print()
|
import collections
s = input()
count = collections.Counter(s)
_max = 0
for i in count.values():
if _max < i:
_max = i
if _max >= 2:
print("no")
else:
print("yes") |
def gcd_(a, b):
if a < b: a, b = b, a
if b == 0: return a
return gcd_(b, a % b)
def gcd(l):
ans = l[0]
for i in l: ans = gcd_(ans, i)
return ans
N = int(input())
print(gcd(list(map(int,input().split())))) |
x = int(input())
xd = x//100
if xd*100 <= x <= xd*105:
print(1)
else:
print(0) |
s=input()
if 'C' in s:
if 'F' in s[s.index('C'):]:
print('Yes')
else:
print('No')
else:
print('No') |
n = int(input())
if n < 100:
result = "ABC"# + "00" + str(n)
elif n > 999:
n = n - 999
result = "ABD" #+ str(n)
else:
result = "ABC" #+ str(n)
print(result) |
#!/usr/bin/env python3
a = []
a = list(map(int, input().split()))
if a[0] == a[1] and a[1] == a[2]:
print('Yes')
else:
print('No') |
def swap(A, i, j):
tmp = A[i]
A[i] = A[j]
A[j] = tmp
def bubble_sort(A, n):
count = 0
for i in range(0, n):
for j in range(n-1, i, -1):
if A[j] < A[j-1]:
swap(A, j, j-1)
count += 1
return A, count
n = int(input())
A = [int(x) for x in input().split()]
s_A, count = bubble_sort(A, n)
print(" ".join([str(x) for x in s_A]))
print(count)
|
def insertion_sort(seq):
print(' '.join(map(str, seq)))
for i in range(1, len(seq)):
key = seq[i]
j = i - 1
while j >= 0 and seq[j] > key:
seq[j+1] = seq[j]
j -= 1
seq[j+1] = key
print(' '.join(map(str, seq)))
return seq
n = int(input())
seq = list(map(int, input().split()))
insertion_sort(seq) |
# -*- coding: utf-8 -*-
#重み付きUnion-Findによる実装
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
#xの根を求める
def find(x):
if par[x] < 0:
return x
else:
px = find(par[x])
wei[x] += wei[par[x]]
par[x] = px
return px
#xの根から距離
def weight(x):
find(x)
return wei[x]
#w[y]=w[x]+wとなるようにxとyを併合
def unite(x,y,w):
w += wei[x]-wei[y]
x = find(x)
y = find(y)
if x == y:
return False
else:
#sizeの大きいほうがx
if par[x] > par[y]:
x,y = y,x
w = -w
par[x] += par[y]
par[y] = x
wei[y] = w
return True
#xとyが同じ集合に属するかの判定
def same(x,y):
return find(x) == find(y)
#xが属する集合の個数
def size(x):
return -par[find(x)]
#x,yが同じ集合に属するときのwei[y]-wei[x]
def diff(x,y):
return weight(y)-weight(x)
N,M = map(int,readline().split())
#0-index
par = [-1]*N
wei = [0]*N
for _ in range(M):
l,r,d = map(int,readline().split())
l,r = l-1,r-1
if same(l,r):
if d != diff(l,r):
print('No')
exit()
else:
unite(l,r,d)
print('Yes') |
n = input()
x = list(n)
length = len(x)
if x[length-1] == "3":
print("bon")
elif x[length-1] == "0" or x[length-1] == "1" or x[length-1] == "6" or x[length-1] =="8":
print("pon")
else:
print("hon") |
def solve():
X, A, B = [int(input()) for i in range(3)]
return (X - A) % B
if __name__ == '__main__':
print(solve()) |
X, Y = map(int, input().split())
if Y%2!=0 or Y<(X*2) or Y>(X*4):
print("No")
else:
print("Yes") |
from math import sqrt, pow
x1, y1, x2, y2 = list(map(float, input().split()))
print(sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)))
|
from itertools import product
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
def has_neighbor(_i: int, _j: int) -> bool:
patterns = [
(-1, 0), (1, 0), (0, -1), (0, 1),
]
cnt = 0
for pattern in patterns:
y, x = _i + pattern[0], _j + pattern[1]
if y in range(H) and x in range(W):
c = S[y][x]
if c == "#":
cnt += 1
else:
pass
if cnt:
return True
else:
return False
for i, j in product(range(H), range(W)):
if S[i][j] == "#" and not has_neighbor(i, j):
print("No")
break
else:
print("Yes")
|
def gcd(a, b):
return gcd(b, a%b) if b else a
while True:
try:
a, b = map(int, raw_input().split())
ans = gcd(a, b)
print ans, a*b//ans
except EOFError:
break |
import math
r = float(input())
S = math.pi * r**2
L = 2 * math.pi * r
print(S, L) |
letters = input()
if letters[2] == letters[3] and letters[4] == letters[5] :
print('Yes')
else :
print('No') |
#coding: UTF-8
import sys
table = [0]*26
letters = [chr(i) for i in range(97, 97+26)]
input_str = sys.stdin.read()
for A in input_str:
index = 0
for B in letters:
if A == B or A == B.upper():
table[index] += 1
break
index += 1
for i in range(len(letters)):
print("%s : %d"%(letters[i], table[i]))
|
import math
while True:
x = input().split()
a = int(x[0])
b = int(x[2])
oprnd = x[1]
if oprnd=="+":
print(a+b)
elif oprnd=="-":
print(a-b)
elif oprnd=="*":
print(a*b)
elif oprnd=="/":
print(math.floor(a/b))
elif oprnd=="?":
break |
for A in range(1, 10):
for B in range(1, 10):
print str(A) + 'x' + str(B) + '=' + str(A * B) |
"""
与えられた数列の奇数番目の数と偶数番目の数をそれぞれ確認し、
要素数の多いものにそれぞれ書き換える。
文字種が1種類にならないように注意する
"""
from collections import Counter
N = int(input())
V_LI = list(map(int, input().split()))
if len(set(V_LI)) == 1:
# そもそも一種類しかなかったら
print(N // 2)
exit()
odd_li = [V_LI[i] for i in range(0, N, 2)]
even_li = [V_LI[i] for i in range(1, N, 2)]
odd_c = sorted(Counter(odd_li).items(), key=lambda x: -x[1])
even_c = sorted(Counter(even_li).items(), key=lambda x: -x[1])
if odd_c[0][0] == even_c[0][0]:
cnt_1 = N
cnt_2 = N
# 偶数側を固定する
if len(even_c) > 1:
odd_cnt = len(odd_li) - odd_c[0][1]
even_cnt = len(even_li) - even_c[1][1]
cnt_1 = odd_cnt + even_cnt
# 奇数側を固定する
if len(odd_c) > 1:
odd_cnt = len(odd_li) - odd_c[1][1]
even_cnt = len(even_li) - even_c[0][1]
cnt_2 = odd_cnt + even_cnt
print(min(cnt_1, cnt_2))
else:
odd_cnt = len(odd_li) - odd_c[0][1]
even_cnt = len(even_li) - even_c[0][1]
print(odd_cnt + even_cnt)
|
a,b,c = map(int,input().split())
if(b < c and a > c):
print("Yes")
elif(a < c and b > c):
print("Yes")
else:
print("No") |
N = int(input())
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
if (n == 1):
return []
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
#print(factorization(N))
list_a = factorization(N)
count = 0
for i in range(len(list_a)):
num = list_a[i][1]
cal = 1
while(num > 0):
num -= cal
cal += 1
if(num < 0) :
break
count += 1
#print(num,count)
print(count)
|
while True:
x = input().split()
x_int = [int(i) for i in x]
if x_int[0] == 0 and x_int[1] == 0:
break
for i in range(x_int[0]):
for j in range(x_int[1]):
if i == 0 or i == x_int[0]-1:
print('#',end='')
else:
if j == 0 or j == x_int[1]-1:
print('#',end = '')
else:
print('.',end = '')
print()
print() |
a,b=input().split()
ab=a*int(b)
ba=b*int(a)
print(ab if ab < ba else ba) |
def selectionSort(numbers):
n = len(numbers)
count = 0
for i in range(n):
min_j = i
for j in range(i + 1, n):
if numbers[j] < numbers[min_j]:
min_j = j
if min_j != i:
temp = numbers[i]
numbers[i] = numbers[min_j]
numbers[min_j] = temp
count += 1
return (" ".join(list(map(str, numbers))), count)
def inputInline():
int(input())
numbers = list(map(int, input().split(" ")))
return numbers
result = selectionSort(inputInline())
print(result[0])
print(result[1]) |
#!/usr/bin/env python3
import sys
try:
from typing import List
except ImportError:
pass
def solve(x: "List[int]", y: "List[int]"):
x1, x2 = x
y1, y2 = y
x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x3 - (y3 - y2)
y4 = y3 + (x3 - x2)
print(x3, y3, x4, y4)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
x = [int()] * (2) # type: "List[int]"
y = [int()] * (2) # type: "List[int]"
for i in range(2):
x[i] = int(next(tokens))
y[i] = int(next(tokens))
solve(x, y)
if __name__ == '__main__':
main()
|
a,b=input().split();print('=' if a==b else '<' if a<b else '>') |
n=int(input())
if "Y" in list(map(str,input().split())):
print("Four")
else:
print("Three") |
def lcm(a, b):
return a // gcd(a, b) * b
def gcd(a, b):
if(b == 0): return a
else: return gcd(b, a % b)
def cnt(a):
res = 0
while(a and a % 2 == 0):
a //= 2
res += 1
return res
n, m = map(int, input().split())
A = list(map(int, input().split()))
l = 1
c = cnt(A[0])
for a in A:
if cnt(a) != c or c == 0:
print(0)
exit()
else:
l = lcm(l, a // 2)
d = m // l
print((d + 1) // 2) |
N = int(input())
ans = 0
for i in range(N):
n = i + 1
if n % 3 == 0 or n % 5 == 0:
continue
else:
ans += n
print(ans) |
N = int(input())
number1 = [2,4,5,7,9]
number2 = [3]
number3 = [0,1,6,8]
if N % 10 in number1:
print('hon')
elif N % 10 in number2:
print('bon')
elif N % 10 in number3:
print('pon') |
# A - Next Alphabet https://atcoder.jp/contests/abc151/tasks/abc151_a
number=ord(input())
moji=chr(number+1)
print(moji) |
dict_1 = {"A":"T","G":"C"}
dict_2 = {"T":"A","C":"G"}
s = input()
if s in dict_1:
ans = dict_1[s]
else:
ans = dict_2[s]
print(ans) |
s = input()
a = "abcdefghijklmnopqrstuvwxyz"
for i in s:
a = a.replace(i, "")
else:
if len(a):
print(a[0])
else:
print("None") |
n = input()
if n >= 'A' and n <= 'Z':
print('A')
if n >= 'a' and n <= 'z':
print('a') |
X = int(input())
n = X//100
k = X % 100
if k <= 5*n:
print(1)
else:
print(0) |
import math
N = int(input())
for n in range(N):
num = N - n
sqrt_num = math.sqrt(num)
if (int(sqrt_num) == sqrt_num):
print(num)
break |
N = int(input())
T = ("3","5","7")
def dfs(x):
if x != "" and int(x) > N:
return 0
res = 0
if len(set(x)) == 3:
res = 1
for t in T:
res += dfs(x + t)
return res
print(dfs("")) |
if __name__ == "__main__":
while True:
a,op,b = map(str,input().split())
if op is "+":
print("%d"%(int(a)+int(b)))
elif op is "-":
print("%d"%(int(a)-int(b)))
elif op is "*":
print("%d"%(int(a)*int(b)))
elif op is "/":
print("%d"%(int(a)/int(b)))
else:
break |
A, B, C = map(int, input().split())
if A * B * C % 2 == 0:
print(0)
else:
M = max(A, B, C)
if M == A:
print(B * C)
elif M == B:
print(A * C)
else:
print(A * B) |
import math
cnt = 0
for i in range(int(input())):
x = int(input())
flg = False # なんらかの数で割り切れるかどうか
if x == 1:
continue
if x == 2:
cnt += 1
continue
for k in range(2, math.floor(math.sqrt(x))+1):
if not(x % k):
flg = True
break
if not flg:
cnt += 1
print(cnt)
|
import sys
input = sys.stdin.readline
N = int(input())
# 素因数分解 (dictバージョン)
# 考え方:1~√nまで実際に割れるか試せば良いが、割れた場合は割れる限りその数で割り続ける
# 計算量:O(√n)
def prime_factorize(n, primes):
i = 2
while i * i <= n:
if n % i != 0:
i += 1
continue
exp = 0
while n % i == 0:
exp += 1
n = n // i
if i not in primes:
primes[i] = exp
else:
primes[i] += exp
i += 1
# 最後に残った数は1か素数にしかならない
if n != 1:
if n not in primes:
primes[n] = 1
else:
primes[n] += 1
return primes
primes = {}
for k in range(1, N+1):
primes = prime_factorize(k, primes)
count = 1
for p in primes:
count *= (primes[p] + 1)
ans = count % (10**9 + 7)
print(ans) |
s = list(input())
t = list(input())
s.sort()
t.sort(reverse=True)
S=''.join(s)
T=''.join(t)
ans_ = [S,T]
ans_.sort()
ans='Yes'
if ans_[0] == T:
ans='No'
print(ans) |
from math import sqrt
def sd(nums):
n = len(nums)
ave = sum(nums)/n
return abs(sqrt(sum([(s - ave)**2 for s in nums])/n))
def main():
while True:
n = input()
if n == '0':
break
nums = [int(x) for x in input().split()]
print("{:f}".format(sd(nums)))
if __name__ == '__main__':
main()
|
def gcd(a,b):
while a>0 and b>0:
if a>b:a%=b
else: b%=a
return max(a,b)
a,b =(int(i) for i in input().split())
print((a*b)//gcd(a,b)) |
import math
r = float(input())
a = math.pi * r * r
l = 2 * math.pi * r
print(f'{a} {l}')
|
N = int(input())
import math
n_sqrt = math.floor(math.sqrt(N))
print(n_sqrt ** 2) |
n = int(input())
if n == 1: print("Hello World")
else:
answer = 0
for x in range(2):
answer += int(input())
print(answer) |
from collections import deque
class peke:
def __init__(self,Start,End,S):
self.start=Start
self.end=End
self.S=S
S1=deque()
S2=deque()
total=0
A=input()
for n in range(len(A)):
if A[n]=='\\':
S1.append(n)
elif A[n]=='/' and S1:
j=S1.pop()
now=n-j
total=total+now
while S2:
if S2[-1].start>j and S2[-1].end<n:
now=now+S2[-1].S
S2.pop()
else:
break
S2.append(peke(j,n,now))
print(total)
print(len(S2),end ="")
while S2:
print(" ",end="")
print(S2[0].S,end="")
S2.popleft()
print()
|
#78
data=list(input().split())
if data[0]<data[1]:
print('<')
elif data[0]>data[1]:
print('>')
else:
print('=') |
def main():
n,a = (int(input()) for _ in range(2))
print('Yes' if n%500 <= a else 'No')
if __name__ == '__main__':
main() |
n=int(input())
m=list(str(n))
res=0
for i in m:res+=int(i)
print("Yes" if n % res == 0 else "No")
|
N = int(input())
個数 = 0
for N in range(N+1):
個数 += N
print(個数) |
s = input()
ans = s
if s[-1] == "s":
ans += "e"
print(ans+"s") |
s = str(input())
w = int(input())
word = "".join(s[h] for h in range(0,len(s),w))
print(word) |
n=int(input())
ans=0
for i in range(n):
if (i+1)%3==0 and (i+1)%5==0:
continue
elif (i+1)%3==0:
continue
elif (i+1)%5==0:
continue
else:
ans+=i+1
print(ans) |
n=int(input())
list=list(map(int,input().split(" ")))
list.reverse()
for i in range(n-1):
print(str(list[i])+" ",end="")
print(str(list[n-1]))
|
N = input()
cnt = 0
for s in N:
if s == "2":
cnt += 1
print(cnt) |
N = int(input().rstrip())
A = []
mx1 = 0
mx2 = 0
for i in range(N):
A.append(int(input().rstrip()))
if A[i] > mx1:
mx1, mx2 = A[i], mx1
elif A[i] > mx2:
mx2 = A[i]
for j in range(N):
if A[j] == mx1:
print(mx2)
else:
print(mx1) |
A = input()
B = input()
ref = '123'
for i in ref:
if i != A and i != B:
print(i) |
import re
s=input()
count=0
if re.search(r'a',s):
count+=1
if re.search(r'b',s):
count+=1
if re.search(r'c',s):
count+=1
if count==3:
print('Yes')
else:
print('No') |
from collections import deque
def main():
s = input()
q = int(input())
d = deque(s)
is_reversed = False
for _ in range(q):
query = list(input().split())
if query[0] == "1":
if is_reversed:
is_reversed = False
else:
is_reversed = True
elif query[0] == "2":
if query[1] == "1":
if is_reversed:
d.append(query[2])
else:
d.appendleft(query[2])
elif query[1] == "2":
if is_reversed:
d.appendleft(query[2])
else:
d.append(query[2])
if is_reversed:
print(*(list(d)[::-1]), sep="")
else:
print(*list(d), sep="")
if __name__ == "__main__":
main()
|
N = int(input())
A = list(map(int, input().split()))
# number_to_prime[i]: i の最小の素因数, iが素数ならば0
number_to_prime = [0] * (10**6 + 1)
# preprocess
for i in range(2, 10**6+1):
if not number_to_prime[i]:
j = 1
while j*i <= 10**6:
number_to_prime[j*i] = i
j += 1
def is_pair_copr(A):
import numpy as np
U = 1 << 20
div_p = np.arange(U)
for p in range(2, U):
if div_p[p] != p:
continue
div_p[p::p] = p
used = np.zeros(U, np.bool_)
for x in A:
while x > 1:
p = div_p[x]
while x % p == 0:
x //= p
if used[p]:
return False
used[p] = True
return True
def is_pairwise():
used_primes = set()
pairwise_flag = 1
for a in A:
curr_primes = set()
while a > 1:
prime = number_to_prime[a]
curr_primes.add(prime)
a //= prime
if used_primes & curr_primes:
pairwise_flag = 0
break
else:
used_primes = used_primes | curr_primes
return pairwise_flag
def is_setwise(*A):
import math
from functools import reduce
return reduce(math.gcd, A) == 1
if is_pair_copr(A):
print("pairwise coprime")
elif is_setwise(*A):
print("setwise coprime")
else:
print("not coprime") |
s=input()
t=input()
n=len(s)
d={}
for i in range(n):
ss=s[i]
tt=t[i]
if ss in d and (ss,tt) not in d.items():
print("No")
exit()
if tt in d.values() and (ss,tt) not in d.items():
print("No")
exit()
if ss not in d:
d[ss]=tt
print("Yes") |
from math import gcd
N = int(input())
A = list(map(int,input().split()))
def lcm(a,b):
return a*b//gcd(a,b)
lcm_a = 1
for i in A:
lcm_a = lcm(lcm_a,i)
ans = 0
for i in A:
ans += lcm_a//i
print(ans%(10**9+7))
|
# encoding:utf-8
input = map(int, raw_input().split())
height = input[0]
width = input[1]
area = height * width
circumference = (height + width) * 2
print(area),
print(circumference) |
n = int(input())
n = str(n)
if n[0] == n[1] == n[2] or n[1] == n[2] == n[3]:
print('Yes')
else:
print('No') |
import math
r = float(input())
print("%.7f %.7f" % (math.pi*r*r,2.0*r*math.pi)) |
s = input()
s_list = list(s)
if s_list[-1] == 's':
output = s + 'es'
else:
output = s + 's'
print(output) |
# 数値で入力ではなく, 文字列で入力しlist関数を使う
k = int(input())
s = input()
n = len(s)
list_s = list(s)
# リストのスライス機能を使用
if n > k:
tmp = list_s[0:k]
print(''.join(tmp) + '...')
else: print(''.join(list_s)) |
x = int(input(""))
if -40 <= x <= 29:
print("No")
elif 30 <= x <= 40:
print("Yes") |
n = int(input())
d = {}
for i in range(n):
order,string = input().split()
if order == "insert":
d[string] = 1
else:
try:
if d[string] :
print("yes")
except:
print("no")
|
n = int(input())
s = [input() for _ in range(2)]
mod = 10 ** 9 + 7
def is_vertical(i):
return s[0][i] == s[1][i]
i = 0
if is_vertical(i):
ans = 3
prev_is_vertical = True
i += 1
else:
ans = 3 * 2
prev_is_vertical = False
i += 2
while i < n:
if is_vertical(i):
if prev_is_vertical:
ans *= 2
else:
ans *= 1
prev_is_vertical = True
i += 1
else:
if prev_is_vertical:
ans *= 2
else:
ans *= 3
prev_is_vertical = False
i += 2
ans %= mod
print(ans)
|
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
tmp = []
if n % i == 0:
tmp.append(i)
tmp.append(n//i)
if(len(tmp)>0):
divisors.append(sum(tmp))
return divisors
def main5():
n = int(input())
k = make_divisors(n)
print(min(k)-2)
if __name__ == '__main__':
main5()
|
x = int(input())
def prime_check(n):
f = 3
while f * f <= n:
if n % f == 0:
return False
else:
f += 2
else:
return True
if x != 2:
if x % 2 == 0:
x += 1
while 1:
if prime_check(x) == True:
print(x)
break
else:
x += 2
else:
print(2) |
n = input()
cards = []
for i in range(n):
cards.append(raw_input().split())
marks = ['S', 'H', 'C', 'D']
for i in marks:
for j in range(1, 14):
if [i, str(j)] not in cards:
print i, j |
a = input()
if len(a) == 2:
print(a)
elif len(a) == 3:
print(a[::-1]) |
a = input()
b = input()
if len(a)<len(b):
print("LESS")
elif len(a)==len(b):
print("LESS" if a<b else "EQUAL" if a==b else "GREATER")
else:
print("GREATER") |
N=int(input())
A=[int(input()) for _ in range(N)]
B=sorted(A)
for n in range(N):
if A[n]!=B[-1]:
print(B[-1])
else:
print(B[-2]) |
def inp(): # n=1
return int(input())
def inpm(): # x=1,y=2
return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
return list(input().split())
def inplm(n): # x=[] 複数行
return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
if k == 0:x.sort(key=lambda y:y[1,n])
else:x.sort(reversed=True, key=lambda y:y[1,n])
def main():
s = input()
NG = 1
NP = 0
did = ["g"]
point = 0
for i in range(1,len(s)):
if s[i] == "g":
if NP + 1 <= NG:
did.append("p")
NP += 1
point += 1
else:
did.append("g")
NG += 1
else:
if NP + 1 <= NG:
did.append("p")
NP += 1
else:
did.append("g")
NG += 1
point -= 1
print(point)
if __name__ == "__main__":
main() |
import math
def insertion_sort(alist, step):
size = len(alist)
count = 0
for i in range(step, size):
v = alist[i]
j = i - step
while j >= 0 and alist[j] > v:
alist[j+step] = alist[j]
j -= step
count += 1
alist[j+step] = v
return (count, alist)
def shell_sort(alist, steps):
total_count = 0
sorted_list = alist
for step in steps:
(count, sorted_list) = insertion_sort(sorted_list, step)
total_count += count
return (total_count, sorted_list)
def run():
n = int(input())
nums = []
for i in range(n):
nums.append(int(input()))
steps = create_steps(n)
(cnt, nums) = shell_sort(nums, steps)
print(len(steps))
print(" ".join([str(s) for s in steps]))
print(cnt)
for n in nums:
print(n)
def create_steps(n):
steps = []
k = 1
while True:
steps = [k] + steps
k = 2 * k + int(math.sqrt(k)) + 1
if k >= n:
break
return steps
if __name__ == '__main__':
run()
|
a, b = map(int, input().split())
if a >= b + 2:
print(a + a - 1)
elif a == b + 1 or b == a + 1 or a == b:
print(a + b)
elif a + 2 <= b:
print(b + b - 1) |
n = int(input())
def gcd(a,b):
while b != 0:
a, b = b, a % b
return a
# 最小公倍数
def lcm(a,b):
return a // gcd(a,b) * b
ans = 1
for i in range(n):
t = int(input())
ans = lcm(ans,t)
print(ans)
|
N = list(input())
Nr = N[::-1]
print("Yes") if N == Nr else print("No")
|
import math
x1, y1, x2, y2 = [float(i) for i in input().split()]
bottom = x2 - x1
height = y2 - y1
print(math.sqrt(bottom**2 + height**2)) |
from collections import Counter
lst = []
for i in range(3):
a, b = map(int, input().split())
lst.append(a)
lst.append(b)
if sorted(list(Counter(lst).values())) == [1, 1, 2, 2]:
print('YES')
else:
print('NO') |
#!/usr/bin/env python3
import sys
def solve(A: int, B: int, C: int):
ans = 0
s = set()
while True:
if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
print(ans)
break
newA = B / 2 + C / 2
newB = A / 2 + C / 2
newC = A / 2 + B / 2
A = newA
B = newB
C = newC
ans += 1
n = ','.join(map(str, [A, B, C]))
if n in s:
print("-1")
break
s.add(n)
return
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
C = int(next(tokens)) # type: int
solve(A, B, C)
if __name__ == '__main__':
main()
|
x = int(input())
if x <= 6:
print(1)
else:
ans = (x//11)*2
if x%11 == 0:
print(int((x/11)*2))
elif (x//11)*11 +6 >= x:
print(ans+1)
else:
print(ans+2) |
# Python3 implementation of the approach
# Function to find the number of divisors
# of all numbers in the range [1,n]
def findDivisors(n):
# List to store the count
# of divisors
div = [0 for i in range(n + 1)]
# For every number from 1 to n
for i in range(1, n + 1):
# Increase divisors count for
# every number divisible by i
for j in range(1, n + 1):
if j * i <= n:
div[i * j] += 1
else:
break
# Print the divisors
return div
# Driver Code
if __name__ == "__main__":
n = int(input())
print(sum(findDivisors(n-1)))
# This code is contributed by
# Vivek Kumar Singh
|
minute = int(input())
print('{}:{}:{}'.format(minute // 3600, (minute % 3600) // 60, (minute % 3600) % 60))
|
a, b, c = map(int, (input().split()))
s="No"
if a <= c and c <= b:
s="Yes"
print(s) |
antennas = [int(input()) for _ in range(5)]
distance = int(input())
antennas_distance = abs(sorted(antennas)[len(antennas)-1] - sorted(antennas)[0])
print(':(' if antennas_distance > distance else 'Yay!') |
#!/usr/bin/env python3
import sys
def input():
return sys.stdin.readline()[:-1]
def main():
X = int(input())
y = 100
ans = 0
while y < X:
ans += 1
y += y // 100
print(ans)
if __name__ == '__main__':
main()
|
s = input()
if len(s) % 2 == 1:
s = s[:-1]
else:
s = s[:-2]
while True:
if s[:len(s)//2] == s[len(s)//2:]:
print(len(s))
exit()
else:
s = s[:-2] |
# -*- coding: utf-8 -*-
def call(n):
print '',
for i in xrange(1, n+1):
if check(i):
print(i),
print
def check(i):
if i % 3 == 0:
return True
elif i % 10 == 3:
return True
elif i / 10 > 0:
x = i
x /= 10
while (x > 0):
if x % 10 == 3:
return True
else:
x /= 10
return False
n = int(raw_input())
call(n) |
#input an interget
k=int(input())
#input an string
str1=str(input())
#get the length of the string
x=int(len(str1))
#initialise y
y=0
#make a second string for the appending
str2="..."
#if statement about how the string will function
#if the string is the same length as k then print it
if x<=k:
print(str1)
#if not, delete the last character of the string
else:
while y<k:
print(str1[y],end=(""))
y+=1
print(str2)
|
s = sorted(str(input()))
t = sorted(str(input()), reverse = True)
print("Yes" if s < t else "No") |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.