A. Water Station
import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input().rstrip('\n'))
ls = []
for i in range(0, 101, 5):
ls.append([abs(i-n), i])
ls.sort()
print(ls[0][1])
if __name__ == '__main__':
solve()
B. ABCDEFG
import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
d = {"A": 0, "B": 3, "C": 4, "D": 8, "E": 9, "F": 14, "G": 23}
p, q = list(map(str, input().rstrip('\n').split()))
print(abs(d[p] - d[q]))
if __name__ == '__main__':
solve()
C. Snuke the Cookie Picker
import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
h, w = list(map(int, input().rstrip('\n').split()))
s = [list(str(input().rstrip('\n'))) for _ in range(h)]
mxx, mxy = 0, 0
mnx, mny = pow(10, 30), pow(10, 30)
for i in range(h):
for j in range(w):
if s[i][j] == "#":
mxx = max(i, mxx)
mxy = max(j, mxy)
mnx = min(i, mnx)
mny = min(j, mny)
for i in range(mnx, mxx + 1):
for j in range(mny, mxy + 1):
if s[i][j] != "#":
print(i + 1, j + 1)
if __name__ == '__main__':
solve()
D. Sleep Log
import sys
import bisect
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input().rstrip('\n'))
a = list(map(int, input().rstrip('\n').split()))
total = 0
time = []
for i in range(n):
if i == 0:
time.append(total)
else:
if i % 2 == 0:
total += a[i] - a[i-1]
time.append(total)
q = int(input().rstrip('\n'))
for i in range(q):
l, r = list(map(int, input().rstrip('\n').split()))
l_pos = bisect.bisect_right(a, l)
r_pos = bisect.bisect_left(a, r)
ans = time[r_pos] - time[l_pos]
if r_pos % 2 == 0:
ans -= a[r_pos] - r
if l_pos % 2 == 0:
ans += a[l_pos] - l
print(ans)
if __name__ == '__main__':
solve()
E. Art Gallery on Graph
import sys
import collections
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n, m, k = list(map(int, input().rstrip('\n').split()))
tmd = collections.defaultdict(list)
for i in range(m):
tma, tmb = list(map(int, input().rstrip('\n').split()))
tmd[tma-1] += [tmb-1]
tmd[tmb-1] += [tma-1]
fq = collections.defaultdict(int)
ph = sorted([list(map(int, input().rstrip('\n').split())) for _ in range(k)], key=lambda x: x[1], reverse=True)
for p, h in ph:
if len(fq) == n:
break
ql = [[h, p-1]]
ql = collections.deque(ql)
fq[p-1] = h
while True:
if len(ql) != 0:
cost, tmp = ql.popleft()
for tmv in tmd[tmp]:
if fq[tmv] < cost - 1:
ql.append([cost - 1, tmv])
fq[tmv] = cost - 1
else:
break
print(len(fq))
print(*sorted([k + 1 for k in fq.keys()]))
if __name__ == '__main__':
solve()