A. CAPS LOCK
import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
print(str(input().rstrip('\n')).upper())
if __name__ == '__main__':
solve()
B. Yellow and Red Card
import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n, q = list(map(int, input().rstrip('\n').split()))
ls = [0] * n
for i in range(q):
e, x = list(map(int, input().rstrip('\n').split()))
if e == 1:
ls[x-1] += 1
elif e == 2:
ls[x-1] += 2
else:
print("Yes" if ls[x-1] >= 2 else "No")
if __name__ == '__main__':
solve()
C. Four Variables
import sys
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input().rstrip('\n'))
ls = [0] * (n + 1)
for i in range(1, n + 1):
for j in range(i, n + 1, i):
ls[j] += 1
cnt = 0
for i in range(1, n + 1):
for j in range(i, n + 1, i):
cnt += ls[n - j]
print(cnt)
if __name__ == '__main__':
solve()
D. Unicyclic Components
import sys
import collections
class AlgUnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def solve():
input = sys.stdin.readline
mod = 10 ** 9 + 7
n, m = list(map(int, input().rstrip('\n').split()))
uf = AlgUnionFind(n)
v = sorted([list(map(int, input().rstrip('\n').split())) for _ in range(m)])
d = collections.defaultdict(int)
for i in range(m):
lst = d[uf.find(v[i][1] - 1)]
d[uf.find(v[i][1] - 1)] = 0
uf.union(v[i][0]-1, v[i][1]-1)
d[uf.find(v[i][0] - 1)] += lst + 1
for v in uf.roots():
if uf.size(v) != d[v]:
print("No")
exit()
print("Yes")
if __name__ == '__main__':
solve()