Question 1
# You are given
n = int(input())
if n == 0:
print(0)
else:
pairs = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[1])
count = 1
curr_end = pairs[0][1]
for i in range(1, n):
if pairs[i][0] > curr_end:
count += 1
curr_end = pairs[i][1]
print(count)
Question 2
# Dr. Sophia is
import sys
from functools import lru_cache
sys.setrecursionlimit(2005)
s1 = input()
s2 = input()
m, n = len(s1), len(s2)
dp = [[0] * (n + 1) for _ in range(m + 1)]
for i in range(1, m + 1):
for j in range(1, n + 1):
if s1[i - 1] == s2[j - 1]:
dp[i][j] = 1 + dp[i - 1][j - 1]
else:
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
@lru_cache(maxsize=None)
def find_lcs_strings(i, j):
if i == 0 or j == 0:
return {""}
if s1[i - 1] == s2[j - 1]:
return {lcs + s1[i - 1] for lcs in find_lcs_strings(i - 1, j - 1)}
res = set()
if dp[i][j] == dp[i][j - 1]:
res.update(find_lcs_strings(i, j - 1))
if dp[i][j] == dp[i - 1][j]:
res.update(find_lcs_strings(i - 1, j))
return res
all_lcs = sorted(find_lcs_strings(m, n))
print("All possible unique LCS combinations:")
for lcs in all_lcs:
print(lcs)
print(f"Length of LCS: {dp[m][n]}")
Question 3
# Krishna is a
tot = int(input())
lit = int(input())
men = int(input())
menlitper = int(input())
totlit = (tot * lit) // 100
totilit = tot - totlit
totmen = (tot * men) // 100
totwo = tot - totmen
menlit = (tot * menlitper) // 100
wolit = totlit - menlit
menilit = totmen - menlit
woilit = totwo - wolit
print(f"Men population={totmen}")
print(f"Women population={totwo}")
print(f"Literates={totlit}")
print(f"Illiterates={totilit}")
print(f"Men literates={menlit}")
print(f"Women literates={wolit}")
print(f"Men illiterates={menilit}")
print(f"Women illiterates={woilit}")
Question 4
# James is a
m = int(input())
g = int(input())
a = float(input())
p = int(input())
t = int(input())
print(f"{(m / a) * g + p + t:.2f}")
Question 5
// Write a program
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n1, d1, n2, d2;
cin >> n1 >> d1 >> n2 >> d2;
int num = n1 * d2 + n2 * d1, den = d1 * d2;
int g = __gcd(num, den);
cout << num / g << '/' << den / g;