Masala A. HTTS
Shartida berilgandek N soniniberiladi, berilgan N sonining uzunligini toq va har bir raqamlari ham toq bo'lsa shuning o'zi yetarli bo'ladi.
C++ dasturlash tilida yechim:

#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,y;
	cin>>n;
	int s=0;
	while(n>0){
		y=n%10;s += 1;
		if(y%2==0){
			cout<<"NO"; return 0;
		}
		n/=10;
	}
	if(s%2==1) cout<<"YES";
	else cout<<"NO";
}

Python dasturlash tilida yechim:

n = int(input())
s = 0
while n > 0:
    y = n % 10
    s += 1
    if y % 2 == 0:
        print("NO")
        exit()
    n //= 10
if s % 2 == 1:
    print("YES")
else:
    print("NO")


Masala B. Tarvuz
Algoritm: Matematika

C++ dasturlash tilida yechim:

#include <bits/stdc++.h>
using namespace std;
int main(){
	long double a;
	int b, c;
	cin >> a >> b >> c;
	cout << fixed << setprecision(5) <<  a*(100-b)/(100-c);
	return 0;
}

Python dasturlash tilida yechim:

a, b, c = map(int, input().split())
print(a*(100-b)/(100-c))


Masala C. Maximum sum
Algoritm: Two pointers, Perebor, Tartiblash.

#include<bits/stdc++.h>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    vector<int> sum(n, 0);
    sum[0] = a[0];
    for (int i = 1; i < n; i++) {
        sum[i] = sum[i - 1] + a[i];
    }
    int l, r;
    int ans = 0;
    for (int i = 0; i <= k; i++) {
        l = 2 * i;
        r = n - k + i - 1;
        ans = max(ans, sum[r] - sum[l] + a[l]);
    }
    cout << ans << endl;

}

Python dasturlash tilida yechim:

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
sum = [0] * n
sum[0] = a[0]
for i in range(1, n):
    sum[i] = sum[i - 1] + a[i]
ans = 0
for i in range(k + 1):
    l = 2 * i
    r = n - k + i - 1
    ans = max(ans, sum[r] - sum[l] + a[l])

print(ans)

Masala D. O'zgartirishlar
Algoritm: Prefiks sum.

#include<bits/stdc++.h>

using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define int long long
signed main() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    vector<int> sum(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sum[0] = a[0];
    for (int i = 1; i < n; ++i) sum[i] = sum[i - 1] + a[i];
    while (q--) {
        int l, r, k;
        cin >> l >> r >> k;
        l--;
        r--;
        if ((sum[n - 1] - (sum[r] - sum[l] + a[l]) + k * (r - l + 1)) % 2 == 0) yes;
        else no;
    }
}

Python dasturlash tilida yechim:

n, q = map(int, input().split())
a = list(map(int, input().split()))
sum = [0] * n
sum[0] = a[0]
for i in range(1, n):
    sum[i] = sum[i - 1] + a[i]
for i in range(q):
    l, r, k = map(int, input().split())
    l -= 1
    r -= 1
    if ((sum[n - 1] - (sum[r] - sum[l] + a[l]) + k * (r - l + 1)) % 2 == 0):
        print("YES")
    else:
        print("NO")

Masala E. O'rmon va daraxtlar
Algoritm: Binary search.

#include<bits/stdc++.h>

using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define int long long
signed main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int &i : a) cin >> i;
    sort(a.begin(), a.end());
    int l = 1, r = 1e9;
    while(l < r) {
        int h = (l + r) / 2;
        int s = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] > h) {
                s += a[i] - h;
            }
        }
        if (s >= m) {
            l = h + 1;
        } else {
            r = h;
        }
    }
    cout << l - 1 << endl;
}

Python dasturlash tilidagi yechim:

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l = 1
r = 10 ** 9
while l < r:
    h = (l + r) // 2
    s = 0
    for i in range(n):
        if a[i] > h:
            s += a[i] - h
    if s >= m:
        l = h + 1
    else:
        r = h
print(l - 1)

 

Masala F. Robolandiyada saralash

#include<bits/stdc++.h>

using namespace std;

#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define int long long
#define endl "\n"

signed main() {
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(4,0));
    for(int i = 0; i <  n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        v[i][0] = -a;
        v[i][1] = -b;
        v[i][2] = c;
        v[i][3] = i + 1;
    }
    sort(v.begin(), v.end());
    for (auto i : v) {
        cout << i[3] << " ";
    }
}

Python dasturlash tilida yechim:

n = int(input())
v = []
for i in range(n):
    a, b, c = map(int, input().split())
    v.append([-a, -b, c, i + 1])
v.sort()
for i in v:
    print(i[3], end=' ')

 

Masala G. Haqiqiy tenglama.
Algoritm: Binary search

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double



signed main() {
    ld c;
    int n;
    cin >> c >> n;
    ld l = 0, r = 1e12;
    while(r - l > 1e-10) {
        ld mid = (l + r) / 2;
        if (n * pow(mid, n) + pow(mid, 1.0/n) < c) {
            l = mid;
        } else {
            r = mid;
        }
    }
    cout << fixed << setprecision(7) << (double)l << endl;
}

Python dasturlash tilida yechim:

c = float(input())
n = int(input())
left = 0
right = 1e12
while right - left > 1e-11:
    mid = (left + right) / 2
    if n * pow(mid, n) + pow(mid, 1.0 / n) < c:
        left = mid
    else:
        right = mid
print(f'{left:0.7f}')

 

Masala H. AVL daraxt.

Algoritm: Dinamik dasturlash, Matrix pow, Ikkilik daraja

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define mod 1000000007

int32_t main() {
    int n;
    cin >> n;
    n = n + 3;
    int a[2][2] = {{0,1}, {1,1}};
    int r[2][2] = {{1,0}, {0,1}};
    while(n>0){
        if(n%2 == 1){
            int c[2][2] = {{0,0}, {0,0}};
            for(int i=0; i<2; i++){
                for(int j=0; j<2; j++){
                    for(int k=0; k<2; k++){
                        c[i][j] = (c[i][j] + r[i][k] * a[k][j])%mod;
                    }
                }
            }
            for(int i=0; i<2; i++){
                for(int j=0; j<2; j++){
                    r[i][j] = c[i][j];
                }
            }
            n = n - 1;
        }
        else{
            int c[2][2] = {{0,0}, {0,0}};
            for(int i=0; i<2; i++){
                for(int j=0; j<2; j++){
                    for(int k=0; k<2; k++){
                        c[i][j] = (c[i][j] + a[i][k] * a[k][j])%mod;
                    }
                }
            }
            for(int i=0; i<2; i++){
                for(int j=0; j<2; j++){
                    a[i][j] = c[i][j];
                }
            }
            n = n / 2;
        }
    }
    cout << r[1][0] - 1 << endl;
    return 0;
}

Python dasturlash tilida yechim:

import math
def f(a,b):
    mod = 10**9+7
    c = [[0,0], [0,0]]
    for i in range(2):
        for j in range(2):
            for k in range(2):
                c[i][j] = (c[i][j] + a[i][k] * b[k][j])%mod
    return c

def fib(n):
    a = [[0,1], [1,1]]
    r = [[1,0], [0,1]]
    while(n>0):
        if n%2 == 1:
            r = f(r,a)
        n = n // 2
        a = f(a,a)
    return r[1][0]
n = int(input())
n = n + 3
print(fib(n)-1)