A - Cookie Exchanges, A - Irreversible operation, B - Toll Gates

###[A - Cookie Exchanges](https://atcoder.jp/contests/agc014/tasks/agc014_a)

O(N)
シミュレートします。

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.141592653589793238;
 
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

void solve(ll a, ll b, ll c){

    if(!(a%2==0 && b%2==0 && c%2==0)){cout << 0 << endl; return;}

    ll ok=0;
    ll aa=0, bb=0, cc=0;
    while(1){
        aa= b / 2 + c / 2;
        bb= a / 2 + c / 2;
        cc= b / 2 + a / 2;
        
        if(a==aa && b==bb && c==cc){ok=-1; break;}
        else if(!(aa%2==0 && bb%2==0 && cc%2==0)){ok++; break;}
        a = aa; b = bb; c = cc; ok++;
    }
    cout << ok << endl;
}
 
int main() {
    int a, b, c;
    cin >> a >> b >> c;

    solve(a, b, c);
 
    return 0;
}
```

###[A - Irreversible operation](https://atcoder.jp/contests/agc029/tasks/agc029_a)

O(N)
特に書くことがない灰diffですね。

```C++:C++
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main() {
    string s;
    cin >> s;

    ll res=0;
    int l=0, r=s.length()-1;
    while(l<r){
        if(s[l] == 'B'){
            while(s[r] == 'B' && l<r) r--;
            
            if(l<r){
                swap(s[l], s[r]);
                res += (r - l);
                r--;
            }
        }
        l++;
    }
    cout << res << endl;

    return 0;
}
```

##[B - Toll Gates](https://atcoder.jp/contests/abc094/tasks/abc094_b)

O(N)
X地点より小さい地点A_iの合計
X地点より大きい地点A_iの合計
を求めると解答できます。

```C++:C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

int main() {
    int N, M, X;
    cin >> N >> M >> X;

    vector<int> A(M);
    rep(i, M) cin >> A[i];

    int l=0, r=0;
    rep(i, A.size()){
        if(A[i] < X) l++;
        if(A[i] > X) r++;
    }

    cout << min(l, r) << endl;

    return 0;
}
```