---
# System prepended metadata

title: NDI122K21 - COMPLETE SUBMIT

---

# NDI122K21 - COMPLETE SUBMIT
**BÀI 1 - TẶNG QUÀ**
```c++
#include <bits/stdc++.h>
using namespace std;
const int X = 3e5 + 35;
int n, d = 0, x, F[X];
bool ifperfect_ok(int q)
{
    int T = 0, k = sqrt(q);
    for (int i = 1; i <= k; i++)
        T += ((q % i == 0) ? i + q / i : 0);
    return (T == 2 * q);
}
signed main()
{
    freopen("QUA.INP", "r", stdin);
    freopen("QUA.OUT", "w", stdout);
    cin.tie(NULL)->sync_with_stdio(false);
    cin >> n;
    for (int p = 1; p <= n; p++)
    {
        cin >> x;
        if (ifperfect_ok(x)) F[++d] = x;
    }
    cout << d << "\n";
    for (int i = 1; i <= d; i++) cout << F[i] << " ";
    return 0;
}
```
**BÀI 2 - CHỌN BI**
```c++
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
const lli E = 1e5 + 15;
lli T, n, m, d = 0;
struct marblebox
{
    lli a, b;
};
marblebox Bx[E];
bool cmp(marblebox X, marblebox Y)
{
    return X.b > Y.b;
}
signed main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    freopen("CHONBI.INP", "r", stdin);
    freopen("CHONBI.OUT", "w", stdout);
    cin >> n >> m;
    for (lli i = 1; i <= m; i++) cin >> Bx[i].a >> Bx[i].b;
    T = 0;
    sort(Bx + 1, Bx + m + 1, cmp);
    while (n > 0 || d < m)
    {
        lli k = min(n, Bx[++d].a);
        T += Bx[d].b * k;
        n -= k;
    }
    cout << T;
    return 0;
}
```
**BÀI 3 - DÃY ĐẸP**
```c++
#include <bits/stdc++.h>
using namespace std;
map <int, int> cnt;
map <int, int>::iterator it;
int n, x, del = 0;
signed main()
{
    freopen("DAYDEP.INP", "r", stdin);
    freopen("DAYDEP.OUT", "w", stdout);
    cin.tie(NULL)->sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; i++) { cin >> x; cnt[x]++; }
    for (it = cnt.begin(); it != cnt.end(); it++)
        if (it->second >= it->first) del += it->second - it->first;
            else del += it->second;
    cout << del;
    return 0;
}
```
**BÀI 4 - CHỌN ĐỘI TUYỂN**
```c++
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli h, s, g, p, t, n;
string name;
signed main()
{
    cin.tie(NULL) -> sync_with_stdio(false);
    freopen("CHONDOI.INP", "r", stdin);
    freopen("CHONDOI.OUT", "w", stdout);
    cin >> n;
    h = s = g = p = t = 0;
    for (lli x = 1; x <= n; x++)
    {
        cin >> name;
        h += (name[0] == 'H');
        s += (name[0] == 'S');
        g += (name[0] == 'G');
        p += (name[0] == 'P');
        t += (name[0] == 'T');
    }
    cout << h*s*g + h*s*p + h*s*t + h*g*p + h*g*t + h*p*t + s*g*p + s*g*t + s*p*t + g*p*t;
    return 0;
}
```