A. Overall Winner
import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input().rstrip('\n'))
s = str(input().rstrip('\n'))
t = s.count("T")
a = s.count("A")
if t == a:
if s[-1] == "T":
print("A")
else:
print("T")
elif t > a:
print("T")
elif t < a:
print("A")
if __name__ == '__main__':
solve()
B. Fill the Gaps
import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input().rstrip('\n'))
a = list(map(int, input().rstrip('\n').split()))
ans = []
for i in range(1, n):
step = 1 if a[i] > a[i-1] else -1
for j in range(a[i-1], a[i], step):
ans += [j]
ans += [a[-1]]
print(*ans)
if __name__ == '__main__':
solve()
C. AtCoder Cards
import sys
import collections
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
s = str(input().rstrip('\n'))
t = str(input().rstrip('\n'))
d = collections.defaultdict(int)
sa = 0
ta = 0
for i in range(len(s)):
if s[i] != "@":
d[s[i]] += 1
else:
sa += 1
if t[i] != "@":
d[t[i]] -= 1
else:
ta += 1
for k, v in d.items():
if v < 0 and k in ["a", "t", "c", "o", "d", "e", "r"]:
sa += v
elif v > 0 and k in ["a", "t", "c", "o", "d", "e", "r"]:
ta -= v
elif v == 0:
continue
else:
print("No")
exit()
print("Yes" if sa >= 0 and ta >= 0 else "No")
if __name__ == '__main__':
solve()
D. Bitmask
import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
s = str(input().rstrip('\n'))
n = int(input().rstrip('\n'))
lns = len(s)
total = 0
for i in range(lns):
if s[i] == "1":
total += pow(2, lns - i - 1)
if total > n:
print(-1)
else:
for i in range(lns):
if s[i] == "?":
if pow(2, lns - i - 1) + total <= n:
total = pow(2, lns - i - 1) + total
print(total)
if __name__ == '__main__':
solve()