akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	priority_queue<ll> pq;
	rep(i,n){
	    ll t;
	    cin>>t;
	    pq.push(t);
	}
	ll ans=0;
	rep(i,m){
	    ll t=pq.top();
	    pq.pop();
	    pq.push(t/2);
	}
	while(!pq.empty()){ans+=pq.top();pq.pop();}
	puta(ans);
	return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  long long n, m, k;
  cin >> n >> m >> k;
  vector<int> A(n), B(m);
  for (auto &a : A) {
    cin >> a;
  }

  for (auto &b : B) {
    cin >> b;
  }

  vector<long long> preffix_sum_A(n + 1), preffix_sum_B(m + 1);
  for (int i = 1; i <= n; i++) {
    preffix_sum_A[i] = preffix_sum_A[i - 1] + A[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    preffix_sum_B[i] = preffix_sum_B[i - 1] + B[i - 1];
  }

  int best_res = 0;
  for (int i = 0; i <= n; i++) {
    if (preffix_sum_A[i] > k) {
      break;
    }
    long long from_A = preffix_sum_A[i];
    int cnt_B =
        upper_bound(preffix_sum_B.begin(), preffix_sum_B.end(), k - from_A) -
        preffix_sum_B.begin() - 1;
    best_res = max(i + cnt_B, best_res);
  }

  cout << best_res << "\n";
  return 0;
}

Measured memory_bytes: 7948
s = list(input())
n = len(s)
ans = 10**19
# 連続する３つの数字と比較する。
for i in range(1, n-1):
    a = int("".join([s[i-1], s[i], s[i+1]]))
    ans = min(abs(753-a), ans)
print(ans)


Measured memory_bytes: 9148
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, K, h[111111];

  std::cin >> N >> K;

  for (int i = 0; i < N; i ++)
    std::cin >> h[i];

  long long dp[111111];

  memset(dp, 0x3f, sizeof(dp));

  dp[0] = 0;

  for (int i = 0; i < N; i ++)
    for (int j = 1; j <= K; j ++)
      if (i + j < N)
        dp[i + j] = std::min(std::abs(h[i + j] - h[i]) + dp[i], dp[i + j]);

  std::cout << dp[N - 1] << std::endl;

  return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>
int main(int argc, char const *argv[])
{
    int n;
    int temp;
    scanf("%d",&n);
    int a[n];

    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n-1;i++){
            if(a[i]>a[i+1]){
                temp=a[i];
                a[i]=a[i+1];
                a[i+1]=temp;
            }
        }
    }


    int total=0;

    for(int i=0;i<n;i++){
        total=total+a[i];
    }

    total=total-(a[n-1]/2);
    printf("%d\n",total);
    return 0;
}

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

int main() {
	int n, m;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i<n; i++) cin >> a.at(i);
	cin >> m;
	vector<int> b(m);
	for (int i = 0; i<m; i++) cin >> b.at(i);
	
	if (a.at(n - 1) < b.at(m - 1)) {
		cout << 0 << endl;
		return 0;
	}
	int j=0;

	for (int i = 0; i<m; i++) {
		while (j<n) {
			if (b.at(i) == a.at(j)) break;
			if (b.at(i) < a.at(j)) {
				cout << 0 << endl;
				return 0;
			}
			j++;
		}
	}
	cout << 1 << endl;
}



Measured memory_bytes: 4236
inp = list(map(int, input().split()))
H, W = inp[0], inp[1]

import numpy as np

arr = np.array([[0 if e == '.' else 1 for e in input().split()[0]] for _ in range(H)])

h = []
for i in range(H):
    if (arr[i] == [0] * W).all():
        h.append(i)
ind = np.ones(H, dtype=bool)
ind[h] = False
arr = arr[ind]

w = []
for i in range(len(arr[0])):
    if (arr[:, i] == [0] * len(arr[:,0])).all():
        w.append(i)
ind = np.ones(len(arr[0]), dtype=bool)
ind[w] = False
arr = arr[:, ind]

for i in range(len(arr)):
    txt = ''
    for j in range(len(arr[0])):
        if arr[i][j] == 0:
            txt += '.'
        else:
            txt += '#'
    print(txt)

