akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


int main() {
  int H, W;
  cin >> H >> W;
  
  vector<string> S(H);
  vector<vector<int>> A(H+2, vector<int>(W+2,0));
  for (int i=0; i<H; i++) {
  	cin >> S.at(i);
    for (int j=0; j<W; j++) {
      if (S.at(i).at(j)=='#') {
        A.at(i).at(j) += 1;
        A.at(i).at(j+1) += 1;
        A.at(i).at(j+2) += 1;
        A.at(i+1).at(j) += 1;
        A.at(i+1).at(j+1) += 1;
        A.at(i+1).at(j+2) += 1;
        A.at(i+2).at(j) += 1;
        A.at(i+2).at(j+1) += 1;
        A.at(i+2).at(j+2) += 1;
      }
    }
  }
  
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      if (S.at(i).at(j)=='#') cout << "#";
      else cout << A.at(i+1).at(j+1);
    }
    cout << endl;
  }    
  

  return 0;
}


Measured memory_bytes: 3616
//const int N = 4005;
//int grid[N][N][2];
//int _(){
//    int n,k;
//    cin >> n >> k;
//    while(n--){
//        int x,y;
//        char c;
//        cin >> x >> y >> c;
//        x %= 2*k;
//        y %= 2*k;
//        x += 1;
//        y += 1;
//        int type = c == 'B';
//        grid[x][y][type] += 1;
//        grid[x+2*k][y][type] += 1;
//        grid[x][y+2*k][type] += 1;
//        grid[x+2*k][y+2*k][type] += 1;
//    }
//    int ans = 0;
//    rep(i,1,4*k)
//        rep(j,1,4*k)
//            rep(t,0,1)
//                grid[i][j][t]+=grid[i-1][j][t]+grid[i][j-1][t]-grid[i-1][j-1][t];
//    rep(i,0,2*k-1)
//        rep(j,0,2*k-1){
//            int s1 = grid[i+k][j+k][0]-grid[i+k][j][0]-grid[i][j+k][0]+grid[i][j][0];
//            int s4 = grid[i+k+k][j+k+k][0]-grid[i+k+k][j+k][0]-grid[i+k][j+k+k][0]+grid[i+k][j+k][0];
//            int s2 = grid[i+k+k][j+k][1]-grid[i+k+k][j][1]-grid[i+k][j+k][1]+grid[i+k][j][1];
//            int s3 = grid[i+k][j+k+k][1]-grid[i+k][j+k][1]-grid[i][j+k+k][1]+grid[i][j+k][1];
//            ans = max(ans,s1+s2+s3+s4);
//        }
//    return ans;
//
//}
//
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define T1 template<typename T> static
using namespace std;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
const int N = 4005;
int grid[N][N][2];
int _(){
    int n,k;
    cin >> n >> k;
    while(n--){
        int x,y;
        char c;
        cin >> x >> y >> c;
        x %= 2*k;
        y %= 2*k;
        x += 1;
        y += 1;
        int type = c == 'B';
        grid[x][y][type] += 1;
        grid[x+2*k][y][type] += 1;
        grid[x][y+2*k][type] += 1;
        grid[x+2*k][y+2*k][type] += 1;
    }
    int ans = 0;
    rep(i,1,4*k)
        rep(j,1,4*k)
            rep(t,0,1)
                grid[i][j][t]+=grid[i-1][j][t]+grid[i][j-1][t]-grid[i-1][j-1][t];
    rep(i,0,2*k-1)
        rep(j,0,2*k-1){
            int s1 = grid[i+k][j+k][0]-grid[i+k][j][0]-grid[i][j+k][0]+grid[i][j][0];
            int s4 = grid[i+k+k][j+k+k][0]-grid[i+k+k][j+k][0]-grid[i+k][j+k+k][0]+grid[i+k][j+k][0];
            int s2 = grid[i+k+k][j+k][1]-grid[i+k+k][j][1]-grid[i+k][j+k][1]+grid[i+k][j][1];
            int s3 = grid[i+k][j+k+k][1]-grid[i+k][j+k][1]-grid[i][j+k+k][1]+grid[i][j+k][1];
            ans = max(ans,s1+s2+s3+s4);
        }
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        cout << _() << '\n';
}


