Last active
April 3, 2024 12:01
-
-
Save nptit/1f9396aadb48d49f3f1497592e8b1638 to your computer and use it in GitHub Desktop.
Problems from https://snakify.org site https://git.io/snakify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = int(input()) | |
b = int(input()) | |
c = int(input()) | |
if a <= b and a <= c: | |
print(a) | |
elif b <= a and b <= c: | |
print(b) | |
else: | |
print(c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = int(input()) | |
b = int(input()) | |
c = int(input()) | |
if a == b == c: | |
print(3) | |
elif a == b or b == c or a == c: | |
print(2) | |
else: | |
print(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x1 = int(input()) | |
y1 = int(input()) | |
x2 = int(input()) | |
y2 = int(input()) | |
if x1 == x2 or y1 == y2: | |
print('YES') | |
else: | |
print('NO') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x1 = int(input()) | |
y1 = int(input()) | |
x2 = int(input()) | |
y2 = int(input()) | |
if x1 - x2 < 2 and y1 - y2 < 2 and x1 - x2 > -2 and y1 - y2 > -2 : | |
print('YES') | |
else: | |
print('NO') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x1 = int(input()) | |
y1 = int(input()) | |
x2 = int(input()) | |
y2 = int(input()) | |
if x1 - x2 == y1 - y2 or x1 - x2 == y2 - y1: | |
print('YES') | |
else: | |
print('NO') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x1 = int(input()) | |
y1 = int(input()) | |
x2 = int(input()) | |
y2 = int(input()) | |
if x1 == x2 or y1 == y2 or x1 - x2 == y1 - y2 or x1 - x2 == y2 - y1: | |
print('YES') | |
else: | |
print('NO') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
m = int(input()) | |
k = int(input()) | |
if k <= n * m and (k % n == 0 or k % m == 0): | |
print('YES') | |
else: | |
print('NO') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = int(input()) | |
M = int(input()) | |
x = int(input()) | |
y = int(input()) | |
if M < N: | |
if M - x < x: | |
x = M - x | |
if N - y < y: | |
y = N - y | |
else: | |
if N - x < x: | |
x = N - x | |
if M - y < y: | |
y = M - y | |
if x < y: | |
print(x) | |
else: | |
print(y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x1 = int(input()) | |
y1 = int(input()) | |
x2 = int(input()) | |
y2 = int(input()) | |
if abs(x1 - x2) == 2 and abs(y1 - y2) == 1 or abs(x1 - x2) == 1 and abs(y1 - y2) == 2: | |
print('YES') | |
else: | |
print('NO') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v = int(input()) | |
t = int(input()) | |
print(v * t % 109) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = float(input()) | |
print(x - int(x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = float(input()) | |
print(int(x * 10) % 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
sb = n // 2 | |
lb = n - sb - 1 | |
t = n * 45 + sb * 5 + lb * 15 | |
print(t // 60 + 9, t % 60) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import ceil | |
n = int(input()) | |
m = int(input()) | |
print(ceil(m / n)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = int(input()) | |
b = int(input()) | |
n = int(input()) | |
print((a * 100 + b ) * n // 100, n * b % 100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 = int(input()) | |
m1 = int(input()) | |
s1 = int(input()) | |
h2 = int(input()) | |
m2 = int(input()) | |
s2 = int(input()) | |
print(h2*60*60 + m2*60 + s2 - (h1*60*60 + m1*60 + s1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import ceil | |
h = int(input()) | |
a = int(input()) | |
b = int(input()) | |
print(ceil((h-a)/(a-b))+1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
print(n//10%10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
print(n%10 + n//10%10 + n//100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt | |
a = int(input()) | |
b = int(input()) | |
print(sqrt(a**2+b**2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = float(input()) | |
if x*10%10 == 5: | |
print(round(x+0.1)) | |
else: | |
print(round(x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
H = int(input()) | |
M = int(input()) | |
S = int(input()) | |
print(360/12*H + 360/12/60*M + 360/12/60/60*S) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alfa = float(input()) | |
sec = alfa/360*12*60*60 | |
hours = sec//3600 | |
speed = 360/60/60 # minit arrow per second | |
print((sec-hours*3600)*speed) | |
# solution from developers | |
# alpha = float(input()) | |
# print(alpha % 30 * 12) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alfa = float(input()) | |
S = alfa / 360 * 12 * 60 * 60 | |
H = S // 3600 | |
M = S % 3600 // 60 | |
print(int(H), int(M), int(S%60)) | |
# solution from developers | |
# angle = float(input()) | |
# print(int(angle // 30), int(angle % 30 * 2), int(angle % 0.5 * 120)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
P = int(input()) | |
X = int(input()) | |
Y = int(input()) | |
Z = X * 100 + Y | |
R = Z + Z / 100 * P | |
print(int(R // 100) , int(R % 100)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A = int(input()) | |
B = int(input()) | |
for i in range(A, B + 1): | |
print(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A = int(input()) | |
B = int(input()) | |
if A < B: | |
for i in range(A, B + 1): | |
print(i, end=' ') | |
else: | |
for i in range(A, B - 1, -1): | |
print(i, end=' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A = int(input()) | |
B = int(input()) | |
for i in range(A + A % 2 - 1, B - 1, -2): | |
print(i, end=' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
S = 0 | |
for i in range(0, 10): | |
n = int(input()) | |
S += n | |
print(S) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = int(input()) | |
S = 0 | |
for i in range(N): | |
S += int(input()) | |
print(S) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
S = 0 | |
for i in range(1, n +1): | |
S += i**3 | |
print(S) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
f = 1 | |
for i in range(1, n +1): | |
f *= i | |
print(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
f = 1 | |
S = 0 | |
for i in range(1, n +1): | |
f *= i | |
S += f | |
print(S) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
counter = 0 | |
for i in range(int(input())): | |
if int(input()) == 0: | |
counter += 1 | |
print(counter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
for i in range(1, n + 1): | |
for j in range(1, i + 1): | |
print(j, end='') | |
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
s = (n + 1) * n / 2 | |
for i in range(n-1): | |
s -= int(input()) | |
print(int(s)) | |
# solution from developers | |
# n = int(input()) | |
# sum = 0 | |
# for i in range(1, n + 1): | |
# sum += i | |
# # можно доказать формулу: | |
# # sum == n * (n + 1) // 2 | |
# # но мы посчитаем это значение циклом | |
# for i in range(n - 1): | |
# sum -= int(input()) | |
# print(sum) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = input() | |
print(s[2]) | |
print(s[-2]) | |
print(s[:5]) | |
print(s[:-2]) | |
print(s[::2]) | |
print(s[1::2]) | |
print(s[::-1]) | |
print(s[::-2]) | |
print(len(s)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(input().count(' ') + 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = input() | |
l = int(len(s)/2) | |
print(s[-l:]+s[:-l]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = input() | |
n = s.find(' ') | |
print(s[n:], s[:n]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = input() | |
с = s.count('f') | |
if с == 1: | |
print(s.find('f')) | |
if с > 1: | |
print(s.find('f'),s.rfind('f')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = input() | |
с = s.count('f') | |
if с == 0: | |
print(-2) | |
if с == 1: | |
print(-1) | |
if с > 1: | |
print(s.find('f', s.find('f') + 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = input() | |
print(s[:s.find('h')] + s[s.rfind('h')+1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = input() | |
i = s[s.find('h'):(s.rfind('h'))] | |
print(s[:s.find('h') + 1] + i[::-1] + s[s.rfind('h')+1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(input().replace('1', 'one')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(input().replace('@', '')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = input() | |
i = s[s.find('h')+1:(s.rfind('h'))] | |
print(s[:s.find('h')+1] + i.replace('h', 'H') + s[s.rfind('h'):]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = input() | |
result = '' | |
for i in range(1,len(s),3): | |
result += s[i:i+2] | |
print(result) | |
#solution from developers | |
#s = input() | |
#t = '' | |
#for i in range(len(s)): | |
# if i % 3 != 0: | |
# t = t + s[i] | |
#print(t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = int(input()) | |
i = 1 | |
while i**2 <= N: | |
print(i**2) | |
i += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
i = 2 | |
while n % i != 0: | |
i += 1 | |
print(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = int(input()) | |
i, p = 0, 1 | |
while p * 2 <= N: | |
i, p = i + 1, p * 2 | |
print(i, p) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = int(input()) | |
y = int(input()) | |
i = 1 | |
while x < y: | |
x *= 1.1 | |
i += 1 | |
print(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = int(input()) | |
p = int(input()) | |
y = int(input()) | |
i = 0 | |
while x < y: | |
x += x * p / 100 # alternative variant: x *= 1 + p / 100 | |
x = int(x * 100) / 100 | |
i += 1 | |
print(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
i = 0 | |
while int(input()) != 0: | |
i += 1 | |
print(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
S = 0 | |
a = int(input()) | |
while a != 0: | |
S += a | |
a = int(input()) | |
print(S) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
S = 0 | |
n = 0 | |
a = int(input()) | |
while a != 0: | |
S += a | |
n += 1 | |
a = int(input()) | |
print(S/n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
max = 0 | |
a = int(input()) | |
while a != 0: | |
if a > max: | |
max = a | |
a = int(input()) | |
print(max) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
max = 0 | |
i = 0 | |
max_i = 0 | |
a = int(input()) | |
while a != 0: | |
if a > max: | |
max = a | |
max_i = i | |
a = int(input()) | |
i += 1 | |
print(max_i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = 0 | |
a = int(input()) | |
while a != 0: | |
if a % 2 == 0: | |
N += 1 | |
a = int(input()) | |
print(N) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c = 0 | |
b = int(input()) | |
a = b | |
while b != 0: | |
if b > a: | |
c += 1 | |
a = b | |
b = int(input()) | |
print(c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
max_2 = -1 | |
a = int(input()) | |
max = 0 | |
while a != 0: | |
if a > max: | |
max_2 = max | |
max = a | |
elif a > max_2: | |
max_2 = a | |
a = int(input()) | |
print(max_2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
max = 0 | |
с = 1 | |
a = int(input()) | |
while a != 0: | |
if a > max: | |
max = a | |
с = 1 | |
elif a == max: | |
с += 1 | |
a = int(input()) | |
print(с) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
fi1 = 0 | |
fi2 = 1 | |
if n < 1: | |
print(0) | |
elif n == 1: | |
print(1) | |
else: | |
i = 2 | |
while i <= n: | |
fi2, fi1 = fi1 + fi2, fi2 | |
i += 1 | |
print(fi2) | |
# developers solution | |
# n = int(input()) | |
# if n == 0: | |
# print(0) | |
# else: | |
# a, b = 0, 1 | |
# for i in range(2, n + 1): | |
# a, b = b, a + b | |
# print(b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A = int(input()) | |
fi1 = 0 | |
fi2 = 1 | |
if A == 1: | |
print(1) | |
else: | |
i = 1 | |
while A > fi2: | |
fi2, fi1 = fi1 + fi2, fi2 | |
i += 1 | |
if A == fi2: | |
print(i) | |
else: | |
print(-1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chunk = 1 | |
max_chunk = 1 | |
a = int(input()) | |
b = a | |
while b != 0: | |
b, a = int(input()), b | |
if b == a: | |
chunk += 1 | |
else: | |
if chunk > max_chunk: | |
max_chunk = chunk | |
chunk = 1 | |
print(max_chunk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt | |
partial_sum = 0 | |
partial_sum_squares = 0 | |
x_i = int(input()) | |
n = 0 | |
while x_i != 0: | |
n += 1 | |
partial_sum += x_i | |
partial_sum_squares += x_i ** 2 | |
x_i = int(input()) | |
print(sqrt((partial_sum_squares - partial_sum ** 2 / n) / (n - 1))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(' '.join(input().split()[::2])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for elem in [int(s) for s in input().split()]: | |
if elem % 2 == 0: | |
print(elem, end=' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [int(s) for s in input().split()] | |
for i in range(1, len(a)): | |
if a[i] > a[i-1]: | |
print(a[i], end=' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [int(s) for s in input().split()] | |
for i in range(1, len(a)): | |
if a[i] * a[i-1] > 0: | |
print(a[i-1], a[i], end=' ') | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [int(s) for s in input().split()] | |
с = 0 | |
for i in range(1, len(a)-1): | |
if a[i - 1] < a[i] > a[i + 1]: | |
с += 1 | |
print(с) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [int(s) for s in input().split()] | |
maximum = a[0] | |
max_i = 0 | |
for i in range(1, len(a)): | |
if a[i] > maximum: | |
max_i = i | |
maximum = a[i] | |
print(maximum, max_i, end=' ') | |
# developers solution | |
# index_of_max = 0 | |
# a = [int(i) for i in input().split()] | |
# for i in range(1, len(a)): | |
# if a[i] > a[index_of_max]: | |
# index_of_max = i | |
# print(a[index_of_max], index_of_max) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
heights = [int(i) for i in input().split()] | |
peters_height = int(input()) | |
pos = len(heights) + 1 | |
for i in range(len(heights)): | |
if peters_height > heights[i]: | |
pos = i + 1 | |
break | |
print(pos) | |
# developers solution | |
# a = [int(i) for i in input().split()] | |
# x = int(input()) | |
# pos = 0 | |
# while pos < len(a) and a[pos] >= x: | |
# pos += 1 | |
# print(pos + 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [int(i) for i in input().split()] | |
num_of_diff = 1 | |
for i in range(1,len(a)): | |
if a[i] > a[i-1]: | |
num_of_diff += 1 | |
print(num_of_diff) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [int(i) for i in input().split()] | |
for i in range(0,len(a)-1,2): | |
a[i], a[i+1] = a[i+1], a[i] | |
print(' '.join([str(i) for i in a])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
index_of_max = 0 | |
index_of_min = 0 | |
a = [int(i) for i in input().split()] | |
for i in range(1, len(a)): | |
if a[i] > a[index_of_max]: | |
index_of_max = i | |
if a[i] < a[index_of_min]: | |
index_of_min = i | |
a[index_of_max], a[index_of_min] = a[index_of_min], a[index_of_max] | |
print(' '.join([str(i) for i in a])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [int(i) for i in input().split()] | |
k = int(input()) | |
a = a[:k]+a[k+1:] | |
print(' '.join([str(i) for i in a])) | |
# developers solution | |
# a = [int(s) for s in input().split()] | |
# k = int(input()) | |
# for i in range(k + 1, len(a)): | |
# a[i - 1] = a[i] | |
# a.pop() | |
# print(' '.join([str(i) for i in a])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [int(i) for i in input().split()] | |
k, C = [int(i) for i in input().split()] | |
a = a[:k] + [C] + a[k:] | |
print(' '.join([str(i) for i in a])) | |
# developers solution | |
# a = [int(s) for s in input().split()] | |
# обратите внимание на множественное присваивание: | |
# справа от "=" стоит список из двух элементов, | |
# а слева -- две переменные, | |
# поэтому так делать можно | |
# k, C = [int(s) for s in input().split()] | |
# a.append(0) | |
# for i in range(len(a) - 1, k, -1): | |
# a[i] = a[i - 1] | |
# a[k] = C | |
# print(' '.join([str(i) for i in a])) | |
# community solution | |
# a = [int(s) for s in input().split()] | |
# k, c = [int(s) for s in input().split()] | |
# a.insert(k, c) | |
# print(' '.join([str(i) for i in a])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [int(s) for s in input().split()] | |
counter = 0 | |
for i in range(len(a)): | |
for j in range(i + 1, len(a)): | |
if a[i] == a[j]: | |
counter += 1 | |
print(counter) | |
# another worst solutions | |
# a = [int(i) for i in input().split()] | |
# num_equal_pairs = 0 | |
# for i in range(len(a)): | |
# for j in range(len(a)): | |
# if i != j and a[i] == a[j]: | |
# num_equal_pairs += 1 | |
# print(num_equal_pairs // 2) | |
# a = [int(i) for i in input().split()] | |
# num_equal_pairs = 0 | |
# for i in range(len(a)): | |
# for j in range(len(a)): | |
# if a[i] == a[j]: | |
# num_equal_pairs += 1 | |
# print((num_equal_pairs - len(a)) // 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [int(s) for s in input().split()] | |
uniqs = [] | |
for elem in a: | |
if a.count(elem) == 1: | |
uniqs.append(elem) | |
print(' '.join([str(i) for i in uniqs])) | |
# developers solution | |
# a = [int(s) for s in input().split()] | |
# for i in range(len(a)): | |
# for j in range(len(a)): | |
# if i != j and a[i] == a[j]: | |
# break | |
# else: | |
# print(a[i], end=' ') | |
# community solution | |
lst = [int(i) for i in input().split()] | |
for element in lst: | |
if lst.count(element) == 1: | |
print(element, end = ' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N, K = [int(i) for i in input().split()] | |
kegels = ['I'] * N | |
for j in range(K): | |
l, r = [int(i) for i in input().split()] | |
kegels[l-1:r] = ['.'] * (r-l+1) | |
print(''.join([str(i) for i in kegels])) | |
# developers solution | |
# n, k = [int(s) for s in input().split()] | |
# bahn = ['I'] * n | |
# for i in range(k): | |
# left, right = [int(s) for s in input().split()] | |
# for j in range(left - 1, right): | |
# bahn[j] = '.' | |
# print(''.join(bahn)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = 8 | |
result = 'NO' | |
x = [0] * N | |
y = [0] * N | |
for i in range(N): | |
x[i], y[i] = [int(j) for j in input().split()] | |
for i in range (N): | |
for j in range(i+1,N): | |
if x[i] == x[j] or y[i] == y[j] or abs(x[i] - x[j]) == abs(y[i] - y[j]): | |
result = 'YES' | |
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def distance(x1, y1, x2, y2): | |
from math import sqrt | |
return sqrt((x1-x2)**2+(y1-y2)**2) | |
x1 = float(input()) | |
y1 = float(input()) | |
x2 = float(input()) | |
y2 = float(input()) | |
print(distance(x1, y1, x2, y2)) | |
# community solution | |
# def distance (x1, y1, x2, y2): | |
# return ((x2-x1)**2+(y2-y1)**2)**0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def power(a, n): | |
res = 1 | |
for i in range(abs(n)): | |
res *= a | |
if n >= 0: | |
return res | |
else: | |
return 1 / res | |
print(power(float(input()), int(input()))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def capitalize(word): | |
return chr(ord(word[0]) + ord('A') - ord('a')) + word[1:] | |
s = [str(s) for s in input().split()] | |
for i in range(len(s)): | |
s[i] = capitalize(s[i]) | |
print(' '.join([str(i) for i in s])) | |
# community solution after def capitalize | |
# print(' '.join([capitalize(str(s)) for s in input().split()])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def power(a, n): | |
if n == 0: | |
return 1 | |
else: | |
return a * power(a, n - 1) | |
print(power(float(input()), int(input()))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverse(): | |
a = int(input()) | |
if a != 0: | |
reverse() | |
print(a) | |
reverse() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fib(n): | |
if n == 1 or n == 2: | |
return 1 | |
else: | |
return fib(n - 1) + fib(n - 2) | |
print(fib(int(input()))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n, m = [int(j) for j in input().split()] | |
a = [[int(j) for j in input().split()] for i in range(n)] | |
max_row = 0 | |
max_col = 0 | |
max = a[max_row][max_col] | |
for i in range(n): | |
for j in range(m): | |
if max < a[i][j]: | |
max = a[i][j] | |
max_row = i | |
max_col = j | |
print(max_row, max_col) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def chessboard(n, m): | |
if (n + m) % 2 == 0: | |
return '.' | |
else: | |
return '*' | |
n, m = [int(j) for j in input().split()] | |
a = [[chessboard(i, j) for j in range(m)] for i in range(n)] | |
for row in a: | |
print(' '.join(row)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
k = n // 2 | |
a = [['.'] * n for i in range(n)] | |
for i in range(n): | |
a[k][i] = '*' | |
a[i][k] = '*' | |
a[i][i] = '*' | |
a[n-i-1][i] = '*' | |
for row in a: | |
print(' '.join(row)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
a = [[abs(i - j) for j in range(n)] for i in range(n)] | |
for row in a: | |
print(' '.join([str(i) for i in row])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
a = [0] * n | |
a = [[0] * (n - i - 1) + [1] + [2] * i for i in range(n)] | |
for row in a: | |
print(' '.join([str(i) for i in row])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def swap_columns(a, i, j): | |
for row in a: | |
row[i], row[j] = row[j], row[i] | |
return a | |
n, m = [int(k) for k in input().split()] | |
a = [[int(j) for j in input().split()] for i in range(n)] | |
i, j = [int(k) for k in input().split()] | |
for row in swap_columns(a, i, j): | |
print(' '.join([str(i) for i in row])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(len(set(input().split()))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(len(set(input().split()) & set(input().split()))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(*sorted(set(input().split()) & set(input().split()), key=int)) | |
# my bad solution | |
# a = list(set(input().split()) & set(input().split())) | |
# a = list(map(int, a)) | |
# a.sort() | |
# a = list(map(str, a)) | |
# print(' '.join(a)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = input().split() | |
for i in range(len(a)): | |
if a[i] in a[:i]: | |
print('YES') | |
else: | |
print('NO') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n, m = [int(j) for j in input().split()] | |
A = set() | |
B = set() | |
for i in range(n): | |
A.add(int(input())) | |
for i in range(m): | |
B.add(int(input())) | |
C = A & B | |
D = A - B | |
Е = B - A | |
print(len(C)) | |
print(*sorted(C), key=int) | |
print(len(D)) | |
print(*sorted(D), key=int) | |
print(len(Е)) | |
print(*sorted(Е), key=int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
a = [[j for j in input().split()] for i in range(n)] | |
print(len(set(sum(a, [])))) | |
# developers solution | |
# words = set() | |
# for _ in range(int(input())): | |
# words.update(input().split()) | |
# print(len(words)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
a = [i for i in range(1,n+1)] | |
s = set(a) | |
while True: | |
guess = input() | |
if guess == 'HELP': | |
break | |
answer = input() | |
if answer == 'NO': | |
s -= set(guess.split()) | |
elif answer == 'YES': | |
s &= set(guess.split()) | |
print(' '.join([str(i) for i in list(s)])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
all_nums = set(range(1, n + 1)) | |
possible_nums = all_nums | |
while True: | |
guess = input() | |
if guess == 'HELP': | |
break | |
guess = {int(x) for x in guess.split()} | |
if len(possible_nums & guess) > len(possible_nums) / 2: | |
print('YES') | |
possible_nums &= guess | |
else: | |
print('NO') | |
possible_nums &= all_nums - guess | |
print(' '.join([str(x) for x in sorted(possible_nums)])) | |
# my wrong solution | |
# n = int(input()) | |
# a = [i for i in range(1,n+1)] | |
# s = set(a) | |
# while True: | |
# guess = input() | |
# if guess == 'HELP': | |
# break | |
# if 2 * len(set(guess.split())) > len(s): | |
# s &= set(guess.split()) | |
# print('YES') | |
# else: | |
# s -= set(guess.split()) | |
# print('NO') | |
# print(' '.join([str(i) for i in list(s)])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) # количество учеников | |
lang_nums = [0] * n # количество языков для каждого ученика | |
langs = [] # наименования языков, для каждого из учеников | |
for i in range(n): | |
lang_nums[i] = int(input()) | |
l = set() | |
for j in range(lang_nums[i]): | |
l.add(input()) | |
langs.append(l) | |
uni = set.union(*langs) | |
inter = set.intersection(*langs) | |
print(len(inter), '\n'.join(sorted(inter)), len(uni), '\n'.join(sorted(uni)), sep='\n') | |
# developers solution | |
# students = [{input() for j in range(int(input()))} for i in range(int(input()))] | |
# known_by_everyone, known_by_someone = set.intersection(*students), set.union(*students) | |
# print(len(known_by_everyone), *sorted(known_by_everyone), sep='\n') | |
# print(len(known_by_someone), *sorted(known_by_someone), sep='\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N, K = [int(k) for k in input().split()] | |
strikes = [[int(k) for k in input().split()] for i in range(K)] | |
strike_dates = set() | |
for i in range(K): | |
for j in range(strikes[i][0], N+1, strikes[i][1]): | |
if j % 7 != 0 and j % 7 != 6: | |
strike_dates.add(j) | |
print(len(strike_dates)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# developers solution | |
counter = {} | |
for word in input().split(): | |
counter[word] = counter.get(word, 0) + 1 | |
print(counter[word] - 1, end=' ') | |
# my solution without dicts | |
words = input().split() | |
for i in range(len(words)): | |
print(words[:i].count(words[i]), end=' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nice developers solution | |
n = int(input()) | |
d = {} | |
for i in range(n): | |
first, second = input().split() | |
d[first] = second | |
d[second] = first | |
print(d[input()]) | |
# my solution | |
# n = int(input()) | |
# synonyms = {} | |
# for i in range(n): | |
# pair = input().split() | |
# synonyms[pair[0]] = pair[1] | |
# word = input() | |
# for key in synonyms: | |
# if key == word: | |
# print(synonyms[key]) | |
# if synonyms[key] == word: | |
# print(key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nice developers solution | |
num_votes = {} | |
for _ in range(int(input())): | |
candidate, votes = input().split() | |
num_votes[candidate] = num_votes.get(candidate, 0) + int(votes) | |
for candidate, votes in sorted(num_votes.items()): | |
print(candidate, votes) | |
# my solution | |
# n = int(input()) | |
# d = {} | |
# for i in range(n): | |
# key, val = input().split() | |
# if key in d: | |
# d[key] += int(val) | |
# else: | |
# d[key] = int(val) | |
# for key, val in sorted(d.items()): | |
# print(key, val) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nice developers solution | |
counter = {} | |
for i in range(int(input())): | |
line = input().split() | |
for word in line: | |
counter[word] = counter.get(word, 0) + 1 | |
max_count = max(counter.values()) | |
most_frequent = [k for k, v in counter.items() if v == max_count] | |
print(min(most_frequent)) | |
# my solution | |
# max = 0 | |
# for _ in range(n): | |
# for word in input().split(): | |
# if word in d: | |
# d[word] += 1 | |
# else: | |
# d[word] = 1 | |
# if d[word] > max: | |
# max = d[word] | |
# for key, val in sorted(d.items()): | |
# if val == max: | |
# print(key) | |
# break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nice developers solution | |
ACTION_PERMISSION = { | |
'read': 'R', | |
'write': 'W', | |
'execute': 'X', | |
} | |
file_permissions = {} | |
for i in range(int(input())): | |
file, *permissions = input().split() | |
file_permissions[file] = set(permissions) | |
for i in range(int(input())): | |
action, file = input().split() | |
if ACTION_PERMISSION[action] in file_permissions[file]: | |
print('OK') | |
else: | |
print('Access denied') | |
# my solution | |
# permissions = {} | |
# n = int(input()) | |
# for _ in range(n): | |
# s = input().split() | |
# permissions[s[0]] = set(s[1:]) | |
# for _ in range(int(input())): | |
# perm, file = input().split() | |
# if perm == 'read': | |
# perm = 'R' | |
# if perm == 'write': | |
# perm = 'W' | |
# if perm == 'execute': | |
# perm = 'X' | |
# if perm in permissions[file]: | |
# print('OK') | |
# else: | |
# print('Access denied') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is my solution, taken from community | |
counter = {} | |
for i in range(int(input())): | |
line = input().split() | |
for word in line: | |
counter[word] = counter.get(word, 0) + 1 | |
for i in sorted(counter.items(), key=lambda x:(-x[1],x[0])): | |
print(i[0]) | |
# developers solution | |
# from collections import Counter | |
# words = [] | |
# for _ in range(int(input())): | |
# words.extend(input().split()) | |
# counter = Counter(words) | |
# pairs = [(-pair[1], pair[0]) for pair in counter.most_common()] | |
# words = [pair[1] for pair in sorted(pairs)] | |
# print('\n'.join(words)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
cities = {} | |
for _ in range(n): | |
line = input().split() | |
for city in line[1:]: | |
cities[city] = line[0] | |
for _ in range(int(input())): | |
print(cities[input()]) | |
# developers solution | |
# motherland = {} | |
# for i in range(int(input())): | |
# country, *cities = input().split() | |
# for city in cities: | |
# motherland[city] = country | |
# for i in range(int(input())): | |
# print(motherland[input()]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update on 06_10_seq_index_of_max.py
The output value always comes one value lesser
Alternative code