akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

const int INF = 1e7;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};

using L = tuple<int, int, int>;

int main() {
  int h, w;
  cin >> h >> w;
  V<string> g(h);
  rep(i, h) cin >> g[i];

  V<V<int>> c(h, V<int>(w, INF));
  priority_queue<L, V<L>, greater<L>> q;
  rep(i, h) rep(j, w) {
    if (g[i][j] == '.') continue;
    c[i][j] = 0;
    for (int k = 0; k < 4; k++) {
      int x = j + dx[k];
      int y = i + dy[k];
      if (x < 0 || x >= w || y < 0 || y >= h) continue;
      if (g[y][x] == '#') continue;
      c[y][x] = 1;
      q.push({1, y, x});
    }
  }
  while (!q.empty()) {
    auto e = q.top();
    q.pop();
    int d = get<0>(e);
    int i = get<1>(e);
    int j = get<2>(e);
    for (int k = 0; k < 4; k++) {
      int x = j + dx[k];
      int y = i + dy[k];
      if (x < 0 || x >= w || y < 0 || y >= h) continue;
      if (g[y][x] == '#') continue;
      int cost = d + 1;
      if (cost < c[y][x]) {
        c[y][x] = cost;
        q.push({cost, y, x});
      }
    }
  }
  int ans = 0;
  rep(i, h) rep(j, w) ans = max(ans, c[i][j]);
  cout << ans << endl;
}


Measured memory_bytes: 21100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;

int main(){
  int n;
  cin >> n;
  vector<int> prime = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
  int a = 0, b = 0, c = 0, d = 0, e = 0;
  for(int x : prime){
    int tmp = 0;
    int y = x;
    while(n >= y){
      tmp += n / y;
      y = y * x;
    }
    if(tmp >= 74) e++;
    if(tmp >= 24) d++;
    if(tmp >= 14) c++;
    if(tmp >= 4) a++;
    if(tmp >= 2) b++; 
  }
  cout << a * (a-1)/2 * (b-2) + e + d * (b-1) + c * (a-1) << endl;
    
}

Measured memory_bytes: 3604
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n, d = na()
ct = 0
for i in range(n):
    x, y = na()
    if x*x+y*y <= d*d:
        ct += 1
print(ct)


Measured memory_bytes: 68376
#include "bits/stdc++.h"
#include<assert.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define MRE assert(0);
const int inf = 1e17;
const int mod = 998244353;
typedef pair<int, int> P;
struct edge {
	int to, dir;
};

signed main(){
	int a, b; cin >> a >> b;
	if (a > b)swap(a, b);
	if (a == 1)cout << 1 << endl;
	else if (a % 2 == 1 && b % 2 == 1)cout << (a*b + 1) / 2 << endl;
	else cout << a*b / 2 << endl;
}

Measured memory_bytes: 256
import numpy as np
N,M = map(int,input().split())
A = (N+2)*[0]

for m in range(M):
  L,R = map(int,input().split())
  A[L]+=1
  A[R+1]-=1

A = np.cumsum(A)
print(sum(a==M for a in A))

Measured memory_bytes: 29212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int a[100];
int cells[100][100]; // r * c

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

  vector<ll> a(N);
  rep0(i, N) {
    cin >> a[i];
    a[i]--;
  }

  int ans = 0;
  rep0(i, N) {
    if (a[a[i]] == i) ans++;
  }

  cout << (ans / 2) << BR;
  return 0;
}

Measured memory_bytes: 1024
N = int(input())
tmp = []
for i in range(10):
  for j in range(10):
    solve = (4*(i+1))+(7*(j+1))
    if solve <= 100:
      tmp.append(solve)
multiples = sorted(list(set(tmp)))
if N % 4 == 0 or N % 7 == 0 or N in multiples:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int N;

  scanf("%d", &N);

  double btc = 0;
  int jpy = 0;

  while(N--) {
    double x;
    char u[5];
    scanf("%lf%s", &x, u);

    if (u[0] == 'B') {
      btc += x;
    } else {
      jpy += x;
    }
  }

  printf("%.10lf\n", btc * 380000.0 + jpy);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,T;
int A[3005],B[3005];
pair<int,int> p[3005];
int dp[3005][3005];