Measured memory_bytes: 125440
#include<stdio.h>
int main(){
  int n,i,j,min,count=0,w;
  int B[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&B[i]);
  }
  for(i=0;i<=n-1;i++){
    min=i;
    for(j=i;j<=n-1;j++){
      if(B[j]<B[min]){
	min=j;
      }
    }
      if(i != min){
	count++;
	w=B[i];
	B[i]=B[min];
	B[min]=w;
      }}
    for(i=0;i<n-1;i++){
      printf("%d ",B[i]);
			   
	}
    printf("%d",B[n-1]);
    printf("\n");
    printf("%d\n",count);
    return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int iCount, plusNum;
  int result = 1;
  cin >> iCount >> plusNum;
  
  for (int i=0;i<iCount;i++){
    if (result * 2 > result + plusNum){
      result += plusNum;
    } else {
      result *= 2;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

struct UF {
  int siz;
  vector<int> p;
  UF(int n) : siz(n),p(n,-1) {}
  int rt(int x) { return p[x]<0 ? x : p[x]=rt(p[x]); }
  void cat(int x, int y) {
    x=rt(x); y=rt(y);
    if(x==y) return;
    siz--;
    if(p[x]<p[y]) swap(x,y);
    p[y]+=p[x];
    p[x]=y;
  }
};

int main() {
  static char tbl[20][20];
  for(int tci = 0; ; tci++) {
    int pty = 0;
    for(int y = 0; y < 12; y++) {
      if(scanf(" %s", tbl[y])<1) return 0;
      for(int x = 0; x < 12; x++) {
        pty += (tbl[y][x]=='0');
      }
    }
    UF uf(12*12);
    for(int y = 0; y < 12; y++) {
      for(int x = 0; x < 12; x++) {
        if(y>0 && tbl[y][x]=='1' && tbl[y-1][x]=='1') uf.cat(12*y+x, 12*(y-1)+x);
        if(x>0 && tbl[y][x]=='1' && tbl[y][x-1]=='1') uf.cat(12*y+x, 12*y+(x-1));
      }
    }
    printf("%d\n", uf.siz-pty);
  }
  return 0;
}

Measured memory_bytes: 1008
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int main(){
	long long X,A,B;
	cin>> X >> A >> B;
	X -= A;
	while (X >= 0)
		X -= B;
	X += B;
	cout<< X <<endl;
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vll proc(200, 0);
    for (ll i = 1; i < 200; i++) proc[i] = i * (i + 1) * (i + 2) / 6;

    vll dp(1000005, HIGHINF), odd_dp(1000005, HIGHINF);
    dp[0] = odd_dp[0] = 0;
    for (ll i = 0; i < 1000005; i++) {
        for (ll j = 0; j < 200; j++) {
            if (i - proc[j] >= 0) {
                chmin(dp[i], dp[i - proc[j]] + 1);
                if (proc[j] % 2 == 1) chmin(odd_dp[i], odd_dp[i - proc[j]] + 1);
            }
        }
    }

    ll n;
    while (true) {
        cin >> n;
        if (n == 0) break;
        cout << dp[n] << ' ' << odd_dp[n] << '\n';
    }
    return 0;
}



Measured memory_bytes: 18232
from math import gcd
INF = float('inf')
N = int(input())
A = list(map(int,input().split()))
flg = True
lis = [INF] * (10**6+5)
for i in range(2,int((10**6)**0.5)+1):
    if lis[i] == INF:
        for j in range(i*2,10**6+1,i):
            lis[j] = i
st = set()
for i in range(N):
    p = A[i]
    d  =[]
    while lis[p] != INF:
        d.append(lis[p])
        p //= lis[p]
    if p > 1:
        d.append(p)
    for i in range(len(d)):
        if d[i] in st:
            flg = False
    for i in range(len(d)):
        st.add(d[i]) 
#print(lis[:15])

if flg == True:
    print('pairwise coprime')
    exit()



val = A[0]
for i in range(1,N):
    val = gcd(val,A[i])
if val == 1:
    print('setwise coprime')
    exit()
print('not coprime')

Measured memory_bytes: 196668
#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int x,y;
	cin >>x >> y;

	int a[13] = {0,0,2,0,1,0,1,0,0,1,0,1,0};
	if(a[x] == a[y])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int L,R,d;
    cin>>L>>R>>d;
    int ans=0;
    for(int i=L;i<=R;i++)
    {
        if(i%d==0)
        {
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define int long long

string S,T;
int dp[3001][3001];

signed main() {
  cin >> S >> T;
  for(int s=0, ss=S.size(); s<ss; s++) for(int t=0, tt=T.size(); t<tt; t++) {
    if(S[s] == T[t]) dp[s+1][t+1] = dp[s][t] + 1;
    else             dp[s+1][t+1] = max(dp[s][t+1], dp[s+1][t]);
  }

  int s=S.size(), t=T.size();
  stack<char> st;
  int count = dp[s][t];
  while(count) {
    if(S[s-1]==T[t-1]) {
      st.push(S[s-1]);
      count--;
      s--; t--;
    }
    else if(dp[s][t]==dp[s-1][t]) {
      s--;
    }
    else {
      t--;
    }
  }
  while(st.size()){
    cout << st.top();
    st.pop();
  }
  
  puts("");
}


Measured memory_bytes: 70656
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {

    int a, b;
    string s;
    cin >> a >> b;
    cin >> s;

    bool out = false;
    REP(i, s.size()){
        if (i != a){
            if (!('0' <= s[i] && s[i] <= '9')) out = true;
        }else{
            if (s[i] != '-') out = true;
        }
        if (out){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

long long int cnt2(long long int x){
    long long int ans = 0;
    while(x%2 == 0){
        x /= 2;
        ans++;
    }

    return ans;

}

int main()
{
    int n;
    cin >> n;

    long long int ans = 1000000000;

    vector<long long int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        ans = min(ans, cnt2(a[i]));
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int n, m;
int a[100], b[100];

void solve() {
	int asum = 0, bsum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		asum += a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		bsum += b[i];
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (asum - a[i] + b[j] == bsum - b[j] + a[i]) {
				cout << a[i] << " " << b[j] << endl;
				return;
			}
		}
	}
	cout << -1 << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	while (cin >> n >> m , n) {
		solve();
	}
}

Measured memory_bytes: 1192
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int A[3];
int N,M;
bool a = true;

int main() {
    cin >> N >> M;
    for (int i = 0;i<N;i++){
        A[i] = -1;
    }
    for (int i = 0;i<M;i++){
        int s,c;
        cin >> s >> c;
        if ((A[s-1] == -1 || A[s-1] == c) && !(s == 1 && c == 0 && N != 1)){
            A[s-1] = c;
        } else {
            a = false;
        }
    }
    if (a) {
        for (int i=0;i<N;i++){
            if (A[i] == -1 && i == 0 && N!=1){
                cout << 1;
            } else if (A[i] == -1){
              cout << 0;
            }
          else{
                cout << A[i];
            }
        }
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int NN = 1100;

ll f[NN][NN];
ll mod, k, n, a[NN], b[NN], ans, x;
int vis1[30], vis2[30];
char s[NN];


int main(){
	//freopen("a.in", "r", stdin);

	
	char  s[20];
	scanf("%s", s+1);
	if (s[3] == s[4] && s[5] == s[6]) printf("Yes");
	else printf("No"); 
	
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(){
    int N, M;
    cin >> N  >> M;
    int A[M];
    rep(i, M) cin >> A[i];

    int sum=0;
    rep(i, M) sum+=A[i];

    int ans=N-sum;
    if(ans<0) ans=-1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
#define ull unsigned long long int
#define fasterInOut ios::sync_with_stdio(false); cin.tie(0);
#define pi acos(-1)
 
int main()    {
	//freopen("/home/mimi0007/Desktop/Temp/in", "r", stdin);
	fasterInOut;
	string s;
	cin >> s;
	ll sum = 0;
	for(int i = 0; i < s.size();  i++) {
		sum += s[i] - '0';
	}
	
	if(sum % 9 == 0)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <typename T>
struct Compress {
    vector<T> data;
    Compress() = default;
    Compress(const vector<T> &dat) {
        add(dat);
        build();
    }
    void add(const vector<T> &dat) { copy(dat.begin(), dat.end(), back_inserter(data)); }
    void add(const T &d) { data.emplace_back(d); }
    void build() {
        sort(data.begin(), data.end());
        data.erase(unique(data.begin(), data.end()), data.end());
    }
    int size() const { return data.size(); }
    // round up
    int at(const T &x) const { return lower_bound(data.begin(), data.end(), x) - data.begin(); }
    // round down
    int rd(const T &x) const { return prev(upper_bound(data.begin(), data.end(), x)) - data.begin(); }
    // int ru(const T &x) const { return upper_bound(data.begin(), data.end(), x) - data.begin(); }
    const T &operator[](int k) const { return data[k]; }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    Compress<int> idx(a);
    idx.add(-1);
    idx.build();
    int l = idx.size();

    vector<vector<pair<int, lint>>> edges(l);
    for (int i = 0; i < m; ++i) {
        int l, r;
        cin >> l >> r;
        l--;
        int ll = idx.rd(l);
        int rr = idx.rd(r);
        if (ll == rr)
            continue;
        edges[ll].emplace_back(rr, i + 1);
        edges[rr].emplace_back(ll, i + 1);
    }

    vector<int> bomb(l, 0);
    for (int i = 0; i < n; ++i) {
        int k   = idx.at(a[i]);
        bomb[k] = b[i];
    }

    for (int z = 0; z < 2; ++z) {
        bomb[0] = z;

        vector<int> cut(l, 0);
        if (bomb[l - 1] == 1)
            cut[l - 1] = 1;
        for (int i = l - 2; i >= 0; --i) {
            if (bomb[i] != bomb[i + 1])
                cut[i] = 1;
        }

        vector<bool> done(l, false);
        vector<int> ret;
        function<void(int, int)> dfs = [&](int c, int p) {
            done[c] = true;
            for (auto &v : edges[c]) {
                if (done[v.first])
                    continue;
                dfs(v.first, c);
                if (cut[v.first] % 2 == 1)
                    ret.push_back(v.second);
                cut[c] += cut[v.first];
            }
        };
        bool ok = true;
        for (int i = 0; i < l; ++i) {
            if (done[i])
                continue;
            dfs(i, -1);
            if (cut[i] % 2 == 1) {
                ok = false;
            }
        }
        if (ok) {
            sort(ret.begin(), ret.end());
            cout << ret.size() << endl;
            for (int i = 0; i < (int)ret.size(); ++i) {
                if (i)
                    cout << " ";
                cout << ret[i];
            }
            cout << endl;
            return 0;
        }
    }
    cout << -1 << "\n";
    return 0;
}

Measured memory_bytes: 21496
#include<bits/stdc++.h>
using namespace std;
#define INF 1e15
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
typedef pair<int, int> P;
#define END system("PAUSE");return 0
signed main() {
	int n;
	int a[111];
	cin >> n;
	rep(i, n)cin >> a[i];
	int ans = 0;
	for (int i = 1; i < n; i++) {
		if (a[i] == a[i - 1]) {
			a[i] = 10000000 + i;
			ans++;
		}
	}
	cout << ans << endl;
	END;
}


Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(ll i=ll(x);i<(ll)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<ll,ll>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;

int main(){
    ll n,m;
    cin>>n>>m;
    ll a=0;
    if(2*n>=m){
        cout<<m/2<<endl;
        return 0;
    }
    while(m-4*a>=2*n){
        a++;
    }
    ll ans=n+a-1;
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3592
N, K = map(int, input().split())

total = (N - 1) * (N - 2) // 2
if K > total:
    print(-1)
else:
    M = N - 1 + total - K
    cnt = 0
    
    print(M)
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            if cnt == M:
                exit()
            print(i, j)
            cnt += 1


Measured memory_bytes: 44528
import Control.Monad
import Data.IORef
main = do
    n <- readLn :: IO Int
    --
    x <- newIORef 0;
    forM_ [1..n] $ \i -> do
        writeIORef x i
        if (i `mod` 3 == 0) then
            putStr $ " " ++ show i
        else
            include3 i x
    putStrLn ""
    where
    include3 :: Int -> IORef Int -> IO ()
    include3 i x = do
        x' <- readIORef x
        if (x' `mod` 10 == 3) then
            putStr $ " " ++ show i
        else do
            x' <- readIORef x
            writeIORef x (x' `div` 10)
            readIORef x
            >>= \a -> when (a /= 0) $
                include3 i x

Measured memory_bytes: 4108
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; ++i) { scanf("%d", &A[i]); }
  for (int i = 0; i < N; ++i) { scanf("%d", &B[i]); }
  for (int i = 0; i < N; ++i) { scanf("%d", &C[i]); }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  ll ans = 0LL;
  for (int i = 0; i < N; ++i) {
    int b = B[i];
    ll na = distance(A.begin(), lower_bound(A.begin(), A.end(), b));
    ll nc = distance(upper_bound(C.begin(), C.end(), b), C.end());
    ans += (na * nc);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1408
#include        <bits/stdc++.h>
using   namespace       std;

int     main() {
        int N;
        cin >> N;
        vector <int> W(N);
        int S=0;
        for (int i=0; i<N; i++) {
                cin >> W.at(i);
                S += W.at(i);
        }
        int T=0;
        int D=10000;
        for (int i=0; i<N; i++) {
                T += W.at(i);
                S -= W.at(i);
                int DD=abs(T-S);
                D=min(D, DD);
        }
        cout <<D << endl;
        return 0;
}

Measured memory_bytes: 256
/* Focus your enery towards light */

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(int i=0;i<n;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define ford(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265
#define inf 1e18

/******************************************************************************************************/
void file() {
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
/******************************************************************************************************/

// const ll nax = 2e5 + 1;
// const ll mod = 1e9 + 7;



int main() {

    sync

    int testCases = 1;
    // cin >> testCases;

    while (testCases--) {
        int n;
        cin >> n;
        int ans = 0;
        forn (i, n) {
            int x;
            cin >> x;
            ans += (x % 2) && (i % 2 == 0) ? 1 : 0;
        }
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>

using namespace std;

template<typename T>
class SegTree {
public:
    explicit SegTree(int n, T def) : N(calcN_(n)), def(def), mVal(2*calcN_(n)-1, def) {}
    void update(int idx, T value){
        int i = N + idx - 1;
        update_(mVal[i], value);
        while(i > 0){
            i = (i-1)/2;
            mVal[i] = operate(mVal[2*i+1], mVal[2*i+2]);
        }
    }
    T get(int l, int r){
        l = max(0, l);
        r = min(N, r);
        int offset = N;
        T res = def;
        while(offset > 0){
            if(l >= r) break;
            if(l&1){ res = operate(res, mVal[offset+l-1]); l++; }
            if(r&1){ res = operate(res, mVal[offset+r-2]); }
            l /= 2;
            r /= 2;
            offset /= 2;
        }
        return res;
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    void update_(T& data, T val) { data += val; }
    T operate(T a, T b) { return a+b; }
    const int N;
    const T def;
    vector<T> mVal;
};


int main(){
    int n, q;
    while(cin >> n >> q){
        SegTree<int> seg(n, 0);
        for(int i=0;i<q;i++){
            int c, x, y; cin >> c >> x >> y;
            --x;
            if(c == 0){
                seg.update(x, y);
            } else {
                cout << seg.get(x, y) << endl;
            }
        }
    }
}



Measured memory_bytes: 3892
#include <bits/stdc++.h> 
using namespace std;
void dfs(int node, vector<int> adj[], int dp[], bool vis[]) 
{ 
    vis[node] = true; 
    for (int i = 0; i < adj[node].size(); i++) { 
  
        if (!vis[adj[node][i]]) 
            dfs(adj[node][i], adj, dp, vis); 
        dp[node] = max(dp[node], 1 + dp[adj[node][i]]); 
    } 
} 
int findLongestPath(vector<int> adj[], int n) 
{ 
    int dp[n + 1]; 
    memset(dp, 0, sizeof dp); 
    bool vis[n + 1]; 
    memset(vis, false, sizeof vis); 
    for (int i = 1; i <= n; i++) { 
        if (!vis[i]) 
            dfs(i, adj, dp, vis); 
    } 
  
    int ans = 0;
    for (int i = 1; i <= n; i++) { 
        ans = max(ans, dp[i]); 
    } 
    return ans; 
} 
int main ()
{
    int t,n,m,i,j,x,y;
    cin >>n>>m;
    vector <int> adj[n+1];
    
    for(i=0;i<m;i++)
    {cin >>x>>y;
    adj[x].push_back(y);}
    cout << findLongestPath(adj, n); 
}

Measured memory_bytes: 9600
#include<iostream>
using namespace std;
int main() {

	int n;
	string s;
	cin >> n;
	cin >> s;
	int i;
	if (n % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	for (i = 0; i < n / 2; i++) {
		if (s[i] != s[i + (n / 2)]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	int X; cin >> X;
	if (X >= 30) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define ll long long
using namespace std;
int n,ans,idx;
ll h;
struct node
{
    ll a,b;
};
node s[200000];
bool cmp(node a,node b)
{
    if (a.b!=b.b) return a.b>b.b;
    return a.a>b.a;
}

int main()
{
    cin>>n>>h;
    for (int i=0; i<n; ++i)
        scanf("%lld%lld",&s[i].a,&s[i].b);
    sort(s,s+n,cmp);
    for (int i=0; i<n; ++i)
        if (s[i].a>=s[idx].a)
        {
            idx=i;
        }
    for (int i=0; i<n; ++i)
    {
        if (h>0 && s[i].b>s[idx].a)
        {
            ans+=1;
            h-=s[i].b;
        }
    }
    if (h>0)
    {
        ans+=(h/s[idx].a);
        h-=(h/s[idx].a)*s[idx].a;
        if (h) ans+=1;
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n; cin >> n;
  const int V = 100000;
  vector<int> m(V + 1);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int t; cin >> t;
    sum += t;
    m[t]++;
  }
  int q; cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= b * m[b];
    sum += c * m[b];
    m[c] += m[b];
    m[b] = 0;
    cout << sum << '\n';
  }
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 4008
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        ArrayList<Integer> input = new ArrayList<Integer>();
        
        for (int i = 0; i < 5; i++) {
            input.add(scanner.nextInt());
        }
        Collections.sort(input);
        Collections.reverse(input);
        
        for ( int i = 0; i < input.size()-1; i ++) {
            System.out.print(input.get(i) + " ");
        }
        System.out.println(input.get(input.size()-1));
    }    
    
}

Measured memory_bytes: 17372
#include <bits/stdc++.h>
using namespace std;

int main() {
  string S;
  cin >>S;
  if (S=="Sunny")cout <<"Cloudy"<<endl;
  else if(S=="Cloudy")cout<<"Rainy"<<endl;
  else if(S=="Rainy")cout<<"Sunny"<<endl;
  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra()
{
    int minv;
    int d[MAX], color[MAX];

    for(int i=0; i<n; i++)
    {
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0] = 0;
    color[0] = GRAY;
    while(1)
    {
        minv = INFTY;
        int u = -1;
        for(int i=0; i<n; i++)
        {
            if(minv > d[i] && color[i] != BLACK)
            {
                u = i;
                minv = d[i];
            }
        }
        if(u == -1) break;
        color[u] = BLACK;
        for(int v=0; v<n; v++)
        {
            if(color[v]!=BLACK && M[u][v]!=INFTY)
            {
                if(d[v]>d[u]+M[u][v])
                {
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    for(int i=0; i<n; i++)
    {
        cout << i << " " << (d[i]==INFTY ? -1:d[i]) << endl;
    }
}

int main()
{
    cin >> n;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++) M[i][j] = INFTY;
    }

    int k, c, u, v;
    for(int i=0; i<n; i++)
    {
        cin >> u >> k;
        for(int j=0; j<k; j++)
        {
            cin >> v >> c;
            M[u][v] = c;
        }
    }
    dijkstra();
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
using namespace std;

int main(){
  int n;

  while(cin >> n, n){
    n++;
    int t[102];

    for(int i = 0; i < n; i++){
      cin >> t[i];
    }

    int val1 = -1, val2 = -1;
    int cnt1 = 0, cnt2 = 0;

    for(int i = 1; i < n; i++){
      int diff = t[i] - t[i - 1];

      if(val1 == -1){
        val1 = diff;
        cnt1++;
      }
      else if(val1 == diff){
        cnt1++;
      }
      else{
        val2 = diff;
        cnt2++;
      }
    }

    if(cnt2 > cnt1){
      swap(val1, val2);
    }

    for(int i = 1; i < n; i++){
      int diff = t[i] - t[i - 1];

      if(val1 != diff){
        if(i == 1 && t[2] - t[1] == val1){
          cout << t[0] << endl;
        }
        else{
          cout << t[i] << endl;
        }
        break;
      }
    }
  }
}

Measured memory_bytes: 1160
INF = float("inf")

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_ints_list = lambda:list(input_ints())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,input_func:[input_func() for _ in range(n)]

import importlib
import_module = lambda module_name:importlib.import_module(module_name)

init_array_1dim = lambda value,n:[value]*n # 1次元配列を生成
init_array_2dim = lambda value,n,m:[init_array_1dim(value,n) for _ in range(m)] # 2次元配列を生成

gcd_base = lambda value1,value2:import_module('fractions').gcd(value1,value2) # 最大公約数（2値)
gcd = lambda lst:import_module('functools').reduce(gcd_base,lst) # 最大公約数（リスト）
lcm_base = lambda value1,value2:(value1*value2)//gcd_base(value1,value2) # 最小公倍数(2値)
lcm = lambda lst:import_module('functools').reduce(lcm_base,lst,1) # 最小公倍数(リスト)

permutations = lambda lst,n:import_module('itertools').permutations(lst,n) # 順列
combinations = lambda lst,n:import_module('itertools').combinations(lst,n) # 組み合わせ
product = lambda lst1,lst2:import_module('itertools').product(lst1,lst2) # 二つのリストの直積

round = lambda value:round(value) # 四捨五入
ceil = lambda value:import_module('math').ceil(value) # 切り上げ
floor = lambda value:import_module('math').floor(value) # 切り捨て

# キュー
init_q = lambda lst: import_module('collections').deque(lst)
q_pop = lambda q: q.popleft() # 先頭から取り出し
q_push = lambda q,value:q.appendleft(value) # 先頭に追加（値）
q_pushlist = lambda q,lst:q.extendleft(lst) # 先頭に追加（リスト）
q_append = lambda q,value:q.append(value) # 末尾に追加（値）
q_appendlist = lambda q,lst:q.extend(lst) # 末尾に追加（リスト）

# プライオリティキュー
init_heap = lambda a:import_module('heapq').heapify(a)
heap_push = lambda a,v:import_module('heapq').heappush(a,v)
heap_pop = lambda a:import_module('heapq').heappop(a) # 最小値を取り出す

def solution():
    # ここに実装
    N = input_int()
    h = input_ints_list()

    dp = init_array_1dim(0,N)
    for i in range(N):
        if i == 0:continue
        elif i == 1:dp[1] = abs(h[1]-h[0])
        else:
            dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
    print(dp[N-1])
    
if __name__ == '__main__':
    solution()

Measured memory_bytes: 13588
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

using namespace std;
const double PI (acos(-1));

int kaidan(int num){
  int sum=0;
  for(int i=num; i>0; i--)
  {
    sum += i;
  }
  return sum;
}

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

  int even = kaidan(N-1);

  int odd = kaidan(M-1);


  cout << even + odd;

  }


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
}
int main() {
  int A, B, K;
  cin >> A >> B >> K;
  
  int g = gcd(A, B);
  int count = 0;
  for (int i = g; i >= 1; i--) {
    if (g % i == 0) {
      count++;
      if (count == K) {
        cout << i << endl;
        return 0;
      }
    }
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll a[300000];
int main(){
	int n;cin>>n;
	ll d=0;
	rep(i,n){
		scanf("%lld",&a[i]);
		d^=a[i];
	}
	rep(i,n){
		cout<<(d^a[i])<<' ';
	}
	cout<<endl;
}

Measured memory_bytes: 5212
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int a, b;
  cin >> a >> b;

  if (a < b)
  {
    for (int i = 0; i < b; i++)
      cout << a;
  }
  else
  {
    for (int i = 0; i < a; i++)
      cout << b;
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vi a(n), cnt(n + 1);
	ll ans = 0;
	rep(i, n){
		cin >> a[i];
		ans += cnt[a[i]]++;
	}
	rep(i, n){
		cout << ans - cnt[a[i]] + 1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[105], v[105], dp[5];
vector<int> dp2[5];
LL sum[5][105];

int main(){
	int n, w;
	scanf("%d%d", &n, &w);
	for(int i=1;i<=n;i++){
		scanf("%d%d", &a[i], &v[i]);
	}
	int w1 = a[1];
	dp2[0].push_back(-2e9);
	dp2[1].push_back(-2e9);
	dp2[2].push_back(-2e9);
	dp2[3].push_back(-2e9);
	for(int i=1;i<=n;i++){
		dp[a[i]-w1]++;
		dp2[a[i]-w1].push_back(-v[i]);
	}
	for(int i=0;i<=3;i++){
		sort(dp2[i].begin(), dp2[i].end());
		for(int j=1;j<=dp[i];j++){
			sum[i][j] = sum[i][j-1] - dp2[i][j];
		}
	}
	LL ans = 0;
	for(int i=0;i<=dp[0];i++){
		for(int j=0;j<=dp[1];j++){
			for(int k=0;k<=dp[2];k++){
				int a = i, b = j, c = k;
				int d = 0;

				LL tot = (LL)w1*a + (LL)(w1+1)*b + (LL)(w1+2)*c;
				if(tot > w) continue;
				LL rem = w-tot;
				d = min((LL)dp[3], rem/(w1+3));


				LL cost = sum[0][a] + sum[1][b] + sum[2][c] + sum[3][d];
				ans = max(ans, cost);
			}	
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
#include <stdbool.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <chrono>
using namespace std;

int main(){
    #if 0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    #endif

    int N;
    cin >> N;

    cout << pow(N,3) << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;
int main()
{
	int N;
	int cnt = 0;

	int A[2][100];
	int x=0, y=0;
	int score[201] = { 0 };
	int score_max;

	cin >> N;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < N; j++) {
			cin >> A[i][j];
		}
	}
	for (int j = 0; j < N; j++) {
		for (int i = 0; i < N; i++) {
			score[j] += A[x][i];
			if (i == j) {
				x++;
				score[j] += A[x][i];		
			}
			
		}
		x = 0;
		if (j == 0)  score_max = score[j];
		else if(score_max < score[j]) score_max = score[j];
	}
	
	
	cout << score_max << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define debug(X) cout << #X << " = " << X << endl

using namespace std;

const int MN = 100010;

int a[MN], par[MN];
set<int> dict[MN];

int findSet(int i) { return par[i] == i ? i : par[i] = findSet(par[i]); }
void unionSet(int i, int j) { par[findSet(i)] = findSet(j); }

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	#ifdef UTP
	freopen("input.txt", "r", stdin);
	#endif
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++) par[i] = i;
	while (m--) {
		int x, y; cin >> x >> y; x--; y--;
		unionSet(x, y);
	}
	for (int i = 0; i < n; i++)
		dict[findSet(i)].insert(a[i] - 1);
	int ans = 0;
	for (int i = 0; i < n; i++)
		ans += dict[findSet(i)].count(i);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,c,k;
  cin >> n >> c >> k;
  vector<int> t(n);
  for(int i=0; i<n; i++){
    cin >> t[i];
  }
  sort(t.begin(),t.end());
  int jok,ans=0;
  int tmp;
  for(int i=0; i<n; i++){
    jok=0;
    if(t[i] > 0){//客iがまだ乗っていなかったら
      ans++;
      tmp = t[i];
      for(int j=i; j<n; j++){
        if(t[j] <= tmp+k && jok<c){//客iと同じバスに乗れるか
          jok++;
          t[j] = -1;
          //cout << jok <<endl;
        }else{
          break;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
import sys

# sys.stdin = open('d1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


n, m = read_int_list()
x = read_int_list()
y = read_int_list()


def compute_sum(q, a):
    return sum([(2 * p - q - 1) * a[p - 1] for p in range(1, q + 1)])


M = 10 ** 9 + 7
s = compute_sum(n, x)
t = compute_sum(m, y)
res = s * t % M
print(res)


Measured memory_bytes: 18624
#include "stdio.h"
#include<iostream>
#include<algorithm>

#define INFINITY 10000000

using namespace std;


int main(void){

  int N;
  scanf("%d",&N);
  
  int* p = new int [N+1];

  int** m = new int* [N+1];
  for(int i=0;i<N+1;i++){
    m[i] = new int [N+1];
  }

  for(int i=1;i<=N;i++){
    scanf("%d %d", &p[i-1], &p[i]);
  }

  for(int i=0;i<=N;i++){
    m[i][i] = 0;
  }


  for(int l=2;l<=N;l++){
    for(int i=1;i<= N-l+1;i++){
      int j = i+l-1;
      
      m[i][j] = INFINITY;
      for(int k=i;k<=j-1;k++){
        m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j]);
      }
    
    }
  
  }

  printf("%d\n", m[1][N]);

  delete [] p;
  for(int i=0;i<N+1;i++){
    delete [] m[i];
  }
  delete [] m;


  return 0;
}



Measured memory_bytes: 3224
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    solve();
}

void solve(){
    ll n;cin>>n;
    vl a(n);rep(i,n)cin>>a[i];

    vp b;
    rep(i,n)b.emplace_back(a[i],i);
    sort(all(b));

    ll ans=0;
    rep(i,n)ans+=b[i].second%2!=i%2;
    cout<<ans/2<<endl;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;
int N, M, K;
vector<int> edge[MAX_N];
vector<int> block[MAX_N];

class UnionFind{
public:
  UnionFind(int aN)
  {
    init(aN);
  }

  void init(int aN)
  {
    par.clear(); cnt.clear();
    par.resize(aN); cnt.resize(aN);
    for (size_t i = 0; i < aN; i++) {
      par[i] = i;
      cnt[i] = 1;
    }
  }

  int find(int aX)
  {
    if(aX == par[aX]) return aX;
    else return par[aX] = find(par[aX]);
  }

  bool same(int aX, int aY)
  {
    return find(aX) == find(aY);
  }

  int size(int aX)
  {
    return cnt[find(aX)];
  }

  void unite(int aX, int aY)
  {
    aX = find(aX);
    aY = find(aY);
    if(aX == aY) return;

    par[aX] = aY;
    cnt[aY] += cnt[aX];
  }
private:
  vector<int> par;
  vector<int> cnt;
};

UnionFind uf(MAX_N);

signed main()
{
  cin >> N >> M >> K;
  REP(m,M) {
    int a, b; cin >> a >> b;
    a--; b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
    uf.unite(a, b);
  }
  REP(k,K) {
    int a, b; cin >> a >> b;
    a--; b--;
    block[a].push_back(b);
    block[b].push_back(a);
  }

  REP(n,N) {
    int ans = uf.size(n) - 1;
    set<int> S;
    for(int next : edge[n]) {
      S.insert(next);
      ans--;
    }
    for(int b : block[n]) {
      if(S.insert(b).second && uf.same(n,b)) {
        ans--;
      }
    }
    if(0 < n) cout << " ";
    cout << ans;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 19572
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int a[3];
    int maxv = 0;
    REP(i, 3)
    {
        cin >> a[i];
        maxv = max(maxv, a[i]);
    }

    int ans = 0;

    while (1)
    {
        int cnt = 0;
        int maxvc = 0;
        REP(i, 3)
        {
            if (a[i] + 1 == maxv)
            {
                cnt++;
            }
            else if (a[i] == maxv)
            {
                maxvc++;
            }
        }
        if (cnt == 1 && maxvc == 2)
        {
            cout << ans + 2 << endl;
            return 0;
        }
        else if (cnt == 2 && maxvc == 1)
        {
            cout << ans + 1 << endl;
            return 0;
        }
        else if (maxvc == 3)
        {
            cout << ans << endl;
            return 0;
        }

        REP(i, 3)
        {
            if (a[i] + 1 < maxv)
            {
                a[i] += 2;
                ans++;
            }
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll>PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll MOD = 1e4+7;
int main() {
    ll x, y;
    cin >> x >> y;
    ll tmp_num = x;
    ll ans = 0;
    while ( tmp_num <= y ) {
        ++ans;
        tmp_num *= 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}

macro_rules! trace {
    ($x:expr) => { dbg!($x); };
    ($($xs:expr),*) => { dbg!(($($xs),*)); }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;


fn ex_gcd(x: i64, y: i64) -> (i64, i64) {
    let mut r0 = x;
    let mut a0 = 1;
    let mut b0 = 0;

    let mut r = y;
    let mut a = 0;
    let mut b = 1;

    while r > 0 {
        let r2 = r0 % r;
        let a2 = a0 - r0 / r * a;
        let b2 = b0 - r0 / r * b;
        r0 = r; r = r2;
        a0 = a; a = a2;
        b0 = b; b = b2;
    }
    (a0, b0)
}

fn mod_inv(x: i64, m: i64) -> i64 {
    let mut a = ex_gcd(x, m).0;
    while a < 0 { a += m; }
    a
}

fn comb(n: i64, k: i64, m: i64) -> i64 {
    if k == 0 { return 1; }
    if k == 1 { return n % m; }
    if n - k < k { return comb(n, n - k, m); }
    let mut c = 1;
    for i in 0..k {
        c *= n - i; c %= m;
        c *= mod_inv(k - i, m); c %= m;
    }
    c
}

fn biF(r: i64, c: i64) -> i64 {
    (comb(r + c + 2, r + 1, M) + M - 1) % M
}

fn main() {
    let mut sc = Scanner::new();
    // for i in 1..6 {
    //     for j in 1..6 {
    //         trace!(i, j, F(i, j), biF(i, j));
    //     }
    // }
    let r1: i64 = sc.cin();
    let c1: i64 = sc.cin();
    let r2: i64 = sc.cin();
    let c2: i64 = sc.cin();

    let mut ans = biF(r2, c2);
    ans %= M;
    ans += biF(r1-1,c1-1);
    ans %= M;
    ans += M - biF(r2, c1-1);
    ans %= M;
    ans += M - biF(r1-1, c2);
    ans %= M;
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;

int main() {
  int n;
cin>>n;
vector<int> A(n);
for(int i = 0; i < n;i++) {
int x;
cin>>x;
A[i]=x;
}
  vector<int> ans(n,0);
if(n==1){
cout<<A[0];}
  ans[0]=0;
  ans[1]=abs(A[0]-A[1]);

  for(int i= 2 ; i < n ;i++){
    ans[i]=min(ans[i-1] + abs(A[i-1]-A[i]),ans[i-2] + abs(A[i-2]-A[i]));
  }
  cout<<ans[A.size()-1]<<endl;
}


Measured memory_bytes: 4044
#include <iostream>
using namespace std;

int main(){
  long n, a, b;
  cin >> n >> a >> b;
  long loop = n/(a+b);
  long out = loop * a;
  if(n-(a+b)*loop > a){
    out += a;
    cout << out << endl;
  }else{
    out += (n-(a+b)*loop);
    cout << out << endl;
  }
  return 0;
}

Measured memory_bytes: 888