---
# System prepended metadata

title: T13

---

# T13
## Khử trùng
```cpp!
#include <bits/stdc++.h>
#define fast() ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
string trim(string s) {
    for(int i = s.size() - 1; i >= 0; --i){
        if(s[i] == ' ') s.erase(s.begin() + i);
    }
    return s;
}

int main(){
    fast();
    unordered_set<string> v;
    string c;
    while(getline(cin , c)){
        v.insert(trim(c));
    }
    for(string d : v){
        cout << d << endl;
    }
    return 0;
}

```
## Giải thích
```cpp!
#include <iostream>
#if 032 == 32 
    #include <https>
#endif

int main()
{
    https://hackmd.io/@HMNhat/t13;
    const int x = 123456789;
    const int y = 123'456'789;
    cout << x - y << endl;
    return 0;
}

```
Lí do 1:
```cpp!
#if 032 == 32 
    #include <https>
#endif
```
Số 0 trước một số biến nó thành 1 hệ số khác (ko phải decimal) nên điều kiện sai, nhánh ko đc biên dịch, ko lỗi.
SỰ THẬT: ```#include <https>``` KO HỀ TỒN TẠI
#IF và #ENDIF chỉ lầ macro tiền xử lí.

Lí do 2:
`https:` đc compiler coi là label dùng trong lệnh `goto label;`
`//hackmd.io/@HMNhat/t13;` là comment

Lí do 3:
`123'456'789`dấu ' dùng để tách số trong C++ => chạy vẫn đc

## Tổng
### 1
```cpp!
#pragma GCC optimize("unroll-loops, O3, avx2")
#include <bits/stdc++.h>
#define fast() ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr)
typedef long long ll;

using namespace std;
int main(){
    fast();
    int n; cin >> n;
    ll tong = 0;
    for(int i=1; i <= n; ++i){
        tong += i;
    }
    cout << tong << endl;
    return 0;
}

```
### 2
```cpp!
#pragma GCC optimize("unroll-loops, O3, avx2")
#include <bits/stdc++.h>
#define fast() ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr)
typedef long long ll;

using namespace std;
int main(){
    fast();
    int n; cin >> n;
    ll tong = 0;
    for(int i=1; i <= n; ++i){
        tong += (ll)(i * i);
    }
    cout << tong << endl;
    return 0;
}
```
### 3
```cpp!
#pragma GCC optimize("unroll-loops, O3, avx2")
#include <bits/stdc++.h>
#define fast() ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr)
typedef long long ll;

using namespace std;
int main(){
    fast();
    int n; cin >> n;
    ll tong = 0;
    for(int i=1; i <= n; ++i){
        tong += (ll)(i * i * i);
    }
    cout << tong << endl;
    return 0;
}
```
### 4
```cpp!
#pragma GCC optimize("unroll-loops, O3, avx2")
#include <bits/stdc++.h>
#define fast() ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr)
typedef long long ll;
const ll MOD = 1e9 + 7;

using namespace std;
int main(){
    fast();
    int n; cin >> n;
    ll tong = 0;
    for(int i=1; i <= n; ++i){
        tong = (tong + i) % MOD;
    }
    cout << tong << endl;
    return 0;
}

```
### 5
```cpp!
#pragma GCC optimize("unroll-loops, O3, avx2")
#include <bits/stdc++.h>
#define fast() ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr)
typedef long long ll;
const ll MOD = 1e9 + 7;

using namespace std;
int main(){
    fast();
    int n; cin >> n;
    ll tong = 0;
    for(int i=1; i <= n; ++i){
        tong = (tong + i * i) % MOD;
    }
    cout << tong << endl;
    return 0;
}
```
### 6
```cpp!
#pragma GCC optimize("unroll-loops, O3, avx2")
#include <bits/stdc++.h>
#define fast() ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr)
typedef long long ll;
const ll MOD = 1e9 + 7;

using namespace std;
int main(){
    fast();
    int n; cin >> n;
    ll tong = 0;
    for(int i=1; i <= n; ++i){
        tong = (tong + i * i * i) % MOD;
    }
    cout << tong << endl;
    return 0;
}

```

# Homework (verdict:accepted):
### https://codeforces.com/problemset/problem/456/A
```cpp!
#include <bits/stdc++.h>
#define fast() ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr)
using namespace std;

int main(){
    fast();
    int b; cin >>b;
    vector<pair<int,int>> a(b);
    for(int c=0; c < b; c++){
        cin >> a[c].first;
        cin >> a[c].second;
    }
    sort(a.begin(), a.end());
    for(int c=1; c < b; c++){
        if(a[c].second < a[c-1].second){
            cout << "Happy Alex" << endl;
            return 0;
        }
    }
    cout << "Poor Alex" << endl;
    return 0;
}
```
### https://codeforces.com/problemset/problem/478/C
```cpp!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    ll a, b,c; cin >> a >> b >>c;
    cout << min((a + b + c) /3, a+b+c - max({a, b, c})) << endl;
    return 0;
}
```
### https://codeforces.com/problemset/problem/348/A
```cpp!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    ll s =0, m=0;
    int a; cin >> a;
    for(int i =0; i < a; ++i){
        ll n; cin >> n;
        s+=n;
        m = max(m, n);
    }
    ll r = (ll)ceil((long double)s / (a -1));
    cout << max(m, r) << endl;
    return 0;
}
```
### https://codeforces.com/problemset/problem/4/C
```cpp!
#include<bits/stdc++.h>
using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int a; cin >> a;
    unordered_map<string, int> m;
    for(int i=0; i < a; ++i){
        string n; cin >> n;
        if(m.find(n) == m.end()){
            cout << "OK" << endl;
            m[n] = 0;
            } else{
            m[n]++;
            string n2 = n +to_string(m[n]);
            cout << n2 << endl;
            m[n2] = 0;
        };
    }
    return 0;
}
```
### https://codeforces.com/problemset/problem/25/A
```cpp!
#include<bits/stdc++.h>
using namespace std;

signed main(){
    int a, c =0, l=0; cin >> a;
    vector<int> v(a);
    for(int i = 0; i < a; ++i){
        cin >> v[i];
        (v[i] % 2 == 0) ? c++ : l++;
    }
    if(c > l){
        for(int i = 0; i < a; ++i){
            if(v[i] % 2 != 0){
                cout << (i + 1) << endl;
                return 0;
            }
        }
    }
    else{
        for(int i = 0; i < a; ++i){
            if(v[i] % 2 == 0){
                cout << (i + 1) << endl;
                return 0;
            }
        }
    }

    return 0;
}
```
### https://codeforces.com/problemset/problem/406/B
```cpp!
#pragma GCC optimize("Ofast,unroll-loops")

#include <bits/stdc++.h>
#define fast() ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr)
using namespace std;

int main(){
    fast();
    int n=0; cin >> n;
    vector<int> a(n);
    for(int c =0; c < n; ++c) cin >> a[c];
    sort(a.begin(), a.end());
    int q = 0; cin >> q;
    for(int c =0; c < q; ++c){
        int t =0; cin >> t;
        cout << upper_bound(a.begin(), a.end(), t) - a.begin() << endl;
    }
    return 0;
}

```

# Research