signed main(){
	cin>>N>>T;
	REP(i,N){
		cin>>A[i]>>B[i];
		p[i]={A[i],B[i]};
	}
	sort(p,p+N);
	int ans=0;
	REP(i,N){
		for(int j=0;j<T;j++){
			dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
			if(j+p[i].first<T){
				dp[i+1][j+p[i].first]=max(dp[i+1][j+p[i].first],dp[i][j]+p[i].second);
			}
		}
		REP(j,T){
			ans=max(ans,dp[i+1][j]+p[i+1].second);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 70784
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n, i = 0, iseven = 1, r = 0;
    int *array;
    scanf("%d", &n);
    array = (int*)malloc(sizeof(int) * n);
    
    for (i = 0; i<n; i++) {
        scanf("%d", &array[i]);
    }
    
    while (iseven == 1) {
        for (i = 0; i<n; i++) {
            if (array[i]%2==0) {
                array[i] /= 2;
            } else {
                iseven = 0;
            }
        }
        
        if (iseven == 0) {
            break;
        }
        r++;
    }
    
    printf("%d\n", r);
    
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, K, Q;
    cin >> N >> K >> Q;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    ll res = (1ll << 60);
    REP(i, N){
    	ll ki = A[i];
    	vector<ll> G[N];
    	ll ind = 0;
    	REP(j, N){
    		if(A[j] < ki) ind++;
    		else G[ind].push_back(A[j]);
    	}
    	vector<ll> cand;
    	REP(j, N){
    		sort(G[j].begin(), G[j].end());
    		REP(k, G[j].size()-K+1){
    			cand.push_back(G[j][k]);
    		}
    	}
    	sort(cand.begin(), cand.end());
    	if(cand.size() >= Q) res = min(res, cand[Q-1] - ki);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;

int main(){
	int n;
	while(cin >> n && n){
		n++;
		vector< pair<string,int> > shop[16];
		for(int i = 1 ; i <= n-1 ; i++){
			int k;
			cin >> k;
			for(int j = 0 ; j < k ; j++){
				string name;
				int value;
				cin >> name >> value;
				shop[i].push_back( make_pair(name,value) );
			}
		}
		set<string> want;
		vector<string> lst;
		int q;
		cin >> q;
		for(int i = 0 ; i < q ; i++){
			string t; cin >> t;
			want.insert(t);
			lst.push_back(t);
		}
		vector< pair<int,int> > con;
		
		for(int i = 0 ; i < (1<<n) ; i++){
			set<string> w = want;
			map<string,int> mini;
			for(int j = 0 ; j < n ; j++){
				if( !(i>>j&1) ) continue;
				for(int k = 0 ; k < shop[j].size() ; k++){
					w.erase(shop[j][k].first);
					if( mini.count(shop[j][k].first) == 0 ) mini[shop[j][k].first] = shop[j][k].second;
					else mini[shop[j][k].first] = min( mini[shop[j][k].first] , shop[j][k].second);
				}
			}
			if( w.size() != 0 ) continue;
			
			int sum = 0;
			for(int j = 0 ; j < q ; j++){
				sum += mini[lst[j]];
			}
			con.push_back(make_pair(sum,i));
		}
		int m;
		cin >> m;
		int wf[11][11] = {};
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ; j < n ; j++)
				wf[i][j] = 1e9;
		for(int i = 0 ; i < n ; i++)
			wf[i][i] = 0;
		for(int i = 0 ; i < m ; i++){
			int s,t,d;
			cin >> s >> t >> d;
			wf[s][t] = wf[t][s] = min(wf[s][t],d);
		}
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ; j < n ; j++)
				for(int k = 0 ; k < n ; k++)
					wf[j][k] = min(wf[j][k],wf[j][i]+wf[i][k]);
		int dp[1<<11][11] = {};
		for(int i = 0 ; i < (1<<11) ; i++)
			for(int j = 0 ; j < 11 ; j++)
				dp[i][j] = 1e9;
		dp[1][0] = 0;
		if( con.size() == 0 ){
			cout <<  "impossible" << endl;
		}else{
			sort(con.begin(),con.end());
			for(int i = 0 ; i < (1<<n) ; i++){
				for(int j = 0 ; j < n ; j++){
					if( i >> j & 1 ) {
						for(int k = 0 ; k < n ; k++){
							dp[i|(1<<k)][k] = min(dp[i|(1<<k)][k],dp[i][j]+wf[j][k]);
						}
					}
				}
			}
			int distance = 1e9;
			int firstCost = con[0].first;
			for(int i = 0 ; i < con.size() ; i++){
				if( con[0].first != con[i].first ) break;
				int bit = con[i].second | 1;
				for(int j = 0 ; j < n ; j++){
					distance = min(distance,dp[bit][j]+wf[j][0]);
				}
			}
			cout << firstCost << " " << distance << endl;
			
		}
	}
	
}

Measured memory_bytes: 1352
#include <iostream>
#include <cstring>
using namespace std;
 
int main() {
    char s[10000]={};
    int n,ok=1;
   /// cin>>s; ///daca nu contine spatii
    cin.getline(s,10000);
    n=strlen(s);/// returneaza cate caractere ai in sir
    ///122131221 n=9 (5,8), (6,7)
    ///012345678
   
    ///akaxaka    (0,6),(1,5),(2,4)
    ///0123456
   
   
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n-i-1]) ok=0;                
    }
    //cout<<ok<<"1\n";
    int m=(n-1)/2;
    for(int i=0;i<(n-1)/4-1;i++){
        if(s[i]!=s[m-i-1]) ok=0;
    }
    //cout<<ok<<"2\n";
    //cout<<n/2+1<<" "<<n/2+1+n/4-1<<" "<<n<<endl<<endl;
    for(int i=n/2+1;i<=n/2+1+n/4-1;i++){
      //  cout<<i<<" "<<n-i-1+(n/2+1)<<endl;
        if(s[i]!=s[n-i-1+(n/2+1)]) ok=0;
    }
    //cout<<ok<<"3\n";
    if(ok==0) cout<<"No";
    else      cout<<"Yes";
 return  0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b == c)
        cout << 1 << endl;
    else if(a == b || b == c || c == a)
        cout << 2 << endl;
    else
        cout << 3 << endl;
}

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