Measured memory_bytes: 13220
#include <bits/stdc++.h>
using namespace std;
 
int main() {

    int N;
    cin >> N;

    vector<int> A(N);
    int i;

    for(i=0; i<N; i++)
    {
        cin >> A.at(i);
    }

    int max = A.at(0);
    int min = A.at(0);;

    for(i=0; i<N; i++)
    {
        if(max < A.at(i))
        {
            max = A.at(i);
        }

        if(min > A.at(i))
        {
            min = A.at(i);
        }
    }

    cout << (max-min);

    return 0;
}

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

int solve(int, int);

int n, q;
int A[2000], m;

int main(){
	
	cin >> n;
	
	for(int i = 0 ; i < n ; i++){
		cin >> A[i];
	}
	
	cin >> q;
	
	for(int i = 0 ; i < q ; i++){
		cin >> m;
		int TorF = solve(0, m);
		if(TorF == true){
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}
	return 0;
}
	
	int solve(int i, int m){
		if(m == 0){
			return true; // can make
		}
		
		if(i >= n){
			return false; //can't make
		}
		
		int tmp = solve(i + 1, m)||solve(i + 1, m - A[i]);
				  /*not use A[i]*/ /*use A[i]*/
		return tmp;
		}

Measured memory_bytes: 1156
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
	int ans = 0;
	int a, b;
	cin >> a >> b;
	for (int i = 0; i < a; i++)
	{
		float x, y;
		cin >> x >> y;
		if (sqrt(pow(x,2)+pow(y,2))<=b)
		{
			ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3700
public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while (true) {
			int n = sc.nextInt();
			int x = sc.nextInt();

			if ( n==0 && x==0 ) break;

			int count = 0;
			for (int i=1; i <= n-2 && i < x/3; i++) {

				for (int j=i+1; j <= n-1 && j < x/2; j++) {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				}

			}

			sb.append(count).append("\n");
		}

		System.out.print(sb);
	}

}

Measured memory_bytes: 26872
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
 
using namespace std;
 
int dfs(vector<vector<int> > &dis,vector<int> &vis,int u=0) {
vis[u] = 1;
int res = 1;
for(int i = 0; i < dis.size(); i++) if(vis[i]==0 && dis[u][i]) {
res += dfs(dis,vis,i);
}
return res;
}
 
int main() {
	int n,m;
	cin >> n >> m;
	vector<vector<int> > dis(n,vector<int>(n,0));
	for(int i = 0; i < m; i++) {
		  int v,u;
		    cin >> u >> v;
		    u--; v--;
		      dis[u][v] = 1;
		        dis[v][u] = 1;
	}
	int res=0;
	for(int i = 0; i < n; i++) for(int j = i+1; j<n; j++) if(dis[i][j]==1) {
		dis[i][j] = 0;
		dis[j][i] = 0;
		vector<int> vis(n,0);
		if(dfs(dis,vis)!=n) res++;
		dis[i][j] = 1;
		dis[j][i] = 1;
	}
	cout << res << endl;
	return 0;
}


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	if (n<=9)
	{
		cout<<n<<endl;
	}
	else if (n<=99)
	{
		cout<<9<<endl;
	}
	else if (n<=999)
	{
		cout<<n-90<<endl;
	}
	else if (n<=9999)
	{
		cout<<909<<endl;
	}
	else if (n<=99999)
	{
		cout<<n-9090<<endl;
	}
	else
	{
		cout<<90909<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
    #include <string.h>
     
    void change (int len, char str[101]) {
    	char tmp = str[len-1];
    	for (int i=len-2; i>=0; i--)
    		str[i+1] = str[i];
     
    	str[0] = tmp;
    }

    int main(int argc, char *argv[]) {
    	char s[1000];
    	char t[1000];
    	int len;
     
    	scanf ("%s", s);
    	scanf ("%s", t);
     
    	len = strlen (s);
     
    	for (int i=0; i<len; i++) {
    		if (! strcmp (s, t)) {
    			printf ("Yes\n");
    			return 0;
    		}
    		change (len, s);
    	}
     
    	printf ("No\n");
    	return 0;
    }

Measured memory_bytes: 128
#include "bits/stdc++.h"


using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define DOUBLE fixed << setprecision(10)
#define fi first
#define se second
const double pi = acos(-1.0);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };
template <typename T>
bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
};
template <typename T>
bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
};
void Pvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void Pvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Ps(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void Pvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}