#define sz(x) (int)(x.size())
#define fr(i,a,b) for(int i=a;i<b;++i)
#define fdr(i,a,b) for(int i=b-1;i>=a;--i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

///////////////////////

int const N = 1e5 + 41;

int p[N];
int n, ans;

void solve(){
	cin >> n;
	fr(i, 1, n+1) cin >> p[i];
	fr(i, 1, n){
		if(p[i] == i || (i + 1 == n && p[i+1] == i + 1)){
			++ans;
			swap(p[i], p[i+1]);
		}
	}
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();



	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cctype>
#include <string>
#include <algorithm>

int main()
{
        std::string target;
        std::cin >> target;

        int cnt=0;
        while(true)
        {
                std::string str;
                std::cin >> str;

                if(str == "END_OF_TEXT")        break;

                transform(str.begin(),str.end(),str.begin(),tolower);

                if(str == target)
                        cnt++;
        }

        std::cout << cnt << std::endl;
}


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

int main() {
  int n; cin >>n; // 2 <= n <= 200000
  string cn; cin >>cn;
  int ret = 0, cr = 0, cw = 0;
  for (int i = 0; i < n; i++) {
    if (cn[i] == 'R') {cr++;}
    else {cw++;}
  }

  if (cr * cw == 0) {
    // どちらかが0なら何もしない
  } else {
    int j = 0, tmp_cr = 0;
    while (j < cr) {
      if (cn[j] == 'W') {ret++;}

      tmp_cr++;
      if (tmp_cr == cr) break;

      j++;
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 3732
n=int(input())
a=list(map(int,input().split()))
if n==1:
    if a[0]==1 and a[1]==1:
        print('Possible')
    else:
        print('Impossible')
    exit()
a.sort()
mxa=max(a)
mia=min(a)
from collections import Counter
ca=Counter(a)
if ca[mxa]==1:
    print('Impossible')
    exit()
if ca[mia]>1+mxa%2:
    print('Impossible')
    exit()
if 2*mia<mxa:
    print('Impossible')
    exit()
for i in range(mia+1,mxa+1):
    if i in ca and ca[i]>=2:
        pass
    else:
        print('Impossible')
        exit()
print('Possible')


Measured memory_bytes: 9368
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define N 2005
int n;
ll dp[N][N];
pair<ll,ll> p[N];
ll solve(int i,int left)
{
    if(i==n) return 0;
    if(dp[i][left]!=-1) return dp[i][left];
    ll right=i-left;
    right=(n-1-right);
    ll id=p[i].s;
    ll mul=p[i].f;
    return dp[i][left]=max(mul*abs(left-id)+solve(i+1,left+1),mul*abs(right-id)+solve(i+1,left));
}
int main()
{
    fastio;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>p[i].f;
        p[i].s=i;
    }
    sort(p,p+n);
    reverse(p,p+n);
    memset(dp,-1,sizeof dp);
    ll ans=solve(0,0);
    cout<<ans<<endl;
}


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

using namespace std;

int SolveDaruma(const int n, const vector<int> &w) {
    vector<vector<int>> s(n, vector<int>(n));

    for (int l = 0; l + 1 < n; ++l)
        if (abs(w[l] - w[l + 1]) <= 1)
            s[l][l + 1] = 2;

    for (int i = 3; i <= n; ++i)
        for (int l = 0; l + i <= n; ++l) {
            const int r = l + i - 1;

            if (abs(w[l] - w[r]) <= 1 && s[l + 1][r - 1] == i - 2)
                s[l][r] = i;

            for (int m = l + 1; m <= r; ++m)
                s[l][r] = max(s[l][r], s[l][m - 1] + s[m][r]);
        }

    return s[0][n - 1];
}

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

    int n;

    while (cin >> n, n) {
        vector<int> w(n);
        for (auto &x : w) cin >> x;

        cout << SolveDaruma(n, w) << '\n';
    }

    return 0;
}



Measured memory_bytes: 3276
package main

import (
	"fmt"
)

func main() {
	var k int
	fmt.Scan(&k)
	
	ans := 0
	for a := 1; a <= k; a++ {
		for b := 1; b <= k; b++ {
			for c := 1; c <= k; c++ {
				ans += gcd(gcd(a,b),c)
			}
		}
	}
	fmt.Println(ans)
}

func gcd(a,b int)int {
	if a % b == 0 {
		return b
	}
	return gcd(b, a%b)

}

Measured memory_bytes: 1776
import java.util.*;
import java.io.*;

public class Main {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer stok;

    String nextToken() throws IOException {
        while (stok == null || !stok.hasMoreTokens()) {
            String s = br.readLine();
            if (s == null) {
                return null;
            }
            stok = new StringTokenizer(s);
        }
        return stok.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    char nextChar() throws IOException {
        return (char) (br.read());
    }

    String nextLine() throws IOException {
        return br.readLine();
    }

    void solve() throws IOException {
        long n = nextInt();
        long x = 1;
        while (x * x <= n) {
            x++;
        }
        x--;
        out.println(x * x);
    }

    void run() throws IOException {
        // br = new BufferedReader(new FileReader("dragons.in"));
        //out = new PrintWriter("dragons.out");
        // br = new BufferedReader(new FileReader("input.txt"));
        // out = new PrintWriter("output.txt");
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        br.close();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        // Locale.setDefault(Locale.US);
        new Main().run();
    }
}

Measured memory_bytes: 21332
MODE = "stdio"
#require 'matrix'
#include Math
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = '9
  insert 5
  insert 2
  insert 3
  insert 1
  delete 3
  insert 6
  delete 5
  deleteFirst
  deleteLast'.split("\n")
  tmp.each{|s|
    line << s.strip
  }
end

n = line[0].to_i

cmd=[]
cmd_arr=[]
  
(1..n).each do |k|    
  cmd = line[k].split(" ")
  cmd[1] = cmd[1].to_i
  cmd_arr << cmd
end


ret_arr = []
cmd_arr.each do |cmd, key|
    case cmd
    when "insert"
        ret_arr.unshift(key)
    when "delete"
        index = ret_arr.index {|item| item == key}
        if index != nil
            ret_arr.delete_at(index)
        end
    when "deleteFirst"
        ret_arr.shift
    when "deleteLast"
        ret_arr.pop
    end
end
 
puts ret_arr.join(" ")

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

int main(){
    int n;
    cin >> n;
    vector<int> in(n+1);
    for(int i=0;i<n;i++){
        cin >> in[i];
    }
    in[n] = 2000000000;
    sort(in.begin(),in.end());
    int ans = 0;

    bool tmp=true;
    for(int i=0;i<n;i++){
        if(in[i]==in[i+1]){
            tmp = !(tmp);
        }
        else{
            if(tmp){
                ans ++;
            }
            else{
                tmp = true;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
using namespace std;
const int N = 1e5+5;
int h[N],n,k,ans[N];
main() {
    cin >> n;
    k = 2;
    // cin >> k;
    for (int i = 1; i <= n; i++)
        cin >> h[i];
    for (int i = 2; i <= n; i++) {
            ans[i] = 1000000000;
        for (int j = max(1,i - k); j < i; j++)
        ans[i] = min(ans[i],ans[j] + abs(h[i] - h[j]));
    }
    cout << ans[n];




}


Measured memory_bytes: 4372
#include <cstdio>

const int INF = 0x3f3f3f3f;
const int MAXN = 105;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

template<typename _T>
_T MIN( const _T a, const _T b )
{
	return a < b ? a : b;
}

int f[MAXN][MAXN][2];
char S[MAXN];
int N, M;
bool grid[MAXN][MAXN];

int main()
{
	read( N ), read( M );
	for( int i = 1 ; i <= N ; i ++ )
	{
		scanf( "%s", S + 1 );
		for( int j = 1 ; j <= M ; j ++ )
			grid[i][j] = S[j] == '#';
	}
	f[1][1][grid[1][1]] = 0, f[1][1][! grid[1][1]] = INF;
	for( int i = 1 ; i <= N ; i ++ ) f[i][0][0] = f[i][0][1] = INF;
	for( int i = 1 ; i <= M ; i ++ ) f[0][i][0] = f[0][i][1] = INF;
	for( int i = 1 ; i <= N ; i ++ )
		for( int j = 1 ; j <= M ; j ++ )
			if( i != 1 || j != 1 )
			{
				if( grid[i][j] )
					f[i][j][0] = INF, 
					f[i][j][1] = MIN( MIN( f[i - 1][j][0], f[i][j - 1][0] ), MIN( f[i - 1][j][1], f[i][j - 1][1] ) );
				else
					f[i][j][1] = INF,
					f[i][j][0] = MIN( MIN( f[i - 1][j][0], f[i][j - 1][0] ), MIN( f[i - 1][j][1], f[i][j - 1][1] ) + 1 );
			}
	write( MIN( f[N][M][0], f[N][M][1] + 1 ) ), putchar( '\n' );
	return 0;
}
/*
4 4
####
...#
...#
...#
*/
/*
4 4
..##
####
####
###.
*/

Measured memory_bytes: 256
s=input()
k=int(input())
ans=0
from itertools import*
g=[len(list(v))for k,v in groupby(s)]
for i in g:
    ans+=i//2
ans*=k
if s[0]==s[-1] and g[0]%2>0 and g[-1]%2>0:
    if len(s)==g[0]:
        ans+=k//2
    else:
        ans+=k-1
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b;
    while(cin>>a>>b)
    {
        if(b>a)  printf("%lld\n",(b-2*a)/4+a);
        else
        {
            printf("%lld\n",b/2);
        }
    }

    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_set>

using std::cin;
using std::cout;
using std::endl;
using std::unordered_set;
using std::pair;
using std::stack;
using std::string;
using std::vector;

int main(int argc, char* argv[]) {
  int n, k;
  cin >> n >> k;

  vector<pair<int, int>> ss(n);
  for (int i = 0; i < n; ++i) {
    int t, d;
    cin >> t >> d;
    ss[i] = std::make_pair(t, d);
  }

  sort(ss.begin(), ss.end(), [](const pair<int, int>& s1, const pair<int, int>& s2) {
      return s1.second > s2.second;
    });

  stack<pair<int, int>> ds;  // duplicated sushis
  unordered_set<int> ts;  // toppings;

  unsigned long max_satisfaction = 0;
  for (int i = 0; i < k; ++i) {
    if (ts.find(ss[i].first) == ts.end()) {
      ts.insert(ss[i].first);
    } else {
      ds.push(ss[i]);
    }
    max_satisfaction += ss[i].second;
  }
  max_satisfaction += ts.size() * ts.size();

  unsigned long satisfaction = max_satisfaction;
  for (int i = k; i < n; ++i) {
    if (ds.empty()) {
      break;
    }
    if (ts.find(ss[i].first) != ts.end()) {
      continue;
    }
    satisfaction = satisfaction + (ss[i].second - ds.top().second)
      + (ts.size() + 1) * (ts.size() + 1) - ts.size() * ts.size();
    if (satisfaction > max_satisfaction) {
      max_satisfaction = satisfaction;
    }
    ts.insert(ss[i].first);
    ds.pop();
  }

  cout << max_satisfaction;

  return 0;
}


Measured memory_bytes: 4748
import sys

L, R = map(int, input().split())

ans = sys.maxsize

for i in range(L, R+1):
    for j in range(i+1, R+1):
        minNum = (i * j) % 2019
        if minNum == 0:
            ans = minNum
            break
        else:
            ans = min(ans, minNum)
    else:
        continue
    break

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check(int n) {
    for(int i=2;i*i<=n;++i) {
        if(n%i==0)
        return false;
    }
    return true;
}


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     // return p.first>q.first;//descending by first
//     // return p.first<q.first;//ascending by first
//     // return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }

bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    int n,a,b;
    cin>>n>>a>>b;

    if(n*a<b)cout<<n*a<<endl;
    else cout<<b<<endl;
    // ()?cout<<"YES"<<endl:cout<<"NO"<<endl;
    
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vec vector<ll>
#define vvec vector<vec>
#define f(i,o,n) for(auto i=o;i!=n;i++)
#define pb push_back
#define mk make_pair
#define all(x) (x.begin(), x.end())

int main()
{
    ll n;
    cin>>n;
    vec a(n);
    f(i,0,n)
        cin>>a[i];
    vec dp(n);
    if(n<=1)
        cout<<"0"<<endl;
    else if(n==2)
        cout<<(abs(a[1]-a[0]))<<endl;
    else
    {
        dp[0] = 0;
        dp[1] = abs(a[1]-a[0]);
        // dp[2] = min(dp[1]+abs(a[2]-a[1]), abs(a[2]-a[0]));
        f(i,2,n)
        {
            dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
        }
        cout<<dp[n-1]<<endl;
    }
    
}

Measured memory_bytes: 4780
n = int(input())
l = list(map(int,input().split()))

m = []
for i in range(n):
    m.append(l[i]-i-1)

m.sort()
index = n//2

b = m[index]

ans = 0
for i in range(n):
    ans += abs(l[i]-b-i-1)

print(ans)


Measured memory_bytes: 26020
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main() {
  string a;
  cin >> a;
  vector <char> vec;
  for (int i = 0; i < a.size(); i++) {
    if (!vec.empty() && a[i] != vec.back()) {
      vec.pop_back();
    } else vec.push_back(a[i]);
  }
  cout << a.size() - vec.size() << endl;
  return 0;
}


Measured memory_bytes: 640
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int a,v,b,w,t;
   cin >> a >> v >> b >> w >> t;
   if(v <= w){
      cout << "NO\n";
      return 0;
   }
   int n = abs(a-b),d = abs(w-v);
   int T = (n+d-1)/d;
   if(T <= t){
      cout << "YES\n";
   }else{
      cout << "NO\n";
   }
   return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>   
using namespace std;


int main() {
    int k;
    string s;
    cin >> s >> k;
    int n = s.length();
    set<string> s_set;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= k; ++j) {
            s_set.insert(s.substr(i, j));
        }
    }
    vector<string> s_vec(s_set.begin(), s_set.end());
    sort(s_vec.begin(), s_vec.end());

    cout << s_vec[k - 1] << endl;
}

Measured memory_bytes: 1792
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) { //Boolean markers+DP
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		boolean[] bad = new boolean[N+1];
		long mod = (long)(1e9+7);
		long[] dp = new long[N+1];
		for (int i = 0; i < M; i++) {
			int x = input.nextInt();
			bad[x]=true;
		}
		if (N==1) System.out.println(1);
		else {
			if (!bad[1]) dp[1]=1;
			if (!bad[2]) dp[2]=dp[1]+1;
			for (int step = 3; step<=N; step++) {
				if (!bad[step]) {
					dp[step]=dp[step-1]+dp[step-2];
					dp[step]%=mod;
				} 
			}
			System.out.println(dp[N]);
		}	
	}	
}

Measured memory_bytes: 50092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007 //998244353
typedef vector<ll> vl;
typedef vector<vl> matrix;//A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
typedef vector<bool> vb;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Sortup(V) sort(V.begin(), V.end())
#define Sortdown(V) sort(V.rbegin(), V.rend())
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;}
void CumuSum(vl &A){rep(i,A.size())if(i)A[i]+=A[i-1];}
ll llpow(ll e,ll x){ll res=1LL;while(x){if(x&1)res*=e;e*=e;x/=2;}return res;}
ll llpowMOD(ll e,ll x){ll res=1LL;while(x){if(x&1)res*=e;e*=e;x/=2;res%=MOD;e%=MOD;}return res;}

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

    // solution comes here

    ll N;
    cin >> N;
    vl a(N), b(N);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];

    vl sa(N);
    rep(i, N) sa[i] = a[i] - b[i];
    Sortup(sa);

    ll end=lower_bound(sa.begin(), sa.end(), 0) - sa.begin();
    if(end==0) {
        cout << "0" << nl;
        return 0;
    }
    if(end==N) {
        cout << "-1" << nl;
        return 0;
    }

    for(ll i=0; i<end; i++) if(i) sa[i] += sa[i-1];
    for(ll i=N-1; i>=end; i--) {
        if(i!=N-1) sa[i] += sa[i+1];
        if(sa[i]>=abs(sa[end-1])) {
            cout << end+N-i << nl;
            return 0;
        }
    }

    cout << "-1" << nl;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <list>
using namespace std;

void deleteElement(list<int> &intList, int target){
    list<int>::iterator itr;
    for(itr=intList.begin() ; itr!=intList.end() ; itr++){
        if(*itr == target){
            intList.erase(itr);
            break;
        }
    }
    return;
}

int main(int argc, char const *argv[]) {
    int n, inputInt;
    char command[12];
    list<int> intList;

    scanf("%d", &n);
    for(int i=0 ; i<n ; i++){
        scanf("%s", command);
        // ??????????????????????????\
        if(strncmp(command, "insert", 6) == 0){
            scanf("%d", &inputInt);
            intList.push_front(inputInt);
        }
        // ???????????????
        else if(strncmp(command, "deleteFirst", 11) == 0){
            intList.pop_front();
        }
        // ????°??????????
        else if(strncmp(command, "deleteLast", 10) == 0){
            intList.pop_back();
        }
        // ?????????????´??????????
        else if(strncmp(command, "delete", 6) == 0){
            scanf("%d", &inputInt);
            deleteElement(intList, inputInt);
        }
        else printf("?????????????????????\n");
    }

    list<int>::iterator itr = intList.begin();
    printf("%d", *itr);
    itr++;
    for( ; itr!=intList.end() ; itr++){
        printf(" %d", *itr);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 33880
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#define MAXN 200005
#define MAXM
#define LL long long
#define LD long double
using namespace std;

int n, ans, a[MAXN];

map<LL, LL> num;

struct Edge {int next, to;} edge[MAXN*2];

bool CMP(int x, int y)
{
	return x>y;
}

int main()
{
	scanf("%d", &n);
	for(int i=1; i<=n; i++)
	{
		scanf("%d", &a[i]);
		num[a[i]]++;
	}
	sort(a+1, a+n+1, CMP);
	for(int i=1; i<=n; i++)
	{
		num[a[i]]--; int tag=0;
		for(int j=32; j>=1; j--)
		{
			LL temp=(1LL<<j)-a[i];
			if(temp<a[i]) break; 
			if(num.count(temp) && num[temp]>0)
			{
				tag=1; ans++;
				num[temp]--;
				break;
			}
		}
		if(!tag) num[a[i]]++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
typedef long long ll;

ll M,N;

int main(){
	cin>>N>>M;
	ll ans=min(N,M/2);
	N-=ans;
	M-=ans*2;
	ans+=M/4;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

template <typename T>
bool MinPlace(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool MaxPlace(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename Container>
int SZ(const Container& S) { return S.size(); }

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg_var(x) clog << #x  << ": " << x << endl;
    #define dbg_array(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg_var(x)
    #define dbg_array(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

const int MAXN = -1; 

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!
    // 17.22
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    C *= 2;
    C = min(C, A+B);
    A = min(A, C);
    B = min(B, C);
    if (X > Y) swap(X, Y), swap(A, B);
    cout << X*C + (Y-X)*B << "\n";
}



Measured memory_bytes: 256
#!/usr/bin/env ruby
require 'set'

N = 50_000 # ??¢?´¢???????´???°?????????
elt = Array.new(N, 1)
primes = []

# ??¨????????????????????????
elt[0] = 0
elt[1] = 0

N.times do |i|
  next if elt[i].zero?
  primes << i
  k = i * 2
  while k < N
    elt[k] = 0
    k += i
  end
end

# #include?????????????
primes = primes.to_set

while line = gets
  n = line.chomp!.to_i
  n2 = n/2
  break if n.zero?

  cnt = 0
  primes.each do |pr|
    break if pr > n2
    cnt += 1 if primes.include?(n-pr)
  end
  puts cnt
end

Measured memory_bytes: 9712
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    string s;
    cin>>s;

    if (s == "ABC") cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl; 
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
long long int gcd(long long int a,long long int b){
    if (b == 0)
      return a;
   return gcd(b, a % b);
}
long long int lcm(long long int a,long long int b){
    return (a*b)/gcd(a, b);
}

int main()
{
    long long int a,b,c,d,x,y,z;
     cin>>a>>b>>c>>d;
    x=(b/c-(a-1)/c);
    y=(b/d-(a-1)/d);
    z=(b/lcm(c,d)-(a-1)/lcm(c,d));
    x=x+y-z;


  cout<<b-a+1-x<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
    double x1,y1,x2,y2;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    printf("%lf\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
    return 0;
}


Measured memory_bytes: 2064
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
aa = [int(input()) for i in range(N)]

cnt = defaultdict(lambda:[0,0])
for i,a in enumerate(aa):
    if i%2 == 0:
        cnt[a][0] += 1
    else:
        cnt[a][1] += 1

aa.sort()
ans = 0
for i,a in enumerate(aa):
    ev,od = cnt[a]
    if i%2 == 0:
        if ev == 0:
            ans += 1
            cnt[a][0] -= 1
        else:
            cnt[a][1] -= 1
    else:
        if od == 0:
            ans += 1
            cnt[a][0] -= 1
        else:
            cnt[a][1] -= 1

print(ans//2)


Measured memory_bytes: 25556
/**
 *    author:  tourist
 *    created: 03.02.2018 17:31:24       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> val(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    val[x] ^= z;
    val[y] ^= z;
  }
  vector<int> cnt(16);
  for (int i = 0; i < n; i++) {
    cnt[val[i]]++;
  }
  int ans = 0;
  for (int i = 1; i < 16; i++) {
    ans += cnt[i] / 2;
    cnt[i] %= 2;
  }
  int mask = 0;
  for (int i = 1; i < 16; i++) {
    if (cnt[i] == 1) {
      mask |= (1 << i);
    }
  }
  vector<int> good(1 << 16);
  for (int t = 0; t < (1 << 16); t++) {
    int x = 0;
    for (int i = 0; i < 16; i++) {
      if (t & (1 << i)) {
        x ^= i;
      }
    }
    good[t] = (x == 0);
  }
  vector<int> dp(1 << 16, 0);
  for (int t = 0; t < (1 << 16); t++) {
    if (t & 1) {
      continue;
    }
    int u = t;
    while (u > 0) {
      if (good[u]) {
        dp[t] = max(dp[t], dp[t ^ u] + 1);
      }
      u = (u - 1) & t;
    }
  }
  printf("%d\n", ans + __builtin_popcount(mask) - dp[mask]);
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<vector<int>> x(N, vector<int>(N)), y(N, vector<int>(N));
    for(int i = 0; i < N; i++){
        cin >> A[i];
        for(int j = 0; j < A[i]; j++){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    int ans = 0;
    for(int bit = 1; bit < (1 << N); bit++){
        int cnt = 0;
        int flag = 0;
        for(int j = 0; j < N; j++){
            if(bit & (1 << j)){
                for(int k = 0; k < A[j]; k++){
                    if(y[j][k] == 0 && bit & (1 << x[j][k])) {
                        flag = 1;
                        break;
                    }
                    if(y[j][k] == 1 && (bit & (1 << x[j][k])) == 0) {
                        flag = 1;
                        break;
                    }
                }
                cnt++;
            }
            if(flag == 1) break;
        }
        if(flag == 0) ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3560
dxdy = [[1,0],[-1,0],[0,1],[0,-1]]
H,W = map(int,input().split())
s = []
for i in range(H):
    s.append(input())

goto = [[False]*W for _ in range(H)]
count = 0
for h in range(H):
    for w in range(W):
        black = 0
        white = 0
        if s[h][w] == '#' and goto[h][w] == False:
            black = 1
            goto[h][w] = True
            stack = [[h,w,'#']]
            while(stack!=[]):
                tarr = stack.pop()
                for dx,dy in dxdy:
                    if tarr[0]+dx >= 0 and tarr[0]+dx < H and tarr[1]+dy >= 0 and tarr[1]+dy < W:
                        if s[tarr[0]+dx][tarr[1]+dy] != tarr[2] and goto[tarr[0]+dx][tarr[1]+dy] == False:
                            stack.append([tarr[0]+dx,tarr[1]+dy,s[tarr[0]+dx][tarr[1]+dy]])
                            goto[tarr[0]+dx][tarr[1]+dy] = True
                            if s[tarr[0]+dx][tarr[1]+dy] == '#':
                                black += 1
                            else:
                                white += 1
        count += black*white
print(count)

Measured memory_bytes: 14404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i, n) cin >> A[i];
    int maxi = 0;
    bool d = 0;
    rep(i, n) {
        if (chmax(maxi, A[i])) {
            d = 0;
        } else if (maxi == A[i]) {
            d = 1;
        }
    }
    if (d) {
        rep(i, n) cout << maxi << endl;
        return;
    }
    int s = 0;
    rep(i, n) {
        if (A[i] == maxi) continue;
        chmax(s, A[i]);
    }
    rep(i, n) {
        if (A[i] == maxi) {
            cout << s << endl;
        } else {
            cout << maxi << endl;
        }
    }
}

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


Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#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*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    char c;
    cin>>c;
    map<char,char>m;
    m['A']='T';
    m['T']='A';
    m['C']='G';
    m['G']='C';
    cout<<m[c]<<endl;

}
return 0;
}

Measured memory_bytes: 256
n,k = gets.split.map &:to_i
p = gets.split.map &:to_i

max = n - k + 1

p_count = 0

count = 1
t_p = p[0]
start_i = 0

(1...p.size).each{ |i|
	if p[i] > t_p then
		count += 1
	else
		if count >= k then
			p_count += 1
		end
		count = 1
		start_i = i
	end

	t_p = p[i]
}

if count >= k then
	p_count += 1
end

min_q = []
max_q = []
del = 0

w = k - 1

(0...p.size).each{ |i|
#	print i, min_q, max_q, "\n"

	if i >= k && p[i] > max_q[0] && p[i - k] < min_q[0] then
		del += 1
	end

	if i >= w then
		if min_q[0] == p[i - w] then
			min_q.shift
		end
		if max_q[0] == p[i - w] then
			max_q.shift
		end
	end
	
	min_i = min_q.bsearch_index{ |x| x > p[i] }
	if min_i != nil then
		min_q.pop(min_q.size - min_i)
	end
	max_i = max_q.bsearch_index{ |x| x < p[i] }
	if max_i != nil then
		max_q.pop(max_q.size - max_i)
	end

	min_q.push(p[i])
	max_q.push(p[i])
}

#print del, p_count, "\n"
puts max - [p_count - 1, 0].max - del

Measured memory_bytes: 45840
#include <iostream>

using namespace std;

int main() {
	int k, x; cin >> k >> x;
	for (int i = x - k + 1; i < x + k; ++i) {
		if (i != x - k + 1) cout << " ";
		cout << i;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  void run() {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] s = new int[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
      s[i] = sc.nextInt();
      sum += s[i];
    }

    if (sum % 10 != 0) {
      System.out.println(sum);
    } else {
      Arrays.sort(s);
      for (int i = 0; i < n; i++) {
        if (s[i] % 10 == 0) {
          continue;
        }
        System.out.println(sum - s[i]);
        return;
      }
      System.out.println(0);
    }
  }
 
  public static void main(String[] args) {
    new Main().run();
  }
}


Measured memory_bytes: 21844