void Yay(bool x) {
	if (x) cout << "Yay!\n";
	else cout << ":(\n";
}

ll  n, m, r, l, k, h, ans = 0, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s,t;

void INIT() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << DOUBLE;
}

int main() {
	INIT();
	cin >> n;
	vll v(n+1), w(n);
	rep(i, n+1) cin >> v[i];
	rep(i, n) cin >> w[i];
	rep(i, n) {
		ans += min(v[i], w[i]);
		w[i] -= v[i];
		if (w[i] > 0) {
			ans += min(w[i],v[i+1]);
			v[i + 1] -= w[i];
			if (v[i + 1] < 0) v[i + 1] = 0;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MOD (ll)998244353

int l[200001], r[200001];
map<ll, ll> ma;
vector<int> v;


ll a[100001];

int main(void)
{
	ll n, x, m;
	scanf("%lld %lld %lld", &n, &x, &m);
	a[1] = x;
	ma[a[1]] = 1LL;
	ll period, start;
	ll sum = 0;
	for (ll i = 2; i <= 500000LL; i++)
	{
		a[i] = (a[i - 1] * a[i - 1]) % m;
		if (ma.find(a[i]) != ma.end())
		{
			period = i - ma[a[i]];
			start = ma[a[i]];
			break;
		}
		ma[a[i]] = i;
	}
	for (ll i = start; i < start + period; i++)
		sum += a[i];

	ll ans = 0;

	ll rotate = max(0LL, (n - start + 1LL) / period);
	ans += rotate * sum;

	n -= rotate * period;

	for (ll i = 1; i <= n; i++)
		ans += a[i];

	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 6744
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	vector<int> a(n);

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

	vector<int> b = a;

	if (prev_permutation(a.begin(), a.end())) {
		for (int i = 0; i < n; i++) {
			cout << a[i];

			if (i == n - 1) {
				cout << endl;
			}
			else {
				cout << " ";
			}
		}

		
	}

	

	
	for (int i = 0; i < n; i++) {
		cout << b[i];

		if (i == n - 1) {
			cout << endl;
		}
		else {
			cout << " ";
		}
	}
	
	
	
	if (next_permutation(b.begin(), b.end())) {
		for (int i = 0; i < n; i++) {
			cout << b[i];

			if (i == n - 1) {
				cout << endl;
			}
			else {
				cout << " ";
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3164
N = int(input())
h = list(map(int,input().split()))


test = []
tmp = []

while max(h) != 0:
    tmp = []
    for i in range(N):
        if h[i] == 0:
            tmp.append(0)
        else:
            tmp.append(1)
            h[i] -= 1
    test.append(tmp)

ans = 0
flag = 0
for i in test:
    if i[0] == 1:
        ans += 1
    for j in range(1,N):
        if i[j] == 0:
            continue
        elif i[j-1] == 0 and i[j] == 1:
            ans += 1
print(ans)


Measured memory_bytes: 3064
/*
	Name:
	Author: xiaruize
	Date:
*/
#pragma GCC optimize(2)
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<vector>
#include<cwchar>
#include<cwctype>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second
#define sz(a) int((a).size())

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	string s;
	cin>>s;
	int len=s.size();
	for(int i=0;i<min(n,len);i++)
	{
		cout<<s[i];
	}
	if(n<s.size())
	{
		cout<<"...";
	}
	return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
#define MAX 100000

int parent(int i){return i/2;};
int left(int i){return i*2;};
int right(int i){return i*2+1;};

int main()
{
  int H,i,A[MAX];
  
  scanf("%d",&H);
  for(i = 1; i <= H; i++)
    scanf("%d",&A[i]);
  for(i = 1;i <= H; i++)
    {
      printf("node %d: key = %d, ",i,A[i]);
      if(parent(i) >= 1) printf("parent key = %d, ",A[parent(i)]);
      if(left(i) <= H) printf("left key = %d, ",A[left(i)]);
      if(right(i) <= H) printf("right key = %d, ",A[right(i)]);
      printf("\n");
    }
  
  return 0;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
#define db(x) cout<<#x<<"="<<x<<endl;
using namespace std;
int n,a[25],ans;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=2;i<n;i++)if(a[i]==a[i-1]+a[i]+a[i+1]-max(a[i-1],max(a[i],a[i+1]))-min(a[i-1],min(a[i],a[i+1])))ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
///not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair< int, pair<int, int> >
#define plpll pair< ll, pair<ll, ll> >

using namespace std;

int32_t main(){
      string s, t;
      cin >>s >>t;
      int ans = 0;
      for(int i = 0; i < 3; i ++){
            if(s[i] == t[i])
                  ans ++;
      }
      cout <<ans <<endl;
      return false;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
const int mod = 998244353;
//const int mod = 1000000007;

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
// h(n, r) = c(n+r-1, r)
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
    fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
    ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
    return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main()
{
  int n, m, k;
  cin >> n >> m >> k;
  mint ans = 0;
  combination C(n);
  for(int i = 0; i <= k; ++i) {
    mint add = C(n-1, i);
    add *= m;
    add *= modpow(m-1, n-1-i);
    ans += add;
  }
  cout << ans.x << endl;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, c;
  in3(a, b, c);
  if(a == b)
    out(c);
  if(b == c)
    out(a);
  if(c == a)
    out(b);
  memi;
}

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

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	if(s.back()=='s'){
		cout << s << "es" << endl;
	}
	else{
		cout << s << "s" << endl;
	}
}

Measured memory_bytes: 3648
//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second
#define pll pair<lli, lli>
#define pii pair<int, int>
#define pil pair<int, lli>

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define findnot find_first_not_of
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements sbtriectly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD funcions*/
int main()
{
    kira;
    lli a,b,c;
    cin>>a>>b>>c;
    lli s=0;
    s+=a+b+c;
    if(s>=22)p0("bust");
    else p0("win");
    return 0;
}

Measured memory_bytes: 256
def bubble_sort(A):
    N=len(A)
    flag=True
    while flag:
        flag=False
        j=0
        for i in range(N-1, j, -1):
            if A[i-1][1:]>A[i][1:]:
                A[i-1],A[i]=A[i],A[i-1]
                flag=True
        j+=1
    return A

def selection_sort(A):
    N=len(A)
    for i in range(N-1):
        minj=i
        for j in range(i+1,N):
            if A[j][1:]<A[minj][1:]:
                minj=j
        A[i],A[minj]=A[minj],A[i]
    return A

N=int(input())
A=input().split()

bub=bubble_sort(A[:])
sel=selection_sort(A)
msg="Stable"

for i in range(N):
    if bub[i]!=sel[i]:
        msg="Not stable"

print(*bub)
print("Stable")
print(*sel)
print(msg)


Measured memory_bytes: 5616
import sys
 
sys.setrecursionlimit(100000)
 
while True:
  h, w = map(int, input().split())
  if not h:
    break
 
  mp = [list("X" + input() + "X") for _ in range(h)]
  mp.insert(0, ["X"] * (w + 2))
  mp.append(["X"] * (w + 2))
   
  direct = ((0, 1), (0, -1), (1, 0), (-1, 0))
 
  def search(x, y, target):
    mp[y][x] = "X"
    for dx, dy in direct:
      nx, ny = x + dx, y + dy
      if mp[ny][nx] == target:
        search(nx, ny, target)
   
  ans = 0
 
  for x in range(1, w + 1):
    for y in range(1, h + 1):
      target = mp[y][x]
      if target != "X":
        search(x, y, target)
        ans += 1
   
  print(ans)


Measured memory_bytes: 15904
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;

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

    int ans = 0;
    int seq = 0;
    int prev = 0;
    vector<int> h;
    for(int i = 0; i < n; i++){
        int cur;
        cin >>cur;
        if(cur <= prev){
            seq++;
            ans = max(seq, ans);
        }else{
            seq = 0;
        }
        prev = cur;
    }

    printf("%d\n", ans);

    return 0;
}

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

int n, som, maior, aux;
int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
	    scanf("%d", &aux);
	    if(aux>maior)maior = aux;
	    som+=aux;
	}
    som-=maior/2;
	printf("%d\n", som);
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	int X[100] = { 0 };
	cin >> a >> b;
	cout << a + (b / 2);
}

Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#define MAX_INT 2100000000
using namespace std;
typedef long long int ll;
//#include "Header.h"
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if ((a <= c && c <= b) || (b <= c && c <= a)) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<iomanip>
#include<bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
/*bool isPrime(long long n) 
{ long long i;
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false;
  
    return true; 
}

long long factorial(long long n) 
{    if(n==0||n==1)
     return 1;
     else
     return n*factorial(n - 1);  
} 

long long binarySearch(long long arr[], long long l, long long r, long long x) 
{ 
    while (l <= r) { 
        long long  m = l + (r - l) / 2; 
  
        
        if (arr[m] == x) 
            return m; 
  
      
        if (arr[m] < x) 
            l = m + 1; 
  
       
        else
            r = m - 1; 
    } 
    return -1; 
} 
*/

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    long long N,i,c=0;
 cin>>N;
 long long A[N];
 for(i=0;i<N;i++)
  cin>>A[i];
 for(i=0;i<N;i++)
 {if(A[i]%2!=0 && (i+1)%2!=0)
    c++;
  else 
    continue;
 }
 cout<<c<<endl;
  
    
    
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
using namespace std;


#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<VV> VVV;

vector<long long int> vec;

int main() {
	long long int a[5],c=0;
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < 5; i++) {
		vec.push_back(a[i]%10);
	}
	sort(vec.begin(), vec.end(), greater<long long int>());
	for (int i = 0; i < 5; i++) {
		if (vec[i] != 0)c = vec[i];
	}
	ll sum = 0,count=0;
	for (int i = 0; i < 5; i++) {
		if (a[i] % 10 == 0) {
			sum += a[i];
			count += 1;
		}
		else {
			sum += (a[i] / 10+1) * 10;
		}
	}
	if (count == 5) {
		cout << sum << endl;
	}
	else {
		cout << sum + c - 10 << endl;
	}
}


Measured memory_bytes: 256
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n,i,a,b,c,d[100010][3]={};
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d",&a,&b,&c);
    d[i+1][0]=MAX(d[i][1],d[i][2])+a;
    d[i+1][1]=MAX(d[i][0],d[i][2])+b;
    d[i+1][2]=MAX(d[i][0],d[i][1])+c;
  }
  printf("%d\n",MAX(d[i][0],MAX(d[i][1],d[i][2])));
  return 0;
}


Measured memory_bytes: 1280
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {  
 
	public static void main(String[] args) {  
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String a = I.next().toUpperCase();
		String b = I.next().toUpperCase();
		String c = I.next().toUpperCase();
		Queue<Character> A = new LinkedList<Character>();
		Queue<Character> B = new LinkedList<Character>();
		Queue<Character> C = new LinkedList<Character>();
		char cur = 'A';
		String ans = "";
		for (int i = 0; i < a.length(); i++) A.add(a.charAt(i));
		for (int i = 0; i < b.length(); i++) B.add(b.charAt(i));
		for (int i = 0; i < c.length(); i++) C.add(c.charAt(i));
		while (true) {
			if (cur=='A') {
				if (A.size()==0) {
					ans="A";
					break;
				}
				cur=A.poll();
			}else if (cur=='B') {
				if (B.size()==0) {
					ans="B";
					break;
				}
				cur=B.poll();
			}else {
				if (C.size()==0) {
					ans="C";
					break;
				}
				cur=C.poll();
			}
			//O.pln(cur);
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}

Measured memory_bytes: 25656
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node * treeMinimum(Node *x) {
	while( x->left != NIL ) x = x->left;
	return x;
}

Node * find(Node *u, int k) {
	while( u != NIL && k != u->key ) {
		if ( k < u->key ) u = u->left;
		else u = u->right;
	}
	return u;
}

Node * treeSuccessor(Node *x ) {
	if ( x->right != NIL ) return treeMinimum(x->right);
	Node *y = x->parent;
	while( y != NIL && x == y->right ) {
		x = y;
		y = y->parent;
	}
	return y;
}

void treeDelete(Node *z) {
	Node *y; // 削除する対象
	Node *x; // y の子
	
	// 削除する節点を決める
	if ( z->left == NIL || z->right == NIL ) y = z;
	else y = treeSuccessor(z);
	
	// y の子 x を決める
	if ( y->left != NIL ) {
		x = y->left;
	} else {
		x = y->right;
	}
	
	if ( x != NIL ) {
		x->parent = y->parent;
	}
	
	if ( y->parent == NIL ) {
		root = x;
	} else {
		if ( y == y->parent->left) {
			y->parent->left = x;
		} else {
			y->parent->right = x;
		}
	}
	
	if ( y != z ) {
		z->key = y->key;
	}
	
	free(y);
}

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while ( x != NIL ) {
		y = x;
		if ( z->key < x->key ) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if ( y == NIL ) {
		root = z;
	} else {
		if ( z->key < y->key ) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if ( u == NIL ) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u) {
	if ( u == NIL )return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main() {
	int n, i, x;
	string com;
	
	scanf("%d", &n);
	
	for ( i = 0; i < n; i++ ) {
		cin >> com;
		if ( com[0] == 'f' ) {
			scanf("%d", &x);
			Node *t = find(root, x);
			if ( t != NIL ) printf("yes\n");
			else printf("no\n");
		} else if ( com == "insert" ) {
			scanf("%d", &x);
			insert(x);
		} else if ( com == "print" ) {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		} else if ( com == "delete" ) {
			scanf("%d", &x);
			treeDelete(find(root, x));
		}
	}
	
	return 0;
}



Measured memory_bytes: 22040
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,R;
    int r[10];
    ll A[30000], B[30000], C[30000];
    cin >> N >> M >> R;
    rep(i,0,R){
        cin >> r[i];
        r[i]--;
    }
    rep(i,0,M){
        cin >> A[i] >> B[i] >> C[i];
        A[i]--;
        B[i]--;
    }
    ll d[210][210] = {};
    rep(i,0,N){
        rep(j,0,N){
            d[i][j] = INF;
        }
    }
    rep(i,0,M){
        d[A[i]][B[i]] = C[i];
        d[B[i]][A[i]] = C[i];
    }
    rep(k,0,N){
        rep(i,0,N){
            rep(j,0,N){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    vector<int> v(R);
    iota(v.begin(), v.end(), 0);
    ll ans = 1e9;
    do{
        ll ans_tmp = 0;

        rep(i,0,R-1){
            int r0 = r[v[i]];
            int r1 = r[v[i+1]];
            ans_tmp += d[r0][r1];
        }
        ans = min(ans, ans_tmp);

    }while(next_permutation(v.begin(), v.end()));
    print(ans);
}


Measured memory_bytes: 1152
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <vector>

using namespace std;

int getint()
{
    char ch=getchar();
    int f=1,x=0;
    while(!isdigit(ch)){if(ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-'0'; ch=getchar();}
    return f*x;
}

const int N=100100;

int n;
int a[N],a2[N];
int b[N],b2[N];
int fa[N];
bool vis[N];
vector<int> g[N];
int idx[N];
pair<int,int> c[N];
int sm,lpcnt;

int getfa(int x)
{
    if(fa[x]==x) return x;
    return fa[x]=getfa(fa[x]);
}

void merge(int x,int y)
{
    x=getfa(x);
    y=getfa(y);
    if(x==y) return;
    fa[x]=y;
}

void dscrt(int a[])
{
    for(int i=0; i<=n; i++){
        c[i].first=a[i];
        c[i].second=i;
    }
    sort(c,c+1+n);
    int tmp=0;
    a[c[0].second]=++tmp;
    for(int i=1; i<=n; i++){
        tmp+=c[i].first!=c[i-1].first;
        a[c[i].second]=tmp;
    }
}

void init()
{
    n=getint();
    for(int i=1; i<=n; i++){
        a[i]=a2[i]=getint();
        a[0]^=a[i];
        a2[0]^=a[i];
    }
    for(int i=1; i<=n; i++){
        b[i]=b2[i]=getint();
        b[0]^=b[i];
        b2[0]^=b[i];
    }
    sort(a2,a2+1+n);
    sort(b2,b2+1+n);
    for(int i=0; i<=n; i++) fa[i]=i;
    dscrt(a);
    dscrt(b);
    /*
    for(int i=0; i<=n; i++){
        printf("%d ",a[i]);
    }
    puts("");
    for(int i=0; i<=n; i++){
        printf("%d ",b[i]);
    }
    puts("");
    */
}

int main()
{
    init();
    bool flag=false;
    for(int i=0; i<=n; i++){
        if(a2[i]!=b2[i]){
            flag=true;
            break;
        }
    }
    if(flag){
        puts("-1");
        return 0;
    }
    for(int i=1; i<=n; i++){
        sm+=a[i]==b[i];
    }
    for(int i=0; i<=n; i++){
        g[a[i]].push_back(i);
    }
    for(int i=0; i<=n; i++){
        merge(i,g[b[i]][idx[b[i]]++]);
    }
    for(int i=0; i<=n; i++){
        for(int j=0; j+1<(int)g[i].size(); j++){
            merge(g[i][j],g[i][j+1]);
        }
    }
    for(int i=0; i<=n; i++){
        if(i!=0 && a[i]==b[i]) continue;
        int tmp=getfa(i);
        if(!vis[tmp]){
            vis[tmp]=true;
            lpcnt++;
        }
    }
    //printf("%d\n",lpcnt);
    printf("%d\n",max(0,n+lpcnt-1-sm));
    return 0;
}


Measured memory_bytes: 10496
b=list(map(int,input().split()))
c = int(input())
ans = 0
r = min([b[0]*4, b[1]*2, b[2]])
r2 = min([b[0]*8,b[1]*4,b[2]*2, b[3]])
#if c % 2 == 1:
#    ans += r
#   c -= 1
#ans += r2 * (c / 2)
#print(int(ans))

if c%2==1:
	print(((c-1)//2)*r2+r)
else :
	print((c//2)*r2)


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

int main() {
  string s;cin >> s;
  rep(i,4)cout << s[i];
  cout << ' ';
  rep2(i,4,12)cout << s[i];
  cout << endl;
}


Measured memory_bytes: 256
s = list(input())
alp = list("abcdefghijklmnopqrstuvwxyz")
for i in s:
    for j in range(len(alp)):
        if i == alp[j]:
            alp.pop(j)
            break
if len(alp) != 0: print(alp[0])
else: print("None")

Measured memory_bytes: 3956
N = int(input())
S = [input() for _ in range(N)]

S_ = {}
for a in S:
  if a not in S_:
    S_[a] = 1
  else:
    S_[a] += 1

S_ = sorted(S_.items(), key=lambda x:-x[1])

#print(S_)
max_ = 0
a = []
for i in range(len(S_)):
  #print(S_[i][1], )
  if S_[i][1] >= max_:
    max_ = S_[i][1]
    #print(a)
    a.append(S_[i][0])
  else:
    break
a =sorted(a)
print(*a)

Measured memory_bytes: 44684
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int n;
int q;
vector<int> edge[200005];
int cost[200005];
int child[200005];

void dfs(int v) {
    for(auto&&u:edge[v]) {
        if(-1==child[u]){
            cost[u] += cost[v];
            child[u] = child[v] + cost[u];
            dfs(u);
        }
    }
}

signed main() {

    cin >> n >> q;
    int a, b;
    for(int i = 0; i < n-1; i++) {
        cin >> a >> b;
        edge[a].bash(b);
        edge[b].bash(a);
    }
    for(int i = 0; i < q; i++) {
        cin >> a >> b;
        cost[a] += b;
    }
    memset(child,-1,sizeof(child));
    child[1] = cost[1];
    
    dfs(1);

    for(int i = 1; i <= n; i++) {
        cout << cost[i] ___ ;
    }cout << endl;
  
    return 0;
}



Measured memory_bytes: 22784
#include <cstdio>
#include <algorithm>

using namespace std;
int INF = 10000000;

void warshall_floyd (int dist[100][100], int N) {
  int i, j, k;
  for (k = 0; k < N; k++) {
    for (i = 0; i < N; i++) {
      for (j = 0; j < N; j++) {
	dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
      }
    }
  }
}

int main() {
  int N, M;
  int dist[100][100];
  int abc[1000][3];
  int i, j;
  scanf("%d %d", &N, &M);
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      if (i == j) {
	dist[i][j] = 0;
      } else {
	dist[i][j] = INF;
      }
    }
  }
  for (i = 0; i < M; i++) {
    scanf("%d %d %d", &abc[i][0], &abc[i][1], &abc[i][2]);
    dist[abc[i][0]-1][abc[i][1]-1] = abc[i][2];
    dist[abc[i][1]-1][abc[i][0]-1] = abc[i][2];
  }
  warshall_floyd(dist, N);
  //for (i = 0; i < N; i++) {
  //  for (j = 0; j < N; j++) {
  //    printf("%d ", dist[i][j]);
  //  }
  //  printf("\n");
  //}
  int ans = M;
  for (i = 0; i < M; i++) {
    bool flag = false;
    for (j = 0; j < N; j++) {
      if (dist[j][abc[i][1]-1] == dist[j][abc[i][0]-1]+abc[i][2]) {
	flag = true;
	break;
      }
    }
    if (flag == true) {
      ans -= 1;
    }
  }
  printf("%d", ans);
}
  
  
  
  


Measured memory_bytes: 256
function main(input) {
  const args = input.split('\n');
  let num = Number(args[0])
  let arr = args[1].split(' ').map(n => Number(n))

  answer = bubbleSort(num, arr)
  console.log(answer[0].join(' '))
  console.log(answer[1])

}

function bubbleSort(length, arr) {
  let flag = true
  let times = 0

  while (flag) {
    flag = false
    for (let i = (length-1); i > 0; i--) {
      if ( arr[i] < arr[i-1] ) {
        let tmp = arr[i-1] 
        arr[i-1] = arr[i]
        arr[i] = tmp
        flag = true
        times++
      }
    }
  }
  return [arr, times]
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 15552
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))

MOD = 10 ** 9 + 7

dp = [[0 for _ in range(m)] for _ in range(n)]
sd = [[0 for _ in range(m)] for _ in range(n)]

ans = 1

if s[0] == t[0]:
    dp[0][0] = 1
    sd[0][0] = 1
    ans += 1

for i in range(1, n):
    if s[i] == t[0]:
        dp[i][0] = 1
        ans += 1
    sd[i][0] = dp[i][0] + sd[i-1][0]

for j in range(1, m):
    if s[0] == t[j]:
        dp[0][j] = 1
        ans += 1
    sd[0][j] = dp[0][j] + sd[0][j-1]

for i in range(1, n):
    for j in range(1, m):
        if s[i] == t[j]:
            dp[i][j] = (sd[i-1][j-1] + 1) % MOD
            ans = (ans + dp[i][j]) % MOD
        sd[i][j] = (sd[i-1][j] + sd[i][j-1] - sd[i-1][j-1] + dp[i][j]) % MOD

print(ans)



Measured memory_bytes: 108124
#include <stdio.h>

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N], col[N], dpos[2*N-1], dneg[2*N-1];
int X[N][N];

void initialize();
void printBoard();
void recursive(int);


int main(){
  int i, j, k, r, c;

  initialize();

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      X[i][j] = 0;
    }
  }

  scanf("%d",&k);

  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    X[r][c] = 1;
  }

  recursive(0);



  return 0;
}

void initialize() {
  int i;
  for(i=0;i<N;i++) {
    row[i] = FREE;
    col[i] = FREE;
  }
  for(i=0;i<2*N-1;i++) {
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
}

void printBoard(){
  int i, j;
  for(i=0;i<N;i++) {
    for(j=0;j<N;j++) {
      if(X[i][j]){
        if(row[i]!=j) return;
      }
    }
  }
  for(i=0;i<N;i++) {
    for(j=0;j<N;j++){
      printf("%c",row[i]==j ? 'Q' : '.' );
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;
  if(i==N) {
    //クイーンの配置に成功
    printBoard();
    return;
  }

  for(j=0;j<N;j++){
    //(i,j)が他のクイーンに襲撃されている場合は無視
    if(NOT_FREE==col[j] || NOT_FREE==dpos[i+j] || NOT_FREE==dneg[i-j+N-1]) continue;
    //(i,j)にクイーンを配置
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    //次の行を試す
    recursive(i+1);
    //(i,j)に配置されているクイーンを取り除く
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
  //クイーンの配置に失敗
}



Measured memory_bytes: 2108